wininet: Improve stub message for InternetSetFilePointer.
[wine/multimedia.git] / programs / msiexec / msiexec.c
blobb794557cc2815bc11f4abed1c95e408a9d6e1616
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 <objbase.h>
27 #include <stdio.h>
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
34 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
35 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
37 DWORD DoService(void);
39 struct string_list
41 struct string_list *next;
42 WCHAR str[1];
45 static const WCHAR ActionAdmin[] = {
46 'A','C','T','I','O','N','=','A','D','M','I','N',0 };
47 static const WCHAR RemoveAll[] = {
48 'R','E','M','O','V','E','=','A','L','L',0 };
50 static const WCHAR InstallRunOnce[] = {
51 'S','o','f','t','w','a','r','e','\\',
52 'M','i','c','r','o','s','o','f','t','\\',
53 'W','i','n','d','o','w','s','\\',
54 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
55 'I','n','s','t','a','l','l','e','r','\\',
56 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
58 static void ShowUsage(int ExitCode)
60 WCHAR msiexec_version[40];
61 WCHAR filename[MAX_PATH];
62 LPWSTR msi_res;
63 LPWSTR msiexec_help;
64 HMODULE hmsi = GetModuleHandleA("msi.dll");
65 DWORD len;
66 DWORD res;
68 /* MsiGetFileVersion need the full path */
69 *filename = 0;
70 res = GetModuleFileNameW(hmsi, filename, sizeof(filename) / sizeof(filename[0]));
71 if (!res)
72 WINE_ERR("GetModuleFileName failed: %d\n", GetLastError());
74 len = sizeof(msiexec_version) / sizeof(msiexec_version[0]);
75 *msiexec_version = 0;
76 res = MsiGetFileVersionW(filename, msiexec_version, &len, NULL, NULL);
77 if (res)
78 WINE_ERR("MsiGetFileVersion failed with %d\n", res);
80 /* Return the length of the resource.
81 No typo: The LPWSTR parameter must be a LPWSTR * for this mode */
82 len = LoadStringW(hmsi, 10, (LPWSTR) &msi_res, 0);
84 msi_res = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
85 msiexec_help = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) + sizeof(msiexec_version));
86 if (msi_res && msiexec_help) {
87 *msi_res = 0;
88 LoadStringW(hmsi, 10, msi_res, len + 1);
90 sprintfW(msiexec_help, msi_res, msiexec_version);
91 MsiMessageBoxW(0, msiexec_help, NULL, 0, GetUserDefaultLangID(), 0);
93 HeapFree(GetProcessHeap(), 0, msi_res);
94 HeapFree(GetProcessHeap(), 0, msiexec_help);
95 ExitProcess(ExitCode);
98 static BOOL IsProductCode(LPWSTR str)
100 GUID ProductCode;
102 if(lstrlenW(str) != 38)
103 return FALSE;
104 return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
108 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
110 struct string_list *entry;
111 DWORD size;
113 size = sizeof *entry + lstrlenW(str) * sizeof (WCHAR);
114 entry = HeapAlloc(GetProcessHeap(), 0, size);
115 if(!entry)
117 WINE_ERR("Out of memory!\n");
118 ExitProcess(1);
120 lstrcpyW(entry->str, str);
121 entry->next = NULL;
124 * Ignoring o(n^2) time complexity to add n strings for simplicity,
125 * add the string to the end of the list to preserve the order.
127 while( *list )
128 list = &(*list)->next;
129 *list = entry;
132 static LPWSTR build_properties(struct string_list *property_list)
134 struct string_list *list;
135 LPWSTR ret, p, value;
136 DWORD len;
137 BOOL needs_quote;
139 if(!property_list)
140 return NULL;
142 /* count the space we need */
143 len = 1;
144 for(list = property_list; list; list = list->next)
145 len += lstrlenW(list->str) + 3;
147 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
149 /* add a space before each string, and quote the value */
150 p = ret;
151 for(list = property_list; list; list = list->next)
153 value = strchrW(list->str,'=');
154 if(!value)
155 continue;
156 len = value - list->str;
157 *p++ = ' ';
158 memcpy(p, list->str, len * sizeof(WCHAR));
159 p += len;
160 *p++ = '=';
162 /* check if the value contains spaces and maybe quote it */
163 value++;
164 needs_quote = strchrW(value,' ') ? 1 : 0;
165 if(needs_quote)
166 *p++ = '"';
167 len = lstrlenW(value);
168 memcpy(p, value, len * sizeof(WCHAR));
169 p += len;
170 if(needs_quote)
171 *p++ = '"';
173 *p = 0;
175 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
177 return ret;
180 static LPWSTR build_transforms(struct string_list *transform_list)
182 struct string_list *list;
183 LPWSTR ret, p;
184 DWORD len;
186 /* count the space we need */
187 len = 1;
188 for(list = transform_list; list; list = list->next)
189 len += lstrlenW(list->str) + 1;
191 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
193 /* add all the transforms with a semicolon between each one */
194 p = ret;
195 for(list = transform_list; list; list = list->next)
197 len = lstrlenW(list->str);
198 lstrcpynW(p, list->str, len );
199 p += len;
200 if(list->next)
201 *p++ = ';';
203 *p = 0;
205 return ret;
208 static DWORD msi_atou(LPCWSTR str)
210 DWORD ret = 0;
211 while(*str >= '0' && *str <= '9')
213 ret *= 10;
214 ret += (*str - '0');
215 str++;
217 return ret;
220 static LPWSTR msi_strdup(LPCWSTR str)
222 DWORD len = lstrlenW(str)+1;
223 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
224 lstrcpyW(ret, str);
225 return ret;
228 /* str1 is the same as str2, ignoring case */
229 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
231 DWORD len, ret;
232 LPWSTR strW;
234 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
235 if( !len )
236 return FALSE;
237 if( lstrlenW(str1) != (len-1) )
238 return FALSE;
239 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
240 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
241 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
242 HeapFree(GetProcessHeap(), 0, strW);
243 return (ret == CSTR_EQUAL);
246 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
247 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
249 if (str1[0] != '/' && str1[0] != '-')
250 return FALSE;
252 /* skip over the hyphen or slash */
253 return msi_strequal(str1 + 1, str2);
256 /* str2 is at the beginning of str1, ignoring case */
257 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
259 DWORD len, ret;
260 LPWSTR strW;
262 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
263 if( !len )
264 return FALSE;
265 if( lstrlenW(str1) < (len-1) )
266 return FALSE;
267 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
268 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
269 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
270 HeapFree(GetProcessHeap(), 0, strW);
271 return (ret == CSTR_EQUAL);
274 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
275 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
277 if (str1[0] != '/' && str1[0] != '-')
278 return FALSE;
280 /* skip over the hyphen or slash */
281 return msi_strprefix(str1 + 1, str2);
284 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
286 VOID* (*proc)(void);
288 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
289 if(!*DllHandle)
291 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
292 ExitProcess(1);
294 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
295 if(!proc)
297 fprintf(stderr, "Dll %s does not implement function %s\n",
298 wine_dbgstr_w(DllName), ProcName);
299 FreeLibrary(*DllHandle);
300 ExitProcess(1);
303 return proc;
306 static DWORD DoDllRegisterServer(LPCWSTR DllName)
308 HRESULT hr;
309 DLLREGISTERSERVER pfDllRegisterServer = NULL;
310 HMODULE DllHandle = NULL;
312 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
314 hr = pfDllRegisterServer();
315 if(FAILED(hr))
317 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
318 return 1;
320 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
321 if(DllHandle)
322 FreeLibrary(DllHandle);
323 return 0;
326 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
328 HRESULT hr;
329 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
330 HMODULE DllHandle = NULL;
332 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
334 hr = pfDllUnregisterServer();
335 if(FAILED(hr))
337 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
338 return 1;
340 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
341 if(DllHandle)
342 FreeLibrary(DllHandle);
343 return 0;
346 static DWORD DoRegServer(void)
348 SC_HANDLE scm, service;
349 CHAR path[MAX_PATH+12];
350 DWORD ret = 0;
352 scm = OpenSCManagerA(NULL, SERVICES_ACTIVE_DATABASEA, SC_MANAGER_CREATE_SERVICE);
353 if (!scm)
355 fprintf(stderr, "Failed to open the service control manager.\n");
356 return 1;
359 GetSystemDirectoryA(path, MAX_PATH);
360 lstrcatA(path, "\\msiexec.exe /V");
362 service = CreateServiceA(scm, "MSIServer", "MSIServer", GENERIC_ALL,
363 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
364 SERVICE_ERROR_NORMAL, path, NULL, NULL,
365 NULL, NULL, NULL);
367 if (service) CloseServiceHandle(service);
368 else if (GetLastError() != ERROR_SERVICE_EXISTS)
370 fprintf(stderr, "Failed to create MSI service\n");
371 ret = 1;
373 CloseServiceHandle(scm);
374 return ret;
377 static INT DoEmbedding( LPWSTR key )
379 printf("Remote custom actions are not supported yet\n");
380 return 1;
384 * state machine to break up the command line properly
387 enum chomp_state
389 cs_whitespace,
390 cs_token,
391 cs_quote
394 static int chomp( WCHAR *str )
396 enum chomp_state state = cs_token;
397 WCHAR *p, *out;
398 int count = 1, ignore;
400 for( p = str, out = str; *p; p++ )
402 ignore = 1;
403 switch( state )
405 case cs_whitespace:
406 switch( *p )
408 case ' ':
409 break;
410 case '"':
411 state = cs_quote;
412 count++;
413 break;
414 default:
415 count++;
416 ignore = 0;
417 state = cs_token;
419 break;
421 case cs_token:
422 switch( *p )
424 case '"':
425 state = cs_quote;
426 break;
427 case ' ':
428 state = cs_whitespace;
429 *out++ = 0;
430 break;
431 default:
432 ignore = 0;
434 break;
436 case cs_quote:
437 switch( *p )
439 case '"':
440 state = cs_token;
441 break;
442 default:
443 ignore = 0;
445 break;
447 if( !ignore )
448 *out++ = *p;
451 *out = 0;
453 return count;
456 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
458 WCHAR **argv, *p = msi_strdup(cmdline);
459 int i, n;
461 n = chomp( p );
462 argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
463 for( i=0; i<n; i++ )
465 argv[i] = p;
466 p += lstrlenW(p) + 1;
468 argv[i] = NULL;
470 *pargc = n;
471 *pargv = argv;
474 static BOOL process_args_from_reg( const WCHAR *ident, int *pargc, WCHAR ***pargv )
476 LONG r;
477 HKEY hkey;
478 DWORD sz = 0, type = 0;
479 WCHAR *buf;
480 BOOL ret = FALSE;
482 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
483 if(r != ERROR_SUCCESS)
484 return FALSE;
485 r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
486 if(r == ERROR_SUCCESS && type == REG_SZ)
488 int len = lstrlenW( *pargv[0] );
489 if (!(buf = HeapAlloc( GetProcessHeap(), 0, sz + (len + 1) * sizeof(WCHAR) )))
491 RegCloseKey( hkey );
492 return FALSE;
494 memcpy( buf, *pargv[0], len * sizeof(WCHAR) );
495 buf[len++] = ' ';
496 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)(buf + len), &sz);
497 if( r == ERROR_SUCCESS )
499 process_args(buf, pargc, pargv);
500 ret = TRUE;
502 HeapFree(GetProcessHeap(), 0, buf);
504 RegCloseKey(hkey);
505 return ret;
508 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
510 int i;
511 BOOL FunctionInstall = FALSE;
512 BOOL FunctionInstallAdmin = FALSE;
513 BOOL FunctionRepair = FALSE;
514 BOOL FunctionAdvertise = FALSE;
515 BOOL FunctionPatch = FALSE;
516 BOOL FunctionDllRegisterServer = FALSE;
517 BOOL FunctionDllUnregisterServer = FALSE;
518 BOOL FunctionRegServer = FALSE;
519 BOOL FunctionUnregServer = FALSE;
520 BOOL FunctionServer = FALSE;
521 BOOL FunctionUnknown = FALSE;
523 LPWSTR PackageName = NULL;
524 LPWSTR Properties = NULL;
525 struct string_list *property_list = NULL;
527 DWORD RepairMode = 0;
529 DWORD_PTR AdvertiseMode = 0;
530 struct string_list *transform_list = NULL;
531 LANGID Language = 0;
533 DWORD LogMode = 0;
534 LPWSTR LogFileName = NULL;
535 DWORD LogAttributes = 0;
537 LPWSTR PatchFileName = NULL;
538 INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
540 INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
542 LPWSTR DllName = NULL;
543 DWORD ReturnCode;
544 int argc;
545 LPWSTR *argvW = NULL;
547 /* parse the command line */
548 process_args( GetCommandLineW(), &argc, &argvW );
551 * If the args begin with /@ IDENT then we need to load the real
552 * command line out of the RunOnceEntries key in the registry.
553 * We do that before starting to process the real commandline,
554 * then overwrite the commandline again.
556 if(argc>1 && msi_option_equal(argvW[1], "@"))
558 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
559 return 1;
562 if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
563 return DoEmbedding( argvW[2] );
565 for(i = 1; i < argc; i++)
567 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
569 if (msi_option_equal(argvW[i], "regserver"))
571 FunctionRegServer = TRUE;
573 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister")
574 || msi_option_equal(argvW[i], "unreg"))
576 FunctionUnregServer = TRUE;
578 else if(msi_option_prefix(argvW[i], "i") || msi_option_prefix(argvW[i], "package"))
580 LPWSTR argvWi = argvW[i];
581 int argLen = (msi_option_prefix(argvW[i], "i") ? 2 : 8);
582 FunctionInstall = TRUE;
583 if(lstrlenW(argvW[i]) > argLen)
584 argvWi += argLen;
585 else
587 i++;
588 if(i >= argc)
589 ShowUsage(1);
590 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
591 argvWi = argvW[i];
593 PackageName = argvWi;
595 else if(msi_option_equal(argvW[i], "a"))
597 FunctionInstall = TRUE;
598 FunctionInstallAdmin = TRUE;
599 InstallType = INSTALLTYPE_NETWORK_IMAGE;
600 i++;
601 if(i >= argc)
602 ShowUsage(1);
603 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
604 PackageName = argvW[i];
605 StringListAppend(&property_list, ActionAdmin);
607 else if(msi_option_prefix(argvW[i], "f"))
609 int j;
610 int len = lstrlenW(argvW[i]);
611 FunctionRepair = TRUE;
612 for(j = 2; j < len; j++)
614 switch(argvW[i][j])
616 case 'P':
617 case 'p':
618 RepairMode |= REINSTALLMODE_FILEMISSING;
619 break;
620 case 'O':
621 case 'o':
622 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
623 break;
624 case 'E':
625 case 'e':
626 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
627 break;
628 case 'D':
629 case 'd':
630 RepairMode |= REINSTALLMODE_FILEEXACT;
631 break;
632 case 'C':
633 case 'c':
634 RepairMode |= REINSTALLMODE_FILEVERIFY;
635 break;
636 case 'A':
637 case 'a':
638 RepairMode |= REINSTALLMODE_FILEREPLACE;
639 break;
640 case 'U':
641 case 'u':
642 RepairMode |= REINSTALLMODE_USERDATA;
643 break;
644 case 'M':
645 case 'm':
646 RepairMode |= REINSTALLMODE_MACHINEDATA;
647 break;
648 case 'S':
649 case 's':
650 RepairMode |= REINSTALLMODE_SHORTCUT;
651 break;
652 case 'V':
653 case 'v':
654 RepairMode |= REINSTALLMODE_PACKAGE;
655 break;
656 default:
657 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
658 break;
661 if(len == 2)
663 RepairMode = REINSTALLMODE_FILEMISSING |
664 REINSTALLMODE_FILEEQUALVERSION |
665 REINSTALLMODE_FILEVERIFY |
666 REINSTALLMODE_MACHINEDATA |
667 REINSTALLMODE_SHORTCUT;
669 i++;
670 if(i >= argc)
671 ShowUsage(1);
672 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
673 PackageName = argvW[i];
675 else if(msi_option_prefix(argvW[i], "x") || msi_option_equal(argvW[i], "uninstall"))
677 FunctionInstall = TRUE;
678 if(msi_option_prefix(argvW[i], "x")) PackageName = argvW[i]+2;
679 if(!PackageName || !PackageName[0])
681 i++;
682 if (i >= argc)
683 ShowUsage(1);
684 PackageName = argvW[i];
686 WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
687 StringListAppend(&property_list, RemoveAll);
689 else if(msi_option_prefix(argvW[i], "j"))
691 int j;
692 int len = lstrlenW(argvW[i]);
693 FunctionAdvertise = TRUE;
694 for(j = 2; j < len; j++)
696 switch(argvW[i][j])
698 case 'U':
699 case 'u':
700 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
701 break;
702 case 'M':
703 case 'm':
704 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
705 break;
706 default:
707 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
708 break;
711 i++;
712 if(i >= argc)
713 ShowUsage(1);
714 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
715 PackageName = argvW[i];
717 else if(msi_strequal(argvW[i], "u"))
719 FunctionAdvertise = TRUE;
720 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
721 i++;
722 if(i >= argc)
723 ShowUsage(1);
724 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
725 PackageName = argvW[i];
727 else if(msi_strequal(argvW[i], "m"))
729 FunctionAdvertise = TRUE;
730 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
731 i++;
732 if(i >= argc)
733 ShowUsage(1);
734 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
735 PackageName = argvW[i];
737 else if(msi_option_equal(argvW[i], "t"))
739 i++;
740 if(i >= argc)
741 ShowUsage(1);
742 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
743 StringListAppend(&transform_list, argvW[i]);
745 else if(msi_option_equal(argvW[i], "g"))
747 i++;
748 if(i >= argc)
749 ShowUsage(1);
750 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
751 Language = msi_atou(argvW[i]);
753 else if(msi_option_prefix(argvW[i], "l"))
755 int j;
756 int len = lstrlenW(argvW[i]);
757 for(j = 2; j < len; j++)
759 switch(argvW[i][j])
761 case 'I':
762 case 'i':
763 LogMode |= INSTALLLOGMODE_INFO;
764 break;
765 case 'W':
766 case 'w':
767 LogMode |= INSTALLLOGMODE_WARNING;
768 break;
769 case 'E':
770 case 'e':
771 LogMode |= INSTALLLOGMODE_ERROR;
772 break;
773 case 'A':
774 case 'a':
775 LogMode |= INSTALLLOGMODE_ACTIONSTART;
776 break;
777 case 'R':
778 case 'r':
779 LogMode |= INSTALLLOGMODE_ACTIONDATA;
780 break;
781 case 'U':
782 case 'u':
783 LogMode |= INSTALLLOGMODE_USER;
784 break;
785 case 'C':
786 case 'c':
787 LogMode |= INSTALLLOGMODE_COMMONDATA;
788 break;
789 case 'M':
790 case 'm':
791 LogMode |= INSTALLLOGMODE_FATALEXIT;
792 break;
793 case 'O':
794 case 'o':
795 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
796 break;
797 case 'P':
798 case 'p':
799 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
800 break;
801 case 'V':
802 case 'v':
803 LogMode |= INSTALLLOGMODE_VERBOSE;
804 break;
805 case '*':
806 LogMode = INSTALLLOGMODE_FATALEXIT |
807 INSTALLLOGMODE_ERROR |
808 INSTALLLOGMODE_WARNING |
809 INSTALLLOGMODE_USER |
810 INSTALLLOGMODE_INFO |
811 INSTALLLOGMODE_RESOLVESOURCE |
812 INSTALLLOGMODE_OUTOFDISKSPACE |
813 INSTALLLOGMODE_ACTIONSTART |
814 INSTALLLOGMODE_ACTIONDATA |
815 INSTALLLOGMODE_COMMONDATA |
816 INSTALLLOGMODE_PROPERTYDUMP |
817 INSTALLLOGMODE_PROGRESS |
818 INSTALLLOGMODE_INITIALIZE |
819 INSTALLLOGMODE_TERMINATE |
820 INSTALLLOGMODE_SHOWDIALOG;
821 break;
822 case '+':
823 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
824 break;
825 case '!':
826 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
827 break;
828 default:
829 break;
832 i++;
833 if(i >= argc)
834 ShowUsage(1);
835 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
836 LogFileName = argvW[i];
837 if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
839 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
840 wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
841 ExitProcess(1);
844 else if(msi_option_equal(argvW[i], "p"))
846 FunctionPatch = TRUE;
847 i++;
848 if(i >= argc)
849 ShowUsage(1);
850 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
851 PatchFileName = argvW[i];
853 else if(msi_option_prefix(argvW[i], "q"))
855 if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
856 msi_strequal(argvW[i] + 2, "uiet"))
858 InstallUILevel = INSTALLUILEVEL_NONE;
860 else if(msi_strequal(argvW[i]+2, "b"))
862 InstallUILevel = INSTALLUILEVEL_BASIC;
864 else if(msi_strequal(argvW[i]+2, "r"))
866 InstallUILevel = INSTALLUILEVEL_REDUCED;
868 else if(msi_strequal(argvW[i]+2, "f"))
870 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
872 else if(msi_strequal(argvW[i]+2, "n+"))
874 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
876 else if(msi_strequal(argvW[i]+2, "b+"))
878 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
880 else if(msi_strequal(argvW[i]+2, "b-"))
882 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
884 else if(msi_strequal(argvW[i]+2, "b+!"))
886 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
887 WINE_FIXME("Unknown modifier: !\n");
889 else
891 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
892 wine_dbgstr_w(argvW[i]+2));
895 else if(msi_option_equal(argvW[i], "y"))
897 FunctionDllRegisterServer = TRUE;
898 i++;
899 if(i >= argc)
900 ShowUsage(1);
901 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
902 DllName = argvW[i];
904 else if(msi_option_equal(argvW[i], "z"))
906 FunctionDllUnregisterServer = TRUE;
907 i++;
908 if(i >= argc)
909 ShowUsage(1);
910 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
911 DllName = argvW[i];
913 else if(msi_option_equal(argvW[i], "help") || msi_option_equal(argvW[i], "?"))
915 ShowUsage(0);
917 else if(msi_option_equal(argvW[i], "m"))
919 FunctionUnknown = TRUE;
920 WINE_FIXME("Unknown parameter /m\n");
922 else if(msi_option_equal(argvW[i], "D"))
924 FunctionUnknown = TRUE;
925 WINE_FIXME("Unknown parameter /D\n");
927 else if (msi_option_equal(argvW[i], "V"))
929 FunctionServer = TRUE;
931 else
932 StringListAppend(&property_list, argvW[i]);
935 /* start the GUI */
936 MsiSetInternalUI(InstallUILevel, NULL);
938 Properties = build_properties( property_list );
940 if(FunctionInstallAdmin && FunctionPatch)
941 FunctionInstall = FALSE;
943 ReturnCode = 1;
944 if(FunctionInstall)
946 if(IsProductCode(PackageName))
947 ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
948 else
949 ReturnCode = MsiInstallProductW(PackageName, Properties);
951 else if(FunctionRepair)
953 if(IsProductCode(PackageName))
954 WINE_FIXME("Product code treatment not implemented yet\n");
955 else
956 ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
958 else if(FunctionAdvertise)
960 LPWSTR Transforms = build_transforms( property_list );
961 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
963 else if(FunctionPatch)
965 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
967 else if(FunctionDllRegisterServer)
969 ReturnCode = DoDllRegisterServer(DllName);
971 else if(FunctionDllUnregisterServer)
973 ReturnCode = DoDllUnregisterServer(DllName);
975 else if (FunctionRegServer)
977 ReturnCode = DoRegServer();
979 else if (FunctionUnregServer)
981 WINE_FIXME( "/unregserver not implemented yet, ignoring\n" );
983 else if (FunctionServer)
985 ReturnCode = DoService();
987 else if (FunctionUnknown)
989 WINE_FIXME( "Unknown function, ignoring\n" );
991 else
992 ShowUsage(1);
994 return ReturnCode;