opengl32: Get rid of invalid opengl 0.0 test.
[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
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31
32 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
33
34 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
35 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
36
37 DWORD DoService(void);
38
39 struct string_list
40 {
41         struct string_list *next;
42         WCHAR str[1];
43 };
44
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";
73
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 };
78
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};
86
87 static void ShowUsage(int ExitCode)
88 {
89         printf(UsageStr);
90         ExitProcess(ExitCode);
91 }
92
93 static BOOL IsProductCode(LPWSTR str)
94 {
95         GUID ProductCode;
96
97         if(lstrlenW(str) != 38)
98                 return FALSE;
99         return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
100
101 }
102
103 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
104 {
105         struct string_list *entry;
106         DWORD size;
107
108         size = sizeof *entry + lstrlenW(str) * sizeof (WCHAR);
109         entry = HeapAlloc(GetProcessHeap(), 0, size);
110         if(!entry)
111         {
112                 WINE_ERR("Out of memory!\n");
113                 ExitProcess(1);
114         }
115         lstrcpyW(entry->str, str);
116         entry->next = NULL;
117
118         /*
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.
121          */
122         while( *list )
123                 list = &(*list)->next;
124         *list = entry;
125 }
126
127 static LPWSTR build_properties(struct string_list *property_list)
128 {
129         struct string_list *list;
130         LPWSTR ret, p, value;
131         DWORD len;
132         BOOL needs_quote;
133
134         if(!property_list)
135                 return NULL;
136
137         /* count the space we need */
138         len = 1;
139         for(list = property_list; list; list = list->next)
140                 len += lstrlenW(list->str) + 3;
141
142         ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
143
144         /* add a space before each string, and quote the value */
145         p = ret;
146         for(list = property_list; list; list = list->next)
147         {
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++ = '=';
156
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++ = '"';
167         }
168         *p = 0;
169
170         WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
171
172         return ret;
173 }
174
175 static LPWSTR build_transforms(struct string_list *transform_list)
176 {
177         struct string_list *list;
178         LPWSTR ret, p;
179         DWORD len;
180
181         /* count the space we need */
182         len = 1;
183         for(list = transform_list; list; list = list->next)
184                 len += lstrlenW(list->str) + 1;
185
186         ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
187
188         /* add all the transforms with a semicolon between each one */
189         p = ret;
190         for(list = transform_list; list; list = list->next)
191         {
192                 len = lstrlenW(list->str);
193                 lstrcpynW(p, list->str, len );
194                 p += len;
195                 if(list->next)
196                         *p++ = ';';
197         }
198         *p = 0;
199
200         return ret;
201 }
202
203 static DWORD msi_atou(LPCWSTR str)
204 {
205         DWORD ret = 0;
206         while(*str >= '0' && *str <= '9')
207         {
208                 ret *= 10;
209                 ret += (*str - '0');
210                 str++;
211         }
212         return ret;
213 }
214
215 static LPWSTR msi_strdup(LPCWSTR str)
216 {
217         DWORD len = lstrlenW(str)+1;
218         LPWSTR ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
219         lstrcpyW(ret, str);
220         return ret;
221 }
222
223 /* str1 is the same as str2, ignoring case */
224 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
225 {
226         DWORD len, ret;
227         LPWSTR strW;
228
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);
239 }
240
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)
243 {
244     if (str1[0] != '/' && str1[0] != '-')
245         return FALSE;
246
247     /* skip over the hyphen or slash */
248     return msi_strequal(str1 + 1, str2);
249 }
250
251 /* str2 is at the beginning of str1, ignoring case */
252 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
253 {
254         DWORD len, ret;
255         LPWSTR strW;
256
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);
267 }
268
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)
271 {
272     if (str1[0] != '/' && str1[0] != '-')
273         return FALSE;
274
275     /* skip over the hyphen or slash */
276     return msi_strprefix(str1 + 1, str2);
277 }
278
279 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
280 {
281         VOID* (*proc)(void);
282
283         *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
284         if(!*DllHandle)
285         {
286                 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
287                 ExitProcess(1);
288         }
289         proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
290         if(!proc)
291         {
292                 fprintf(stderr, "Dll %s does not implement function %s\n",
293                         wine_dbgstr_w(DllName), ProcName);
294                 FreeLibrary(*DllHandle);
295                 ExitProcess(1);
296         }
297
298         return proc;
299 }
300
301 static DWORD DoDllRegisterServer(LPCWSTR DllName)
302 {
303         HRESULT hr;
304         DLLREGISTERSERVER pfDllRegisterServer = NULL;
305         HMODULE DllHandle = NULL;
306
307         pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
308
309         hr = pfDllRegisterServer();
310         if(FAILED(hr))
311         {
312                 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
313                 return 1;
314         }
315         printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
316         if(DllHandle)
317                 FreeLibrary(DllHandle);
318         return 0;
319 }
320
321 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
322 {
323         HRESULT hr;
324         DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
325         HMODULE DllHandle = NULL;
326
327         pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
328
329         hr = pfDllUnregisterServer();
330         if(FAILED(hr))
331         {
332                 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
333                 return 1;
334         }
335         printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
336         if(DllHandle)
337                 FreeLibrary(DllHandle);
338         return 0;
339 }
340
341 static DWORD DoRegServer(void)
342 {
343     SC_HANDLE scm, service;
344     CHAR path[MAX_PATH+12];
345     DWORD ret = 0;
346
347     scm = OpenSCManagerA(NULL, SERVICES_ACTIVE_DATABASEA, SC_MANAGER_CREATE_SERVICE);
348     if (!scm)
349     {
350         fprintf(stderr, "Failed to open the service control manager.\n");
351         return 1;
352     }
353
354     GetSystemDirectoryA(path, MAX_PATH);
355     lstrcatA(path, "\\msiexec.exe /V");
356
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);
361
362     if (service) CloseServiceHandle(service);
363     else if (GetLastError() != ERROR_SERVICE_EXISTS)
364     {
365         fprintf(stderr, "Failed to create MSI service\n");
366         ret = 1;
367     }
368     CloseServiceHandle(scm);
369     return ret;
370 }
371
372 static INT DoEmbedding( LPWSTR key )
373 {
374         printf("Remote custom actions are not supported yet\n");
375         return 1;
376 }
377
378 /*
379  * state machine to break up the command line properly
380  */
381
382 enum chomp_state
383 {
384         cs_whitespace,
385         cs_token,
386         cs_quote
387 };
388
389 static int chomp( WCHAR *str )
390 {
391         enum chomp_state state = cs_token;
392         WCHAR *p, *out;
393         int count = 1, ignore;
394
395         for( p = str, out = str; *p; p++ )
396         {
397                 ignore = 1;
398                 switch( state )
399                 {
400                 case cs_whitespace:
401                         switch( *p )
402                         {
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;
413                         }
414                         break;
415
416                 case cs_token:
417                         switch( *p )
418                         {
419                         case '"':
420                                 state = cs_quote;
421                                 break;
422                         case ' ':
423                                 state = cs_whitespace;
424                                 *out++ = 0;
425                                 break;
426                         default:
427                                 ignore = 0;
428                         }
429                         break;
430
431                 case cs_quote:
432                         switch( *p )
433                         {
434                         case '"':
435                                 state = cs_token;
436                                 break;
437                         default:
438                                 ignore = 0;
439                         }
440                         break;
441                 }
442                 if( !ignore )
443                         *out++ = *p;
444         }
445
446         *out = 0;
447
448         return count;
449 }
450
451 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
452 {
453         WCHAR **argv, *p = msi_strdup(cmdline);
454         int i, n;
455
456         n = chomp( p );
457         argv = HeapAlloc(GetProcessHeap(), 0, sizeof (WCHAR*)*(n+1));
458         for( i=0; i<n; i++ )
459         {
460                 argv[i] = p;
461                 p += lstrlenW(p) + 1;
462         }
463         argv[i] = NULL;
464
465         *pargc = n;
466         *pargv = argv;
467 }
468
469 static BOOL process_args_from_reg( LPWSTR ident, int *pargc, WCHAR ***pargv )
470 {
471         LONG r;
472         HKEY hkey = 0, hkeyArgs = 0;
473         DWORD sz = 0, type = 0;
474         LPWSTR buf = NULL;
475         BOOL ret = FALSE;
476
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)
482         {
483                 buf = HeapAlloc(GetProcessHeap(), 0, sz);
484                 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)buf, &sz);
485                 if( r == ERROR_SUCCESS )
486                 {
487                         process_args(buf, pargc, pargv);
488                         ret = TRUE;
489                 }
490                 HeapFree(GetProcessHeap(), 0, buf);
491         }
492         RegCloseKey(hkeyArgs);
493         return ret;
494 }
495
496 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
497 {
498         int i;
499         BOOL FunctionInstall = FALSE;
500         BOOL FunctionInstallAdmin = FALSE;
501         BOOL FunctionRepair = FALSE;
502         BOOL FunctionAdvertise = FALSE;
503         BOOL FunctionPatch = FALSE;
504         BOOL FunctionDllRegisterServer = FALSE;
505         BOOL FunctionDllUnregisterServer = FALSE;
506         BOOL FunctionRegServer = FALSE;
507         BOOL FunctionUnregServer = FALSE;
508         BOOL FunctionServer = FALSE;
509         BOOL FunctionUnknown = FALSE;
510
511         LPWSTR PackageName = NULL;
512         LPWSTR Properties = NULL;
513         struct string_list *property_list = NULL;
514
515         DWORD RepairMode = 0;
516
517         DWORD_PTR AdvertiseMode = 0;
518         struct string_list *transform_list = NULL;
519         LANGID Language = 0;
520
521         DWORD LogMode = 0;
522         LPWSTR LogFileName = NULL;
523         DWORD LogAttributes = 0;
524
525         LPWSTR PatchFileName = NULL;
526         INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
527
528         INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
529
530         LPWSTR DllName = NULL;
531         DWORD ReturnCode;
532         int argc;
533         LPWSTR *argvW = NULL;
534
535         /* parse the command line */
536         process_args( GetCommandLineW(), &argc, &argvW );
537
538         /*
539          * If the args begin with /@ IDENT then we need to load the real
540          * command line out of the RunOnceEntries key in the registry.
541          *  We do that before starting to process the real commandline,
542          * then overwrite the commandline again.
543          */
544         if(argc>1 && msi_option_equal(argvW[1], "@"))
545         {
546                 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
547                         return 1;
548         }
549
550         if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
551                 return DoEmbedding( argvW[2] );
552
553         for(i = 1; i < argc; i++)
554         {
555                 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
556
557                 if (msi_option_equal(argvW[i], "regserver"))
558                 {
559                         FunctionRegServer = TRUE;
560                 }
561                 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister"))
562                 {
563                         FunctionUnregServer = TRUE;
564                 }
565                 else if(msi_option_prefix(argvW[i], "i"))
566                 {
567                         LPWSTR argvWi = argvW[i];
568                         FunctionInstall = TRUE;
569                         if(lstrlenW(argvWi) > 2)
570                                 argvWi += 2;
571                         else
572                         {
573                                 i++;
574                                 if(i >= argc)
575                                         ShowUsage(1);
576                                 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
577                                 argvWi = argvW[i];
578                         }
579                         PackageName = argvWi;
580                 }
581                 else if(msi_option_equal(argvW[i], "a"))
582                 {
583                         FunctionInstall = TRUE;
584                         FunctionInstallAdmin = TRUE;
585                         InstallType = INSTALLTYPE_NETWORK_IMAGE;
586                         i++;
587                         if(i >= argc)
588                                 ShowUsage(1);
589                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
590                         PackageName = argvW[i];
591                         StringListAppend(&property_list, ActionAdmin);
592                 }
593                 else if(msi_option_prefix(argvW[i], "f"))
594                 {
595                         int j;
596                         int len = lstrlenW(argvW[i]);
597                         FunctionRepair = TRUE;
598                         for(j = 2; j < len; j++)
599                         {
600                                 switch(argvW[i][j])
601                                 {
602                                         case 'P':
603                                         case 'p':
604                                                 RepairMode |= REINSTALLMODE_FILEMISSING;
605                                                 break;
606                                         case 'O':
607                                         case 'o':
608                                                 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
609                                                 break;
610                                         case 'E':
611                                         case 'e':
612                                                 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
613                                                 break;
614                                         case 'D':
615                                         case 'd':
616                                                 RepairMode |= REINSTALLMODE_FILEEXACT;
617                                                 break;
618                                         case 'C':
619                                         case 'c':
620                                                 RepairMode |= REINSTALLMODE_FILEVERIFY;
621                                                 break;
622                                         case 'A':
623                                         case 'a':
624                                                 RepairMode |= REINSTALLMODE_FILEREPLACE;
625                                                 break;
626                                         case 'U':
627                                         case 'u':
628                                                 RepairMode |= REINSTALLMODE_USERDATA;
629                                                 break;
630                                         case 'M':
631                                         case 'm':
632                                                 RepairMode |= REINSTALLMODE_MACHINEDATA;
633                                                 break;
634                                         case 'S':
635                                         case 's':
636                                                 RepairMode |= REINSTALLMODE_SHORTCUT;
637                                                 break;
638                                         case 'V':
639                                         case 'v':
640                                                 RepairMode |= REINSTALLMODE_PACKAGE;
641                                                 break;
642                                         default:
643                                                 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
644                                                 break;
645                                 }
646                         }
647                         if(len == 2)
648                         {
649                                 RepairMode = REINSTALLMODE_FILEMISSING |
650                                         REINSTALLMODE_FILEEQUALVERSION |
651                                         REINSTALLMODE_FILEVERIFY |
652                                         REINSTALLMODE_MACHINEDATA |
653                                         REINSTALLMODE_SHORTCUT;
654                         }
655                         i++;
656                         if(i >= argc)
657                                 ShowUsage(1);
658                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
659                         PackageName = argvW[i];
660                 }
661                 else if(msi_option_prefix(argvW[i], "x"))
662                 {
663                         FunctionInstall = TRUE;
664                         PackageName = argvW[i]+2;
665                         if (!PackageName[0])
666                         {
667                                 i++;
668                                 if (i >= argc)
669                                         ShowUsage(1);
670                                 PackageName = argvW[i];
671                         }
672                         WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
673                         StringListAppend(&property_list, RemoveAll);
674                 }
675                 else if(msi_option_prefix(argvW[i], "j"))
676                 {
677                         int j;
678                         int len = lstrlenW(argvW[i]);
679                         FunctionAdvertise = TRUE;
680                         for(j = 2; j < len; j++)
681                         {
682                                 switch(argvW[i][j])
683                                 {
684                                         case 'U':
685                                         case 'u':
686                                                 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
687                                                 break;
688                                         case 'M':
689                                         case 'm':
690                                                 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
691                                                 break;
692                                         default:
693                                                 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
694                                                 break;
695                                 }
696                         }
697                         i++;
698                         if(i >= argc)
699                                 ShowUsage(1);
700                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
701                         PackageName = argvW[i];
702                 }
703                 else if(msi_strequal(argvW[i], "u"))
704                 {
705                         FunctionAdvertise = TRUE;
706                         AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
707                         i++;
708                         if(i >= argc)
709                                 ShowUsage(1);
710                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
711                         PackageName = argvW[i];
712                 }
713                 else if(msi_strequal(argvW[i], "m"))
714                 {
715                         FunctionAdvertise = TRUE;
716                         AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
717                         i++;
718                         if(i >= argc)
719                                 ShowUsage(1);
720                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
721                         PackageName = argvW[i];
722                 }
723                 else if(msi_option_equal(argvW[i], "t"))
724                 {
725                         i++;
726                         if(i >= argc)
727                                 ShowUsage(1);
728                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
729                         StringListAppend(&transform_list, argvW[i]);
730                 }
731                 else if(msi_option_equal(argvW[i], "g"))
732                 {
733                         i++;
734                         if(i >= argc)
735                                 ShowUsage(1);
736                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
737                         Language = msi_atou(argvW[i]);
738                 }
739                 else if(msi_option_prefix(argvW[i], "l"))
740                 {
741                         int j;
742                         int len = lstrlenW(argvW[i]);
743                         for(j = 2; j < len; j++)
744                         {
745                                 switch(argvW[i][j])
746                                 {
747                                         case 'I':
748                                         case 'i':
749                                                 LogMode |= INSTALLLOGMODE_INFO;
750                                                 break;
751                                         case 'W':
752                                         case 'w':
753                                                 LogMode |= INSTALLLOGMODE_WARNING;
754                                                 break;
755                                         case 'E':
756                                         case 'e':
757                                                 LogMode |= INSTALLLOGMODE_ERROR;
758                                                 break;
759                                         case 'A':
760                                         case 'a':
761                                                 LogMode |= INSTALLLOGMODE_ACTIONSTART;
762                                                 break;
763                                         case 'R':
764                                         case 'r':
765                                                 LogMode |= INSTALLLOGMODE_ACTIONDATA;
766                                                 break;
767                                         case 'U':
768                                         case 'u':
769                                                 LogMode |= INSTALLLOGMODE_USER;
770                                                 break;
771                                         case 'C':
772                                         case 'c':
773                                                 LogMode |= INSTALLLOGMODE_COMMONDATA;
774                                                 break;
775                                         case 'M':
776                                         case 'm':
777                                                 LogMode |= INSTALLLOGMODE_FATALEXIT;
778                                                 break;
779                                         case 'O':
780                                         case 'o':
781                                                 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
782                                                 break;
783                                         case 'P':
784                                         case 'p':
785                                                 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
786                                                 break;
787                                         case 'V':
788                                         case 'v':
789                                                 LogMode |= INSTALLLOGMODE_VERBOSE;
790                                                 break;
791                                         case '*':
792                                                 LogMode = INSTALLLOGMODE_FATALEXIT |
793                                                         INSTALLLOGMODE_ERROR |
794                                                         INSTALLLOGMODE_WARNING |
795                                                         INSTALLLOGMODE_USER |
796                                                         INSTALLLOGMODE_INFO |
797                                                         INSTALLLOGMODE_RESOLVESOURCE |
798                                                         INSTALLLOGMODE_OUTOFDISKSPACE |
799                                                         INSTALLLOGMODE_ACTIONSTART |
800                                                         INSTALLLOGMODE_ACTIONDATA |
801                                                         INSTALLLOGMODE_COMMONDATA |
802                                                         INSTALLLOGMODE_PROPERTYDUMP |
803                                                         INSTALLLOGMODE_PROGRESS |
804                                                         INSTALLLOGMODE_INITIALIZE |
805                                                         INSTALLLOGMODE_TERMINATE |
806                                                         INSTALLLOGMODE_SHOWDIALOG;
807                                                 break;
808                                         case '+':
809                                                 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
810                                                 break;
811                                         case '!':
812                                                 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
813                                                 break;
814                                         default:
815                                                 break;
816                                 }
817                         }
818                         i++;
819                         if(i >= argc)
820                                 ShowUsage(1);
821                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
822                         LogFileName = argvW[i];
823                         if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
824                         {
825                                 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
826                                          wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
827                                 ExitProcess(1);
828                         }
829                 }
830                 else if(msi_option_equal(argvW[i], "p"))
831                 {
832                         FunctionPatch = TRUE;
833                         i++;
834                         if(i >= argc)
835                                 ShowUsage(1);
836                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
837                         PatchFileName = argvW[i];
838                 }
839                 else if(msi_option_prefix(argvW[i], "q"))
840                 {
841                         if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
842                            msi_strequal(argvW[i] + 2, "uiet"))
843                         {
844                                 InstallUILevel = INSTALLUILEVEL_NONE;
845                         }
846                         else if(msi_strequal(argvW[i]+2, "b"))
847                         {
848                                 InstallUILevel = INSTALLUILEVEL_BASIC;
849                         }
850                         else if(msi_strequal(argvW[i]+2, "r"))
851                         {
852                                 InstallUILevel = INSTALLUILEVEL_REDUCED;
853                         }
854                         else if(msi_strequal(argvW[i]+2, "f"))
855                         {
856                                 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
857                         }
858                         else if(msi_strequal(argvW[i]+2, "n+"))
859                         {
860                                 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
861                         }
862                         else if(msi_strequal(argvW[i]+2, "b+"))
863                         {
864                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
865                         }
866                         else if(msi_strequal(argvW[i]+2, "b-"))
867                         {
868                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY;
869                         }
870                         else if(msi_strequal(argvW[i]+2, "b+!"))
871                         {
872                                 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_ENDDIALOG;
873                                 WINE_FIXME("Unknown modifier: !\n");
874                         }
875                         else
876                         {
877                                 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
878                                          wine_dbgstr_w(argvW[i]+2));
879                         }
880                 }
881                 else if(msi_option_equal(argvW[i], "y"))
882                 {
883                         FunctionDllRegisterServer = TRUE;
884                         i++;
885                         if(i >= argc)
886                                 ShowUsage(1);
887                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
888                         DllName = argvW[i];
889                 }
890                 else if(msi_option_equal(argvW[i], "z"))
891                 {
892                         FunctionDllUnregisterServer = TRUE;
893                         i++;
894                         if(i >= argc)
895                                 ShowUsage(1);
896                         WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
897                         DllName = argvW[i];
898                 }
899                 else if(msi_option_equal(argvW[i], "h") || msi_option_equal(argvW[i], "?"))
900                 {
901                         ShowUsage(0);
902                 }
903                 else if(msi_option_equal(argvW[i], "m"))
904                 {
905                         FunctionUnknown = TRUE;
906                         WINE_FIXME("Unknown parameter /m\n");
907                 }
908                 else if(msi_option_equal(argvW[i], "D"))
909                 {
910                         FunctionUnknown = TRUE;
911                         WINE_FIXME("Unknown parameter /D\n");
912                 }
913                 else if (msi_option_equal(argvW[i], "V"))
914                 {
915                     FunctionServer = TRUE;
916                 }
917                 else
918                         StringListAppend(&property_list, argvW[i]);
919         }
920
921         /* start the GUI */
922         MsiSetInternalUI(InstallUILevel, NULL);
923
924         Properties = build_properties( property_list );
925
926         if(FunctionInstallAdmin && FunctionPatch)
927                 FunctionInstall = FALSE;
928
929         ReturnCode = 1;
930         if(FunctionInstall)
931         {
932                 if(IsProductCode(PackageName))
933                         ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
934                 else
935                         ReturnCode = MsiInstallProductW(PackageName, Properties);
936         }
937         else if(FunctionRepair)
938         {
939                 if(IsProductCode(PackageName))
940                         WINE_FIXME("Product code treatment not implemented yet\n");
941                 else
942                         ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
943         }
944         else if(FunctionAdvertise)
945         {
946                 LPWSTR Transforms = build_transforms( property_list );
947                 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
948         }
949         else if(FunctionPatch)
950         {
951                 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
952         }
953         else if(FunctionDllRegisterServer)
954         {
955                 ReturnCode = DoDllRegisterServer(DllName);
956         }
957         else if(FunctionDllUnregisterServer)
958         {
959                 ReturnCode = DoDllUnregisterServer(DllName);
960         }
961         else if (FunctionRegServer)
962         {
963                 ReturnCode = DoRegServer();
964         }
965         else if (FunctionUnregServer)
966         {
967                 WINE_FIXME( "/unregserver not implemented yet, ignoring\n" );
968         }
969         else if (FunctionServer)
970         {
971             ReturnCode = DoService();
972         }
973         else if (FunctionUnknown)
974         {
975                 WINE_FIXME( "Unknown function, ignoring\n" );
976         }
977         else
978                 ShowUsage(1);
979
980         return ReturnCode;
981 }