gdi32: Don't hold the gdi lock while creating a DC.
[wine/multimedia.git] / programs / msiexec / msiexec.c
blob71e81c89add90e1ab67c816b5ab6898239c86676
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 char UsageStr[] =
46 "Usage:\n"
47 " Install a product:\n"
48 " msiexec {package|productcode} [property]\n"
49 " msiexec /i {package|productcode} [property]\n"
50 " msiexec /a package [property]\n"
51 " Repair an installation:\n"
52 " msiexec /f[p|o|e|d|c|a|u|m|s|v] {package|productcode}\n"
53 " Uninstall a product:\n"
54 " msiexec /x {package|productcode} [property]\n"
55 " Advertise a product:\n"
56 " msiexec /j[u|m] package [/t transform] [/g languageid]\n"
57 " msiexec {u|m} package [/t transform] [/g languageid]\n"
58 " Apply a patch:\n"
59 " msiexec /p patchpackage [property]\n"
60 " msiexec /p patchpackage /a package [property]\n"
61 " Modifiers for above operations:\n"
62 " msiexec /l[*][i|w|e|a|r|u|c|m|o|p|v|][+|!] logfile\n"
63 " msiexec /q{|n|b|r|f|n+|b+|b-}\n"
64 " Register a module:\n"
65 " msiexec /y module\n"
66 " Unregister a module:\n"
67 " msiexec /z module\n"
68 " Display usage and copyright:\n"
69 " msiexec {/h|/?}\n"
70 "NOTE: Product code on commandline unimplemented as of yet\n"
71 "\n"
72 "Copyright 2004 Vincent Béron\n";
74 static const WCHAR ActionAdmin[] = {
75 'A','C','T','I','O','N','=','A','D','M','I','N',0 };
76 static const WCHAR RemoveAll[] = {
77 'R','E','M','O','V','E','=','A','L','L',0 };
79 static const WCHAR InstallRunOnce[] = {
80 'S','o','f','t','w','a','r','e','\\',
81 'M','i','c','r','o','s','o','f','t','\\',
82 'W','i','n','d','o','w','s','\\',
83 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
84 'I','n','s','t','a','l','l','e','r','\\',
85 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
87 static void ShowUsage(int ExitCode)
89 printf(UsageStr);
90 ExitProcess(ExitCode);
93 static BOOL IsProductCode(LPWSTR str)
95 GUID ProductCode;
97 if(lstrlenW(str) != 38)
98 return FALSE;
99 return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
103 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
105 struct string_list *entry;
106 DWORD size;
108 size = sizeof *entry + lstrlenW(str) * sizeof (WCHAR);
109 entry = HeapAlloc(GetProcessHeap(), 0, size);
110 if(!entry)
112 WINE_ERR("Out of memory!\n");
113 ExitProcess(1);
115 lstrcpyW(entry->str, str);
116 entry->next = NULL;
119 * Ignoring o(n^2) time complexity to add n strings for simplicity,
120 * add the string to the end of the list to preserve the order.
122 while( *list )
123 list = &(*list)->next;
124 *list = entry;
127 static LPWSTR build_properties(struct string_list *property_list)
129 struct string_list *list;
130 LPWSTR ret, p, value;
131 DWORD len;
132 BOOL needs_quote;
134 if(!property_list)
135 return NULL;
137 /* count the space we need */
138 len = 1;
139 for(list = property_list; list; list = list->next)
140 len += lstrlenW(list->str) + 3;
142 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
144 /* add a space before each string, and quote the value */
145 p = ret;
146 for(list = property_list; list; list = list->next)
148 value = strchrW(list->str,'=');
149 if(!value)
150 continue;
151 len = value - list->str;
152 *p++ = ' ';
153 memcpy(p, list->str, len * sizeof(WCHAR));
154 p += len;
155 *p++ = '=';
157 /* check if the value contains spaces and maybe quote it */
158 value++;
159 needs_quote = strchrW(value,' ') ? 1 : 0;
160 if(needs_quote)
161 *p++ = '"';
162 len = lstrlenW(value);
163 memcpy(p, value, len * sizeof(WCHAR));
164 p += len;
165 if(needs_quote)
166 *p++ = '"';
168 *p = 0;
170 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
172 return ret;
175 static LPWSTR build_transforms(struct string_list *transform_list)
177 struct string_list *list;
178 LPWSTR ret, p;
179 DWORD len;
181 /* count the space we need */
182 len = 1;
183 for(list = transform_list; list; list = list->next)
184 len += lstrlenW(list->str) + 1;
186 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
188 /* add all the transforms with a semicolon between each one */
189 p = ret;
190 for(list = transform_list; list; list = list->next)
192 len = lstrlenW(list->str);
193 lstrcpynW(p, list->str, len );
194 p += len;
195 if(list->next)
196 *p++ = ';';
198 *p = 0;
200 return ret;
203 static DWORD msi_atou(LPCWSTR str)
205 DWORD ret = 0;
206 while(*str >= '0' && *str <= '9')
208 ret *= 10;
209 ret += (*str - '0');
210 str++;
212 return 0;
215 static LPWSTR msi_strdup(LPCWSTR str)
217 DWORD len = lstrlenW(str)+1;
218 LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
219 lstrcpyW(ret, str);
220 return ret;
223 /* str1 is the same as str2, ignoring case */
224 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
226 DWORD len, ret;
227 LPWSTR strW;
229 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
230 if( !len )
231 return FALSE;
232 if( lstrlenW(str1) != (len-1) )
233 return FALSE;
234 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
235 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
236 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
237 HeapFree(GetProcessHeap(), 0, strW);
238 return (ret == CSTR_EQUAL);
241 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
242 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
244 if (str1[0] != '/' && str1[0] != '-')
245 return FALSE;
247 /* skip over the hyphen or slash */
248 return msi_strequal(str1 + 1, str2);
251 /* str2 is at the beginning of str1, ignoring case */
252 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
254 DWORD len, ret;
255 LPWSTR strW;
257 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
258 if( !len )
259 return FALSE;
260 if( lstrlenW(str1) < (len-1) )
261 return FALSE;
262 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
263 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
264 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
265 HeapFree(GetProcessHeap(), 0, strW);
266 return (ret == CSTR_EQUAL);
269 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
270 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
272 if (str1[0] != '/' && str1[0] != '-')
273 return FALSE;
275 /* skip over the hyphen or slash */
276 return msi_strprefix(str1 + 1, str2);
279 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
281 VOID* (*proc)(void);
283 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
284 if(!*DllHandle)
286 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
287 ExitProcess(1);
289 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
290 if(!proc)
292 fprintf(stderr, "Dll %s does not implement function %s\n",
293 wine_dbgstr_w(DllName), ProcName);
294 FreeLibrary(*DllHandle);
295 ExitProcess(1);
298 return proc;
301 static DWORD DoDllRegisterServer(LPCWSTR DllName)
303 HRESULT hr;
304 DLLREGISTERSERVER pfDllRegisterServer = NULL;
305 HMODULE DllHandle = NULL;
307 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
309 hr = pfDllRegisterServer();
310 if(FAILED(hr))
312 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
313 return 1;
315 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
316 if(DllHandle)
317 FreeLibrary(DllHandle);
318 return 0;
321 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
323 HRESULT hr;
324 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
325 HMODULE DllHandle = NULL;
327 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
329 hr = pfDllUnregisterServer();
330 if(FAILED(hr))
332 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
333 return 1;
335 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
336 if(DllHandle)
337 FreeLibrary(DllHandle);
338 return 0;
341 static DWORD DoRegServer(void)
343 SC_HANDLE scm, service;
344 CHAR path[MAX_PATH+12];
345 DWORD ret = 0;
347 scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE);
348 if (!scm)
350 fprintf(stderr, "Failed to open the service control manager.\n");
351 return 1;
354 GetSystemDirectory(path, MAX_PATH);
355 lstrcatA(path, "\\msiexec.exe /V");
357 service = CreateServiceA(scm, "MSIServer", "MSIServer", GENERIC_ALL,
358 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
359 SERVICE_ERROR_NORMAL, path, NULL, NULL,
360 NULL, NULL, NULL);
362 if (service) CloseServiceHandle(service);
363 else if (GetLastError() != ERROR_SERVICE_EXISTS)
365 fprintf(stderr, "Failed to create MSI service\n");
366 ret = 1;
368 CloseServiceHandle(scm);
369 return ret;
372 static INT DoEmbedding( LPWSTR key )
374 printf("Remote custom actions are not supported yet\n");
375 return 1;
379 * state machine to break up the command line properly
382 enum chomp_state
384 cs_whitespace,
385 cs_token,
386 cs_quote
389 static int chomp( WCHAR *str )
391 enum chomp_state state = cs_whitespace;
392 WCHAR *p, *out;
393 int count = 0, ignore;
395 for( p = str, out = str; *p; p++ )
397 ignore = 1;
398 switch( state )
400 case cs_whitespace:
401 switch( *p )
403 case ' ':
404 break;
405 case '"':
406 state = cs_quote;
407 count++;
408 break;
409 default:
410 count++;
411 ignore = 0;
412 state = cs_token;
414 break;
416 case cs_token:
417 switch( *p )
419 case '"':
420 state = cs_quote;
421 break;
422 case ' ':
423 state = cs_whitespace;
424 *out++ = 0;
425 break;
426 default:
427 ignore = 0;
429 break;
431 case cs_quote:
432 switch( *p )
434 case '"':
435 state = cs_token;
436 break;
437 default:
438 ignore = 0;
440 break;
442 if( !ignore )
443 *out++ = *p;
446 *out = 0;
448 return count;
451 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
453 WCHAR **argv, *p = msi_strdup(cmdline);
454 int i, n;
456 n = chomp( p );
457 argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
458 for( i=0; i<n; i++ )
460 argv[i] = p;
461 p += lstrlenW(p) + 1;
463 argv[i] = NULL;
465 *pargc = n;
466 *pargv = argv;
469 static BOOL process_args_from_reg( LPWSTR ident, int *pargc, WCHAR ***pargv )
471 LONG r;
472 HKEY hkey = 0, hkeyArgs = 0;
473 DWORD sz = 0, type = 0;
474 LPWSTR buf = NULL;
475 BOOL ret = FALSE;
477 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
478 if(r != ERROR_SUCCESS)
479 return FALSE;
480 r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
481 if(r == ERROR_SUCCESS && type == REG_SZ)
483 buf = HeapAlloc(GetProcessHeap(), 0, sz);
484 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)buf, &sz);
485 if( r == ERROR_SUCCESS )
487 process_args(buf, pargc, pargv);
488 ret = TRUE;
491 RegCloseKey(hkeyArgs);
492 return ret;
495 int main(int argc, char **argv)
497 int i;
498 BOOL FunctionInstall = FALSE;
499 BOOL FunctionInstallAdmin = FALSE;
500 BOOL FunctionRepair = FALSE;
501 BOOL FunctionAdvertise = FALSE;
502 BOOL FunctionPatch = FALSE;
503 BOOL FunctionDllRegisterServer = FALSE;
504 BOOL FunctionDllUnregisterServer = FALSE;
505 BOOL FunctionRegServer = FALSE;
506 BOOL FunctionUnregServer = FALSE;
507 BOOL FunctionServer = FALSE;
508 BOOL FunctionUnknown = FALSE;
510 LPWSTR PackageName = NULL;
511 LPWSTR Properties = NULL;
512 struct string_list *property_list = NULL;
514 DWORD RepairMode = 0;
516 DWORD_PTR AdvertiseMode = 0;
517 struct string_list *transform_list = NULL;
518 LANGID Language = 0;
520 DWORD LogMode = 0;
521 LPWSTR LogFileName = NULL;
522 DWORD LogAttributes = 0;
524 LPWSTR PatchFileName = NULL;
525 INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
527 INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
529 LPWSTR DllName = NULL;
530 DWORD ReturnCode;
531 LPWSTR *argvW = NULL;
533 /* overwrite the command line */
534 process_args( GetCommandLineW(), &argc, &argvW );
537 * If the args begin with /@ IDENT then we need to load the real
538 * command line out of the RunOnceEntries key in the registry.
539 * We do that before starting to process the real commandline,
540 * then overwrite the commandline again.
542 if(argc>1 && msi_option_equal(argvW[1], "@"))
544 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
545 return 1;
548 if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
549 return DoEmbedding( argvW[2] );
551 for(i = 1; i < argc; i++)
553 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
555 if (msi_option_equal(argvW[i], "regserver"))
557 FunctionRegServer = TRUE;
559 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister"))
561 FunctionUnregServer = TRUE;
563 else if(msi_option_prefix(argvW[i], "i"))
565 LPWSTR argvWi = argvW[i];
566 FunctionInstall = TRUE;
567 if(lstrlenW(argvWi) > 2)
568 argvWi += 2;
569 else
571 i++;
572 if(i >= argc)
573 ShowUsage(1);
574 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
575 argvWi = argvW[i];
577 PackageName = argvWi;
579 else if(msi_option_equal(argvW[i], "a"))
581 FunctionInstall = TRUE;
582 FunctionInstallAdmin = TRUE;
583 InstallType = INSTALLTYPE_NETWORK_IMAGE;
584 i++;
585 if(i >= argc)
586 ShowUsage(1);
587 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
588 PackageName = argvW[i];
589 StringListAppend(&property_list, ActionAdmin);
591 else if(msi_option_prefix(argvW[i], "f"))
593 int j;
594 int len = lstrlenW(argvW[i]);
595 FunctionRepair = TRUE;
596 for(j = 2; j < len; j++)
598 switch(argvW[i][j])
600 case 'P':
601 case 'p':
602 RepairMode |= REINSTALLMODE_FILEMISSING;
603 break;
604 case 'O':
605 case 'o':
606 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
607 break;
608 case 'E':
609 case 'e':
610 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
611 break;
612 case 'D':
613 case 'd':
614 RepairMode |= REINSTALLMODE_FILEEXACT;
615 break;
616 case 'C':
617 case 'c':
618 RepairMode |= REINSTALLMODE_FILEVERIFY;
619 break;
620 case 'A':
621 case 'a':
622 RepairMode |= REINSTALLMODE_FILEREPLACE;
623 break;
624 case 'U':
625 case 'u':
626 RepairMode |= REINSTALLMODE_USERDATA;
627 break;
628 case 'M':
629 case 'm':
630 RepairMode |= REINSTALLMODE_MACHINEDATA;
631 break;
632 case 'S':
633 case 's':
634 RepairMode |= REINSTALLMODE_SHORTCUT;
635 break;
636 case 'V':
637 case 'v':
638 RepairMode |= REINSTALLMODE_PACKAGE;
639 break;
640 default:
641 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
642 break;
645 if(len == 2)
647 RepairMode = REINSTALLMODE_FILEMISSING |
648 REINSTALLMODE_FILEEQUALVERSION |
649 REINSTALLMODE_FILEVERIFY |
650 REINSTALLMODE_MACHINEDATA |
651 REINSTALLMODE_SHORTCUT;
653 i++;
654 if(i >= argc)
655 ShowUsage(1);
656 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
657 PackageName = argvW[i];
659 else if(msi_option_prefix(argvW[i], "x"))
661 FunctionInstall = TRUE;
662 PackageName = argvW[i]+2;
663 if (!PackageName[0])
665 i++;
666 if (i >= argc)
667 ShowUsage(1);
668 PackageName = argvW[i];
670 WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
671 StringListAppend(&property_list, RemoveAll);
673 else if(msi_option_prefix(argvW[i], "j"))
675 int j;
676 int len = lstrlenW(argvW[i]);
677 FunctionAdvertise = TRUE;
678 for(j = 2; j < len; j++)
680 switch(argvW[i][j])
682 case 'U':
683 case 'u':
684 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
685 break;
686 case 'M':
687 case 'm':
688 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
689 break;
690 default:
691 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
692 break;
695 i++;
696 if(i >= argc)
697 ShowUsage(1);
698 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
699 PackageName = argvW[i];
701 else if(msi_strequal(argvW[i], "u"))
703 FunctionAdvertise = TRUE;
704 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
705 i++;
706 if(i >= argc)
707 ShowUsage(1);
708 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
709 PackageName = argvW[i];
711 else if(msi_strequal(argvW[i], "m"))
713 FunctionAdvertise = TRUE;
714 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
715 i++;
716 if(i >= argc)
717 ShowUsage(1);
718 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
719 PackageName = argvW[i];
721 else if(msi_option_equal(argvW[i], "t"))
723 i++;
724 if(i >= argc)
725 ShowUsage(1);
726 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
727 StringListAppend(&transform_list, argvW[i]);
729 else if(msi_option_equal(argvW[i], "g"))
731 i++;
732 if(i >= argc)
733 ShowUsage(1);
734 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
735 Language = msi_atou(argvW[i]);
737 else if(msi_option_prefix(argvW[i], "l"))
739 int j;
740 int len = lstrlenW(argvW[i]);
741 for(j = 2; j < len; j++)
743 switch(argvW[i][j])
745 case 'I':
746 case 'i':
747 LogMode |= INSTALLLOGMODE_INFO;
748 break;
749 case 'W':
750 case 'w':
751 LogMode |= INSTALLLOGMODE_WARNING;
752 break;
753 case 'E':
754 case 'e':
755 LogMode |= INSTALLLOGMODE_ERROR;
756 break;
757 case 'A':
758 case 'a':
759 LogMode |= INSTALLLOGMODE_ACTIONSTART;
760 break;
761 case 'R':
762 case 'r':
763 LogMode |= INSTALLLOGMODE_ACTIONDATA;
764 break;
765 case 'U':
766 case 'u':
767 LogMode |= INSTALLLOGMODE_USER;
768 break;
769 case 'C':
770 case 'c':
771 LogMode |= INSTALLLOGMODE_COMMONDATA;
772 break;
773 case 'M':
774 case 'm':
775 LogMode |= INSTALLLOGMODE_FATALEXIT;
776 break;
777 case 'O':
778 case 'o':
779 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
780 break;
781 case 'P':
782 case 'p':
783 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
784 break;
785 case 'V':
786 case 'v':
787 LogMode |= INSTALLLOGMODE_VERBOSE;
788 break;
789 case '*':
790 LogMode = INSTALLLOGMODE_FATALEXIT |
791 INSTALLLOGMODE_ERROR |
792 INSTALLLOGMODE_WARNING |
793 INSTALLLOGMODE_USER |
794 INSTALLLOGMODE_INFO |
795 INSTALLLOGMODE_RESOLVESOURCE |
796 INSTALLLOGMODE_OUTOFDISKSPACE |
797 INSTALLLOGMODE_ACTIONSTART |
798 INSTALLLOGMODE_ACTIONDATA |
799 INSTALLLOGMODE_COMMONDATA |
800 INSTALLLOGMODE_PROPERTYDUMP |
801 INSTALLLOGMODE_PROGRESS |
802 INSTALLLOGMODE_INITIALIZE |
803 INSTALLLOGMODE_TERMINATE |
804 INSTALLLOGMODE_SHOWDIALOG;
805 break;
806 case '+':
807 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
808 break;
809 case '!':
810 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
811 break;
812 default:
813 break;
816 i++;
817 if(i >= argc)
818 ShowUsage(1);
819 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
820 LogFileName = argvW[i];
821 if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
823 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
824 wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
825 ExitProcess(1);
828 else if(msi_option_equal(argvW[i], "p"))
830 FunctionPatch = TRUE;
831 i++;
832 if(i >= argc)
833 ShowUsage(1);
834 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
835 PatchFileName = argvW[i];
837 else if(msi_option_prefix(argvW[i], "q"))
839 if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
840 msi_strequal(argvW[i] + 2, "uiet"))
842 InstallUILevel = INSTALLUILEVEL_NONE;
844 else if(msi_strequal(argvW[i]+2, "b"))
846 InstallUILevel = INSTALLUILEVEL_BASIC;
848 else if(msi_strequal(argvW[i]+2, "r"))
850 InstallUILevel = INSTALLUILEVEL_REDUCED;
852 else if(msi_strequal(argvW[i]+2, "f"))
854 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
856 else if(msi_strequal(argvW[i]+2, "n+"))
858 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
860 else if(msi_strequal(argvW[i]+2, "b+"))
862 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
864 else if(msi_strequal(argvW[i]+2, "b-"))
866 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
868 else if(msi_strequal(argvW[i]+2, "b+!"))
870 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
871 WINE_FIXME("Unknown modifier: !\n");
873 else
875 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
876 wine_dbgstr_w(argvW[i]+2));
879 else if(msi_option_equal(argvW[i], "y"))
881 FunctionDllRegisterServer = TRUE;
882 i++;
883 if(i >= argc)
884 ShowUsage(1);
885 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
886 DllName = argvW[i];
888 else if(msi_option_equal(argvW[i], "z"))
890 FunctionDllUnregisterServer = TRUE;
891 i++;
892 if(i >= argc)
893 ShowUsage(1);
894 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
895 DllName = argvW[i];
897 else if(msi_option_equal(argvW[i], "h") || msi_option_equal(argvW[i], "?"))
899 ShowUsage(0);
901 else if(msi_option_equal(argvW[i], "m"))
903 FunctionUnknown = TRUE;
904 WINE_FIXME("Unknown parameter /m\n");
906 else if(msi_option_equal(argvW[i], "D"))
908 FunctionUnknown = TRUE;
909 WINE_FIXME("Unknown parameter /D\n");
911 else if (msi_option_equal(argvW[i], "V"))
913 FunctionServer = TRUE;
915 else
916 StringListAppend(&property_list, argvW[i]);
919 /* start the GUI */
920 MsiSetInternalUI(InstallUILevel, NULL);
922 Properties = build_properties( property_list );
924 if(FunctionInstallAdmin && FunctionPatch)
925 FunctionInstall = FALSE;
927 ReturnCode = 1;
928 if(FunctionInstall)
930 if(IsProductCode(PackageName))
931 ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
932 else
933 ReturnCode = MsiInstallProductW(PackageName, Properties);
935 else if(FunctionRepair)
937 if(IsProductCode(PackageName))
938 WINE_FIXME("Product code treatment not implemented yet\n");
939 else
940 ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
942 else if(FunctionAdvertise)
944 LPWSTR Transforms = build_transforms( property_list );
945 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
947 else if(FunctionPatch)
949 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
951 else if(FunctionDllRegisterServer)
953 ReturnCode = DoDllRegisterServer(DllName);
955 else if(FunctionDllUnregisterServer)
957 ReturnCode = DoDllUnregisterServer(DllName);
959 else if (FunctionRegServer)
961 ReturnCode = DoRegServer();
963 else if (FunctionUnregServer)
965 WINE_FIXME( "/unregserver not implemented yet, ignoring\n" );
967 else if (FunctionServer)
969 ReturnCode = DoService();
971 else if (FunctionUnknown)
973 WINE_FIXME( "Unknown function, ignoring\n" );
975 else
976 ShowUsage(1);
978 return ReturnCode;