include/wincrypt.h: Add identifiers for Elliptic curve Diffie-Hellman algorithm.
[wine.git] / programs / msiexec / msiexec.c
blob2227af06aa8dde340f588915356ebb2b34f5a5e8
1 /*
2 * msiexec.exe implementation
4 * Copyright 2004 Vincent BĂ©ron
5 * Copyright 2005 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #define WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <msi.h>
26 #include <winsvc.h>
27 #include <objbase.h>
28 #include <stdio.h>
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
35 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
36 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
38 DWORD DoService(void);
40 struct string_list
42 struct string_list *next;
43 WCHAR str[1];
46 static const WCHAR ActionAdmin[] = {
47 'A','C','T','I','O','N','=','A','D','M','I','N',0 };
48 static const WCHAR RemoveAll[] = {
49 'R','E','M','O','V','E','=','A','L','L',0 };
51 static const WCHAR InstallRunOnce[] = {
52 'S','o','f','t','w','a','r','e','\\',
53 'M','i','c','r','o','s','o','f','t','\\',
54 'W','i','n','d','o','w','s','\\',
55 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
56 'I','n','s','t','a','l','l','e','r','\\',
57 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
59 static void ShowUsage(int ExitCode)
61 WCHAR msiexec_version[40];
62 WCHAR filename[MAX_PATH];
63 LPWSTR msi_res;
64 LPWSTR msiexec_help;
65 HMODULE hmsi = GetModuleHandleA("msi.dll");
66 DWORD len;
67 DWORD res;
69 /* MsiGetFileVersion need the full path */
70 *filename = 0;
71 res = GetModuleFileNameW(hmsi, filename, sizeof(filename) / sizeof(filename[0]));
72 if (!res)
73 WINE_ERR("GetModuleFileName failed: %d\n", GetLastError());
75 len = sizeof(msiexec_version) / sizeof(msiexec_version[0]);
76 *msiexec_version = 0;
77 res = MsiGetFileVersionW(filename, msiexec_version, &len, NULL, NULL);
78 if (res)
79 WINE_ERR("MsiGetFileVersion failed with %d\n", res);
81 /* Return the length of the resource.
82 No typo: The LPWSTR parameter must be a LPWSTR * for this mode */
83 len = LoadStringW(hmsi, 10, (LPWSTR) &msi_res, 0);
85 msi_res = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
86 msiexec_help = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) + sizeof(msiexec_version));
87 if (msi_res && msiexec_help) {
88 *msi_res = 0;
89 LoadStringW(hmsi, 10, msi_res, len + 1);
91 sprintfW(msiexec_help, msi_res, msiexec_version);
92 MsiMessageBoxW(0, msiexec_help, NULL, 0, GetUserDefaultLangID(), 0);
94 HeapFree(GetProcessHeap(), 0, msi_res);
95 HeapFree(GetProcessHeap(), 0, msiexec_help);
96 ExitProcess(ExitCode);
99 static BOOL IsProductCode(LPWSTR str)
101 GUID ProductCode;
103 if(lstrlenW(str) != 38)
104 return FALSE;
105 return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
109 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
111 struct string_list *entry;
112 DWORD size;
114 size = sizeof *entry + lstrlenW(str) * sizeof (WCHAR);
115 entry = HeapAlloc(GetProcessHeap(), 0, size);
116 if(!entry)
118 WINE_ERR("Out of memory!\n");
119 ExitProcess(1);
121 lstrcpyW(entry->str, str);
122 entry->next = NULL;
125 * Ignoring o(n^2) time complexity to add n strings for simplicity,
126 * add the string to the end of the list to preserve the order.
128 while( *list )
129 list = &(*list)->next;
130 *list = entry;
133 static LPWSTR build_properties(struct string_list *property_list)
135 struct string_list *list;
136 LPWSTR ret, p, value;
137 DWORD len;
138 BOOL needs_quote;
140 if(!property_list)
141 return NULL;
143 /* count the space we need */
144 len = 1;
145 for(list = property_list; list; list = list->next)
146 len += lstrlenW(list->str) + 3;
148 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
150 /* add a space before each string, and quote the value */
151 p = ret;
152 for(list = property_list; list; list = list->next)
154 value = strchrW(list->str,'=');
155 if(!value)
156 continue;
157 len = value - list->str;
158 *p++ = ' ';
159 memcpy(p, list->str, len * sizeof(WCHAR));
160 p += len;
161 *p++ = '=';
163 /* check if the value contains spaces and maybe quote it */
164 value++;
165 needs_quote = strchrW(value,' ') ? 1 : 0;
166 if(needs_quote)
167 *p++ = '"';
168 len = lstrlenW(value);
169 memcpy(p, value, len * sizeof(WCHAR));
170 p += len;
171 if(needs_quote)
172 *p++ = '"';
174 *p = 0;
176 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
178 return ret;
181 static LPWSTR build_transforms(struct string_list *transform_list)
183 struct string_list *list;
184 LPWSTR ret, p;
185 DWORD len;
187 /* count the space we need */
188 len = 1;
189 for(list = transform_list; list; list = list->next)
190 len += lstrlenW(list->str) + 1;
192 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
194 /* add all the transforms with a semicolon between each one */
195 p = ret;
196 for(list = transform_list; list; list = list->next)
198 len = lstrlenW(list->str);
199 lstrcpynW(p, list->str, len );
200 p += len;
201 if(list->next)
202 *p++ = ';';
204 *p = 0;
206 return ret;
209 static DWORD msi_atou(LPCWSTR str)
211 DWORD ret = 0;
212 while(*str >= '0' && *str <= '9')
214 ret *= 10;
215 ret += (*str - '0');
216 str++;
218 return ret;
221 static LPWSTR msi_strdup(LPCWSTR str)
223 DWORD len = lstrlenW(str)+1;
224 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
225 lstrcpyW(ret, str);
226 return ret;
229 /* str1 is the same as str2, ignoring case */
230 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
232 DWORD len, ret;
233 LPWSTR strW;
235 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
236 if( !len )
237 return FALSE;
238 if( lstrlenW(str1) != (len-1) )
239 return FALSE;
240 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
241 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
242 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
243 HeapFree(GetProcessHeap(), 0, strW);
244 return (ret == CSTR_EQUAL);
247 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
248 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
250 if (str1[0] != '/' && str1[0] != '-')
251 return FALSE;
253 /* skip over the hyphen or slash */
254 return msi_strequal(str1 + 1, str2);
257 /* str2 is at the beginning of str1, ignoring case */
258 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
260 DWORD len, ret;
261 LPWSTR strW;
263 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
264 if( !len )
265 return FALSE;
266 if( lstrlenW(str1) < (len-1) )
267 return FALSE;
268 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
269 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
270 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
271 HeapFree(GetProcessHeap(), 0, strW);
272 return (ret == CSTR_EQUAL);
275 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
276 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
278 if (str1[0] != '/' && str1[0] != '-')
279 return FALSE;
281 /* skip over the hyphen or slash */
282 return msi_strprefix(str1 + 1, str2);
285 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
287 VOID* (*proc)(void);
289 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
290 if(!*DllHandle)
292 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
293 ExitProcess(1);
295 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
296 if(!proc)
298 fprintf(stderr, "Dll %s does not implement function %s\n",
299 wine_dbgstr_w(DllName), ProcName);
300 FreeLibrary(*DllHandle);
301 ExitProcess(1);
304 return proc;
307 static DWORD DoDllRegisterServer(LPCWSTR DllName)
309 HRESULT hr;
310 DLLREGISTERSERVER pfDllRegisterServer = NULL;
311 HMODULE DllHandle = NULL;
313 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
315 hr = pfDllRegisterServer();
316 if(FAILED(hr))
318 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
319 return 1;
321 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
322 if(DllHandle)
323 FreeLibrary(DllHandle);
324 return 0;
327 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
329 HRESULT hr;
330 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
331 HMODULE DllHandle = NULL;
333 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
335 hr = pfDllUnregisterServer();
336 if(FAILED(hr))
338 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
339 return 1;
341 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
342 if(DllHandle)
343 FreeLibrary(DllHandle);
344 return 0;
347 static DWORD DoRegServer(void)
349 SC_HANDLE scm, service;
350 CHAR path[MAX_PATH+12];
351 DWORD ret = 0;
353 scm = OpenSCManagerA(NULL, SERVICES_ACTIVE_DATABASEA, SC_MANAGER_CREATE_SERVICE);
354 if (!scm)
356 fprintf(stderr, "Failed to open the service control manager.\n");
357 return 1;
360 GetSystemDirectoryA(path, MAX_PATH);
361 lstrcatA(path, "\\msiexec.exe /V");
363 service = CreateServiceA(scm, "MSIServer", "MSIServer", GENERIC_ALL,
364 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
365 SERVICE_ERROR_NORMAL, path, NULL, NULL,
366 NULL, NULL, NULL);
368 if (service) CloseServiceHandle(service);
369 else if (GetLastError() != ERROR_SERVICE_EXISTS)
371 fprintf(stderr, "Failed to create MSI service\n");
372 ret = 1;
374 CloseServiceHandle(scm);
375 return ret;
378 static INT DoEmbedding( LPWSTR key )
380 printf("Remote custom actions are not supported yet\n");
381 return 1;
385 * state machine to break up the command line properly
388 enum chomp_state
390 cs_whitespace,
391 cs_token,
392 cs_quote
395 static int chomp( WCHAR *str )
397 enum chomp_state state = cs_token;
398 WCHAR *p, *out;
399 int count = 1, ignore;
401 for( p = str, out = str; *p; p++ )
403 ignore = 1;
404 switch( state )
406 case cs_whitespace:
407 switch( *p )
409 case ' ':
410 break;
411 case '"':
412 state = cs_quote;
413 count++;
414 break;
415 default:
416 count++;
417 ignore = 0;
418 state = cs_token;
420 break;
422 case cs_token:
423 switch( *p )
425 case '"':
426 state = cs_quote;
427 break;
428 case ' ':
429 state = cs_whitespace;
430 *out++ = 0;
431 break;
432 default:
433 ignore = 0;
435 break;
437 case cs_quote:
438 switch( *p )
440 case '"':
441 state = cs_token;
442 break;
443 default:
444 ignore = 0;
446 break;
448 if( !ignore )
449 *out++ = *p;
452 *out = 0;
454 return count;
457 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
459 WCHAR **argv, *p = msi_strdup(cmdline);
460 int i, n;
462 n = chomp( p );
463 argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
464 for( i=0; i<n; i++ )
466 argv[i] = p;
467 p += lstrlenW(p) + 1;
469 argv[i] = NULL;
471 *pargc = n;
472 *pargv = argv;
475 static BOOL process_args_from_reg( const WCHAR *ident, int *pargc, WCHAR ***pargv )
477 LONG r;
478 HKEY hkey;
479 DWORD sz = 0, type = 0;
480 WCHAR *buf;
481 BOOL ret = FALSE;
483 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
484 if(r != ERROR_SUCCESS)
485 return FALSE;
486 r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
487 if(r == ERROR_SUCCESS && type == REG_SZ)
489 int len = lstrlenW( *pargv[0] );
490 if (!(buf = HeapAlloc( GetProcessHeap(), 0, sz + (len + 1) * sizeof(WCHAR) )))
492 RegCloseKey( hkey );
493 return FALSE;
495 memcpy( buf, *pargv[0], len * sizeof(WCHAR) );
496 buf[len++] = ' ';
497 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)(buf + len), &sz);
498 if( r == ERROR_SUCCESS )
500 process_args(buf, pargc, pargv);
501 ret = TRUE;
503 HeapFree(GetProcessHeap(), 0, buf);
505 RegCloseKey(hkey);
506 return ret;
509 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
511 int i;
512 BOOL FunctionInstall = FALSE;
513 BOOL FunctionInstallAdmin = FALSE;
514 BOOL FunctionRepair = FALSE;
515 BOOL FunctionAdvertise = FALSE;
516 BOOL FunctionPatch = FALSE;
517 BOOL FunctionDllRegisterServer = FALSE;
518 BOOL FunctionDllUnregisterServer = FALSE;
519 BOOL FunctionRegServer = FALSE;
520 BOOL FunctionUnregServer = FALSE;
521 BOOL FunctionServer = FALSE;
522 BOOL FunctionUnknown = FALSE;
524 LPWSTR PackageName = NULL;
525 LPWSTR Properties = NULL;
526 struct string_list *property_list = NULL;
528 DWORD RepairMode = 0;
530 DWORD_PTR AdvertiseMode = 0;
531 struct string_list *transform_list = NULL;
532 LANGID Language = 0;
534 DWORD LogMode = 0;
535 LPWSTR LogFileName = NULL;
536 DWORD LogAttributes = 0;
538 LPWSTR PatchFileName = NULL;
539 INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
541 INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
543 LPWSTR DllName = NULL;
544 DWORD ReturnCode;
545 int argc;
546 LPWSTR *argvW = NULL;
548 /* parse the command line */
549 process_args( GetCommandLineW(), &argc, &argvW );
552 * If the args begin with /@ IDENT then we need to load the real
553 * command line out of the RunOnceEntries key in the registry.
554 * We do that before starting to process the real commandline,
555 * then overwrite the commandline again.
557 if(argc>1 && msi_option_equal(argvW[1], "@"))
559 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
560 return 1;
563 if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
564 return DoEmbedding( argvW[2] );
566 for(i = 1; i < argc; i++)
568 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
570 if (msi_option_equal(argvW[i], "regserver"))
572 FunctionRegServer = TRUE;
574 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister")
575 || msi_option_equal(argvW[i], "unreg"))
577 FunctionUnregServer = TRUE;
579 else if(msi_option_prefix(argvW[i], "i") || msi_option_prefix(argvW[i], "package"))
581 LPWSTR argvWi = argvW[i];
582 int argLen = (msi_option_prefix(argvW[i], "i") ? 2 : 8);
583 FunctionInstall = TRUE;
584 if(lstrlenW(argvW[i]) > argLen)
585 argvWi += argLen;
586 else
588 i++;
589 if(i >= argc)
590 ShowUsage(1);
591 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
592 argvWi = argvW[i];
594 PackageName = argvWi;
596 else if(msi_option_equal(argvW[i], "a"))
598 FunctionInstall = TRUE;
599 FunctionInstallAdmin = TRUE;
600 InstallType = INSTALLTYPE_NETWORK_IMAGE;
601 i++;
602 if(i >= argc)
603 ShowUsage(1);
604 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
605 PackageName = argvW[i];
606 StringListAppend(&property_list, ActionAdmin);
608 else if(msi_option_prefix(argvW[i], "f"))
610 int j;
611 int len = lstrlenW(argvW[i]);
612 FunctionRepair = TRUE;
613 for(j = 2; j < len; j++)
615 switch(argvW[i][j])
617 case 'P':
618 case 'p':
619 RepairMode |= REINSTALLMODE_FILEMISSING;
620 break;
621 case 'O':
622 case 'o':
623 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
624 break;
625 case 'E':
626 case 'e':
627 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
628 break;
629 case 'D':
630 case 'd':
631 RepairMode |= REINSTALLMODE_FILEEXACT;
632 break;
633 case 'C':
634 case 'c':
635 RepairMode |= REINSTALLMODE_FILEVERIFY;
636 break;
637 case 'A':
638 case 'a':
639 RepairMode |= REINSTALLMODE_FILEREPLACE;
640 break;
641 case 'U':
642 case 'u':
643 RepairMode |= REINSTALLMODE_USERDATA;
644 break;
645 case 'M':
646 case 'm':
647 RepairMode |= REINSTALLMODE_MACHINEDATA;
648 break;
649 case 'S':
650 case 's':
651 RepairMode |= REINSTALLMODE_SHORTCUT;
652 break;
653 case 'V':
654 case 'v':
655 RepairMode |= REINSTALLMODE_PACKAGE;
656 break;
657 default:
658 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
659 break;
662 if(len == 2)
664 RepairMode = REINSTALLMODE_FILEMISSING |
665 REINSTALLMODE_FILEEQUALVERSION |
666 REINSTALLMODE_FILEVERIFY |
667 REINSTALLMODE_MACHINEDATA |
668 REINSTALLMODE_SHORTCUT;
670 i++;
671 if(i >= argc)
672 ShowUsage(1);
673 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
674 PackageName = argvW[i];
676 else if(msi_option_prefix(argvW[i], "x") || msi_option_equal(argvW[i], "uninstall"))
678 FunctionInstall = TRUE;
679 if(msi_option_prefix(argvW[i], "x")) PackageName = argvW[i]+2;
680 if(!PackageName || !PackageName[0])
682 i++;
683 if (i >= argc)
684 ShowUsage(1);
685 PackageName = argvW[i];
687 WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
688 StringListAppend(&property_list, RemoveAll);
690 else if(msi_option_prefix(argvW[i], "j"))
692 int j;
693 int len = lstrlenW(argvW[i]);
694 FunctionAdvertise = TRUE;
695 for(j = 2; j < len; j++)
697 switch(argvW[i][j])
699 case 'U':
700 case 'u':
701 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
702 break;
703 case 'M':
704 case 'm':
705 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
706 break;
707 default:
708 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
709 break;
712 i++;
713 if(i >= argc)
714 ShowUsage(1);
715 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
716 PackageName = argvW[i];
718 else if(msi_strequal(argvW[i], "u"))
720 FunctionAdvertise = TRUE;
721 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
722 i++;
723 if(i >= argc)
724 ShowUsage(1);
725 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
726 PackageName = argvW[i];
728 else if(msi_strequal(argvW[i], "m"))
730 FunctionAdvertise = TRUE;
731 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
732 i++;
733 if(i >= argc)
734 ShowUsage(1);
735 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
736 PackageName = argvW[i];
738 else if(msi_option_equal(argvW[i], "t"))
740 i++;
741 if(i >= argc)
742 ShowUsage(1);
743 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
744 StringListAppend(&transform_list, argvW[i]);
746 else if(msi_option_equal(argvW[i], "g"))
748 i++;
749 if(i >= argc)
750 ShowUsage(1);
751 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
752 Language = msi_atou(argvW[i]);
754 else if(msi_option_prefix(argvW[i], "l"))
756 int j;
757 int len = lstrlenW(argvW[i]);
758 for(j = 2; j < len; j++)
760 switch(argvW[i][j])
762 case 'I':
763 case 'i':
764 LogMode |= INSTALLLOGMODE_INFO;
765 break;
766 case 'W':
767 case 'w':
768 LogMode |= INSTALLLOGMODE_WARNING;
769 break;
770 case 'E':
771 case 'e':
772 LogMode |= INSTALLLOGMODE_ERROR;
773 break;
774 case 'A':
775 case 'a':
776 LogMode |= INSTALLLOGMODE_ACTIONSTART;
777 break;
778 case 'R':
779 case 'r':
780 LogMode |= INSTALLLOGMODE_ACTIONDATA;
781 break;
782 case 'U':
783 case 'u':
784 LogMode |= INSTALLLOGMODE_USER;
785 break;
786 case 'C':
787 case 'c':
788 LogMode |= INSTALLLOGMODE_COMMONDATA;
789 break;
790 case 'M':
791 case 'm':
792 LogMode |= INSTALLLOGMODE_FATALEXIT;
793 break;
794 case 'O':
795 case 'o':
796 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
797 break;
798 case 'P':
799 case 'p':
800 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
801 break;
802 case 'V':
803 case 'v':
804 LogMode |= INSTALLLOGMODE_VERBOSE;
805 break;
806 case '*':
807 LogMode = INSTALLLOGMODE_FATALEXIT |
808 INSTALLLOGMODE_ERROR |
809 INSTALLLOGMODE_WARNING |
810 INSTALLLOGMODE_USER |
811 INSTALLLOGMODE_INFO |
812 INSTALLLOGMODE_RESOLVESOURCE |
813 INSTALLLOGMODE_OUTOFDISKSPACE |
814 INSTALLLOGMODE_ACTIONSTART |
815 INSTALLLOGMODE_ACTIONDATA |
816 INSTALLLOGMODE_COMMONDATA |
817 INSTALLLOGMODE_PROPERTYDUMP |
818 INSTALLLOGMODE_PROGRESS |
819 INSTALLLOGMODE_INITIALIZE |
820 INSTALLLOGMODE_TERMINATE |
821 INSTALLLOGMODE_SHOWDIALOG;
822 break;
823 case '+':
824 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
825 break;
826 case '!':
827 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
828 break;
829 default:
830 break;
833 i++;
834 if(i >= argc)
835 ShowUsage(1);
836 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
837 LogFileName = argvW[i];
838 if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
840 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
841 wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
842 ExitProcess(1);
845 else if(msi_option_equal(argvW[i], "p"))
847 FunctionPatch = TRUE;
848 i++;
849 if(i >= argc)
850 ShowUsage(1);
851 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
852 PatchFileName = argvW[i];
854 else if(msi_option_prefix(argvW[i], "q"))
856 if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
857 msi_strequal(argvW[i] + 2, "uiet"))
859 InstallUILevel = INSTALLUILEVEL_NONE;
861 else if(msi_strequal(argvW[i]+2, "b"))
863 InstallUILevel = INSTALLUILEVEL_BASIC;
865 else if(msi_strequal(argvW[i]+2, "r"))
867 InstallUILevel = INSTALLUILEVEL_REDUCED;
869 else if(msi_strequal(argvW[i]+2, "f"))
871 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
873 else if(msi_strequal(argvW[i]+2, "n+"))
875 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
877 else if(msi_strequal(argvW[i]+2, "b+"))
879 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
881 else if(msi_strequal(argvW[i]+2, "b-"))
883 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
885 else if(msi_strequal(argvW[i]+2, "b+!"))
887 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
888 WINE_FIXME("Unknown modifier: !\n");
890 else if(msi_strequal(argvW[i]+2, "b!"))
892 InstallUILevel = INSTALLUILEVEL_BASIC;
893 WINE_FIXME("Unknown modifier: !\n");
895 else
897 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
898 wine_dbgstr_w(argvW[i]+2));
901 else if(msi_option_equal(argvW[i], "y"))
903 FunctionDllRegisterServer = TRUE;
904 i++;
905 if(i >= argc)
906 ShowUsage(1);
907 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
908 DllName = argvW[i];
910 else if(msi_option_equal(argvW[i], "z"))
912 FunctionDllUnregisterServer = TRUE;
913 i++;
914 if(i >= argc)
915 ShowUsage(1);
916 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
917 DllName = argvW[i];
919 else if(msi_option_equal(argvW[i], "help") || msi_option_equal(argvW[i], "?"))
921 ShowUsage(0);
923 else if(msi_option_equal(argvW[i], "m"))
925 FunctionUnknown = TRUE;
926 WINE_FIXME("Unknown parameter /m\n");
928 else if(msi_option_equal(argvW[i], "D"))
930 FunctionUnknown = TRUE;
931 WINE_FIXME("Unknown parameter /D\n");
933 else if (msi_option_equal(argvW[i], "V"))
935 FunctionServer = TRUE;
937 else
938 StringListAppend(&property_list, argvW[i]);
941 /* start the GUI */
942 MsiSetInternalUI(InstallUILevel, NULL);
944 Properties = build_properties( property_list );
946 if(FunctionInstallAdmin && FunctionPatch)
947 FunctionInstall = FALSE;
949 ReturnCode = 1;
950 if(FunctionInstall)
952 if(IsProductCode(PackageName))
953 ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
954 else
955 ReturnCode = MsiInstallProductW(PackageName, Properties);
957 else if(FunctionRepair)
959 if(IsProductCode(PackageName))
960 WINE_FIXME("Product code treatment not implemented yet\n");
961 else
962 ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
964 else if(FunctionAdvertise)
966 LPWSTR Transforms = build_transforms( property_list );
967 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
969 else if(FunctionPatch)
971 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
973 else if(FunctionDllRegisterServer)
975 ReturnCode = DoDllRegisterServer(DllName);
977 else if(FunctionDllUnregisterServer)
979 ReturnCode = DoDllUnregisterServer(DllName);
981 else if (FunctionRegServer)
983 ReturnCode = DoRegServer();
985 else if (FunctionUnregServer)
987 WINE_FIXME( "/unregserver not implemented yet, ignoring\n" );
989 else if (FunctionServer)
991 ReturnCode = DoService();
993 else if (FunctionUnknown)
995 WINE_FIXME( "Unknown function, ignoring\n" );
997 else
998 ShowUsage(1);
1000 return ReturnCode;