xmllite/tests: Use common wine_dbgstr_guid implementation from test.h.
[wine/wine-gecko.git] / programs / msiexec / msiexec.c
blobe76b526b76ed81754eefa0ccd9fa7a1ae4a3ce49
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;
113 entry = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(struct string_list, str[lstrlenW(str) + 1]));
114 if(!entry)
116 WINE_ERR("Out of memory!\n");
117 ExitProcess(1);
119 lstrcpyW(entry->str, str);
120 entry->next = NULL;
123 * Ignoring o(n^2) time complexity to add n strings for simplicity,
124 * add the string to the end of the list to preserve the order.
126 while( *list )
127 list = &(*list)->next;
128 *list = entry;
131 static LPWSTR build_properties(struct string_list *property_list)
133 struct string_list *list;
134 LPWSTR ret, p, value;
135 DWORD len;
136 BOOL needs_quote;
138 if(!property_list)
139 return NULL;
141 /* count the space we need */
142 len = 1;
143 for(list = property_list; list; list = list->next)
144 len += lstrlenW(list->str) + 3;
146 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
148 /* add a space before each string, and quote the value */
149 p = ret;
150 for(list = property_list; list; list = list->next)
152 value = strchrW(list->str,'=');
153 if(!value)
154 continue;
155 len = value - list->str;
156 *p++ = ' ';
157 memcpy(p, list->str, len * sizeof(WCHAR));
158 p += len;
159 *p++ = '=';
161 /* check if the value contains spaces and maybe quote it */
162 value++;
163 needs_quote = strchrW(value,' ') ? 1 : 0;
164 if(needs_quote)
165 *p++ = '"';
166 len = lstrlenW(value);
167 memcpy(p, value, len * sizeof(WCHAR));
168 p += len;
169 if(needs_quote)
170 *p++ = '"';
172 *p = 0;
174 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
176 return ret;
179 static LPWSTR build_transforms(struct string_list *transform_list)
181 struct string_list *list;
182 LPWSTR ret, p;
183 DWORD len;
185 /* count the space we need */
186 len = 1;
187 for(list = transform_list; list; list = list->next)
188 len += lstrlenW(list->str) + 1;
190 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
192 /* add all the transforms with a semicolon between each one */
193 p = ret;
194 for(list = transform_list; list; list = list->next)
196 len = lstrlenW(list->str);
197 lstrcpynW(p, list->str, len );
198 p += len;
199 if(list->next)
200 *p++ = ';';
202 *p = 0;
204 return ret;
207 static DWORD msi_atou(LPCWSTR str)
209 DWORD ret = 0;
210 while(*str >= '0' && *str <= '9')
212 ret *= 10;
213 ret += (*str - '0');
214 str++;
216 return ret;
219 static LPWSTR msi_strdup(LPCWSTR str)
221 DWORD len = lstrlenW(str)+1;
222 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
223 lstrcpyW(ret, str);
224 return ret;
227 /* str1 is the same as str2, ignoring case */
228 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
230 DWORD len, ret;
231 LPWSTR strW;
233 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
234 if( !len )
235 return FALSE;
236 if( lstrlenW(str1) != (len-1) )
237 return FALSE;
238 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
239 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
240 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
241 HeapFree(GetProcessHeap(), 0, strW);
242 return (ret == CSTR_EQUAL);
245 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
246 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
248 if (str1[0] != '/' && str1[0] != '-')
249 return FALSE;
251 /* skip over the hyphen or slash */
252 return msi_strequal(str1 + 1, str2);
255 /* str2 is at the beginning of str1, ignoring case */
256 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
258 DWORD len, ret;
259 LPWSTR strW;
261 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
262 if( !len )
263 return FALSE;
264 if( lstrlenW(str1) < (len-1) )
265 return FALSE;
266 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
267 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
268 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
269 HeapFree(GetProcessHeap(), 0, strW);
270 return (ret == CSTR_EQUAL);
273 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
274 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
276 if (str1[0] != '/' && str1[0] != '-')
277 return FALSE;
279 /* skip over the hyphen or slash */
280 return msi_strprefix(str1 + 1, str2);
283 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
285 VOID* (*proc)(void);
287 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
288 if(!*DllHandle)
290 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
291 ExitProcess(1);
293 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
294 if(!proc)
296 fprintf(stderr, "Dll %s does not implement function %s\n",
297 wine_dbgstr_w(DllName), ProcName);
298 FreeLibrary(*DllHandle);
299 ExitProcess(1);
302 return proc;
305 static DWORD DoDllRegisterServer(LPCWSTR DllName)
307 HRESULT hr;
308 DLLREGISTERSERVER pfDllRegisterServer = NULL;
309 HMODULE DllHandle = NULL;
311 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
313 hr = pfDllRegisterServer();
314 if(FAILED(hr))
316 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
317 return 1;
319 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
320 if(DllHandle)
321 FreeLibrary(DllHandle);
322 return 0;
325 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
327 HRESULT hr;
328 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
329 HMODULE DllHandle = NULL;
331 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
333 hr = pfDllUnregisterServer();
334 if(FAILED(hr))
336 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
337 return 1;
339 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
340 if(DllHandle)
341 FreeLibrary(DllHandle);
342 return 0;
345 static DWORD DoRegServer(void)
347 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
348 static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c',' ','/','V',0};
349 SC_HANDLE scm, service;
350 WCHAR path[MAX_PATH+12];
351 DWORD len, ret = 0;
353 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CREATE_SERVICE)))
355 fprintf(stderr, "Failed to open the service control manager.\n");
356 return 1;
358 len = GetSystemDirectoryW(path, MAX_PATH);
359 lstrcpyW(path + len, msiexecW);
360 if ((service = CreateServiceW(scm, msiserverW, msiserverW, GENERIC_ALL,
361 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
362 SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL)))
364 CloseServiceHandle(service);
366 else if (GetLastError() != ERROR_SERVICE_EXISTS)
368 fprintf(stderr, "Failed to create MSI service\n");
369 ret = 1;
371 CloseServiceHandle(scm);
372 return ret;
375 static DWORD DoUnregServer(void)
377 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
378 SC_HANDLE scm, service;
379 DWORD ret = 0;
381 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CONNECT)))
383 fprintf(stderr, "Failed to open service control manager\n");
384 return 1;
386 if ((service = OpenServiceW(scm, msiserverW, DELETE)))
388 if (!DeleteService(service))
390 fprintf(stderr, "Failed to delete MSI service\n");
391 ret = 1;
393 CloseServiceHandle(service);
395 else if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
397 fprintf(stderr, "Failed to open MSI service\n");
398 ret = 1;
400 CloseServiceHandle(scm);
401 return ret;
404 static INT DoEmbedding( LPWSTR key )
406 printf("Remote custom actions are not supported yet\n");
407 return 1;
411 * state machine to break up the command line properly
414 enum chomp_state
416 cs_whitespace,
417 cs_token,
418 cs_quote
421 static int chomp( WCHAR *str )
423 enum chomp_state state = cs_token;
424 WCHAR *p, *out;
425 int count = 1;
426 BOOL ignore;
428 for( p = str, out = str; *p; p++ )
430 ignore = TRUE;
431 switch( state )
433 case cs_whitespace:
434 switch( *p )
436 case ' ':
437 break;
438 case '"':
439 state = cs_quote;
440 count++;
441 break;
442 default:
443 count++;
444 ignore = FALSE;
445 state = cs_token;
447 break;
449 case cs_token:
450 switch( *p )
452 case '"':
453 state = cs_quote;
454 break;
455 case ' ':
456 state = cs_whitespace;
457 *out++ = 0;
458 break;
459 default:
460 ignore = FALSE;
462 break;
464 case cs_quote:
465 switch( *p )
467 case '"':
468 state = cs_token;
469 break;
470 default:
471 ignore = FALSE;
473 break;
475 if( !ignore )
476 *out++ = *p;
479 *out = 0;
481 return count;
484 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
486 WCHAR **argv, *p = msi_strdup(cmdline);
487 int i, n;
489 n = chomp( p );
490 argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
491 for( i=0; i<n; i++ )
493 argv[i] = p;
494 p += lstrlenW(p) + 1;
496 argv[i] = NULL;
498 *pargc = n;
499 *pargv = argv;
502 static BOOL process_args_from_reg( const WCHAR *ident, int *pargc, WCHAR ***pargv )
504 LONG r;
505 HKEY hkey;
506 DWORD sz = 0, type = 0;
507 WCHAR *buf;
508 BOOL ret = FALSE;
510 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
511 if(r != ERROR_SUCCESS)
512 return FALSE;
513 r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
514 if(r == ERROR_SUCCESS && type == REG_SZ)
516 int len = lstrlenW( *pargv[0] );
517 if (!(buf = HeapAlloc( GetProcessHeap(), 0, sz + (len + 1) * sizeof(WCHAR) )))
519 RegCloseKey( hkey );
520 return FALSE;
522 memcpy( buf, *pargv[0], len * sizeof(WCHAR) );
523 buf[len++] = ' ';
524 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)(buf + len), &sz);
525 if( r == ERROR_SUCCESS )
527 process_args(buf, pargc, pargv);
528 ret = TRUE;
530 HeapFree(GetProcessHeap(), 0, buf);
532 RegCloseKey(hkey);
533 return ret;
536 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
538 int i;
539 BOOL FunctionInstall = FALSE;
540 BOOL FunctionInstallAdmin = FALSE;
541 BOOL FunctionRepair = FALSE;
542 BOOL FunctionAdvertise = FALSE;
543 BOOL FunctionPatch = FALSE;
544 BOOL FunctionDllRegisterServer = FALSE;
545 BOOL FunctionDllUnregisterServer = FALSE;
546 BOOL FunctionRegServer = FALSE;
547 BOOL FunctionUnregServer = FALSE;
548 BOOL FunctionServer = FALSE;
549 BOOL FunctionUnknown = FALSE;
551 LPWSTR PackageName = NULL;
552 LPWSTR Properties = NULL;
553 struct string_list *property_list = NULL;
555 DWORD RepairMode = 0;
557 DWORD_PTR AdvertiseMode = 0;
558 struct string_list *transform_list = NULL;
559 LANGID Language = 0;
561 DWORD LogMode = 0;
562 LPWSTR LogFileName = NULL;
563 DWORD LogAttributes = 0;
565 LPWSTR PatchFileName = NULL;
566 INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
568 INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
570 LPWSTR DllName = NULL;
571 DWORD ReturnCode;
572 int argc;
573 LPWSTR *argvW = NULL;
575 /* parse the command line */
576 process_args( GetCommandLineW(), &argc, &argvW );
579 * If the args begin with /@ IDENT then we need to load the real
580 * command line out of the RunOnceEntries key in the registry.
581 * We do that before starting to process the real commandline,
582 * then overwrite the commandline again.
584 if(argc>1 && msi_option_equal(argvW[1], "@"))
586 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
587 return 1;
590 if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
591 return DoEmbedding( argvW[2] );
593 for(i = 1; i < argc; i++)
595 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
597 if (msi_option_equal(argvW[i], "regserver"))
599 FunctionRegServer = TRUE;
601 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister")
602 || msi_option_equal(argvW[i], "unreg"))
604 FunctionUnregServer = TRUE;
606 else if(msi_option_prefix(argvW[i], "i") || msi_option_prefix(argvW[i], "package"))
608 LPWSTR argvWi = argvW[i];
609 int argLen = (msi_option_prefix(argvW[i], "i") ? 2 : 8);
610 FunctionInstall = TRUE;
611 if(lstrlenW(argvW[i]) > argLen)
612 argvWi += argLen;
613 else
615 i++;
616 if(i >= argc)
617 ShowUsage(1);
618 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
619 argvWi = argvW[i];
621 PackageName = argvWi;
623 else if(msi_option_equal(argvW[i], "a"))
625 FunctionInstall = TRUE;
626 FunctionInstallAdmin = TRUE;
627 InstallType = INSTALLTYPE_NETWORK_IMAGE;
628 i++;
629 if(i >= argc)
630 ShowUsage(1);
631 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
632 PackageName = argvW[i];
633 StringListAppend(&property_list, ActionAdmin);
634 WINE_FIXME("Administrative installs are not currently supported\n");
636 else if(msi_option_prefix(argvW[i], "f"))
638 int j;
639 int len = lstrlenW(argvW[i]);
640 FunctionRepair = TRUE;
641 for(j = 2; j < len; j++)
643 switch(argvW[i][j])
645 case 'P':
646 case 'p':
647 RepairMode |= REINSTALLMODE_FILEMISSING;
648 break;
649 case 'O':
650 case 'o':
651 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
652 break;
653 case 'E':
654 case 'e':
655 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
656 break;
657 case 'D':
658 case 'd':
659 RepairMode |= REINSTALLMODE_FILEEXACT;
660 break;
661 case 'C':
662 case 'c':
663 RepairMode |= REINSTALLMODE_FILEVERIFY;
664 break;
665 case 'A':
666 case 'a':
667 RepairMode |= REINSTALLMODE_FILEREPLACE;
668 break;
669 case 'U':
670 case 'u':
671 RepairMode |= REINSTALLMODE_USERDATA;
672 break;
673 case 'M':
674 case 'm':
675 RepairMode |= REINSTALLMODE_MACHINEDATA;
676 break;
677 case 'S':
678 case 's':
679 RepairMode |= REINSTALLMODE_SHORTCUT;
680 break;
681 case 'V':
682 case 'v':
683 RepairMode |= REINSTALLMODE_PACKAGE;
684 break;
685 default:
686 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
687 break;
690 if(len == 2)
692 RepairMode = REINSTALLMODE_FILEMISSING |
693 REINSTALLMODE_FILEEQUALVERSION |
694 REINSTALLMODE_FILEVERIFY |
695 REINSTALLMODE_MACHINEDATA |
696 REINSTALLMODE_SHORTCUT;
698 i++;
699 if(i >= argc)
700 ShowUsage(1);
701 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
702 PackageName = argvW[i];
704 else if(msi_option_prefix(argvW[i], "x") || msi_option_equal(argvW[i], "uninstall"))
706 FunctionInstall = TRUE;
707 if(msi_option_prefix(argvW[i], "x")) PackageName = argvW[i]+2;
708 if(!PackageName || !PackageName[0])
710 i++;
711 if (i >= argc)
712 ShowUsage(1);
713 PackageName = argvW[i];
715 WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
716 StringListAppend(&property_list, RemoveAll);
718 else if(msi_option_prefix(argvW[i], "j"))
720 int j;
721 int len = lstrlenW(argvW[i]);
722 FunctionAdvertise = TRUE;
723 for(j = 2; j < len; j++)
725 switch(argvW[i][j])
727 case 'U':
728 case 'u':
729 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
730 break;
731 case 'M':
732 case 'm':
733 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
734 break;
735 default:
736 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
737 break;
740 i++;
741 if(i >= argc)
742 ShowUsage(1);
743 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
744 PackageName = argvW[i];
746 else if(msi_strequal(argvW[i], "u"))
748 FunctionAdvertise = TRUE;
749 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
750 i++;
751 if(i >= argc)
752 ShowUsage(1);
753 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
754 PackageName = argvW[i];
756 else if(msi_strequal(argvW[i], "m"))
758 FunctionAdvertise = TRUE;
759 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
760 i++;
761 if(i >= argc)
762 ShowUsage(1);
763 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
764 PackageName = argvW[i];
766 else if(msi_option_equal(argvW[i], "t"))
768 i++;
769 if(i >= argc)
770 ShowUsage(1);
771 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
772 StringListAppend(&transform_list, argvW[i]);
774 else if(msi_option_equal(argvW[i], "g"))
776 i++;
777 if(i >= argc)
778 ShowUsage(1);
779 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
780 Language = msi_atou(argvW[i]);
782 else if(msi_option_prefix(argvW[i], "l"))
784 int j;
785 int len = lstrlenW(argvW[i]);
786 for(j = 2; j < len; j++)
788 switch(argvW[i][j])
790 case 'I':
791 case 'i':
792 LogMode |= INSTALLLOGMODE_INFO;
793 break;
794 case 'W':
795 case 'w':
796 LogMode |= INSTALLLOGMODE_WARNING;
797 break;
798 case 'E':
799 case 'e':
800 LogMode |= INSTALLLOGMODE_ERROR;
801 break;
802 case 'A':
803 case 'a':
804 LogMode |= INSTALLLOGMODE_ACTIONSTART;
805 break;
806 case 'R':
807 case 'r':
808 LogMode |= INSTALLLOGMODE_ACTIONDATA;
809 break;
810 case 'U':
811 case 'u':
812 LogMode |= INSTALLLOGMODE_USER;
813 break;
814 case 'C':
815 case 'c':
816 LogMode |= INSTALLLOGMODE_COMMONDATA;
817 break;
818 case 'M':
819 case 'm':
820 LogMode |= INSTALLLOGMODE_FATALEXIT;
821 break;
822 case 'O':
823 case 'o':
824 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
825 break;
826 case 'P':
827 case 'p':
828 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
829 break;
830 case 'V':
831 case 'v':
832 LogMode |= INSTALLLOGMODE_VERBOSE;
833 break;
834 case '*':
835 LogMode = INSTALLLOGMODE_FATALEXIT |
836 INSTALLLOGMODE_ERROR |
837 INSTALLLOGMODE_WARNING |
838 INSTALLLOGMODE_USER |
839 INSTALLLOGMODE_INFO |
840 INSTALLLOGMODE_RESOLVESOURCE |
841 INSTALLLOGMODE_OUTOFDISKSPACE |
842 INSTALLLOGMODE_ACTIONSTART |
843 INSTALLLOGMODE_ACTIONDATA |
844 INSTALLLOGMODE_COMMONDATA |
845 INSTALLLOGMODE_PROPERTYDUMP |
846 INSTALLLOGMODE_PROGRESS |
847 INSTALLLOGMODE_INITIALIZE |
848 INSTALLLOGMODE_TERMINATE |
849 INSTALLLOGMODE_SHOWDIALOG;
850 break;
851 case '+':
852 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
853 break;
854 case '!':
855 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
856 break;
857 default:
858 break;
861 i++;
862 if(i >= argc)
863 ShowUsage(1);
864 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
865 LogFileName = argvW[i];
866 if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
868 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
869 wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
870 ExitProcess(1);
873 else if(msi_option_equal(argvW[i], "p"))
875 FunctionPatch = TRUE;
876 i++;
877 if(i >= argc)
878 ShowUsage(1);
879 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
880 PatchFileName = argvW[i];
882 else if(msi_option_prefix(argvW[i], "q"))
884 if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
885 msi_strequal(argvW[i] + 2, "uiet"))
887 InstallUILevel = INSTALLUILEVEL_NONE;
889 else if(msi_strequal(argvW[i]+2, "b"))
891 InstallUILevel = INSTALLUILEVEL_BASIC;
893 else if(msi_strequal(argvW[i]+2, "r"))
895 InstallUILevel = INSTALLUILEVEL_REDUCED;
897 else if(msi_strequal(argvW[i]+2, "f"))
899 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
901 else if(msi_strequal(argvW[i]+2, "n+"))
903 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
905 else if(msi_strequal(argvW[i]+2, "b+"))
907 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
909 else if(msi_strequal(argvW[i]+2, "b-"))
911 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
913 else if(msi_strequal(argvW[i]+2, "b+!"))
915 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
916 WINE_FIXME("Unknown modifier: !\n");
918 else if(msi_strequal(argvW[i]+2, "b!"))
920 InstallUILevel = INSTALLUILEVEL_BASIC;
921 WINE_FIXME("Unknown modifier: !\n");
923 else
925 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
926 wine_dbgstr_w(argvW[i]+2));
929 else if(msi_option_equal(argvW[i], "y"))
931 FunctionDllRegisterServer = TRUE;
932 i++;
933 if(i >= argc)
934 ShowUsage(1);
935 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
936 DllName = argvW[i];
938 else if(msi_option_equal(argvW[i], "z"))
940 FunctionDllUnregisterServer = TRUE;
941 i++;
942 if(i >= argc)
943 ShowUsage(1);
944 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
945 DllName = argvW[i];
947 else if(msi_option_equal(argvW[i], "help") || msi_option_equal(argvW[i], "?"))
949 ShowUsage(0);
951 else if(msi_option_equal(argvW[i], "m"))
953 FunctionUnknown = TRUE;
954 WINE_FIXME("Unknown parameter /m\n");
956 else if(msi_option_equal(argvW[i], "D"))
958 FunctionUnknown = TRUE;
959 WINE_FIXME("Unknown parameter /D\n");
961 else if (msi_option_equal(argvW[i], "V"))
963 FunctionServer = TRUE;
965 else
966 StringListAppend(&property_list, argvW[i]);
969 /* start the GUI */
970 MsiSetInternalUI(InstallUILevel, NULL);
972 Properties = build_properties( property_list );
974 if(FunctionInstallAdmin && FunctionPatch)
975 FunctionInstall = FALSE;
977 ReturnCode = 1;
978 if(FunctionInstall)
980 if(IsProductCode(PackageName))
981 ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
982 else
983 ReturnCode = MsiInstallProductW(PackageName, Properties);
985 else if(FunctionRepair)
987 if(IsProductCode(PackageName))
988 WINE_FIXME("Product code treatment not implemented yet\n");
989 else
990 ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
992 else if(FunctionAdvertise)
994 LPWSTR Transforms = build_transforms( property_list );
995 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
997 else if(FunctionPatch)
999 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
1001 else if(FunctionDllRegisterServer)
1003 ReturnCode = DoDllRegisterServer(DllName);
1005 else if(FunctionDllUnregisterServer)
1007 ReturnCode = DoDllUnregisterServer(DllName);
1009 else if (FunctionRegServer)
1011 ReturnCode = DoRegServer();
1013 else if (FunctionUnregServer)
1015 ReturnCode = DoUnregServer();
1017 else if (FunctionServer)
1019 ReturnCode = DoService();
1021 else if (FunctionUnknown)
1023 WINE_FIXME( "Unknown function, ignoring\n" );
1025 else
1026 ShowUsage(1);
1028 return ReturnCode;