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