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
27 #define WIN32_NO_STATUS
39 #include "wine/debug.h"
40 #include "wine/exception.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
44 #define CUSTOM_ACTION_TYPE_MASK 0x3F
54 typedef UINT (WINAPI
*MsiCustomActionEntryPoint
)( MSIHANDLE
);
56 static CRITICAL_SECTION custom_action_cs
;
57 static CRITICAL_SECTION_DEBUG custom_action_cs_debug
=
59 0, 0, &custom_action_cs
,
60 { &custom_action_cs_debug
.ProcessLocksList
,
61 &custom_action_cs_debug
.ProcessLocksList
},
62 0, 0, { (DWORD_PTR
)(__FILE__
": custom_action_cs") }
64 static CRITICAL_SECTION custom_action_cs
= { &custom_action_cs_debug
, -1, 0, 0, 0, 0 };
66 static struct list pending_custom_actions
= LIST_INIT( pending_custom_actions
);
68 void __RPC_FAR
* __RPC_USER
MIDL_user_allocate(SIZE_T len
)
73 void __RPC_USER
MIDL_user_free(void __RPC_FAR
* ptr
)
78 LONG WINAPI
rpc_filter(EXCEPTION_POINTERS
*eptr
)
80 return I_RpcExceptionFilter(eptr
->ExceptionRecord
->ExceptionCode
);
83 UINT
msi_schedule_action( MSIPACKAGE
*package
, UINT script
, const WCHAR
*action
)
86 WCHAR
**newbuf
= NULL
;
88 if (script
>= SCRIPT_MAX
)
90 FIXME("Unknown script requested %u\n", script
);
91 return ERROR_FUNCTION_FAILED
;
93 TRACE("Scheduling action %s in script %u\n", debugstr_w(action
), script
);
95 count
= package
->script_actions_count
[script
];
96 package
->script_actions_count
[script
]++;
97 if (count
!= 0) newbuf
= realloc( package
->script_actions
[script
],
98 package
->script_actions_count
[script
] * sizeof(WCHAR
*) );
99 else newbuf
= malloc( sizeof(WCHAR
*) );
101 newbuf
[count
] = wcsdup( action
);
102 package
->script_actions
[script
] = newbuf
;
103 return ERROR_SUCCESS
;
106 UINT
msi_register_unique_action( MSIPACKAGE
*package
, const WCHAR
*action
)
109 WCHAR
**newbuf
= NULL
;
111 TRACE("Registering %s as unique action\n", debugstr_w(action
));
113 count
= package
->unique_actions_count
;
114 package
->unique_actions_count
++;
115 if (count
!= 0) newbuf
= realloc( package
->unique_actions
,
116 package
->unique_actions_count
* sizeof(WCHAR
*) );
117 else newbuf
= malloc( sizeof(WCHAR
*) );
119 newbuf
[count
] = wcsdup( action
);
120 package
->unique_actions
= newbuf
;
121 return ERROR_SUCCESS
;
124 BOOL
msi_action_is_unique( const MSIPACKAGE
*package
, const WCHAR
*action
)
128 for (i
= 0; i
< package
->unique_actions_count
; i
++)
130 if (!wcscmp( package
->unique_actions
[i
], action
)) return TRUE
;
135 static BOOL
check_execution_scheduling_options(MSIPACKAGE
*package
, LPCWSTR action
, UINT options
)
137 if ((options
& msidbCustomActionTypeClientRepeat
) ==
138 msidbCustomActionTypeClientRepeat
)
140 if (!(package
->InWhatSequence
& SEQUENCE_UI
&&
141 package
->InWhatSequence
& SEQUENCE_EXEC
))
143 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
147 else if (options
& msidbCustomActionTypeFirstSequence
)
149 if (package
->InWhatSequence
& SEQUENCE_UI
&&
150 package
->InWhatSequence
& SEQUENCE_EXEC
)
152 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
156 else if (options
& msidbCustomActionTypeOncePerProcess
)
158 if (msi_action_is_unique(package
, action
))
160 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
164 msi_register_unique_action(package
, action
);
170 /* stores the following properties before the action:
172 * [CustomActionData<=>UserSID<=>ProductCode]Action
174 static WCHAR
*get_deferred_action(const WCHAR
*action
, const WCHAR
*actiondata
, const WCHAR
*usersid
,
175 const WCHAR
*prodcode
)
181 return wcsdup(action
);
183 len
= lstrlenW(action
) + lstrlenW(actiondata
) +
184 lstrlenW(usersid
) + lstrlenW(prodcode
) +
185 lstrlenW(L
"[%s<=>%s<=>%s]%s") - 7;
186 deferred
= malloc(len
* sizeof(WCHAR
));
188 swprintf(deferred
, len
, L
"[%s<=>%s<=>%s]%s", actiondata
, usersid
, prodcode
, action
);
192 static void set_deferred_action_props( MSIPACKAGE
*package
, const WCHAR
*deferred_data
)
194 const WCHAR
*end
, *beg
= deferred_data
+ 1;
196 end
= wcsstr(beg
, L
"<=>");
197 msi_set_property( package
->db
, L
"CustomActionData", beg
, end
- beg
);
200 end
= wcsstr(beg
, L
"<=>");
201 msi_set_property( package
->db
, L
"UserSID", beg
, end
- beg
);
204 end
= wcschr(beg
, ']');
205 msi_set_property( package
->db
, L
"ProductCode", beg
, end
- beg
);
208 WCHAR
*msi_create_temp_file( MSIDATABASE
*db
)
215 DWORD len
= ARRAY_SIZE( tmp
);
217 if (msi_get_property( db
, L
"TempFolder", tmp
, &len
) ||
218 GetFileAttributesW( tmp
) != FILE_ATTRIBUTE_DIRECTORY
)
220 GetTempPathW( MAX_PATH
, tmp
);
222 if (!(db
->tempfolder
= wcsdup( tmp
))) return NULL
;
225 if ((ret
= malloc( (wcslen( db
->tempfolder
) + 20) * sizeof(WCHAR
) )))
227 if (!GetTempFileNameW( db
->tempfolder
, L
"msi", 0, ret
))
237 static MSIBINARY
*create_temp_binary(MSIPACKAGE
*package
, LPCWSTR source
)
240 MSIBINARY
*binary
= NULL
;
247 if (!(tmpfile
= msi_create_temp_file( package
->db
))) return NULL
;
249 if (!(row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", source
))) goto error
;
250 if (!(binary
= calloc( 1, sizeof(MSIBINARY
) ))) goto error
;
252 file
= CreateFileW( tmpfile
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
253 if (file
== INVALID_HANDLE_VALUE
) goto error
;
258 r
= MSI_RecordReadStream( row
, 2, buffer
, &sz
);
259 if (r
!= ERROR_SUCCESS
)
261 ERR("Failed to get stream\n");
264 WriteFile( file
, buffer
, sz
, &write
, NULL
);
265 } while (sz
== sizeof buffer
);
268 if (r
!= ERROR_SUCCESS
) goto error
;
270 binary
->source
= wcsdup( source
);
271 binary
->tmpfile
= tmpfile
;
272 list_add_tail( &package
->binaries
, &binary
->entry
);
274 msiobj_release( &row
->hdr
);
278 if (row
) msiobj_release( &row
->hdr
);
279 DeleteFileW( tmpfile
);
285 static MSIBINARY
*get_temp_binary(MSIPACKAGE
*package
, LPCWSTR source
)
289 LIST_FOR_EACH_ENTRY( binary
, &package
->binaries
, MSIBINARY
, entry
)
291 if (!wcscmp( binary
->source
, source
))
295 return create_temp_binary(package
, source
);
298 static void file_running_action(MSIPACKAGE
* package
, HANDLE Handle
,
299 BOOL process
, LPCWSTR name
)
301 struct running_action
*action
;
303 action
= malloc( sizeof(*action
) );
305 action
->handle
= Handle
;
306 action
->process
= process
;
307 action
->name
= wcsdup(name
);
309 list_add_tail( &package
->RunningActions
, &action
->entry
);
312 static UINT
custom_get_process_return( HANDLE process
)
316 GetExitCodeProcess( process
, &rc
);
317 TRACE( "exit code is %lu\n", rc
);
319 return ERROR_FUNCTION_FAILED
;
320 return ERROR_SUCCESS
;
323 static UINT
custom_get_thread_return( MSIPACKAGE
*package
, HANDLE thread
)
327 GetExitCodeThread( thread
, &rc
);
331 case ERROR_FUNCTION_NOT_CALLED
:
333 case ERROR_INSTALL_USEREXIT
:
334 case ERROR_INSTALL_FAILURE
:
336 case ERROR_NO_MORE_ITEMS
:
337 return ERROR_SUCCESS
;
338 case ERROR_INSTALL_SUSPEND
:
339 ACTION_ForceReboot( package
);
340 return ERROR_SUCCESS
;
342 ERR( "invalid Return Code %lu\n", rc
);
343 return ERROR_INSTALL_FAILURE
;
347 static UINT
wait_process_handle(MSIPACKAGE
* package
, UINT type
,
348 HANDLE ProcessHandle
, LPCWSTR name
)
350 UINT rc
= ERROR_SUCCESS
;
352 if (!(type
& msidbCustomActionTypeAsync
))
354 TRACE("waiting for %s\n", debugstr_w(name
));
356 msi_dialog_check_messages(ProcessHandle
);
358 if (!(type
& msidbCustomActionTypeContinue
))
359 rc
= custom_get_process_return(ProcessHandle
);
361 CloseHandle(ProcessHandle
);
365 TRACE("%s running in background\n", debugstr_w(name
));
367 if (!(type
& msidbCustomActionTypeContinue
))
368 file_running_action(package
, ProcessHandle
, TRUE
, name
);
370 CloseHandle(ProcessHandle
);
387 } custom_action_info
;
389 static void free_custom_action_data( custom_action_info
*info
)
391 EnterCriticalSection( &custom_action_cs
);
393 list_remove( &info
->entry
);
395 CloseHandle( info
->handle
);
396 free( info
->action
);
397 free( info
->source
);
398 free( info
->target
);
399 msiobj_release( &info
->package
->hdr
);
402 LeaveCriticalSection( &custom_action_cs
);
405 static UINT
wait_thread_handle( custom_action_info
*info
)
407 UINT rc
= ERROR_SUCCESS
;
409 if (!(info
->type
& msidbCustomActionTypeAsync
))
411 TRACE("waiting for %s\n", debugstr_w( info
->action
));
413 msi_dialog_check_messages( info
->handle
);
415 if (!(info
->type
& msidbCustomActionTypeContinue
))
416 rc
= custom_get_thread_return( info
->package
, info
->handle
);
418 free_custom_action_data( info
);
422 TRACE("%s running in background\n", debugstr_w( info
->action
));
428 static custom_action_info
*find_action_by_guid( const GUID
*guid
)
430 custom_action_info
*info
;
433 EnterCriticalSection( &custom_action_cs
);
435 LIST_FOR_EACH_ENTRY( info
, &pending_custom_actions
, custom_action_info
, entry
)
437 if (IsEqualGUID( &info
->guid
, guid
))
444 LeaveCriticalSection( &custom_action_cs
);
452 static void handle_msi_break( const WCHAR
*action
)
454 const WCHAR fmt
[] = L
"To debug your custom action, attach your debugger to process %u (0x%x) and press OK";
455 WCHAR val
[MAX_PATH
], msg
[100];
457 if (!GetEnvironmentVariableW( L
"MsiBreak", val
, MAX_PATH
) || wcscmp( val
, action
)) return;
459 swprintf( msg
, ARRAY_SIZE(msg
), fmt
, GetCurrentProcessId(), GetCurrentProcessId() );
460 MessageBoxW( NULL
, msg
, L
"Windows Installer", MB_OK
);
465 /* wrapper for apps that don't declare the thread function correctly */
466 extern UINT
custom_proc_wrapper( MsiCustomActionEntryPoint entry
, MSIHANDLE hinst
);
467 __ASM_GLOBAL_FUNC(custom_proc_wrapper
,
469 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
470 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
472 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
477 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
478 __ASM_CFI(".cfi_same_value %ebp\n\t")
481 static UINT
custom_proc_wrapper( MsiCustomActionEntryPoint entry
, MSIHANDLE hinst
)
487 UINT CDECL
__wine_msi_call_dll_function(DWORD client_pid
, const GUID
*guid
)
489 MsiCustomActionEntryPoint fn
;
490 MSIHANDLE remote_package
= 0;
491 RPC_WSTR binding_str
;
494 WCHAR
*dll
= NULL
, *action
= NULL
;
500 TRACE("%s\n", debugstr_guid( guid
));
506 swprintf(endpoint
, ARRAY_SIZE(endpoint
), L
"msi%x", client_pid
);
507 status
= RpcStringBindingComposeW(NULL
, (WCHAR
*)L
"ncalrpc", NULL
, endpoint
, NULL
, &binding_str
);
508 if (status
!= RPC_S_OK
)
510 ERR("RpcStringBindingCompose failed: %#lx\n", status
);
513 status
= RpcBindingFromStringBindingW(binding_str
, &rpc_handle
);
514 if (status
!= RPC_S_OK
)
516 ERR("RpcBindingFromStringBinding failed: %#lx\n", status
);
519 RpcStringFreeW(&binding_str
);
522 r
= remote_GetActionInfo(guid
, &action
, &type
, &dll
, &proc
, &remote_package
);
523 if (r
!= ERROR_SUCCESS
)
526 hPackage
= alloc_msi_remote_handle( remote_package
);
529 ERR( "failed to create handle for %#lx\n", remote_package
);
530 midl_user_free( action
);
531 midl_user_free( dll
);
532 midl_user_free( proc
);
533 return ERROR_INSTALL_FAILURE
;
536 hModule
= LoadLibraryW( dll
);
539 ERR( "failed to load dll %s (%lu)\n", debugstr_w( dll
), GetLastError() );
540 midl_user_free( action
);
541 midl_user_free( dll
);
542 midl_user_free( proc
);
543 MsiCloseHandle( hPackage
);
544 return ERROR_SUCCESS
;
547 fn
= (MsiCustomActionEntryPoint
) GetProcAddress( hModule
, proc
);
548 if (!fn
) WARN( "GetProcAddress(%s) failed\n", debugstr_a(proc
) );
551 handle_msi_break(action
);
555 r
= custom_proc_wrapper( fn
, hPackage
);
559 ERR( "Custom action (%s:%s) caused a page fault: %#lx\n",
560 debugstr_w(dll
), debugstr_a(proc
), GetExceptionCode() );
566 FreeLibrary(hModule
);
568 midl_user_free(action
);
570 midl_user_free(proc
);
572 MsiCloseAllHandles();
576 static HANDLE
get_admin_token(void)
578 TOKEN_ELEVATION_TYPE type
;
579 TOKEN_LINKED_TOKEN linked
;
582 if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenElevationType
, &type
, sizeof(type
), &size
)
583 || type
== TokenElevationTypeFull
)
586 if (!GetTokenInformation(GetCurrentThreadEffectiveToken(), TokenLinkedToken
, &linked
, sizeof(linked
), &size
))
588 return linked
.LinkedToken
;
591 static DWORD
custom_start_server(MSIPACKAGE
*package
, DWORD arch
)
593 WCHAR path
[MAX_PATH
], cmdline
[MAX_PATH
+ 23];
594 PROCESS_INFORMATION pi
= {0};
595 STARTUPINFOW si
= {0};
601 if ((arch
== SCS_32BIT_BINARY
&& package
->custom_server_32_process
) ||
602 (arch
== SCS_64BIT_BINARY
&& package
->custom_server_64_process
))
603 return ERROR_SUCCESS
;
605 swprintf(buffer
, ARRAY_SIZE(buffer
), L
"\\\\.\\pipe\\msica_%x_%d",
606 GetCurrentProcessId(), arch
== SCS_32BIT_BINARY
? 32 : 64);
607 pipe
= CreateNamedPipeW(buffer
, PIPE_ACCESS_DUPLEX
, 0, 1, sizeof(DWORD64
),
608 sizeof(GUID
), 0, NULL
);
609 if (pipe
== INVALID_HANDLE_VALUE
)
610 ERR("failed to create custom action client pipe: %lu\n", GetLastError());
612 if ((sizeof(void *) == 8 || is_wow64
) && arch
== SCS_32BIT_BINARY
)
613 GetSystemWow64DirectoryW(path
, MAX_PATH
- ARRAY_SIZE(L
"\\msiexec.exe"));
615 GetSystemDirectoryW(path
, MAX_PATH
- ARRAY_SIZE(L
"\\msiexec.exe"));
616 lstrcatW(path
, L
"\\msiexec.exe");
617 swprintf(cmdline
, ARRAY_SIZE(cmdline
), L
"%s -Embedding %d", path
, GetCurrentProcessId());
619 token
= get_admin_token();
621 if (is_wow64
&& arch
== SCS_64BIT_BINARY
)
623 Wow64DisableWow64FsRedirection(&cookie
);
624 CreateProcessAsUserW(token
, path
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
625 Wow64RevertWow64FsRedirection(cookie
);
628 CreateProcessAsUserW(token
, path
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
630 if (token
) CloseHandle(token
);
632 CloseHandle(pi
.hThread
);
634 if (arch
== SCS_32BIT_BINARY
)
636 package
->custom_server_32_process
= pi
.hProcess
;
637 package
->custom_server_32_pipe
= pipe
;
641 package
->custom_server_64_process
= pi
.hProcess
;
642 package
->custom_server_64_pipe
= pipe
;
645 if (!ConnectNamedPipe(pipe
, NULL
))
647 ERR("failed to connect to custom action server: %lu\n", GetLastError());
648 return GetLastError();
651 return ERROR_SUCCESS
;
654 void custom_stop_server(HANDLE process
, HANDLE pipe
)
658 WriteFile(pipe
, &GUID_NULL
, sizeof(GUID_NULL
), &size
, NULL
);
659 WaitForSingleObject(process
, INFINITE
);
660 CloseHandle(process
);
664 static DWORD WINAPI
custom_client_thread(void *arg
)
666 custom_action_info
*info
= arg
;
674 CoInitializeEx(NULL
, COINIT_MULTITHREADED
); /* needed to marshal streams */
676 if (info
->arch
== SCS_32BIT_BINARY
)
678 process
= info
->package
->custom_server_32_process
;
679 pipe
= info
->package
->custom_server_32_pipe
;
683 process
= info
->package
->custom_server_64_process
;
684 pipe
= info
->package
->custom_server_64_pipe
;
687 EnterCriticalSection(&custom_action_cs
);
689 if (!WriteFile(pipe
, &info
->guid
, sizeof(info
->guid
), &size
, NULL
) ||
690 size
!= sizeof(info
->guid
))
692 ERR("failed to write to custom action client pipe: %lu\n", GetLastError());
693 LeaveCriticalSection(&custom_action_cs
);
694 return GetLastError();
696 if (!ReadFile(pipe
, &thread64
, sizeof(thread64
), &size
, NULL
) || size
!= sizeof(thread64
))
698 ERR("failed to read from custom action client pipe: %lu\n", GetLastError());
699 LeaveCriticalSection(&custom_action_cs
);
700 return GetLastError();
703 LeaveCriticalSection(&custom_action_cs
);
705 if (DuplicateHandle(process
, (HANDLE
)(DWORD_PTR
)thread64
, GetCurrentProcess(),
706 &thread
, 0, FALSE
, DUPLICATE_SAME_ACCESS
| DUPLICATE_CLOSE_SOURCE
))
708 WaitForSingleObject(thread
, INFINITE
);
709 GetExitCodeThread(thread
, &rc
);
719 /* based on kernel32.GetBinaryTypeW() */
720 static BOOL
get_binary_type( const WCHAR
*name
, DWORD
*type
)
722 HANDLE hfile
, mapping
;
725 hfile
= CreateFileW( name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
726 if (hfile
== INVALID_HANDLE_VALUE
)
729 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
, NULL
, NULL
, PAGE_READONLY
,
731 CloseHandle( hfile
);
737 SECTION_IMAGE_INFORMATION info
;
739 status
= NtQuerySection( mapping
, SectionImageInformation
, &info
, sizeof(info
), NULL
);
740 CloseHandle( mapping
);
741 if (status
) return FALSE
;
742 switch (info
.Machine
)
744 case IMAGE_FILE_MACHINE_I386
:
745 case IMAGE_FILE_MACHINE_ARMNT
:
746 *type
= SCS_32BIT_BINARY
;
748 case IMAGE_FILE_MACHINE_AMD64
:
749 case IMAGE_FILE_MACHINE_ARM64
:
750 *type
= SCS_64BIT_BINARY
;
756 case STATUS_INVALID_IMAGE_WIN_64
:
757 *type
= SCS_64BIT_BINARY
;
764 static custom_action_info
*do_msidbCustomActionTypeDll(
765 MSIPACKAGE
*package
, INT type
, LPCWSTR source
, LPCWSTR target
, LPCWSTR action
)
767 custom_action_info
*info
;
771 info
= malloc( sizeof *info
);
775 msiobj_addref( &package
->hdr
);
776 info
->package
= package
;
778 info
->target
= wcsdup( target
);
779 info
->source
= wcsdup( source
);
780 info
->action
= wcsdup( action
);
781 CoCreateGuid( &info
->guid
);
783 EnterCriticalSection( &custom_action_cs
);
784 list_add_tail( &pending_custom_actions
, &info
->entry
);
785 LeaveCriticalSection( &custom_action_cs
);
787 if (!package
->rpc_server_started
)
791 swprintf(endpoint
, ARRAY_SIZE(endpoint
), L
"msi%x", GetCurrentProcessId());
792 status
= RpcServerUseProtseqEpW((WCHAR
*)L
"ncalrpc", RPC_C_PROTSEQ_MAX_REQS_DEFAULT
,
794 if (status
!= RPC_S_OK
)
796 ERR("RpcServerUseProtseqEp failed: %#lx\n", status
);
800 status
= RpcServerRegisterIfEx(s_IWineMsiRemote_v0_0_s_ifspec
, NULL
, NULL
,
801 RPC_IF_AUTOLISTEN
, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
802 if (status
!= RPC_S_OK
)
804 ERR("RpcServerRegisterIfEx failed: %#lx\n", status
);
808 info
->package
->rpc_server_started
= 1;
811 ret
= get_binary_type(source
, &info
->arch
);
813 info
->arch
= (sizeof(void *) == 8 ? SCS_64BIT_BINARY
: SCS_32BIT_BINARY
);
815 if (info
->arch
== SCS_64BIT_BINARY
&& sizeof(void *) == 4 && !is_wow64
)
817 ERR("Attempt to run a 64-bit custom action inside a 32-bit WINEPREFIX.\n");
818 free_custom_action_data( info
);
822 custom_start_server(package
, info
->arch
);
824 info
->handle
= CreateThread(NULL
, 0, custom_client_thread
, info
, 0, NULL
);
827 free_custom_action_data( info
);
834 static UINT
HANDLE_CustomType1( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
835 INT type
, const WCHAR
*action
)
837 custom_action_info
*info
;
840 if (!(binary
= get_temp_binary(package
, source
)))
841 return ERROR_FUNCTION_FAILED
;
843 TRACE("Calling function %s from %s\n", debugstr_w(target
), debugstr_w(binary
->tmpfile
));
845 if (!(info
= do_msidbCustomActionTypeDll( package
, type
, binary
->tmpfile
, target
, action
)))
846 return ERROR_FUNCTION_FAILED
;
847 return wait_thread_handle( info
);
850 static HANDLE
execute_command( const WCHAR
*app
, WCHAR
*arg
, const WCHAR
*dir
)
853 PROCESS_INFORMATION info
;
854 WCHAR
*exe
= NULL
, *cmd
= NULL
, *p
;
862 if (!(exe
= malloc( MAX_PATH
* sizeof(WCHAR
) ))) return INVALID_HANDLE_VALUE
;
863 len_exe
= SearchPathW( NULL
, app
, L
".exe", MAX_PATH
, exe
, NULL
);
864 if (len_exe
>= MAX_PATH
)
867 if (!(exe
= malloc( len_exe
* sizeof(WCHAR
) ))) return INVALID_HANDLE_VALUE
;
868 len_exe
= SearchPathW( NULL
, app
, L
".exe", len_exe
, exe
, NULL
);
872 ERR("can't find executable %lu\n", GetLastError());
874 return INVALID_HANDLE_VALUE
;
877 if (arg
) len_arg
= lstrlenW( arg
);
878 if (!(cmd
= malloc( (len_exe
+ len_arg
+ 4) * sizeof(WCHAR
) )))
881 return INVALID_HANDLE_VALUE
;
884 if (wcschr( exe
, ' ' ))
887 memcpy( p
, exe
, len_exe
* sizeof(WCHAR
) );
900 memcpy( p
, arg
, len_arg
* sizeof(WCHAR
) );
904 memset( &si
, 0, sizeof(STARTUPINFOW
) );
905 ret
= CreateProcessW( exe
, exe
? cmd
: arg
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
);
910 ERR("unable to execute command %lu\n", GetLastError());
911 return INVALID_HANDLE_VALUE
;
913 CloseHandle( info
.hThread
);
914 return info
.hProcess
;
917 static UINT
HANDLE_CustomType2( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
918 INT type
, const WCHAR
*action
)
924 if (!(binary
= get_temp_binary(package
, source
)))
925 return ERROR_FUNCTION_FAILED
;
927 deformat_string( package
, target
, &arg
);
928 TRACE("exe %s arg %s\n", debugstr_w(binary
->tmpfile
), debugstr_w(arg
));
930 handle
= execute_command( binary
->tmpfile
, arg
, L
"C:\\" );
932 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
933 return wait_process_handle( package
, type
, handle
, action
);
936 static UINT
HANDLE_CustomType17( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
937 INT type
, const WCHAR
*action
)
939 custom_action_info
*info
;
942 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
944 file
= msi_get_loaded_file( package
, source
);
947 ERR("invalid file key %s\n", debugstr_w( source
));
948 return ERROR_FUNCTION_FAILED
;
951 if (!(info
= do_msidbCustomActionTypeDll( package
, type
, file
->TargetPath
, target
, action
)))
952 return ERROR_FUNCTION_FAILED
;
953 return wait_thread_handle( info
);
956 static UINT
HANDLE_CustomType18( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
957 INT type
, const WCHAR
*action
)
963 if (!(file
= msi_get_loaded_file( package
, source
))) return ERROR_FUNCTION_FAILED
;
965 deformat_string( package
, target
, &arg
);
966 TRACE("exe %s arg %s\n", debugstr_w(file
->TargetPath
), debugstr_w(arg
));
968 handle
= execute_command( file
->TargetPath
, arg
, L
"C:\\" );
970 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
971 return wait_process_handle( package
, type
, handle
, action
);
974 static UINT
HANDLE_CustomType19( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
975 INT type
, const WCHAR
*action
)
978 LPWSTR deformated
= NULL
;
980 deformat_string( package
, target
, &deformated
);
982 /* first try treat the error as a number */
983 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT `Message` FROM `Error` WHERE `Error` = '%s'", deformated
);
986 LPCWSTR error
= MSI_RecordGetString( row
, 1 );
987 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
988 MessageBoxW( NULL
, error
, NULL
, MB_OK
);
989 msiobj_release( &row
->hdr
);
991 else if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
992 MessageBoxW( NULL
, deformated
, NULL
, MB_OK
);
996 return ERROR_INSTALL_FAILURE
;
999 static WCHAR
*build_msiexec_args( const WCHAR
*filename
, const WCHAR
*params
)
1001 UINT len_filename
= lstrlenW( filename
), len_params
= lstrlenW( params
);
1002 UINT len
= ARRAY_SIZE(L
"/qb /i ") - 1;
1005 if (!(ret
= malloc( (len
+ len_filename
+ len_params
+ 4) * sizeof(WCHAR
) ))) return NULL
;
1006 memcpy( ret
, L
"/qb /i ", sizeof(L
"/qb /i ") );
1008 memcpy( ret
+ len
, filename
, len_filename
* sizeof(WCHAR
) );
1009 len
+= len_filename
;
1012 lstrcpyW( ret
+ len
, params
);
1016 static UINT
HANDLE_CustomType23( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1017 INT type
, const WCHAR
*action
)
1019 WCHAR
*dir
, *filename
, *args
, *p
;
1020 UINT len_dir
, len_source
= lstrlenW( source
);
1023 if (!(dir
= msi_dup_property( package
->db
, L
"OriginalDatabase" ))) return ERROR_OUTOFMEMORY
;
1024 if (!(p
= wcsrchr( dir
, '\\' )) && !(p
= wcsrchr( dir
, '/' )))
1027 return ERROR_FUNCTION_FAILED
;
1031 if (!(filename
= malloc( (len_dir
+ len_source
+ 2) * sizeof(WCHAR
) )))
1034 return ERROR_OUTOFMEMORY
;
1036 memcpy( filename
, dir
, len_dir
* sizeof(WCHAR
) );
1037 filename
[len_dir
++] = '\\';
1038 memcpy( filename
+ len_dir
, source
, len_source
* sizeof(WCHAR
) );
1039 filename
[len_dir
+ len_source
] = 0;
1041 if (!(args
= build_msiexec_args( filename
, target
)))
1045 return ERROR_OUTOFMEMORY
;
1048 TRACE("installing %s concurrently\n", debugstr_w(source
));
1050 handle
= execute_command( L
"msiexec", args
, dir
);
1054 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1055 return wait_process_handle( package
, type
, handle
, action
);
1058 static UINT
write_substorage_to_file( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*filename
)
1060 IStorage
*src
= NULL
, *dst
= NULL
;
1061 UINT r
= ERROR_FUNCTION_FAILED
;
1064 hr
= StgCreateDocfile( filename
, STGM_CREATE
|STGM_TRANSACTED
|STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, 0, &dst
);
1067 WARN( "can't open destination storage %s (%#lx)\n", debugstr_w(filename
), hr
);
1071 hr
= IStorage_OpenStorage( package
->db
->storage
, source
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &src
);
1074 WARN( "can't open source storage %s (%#lx)\n", debugstr_w(source
), hr
);
1078 hr
= IStorage_CopyTo( src
, 0, NULL
, NULL
, dst
);
1081 ERR( "failed to copy storage %s (%#lx)\n", debugstr_w(source
), hr
);
1085 hr
= IStorage_Commit( dst
, 0 );
1087 ERR( "failed to commit storage (%#lx)\n", hr
);
1092 if (src
) IStorage_Release( src
);
1093 if (dst
) IStorage_Release( dst
);
1097 static UINT
HANDLE_CustomType7( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1098 INT type
, const WCHAR
*action
)
1100 WCHAR
*tmpfile
, *args
;
1101 MSIBINARY
*binary
= NULL
;
1105 if (!(tmpfile
= msi_create_temp_file( package
->db
))) return ERROR_FUNCTION_FAILED
;
1107 r
= write_substorage_to_file( package
, source
, tmpfile
);
1108 if (r
!= ERROR_SUCCESS
)
1111 if (!(binary
= malloc( sizeof(*binary
) ))) goto error
;
1112 binary
->source
= NULL
;
1113 binary
->tmpfile
= tmpfile
;
1114 list_add_tail( &package
->binaries
, &binary
->entry
);
1116 if (!(args
= build_msiexec_args( tmpfile
, target
))) return ERROR_OUTOFMEMORY
;
1118 TRACE("installing %s concurrently\n", debugstr_w(source
));
1120 handle
= execute_command( L
"msiexec", args
, L
"C:\\" );
1122 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1123 return wait_process_handle( package
, type
, handle
, action
);
1126 DeleteFileW( tmpfile
);
1128 return ERROR_FUNCTION_FAILED
;
1131 static UINT
HANDLE_CustomType50( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1132 INT type
, const WCHAR
*action
)
1137 if (!(exe
= msi_dup_property( package
->db
, source
))) return ERROR_SUCCESS
;
1139 deformat_string( package
, target
, &arg
);
1140 TRACE("exe %s arg %s\n", debugstr_w(exe
), debugstr_w(arg
));
1142 handle
= execute_command( exe
, arg
, L
"C:\\" );
1145 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1146 return wait_process_handle( package
, type
, handle
, action
);
1149 static UINT
HANDLE_CustomType34( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1150 INT type
, const WCHAR
*action
)
1152 const WCHAR
*workingdir
= NULL
;
1158 workingdir
= msi_get_target_folder( package
, source
);
1159 if (!workingdir
) return ERROR_FUNCTION_FAILED
;
1161 deformat_string( package
, target
, &cmd
);
1162 if (!cmd
) return ERROR_FUNCTION_FAILED
;
1164 TRACE("cmd %s dir %s\n", debugstr_w(cmd
), debugstr_w(workingdir
));
1166 handle
= execute_command( NULL
, cmd
, workingdir
);
1168 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1169 return wait_process_handle( package
, type
, handle
, action
);
1172 static DWORD
ACTION_CallScript( const GUID
*guid
)
1174 custom_action_info
*info
;
1176 UINT r
= ERROR_FUNCTION_FAILED
;
1178 info
= find_action_by_guid( guid
);
1181 ERR("failed to find action %s\n", debugstr_guid( guid
) );
1182 return ERROR_FUNCTION_FAILED
;
1185 TRACE("function %s, script %s\n", debugstr_w( info
->target
), debugstr_w( info
->source
) );
1187 hPackage
= alloc_msihandle( &info
->package
->hdr
);
1190 r
= call_script( hPackage
, info
->type
, info
->source
, info
->target
, info
->action
);
1191 TRACE("script returned %u\n", r
);
1192 MsiCloseHandle( hPackage
);
1195 ERR("failed to create handle for %p\n", info
->package
);
1200 static DWORD WINAPI
ScriptThread( LPVOID arg
)
1205 TRACE("custom action (%#lx) started\n", GetCurrentThreadId() );
1207 rc
= ACTION_CallScript( guid
);
1209 TRACE("custom action (%#lx) returned %lu\n", GetCurrentThreadId(), rc
);
1211 MsiCloseAllHandles();
1215 static custom_action_info
*do_msidbCustomActionTypeScript(
1216 MSIPACKAGE
*package
, INT type
, LPCWSTR script
, LPCWSTR function
, LPCWSTR action
)
1218 custom_action_info
*info
;
1220 info
= malloc( sizeof *info
);
1224 msiobj_addref( &package
->hdr
);
1225 info
->package
= package
;
1227 info
->target
= wcsdup( function
);
1228 info
->source
= wcsdup( script
);
1229 info
->action
= wcsdup( action
);
1230 CoCreateGuid( &info
->guid
);
1232 EnterCriticalSection( &custom_action_cs
);
1233 list_add_tail( &pending_custom_actions
, &info
->entry
);
1234 LeaveCriticalSection( &custom_action_cs
);
1236 info
->handle
= CreateThread( NULL
, 0, ScriptThread
, &info
->guid
, 0, NULL
);
1239 free_custom_action_data( info
);
1246 static UINT
HANDLE_CustomType37_38( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1247 INT type
, const WCHAR
*action
)
1249 custom_action_info
*info
;
1251 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1253 info
= do_msidbCustomActionTypeScript( package
, type
, target
, NULL
, action
);
1254 return wait_thread_handle( info
);
1257 static UINT
HANDLE_CustomType5_6( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1258 INT type
, const WCHAR
*action
)
1260 MSIRECORD
*row
= NULL
;
1261 custom_action_info
*info
;
1262 CHAR
*buffer
= NULL
;
1263 WCHAR
*bufferw
= NULL
;
1267 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1269 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", source
);
1271 return ERROR_FUNCTION_FAILED
;
1273 r
= MSI_RecordReadStream(row
, 2, NULL
, &sz
);
1274 if (r
!= ERROR_SUCCESS
) goto done
;
1276 buffer
= malloc( sz
+ 1 );
1279 r
= ERROR_FUNCTION_FAILED
;
1283 r
= MSI_RecordReadStream(row
, 2, buffer
, &sz
);
1284 if (r
!= ERROR_SUCCESS
)
1288 bufferw
= strdupAtoW(buffer
);
1291 r
= ERROR_FUNCTION_FAILED
;
1295 info
= do_msidbCustomActionTypeScript( package
, type
, bufferw
, target
, action
);
1296 r
= wait_thread_handle( info
);
1301 msiobj_release(&row
->hdr
);
1305 static UINT
HANDLE_CustomType21_22( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1306 INT type
, const WCHAR
*action
)
1308 custom_action_info
*info
;
1311 DWORD sz
, szHighWord
= 0, read
;
1313 WCHAR
*bufferw
=NULL
;
1317 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1319 file
= msi_get_loaded_file(package
, source
);
1322 ERR("invalid file key %s\n", debugstr_w(source
));
1323 return ERROR_FUNCTION_FAILED
;
1326 hFile
= msi_create_file( package
, file
->TargetPath
, GENERIC_READ
, FILE_SHARE_READ
, OPEN_EXISTING
, 0 );
1327 if (hFile
== INVALID_HANDLE_VALUE
) return ERROR_FUNCTION_FAILED
;
1329 sz
= GetFileSize(hFile
, &szHighWord
);
1330 if (sz
== INVALID_FILE_SIZE
|| szHighWord
!= 0)
1333 return ERROR_FUNCTION_FAILED
;
1335 buffer
= malloc( sz
+ 1 );
1339 return ERROR_FUNCTION_FAILED
;
1341 bRet
= ReadFile(hFile
, buffer
, sz
, &read
, NULL
);
1345 r
= ERROR_FUNCTION_FAILED
;
1349 bufferw
= strdupAtoW(buffer
);
1352 r
= ERROR_FUNCTION_FAILED
;
1355 info
= do_msidbCustomActionTypeScript( package
, type
, bufferw
, target
, action
);
1356 r
= wait_thread_handle( info
);
1364 static UINT
HANDLE_CustomType53_54( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1365 INT type
, const WCHAR
*action
)
1367 custom_action_info
*info
;
1370 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1372 prop
= msi_dup_property( package
->db
, source
);
1373 if (!prop
) return ERROR_SUCCESS
;
1375 info
= do_msidbCustomActionTypeScript( package
, type
, prop
, NULL
, action
);
1377 return wait_thread_handle( info
);
1380 static BOOL
action_type_matches_script( UINT type
, UINT script
)
1386 case SCRIPT_INSTALL
:
1387 return !(type
& msidbCustomActionTypeCommit
) && !(type
& msidbCustomActionTypeRollback
);
1389 return (type
& msidbCustomActionTypeCommit
);
1390 case SCRIPT_ROLLBACK
:
1391 return (type
& msidbCustomActionTypeRollback
);
1393 ERR("unhandled script %u\n", script
);
1398 static UINT
defer_custom_action( MSIPACKAGE
*package
, const WCHAR
*action
, UINT type
)
1400 WCHAR
*actiondata
= msi_dup_property( package
->db
, action
);
1401 WCHAR
*usersid
= msi_dup_property( package
->db
, L
"UserSID" );
1402 WCHAR
*prodcode
= msi_dup_property( package
->db
, L
"ProductCode" );
1403 WCHAR
*deferred
= get_deferred_action( action
, actiondata
, usersid
, prodcode
);
1410 return ERROR_OUTOFMEMORY
;
1412 if (type
& msidbCustomActionTypeCommit
)
1414 TRACE("deferring commit action\n");
1415 msi_schedule_action( package
, SCRIPT_COMMIT
, deferred
);
1417 else if (type
& msidbCustomActionTypeRollback
)
1419 TRACE("deferring rollback action\n");
1420 msi_schedule_action( package
, SCRIPT_ROLLBACK
, deferred
);
1424 TRACE("deferring install action\n");
1425 msi_schedule_action( package
, SCRIPT_INSTALL
, deferred
);
1432 return ERROR_SUCCESS
;
1435 UINT
ACTION_CustomAction(MSIPACKAGE
*package
, const WCHAR
*action
)
1437 UINT rc
= ERROR_SUCCESS
;
1440 const WCHAR
*source
, *target
, *ptr
, *deferred_data
= NULL
;
1441 WCHAR
*deformated
= NULL
;
1444 /* deferred action: [properties]Action */
1445 if ((ptr
= wcsrchr(action
, ']')))
1447 deferred_data
= action
;
1451 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `CustomAction` WHERE `Action` = '%s'", action
);
1453 return ERROR_FUNCTION_NOT_CALLED
;
1455 type
= MSI_RecordGetInteger(row
,2);
1456 source
= MSI_RecordGetString(row
,3);
1457 target
= MSI_RecordGetString(row
,4);
1459 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action
),type
,
1460 debugstr_w(source
), debugstr_w(target
));
1462 /* handle some of the deferred actions */
1463 if (type
& msidbCustomActionTypeTSAware
)
1464 FIXME("msidbCustomActionTypeTSAware not handled\n");
1466 if (type
& msidbCustomActionTypeInScript
)
1468 if (type
& msidbCustomActionTypeNoImpersonate
)
1469 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1471 if (!action_type_matches_script(type
, package
->script
))
1473 rc
= defer_custom_action( package
, action
, type
);
1478 LPWSTR actiondata
= msi_dup_property( package
->db
, action
);
1480 if (type
& msidbCustomActionTypeInScript
)
1481 package
->scheduled_action_running
= TRUE
;
1483 if (type
& msidbCustomActionTypeCommit
)
1484 package
->commit_action_running
= TRUE
;
1486 if (type
& msidbCustomActionTypeRollback
)
1487 package
->rollback_action_running
= TRUE
;
1490 set_deferred_action_props(package
, deferred_data
);
1491 else if (actiondata
)
1492 msi_set_property( package
->db
, L
"CustomActionData", actiondata
, -1 );
1494 msi_set_property( package
->db
, L
"CustomActionData", L
"", -1 );
1499 else if (!check_execution_scheduling_options(package
,action
,type
))
1505 switch (type
& CUSTOM_ACTION_TYPE_MASK
)
1507 case 1: /* DLL file stored in a Binary table stream */
1508 rc
= HANDLE_CustomType1( package
, source
, target
, type
, action
);
1510 case 2: /* EXE file stored in a Binary table stream */
1511 rc
= HANDLE_CustomType2( package
, source
, target
, type
, action
);
1514 case 6: /* JScript/VBScript file stored in a Binary table stream */
1515 rc
= HANDLE_CustomType5_6( package
, source
, target
, type
, action
);
1517 case 7: /* Concurrent install from substorage */
1518 deformat_string( package
, target
, &deformated
);
1519 rc
= HANDLE_CustomType7( package
, source
, target
, type
, action
);
1523 rc
= HANDLE_CustomType17( package
, source
, target
, type
, action
);
1525 case 18: /* EXE file installed with package */
1526 rc
= HANDLE_CustomType18( package
, source
, target
, type
, action
);
1528 case 19: /* Error that halts install */
1529 rc
= HANDLE_CustomType19( package
, source
, target
, type
, action
);
1531 case 21: /* JScript/VBScript file installed with the product */
1533 rc
= HANDLE_CustomType21_22( package
, source
, target
, type
, action
);
1535 case 23: /* Installs another package in the source tree */
1536 deformat_string( package
, target
, &deformated
);
1537 rc
= HANDLE_CustomType23( package
, source
, deformated
, type
, action
);
1540 case 34: /* EXE to be run in specified directory */
1541 rc
= HANDLE_CustomType34( package
, source
, target
, type
, action
);
1543 case 35: /* Directory set with formatted text */
1544 deformat_string( package
, target
, &deformated
);
1545 MSI_SetTargetPathW( package
, source
, deformated
);
1548 case 37: /* JScript/VBScript text stored in target column */
1550 rc
= HANDLE_CustomType37_38( package
, source
, target
, type
, action
);
1552 case 50: /* EXE file specified by a property value */
1553 rc
= HANDLE_CustomType50( package
, source
, target
, type
, action
);
1555 case 51: /* Property set with formatted text */
1557 len
= deformat_string( package
, target
, &deformated
);
1558 rc
= msi_set_property( package
->db
, source
, deformated
, len
);
1559 if (rc
== ERROR_SUCCESS
&& !wcscmp( source
, L
"SourceDir" )) msi_reset_source_folders( package
);
1562 case 53: /* JScript/VBScript text specified by a property value */
1564 rc
= HANDLE_CustomType53_54( package
, source
, target
, type
, action
);
1567 FIXME( "unhandled action type %u (%s %s)\n", type
& CUSTOM_ACTION_TYPE_MASK
, debugstr_w(source
),
1568 debugstr_w(target
) );
1572 package
->scheduled_action_running
= FALSE
;
1573 package
->commit_action_running
= FALSE
;
1574 package
->rollback_action_running
= FALSE
;
1575 msiobj_release(&row
->hdr
);
1579 void ACTION_FinishCustomActions(const MSIPACKAGE
* package
)
1582 HANDLE
*wait_handles
;
1583 unsigned int handle_count
, i
;
1584 custom_action_info
*info
, *cursor
;
1586 while ((item
= list_head( &package
->RunningActions
)))
1588 struct running_action
*action
= LIST_ENTRY( item
, struct running_action
, entry
);
1590 list_remove( &action
->entry
);
1592 TRACE("waiting for %s\n", debugstr_w( action
->name
) );
1593 msi_dialog_check_messages( action
->handle
);
1595 CloseHandle( action
->handle
);
1596 free( action
->name
);
1600 EnterCriticalSection( &custom_action_cs
);
1602 handle_count
= list_count( &pending_custom_actions
);
1603 wait_handles
= malloc( handle_count
* sizeof(HANDLE
) );
1606 LIST_FOR_EACH_ENTRY_SAFE( info
, cursor
, &pending_custom_actions
, custom_action_info
, entry
)
1608 if (info
->package
== package
)
1610 if (DuplicateHandle(GetCurrentProcess(), info
->handle
, GetCurrentProcess(), &wait_handles
[handle_count
], SYNCHRONIZE
, FALSE
, 0))
1615 LeaveCriticalSection( &custom_action_cs
);
1617 for (i
= 0; i
< handle_count
; i
++)
1619 msi_dialog_check_messages( wait_handles
[i
] );
1620 CloseHandle( wait_handles
[i
] );
1622 free( wait_handles
);
1624 EnterCriticalSection( &custom_action_cs
);
1625 LIST_FOR_EACH_ENTRY_SAFE( info
, cursor
, &pending_custom_actions
, custom_action_info
, entry
)
1627 if (info
->package
== package
)
1628 free_custom_action_data( info
);
1630 LeaveCriticalSection( &custom_action_cs
);
1633 UINT __cdecl
s_remote_GetActionInfo(const GUID
*guid
, WCHAR
**name
, int *type
, WCHAR
**dll
, char **func
, MSIHANDLE
*hinst
)
1635 custom_action_info
*info
;
1637 info
= find_action_by_guid(guid
);
1639 return ERROR_INVALID_DATA
;
1641 *name
= wcsdup(info
->action
);
1643 *hinst
= alloc_msihandle(&info
->package
->hdr
);
1644 *dll
= wcsdup(info
->source
);
1645 *func
= strdupWtoA(info
->target
);
1647 return ERROR_SUCCESS
;