msi: Don't leak memory on error path.
[wine.git] / dlls / msi / custom.c
blob6fa1038be1bea95d033762e18e3e63c1ab16c45d
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 #include "config.h"
22 #include "wine/port.h"
24 #define COBJMACROS
26 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "msidefs.h"
31 #include "winuser.h"
32 #include "objbase.h"
33 #include "oleauto.h"
35 #include "msipriv.h"
36 #include "msiserver.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39 #include "wine/exception.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
43 #define CUSTOM_ACTION_TYPE_MASK 0x3F
44 static const WCHAR c_collen[] = {'C',':','\\',0};
45 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
47 typedef struct tagMSIRUNNINGACTION
49 struct list entry;
50 HANDLE handle;
51 BOOL process;
52 LPWSTR name;
53 } MSIRUNNINGACTION;
55 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
56 LPCWSTR target, const INT type, LPCWSTR action);
57 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
58 LPCWSTR target, const INT type, LPCWSTR action);
59 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
60 LPCWSTR target, const INT type, LPCWSTR action);
61 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
62 LPCWSTR target, const INT type, LPCWSTR action);
63 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
64 LPCWSTR target, const INT type, LPCWSTR action);
65 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
66 LPCWSTR target, const INT type, LPCWSTR action);
67 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
68 LPCWSTR target, const INT type, LPCWSTR action);
69 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
70 LPCWSTR target, const INT type, LPCWSTR action);
71 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
72 LPCWSTR target, const INT type, LPCWSTR action);
73 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
74 LPCWSTR target, const INT type, LPCWSTR action);
75 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
76 LPCWSTR target, const INT type, LPCWSTR action);
77 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
78 LPCWSTR target, const INT type, LPCWSTR action);
80 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
82 static CRITICAL_SECTION msi_custom_action_cs;
83 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
85 0, 0, &msi_custom_action_cs,
86 { &msi_custom_action_cs_debug.ProcessLocksList,
87 &msi_custom_action_cs_debug.ProcessLocksList },
88 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
90 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
92 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
94 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
96 if (!package->script)
97 return TRUE;
99 if ((options & msidbCustomActionTypeClientRepeat) ==
100 msidbCustomActionTypeClientRepeat)
102 if (!(package->script->InWhatSequence & SEQUENCE_UI &&
103 package->script->InWhatSequence & SEQUENCE_EXEC))
105 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
106 return FALSE;
109 else if (options & msidbCustomActionTypeFirstSequence)
111 if (package->script->InWhatSequence & SEQUENCE_UI &&
112 package->script->InWhatSequence & SEQUENCE_EXEC )
114 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
115 return FALSE;
118 else if (options & msidbCustomActionTypeOncePerProcess)
120 if (check_unique_action(package,action))
122 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
123 return FALSE;
125 else
126 register_unique_action(package,action);
129 return TRUE;
132 /* stores the following properties before the action:
134 * [CustomActionData<=>UserSID<=>ProductCode]Action
136 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
137 LPCWSTR usersid, LPCWSTR prodcode)
139 LPWSTR deferred;
140 DWORD len;
142 static const WCHAR format[] = {
143 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
146 if (!actiondata)
147 return strdupW(action);
149 len = lstrlenW(action) + lstrlenW(actiondata) +
150 lstrlenW(usersid) + lstrlenW(prodcode) +
151 lstrlenW(format) - 7;
152 deferred = msi_alloc(len * sizeof(WCHAR));
154 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
155 return deferred;
158 static void set_deferred_action_props(MSIPACKAGE *package, LPWSTR deferred_data)
160 LPWSTR end, beg = deferred_data + 1;
162 static const WCHAR sep[] = {'<','=','>',0};
164 end = strstrW(beg, sep);
165 *end = '\0';
166 msi_set_property(package->db, szCustomActionData, beg);
167 beg = end + 3;
169 end = strstrW(beg, sep);
170 *end = '\0';
171 msi_set_property(package->db, szUserSID, beg);
172 beg = end + 3;
174 end = strchrW(beg, ']');
175 *end = '\0';
176 msi_set_property(package->db, szProductCode, beg);
179 UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL execute)
181 UINT rc = ERROR_SUCCESS;
182 MSIRECORD * row = 0;
183 static const WCHAR ExecSeqQuery[] =
184 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
185 '`','C','u','s','t','o' ,'m','A','c','t','i','o','n','`',
186 ' ','W','H','E','R','E',' ','`','A','c','t','i' ,'o','n','`',' ',
187 '=',' ','\'','%','s','\'',0};
188 UINT type;
189 LPCWSTR source, target;
190 LPWSTR ptr, deferred_data = NULL;
191 LPWSTR action_copy = strdupW(action);
192 WCHAR *deformated=NULL;
194 /* deferred action: [properties]Action */
195 if ((ptr = strrchrW(action_copy, ']')))
197 deferred_data = action_copy;
198 action = ptr + 1;
201 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, action );
202 if (!row)
204 msi_free(action_copy);
205 return ERROR_CALL_NOT_IMPLEMENTED;
208 type = MSI_RecordGetInteger(row,2);
210 source = MSI_RecordGetString(row,3);
211 target = MSI_RecordGetString(row,4);
213 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
214 debugstr_w(source), debugstr_w(target));
216 /* handle some of the deferred actions */
217 if (type & msidbCustomActionTypeTSAware)
218 FIXME("msidbCustomActionTypeTSAware not handled\n");
220 if (type & msidbCustomActionTypeInScript)
222 if (type & msidbCustomActionTypeNoImpersonate)
223 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
225 if (!execute)
227 LPWSTR actiondata = msi_dup_property(package->db, action);
228 LPWSTR usersid = msi_dup_property(package->db, szUserSID);
229 LPWSTR prodcode = msi_dup_property(package->db, szProductCode);
230 LPWSTR deferred = msi_get_deferred_action(action, actiondata, usersid, prodcode);
232 if (type & msidbCustomActionTypeCommit)
234 TRACE("Deferring commit action\n");
235 schedule_action(package, COMMIT_SCRIPT, deferred);
237 else if (type & msidbCustomActionTypeRollback)
239 FIXME("Deferring rollback only action... rollbacks not supported yet\n");
240 schedule_action(package, ROLLBACK_SCRIPT, deferred);
242 else
244 TRACE("Deferring action\n");
245 schedule_action(package, INSTALL_SCRIPT, deferred);
248 rc = ERROR_SUCCESS;
249 msi_free(actiondata);
250 msi_free(usersid);
251 msi_free(prodcode);
252 msi_free(deferred);
253 goto end;
255 else
257 LPWSTR actiondata = msi_dup_property( package->db, action );
259 if (type & msidbCustomActionTypeInScript)
260 package->scheduled_action_running = TRUE;
262 if (type & msidbCustomActionTypeCommit)
263 package->commit_action_running = TRUE;
265 if (type & msidbCustomActionTypeRollback)
266 package->rollback_action_running = TRUE;
268 if (deferred_data)
269 set_deferred_action_props(package, deferred_data);
270 else if (actiondata)
271 msi_set_property(package->db, szCustomActionData, actiondata);
272 else
273 msi_set_property(package->db, szCustomActionData, szEmpty);
275 msi_free(actiondata);
278 else if (!check_execution_scheduling_options(package,action,type))
280 rc = ERROR_SUCCESS;
281 goto end;
284 switch (type & CUSTOM_ACTION_TYPE_MASK)
286 case 1: /* DLL file stored in a Binary table stream */
287 rc = HANDLE_CustomType1(package,source,target,type,action);
288 break;
289 case 2: /* EXE file stored in a Binary table stream */
290 rc = HANDLE_CustomType2(package,source,target,type,action);
291 break;
292 case 18: /*EXE file installed with package */
293 rc = HANDLE_CustomType18(package,source,target,type,action);
294 break;
295 case 19: /* Error that halts install */
296 rc = HANDLE_CustomType19(package,source,target,type,action);
297 break;
298 case 17:
299 rc = HANDLE_CustomType17(package,source,target,type,action);
300 break;
301 case 23: /* installs another package in the source tree */
302 deformat_string(package,target,&deformated);
303 rc = HANDLE_CustomType23(package,source,deformated,type,action);
304 msi_free(deformated);
305 break;
306 case 50: /*EXE file specified by a property value */
307 rc = HANDLE_CustomType50(package,source,target,type,action);
308 break;
309 case 34: /*EXE to be run in specified directory */
310 rc = HANDLE_CustomType34(package,source,target,type,action);
311 break;
312 case 35: /* Directory set with formatted text. */
313 deformat_string(package,target,&deformated);
314 MSI_SetTargetPathW(package, source, deformated);
315 msi_free(deformated);
316 break;
317 case 51: /* Property set with formatted text. */
318 if (!source)
319 break;
321 deformat_string(package,target,&deformated);
322 rc = msi_set_property( package->db, source, deformated );
323 if (rc == ERROR_SUCCESS && !strcmpW( source, cszSourceDir ))
324 msi_reset_folders( package, TRUE );
325 msi_free(deformated);
326 break;
327 case 37: /* JScript/VBScript text stored in target column. */
328 case 38:
329 rc = HANDLE_CustomType37_38(package,source,target,type,action);
330 break;
331 case 5:
332 case 6: /* JScript/VBScript file stored in a Binary table stream. */
333 rc = HANDLE_CustomType5_6(package,source,target,type,action);
334 break;
335 case 21: /* JScript/VBScript file installed with the product. */
336 case 22:
337 rc = HANDLE_CustomType21_22(package,source,target,type,action);
338 break;
339 case 53: /* JScript/VBScript text specified by a property value. */
340 case 54:
341 rc = HANDLE_CustomType53_54(package,source,target,type,action);
342 break;
343 default:
344 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
345 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
346 debugstr_w(target));
349 end:
350 package->scheduled_action_running = FALSE;
351 package->commit_action_running = FALSE;
352 package->rollback_action_running = FALSE;
353 msi_free(action_copy);
354 msiobj_release(&row->hdr);
355 return rc;
358 static MSIBINARY *create_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
360 static const WCHAR query[] = {
361 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
362 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
363 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
364 MSIRECORD *row;
365 MSIBINARY *binary;
366 HANDLE file;
367 CHAR buffer[1024];
368 WCHAR fmt[MAX_PATH], tmpfile[MAX_PATH];
369 DWORD sz = MAX_PATH, write;
370 UINT r;
372 if (msi_get_property(package->db, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
373 GetTempPathW(MAX_PATH, fmt);
375 if (!GetTempFileNameW( fmt, szMsi, 0, tmpfile ))
377 TRACE("unable to create temp file %s (%u)\n", debugstr_w(tmpfile), GetLastError());
378 return NULL;
381 row = MSI_QueryGetRecord(package->db, query, source);
382 if (!row)
383 return NULL;
385 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) )))
387 msiobj_release( &row->hdr );
388 return NULL;
390 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
391 if (file == INVALID_HANDLE_VALUE)
393 msiobj_release( &row->hdr );
394 msi_free( binary );
395 return NULL;
399 sz = sizeof(buffer);
400 r = MSI_RecordReadStream( row, 2, buffer, &sz );
401 if (r != ERROR_SUCCESS)
403 ERR("Failed to get stream\n");
404 break;
406 WriteFile( file, buffer, sz, &write, NULL );
407 } while (sz == sizeof buffer);
409 CloseHandle( file );
410 msiobj_release( &row->hdr );
411 if (r != ERROR_SUCCESS)
413 DeleteFileW( tmpfile );
414 msi_free( binary );
415 return NULL;
418 /* keep a reference to prevent the dll from being unloaded */
419 if (dll && !(binary->module = LoadLibraryW( tmpfile )))
421 ERR("failed to load dll %s (%u)\n", debugstr_w( binary->tmpfile ), GetLastError() );
422 DeleteFileW( tmpfile );
423 msi_free( binary );
424 return NULL;
426 binary->source = strdupW( source );
427 binary->tmpfile = strdupW( tmpfile );
428 list_add_tail( &package->binaries, &binary->entry );
429 return binary;
432 static MSIBINARY *get_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
434 MSIBINARY *binary;
436 LIST_FOR_EACH_ENTRY( binary, &package->binaries, MSIBINARY, entry )
438 if (!strcmpW( binary->source, source ))
439 return binary;
442 return create_temp_binary( package, source, dll );
445 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
446 BOOL process, LPCWSTR name)
448 MSIRUNNINGACTION *action;
450 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
452 action->handle = Handle;
453 action->process = process;
454 action->name = strdupW(name);
456 list_add_tail( &package->RunningActions, &action->entry );
459 static UINT custom_get_process_return( HANDLE process )
461 DWORD rc = 0;
463 GetExitCodeProcess( process, &rc );
464 if (rc != 0)
465 return ERROR_FUNCTION_FAILED;
466 return ERROR_SUCCESS;
469 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
471 DWORD rc = 0;
473 GetExitCodeThread( thread, &rc );
475 switch (rc)
477 case ERROR_FUNCTION_NOT_CALLED:
478 case ERROR_SUCCESS:
479 case ERROR_INSTALL_USEREXIT:
480 case ERROR_INSTALL_FAILURE:
481 return rc;
482 case ERROR_NO_MORE_ITEMS:
483 return ERROR_SUCCESS;
484 case ERROR_INSTALL_SUSPEND:
485 ACTION_ForceReboot( package );
486 return ERROR_SUCCESS;
487 default:
488 ERR("Invalid Return Code %d\n",rc);
489 return ERROR_INSTALL_FAILURE;
493 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
494 HANDLE ProcessHandle, LPCWSTR name)
496 UINT rc = ERROR_SUCCESS;
498 if (!(type & msidbCustomActionTypeAsync))
500 TRACE("waiting for %s\n", debugstr_w(name));
502 msi_dialog_check_messages(ProcessHandle);
504 if (!(type & msidbCustomActionTypeContinue))
505 rc = custom_get_process_return(ProcessHandle);
507 CloseHandle(ProcessHandle);
509 else
511 TRACE("%s running in background\n", debugstr_w(name));
513 if (!(type & msidbCustomActionTypeContinue))
514 file_running_action(package, ProcessHandle, TRUE, name);
515 else
516 CloseHandle(ProcessHandle);
519 return rc;
522 typedef struct _msi_custom_action_info {
523 struct list entry;
524 LONG refs;
525 MSIPACKAGE *package;
526 LPWSTR source;
527 LPWSTR target;
528 HANDLE handle;
529 LPWSTR action;
530 INT type;
531 GUID guid;
532 } msi_custom_action_info;
534 static void release_custom_action_data( msi_custom_action_info *info )
536 EnterCriticalSection( &msi_custom_action_cs );
538 if (!--info->refs)
540 list_remove( &info->entry );
541 if (info->handle)
542 CloseHandle( info->handle );
543 msi_free( info->action );
544 msi_free( info->source );
545 msi_free( info->target );
546 msiobj_release( &info->package->hdr );
547 msi_free( info );
550 LeaveCriticalSection( &msi_custom_action_cs );
553 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
554 static void addref_custom_action_data( msi_custom_action_info *info )
556 info->refs++;
559 static UINT wait_thread_handle( msi_custom_action_info *info )
561 UINT rc = ERROR_SUCCESS;
563 if (!(info->type & msidbCustomActionTypeAsync))
565 TRACE("waiting for %s\n", debugstr_w( info->action ));
567 msi_dialog_check_messages( info->handle );
569 if (!(info->type & msidbCustomActionTypeContinue))
570 rc = custom_get_thread_return( info->package, info->handle );
572 release_custom_action_data( info );
574 else
576 TRACE("%s running in background\n", debugstr_w( info->action ));
579 return rc;
582 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
584 msi_custom_action_info *info;
585 BOOL found = FALSE;
587 EnterCriticalSection( &msi_custom_action_cs );
589 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
591 if (IsEqualGUID( &info->guid, guid ))
593 addref_custom_action_data( info );
594 found = TRUE;
595 break;
599 LeaveCriticalSection( &msi_custom_action_cs );
601 if (!found)
602 return NULL;
604 return info;
607 static void handle_msi_break( LPCWSTR target )
609 LPWSTR msg;
610 WCHAR val[MAX_PATH];
612 static const WCHAR MsiBreak[] = { 'M','s','i','B','r','e','a','k',0 };
613 static const WCHAR WindowsInstaller[] = {
614 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
617 static const WCHAR format[] = {
618 'T','o',' ','d','e','b','u','g',' ','y','o','u','r',' ',
619 'c','u','s','t','o','m',' ','a','c','t','i','o','n',',',' ',
620 'a','t','t','a','c','h',' ','y','o','u','r',' ','d','e','b','u','g','g','e','r',' ',
621 't','o',' ','p','r','o','c','e','s','s',' ','%','i',' ','(','0','x','%','X',')',' ',
622 'a','n','d',' ','p','r','e','s','s',' ','O','K',0
625 if( !GetEnvironmentVariableW( MsiBreak, val, MAX_PATH ))
626 return;
628 if( strcmpiW( val, target ))
629 return;
631 msg = msi_alloc( (lstrlenW(format) + 10) * sizeof(WCHAR) );
632 if (!msg)
633 return;
635 wsprintfW( msg, format, GetCurrentProcessId(), GetCurrentProcessId());
636 MessageBoxW( NULL, msg, WindowsInstaller, MB_OK);
637 msi_free(msg);
638 DebugBreak();
641 static UINT get_action_info( const GUID *guid, INT *type, MSIHANDLE *handle,
642 BSTR *dll, BSTR *funcname,
643 IWineMsiRemotePackage **package )
645 IClassFactory *cf = NULL;
646 IWineMsiRemoteCustomAction *rca = NULL;
647 HRESULT r;
649 r = DllGetClassObject( &CLSID_IWineMsiRemoteCustomAction,
650 &IID_IClassFactory, (LPVOID *)&cf );
651 if (FAILED(r))
653 ERR("failed to get IClassFactory interface\n");
654 return ERROR_FUNCTION_FAILED;
657 r = IClassFactory_CreateInstance( cf, NULL, &IID_IWineMsiRemoteCustomAction, (LPVOID *)&rca );
658 if (FAILED(r))
660 ERR("failed to get IWineMsiRemoteCustomAction interface\n");
661 return ERROR_FUNCTION_FAILED;
664 r = IWineMsiRemoteCustomAction_GetActionInfo( rca, guid, type, handle, dll, funcname, package );
665 IWineMsiRemoteCustomAction_Release( rca );
666 if (FAILED(r))
668 ERR("GetActionInfo failed\n");
669 return ERROR_FUNCTION_FAILED;
672 return ERROR_SUCCESS;
675 #ifdef __i386__
676 extern UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle );
677 __ASM_GLOBAL_FUNC( CUSTOMPROC_wrapper,
678 "pushl %ebp\n\t"
679 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
680 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
681 "movl %esp,%ebp\n\t"
682 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
683 "pushl 12(%ebp)\n\t"
684 "movl 8(%ebp),%eax\n\t"
685 "call *%eax\n\t"
686 "leave\n\t"
687 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
688 __ASM_CFI(".cfi_same_value %ebp\n\t")
689 "ret" )
690 #else
691 static inline UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle )
693 return proc(handle);
695 #endif
697 static DWORD ACTION_CallDllFunction( const GUID *guid )
699 MsiCustomActionEntryPoint fn;
700 MSIHANDLE hPackage, handle;
701 HANDLE hModule;
702 LPSTR proc;
703 UINT r = ERROR_FUNCTION_FAILED;
704 BSTR dll = NULL, function = NULL;
705 INT type;
706 IWineMsiRemotePackage *remote_package = NULL;
708 TRACE("%s\n", debugstr_guid( guid ));
710 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
711 if (r != ERROR_SUCCESS)
712 return r;
714 hModule = LoadLibraryW( dll );
715 if (!hModule)
717 ERR("failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
718 return r;
721 proc = strdupWtoA( function );
722 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
723 msi_free( proc );
724 if (fn)
726 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
727 if (hPackage)
729 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
730 TRACE("calling %s\n", debugstr_w( function ) );
731 handle_msi_break( function );
733 __TRY
735 r = CUSTOMPROC_wrapper( fn, hPackage );
737 __EXCEPT_PAGE_FAULT
739 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
740 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
741 r = ERROR_SUCCESS;
743 __ENDTRY;
745 MsiCloseHandle( hPackage );
747 else
748 ERR("failed to create handle for %p\n", remote_package );
750 else
751 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
753 FreeLibrary(hModule);
755 IWineMsiRemotePackage_Release( remote_package );
756 SysFreeString( dll );
757 SysFreeString( function );
758 MsiCloseHandle( handle );
760 return r;
763 static DWORD WINAPI DllThread( LPVOID arg )
765 LPGUID guid = arg;
766 DWORD rc = 0;
768 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
770 rc = ACTION_CallDllFunction( guid );
772 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
774 MsiCloseAllHandles();
775 return rc;
778 static DWORD ACTION_CAInstallPackage(const GUID *guid)
780 msi_custom_action_info *info;
781 UINT r = ERROR_FUNCTION_FAILED;
782 INSTALLUILEVEL old_level;
784 info = find_action_by_guid(guid);
785 if (!info)
787 ERR("failed to find action %s\n", debugstr_guid(guid));
788 return r;
791 old_level = MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);
792 r = MsiInstallProductW(info->source, info->target);
793 MsiSetInternalUI(old_level, NULL);
795 release_custom_action_data(info);
797 return r;
800 static DWORD WINAPI ConcurrentInstallThread(LPVOID arg)
802 LPGUID guid = arg;
803 DWORD rc;
805 TRACE("concurrent installation (%x) started\n", GetCurrentThreadId());
807 rc = ACTION_CAInstallPackage(guid);
809 TRACE("concurrent installation (%x) returned %i\n", GetCurrentThreadId(), rc);
811 MsiCloseAllHandles();
812 return rc;
815 static msi_custom_action_info *do_msidbCustomActionTypeDll(
816 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
818 msi_custom_action_info *info;
820 info = msi_alloc( sizeof *info );
821 if (!info)
822 return NULL;
824 msiobj_addref( &package->hdr );
825 info->refs = 2; /* 1 for our caller and 1 for thread we created */
826 info->package = package;
827 info->type = type;
828 info->target = strdupW( target );
829 info->source = strdupW( source );
830 info->action = strdupW( action );
831 CoCreateGuid( &info->guid );
833 EnterCriticalSection( &msi_custom_action_cs );
834 list_add_tail( &msi_pending_custom_actions, &info->entry );
835 LeaveCriticalSection( &msi_custom_action_cs );
837 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
838 if (!info->handle)
840 /* release both references */
841 release_custom_action_data( info );
842 release_custom_action_data( info );
843 return NULL;
846 return info;
849 static msi_custom_action_info *do_msidbCAConcurrentInstall(
850 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action)
852 msi_custom_action_info *info;
854 info = msi_alloc( sizeof *info );
855 if (!info)
856 return NULL;
858 msiobj_addref( &package->hdr );
859 info->refs = 2; /* 1 for our caller and 1 for thread we created */
860 info->package = package;
861 info->type = type;
862 info->target = strdupW( target );
863 info->source = strdupW( source );
864 info->action = strdupW( action );
865 CoCreateGuid( &info->guid );
867 EnterCriticalSection( &msi_custom_action_cs );
868 list_add_tail( &msi_pending_custom_actions, &info->entry );
869 LeaveCriticalSection( &msi_custom_action_cs );
871 info->handle = CreateThread( NULL, 0, ConcurrentInstallThread, &info->guid, 0, NULL );
872 if (!info->handle)
874 /* release both references */
875 release_custom_action_data( info );
876 release_custom_action_data( info );
877 return NULL;
880 return info;
883 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
884 LPCWSTR target, const INT type, LPCWSTR action)
886 msi_custom_action_info *info;
887 WCHAR package_path[MAX_PATH];
888 DWORD size;
889 UINT r;
891 size = MAX_PATH;
892 msi_get_property(package->db, cszSourceDir, package_path, &size);
893 lstrcatW(package_path, szBackSlash);
894 lstrcatW(package_path, source);
896 TRACE("Installing package %s concurrently\n", debugstr_w(package_path));
898 info = do_msidbCAConcurrentInstall(package, type, package_path, target, action);
900 r = wait_thread_handle(info);
901 release_custom_action_data( info );
902 return r;
905 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
906 LPCWSTR target, const INT type, LPCWSTR action)
908 msi_custom_action_info *info;
909 MSIBINARY *binary;
910 UINT r;
912 if (!(binary = get_temp_binary( package, source, TRUE )))
913 return ERROR_FUNCTION_FAILED;
915 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
917 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
919 r = wait_thread_handle( info );
920 release_custom_action_data( info );
921 return r;
924 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
925 LPCWSTR target, const INT type, LPCWSTR action)
927 STARTUPINFOW si;
928 PROCESS_INFORMATION info;
929 BOOL rc;
930 INT len;
931 WCHAR *deformated = NULL;
932 WCHAR *cmd;
933 static const WCHAR spc[] = {' ',0};
934 MSIBINARY *binary;
935 UINT r;
937 memset(&si,0,sizeof(STARTUPINFOW));
939 if (!(binary = get_temp_binary( package, source, FALSE )))
940 return ERROR_FUNCTION_FAILED;
942 deformat_string(package,target,&deformated);
944 len = strlenW( binary->tmpfile ) + 2;
945 if (deformated)
946 len += strlenW(deformated);
948 cmd = msi_alloc(sizeof(WCHAR)*len);
950 strcpyW( cmd, binary->tmpfile );
951 if (deformated)
953 strcatW(cmd,spc);
954 strcatW(cmd,deformated);
955 msi_free(deformated);
958 TRACE("executing exe %s\n", debugstr_w(cmd));
960 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
961 c_collen, &si, &info);
962 msi_free(cmd);
964 if ( !rc )
966 ERR("Unable to execute command %s\n", debugstr_w(cmd));
967 return ERROR_SUCCESS;
969 CloseHandle( info.hThread );
971 r = wait_process_handle(package, type, info.hProcess, action);
973 return r;
976 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
977 LPCWSTR target, const INT type, LPCWSTR action)
979 msi_custom_action_info *info;
980 MSIFILE *file;
981 UINT r;
983 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
985 file = get_loaded_file( package, source );
986 if (!file)
988 ERR("invalid file key %s\n", debugstr_w( source ));
989 return ERROR_FUNCTION_FAILED;
992 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
994 r = wait_thread_handle( info );
995 release_custom_action_data( info );
996 return r;
999 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
1000 LPCWSTR target, const INT type, LPCWSTR action)
1002 STARTUPINFOW si;
1003 PROCESS_INFORMATION info;
1004 BOOL rc;
1005 WCHAR *deformated;
1006 WCHAR *cmd;
1007 INT len;
1008 static const WCHAR spc[] = {' ',0};
1009 MSIFILE *file;
1011 memset(&si,0,sizeof(STARTUPINFOW));
1013 file = get_loaded_file(package,source);
1014 if( !file )
1015 return ERROR_FUNCTION_FAILED;
1017 len = lstrlenW( file->TargetPath );
1019 deformat_string(package,target,&deformated);
1020 if (deformated)
1021 len += strlenW(deformated);
1022 len += 2;
1024 cmd = msi_alloc(len * sizeof(WCHAR));
1026 lstrcpyW( cmd, file->TargetPath);
1027 if (deformated)
1029 strcatW(cmd, spc);
1030 strcatW(cmd, deformated);
1032 msi_free(deformated);
1035 TRACE("executing exe %s\n", debugstr_w(cmd));
1037 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1038 c_collen, &si, &info);
1040 if ( !rc )
1042 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1043 msi_free(cmd);
1044 return ERROR_SUCCESS;
1046 msi_free(cmd);
1047 CloseHandle( info.hThread );
1049 return wait_process_handle(package, type, info.hProcess, action);
1052 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
1053 LPCWSTR target, const INT type, LPCWSTR action)
1055 static const WCHAR query[] = {
1056 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1057 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
1058 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
1059 '%','s',0
1061 MSIRECORD *row = 0;
1062 LPWSTR deformated = NULL;
1064 deformat_string( package, target, &deformated );
1066 /* first try treat the error as a number */
1067 row = MSI_QueryGetRecord( package->db, query, deformated );
1068 if( row )
1070 LPCWSTR error = MSI_RecordGetString( row, 1 );
1071 if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
1072 MessageBoxW( NULL, error, NULL, MB_OK );
1073 msiobj_release( &row->hdr );
1075 else if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
1076 MessageBoxW( NULL, deformated, NULL, MB_OK );
1078 msi_free( deformated );
1080 return ERROR_INSTALL_FAILURE;
1083 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
1084 LPCWSTR target, const INT type, LPCWSTR action)
1086 STARTUPINFOW si;
1087 PROCESS_INFORMATION info;
1088 WCHAR *prop;
1089 BOOL rc;
1090 WCHAR *deformated;
1091 WCHAR *cmd;
1092 INT len;
1093 static const WCHAR spc[] = {' ',0};
1095 memset(&si,0,sizeof(STARTUPINFOW));
1096 memset(&info,0,sizeof(PROCESS_INFORMATION));
1098 prop = msi_dup_property( package->db, source );
1099 if (!prop)
1100 return ERROR_SUCCESS;
1102 deformat_string(package,target,&deformated);
1103 len = strlenW(prop) + 2;
1104 if (deformated)
1105 len += strlenW(deformated);
1107 cmd = msi_alloc(sizeof(WCHAR)*len);
1109 strcpyW(cmd,prop);
1110 if (deformated)
1112 strcatW(cmd,spc);
1113 strcatW(cmd,deformated);
1115 msi_free(deformated);
1117 msi_free(prop);
1119 TRACE("executing exe %s\n", debugstr_w(cmd));
1121 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1122 c_collen, &si, &info);
1124 if ( !rc )
1126 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1127 msi_free(cmd);
1128 return ERROR_SUCCESS;
1130 msi_free(cmd);
1132 CloseHandle( info.hThread );
1134 return wait_process_handle(package, type, info.hProcess, action);
1137 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
1138 LPCWSTR target, const INT type, LPCWSTR action)
1140 LPWSTR workingdir, filename;
1141 STARTUPINFOW si;
1142 PROCESS_INFORMATION info;
1143 BOOL rc;
1145 memset(&si, 0, sizeof(STARTUPINFOW));
1147 workingdir = resolve_folder(package, source, FALSE, FALSE, TRUE, NULL);
1149 if (!workingdir)
1150 return ERROR_FUNCTION_FAILED;
1152 deformat_string(package, target, &filename);
1154 if (!filename)
1156 msi_free(workingdir);
1157 return ERROR_FUNCTION_FAILED;
1160 TRACE("executing exe %s with working directory %s\n",
1161 debugstr_w(filename), debugstr_w(workingdir));
1163 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1164 workingdir, &si, &info);
1166 if ( !rc )
1168 ERR("Unable to execute command %s with working directory %s\n",
1169 debugstr_w(filename), debugstr_w(workingdir));
1170 msi_free(filename);
1171 msi_free(workingdir);
1172 return ERROR_SUCCESS;
1175 msi_free(filename);
1176 msi_free(workingdir);
1178 CloseHandle( info.hThread );
1180 return wait_process_handle(package, type, info.hProcess, action);
1183 static DWORD ACTION_CallScript( const GUID *guid )
1185 msi_custom_action_info *info;
1186 MSIHANDLE hPackage;
1187 UINT r = ERROR_FUNCTION_FAILED;
1189 info = find_action_by_guid( guid );
1190 if (!info)
1192 ERR("failed to find action %s\n", debugstr_guid( guid) );
1193 return r;
1196 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1198 hPackage = alloc_msihandle( &info->package->hdr );
1199 if (hPackage)
1201 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1202 MsiCloseHandle( hPackage );
1204 else
1205 ERR("failed to create handle for %p\n", info->package );
1207 release_custom_action_data( info );
1209 return S_OK;
1212 static DWORD WINAPI ScriptThread( LPVOID arg )
1214 LPGUID guid = arg;
1215 DWORD rc = 0;
1217 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1219 rc = ACTION_CallScript( guid );
1221 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1223 MsiCloseAllHandles();
1224 return rc;
1227 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1228 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1230 msi_custom_action_info *info;
1232 info = msi_alloc( sizeof *info );
1233 if (!info)
1234 return NULL;
1236 msiobj_addref( &package->hdr );
1237 info->refs = 2; /* 1 for our caller and 1 for thread we created */
1238 info->package = package;
1239 info->type = type;
1240 info->target = strdupW( function );
1241 info->source = strdupW( script );
1242 info->action = strdupW( action );
1243 CoCreateGuid( &info->guid );
1245 EnterCriticalSection( &msi_custom_action_cs );
1246 list_add_tail( &msi_pending_custom_actions, &info->entry );
1247 LeaveCriticalSection( &msi_custom_action_cs );
1249 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1250 if (!info->handle)
1252 /* release both references */
1253 release_custom_action_data( info );
1254 release_custom_action_data( info );
1255 return NULL;
1258 return info;
1261 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
1262 LPCWSTR target, const INT type, LPCWSTR action)
1264 UINT r;
1265 msi_custom_action_info *info;
1267 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1269 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1271 r = wait_thread_handle( info );
1272 release_custom_action_data( info );
1273 return r;
1276 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
1277 LPCWSTR target, const INT type, LPCWSTR action)
1279 static const WCHAR query[] = {
1280 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1281 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1282 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1283 MSIRECORD *row = 0;
1284 msi_custom_action_info *info;
1285 CHAR *buffer = NULL;
1286 WCHAR *bufferw = NULL;
1287 DWORD sz = 0;
1288 UINT r;
1290 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1292 row = MSI_QueryGetRecord(package->db, query, source);
1293 if (!row)
1294 return ERROR_FUNCTION_FAILED;
1296 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1297 if (r != ERROR_SUCCESS)
1298 return r;
1300 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1301 if (!buffer)
1302 return ERROR_FUNCTION_FAILED;
1304 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1305 if (r != ERROR_SUCCESS)
1306 goto done;
1308 buffer[sz] = 0;
1309 bufferw = strdupAtoW(buffer);
1310 if (!bufferw)
1312 r = ERROR_FUNCTION_FAILED;
1313 goto done;
1316 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1317 r = wait_thread_handle( info );
1318 release_custom_action_data( info );
1320 done:
1321 msi_free(bufferw);
1322 msi_free(buffer);
1323 return r;
1326 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
1327 LPCWSTR target, const INT type, LPCWSTR action)
1329 msi_custom_action_info *info;
1330 MSIFILE *file;
1331 HANDLE hFile;
1332 DWORD sz, szHighWord = 0, read;
1333 CHAR *buffer=NULL;
1334 WCHAR *bufferw=NULL;
1335 BOOL bRet;
1336 UINT r;
1338 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1340 file = get_loaded_file(package,source);
1341 if (!file)
1343 ERR("invalid file key %s\n", debugstr_w(source));
1344 return ERROR_FUNCTION_FAILED;
1347 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1348 if (hFile == INVALID_HANDLE_VALUE)
1349 return ERROR_FUNCTION_FAILED;
1351 sz = GetFileSize(hFile, &szHighWord);
1352 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1354 CloseHandle(hFile);
1355 return ERROR_FUNCTION_FAILED;
1358 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1359 if (!buffer)
1361 CloseHandle(hFile);
1362 return ERROR_FUNCTION_FAILED;
1365 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1366 CloseHandle(hFile);
1367 if (!bRet)
1369 r = ERROR_FUNCTION_FAILED;
1370 goto done;
1373 buffer[read] = 0;
1374 bufferw = strdupAtoW(buffer);
1375 if (!bufferw)
1377 r = ERROR_FUNCTION_FAILED;
1378 goto done;
1381 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1382 r = wait_thread_handle( info );
1383 release_custom_action_data( info );
1385 done:
1386 msi_free(bufferw);
1387 msi_free(buffer);
1388 return r;
1391 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
1392 LPCWSTR target, const INT type, LPCWSTR action)
1394 msi_custom_action_info *info;
1395 WCHAR *prop;
1396 UINT r;
1398 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1400 prop = msi_dup_property( package->db, source );
1401 if (!prop)
1402 return ERROR_SUCCESS;
1404 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1405 msi_free(prop);
1406 r = wait_thread_handle( info );
1407 release_custom_action_data( info );
1408 return r;
1411 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1413 struct list *item;
1414 HANDLE *wait_handles;
1415 unsigned int handle_count, i;
1416 msi_custom_action_info *info, *cursor;
1418 while ((item = list_head( &package->RunningActions )))
1420 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1422 list_remove( &action->entry );
1424 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1425 msi_dialog_check_messages( action->handle );
1427 CloseHandle( action->handle );
1428 msi_free( action->name );
1429 msi_free( action );
1432 EnterCriticalSection( &msi_custom_action_cs );
1434 handle_count = list_count( &msi_pending_custom_actions );
1435 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1437 handle_count = 0;
1438 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1440 if (info->package == package )
1442 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1443 handle_count++;
1447 LeaveCriticalSection( &msi_custom_action_cs );
1449 for (i = 0; i < handle_count; i++)
1451 msi_dialog_check_messages( wait_handles[i] );
1452 CloseHandle( wait_handles[i] );
1455 msi_free( wait_handles );
1458 typedef struct _msi_custom_remote_impl {
1459 const IWineMsiRemoteCustomActionVtbl *lpVtbl;
1460 LONG refs;
1461 } msi_custom_remote_impl;
1463 static inline msi_custom_remote_impl* mcr_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction* iface )
1465 return (msi_custom_remote_impl*) iface;
1468 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1469 REFIID riid,LPVOID *ppobj)
1471 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1472 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1474 IUnknown_AddRef( iface );
1475 *ppobj = iface;
1476 return S_OK;
1479 return E_NOINTERFACE;
1482 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1484 msi_custom_remote_impl* This = mcr_from_IWineMsiRemoteCustomAction( iface );
1486 return InterlockedIncrement( &This->refs );
1489 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1491 msi_custom_remote_impl* This = mcr_from_IWineMsiRemoteCustomAction( iface );
1492 ULONG r;
1494 r = InterlockedDecrement( &This->refs );
1495 if (r == 0)
1496 msi_free( This );
1497 return r;
1500 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1501 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1503 msi_custom_action_info *info;
1505 info = find_action_by_guid( custom_action_guid );
1506 if (!info)
1507 return E_FAIL;
1509 *type = info->type;
1510 *handle = alloc_msihandle( &info->package->hdr );
1511 *dll = SysAllocString( info->source );
1512 *func = SysAllocString( info->target );
1514 release_custom_action_data( info );
1515 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1518 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1520 mcr_QueryInterface,
1521 mcr_AddRef,
1522 mcr_Release,
1523 mcr_GetActionInfo,
1526 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1528 msi_custom_remote_impl* This;
1530 This = msi_alloc( sizeof *This );
1531 if (!This)
1532 return E_OUTOFMEMORY;
1534 This->lpVtbl = &msi_custom_remote_vtbl;
1535 This->refs = 1;
1537 *ppObj = This;
1539 return S_OK;