Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / msi / custom.c
blob969ab90a6ad033a983340fd081ca8ff371211370
1 /*
2 * Custom Action processing for the Microsoft Installer (msi.dll)
4 * Copyright 2005 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
23 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winerror.h"
27 #include "msidefs.h"
28 #include "msipriv.h"
29 #include "winuser.h"
30 #include "wine/debug.h"
31 #include "wine/unicode.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(msi);
35 #define CUSTOM_ACTION_TYPE_MASK 0x3F
36 static const WCHAR c_collen[] = {'C',':','\\',0};
37 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
39 typedef struct tagMSIRUNNINGACTION
41 struct list entry;
42 HANDLE handle;
43 BOOL process;
44 LPWSTR name;
45 } MSIRUNNINGACTION;
47 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
48 LPCWSTR target, const INT type, LPCWSTR action);
49 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
50 LPCWSTR target, const INT type, LPCWSTR action);
51 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
52 LPCWSTR target, const INT type, LPCWSTR action);
53 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
54 LPCWSTR target, const INT type, LPCWSTR action);
55 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
56 LPCWSTR target, const INT type, LPCWSTR action);
57 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
58 LPCWSTR target, const INT type, LPCWSTR action);
59 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
60 LPCWSTR target, const INT type, LPCWSTR action);
62 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
64 static CRITICAL_SECTION msi_custom_action_cs;
65 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
67 0, 0, &msi_custom_action_cs,
68 { &msi_custom_action_cs_debug.ProcessLocksList,
69 &msi_custom_action_cs_debug.ProcessLocksList },
70 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
72 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
74 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
76 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
78 if (!package->script)
79 return TRUE;
81 if ((options & msidbCustomActionTypeClientRepeat) ==
82 msidbCustomActionTypeClientRepeat)
84 if (!(package->script->InWhatSequence & SEQUENCE_UI &&
85 package->script->InWhatSequence & SEQUENCE_EXEC))
87 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
88 return FALSE;
91 else if (options & msidbCustomActionTypeFirstSequence)
93 if (package->script->InWhatSequence & SEQUENCE_UI &&
94 package->script->InWhatSequence & SEQUENCE_EXEC )
96 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
97 return FALSE;
100 else if (options & msidbCustomActionTypeOncePerProcess)
102 if (check_unique_action(package,action))
104 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
105 return FALSE;
107 else
108 register_unique_action(package,action);
111 return TRUE;
114 /* stores the CustomActionData before the action:
115 * [CustomActionData]Action
117 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPWSTR actiondata)
119 LPWSTR deferred;
120 DWORD len;
122 static const WCHAR begin[] = {'[',0};
123 static const WCHAR end[] = {']',0};
125 if (!actiondata)
126 return strdupW(action);
128 len = lstrlenW(action) + lstrlenW(actiondata) + 3;
129 deferred = msi_alloc(len * sizeof(WCHAR));
131 lstrcpyW(deferred, begin);
132 lstrcatW(deferred, actiondata);
133 lstrcatW(deferred, end);
134 lstrcatW(deferred, action);
136 return deferred;
139 UINT ACTION_CustomAction(MSIPACKAGE *package,LPCWSTR action, BOOL execute)
141 UINT rc = ERROR_SUCCESS;
142 MSIRECORD * row = 0;
143 static const WCHAR ExecSeqQuery[] =
144 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
145 '`','C','u','s','t','o' ,'m','A','c','t','i','o','n','`',
146 ' ','W','H','E','R','E',' ','`','A','c','t','i' ,'o','n','`',' ',
147 '=',' ','\'','%','s','\'',0};
148 UINT type;
149 LPCWSTR source, target;
150 LPWSTR ptr, deferred_data = NULL;
151 LPWSTR action_copy = strdupW(action);
152 WCHAR *deformated=NULL;
154 /* deferred action: [CustomActionData]Action */
155 if ((ptr = strchrW(action_copy, ']')))
157 deferred_data = action_copy + 1;
158 *ptr = '\0';
159 action = ptr + 1;
162 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, action );
163 if (!row)
165 msi_free(action_copy);
166 return ERROR_CALL_NOT_IMPLEMENTED;
169 type = MSI_RecordGetInteger(row,2);
171 source = MSI_RecordGetString(row,3);
172 target = MSI_RecordGetString(row,4);
174 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
175 debugstr_w(source), debugstr_w(target));
177 /* handle some of the deferred actions */
178 if (type & msidbCustomActionTypeTSAware)
179 FIXME("msidbCustomActionTypeTSAware not handled\n");
181 if (type & msidbCustomActionTypeInScript)
183 TRACE("msidbCustomActionTypeInScript\n");
184 if (type & msidbCustomActionTypeNoImpersonate)
185 FIXME("msidbCustomActionTypeNoImpersonate not handled\n");
187 if (type & msidbCustomActionTypeRollback)
189 FIXME("Rollback only action... rollbacks not supported yet\n");
190 schedule_action(package, ROLLBACK_SCRIPT, action);
191 rc = ERROR_SUCCESS;
192 goto end;
194 if (!execute)
196 LPWSTR actiondata = msi_dup_property(package, action);
197 LPWSTR deferred = msi_get_deferred_action(action, actiondata);
199 if (type & msidbCustomActionTypeCommit)
201 TRACE("Deferring Commit Action!\n");
202 schedule_action(package, COMMIT_SCRIPT, deferred);
204 else
206 TRACE("Deferring Action!\n");
207 schedule_action(package, INSTALL_SCRIPT, deferred);
210 rc = ERROR_SUCCESS;
211 msi_free(deferred);
212 goto end;
214 else
216 /*Set ActionData*/
218 static const WCHAR szActionData[] = {
219 'C','u','s','t','o','m','A','c','t','i','o','n','D','a','t','a',0};
220 static const WCHAR szBlank[] = {0};
221 LPWSTR actiondata = msi_dup_property( package, action );
222 if (deferred_data)
223 MSI_SetPropertyW(package,szActionData,deferred_data);
224 else if (actiondata)
225 MSI_SetPropertyW(package,szActionData,actiondata);
226 else
227 MSI_SetPropertyW(package,szActionData,szBlank);
228 msi_free(actiondata);
231 else if (!check_execution_scheduling_options(package,action,type))
233 rc = ERROR_SUCCESS;
234 goto end;
237 switch (type & CUSTOM_ACTION_TYPE_MASK)
239 case 1: /* DLL file stored in a Binary table stream */
240 rc = HANDLE_CustomType1(package,source,target,type,action);
241 break;
242 case 2: /* EXE file stored in a Binary table stream */
243 rc = HANDLE_CustomType2(package,source,target,type,action);
244 break;
245 case 18: /*EXE file installed with package */
246 rc = HANDLE_CustomType18(package,source,target,type,action);
247 break;
248 case 19: /* Error that halts install */
249 rc = HANDLE_CustomType19(package,source,target,type,action);
250 break;
251 case 17:
252 rc = HANDLE_CustomType17(package,source,target,type,action);
253 break;
254 case 50: /*EXE file specified by a property value */
255 rc = HANDLE_CustomType50(package,source,target,type,action);
256 break;
257 case 34: /*EXE to be run in specified directory */
258 rc = HANDLE_CustomType34(package,source,target,type,action);
259 break;
260 case 35: /* Directory set with formatted text. */
261 deformat_string(package,target,&deformated);
262 MSI_SetTargetPathW(package, source, deformated);
263 msi_free(deformated);
264 break;
265 case 51: /* Property set with formatted text. */
266 deformat_string(package,target,&deformated);
267 rc = MSI_SetPropertyW(package,source,deformated);
268 msi_free(deformated);
269 break;
270 default:
271 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
272 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
273 debugstr_w(target));
276 end:
277 msi_free(action_copy);
278 msiobj_release(&row->hdr);
279 return rc;
283 static UINT store_binary_to_temp(MSIPACKAGE *package, LPCWSTR source,
284 LPWSTR tmp_file)
286 static const WCHAR query[] = {
287 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
288 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
289 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
290 MSIRECORD *row = 0;
291 HANDLE file;
292 CHAR buffer[1024];
293 static const WCHAR f1[] = {'m','s','i',0};
294 WCHAR fmt[MAX_PATH];
295 DWORD sz = MAX_PATH;
296 UINT r;
298 if (MSI_GetPropertyW(package, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
299 GetTempPathW(MAX_PATH, fmt);
301 if (GetTempFileNameW(fmt, f1, 0, tmp_file) == 0)
303 TRACE("Unable to create file\n");
304 return ERROR_FUNCTION_FAILED;
306 track_tempfile(package, tmp_file);
308 row = MSI_QueryGetRecord(package->db, query, source);
309 if (!row)
310 return ERROR_FUNCTION_FAILED;
312 /* write out the file */
313 file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
314 FILE_ATTRIBUTE_NORMAL, NULL);
315 if (file == INVALID_HANDLE_VALUE)
316 r = ERROR_FUNCTION_FAILED;
317 else
321 DWORD write;
322 sz = sizeof buffer;
323 r = MSI_RecordReadStream(row, 2, buffer, &sz);
324 if (r != ERROR_SUCCESS)
326 ERR("Failed to get stream\n");
327 break;
329 WriteFile(file, buffer, sz, &write, NULL);
330 } while (sz == sizeof buffer);
331 CloseHandle(file);
334 msiobj_release(&row->hdr);
336 return r;
339 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
340 BOOL process, LPCWSTR name)
342 MSIRUNNINGACTION *action;
344 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
346 action->handle = Handle;
347 action->process = process;
348 action->name = strdupW(name);
350 list_add_tail( &package->RunningActions, &action->entry );
353 static UINT custom_get_process_return( HANDLE process )
355 DWORD rc = 0;
357 GetExitCodeProcess( process, &rc );
358 if (rc != 0)
359 return ERROR_FUNCTION_FAILED;
360 return ERROR_SUCCESS;
363 static UINT custom_get_thread_return( HANDLE thread )
365 DWORD rc = 0;
367 GetExitCodeThread( thread, &rc );
369 switch (rc)
371 case ERROR_FUNCTION_NOT_CALLED:
372 case ERROR_SUCCESS:
373 case ERROR_INSTALL_USEREXIT:
374 case ERROR_INSTALL_FAILURE:
375 return rc;
376 case ERROR_NO_MORE_ITEMS:
377 return ERROR_SUCCESS;
378 default:
379 ERR("Invalid Return Code %d\n",rc);
380 return ERROR_INSTALL_FAILURE;
384 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
385 HANDLE ProcessHandle, LPCWSTR name)
387 UINT rc = ERROR_SUCCESS;
389 if (!(type & msidbCustomActionTypeAsync))
391 TRACE("waiting for %s\n", debugstr_w(name));
393 msi_dialog_check_messages(ProcessHandle);
395 if (!(type & msidbCustomActionTypeContinue))
396 rc = custom_get_process_return(ProcessHandle);
398 CloseHandle(ProcessHandle);
400 else
402 TRACE("%s running in background\n", debugstr_w(name));
404 if (!(type & msidbCustomActionTypeContinue))
405 file_running_action(package, ProcessHandle, TRUE, name);
406 else
407 CloseHandle(ProcessHandle);
410 return rc;
413 typedef struct _msi_custom_action_info {
414 struct list entry;
415 MSIPACKAGE *package;
416 LPWSTR dllname;
417 LPWSTR function;
418 HANDLE handle;
419 LPWSTR action;
420 INT type;
421 GUID guid;
422 } msi_custom_action_info;
424 static void free_custom_action_data( msi_custom_action_info *info )
426 EnterCriticalSection( &msi_custom_action_cs );
427 list_remove( &info->entry );
428 LeaveCriticalSection( &msi_custom_action_cs );
429 if (info->handle)
430 CloseHandle( info->handle );
431 msi_free( info->action );
432 msi_free( info->dllname );
433 msi_free( info->function );
434 msiobj_release( &info->package->hdr );
435 msi_free( info );
438 static UINT wait_thread_handle( msi_custom_action_info *info )
440 UINT rc = ERROR_SUCCESS;
442 if (!(info->type & msidbCustomActionTypeAsync))
444 TRACE("waiting for %s\n", debugstr_w( info->action ));
446 msi_dialog_check_messages( info->handle );
448 if (!(info->type & msidbCustomActionTypeContinue))
449 rc = custom_get_thread_return( info->handle );
451 free_custom_action_data( info );
453 else
455 TRACE("%s running in background\n", debugstr_w( info->action ));
458 return rc;
461 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
463 msi_custom_action_info *info;
464 BOOL found = FALSE;
466 EnterCriticalSection( &msi_custom_action_cs );
468 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
470 if (IsEqualGUID( &info->guid, guid ))
472 found = TRUE;
473 break;
477 LeaveCriticalSection( &msi_custom_action_cs );
479 if (!found)
480 return NULL;
482 return info;
485 static DWORD WINAPI ACTION_CallDllFunction( const GUID *guid )
487 msi_custom_action_info *info;
488 MsiCustomActionEntryPoint fn;
489 MSIHANDLE hPackage;
490 HANDLE hModule;
491 LPSTR proc;
492 UINT r = ERROR_FUNCTION_FAILED;
494 info = find_action_by_guid( guid );
495 if (!info)
497 ERR("failed to find action %s\n", debugstr_guid( guid) );
498 return r;
501 TRACE("%s %s\n", debugstr_w( info->dllname ), debugstr_w( info->function ) );
503 TlsSetValue( tls_slot, (void*) 1 );
505 hModule = LoadLibraryW( info->dllname );
506 if (!hModule)
508 ERR("failed to load dll %s\n", debugstr_w( info->dllname ) );
509 return r;
512 proc = strdupWtoA( info->function );
513 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
514 msi_free( proc );
515 if (fn)
517 hPackage = alloc_msihandle( &info->package->hdr );
518 if (hPackage)
520 TRACE("calling %s\n", debugstr_w( info->function ) );
521 r = fn( hPackage );
522 MsiCloseHandle( hPackage );
524 else
525 ERR("failed to create handle for %p\n", info->package );
527 else
528 ERR("GetProcAddress(%s) failed\n", debugstr_w( info->function ) );
530 FreeLibrary(hModule);
532 if (info->type & msidbCustomActionTypeAsync &&
533 info->type & msidbCustomActionTypeContinue)
534 free_custom_action_data( info );
536 return r;
539 static DWORD WINAPI DllThread( LPVOID arg )
541 LPGUID guid = arg;
542 DWORD rc = 0;
544 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
546 rc = ACTION_CallDllFunction( guid );
548 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
550 MsiCloseAllHandles();
551 return rc;
554 static msi_custom_action_info *do_msidbCustomActionTypeDll(
555 MSIPACKAGE *package, INT type, LPCWSTR dllname, LPCWSTR function, LPCWSTR action )
557 msi_custom_action_info *info;
559 info = msi_alloc( sizeof *info );
560 if (!info)
561 return NULL;
563 msiobj_addref( &package->hdr );
564 info->package = package;
565 info->type = type;
566 info->function = strdupW( function );
567 info->dllname = strdupW( dllname );
568 info->action = strdupW( action );
569 CoCreateGuid( &info->guid );
571 EnterCriticalSection( &msi_custom_action_cs );
572 list_add_tail( &msi_pending_custom_actions, &info->entry );
573 LeaveCriticalSection( &msi_custom_action_cs );
575 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
576 if (!info->handle)
578 free_custom_action_data( info );
579 return NULL;
582 return info;
585 extern int global_deferred;
586 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
587 LPCWSTR target, const INT type, LPCWSTR action)
589 msi_custom_action_info *info;
590 WCHAR tmp_file[MAX_PATH];
591 UINT r;
593 if (type & msidbCustomActionTypeInScript)
595 TRACE("setting global_deferred=1\n");
596 global_deferred=1;
599 r = store_binary_to_temp(package, source, tmp_file);
600 if (r != ERROR_SUCCESS)
601 return r;
603 TRACE("Calling function %s from %s\n",debugstr_w(target),
604 debugstr_w(tmp_file));
606 if (!strchrW(tmp_file,'.'))
608 static const WCHAR dot[]={'.',0};
609 strcatW(tmp_file,dot);
612 info = do_msidbCustomActionTypeDll( package, type, tmp_file, target, action );
614 r = wait_thread_handle( info );
615 if (type & msidbCustomActionTypeInScript)
617 TRACE("setting global_deferred=0\n");
618 global_deferred=0;
620 return r;
623 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
624 LPCWSTR target, const INT type, LPCWSTR action)
626 WCHAR tmp_file[MAX_PATH];
627 STARTUPINFOW si;
628 PROCESS_INFORMATION info;
629 BOOL rc;
630 INT len;
631 WCHAR *deformated = NULL;
632 WCHAR *cmd;
633 static const WCHAR spc[] = {' ',0};
634 UINT r;
636 memset(&si,0,sizeof(STARTUPINFOW));
638 r = store_binary_to_temp(package, source, tmp_file);
639 if (r != ERROR_SUCCESS)
640 return r;
642 deformat_string(package,target,&deformated);
644 len = strlenW(tmp_file)+2;
646 if (deformated)
647 len += strlenW(deformated);
649 cmd = msi_alloc(sizeof(WCHAR)*len);
651 strcpyW(cmd,tmp_file);
652 if (deformated)
654 strcatW(cmd,spc);
655 strcatW(cmd,deformated);
657 msi_free(deformated);
660 TRACE("executing exe %s\n", debugstr_w(cmd));
662 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
663 c_collen, &si, &info);
664 msi_free(cmd);
666 if ( !rc )
668 ERR("Unable to execute command %s\n", debugstr_w(cmd));
669 return ERROR_SUCCESS;
671 CloseHandle( info.hThread );
673 r = wait_process_handle(package, type, info.hProcess, action);
675 return r;
678 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
679 LPCWSTR target, const INT type, LPCWSTR action)
681 msi_custom_action_info *info;
682 MSIFILE *file;
684 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
686 file = get_loaded_file( package, source );
687 if (!file)
689 ERR("invalid file key %s\n", debugstr_w( source ));
690 return ERROR_FUNCTION_FAILED;
693 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
695 return wait_thread_handle( info );
698 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
699 LPCWSTR target, const INT type, LPCWSTR action)
701 STARTUPINFOW si;
702 PROCESS_INFORMATION info;
703 BOOL rc;
704 WCHAR *deformated;
705 WCHAR *cmd;
706 INT len;
707 static const WCHAR spc[] = {' ',0};
708 MSIFILE *file;
710 memset(&si,0,sizeof(STARTUPINFOW));
712 file = get_loaded_file(package,source);
713 if( !file )
714 return ERROR_FUNCTION_FAILED;
716 len = lstrlenW( file->TargetPath );
718 deformat_string(package,target,&deformated);
719 if (deformated)
720 len += strlenW(deformated);
721 len += 2;
723 cmd = msi_alloc(len * sizeof(WCHAR));
725 lstrcpyW( cmd, file->TargetPath);
726 if (deformated)
728 strcatW(cmd, spc);
729 strcatW(cmd, deformated);
731 msi_free(deformated);
734 TRACE("executing exe %s\n", debugstr_w(cmd));
736 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
737 c_collen, &si, &info);
739 if ( !rc )
741 ERR("Unable to execute command %s\n", debugstr_w(cmd));
742 msi_free(cmd);
743 return ERROR_SUCCESS;
745 msi_free(cmd);
746 CloseHandle( info.hThread );
748 return wait_process_handle(package, type, info.hProcess, action);
751 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
752 LPCWSTR target, const INT type, LPCWSTR action)
754 static const WCHAR query[] = {
755 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
756 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
757 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
758 '%','s',0
760 MSIRECORD *row = 0;
761 LPWSTR deformated = NULL;
763 deformat_string( package, target, &deformated );
765 /* first try treat the error as a number */
766 row = MSI_QueryGetRecord( package->db, query, deformated );
767 if( row )
769 LPCWSTR error = MSI_RecordGetString( row, 1 );
770 MessageBoxW( NULL, error, NULL, MB_OK );
771 msiobj_release( &row->hdr );
773 else
774 MessageBoxW( NULL, deformated, NULL, MB_OK );
776 msi_free( deformated );
778 return ERROR_FUNCTION_FAILED;
781 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
782 LPCWSTR target, const INT type, LPCWSTR action)
784 STARTUPINFOW si;
785 PROCESS_INFORMATION info;
786 WCHAR *prop;
787 BOOL rc;
788 WCHAR *deformated;
789 WCHAR *cmd;
790 INT len;
791 static const WCHAR spc[] = {' ',0};
793 memset(&si,0,sizeof(STARTUPINFOW));
794 memset(&info,0,sizeof(PROCESS_INFORMATION));
796 prop = msi_dup_property( package, source );
797 if (!prop)
798 return ERROR_SUCCESS;
800 deformat_string(package,target,&deformated);
801 len = strlenW(prop) + 2;
802 if (deformated)
803 len += strlenW(deformated);
805 cmd = msi_alloc(sizeof(WCHAR)*len);
807 strcpyW(cmd,prop);
808 if (deformated)
810 strcatW(cmd,spc);
811 strcatW(cmd,deformated);
813 msi_free(deformated);
815 msi_free(prop);
817 TRACE("executing exe %s\n", debugstr_w(cmd));
819 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
820 c_collen, &si, &info);
822 if ( !rc )
824 ERR("Unable to execute command %s\n", debugstr_w(cmd));
825 msi_free(cmd);
826 return ERROR_SUCCESS;
828 msi_free(cmd);
830 CloseHandle( info.hThread );
832 return wait_process_handle(package, type, info.hProcess, action);
835 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
836 LPCWSTR target, const INT type, LPCWSTR action)
838 LPWSTR filename, deformated;
839 STARTUPINFOW si;
840 PROCESS_INFORMATION info;
841 BOOL rc;
843 memset(&si,0,sizeof(STARTUPINFOW));
845 filename = resolve_folder(package, source, FALSE, FALSE, TRUE, NULL);
847 if (!filename)
848 return ERROR_FUNCTION_FAILED;
850 SetCurrentDirectoryW(filename);
851 msi_free(filename);
853 deformat_string(package,target,&deformated);
855 if (!deformated)
856 return ERROR_FUNCTION_FAILED;
858 TRACE("executing exe %s\n", debugstr_w(deformated));
860 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
861 c_collen, &si, &info);
863 if ( !rc )
865 ERR("Unable to execute command %s\n", debugstr_w(deformated));
866 msi_free(deformated);
867 return ERROR_SUCCESS;
869 msi_free(deformated);
870 CloseHandle( info.hThread );
872 return wait_process_handle(package, type, info.hProcess, action);
875 void ACTION_FinishCustomActions(MSIPACKAGE* package)
877 struct list *item;
878 HANDLE *wait_handles;
879 unsigned int handle_count, i;
880 msi_custom_action_info *info, *cursor;
882 while ((item = list_head( &package->RunningActions )))
884 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
886 list_remove( &action->entry );
888 TRACE("waiting for %s\n", debugstr_w( action->name ) );
889 msi_dialog_check_messages( action->handle );
891 CloseHandle( action->handle );
892 msi_free( action->name );
893 msi_free( action );
896 EnterCriticalSection( &msi_custom_action_cs );
898 handle_count = list_count( &msi_pending_custom_actions );
899 wait_handles = HeapAlloc( GetProcessHeap(), 0, handle_count * sizeof(HANDLE) );
901 handle_count = 0;
902 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
904 if (info->package == package )
906 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
907 handle_count++;
908 free_custom_action_data( info );
912 LeaveCriticalSection( &msi_custom_action_cs );
914 for (i = 0; i < handle_count; i++)
916 msi_dialog_check_messages( wait_handles[i] );
917 CloseHandle( wait_handles[i] );
920 HeapFree( GetProcessHeap(), 0, wait_handles );