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