msi: Implement deferral for standard and custom actions.
[wine.git] / dlls / msi / custom.c
blob160754a91b3aaa2de04469349078631bd6770258
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 #include "config.h"
22 #include "wine/port.h"
24 #define COBJMACROS
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winerror.h"
31 #include "msidefs.h"
32 #include "winuser.h"
33 #include "objbase.h"
34 #include "oleauto.h"
36 #include "msipriv.h"
37 #include "winemsi.h"
38 #include "wine/heap.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
41 #include "wine/exception.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msi);
45 #define CUSTOM_ACTION_TYPE_MASK 0x3F
47 typedef struct tagMSIRUNNINGACTION
49 struct list entry;
50 HANDLE handle;
51 BOOL process;
52 LPWSTR name;
53 } MSIRUNNINGACTION;
55 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
57 static CRITICAL_SECTION msi_custom_action_cs;
58 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
60 0, 0, &msi_custom_action_cs,
61 { &msi_custom_action_cs_debug.ProcessLocksList,
62 &msi_custom_action_cs_debug.ProcessLocksList },
63 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
65 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
67 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
69 void __RPC_FAR * __RPC_USER MIDL_user_allocate(SIZE_T len)
71 return heap_alloc(len);
74 void __RPC_USER MIDL_user_free(void __RPC_FAR * ptr)
76 heap_free(ptr);
79 UINT msi_schedule_action( MSIPACKAGE *package, UINT script, const WCHAR *action )
81 UINT count;
82 WCHAR **newbuf = NULL;
84 if (script >= SCRIPT_MAX)
86 FIXME("Unknown script requested %u\n", script);
87 return ERROR_FUNCTION_FAILED;
89 TRACE("Scheduling action %s in script %u\n", debugstr_w(action), script);
91 count = package->script_actions_count[script];
92 package->script_actions_count[script]++;
93 if (count != 0) newbuf = msi_realloc( package->script_actions[script],
94 package->script_actions_count[script] * sizeof(WCHAR *) );
95 else newbuf = msi_alloc( sizeof(WCHAR *) );
97 newbuf[count] = strdupW( action );
98 package->script_actions[script] = newbuf;
99 return ERROR_SUCCESS;
102 UINT msi_register_unique_action( MSIPACKAGE *package, const WCHAR *action )
104 UINT count;
105 WCHAR **newbuf = NULL;
107 TRACE("Registering %s as unique action\n", debugstr_w(action));
109 count = package->unique_actions_count;
110 package->unique_actions_count++;
111 if (count != 0) newbuf = msi_realloc( package->unique_actions,
112 package->unique_actions_count * sizeof(WCHAR *) );
113 else newbuf = msi_alloc( sizeof(WCHAR *) );
115 newbuf[count] = strdupW( action );
116 package->unique_actions = newbuf;
117 return ERROR_SUCCESS;
120 BOOL msi_action_is_unique( const MSIPACKAGE *package, const WCHAR *action )
122 UINT i;
124 for (i = 0; i < package->unique_actions_count; i++)
126 if (!strcmpW( package->unique_actions[i], action )) return TRUE;
128 return FALSE;
131 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
133 if ((options & msidbCustomActionTypeClientRepeat) ==
134 msidbCustomActionTypeClientRepeat)
136 if (!(package->InWhatSequence & SEQUENCE_UI &&
137 package->InWhatSequence & SEQUENCE_EXEC))
139 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
140 return FALSE;
143 else if (options & msidbCustomActionTypeFirstSequence)
145 if (package->InWhatSequence & SEQUENCE_UI &&
146 package->InWhatSequence & SEQUENCE_EXEC )
148 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
149 return FALSE;
152 else if (options & msidbCustomActionTypeOncePerProcess)
154 if (msi_action_is_unique(package, action))
156 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
157 return FALSE;
159 else
160 msi_register_unique_action(package, action);
163 return TRUE;
166 /* stores the following properties before the action:
168 * [CustomActionData<=>UserSID<=>ProductCode]Action
170 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
171 LPCWSTR usersid, LPCWSTR prodcode)
173 LPWSTR deferred;
174 DWORD len;
176 static const WCHAR format[] = {
177 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
180 if (!actiondata)
181 return strdupW(action);
183 len = lstrlenW(action) + lstrlenW(actiondata) +
184 lstrlenW(usersid) + lstrlenW(prodcode) +
185 lstrlenW(format) - 7;
186 deferred = msi_alloc(len * sizeof(WCHAR));
188 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
189 return deferred;
192 static void set_deferred_action_props( MSIPACKAGE *package, const WCHAR *deferred_data )
194 static const WCHAR sep[] = {'<','=','>',0};
195 const WCHAR *end, *beg = deferred_data + 1;
197 end = strstrW(beg, sep);
198 msi_set_property( package->db, szCustomActionData, beg, end - beg );
199 beg = end + 3;
201 end = strstrW(beg, sep);
202 msi_set_property( package->db, szUserSID, beg, end - beg );
203 beg = end + 3;
205 end = strchrW(beg, ']');
206 msi_set_property( package->db, szProductCode, beg, end - beg );
209 WCHAR *msi_create_temp_file( MSIDATABASE *db )
211 WCHAR *ret;
213 if (!db->tempfolder)
215 WCHAR tmp[MAX_PATH];
216 UINT len = sizeof(tmp)/sizeof(tmp[0]);
218 if (msi_get_property( db, szTempFolder, tmp, &len ) ||
219 GetFileAttributesW( tmp ) != FILE_ATTRIBUTE_DIRECTORY)
221 GetTempPathW( MAX_PATH, tmp );
223 if (!(db->tempfolder = strdupW( tmp ))) return NULL;
226 if ((ret = msi_alloc( (strlenW( db->tempfolder ) + 20) * sizeof(WCHAR) )))
228 if (!GetTempFileNameW( db->tempfolder, szMsi, 0, ret ))
230 msi_free( ret );
231 return NULL;
235 return ret;
238 static MSIBINARY *create_temp_binary(MSIPACKAGE *package, LPCWSTR source)
240 static const WCHAR query[] = {
241 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
242 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
243 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
244 MSIRECORD *row;
245 MSIBINARY *binary = NULL;
246 HANDLE file;
247 CHAR buffer[1024];
248 WCHAR *tmpfile;
249 DWORD sz, write;
250 UINT r;
252 if (!(tmpfile = msi_create_temp_file( package->db ))) return NULL;
254 if (!(row = MSI_QueryGetRecord( package->db, query, source ))) goto error;
255 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) ))) goto error;
257 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
258 if (file == INVALID_HANDLE_VALUE) goto error;
262 sz = sizeof(buffer);
263 r = MSI_RecordReadStream( row, 2, buffer, &sz );
264 if (r != ERROR_SUCCESS)
266 ERR("Failed to get stream\n");
267 break;
269 WriteFile( file, buffer, sz, &write, NULL );
270 } while (sz == sizeof buffer);
272 CloseHandle( file );
273 if (r != ERROR_SUCCESS) goto error;
275 binary->source = strdupW( source );
276 binary->tmpfile = tmpfile;
277 list_add_tail( &package->binaries, &binary->entry );
279 msiobj_release( &row->hdr );
280 return binary;
282 error:
283 if (row) msiobj_release( &row->hdr );
284 DeleteFileW( tmpfile );
285 msi_free( tmpfile );
286 msi_free( binary );
287 return NULL;
290 static MSIBINARY *get_temp_binary(MSIPACKAGE *package, LPCWSTR source)
292 MSIBINARY *binary;
294 LIST_FOR_EACH_ENTRY( binary, &package->binaries, MSIBINARY, entry )
296 if (!strcmpW( binary->source, source ))
297 return binary;
300 return create_temp_binary(package, source);
303 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
304 BOOL process, LPCWSTR name)
306 MSIRUNNINGACTION *action;
308 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
310 action->handle = Handle;
311 action->process = process;
312 action->name = strdupW(name);
314 list_add_tail( &package->RunningActions, &action->entry );
317 static UINT custom_get_process_return( HANDLE process )
319 DWORD rc = 0;
321 GetExitCodeProcess( process, &rc );
322 TRACE("exit code is %u\n", rc);
323 if (rc != 0)
324 return ERROR_FUNCTION_FAILED;
325 return ERROR_SUCCESS;
328 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
330 DWORD rc = 0;
332 GetExitCodeThread( thread, &rc );
334 switch (rc)
336 case ERROR_FUNCTION_NOT_CALLED:
337 case ERROR_SUCCESS:
338 case ERROR_INSTALL_USEREXIT:
339 case ERROR_INSTALL_FAILURE:
340 return rc;
341 case ERROR_NO_MORE_ITEMS:
342 return ERROR_SUCCESS;
343 case ERROR_INSTALL_SUSPEND:
344 ACTION_ForceReboot( package );
345 return ERROR_SUCCESS;
346 default:
347 ERR("Invalid Return Code %d\n",rc);
348 return ERROR_INSTALL_FAILURE;
352 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
353 HANDLE ProcessHandle, LPCWSTR name)
355 UINT rc = ERROR_SUCCESS;
357 if (!(type & msidbCustomActionTypeAsync))
359 TRACE("waiting for %s\n", debugstr_w(name));
361 msi_dialog_check_messages(ProcessHandle);
363 if (!(type & msidbCustomActionTypeContinue))
364 rc = custom_get_process_return(ProcessHandle);
366 CloseHandle(ProcessHandle);
368 else
370 TRACE("%s running in background\n", debugstr_w(name));
372 if (!(type & msidbCustomActionTypeContinue))
373 file_running_action(package, ProcessHandle, TRUE, name);
374 else
375 CloseHandle(ProcessHandle);
378 return rc;
381 typedef struct _msi_custom_action_info {
382 struct list entry;
383 LONG refs;
384 MSIPACKAGE *package;
385 LPWSTR source;
386 LPWSTR target;
387 HANDLE handle;
388 LPWSTR action;
389 INT type;
390 GUID guid;
391 } msi_custom_action_info;
393 static void release_custom_action_data( msi_custom_action_info *info )
395 EnterCriticalSection( &msi_custom_action_cs );
397 if (!--info->refs)
399 list_remove( &info->entry );
400 if (info->handle)
401 CloseHandle( info->handle );
402 msi_free( info->action );
403 msi_free( info->source );
404 msi_free( info->target );
405 msiobj_release( &info->package->hdr );
406 msi_free( info );
409 LeaveCriticalSection( &msi_custom_action_cs );
412 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
413 static void addref_custom_action_data( msi_custom_action_info *info )
415 info->refs++;
418 static UINT wait_thread_handle( msi_custom_action_info *info )
420 UINT rc = ERROR_SUCCESS;
422 if (!(info->type & msidbCustomActionTypeAsync))
424 TRACE("waiting for %s\n", debugstr_w( info->action ));
426 msi_dialog_check_messages( info->handle );
428 if (!(info->type & msidbCustomActionTypeContinue))
429 rc = custom_get_thread_return( info->package, info->handle );
431 release_custom_action_data( info );
433 else
435 TRACE("%s running in background\n", debugstr_w( info->action ));
438 return rc;
441 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
443 msi_custom_action_info *info;
444 BOOL found = FALSE;
446 EnterCriticalSection( &msi_custom_action_cs );
448 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
450 if (IsEqualGUID( &info->guid, guid ))
452 addref_custom_action_data( info );
453 found = TRUE;
454 break;
458 LeaveCriticalSection( &msi_custom_action_cs );
460 if (!found)
461 return NULL;
463 return info;
466 static void handle_msi_break(LPCSTR target)
468 char format[] = "To debug your custom action, attach your debugger to "
469 "process %i (0x%X) and press OK";
470 char val[MAX_PATH];
471 char msg[100];
473 if (!GetEnvironmentVariableA("MsiBreak", val, MAX_PATH))
474 return;
476 if (strcasecmp(val, target))
477 return;
479 sprintf(msg, format, GetCurrentProcessId(), GetCurrentProcessId());
480 MessageBoxA(NULL, msg, "Windows Installer", MB_OK);
481 DebugBreak();
484 static WCHAR ncalrpcW[] = {'n','c','a','l','r','p','c',0};
485 static WCHAR endpoint_lrpcW[] = {'m','s','i',0};
487 #ifdef __i386__
488 /* wrapper for apps that don't declare the thread function correctly */
489 extern UINT custom_proc_wrapper( MsiCustomActionEntryPoint entry, MSIHANDLE hinst );
490 __ASM_GLOBAL_FUNC(custom_proc_wrapper,
491 "pushl %ebp\n\t"
492 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
493 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
494 "movl %esp,%ebp\n\t"
495 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
496 "subl $4,%esp\n\t"
497 "pushl 12(%ebp)\n\t"
498 "call *8(%ebp)\n\t"
499 "leave\n\t"
500 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
501 __ASM_CFI(".cfi_same_value %ebp\n\t")
502 "ret" )
503 #else
504 static UINT custom_proc_wrapper( MsiCustomActionEntryPoint entry, MSIHANDLE hinst )
506 return entry(hinst);
508 #endif
510 UINT CDECL __wine_msi_call_dll_function(const GUID *guid)
512 MsiCustomActionEntryPoint fn;
513 MSIHANDLE remote_package = 0;
514 RPC_WSTR binding_str;
515 MSIHANDLE hPackage;
516 RPC_STATUS status;
517 LPWSTR dll = NULL;
518 LPSTR proc = NULL;
519 HANDLE hModule;
520 INT type;
521 UINT r;
523 TRACE("%s\n", debugstr_guid( guid ));
525 if (!rpc_handle)
527 status = RpcStringBindingComposeW(NULL, ncalrpcW, NULL, endpoint_lrpcW, NULL, &binding_str);
528 if (status != RPC_S_OK)
530 ERR("RpcStringBindingCompose failed: %#x\n", status);
531 return status;
533 status = RpcBindingFromStringBindingW(binding_str, &rpc_handle);
534 if (status != RPC_S_OK)
536 ERR("RpcBindingFromStringBinding failed: %#x\n", status);
537 return status;
539 RpcStringFreeW(&binding_str);
542 r = remote_GetActionInfo(guid, &type, &dll, &proc, &remote_package);
543 if (r != ERROR_SUCCESS)
544 return r;
546 hModule = LoadLibraryW( dll );
547 if (!hModule)
549 ERR( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
550 return ERROR_SUCCESS;
553 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
554 if (fn)
556 hPackage = alloc_msi_remote_handle( remote_package );
557 if (hPackage)
559 TRACE("calling %s\n", debugstr_a(proc));
560 handle_msi_break(proc);
562 __TRY
564 r = custom_proc_wrapper(fn, hPackage);
566 __EXCEPT_PAGE_FAULT
568 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
569 debugstr_w(dll), debugstr_a(proc), GetExceptionCode());
570 r = ERROR_SUCCESS;
572 __ENDTRY;
574 MsiCloseHandle( hPackage );
576 else
577 ERR("failed to create handle for %x\n", remote_package );
579 else
580 ERR("GetProcAddress(%s) failed\n", debugstr_a(proc));
582 FreeLibrary(hModule);
584 midl_user_free(dll);
585 midl_user_free(proc);
587 return r;
590 static DWORD custom_start_server(MSIPACKAGE *package, DWORD arch)
592 static const WCHAR pipe_name[] = {'\\','\\','.','\\','p','i','p','e','\\','m','s','i','c','a','_','%','x',0};
593 static const WCHAR msiexecW[] = {'\\','m','s','i','e','x','e','c','.','e','x','e',0};
594 static const WCHAR argsW[] = {'%','s',' ','-','E','m','b','e','d','d','i','n','g',' ','%','d',0};
596 WCHAR path[MAX_PATH], cmdline[MAX_PATH + 23];
597 PROCESS_INFORMATION pi = {0};
598 STARTUPINFOW si = {0};
599 WCHAR buffer[24];
600 void *cookie;
601 HANDLE pipe;
602 BOOL wow64;
604 if ((arch == SCS_32BIT_BINARY && package->custom_server_32_process) ||
605 (arch == SCS_64BIT_BINARY && package->custom_server_64_process))
606 return ERROR_SUCCESS;
608 sprintfW(buffer, pipe_name, GetCurrentProcessId());
609 pipe = CreateNamedPipeW(buffer, PIPE_ACCESS_DUPLEX, 0, 1, sizeof(DWORD64),
610 sizeof(GUID), 0, NULL);
612 if (sizeof(void *) == 8 && arch == SCS_32BIT_BINARY)
613 GetSystemWow64DirectoryW(path, MAX_PATH - sizeof(msiexecW)/sizeof(WCHAR));
614 else
615 GetSystemDirectoryW(path, MAX_PATH - sizeof(msiexecW)/sizeof(WCHAR));
616 strcatW(path, msiexecW);
617 sprintfW(cmdline, argsW, path, GetCurrentProcessId());
619 if (IsWow64Process(GetCurrentProcess(), &wow64) && wow64 && arch == SCS_64BIT_BINARY)
621 Wow64DisableWow64FsRedirection(&cookie);
622 CreateProcessW(path, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
623 Wow64RevertWow64FsRedirection(cookie);
625 else
626 CreateProcessW(path, cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
628 CloseHandle(pi.hThread);
630 if (arch == SCS_32BIT_BINARY)
632 package->custom_server_32_process = pi.hProcess;
633 package->custom_server_32_pipe = pipe;
635 else
637 package->custom_server_64_process = pi.hProcess;
638 package->custom_server_64_pipe = pipe;
641 if (!ConnectNamedPipe(pipe, NULL))
643 ERR("Failed to connect to custom action server: %u\n", GetLastError());
644 return GetLastError();
647 return ERROR_SUCCESS;
650 void custom_stop_server(HANDLE process, HANDLE pipe)
652 DWORD size;
654 WriteFile(pipe, &GUID_NULL, sizeof(GUID_NULL), &size, NULL);
655 WaitForSingleObject(process, INFINITE);
656 CloseHandle(process);
657 CloseHandle(pipe);
660 static DWORD WINAPI custom_client_thread(void *arg)
662 msi_custom_action_info *info = arg;
663 RPC_STATUS status;
664 DWORD64 thread64;
665 HANDLE process;
666 HANDLE thread;
667 HANDLE pipe;
668 DWORD arch;
669 DWORD size;
670 BOOL ret;
671 UINT rc;
673 CoInitializeEx(NULL, COINIT_MULTITHREADED); /* needed to marshal streams */
675 if (!info->package->rpc_server_started)
677 status = RpcServerUseProtseqEpW(ncalrpcW, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
678 endpoint_lrpcW, NULL);
679 if (status != RPC_S_OK)
681 ERR("RpcServerUseProtseqEp failed: %#x\n", status);
682 return status;
685 status = RpcServerRegisterIfEx(s_IWineMsiRemote_v0_0_s_ifspec, NULL, NULL,
686 RPC_IF_AUTOLISTEN, RPC_C_LISTEN_MAX_CALLS_DEFAULT, NULL);
687 if (status != RPC_S_OK)
689 ERR("RpcServerRegisterIfEx failed: %#x\n", status);
690 return status;
693 info->package->rpc_server_started = 1;
696 ret = GetBinaryTypeW(info->source, &arch);
697 if (!ret)
698 arch = (sizeof(void *) == 8 ? SCS_64BIT_BINARY : SCS_32BIT_BINARY);
700 custom_start_server(info->package, arch);
701 if (arch == SCS_32BIT_BINARY)
703 process = info->package->custom_server_32_process;
704 pipe = info->package->custom_server_32_pipe;
706 else
708 process = info->package->custom_server_64_process;
709 pipe = info->package->custom_server_64_pipe;
712 if (!WriteFile(pipe, &info->guid, sizeof(info->guid), &size, NULL) ||
713 size != sizeof(info->guid))
715 ERR("Failed to write to custom action client pipe: %u\n", GetLastError());
716 return GetLastError();
718 if (!ReadFile(pipe, &thread64, sizeof(thread64), &size, NULL) || size != sizeof(thread64))
720 ERR("Failed to read from custom action client pipe: %u\n", GetLastError());
721 return GetLastError();
724 if (DuplicateHandle(process, (HANDLE)(DWORD_PTR)thread64, GetCurrentProcess(),
725 &thread, 0, FALSE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
727 WaitForSingleObject(thread, INFINITE);
728 GetExitCodeThread(thread, &rc);
729 CloseHandle(thread);
731 else
732 rc = GetLastError();
734 CoUninitialize();
735 return rc;
738 static msi_custom_action_info *do_msidbCustomActionTypeDll(
739 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
741 msi_custom_action_info *info;
743 info = msi_alloc( sizeof *info );
744 if (!info)
745 return NULL;
747 msiobj_addref( &package->hdr );
748 info->refs = 2; /* 1 for our caller and 1 for thread we created */
749 info->package = package;
750 info->type = type;
751 info->target = strdupW( target );
752 info->source = strdupW( source );
753 info->action = strdupW( action );
754 CoCreateGuid( &info->guid );
756 EnterCriticalSection( &msi_custom_action_cs );
757 list_add_tail( &msi_pending_custom_actions, &info->entry );
758 LeaveCriticalSection( &msi_custom_action_cs );
760 info->handle = CreateThread(NULL, 0, custom_client_thread, info, 0, NULL);
761 if (!info->handle)
763 /* release both references */
764 release_custom_action_data( info );
765 release_custom_action_data( info );
766 return NULL;
769 return info;
772 static UINT HANDLE_CustomType1( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
773 INT type, const WCHAR *action )
775 msi_custom_action_info *info;
776 MSIBINARY *binary;
778 if (!(binary = get_temp_binary(package, source)))
779 return ERROR_FUNCTION_FAILED;
781 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
783 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
784 return wait_thread_handle( info );
787 static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
789 static const WCHAR dotexeW[] = {'.','e','x','e',0};
790 STARTUPINFOW si;
791 PROCESS_INFORMATION info;
792 WCHAR *exe = NULL, *cmd = NULL, *p;
793 BOOL ret;
795 if (app)
797 int len_arg = 0;
798 DWORD len_exe;
800 if (!(exe = msi_alloc( MAX_PATH * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
801 len_exe = SearchPathW( NULL, app, dotexeW, MAX_PATH, exe, NULL );
802 if (len_exe >= MAX_PATH)
804 msi_free( exe );
805 if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
806 len_exe = SearchPathW( NULL, app, dotexeW, len_exe, exe, NULL );
808 if (!len_exe)
810 ERR("can't find executable %u\n", GetLastError());
811 msi_free( exe );
812 return INVALID_HANDLE_VALUE;
815 if (arg) len_arg = strlenW( arg );
816 if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
818 msi_free( exe );
819 return INVALID_HANDLE_VALUE;
821 p = cmd;
822 if (strchrW( exe, ' ' ))
824 *p++ = '\"';
825 memcpy( p, exe, len_exe * sizeof(WCHAR) );
826 p += len_exe;
827 *p++ = '\"';
828 *p = 0;
830 else
832 strcpyW( p, exe );
833 p += len_exe;
835 if (arg)
837 *p++ = ' ';
838 memcpy( p, arg, len_arg * sizeof(WCHAR) );
839 p[len_arg] = 0;
842 memset( &si, 0, sizeof(STARTUPINFOW) );
843 ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
844 msi_free( cmd );
845 msi_free( exe );
846 if (!ret)
848 ERR("unable to execute command %u\n", GetLastError());
849 return INVALID_HANDLE_VALUE;
851 CloseHandle( info.hThread );
852 return info.hProcess;
855 static UINT HANDLE_CustomType2( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
856 INT type, const WCHAR *action )
858 MSIBINARY *binary;
859 HANDLE handle;
860 WCHAR *arg;
862 if (!(binary = get_temp_binary(package, source)))
863 return ERROR_FUNCTION_FAILED;
865 deformat_string( package, target, &arg );
866 TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
868 handle = execute_command( binary->tmpfile, arg, szCRoot );
869 msi_free( arg );
870 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
871 return wait_process_handle( package, type, handle, action );
874 static UINT HANDLE_CustomType17( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
875 INT type, const WCHAR *action )
877 msi_custom_action_info *info;
878 MSIFILE *file;
880 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
882 file = msi_get_loaded_file( package, source );
883 if (!file)
885 ERR("invalid file key %s\n", debugstr_w( source ));
886 return ERROR_FUNCTION_FAILED;
889 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
890 return wait_thread_handle( info );
893 static UINT HANDLE_CustomType18( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
894 INT type, const WCHAR *action )
896 MSIFILE *file;
897 HANDLE handle;
898 WCHAR *arg;
900 if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
902 deformat_string( package, target, &arg );
903 TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
905 handle = execute_command( file->TargetPath, arg, szCRoot );
906 msi_free( arg );
907 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
908 return wait_process_handle( package, type, handle, action );
911 static UINT HANDLE_CustomType19( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
912 INT type, const WCHAR *action )
914 static const WCHAR query[] = {
915 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
916 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
917 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
918 '%','s',0
920 MSIRECORD *row = 0;
921 LPWSTR deformated = NULL;
923 deformat_string( package, target, &deformated );
925 /* first try treat the error as a number */
926 row = MSI_QueryGetRecord( package->db, query, deformated );
927 if( row )
929 LPCWSTR error = MSI_RecordGetString( row, 1 );
930 if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
931 MessageBoxW( NULL, error, NULL, MB_OK );
932 msiobj_release( &row->hdr );
934 else if ((package->ui_level & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
935 MessageBoxW( NULL, deformated, NULL, MB_OK );
937 msi_free( deformated );
939 return ERROR_INSTALL_FAILURE;
942 static UINT HANDLE_CustomType23( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
943 INT type, const WCHAR *action )
945 static const WCHAR msiexecW[] = {'m','s','i','e','x','e','c',0};
946 static const WCHAR paramsW[] = {'/','q','b',' ','/','i',' '};
947 WCHAR *dir, *arg, *p;
948 UINT len_src, len_dir, len_tgt, len = sizeof(paramsW)/sizeof(paramsW[0]);
949 HANDLE handle;
951 if (!(dir = msi_dup_property( package->db, szOriginalDatabase ))) return ERROR_OUTOFMEMORY;
952 if (!(p = strrchrW( dir, '\\' )) && !(p = strrchrW( dir, '/' )))
954 msi_free( dir );
955 return ERROR_FUNCTION_FAILED;
957 *p = 0;
958 len_dir = p - dir;
959 len_src = strlenW( source );
960 len_tgt = strlenW( target );
961 if (!(arg = msi_alloc( (len + len_dir + len_src + len_tgt + 5) * sizeof(WCHAR) )))
963 msi_free( dir );
964 return ERROR_OUTOFMEMORY;
966 memcpy( arg, paramsW, sizeof(paramsW) );
967 arg[len++] = '"';
968 memcpy( arg + len, dir, len_dir * sizeof(WCHAR) );
969 len += len_dir;
970 arg[len++] = '\\';
971 memcpy( arg + len, source, len_src * sizeof(WCHAR) );
972 len += len_src;
973 arg[len++] = '"';
974 arg[len++] = ' ';
975 strcpyW( arg + len, target );
977 TRACE("installing %s concurrently\n", debugstr_w(source));
979 handle = execute_command( msiexecW, arg, dir );
980 msi_free( dir );
981 msi_free( arg );
982 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
983 return wait_process_handle( package, type, handle, action );
986 static UINT HANDLE_CustomType50( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
987 INT type, const WCHAR *action )
989 WCHAR *exe, *arg;
990 HANDLE handle;
992 if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
994 deformat_string( package, target, &arg );
995 TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
997 handle = execute_command( exe, arg, szCRoot );
998 msi_free( exe );
999 msi_free( arg );
1000 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
1001 return wait_process_handle( package, type, handle, action );
1004 static UINT HANDLE_CustomType34( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1005 INT type, const WCHAR *action )
1007 const WCHAR *workingdir = NULL;
1008 HANDLE handle;
1009 WCHAR *cmd;
1011 if (source)
1013 workingdir = msi_get_target_folder( package, source );
1014 if (!workingdir) return ERROR_FUNCTION_FAILED;
1016 deformat_string( package, target, &cmd );
1017 if (!cmd) return ERROR_FUNCTION_FAILED;
1019 TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
1021 handle = execute_command( NULL, cmd, workingdir );
1022 msi_free( cmd );
1023 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
1024 return wait_process_handle( package, type, handle, action );
1027 static DWORD ACTION_CallScript( const GUID *guid )
1029 msi_custom_action_info *info;
1030 MSIHANDLE hPackage;
1031 UINT r = ERROR_FUNCTION_FAILED;
1033 info = find_action_by_guid( guid );
1034 if (!info)
1036 ERR("failed to find action %s\n", debugstr_guid( guid) );
1037 return ERROR_FUNCTION_FAILED;
1040 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1042 hPackage = alloc_msihandle( &info->package->hdr );
1043 if (hPackage)
1045 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1046 TRACE("script returned %u\n", r);
1047 MsiCloseHandle( hPackage );
1049 else
1050 ERR("failed to create handle for %p\n", info->package );
1052 release_custom_action_data( info );
1053 return r;
1056 static DWORD WINAPI ScriptThread( LPVOID arg )
1058 LPGUID guid = arg;
1059 DWORD rc;
1061 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1063 rc = ACTION_CallScript( guid );
1065 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1067 MsiCloseAllHandles();
1068 return rc;
1071 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1072 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1074 msi_custom_action_info *info;
1076 info = msi_alloc( sizeof *info );
1077 if (!info)
1078 return NULL;
1080 msiobj_addref( &package->hdr );
1081 info->refs = 2; /* 1 for our caller and 1 for thread we created */
1082 info->package = package;
1083 info->type = type;
1084 info->target = strdupW( function );
1085 info->source = strdupW( script );
1086 info->action = strdupW( action );
1087 CoCreateGuid( &info->guid );
1089 EnterCriticalSection( &msi_custom_action_cs );
1090 list_add_tail( &msi_pending_custom_actions, &info->entry );
1091 LeaveCriticalSection( &msi_custom_action_cs );
1093 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1094 if (!info->handle)
1096 /* release both references */
1097 release_custom_action_data( info );
1098 release_custom_action_data( info );
1099 return NULL;
1102 return info;
1105 static UINT HANDLE_CustomType37_38( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1106 INT type, const WCHAR *action )
1108 msi_custom_action_info *info;
1110 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1112 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1113 return wait_thread_handle( info );
1116 static UINT HANDLE_CustomType5_6( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1117 INT type, const WCHAR *action )
1119 static const WCHAR query[] = {
1120 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1121 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1122 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1123 MSIRECORD *row = NULL;
1124 msi_custom_action_info *info;
1125 CHAR *buffer = NULL;
1126 WCHAR *bufferw = NULL;
1127 DWORD sz = 0;
1128 UINT r;
1130 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1132 row = MSI_QueryGetRecord(package->db, query, source);
1133 if (!row)
1134 return ERROR_FUNCTION_FAILED;
1136 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1137 if (r != ERROR_SUCCESS) goto done;
1139 buffer = msi_alloc( sz + 1 );
1140 if (!buffer)
1142 r = ERROR_FUNCTION_FAILED;
1143 goto done;
1146 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1147 if (r != ERROR_SUCCESS)
1148 goto done;
1150 buffer[sz] = 0;
1151 bufferw = strdupAtoW(buffer);
1152 if (!bufferw)
1154 r = ERROR_FUNCTION_FAILED;
1155 goto done;
1158 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1159 r = wait_thread_handle( info );
1161 done:
1162 msi_free(bufferw);
1163 msi_free(buffer);
1164 msiobj_release(&row->hdr);
1165 return r;
1168 static UINT HANDLE_CustomType21_22( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1169 INT type, const WCHAR *action )
1171 msi_custom_action_info *info;
1172 MSIFILE *file;
1173 HANDLE hFile;
1174 DWORD sz, szHighWord = 0, read;
1175 CHAR *buffer=NULL;
1176 WCHAR *bufferw=NULL;
1177 BOOL bRet;
1178 UINT r;
1180 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1182 file = msi_get_loaded_file(package, source);
1183 if (!file)
1185 ERR("invalid file key %s\n", debugstr_w(source));
1186 return ERROR_FUNCTION_FAILED;
1189 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1190 if (hFile == INVALID_HANDLE_VALUE) return ERROR_FUNCTION_FAILED;
1192 sz = GetFileSize(hFile, &szHighWord);
1193 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1195 CloseHandle(hFile);
1196 return ERROR_FUNCTION_FAILED;
1198 buffer = msi_alloc( sz + 1 );
1199 if (!buffer)
1201 CloseHandle(hFile);
1202 return ERROR_FUNCTION_FAILED;
1204 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1205 CloseHandle(hFile);
1206 if (!bRet)
1208 r = ERROR_FUNCTION_FAILED;
1209 goto done;
1211 buffer[read] = 0;
1212 bufferw = strdupAtoW(buffer);
1213 if (!bufferw)
1215 r = ERROR_FUNCTION_FAILED;
1216 goto done;
1218 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1219 r = wait_thread_handle( info );
1221 done:
1222 msi_free(bufferw);
1223 msi_free(buffer);
1224 return r;
1227 static UINT HANDLE_CustomType53_54( MSIPACKAGE *package, const WCHAR *source, const WCHAR *target,
1228 INT type, const WCHAR *action )
1230 msi_custom_action_info *info;
1231 WCHAR *prop;
1233 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1235 prop = msi_dup_property( package->db, source );
1236 if (!prop) return ERROR_SUCCESS;
1238 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1239 msi_free(prop);
1240 return wait_thread_handle( info );
1243 static BOOL action_type_matches_script( UINT type, UINT script )
1245 switch (script)
1247 case SCRIPT_NONE:
1248 return FALSE;
1249 case SCRIPT_INSTALL:
1250 return !(type & msidbCustomActionTypeCommit) && !(type & msidbCustomActionTypeRollback);
1251 case SCRIPT_COMMIT:
1252 return (type & msidbCustomActionTypeCommit);
1253 case SCRIPT_ROLLBACK:
1254 return (type & msidbCustomActionTypeRollback);
1255 default:
1256 ERR("unhandled script %u\n", script);
1258 return FALSE;
1261 static UINT defer_custom_action( MSIPACKAGE *package, const WCHAR *action, UINT type )
1263 WCHAR *actiondata = msi_dup_property( package->db, action );
1264 WCHAR *usersid = msi_dup_property( package->db, szUserSID );
1265 WCHAR *prodcode = msi_dup_property( package->db, szProductCode );
1266 WCHAR *deferred = msi_get_deferred_action( action, actiondata, usersid, prodcode );
1268 if (!deferred)
1270 msi_free( actiondata );
1271 msi_free( usersid );
1272 msi_free( prodcode );
1273 return ERROR_OUTOFMEMORY;
1275 if (type & msidbCustomActionTypeCommit)
1277 TRACE("deferring commit action\n");
1278 msi_schedule_action( package, SCRIPT_COMMIT, deferred );
1280 else if (type & msidbCustomActionTypeRollback)
1282 TRACE("deferring rollback action\n");
1283 msi_schedule_action( package, SCRIPT_ROLLBACK, deferred );
1285 else
1287 TRACE("deferring install action\n");
1288 msi_schedule_action( package, SCRIPT_INSTALL, deferred );
1291 msi_free( actiondata );
1292 msi_free( usersid );
1293 msi_free( prodcode );
1294 msi_free( deferred );
1295 return ERROR_SUCCESS;
1298 UINT ACTION_CustomAction(MSIPACKAGE *package, const WCHAR *action)
1300 static const WCHAR query[] = {
1301 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1302 '`','C','u','s','t','o','m','A','c','t','i','o','n','`',' ','W','H','E','R','E',' ',
1303 '`','A','c','t','i' ,'o','n','`',' ','=',' ','\'','%','s','\'',0};
1304 UINT rc = ERROR_SUCCESS;
1305 MSIRECORD *row;
1306 UINT type;
1307 const WCHAR *source, *target, *ptr, *deferred_data = NULL;
1308 WCHAR *deformated = NULL;
1309 int len;
1311 /* deferred action: [properties]Action */
1312 if ((ptr = strrchrW(action, ']')))
1314 deferred_data = action;
1315 action = ptr + 1;
1318 row = MSI_QueryGetRecord( package->db, query, action );
1319 if (!row)
1320 return ERROR_FUNCTION_NOT_CALLED;
1322 type = MSI_RecordGetInteger(row,2);
1323 source = MSI_RecordGetString(row,3);
1324 target = MSI_RecordGetString(row,4);
1326 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1327 debugstr_w(source), debugstr_w(target));
1329 /* handle some of the deferred actions */
1330 if (type & msidbCustomActionTypeTSAware)
1331 FIXME("msidbCustomActionTypeTSAware not handled\n");
1333 if (type & msidbCustomActionTypeInScript)
1335 if (type & msidbCustomActionTypeNoImpersonate)
1336 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1338 if (!action_type_matches_script(type, package->script))
1340 rc = defer_custom_action( package, action, type );
1341 goto end;
1343 else
1345 LPWSTR actiondata = msi_dup_property( package->db, action );
1347 if (type & msidbCustomActionTypeInScript)
1348 package->scheduled_action_running = TRUE;
1350 if (type & msidbCustomActionTypeCommit)
1351 package->commit_action_running = TRUE;
1353 if (type & msidbCustomActionTypeRollback)
1354 package->rollback_action_running = TRUE;
1356 if (deferred_data)
1357 set_deferred_action_props(package, deferred_data);
1358 else if (actiondata)
1359 msi_set_property( package->db, szCustomActionData, actiondata, -1 );
1360 else
1361 msi_set_property( package->db, szCustomActionData, szEmpty, -1 );
1363 msi_free(actiondata);
1366 else if (!check_execution_scheduling_options(package,action,type))
1368 rc = ERROR_SUCCESS;
1369 goto end;
1372 switch (type & CUSTOM_ACTION_TYPE_MASK)
1374 case 1: /* DLL file stored in a Binary table stream */
1375 rc = HANDLE_CustomType1(package,source,target,type,action);
1376 break;
1377 case 2: /* EXE file stored in a Binary table stream */
1378 rc = HANDLE_CustomType2(package,source,target,type,action);
1379 break;
1380 case 18: /*EXE file installed with package */
1381 rc = HANDLE_CustomType18(package,source,target,type,action);
1382 break;
1383 case 19: /* Error that halts install */
1384 rc = HANDLE_CustomType19(package,source,target,type,action);
1385 break;
1386 case 17:
1387 rc = HANDLE_CustomType17(package,source,target,type,action);
1388 break;
1389 case 23: /* installs another package in the source tree */
1390 deformat_string(package,target,&deformated);
1391 rc = HANDLE_CustomType23(package,source,deformated,type,action);
1392 msi_free(deformated);
1393 break;
1394 case 50: /*EXE file specified by a property value */
1395 rc = HANDLE_CustomType50(package,source,target,type,action);
1396 break;
1397 case 34: /*EXE to be run in specified directory */
1398 rc = HANDLE_CustomType34(package,source,target,type,action);
1399 break;
1400 case 35: /* Directory set with formatted text. */
1401 deformat_string(package,target,&deformated);
1402 MSI_SetTargetPathW(package, source, deformated);
1403 msi_free(deformated);
1404 break;
1405 case 51: /* Property set with formatted text. */
1406 if (!source)
1407 break;
1409 len = deformat_string( package, target, &deformated );
1410 rc = msi_set_property( package->db, source, deformated, len );
1411 if (rc == ERROR_SUCCESS && !strcmpW( source, szSourceDir ))
1412 msi_reset_folders( package, TRUE );
1413 msi_free(deformated);
1414 break;
1415 case 37: /* JScript/VBScript text stored in target column. */
1416 case 38:
1417 rc = HANDLE_CustomType37_38(package,source,target,type,action);
1418 break;
1419 case 5:
1420 case 6: /* JScript/VBScript file stored in a Binary table stream. */
1421 rc = HANDLE_CustomType5_6(package,source,target,type,action);
1422 break;
1423 case 21: /* JScript/VBScript file installed with the product. */
1424 case 22:
1425 rc = HANDLE_CustomType21_22(package,source,target,type,action);
1426 break;
1427 case 53: /* JScript/VBScript text specified by a property value. */
1428 case 54:
1429 rc = HANDLE_CustomType53_54(package,source,target,type,action);
1430 break;
1431 default:
1432 FIXME("unhandled action type %u (%s %s)\n", type & CUSTOM_ACTION_TYPE_MASK,
1433 debugstr_w(source), debugstr_w(target));
1436 end:
1437 package->scheduled_action_running = FALSE;
1438 package->commit_action_running = FALSE;
1439 package->rollback_action_running = FALSE;
1440 msiobj_release(&row->hdr);
1441 return rc;
1444 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1446 struct list *item;
1447 HANDLE *wait_handles;
1448 unsigned int handle_count, i;
1449 msi_custom_action_info *info, *cursor;
1451 while ((item = list_head( &package->RunningActions )))
1453 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1455 list_remove( &action->entry );
1457 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1458 msi_dialog_check_messages( action->handle );
1460 CloseHandle( action->handle );
1461 msi_free( action->name );
1462 msi_free( action );
1465 EnterCriticalSection( &msi_custom_action_cs );
1467 handle_count = list_count( &msi_pending_custom_actions );
1468 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1470 handle_count = 0;
1471 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1473 if (info->package == package )
1475 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1476 handle_count++;
1480 LeaveCriticalSection( &msi_custom_action_cs );
1482 for (i = 0; i < handle_count; i++)
1484 msi_dialog_check_messages( wait_handles[i] );
1485 CloseHandle( wait_handles[i] );
1487 msi_free( wait_handles );
1489 EnterCriticalSection( &msi_custom_action_cs );
1490 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1492 if (info->package == package) release_custom_action_data( info );
1494 LeaveCriticalSection( &msi_custom_action_cs );
1497 UINT __cdecl s_remote_GetActionInfo(const GUID *guid, int *type, LPWSTR *dll, LPSTR *func, MSIHANDLE *hinst)
1499 msi_custom_action_info *info;
1501 info = find_action_by_guid(guid);
1502 if (!info)
1503 return ERROR_INVALID_DATA;
1505 *type = info->type;
1506 *hinst = alloc_msihandle(&info->package->hdr);
1507 *dll = strdupW(info->source);
1508 *func = strdupWtoA(info->target);
1510 release_custom_action_data(info);
1511 return ERROR_SUCCESS;