dwrite: Check for allocation failures of glyph buffers.
[wine.git] / dlls / msi / custom.c
blobfb03958eb11565a853152763f1325450bda8350a
1 /*
2 * Custom Action processing for the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winerror.h"
28 #include "msidefs.h"
29 #include "winuser.h"
30 #include "objbase.h"
31 #include "oleauto.h"
33 #include "msipriv.h"
34 #include "winemsi.h"
35 #include "wine/asm.h"
36 #include "wine/heap.h"
37 #include "wine/debug.h"
38 #include "wine/exception.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi);
42 #define CUSTOM_ACTION_TYPE_MASK 0x3F
44 typedef struct tagMSIRUNNINGACTION
46 struct list entry;
47 HANDLE handle;
48 BOOL process;
49 LPWSTR name;
50 } MSIRUNNINGACTION;
52 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
54 static CRITICAL_SECTION msi_custom_action_cs;
55 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
57 0, 0, &msi_custom_action_cs,
58 { &msi_custom_action_cs_debug.ProcessLocksList,
59 &msi_custom_action_cs_debug.ProcessLocksList },
60 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
62 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
64 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
66 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
68 return heap_alloc(len);
71 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
73 heap_free(ptr);
76 LONG WINAPI rpc_filter(EXCEPTION_POINTERS *eptr)
78 return I_RpcExceptionFilter(eptr->ExceptionRecord->ExceptionCode);
81 UINT msi_schedule_action( MSIPACKAGE *package, UINT script, const WCHAR *action )
83 UINT count;
84 WCHAR **newbuf = NULL;
86 if (script >= SCRIPT_MAX)
88 FIXME("Unknown script requested %u\n", script);
89 return ERROR_FUNCTION_FAILED;
91 TRACE("Scheduling action %s in script %u\n", debugstr_w(action), script);
93 count = package->script_actions_count[script];
94 package->script_actions_count[script]++;
95 if (count != 0) newbuf = msi_realloc( package->script_actions[script],
96 package->script_actions_count[script] * sizeof(WCHAR *) );
97 else newbuf = msi_alloc( sizeof(WCHAR *) );
99 newbuf[count] = strdupW( action );
100 package->script_actions[script] = newbuf;
101 return ERROR_SUCCESS;
104 UINT msi_register_unique_action( MSIPACKAGE *package, const WCHAR *action )
106 UINT count;
107 WCHAR **newbuf = NULL;
109 TRACE("Registering %s as unique action\n", debugstr_w(action));
111 count = package->unique_actions_count;
112 package->unique_actions_count++;
113 if (count != 0) newbuf = msi_realloc( package->unique_actions,
114 package->unique_actions_count * sizeof(WCHAR *) );
115 else newbuf = msi_alloc( sizeof(WCHAR *) );
117 newbuf[count] = strdupW( action );
118 package->unique_actions = newbuf;
119 return ERROR_SUCCESS;
122 BOOL msi_action_is_unique( const MSIPACKAGE *package, const WCHAR *action )
124 UINT i;
126 for (i = 0; i < package->unique_actions_count; i++)
128 if (!wcscmp( package->unique_actions[i], action )) return TRUE;
130 return FALSE;
133 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
135 if ((options & msidbCustomActionTypeClientRepeat) ==
136 msidbCustomActionTypeClientRepeat)
138 if (!(package->InWhatSequence & SEQUENCE_UI &&
139 package->InWhatSequence & SEQUENCE_EXEC))
141 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
142 return FALSE;
145 else if (options & msidbCustomActionTypeFirstSequence)
147 if (package->InWhatSequence & SEQUENCE_UI &&
148 package->InWhatSequence & SEQUENCE_EXEC )
150 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
151 return FALSE;
154 else if (options & msidbCustomActionTypeOncePerProcess)
156 if (msi_action_is_unique(package, action))
158 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
159 return FALSE;
161 else
162 msi_register_unique_action(package, action);
165 return TRUE;
168 /* stores the following properties before the action:
170 * [CustomActionData<=>UserSID<=>ProductCode]Action
172 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
173 LPCWSTR usersid, LPCWSTR prodcode)
175 LPWSTR deferred;
176 DWORD len;
178 if (!actiondata)
179 return strdupW(action);
181 len = lstrlenW(action) + lstrlenW(actiondata) +
182 lstrlenW(usersid) + lstrlenW(prodcode) +
183 lstrlenW(L"[%s<=>%s<=>%s]%s") - 7;
184 deferred = msi_alloc(len * sizeof(WCHAR));
186 swprintf(deferred, len, L"[%s<=>%s<=>%s]%s", actiondata, usersid, prodcode, action);
187 return deferred;
190 static void set_deferred_action_props( MSIPACKAGE *package, const WCHAR *deferred_data )
192 const WCHAR *end, *beg = deferred_data + 1;
194 end = wcsstr(beg, L"<=>");
195 msi_set_property( package->db, L"CustomActionData", beg, end - beg );
196 beg = end + 3;
198 end = wcsstr(beg, L"<=>");
199 msi_set_property( package->db, L"UserSID", beg, end - beg );
200 beg = end + 3;
202 end = wcschr(beg, ']');
203 msi_set_property( package->db, L"ProductCode", beg, end - beg );
206 WCHAR *msi_create_temp_file( MSIDATABASE *db )
208 WCHAR *ret;
210 if (!db->tempfolder)
212 WCHAR tmp[MAX_PATH];
213 UINT len = ARRAY_SIZE( tmp );
215 if (msi_get_property( db, L"TempFolder", tmp, &len ) ||
216 GetFileAttributesW( tmp ) != FILE_ATTRIBUTE_DIRECTORY)
218 GetTempPathW( MAX_PATH, tmp );
220 if (!(db->tempfolder = strdupW( tmp ))) return NULL;
223 if ((ret = msi_alloc( (lstrlenW( db->tempfolder ) + 20) * sizeof(WCHAR) )))
225 if (!GetTempFileNameW( db->tempfolder, L"msi", 0, ret ))
227 msi_free( ret );
228 return NULL;
232 return ret;
235 static MSIBINARY *create_temp_binary(MSIPACKAGE *package, LPCWSTR source)
237 MSIRECORD *row;
238 MSIBINARY *binary = NULL;
239 HANDLE file;
240 CHAR buffer[1024];
241 WCHAR *tmpfile;
242 DWORD sz, write;
243 UINT r;
245 if (!(tmpfile = msi_create_temp_file( package->db ))) return NULL;
247 if (!(row = MSI_QueryGetRecord( package->db, L"SELECT * FROM `Binary` WHERE `Name` = '%s'", source ))) goto error;
248 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) ))) goto error;
250 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
251 if (file == INVALID_HANDLE_VALUE) goto error;
255 sz = sizeof(buffer);
256 r = MSI_RecordReadStream( row, 2, buffer, &sz );
257 if (r != ERROR_SUCCESS)
259 ERR("Failed to get stream\n");
260 break;
262 WriteFile( file, buffer, sz, &write, NULL );
263 } while (sz == sizeof buffer);
265 CloseHandle( file );
266 if (r != ERROR_SUCCESS) goto error;
268 binary->source = strdupW( source );
269 binary->tmpfile = tmpfile;
270 list_add_tail( &package->binaries, &binary->entry );
272 msiobj_release( &row->hdr );
273 return binary;
275 error:
276 if (row) msiobj_release( &row->hdr );
277 DeleteFileW( tmpfile );
278 msi_free( tmpfile );
279 msi_free( binary );
280 return NULL;
283 static MSIBINARY *get_temp_binary(MSIPACKAGE *package, LPCWSTR source)
285 MSIBINARY *binary;
287 LIST_FOR_EACH_ENTRY( binary, &package->binaries, MSIBINARY, entry )
289 if (!wcscmp( binary->source, source ))
290 return binary;
293 return create_temp_binary(package, source);
296 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
297 BOOL process, LPCWSTR name)
299 MSIRUNNINGACTION *action;
301 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
303 action->handle = Handle;
304 action->process = process;
305 action->name = strdupW(name);
307 list_add_tail( &package->RunningActions, &action->entry );
310 static UINT custom_get_process_return( HANDLE process )
312 DWORD rc = 0;
314 GetExitCodeProcess( process, &rc );
315 TRACE("exit code is %u\n", rc);
316 if (rc != 0)
317 return ERROR_FUNCTION_FAILED;
318 return ERROR_SUCCESS;
321 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
323 DWORD rc = 0;
325 GetExitCodeThread( thread, &rc );
327 switch (rc)
329 case ERROR_FUNCTION_NOT_CALLED:
330 case ERROR_SUCCESS:
331 case ERROR_INSTALL_USEREXIT:
332 case ERROR_INSTALL_FAILURE:
333 return rc;
334 case ERROR_NO_MORE_ITEMS:
335 return ERROR_SUCCESS;
336 case ERROR_INSTALL_SUSPEND:
337 ACTION_ForceReboot( package );
338 return ERROR_SUCCESS;
339 default:
340 ERR("Invalid Return Code %d\n",rc);
341 return ERROR_INSTALL_FAILURE;
345 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
346 HANDLE ProcessHandle, LPCWSTR name)
348 UINT rc = ERROR_SUCCESS;
350 if (!(type & msidbCustomActionTypeAsync))
352 TRACE("waiting for %s\n", debugstr_w(name));
354 msi_dialog_check_messages(ProcessHandle);
356 if (!(type & msidbCustomActionTypeContinue))
357 rc = custom_get_process_return(ProcessHandle);
359 CloseHandle(ProcessHandle);
361 else
363 TRACE("%s running in background\n", debugstr_w(name));
365 if (!(type & msidbCustomActionTypeContinue))
366 file_running_action(package, ProcessHandle, TRUE, name);
367 else
368 CloseHandle(ProcessHandle);
371 return rc;
374 typedef struct _msi_custom_action_info {
375 struct list entry;
376 MSIPACKAGE *package;
377 LPWSTR source;
378 LPWSTR target;
379 HANDLE handle;
380 LPWSTR action;
381 INT type;
382 GUID guid;
383 DWORD arch;
384 } msi_custom_action_info;
386 static void free_custom_action_data( msi_custom_action_info *info )
388 EnterCriticalSection( &msi_custom_action_cs );
390 list_remove( &info->entry );
391 if (info->handle)
392 CloseHandle( info->handle );
393 msi_free( info->action );
394 msi_free( info->source );
395 msi_free( info->target );
396 msiobj_release( &info->package->hdr );
397 msi_free( info );
399 LeaveCriticalSection( &msi_custom_action_cs );
402 static UINT wait_thread_handle( msi_custom_action_info *info )
404 UINT rc = ERROR_SUCCESS;
406 if (!(info->type & msidbCustomActionTypeAsync))
408 TRACE("waiting for %s\n", debugstr_w( info->action ));
410 msi_dialog_check_messages( info->handle );
412 if (!(info->type & msidbCustomActionTypeContinue))
413 rc = custom_get_thread_return( info->package, info->handle );
415 free_custom_action_data( info );
417 else
419 TRACE("%s running in background\n", debugstr_w( info->action ));
422 return rc;
425 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
427 msi_custom_action_info *info;
428 BOOL found = FALSE;
430 EnterCriticalSection( &msi_custom_action_cs );
432 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
434 if (IsEqualGUID( &info->guid, guid ))
436 found = TRUE;
437 break;
441 LeaveCriticalSection( &msi_custom_action_cs );
443 if (!found)
444 return NULL;
446 return info;
449 static void handle_msi_break(LPCSTR target)
451 char format[] = "To debug your custom action, attach your debugger to "
452 "process %i (0x%X) and press OK";
453 char val[MAX_PATH];
454 char msg[100];
456 if (!GetEnvironmentVariableA("MsiBreak", val, MAX_PATH))
457 return;
459 if (strcmp(val, target))
460 return;
462 sprintf(msg, format, GetCurrentProcessId(), GetCurrentProcessId());
463 MessageBoxA(NULL, msg, "Windows Installer", MB_OK);
464 DebugBreak();
467 #ifdef __i386__
468 /* wrapper for apps that don't declare the thread function correctly */
469 extern UINT custom_proc_wrapper( MsiCustomActionEntryPoint entry, MSIHANDLE hinst );
470 __ASM_GLOBAL_FUNC(custom_proc_wrapper,
471 "pushl %ebp\n\t"
472 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
473 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
474 "movl %esp,%ebp\n\t"
475 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
476 "subl $4,%esp\n\t"
477 "pushl 12(%ebp)\n\t"
478 "call *8(%ebp)\n\t"
479 "leave\n\t"
480 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
481 __ASM_CFI(".cfi_same_value %ebp\n\t")
482 "ret" )
483 #else
484 static UINT custom_proc_wrapper( MsiCustomActionEntryPoint entry, MSIHANDLE hinst )
486 return entry(hinst);
488 #endif
490 UINT CDECL __wine_msi_call_dll_function(DWORD client_pid, const GUID *guid)
492 MsiCustomActionEntryPoint fn;
493 MSIHANDLE remote_package = 0;
494 RPC_WSTR binding_str;
495 MSIHANDLE hPackage;
496 RPC_STATUS status;
497 LPWSTR dll = NULL;
498 LPSTR proc = NULL;
499 HANDLE hModule;
500 INT type;
501 UINT r;
503 TRACE("%s\n", debugstr_guid( guid ));
505 if (!rpc_handle)
507 WCHAR endpoint[12];
509 swprintf(endpoint, ARRAY_SIZE(endpoint), L"msi%x", client_pid);
510 status = RpcStringBindingComposeW(NULL, (WCHAR *)L"ncalrpc", NULL, endpoint, NULL, &binding_str);
511 if (status != RPC_S_OK)
513 ERR("RpcStringBindingCompose failed: %#x\n", status);
514 return status;
516 status = RpcBindingFromStringBindingW(binding_str, &rpc_handle);
517 if (status != RPC_S_OK)
519 ERR("RpcBindingFromStringBinding failed: %#x\n", status);
520 return status;
522 RpcStringFreeW(&binding_str);
525 r = remote_GetActionInfo(guid, &type, &dll, &proc, &remote_package);
526 if (r != ERROR_SUCCESS)
527 return r;
529 hPackage = alloc_msi_remote_handle( remote_package );
530 if (!hPackage)
532 ERR( "failed to create handle for %x\n", remote_package );
533 midl_user_free( dll );
534 midl_user_free( proc );
535 return ERROR_INSTALL_FAILURE;
538 hModule = LoadLibraryW( dll );
539 if (!hModule)
541 ERR( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
542 midl_user_free( dll );
543 midl_user_free( proc );
544 MsiCloseHandle( hPackage );
545 return ERROR_SUCCESS;
548 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
549 if (!fn) WARN( "GetProcAddress(%s) failed\n", debugstr_a(proc) );
550 else
552 handle_msi_break(proc);
554 __TRY
556 r = custom_proc_wrapper( fn, hPackage );
558 __EXCEPT_PAGE_FAULT
560 ERR( "Custom action (%s:%s) caused a page fault: %08x\n",
561 debugstr_w(dll), debugstr_a(proc), GetExceptionCode() );
562 r = ERROR_SUCCESS;
564 __ENDTRY;
567 FreeLibrary(hModule);
569 midl_user_free(dll);
570 midl_user_free(proc);
572 MsiCloseAllHandles();
574 return r;
577 static DWORD custom_start_server(MSIPACKAGE *package, DWORD arch)
579 WCHAR path[MAX_PATH], cmdline[MAX_PATH + 23];
580 PROCESS_INFORMATION pi = {0};
581 STARTUPINFOW si = {0};
582 WCHAR buffer[24];
583 void *cookie;
584 HANDLE pipe;
586 if ((arch == SCS_32BIT_BINARY && package->custom_server_32_process) ||
587 (arch == SCS_64BIT_BINARY && package->custom_server_64_process))
588 return ERROR_SUCCESS;
590 swprintf(buffer, ARRAY_SIZE(buffer), L"\\\\.\\pipe\\msica_%x_%d",
591 GetCurrentProcessId(), arch == SCS_32BIT_BINARY ? 32 : 64);
592 pipe = CreateNamedPipeW(buffer, PIPE_ACCESS_DUPLEX, 0, 1, sizeof(DWORD64),
593 sizeof(GUID), 0, NULL);
594 if (pipe == INVALID_HANDLE_VALUE)
595 ERR("Failed to create custom action client pipe: %u\n", GetLastError());
597 if ((sizeof(void *) == 8 || is_wow64) && arch == SCS_32BIT_BINARY)
598 GetSystemWow64DirectoryW(path, MAX_PATH - ARRAY_SIZE(L"\\msiexec.exe"));
599 else
600 GetSystemDirectoryW(path, MAX_PATH - ARRAY_SIZE(L"\\msiexec.exe"));
601 lstrcatW(path, L"\\msiexec.exe");
602 swprintf(cmdline, ARRAY_SIZE(cmdline), L"%s -Embedding %d", path, GetCurrentProcessId());
604 if (is_wow64 && arch == SCS_64BIT_BINARY)
606 Wow64DisableWow64FsRedirection(&cookie);
607 CreateProcessW(path, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
608 Wow64RevertWow64FsRedirection(cookie);
610 else
611 CreateProcessW(path, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
613 CloseHandle(pi.hThread);
615 if (arch == SCS_32BIT_BINARY)
617 package->custom_server_32_process = pi.hProcess;
618 package->custom_server_32_pipe = pipe;
620 else
622 package->custom_server_64_process = pi.hProcess;
623 package->custom_server_64_pipe = pipe;
626 if (!ConnectNamedPipe(pipe, NULL))
628 ERR("Failed to connect to custom action server: %u\n", GetLastError());
629 return GetLastError();
632 return ERROR_SUCCESS;
635 void custom_stop_server(HANDLE process, HANDLE pipe)
637 DWORD size;
639 WriteFile(pipe, &GUID_NULL, sizeof(GUID_NULL), &size, NULL);
640 WaitForSingleObject(process, INFINITE);
641 CloseHandle(process);
642 CloseHandle(pipe);
645 static DWORD WINAPI custom_client_thread(void *arg)
647 msi_custom_action_info *info = arg;
648 DWORD64 thread64;
649 HANDLE process;
650 HANDLE thread;
651 HANDLE pipe;
652 DWORD size;
653 UINT rc;
655 CoInitializeEx(NULL, COINIT_MULTITHREADED); /* needed to marshal streams */
657 if (info->arch == SCS_32BIT_BINARY)
659 process = info->package->custom_server_32_process;
660 pipe = info->package->custom_server_32_pipe;
662 else
664 process = info->package->custom_server_64_process;
665 pipe = info->package->custom_server_64_pipe;
668 EnterCriticalSection(&msi_custom_action_cs);
670 if (!WriteFile(pipe, &info->guid, sizeof(info->guid), &size, NULL) ||
671 size != sizeof(info->guid))
673 ERR("Failed to write to custom action client pipe: %u\n", GetLastError());
674 LeaveCriticalSection(&msi_custom_action_cs);
675 return GetLastError();
677 if (!ReadFile(pipe, &thread64, sizeof(thread64), &size, NULL) || size != sizeof(thread64))
679 ERR("Failed to read from custom action client pipe: %u\n", GetLastError());
680 LeaveCriticalSection(&msi_custom_action_cs);
681 return GetLastError();
684 LeaveCriticalSection(&msi_custom_action_cs);
686 if (DuplicateHandle(process, (HANDLE)(DWORD_PTR)thread64, GetCurrentProcess(),
687 &thread, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
689 WaitForSingleObject(thread, INFINITE);
690 GetExitCodeThread(thread, &rc);
691 CloseHandle(thread);
693 else
694 rc = GetLastError();
696 CoUninitialize();
697 return rc;
700 static msi_custom_action_info *do_msidbCustomActionTypeDll(
701 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
703 msi_custom_action_info *info;
704 RPC_STATUS status;
705 BOOL ret;
707 info = msi_alloc( sizeof *info );
708 if (!info)
709 return NULL;
711 msiobj_addref( &package->hdr );
712 info->package = package;
713 info->type = type;
714 info->target = strdupW( target );
715 info->source = strdupW( source );
716 info->action = strdupW( action );
717 CoCreateGuid( &info->guid );
719 EnterCriticalSection( &msi_custom_action_cs );
720 list_add_tail( &msi_pending_custom_actions, &info->entry );
721 LeaveCriticalSection( &msi_custom_action_cs );
723 if (!package->rpc_server_started)
725 WCHAR endpoint[12];
727 swprintf(endpoint, ARRAY_SIZE(endpoint), L"msi%x", GetCurrentProcessId());
728 status = RpcServerUseProtseqEpW((WCHAR *)L"ncalrpc", RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
729 endpoint, NULL);
730 if (status != RPC_S_OK)
732 ERR("RpcServerUseProtseqEp failed: %#x\n", status);
733 return NULL;
736 status = RpcServerRegisterIfEx(s_IWineMsiRemote_v0_0_s_ifspec, NULL, NULL,
737 RPC_IF_AUTOLISTEN, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
738 if (status != RPC_S_OK)
740 ERR("RpcServerRegisterIfEx failed: %#x\n", status);
741 return NULL;
744 info->package->rpc_server_started = 1;
747 ret = GetBinaryTypeW(source, &info->arch);
748 if (!ret)
749 info->arch = (sizeof(void *) == 8 ? SCS_64BIT_BINARY : SCS_32BIT_BINARY);
751 if (info->arch == SCS_64BIT_BINARY && sizeof(void *) == 4 && !is_wow64)
753 ERR("Attempt to run a 64-bit custom action inside a 32-bit WINEPREFIX.\n");
754 free_custom_action_data( info );
755 return NULL;
758 custom_start_server(package, info->arch);
760 info->handle = CreateThread(NULL, 0, custom_client_thread, info, 0, NULL);
761 if (!info->handle)
763 free_custom_action_data( info );
764 return NULL;
767 return info;
770 static UINT HANDLE_CustomType1( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
771 INT type, const WCHAR *action )
773 msi_custom_action_info *info;
774 MSIBINARY *binary;
776 if (!(binary = get_temp_binary(package, source)))
777 return ERROR_FUNCTION_FAILED;
779 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
781 if (!(info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action )))
782 return ERROR_FUNCTION_FAILED;
783 return wait_thread_handle( info );
786 static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
788 STARTUPINFOW si;
789 PROCESS_INFORMATION info;
790 WCHAR *exe = NULL, *cmd = NULL, *p;
791 BOOL ret;
793 if (app)
795 int len_arg = 0;
796 DWORD len_exe;
798 if (!(exe = msi_alloc( MAX_PATH * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
799 len_exe = SearchPathW( NULL, app, L".exe", MAX_PATH, exe, NULL );
800 if (len_exe >= MAX_PATH)
802 msi_free( exe );
803 if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
804 len_exe = SearchPathW( NULL, app, L".exe", len_exe, exe, NULL );
806 if (!len_exe)
808 ERR("can't find executable %u\n", GetLastError());
809 msi_free( exe );
810 return INVALID_HANDLE_VALUE;
813 if (arg) len_arg = lstrlenW( arg );
814 if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
816 msi_free( exe );
817 return INVALID_HANDLE_VALUE;
819 p = cmd;
820 if (wcschr( exe, ' ' ))
822 *p++ = '\"';
823 memcpy( p, exe, len_exe * sizeof(WCHAR) );
824 p += len_exe;
825 *p++ = '\"';
826 *p = 0;
828 else
830 lstrcpyW( p, exe );
831 p += len_exe;
833 if (arg)
835 *p++ = ' ';
836 memcpy( p, arg, len_arg * sizeof(WCHAR) );
837 p[len_arg] = 0;
840 memset( &si, 0, sizeof(STARTUPINFOW) );
841 ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
842 msi_free( cmd );
843 msi_free( exe );
844 if (!ret)
846 ERR("unable to execute command %u\n", GetLastError());
847 return INVALID_HANDLE_VALUE;
849 CloseHandle( info.hThread );
850 return info.hProcess;
853 static UINT HANDLE_CustomType2( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
854 INT type, const WCHAR *action )
856 MSIBINARY *binary;
857 HANDLE handle;
858 WCHAR *arg;
860 if (!(binary = get_temp_binary(package, source)))
861 return ERROR_FUNCTION_FAILED;
863 deformat_string( package, target, &arg );
864 TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
866 handle = execute_command( binary->tmpfile, arg, L"C:\\" );
867 msi_free( arg );
868 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
869 return wait_process_handle( package, type, handle, action );
872 static UINT HANDLE_CustomType17( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
873 INT type, const WCHAR *action )
875 msi_custom_action_info *info;
876 MSIFILE *file;
878 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
880 file = msi_get_loaded_file( package, source );
881 if (!file)
883 ERR("invalid file key %s\n", debugstr_w( source ));
884 return ERROR_FUNCTION_FAILED;
887 if (!(info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action )))
888 return ERROR_FUNCTION_FAILED;
889 return wait_thread_handle( info );
892 static UINT HANDLE_CustomType18( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
893 INT type, const WCHAR *action )
895 MSIFILE *file;
896 HANDLE handle;
897 WCHAR *arg;
899 if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
901 deformat_string( package, target, &arg );
902 TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
904 handle = execute_command( file->TargetPath, arg, L"C:\\" );
905 msi_free( arg );
906 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
907 return wait_process_handle( package, type, handle, action );
910 static UINT HANDLE_CustomType19( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
911 INT type, const WCHAR *action )
913 MSIRECORD *row = 0;
914 LPWSTR deformated = NULL;
916 deformat_string( package, target, &deformated );
918 /* first try treat the error as a number */
919 row = MSI_QueryGetRecord( package->db, L"SELECT `Message` FROM `Error` WHERE `Error` = '%s'", deformated );
920 if( row )
922 LPCWSTR error = MSI_RecordGetString( row, 1 );
923 if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
924 MessageBoxW( NULL, error, NULL, MB_OK );
925 msiobj_release( &row->hdr );
927 else if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
928 MessageBoxW( NULL, deformated, NULL, MB_OK );
930 msi_free( deformated );
932 return ERROR_INSTALL_FAILURE;
935 static WCHAR *build_msiexec_args( const WCHAR *filename, const WCHAR *params )
937 UINT len_filename = lstrlenW( filename ), len_params = lstrlenW( params );
938 UINT len = ARRAY_SIZE(L"/qb /i ") - 1;
939 WCHAR *ret;
941 if (!(ret = msi_alloc( (len + len_filename + len_params + 4) * sizeof(WCHAR) ))) return NULL;
942 memcpy( ret, L"/qb /i ", sizeof(L"/qb /i ") );
943 ret[len++] = '"';
944 memcpy( ret + len, filename, len_filename * sizeof(WCHAR) );
945 len += len_filename;
946 ret[len++] = '"';
947 ret[len++] = ' ';
948 lstrcpyW( ret + len, params );
949 return ret;
952 static UINT HANDLE_CustomType23( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
953 INT type, const WCHAR *action )
955 WCHAR *dir, *filename, *args, *p;
956 UINT len_dir, len_source = lstrlenW( source );
957 HANDLE handle;
959 if (!(dir = msi_dup_property( package->db, L"OriginalDatabase" ))) return ERROR_OUTOFMEMORY;
960 if (!(p = wcsrchr( dir, '\\' )) && !(p = wcsrchr( dir, '/' )))
962 msi_free( dir );
963 return ERROR_FUNCTION_FAILED;
965 *p = 0;
966 len_dir = p - dir;
967 if (!(filename = msi_alloc( (len_dir + len_source + 2) * sizeof(WCHAR) )))
969 msi_free( dir );
970 return ERROR_OUTOFMEMORY;
972 memcpy( filename, dir, len_dir * sizeof(WCHAR) );
973 filename[len_dir++] = '\\';
974 memcpy( filename + len_dir, source, len_source * sizeof(WCHAR) );
975 filename[len_dir + len_source] = 0;
977 if (!(args = build_msiexec_args( filename, target )))
979 msi_free( dir );
980 return ERROR_OUTOFMEMORY;
983 TRACE("installing %s concurrently\n", debugstr_w(source));
985 handle = execute_command( L"msiexec", args, dir );
986 msi_free( dir );
987 msi_free( args );
988 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
989 return wait_process_handle( package, type, handle, action );
992 static UINT write_substorage_to_file( MSIPACKAGE *package, const WCHAR *source, const WCHAR *filename )
994 IStorage *src = NULL, *dst = NULL;
995 UINT r = ERROR_FUNCTION_FAILED;
996 HRESULT hr;
998 hr = StgCreateDocfile( filename, STGM_CREATE|STGM_TRANSACTED|STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, &dst );
999 if (FAILED( hr ))
1001 WARN( "can't open destination storage %s (%08x)\n", debugstr_w(filename), hr );
1002 goto done;
1005 hr = IStorage_OpenStorage( package->db->storage, source, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &src );
1006 if (FAILED( hr ))
1008 WARN( "can't open source storage %s (%08x)\n", debugstr_w(source), hr );
1009 goto done;
1012 hr = IStorage_CopyTo( src, 0, NULL, NULL, dst );
1013 if (FAILED( hr ))
1015 ERR( "failed to copy storage %s (%08x)\n", debugstr_w(source), hr );
1016 goto done;
1019 hr = IStorage_Commit( dst, 0 );
1020 if (FAILED( hr ))
1021 ERR( "failed to commit storage (%08x)\n", hr );
1022 else
1023 r = ERROR_SUCCESS;
1025 done:
1026 if (src) IStorage_Release( src );
1027 if (dst) IStorage_Release( dst );
1028 return r;
1031 static UINT HANDLE_CustomType7( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1032 INT type, const WCHAR *action )
1034 WCHAR *tmpfile, *args;
1035 MSIBINARY *binary = NULL;
1036 HANDLE handle;
1037 UINT r;
1039 if (!(tmpfile = msi_create_temp_file( package->db ))) return ERROR_FUNCTION_FAILED;
1041 r = write_substorage_to_file( package, source, tmpfile );
1042 if (r != ERROR_SUCCESS)
1043 goto error;
1045 if (!(binary = msi_alloc( sizeof(*binary) ))) goto error;
1046 binary->source = NULL;
1047 binary->tmpfile = tmpfile;
1048 list_add_tail( &package->binaries, &binary->entry );
1050 if (!(args = build_msiexec_args( tmpfile, target ))) return ERROR_OUTOFMEMORY;
1052 TRACE("installing %s concurrently\n", debugstr_w(source));
1054 handle = execute_command( L"msiexec", args, L"C:\\" );
1055 msi_free( args );
1056 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
1057 return wait_process_handle( package, type, handle, action );
1059 error:
1060 DeleteFileW( tmpfile );
1061 msi_free( tmpfile );
1062 return ERROR_FUNCTION_FAILED;
1065 static UINT HANDLE_CustomType50( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1066 INT type, const WCHAR *action )
1068 WCHAR *exe, *arg;
1069 HANDLE handle;
1071 if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
1073 deformat_string( package, target, &arg );
1074 TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
1076 handle = execute_command( exe, arg, L"C:\\" );
1077 msi_free( exe );
1078 msi_free( arg );
1079 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
1080 return wait_process_handle( package, type, handle, action );
1083 static UINT HANDLE_CustomType34( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1084 INT type, const WCHAR *action )
1086 const WCHAR *workingdir = NULL;
1087 HANDLE handle;
1088 WCHAR *cmd;
1090 if (source)
1092 workingdir = msi_get_target_folder( package, source );
1093 if (!workingdir) return ERROR_FUNCTION_FAILED;
1095 deformat_string( package, target, &cmd );
1096 if (!cmd) return ERROR_FUNCTION_FAILED;
1098 TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
1100 handle = execute_command( NULL, cmd, workingdir );
1101 msi_free( cmd );
1102 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
1103 return wait_process_handle( package, type, handle, action );
1106 static DWORD ACTION_CallScript( const GUID *guid )
1108 msi_custom_action_info *info;
1109 MSIHANDLE hPackage;
1110 UINT r = ERROR_FUNCTION_FAILED;
1112 info = find_action_by_guid( guid );
1113 if (!info)
1115 ERR("failed to find action %s\n", debugstr_guid( guid) );
1116 return ERROR_FUNCTION_FAILED;
1119 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1121 hPackage = alloc_msihandle( &info->package->hdr );
1122 if (hPackage)
1124 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1125 TRACE("script returned %u\n", r);
1126 MsiCloseHandle( hPackage );
1128 else
1129 ERR("failed to create handle for %p\n", info->package );
1131 return r;
1134 static DWORD WINAPI ScriptThread( LPVOID arg )
1136 LPGUID guid = arg;
1137 DWORD rc;
1139 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1141 rc = ACTION_CallScript( guid );
1143 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1145 MsiCloseAllHandles();
1146 return rc;
1149 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1150 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1152 msi_custom_action_info *info;
1154 info = msi_alloc( sizeof *info );
1155 if (!info)
1156 return NULL;
1158 msiobj_addref( &package->hdr );
1159 info->package = package;
1160 info->type = type;
1161 info->target = strdupW( function );
1162 info->source = strdupW( script );
1163 info->action = strdupW( action );
1164 CoCreateGuid( &info->guid );
1166 EnterCriticalSection( &msi_custom_action_cs );
1167 list_add_tail( &msi_pending_custom_actions, &info->entry );
1168 LeaveCriticalSection( &msi_custom_action_cs );
1170 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1171 if (!info->handle)
1173 free_custom_action_data( info );
1174 return NULL;
1177 return info;
1180 static UINT HANDLE_CustomType37_38( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1181 INT type, const WCHAR *action )
1183 msi_custom_action_info *info;
1185 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1187 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1188 return wait_thread_handle( info );
1191 static UINT HANDLE_CustomType5_6( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1192 INT type, const WCHAR *action )
1194 MSIRECORD *row = NULL;
1195 msi_custom_action_info *info;
1196 CHAR *buffer = NULL;
1197 WCHAR *bufferw = NULL;
1198 DWORD sz = 0;
1199 UINT r;
1201 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1203 row = MSI_QueryGetRecord(package->db, L"SELECT * FROM `Binary` WHERE `Name` = '%s'", source);
1204 if (!row)
1205 return ERROR_FUNCTION_FAILED;
1207 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1208 if (r != ERROR_SUCCESS) goto done;
1210 buffer = msi_alloc( sz + 1 );
1211 if (!buffer)
1213 r = ERROR_FUNCTION_FAILED;
1214 goto done;
1217 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1218 if (r != ERROR_SUCCESS)
1219 goto done;
1221 buffer[sz] = 0;
1222 bufferw = strdupAtoW(buffer);
1223 if (!bufferw)
1225 r = ERROR_FUNCTION_FAILED;
1226 goto done;
1229 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1230 r = wait_thread_handle( info );
1232 done:
1233 msi_free(bufferw);
1234 msi_free(buffer);
1235 msiobj_release(&row->hdr);
1236 return r;
1239 static UINT HANDLE_CustomType21_22( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1240 INT type, const WCHAR *action )
1242 msi_custom_action_info *info;
1243 MSIFILE *file;
1244 HANDLE hFile;
1245 DWORD sz, szHighWord = 0, read;
1246 CHAR *buffer=NULL;
1247 WCHAR *bufferw=NULL;
1248 BOOL bRet;
1249 UINT r;
1251 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1253 file = msi_get_loaded_file(package, source);
1254 if (!file)
1256 ERR("invalid file key %s\n", debugstr_w(source));
1257 return ERROR_FUNCTION_FAILED;
1260 hFile = msi_create_file( package, file->TargetPath, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, 0 );
1261 if (hFile == INVALID_HANDLE_VALUE) return ERROR_FUNCTION_FAILED;
1263 sz = GetFileSize(hFile, &szHighWord);
1264 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1266 CloseHandle(hFile);
1267 return ERROR_FUNCTION_FAILED;
1269 buffer = msi_alloc( sz + 1 );
1270 if (!buffer)
1272 CloseHandle(hFile);
1273 return ERROR_FUNCTION_FAILED;
1275 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1276 CloseHandle(hFile);
1277 if (!bRet)
1279 r = ERROR_FUNCTION_FAILED;
1280 goto done;
1282 buffer[read] = 0;
1283 bufferw = strdupAtoW(buffer);
1284 if (!bufferw)
1286 r = ERROR_FUNCTION_FAILED;
1287 goto done;
1289 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1290 r = wait_thread_handle( info );
1292 done:
1293 msi_free(bufferw);
1294 msi_free(buffer);
1295 return r;
1298 static UINT HANDLE_CustomType53_54( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1299 INT type, const WCHAR *action )
1301 msi_custom_action_info *info;
1302 WCHAR *prop;
1304 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1306 prop = msi_dup_property( package->db, source );
1307 if (!prop) return ERROR_SUCCESS;
1309 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1310 msi_free(prop);
1311 return wait_thread_handle( info );
1314 static BOOL action_type_matches_script( UINT type, UINT script )
1316 switch (script)
1318 case SCRIPT_NONE:
1319 return FALSE;
1320 case SCRIPT_INSTALL:
1321 return !(type & msidbCustomActionTypeCommit) && !(type & msidbCustomActionTypeRollback);
1322 case SCRIPT_COMMIT:
1323 return (type & msidbCustomActionTypeCommit);
1324 case SCRIPT_ROLLBACK:
1325 return (type & msidbCustomActionTypeRollback);
1326 default:
1327 ERR("unhandled script %u\n", script);
1329 return FALSE;
1332 static UINT defer_custom_action( MSIPACKAGE *package, const WCHAR *action, UINT type )
1334 WCHAR *actiondata = msi_dup_property( package->db, action );
1335 WCHAR *usersid = msi_dup_property( package->db, L"UserSID" );
1336 WCHAR *prodcode = msi_dup_property( package->db, L"ProductCode" );
1337 WCHAR *deferred = msi_get_deferred_action( action, actiondata, usersid, prodcode );
1339 if (!deferred)
1341 msi_free( actiondata );
1342 msi_free( usersid );
1343 msi_free( prodcode );
1344 return ERROR_OUTOFMEMORY;
1346 if (type & msidbCustomActionTypeCommit)
1348 TRACE("deferring commit action\n");
1349 msi_schedule_action( package, SCRIPT_COMMIT, deferred );
1351 else if (type & msidbCustomActionTypeRollback)
1353 TRACE("deferring rollback action\n");
1354 msi_schedule_action( package, SCRIPT_ROLLBACK, deferred );
1356 else
1358 TRACE("deferring install action\n");
1359 msi_schedule_action( package, SCRIPT_INSTALL, deferred );
1362 msi_free( actiondata );
1363 msi_free( usersid );
1364 msi_free( prodcode );
1365 msi_free( deferred );
1366 return ERROR_SUCCESS;
1369 UINT ACTION_CustomAction(MSIPACKAGE *package, const WCHAR *action)
1371 UINT rc = ERROR_SUCCESS;
1372 MSIRECORD *row;
1373 UINT type;
1374 const WCHAR *source, *target, *ptr, *deferred_data = NULL;
1375 WCHAR *deformated = NULL;
1376 int len;
1378 /* deferred action: [properties]Action */
1379 if ((ptr = wcsrchr(action, ']')))
1381 deferred_data = action;
1382 action = ptr + 1;
1385 row = MSI_QueryGetRecord( package->db, L"SELECT * FROM `CustomAction` WHERE `Action` = '%s'", action );
1386 if (!row)
1387 return ERROR_FUNCTION_NOT_CALLED;
1389 type = MSI_RecordGetInteger(row,2);
1390 source = MSI_RecordGetString(row,3);
1391 target = MSI_RecordGetString(row,4);
1393 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1394 debugstr_w(source), debugstr_w(target));
1396 /* handle some of the deferred actions */
1397 if (type & msidbCustomActionTypeTSAware)
1398 FIXME("msidbCustomActionTypeTSAware not handled\n");
1400 if (type & msidbCustomActionTypeInScript)
1402 if (type & msidbCustomActionTypeNoImpersonate)
1403 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1405 if (!action_type_matches_script(type, package->script))
1407 rc = defer_custom_action( package, action, type );
1408 goto end;
1410 else
1412 LPWSTR actiondata = msi_dup_property( package->db, action );
1414 if (type & msidbCustomActionTypeInScript)
1415 package->scheduled_action_running = TRUE;
1417 if (type & msidbCustomActionTypeCommit)
1418 package->commit_action_running = TRUE;
1420 if (type & msidbCustomActionTypeRollback)
1421 package->rollback_action_running = TRUE;
1423 if (deferred_data)
1424 set_deferred_action_props(package, deferred_data);
1425 else if (actiondata)
1426 msi_set_property( package->db, L"CustomActionData", actiondata, -1 );
1427 else
1428 msi_set_property( package->db, L"CustomActionData", L"", -1 );
1430 msi_free(actiondata);
1433 else if (!check_execution_scheduling_options(package,action,type))
1435 rc = ERROR_SUCCESS;
1436 goto end;
1439 switch (type & CUSTOM_ACTION_TYPE_MASK)
1441 case 1: /* DLL file stored in a Binary table stream */
1442 rc = HANDLE_CustomType1( package, source, target, type, action );
1443 break;
1444 case 2: /* EXE file stored in a Binary table stream */
1445 rc = HANDLE_CustomType2( package, source, target, type, action );
1446 break;
1447 case 5:
1448 case 6: /* JScript/VBScript file stored in a Binary table stream */
1449 rc = HANDLE_CustomType5_6( package, source, target, type, action );
1450 break;
1451 case 7: /* Concurrent install from substorage */
1452 deformat_string( package, target, &deformated );
1453 rc = HANDLE_CustomType7( package, source, target, type, action );
1454 msi_free( deformated );
1455 break;
1456 case 17:
1457 rc = HANDLE_CustomType17( package, source, target, type, action );
1458 break;
1459 case 18: /* EXE file installed with package */
1460 rc = HANDLE_CustomType18( package, source, target, type, action );
1461 break;
1462 case 19: /* Error that halts install */
1463 rc = HANDLE_CustomType19( package, source, target, type, action );
1464 break;
1465 case 21: /* JScript/VBScript file installed with the product */
1466 case 22:
1467 rc = HANDLE_CustomType21_22( package, source, target, type, action );
1468 break;
1469 case 23: /* Installs another package in the source tree */
1470 deformat_string( package, target, &deformated );
1471 rc = HANDLE_CustomType23( package, source, deformated, type, action );
1472 msi_free( deformated );
1473 break;
1474 case 34: /* EXE to be run in specified directory */
1475 rc = HANDLE_CustomType34( package, source, target, type, action );
1476 break;
1477 case 35: /* Directory set with formatted text */
1478 deformat_string( package, target, &deformated );
1479 MSI_SetTargetPathW( package, source, deformated );
1480 msi_free( deformated );
1481 break;
1482 case 37: /* JScript/VBScript text stored in target column */
1483 case 38:
1484 rc = HANDLE_CustomType37_38( package, source, target, type, action );
1485 break;
1486 case 50: /* EXE file specified by a property value */
1487 rc = HANDLE_CustomType50( package, source, target, type, action );
1488 break;
1489 case 51: /* Property set with formatted text */
1490 if (!source) break;
1491 len = deformat_string( package, target, &deformated );
1492 rc = msi_set_property( package->db, source, deformated, len );
1493 if (rc == ERROR_SUCCESS && !wcscmp( source, L"SourceDir" )) msi_reset_source_folders( package );
1494 msi_free( deformated );
1495 break;
1496 case 53: /* JScript/VBScript text specified by a property value */
1497 case 54:
1498 rc = HANDLE_CustomType53_54( package, source, target, type, action );
1499 break;
1500 default:
1501 FIXME( "unhandled action type %u (%s %s)\n", type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
1502 debugstr_w(target) );
1505 end:
1506 package->scheduled_action_running = FALSE;
1507 package->commit_action_running = FALSE;
1508 package->rollback_action_running = FALSE;
1509 msiobj_release(&row->hdr);
1510 return rc;
1513 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1515 struct list *item;
1516 HANDLE *wait_handles;
1517 unsigned int handle_count, i;
1518 msi_custom_action_info *info, *cursor;
1520 while ((item = list_head( &package->RunningActions )))
1522 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1524 list_remove( &action->entry );
1526 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1527 msi_dialog_check_messages( action->handle );
1529 CloseHandle( action->handle );
1530 msi_free( action->name );
1531 msi_free( action );
1534 EnterCriticalSection( &msi_custom_action_cs );
1536 handle_count = list_count( &msi_pending_custom_actions );
1537 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1539 handle_count = 0;
1540 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1542 if (info->package == package )
1544 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1545 handle_count++;
1549 LeaveCriticalSection( &msi_custom_action_cs );
1551 for (i = 0; i < handle_count; i++)
1553 msi_dialog_check_messages( wait_handles[i] );
1554 CloseHandle( wait_handles[i] );
1556 msi_free( wait_handles );
1558 EnterCriticalSection( &msi_custom_action_cs );
1559 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1561 if (info->package == package)
1562 free_custom_action_data( info );
1564 LeaveCriticalSection( &msi_custom_action_cs );
1567 UINT __cdecl s_remote_GetActionInfo(const GUID *guid, int *type, LPWSTR *dll, LPSTR *func, MSIHANDLE *hinst)
1569 msi_custom_action_info *info;
1571 info = find_action_by_guid(guid);
1572 if (!info)
1573 return ERROR_INVALID_DATA;
1575 *type = info->type;
1576 *hinst = alloc_msihandle(&info->package->hdr);
1577 *dll = strdupW(info->source);
1578 *func = strdupWtoA(info->target);
1580 return ERROR_SUCCESS;