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
46 typedef struct tagMSIRUNNINGACTION
54 typedef UINT (WINAPI
*MsiCustomActionEntryPoint
)( MSIHANDLE
);
56 static CRITICAL_SECTION msi_custom_action_cs
;
57 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug
=
59 0, 0, &msi_custom_action_cs
,
60 { &msi_custom_action_cs_debug
.ProcessLocksList
,
61 &msi_custom_action_cs_debug
.ProcessLocksList
},
62 0, 0, { (DWORD_PTR
)(__FILE__
": msi_custom_action_cs") }
64 static CRITICAL_SECTION msi_custom_action_cs
= { &msi_custom_action_cs_debug
, -1, 0, 0, 0, 0 };
66 static struct list msi_pending_custom_actions
= LIST_INIT( msi_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
= msi_realloc( package
->script_actions
[script
],
98 package
->script_actions_count
[script
] * sizeof(WCHAR
*) );
99 else newbuf
= msi_alloc( sizeof(WCHAR
*) );
101 newbuf
[count
] = strdupW( 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
= msi_realloc( package
->unique_actions
,
116 package
->unique_actions_count
* sizeof(WCHAR
*) );
117 else newbuf
= msi_alloc( sizeof(WCHAR
*) );
119 newbuf
[count
] = strdupW( 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 LPWSTR
msi_get_deferred_action(LPCWSTR action
, LPCWSTR actiondata
,
175 LPCWSTR usersid
, LPCWSTR prodcode
)
181 return strdupW(action
);
183 len
= lstrlenW(action
) + lstrlenW(actiondata
) +
184 lstrlenW(usersid
) + lstrlenW(prodcode
) +
185 lstrlenW(L
"[%s<=>%s<=>%s]%s") - 7;
186 deferred
= msi_alloc(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 UINT 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
= strdupW( tmp
))) return NULL
;
225 if ((ret
= msi_alloc( (lstrlenW( 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
= msi_alloc_zero( 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
= strdupW( 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 MSIRUNNINGACTION
*action
;
303 action
= msi_alloc( sizeof(MSIRUNNINGACTION
) );
305 action
->handle
= Handle
;
306 action
->process
= process
;
307 action
->name
= strdupW(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 %u\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 %d\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
);
376 typedef struct _msi_custom_action_info
{
386 } msi_custom_action_info
;
388 static void free_custom_action_data( msi_custom_action_info
*info
)
390 EnterCriticalSection( &msi_custom_action_cs
);
392 list_remove( &info
->entry
);
394 CloseHandle( info
->handle
);
395 msi_free( info
->action
);
396 msi_free( info
->source
);
397 msi_free( info
->target
);
398 msiobj_release( &info
->package
->hdr
);
401 LeaveCriticalSection( &msi_custom_action_cs
);
404 static UINT
wait_thread_handle( msi_custom_action_info
*info
)
406 UINT rc
= ERROR_SUCCESS
;
408 if (!(info
->type
& msidbCustomActionTypeAsync
))
410 TRACE("waiting for %s\n", debugstr_w( info
->action
));
412 msi_dialog_check_messages( info
->handle
);
414 if (!(info
->type
& msidbCustomActionTypeContinue
))
415 rc
= custom_get_thread_return( info
->package
, info
->handle
);
417 free_custom_action_data( info
);
421 TRACE("%s running in background\n", debugstr_w( info
->action
));
427 static msi_custom_action_info
*find_action_by_guid( const GUID
*guid
)
429 msi_custom_action_info
*info
;
432 EnterCriticalSection( &msi_custom_action_cs
);
434 LIST_FOR_EACH_ENTRY( info
, &msi_pending_custom_actions
, msi_custom_action_info
, entry
)
436 if (IsEqualGUID( &info
->guid
, guid
))
443 LeaveCriticalSection( &msi_custom_action_cs
);
451 static void handle_msi_break( const WCHAR
*action
)
453 const WCHAR fmt
[] = L
"To debug your custom action, attach your debugger to process %u (0x%x) and press OK";
454 WCHAR val
[MAX_PATH
], msg
[100];
456 if (!GetEnvironmentVariableW( L
"MsiBreak", val
, MAX_PATH
) || wcscmp( val
, action
)) return;
458 swprintf( msg
, ARRAY_SIZE(msg
), fmt
, GetCurrentProcessId(), GetCurrentProcessId() );
459 MessageBoxW( NULL
, msg
, L
"Windows Installer", MB_OK
);
464 /* wrapper for apps that don't declare the thread function correctly */
465 extern UINT
custom_proc_wrapper( MsiCustomActionEntryPoint entry
, MSIHANDLE hinst
);
466 __ASM_GLOBAL_FUNC(custom_proc_wrapper
,
468 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
469 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
471 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
476 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
477 __ASM_CFI(".cfi_same_value %ebp\n\t")
480 static UINT
custom_proc_wrapper( MsiCustomActionEntryPoint entry
, MSIHANDLE hinst
)
486 UINT CDECL
__wine_msi_call_dll_function(DWORD client_pid
, const GUID
*guid
)
488 MsiCustomActionEntryPoint fn
;
489 MSIHANDLE remote_package
= 0;
490 RPC_WSTR binding_str
;
493 WCHAR
*dll
= NULL
, *action
= NULL
;
499 TRACE("%s\n", debugstr_guid( guid
));
505 swprintf(endpoint
, ARRAY_SIZE(endpoint
), L
"msi%x", client_pid
);
506 status
= RpcStringBindingComposeW(NULL
, (WCHAR
*)L
"ncalrpc", NULL
, endpoint
, NULL
, &binding_str
);
507 if (status
!= RPC_S_OK
)
509 ERR("RpcStringBindingCompose failed: %#x\n", status
);
512 status
= RpcBindingFromStringBindingW(binding_str
, &rpc_handle
);
513 if (status
!= RPC_S_OK
)
515 ERR("RpcBindingFromStringBinding failed: %#x\n", status
);
518 RpcStringFreeW(&binding_str
);
521 r
= remote_GetActionInfo(guid
, &action
, &type
, &dll
, &proc
, &remote_package
);
522 if (r
!= ERROR_SUCCESS
)
525 hPackage
= alloc_msi_remote_handle( remote_package
);
528 ERR( "failed to create handle for %x\n", remote_package
);
529 midl_user_free( action
);
530 midl_user_free( dll
);
531 midl_user_free( proc
);
532 return ERROR_INSTALL_FAILURE
;
535 hModule
= LoadLibraryW( dll
);
538 ERR( "failed to load dll %s (%u)\n", debugstr_w( dll
), GetLastError() );
539 midl_user_free( action
);
540 midl_user_free( dll
);
541 midl_user_free( proc
);
542 MsiCloseHandle( hPackage
);
543 return ERROR_SUCCESS
;
546 fn
= (MsiCustomActionEntryPoint
) GetProcAddress( hModule
, proc
);
547 if (!fn
) WARN( "GetProcAddress(%s) failed\n", debugstr_a(proc
) );
550 handle_msi_break(action
);
554 r
= custom_proc_wrapper( fn
, hPackage
);
558 ERR( "Custom action (%s:%s) caused a page fault: %08x\n",
559 debugstr_w(dll
), debugstr_a(proc
), GetExceptionCode() );
565 FreeLibrary(hModule
);
567 midl_user_free(action
);
569 midl_user_free(proc
);
571 MsiCloseAllHandles();
575 static DWORD
custom_start_server(MSIPACKAGE
*package
, DWORD arch
)
577 WCHAR path
[MAX_PATH
], cmdline
[MAX_PATH
+ 23];
578 PROCESS_INFORMATION pi
= {0};
579 STARTUPINFOW si
= {0};
584 if ((arch
== SCS_32BIT_BINARY
&& package
->custom_server_32_process
) ||
585 (arch
== SCS_64BIT_BINARY
&& package
->custom_server_64_process
))
586 return ERROR_SUCCESS
;
588 swprintf(buffer
, ARRAY_SIZE(buffer
), L
"\\\\.\\pipe\\msica_%x_%d",
589 GetCurrentProcessId(), arch
== SCS_32BIT_BINARY
? 32 : 64);
590 pipe
= CreateNamedPipeW(buffer
, PIPE_ACCESS_DUPLEX
, 0, 1, sizeof(DWORD64
),
591 sizeof(GUID
), 0, NULL
);
592 if (pipe
== INVALID_HANDLE_VALUE
)
593 ERR("Failed to create custom action client pipe: %u\n", GetLastError());
595 if ((sizeof(void *) == 8 || is_wow64
) && arch
== SCS_32BIT_BINARY
)
596 GetSystemWow64DirectoryW(path
, MAX_PATH
- ARRAY_SIZE(L
"\\msiexec.exe"));
598 GetSystemDirectoryW(path
, MAX_PATH
- ARRAY_SIZE(L
"\\msiexec.exe"));
599 lstrcatW(path
, L
"\\msiexec.exe");
600 swprintf(cmdline
, ARRAY_SIZE(cmdline
), L
"%s -Embedding %d", path
, GetCurrentProcessId());
602 if (is_wow64
&& arch
== SCS_64BIT_BINARY
)
604 Wow64DisableWow64FsRedirection(&cookie
);
605 CreateProcessW(path
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
606 Wow64RevertWow64FsRedirection(cookie
);
609 CreateProcessW(path
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
611 CloseHandle(pi
.hThread
);
613 if (arch
== SCS_32BIT_BINARY
)
615 package
->custom_server_32_process
= pi
.hProcess
;
616 package
->custom_server_32_pipe
= pipe
;
620 package
->custom_server_64_process
= pi
.hProcess
;
621 package
->custom_server_64_pipe
= pipe
;
624 if (!ConnectNamedPipe(pipe
, NULL
))
626 ERR("Failed to connect to custom action server: %u\n", GetLastError());
627 return GetLastError();
630 return ERROR_SUCCESS
;
633 void custom_stop_server(HANDLE process
, HANDLE pipe
)
637 WriteFile(pipe
, &GUID_NULL
, sizeof(GUID_NULL
), &size
, NULL
);
638 WaitForSingleObject(process
, INFINITE
);
639 CloseHandle(process
);
643 static DWORD WINAPI
custom_client_thread(void *arg
)
645 msi_custom_action_info
*info
= arg
;
653 CoInitializeEx(NULL
, COINIT_MULTITHREADED
); /* needed to marshal streams */
655 if (info
->arch
== SCS_32BIT_BINARY
)
657 process
= info
->package
->custom_server_32_process
;
658 pipe
= info
->package
->custom_server_32_pipe
;
662 process
= info
->package
->custom_server_64_process
;
663 pipe
= info
->package
->custom_server_64_pipe
;
666 EnterCriticalSection(&msi_custom_action_cs
);
668 if (!WriteFile(pipe
, &info
->guid
, sizeof(info
->guid
), &size
, NULL
) ||
669 size
!= sizeof(info
->guid
))
671 ERR("Failed to write to custom action client pipe: %u\n", GetLastError());
672 LeaveCriticalSection(&msi_custom_action_cs
);
673 return GetLastError();
675 if (!ReadFile(pipe
, &thread64
, sizeof(thread64
), &size
, NULL
) || size
!= sizeof(thread64
))
677 ERR("Failed to read from custom action client pipe: %u\n", GetLastError());
678 LeaveCriticalSection(&msi_custom_action_cs
);
679 return GetLastError();
682 LeaveCriticalSection(&msi_custom_action_cs
);
684 if (DuplicateHandle(process
, (HANDLE
)(DWORD_PTR
)thread64
, GetCurrentProcess(),
685 &thread
, 0, FALSE
, DUPLICATE_SAME_ACCESS
| DUPLICATE_CLOSE_SOURCE
))
687 WaitForSingleObject(thread
, INFINITE
);
688 GetExitCodeThread(thread
, &rc
);
698 /* based on kernel32.GetBinaryTypeW() */
699 static BOOL
get_binary_type( const WCHAR
*name
, DWORD
*type
)
701 HANDLE hfile
, mapping
;
704 hfile
= CreateFileW( name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
705 if (hfile
== INVALID_HANDLE_VALUE
)
708 status
= NtCreateSection( &mapping
, STANDARD_RIGHTS_REQUIRED
| SECTION_QUERY
, NULL
, NULL
, PAGE_READONLY
,
710 CloseHandle( hfile
);
716 SECTION_IMAGE_INFORMATION info
;
718 status
= NtQuerySection( mapping
, SectionImageInformation
, &info
, sizeof(info
), NULL
);
719 CloseHandle( mapping
);
720 if (status
) return FALSE
;
721 switch (info
.Machine
)
723 case IMAGE_FILE_MACHINE_I386
:
724 case IMAGE_FILE_MACHINE_ARMNT
:
725 *type
= SCS_32BIT_BINARY
;
727 case IMAGE_FILE_MACHINE_AMD64
:
728 case IMAGE_FILE_MACHINE_ARM64
:
729 *type
= SCS_64BIT_BINARY
;
735 case STATUS_INVALID_IMAGE_WIN_64
:
736 *type
= SCS_64BIT_BINARY
;
743 static msi_custom_action_info
*do_msidbCustomActionTypeDll(
744 MSIPACKAGE
*package
, INT type
, LPCWSTR source
, LPCWSTR target
, LPCWSTR action
)
746 msi_custom_action_info
*info
;
750 info
= msi_alloc( sizeof *info
);
754 msiobj_addref( &package
->hdr
);
755 info
->package
= package
;
757 info
->target
= strdupW( target
);
758 info
->source
= strdupW( source
);
759 info
->action
= strdupW( action
);
760 CoCreateGuid( &info
->guid
);
762 EnterCriticalSection( &msi_custom_action_cs
);
763 list_add_tail( &msi_pending_custom_actions
, &info
->entry
);
764 LeaveCriticalSection( &msi_custom_action_cs
);
766 if (!package
->rpc_server_started
)
770 swprintf(endpoint
, ARRAY_SIZE(endpoint
), L
"msi%x", GetCurrentProcessId());
771 status
= RpcServerUseProtseqEpW((WCHAR
*)L
"ncalrpc", RPC_C_PROTSEQ_MAX_REQS_DEFAULT
,
773 if (status
!= RPC_S_OK
)
775 ERR("RpcServerUseProtseqEp failed: %#x\n", status
);
779 status
= RpcServerRegisterIfEx(s_IWineMsiRemote_v0_0_s_ifspec
, NULL
, NULL
,
780 RPC_IF_AUTOLISTEN
, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
781 if (status
!= RPC_S_OK
)
783 ERR("RpcServerRegisterIfEx failed: %#x\n", status
);
787 info
->package
->rpc_server_started
= 1;
790 ret
= get_binary_type(source
, &info
->arch
);
792 info
->arch
= (sizeof(void *) == 8 ? SCS_64BIT_BINARY
: SCS_32BIT_BINARY
);
794 if (info
->arch
== SCS_64BIT_BINARY
&& sizeof(void *) == 4 && !is_wow64
)
796 ERR("Attempt to run a 64-bit custom action inside a 32-bit WINEPREFIX.\n");
797 free_custom_action_data( info
);
801 custom_start_server(package
, info
->arch
);
803 info
->handle
= CreateThread(NULL
, 0, custom_client_thread
, info
, 0, NULL
);
806 free_custom_action_data( info
);
813 static UINT
HANDLE_CustomType1( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
814 INT type
, const WCHAR
*action
)
816 msi_custom_action_info
*info
;
819 if (!(binary
= get_temp_binary(package
, source
)))
820 return ERROR_FUNCTION_FAILED
;
822 TRACE("Calling function %s from %s\n", debugstr_w(target
), debugstr_w(binary
->tmpfile
));
824 if (!(info
= do_msidbCustomActionTypeDll( package
, type
, binary
->tmpfile
, target
, action
)))
825 return ERROR_FUNCTION_FAILED
;
826 return wait_thread_handle( info
);
829 static HANDLE
execute_command( const WCHAR
*app
, WCHAR
*arg
, const WCHAR
*dir
)
832 PROCESS_INFORMATION info
;
833 WCHAR
*exe
= NULL
, *cmd
= NULL
, *p
;
841 if (!(exe
= msi_alloc( MAX_PATH
* sizeof(WCHAR
) ))) return INVALID_HANDLE_VALUE
;
842 len_exe
= SearchPathW( NULL
, app
, L
".exe", MAX_PATH
, exe
, NULL
);
843 if (len_exe
>= MAX_PATH
)
846 if (!(exe
= msi_alloc( len_exe
* sizeof(WCHAR
) ))) return INVALID_HANDLE_VALUE
;
847 len_exe
= SearchPathW( NULL
, app
, L
".exe", len_exe
, exe
, NULL
);
851 ERR("can't find executable %u\n", GetLastError());
853 return INVALID_HANDLE_VALUE
;
856 if (arg
) len_arg
= lstrlenW( arg
);
857 if (!(cmd
= msi_alloc( (len_exe
+ len_arg
+ 4) * sizeof(WCHAR
) )))
860 return INVALID_HANDLE_VALUE
;
863 if (wcschr( exe
, ' ' ))
866 memcpy( p
, exe
, len_exe
* sizeof(WCHAR
) );
879 memcpy( p
, arg
, len_arg
* sizeof(WCHAR
) );
883 memset( &si
, 0, sizeof(STARTUPINFOW
) );
884 ret
= CreateProcessW( exe
, exe
? cmd
: arg
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
);
889 ERR("unable to execute command %u\n", GetLastError());
890 return INVALID_HANDLE_VALUE
;
892 CloseHandle( info
.hThread
);
893 return info
.hProcess
;
896 static UINT
HANDLE_CustomType2( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
897 INT type
, const WCHAR
*action
)
903 if (!(binary
= get_temp_binary(package
, source
)))
904 return ERROR_FUNCTION_FAILED
;
906 deformat_string( package
, target
, &arg
);
907 TRACE("exe %s arg %s\n", debugstr_w(binary
->tmpfile
), debugstr_w(arg
));
909 handle
= execute_command( binary
->tmpfile
, arg
, L
"C:\\" );
911 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
912 return wait_process_handle( package
, type
, handle
, action
);
915 static UINT
HANDLE_CustomType17( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
916 INT type
, const WCHAR
*action
)
918 msi_custom_action_info
*info
;
921 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
923 file
= msi_get_loaded_file( package
, source
);
926 ERR("invalid file key %s\n", debugstr_w( source
));
927 return ERROR_FUNCTION_FAILED
;
930 if (!(info
= do_msidbCustomActionTypeDll( package
, type
, file
->TargetPath
, target
, action
)))
931 return ERROR_FUNCTION_FAILED
;
932 return wait_thread_handle( info
);
935 static UINT
HANDLE_CustomType18( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
936 INT type
, const WCHAR
*action
)
942 if (!(file
= msi_get_loaded_file( package
, source
))) return ERROR_FUNCTION_FAILED
;
944 deformat_string( package
, target
, &arg
);
945 TRACE("exe %s arg %s\n", debugstr_w(file
->TargetPath
), debugstr_w(arg
));
947 handle
= execute_command( file
->TargetPath
, arg
, L
"C:\\" );
949 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
950 return wait_process_handle( package
, type
, handle
, action
);
953 static UINT
HANDLE_CustomType19( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
954 INT type
, const WCHAR
*action
)
957 LPWSTR deformated
= NULL
;
959 deformat_string( package
, target
, &deformated
);
961 /* first try treat the error as a number */
962 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT `Message` FROM `Error` WHERE `Error` = '%s'", deformated
);
965 LPCWSTR error
= MSI_RecordGetString( row
, 1 );
966 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
967 MessageBoxW( NULL
, error
, NULL
, MB_OK
);
968 msiobj_release( &row
->hdr
);
970 else if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
971 MessageBoxW( NULL
, deformated
, NULL
, MB_OK
);
973 msi_free( deformated
);
975 return ERROR_INSTALL_FAILURE
;
978 static WCHAR
*build_msiexec_args( const WCHAR
*filename
, const WCHAR
*params
)
980 UINT len_filename
= lstrlenW( filename
), len_params
= lstrlenW( params
);
981 UINT len
= ARRAY_SIZE(L
"/qb /i ") - 1;
984 if (!(ret
= msi_alloc( (len
+ len_filename
+ len_params
+ 4) * sizeof(WCHAR
) ))) return NULL
;
985 memcpy( ret
, L
"/qb /i ", sizeof(L
"/qb /i ") );
987 memcpy( ret
+ len
, filename
, len_filename
* sizeof(WCHAR
) );
991 lstrcpyW( ret
+ len
, params
);
995 static UINT
HANDLE_CustomType23( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
996 INT type
, const WCHAR
*action
)
998 WCHAR
*dir
, *filename
, *args
, *p
;
999 UINT len_dir
, len_source
= lstrlenW( source
);
1002 if (!(dir
= msi_dup_property( package
->db
, L
"OriginalDatabase" ))) return ERROR_OUTOFMEMORY
;
1003 if (!(p
= wcsrchr( dir
, '\\' )) && !(p
= wcsrchr( dir
, '/' )))
1006 return ERROR_FUNCTION_FAILED
;
1010 if (!(filename
= msi_alloc( (len_dir
+ len_source
+ 2) * sizeof(WCHAR
) )))
1013 return ERROR_OUTOFMEMORY
;
1015 memcpy( filename
, dir
, len_dir
* sizeof(WCHAR
) );
1016 filename
[len_dir
++] = '\\';
1017 memcpy( filename
+ len_dir
, source
, len_source
* sizeof(WCHAR
) );
1018 filename
[len_dir
+ len_source
] = 0;
1020 if (!(args
= build_msiexec_args( filename
, target
)))
1023 return ERROR_OUTOFMEMORY
;
1026 TRACE("installing %s concurrently\n", debugstr_w(source
));
1028 handle
= execute_command( L
"msiexec", args
, dir
);
1031 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1032 return wait_process_handle( package
, type
, handle
, action
);
1035 static UINT
write_substorage_to_file( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*filename
)
1037 IStorage
*src
= NULL
, *dst
= NULL
;
1038 UINT r
= ERROR_FUNCTION_FAILED
;
1041 hr
= StgCreateDocfile( filename
, STGM_CREATE
|STGM_TRANSACTED
|STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, 0, &dst
);
1044 WARN( "can't open destination storage %s (%08x)\n", debugstr_w(filename
), hr
);
1048 hr
= IStorage_OpenStorage( package
->db
->storage
, source
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &src
);
1051 WARN( "can't open source storage %s (%08x)\n", debugstr_w(source
), hr
);
1055 hr
= IStorage_CopyTo( src
, 0, NULL
, NULL
, dst
);
1058 ERR( "failed to copy storage %s (%08x)\n", debugstr_w(source
), hr
);
1062 hr
= IStorage_Commit( dst
, 0 );
1064 ERR( "failed to commit storage (%08x)\n", hr
);
1069 if (src
) IStorage_Release( src
);
1070 if (dst
) IStorage_Release( dst
);
1074 static UINT
HANDLE_CustomType7( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1075 INT type
, const WCHAR
*action
)
1077 WCHAR
*tmpfile
, *args
;
1078 MSIBINARY
*binary
= NULL
;
1082 if (!(tmpfile
= msi_create_temp_file( package
->db
))) return ERROR_FUNCTION_FAILED
;
1084 r
= write_substorage_to_file( package
, source
, tmpfile
);
1085 if (r
!= ERROR_SUCCESS
)
1088 if (!(binary
= msi_alloc( sizeof(*binary
) ))) goto error
;
1089 binary
->source
= NULL
;
1090 binary
->tmpfile
= tmpfile
;
1091 list_add_tail( &package
->binaries
, &binary
->entry
);
1093 if (!(args
= build_msiexec_args( tmpfile
, target
))) return ERROR_OUTOFMEMORY
;
1095 TRACE("installing %s concurrently\n", debugstr_w(source
));
1097 handle
= execute_command( L
"msiexec", args
, L
"C:\\" );
1099 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1100 return wait_process_handle( package
, type
, handle
, action
);
1103 DeleteFileW( tmpfile
);
1104 msi_free( tmpfile
);
1105 return ERROR_FUNCTION_FAILED
;
1108 static UINT
HANDLE_CustomType50( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1109 INT type
, const WCHAR
*action
)
1114 if (!(exe
= msi_dup_property( package
->db
, source
))) return ERROR_SUCCESS
;
1116 deformat_string( package
, target
, &arg
);
1117 TRACE("exe %s arg %s\n", debugstr_w(exe
), debugstr_w(arg
));
1119 handle
= execute_command( exe
, arg
, L
"C:\\" );
1122 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1123 return wait_process_handle( package
, type
, handle
, action
);
1126 static UINT
HANDLE_CustomType34( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1127 INT type
, const WCHAR
*action
)
1129 const WCHAR
*workingdir
= NULL
;
1135 workingdir
= msi_get_target_folder( package
, source
);
1136 if (!workingdir
) return ERROR_FUNCTION_FAILED
;
1138 deformat_string( package
, target
, &cmd
);
1139 if (!cmd
) return ERROR_FUNCTION_FAILED
;
1141 TRACE("cmd %s dir %s\n", debugstr_w(cmd
), debugstr_w(workingdir
));
1143 handle
= execute_command( NULL
, cmd
, workingdir
);
1145 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1146 return wait_process_handle( package
, type
, handle
, action
);
1149 static DWORD
ACTION_CallScript( const GUID
*guid
)
1151 msi_custom_action_info
*info
;
1153 UINT r
= ERROR_FUNCTION_FAILED
;
1155 info
= find_action_by_guid( guid
);
1158 ERR("failed to find action %s\n", debugstr_guid( guid
) );
1159 return ERROR_FUNCTION_FAILED
;
1162 TRACE("function %s, script %s\n", debugstr_w( info
->target
), debugstr_w( info
->source
) );
1164 hPackage
= alloc_msihandle( &info
->package
->hdr
);
1167 r
= call_script( hPackage
, info
->type
, info
->source
, info
->target
, info
->action
);
1168 TRACE("script returned %u\n", r
);
1169 MsiCloseHandle( hPackage
);
1172 ERR("failed to create handle for %p\n", info
->package
);
1177 static DWORD WINAPI
ScriptThread( LPVOID arg
)
1182 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1184 rc
= ACTION_CallScript( guid
);
1186 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc
);
1188 MsiCloseAllHandles();
1192 static msi_custom_action_info
*do_msidbCustomActionTypeScript(
1193 MSIPACKAGE
*package
, INT type
, LPCWSTR script
, LPCWSTR function
, LPCWSTR action
)
1195 msi_custom_action_info
*info
;
1197 info
= msi_alloc( sizeof *info
);
1201 msiobj_addref( &package
->hdr
);
1202 info
->package
= package
;
1204 info
->target
= strdupW( function
);
1205 info
->source
= strdupW( script
);
1206 info
->action
= strdupW( action
);
1207 CoCreateGuid( &info
->guid
);
1209 EnterCriticalSection( &msi_custom_action_cs
);
1210 list_add_tail( &msi_pending_custom_actions
, &info
->entry
);
1211 LeaveCriticalSection( &msi_custom_action_cs
);
1213 info
->handle
= CreateThread( NULL
, 0, ScriptThread
, &info
->guid
, 0, NULL
);
1216 free_custom_action_data( info
);
1223 static UINT
HANDLE_CustomType37_38( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1224 INT type
, const WCHAR
*action
)
1226 msi_custom_action_info
*info
;
1228 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1230 info
= do_msidbCustomActionTypeScript( package
, type
, target
, NULL
, action
);
1231 return wait_thread_handle( info
);
1234 static UINT
HANDLE_CustomType5_6( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1235 INT type
, const WCHAR
*action
)
1237 MSIRECORD
*row
= NULL
;
1238 msi_custom_action_info
*info
;
1239 CHAR
*buffer
= NULL
;
1240 WCHAR
*bufferw
= NULL
;
1244 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1246 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Binary` WHERE `Name` = '%s'", source
);
1248 return ERROR_FUNCTION_FAILED
;
1250 r
= MSI_RecordReadStream(row
, 2, NULL
, &sz
);
1251 if (r
!= ERROR_SUCCESS
) goto done
;
1253 buffer
= msi_alloc( sz
+ 1 );
1256 r
= ERROR_FUNCTION_FAILED
;
1260 r
= MSI_RecordReadStream(row
, 2, buffer
, &sz
);
1261 if (r
!= ERROR_SUCCESS
)
1265 bufferw
= strdupAtoW(buffer
);
1268 r
= ERROR_FUNCTION_FAILED
;
1272 info
= do_msidbCustomActionTypeScript( package
, type
, bufferw
, target
, action
);
1273 r
= wait_thread_handle( info
);
1278 msiobj_release(&row
->hdr
);
1282 static UINT
HANDLE_CustomType21_22( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1283 INT type
, const WCHAR
*action
)
1285 msi_custom_action_info
*info
;
1288 DWORD sz
, szHighWord
= 0, read
;
1290 WCHAR
*bufferw
=NULL
;
1294 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1296 file
= msi_get_loaded_file(package
, source
);
1299 ERR("invalid file key %s\n", debugstr_w(source
));
1300 return ERROR_FUNCTION_FAILED
;
1303 hFile
= msi_create_file( package
, file
->TargetPath
, GENERIC_READ
, FILE_SHARE_READ
, OPEN_EXISTING
, 0 );
1304 if (hFile
== INVALID_HANDLE_VALUE
) return ERROR_FUNCTION_FAILED
;
1306 sz
= GetFileSize(hFile
, &szHighWord
);
1307 if (sz
== INVALID_FILE_SIZE
|| szHighWord
!= 0)
1310 return ERROR_FUNCTION_FAILED
;
1312 buffer
= msi_alloc( sz
+ 1 );
1316 return ERROR_FUNCTION_FAILED
;
1318 bRet
= ReadFile(hFile
, buffer
, sz
, &read
, NULL
);
1322 r
= ERROR_FUNCTION_FAILED
;
1326 bufferw
= strdupAtoW(buffer
);
1329 r
= ERROR_FUNCTION_FAILED
;
1332 info
= do_msidbCustomActionTypeScript( package
, type
, bufferw
, target
, action
);
1333 r
= wait_thread_handle( info
);
1341 static UINT
HANDLE_CustomType53_54( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1342 INT type
, const WCHAR
*action
)
1344 msi_custom_action_info
*info
;
1347 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1349 prop
= msi_dup_property( package
->db
, source
);
1350 if (!prop
) return ERROR_SUCCESS
;
1352 info
= do_msidbCustomActionTypeScript( package
, type
, prop
, NULL
, action
);
1354 return wait_thread_handle( info
);
1357 static BOOL
action_type_matches_script( UINT type
, UINT script
)
1363 case SCRIPT_INSTALL
:
1364 return !(type
& msidbCustomActionTypeCommit
) && !(type
& msidbCustomActionTypeRollback
);
1366 return (type
& msidbCustomActionTypeCommit
);
1367 case SCRIPT_ROLLBACK
:
1368 return (type
& msidbCustomActionTypeRollback
);
1370 ERR("unhandled script %u\n", script
);
1375 static UINT
defer_custom_action( MSIPACKAGE
*package
, const WCHAR
*action
, UINT type
)
1377 WCHAR
*actiondata
= msi_dup_property( package
->db
, action
);
1378 WCHAR
*usersid
= msi_dup_property( package
->db
, L
"UserSID" );
1379 WCHAR
*prodcode
= msi_dup_property( package
->db
, L
"ProductCode" );
1380 WCHAR
*deferred
= msi_get_deferred_action( action
, actiondata
, usersid
, prodcode
);
1384 msi_free( actiondata
);
1385 msi_free( usersid
);
1386 msi_free( prodcode
);
1387 return ERROR_OUTOFMEMORY
;
1389 if (type
& msidbCustomActionTypeCommit
)
1391 TRACE("deferring commit action\n");
1392 msi_schedule_action( package
, SCRIPT_COMMIT
, deferred
);
1394 else if (type
& msidbCustomActionTypeRollback
)
1396 TRACE("deferring rollback action\n");
1397 msi_schedule_action( package
, SCRIPT_ROLLBACK
, deferred
);
1401 TRACE("deferring install action\n");
1402 msi_schedule_action( package
, SCRIPT_INSTALL
, deferred
);
1405 msi_free( actiondata
);
1406 msi_free( usersid
);
1407 msi_free( prodcode
);
1408 msi_free( deferred
);
1409 return ERROR_SUCCESS
;
1412 UINT
ACTION_CustomAction(MSIPACKAGE
*package
, const WCHAR
*action
)
1414 UINT rc
= ERROR_SUCCESS
;
1417 const WCHAR
*source
, *target
, *ptr
, *deferred_data
= NULL
;
1418 WCHAR
*deformated
= NULL
;
1421 /* deferred action: [properties]Action */
1422 if ((ptr
= wcsrchr(action
, ']')))
1424 deferred_data
= action
;
1428 row
= MSI_QueryGetRecord( package
->db
, L
"SELECT * FROM `CustomAction` WHERE `Action` = '%s'", action
);
1430 return ERROR_FUNCTION_NOT_CALLED
;
1432 type
= MSI_RecordGetInteger(row
,2);
1433 source
= MSI_RecordGetString(row
,3);
1434 target
= MSI_RecordGetString(row
,4);
1436 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action
),type
,
1437 debugstr_w(source
), debugstr_w(target
));
1439 /* handle some of the deferred actions */
1440 if (type
& msidbCustomActionTypeTSAware
)
1441 FIXME("msidbCustomActionTypeTSAware not handled\n");
1443 if (type
& msidbCustomActionTypeInScript
)
1445 if (type
& msidbCustomActionTypeNoImpersonate
)
1446 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1448 if (!action_type_matches_script(type
, package
->script
))
1450 rc
= defer_custom_action( package
, action
, type
);
1455 LPWSTR actiondata
= msi_dup_property( package
->db
, action
);
1457 if (type
& msidbCustomActionTypeInScript
)
1458 package
->scheduled_action_running
= TRUE
;
1460 if (type
& msidbCustomActionTypeCommit
)
1461 package
->commit_action_running
= TRUE
;
1463 if (type
& msidbCustomActionTypeRollback
)
1464 package
->rollback_action_running
= TRUE
;
1467 set_deferred_action_props(package
, deferred_data
);
1468 else if (actiondata
)
1469 msi_set_property( package
->db
, L
"CustomActionData", actiondata
, -1 );
1471 msi_set_property( package
->db
, L
"CustomActionData", L
"", -1 );
1473 msi_free(actiondata
);
1476 else if (!check_execution_scheduling_options(package
,action
,type
))
1482 switch (type
& CUSTOM_ACTION_TYPE_MASK
)
1484 case 1: /* DLL file stored in a Binary table stream */
1485 rc
= HANDLE_CustomType1( package
, source
, target
, type
, action
);
1487 case 2: /* EXE file stored in a Binary table stream */
1488 rc
= HANDLE_CustomType2( package
, source
, target
, type
, action
);
1491 case 6: /* JScript/VBScript file stored in a Binary table stream */
1492 rc
= HANDLE_CustomType5_6( package
, source
, target
, type
, action
);
1494 case 7: /* Concurrent install from substorage */
1495 deformat_string( package
, target
, &deformated
);
1496 rc
= HANDLE_CustomType7( package
, source
, target
, type
, action
);
1497 msi_free( deformated
);
1500 rc
= HANDLE_CustomType17( package
, source
, target
, type
, action
);
1502 case 18: /* EXE file installed with package */
1503 rc
= HANDLE_CustomType18( package
, source
, target
, type
, action
);
1505 case 19: /* Error that halts install */
1506 rc
= HANDLE_CustomType19( package
, source
, target
, type
, action
);
1508 case 21: /* JScript/VBScript file installed with the product */
1510 rc
= HANDLE_CustomType21_22( package
, source
, target
, type
, action
);
1512 case 23: /* Installs another package in the source tree */
1513 deformat_string( package
, target
, &deformated
);
1514 rc
= HANDLE_CustomType23( package
, source
, deformated
, type
, action
);
1515 msi_free( deformated
);
1517 case 34: /* EXE to be run in specified directory */
1518 rc
= HANDLE_CustomType34( package
, source
, target
, type
, action
);
1520 case 35: /* Directory set with formatted text */
1521 deformat_string( package
, target
, &deformated
);
1522 MSI_SetTargetPathW( package
, source
, deformated
);
1523 msi_free( deformated
);
1525 case 37: /* JScript/VBScript text stored in target column */
1527 rc
= HANDLE_CustomType37_38( package
, source
, target
, type
, action
);
1529 case 50: /* EXE file specified by a property value */
1530 rc
= HANDLE_CustomType50( package
, source
, target
, type
, action
);
1532 case 51: /* Property set with formatted text */
1534 len
= deformat_string( package
, target
, &deformated
);
1535 rc
= msi_set_property( package
->db
, source
, deformated
, len
);
1536 if (rc
== ERROR_SUCCESS
&& !wcscmp( source
, L
"SourceDir" )) msi_reset_source_folders( package
);
1537 msi_free( deformated
);
1539 case 53: /* JScript/VBScript text specified by a property value */
1541 rc
= HANDLE_CustomType53_54( package
, source
, target
, type
, action
);
1544 FIXME( "unhandled action type %u (%s %s)\n", type
& CUSTOM_ACTION_TYPE_MASK
, debugstr_w(source
),
1545 debugstr_w(target
) );
1549 package
->scheduled_action_running
= FALSE
;
1550 package
->commit_action_running
= FALSE
;
1551 package
->rollback_action_running
= FALSE
;
1552 msiobj_release(&row
->hdr
);
1556 void ACTION_FinishCustomActions(const MSIPACKAGE
* package
)
1559 HANDLE
*wait_handles
;
1560 unsigned int handle_count
, i
;
1561 msi_custom_action_info
*info
, *cursor
;
1563 while ((item
= list_head( &package
->RunningActions
)))
1565 MSIRUNNINGACTION
*action
= LIST_ENTRY( item
, MSIRUNNINGACTION
, entry
);
1567 list_remove( &action
->entry
);
1569 TRACE("waiting for %s\n", debugstr_w( action
->name
) );
1570 msi_dialog_check_messages( action
->handle
);
1572 CloseHandle( action
->handle
);
1573 msi_free( action
->name
);
1577 EnterCriticalSection( &msi_custom_action_cs
);
1579 handle_count
= list_count( &msi_pending_custom_actions
);
1580 wait_handles
= msi_alloc( handle_count
* sizeof(HANDLE
) );
1583 LIST_FOR_EACH_ENTRY_SAFE( info
, cursor
, &msi_pending_custom_actions
, msi_custom_action_info
, entry
)
1585 if (info
->package
== package
)
1587 if (DuplicateHandle(GetCurrentProcess(), info
->handle
, GetCurrentProcess(), &wait_handles
[handle_count
], SYNCHRONIZE
, FALSE
, 0))
1592 LeaveCriticalSection( &msi_custom_action_cs
);
1594 for (i
= 0; i
< handle_count
; i
++)
1596 msi_dialog_check_messages( wait_handles
[i
] );
1597 CloseHandle( wait_handles
[i
] );
1599 msi_free( wait_handles
);
1601 EnterCriticalSection( &msi_custom_action_cs
);
1602 LIST_FOR_EACH_ENTRY_SAFE( info
, cursor
, &msi_pending_custom_actions
, msi_custom_action_info
, entry
)
1604 if (info
->package
== package
)
1605 free_custom_action_data( info
);
1607 LeaveCriticalSection( &msi_custom_action_cs
);
1610 UINT __cdecl
s_remote_GetActionInfo(const GUID
*guid
, WCHAR
**name
, int *type
, WCHAR
**dll
, char **func
, MSIHANDLE
*hinst
)
1612 msi_custom_action_info
*info
;
1614 info
= find_action_by_guid(guid
);
1616 return ERROR_INVALID_DATA
;
1618 *name
= strdupW(info
->action
);
1620 *hinst
= alloc_msihandle(&info
->package
->hdr
);
1621 *dll
= strdupW(info
->source
);
1622 *func
= strdupWtoA(info
->target
);
1624 return ERROR_SUCCESS
;