dbghelp: Make dwarf2 parser only report file numbers when at least one compilation...
[wine] / programs / msiexec / msiexec.c
1 /*
2  * msiexec.exe implementation
3  *
4  * Copyright 2004 Vincent Béron
5  * Copyright 2005 Mike McCormack
6  *
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.
11  *
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.
16  *
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
20  */
21
22 #define WIN32_LEAN_AND_MEAN
23
24 #include <windows.h>
25 #include <msi.h>
26 #include <objbase.h>
27 #include <stdio.h>
28 #include <shellapi.h>
29
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
34
35 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
36 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
37
38 struct string_list
39 {
40         struct string_list *next;
41         WCHAR str[1];
42 };
43
44 static const char UsageStr[] =
45 "Usage:\n"
46 "  Install a product:\n"
47 "    msiexec {package|productcode} [property]\n"
48 "    msiexec /i {package|productcode} [property]\n"
49 "    msiexec /a package [property]\n"
50 "  Repair an installation:\n"
51 "    msiexec /f[p|o|e|d|c|a|u|m|s|v] {package|productcode}\n"
52 "  Uninstall a product:\n"
53 "    msiexec /x {package|productcode} [property]\n"
54 "  Advertise a product:\n"
55 "    msiexec /j[u|m] package [/t transform] [/g languageid]\n"
56 "    msiexec {u|m} package [/t transform] [/g languageid]\n"
57 "  Apply a patch:\n"
58 "    msiexec /p patchpackage [property]\n"
59 "    msiexec /p patchpackage /a package [property]\n"
60 "  Modifiers for above operations:\n"
61 "    msiexec /l[*][i|w|e|a|r|u|c|m|o|p|v|][+|!] logfile\n"
62 "    msiexec /q{|n|b|r|f|n+|b+|b-}\n"
63 "  Register a module:\n"
64 "    msiexec /y module\n"
65 "  Unregister a module:\n"
66 "    msiexec /z module\n"
67 "  Display usage and copyright:\n"
68 "    msiexec {/h|/?}\n"
69 "NOTE: Product code on commandline unimplemented as of yet\n"
70 "\n"
71 "Copyright 2004 Vincent Béron\n";
72
73 static const WCHAR ActionAdmin[] = {
74    'A','C','T','I','O','N','=','A','D','M','I','N',0 };
75 static const WCHAR RemoveAll[] = {
76    'R','E','M','O','V','E','=','A','L','L',0 };
77
78 static const WCHAR InstallRunOnce[] = {
79    'S','o','f','t','w','a','r','e','\\',
80    'M','i','c','r','o','s','o','f','t','\\',
81    'W','i','n','d','o','w','s','\\',
82    'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
83    'I','n','s','t','a','l','l','e','r','\\',
84    'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
85
86 static void ShowUsage(int ExitCode)
87 {
88         printf(UsageStr);
89         ExitProcess(ExitCode);
90 }
91
92 static BOOL IsProductCode(LPWSTR str)
93 {
94         GUID ProductCode;
95
96         if(lstrlenW(str) != 38)
97                 return FALSE;
98         return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
99
100 }
101
102 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
103 {
104         struct string_list *entry;
105         DWORD size;
106
107         size = sizeof *entry + lstrlenW(str) * sizeof (WCHAR);
108         entry = HeapAlloc(GetProcessHeap(), 0, size);
109         if(!entry)
110         {
111                 WINE_ERR("Out of memory!\n");
112                 ExitProcess(1);
113         }
114         lstrcpyW(entry->str, str);
115         entry->next = NULL;
116
117         /*
118          * Ignoring o(n^2) time complexity to add n strings for simplicity,
119          *  add the string to the end of the list to preserve the order.
120          */
121         while( *list )
122                 list = &(*list)->next;
123         *list = entry;
124 }
125
126 static LPWSTR build_properties(struct string_list *property_list)
127 {
128         struct string_list *list;
129         LPWSTR ret, p, value;
130         DWORD len;
131         BOOL needs_quote;
132
133         if(!property_list)
134                 return NULL;
135
136         /* count the space we need */
137         len = 1;
138         for(list = property_list; list; list = list->next)
139                 len += lstrlenW(list->str) + 3;
140
141         ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
142
143         /* add a space before each string, and quote the value */
144         p = ret;
145         for(list = property_list; list; list = list->next)
146         {
147                 value = strchrW(list->str,'=');
148                 if(!value)
149                         continue;
150                 len = value - list->str;
151                 *p++ = ' ';
152                 memcpy(p, list->str, len * sizeof(WCHAR));
153                 p += len;
154                 *p++ = '=';
155
156                 /* check if the value contains spaces and maybe quote it */
157                 value++;
158                 needs_quote = strchrW(value,' ') ? 1 : 0;
159                 if(needs_quote)
160                         *p++ = '"';
161                 len = lstrlenW(value);
162                 memcpy(p, value, len * sizeof(WCHAR));
163                 p += len;
164                 if(needs_quote)
165                         *p++ = '"';
166         }
167         *p = 0;
168
169         WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
170
171         return ret;
172 }
173
174 static LPWSTR build_transforms(struct string_list *transform_list)
175 {
176         struct string_list *list;
177         LPWSTR ret, p;
178         DWORD len;
179
180         /* count the space we need */
181         len = 1;
182         for(list = transform_list; list; list = list->next)
183                 len += lstrlenW(list->str) + 1;
184
185         ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
186
187         /* add all the transforms with a semicolon between each one */
188         p = ret;
189         for(list = transform_list; list; list = list->next)
190         {
191                 len = lstrlenW(list->str);
192                 lstrcpynW(p, list->str, len );
193                 p += len;
194                 if(list->next)
195                         *p++ = ';';
196         }
197         *p = 0;
198
199         return ret;
200 }
201
202 static DWORD msi_atou(LPCWSTR str)
203 {
204         DWORD ret = 0;
205         while(*str >= '0' && *str <= '9')
206         {
207                 ret *= 10;
208                 ret += (*str - '0');
209                 str++;
210         }
211         return 0;
212 }
213
214 /* str1 is the same as str2, ignoring case */
215 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
216 {
217         DWORD len, ret;
218         LPWSTR strW;
219
220         len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
221         if( !len )
222                 return FALSE;
223         if( lstrlenW(str1) != (len-1) )
224                 return FALSE;
225         strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
226         MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
227         ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
228         HeapFree(GetProcessHeap(), 0, strW);
229         return (ret == CSTR_EQUAL);
230 }
231
232 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
233 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
234 {
235     if (str1[0] != '/' && str1[0] != '-')
236         return FALSE;
237
238     /* skip over the hyphen or slash */
239     return msi_strequal(str1 + 1, str2);
240 }
241
242 /* str2 is at the beginning of str1, ignoring case */
243 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
244 {
245         DWORD len, ret;
246         LPWSTR strW;
247
248         len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
249         if( !len )
250                 return FALSE;
251         if( lstrlenW(str1) < (len-1) )
252                 return FALSE;
253         strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
254         MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
255         ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
256         HeapFree(GetProcessHeap(), 0, strW);
257         return (ret == CSTR_EQUAL);
258 }
259
260 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
261 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
262 {
263     if (str1[0] != '/' && str1[0] != '-')
264         return FALSE;
265
266     /* skip over the hyphen or slash */
267     return msi_strprefix(str1 + 1, str2);
268 }
269
270 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
271 {
272         VOID* (*proc)(void);
273
274         *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
275         if(!*DllHandle)
276         {
277                 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
278                 ExitProcess(1);
279         }
280         proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
281         if(!proc)
282         {
283                 fprintf(stderr, "Dll %s does not implement function %s\n",
284                         wine_dbgstr_w(DllName), ProcName);
285                 FreeLibrary(*DllHandle);
286                 ExitProcess(1);
287         }
288
289         return proc;
290 }
291
292 static DWORD DoDllRegisterServer(LPCWSTR DllName)
293 {
294         HRESULT hr;
295         DLLREGISTERSERVER pfDllRegisterServer = NULL;
296         HMODULE DllHandle = NULL;
297
298         pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
299
300         hr = pfDllRegisterServer();
301         if(FAILED(hr))
302         {
303                 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
304                 return 1;
305         }
306         printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
307         if(DllHandle)
308                 FreeLibrary(DllHandle);
309         return 0;
310 }
311
312 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
313 {
314         HRESULT hr;
315         DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
316         HMODULE DllHandle = NULL;
317
318         pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
319
320         hr = pfDllUnregisterServer();
321         if(FAILED(hr))
322         {
323                 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
324                 return 1;
325         }
326         printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
327         if(DllHandle)
328                 FreeLibrary(DllHandle);
329         return 0;
330 }
331
332 static DWORD DoRegServer(void)
333 {
334     SC_HANDLE scm, service;
335     CHAR path[MAX_PATH+12];
336     DWORD ret = 0;
337
338     scm = OpenSCManager(NULL, SERVICES_ACTIVE_DATABASE, SC_MANAGER_CREATE_SERVICE);
339     if (!scm)
340     {
341         fprintf(stderr, "Failed to open the service control manager.\n");
342         return 1;
343     }
344
345     GetSystemDirectory(path, MAX_PATH);
346     lstrcatA(path, "\\msiexec.exe");
347
348     service = CreateServiceA(scm, "MSIServer", "MSIServer", GENERIC_ALL,
349                              SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
350                              SERVICE_ERROR_NORMAL, path, NULL, NULL,
351                              NULL, NULL, NULL);
352
353     if (service) CloseServiceHandle(service);
354     else if (GetLastError() != ERROR_SERVICE_EXISTS)
355     {
356         fprintf(stderr, "Failed to create MSI service\n");
357         ret = 1;
358     }
359     CloseServiceHandle(scm);
360     return ret;
361 }
362
363 static BOOL process_args_from_reg( LPWSTR ident, int *pargc, WCHAR ***pargv )
364 {
365         LONG r;
366         HKEY hkey = 0, hkeyArgs = 0;
367         DWORD sz = 0, type = 0;
368         LPWSTR buf = NULL;
369         BOOL ret = FALSE;
370
371         r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
372         if(r != ERROR_SUCCESS)
373                 return FALSE;
374         r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
375         if(r == ERROR_SUCCESS && type == REG_SZ)
376         {
377                 buf = HeapAlloc(GetProcessHeap(), 0, sz);
378                 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)buf, &sz);
379                 if( r == ERROR_SUCCESS )
380                 {
381                         *pargv = CommandLineToArgvW(buf, pargc);
382                         ret = TRUE;
383                 }
384         }
385         RegCloseKey(hkeyArgs);
386         return ret;
387 }
388
389 int main(int argc, char **argv)
390 {
391         int i;
392         BOOL FunctionInstall = FALSE;
393         BOOL FunctionInstallAdmin = FALSE;
394         BOOL FunctionRepair = FALSE;
395         BOOL FunctionAdvertise = FALSE;
396         BOOL FunctionPatch = FALSE;
397         BOOL FunctionDllRegisterServer = FALSE;
398         BOOL FunctionDllUnregisterServer = FALSE;
399         BOOL FunctionRegServer = FALSE;
400         BOOL FunctionUnregServer = FALSE;
401         BOOL FunctionUnknown = FALSE;
402
403         LPWSTR PackageName = NULL;
404         LPWSTR Properties = NULL;
405         struct string_list *property_list = NULL;
406
407         DWORD RepairMode = 0;
408
409         DWORD_PTR AdvertiseMode = 0;
410         struct string_list *transform_list = NULL;
411         LANGID Language = 0;
412
413         DWORD LogMode = 0;
414         LPWSTR LogFileName = NULL;
415         DWORD LogAttributes = 0;
416
417         LPWSTR PatchFileName = NULL;
418         INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
419
420         INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
421
422         LPWSTR DllName = NULL;
423         DWORD ReturnCode;
424         LPWSTR *argvW = NULL;
425
426         /* overwrite the command line */
427         argvW = CommandLineToArgvW( GetCommandLineW(), &argc );
428
429         /*
430          * If the args begin with /@ IDENT then we need to load the real
431          * command line out of the RunOnceEntries key in the registry.
432          *  We do that before starting to process the real commandline,
433          * then overwrite the commandline again.
434          */
435         if(argc>1 && msi_option_equal(argvW[1], "@"))
436         {
437                 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
438                         return 1;
439         }
440
441         for(i = 1; i < argc; i++)
442         {
443                 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
444
445                 if (msi_option_equal(argvW[i], "regserver"))
446                 {
447                         FunctionRegServer = TRUE;
448                 }
449                 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister"))
450                 {
451                         FunctionUnregServer = TRUE;
452                 }
453                 else if(msi_option_prefix(argvW[i], "i"))
454                 {
455                         LPWSTR argvWi = argvW[i];
456                         FunctionInstall = TRUE;
457                         if(lstrlenW(argvWi) > 2)
458                                 argvWi += 2;
459                         else
460                         {
461                                 i++;
462                                 if(i >= argc)
463                                         ShowUsage(1);
464                                 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
465                                 argvWi = argvW[i];
466                         }
467                         PackageName = argvWi;
468                 }
469                 else if(msi_option_equal(argvW[i], "a"))
470                 {
471                         FunctionInstall = TRUE;
472                         FunctionInstallAdmin = TRUE;
473                         InstallType = INSTALLTYPE_NETWORK_IMAGE;
474                         i++;
475                         if(i >= argc)
476                                 ShowUsage(1);
477                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
478                         PackageName = argvW[i];
479                         StringListAppend(&property_list, ActionAdmin);
480                 }
481                 else if(msi_option_prefix(argvW[i], "f"))
482                 {
483                         int j;
484                         int len = lstrlenW(argvW[i]);
485                         FunctionRepair = TRUE;
486                         for(j = 2; j < len; j++)
487                         {
488                                 switch(argvW[i][j])
489                                 {
490                                         case 'P':
491                                         case 'p':
492                                                 RepairMode |= REINSTALLMODE_FILEMISSING;
493                                                 break;
494                                         case 'O':
495                                         case 'o':
496                                                 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
497                                                 break;
498                                         case 'E':
499                                         case 'e':
500                                                 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
501                                                 break;
502                                         case 'D':
503                                         case 'd':
504                                                 RepairMode |= REINSTALLMODE_FILEEXACT;
505                                                 break;
506                                         case 'C':
507                                         case 'c':
508                                                 RepairMode |= REINSTALLMODE_FILEVERIFY;
509                                                 break;
510                                         case 'A':
511                                         case 'a':
512                                                 RepairMode |= REINSTALLMODE_FILEREPLACE;
513                                                 break;
514                                         case 'U':
515                                         case 'u':
516                                                 RepairMode |= REINSTALLMODE_USERDATA;
517                                                 break;
518                                         case 'M':
519                                         case 'm':
520                                                 RepairMode |= REINSTALLMODE_MACHINEDATA;
521                                                 break;
522                                         case 'S':
523                                         case 's':
524                                                 RepairMode |= REINSTALLMODE_SHORTCUT;
525                                                 break;
526                                         case 'V':
527                                         case 'v':
528                                                 RepairMode |= REINSTALLMODE_PACKAGE;
529                                                 break;
530                                         default:
531                                                 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
532                                                 break;
533                                 }
534                         }
535                         if(len == 2)
536                         {
537                                 RepairMode = REINSTALLMODE_FILEMISSING |
538                                         REINSTALLMODE_FILEEQUALVERSION |
539                                         REINSTALLMODE_FILEVERIFY |
540                                         REINSTALLMODE_MACHINEDATA |
541                                         REINSTALLMODE_SHORTCUT;
542                         }
543                         i++;
544                         if(i >= argc)
545                                 ShowUsage(1);
546                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
547                         PackageName = argvW[i];
548                 }
549                 else if(msi_option_prefix(argvW[i], "x"))
550                 {
551                         FunctionInstall = TRUE;
552                         PackageName = argvW[i]+2;
553                         if (!PackageName[0])
554                         {
555                                 i++;
556                                 if (i >= argc)
557                                         ShowUsage(1);
558                                 PackageName = argvW[i];
559                         }
560                         WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
561                         StringListAppend(&property_list, RemoveAll);
562                 }
563                 else if(msi_option_prefix(argvW[i], "j"))
564                 {
565                         int j;
566                         int len = lstrlenW(argvW[i]);
567                         FunctionAdvertise = TRUE;
568                         for(j = 2; j < len; j++)
569                         {
570                                 switch(argvW[i][j])
571                                 {
572                                         case 'U':
573                                         case 'u':
574                                                 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
575                                                 break;
576                                         case 'M':
577                                         case 'm':
578                                                 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
579                                                 break;
580                                         default:
581                                                 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
582                                                 break;
583                                 }
584                         }
585                         i++;
586                         if(i >= argc)
587                                 ShowUsage(1);
588                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
589                         PackageName = argvW[i];
590                 }
591                 else if(msi_strequal(argvW[i], "u"))
592                 {
593                         FunctionAdvertise = TRUE;
594                         AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
595                         i++;
596                         if(i >= argc)
597                                 ShowUsage(1);
598                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
599                         PackageName = argvW[i];
600                 }
601                 else if(msi_strequal(argvW[i], "m"))
602                 {
603                         FunctionAdvertise = TRUE;
604                         AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
605                         i++;
606                         if(i >= argc)
607                                 ShowUsage(1);
608                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
609                         PackageName = argvW[i];
610                 }
611                 else if(msi_option_equal(argvW[i], "t"))
612                 {
613                         i++;
614                         if(i >= argc)
615                                 ShowUsage(1);
616                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
617                         StringListAppend(&transform_list, argvW[i]);
618                 }
619                 else if(msi_option_equal(argvW[i], "g"))
620                 {
621                         i++;
622                         if(i >= argc)
623                                 ShowUsage(1);
624                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
625                         Language = msi_atou(argvW[i]);
626                 }
627                 else if(msi_option_prefix(argvW[i], "l"))
628                 {
629                         int j;
630                         int len = lstrlenW(argvW[i]);
631                         for(j = 2; j < len; j++)
632                         {
633                                 switch(argvW[i][j])
634                                 {
635                                         case 'I':
636                                         case 'i':
637                                                 LogMode |= INSTALLLOGMODE_INFO;
638                                                 break;
639                                         case 'W':
640                                         case 'w':
641                                                 LogMode |= INSTALLLOGMODE_WARNING;
642                                                 break;
643                                         case 'E':
644                                         case 'e':
645                                                 LogMode |= INSTALLLOGMODE_ERROR;
646                                                 break;
647                                         case 'A':
648                                         case 'a':
649                                                 LogMode |= INSTALLLOGMODE_ACTIONSTART;
650                                                 break;
651                                         case 'R':
652                                         case 'r':
653                                                 LogMode |= INSTALLLOGMODE_ACTIONDATA;
654                                                 break;
655                                         case 'U':
656                                         case 'u':
657                                                 LogMode |= INSTALLLOGMODE_USER;
658                                                 break;
659                                         case 'C':
660                                         case 'c':
661                                                 LogMode |= INSTALLLOGMODE_COMMONDATA;
662                                                 break;
663                                         case 'M':
664                                         case 'm':
665                                                 LogMode |= INSTALLLOGMODE_FATALEXIT;
666                                                 break;
667                                         case 'O':
668                                         case 'o':
669                                                 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
670                                                 break;
671                                         case 'P':
672                                         case 'p':
673                                                 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
674                                                 break;
675                                         case 'V':
676                                         case 'v':
677                                                 LogMode |= INSTALLLOGMODE_VERBOSE;
678                                                 break;
679                                         case '*':
680                                                 LogMode = INSTALLLOGMODE_FATALEXIT |
681                                                         INSTALLLOGMODE_ERROR |
682                                                         INSTALLLOGMODE_WARNING |
683                                                         INSTALLLOGMODE_USER |
684                                                         INSTALLLOGMODE_INFO |
685                                                         INSTALLLOGMODE_RESOLVESOURCE |
686                                                         INSTALLLOGMODE_OUTOFDISKSPACE |
687                                                         INSTALLLOGMODE_ACTIONSTART |
688                                                         INSTALLLOGMODE_ACTIONDATA |
689                                                         INSTALLLOGMODE_COMMONDATA |
690                                                         INSTALLLOGMODE_PROPERTYDUMP |
691                                                         INSTALLLOGMODE_PROGRESS |
692                                                         INSTALLLOGMODE_INITIALIZE |
693                                                         INSTALLLOGMODE_TERMINATE |
694                                                         INSTALLLOGMODE_SHOWDIALOG;
695                                                 break;
696                                         case '+':
697                                                 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
698                                                 break;
699                                         case '!':
700                                                 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
701                                                 break;
702                                         default:
703                                                 break;
704                                 }
705                         }
706                         i++;
707                         if(i >= argc)
708                                 ShowUsage(1);
709                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
710                         LogFileName = argvW[i];
711                         if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
712                         {
713                                 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
714                                          wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
715                                 ExitProcess(1);
716                         }
717                 }
718                 else if(msi_option_equal(argvW[i], "p"))
719                 {
720                         FunctionPatch = TRUE;
721                         i++;
722                         if(i >= argc)
723                                 ShowUsage(1);
724                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
725                         PatchFileName = argvW[i];
726                 }
727                 else if(msi_option_prefix(argvW[i], "q"))
728                 {
729                         if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n"))
730                         {
731                                 InstallUILevel = INSTALLUILEVEL_NONE;
732                         }
733                         else if(msi_strequal(argvW[i]+2, "b"))
734                         {
735                                 InstallUILevel = INSTALLUILEVEL_BASIC;
736                         }
737                         else if(msi_strequal(argvW[i]+2, "r"))
738                         {
739                                 InstallUILevel = INSTALLUILEVEL_REDUCED;
740                         }
741                         else if(msi_strequal(argvW[i]+2, "f"))
742                         {
743                                 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
744                         }
745                         else if(msi_strequal(argvW[i]+2, "n+"))
746                         {
747                                 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
748                         }
749                         else if(msi_strequal(argvW[i]+2, "b+"))
750                         {
751                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
752                         }
753                         else if(msi_strequal(argvW[i]+2, "b-"))
754                         {
755                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
756                         }
757                         else if(msi_strequal(argvW[i]+2, "b+!"))
758                         {
759                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
760                                 WINE_FIXME("Unknown modifier: !\n");
761                         }
762                         else
763                         {
764                                 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
765                                          wine_dbgstr_w(argvW[i]+2));
766                         }
767                 }
768                 else if(msi_option_equal(argvW[i], "y"))
769                 {
770                         FunctionDllRegisterServer = TRUE;
771                         i++;
772                         if(i >= argc)
773                                 ShowUsage(1);
774                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
775                         DllName = argvW[i];
776                 }
777                 else if(msi_option_equal(argvW[i], "z"))
778                 {
779                         FunctionDllUnregisterServer = TRUE;
780                         i++;
781                         if(i >= argc)
782                                 ShowUsage(1);
783                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
784                         DllName = argvW[i];
785                 }
786                 else if(msi_option_equal(argvW[i], "h") || msi_option_equal(argvW[i], "?"))
787                 {
788                         ShowUsage(0);
789                 }
790                 else if(msi_option_equal(argvW[i], "m"))
791                 {
792                         FunctionUnknown = TRUE;
793                         WINE_FIXME("Unknown parameter /m\n");
794                 }
795                 else if(msi_option_equal(argvW[i], "D"))
796                 {
797                         FunctionUnknown = TRUE;
798                         WINE_FIXME("Unknown parameter /D\n");
799                 }
800                 else
801                         StringListAppend(&property_list, argvW[i]);
802         }
803
804         /* start the GUI */
805         MsiSetInternalUI(InstallUILevel, NULL);
806
807         Properties = build_properties( property_list );
808
809         if(FunctionInstallAdmin && FunctionPatch)
810                 FunctionInstall = FALSE;
811
812         ReturnCode = 1;
813         if(FunctionInstall)
814         {
815                 if(IsProductCode(PackageName))
816                         ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
817                 else
818                         ReturnCode = MsiInstallProductW(PackageName, Properties);
819         }
820         else if(FunctionRepair)
821         {
822                 if(IsProductCode(PackageName))
823                         WINE_FIXME("Product code treatment not implemented yet\n");
824                 else
825                         ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
826         }
827         else if(FunctionAdvertise)
828         {
829                 LPWSTR Transforms = build_transforms( property_list );
830                 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
831         }
832         else if(FunctionPatch)
833         {
834                 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
835         }
836         else if(FunctionDllRegisterServer)
837         {
838                 ReturnCode = DoDllRegisterServer(DllName);
839         }
840         else if(FunctionDllUnregisterServer)
841         {
842                 ReturnCode = DoDllUnregisterServer(DllName);
843         }
844         else if (FunctionRegServer)
845         {
846                 ReturnCode = DoRegServer();
847         }
848         else if (FunctionUnregServer)
849         {
850                 WINE_FIXME( "/unregserver not implemented yet, ignoring\n" );
851         }
852         else if (FunctionUnknown)
853         {
854                 WINE_FIXME( "Unknown function, ignoring\n" );
855         }
856         else
857                 ShowUsage(1);
858
859         return ReturnCode;
860 }