msi: Add an offset to sequence numbers belonging to files added by a patch.
[wine.git] / dlls / msi / custom.c
blob83a750dd5780644b9e7af476cf6b422e53f80226
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\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);
277 if (type & msidbCustomActionTypeRollback)
279 FIXME("Rollbacks not supported yet\n");
280 rc = ERROR_SUCCESS;
281 goto end;
284 else if (!check_execution_scheduling_options(package,action,type))
286 rc = ERROR_SUCCESS;
287 goto end;
290 switch (type & CUSTOM_ACTION_TYPE_MASK)
292 case 1: /* DLL file stored in a Binary table stream */
293 rc = HANDLE_CustomType1(package,source,target,type,action);
294 break;
295 case 2: /* EXE file stored in a Binary table stream */
296 rc = HANDLE_CustomType2(package,source,target,type,action);
297 break;
298 case 18: /*EXE file installed with package */
299 rc = HANDLE_CustomType18(package,source,target,type,action);
300 break;
301 case 19: /* Error that halts install */
302 rc = HANDLE_CustomType19(package,source,target,type,action);
303 break;
304 case 17:
305 rc = HANDLE_CustomType17(package,source,target,type,action);
306 break;
307 case 23: /* installs another package in the source tree */
308 deformat_string(package,target,&deformated);
309 rc = HANDLE_CustomType23(package,source,deformated,type,action);
310 msi_free(deformated);
311 break;
312 case 50: /*EXE file specified by a property value */
313 rc = HANDLE_CustomType50(package,source,target,type,action);
314 break;
315 case 34: /*EXE to be run in specified directory */
316 rc = HANDLE_CustomType34(package,source,target,type,action);
317 break;
318 case 35: /* Directory set with formatted text. */
319 deformat_string(package,target,&deformated);
320 MSI_SetTargetPathW(package, source, deformated);
321 msi_free(deformated);
322 break;
323 case 51: /* Property set with formatted text. */
324 if (!source)
325 break;
327 deformat_string(package,target,&deformated);
328 rc = msi_set_property( package->db, source, deformated );
329 if (rc == ERROR_SUCCESS && !strcmpW( source, cszSourceDir ))
330 msi_reset_folders( package, TRUE );
331 msi_free(deformated);
332 break;
333 case 37: /* JScript/VBScript text stored in target column. */
334 case 38:
335 rc = HANDLE_CustomType37_38(package,source,target,type,action);
336 break;
337 case 5:
338 case 6: /* JScript/VBScript file stored in a Binary table stream. */
339 rc = HANDLE_CustomType5_6(package,source,target,type,action);
340 break;
341 case 21: /* JScript/VBScript file installed with the product. */
342 case 22:
343 rc = HANDLE_CustomType21_22(package,source,target,type,action);
344 break;
345 case 53: /* JScript/VBScript text specified by a property value. */
346 case 54:
347 rc = HANDLE_CustomType53_54(package,source,target,type,action);
348 break;
349 default:
350 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
351 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
352 debugstr_w(target));
355 end:
356 package->scheduled_action_running = FALSE;
357 package->commit_action_running = FALSE;
358 package->rollback_action_running = FALSE;
359 msi_free(action_copy);
360 msiobj_release(&row->hdr);
361 return rc;
364 static MSIBINARY *create_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
366 static const WCHAR query[] = {
367 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
368 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
369 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
370 MSIRECORD *row;
371 MSIBINARY *binary;
372 HANDLE file;
373 CHAR buffer[1024];
374 WCHAR fmt[MAX_PATH], tmpfile[MAX_PATH];
375 DWORD sz = MAX_PATH, write;
376 UINT r;
378 if (msi_get_property(package->db, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
379 GetTempPathW(MAX_PATH, fmt);
381 if (!GetTempFileNameW( fmt, szMsi, 0, tmpfile ))
383 TRACE("unable to create temp file %s (%u)\n", debugstr_w(tmpfile), GetLastError());
384 return NULL;
387 row = MSI_QueryGetRecord(package->db, query, source);
388 if (!row)
389 return NULL;
391 if (!(binary = msi_alloc_zero( sizeof(MSIBINARY) )))
393 msiobj_release( &row->hdr );
394 return NULL;
396 file = CreateFileW( tmpfile, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
397 if (file == INVALID_HANDLE_VALUE)
399 msiobj_release( &row->hdr );
400 msi_free( binary );
401 return NULL;
405 sz = sizeof(buffer);
406 r = MSI_RecordReadStream( row, 2, buffer, &sz );
407 if (r != ERROR_SUCCESS)
409 ERR("Failed to get stream\n");
410 break;
412 WriteFile( file, buffer, sz, &write, NULL );
413 } while (sz == sizeof buffer);
415 CloseHandle( file );
416 msiobj_release( &row->hdr );
417 if (r != ERROR_SUCCESS)
419 DeleteFileW( tmpfile );
420 msi_free( binary );
421 return NULL;
424 /* keep a reference to prevent the dll from being unloaded */
425 if (dll && !(binary->module = LoadLibraryW( tmpfile )))
427 WARN( "failed to load dll %s (%u)\n", debugstr_w( tmpfile ), GetLastError() );
429 binary->source = strdupW( source );
430 binary->tmpfile = strdupW( tmpfile );
431 list_add_tail( &package->binaries, &binary->entry );
432 return binary;
435 static MSIBINARY *get_temp_binary( MSIPACKAGE *package, LPCWSTR source, BOOL dll )
437 MSIBINARY *binary;
439 LIST_FOR_EACH_ENTRY( binary, &package->binaries, MSIBINARY, entry )
441 if (!strcmpW( binary->source, source ))
442 return binary;
445 return create_temp_binary( package, source, dll );
448 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
449 BOOL process, LPCWSTR name)
451 MSIRUNNINGACTION *action;
453 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
455 action->handle = Handle;
456 action->process = process;
457 action->name = strdupW(name);
459 list_add_tail( &package->RunningActions, &action->entry );
462 static UINT custom_get_process_return( HANDLE process )
464 DWORD rc = 0;
466 GetExitCodeProcess( process, &rc );
467 if (rc != 0)
468 return ERROR_FUNCTION_FAILED;
469 return ERROR_SUCCESS;
472 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
474 DWORD rc = 0;
476 GetExitCodeThread( thread, &rc );
478 switch (rc)
480 case ERROR_FUNCTION_NOT_CALLED:
481 case ERROR_SUCCESS:
482 case ERROR_INSTALL_USEREXIT:
483 case ERROR_INSTALL_FAILURE:
484 return rc;
485 case ERROR_NO_MORE_ITEMS:
486 return ERROR_SUCCESS;
487 case ERROR_INSTALL_SUSPEND:
488 ACTION_ForceReboot( package );
489 return ERROR_SUCCESS;
490 default:
491 ERR("Invalid Return Code %d\n",rc);
492 return ERROR_INSTALL_FAILURE;
496 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
497 HANDLE ProcessHandle, LPCWSTR name)
499 UINT rc = ERROR_SUCCESS;
501 if (!(type & msidbCustomActionTypeAsync))
503 TRACE("waiting for %s\n", debugstr_w(name));
505 msi_dialog_check_messages(ProcessHandle);
507 if (!(type & msidbCustomActionTypeContinue))
508 rc = custom_get_process_return(ProcessHandle);
510 CloseHandle(ProcessHandle);
512 else
514 TRACE("%s running in background\n", debugstr_w(name));
516 if (!(type & msidbCustomActionTypeContinue))
517 file_running_action(package, ProcessHandle, TRUE, name);
518 else
519 CloseHandle(ProcessHandle);
522 return rc;
525 typedef struct _msi_custom_action_info {
526 struct list entry;
527 LONG refs;
528 MSIPACKAGE *package;
529 LPWSTR source;
530 LPWSTR target;
531 HANDLE handle;
532 LPWSTR action;
533 INT type;
534 GUID guid;
535 } msi_custom_action_info;
537 static void release_custom_action_data( msi_custom_action_info *info )
539 EnterCriticalSection( &msi_custom_action_cs );
541 if (!--info->refs)
543 list_remove( &info->entry );
544 if (info->handle)
545 CloseHandle( info->handle );
546 msi_free( info->action );
547 msi_free( info->source );
548 msi_free( info->target );
549 msiobj_release( &info->package->hdr );
550 msi_free( info );
553 LeaveCriticalSection( &msi_custom_action_cs );
556 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
557 static void addref_custom_action_data( msi_custom_action_info *info )
559 info->refs++;
562 static UINT wait_thread_handle( msi_custom_action_info *info )
564 UINT rc = ERROR_SUCCESS;
566 if (!(info->type & msidbCustomActionTypeAsync))
568 TRACE("waiting for %s\n", debugstr_w( info->action ));
570 msi_dialog_check_messages( info->handle );
572 if (!(info->type & msidbCustomActionTypeContinue))
573 rc = custom_get_thread_return( info->package, info->handle );
575 release_custom_action_data( info );
577 else
579 TRACE("%s running in background\n", debugstr_w( info->action ));
582 return rc;
585 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
587 msi_custom_action_info *info;
588 BOOL found = FALSE;
590 EnterCriticalSection( &msi_custom_action_cs );
592 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
594 if (IsEqualGUID( &info->guid, guid ))
596 addref_custom_action_data( info );
597 found = TRUE;
598 break;
602 LeaveCriticalSection( &msi_custom_action_cs );
604 if (!found)
605 return NULL;
607 return info;
610 static void handle_msi_break( LPCWSTR target )
612 LPWSTR msg;
613 WCHAR val[MAX_PATH];
615 static const WCHAR MsiBreak[] = { 'M','s','i','B','r','e','a','k',0 };
616 static const WCHAR WindowsInstaller[] = {
617 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
620 static const WCHAR format[] = {
621 'T','o',' ','d','e','b','u','g',' ','y','o','u','r',' ',
622 'c','u','s','t','o','m',' ','a','c','t','i','o','n',',',' ',
623 'a','t','t','a','c','h',' ','y','o','u','r',' ','d','e','b','u','g','g','e','r',' ',
624 't','o',' ','p','r','o','c','e','s','s',' ','%','i',' ','(','0','x','%','X',')',' ',
625 'a','n','d',' ','p','r','e','s','s',' ','O','K',0
628 if( !GetEnvironmentVariableW( MsiBreak, val, MAX_PATH ))
629 return;
631 if( strcmpiW( val, target ))
632 return;
634 msg = msi_alloc( (lstrlenW(format) + 10) * sizeof(WCHAR) );
635 if (!msg)
636 return;
638 wsprintfW( msg, format, GetCurrentProcessId(), GetCurrentProcessId());
639 MessageBoxW( NULL, msg, WindowsInstaller, MB_OK);
640 msi_free(msg);
641 DebugBreak();
644 static UINT get_action_info( const GUID *guid, INT *type, MSIHANDLE *handle,
645 BSTR *dll, BSTR *funcname,
646 IWineMsiRemotePackage **package )
648 IClassFactory *cf = NULL;
649 IWineMsiRemoteCustomAction *rca = NULL;
650 HRESULT r;
652 r = DllGetClassObject( &CLSID_WineMsiRemoteCustomAction,
653 &IID_IClassFactory, (LPVOID *)&cf );
654 if (FAILED(r))
656 ERR("failed to get IClassFactory interface\n");
657 return ERROR_FUNCTION_FAILED;
660 r = IClassFactory_CreateInstance( cf, NULL, &IID_IWineMsiRemoteCustomAction, (LPVOID *)&rca );
661 if (FAILED(r))
663 ERR("failed to get IWineMsiRemoteCustomAction interface\n");
664 return ERROR_FUNCTION_FAILED;
667 r = IWineMsiRemoteCustomAction_GetActionInfo( rca, guid, type, handle, dll, funcname, package );
668 IWineMsiRemoteCustomAction_Release( rca );
669 if (FAILED(r))
671 ERR("GetActionInfo failed\n");
672 return ERROR_FUNCTION_FAILED;
675 return ERROR_SUCCESS;
678 #ifdef __i386__
679 extern UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle );
680 __ASM_GLOBAL_FUNC( CUSTOMPROC_wrapper,
681 "pushl %ebp\n\t"
682 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
683 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
684 "movl %esp,%ebp\n\t"
685 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
686 "pushl 12(%ebp)\n\t"
687 "movl 8(%ebp),%eax\n\t"
688 "call *%eax\n\t"
689 "leave\n\t"
690 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
691 __ASM_CFI(".cfi_same_value %ebp\n\t")
692 "ret" )
693 #else
694 static inline UINT CUSTOMPROC_wrapper( MsiCustomActionEntryPoint proc, MSIHANDLE handle )
696 return proc(handle);
698 #endif
700 static DWORD ACTION_CallDllFunction( const GUID *guid )
702 MsiCustomActionEntryPoint fn;
703 MSIHANDLE hPackage, handle;
704 HANDLE hModule;
705 LPSTR proc;
706 UINT r = ERROR_FUNCTION_FAILED;
707 BSTR dll = NULL, function = NULL;
708 INT type;
709 IWineMsiRemotePackage *remote_package = NULL;
711 TRACE("%s\n", debugstr_guid( guid ));
713 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
714 if (r != ERROR_SUCCESS)
715 return r;
717 hModule = LoadLibraryW( dll );
718 if (!hModule)
720 WARN( "failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
721 return ERROR_SUCCESS;
724 proc = strdupWtoA( function );
725 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
726 msi_free( proc );
727 if (fn)
729 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
730 if (hPackage)
732 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
733 TRACE("calling %s\n", debugstr_w( function ) );
734 handle_msi_break( function );
736 __TRY
738 r = CUSTOMPROC_wrapper( fn, hPackage );
740 __EXCEPT_PAGE_FAULT
742 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
743 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
744 r = ERROR_SUCCESS;
746 __ENDTRY;
748 MsiCloseHandle( hPackage );
750 else
751 ERR("failed to create handle for %p\n", remote_package );
753 else
754 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
756 FreeLibrary(hModule);
758 IWineMsiRemotePackage_Release( remote_package );
759 SysFreeString( dll );
760 SysFreeString( function );
761 MsiCloseHandle( handle );
763 return r;
766 static DWORD WINAPI DllThread( LPVOID arg )
768 LPGUID guid = arg;
769 DWORD rc = 0;
771 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
773 rc = ACTION_CallDllFunction( guid );
775 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
777 MsiCloseAllHandles();
778 return rc;
781 static DWORD ACTION_CAInstallPackage(const GUID *guid)
783 msi_custom_action_info *info;
784 UINT r = ERROR_FUNCTION_FAILED;
785 INSTALLUILEVEL old_level;
787 info = find_action_by_guid(guid);
788 if (!info)
790 ERR("failed to find action %s\n", debugstr_guid(guid));
791 return r;
794 old_level = MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);
795 r = MsiInstallProductW(info->source, info->target);
796 MsiSetInternalUI(old_level, NULL);
798 release_custom_action_data(info);
800 return r;
803 static DWORD WINAPI ConcurrentInstallThread(LPVOID arg)
805 LPGUID guid = arg;
806 DWORD rc;
808 TRACE("concurrent installation (%x) started\n", GetCurrentThreadId());
810 rc = ACTION_CAInstallPackage(guid);
812 TRACE("concurrent installation (%x) returned %i\n", GetCurrentThreadId(), rc);
814 MsiCloseAllHandles();
815 return rc;
818 static msi_custom_action_info *do_msidbCustomActionTypeDll(
819 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
821 msi_custom_action_info *info;
823 info = msi_alloc( sizeof *info );
824 if (!info)
825 return NULL;
827 msiobj_addref( &package->hdr );
828 info->refs = 2; /* 1 for our caller and 1 for thread we created */
829 info->package = package;
830 info->type = type;
831 info->target = strdupW( target );
832 info->source = strdupW( source );
833 info->action = strdupW( action );
834 CoCreateGuid( &info->guid );
836 EnterCriticalSection( &msi_custom_action_cs );
837 list_add_tail( &msi_pending_custom_actions, &info->entry );
838 LeaveCriticalSection( &msi_custom_action_cs );
840 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
841 if (!info->handle)
843 /* release both references */
844 release_custom_action_data( info );
845 release_custom_action_data( info );
846 return NULL;
849 return info;
852 static msi_custom_action_info *do_msidbCAConcurrentInstall(
853 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action)
855 msi_custom_action_info *info;
857 info = msi_alloc( sizeof *info );
858 if (!info)
859 return NULL;
861 msiobj_addref( &package->hdr );
862 info->refs = 2; /* 1 for our caller and 1 for thread we created */
863 info->package = package;
864 info->type = type;
865 info->target = strdupW( target );
866 info->source = strdupW( source );
867 info->action = strdupW( action );
868 CoCreateGuid( &info->guid );
870 EnterCriticalSection( &msi_custom_action_cs );
871 list_add_tail( &msi_pending_custom_actions, &info->entry );
872 LeaveCriticalSection( &msi_custom_action_cs );
874 info->handle = CreateThread( NULL, 0, ConcurrentInstallThread, &info->guid, 0, NULL );
875 if (!info->handle)
877 /* release both references */
878 release_custom_action_data( info );
879 release_custom_action_data( info );
880 return NULL;
883 return info;
886 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
887 LPCWSTR target, const INT type, LPCWSTR action)
889 msi_custom_action_info *info;
890 WCHAR package_path[MAX_PATH];
891 DWORD size;
892 UINT r;
894 size = MAX_PATH;
895 msi_get_property(package->db, cszSourceDir, package_path, &size);
896 lstrcatW(package_path, szBackSlash);
897 lstrcatW(package_path, source);
899 TRACE("Installing package %s concurrently\n", debugstr_w(package_path));
901 info = do_msidbCAConcurrentInstall(package, type, package_path, target, action);
903 r = wait_thread_handle(info);
904 release_custom_action_data( info );
905 return r;
908 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
909 LPCWSTR target, const INT type, LPCWSTR action)
911 msi_custom_action_info *info;
912 MSIBINARY *binary;
913 UINT r;
915 if (!(binary = get_temp_binary( package, source, TRUE )))
916 return ERROR_FUNCTION_FAILED;
918 TRACE("Calling function %s from %s\n", debugstr_w(target), debugstr_w(binary->tmpfile));
920 info = do_msidbCustomActionTypeDll( package, type, binary->tmpfile, target, action );
922 r = wait_thread_handle( info );
923 release_custom_action_data( info );
924 return r;
927 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
928 LPCWSTR target, const INT type, LPCWSTR action)
930 STARTUPINFOW si;
931 PROCESS_INFORMATION info;
932 BOOL rc;
933 INT len;
934 WCHAR *deformated = NULL;
935 WCHAR *cmd;
936 static const WCHAR spc[] = {' ',0};
937 MSIBINARY *binary;
938 UINT r;
940 memset(&si,0,sizeof(STARTUPINFOW));
942 if (!(binary = get_temp_binary( package, source, FALSE )))
943 return ERROR_FUNCTION_FAILED;
945 deformat_string(package,target,&deformated);
947 len = strlenW( binary->tmpfile ) + 2;
948 if (deformated)
949 len += strlenW(deformated);
951 cmd = msi_alloc(sizeof(WCHAR)*len);
953 strcpyW( cmd, binary->tmpfile );
954 if (deformated)
956 strcatW(cmd,spc);
957 strcatW(cmd,deformated);
958 msi_free(deformated);
961 TRACE("executing exe %s\n", debugstr_w(cmd));
963 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
964 c_collen, &si, &info);
965 msi_free(cmd);
967 if ( !rc )
969 ERR("Unable to execute command %s\n", debugstr_w(cmd));
970 return ERROR_SUCCESS;
972 CloseHandle( info.hThread );
974 r = wait_process_handle(package, type, info.hProcess, action);
976 return r;
979 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
980 LPCWSTR target, const INT type, LPCWSTR action)
982 msi_custom_action_info *info;
983 MSIFILE *file;
984 UINT r;
986 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
988 file = get_loaded_file( package, source );
989 if (!file)
991 ERR("invalid file key %s\n", debugstr_w( source ));
992 return ERROR_FUNCTION_FAILED;
995 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
997 r = wait_thread_handle( info );
998 release_custom_action_data( info );
999 return r;
1002 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
1003 LPCWSTR target, const INT type, LPCWSTR action)
1005 STARTUPINFOW si;
1006 PROCESS_INFORMATION info;
1007 BOOL rc;
1008 WCHAR *deformated;
1009 WCHAR *cmd;
1010 INT len;
1011 static const WCHAR spc[] = {' ',0};
1012 MSIFILE *file;
1014 memset(&si,0,sizeof(STARTUPINFOW));
1016 file = get_loaded_file(package,source);
1017 if( !file )
1018 return ERROR_FUNCTION_FAILED;
1020 len = lstrlenW( file->TargetPath );
1022 deformat_string(package,target,&deformated);
1023 if (deformated)
1024 len += strlenW(deformated);
1025 len += 2;
1027 cmd = msi_alloc(len * sizeof(WCHAR));
1029 lstrcpyW( cmd, file->TargetPath);
1030 if (deformated)
1032 strcatW(cmd, spc);
1033 strcatW(cmd, deformated);
1035 msi_free(deformated);
1038 TRACE("executing exe %s\n", debugstr_w(cmd));
1040 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1041 c_collen, &si, &info);
1043 if ( !rc )
1045 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1046 msi_free(cmd);
1047 return ERROR_SUCCESS;
1049 msi_free(cmd);
1050 CloseHandle( info.hThread );
1052 return wait_process_handle(package, type, info.hProcess, action);
1055 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
1056 LPCWSTR target, const INT type, LPCWSTR action)
1058 static const WCHAR query[] = {
1059 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1060 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
1061 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
1062 '%','s',0
1064 MSIRECORD *row = 0;
1065 LPWSTR deformated = NULL;
1067 deformat_string( package, target, &deformated );
1069 /* first try treat the error as a number */
1070 row = MSI_QueryGetRecord( package->db, query, deformated );
1071 if( row )
1073 LPCWSTR error = MSI_RecordGetString( row, 1 );
1074 if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
1075 MessageBoxW( NULL, error, NULL, MB_OK );
1076 msiobj_release( &row->hdr );
1078 else if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
1079 MessageBoxW( NULL, deformated, NULL, MB_OK );
1081 msi_free( deformated );
1083 return ERROR_INSTALL_FAILURE;
1086 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
1087 LPCWSTR target, const INT type, LPCWSTR action)
1089 STARTUPINFOW si;
1090 PROCESS_INFORMATION info;
1091 WCHAR *prop;
1092 BOOL rc;
1093 WCHAR *deformated;
1094 WCHAR *cmd;
1095 INT len;
1096 static const WCHAR spc[] = {' ',0};
1098 memset(&si,0,sizeof(STARTUPINFOW));
1099 memset(&info,0,sizeof(PROCESS_INFORMATION));
1101 prop = msi_dup_property( package->db, source );
1102 if (!prop)
1103 return ERROR_SUCCESS;
1105 deformat_string(package,target,&deformated);
1106 len = strlenW(prop) + 2;
1107 if (deformated)
1108 len += strlenW(deformated);
1110 cmd = msi_alloc(sizeof(WCHAR)*len);
1112 strcpyW(cmd,prop);
1113 if (deformated)
1115 strcatW(cmd,spc);
1116 strcatW(cmd,deformated);
1118 msi_free(deformated);
1120 msi_free(prop);
1122 TRACE("executing exe %s\n", debugstr_w(cmd));
1124 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1125 c_collen, &si, &info);
1127 if ( !rc )
1129 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1130 msi_free(cmd);
1131 return ERROR_SUCCESS;
1133 msi_free(cmd);
1135 CloseHandle( info.hThread );
1137 return wait_process_handle(package, type, info.hProcess, action);
1140 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
1141 LPCWSTR target, const INT type, LPCWSTR action)
1143 LPWSTR workingdir, filename;
1144 STARTUPINFOW si;
1145 PROCESS_INFORMATION info;
1146 BOOL rc;
1148 memset(&si, 0, sizeof(STARTUPINFOW));
1150 workingdir = resolve_target_folder( package, source, FALSE, TRUE, NULL );
1151 if (!workingdir)
1152 return ERROR_FUNCTION_FAILED;
1154 deformat_string(package, target, &filename);
1156 if (!filename)
1158 msi_free(workingdir);
1159 return ERROR_FUNCTION_FAILED;
1162 TRACE("executing exe %s with working directory %s\n",
1163 debugstr_w(filename), debugstr_w(workingdir));
1165 rc = CreateProcessW(NULL, filename, NULL, NULL, FALSE, 0, NULL,
1166 workingdir, &si, &info);
1168 if ( !rc )
1170 ERR("Unable to execute command %s with working directory %s\n",
1171 debugstr_w(filename), debugstr_w(workingdir));
1172 msi_free(filename);
1173 msi_free(workingdir);
1174 return ERROR_SUCCESS;
1177 msi_free(filename);
1178 msi_free(workingdir);
1180 CloseHandle( info.hThread );
1182 return wait_process_handle(package, type, info.hProcess, action);
1185 static DWORD ACTION_CallScript( const GUID *guid )
1187 msi_custom_action_info *info;
1188 MSIHANDLE hPackage;
1189 UINT r;
1191 info = find_action_by_guid( guid );
1192 if (!info)
1194 ERR("failed to find action %s\n", debugstr_guid( guid) );
1195 return ERROR_FUNCTION_FAILED;
1198 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1200 hPackage = alloc_msihandle( &info->package->hdr );
1201 if (hPackage)
1203 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1204 TRACE("script returned %u\n", r);
1205 MsiCloseHandle( hPackage );
1207 else
1208 ERR("failed to create handle for %p\n", info->package );
1210 release_custom_action_data( info );
1211 return S_OK;
1214 static DWORD WINAPI ScriptThread( LPVOID arg )
1216 LPGUID guid = arg;
1217 DWORD rc = 0;
1219 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1221 rc = ACTION_CallScript( guid );
1223 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1225 MsiCloseAllHandles();
1226 return rc;
1229 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1230 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1232 msi_custom_action_info *info;
1234 info = msi_alloc( sizeof *info );
1235 if (!info)
1236 return NULL;
1238 msiobj_addref( &package->hdr );
1239 info->refs = 2; /* 1 for our caller and 1 for thread we created */
1240 info->package = package;
1241 info->type = type;
1242 info->target = strdupW( function );
1243 info->source = strdupW( script );
1244 info->action = strdupW( action );
1245 CoCreateGuid( &info->guid );
1247 EnterCriticalSection( &msi_custom_action_cs );
1248 list_add_tail( &msi_pending_custom_actions, &info->entry );
1249 LeaveCriticalSection( &msi_custom_action_cs );
1251 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1252 if (!info->handle)
1254 /* release both references */
1255 release_custom_action_data( info );
1256 release_custom_action_data( info );
1257 return NULL;
1260 return info;
1263 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
1264 LPCWSTR target, const INT type, LPCWSTR action)
1266 UINT r;
1267 msi_custom_action_info *info;
1269 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1271 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1273 r = wait_thread_handle( info );
1274 release_custom_action_data( info );
1275 return r;
1278 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
1279 LPCWSTR target, const INT type, LPCWSTR action)
1281 static const WCHAR query[] = {
1282 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1283 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1284 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1285 MSIRECORD *row = 0;
1286 msi_custom_action_info *info;
1287 CHAR *buffer = NULL;
1288 WCHAR *bufferw = NULL;
1289 DWORD sz = 0;
1290 UINT r;
1292 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1294 row = MSI_QueryGetRecord(package->db, query, source);
1295 if (!row)
1296 return ERROR_FUNCTION_FAILED;
1298 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1299 if (r != ERROR_SUCCESS)
1300 return r;
1302 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1303 if (!buffer)
1304 return ERROR_FUNCTION_FAILED;
1306 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1307 if (r != ERROR_SUCCESS)
1308 goto done;
1310 buffer[sz] = 0;
1311 bufferw = strdupAtoW(buffer);
1312 if (!bufferw)
1314 r = ERROR_FUNCTION_FAILED;
1315 goto done;
1318 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1319 r = wait_thread_handle( info );
1320 release_custom_action_data( info );
1322 done:
1323 msi_free(bufferw);
1324 msi_free(buffer);
1325 return r;
1328 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
1329 LPCWSTR target, const INT type, LPCWSTR action)
1331 msi_custom_action_info *info;
1332 MSIFILE *file;
1333 HANDLE hFile;
1334 DWORD sz, szHighWord = 0, read;
1335 CHAR *buffer=NULL;
1336 WCHAR *bufferw=NULL;
1337 BOOL bRet;
1338 UINT r;
1340 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1342 file = get_loaded_file(package,source);
1343 if (!file)
1345 ERR("invalid file key %s\n", debugstr_w(source));
1346 return ERROR_FUNCTION_FAILED;
1349 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1350 if (hFile == INVALID_HANDLE_VALUE)
1351 return ERROR_FUNCTION_FAILED;
1353 sz = GetFileSize(hFile, &szHighWord);
1354 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1356 CloseHandle(hFile);
1357 return ERROR_FUNCTION_FAILED;
1360 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1361 if (!buffer)
1363 CloseHandle(hFile);
1364 return ERROR_FUNCTION_FAILED;
1367 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1368 CloseHandle(hFile);
1369 if (!bRet)
1371 r = ERROR_FUNCTION_FAILED;
1372 goto done;
1375 buffer[read] = 0;
1376 bufferw = strdupAtoW(buffer);
1377 if (!bufferw)
1379 r = ERROR_FUNCTION_FAILED;
1380 goto done;
1383 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1384 r = wait_thread_handle( info );
1385 release_custom_action_data( info );
1387 done:
1388 msi_free(bufferw);
1389 msi_free(buffer);
1390 return r;
1393 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
1394 LPCWSTR target, const INT type, LPCWSTR action)
1396 msi_custom_action_info *info;
1397 WCHAR *prop;
1398 UINT r;
1400 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1402 prop = msi_dup_property( package->db, source );
1403 if (!prop)
1404 return ERROR_SUCCESS;
1406 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1407 msi_free(prop);
1408 r = wait_thread_handle( info );
1409 release_custom_action_data( info );
1410 return r;
1413 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1415 struct list *item;
1416 HANDLE *wait_handles;
1417 unsigned int handle_count, i;
1418 msi_custom_action_info *info, *cursor;
1420 while ((item = list_head( &package->RunningActions )))
1422 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1424 list_remove( &action->entry );
1426 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1427 msi_dialog_check_messages( action->handle );
1429 CloseHandle( action->handle );
1430 msi_free( action->name );
1431 msi_free( action );
1434 EnterCriticalSection( &msi_custom_action_cs );
1436 handle_count = list_count( &msi_pending_custom_actions );
1437 wait_handles = msi_alloc( handle_count * sizeof(HANDLE) );
1439 handle_count = 0;
1440 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1442 if (info->package == package )
1444 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1445 handle_count++;
1449 LeaveCriticalSection( &msi_custom_action_cs );
1451 for (i = 0; i < handle_count; i++)
1453 msi_dialog_check_messages( wait_handles[i] );
1454 CloseHandle( wait_handles[i] );
1457 msi_free( wait_handles );
1460 typedef struct _msi_custom_remote_impl {
1461 IWineMsiRemoteCustomAction IWineMsiRemoteCustomAction_iface;
1462 LONG refs;
1463 } msi_custom_remote_impl;
1465 static inline msi_custom_remote_impl *impl_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction *iface )
1467 return CONTAINING_RECORD(iface, msi_custom_remote_impl, IWineMsiRemoteCustomAction_iface);
1470 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1471 REFIID riid,LPVOID *ppobj)
1473 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1474 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1476 IUnknown_AddRef( iface );
1477 *ppobj = iface;
1478 return S_OK;
1481 return E_NOINTERFACE;
1484 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1486 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1488 return InterlockedIncrement( &This->refs );
1491 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1493 msi_custom_remote_impl* This = impl_from_IWineMsiRemoteCustomAction( iface );
1494 ULONG r;
1496 r = InterlockedDecrement( &This->refs );
1497 if (r == 0)
1498 msi_free( This );
1499 return r;
1502 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1503 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1505 msi_custom_action_info *info;
1507 info = find_action_by_guid( custom_action_guid );
1508 if (!info)
1509 return E_FAIL;
1511 *type = info->type;
1512 *handle = alloc_msihandle( &info->package->hdr );
1513 *dll = SysAllocString( info->source );
1514 *func = SysAllocString( info->target );
1516 release_custom_action_data( info );
1517 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1520 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1522 mcr_QueryInterface,
1523 mcr_AddRef,
1524 mcr_Release,
1525 mcr_GetActionInfo,
1528 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1530 msi_custom_remote_impl* This;
1532 This = msi_alloc( sizeof *This );
1533 if (!This)
1534 return E_OUTOFMEMORY;
1536 This->IWineMsiRemoteCustomAction_iface.lpVtbl = &msi_custom_remote_vtbl;
1537 This->refs = 1;
1539 *ppObj = This;
1541 return S_OK;