msi: Only call a custom action remotely if the type is msidbCustomActionTypeInScript.
[wine/gsoc_dplay.git] / dlls / msi / custom.c
blob86d4ccbd5e403b5f095966c391a726760f95a37c
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 "winuser.h"
29 #include "objbase.h"
30 #include "oleauto.h"
32 #include "msipriv.h"
33 #include "msiserver.h"
34 #include "wine/debug.h"
35 #include "wine/unicode.h"
36 #include "wine/exception.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msi);
40 #define CUSTOM_ACTION_TYPE_MASK 0x3F
41 static const WCHAR c_collen[] = {'C',':','\\',0};
42 static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
45 static const WCHAR szActionData[] = {
46 'C','u','s','t','o','m','A','c','t','i','o','n','D','a','t','a',0
48 static const WCHAR ProdCode[] = {
49 'P','r','o','d','u','c','t','C','o','d','e',0
51 static const WCHAR UserSID[] = {'U','s','e','r','S','I','D',0};
53 typedef struct tagMSIRUNNINGACTION
55 struct list entry;
56 HANDLE handle;
57 BOOL process;
58 LPWSTR name;
59 } MSIRUNNINGACTION;
61 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
62 LPCWSTR target, const INT type, LPCWSTR action);
63 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
64 LPCWSTR target, const INT type, LPCWSTR action);
65 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
66 LPCWSTR target, const INT type, LPCWSTR action);
67 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
68 LPCWSTR target, const INT type, LPCWSTR action);
69 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
70 LPCWSTR target, const INT type, LPCWSTR action);
71 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
72 LPCWSTR target, const INT type, LPCWSTR action);
73 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
74 LPCWSTR target, const INT type, LPCWSTR action);
75 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
76 LPCWSTR target, const INT type, LPCWSTR action);
77 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
78 LPCWSTR target, const INT type, LPCWSTR action);
79 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
80 LPCWSTR target, const INT type, LPCWSTR action);
81 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
82 LPCWSTR target, const INT type, LPCWSTR action);
83 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
84 LPCWSTR target, const INT type, LPCWSTR action);
86 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
88 static CRITICAL_SECTION msi_custom_action_cs;
89 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
91 0, 0, &msi_custom_action_cs,
92 { &msi_custom_action_cs_debug.ProcessLocksList,
93 &msi_custom_action_cs_debug.ProcessLocksList },
94 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
96 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
98 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
100 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
102 if (!package->script)
103 return TRUE;
105 if ((options & msidbCustomActionTypeClientRepeat) ==
106 msidbCustomActionTypeClientRepeat)
108 if (!(package->script->InWhatSequence & SEQUENCE_UI &&
109 package->script->InWhatSequence & SEQUENCE_EXEC))
111 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
112 return FALSE;
115 else if (options & msidbCustomActionTypeFirstSequence)
117 if (package->script->InWhatSequence & SEQUENCE_UI &&
118 package->script->InWhatSequence & SEQUENCE_EXEC )
120 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
121 return FALSE;
124 else if (options & msidbCustomActionTypeOncePerProcess)
126 if (check_unique_action(package,action))
128 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
129 return FALSE;
131 else
132 register_unique_action(package,action);
135 return TRUE;
138 /* stores the following properties before the action:
140 * [CustomActionData;UserSID;ProductCode]Action
142 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
143 LPCWSTR usersid, LPCWSTR prodcode)
145 LPWSTR deferred;
146 DWORD len;
148 static const WCHAR format[] = {'[','%','s',';','%','s',';','%','s',']','%','s',0};
150 if (!actiondata)
151 return strdupW(action);
153 len = lstrlenW(action) + lstrlenW(actiondata) +
154 lstrlenW(usersid) + lstrlenW(prodcode) + 5;
155 deferred = msi_alloc(len * sizeof(WCHAR));
157 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
158 return deferred;
161 static void set_deferred_action_props(MSIPACKAGE *package, LPWSTR deferred_data)
163 LPWSTR end, beg = deferred_data + 1;
165 end = strchrW(beg, ';');
166 *end = '\0';
167 MSI_SetPropertyW(package, szActionData, beg);
168 beg = end + 1;
170 end = strchrW(beg, ';');
171 *end = '\0';
172 MSI_SetPropertyW(package, UserSID, beg);
173 beg = end + 1;
175 end = strchrW(beg, ']');
176 *end = '\0';
177 MSI_SetPropertyW(package, ProdCode, beg);
180 UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL execute)
182 UINT rc = ERROR_SUCCESS;
183 MSIRECORD * row = 0;
184 static const WCHAR ExecSeqQuery[] =
185 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
186 '`','C','u','s','t','o' ,'m','A','c','t','i','o','n','`',
187 ' ','W','H','E','R','E',' ','`','A','c','t','i' ,'o','n','`',' ',
188 '=',' ','\'','%','s','\'',0};
189 UINT type;
190 LPCWSTR source, target;
191 LPWSTR ptr, deferred_data = NULL;
192 LPWSTR action_copy = strdupW(action);
193 WCHAR *deformated=NULL;
195 /* deferred action: [properties]Action */
196 if ((ptr = strchrW(action_copy, ']')))
198 deferred_data = action_copy;
199 action = ptr + 1;
202 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, action );
203 if (!row)
205 msi_free(action_copy);
206 return ERROR_CALL_NOT_IMPLEMENTED;
209 type = MSI_RecordGetInteger(row,2);
211 source = MSI_RecordGetString(row,3);
212 target = MSI_RecordGetString(row,4);
214 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
215 debugstr_w(source), debugstr_w(target));
217 /* handle some of the deferred actions */
218 if (type & msidbCustomActionTypeTSAware)
219 FIXME("msidbCustomActionTypeTSAware not handled\n");
221 if (type & msidbCustomActionTypeInScript)
223 if (type & msidbCustomActionTypeNoImpersonate)
224 FIXME("msidbCustomActionTypeNoImpersonate not handled\n");
226 if (type & msidbCustomActionTypeRollback)
228 FIXME("Rollback only action... rollbacks not supported yet\n");
229 schedule_action(package, ROLLBACK_SCRIPT, action);
230 rc = ERROR_SUCCESS;
231 goto end;
233 if (!execute)
235 LPWSTR actiondata = msi_dup_property(package, action);
236 LPWSTR usersid = msi_dup_property(package, UserSID);
237 LPWSTR prodcode = msi_dup_property(package, ProdCode);
238 LPWSTR deferred = msi_get_deferred_action(action, actiondata, usersid, prodcode);
240 if (type & msidbCustomActionTypeCommit)
242 TRACE("Deferring Commit Action!\n");
243 schedule_action(package, COMMIT_SCRIPT, deferred);
245 else
247 TRACE("Deferring Action!\n");
248 schedule_action(package, INSTALL_SCRIPT, deferred);
251 rc = ERROR_SUCCESS;
252 msi_free(actiondata);
253 msi_free(usersid);
254 msi_free(prodcode);
255 msi_free(deferred);
256 goto end;
258 else
260 static const WCHAR szBlank[] = {0};
262 LPWSTR actiondata = msi_dup_property( package, action );
264 switch (script)
266 case INSTALL_SCRIPT:
267 package->scheduled_action_running = TRUE;
268 break;
269 case COMMIT_SCRIPT:
270 package->commit_action_running = TRUE;
271 break;
272 case ROLLBACK_SCRIPT:
273 package->rollback_action_running = TRUE;
274 break;
275 default:
276 break;
279 if (deferred_data)
280 set_deferred_action_props(package, deferred_data);
281 else if (actiondata)
282 MSI_SetPropertyW(package,szActionData,actiondata);
283 else
284 MSI_SetPropertyW(package,szActionData,szBlank);
286 msi_free(actiondata);
289 else if (!check_execution_scheduling_options(package,action,type))
291 rc = ERROR_SUCCESS;
292 goto end;
295 switch (type & CUSTOM_ACTION_TYPE_MASK)
297 case 1: /* DLL file stored in a Binary table stream */
298 rc = HANDLE_CustomType1(package,source,target,type,action);
299 break;
300 case 2: /* EXE file stored in a Binary table stream */
301 rc = HANDLE_CustomType2(package,source,target,type,action);
302 break;
303 case 18: /*EXE file installed with package */
304 rc = HANDLE_CustomType18(package,source,target,type,action);
305 break;
306 case 19: /* Error that halts install */
307 rc = HANDLE_CustomType19(package,source,target,type,action);
308 break;
309 case 17:
310 rc = HANDLE_CustomType17(package,source,target,type,action);
311 break;
312 case 23: /* installs another package in the source tree */
313 deformat_string(package,target,&deformated);
314 rc = HANDLE_CustomType23(package,source,deformated,type,action);
315 break;
316 case 50: /*EXE file specified by a property value */
317 rc = HANDLE_CustomType50(package,source,target,type,action);
318 break;
319 case 34: /*EXE to be run in specified directory */
320 rc = HANDLE_CustomType34(package,source,target,type,action);
321 break;
322 case 35: /* Directory set with formatted text. */
323 deformat_string(package,target,&deformated);
324 MSI_SetTargetPathW(package, source, deformated);
325 msi_free(deformated);
326 break;
327 case 51: /* Property set with formatted text. */
328 deformat_string(package,target,&deformated);
329 rc = MSI_SetPropertyW(package,source,deformated);
330 msi_free(deformated);
331 break;
332 case 37: /* JScript/VBScript text stored in target column. */
333 case 38:
334 rc = HANDLE_CustomType37_38(package,source,target,type,action);
335 break;
336 case 5:
337 case 6: /* JScript/VBScript file stored in a Binary table stream. */
338 rc = HANDLE_CustomType5_6(package,source,target,type,action);
339 break;
340 case 21: /* JScript/VBScript file installed with the product. */
341 case 22:
342 rc = HANDLE_CustomType21_22(package,source,target,type,action);
343 break;
344 case 53: /* JScript/VBScript text specified by a property value. */
345 case 54:
346 rc = HANDLE_CustomType53_54(package,source,target,type,action);
347 break;
348 default:
349 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
350 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
351 debugstr_w(target));
354 end:
355 package->scheduled_action_running = FALSE;
356 package->commit_action_running = FALSE;
357 package->rollback_action_running = FALSE;
358 msi_free(action_copy);
359 msiobj_release(&row->hdr);
360 return rc;
364 static UINT store_binary_to_temp(MSIPACKAGE *package, LPCWSTR source,
365 LPWSTR tmp_file)
367 static const WCHAR query[] = {
368 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
369 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
370 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
371 MSIRECORD *row = 0;
372 HANDLE file;
373 CHAR buffer[1024];
374 static const WCHAR f1[] = {'m','s','i',0};
375 WCHAR fmt[MAX_PATH];
376 DWORD sz = MAX_PATH;
377 UINT r;
379 if (MSI_GetPropertyW(package, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
380 GetTempPathW(MAX_PATH, fmt);
382 if (GetTempFileNameW(fmt, f1, 0, tmp_file) == 0)
384 TRACE("Unable to create file\n");
385 return ERROR_FUNCTION_FAILED;
387 track_tempfile(package, tmp_file);
389 row = MSI_QueryGetRecord(package->db, query, source);
390 if (!row)
391 return ERROR_FUNCTION_FAILED;
393 /* write out the file */
394 file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
395 FILE_ATTRIBUTE_NORMAL, NULL);
396 if (file == INVALID_HANDLE_VALUE)
397 r = ERROR_FUNCTION_FAILED;
398 else
402 DWORD write;
403 sz = sizeof buffer;
404 r = MSI_RecordReadStream(row, 2, buffer, &sz);
405 if (r != ERROR_SUCCESS)
407 ERR("Failed to get stream\n");
408 break;
410 WriteFile(file, buffer, sz, &write, NULL);
411 } while (sz == sizeof buffer);
412 CloseHandle(file);
415 msiobj_release(&row->hdr);
417 return r;
420 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
421 BOOL process, LPCWSTR name)
423 MSIRUNNINGACTION *action;
425 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
427 action->handle = Handle;
428 action->process = process;
429 action->name = strdupW(name);
431 list_add_tail( &package->RunningActions, &action->entry );
434 static UINT custom_get_process_return( HANDLE process )
436 DWORD rc = 0;
438 GetExitCodeProcess( process, &rc );
439 if (rc != 0)
440 return ERROR_FUNCTION_FAILED;
441 return ERROR_SUCCESS;
444 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
446 DWORD rc = 0;
448 GetExitCodeThread( thread, &rc );
450 switch (rc)
452 case ERROR_FUNCTION_NOT_CALLED:
453 case ERROR_SUCCESS:
454 case ERROR_INSTALL_USEREXIT:
455 case ERROR_INSTALL_FAILURE:
456 return rc;
457 case ERROR_NO_MORE_ITEMS:
458 return ERROR_SUCCESS;
459 case ERROR_INSTALL_SUSPEND:
460 ACTION_ForceReboot( package );
461 return ERROR_SUCCESS;
462 default:
463 ERR("Invalid Return Code %d\n",rc);
464 return ERROR_INSTALL_FAILURE;
468 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
469 HANDLE ProcessHandle, LPCWSTR name)
471 UINT rc = ERROR_SUCCESS;
473 if (!(type & msidbCustomActionTypeAsync))
475 TRACE("waiting for %s\n", debugstr_w(name));
477 msi_dialog_check_messages(ProcessHandle);
479 if (!(type & msidbCustomActionTypeContinue))
480 rc = custom_get_process_return(ProcessHandle);
482 CloseHandle(ProcessHandle);
484 else
486 TRACE("%s running in background\n", debugstr_w(name));
488 if (!(type & msidbCustomActionTypeContinue))
489 file_running_action(package, ProcessHandle, TRUE, name);
490 else
491 CloseHandle(ProcessHandle);
494 return rc;
497 typedef struct _msi_custom_action_info {
498 struct list entry;
499 LONG refs;
500 MSIPACKAGE *package;
501 LPWSTR source;
502 LPWSTR target;
503 HANDLE handle;
504 LPWSTR action;
505 INT type;
506 GUID guid;
507 } msi_custom_action_info;
509 static void release_custom_action_data( msi_custom_action_info *info )
511 EnterCriticalSection( &msi_custom_action_cs );
513 if (!--info->refs)
515 list_remove( &info->entry );
516 if (info->handle)
517 CloseHandle( info->handle );
518 msi_free( info->action );
519 msi_free( info->source );
520 msi_free( info->target );
521 msiobj_release( &info->package->hdr );
522 msi_free( info );
525 LeaveCriticalSection( &msi_custom_action_cs );
528 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
529 static void addref_custom_action_data( msi_custom_action_info *info )
531 info->refs++;
534 static UINT wait_thread_handle( msi_custom_action_info *info )
536 UINT rc = ERROR_SUCCESS;
538 if (!(info->type & msidbCustomActionTypeAsync))
540 TRACE("waiting for %s\n", debugstr_w( info->action ));
542 msi_dialog_check_messages( info->handle );
544 if (!(info->type & msidbCustomActionTypeContinue))
545 rc = custom_get_thread_return( info->package, info->handle );
547 release_custom_action_data( info );
549 else
551 TRACE("%s running in background\n", debugstr_w( info->action ));
554 return rc;
557 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
559 msi_custom_action_info *info;
560 BOOL found = FALSE;
562 EnterCriticalSection( &msi_custom_action_cs );
564 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
566 if (IsEqualGUID( &info->guid, guid ))
568 addref_custom_action_data( info );
569 found = TRUE;
570 break;
574 LeaveCriticalSection( &msi_custom_action_cs );
576 if (!found)
577 return NULL;
579 return info;
582 static void handle_msi_break( LPCWSTR target )
584 LPWSTR msg;
585 WCHAR val[MAX_PATH];
587 static const WCHAR MsiBreak[] = { 'M','s','i','B','r','e','a','k',0 };
588 static const WCHAR WindowsInstaller[] = {
589 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
592 static const WCHAR format[] = {
593 'T','o',' ','d','e','b','u','g',' ','y','o','u','r',' ',
594 'c','u','s','t','o','m',' ','a','c','t','i','o','n',',',' ',
595 'a','t','t','a','c','h',' ','y','o','u','r',' ','d','e','b','u','g','g','e','r',' ',
596 't','o',' ','p','r','o','c','e','s','s',' ','%','i',' ','(','0','x','%','X',')',' ',
597 'a','n','d',' ','p','r','e','s','s',' ','O','K',0
600 if( !GetEnvironmentVariableW( MsiBreak, val, MAX_PATH ))
601 return;
603 if( lstrcmpiW( val, target ))
604 return;
606 msg = msi_alloc( (lstrlenW(format) + 10) * sizeof(WCHAR) );
607 if (!msg)
608 return;
610 wsprintfW( msg, format, GetCurrentProcessId(), GetCurrentProcessId());
611 MessageBoxW( NULL, msg, WindowsInstaller, MB_OK);
612 msi_free(msg);
613 DebugBreak();
616 static UINT get_action_info( const GUID *guid, INT *type, MSIHANDLE *handle,
617 BSTR *dll, BSTR *funcname,
618 IWineMsiRemotePackage **package )
620 IClassFactory *cf = NULL;
621 IWineMsiRemoteCustomAction *rca = NULL;
622 HRESULT r;
624 r = DllGetClassObject( &CLSID_IWineMsiRemoteCustomAction,
625 &IID_IClassFactory, (LPVOID *)&cf );
626 if (FAILED(r))
628 ERR("failed to get IClassFactory interface\n");
629 return ERROR_FUNCTION_FAILED;
632 r = IClassFactory_CreateInstance( cf, NULL, &IID_IWineMsiRemoteCustomAction, (LPVOID *)&rca );
633 if (FAILED(r))
635 ERR("failed to get IWineMsiRemoteCustomAction interface\n");
636 return ERROR_FUNCTION_FAILED;
639 r = IWineMsiRemoteCustomAction_GetActionInfo( rca, guid, type, handle, dll, funcname, package );
640 IWineMsiRemoteCustomAction_Release( rca );
641 if (FAILED(r))
643 ERR("GetActionInfo failed\n");
644 return ERROR_FUNCTION_FAILED;
647 return ERROR_SUCCESS;
650 static DWORD WINAPI ACTION_CallRemoteDllFunction( const GUID *guid )
652 MsiCustomActionEntryPoint fn;
653 MSIHANDLE hPackage, handle;
654 HANDLE hModule;
655 LPSTR proc;
656 UINT r = ERROR_FUNCTION_FAILED;
657 BSTR dll = NULL, function = NULL;
658 INT type;
659 IWineMsiRemotePackage *remote_package = NULL;
661 TRACE("%s\n", debugstr_guid( guid ));
663 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
664 if (r != ERROR_SUCCESS)
665 return r;
667 hModule = LoadLibraryW( dll );
668 if (!hModule)
670 ERR("failed to load dll %s\n", debugstr_w( dll ) );
671 return r;
674 proc = strdupWtoA( function );
675 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
676 msi_free( proc );
677 if (fn)
679 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
680 if (hPackage)
682 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
683 TRACE("calling %s\n", debugstr_w( function ) );
684 handle_msi_break( function );
686 __TRY
688 r = fn( hPackage );
690 __EXCEPT_PAGE_FAULT
692 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
693 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
694 r = ERROR_SUCCESS;
696 __ENDTRY;
698 MsiCloseHandle( hPackage );
700 else
701 ERR("failed to create handle for %p\n", remote_package );
703 else
704 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
706 FreeLibrary(hModule);
708 IWineMsiRemotePackage_Release( remote_package );
709 SysFreeString( dll );
710 SysFreeString( function );
711 MsiCloseHandle( handle );
713 return r;
716 static DWORD WINAPI ACTION_CallLocalDllFunction( msi_custom_action_info *info )
718 MsiCustomActionEntryPoint fn;
719 MSIHANDLE hPackage;
720 HANDLE hModule;
721 LPSTR proc;
722 UINT r = ERROR_FUNCTION_FAILED;
724 TRACE("%s %s\n", debugstr_w( info->source ), debugstr_w( info->target ) );
726 hModule = LoadLibraryW( info->source );
727 if (!hModule)
729 ERR("failed to load dll %s\n", debugstr_w( info->source ) );
730 return r;
733 proc = strdupWtoA( info->target );
734 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
735 msi_free( proc );
736 if (fn)
738 hPackage = alloc_msihandle( &info->package->hdr );
739 if (hPackage)
741 TRACE("calling %s\n", debugstr_w( info->target ) );
742 handle_msi_break( info->target );
744 __TRY
746 r = fn( hPackage );
748 __EXCEPT_PAGE_FAULT
750 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
751 debugstr_w(info->source), debugstr_w(info->target), GetExceptionCode());
752 r = ERROR_SUCCESS;
754 __ENDTRY;
756 MsiCloseHandle( hPackage );
758 else
759 ERR("failed to create handle for %p\n", info->package );
761 else
762 ERR("GetProcAddress(%s) failed\n", debugstr_w( info->target ) );
764 FreeLibrary(hModule);
766 return r;
769 static DWORD WINAPI ACTION_CallDllFunction(const GUID *guid)
771 msi_custom_action_info *info;
772 UINT r;
774 info = find_action_by_guid(guid);
775 if (!info)
777 ERR("failed to find action %s\n", debugstr_guid(guid));
778 return ERROR_FUNCTION_FAILED;
781 TRACE("%s %s\n", debugstr_w(info->source), debugstr_w(info->target));
783 if (info->type & msidbCustomActionTypeInScript)
784 r = ACTION_CallRemoteDllFunction(guid);
785 else
786 r = ACTION_CallLocalDllFunction(info);
788 release_custom_action_data(info);
789 return r;
792 static DWORD WINAPI DllThread( LPVOID arg )
794 LPGUID guid = arg;
795 DWORD rc = 0;
797 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
799 rc = ACTION_CallDllFunction( guid );
801 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
803 MsiCloseAllHandles();
804 return rc;
807 static DWORD WINAPI ACTION_CAInstallPackage(const GUID *guid)
809 msi_custom_action_info *info;
810 UINT r = ERROR_FUNCTION_FAILED;
811 INSTALLUILEVEL old_level;
813 info = find_action_by_guid(guid);
814 if (!info)
816 ERR("failed to find action %s\n", debugstr_guid(guid));
817 return r;
820 old_level = MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);
821 r = MsiInstallProductW(info->source, info->target);
822 MsiSetInternalUI(old_level, NULL);
824 release_custom_action_data(info);
826 return r;
829 static DWORD WINAPI ConcurrentInstallThread(LPVOID arg)
831 LPGUID guid = arg;
832 DWORD rc;
834 TRACE("concurrent installation (%x) started\n", GetCurrentThreadId());
836 rc = ACTION_CAInstallPackage(guid);
838 TRACE("concurrent installation (%x) returned %i\n", GetCurrentThreadId(), rc);
840 MsiCloseAllHandles();
841 return rc;
844 static msi_custom_action_info *do_msidbCustomActionTypeDll(
845 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
847 msi_custom_action_info *info;
849 info = msi_alloc( sizeof *info );
850 if (!info)
851 return NULL;
853 msiobj_addref( &package->hdr );
854 info->refs = 2; /* 1 for our caller and 1 for thread we created */
855 info->package = package;
856 info->type = type;
857 info->target = strdupW( target );
858 info->source = strdupW( source );
859 info->action = strdupW( action );
860 CoCreateGuid( &info->guid );
862 EnterCriticalSection( &msi_custom_action_cs );
863 list_add_tail( &msi_pending_custom_actions, &info->entry );
864 LeaveCriticalSection( &msi_custom_action_cs );
866 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
867 if (!info->handle)
869 /* release both references */
870 release_custom_action_data( info );
871 release_custom_action_data( info );
872 return NULL;
875 return info;
878 static msi_custom_action_info *do_msidbCAConcurrentInstall(
879 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action)
881 msi_custom_action_info *info;
883 info = msi_alloc( sizeof *info );
884 if (!info)
885 return NULL;
887 msiobj_addref( &package->hdr );
888 info->refs = 2; /* 1 for our caller and 1 for thread we created */
889 info->package = package;
890 info->type = type;
891 info->target = strdupW( target );
892 info->source = strdupW( source );
893 info->action = strdupW( action );
894 CoCreateGuid( &info->guid );
896 EnterCriticalSection( &msi_custom_action_cs );
897 list_add_tail( &msi_pending_custom_actions, &info->entry );
898 LeaveCriticalSection( &msi_custom_action_cs );
900 info->handle = CreateThread( NULL, 0, ConcurrentInstallThread, &info->guid, 0, NULL );
901 if (!info->handle)
903 /* release both references */
904 release_custom_action_data( info );
905 release_custom_action_data( info );
906 return NULL;
909 return info;
912 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
913 LPCWSTR target, const INT type, LPCWSTR action)
915 msi_custom_action_info *info;
916 WCHAR package_path[MAX_PATH];
917 DWORD size;
919 static const WCHAR backslash[] = {'\\',0};
921 MSI_GetPropertyW(package, cszSourceDir, package_path, &size);
922 lstrcatW(package_path, backslash);
923 lstrcatW(package_path, source);
925 if (GetFileAttributesW(package_path) == INVALID_FILE_ATTRIBUTES)
927 ERR("Source package does not exist: %s\n", debugstr_w(package_path));
928 return ERROR_FUNCTION_FAILED;
931 TRACE("Installing package %s concurrently\n", debugstr_w(package_path));
933 info = do_msidbCAConcurrentInstall(package, type, package_path, target, action);
935 return wait_thread_handle(info);
938 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
939 LPCWSTR target, const INT type, LPCWSTR action)
941 msi_custom_action_info *info;
942 WCHAR tmp_file[MAX_PATH];
943 UINT r;
945 r = store_binary_to_temp(package, source, tmp_file);
946 if (r != ERROR_SUCCESS)
947 return r;
949 TRACE("Calling function %s from %s\n",debugstr_w(target),
950 debugstr_w(tmp_file));
952 if (!strchrW(tmp_file,'.'))
954 static const WCHAR dot[]={'.',0};
955 strcatW(tmp_file,dot);
958 info = do_msidbCustomActionTypeDll( package, type, tmp_file, target, action );
960 return wait_thread_handle( info );
963 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
964 LPCWSTR target, const INT type, LPCWSTR action)
966 WCHAR tmp_file[MAX_PATH];
967 STARTUPINFOW si;
968 PROCESS_INFORMATION info;
969 BOOL rc;
970 INT len;
971 WCHAR *deformated = NULL;
972 WCHAR *cmd;
973 static const WCHAR spc[] = {' ',0};
974 UINT r;
976 memset(&si,0,sizeof(STARTUPINFOW));
978 r = store_binary_to_temp(package, source, tmp_file);
979 if (r != ERROR_SUCCESS)
980 return r;
982 deformat_string(package,target,&deformated);
984 len = strlenW(tmp_file)+2;
986 if (deformated)
987 len += strlenW(deformated);
989 cmd = msi_alloc(sizeof(WCHAR)*len);
991 strcpyW(cmd,tmp_file);
992 if (deformated)
994 strcatW(cmd,spc);
995 strcatW(cmd,deformated);
997 msi_free(deformated);
1000 TRACE("executing exe %s\n", debugstr_w(cmd));
1002 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1003 c_collen, &si, &info);
1004 msi_free(cmd);
1006 if ( !rc )
1008 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1009 return ERROR_SUCCESS;
1011 CloseHandle( info.hThread );
1013 r = wait_process_handle(package, type, info.hProcess, action);
1015 return r;
1018 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
1019 LPCWSTR target, const INT type, LPCWSTR action)
1021 msi_custom_action_info *info;
1022 MSIFILE *file;
1024 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1026 file = get_loaded_file( package, source );
1027 if (!file)
1029 ERR("invalid file key %s\n", debugstr_w( source ));
1030 return ERROR_FUNCTION_FAILED;
1033 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
1035 return wait_thread_handle( info );
1038 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
1039 LPCWSTR target, const INT type, LPCWSTR action)
1041 STARTUPINFOW si;
1042 PROCESS_INFORMATION info;
1043 BOOL rc;
1044 WCHAR *deformated;
1045 WCHAR *cmd;
1046 INT len;
1047 static const WCHAR spc[] = {' ',0};
1048 MSIFILE *file;
1050 memset(&si,0,sizeof(STARTUPINFOW));
1052 file = get_loaded_file(package,source);
1053 if( !file )
1054 return ERROR_FUNCTION_FAILED;
1056 len = lstrlenW( file->TargetPath );
1058 deformat_string(package,target,&deformated);
1059 if (deformated)
1060 len += strlenW(deformated);
1061 len += 2;
1063 cmd = msi_alloc(len * sizeof(WCHAR));
1065 lstrcpyW( cmd, file->TargetPath);
1066 if (deformated)
1068 strcatW(cmd, spc);
1069 strcatW(cmd, deformated);
1071 msi_free(deformated);
1074 TRACE("executing exe %s\n", debugstr_w(cmd));
1076 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1077 c_collen, &si, &info);
1079 if ( !rc )
1081 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1082 msi_free(cmd);
1083 return ERROR_SUCCESS;
1085 msi_free(cmd);
1086 CloseHandle( info.hThread );
1088 return wait_process_handle(package, type, info.hProcess, action);
1091 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
1092 LPCWSTR target, const INT type, LPCWSTR action)
1094 static const WCHAR query[] = {
1095 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1096 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
1097 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
1098 '%','s',0
1100 MSIRECORD *row = 0;
1101 LPWSTR deformated = NULL;
1103 deformat_string( package, target, &deformated );
1105 /* first try treat the error as a number */
1106 row = MSI_QueryGetRecord( package->db, query, deformated );
1107 if( row )
1109 LPCWSTR error = MSI_RecordGetString( row, 1 );
1110 MessageBoxW( NULL, error, NULL, MB_OK );
1111 msiobj_release( &row->hdr );
1113 else
1114 MessageBoxW( NULL, deformated, NULL, MB_OK );
1116 msi_free( deformated );
1118 return ERROR_FUNCTION_FAILED;
1121 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
1122 LPCWSTR target, const INT type, LPCWSTR action)
1124 STARTUPINFOW si;
1125 PROCESS_INFORMATION info;
1126 WCHAR *prop;
1127 BOOL rc;
1128 WCHAR *deformated;
1129 WCHAR *cmd;
1130 INT len;
1131 static const WCHAR spc[] = {' ',0};
1133 memset(&si,0,sizeof(STARTUPINFOW));
1134 memset(&info,0,sizeof(PROCESS_INFORMATION));
1136 prop = msi_dup_property( package, source );
1137 if (!prop)
1138 return ERROR_SUCCESS;
1140 deformat_string(package,target,&deformated);
1141 len = strlenW(prop) + 2;
1142 if (deformated)
1143 len += strlenW(deformated);
1145 cmd = msi_alloc(sizeof(WCHAR)*len);
1147 strcpyW(cmd,prop);
1148 if (deformated)
1150 strcatW(cmd,spc);
1151 strcatW(cmd,deformated);
1153 msi_free(deformated);
1155 msi_free(prop);
1157 TRACE("executing exe %s\n", debugstr_w(cmd));
1159 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1160 c_collen, &si, &info);
1162 if ( !rc )
1164 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1165 msi_free(cmd);
1166 return ERROR_SUCCESS;
1168 msi_free(cmd);
1170 CloseHandle( info.hThread );
1172 return wait_process_handle(package, type, info.hProcess, action);
1175 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
1176 LPCWSTR target, const INT type, LPCWSTR action)
1178 LPWSTR filename, deformated;
1179 STARTUPINFOW si;
1180 PROCESS_INFORMATION info;
1181 BOOL rc;
1183 memset(&si,0,sizeof(STARTUPINFOW));
1185 filename = resolve_folder(package, source, FALSE, FALSE, TRUE, NULL);
1187 if (!filename)
1188 return ERROR_FUNCTION_FAILED;
1190 SetCurrentDirectoryW(filename);
1191 msi_free(filename);
1193 deformat_string(package,target,&deformated);
1195 if (!deformated)
1196 return ERROR_FUNCTION_FAILED;
1198 TRACE("executing exe %s\n", debugstr_w(deformated));
1200 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
1201 c_collen, &si, &info);
1203 if ( !rc )
1205 ERR("Unable to execute command %s\n", debugstr_w(deformated));
1206 msi_free(deformated);
1207 return ERROR_SUCCESS;
1209 msi_free(deformated);
1210 CloseHandle( info.hThread );
1212 return wait_process_handle(package, type, info.hProcess, action);
1215 static DWORD WINAPI ACTION_CallScript( const GUID *guid )
1217 msi_custom_action_info *info;
1218 MSIHANDLE hPackage;
1219 UINT r = ERROR_FUNCTION_FAILED;
1221 info = find_action_by_guid( guid );
1222 if (!info)
1224 ERR("failed to find action %s\n", debugstr_guid( guid) );
1225 return r;
1228 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1230 hPackage = alloc_msihandle( &info->package->hdr );
1231 if (hPackage)
1233 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1234 MsiCloseHandle( hPackage );
1236 else
1237 ERR("failed to create handle for %p\n", info->package );
1239 if (info->type & msidbCustomActionTypeAsync &&
1240 info->type & msidbCustomActionTypeContinue)
1241 release_custom_action_data( info );
1243 return S_OK;
1246 static DWORD WINAPI ScriptThread( LPVOID arg )
1248 LPGUID guid = arg;
1249 DWORD rc = 0;
1251 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1253 rc = ACTION_CallScript( guid );
1255 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1257 MsiCloseAllHandles();
1258 return rc;
1261 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1262 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1264 msi_custom_action_info *info;
1266 info = msi_alloc( sizeof *info );
1267 if (!info)
1268 return NULL;
1270 msiobj_addref( &package->hdr );
1271 info->refs = 2; /* 1 for our caller and 1 for thread we created */
1272 info->package = package;
1273 info->type = type;
1274 info->target = strdupW( function );
1275 info->source = strdupW( script );
1276 info->action = strdupW( action );
1277 CoCreateGuid( &info->guid );
1279 EnterCriticalSection( &msi_custom_action_cs );
1280 list_add_tail( &msi_pending_custom_actions, &info->entry );
1281 LeaveCriticalSection( &msi_custom_action_cs );
1283 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1284 if (!info->handle)
1286 /* release both references */
1287 release_custom_action_data( info );
1288 release_custom_action_data( info );
1289 return NULL;
1292 return info;
1295 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
1296 LPCWSTR target, const INT type, LPCWSTR action)
1298 msi_custom_action_info *info;
1300 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1302 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1304 return wait_thread_handle( info );
1307 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
1308 LPCWSTR target, const INT type, LPCWSTR action)
1310 static const WCHAR query[] = {
1311 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1312 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1313 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1314 MSIRECORD *row = 0;
1315 msi_custom_action_info *info;
1316 CHAR *buffer = NULL;
1317 WCHAR *bufferw = NULL;
1318 DWORD sz = 0;
1319 UINT r;
1321 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1323 row = MSI_QueryGetRecord(package->db, query, source);
1324 if (!row)
1325 return ERROR_FUNCTION_FAILED;
1327 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1328 if (r != ERROR_SUCCESS)
1329 return r;
1331 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1332 if (!buffer)
1333 return ERROR_FUNCTION_FAILED;
1335 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1336 if (r != ERROR_SUCCESS)
1337 goto done;
1339 buffer[sz] = 0;
1340 bufferw = strdupAtoW(buffer);
1341 if (!bufferw)
1343 r = ERROR_FUNCTION_FAILED;
1344 goto done;
1347 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1348 r = wait_thread_handle( info );
1350 done:
1351 msi_free(bufferw);
1352 msi_free(buffer);
1353 return r;
1356 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
1357 LPCWSTR target, const INT type, LPCWSTR action)
1359 msi_custom_action_info *info;
1360 MSIFILE *file;
1361 HANDLE hFile;
1362 DWORD sz, szHighWord = 0, read;
1363 CHAR *buffer=NULL;
1364 WCHAR *bufferw=NULL;
1365 BOOL bRet;
1366 UINT r;
1368 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1370 file = get_loaded_file(package,source);
1371 if (!file)
1373 ERR("invalid file key %s\n", debugstr_w(source));
1374 return ERROR_FUNCTION_FAILED;
1377 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1378 if (hFile == INVALID_HANDLE_VALUE)
1379 return ERROR_FUNCTION_FAILED;
1381 sz = GetFileSize(hFile, &szHighWord);
1382 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1384 CloseHandle(hFile);
1385 return ERROR_FUNCTION_FAILED;
1388 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1389 if (!buffer)
1391 CloseHandle(hFile);
1392 return ERROR_FUNCTION_FAILED;
1395 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1396 CloseHandle(hFile);
1397 if (!bRet)
1399 r = ERROR_FUNCTION_FAILED;
1400 goto done;
1403 buffer[read] = 0;
1404 bufferw = strdupAtoW(buffer);
1405 if (!bufferw)
1407 r = ERROR_FUNCTION_FAILED;
1408 goto done;
1411 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1412 r = wait_thread_handle( info );
1414 done:
1415 msi_free(bufferw);
1416 msi_free(buffer);
1417 return r;
1420 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
1421 LPCWSTR target, const INT type, LPCWSTR action)
1423 msi_custom_action_info *info;
1424 WCHAR *prop;
1426 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1428 prop = msi_dup_property(package,source);
1429 if (!prop)
1430 return ERROR_SUCCESS;
1432 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1433 msi_free(prop);
1434 return wait_thread_handle( info );
1437 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1439 struct list *item;
1440 HANDLE *wait_handles;
1441 unsigned int handle_count, i;
1442 msi_custom_action_info *info, *cursor;
1444 while ((item = list_head( &package->RunningActions )))
1446 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1448 list_remove( &action->entry );
1450 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1451 msi_dialog_check_messages( action->handle );
1453 CloseHandle( action->handle );
1454 msi_free( action->name );
1455 msi_free( action );
1458 EnterCriticalSection( &msi_custom_action_cs );
1460 handle_count = list_count( &msi_pending_custom_actions );
1461 wait_handles = HeapAlloc( GetProcessHeap(), 0, handle_count * sizeof(HANDLE) );
1463 handle_count = 0;
1464 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1466 if (info->package == package )
1468 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1469 handle_count++;
1473 LeaveCriticalSection( &msi_custom_action_cs );
1475 for (i = 0; i < handle_count; i++)
1477 msi_dialog_check_messages( wait_handles[i] );
1478 CloseHandle( wait_handles[i] );
1481 HeapFree( GetProcessHeap(), 0, wait_handles );
1484 typedef struct _msi_custom_remote_impl {
1485 const IWineMsiRemoteCustomActionVtbl *lpVtbl;
1486 LONG refs;
1487 } msi_custom_remote_impl;
1489 static inline msi_custom_remote_impl* mcr_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction* iface )
1491 return (msi_custom_remote_impl*) iface;
1494 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1495 REFIID riid,LPVOID *ppobj)
1497 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1498 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1500 IUnknown_AddRef( iface );
1501 *ppobj = iface;
1502 return S_OK;
1505 return E_NOINTERFACE;
1508 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1510 msi_custom_remote_impl* This = mcr_from_IWineMsiRemoteCustomAction( iface );
1512 return InterlockedIncrement( &This->refs );
1515 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1517 msi_custom_remote_impl* This = mcr_from_IWineMsiRemoteCustomAction( iface );
1518 ULONG r;
1520 r = InterlockedDecrement( &This->refs );
1521 if (r == 0)
1522 msi_free( This );
1523 return r;
1526 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1527 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1529 msi_custom_action_info *info;
1531 info = find_action_by_guid( custom_action_guid );
1532 if (!info)
1533 return E_FAIL;
1535 *type = info->type;
1536 *handle = alloc_msihandle( &info->package->hdr );
1537 *dll = SysAllocString( info->source );
1538 *func = SysAllocString( info->target );
1540 release_custom_action_data( info );
1541 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1544 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1546 mcr_QueryInterface,
1547 mcr_AddRef,
1548 mcr_Release,
1549 mcr_GetActionInfo,
1552 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1554 msi_custom_remote_impl* This;
1556 This = msi_alloc( sizeof *This );
1557 if (!This)
1558 return E_OUTOFMEMORY;
1560 This->lpVtbl = &msi_custom_remote_vtbl;
1561 This->refs = 1;
1563 *ppObj = This;
1565 return S_OK;