msiexec: Don't keep the custom action GUID in the main thread's stack.
[wine.git] / programs / msiexec / msiexec.c
blobefbcb5c7f4df5bb99ac3bf0502e1e4e1967dc53c
1 /*
2 * msiexec.exe implementation
4 * Copyright 2004 Vincent BĂ©ron
5 * Copyright 2005 Mike McCormack
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.
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.
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
22 #define WIN32_LEAN_AND_MEAN
24 #include <windows.h>
25 #include <msi.h>
26 #include <winsvc.h>
27 #include <objbase.h>
28 #include <stdio.h>
30 #include "wine/debug.h"
31 #include "wine/heap.h"
32 #include "wine/unicode.h"
34 #include "initguid.h"
35 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
37 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
39 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
40 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
42 DWORD DoService(void);
44 struct string_list
46 struct string_list *next;
47 WCHAR str[1];
50 static const WCHAR ActionAdmin[] = {
51 'A','C','T','I','O','N','=','A','D','M','I','N',0 };
52 static const WCHAR RemoveAll[] = {
53 'R','E','M','O','V','E','=','A','L','L',0 };
55 static const WCHAR InstallRunOnce[] = {
56 'S','o','f','t','w','a','r','e','\\',
57 'M','i','c','r','o','s','o','f','t','\\',
58 'W','i','n','d','o','w','s','\\',
59 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
60 'I','n','s','t','a','l','l','e','r','\\',
61 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
63 static void ShowUsage(int ExitCode)
65 WCHAR msiexec_version[40];
66 WCHAR filename[MAX_PATH];
67 LPWSTR msi_res;
68 LPWSTR msiexec_help;
69 HMODULE hmsi = GetModuleHandleA("msi.dll");
70 DWORD len;
71 DWORD res;
73 /* MsiGetFileVersion need the full path */
74 *filename = 0;
75 res = GetModuleFileNameW(hmsi, filename, ARRAY_SIZE(filename));
76 if (!res)
77 WINE_ERR("GetModuleFileName failed: %d\n", GetLastError());
79 len = ARRAY_SIZE(msiexec_version);
80 *msiexec_version = 0;
81 res = MsiGetFileVersionW(filename, msiexec_version, &len, NULL, NULL);
82 if (res)
83 WINE_ERR("MsiGetFileVersion failed with %d\n", res);
85 /* Return the length of the resource.
86 No typo: The LPWSTR parameter must be a LPWSTR * for this mode */
87 len = LoadStringW(hmsi, 10, (LPWSTR) &msi_res, 0);
89 msi_res = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
90 msiexec_help = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) + sizeof(msiexec_version));
91 if (msi_res && msiexec_help) {
92 *msi_res = 0;
93 LoadStringW(hmsi, 10, msi_res, len + 1);
95 sprintfW(msiexec_help, msi_res, msiexec_version);
96 MsiMessageBoxW(0, msiexec_help, NULL, 0, GetUserDefaultLangID(), 0);
98 HeapFree(GetProcessHeap(), 0, msi_res);
99 HeapFree(GetProcessHeap(), 0, msiexec_help);
100 ExitProcess(ExitCode);
103 static BOOL IsProductCode(LPWSTR str)
105 GUID ProductCode;
107 if(lstrlenW(str) != 38)
108 return FALSE;
109 return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
113 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
115 struct string_list *entry;
117 entry = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(struct string_list, str[lstrlenW(str) + 1]));
118 if(!entry)
120 WINE_ERR("Out of memory!\n");
121 ExitProcess(1);
123 lstrcpyW(entry->str, str);
124 entry->next = NULL;
127 * Ignoring o(n^2) time complexity to add n strings for simplicity,
128 * add the string to the end of the list to preserve the order.
130 while( *list )
131 list = &(*list)->next;
132 *list = entry;
135 static LPWSTR build_properties(struct string_list *property_list)
137 struct string_list *list;
138 LPWSTR ret, p, value;
139 DWORD len;
140 BOOL needs_quote;
142 if(!property_list)
143 return NULL;
145 /* count the space we need */
146 len = 1;
147 for(list = property_list; list; list = list->next)
148 len += lstrlenW(list->str) + 3;
150 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
152 /* add a space before each string, and quote the value */
153 p = ret;
154 for(list = property_list; list; list = list->next)
156 value = strchrW(list->str,'=');
157 if(!value)
158 continue;
159 len = value - list->str;
160 *p++ = ' ';
161 memcpy(p, list->str, len * sizeof(WCHAR));
162 p += len;
163 *p++ = '=';
165 /* check if the value contains spaces and maybe quote it */
166 value++;
167 needs_quote = strchrW(value,' ') ? 1 : 0;
168 if(needs_quote)
169 *p++ = '"';
170 len = lstrlenW(value);
171 memcpy(p, value, len * sizeof(WCHAR));
172 p += len;
173 if(needs_quote)
174 *p++ = '"';
176 *p = 0;
178 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
180 return ret;
183 static LPWSTR build_transforms(struct string_list *transform_list)
185 struct string_list *list;
186 LPWSTR ret, p;
187 DWORD len;
189 /* count the space we need */
190 len = 1;
191 for(list = transform_list; list; list = list->next)
192 len += lstrlenW(list->str) + 1;
194 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
196 /* add all the transforms with a semicolon between each one */
197 p = ret;
198 for(list = transform_list; list; list = list->next)
200 len = lstrlenW(list->str);
201 lstrcpynW(p, list->str, len );
202 p += len;
203 if(list->next)
204 *p++ = ';';
206 *p = 0;
208 return ret;
211 static DWORD msi_atou(LPCWSTR str)
213 DWORD ret = 0;
214 while(*str >= '0' && *str <= '9')
216 ret *= 10;
217 ret += (*str - '0');
218 str++;
220 return ret;
223 /* str1 is the same as str2, ignoring case */
224 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
226 DWORD len, ret;
227 LPWSTR strW;
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);
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)
244 if (str1[0] != '/' && str1[0] != '-')
245 return FALSE;
247 /* skip over the hyphen or slash */
248 return msi_strequal(str1 + 1, str2);
251 /* str2 is at the beginning of str1, ignoring case */
252 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
254 DWORD len, ret;
255 LPWSTR strW;
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);
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)
272 if (str1[0] != '/' && str1[0] != '-')
273 return FALSE;
275 /* skip over the hyphen or slash */
276 return msi_strprefix(str1 + 1, str2);
279 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
281 VOID* (*proc)(void);
283 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
284 if(!*DllHandle)
286 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
287 ExitProcess(1);
289 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
290 if(!proc)
292 fprintf(stderr, "Dll %s does not implement function %s\n",
293 wine_dbgstr_w(DllName), ProcName);
294 FreeLibrary(*DllHandle);
295 ExitProcess(1);
298 return proc;
301 static DWORD DoDllRegisterServer(LPCWSTR DllName)
303 HRESULT hr;
304 DLLREGISTERSERVER pfDllRegisterServer = NULL;
305 HMODULE DllHandle = NULL;
307 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
309 hr = pfDllRegisterServer();
310 if(FAILED(hr))
312 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
313 return 1;
315 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
316 if(DllHandle)
317 FreeLibrary(DllHandle);
318 return 0;
321 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
323 HRESULT hr;
324 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
325 HMODULE DllHandle = NULL;
327 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
329 hr = pfDllUnregisterServer();
330 if(FAILED(hr))
332 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
333 return 1;
335 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
336 if(DllHandle)
337 FreeLibrary(DllHandle);
338 return 0;
341 static DWORD DoRegServer(void)
343 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
344 static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c',' ','/','V',0};
345 SC_HANDLE scm, service;
346 WCHAR path[MAX_PATH+12];
347 DWORD len, ret = 0;
349 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CREATE_SERVICE)))
351 fprintf(stderr, "Failed to open the service control manager.\n");
352 return 1;
354 len = GetSystemDirectoryW(path, MAX_PATH);
355 lstrcpyW(path + len, msiexecW);
356 if ((service = CreateServiceW(scm, msiserverW, msiserverW, GENERIC_ALL,
357 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
358 SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL)))
360 CloseServiceHandle(service);
362 else if (GetLastError() != ERROR_SERVICE_EXISTS)
364 fprintf(stderr, "Failed to create MSI service\n");
365 ret = 1;
367 CloseServiceHandle(scm);
368 return ret;
371 static DWORD DoUnregServer(void)
373 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
374 SC_HANDLE scm, service;
375 DWORD ret = 0;
377 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CONNECT)))
379 fprintf(stderr, "Failed to open service control manager\n");
380 return 1;
382 if ((service = OpenServiceW(scm, msiserverW, DELETE)))
384 if (!DeleteService(service))
386 fprintf(stderr, "Failed to delete MSI service\n");
387 ret = 1;
389 CloseServiceHandle(service);
391 else if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
393 fprintf(stderr, "Failed to open MSI service\n");
394 ret = 1;
396 CloseServiceHandle(scm);
397 return ret;
400 extern UINT CDECL __wine_msi_call_dll_function(GUID *guid);
402 static DWORD CALLBACK custom_action_thread(void *arg)
404 GUID guid = *(GUID *)arg;
405 heap_free(arg);
406 return __wine_msi_call_dll_function(&guid);
409 static int custom_action_server(const WCHAR *arg)
411 static const WCHAR pipe_name[] = {'\\','\\','.','\\','p','i','p','e','\\','m','s','i','c','a','_','%','x','_','%','d',0};
412 DWORD client_pid = atoiW(arg);
413 GUID guid, *thread_guid;
414 DWORD64 thread64;
415 WCHAR buffer[24];
416 HANDLE thread;
417 HANDLE pipe;
418 DWORD size;
420 TRACE("%s\n", debugstr_w(arg));
422 if (!client_pid)
424 ERR("Invalid parameter %s\n", debugstr_w(arg));
425 return 1;
428 sprintfW(buffer, pipe_name, client_pid, sizeof(void *) * 8);
429 pipe = CreateFileW(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
430 if (pipe == INVALID_HANDLE_VALUE)
432 ERR("Failed to create custom action server pipe: %u\n", GetLastError());
433 return GetLastError();
436 /* We need this to unmarshal streams, and some apps expect it to be present. */
437 CoInitializeEx(NULL, COINIT_MULTITHREADED);
439 while (ReadFile(pipe, &guid, sizeof(guid), &size, NULL) && size == sizeof(guid))
441 if (IsEqualGUID(&guid, &GUID_NULL))
443 /* package closed; time to shut down */
444 CoUninitialize();
445 return 0;
448 thread_guid = heap_alloc(sizeof(GUID));
449 memcpy(thread_guid, &guid, sizeof(GUID));
450 thread = CreateThread(NULL, 0, custom_action_thread, thread_guid, 0, NULL);
452 /* give the thread handle to the client to wait on, since we might have
453 * to run a nested action and can't block during this one */
454 thread64 = (DWORD_PTR)thread;
455 if (!WriteFile(pipe, &thread64, sizeof(thread64), &size, NULL) || size != sizeof(thread64))
457 ERR("Failed to write to custom action server pipe: %u\n", GetLastError());
458 CoUninitialize();
459 return GetLastError();
462 ERR("Failed to read from custom action server pipe: %u\n", GetLastError());
463 CoUninitialize();
464 return GetLastError();
468 * state machine to break up the command line properly
471 enum chomp_state
473 CS_WHITESPACE,
474 CS_TOKEN,
475 CS_QUOTE
478 static int chomp( const WCHAR *in, WCHAR *out )
480 enum chomp_state state = CS_TOKEN;
481 const WCHAR *p;
482 int count = 1;
483 BOOL ignore;
485 for (p = in; *p; p++)
487 ignore = TRUE;
488 switch (state)
490 case CS_WHITESPACE:
491 switch (*p)
493 case ' ':
494 break;
495 case '"':
496 state = CS_QUOTE;
497 count++;
498 break;
499 default:
500 count++;
501 ignore = FALSE;
502 state = CS_TOKEN;
504 break;
506 case CS_TOKEN:
507 switch (*p)
509 case '"':
510 state = CS_QUOTE;
511 break;
512 case ' ':
513 state = CS_WHITESPACE;
514 if (out) *out++ = 0;
515 break;
516 default:
517 if (p > in && p[-1] == '"')
519 if (out) *out++ = 0;
520 count++;
522 ignore = FALSE;
524 break;
526 case CS_QUOTE:
527 switch (*p)
529 case '"':
530 state = CS_TOKEN;
531 break;
532 default:
533 ignore = FALSE;
535 break;
537 if (!ignore && out) *out++ = *p;
539 if (out) *out = 0;
540 return count;
543 static void process_args( WCHAR *cmdline, int *pargc, WCHAR ***pargv )
545 WCHAR **argv, *p;
546 int i, count;
548 *pargc = 0;
549 *pargv = NULL;
551 count = chomp( cmdline, NULL );
552 if (!(p = HeapAlloc( GetProcessHeap(), 0, (lstrlenW(cmdline) + count + 1) * sizeof(WCHAR) )))
553 return;
555 count = chomp( cmdline, p );
556 if (!(argv = HeapAlloc( GetProcessHeap(), 0, (count + 1) * sizeof(WCHAR *) )))
558 HeapFree( GetProcessHeap(), 0, p );
559 return;
561 for (i = 0; i < count; i++)
563 argv[i] = p;
564 p += lstrlenW( p ) + 1;
566 argv[i] = NULL;
568 *pargc = count;
569 *pargv = argv;
572 static BOOL process_args_from_reg( const WCHAR *ident, int *pargc, WCHAR ***pargv )
574 LONG r;
575 HKEY hkey;
576 DWORD sz = 0, type = 0;
577 WCHAR *buf;
578 BOOL ret = FALSE;
580 r = RegOpenKeyW(HKEY_LOCAL_MACHINE, InstallRunOnce, &hkey);
581 if(r != ERROR_SUCCESS)
582 return FALSE;
583 r = RegQueryValueExW(hkey, ident, 0, &type, 0, &sz);
584 if(r == ERROR_SUCCESS && type == REG_SZ)
586 int len = lstrlenW( *pargv[0] );
587 if (!(buf = HeapAlloc( GetProcessHeap(), 0, sz + (len + 1) * sizeof(WCHAR) )))
589 RegCloseKey( hkey );
590 return FALSE;
592 memcpy( buf, *pargv[0], len * sizeof(WCHAR) );
593 buf[len++] = ' ';
594 r = RegQueryValueExW(hkey, ident, 0, &type, (LPBYTE)(buf + len), &sz);
595 if( r == ERROR_SUCCESS )
597 process_args(buf, pargc, pargv);
598 ret = TRUE;
600 HeapFree(GetProcessHeap(), 0, buf);
602 RegCloseKey(hkey);
603 return ret;
606 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
608 int i;
609 BOOL FunctionInstall = FALSE;
610 BOOL FunctionInstallAdmin = FALSE;
611 BOOL FunctionRepair = FALSE;
612 BOOL FunctionAdvertise = FALSE;
613 BOOL FunctionPatch = FALSE;
614 BOOL FunctionDllRegisterServer = FALSE;
615 BOOL FunctionDllUnregisterServer = FALSE;
616 BOOL FunctionRegServer = FALSE;
617 BOOL FunctionUnregServer = FALSE;
618 BOOL FunctionServer = FALSE;
619 BOOL FunctionUnknown = FALSE;
621 LPWSTR PackageName = NULL;
622 LPWSTR Properties = NULL;
623 struct string_list *property_list = NULL;
625 DWORD RepairMode = 0;
627 DWORD_PTR AdvertiseMode = 0;
628 struct string_list *transform_list = NULL;
629 LANGID Language = 0;
631 DWORD LogMode = 0;
632 LPWSTR LogFileName = NULL;
633 DWORD LogAttributes = 0;
635 LPWSTR PatchFileName = NULL;
636 INSTALLTYPE InstallType = INSTALLTYPE_DEFAULT;
638 INSTALLUILEVEL InstallUILevel = INSTALLUILEVEL_FULL;
640 LPWSTR DllName = NULL;
641 DWORD ReturnCode;
642 int argc;
643 LPWSTR *argvW = NULL;
645 /* parse the command line */
646 process_args( GetCommandLineW(), &argc, &argvW );
649 * If the args begin with /@ IDENT then we need to load the real
650 * command line out of the RunOnceEntries key in the registry.
651 * We do that before starting to process the real commandline,
652 * then overwrite the commandline again.
654 if(argc>1 && msi_option_equal(argvW[1], "@"))
656 if(!process_args_from_reg( argvW[2], &argc, &argvW ))
657 return 1;
660 if (argc == 3 && msi_option_equal(argvW[1], "Embedding"))
661 return custom_action_server(argvW[2]);
663 for(i = 1; i < argc; i++)
665 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
667 if (msi_option_equal(argvW[i], "regserver"))
669 FunctionRegServer = TRUE;
671 else if (msi_option_equal(argvW[i], "unregserver") || msi_option_equal(argvW[i], "unregister")
672 || msi_option_equal(argvW[i], "unreg"))
674 FunctionUnregServer = TRUE;
676 else if(msi_option_prefix(argvW[i], "i") || msi_option_prefix(argvW[i], "package"))
678 LPWSTR argvWi = argvW[i];
679 int argLen = (msi_option_prefix(argvW[i], "i") ? 2 : 8);
680 FunctionInstall = TRUE;
681 if(lstrlenW(argvW[i]) > argLen)
682 argvWi += argLen;
683 else
685 i++;
686 if(i >= argc)
687 ShowUsage(1);
688 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
689 argvWi = argvW[i];
691 PackageName = argvWi;
693 else if(msi_option_equal(argvW[i], "a"))
695 FunctionInstall = TRUE;
696 FunctionInstallAdmin = TRUE;
697 InstallType = INSTALLTYPE_NETWORK_IMAGE;
698 i++;
699 if(i >= argc)
700 ShowUsage(1);
701 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
702 PackageName = argvW[i];
703 StringListAppend(&property_list, ActionAdmin);
704 WINE_FIXME("Administrative installs are not currently supported\n");
706 else if(msi_option_prefix(argvW[i], "f"))
708 int j;
709 int len = lstrlenW(argvW[i]);
710 FunctionRepair = TRUE;
711 for(j = 2; j < len; j++)
713 switch(argvW[i][j])
715 case 'P':
716 case 'p':
717 RepairMode |= REINSTALLMODE_FILEMISSING;
718 break;
719 case 'O':
720 case 'o':
721 RepairMode |= REINSTALLMODE_FILEOLDERVERSION;
722 break;
723 case 'E':
724 case 'e':
725 RepairMode |= REINSTALLMODE_FILEEQUALVERSION;
726 break;
727 case 'D':
728 case 'd':
729 RepairMode |= REINSTALLMODE_FILEEXACT;
730 break;
731 case 'C':
732 case 'c':
733 RepairMode |= REINSTALLMODE_FILEVERIFY;
734 break;
735 case 'A':
736 case 'a':
737 RepairMode |= REINSTALLMODE_FILEREPLACE;
738 break;
739 case 'U':
740 case 'u':
741 RepairMode |= REINSTALLMODE_USERDATA;
742 break;
743 case 'M':
744 case 'm':
745 RepairMode |= REINSTALLMODE_MACHINEDATA;
746 break;
747 case 'S':
748 case 's':
749 RepairMode |= REINSTALLMODE_SHORTCUT;
750 break;
751 case 'V':
752 case 'v':
753 RepairMode |= REINSTALLMODE_PACKAGE;
754 break;
755 default:
756 fprintf(stderr, "Unknown option \"%c\" in Repair mode\n", argvW[i][j]);
757 break;
760 if(len == 2)
762 RepairMode = REINSTALLMODE_FILEMISSING |
763 REINSTALLMODE_FILEEQUALVERSION |
764 REINSTALLMODE_FILEVERIFY |
765 REINSTALLMODE_MACHINEDATA |
766 REINSTALLMODE_SHORTCUT;
768 i++;
769 if(i >= argc)
770 ShowUsage(1);
771 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
772 PackageName = argvW[i];
774 else if(msi_option_prefix(argvW[i], "x") || msi_option_equal(argvW[i], "uninstall"))
776 FunctionInstall = TRUE;
777 if(msi_option_prefix(argvW[i], "x")) PackageName = argvW[i]+2;
778 if(!PackageName || !PackageName[0])
780 i++;
781 if (i >= argc)
782 ShowUsage(1);
783 PackageName = argvW[i];
785 WINE_TRACE("PackageName = %s\n", wine_dbgstr_w(PackageName));
786 StringListAppend(&property_list, RemoveAll);
788 else if(msi_option_prefix(argvW[i], "j"))
790 int j;
791 int len = lstrlenW(argvW[i]);
792 FunctionAdvertise = TRUE;
793 for(j = 2; j < len; j++)
795 switch(argvW[i][j])
797 case 'U':
798 case 'u':
799 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
800 break;
801 case 'M':
802 case 'm':
803 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
804 break;
805 default:
806 fprintf(stderr, "Unknown option \"%c\" in Advertise mode\n", argvW[i][j]);
807 break;
810 i++;
811 if(i >= argc)
812 ShowUsage(1);
813 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
814 PackageName = argvW[i];
816 else if(msi_strequal(argvW[i], "u"))
818 FunctionAdvertise = TRUE;
819 AdvertiseMode = ADVERTISEFLAGS_USERASSIGN;
820 i++;
821 if(i >= argc)
822 ShowUsage(1);
823 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
824 PackageName = argvW[i];
826 else if(msi_strequal(argvW[i], "m"))
828 FunctionAdvertise = TRUE;
829 AdvertiseMode = ADVERTISEFLAGS_MACHINEASSIGN;
830 i++;
831 if(i >= argc)
832 ShowUsage(1);
833 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
834 PackageName = argvW[i];
836 else if(msi_option_equal(argvW[i], "t"))
838 i++;
839 if(i >= argc)
840 ShowUsage(1);
841 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
842 StringListAppend(&transform_list, argvW[i]);
844 else if(msi_option_equal(argvW[i], "g"))
846 i++;
847 if(i >= argc)
848 ShowUsage(1);
849 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
850 Language = msi_atou(argvW[i]);
852 else if(msi_option_prefix(argvW[i], "l"))
854 int j;
855 int len = lstrlenW(argvW[i]);
856 for(j = 2; j < len; j++)
858 switch(argvW[i][j])
860 case 'I':
861 case 'i':
862 LogMode |= INSTALLLOGMODE_INFO;
863 break;
864 case 'W':
865 case 'w':
866 LogMode |= INSTALLLOGMODE_WARNING;
867 break;
868 case 'E':
869 case 'e':
870 LogMode |= INSTALLLOGMODE_ERROR;
871 break;
872 case 'A':
873 case 'a':
874 LogMode |= INSTALLLOGMODE_ACTIONSTART;
875 break;
876 case 'R':
877 case 'r':
878 LogMode |= INSTALLLOGMODE_ACTIONDATA;
879 break;
880 case 'U':
881 case 'u':
882 LogMode |= INSTALLLOGMODE_USER;
883 break;
884 case 'C':
885 case 'c':
886 LogMode |= INSTALLLOGMODE_COMMONDATA;
887 break;
888 case 'M':
889 case 'm':
890 LogMode |= INSTALLLOGMODE_FATALEXIT;
891 break;
892 case 'O':
893 case 'o':
894 LogMode |= INSTALLLOGMODE_OUTOFDISKSPACE;
895 break;
896 case 'P':
897 case 'p':
898 LogMode |= INSTALLLOGMODE_PROPERTYDUMP;
899 break;
900 case 'V':
901 case 'v':
902 LogMode |= INSTALLLOGMODE_VERBOSE;
903 break;
904 case '*':
905 LogMode = INSTALLLOGMODE_FATALEXIT |
906 INSTALLLOGMODE_ERROR |
907 INSTALLLOGMODE_WARNING |
908 INSTALLLOGMODE_USER |
909 INSTALLLOGMODE_INFO |
910 INSTALLLOGMODE_RESOLVESOURCE |
911 INSTALLLOGMODE_OUTOFDISKSPACE |
912 INSTALLLOGMODE_ACTIONSTART |
913 INSTALLLOGMODE_ACTIONDATA |
914 INSTALLLOGMODE_COMMONDATA |
915 INSTALLLOGMODE_PROPERTYDUMP |
916 INSTALLLOGMODE_PROGRESS |
917 INSTALLLOGMODE_INITIALIZE |
918 INSTALLLOGMODE_TERMINATE |
919 INSTALLLOGMODE_SHOWDIALOG;
920 break;
921 case '+':
922 LogAttributes |= INSTALLLOGATTRIBUTES_APPEND;
923 break;
924 case '!':
925 LogAttributes |= INSTALLLOGATTRIBUTES_FLUSHEACHLINE;
926 break;
927 default:
928 break;
931 i++;
932 if(i >= argc)
933 ShowUsage(1);
934 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
935 LogFileName = argvW[i];
936 if(MsiEnableLogW(LogMode, LogFileName, LogAttributes) != ERROR_SUCCESS)
938 fprintf(stderr, "Logging in %s (0x%08x, %u) failed\n",
939 wine_dbgstr_w(LogFileName), LogMode, LogAttributes);
940 ExitProcess(1);
943 else if(msi_option_equal(argvW[i], "p") || msi_option_equal(argvW[i], "update"))
945 FunctionPatch = TRUE;
946 i++;
947 if(i >= argc)
948 ShowUsage(1);
949 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
950 PatchFileName = argvW[i];
952 else if(msi_option_prefix(argvW[i], "q"))
954 if(lstrlenW(argvW[i]) == 2 || msi_strequal(argvW[i]+2, "n") ||
955 msi_strequal(argvW[i] + 2, "uiet"))
957 InstallUILevel = INSTALLUILEVEL_NONE;
959 else if(msi_strequal(argvW[i]+2, "r"))
961 InstallUILevel = INSTALLUILEVEL_REDUCED;
963 else if(msi_strequal(argvW[i]+2, "f"))
965 InstallUILevel = INSTALLUILEVEL_FULL|INSTALLUILEVEL_ENDDIALOG;
967 else if(msi_strequal(argvW[i]+2, "n+"))
969 InstallUILevel = INSTALLUILEVEL_NONE|INSTALLUILEVEL_ENDDIALOG;
971 else if(msi_strprefix(argvW[i]+2, "b"))
973 const WCHAR *ptr = argvW[i] + 3;
975 InstallUILevel = INSTALLUILEVEL_BASIC;
977 while (*ptr)
979 if (msi_strprefix(ptr, "+"))
980 InstallUILevel |= INSTALLUILEVEL_ENDDIALOG;
981 if (msi_strprefix(ptr, "-"))
982 InstallUILevel |= INSTALLUILEVEL_PROGRESSONLY;
983 if (msi_strprefix(ptr, "!"))
985 WINE_FIXME("Unhandled modifier: !\n");
986 InstallUILevel |= INSTALLUILEVEL_HIDECANCEL;
988 ptr++;
991 else
993 fprintf(stderr, "Unknown option \"%s\" for UI level\n",
994 wine_dbgstr_w(argvW[i]+2));
997 else if(msi_option_equal(argvW[i], "passive"))
999 static const WCHAR rebootpromptW[] =
1000 {'R','E','B','O','O','T','P','R','O','M','P','T','=','"','S','"',0};
1002 InstallUILevel = INSTALLUILEVEL_BASIC|INSTALLUILEVEL_PROGRESSONLY|INSTALLUILEVEL_HIDECANCEL;
1003 StringListAppend(&property_list, rebootpromptW);
1005 else if(msi_option_equal(argvW[i], "y"))
1007 FunctionDllRegisterServer = TRUE;
1008 i++;
1009 if(i >= argc)
1010 ShowUsage(1);
1011 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
1012 DllName = argvW[i];
1014 else if(msi_option_equal(argvW[i], "z"))
1016 FunctionDllUnregisterServer = TRUE;
1017 i++;
1018 if(i >= argc)
1019 ShowUsage(1);
1020 WINE_TRACE("argvW[%d] = %s\n", i, wine_dbgstr_w(argvW[i]));
1021 DllName = argvW[i];
1023 else if(msi_option_equal(argvW[i], "help") || msi_option_equal(argvW[i], "?"))
1025 ShowUsage(0);
1027 else if(msi_option_equal(argvW[i], "m"))
1029 FunctionUnknown = TRUE;
1030 WINE_FIXME("Unknown parameter /m\n");
1032 else if(msi_option_equal(argvW[i], "D"))
1034 FunctionUnknown = TRUE;
1035 WINE_FIXME("Unknown parameter /D\n");
1037 else if (msi_option_equal(argvW[i], "V"))
1039 FunctionServer = TRUE;
1041 else
1042 StringListAppend(&property_list, argvW[i]);
1045 /* start the GUI */
1046 MsiSetInternalUI(InstallUILevel, NULL);
1048 Properties = build_properties( property_list );
1050 if(FunctionInstallAdmin && FunctionPatch)
1051 FunctionInstall = FALSE;
1053 ReturnCode = 1;
1054 if(FunctionInstall)
1056 if(IsProductCode(PackageName))
1057 ReturnCode = MsiConfigureProductExW(PackageName, 0, INSTALLSTATE_DEFAULT, Properties);
1058 else
1059 ReturnCode = MsiInstallProductW(PackageName, Properties);
1061 else if(FunctionRepair)
1063 if(IsProductCode(PackageName))
1064 WINE_FIXME("Product code treatment not implemented yet\n");
1065 else
1066 ReturnCode = MsiReinstallProductW(PackageName, RepairMode);
1068 else if(FunctionAdvertise)
1070 LPWSTR Transforms = build_transforms( property_list );
1071 ReturnCode = MsiAdvertiseProductW(PackageName, (LPWSTR) AdvertiseMode, Transforms, Language);
1073 else if(FunctionPatch)
1075 ReturnCode = MsiApplyPatchW(PatchFileName, PackageName, InstallType, Properties);
1077 else if(FunctionDllRegisterServer)
1079 ReturnCode = DoDllRegisterServer(DllName);
1081 else if(FunctionDllUnregisterServer)
1083 ReturnCode = DoDllUnregisterServer(DllName);
1085 else if (FunctionRegServer)
1087 ReturnCode = DoRegServer();
1089 else if (FunctionUnregServer)
1091 ReturnCode = DoUnregServer();
1093 else if (FunctionServer)
1095 ReturnCode = DoService();
1097 else if (FunctionUnknown)
1099 WINE_FIXME( "Unknown function, ignoring\n" );
1101 else
1102 ShowUsage(1);
1104 return ReturnCode;