regedit: An English (United States) spelling fix.
[wine/multimedia.git] / dlls / msi / custom.c
blob75437673761fcd4b6ff34f493e7f59a789608ff5
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
45 typedef struct tagMSIRUNNINGACTION
47 struct list entry;
48 HANDLE handle;
49 BOOL process;
50 LPWSTR name;
51 } MSIRUNNINGACTION;
53 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
55 static CRITICAL_SECTION msi_custom_action_cs;
56 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
58 0, 0, &msi_custom_action_cs,
59 { &msi_custom_action_cs_debug.ProcessLocksList,
60 &msi_custom_action_cs_debug.ProcessLocksList },
61 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
63 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
65 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
67 UINT msi_schedule_action( MSIPACKAGE *package, UINT script, const WCHAR *action )
69 UINT count;
70 WCHAR **newbuf = NULL;
72 if (script >= SCRIPT_MAX)
74 FIXME("Unknown script requested %u\n", script);
75 return ERROR_FUNCTION_FAILED;
77 TRACE("Scheduling action %s in script %u\n", debugstr_w(action), script);
79 count = package->script->ActionCount[script];
80 package->script->ActionCount[script]++;
81 if (count != 0) newbuf = msi_realloc( package->script->Actions[script],
82 package->script->ActionCount[script] * sizeof(WCHAR *) );
83 else newbuf = msi_alloc( sizeof(WCHAR *) );
85 newbuf[count] = strdupW( action );
86 package->script->Actions[script] = newbuf;
87 return ERROR_SUCCESS;
90 UINT msi_register_unique_action( MSIPACKAGE *package, const WCHAR *action )
92 UINT count;
93 WCHAR **newbuf = NULL;
95 if (!package->script) return FALSE;
97 TRACE("Registering %s as unique action\n", debugstr_w(action));
99 count = package->script->UniqueActionsCount;
100 package->script->UniqueActionsCount++;
101 if (count != 0) newbuf = msi_realloc( package->script->UniqueActions,
102 package->script->UniqueActionsCount * sizeof(WCHAR *) );
103 else newbuf = msi_alloc( sizeof(WCHAR *) );
105 newbuf[count] = strdupW( action );
106 package->script->UniqueActions = newbuf;
107 return ERROR_SUCCESS;
110 BOOL msi_action_is_unique( const MSIPACKAGE *package, const WCHAR *action )
112 UINT i;
114 if (!package->script) return FALSE;
116 for (i = 0; i < package->script->UniqueActionsCount; i++)
118 if (!strcmpW( package->script->UniqueActions[i], action )) return TRUE;
120 return FALSE;
123 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
125 if (!package->script)
126 return TRUE;
128 if ((options & msidbCustomActionTypeClientRepeat) ==
129 msidbCustomActionTypeClientRepeat)
131 if (!(package->script->InWhatSequence & SEQUENCE_UI &&
132 package->script->InWhatSequence & SEQUENCE_EXEC))
134 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
135 return FALSE;
138 else if (options & msidbCustomActionTypeFirstSequence)
140 if (package->script->InWhatSequence & SEQUENCE_UI &&
141 package->script->InWhatSequence & SEQUENCE_EXEC )
143 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
144 return FALSE;
147 else if (options & msidbCustomActionTypeOncePerProcess)
149 if (msi_action_is_unique(package, action))
151 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
152 return FALSE;
154 else
155 msi_register_unique_action(package, action);
158 return TRUE;
161 /* stores the following properties before the action:
163 * [CustomActionData<=>UserSID<=>ProductCode]Action
165 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
166 LPCWSTR usersid, LPCWSTR prodcode)
168 LPWSTR deferred;
169 DWORD len;
171 static const WCHAR format[] = {
172 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
175 if (!actiondata)
176 return strdupW(action);
178 len = lstrlenW(action) + lstrlenW(actiondata) +
179 lstrlenW(usersid) + lstrlenW(prodcode) +
180 lstrlenW(format) - 7;
181 deferred = msi_alloc(len * sizeof(WCHAR));
183 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
184 return deferred;
187 static void set_deferred_action_props(MSIPACKAGE *package, LPWSTR deferred_data)
189 LPWSTR end, beg = deferred_data + 1;
191 static const WCHAR sep[] = {'<','=','>',0};
193 end = strstrW(beg, sep);
194 *end = '\0';
195 msi_set_property(package->db, szCustomActionData, beg);
196 beg = end + 3;
198 end = strstrW(beg, sep);
199 *end = '\0';
200 msi_set_property(package->db, szUserSID, beg);
201 beg = end + 3;
203 end = strchrW(beg, ']');
204 *end = '\0';
205 msi_set_property(package->db, szProductCode, beg);
208 static MSIBINARY *create_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
210 static const WCHAR query[] = {
211 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
212 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
213 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
214 MSIRECORD *row;
215 MSIBINARY *binary;
216 HANDLE file;
217 CHAR buffer[1024];
218 WCHAR fmt[MAX_PATH], tmpfile[MAX_PATH];
219 DWORD sz = MAX_PATH, write;
220 UINT r;
222 if (msi_get_property(package->db, szTempFolder, fmt, &sz) != ERROR_SUCCESS)
223 GetTempPathW(MAX_PATH, fmt);
225 if (!GetTempFileNameW( fmt, szMsi, 0, tmpfile ))
227 TRACE("unable to create temp file %s (%u)\n", debugstr_w(tmpfile), GetLastError());
228 return NULL;
231 row = MSI_QueryGetRecord(package->db, query, source);
232 if (!row)
233 return NULL;
235 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) )))
237 msiobj_release( &row->hdr );
238 return NULL;
240 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
241 if (file == INVALID_HANDLE_VALUE)
243 msiobj_release( &row->hdr );
244 msi_free( binary );
245 return NULL;
249 sz = sizeof(buffer);
250 r = MSI_RecordReadStream( row, 2, buffer, &sz );
251 if (r != ERROR_SUCCESS)
253 ERR("Failed to get stream\n");
254 break;
256 WriteFile( file, buffer, sz, &write, NULL );
257 } while (sz == sizeof buffer);
259 CloseHandle( file );
260 msiobj_release( &row->hdr );
261 if (r != ERROR_SUCCESS)
263 DeleteFileW( tmpfile );
264 msi_free( binary );
265 return NULL;
268 /* keep a reference to prevent the dll from being unloaded */
269 if (dll && !(binary->module = LoadLibraryW( tmpfile )))
271 WARN( "failed to load dll %s (%u)\n", debugstr_w( tmpfile ), GetLastError() );
273 binary->source = strdupW( source );
274 binary->tmpfile = strdupW( tmpfile );
275 list_add_tail( &package->binaries, &binary->entry );
276 return binary;
279 static MSIBINARY *get_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
281 MSIBINARY *binary;
283 LIST_FOR_EACH_ENTRY( binary, &package->binaries, MSIBINARY, entry )
285 if (!strcmpW( binary->source, source ))
286 return binary;
289 return create_temp_binary( package, source, dll );
292 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
293 BOOL process, LPCWSTR name)
295 MSIRUNNINGACTION *action;
297 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
299 action->handle = Handle;
300 action->process = process;
301 action->name = strdupW(name);
303 list_add_tail( &package->RunningActions, &action->entry );
306 static UINT custom_get_process_return( HANDLE process )
308 DWORD rc = 0;
310 GetExitCodeProcess( process, &rc );
311 TRACE("exit code is %u\n", rc);
312 if (rc != 0)
313 return ERROR_FUNCTION_FAILED;
314 return ERROR_SUCCESS;
317 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
319 DWORD rc = 0;
321 GetExitCodeThread( thread, &rc );
323 switch (rc)
325 case ERROR_FUNCTION_NOT_CALLED:
326 case ERROR_SUCCESS:
327 case ERROR_INSTALL_USEREXIT:
328 case ERROR_INSTALL_FAILURE:
329 return rc;
330 case ERROR_NO_MORE_ITEMS:
331 return ERROR_SUCCESS;
332 case ERROR_INSTALL_SUSPEND:
333 ACTION_ForceReboot( package );
334 return ERROR_SUCCESS;
335 default:
336 ERR("Invalid Return Code %d\n",rc);
337 return ERROR_INSTALL_FAILURE;
341 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
342 HANDLE ProcessHandle, LPCWSTR name)
344 UINT rc = ERROR_SUCCESS;
346 if (!(type & msidbCustomActionTypeAsync))
348 TRACE("waiting for %s\n", debugstr_w(name));
350 msi_dialog_check_messages(ProcessHandle);
352 if (!(type & msidbCustomActionTypeContinue))
353 rc = custom_get_process_return(ProcessHandle);
355 CloseHandle(ProcessHandle);
357 else
359 TRACE("%s running in background\n", debugstr_w(name));
361 if (!(type & msidbCustomActionTypeContinue))
362 file_running_action(package, ProcessHandle, TRUE, name);
363 else
364 CloseHandle(ProcessHandle);
367 return rc;
370 typedef struct _msi_custom_action_info {
371 struct list entry;
372 LONG refs;
373 MSIPACKAGE *package;
374 LPWSTR source;
375 LPWSTR target;
376 HANDLE handle;
377 LPWSTR action;
378 INT type;
379 GUID guid;
380 } msi_custom_action_info;
382 static void release_custom_action_data( msi_custom_action_info *info )
384 EnterCriticalSection( &msi_custom_action_cs );
386 if (!--info->refs)
388 list_remove( &info->entry );
389 if (info->handle)
390 CloseHandle( info->handle );
391 msi_free( info->action );
392 msi_free( info->source );
393 msi_free( info->target );
394 msiobj_release( &info->package->hdr );
395 msi_free( info );
398 LeaveCriticalSection( &msi_custom_action_cs );
401 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
402 static void addref_custom_action_data( msi_custom_action_info *info )
404 info->refs++;
407 static UINT wait_thread_handle( msi_custom_action_info *info )
409 UINT rc = ERROR_SUCCESS;
411 if (!(info->type & msidbCustomActionTypeAsync))
413 TRACE("waiting for %s\n", debugstr_w( info->action ));
415 msi_dialog_check_messages( info->handle );
417 if (!(info->type & msidbCustomActionTypeContinue))
418 rc = custom_get_thread_return( info->package, info->handle );
420 release_custom_action_data( info );
422 else
424 TRACE("%s running in background\n", debugstr_w( info->action ));
427 return rc;
430 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
432 msi_custom_action_info *info;
433 BOOL found = FALSE;
435 EnterCriticalSection( &msi_custom_action_cs );
437 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
439 if (IsEqualGUID( &info->guid, guid ))
441 addref_custom_action_data( info );
442 found = TRUE;
443 break;
447 LeaveCriticalSection( &msi_custom_action_cs );
449 if (!found)
450 return NULL;
452 return info;
455 static void handle_msi_break( LPCWSTR target )
457 LPWSTR msg;
458 WCHAR val[MAX_PATH];
460 static const WCHAR MsiBreak[] = { 'M','s','i','B','r','e','a','k',0 };
461 static const WCHAR WindowsInstaller[] = {
462 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
465 static const WCHAR format[] = {
466 'T','o',' ','d','e','b','u','g',' ','y','o','u','r',' ',
467 'c','u','s','t','o','m',' ','a','c','t','i','o','n',',',' ',
468 'a','t','t','a','c','h',' ','y','o','u','r',' ','d','e','b','u','g','g','e','r',' ',
469 't','o',' ','p','r','o','c','e','s','s',' ','%','i',' ','(','0','x','%','X',')',' ',
470 'a','n','d',' ','p','r','e','s','s',' ','O','K',0
473 if( !GetEnvironmentVariableW( MsiBreak, val, MAX_PATH ))
474 return;
476 if( strcmpiW( val, target ))
477 return;
479 msg = msi_alloc( (lstrlenW(format) + 10) * sizeof(WCHAR) );
480 if (!msg)
481 return;
483 wsprintfW( msg, format, GetCurrentProcessId(), GetCurrentProcessId());
484 MessageBoxW( NULL, msg, WindowsInstaller, MB_OK);
485 msi_free(msg);
486 DebugBreak();
489 static UINT get_action_info( const GUID *guid, INT *type, MSIHANDLE *handle,
490 BSTR *dll, BSTR *funcname,
491 IWineMsiRemotePackage **package )
493 IClassFactory *cf = NULL;
494 IWineMsiRemoteCustomAction *rca = NULL;
495 HRESULT r;
497 r = DllGetClassObject( &CLSID_WineMsiRemoteCustomAction,
498 &IID_IClassFactory, (LPVOID *)&cf );
499 if (FAILED(r))
501 ERR("failed to get IClassFactory interface\n");
502 return ERROR_FUNCTION_FAILED;
505 r = IClassFactory_CreateInstance( cf, NULL, &IID_IWineMsiRemoteCustomAction, (LPVOID *)&rca );
506 if (FAILED(r))
508 ERR("failed to get IWineMsiRemoteCustomAction interface\n");
509 return ERROR_FUNCTION_FAILED;
512 r = IWineMsiRemoteCustomAction_GetActionInfo( rca, guid, type, handle, dll, funcname, package );
513 IWineMsiRemoteCustomAction_Release( rca );
514 if (FAILED(r))
516 ERR("GetActionInfo failed\n");
517 return ERROR_FUNCTION_FAILED;
520 return ERROR_SUCCESS;
523 #ifdef __i386__
524 extern UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle );
525 __ASM_GLOBAL_FUNC( CUSTOMPROC_wrapper,
526 "pushl %ebp\n\t"
527 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
528 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
529 "movl %esp,%ebp\n\t"
530 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
531 "pushl 12(%ebp)\n\t"
532 "movl 8(%ebp),%eax\n\t"
533 "call *%eax\n\t"
534 "leave\n\t"
535 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
536 __ASM_CFI(".cfi_same_value %ebp\n\t")
537 "ret" )
538 #else
539 static inline UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle )
541 return proc(handle);
543 #endif
545 static DWORD ACTION_CallDllFunction( const GUID *guid )
547 MsiCustomActionEntryPoint fn;
548 MSIHANDLE hPackage, handle;
549 HANDLE hModule;
550 LPSTR proc;
551 UINT r = ERROR_FUNCTION_FAILED;
552 BSTR dll = NULL, function = NULL;
553 INT type;
554 IWineMsiRemotePackage *remote_package = NULL;
556 TRACE("%s\n", debugstr_guid( guid ));
558 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
559 if (r != ERROR_SUCCESS)
560 return r;
562 hModule = LoadLibraryW( dll );
563 if (!hModule)
565 WARN( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
566 return ERROR_SUCCESS;
569 proc = strdupWtoA( function );
570 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
571 msi_free( proc );
572 if (fn)
574 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
575 if (hPackage)
577 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
578 TRACE("calling %s\n", debugstr_w( function ) );
579 handle_msi_break( function );
581 __TRY
583 r = CUSTOMPROC_wrapper( fn, hPackage );
585 __EXCEPT_PAGE_FAULT
587 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
588 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
589 r = ERROR_SUCCESS;
591 __ENDTRY;
593 MsiCloseHandle( hPackage );
595 else
596 ERR("failed to create handle for %p\n", remote_package );
598 else
599 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
601 FreeLibrary(hModule);
603 IWineMsiRemotePackage_Release( remote_package );
604 SysFreeString( dll );
605 SysFreeString( function );
606 MsiCloseHandle( handle );
608 return r;
611 static DWORD WINAPI DllThread( LPVOID arg )
613 LPGUID guid = arg;
614 DWORD rc = 0;
616 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
618 rc = ACTION_CallDllFunction( guid );
620 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
622 MsiCloseAllHandles();
623 return rc;
626 static DWORD ACTION_CAInstallPackage(const GUID *guid)
628 msi_custom_action_info *info;
629 UINT r = ERROR_FUNCTION_FAILED;
630 INSTALLUILEVEL old_level;
632 info = find_action_by_guid(guid);
633 if (!info)
635 ERR("failed to find action %s\n", debugstr_guid(guid));
636 return r;
639 old_level = MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);
640 r = MsiInstallProductW(info->source, info->target);
641 MsiSetInternalUI(old_level, NULL);
643 release_custom_action_data(info);
645 return r;
648 static DWORD WINAPI ConcurrentInstallThread(LPVOID arg)
650 LPGUID guid = arg;
651 DWORD rc;
653 TRACE("concurrent installation (%x) started\n", GetCurrentThreadId());
655 rc = ACTION_CAInstallPackage(guid);
657 TRACE("concurrent installation (%x) returned %i\n", GetCurrentThreadId(), rc);
659 MsiCloseAllHandles();
660 return rc;
663 static msi_custom_action_info *do_msidbCustomActionTypeDll(
664 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
666 msi_custom_action_info *info;
668 info = msi_alloc( sizeof *info );
669 if (!info)
670 return NULL;
672 msiobj_addref( &package->hdr );
673 info->refs = 2; /* 1 for our caller and 1 for thread we created */
674 info->package = package;
675 info->type = type;
676 info->target = strdupW( target );
677 info->source = strdupW( source );
678 info->action = strdupW( action );
679 CoCreateGuid( &info->guid );
681 EnterCriticalSection( &msi_custom_action_cs );
682 list_add_tail( &msi_pending_custom_actions, &info->entry );
683 LeaveCriticalSection( &msi_custom_action_cs );
685 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
686 if (!info->handle)
688 /* release both references */
689 release_custom_action_data( info );
690 release_custom_action_data( info );
691 return NULL;
694 return info;
697 static msi_custom_action_info *do_msidbCAConcurrentInstall(
698 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action)
700 msi_custom_action_info *info;
702 info = msi_alloc( sizeof *info );
703 if (!info)
704 return NULL;
706 msiobj_addref( &package->hdr );
707 info->refs = 2; /* 1 for our caller and 1 for thread we created */
708 info->package = package;
709 info->type = type;
710 info->target = strdupW( target );
711 info->source = strdupW( source );
712 info->action = strdupW( action );
713 CoCreateGuid( &info->guid );
715 EnterCriticalSection( &msi_custom_action_cs );
716 list_add_tail( &msi_pending_custom_actions, &info->entry );
717 LeaveCriticalSection( &msi_custom_action_cs );
719 info->handle = CreateThread( NULL, 0, ConcurrentInstallThread, &info->guid, 0, NULL );
720 if (!info->handle)
722 /* release both references */
723 release_custom_action_data( info );
724 release_custom_action_data( info );
725 return NULL;
728 return info;
731 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
732 LPCWSTR target, const INT type, LPCWSTR action)
734 msi_custom_action_info *info;
735 WCHAR package_path[MAX_PATH];
736 DWORD size;
738 size = MAX_PATH;
739 msi_get_property(package->db, szSourceDir, package_path, &size);
740 lstrcatW(package_path, szBackSlash);
741 lstrcatW(package_path, source);
743 TRACE("Installing package %s concurrently\n", debugstr_w(package_path));
745 info = do_msidbCAConcurrentInstall(package, type, package_path, target, action);
746 return wait_thread_handle(info);
749 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
750 LPCWSTR target, const INT type, LPCWSTR action)
752 msi_custom_action_info *info;
753 MSIBINARY *binary;
755 if (!(binary = get_temp_binary( package, source, TRUE )))
756 return ERROR_FUNCTION_FAILED;
758 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
760 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
761 return wait_thread_handle( info );
764 static HANDLE execute_command( const WCHAR *app, WCHAR *arg, const WCHAR *dir )
766 static const WCHAR dotexeW[] = {'.','e','x','e',0};
767 STARTUPINFOW si;
768 PROCESS_INFORMATION info;
769 WCHAR *exe = NULL, *cmd = NULL, *p;
770 BOOL ret;
772 if (app)
774 int len_arg = 0;
775 DWORD len_exe;
777 if (!(exe = msi_alloc( MAX_PATH * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
778 len_exe = SearchPathW( NULL, app, dotexeW, MAX_PATH, exe, NULL );
779 if (len_exe >= MAX_PATH)
781 msi_free( exe );
782 if (!(exe = msi_alloc( len_exe * sizeof(WCHAR) ))) return INVALID_HANDLE_VALUE;
783 len_exe = SearchPathW( NULL, app, dotexeW, len_exe, exe, NULL );
785 if (!len_exe)
787 WARN("can't find executable %u\n", GetLastError());
788 msi_free( exe );
789 return INVALID_HANDLE_VALUE;
792 if (arg) len_arg = strlenW( arg );
793 if (!(cmd = msi_alloc( (len_exe + len_arg + 4) * sizeof(WCHAR) )))
795 msi_free( exe );
796 return INVALID_HANDLE_VALUE;
798 p = cmd;
799 if (strchrW( exe, ' ' ))
801 *p++ = '\"';
802 memcpy( p, exe, len_exe * sizeof(WCHAR) );
803 p += len_exe;
804 *p++ = '\"';
805 *p = 0;
807 else
809 strcpyW( p, exe );
810 p += len_exe;
812 if (arg)
814 *p++ = ' ';
815 memcpy( p, arg, len_arg * sizeof(WCHAR) );
816 p[len_arg] = 0;
819 memset( &si, 0, sizeof(STARTUPINFOW) );
820 ret = CreateProcessW( exe, exe ? cmd : arg, NULL, NULL, FALSE, 0, NULL, dir, &si, &info );
821 msi_free( cmd );
822 msi_free( exe );
823 if (!ret)
825 WARN("unable to execute command %u\n", GetLastError());
826 return INVALID_HANDLE_VALUE;
828 CloseHandle( info.hThread );
829 return info.hProcess;
832 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
833 LPCWSTR target, const INT type, LPCWSTR action)
835 MSIBINARY *binary;
836 HANDLE handle;
837 WCHAR *arg;
839 if (!(binary = get_temp_binary( package, source, FALSE ))) return ERROR_FUNCTION_FAILED;
841 deformat_string( package, target, &arg );
842 TRACE("exe %s arg %s\n", debugstr_w(binary->tmpfile), debugstr_w(arg));
844 handle = execute_command( binary->tmpfile, arg, szCRoot );
845 msi_free( arg );
846 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
847 return wait_process_handle( package, type, handle, action );
850 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
851 LPCWSTR target, const INT type, LPCWSTR action)
853 msi_custom_action_info *info;
854 MSIFILE *file;
856 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
858 file = msi_get_loaded_file( package, source );
859 if (!file)
861 ERR("invalid file key %s\n", debugstr_w( source ));
862 return ERROR_FUNCTION_FAILED;
865 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
866 return wait_thread_handle( info );
869 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
870 LPCWSTR target, const INT type, LPCWSTR action)
872 MSIFILE *file;
873 HANDLE handle;
874 WCHAR *arg;
876 if (!(file = msi_get_loaded_file( package, source ))) return ERROR_FUNCTION_FAILED;
878 deformat_string( package, target, &arg );
879 TRACE("exe %s arg %s\n", debugstr_w(file->TargetPath), debugstr_w(arg));
881 handle = execute_command( file->TargetPath, arg, szCRoot );
882 msi_free( arg );
883 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
884 return wait_process_handle( package, type, handle, action );
887 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
888 LPCWSTR target, const INT type, LPCWSTR action)
890 static const WCHAR query[] = {
891 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
892 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
893 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
894 '%','s',0
896 MSIRECORD *row = 0;
897 LPWSTR deformated = NULL;
899 deformat_string( package, target, &deformated );
901 /* first try treat the error as a number */
902 row = MSI_QueryGetRecord( package->db, query, deformated );
903 if( row )
905 LPCWSTR error = MSI_RecordGetString( row, 1 );
906 if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
907 MessageBoxW( NULL, error, NULL, MB_OK );
908 msiobj_release( &row->hdr );
910 else if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
911 MessageBoxW( NULL, deformated, NULL, MB_OK );
913 msi_free( deformated );
915 return ERROR_INSTALL_FAILURE;
918 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
919 LPCWSTR target, const INT type, LPCWSTR action)
921 WCHAR *exe, *arg;
922 HANDLE handle;
924 if (!(exe = msi_dup_property( package->db, source ))) return ERROR_SUCCESS;
926 deformat_string( package, target, &arg );
927 TRACE("exe %s arg %s\n", debugstr_w(exe), debugstr_w(arg));
929 handle = execute_command( exe, arg, szCRoot );
930 msi_free( arg );
931 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
932 return wait_process_handle( package, type, handle, action );
935 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
936 LPCWSTR target, const INT type, LPCWSTR action)
938 const WCHAR *workingdir;
939 HANDLE handle;
940 WCHAR *cmd;
942 workingdir = msi_get_target_folder( package, source );
943 if (!workingdir) return ERROR_FUNCTION_FAILED;
945 deformat_string( package, target, &cmd );
946 if (!cmd) return ERROR_FUNCTION_FAILED;
948 TRACE("cmd %s dir %s\n", debugstr_w(cmd), debugstr_w(workingdir));
950 handle = execute_command( NULL, cmd, workingdir );
951 msi_free( cmd );
952 if (handle == INVALID_HANDLE_VALUE) return ERROR_SUCCESS;
953 return wait_process_handle( package, type, handle, action );
956 static DWORD ACTION_CallScript( const GUID *guid )
958 msi_custom_action_info *info;
959 MSIHANDLE hPackage;
960 UINT r;
962 info = find_action_by_guid( guid );
963 if (!info)
965 ERR("failed to find action %s\n", debugstr_guid( guid) );
966 return ERROR_FUNCTION_FAILED;
969 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
971 hPackage = alloc_msihandle( &info->package->hdr );
972 if (hPackage)
974 r = call_script( hPackage, info->type, info->source, info->target, info->action );
975 TRACE("script returned %u\n", r);
976 MsiCloseHandle( hPackage );
978 else
979 ERR("failed to create handle for %p\n", info->package );
981 release_custom_action_data( info );
982 return S_OK;
985 static DWORD WINAPI ScriptThread( LPVOID arg )
987 LPGUID guid = arg;
988 DWORD rc = 0;
990 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
992 rc = ACTION_CallScript( guid );
994 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
996 MsiCloseAllHandles();
997 return rc;
1000 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1001 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1003 msi_custom_action_info *info;
1005 info = msi_alloc( sizeof *info );
1006 if (!info)
1007 return NULL;
1009 msiobj_addref( &package->hdr );
1010 info->refs = 2; /* 1 for our caller and 1 for thread we created */
1011 info->package = package;
1012 info->type = type;
1013 info->target = strdupW( function );
1014 info->source = strdupW( script );
1015 info->action = strdupW( action );
1016 CoCreateGuid( &info->guid );
1018 EnterCriticalSection( &msi_custom_action_cs );
1019 list_add_tail( &msi_pending_custom_actions, &info->entry );
1020 LeaveCriticalSection( &msi_custom_action_cs );
1022 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1023 if (!info->handle)
1025 /* release both references */
1026 release_custom_action_data( info );
1027 release_custom_action_data( info );
1028 return NULL;
1031 return info;
1034 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
1035 LPCWSTR target, const INT type, LPCWSTR action)
1037 msi_custom_action_info *info;
1039 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1041 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1042 return wait_thread_handle( info );
1045 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
1046 LPCWSTR target, const INT type, LPCWSTR action)
1048 static const WCHAR query[] = {
1049 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1050 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1051 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1052 MSIRECORD *row = 0;
1053 msi_custom_action_info *info;
1054 CHAR *buffer = NULL;
1055 WCHAR *bufferw = NULL;
1056 DWORD sz = 0;
1057 UINT r;
1059 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1061 row = MSI_QueryGetRecord(package->db, query, source);
1062 if (!row)
1063 return ERROR_FUNCTION_FAILED;
1065 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1066 if (r != ERROR_SUCCESS) return r;
1068 buffer = msi_alloc( sz + 1 );
1069 if (!buffer) return ERROR_FUNCTION_FAILED;
1071 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1072 if (r != ERROR_SUCCESS)
1073 goto done;
1075 buffer[sz] = 0;
1076 bufferw = strdupAtoW(buffer);
1077 if (!bufferw)
1079 r = ERROR_FUNCTION_FAILED;
1080 goto done;
1083 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1084 r = wait_thread_handle( info );
1086 done:
1087 msi_free(bufferw);
1088 msi_free(buffer);
1089 return r;
1092 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
1093 LPCWSTR target, const INT type, LPCWSTR action)
1095 msi_custom_action_info *info;
1096 MSIFILE *file;
1097 HANDLE hFile;
1098 DWORD sz, szHighWord = 0, read;
1099 CHAR *buffer=NULL;
1100 WCHAR *bufferw=NULL;
1101 BOOL bRet;
1102 UINT r;
1104 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1106 file = msi_get_loaded_file(package, source);
1107 if (!file)
1109 ERR("invalid file key %s\n", debugstr_w(source));
1110 return ERROR_FUNCTION_FAILED;
1113 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1114 if (hFile == INVALID_HANDLE_VALUE) return ERROR_FUNCTION_FAILED;
1116 sz = GetFileSize(hFile, &szHighWord);
1117 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1119 CloseHandle(hFile);
1120 return ERROR_FUNCTION_FAILED;
1122 buffer = msi_alloc( sz + 1 );
1123 if (!buffer)
1125 CloseHandle(hFile);
1126 return ERROR_FUNCTION_FAILED;
1128 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1129 CloseHandle(hFile);
1130 if (!bRet)
1132 r = ERROR_FUNCTION_FAILED;
1133 goto done;
1135 buffer[read] = 0;
1136 bufferw = strdupAtoW(buffer);
1137 if (!bufferw)
1139 r = ERROR_FUNCTION_FAILED;
1140 goto done;
1142 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1143 r = wait_thread_handle( info );
1145 done:
1146 msi_free(bufferw);
1147 msi_free(buffer);
1148 return r;
1151 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
1152 LPCWSTR target, const INT type, LPCWSTR action)
1154 msi_custom_action_info *info;
1155 WCHAR *prop;
1157 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1159 prop = msi_dup_property( package->db, source );
1160 if (!prop) return ERROR_SUCCESS;
1162 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1163 msi_free(prop);
1164 return wait_thread_handle( info );
1167 static BOOL action_type_matches_script( MSIPACKAGE *package, UINT type, UINT script )
1169 switch (script)
1171 case SCRIPT_NONE:
1172 case SCRIPT_INSTALL:
1173 return !(type & msidbCustomActionTypeCommit) && !(type & msidbCustomActionTypeRollback);
1174 case SCRIPT_COMMIT:
1175 return (type & msidbCustomActionTypeCommit);
1176 case SCRIPT_ROLLBACK:
1177 return (type & msidbCustomActionTypeRollback);
1178 default:
1179 ERR("unhandled script %u\n", script);
1181 return FALSE;
1184 static UINT defer_custom_action( MSIPACKAGE *package, const WCHAR *action, UINT type )
1186 WCHAR *actiondata = msi_dup_property( package->db, action );
1187 WCHAR *usersid = msi_dup_property( package->db, szUserSID );
1188 WCHAR *prodcode = msi_dup_property( package->db, szProductCode );
1189 WCHAR *deferred = msi_get_deferred_action( action, actiondata, usersid, prodcode );
1191 if (!deferred)
1193 msi_free( actiondata );
1194 msi_free( usersid );
1195 msi_free( prodcode );
1196 return ERROR_OUTOFMEMORY;
1198 if (type & msidbCustomActionTypeCommit)
1200 TRACE("deferring commit action\n");
1201 msi_schedule_action( package, SCRIPT_COMMIT, deferred );
1203 else if (type & msidbCustomActionTypeRollback)
1205 TRACE("deferring rollback action\n");
1206 msi_schedule_action( package, SCRIPT_ROLLBACK, deferred );
1208 else
1210 TRACE("deferring install action\n");
1211 msi_schedule_action( package, SCRIPT_INSTALL, deferred );
1214 msi_free( actiondata );
1215 msi_free( usersid );
1216 msi_free( prodcode );
1217 msi_free( deferred );
1218 return ERROR_SUCCESS;
1221 UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL execute)
1223 static const WCHAR query[] = {
1224 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1225 '`','C','u','s','t','o','m','A','c','t','i','o','n','`',' ','W','H','E','R','E',' ',
1226 '`','A','c','t','i' ,'o','n','`',' ','=',' ','\'','%','s','\'',0};
1227 UINT rc = ERROR_SUCCESS;
1228 MSIRECORD *row;
1229 UINT type;
1230 LPCWSTR source, target;
1231 LPWSTR ptr, deferred_data = NULL;
1232 LPWSTR deformated = NULL, action_copy = strdupW(action);
1234 /* deferred action: [properties]Action */
1235 if ((ptr = strrchrW(action_copy, ']')))
1237 deferred_data = action_copy;
1238 action = ptr + 1;
1241 row = MSI_QueryGetRecord( package->db, query, action );
1242 if (!row)
1244 msi_free(action_copy);
1245 return ERROR_CALL_NOT_IMPLEMENTED;
1248 type = MSI_RecordGetInteger(row,2);
1249 source = MSI_RecordGetString(row,3);
1250 target = MSI_RecordGetString(row,4);
1252 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
1253 debugstr_w(source), debugstr_w(target));
1255 /* handle some of the deferred actions */
1256 if (type & msidbCustomActionTypeTSAware)
1257 FIXME("msidbCustomActionTypeTSAware not handled\n");
1259 if (type & msidbCustomActionTypeInScript)
1261 if (type & msidbCustomActionTypeNoImpersonate)
1262 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
1264 if (!execute || !action_type_matches_script( package, type, script ))
1266 rc = defer_custom_action( package, action, type );
1267 goto end;
1269 else
1271 LPWSTR actiondata = msi_dup_property( package->db, action );
1273 if (type & msidbCustomActionTypeInScript)
1274 package->scheduled_action_running = TRUE;
1276 if (type & msidbCustomActionTypeCommit)
1277 package->commit_action_running = TRUE;
1279 if (type & msidbCustomActionTypeRollback)
1280 package->rollback_action_running = TRUE;
1282 if (deferred_data)
1283 set_deferred_action_props(package, deferred_data);
1284 else if (actiondata)
1285 msi_set_property(package->db, szCustomActionData, actiondata);
1286 else
1287 msi_set_property(package->db, szCustomActionData, szEmpty);
1289 msi_free(actiondata);
1292 else if (!check_execution_scheduling_options(package,action,type))
1294 rc = ERROR_SUCCESS;
1295 goto end;
1298 switch (type & CUSTOM_ACTION_TYPE_MASK)
1300 case 1: /* DLL file stored in a Binary table stream */
1301 rc = HANDLE_CustomType1(package,source,target,type,action);
1302 break;
1303 case 2: /* EXE file stored in a Binary table stream */
1304 rc = HANDLE_CustomType2(package,source,target,type,action);
1305 break;
1306 case 18: /*EXE file installed with package */
1307 rc = HANDLE_CustomType18(package,source,target,type,action);
1308 break;
1309 case 19: /* Error that halts install */
1310 rc = HANDLE_CustomType19(package,source,target,type,action);
1311 break;
1312 case 17:
1313 rc = HANDLE_CustomType17(package,source,target,type,action);
1314 break;
1315 case 23: /* installs another package in the source tree */
1316 deformat_string(package,target,&deformated);
1317 rc = HANDLE_CustomType23(package,source,deformated,type,action);
1318 msi_free(deformated);
1319 break;
1320 case 50: /*EXE file specified by a property value */
1321 rc = HANDLE_CustomType50(package,source,target,type,action);
1322 break;
1323 case 34: /*EXE to be run in specified directory */
1324 rc = HANDLE_CustomType34(package,source,target,type,action);
1325 break;
1326 case 35: /* Directory set with formatted text. */
1327 deformat_string(package,target,&deformated);
1328 MSI_SetTargetPathW(package, source, deformated);
1329 msi_free(deformated);
1330 break;
1331 case 51: /* Property set with formatted text. */
1332 if (!source)
1333 break;
1335 deformat_string(package,target,&deformated);
1336 rc = msi_set_property( package->db, source, deformated );
1337 if (rc == ERROR_SUCCESS && !strcmpW( source, szSourceDir ))
1338 msi_reset_folders( package, TRUE );
1339 msi_free(deformated);
1340 break;
1341 case 37: /* JScript/VBScript text stored in target column. */
1342 case 38:
1343 rc = HANDLE_CustomType37_38(package,source,target,type,action);
1344 break;
1345 case 5:
1346 case 6: /* JScript/VBScript file stored in a Binary table stream. */
1347 rc = HANDLE_CustomType5_6(package,source,target,type,action);
1348 break;
1349 case 21: /* JScript/VBScript file installed with the product. */
1350 case 22:
1351 rc = HANDLE_CustomType21_22(package,source,target,type,action);
1352 break;
1353 case 53: /* JScript/VBScript text specified by a property value. */
1354 case 54:
1355 rc = HANDLE_CustomType53_54(package,source,target,type,action);
1356 break;
1357 default:
1358 FIXME("unhandled action type %u (%s %s)\n", type & CUSTOM_ACTION_TYPE_MASK,
1359 debugstr_w(source), debugstr_w(target));
1362 end:
1363 package->scheduled_action_running = FALSE;
1364 package->commit_action_running = FALSE;
1365 package->rollback_action_running = FALSE;
1366 msi_free(action_copy);
1367 msiobj_release(&row->hdr);
1368 return rc;
1371 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1373 struct list *item;
1374 HANDLE *wait_handles;
1375 unsigned int handle_count, i;
1376 msi_custom_action_info *info, *cursor;
1378 while ((item = list_head( &package->RunningActions )))
1380 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1382 list_remove( &action->entry );
1384 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1385 msi_dialog_check_messages( action->handle );
1387 CloseHandle( action->handle );
1388 msi_free( action->name );
1389 msi_free( action );
1392 EnterCriticalSection( &msi_custom_action_cs );
1394 handle_count = list_count( &msi_pending_custom_actions );
1395 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1397 handle_count = 0;
1398 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1400 if (info->package == package )
1402 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1403 handle_count++;
1407 LeaveCriticalSection( &msi_custom_action_cs );
1409 for (i = 0; i < handle_count; i++)
1411 msi_dialog_check_messages( wait_handles[i] );
1412 CloseHandle( wait_handles[i] );
1414 msi_free( wait_handles );
1416 EnterCriticalSection( &msi_custom_action_cs );
1417 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1419 if (info->package == package) release_custom_action_data( info );
1421 LeaveCriticalSection( &msi_custom_action_cs );
1424 typedef struct _msi_custom_remote_impl {
1425 IWineMsiRemoteCustomAction IWineMsiRemoteCustomAction_iface;
1426 LONG refs;
1427 } msi_custom_remote_impl;
1429 static inline msi_custom_remote_impl *impl_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction *iface )
1431 return CONTAINING_RECORD(iface, msi_custom_remote_impl, IWineMsiRemoteCustomAction_iface);
1434 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1435 REFIID riid,LPVOID *ppobj)
1437 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1438 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1440 IUnknown_AddRef( iface );
1441 *ppobj = iface;
1442 return S_OK;
1445 return E_NOINTERFACE;
1448 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1450 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1452 return InterlockedIncrement( &This->refs );
1455 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1457 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1458 ULONG r;
1460 r = InterlockedDecrement( &This->refs );
1461 if (r == 0)
1462 msi_free( This );
1463 return r;
1466 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1467 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1469 msi_custom_action_info *info;
1471 info = find_action_by_guid( custom_action_guid );
1472 if (!info)
1473 return E_FAIL;
1475 *type = info->type;
1476 *handle = alloc_msihandle( &info->package->hdr );
1477 *dll = SysAllocString( info->source );
1478 *func = SysAllocString( info->target );
1480 release_custom_action_data( info );
1481 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1484 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1486 mcr_QueryInterface,
1487 mcr_AddRef,
1488 mcr_Release,
1489 mcr_GetActionInfo,
1492 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1494 msi_custom_remote_impl* This;
1496 This = msi_alloc( sizeof *This );
1497 if (!This)
1498 return E_OUTOFMEMORY;
1500 This->IWineMsiRemoteCustomAction_iface.lpVtbl = &msi_custom_remote_vtbl;
1501 This->refs = 1;
1503 *ppObj = This;
1505 return S_OK;