msi: Free the custom action data after the thread function executes.
[wine/hacks.git] / dlls / msi / custom.c
blobc6c07cfbe5069ac4b7ef09873f901088c0441530
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 if (type & msidbCustomActionTypeNoImpersonate)
184 FIXME("msidbCustomActionTypeNoImpersonate not handled\n");
186 if (type & msidbCustomActionTypeRollback)
188 FIXME("Rollback only action... rollbacks not supported yet\n");
189 schedule_action(package, ROLLBACK_SCRIPT, action);
190 rc = ERROR_SUCCESS;
191 goto end;
193 if (!execute)
195 LPWSTR actiondata = msi_dup_property(package, action);
196 LPWSTR deferred = msi_get_deferred_action(action, actiondata);
198 if (type & msidbCustomActionTypeCommit)
200 TRACE("Deferring Commit Action!\n");
201 schedule_action(package, COMMIT_SCRIPT, deferred);
203 else
205 TRACE("Deferring Action!\n");
206 schedule_action(package, INSTALL_SCRIPT, deferred);
209 rc = ERROR_SUCCESS;
210 msi_free(deferred);
211 goto end;
213 else
215 /*Set ActionData*/
217 static const WCHAR szActionData[] = {
218 'C','u','s','t','o','m','A','c','t','i','o','n','D','a','t','a',0};
219 static const WCHAR szBlank[] = {0};
220 LPWSTR actiondata = msi_dup_property( package, action );
221 if (deferred_data)
222 MSI_SetPropertyW(package,szActionData,deferred_data);
223 else if (actiondata)
224 MSI_SetPropertyW(package,szActionData,actiondata);
225 else
226 MSI_SetPropertyW(package,szActionData,szBlank);
227 msi_free(actiondata);
230 else if (!check_execution_scheduling_options(package,action,type))
232 rc = ERROR_SUCCESS;
233 goto end;
236 switch (type & CUSTOM_ACTION_TYPE_MASK)
238 case 1: /* DLL file stored in a Binary table stream */
239 rc = HANDLE_CustomType1(package,source,target,type,action);
240 break;
241 case 2: /* EXE file stored in a Binary table stream */
242 rc = HANDLE_CustomType2(package,source,target,type,action);
243 break;
244 case 18: /*EXE file installed with package */
245 rc = HANDLE_CustomType18(package,source,target,type,action);
246 break;
247 case 19: /* Error that halts install */
248 rc = HANDLE_CustomType19(package,source,target,type,action);
249 break;
250 case 17:
251 rc = HANDLE_CustomType17(package,source,target,type,action);
252 break;
253 case 50: /*EXE file specified by a property value */
254 rc = HANDLE_CustomType50(package,source,target,type,action);
255 break;
256 case 34: /*EXE to be run in specified directory */
257 rc = HANDLE_CustomType34(package,source,target,type,action);
258 break;
259 case 35: /* Directory set with formatted text. */
260 deformat_string(package,target,&deformated);
261 MSI_SetTargetPathW(package, source, deformated);
262 msi_free(deformated);
263 break;
264 case 51: /* Property set with formatted text. */
265 deformat_string(package,target,&deformated);
266 rc = MSI_SetPropertyW(package,source,deformated);
267 msi_free(deformated);
268 break;
269 default:
270 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
271 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
272 debugstr_w(target));
275 end:
276 msi_free(action_copy);
277 msiobj_release(&row->hdr);
278 return rc;
282 static UINT store_binary_to_temp(MSIPACKAGE *package, LPCWSTR source,
283 LPWSTR tmp_file)
285 static const WCHAR query[] = {
286 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
287 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
288 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
289 MSIRECORD *row = 0;
290 HANDLE file;
291 CHAR buffer[1024];
292 static const WCHAR f1[] = {'m','s','i',0};
293 WCHAR fmt[MAX_PATH];
294 DWORD sz = MAX_PATH;
295 UINT r;
297 if (MSI_GetPropertyW(package, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
298 GetTempPathW(MAX_PATH, fmt);
300 if (GetTempFileNameW(fmt, f1, 0, tmp_file) == 0)
302 TRACE("Unable to create file\n");
303 return ERROR_FUNCTION_FAILED;
305 track_tempfile(package, tmp_file);
307 row = MSI_QueryGetRecord(package->db, query, source);
308 if (!row)
309 return ERROR_FUNCTION_FAILED;
311 /* write out the file */
312 file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
313 FILE_ATTRIBUTE_NORMAL, NULL);
314 if (file == INVALID_HANDLE_VALUE)
315 r = ERROR_FUNCTION_FAILED;
316 else
320 DWORD write;
321 sz = sizeof buffer;
322 r = MSI_RecordReadStream(row, 2, buffer, &sz);
323 if (r != ERROR_SUCCESS)
325 ERR("Failed to get stream\n");
326 break;
328 WriteFile(file, buffer, sz, &write, NULL);
329 } while (sz == sizeof buffer);
330 CloseHandle(file);
333 msiobj_release(&row->hdr);
335 return r;
338 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
339 BOOL process, LPCWSTR name)
341 MSIRUNNINGACTION *action;
343 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
345 action->handle = Handle;
346 action->process = process;
347 action->name = strdupW(name);
349 list_add_tail( &package->RunningActions, &action->entry );
352 static UINT custom_get_process_return( HANDLE process )
354 DWORD rc = 0;
356 GetExitCodeProcess( process, &rc );
357 if (rc != 0)
358 return ERROR_FUNCTION_FAILED;
359 return ERROR_SUCCESS;
362 static UINT custom_get_thread_return( HANDLE thread )
364 DWORD rc = 0;
366 GetExitCodeThread( thread, &rc );
368 switch (rc)
370 case ERROR_FUNCTION_NOT_CALLED:
371 case ERROR_SUCCESS:
372 case ERROR_INSTALL_USEREXIT:
373 case ERROR_INSTALL_FAILURE:
374 return rc;
375 case ERROR_NO_MORE_ITEMS:
376 return ERROR_SUCCESS;
377 default:
378 ERR("Invalid Return Code %d\n",rc);
379 return ERROR_INSTALL_FAILURE;
383 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
384 HANDLE ProcessHandle, LPCWSTR name)
386 UINT rc = ERROR_SUCCESS;
388 if (!(type & msidbCustomActionTypeAsync))
390 TRACE("waiting for %s\n", debugstr_w(name));
392 msi_dialog_check_messages(ProcessHandle);
394 if (!(type & msidbCustomActionTypeContinue))
395 rc = custom_get_process_return(ProcessHandle);
397 CloseHandle(ProcessHandle);
399 else
401 TRACE("%s running in background\n", debugstr_w(name));
403 if (!(type & msidbCustomActionTypeContinue))
404 file_running_action(package, ProcessHandle, TRUE, name);
405 else
406 CloseHandle(ProcessHandle);
409 return rc;
412 typedef struct _msi_custom_action_info {
413 struct list entry;
414 MSIPACKAGE *package;
415 LPWSTR dllname;
416 LPWSTR function;
417 HANDLE handle;
418 LPWSTR action;
419 INT type;
420 GUID guid;
421 } msi_custom_action_info;
423 static void free_custom_action_data( msi_custom_action_info *info )
425 EnterCriticalSection( &msi_custom_action_cs );
426 list_remove( &info->entry );
427 LeaveCriticalSection( &msi_custom_action_cs );
428 if (info->handle)
429 CloseHandle( info->handle );
430 msi_free( info->action );
431 msi_free( info->dllname );
432 msi_free( info->function );
433 msiobj_release( &info->package->hdr );
434 msi_free( info );
437 static UINT wait_thread_handle( msi_custom_action_info *info )
439 UINT rc = ERROR_SUCCESS;
441 if (!(info->type & msidbCustomActionTypeAsync))
443 TRACE("waiting for %s\n", debugstr_w( info->action ));
445 msi_dialog_check_messages( info->handle );
447 if (!(info->type & msidbCustomActionTypeContinue))
448 rc = custom_get_thread_return( info->handle );
450 free_custom_action_data( info );
452 else
454 TRACE("%s running in background\n", debugstr_w( info->action ));
457 return rc;
460 static msi_custom_action_info *find_action_by_guid( const LPGUID guid )
462 msi_custom_action_info *info;
463 BOOL found = FALSE;
465 EnterCriticalSection( &msi_custom_action_cs );
467 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
469 if (IsEqualGUID( &info->guid, guid ))
471 found = TRUE;
472 break;
476 LeaveCriticalSection( &msi_custom_action_cs );
478 if (!found)
479 return NULL;
481 return info;
484 static DWORD WINAPI ACTION_CallDllFunction( const LPGUID guid )
486 msi_custom_action_info *info;
487 MsiCustomActionEntryPoint fn;
488 MSIHANDLE hPackage;
489 HANDLE hModule;
490 LPSTR proc;
491 UINT r = ERROR_FUNCTION_FAILED;
493 info = find_action_by_guid( guid );
494 if (!info)
496 ERR("failed to find action %s\n", debugstr_guid( guid) );
497 return r;
500 TRACE("%s %s\n", debugstr_w( info->dllname ), debugstr_w( info->function ) );
502 hModule = LoadLibraryW( info->dllname );
503 if (!hModule)
505 ERR("failed to load dll %s\n", debugstr_w( info->dllname ) );
506 return r;
509 proc = strdupWtoA( info->function );
510 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
511 msi_free( proc );
512 if (fn)
514 hPackage = alloc_msihandle( &info->package->hdr );
515 if (hPackage)
517 TRACE("calling %s\n", debugstr_w( info->function ) );
518 r = fn( hPackage );
519 MsiCloseHandle( hPackage );
521 else
522 ERR("failed to create handle for %p\n", info->package );
524 else
525 ERR("GetProcAddress(%s) failed\n", debugstr_w( info->function ) );
527 FreeLibrary(hModule);
529 if (info->type & msidbCustomActionTypeAsync &&
530 info->type & msidbCustomActionTypeContinue)
531 free_custom_action_data( info );
533 return r;
536 static DWORD WINAPI DllThread( LPVOID arg )
538 LPGUID guid = arg;
539 DWORD rc = 0;
541 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
543 rc = ACTION_CallDllFunction( guid );
545 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
547 MsiCloseAllHandles();
548 return rc;
551 static msi_custom_action_info *do_msidbCustomActionTypeDll(
552 MSIPACKAGE *package, INT type, LPCWSTR dllname, LPCWSTR function, LPCWSTR action )
554 msi_custom_action_info *info;
556 info = msi_alloc( sizeof *info );
557 if (!info)
558 return NULL;
560 msiobj_addref( &package->hdr );
561 info->package = package;
562 info->type = type;
563 info->function = strdupW( function );
564 info->dllname = strdupW( dllname );
565 info->action = strdupW( action );
566 CoCreateGuid( &info->guid );
568 EnterCriticalSection( &msi_custom_action_cs );
569 list_add_tail( &msi_pending_custom_actions, &info->entry );
570 LeaveCriticalSection( &msi_custom_action_cs );
572 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
573 if (!info->handle)
575 free_custom_action_data( info );
576 return NULL;
579 return info;
582 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
583 LPCWSTR target, const INT type, LPCWSTR action)
585 msi_custom_action_info *info;
586 WCHAR tmp_file[MAX_PATH];
587 UINT r;
589 r = store_binary_to_temp(package, source, tmp_file);
590 if (r != ERROR_SUCCESS)
591 return r;
593 TRACE("Calling function %s from %s\n",debugstr_w(target),
594 debugstr_w(tmp_file));
596 if (!strchrW(tmp_file,'.'))
598 static const WCHAR dot[]={'.',0};
599 strcatW(tmp_file,dot);
602 info = do_msidbCustomActionTypeDll( package, type, tmp_file, target, action );
604 return wait_thread_handle( info );
607 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
608 LPCWSTR target, const INT type, LPCWSTR action)
610 WCHAR tmp_file[MAX_PATH];
611 STARTUPINFOW si;
612 PROCESS_INFORMATION info;
613 BOOL rc;
614 INT len;
615 WCHAR *deformated = NULL;
616 WCHAR *cmd;
617 static const WCHAR spc[] = {' ',0};
618 UINT r;
620 memset(&si,0,sizeof(STARTUPINFOW));
622 r = store_binary_to_temp(package, source, tmp_file);
623 if (r != ERROR_SUCCESS)
624 return r;
626 deformat_string(package,target,&deformated);
628 len = strlenW(tmp_file)+2;
630 if (deformated)
631 len += strlenW(deformated);
633 cmd = msi_alloc(sizeof(WCHAR)*len);
635 strcpyW(cmd,tmp_file);
636 if (deformated)
638 strcatW(cmd,spc);
639 strcatW(cmd,deformated);
641 msi_free(deformated);
644 TRACE("executing exe %s\n", debugstr_w(cmd));
646 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
647 c_collen, &si, &info);
648 msi_free(cmd);
650 if ( !rc )
652 ERR("Unable to execute command %s\n", debugstr_w(cmd));
653 return ERROR_SUCCESS;
655 CloseHandle( info.hThread );
657 r = wait_process_handle(package, type, info.hProcess, action);
659 return r;
662 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
663 LPCWSTR target, const INT type, LPCWSTR action)
665 msi_custom_action_info *info;
666 MSIFILE *file;
668 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
670 file = get_loaded_file( package, source );
671 if (!file)
673 ERR("invalid file key %s\n", debugstr_w( source ));
674 return ERROR_FUNCTION_FAILED;
677 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
679 return wait_thread_handle( info );
682 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
683 LPCWSTR target, const INT type, LPCWSTR action)
685 STARTUPINFOW si;
686 PROCESS_INFORMATION info;
687 BOOL rc;
688 WCHAR *deformated;
689 WCHAR *cmd;
690 INT len;
691 static const WCHAR spc[] = {' ',0};
692 MSIFILE *file;
694 memset(&si,0,sizeof(STARTUPINFOW));
696 file = get_loaded_file(package,source);
697 if( !file )
698 return ERROR_FUNCTION_FAILED;
700 len = lstrlenW( file->TargetPath );
702 deformat_string(package,target,&deformated);
703 if (deformated)
704 len += strlenW(deformated);
705 len += 2;
707 cmd = msi_alloc(len * sizeof(WCHAR));
709 lstrcpyW( cmd, file->TargetPath);
710 if (deformated)
712 strcatW(cmd, spc);
713 strcatW(cmd, deformated);
715 msi_free(deformated);
718 TRACE("executing exe %s\n", debugstr_w(cmd));
720 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
721 c_collen, &si, &info);
723 if ( !rc )
725 ERR("Unable to execute command %s\n", debugstr_w(cmd));
726 msi_free(cmd);
727 return ERROR_SUCCESS;
729 msi_free(cmd);
730 CloseHandle( info.hThread );
732 return wait_process_handle(package, type, info.hProcess, action);
735 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
736 LPCWSTR target, const INT type, LPCWSTR action)
738 static const WCHAR query[] = {
739 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
740 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
741 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
742 '%','s',0
744 MSIRECORD *row = 0;
745 LPWSTR deformated = NULL;
747 deformat_string( package, target, &deformated );
749 /* first try treat the error as a number */
750 row = MSI_QueryGetRecord( package->db, query, deformated );
751 if( row )
753 LPCWSTR error = MSI_RecordGetString( row, 1 );
754 MessageBoxW( NULL, error, NULL, MB_OK );
755 msiobj_release( &row->hdr );
757 else
758 MessageBoxW( NULL, deformated, NULL, MB_OK );
760 msi_free( deformated );
762 return ERROR_FUNCTION_FAILED;
765 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
766 LPCWSTR target, const INT type, LPCWSTR action)
768 STARTUPINFOW si;
769 PROCESS_INFORMATION info;
770 WCHAR *prop;
771 BOOL rc;
772 WCHAR *deformated;
773 WCHAR *cmd;
774 INT len;
775 static const WCHAR spc[] = {' ',0};
777 memset(&si,0,sizeof(STARTUPINFOW));
778 memset(&info,0,sizeof(PROCESS_INFORMATION));
780 prop = msi_dup_property( package, source );
781 if (!prop)
782 return ERROR_SUCCESS;
784 deformat_string(package,target,&deformated);
785 len = strlenW(prop) + 2;
786 if (deformated)
787 len += strlenW(deformated);
789 cmd = msi_alloc(sizeof(WCHAR)*len);
791 strcpyW(cmd,prop);
792 if (deformated)
794 strcatW(cmd,spc);
795 strcatW(cmd,deformated);
797 msi_free(deformated);
799 msi_free(prop);
801 TRACE("executing exe %s\n", debugstr_w(cmd));
803 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
804 c_collen, &si, &info);
806 if ( !rc )
808 ERR("Unable to execute command %s\n", debugstr_w(cmd));
809 msi_free(cmd);
810 return ERROR_SUCCESS;
812 msi_free(cmd);
814 CloseHandle( info.hThread );
816 return wait_process_handle(package, type, info.hProcess, action);
819 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
820 LPCWSTR target, const INT type, LPCWSTR action)
822 LPWSTR filename, deformated;
823 STARTUPINFOW si;
824 PROCESS_INFORMATION info;
825 BOOL rc;
827 memset(&si,0,sizeof(STARTUPINFOW));
829 filename = resolve_folder(package, source, FALSE, FALSE, NULL);
831 if (!filename)
832 return ERROR_FUNCTION_FAILED;
834 SetCurrentDirectoryW(filename);
835 msi_free(filename);
837 deformat_string(package,target,&deformated);
839 if (!deformated)
840 return ERROR_FUNCTION_FAILED;
842 TRACE("executing exe %s\n", debugstr_w(deformated));
844 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
845 c_collen, &si, &info);
847 if ( !rc )
849 ERR("Unable to execute command %s\n", debugstr_w(deformated));
850 msi_free(deformated);
851 return ERROR_SUCCESS;
853 msi_free(deformated);
854 CloseHandle( info.hThread );
856 return wait_process_handle(package, type, info.hProcess, action);
859 void ACTION_FinishCustomActions(MSIPACKAGE* package)
861 struct list *item;
863 while ((item = list_head( &package->RunningActions )))
865 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
867 list_remove( &action->entry );
869 TRACE("waiting for %s\n", debugstr_w( action->name ) );
870 msi_dialog_check_messages( action->handle );
872 CloseHandle( action->handle );
873 msi_free( action->name );
874 msi_free( action );
877 while (1)
879 HANDLE handle;
880 msi_custom_action_info *info;
882 EnterCriticalSection( &msi_custom_action_cs );
883 item = list_head( &msi_pending_custom_actions );
884 info = LIST_ENTRY( item, msi_custom_action_info, entry );
886 if (item && info->package == package )
888 handle = info->handle;
889 free_custom_action_data( info );
891 else
892 handle = NULL;
893 LeaveCriticalSection( &msi_custom_action_cs );
895 if (!item)
896 break;
898 msi_dialog_check_messages( handle );