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
36 #include "wine/heap.h"
37 #include "wine/debug.h"
38 #include "wine/exception.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
42 #define CUSTOM_ACTION_TYPE_MASK 0x3F
44 typedef struct tagMSIRUNNINGACTION
52 typedef UINT (WINAPI
*MsiCustomActionEntryPoint
)( MSIHANDLE
);
54 static CRITICAL_SECTION msi_custom_action_cs
;
55 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug
=
57 0, 0, &msi_custom_action_cs
,
58 { &msi_custom_action_cs_debug
.ProcessLocksList
,
59 &msi_custom_action_cs_debug
.ProcessLocksList
},
60 0, 0, { (DWORD_PTR
)(__FILE__
": msi_custom_action_cs") }
62 static CRITICAL_SECTION msi_custom_action_cs
= { &msi_custom_action_cs_debug
, -1, 0, 0, 0, 0 };
64 static struct list msi_pending_custom_actions
= LIST_INIT( msi_pending_custom_actions
);
66 void __RPC_FAR
* __RPC_USER
MIDL_user_allocate(SIZE_T len
)
68 return heap_alloc(len
);
71 void __RPC_USER
MIDL_user_free(void __RPC_FAR
* ptr
)
76 LONG WINAPI
rpc_filter(EXCEPTION_POINTERS
*eptr
)
78 return I_RpcExceptionFilter(eptr
->ExceptionRecord
->ExceptionCode
);
81 UINT
msi_schedule_action( MSIPACKAGE
*package
, UINT script
, const WCHAR
*action
)
84 WCHAR
**newbuf
= NULL
;
86 if (script
>= SCRIPT_MAX
)
88 FIXME("Unknown script requested %u\n", script
);
89 return ERROR_FUNCTION_FAILED
;
91 TRACE("Scheduling action %s in script %u\n", debugstr_w(action
), script
);
93 count
= package
->script_actions_count
[script
];
94 package
->script_actions_count
[script
]++;
95 if (count
!= 0) newbuf
= msi_realloc( package
->script_actions
[script
],
96 package
->script_actions_count
[script
] * sizeof(WCHAR
*) );
97 else newbuf
= msi_alloc( sizeof(WCHAR
*) );
99 newbuf
[count
] = strdupW( action
);
100 package
->script_actions
[script
] = newbuf
;
101 return ERROR_SUCCESS
;
104 UINT
msi_register_unique_action( MSIPACKAGE
*package
, const WCHAR
*action
)
107 WCHAR
**newbuf
= NULL
;
109 TRACE("Registering %s as unique action\n", debugstr_w(action
));
111 count
= package
->unique_actions_count
;
112 package
->unique_actions_count
++;
113 if (count
!= 0) newbuf
= msi_realloc( package
->unique_actions
,
114 package
->unique_actions_count
* sizeof(WCHAR
*) );
115 else newbuf
= msi_alloc( sizeof(WCHAR
*) );
117 newbuf
[count
] = strdupW( action
);
118 package
->unique_actions
= newbuf
;
119 return ERROR_SUCCESS
;
122 BOOL
msi_action_is_unique( const MSIPACKAGE
*package
, const WCHAR
*action
)
126 for (i
= 0; i
< package
->unique_actions_count
; i
++)
128 if (!wcscmp( package
->unique_actions
[i
], action
)) return TRUE
;
133 static BOOL
check_execution_scheduling_options(MSIPACKAGE
*package
, LPCWSTR action
, UINT options
)
135 if ((options
& msidbCustomActionTypeClientRepeat
) ==
136 msidbCustomActionTypeClientRepeat
)
138 if (!(package
->InWhatSequence
& SEQUENCE_UI
&&
139 package
->InWhatSequence
& SEQUENCE_EXEC
))
141 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
145 else if (options
& msidbCustomActionTypeFirstSequence
)
147 if (package
->InWhatSequence
& SEQUENCE_UI
&&
148 package
->InWhatSequence
& SEQUENCE_EXEC
)
150 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
154 else if (options
& msidbCustomActionTypeOncePerProcess
)
156 if (msi_action_is_unique(package
, action
))
158 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
162 msi_register_unique_action(package
, action
);
168 /* stores the following properties before the action:
170 * [CustomActionData<=>UserSID<=>ProductCode]Action
172 static LPWSTR
msi_get_deferred_action(LPCWSTR action
, LPCWSTR actiondata
,
173 LPCWSTR usersid
, LPCWSTR prodcode
)
178 static const WCHAR format
[] = {
179 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
183 return strdupW(action
);
185 len
= lstrlenW(action
) + lstrlenW(actiondata
) +
186 lstrlenW(usersid
) + lstrlenW(prodcode
) +
187 lstrlenW(format
) - 7;
188 deferred
= msi_alloc(len
* sizeof(WCHAR
));
190 swprintf(deferred
, len
, format
, actiondata
, usersid
, prodcode
, action
);
194 static void set_deferred_action_props( MSIPACKAGE
*package
, const WCHAR
*deferred_data
)
196 static const WCHAR sep
[] = {'<','=','>',0};
197 const WCHAR
*end
, *beg
= deferred_data
+ 1;
199 end
= wcsstr(beg
, sep
);
200 msi_set_property( package
->db
, szCustomActionData
, beg
, end
- beg
);
203 end
= wcsstr(beg
, sep
);
204 msi_set_property( package
->db
, szUserSID
, beg
, end
- beg
);
207 end
= wcschr(beg
, ']');
208 msi_set_property( package
->db
, szProductCode
, beg
, end
- beg
);
211 WCHAR
*msi_create_temp_file( MSIDATABASE
*db
)
218 UINT len
= ARRAY_SIZE( tmp
);
220 if (msi_get_property( db
, szTempFolder
, tmp
, &len
) ||
221 GetFileAttributesW( tmp
) != FILE_ATTRIBUTE_DIRECTORY
)
223 GetTempPathW( MAX_PATH
, tmp
);
225 if (!(db
->tempfolder
= strdupW( tmp
))) return NULL
;
228 if ((ret
= msi_alloc( (lstrlenW( db
->tempfolder
) + 20) * sizeof(WCHAR
) )))
230 if (!GetTempFileNameW( db
->tempfolder
, szMsi
, 0, ret
))
240 static MSIBINARY
*create_temp_binary(MSIPACKAGE
*package
, LPCWSTR source
)
242 static const WCHAR query
[] = {
243 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
244 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
245 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
247 MSIBINARY
*binary
= NULL
;
254 if (!(tmpfile
= msi_create_temp_file( package
->db
))) return NULL
;
256 if (!(row
= MSI_QueryGetRecord( package
->db
, query
, source
))) goto error
;
257 if (!(binary
= msi_alloc_zero( sizeof(MSIBINARY
) ))) goto error
;
259 file
= CreateFileW( tmpfile
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
260 if (file
== INVALID_HANDLE_VALUE
) goto error
;
265 r
= MSI_RecordReadStream( row
, 2, buffer
, &sz
);
266 if (r
!= ERROR_SUCCESS
)
268 ERR("Failed to get stream\n");
271 WriteFile( file
, buffer
, sz
, &write
, NULL
);
272 } while (sz
== sizeof buffer
);
275 if (r
!= ERROR_SUCCESS
) goto error
;
277 binary
->source
= strdupW( source
);
278 binary
->tmpfile
= tmpfile
;
279 list_add_tail( &package
->binaries
, &binary
->entry
);
281 msiobj_release( &row
->hdr
);
285 if (row
) msiobj_release( &row
->hdr
);
286 DeleteFileW( tmpfile
);
292 static MSIBINARY
*get_temp_binary(MSIPACKAGE
*package
, LPCWSTR source
)
296 LIST_FOR_EACH_ENTRY( binary
, &package
->binaries
, MSIBINARY
, entry
)
298 if (!wcscmp( binary
->source
, source
))
302 return create_temp_binary(package
, source
);
305 static void file_running_action(MSIPACKAGE
* package
, HANDLE Handle
,
306 BOOL process
, LPCWSTR name
)
308 MSIRUNNINGACTION
*action
;
310 action
= msi_alloc( sizeof(MSIRUNNINGACTION
) );
312 action
->handle
= Handle
;
313 action
->process
= process
;
314 action
->name
= strdupW(name
);
316 list_add_tail( &package
->RunningActions
, &action
->entry
);
319 static UINT
custom_get_process_return( HANDLE process
)
323 GetExitCodeProcess( process
, &rc
);
324 TRACE("exit code is %u\n", rc
);
326 return ERROR_FUNCTION_FAILED
;
327 return ERROR_SUCCESS
;
330 static UINT
custom_get_thread_return( MSIPACKAGE
*package
, HANDLE thread
)
334 GetExitCodeThread( thread
, &rc
);
338 case ERROR_FUNCTION_NOT_CALLED
:
340 case ERROR_INSTALL_USEREXIT
:
341 case ERROR_INSTALL_FAILURE
:
343 case ERROR_NO_MORE_ITEMS
:
344 return ERROR_SUCCESS
;
345 case ERROR_INSTALL_SUSPEND
:
346 ACTION_ForceReboot( package
);
347 return ERROR_SUCCESS
;
349 ERR("Invalid Return Code %d\n",rc
);
350 return ERROR_INSTALL_FAILURE
;
354 static UINT
wait_process_handle(MSIPACKAGE
* package
, UINT type
,
355 HANDLE ProcessHandle
, LPCWSTR name
)
357 UINT rc
= ERROR_SUCCESS
;
359 if (!(type
& msidbCustomActionTypeAsync
))
361 TRACE("waiting for %s\n", debugstr_w(name
));
363 msi_dialog_check_messages(ProcessHandle
);
365 if (!(type
& msidbCustomActionTypeContinue
))
366 rc
= custom_get_process_return(ProcessHandle
);
368 CloseHandle(ProcessHandle
);
372 TRACE("%s running in background\n", debugstr_w(name
));
374 if (!(type
& msidbCustomActionTypeContinue
))
375 file_running_action(package
, ProcessHandle
, TRUE
, name
);
377 CloseHandle(ProcessHandle
);
383 typedef struct _msi_custom_action_info
{
393 } msi_custom_action_info
;
395 static void free_custom_action_data( msi_custom_action_info
*info
)
397 EnterCriticalSection( &msi_custom_action_cs
);
399 list_remove( &info
->entry
);
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
);
408 LeaveCriticalSection( &msi_custom_action_cs
);
411 static UINT
wait_thread_handle( msi_custom_action_info
*info
)
413 UINT rc
= ERROR_SUCCESS
;
415 if (!(info
->type
& msidbCustomActionTypeAsync
))
417 TRACE("waiting for %s\n", debugstr_w( info
->action
));
419 msi_dialog_check_messages( info
->handle
);
421 if (!(info
->type
& msidbCustomActionTypeContinue
))
422 rc
= custom_get_thread_return( info
->package
, info
->handle
);
424 free_custom_action_data( info
);
428 TRACE("%s running in background\n", debugstr_w( info
->action
));
434 static msi_custom_action_info
*find_action_by_guid( const GUID
*guid
)
436 msi_custom_action_info
*info
;
439 EnterCriticalSection( &msi_custom_action_cs
);
441 LIST_FOR_EACH_ENTRY( info
, &msi_pending_custom_actions
, msi_custom_action_info
, entry
)
443 if (IsEqualGUID( &info
->guid
, guid
))
450 LeaveCriticalSection( &msi_custom_action_cs
);
458 static void handle_msi_break(LPCSTR target
)
460 char format
[] = "To debug your custom action, attach your debugger to "
461 "process %i (0x%X) and press OK";
465 if (!GetEnvironmentVariableA("MsiBreak", val
, MAX_PATH
))
468 if (strcmp(val
, target
))
471 sprintf(msg
, format
, GetCurrentProcessId(), GetCurrentProcessId());
472 MessageBoxA(NULL
, msg
, "Windows Installer", MB_OK
);
476 static WCHAR ncalrpcW
[] = {'n','c','a','l','r','p','c',0};
477 static WCHAR endpoint_fmtW
[] = {'m','s','i','%','x',0};
480 /* wrapper for apps that don't declare the thread function correctly */
481 extern UINT
custom_proc_wrapper( MsiCustomActionEntryPoint entry
, MSIHANDLE hinst
);
482 __ASM_GLOBAL_FUNC(custom_proc_wrapper
,
484 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
485 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
487 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
492 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
493 __ASM_CFI(".cfi_same_value %ebp\n\t")
496 static UINT
custom_proc_wrapper( MsiCustomActionEntryPoint entry
, MSIHANDLE hinst
)
502 UINT CDECL
__wine_msi_call_dll_function(DWORD client_pid
, const GUID
*guid
)
504 MsiCustomActionEntryPoint fn
;
505 MSIHANDLE remote_package
= 0;
506 RPC_WSTR binding_str
;
515 TRACE("%s\n", debugstr_guid( guid
));
521 swprintf(endpoint
, ARRAY_SIZE(endpoint
), endpoint_fmtW
, client_pid
);
522 status
= RpcStringBindingComposeW(NULL
, ncalrpcW
, NULL
, endpoint
, NULL
, &binding_str
);
523 if (status
!= RPC_S_OK
)
525 ERR("RpcStringBindingCompose failed: %#x\n", status
);
528 status
= RpcBindingFromStringBindingW(binding_str
, &rpc_handle
);
529 if (status
!= RPC_S_OK
)
531 ERR("RpcBindingFromStringBinding failed: %#x\n", status
);
534 RpcStringFreeW(&binding_str
);
537 r
= remote_GetActionInfo(guid
, &type
, &dll
, &proc
, &remote_package
);
538 if (r
!= ERROR_SUCCESS
)
541 hPackage
= alloc_msi_remote_handle( remote_package
);
544 ERR( "failed to create handle for %x\n", remote_package
);
545 midl_user_free( dll
);
546 midl_user_free( proc
);
547 return ERROR_INSTALL_FAILURE
;
550 hModule
= LoadLibraryW( dll
);
553 ERR( "failed to load dll %s (%u)\n", debugstr_w( dll
), GetLastError() );
554 midl_user_free( dll
);
555 midl_user_free( proc
);
556 MsiCloseHandle( hPackage
);
557 return ERROR_SUCCESS
;
560 fn
= (MsiCustomActionEntryPoint
) GetProcAddress( hModule
, proc
);
561 if (!fn
) WARN( "GetProcAddress(%s) failed\n", debugstr_a(proc
) );
564 handle_msi_break(proc
);
568 r
= custom_proc_wrapper( fn
, hPackage
);
572 ERR( "Custom action (%s:%s) caused a page fault: %08x\n",
573 debugstr_w(dll
), debugstr_a(proc
), GetExceptionCode() );
579 FreeLibrary(hModule
);
582 midl_user_free(proc
);
584 MsiCloseAllHandles();
589 static DWORD
custom_start_server(MSIPACKAGE
*package
, DWORD arch
)
591 static const WCHAR pipe_name
[] = {'\\','\\','.','\\','p','i','p','e','\\','m','s','i','c','a','_','%','x','_','%','d',0};
592 static const WCHAR msiexecW
[] = {'\\','m','s','i','e','x','e','c','.','e','x','e',0};
593 static const WCHAR argsW
[] = {'%','s',' ','-','E','m','b','e','d','d','i','n','g',' ','%','d',0};
595 WCHAR path
[MAX_PATH
], cmdline
[MAX_PATH
+ 23];
596 PROCESS_INFORMATION pi
= {0};
597 STARTUPINFOW si
= {0};
603 if ((arch
== SCS_32BIT_BINARY
&& package
->custom_server_32_process
) ||
604 (arch
== SCS_64BIT_BINARY
&& package
->custom_server_64_process
))
605 return ERROR_SUCCESS
;
607 swprintf(buffer
, ARRAY_SIZE(buffer
), pipe_name
,
608 GetCurrentProcessId(), arch
== SCS_32BIT_BINARY
? 32 : 64);
609 pipe
= CreateNamedPipeW(buffer
, PIPE_ACCESS_DUPLEX
, 0, 1, sizeof(DWORD64
),
610 sizeof(GUID
), 0, NULL
);
611 if (pipe
== INVALID_HANDLE_VALUE
)
612 ERR("Failed to create custom action client pipe: %u\n", GetLastError());
614 if (!IsWow64Process(GetCurrentProcess(), &wow64
))
617 if ((sizeof(void *) == 8 || wow64
) && arch
== SCS_32BIT_BINARY
)
618 GetSystemWow64DirectoryW(path
, MAX_PATH
- ARRAY_SIZE(msiexecW
));
620 GetSystemDirectoryW(path
, MAX_PATH
- ARRAY_SIZE(msiexecW
));
621 lstrcatW(path
, msiexecW
);
622 swprintf(cmdline
, ARRAY_SIZE(cmdline
), argsW
, path
, GetCurrentProcessId());
624 if (wow64
&& arch
== SCS_64BIT_BINARY
)
626 Wow64DisableWow64FsRedirection(&cookie
);
627 CreateProcessW(path
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
628 Wow64RevertWow64FsRedirection(cookie
);
631 CreateProcessW(path
, cmdline
, NULL
, NULL
, FALSE
, 0, NULL
, NULL
, &si
, &pi
);
633 CloseHandle(pi
.hThread
);
635 if (arch
== SCS_32BIT_BINARY
)
637 package
->custom_server_32_process
= pi
.hProcess
;
638 package
->custom_server_32_pipe
= pipe
;
642 package
->custom_server_64_process
= pi
.hProcess
;
643 package
->custom_server_64_pipe
= pipe
;
646 if (!ConnectNamedPipe(pipe
, NULL
))
648 ERR("Failed to connect to custom action server: %u\n", GetLastError());
649 return GetLastError();
652 return ERROR_SUCCESS
;
655 void custom_stop_server(HANDLE process
, HANDLE pipe
)
659 WriteFile(pipe
, &GUID_NULL
, sizeof(GUID_NULL
), &size
, NULL
);
660 WaitForSingleObject(process
, INFINITE
);
661 CloseHandle(process
);
665 static DWORD WINAPI
custom_client_thread(void *arg
)
667 msi_custom_action_info
*info
= arg
;
675 CoInitializeEx(NULL
, COINIT_MULTITHREADED
); /* needed to marshal streams */
677 if (info
->arch
== SCS_32BIT_BINARY
)
679 process
= info
->package
->custom_server_32_process
;
680 pipe
= info
->package
->custom_server_32_pipe
;
684 process
= info
->package
->custom_server_64_process
;
685 pipe
= info
->package
->custom_server_64_pipe
;
688 EnterCriticalSection(&msi_custom_action_cs
);
690 if (!WriteFile(pipe
, &info
->guid
, sizeof(info
->guid
), &size
, NULL
) ||
691 size
!= sizeof(info
->guid
))
693 ERR("Failed to write to custom action client pipe: %u\n", GetLastError());
694 LeaveCriticalSection(&msi_custom_action_cs
);
695 return GetLastError();
697 if (!ReadFile(pipe
, &thread64
, sizeof(thread64
), &size
, NULL
) || size
!= sizeof(thread64
))
699 ERR("Failed to read from custom action client pipe: %u\n", GetLastError());
700 LeaveCriticalSection(&msi_custom_action_cs
);
701 return GetLastError();
704 LeaveCriticalSection(&msi_custom_action_cs
);
706 if (DuplicateHandle(process
, (HANDLE
)(DWORD_PTR
)thread64
, GetCurrentProcess(),
707 &thread
, 0, FALSE
, DUPLICATE_SAME_ACCESS
| DUPLICATE_CLOSE_SOURCE
))
709 WaitForSingleObject(thread
, INFINITE
);
710 GetExitCodeThread(thread
, &rc
);
720 static msi_custom_action_info
*do_msidbCustomActionTypeDll(
721 MSIPACKAGE
*package
, INT type
, LPCWSTR source
, LPCWSTR target
, LPCWSTR action
)
723 msi_custom_action_info
*info
;
727 info
= msi_alloc( sizeof *info
);
731 msiobj_addref( &package
->hdr
);
732 info
->package
= package
;
734 info
->target
= strdupW( target
);
735 info
->source
= strdupW( source
);
736 info
->action
= strdupW( action
);
737 CoCreateGuid( &info
->guid
);
739 EnterCriticalSection( &msi_custom_action_cs
);
740 list_add_tail( &msi_pending_custom_actions
, &info
->entry
);
741 LeaveCriticalSection( &msi_custom_action_cs
);
743 if (!package
->rpc_server_started
)
747 swprintf(endpoint
, ARRAY_SIZE(endpoint
), endpoint_fmtW
, GetCurrentProcessId());
748 status
= RpcServerUseProtseqEpW(ncalrpcW
, RPC_C_PROTSEQ_MAX_REQS_DEFAULT
,
750 if (status
!= RPC_S_OK
)
752 ERR("RpcServerUseProtseqEp failed: %#x\n", status
);
756 status
= RpcServerRegisterIfEx(s_IWineMsiRemote_v0_0_s_ifspec
, NULL
, NULL
,
757 RPC_IF_AUTOLISTEN
, RPC_C_LISTEN_MAX_CALLS_DEFAULT
, NULL
);
758 if (status
!= RPC_S_OK
)
760 ERR("RpcServerRegisterIfEx failed: %#x\n", status
);
764 info
->package
->rpc_server_started
= 1;
767 ret
= GetBinaryTypeW(source
, &info
->arch
);
769 info
->arch
= (sizeof(void *) == 8 ? SCS_64BIT_BINARY
: SCS_32BIT_BINARY
);
771 custom_start_server(package
, info
->arch
);
773 info
->handle
= CreateThread(NULL
, 0, custom_client_thread
, info
, 0, NULL
);
776 free_custom_action_data( info
);
783 static UINT
HANDLE_CustomType1( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
784 INT type
, const WCHAR
*action
)
786 msi_custom_action_info
*info
;
789 if (!(binary
= get_temp_binary(package
, source
)))
790 return ERROR_FUNCTION_FAILED
;
792 TRACE("Calling function %s from %s\n", debugstr_w(target
), debugstr_w(binary
->tmpfile
));
794 info
= do_msidbCustomActionTypeDll( package
, type
, binary
->tmpfile
, target
, action
);
795 return wait_thread_handle( info
);
798 static HANDLE
execute_command( const WCHAR
*app
, WCHAR
*arg
, const WCHAR
*dir
)
800 static const WCHAR dotexeW
[] = {'.','e','x','e',0};
802 PROCESS_INFORMATION info
;
803 WCHAR
*exe
= NULL
, *cmd
= NULL
, *p
;
811 if (!(exe
= msi_alloc( MAX_PATH
* sizeof(WCHAR
) ))) return INVALID_HANDLE_VALUE
;
812 len_exe
= SearchPathW( NULL
, app
, dotexeW
, MAX_PATH
, exe
, NULL
);
813 if (len_exe
>= MAX_PATH
)
816 if (!(exe
= msi_alloc( len_exe
* sizeof(WCHAR
) ))) return INVALID_HANDLE_VALUE
;
817 len_exe
= SearchPathW( NULL
, app
, dotexeW
, len_exe
, exe
, NULL
);
821 ERR("can't find executable %u\n", GetLastError());
823 return INVALID_HANDLE_VALUE
;
826 if (arg
) len_arg
= lstrlenW( arg
);
827 if (!(cmd
= msi_alloc( (len_exe
+ len_arg
+ 4) * sizeof(WCHAR
) )))
830 return INVALID_HANDLE_VALUE
;
833 if (wcschr( exe
, ' ' ))
836 memcpy( p
, exe
, len_exe
* sizeof(WCHAR
) );
849 memcpy( p
, arg
, len_arg
* sizeof(WCHAR
) );
853 memset( &si
, 0, sizeof(STARTUPINFOW
) );
854 ret
= CreateProcessW( exe
, exe
? cmd
: arg
, NULL
, NULL
, FALSE
, 0, NULL
, dir
, &si
, &info
);
859 ERR("unable to execute command %u\n", GetLastError());
860 return INVALID_HANDLE_VALUE
;
862 CloseHandle( info
.hThread
);
863 return info
.hProcess
;
866 static UINT
HANDLE_CustomType2( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
867 INT type
, const WCHAR
*action
)
873 if (!(binary
= get_temp_binary(package
, source
)))
874 return ERROR_FUNCTION_FAILED
;
876 deformat_string( package
, target
, &arg
);
877 TRACE("exe %s arg %s\n", debugstr_w(binary
->tmpfile
), debugstr_w(arg
));
879 handle
= execute_command( binary
->tmpfile
, arg
, szCRoot
);
881 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
882 return wait_process_handle( package
, type
, handle
, action
);
885 static UINT
HANDLE_CustomType17( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
886 INT type
, const WCHAR
*action
)
888 msi_custom_action_info
*info
;
891 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
893 file
= msi_get_loaded_file( package
, source
);
896 ERR("invalid file key %s\n", debugstr_w( source
));
897 return ERROR_FUNCTION_FAILED
;
900 info
= do_msidbCustomActionTypeDll( package
, type
, file
->TargetPath
, target
, action
);
901 return wait_thread_handle( info
);
904 static UINT
HANDLE_CustomType18( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
905 INT type
, const WCHAR
*action
)
911 if (!(file
= msi_get_loaded_file( package
, source
))) return ERROR_FUNCTION_FAILED
;
913 deformat_string( package
, target
, &arg
);
914 TRACE("exe %s arg %s\n", debugstr_w(file
->TargetPath
), debugstr_w(arg
));
916 handle
= execute_command( file
->TargetPath
, arg
, szCRoot
);
918 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
919 return wait_process_handle( package
, type
, handle
, action
);
922 static UINT
HANDLE_CustomType19( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
923 INT type
, const WCHAR
*action
)
925 static const WCHAR query
[] = {
926 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
927 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
928 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
932 LPWSTR deformated
= NULL
;
934 deformat_string( package
, target
, &deformated
);
936 /* first try treat the error as a number */
937 row
= MSI_QueryGetRecord( package
->db
, query
, deformated
);
940 LPCWSTR error
= MSI_RecordGetString( row
, 1 );
941 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
942 MessageBoxW( NULL
, error
, NULL
, MB_OK
);
943 msiobj_release( &row
->hdr
);
945 else if ((package
->ui_level
& INSTALLUILEVEL_MASK
) != INSTALLUILEVEL_NONE
)
946 MessageBoxW( NULL
, deformated
, NULL
, MB_OK
);
948 msi_free( deformated
);
950 return ERROR_INSTALL_FAILURE
;
953 static WCHAR
*build_msiexec_args( const WCHAR
*filename
, const WCHAR
*params
)
955 UINT len_filename
= lstrlenW( filename
), len_params
= lstrlenW( params
);
956 UINT len
= ARRAY_SIZE(L
"/qb /i ") - 1;
959 if (!(ret
= msi_alloc( (len
+ len_filename
+ len_params
+ 4) * sizeof(WCHAR
) ))) return NULL
;
960 memcpy( ret
, L
"/qb /i ", sizeof(L
"/qb /i ") );
962 memcpy( ret
+ len
, filename
, len_filename
* sizeof(WCHAR
) );
966 lstrcpyW( ret
+ len
, params
);
970 static UINT
HANDLE_CustomType23( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
971 INT type
, const WCHAR
*action
)
973 WCHAR
*dir
, *filename
, *args
, *p
;
974 UINT len_dir
, len_source
= lstrlenW( source
);
977 if (!(dir
= msi_dup_property( package
->db
, szOriginalDatabase
))) return ERROR_OUTOFMEMORY
;
978 if (!(p
= wcsrchr( dir
, '\\' )) && !(p
= wcsrchr( dir
, '/' )))
981 return ERROR_FUNCTION_FAILED
;
985 if (!(filename
= msi_alloc( (len_dir
+ len_source
+ 2) * sizeof(WCHAR
) )))
988 return ERROR_OUTOFMEMORY
;
990 memcpy( filename
, dir
, len_dir
* sizeof(WCHAR
) );
991 filename
[len_dir
++] = '\\';
992 memcpy( filename
+ len_dir
, source
, len_source
* sizeof(WCHAR
) );
993 filename
[len_dir
+ len_source
] = 0;
995 if (!(args
= build_msiexec_args( filename
, target
)))
998 return ERROR_OUTOFMEMORY
;
1001 TRACE("installing %s concurrently\n", debugstr_w(source
));
1003 handle
= execute_command( L
"msiexec", args
, dir
);
1006 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1007 return wait_process_handle( package
, type
, handle
, action
);
1010 static UINT
write_substorage_to_file( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*filename
)
1012 IStorage
*src
= NULL
, *dst
= NULL
;
1013 UINT r
= ERROR_FUNCTION_FAILED
;
1016 hr
= StgCreateDocfile( filename
, STGM_CREATE
|STGM_TRANSACTED
|STGM_WRITE
|STGM_SHARE_EXCLUSIVE
, 0, &dst
);
1019 WARN( "can't open destination storage %s (%08x)\n", debugstr_w(filename
), hr
);
1023 hr
= IStorage_OpenStorage( package
->db
->storage
, source
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &src
);
1026 WARN( "can't open source storage %s (%08x)\n", debugstr_w(source
), hr
);
1030 hr
= IStorage_CopyTo( src
, 0, NULL
, NULL
, dst
);
1033 ERR( "failed to copy storage %s (%08x)\n", debugstr_w(source
), hr
);
1037 hr
= IStorage_Commit( dst
, 0 );
1039 ERR( "failed to commit storage (%08x)\n", hr
);
1044 if (src
) IStorage_Release( src
);
1045 if (dst
) IStorage_Release( dst
);
1049 static UINT
HANDLE_CustomType7( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1050 INT type
, const WCHAR
*action
)
1052 WCHAR
*tmpfile
, *args
;
1053 MSIBINARY
*binary
= NULL
;
1057 if (!(tmpfile
= msi_create_temp_file( package
->db
))) return ERROR_FUNCTION_FAILED
;
1059 r
= write_substorage_to_file( package
, source
, tmpfile
);
1060 if (r
!= ERROR_SUCCESS
)
1063 if (!(binary
= msi_alloc( sizeof(*binary
) ))) goto error
;
1064 binary
->source
= NULL
;
1065 binary
->tmpfile
= tmpfile
;
1066 list_add_tail( &package
->binaries
, &binary
->entry
);
1068 if (!(args
= build_msiexec_args( tmpfile
, target
))) return ERROR_OUTOFMEMORY
;
1070 TRACE("installing %s concurrently\n", debugstr_w(source
));
1072 handle
= execute_command( L
"msiexec", args
, L
"C:\\" );
1074 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1075 return wait_process_handle( package
, type
, handle
, action
);
1078 DeleteFileW( tmpfile
);
1079 msi_free( tmpfile
);
1080 return ERROR_FUNCTION_FAILED
;
1083 static UINT
HANDLE_CustomType50( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1084 INT type
, const WCHAR
*action
)
1089 if (!(exe
= msi_dup_property( package
->db
, source
))) return ERROR_SUCCESS
;
1091 deformat_string( package
, target
, &arg
);
1092 TRACE("exe %s arg %s\n", debugstr_w(exe
), debugstr_w(arg
));
1094 handle
= execute_command( exe
, arg
, szCRoot
);
1097 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1098 return wait_process_handle( package
, type
, handle
, action
);
1101 static UINT
HANDLE_CustomType34( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1102 INT type
, const WCHAR
*action
)
1104 const WCHAR
*workingdir
= NULL
;
1110 workingdir
= msi_get_target_folder( package
, source
);
1111 if (!workingdir
) return ERROR_FUNCTION_FAILED
;
1113 deformat_string( package
, target
, &cmd
);
1114 if (!cmd
) return ERROR_FUNCTION_FAILED
;
1116 TRACE("cmd %s dir %s\n", debugstr_w(cmd
), debugstr_w(workingdir
));
1118 handle
= execute_command( NULL
, cmd
, workingdir
);
1120 if (handle
== INVALID_HANDLE_VALUE
) return ERROR_SUCCESS
;
1121 return wait_process_handle( package
, type
, handle
, action
);
1124 static DWORD
ACTION_CallScript( const GUID
*guid
)
1126 msi_custom_action_info
*info
;
1128 UINT r
= ERROR_FUNCTION_FAILED
;
1130 info
= find_action_by_guid( guid
);
1133 ERR("failed to find action %s\n", debugstr_guid( guid
) );
1134 return ERROR_FUNCTION_FAILED
;
1137 TRACE("function %s, script %s\n", debugstr_w( info
->target
), debugstr_w( info
->source
) );
1139 hPackage
= alloc_msihandle( &info
->package
->hdr
);
1142 r
= call_script( hPackage
, info
->type
, info
->source
, info
->target
, info
->action
);
1143 TRACE("script returned %u\n", r
);
1144 MsiCloseHandle( hPackage
);
1147 ERR("failed to create handle for %p\n", info
->package
);
1152 static DWORD WINAPI
ScriptThread( LPVOID arg
)
1157 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1159 rc
= ACTION_CallScript( guid
);
1161 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc
);
1163 MsiCloseAllHandles();
1167 static msi_custom_action_info
*do_msidbCustomActionTypeScript(
1168 MSIPACKAGE
*package
, INT type
, LPCWSTR script
, LPCWSTR function
, LPCWSTR action
)
1170 msi_custom_action_info
*info
;
1172 info
= msi_alloc( sizeof *info
);
1176 msiobj_addref( &package
->hdr
);
1177 info
->package
= package
;
1179 info
->target
= strdupW( function
);
1180 info
->source
= strdupW( script
);
1181 info
->action
= strdupW( action
);
1182 CoCreateGuid( &info
->guid
);
1184 EnterCriticalSection( &msi_custom_action_cs
);
1185 list_add_tail( &msi_pending_custom_actions
, &info
->entry
);
1186 LeaveCriticalSection( &msi_custom_action_cs
);
1188 info
->handle
= CreateThread( NULL
, 0, ScriptThread
, &info
->guid
, 0, NULL
);
1191 free_custom_action_data( info
);
1198 static UINT
HANDLE_CustomType37_38( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1199 INT type
, const WCHAR
*action
)
1201 msi_custom_action_info
*info
;
1203 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1205 info
= do_msidbCustomActionTypeScript( package
, type
, target
, NULL
, action
);
1206 return wait_thread_handle( info
);
1209 static UINT
HANDLE_CustomType5_6( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1210 INT type
, const WCHAR
*action
)
1212 static const WCHAR query
[] = {
1213 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1214 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1215 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1216 MSIRECORD
*row
= NULL
;
1217 msi_custom_action_info
*info
;
1218 CHAR
*buffer
= NULL
;
1219 WCHAR
*bufferw
= NULL
;
1223 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1225 row
= MSI_QueryGetRecord(package
->db
, query
, source
);
1227 return ERROR_FUNCTION_FAILED
;
1229 r
= MSI_RecordReadStream(row
, 2, NULL
, &sz
);
1230 if (r
!= ERROR_SUCCESS
) goto done
;
1232 buffer
= msi_alloc( sz
+ 1 );
1235 r
= ERROR_FUNCTION_FAILED
;
1239 r
= MSI_RecordReadStream(row
, 2, buffer
, &sz
);
1240 if (r
!= ERROR_SUCCESS
)
1244 bufferw
= strdupAtoW(buffer
);
1247 r
= ERROR_FUNCTION_FAILED
;
1251 info
= do_msidbCustomActionTypeScript( package
, type
, bufferw
, target
, action
);
1252 r
= wait_thread_handle( info
);
1257 msiobj_release(&row
->hdr
);
1261 static UINT
HANDLE_CustomType21_22( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1262 INT type
, const WCHAR
*action
)
1264 msi_custom_action_info
*info
;
1267 DWORD sz
, szHighWord
= 0, read
;
1269 WCHAR
*bufferw
=NULL
;
1273 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1275 file
= msi_get_loaded_file(package
, source
);
1278 ERR("invalid file key %s\n", debugstr_w(source
));
1279 return ERROR_FUNCTION_FAILED
;
1282 hFile
= msi_create_file( package
, file
->TargetPath
, GENERIC_READ
, FILE_SHARE_READ
, OPEN_EXISTING
, 0 );
1283 if (hFile
== INVALID_HANDLE_VALUE
) return ERROR_FUNCTION_FAILED
;
1285 sz
= GetFileSize(hFile
, &szHighWord
);
1286 if (sz
== INVALID_FILE_SIZE
|| szHighWord
!= 0)
1289 return ERROR_FUNCTION_FAILED
;
1291 buffer
= msi_alloc( sz
+ 1 );
1295 return ERROR_FUNCTION_FAILED
;
1297 bRet
= ReadFile(hFile
, buffer
, sz
, &read
, NULL
);
1301 r
= ERROR_FUNCTION_FAILED
;
1305 bufferw
= strdupAtoW(buffer
);
1308 r
= ERROR_FUNCTION_FAILED
;
1311 info
= do_msidbCustomActionTypeScript( package
, type
, bufferw
, target
, action
);
1312 r
= wait_thread_handle( info
);
1320 static UINT
HANDLE_CustomType53_54( MSIPACKAGE
*package
, const WCHAR
*source
, const WCHAR
*target
,
1321 INT type
, const WCHAR
*action
)
1323 msi_custom_action_info
*info
;
1326 TRACE("%s %s\n", debugstr_w(source
), debugstr_w(target
));
1328 prop
= msi_dup_property( package
->db
, source
);
1329 if (!prop
) return ERROR_SUCCESS
;
1331 info
= do_msidbCustomActionTypeScript( package
, type
, prop
, NULL
, action
);
1333 return wait_thread_handle( info
);
1336 static BOOL
action_type_matches_script( UINT type
, UINT script
)
1342 case SCRIPT_INSTALL
:
1343 return !(type
& msidbCustomActionTypeCommit
) && !(type
& msidbCustomActionTypeRollback
);
1345 return (type
& msidbCustomActionTypeCommit
);
1346 case SCRIPT_ROLLBACK
:
1347 return (type
& msidbCustomActionTypeRollback
);
1349 ERR("unhandled script %u\n", script
);
1354 static UINT
defer_custom_action( MSIPACKAGE
*package
, const WCHAR
*action
, UINT type
)
1356 WCHAR
*actiondata
= msi_dup_property( package
->db
, action
);
1357 WCHAR
*usersid
= msi_dup_property( package
->db
, szUserSID
);
1358 WCHAR
*prodcode
= msi_dup_property( package
->db
, szProductCode
);
1359 WCHAR
*deferred
= msi_get_deferred_action( action
, actiondata
, usersid
, prodcode
);
1363 msi_free( actiondata
);
1364 msi_free( usersid
);
1365 msi_free( prodcode
);
1366 return ERROR_OUTOFMEMORY
;
1368 if (type
& msidbCustomActionTypeCommit
)
1370 TRACE("deferring commit action\n");
1371 msi_schedule_action( package
, SCRIPT_COMMIT
, deferred
);
1373 else if (type
& msidbCustomActionTypeRollback
)
1375 TRACE("deferring rollback action\n");
1376 msi_schedule_action( package
, SCRIPT_ROLLBACK
, deferred
);
1380 TRACE("deferring install action\n");
1381 msi_schedule_action( package
, SCRIPT_INSTALL
, deferred
);
1384 msi_free( actiondata
);
1385 msi_free( usersid
);
1386 msi_free( prodcode
);
1387 msi_free( deferred
);
1388 return ERROR_SUCCESS
;
1391 UINT
ACTION_CustomAction(MSIPACKAGE
*package
, const WCHAR
*action
)
1393 static const WCHAR query
[] = {
1394 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1395 '`','C','u','s','t','o','m','A','c','t','i','o','n','`',' ','W','H','E','R','E',' ',
1396 '`','A','c','t','i' ,'o','n','`',' ','=',' ','\'','%','s','\'',0};
1397 UINT rc
= ERROR_SUCCESS
;
1400 const WCHAR
*source
, *target
, *ptr
, *deferred_data
= NULL
;
1401 WCHAR
*deformated
= NULL
;
1404 /* deferred action: [properties]Action */
1405 if ((ptr
= wcsrchr(action
, ']')))
1407 deferred_data
= action
;
1411 row
= MSI_QueryGetRecord( package
->db
, query
, action
);
1413 return ERROR_FUNCTION_NOT_CALLED
;
1415 type
= MSI_RecordGetInteger(row
,2);
1416 source
= MSI_RecordGetString(row
,3);
1417 target
= MSI_RecordGetString(row
,4);
1419 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action
),type
,
1420 debugstr_w(source
), debugstr_w(target
));
1422 /* handle some of the deferred actions */
1423 if (type
& msidbCustomActionTypeTSAware
)
1424 FIXME("msidbCustomActionTypeTSAware not handled\n");
1426 if (type
& msidbCustomActionTypeInScript
)
1428 if (type
& msidbCustomActionTypeNoImpersonate
)
1429 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1431 if (!action_type_matches_script(type
, package
->script
))
1433 rc
= defer_custom_action( package
, action
, type
);
1438 LPWSTR actiondata
= msi_dup_property( package
->db
, action
);
1440 if (type
& msidbCustomActionTypeInScript
)
1441 package
->scheduled_action_running
= TRUE
;
1443 if (type
& msidbCustomActionTypeCommit
)
1444 package
->commit_action_running
= TRUE
;
1446 if (type
& msidbCustomActionTypeRollback
)
1447 package
->rollback_action_running
= TRUE
;
1450 set_deferred_action_props(package
, deferred_data
);
1451 else if (actiondata
)
1452 msi_set_property( package
->db
, szCustomActionData
, actiondata
, -1 );
1454 msi_set_property( package
->db
, szCustomActionData
, szEmpty
, -1 );
1456 msi_free(actiondata
);
1459 else if (!check_execution_scheduling_options(package
,action
,type
))
1465 switch (type
& CUSTOM_ACTION_TYPE_MASK
)
1467 case 1: /* DLL file stored in a Binary table stream */
1468 rc
= HANDLE_CustomType1( package
, source
, target
, type
, action
);
1470 case 2: /* EXE file stored in a Binary table stream */
1471 rc
= HANDLE_CustomType2( package
, source
, target
, type
, action
);
1474 case 6: /* JScript/VBScript file stored in a Binary table stream */
1475 rc
= HANDLE_CustomType5_6( package
, source
, target
, type
, action
);
1477 case 7: /* Concurrent install from substorage */
1478 deformat_string( package
, target
, &deformated
);
1479 rc
= HANDLE_CustomType7( package
, source
, target
, type
, action
);
1480 msi_free( deformated
);
1483 rc
= HANDLE_CustomType17( package
, source
, target
, type
, action
);
1485 case 18: /* EXE file installed with package */
1486 rc
= HANDLE_CustomType18( package
, source
, target
, type
, action
);
1488 case 19: /* Error that halts install */
1489 rc
= HANDLE_CustomType19( package
, source
, target
, type
, action
);
1491 case 21: /* JScript/VBScript file installed with the product */
1493 rc
= HANDLE_CustomType21_22( package
, source
, target
, type
, action
);
1495 case 23: /* Installs another package in the source tree */
1496 deformat_string( package
, target
, &deformated
);
1497 rc
= HANDLE_CustomType23( package
, source
, deformated
, type
, action
);
1498 msi_free( deformated
);
1500 case 34: /* EXE to be run in specified directory */
1501 rc
= HANDLE_CustomType34( package
, source
, target
, type
, action
);
1503 case 35: /* Directory set with formatted text */
1504 deformat_string( package
, target
, &deformated
);
1505 MSI_SetTargetPathW( package
, source
, deformated
);
1506 msi_free( deformated
);
1508 case 37: /* JScript/VBScript text stored in target column */
1510 rc
= HANDLE_CustomType37_38( package
, source
, target
, type
, action
);
1512 case 50: /* EXE file specified by a property value */
1513 rc
= HANDLE_CustomType50( package
, source
, target
, type
, action
);
1515 case 51: /* Property set with formatted text */
1517 len
= deformat_string( package
, target
, &deformated
);
1518 rc
= msi_set_property( package
->db
, source
, deformated
, len
);
1519 if (rc
== ERROR_SUCCESS
&& !wcscmp( source
, szSourceDir
)) msi_reset_source_folders( package
);
1520 msi_free( deformated
);
1522 case 53: /* JScript/VBScript text specified by a property value */
1524 rc
= HANDLE_CustomType53_54( package
, source
, target
, type
, action
);
1527 FIXME( "unhandled action type %u (%s %s)\n", type
& CUSTOM_ACTION_TYPE_MASK
, debugstr_w(source
),
1528 debugstr_w(target
) );
1532 package
->scheduled_action_running
= FALSE
;
1533 package
->commit_action_running
= FALSE
;
1534 package
->rollback_action_running
= FALSE
;
1535 msiobj_release(&row
->hdr
);
1539 void ACTION_FinishCustomActions(const MSIPACKAGE
* package
)
1542 HANDLE
*wait_handles
;
1543 unsigned int handle_count
, i
;
1544 msi_custom_action_info
*info
, *cursor
;
1546 while ((item
= list_head( &package
->RunningActions
)))
1548 MSIRUNNINGACTION
*action
= LIST_ENTRY( item
, MSIRUNNINGACTION
, entry
);
1550 list_remove( &action
->entry
);
1552 TRACE("waiting for %s\n", debugstr_w( action
->name
) );
1553 msi_dialog_check_messages( action
->handle
);
1555 CloseHandle( action
->handle
);
1556 msi_free( action
->name
);
1560 EnterCriticalSection( &msi_custom_action_cs
);
1562 handle_count
= list_count( &msi_pending_custom_actions
);
1563 wait_handles
= msi_alloc( handle_count
* sizeof(HANDLE
) );
1566 LIST_FOR_EACH_ENTRY_SAFE( info
, cursor
, &msi_pending_custom_actions
, msi_custom_action_info
, entry
)
1568 if (info
->package
== package
)
1570 if (DuplicateHandle(GetCurrentProcess(), info
->handle
, GetCurrentProcess(), &wait_handles
[handle_count
], SYNCHRONIZE
, FALSE
, 0))
1575 LeaveCriticalSection( &msi_custom_action_cs
);
1577 for (i
= 0; i
< handle_count
; i
++)
1579 msi_dialog_check_messages( wait_handles
[i
] );
1580 CloseHandle( wait_handles
[i
] );
1582 msi_free( wait_handles
);
1584 EnterCriticalSection( &msi_custom_action_cs
);
1585 LIST_FOR_EACH_ENTRY_SAFE( info
, cursor
, &msi_pending_custom_actions
, msi_custom_action_info
, entry
)
1587 if (info
->package
== package
)
1588 free_custom_action_data( info
);
1590 LeaveCriticalSection( &msi_custom_action_cs
);
1593 UINT __cdecl
s_remote_GetActionInfo(const GUID
*guid
, int *type
, LPWSTR
*dll
, LPSTR
*func
, MSIHANDLE
*hinst
)
1595 msi_custom_action_info
*info
;
1597 info
= find_action_by_guid(guid
);
1599 return ERROR_INVALID_DATA
;
1602 *hinst
= alloc_msihandle(&info
->package
->hdr
);
1603 *dll
= strdupW(info
->source
);
1604 *func
= strdupWtoA(info
->target
);
1606 return ERROR_SUCCESS
;