include: Fix ASM_CFI definition.
[wine.git] / programs / msiexec / msiexec.c
blob17d4bf87cdd344fb9643495a6b404faacdd98dc8
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"
33 #include "initguid.h"
34 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
36 WINE_DEFAULT_DEBUG_CHANNEL(msiexec);
38 typedef HRESULT (WINAPI *DLLREGISTERSERVER)(void);
39 typedef HRESULT (WINAPI *DLLUNREGISTERSERVER)(void);
41 DWORD DoService(void);
43 struct string_list
45 struct string_list *next;
46 WCHAR str[1];
49 static const WCHAR ActionAdmin[] = {
50 'A','C','T','I','O','N','=','A','D','M','I','N',0 };
51 static const WCHAR RemoveAll[] = {
52 'R','E','M','O','V','E','=','A','L','L',0 };
54 static const WCHAR InstallRunOnce[] = {
55 'S','o','f','t','w','a','r','e','\\',
56 'M','i','c','r','o','s','o','f','t','\\',
57 'W','i','n','d','o','w','s','\\',
58 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
59 'I','n','s','t','a','l','l','e','r','\\',
60 'R','u','n','O','n','c','e','E','n','t','r','i','e','s',0};
62 static void ShowUsage(int ExitCode)
64 WCHAR msiexec_version[40];
65 WCHAR filename[MAX_PATH];
66 LPWSTR msi_res;
67 LPWSTR msiexec_help;
68 HMODULE hmsi = GetModuleHandleA("msi.dll");
69 DWORD len;
70 DWORD res;
72 /* MsiGetFileVersion need the full path */
73 *filename = 0;
74 res = GetModuleFileNameW(hmsi, filename, ARRAY_SIZE(filename));
75 if (!res)
76 WINE_ERR("GetModuleFileName failed: %d\n", GetLastError());
78 len = ARRAY_SIZE(msiexec_version);
79 *msiexec_version = 0;
80 res = MsiGetFileVersionW(filename, msiexec_version, &len, NULL, NULL);
81 if (res)
82 WINE_ERR("MsiGetFileVersion failed with %d\n", res);
84 /* Return the length of the resource.
85 No typo: The LPWSTR parameter must be a LPWSTR * for this mode */
86 len = LoadStringW(hmsi, 10, (LPWSTR) &msi_res, 0);
88 msi_res = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR));
89 msiexec_help = HeapAlloc(GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) + sizeof(msiexec_version));
90 if (msi_res && msiexec_help) {
91 *msi_res = 0;
92 LoadStringW(hmsi, 10, msi_res, len + 1);
94 swprintf(msiexec_help, len + 1 + ARRAY_SIZE(msiexec_version), msi_res, msiexec_version);
95 MsiMessageBoxW(0, msiexec_help, NULL, 0, GetUserDefaultLangID(), 0);
97 HeapFree(GetProcessHeap(), 0, msi_res);
98 HeapFree(GetProcessHeap(), 0, msiexec_help);
99 ExitProcess(ExitCode);
102 static BOOL IsProductCode(LPWSTR str)
104 GUID ProductCode;
106 if(lstrlenW(str) != 38)
107 return FALSE;
108 return ( (CLSIDFromString(str, &ProductCode) == NOERROR) );
112 static VOID StringListAppend(struct string_list **list, LPCWSTR str)
114 struct string_list *entry;
116 entry = HeapAlloc(GetProcessHeap(), 0, FIELD_OFFSET(struct string_list, str[lstrlenW(str) + 1]));
117 if(!entry)
119 WINE_ERR("Out of memory!\n");
120 ExitProcess(1);
122 lstrcpyW(entry->str, str);
123 entry->next = NULL;
126 * Ignoring o(n^2) time complexity to add n strings for simplicity,
127 * add the string to the end of the list to preserve the order.
129 while( *list )
130 list = &(*list)->next;
131 *list = entry;
134 static LPWSTR build_properties(struct string_list *property_list)
136 struct string_list *list;
137 LPWSTR ret, p, value;
138 DWORD len;
139 BOOL needs_quote;
141 if(!property_list)
142 return NULL;
144 /* count the space we need */
145 len = 1;
146 for(list = property_list; list; list = list->next)
147 len += lstrlenW(list->str) + 3;
149 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
151 /* add a space before each string, and quote the value */
152 p = ret;
153 for(list = property_list; list; list = list->next)
155 value = wcschr(list->str,'=');
156 if(!value)
157 continue;
158 len = value - list->str;
159 *p++ = ' ';
160 memcpy(p, list->str, len * sizeof(WCHAR));
161 p += len;
162 *p++ = '=';
164 /* check if the value contains spaces and maybe quote it */
165 value++;
166 needs_quote = wcschr(value,' ') ? 1 : 0;
167 if(needs_quote)
168 *p++ = '"';
169 len = lstrlenW(value);
170 memcpy(p, value, len * sizeof(WCHAR));
171 p += len;
172 if(needs_quote)
173 *p++ = '"';
175 *p = 0;
177 WINE_TRACE("properties -> %s\n", wine_dbgstr_w(ret) );
179 return ret;
182 static LPWSTR build_transforms(struct string_list *transform_list)
184 struct string_list *list;
185 LPWSTR ret, p;
186 DWORD len;
188 /* count the space we need */
189 len = 1;
190 for(list = transform_list; list; list = list->next)
191 len += lstrlenW(list->str) + 1;
193 ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
195 /* add all the transforms with a semicolon between each one */
196 p = ret;
197 for(list = transform_list; list; list = list->next)
199 len = lstrlenW(list->str);
200 lstrcpynW(p, list->str, len );
201 p += len;
202 if(list->next)
203 *p++ = ';';
205 *p = 0;
207 return ret;
210 static DWORD msi_atou(LPCWSTR str)
212 DWORD ret = 0;
213 while(*str >= '0' && *str <= '9')
215 ret *= 10;
216 ret += (*str - '0');
217 str++;
219 return ret;
222 /* str1 is the same as str2, ignoring case */
223 static BOOL msi_strequal(LPCWSTR str1, LPCSTR str2)
225 DWORD len, ret;
226 LPWSTR strW;
228 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
229 if( !len )
230 return FALSE;
231 if( lstrlenW(str1) != (len-1) )
232 return FALSE;
233 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
234 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
235 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len, strW, len);
236 HeapFree(GetProcessHeap(), 0, strW);
237 return (ret == CSTR_EQUAL);
240 /* prefix is hyphen or dash, and str1 is the same as str2, ignoring case */
241 static BOOL msi_option_equal(LPCWSTR str1, LPCSTR str2)
243 if (str1[0] != '/' && str1[0] != '-')
244 return FALSE;
246 /* skip over the hyphen or slash */
247 return msi_strequal(str1 + 1, str2);
250 /* str2 is at the beginning of str1, ignoring case */
251 static BOOL msi_strprefix(LPCWSTR str1, LPCSTR str2)
253 DWORD len, ret;
254 LPWSTR strW;
256 len = MultiByteToWideChar( CP_ACP, 0, str2, -1, NULL, 0);
257 if( !len )
258 return FALSE;
259 if( lstrlenW(str1) < (len-1) )
260 return FALSE;
261 strW = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
262 MultiByteToWideChar( CP_ACP, 0, str2, -1, strW, len);
263 ret = CompareStringW(GetThreadLocale(), NORM_IGNORECASE, str1, len-1, strW, len-1);
264 HeapFree(GetProcessHeap(), 0, strW);
265 return (ret == CSTR_EQUAL);
268 /* prefix is hyphen or dash, and str2 is at the beginning of str1, ignoring case */
269 static BOOL msi_option_prefix(LPCWSTR str1, LPCSTR str2)
271 if (str1[0] != '/' && str1[0] != '-')
272 return FALSE;
274 /* skip over the hyphen or slash */
275 return msi_strprefix(str1 + 1, str2);
278 static VOID *LoadProc(LPCWSTR DllName, LPCSTR ProcName, HMODULE* DllHandle)
280 VOID* (*proc)(void);
282 *DllHandle = LoadLibraryExW(DllName, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
283 if(!*DllHandle)
285 fprintf(stderr, "Unable to load dll %s\n", wine_dbgstr_w(DllName));
286 ExitProcess(1);
288 proc = (VOID *) GetProcAddress(*DllHandle, ProcName);
289 if(!proc)
291 fprintf(stderr, "Dll %s does not implement function %s\n",
292 wine_dbgstr_w(DllName), ProcName);
293 FreeLibrary(*DllHandle);
294 ExitProcess(1);
297 return proc;
300 static DWORD DoDllRegisterServer(LPCWSTR DllName)
302 HRESULT hr;
303 DLLREGISTERSERVER pfDllRegisterServer = NULL;
304 HMODULE DllHandle = NULL;
306 pfDllRegisterServer = LoadProc(DllName, "DllRegisterServer", &DllHandle);
308 hr = pfDllRegisterServer();
309 if(FAILED(hr))
311 fprintf(stderr, "Failed to register dll %s\n", wine_dbgstr_w(DllName));
312 return 1;
314 printf("Successfully registered dll %s\n", wine_dbgstr_w(DllName));
315 if(DllHandle)
316 FreeLibrary(DllHandle);
317 return 0;
320 static DWORD DoDllUnregisterServer(LPCWSTR DllName)
322 HRESULT hr;
323 DLLUNREGISTERSERVER pfDllUnregisterServer = NULL;
324 HMODULE DllHandle = NULL;
326 pfDllUnregisterServer = LoadProc(DllName, "DllUnregisterServer", &DllHandle);
328 hr = pfDllUnregisterServer();
329 if(FAILED(hr))
331 fprintf(stderr, "Failed to unregister dll %s\n", wine_dbgstr_w(DllName));
332 return 1;
334 printf("Successfully unregistered dll %s\n", wine_dbgstr_w(DllName));
335 if(DllHandle)
336 FreeLibrary(DllHandle);
337 return 0;
340 static DWORD DoRegServer(void)
342 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
343 static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c',' ','/','V',0};
344 SC_HANDLE scm, service;
345 WCHAR path[MAX_PATH+12];
346 DWORD len, ret = 0;
348 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CREATE_SERVICE)))
350 fprintf(stderr, "Failed to open the service control manager.\n");
351 return 1;
353 len = GetSystemDirectoryW(path, MAX_PATH);
354 lstrcpyW(path + len, msiexecW);
355 if ((service = CreateServiceW(scm, msiserverW, msiserverW, GENERIC_ALL,
356 SERVICE_WIN32_SHARE_PROCESS, SERVICE_DEMAND_START,
357 SERVICE_ERROR_NORMAL, path, NULL, NULL, NULL, NULL, NULL)))
359 CloseServiceHandle(service);
361 else if (GetLastError() != ERROR_SERVICE_EXISTS)
363 fprintf(stderr, "Failed to create MSI service\n");
364 ret = 1;
366 CloseServiceHandle(scm);
367 return ret;
370 static DWORD DoUnregServer(void)
372 static const WCHAR msiserverW[] = {'M','S','I','S','e','r','v','e','r',0};
373 SC_HANDLE scm, service;
374 DWORD ret = 0;
376 if (!(scm = OpenSCManagerW(NULL, SERVICES_ACTIVE_DATABASEW, SC_MANAGER_CONNECT)))
378 fprintf(stderr, "Failed to open service control manager\n");
379 return 1;
381 if ((service = OpenServiceW(scm, msiserverW, DELETE)))
383 if (!DeleteService(service))
385 fprintf(stderr, "Failed to delete MSI service\n");
386 ret = 1;
388 CloseServiceHandle(service);
390 else if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST)
392 fprintf(stderr, "Failed to open MSI service\n");
393 ret = 1;
395 CloseServiceHandle(scm);
396 return ret;
399 extern UINT CDECL __wine_msi_call_dll_function(DWORD client_pid, const GUID *guid);
401 static DWORD client_pid;
403 static DWORD CALLBACK custom_action_thread(void *arg)
405 GUID guid = *(GUID *)arg;
406 heap_free(arg);
407 return __wine_msi_call_dll_function(client_pid, &guid);
410 static int custom_action_server(const WCHAR *arg)
412 static const WCHAR pipe_name[] = {'\\','\\','.','\\','p','i','p','e','\\','m','s','i','c','a','_','%','x','_','%','d',0};
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 = wcstol(arg, NULL, 10)))
424 ERR("Invalid parameter %s\n", debugstr_w(arg));
425 return 1;
428 swprintf(buffer, ARRAY_SIZE(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;