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