sync msi to wine 1.1.31
[reactos.git] / reactos / dll / win32 / msi / custom.c
1 /*
2 * Custom Action processing for the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2005 Aric Stewart for CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #define COBJMACROS
25
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"
34
35 #include "msipriv.h"
36 #include "msiserver.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39 #include "wine/exception.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(msi);
42
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};
46
47
48 static const WCHAR szActionData[] = {
49 'C','u','s','t','o','m','A','c','t','i','o','n','D','a','t','a',0
50 };
51 static const WCHAR ProdCode[] = {
52 'P','r','o','d','u','c','t','C','o','d','e',0
53 };
54 static const WCHAR UserSID[] = {'U','s','e','r','S','I','D',0};
55
56 typedef struct tagMSIRUNNINGACTION
57 {
58 struct list entry;
59 HANDLE handle;
60 BOOL process;
61 LPWSTR name;
62 } MSIRUNNINGACTION;
63
64 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
65 LPCWSTR target, const INT type, LPCWSTR action);
66 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
67 LPCWSTR target, const INT type, LPCWSTR action);
68 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
69 LPCWSTR target, const INT type, LPCWSTR action);
70 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
71 LPCWSTR target, const INT type, LPCWSTR action);
72 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
73 LPCWSTR target, const INT type, LPCWSTR action);
74 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
75 LPCWSTR target, const INT type, LPCWSTR action);
76 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
77 LPCWSTR target, const INT type, LPCWSTR action);
78 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
79 LPCWSTR target, const INT type, LPCWSTR action);
80 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
81 LPCWSTR target, const INT type, LPCWSTR action);
82 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
83 LPCWSTR target, const INT type, LPCWSTR action);
84 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
85 LPCWSTR target, const INT type, LPCWSTR action);
86 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
87 LPCWSTR target, const INT type, LPCWSTR action);
88
89 typedef UINT (WINAPI *MsiCustomActionEntryPoint)( MSIHANDLE );
90
91 static CRITICAL_SECTION msi_custom_action_cs;
92 static CRITICAL_SECTION_DEBUG msi_custom_action_cs_debug =
93 {
94 0, 0, &msi_custom_action_cs,
95 { &msi_custom_action_cs_debug.ProcessLocksList,
96 &msi_custom_action_cs_debug.ProcessLocksList },
97 0, 0, { (DWORD_PTR)(__FILE__ ": msi_custom_action_cs") }
98 };
99 static CRITICAL_SECTION msi_custom_action_cs = { &msi_custom_action_cs_debug, -1, 0, 0, 0, 0 };
100
101 static struct list msi_pending_custom_actions = LIST_INIT( msi_pending_custom_actions );
102
103 static BOOL check_execution_scheduling_options(MSIPACKAGE *package, LPCWSTR action, UINT options)
104 {
105 if (!package->script)
106 return TRUE;
107
108 if ((options & msidbCustomActionTypeClientRepeat) ==
109 msidbCustomActionTypeClientRepeat)
110 {
111 if (!(package->script->InWhatSequence & SEQUENCE_UI &&
112 package->script->InWhatSequence & SEQUENCE_EXEC))
113 {
114 TRACE("Skipping action due to dbCustomActionTypeClientRepeat option.\n");
115 return FALSE;
116 }
117 }
118 else if (options & msidbCustomActionTypeFirstSequence)
119 {
120 if (package->script->InWhatSequence & SEQUENCE_UI &&
121 package->script->InWhatSequence & SEQUENCE_EXEC )
122 {
123 TRACE("Skipping action due to msidbCustomActionTypeFirstSequence option.\n");
124 return FALSE;
125 }
126 }
127 else if (options & msidbCustomActionTypeOncePerProcess)
128 {
129 if (check_unique_action(package,action))
130 {
131 TRACE("Skipping action due to msidbCustomActionTypeOncePerProcess option.\n");
132 return FALSE;
133 }
134 else
135 register_unique_action(package,action);
136 }
137
138 return TRUE;
139 }
140
141 /* stores the following properties before the action:
142 *
143 * [CustomActionData<=>UserSID<=>ProductCode]Action
144 */
145 static LPWSTR msi_get_deferred_action(LPCWSTR action, LPCWSTR actiondata,
146 LPCWSTR usersid, LPCWSTR prodcode)
147 {
148 LPWSTR deferred;
149 DWORD len;
150
151 static const WCHAR format[] = {
152 '[','%','s','<','=','>','%','s','<','=','>','%','s',']','%','s',0
153 };
154
155 if (!actiondata)
156 return strdupW(action);
157
158 len = lstrlenW(action) + lstrlenW(actiondata) +
159 lstrlenW(usersid) + lstrlenW(prodcode) +
160 lstrlenW(format) - 7;
161 deferred = msi_alloc(len * sizeof(WCHAR));
162
163 sprintfW(deferred, format, actiondata, usersid, prodcode, action);
164 return deferred;
165 }
166
167 static void set_deferred_action_props(MSIPACKAGE *package, LPWSTR deferred_data)
168 {
169 LPWSTR end, beg = deferred_data + 1;
170
171 static const WCHAR sep[] = {'<','=','>',0};
172
173 end = strstrW(beg, sep);
174 *end = '\0';
175 MSI_SetPropertyW(package, szActionData, beg);
176 beg = end + 3;
177
178 end = strstrW(beg, sep);
179 *end = '\0';
180 MSI_SetPropertyW(package, UserSID, beg);
181 beg = end + 3;
182
183 end = strchrW(beg, ']');
184 *end = '\0';
185 MSI_SetPropertyW(package, ProdCode, beg);
186 }
187
188 UINT ACTION_CustomAction(MSIPACKAGE *package, LPCWSTR action, UINT script, BOOL execute)
189 {
190 UINT rc = ERROR_SUCCESS;
191 MSIRECORD * row = 0;
192 static const WCHAR ExecSeqQuery[] =
193 {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
194 '`','C','u','s','t','o' ,'m','A','c','t','i','o','n','`',
195 ' ','W','H','E','R','E',' ','`','A','c','t','i' ,'o','n','`',' ',
196 '=',' ','\'','%','s','\'',0};
197 UINT type;
198 LPCWSTR source, target;
199 LPWSTR ptr, deferred_data = NULL;
200 LPWSTR action_copy = strdupW(action);
201 WCHAR *deformated=NULL;
202
203 /* deferred action: [properties]Action */
204 if ((ptr = strrchrW(action_copy, ']')))
205 {
206 deferred_data = action_copy;
207 action = ptr + 1;
208 }
209
210 row = MSI_QueryGetRecord( package->db, ExecSeqQuery, action );
211 if (!row)
212 {
213 msi_free(action_copy);
214 return ERROR_CALL_NOT_IMPLEMENTED;
215 }
216
217 type = MSI_RecordGetInteger(row,2);
218
219 source = MSI_RecordGetString(row,3);
220 target = MSI_RecordGetString(row,4);
221
222 TRACE("Handling custom action %s (%x %s %s)\n",debugstr_w(action),type,
223 debugstr_w(source), debugstr_w(target));
224
225 /* handle some of the deferred actions */
226 if (type & msidbCustomActionTypeTSAware)
227 FIXME("msidbCustomActionTypeTSAware not handled\n");
228
229 if (type & msidbCustomActionTypeInScript)
230 {
231 if (type & msidbCustomActionTypeNoImpersonate)
232 WARN("msidbCustomActionTypeNoImpersonate not handled\n");
233
234 if (type & msidbCustomActionTypeRollback)
235 {
236 FIXME("Rollback only action... rollbacks not supported yet\n");
237 schedule_action(package, ROLLBACK_SCRIPT, action);
238 rc = ERROR_SUCCESS;
239 goto end;
240 }
241 if (!execute)
242 {
243 LPWSTR actiondata = msi_dup_property(package, action);
244 LPWSTR usersid = msi_dup_property(package, UserSID);
245 LPWSTR prodcode = msi_dup_property(package, ProdCode);
246 LPWSTR deferred = msi_get_deferred_action(action, actiondata, usersid, prodcode);
247
248 if (type & msidbCustomActionTypeCommit)
249 {
250 TRACE("Deferring Commit Action!\n");
251 schedule_action(package, COMMIT_SCRIPT, deferred);
252 }
253 else
254 {
255 TRACE("Deferring Action!\n");
256 schedule_action(package, INSTALL_SCRIPT, deferred);
257 }
258
259 rc = ERROR_SUCCESS;
260 msi_free(actiondata);
261 msi_free(usersid);
262 msi_free(prodcode);
263 msi_free(deferred);
264 goto end;
265 }
266 else
267 {
268 static const WCHAR szBlank[] = {0};
269
270 LPWSTR actiondata = msi_dup_property( package, action );
271
272 switch (script)
273 {
274 case INSTALL_SCRIPT:
275 package->scheduled_action_running = TRUE;
276 break;
277 case COMMIT_SCRIPT:
278 package->commit_action_running = TRUE;
279 break;
280 case ROLLBACK_SCRIPT:
281 package->rollback_action_running = TRUE;
282 break;
283 default:
284 break;
285 }
286
287 if (deferred_data)
288 set_deferred_action_props(package, deferred_data);
289 else if (actiondata)
290 MSI_SetPropertyW(package,szActionData,actiondata);
291 else
292 MSI_SetPropertyW(package,szActionData,szBlank);
293
294 msi_free(actiondata);
295 }
296 }
297 else if (!check_execution_scheduling_options(package,action,type))
298 {
299 rc = ERROR_SUCCESS;
300 goto end;
301 }
302
303 switch (type & CUSTOM_ACTION_TYPE_MASK)
304 {
305 case 1: /* DLL file stored in a Binary table stream */
306 rc = HANDLE_CustomType1(package,source,target,type,action);
307 break;
308 case 2: /* EXE file stored in a Binary table stream */
309 rc = HANDLE_CustomType2(package,source,target,type,action);
310 break;
311 case 18: /*EXE file installed with package */
312 rc = HANDLE_CustomType18(package,source,target,type,action);
313 break;
314 case 19: /* Error that halts install */
315 rc = HANDLE_CustomType19(package,source,target,type,action);
316 break;
317 case 17:
318 rc = HANDLE_CustomType17(package,source,target,type,action);
319 break;
320 case 23: /* installs another package in the source tree */
321 deformat_string(package,target,&deformated);
322 rc = HANDLE_CustomType23(package,source,deformated,type,action);
323 msi_free(deformated);
324 break;
325 case 50: /*EXE file specified by a property value */
326 rc = HANDLE_CustomType50(package,source,target,type,action);
327 break;
328 case 34: /*EXE to be run in specified directory */
329 rc = HANDLE_CustomType34(package,source,target,type,action);
330 break;
331 case 35: /* Directory set with formatted text. */
332 deformat_string(package,target,&deformated);
333 MSI_SetTargetPathW(package, source, deformated);
334 msi_free(deformated);
335 break;
336 case 51: /* Property set with formatted text. */
337 if (!source)
338 break;
339
340 deformat_string(package,target,&deformated);
341 rc = MSI_SetPropertyW(package,source,deformated);
342 msi_free(deformated);
343 break;
344 case 37: /* JScript/VBScript text stored in target column. */
345 case 38:
346 rc = HANDLE_CustomType37_38(package,source,target,type,action);
347 break;
348 case 5:
349 case 6: /* JScript/VBScript file stored in a Binary table stream. */
350 rc = HANDLE_CustomType5_6(package,source,target,type,action);
351 break;
352 case 21: /* JScript/VBScript file installed with the product. */
353 case 22:
354 rc = HANDLE_CustomType21_22(package,source,target,type,action);
355 break;
356 case 53: /* JScript/VBScript text specified by a property value. */
357 case 54:
358 rc = HANDLE_CustomType53_54(package,source,target,type,action);
359 break;
360 default:
361 FIXME("UNHANDLED ACTION TYPE %i (%s %s)\n",
362 type & CUSTOM_ACTION_TYPE_MASK, debugstr_w(source),
363 debugstr_w(target));
364 }
365
366 end:
367 package->scheduled_action_running = FALSE;
368 package->commit_action_running = FALSE;
369 package->rollback_action_running = FALSE;
370 msi_free(action_copy);
371 msiobj_release(&row->hdr);
372 return rc;
373 }
374
375
376 static UINT store_binary_to_temp(MSIPACKAGE *package, LPCWSTR source,
377 LPWSTR tmp_file)
378 {
379 static const WCHAR query[] = {
380 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
381 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
382 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
383 MSIRECORD *row = 0;
384 HANDLE file;
385 CHAR buffer[1024];
386 static const WCHAR f1[] = {'m','s','i',0};
387 WCHAR fmt[MAX_PATH];
388 DWORD sz = MAX_PATH;
389 UINT r;
390
391 if (MSI_GetPropertyW(package, cszTempFolder, fmt, &sz) != ERROR_SUCCESS)
392 GetTempPathW(MAX_PATH, fmt);
393
394 if (GetTempFileNameW(fmt, f1, 0, tmp_file) == 0)
395 {
396 TRACE("Unable to create file\n");
397 return ERROR_FUNCTION_FAILED;
398 }
399 track_tempfile(package, tmp_file);
400
401 row = MSI_QueryGetRecord(package->db, query, source);
402 if (!row)
403 return ERROR_FUNCTION_FAILED;
404
405 /* write out the file */
406 file = CreateFileW(tmp_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
407 FILE_ATTRIBUTE_NORMAL, NULL);
408 if (file == INVALID_HANDLE_VALUE)
409 r = ERROR_FUNCTION_FAILED;
410 else
411 {
412 do
413 {
414 DWORD write;
415 sz = sizeof buffer;
416 r = MSI_RecordReadStream(row, 2, buffer, &sz);
417 if (r != ERROR_SUCCESS)
418 {
419 ERR("Failed to get stream\n");
420 break;
421 }
422 WriteFile(file, buffer, sz, &write, NULL);
423 } while (sz == sizeof buffer);
424 CloseHandle(file);
425 }
426
427 msiobj_release(&row->hdr);
428
429 return r;
430 }
431
432 static void file_running_action(MSIPACKAGE* package, HANDLE Handle,
433 BOOL process, LPCWSTR name)
434 {
435 MSIRUNNINGACTION *action;
436
437 action = msi_alloc( sizeof(MSIRUNNINGACTION) );
438
439 action->handle = Handle;
440 action->process = process;
441 action->name = strdupW(name);
442
443 list_add_tail( &package->RunningActions, &action->entry );
444 }
445
446 static UINT custom_get_process_return( HANDLE process )
447 {
448 DWORD rc = 0;
449
450 GetExitCodeProcess( process, &rc );
451 if (rc != 0)
452 return ERROR_FUNCTION_FAILED;
453 return ERROR_SUCCESS;
454 }
455
456 static UINT custom_get_thread_return( MSIPACKAGE *package, HANDLE thread )
457 {
458 DWORD rc = 0;
459
460 GetExitCodeThread( thread, &rc );
461
462 switch (rc)
463 {
464 case ERROR_FUNCTION_NOT_CALLED:
465 case ERROR_SUCCESS:
466 case ERROR_INSTALL_USEREXIT:
467 case ERROR_INSTALL_FAILURE:
468 return rc;
469 case ERROR_NO_MORE_ITEMS:
470 return ERROR_SUCCESS;
471 case ERROR_INSTALL_SUSPEND:
472 ACTION_ForceReboot( package );
473 return ERROR_SUCCESS;
474 default:
475 ERR("Invalid Return Code %d\n",rc);
476 return ERROR_INSTALL_FAILURE;
477 }
478 }
479
480 static UINT wait_process_handle(MSIPACKAGE* package, UINT type,
481 HANDLE ProcessHandle, LPCWSTR name)
482 {
483 UINT rc = ERROR_SUCCESS;
484
485 if (!(type & msidbCustomActionTypeAsync))
486 {
487 TRACE("waiting for %s\n", debugstr_w(name));
488
489 msi_dialog_check_messages(ProcessHandle);
490
491 if (!(type & msidbCustomActionTypeContinue))
492 rc = custom_get_process_return(ProcessHandle);
493
494 CloseHandle(ProcessHandle);
495 }
496 else
497 {
498 TRACE("%s running in background\n", debugstr_w(name));
499
500 if (!(type & msidbCustomActionTypeContinue))
501 file_running_action(package, ProcessHandle, TRUE, name);
502 else
503 CloseHandle(ProcessHandle);
504 }
505
506 return rc;
507 }
508
509 typedef struct _msi_custom_action_info {
510 struct list entry;
511 LONG refs;
512 MSIPACKAGE *package;
513 LPWSTR source;
514 LPWSTR target;
515 HANDLE handle;
516 LPWSTR action;
517 INT type;
518 GUID guid;
519 } msi_custom_action_info;
520
521 static void release_custom_action_data( msi_custom_action_info *info )
522 {
523 EnterCriticalSection( &msi_custom_action_cs );
524
525 if (!--info->refs)
526 {
527 list_remove( &info->entry );
528 if (info->handle)
529 CloseHandle( info->handle );
530 msi_free( info->action );
531 msi_free( info->source );
532 msi_free( info->target );
533 msiobj_release( &info->package->hdr );
534 msi_free( info );
535 }
536
537 LeaveCriticalSection( &msi_custom_action_cs );
538 }
539
540 /* must be called inside msi_custom_action_cs if info is in the pending custom actions list */
541 static void addref_custom_action_data( msi_custom_action_info *info )
542 {
543 info->refs++;
544 }
545
546 static UINT wait_thread_handle( msi_custom_action_info *info )
547 {
548 UINT rc = ERROR_SUCCESS;
549
550 if (!(info->type & msidbCustomActionTypeAsync))
551 {
552 TRACE("waiting for %s\n", debugstr_w( info->action ));
553
554 msi_dialog_check_messages( info->handle );
555
556 if (!(info->type & msidbCustomActionTypeContinue))
557 rc = custom_get_thread_return( info->package, info->handle );
558
559 release_custom_action_data( info );
560 }
561 else
562 {
563 TRACE("%s running in background\n", debugstr_w( info->action ));
564 }
565
566 return rc;
567 }
568
569 static msi_custom_action_info *find_action_by_guid( const GUID *guid )
570 {
571 msi_custom_action_info *info;
572 BOOL found = FALSE;
573
574 EnterCriticalSection( &msi_custom_action_cs );
575
576 LIST_FOR_EACH_ENTRY( info, &msi_pending_custom_actions, msi_custom_action_info, entry )
577 {
578 if (IsEqualGUID( &info->guid, guid ))
579 {
580 addref_custom_action_data( info );
581 found = TRUE;
582 break;
583 }
584 }
585
586 LeaveCriticalSection( &msi_custom_action_cs );
587
588 if (!found)
589 return NULL;
590
591 return info;
592 }
593
594 static void handle_msi_break( LPCWSTR target )
595 {
596 LPWSTR msg;
597 WCHAR val[MAX_PATH];
598
599 static const WCHAR MsiBreak[] = { 'M','s','i','B','r','e','a','k',0 };
600 static const WCHAR WindowsInstaller[] = {
601 'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0
602 };
603
604 static const WCHAR format[] = {
605 'T','o',' ','d','e','b','u','g',' ','y','o','u','r',' ',
606 'c','u','s','t','o','m',' ','a','c','t','i','o','n',',',' ',
607 'a','t','t','a','c','h',' ','y','o','u','r',' ','d','e','b','u','g','g','e','r',' ',
608 't','o',' ','p','r','o','c','e','s','s',' ','%','i',' ','(','0','x','%','X',')',' ',
609 'a','n','d',' ','p','r','e','s','s',' ','O','K',0
610 };
611
612 if( !GetEnvironmentVariableW( MsiBreak, val, MAX_PATH ))
613 return;
614
615 if( lstrcmpiW( val, target ))
616 return;
617
618 msg = msi_alloc( (lstrlenW(format) + 10) * sizeof(WCHAR) );
619 if (!msg)
620 return;
621
622 wsprintfW( msg, format, GetCurrentProcessId(), GetCurrentProcessId());
623 MessageBoxW( NULL, msg, WindowsInstaller, MB_OK);
624 msi_free(msg);
625 DebugBreak();
626 }
627
628 static UINT get_action_info( const GUID *guid, INT *type, MSIHANDLE *handle,
629 BSTR *dll, BSTR *funcname,
630 IWineMsiRemotePackage **package )
631 {
632 IClassFactory *cf = NULL;
633 IWineMsiRemoteCustomAction *rca = NULL;
634 HRESULT r;
635
636 r = DllGetClassObject( &CLSID_IWineMsiRemoteCustomAction,
637 &IID_IClassFactory, (LPVOID *)&cf );
638 if (FAILED(r))
639 {
640 ERR("failed to get IClassFactory interface\n");
641 return ERROR_FUNCTION_FAILED;
642 }
643
644 r = IClassFactory_CreateInstance( cf, NULL, &IID_IWineMsiRemoteCustomAction, (LPVOID *)&rca );
645 if (FAILED(r))
646 {
647 ERR("failed to get IWineMsiRemoteCustomAction interface\n");
648 return ERROR_FUNCTION_FAILED;
649 }
650
651 r = IWineMsiRemoteCustomAction_GetActionInfo( rca, guid, type, handle, dll, funcname, package );
652 IWineMsiRemoteCustomAction_Release( rca );
653 if (FAILED(r))
654 {
655 ERR("GetActionInfo failed\n");
656 return ERROR_FUNCTION_FAILED;
657 }
658
659 return ERROR_SUCCESS;
660 }
661
662 static DWORD ACTION_CallDllFunction( const GUID *guid )
663 {
664 MsiCustomActionEntryPoint fn;
665 MSIHANDLE hPackage, handle;
666 HANDLE hModule;
667 LPSTR proc;
668 UINT r = ERROR_FUNCTION_FAILED;
669 BSTR dll = NULL, function = NULL;
670 INT type;
671 IWineMsiRemotePackage *remote_package = NULL;
672
673 TRACE("%s\n", debugstr_guid( guid ));
674
675 r = get_action_info( guid, &type, &handle, &dll, &function, &remote_package );
676 if (r != ERROR_SUCCESS)
677 return r;
678
679 hModule = LoadLibraryW( dll );
680 if (!hModule)
681 {
682 ERR("failed to load dll %s (%u)\n", debugstr_w( dll ), GetLastError() );
683 return r;
684 }
685
686 proc = strdupWtoA( function );
687 fn = (MsiCustomActionEntryPoint) GetProcAddress( hModule, proc );
688 msi_free( proc );
689 if (fn)
690 {
691 hPackage = alloc_msi_remote_handle( (IUnknown *)remote_package );
692 if (hPackage)
693 {
694 IWineMsiRemotePackage_SetMsiHandle( remote_package, handle );
695 TRACE("calling %s\n", debugstr_w( function ) );
696 handle_msi_break( function );
697
698 __TRY
699 {
700 r = fn( hPackage );
701 }
702 __EXCEPT_PAGE_FAULT
703 {
704 ERR("Custom action (%s:%s) caused a page fault: %08x\n",
705 debugstr_w(dll), debugstr_w(function), GetExceptionCode());
706 r = ERROR_SUCCESS;
707 }
708 __ENDTRY;
709
710 MsiCloseHandle( hPackage );
711 }
712 else
713 ERR("failed to create handle for %p\n", remote_package );
714 }
715 else
716 ERR("GetProcAddress(%s) failed\n", debugstr_w( function ) );
717
718 FreeLibrary(hModule);
719
720 IWineMsiRemotePackage_Release( remote_package );
721 SysFreeString( dll );
722 SysFreeString( function );
723 MsiCloseHandle( handle );
724
725 return r;
726 }
727
728 static DWORD WINAPI DllThread( LPVOID arg )
729 {
730 LPGUID guid = arg;
731 DWORD rc = 0;
732
733 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
734
735 rc = ACTION_CallDllFunction( guid );
736
737 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
738
739 MsiCloseAllHandles();
740 return rc;
741 }
742
743 static DWORD ACTION_CAInstallPackage(const GUID *guid)
744 {
745 msi_custom_action_info *info;
746 UINT r = ERROR_FUNCTION_FAILED;
747 INSTALLUILEVEL old_level;
748
749 info = find_action_by_guid(guid);
750 if (!info)
751 {
752 ERR("failed to find action %s\n", debugstr_guid(guid));
753 return r;
754 }
755
756 old_level = MsiSetInternalUI(INSTALLUILEVEL_BASIC, NULL);
757 r = MsiInstallProductW(info->source, info->target);
758 MsiSetInternalUI(old_level, NULL);
759
760 release_custom_action_data(info);
761
762 return r;
763 }
764
765 static DWORD WINAPI ConcurrentInstallThread(LPVOID arg)
766 {
767 LPGUID guid = arg;
768 DWORD rc;
769
770 TRACE("concurrent installation (%x) started\n", GetCurrentThreadId());
771
772 rc = ACTION_CAInstallPackage(guid);
773
774 TRACE("concurrent installation (%x) returned %i\n", GetCurrentThreadId(), rc);
775
776 MsiCloseAllHandles();
777 return rc;
778 }
779
780 static msi_custom_action_info *do_msidbCustomActionTypeDll(
781 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action )
782 {
783 msi_custom_action_info *info;
784
785 info = msi_alloc( sizeof *info );
786 if (!info)
787 return NULL;
788
789 msiobj_addref( &package->hdr );
790 info->refs = 2; /* 1 for our caller and 1 for thread we created */
791 info->package = package;
792 info->type = type;
793 info->target = strdupW( target );
794 info->source = strdupW( source );
795 info->action = strdupW( action );
796 CoCreateGuid( &info->guid );
797
798 EnterCriticalSection( &msi_custom_action_cs );
799 list_add_tail( &msi_pending_custom_actions, &info->entry );
800 LeaveCriticalSection( &msi_custom_action_cs );
801
802 info->handle = CreateThread( NULL, 0, DllThread, &info->guid, 0, NULL );
803 if (!info->handle)
804 {
805 /* release both references */
806 release_custom_action_data( info );
807 release_custom_action_data( info );
808 return NULL;
809 }
810
811 return info;
812 }
813
814 static msi_custom_action_info *do_msidbCAConcurrentInstall(
815 MSIPACKAGE *package, INT type, LPCWSTR source, LPCWSTR target, LPCWSTR action)
816 {
817 msi_custom_action_info *info;
818
819 info = msi_alloc( sizeof *info );
820 if (!info)
821 return NULL;
822
823 msiobj_addref( &package->hdr );
824 info->refs = 2; /* 1 for our caller and 1 for thread we created */
825 info->package = package;
826 info->type = type;
827 info->target = strdupW( target );
828 info->source = strdupW( source );
829 info->action = strdupW( action );
830 CoCreateGuid( &info->guid );
831
832 EnterCriticalSection( &msi_custom_action_cs );
833 list_add_tail( &msi_pending_custom_actions, &info->entry );
834 LeaveCriticalSection( &msi_custom_action_cs );
835
836 info->handle = CreateThread( NULL, 0, ConcurrentInstallThread, &info->guid, 0, NULL );
837 if (!info->handle)
838 {
839 /* release both references */
840 release_custom_action_data( info );
841 release_custom_action_data( info );
842 return NULL;
843 }
844
845 return info;
846 }
847
848 static UINT HANDLE_CustomType23(MSIPACKAGE *package, LPCWSTR source,
849 LPCWSTR target, const INT type, LPCWSTR action)
850 {
851 msi_custom_action_info *info;
852 WCHAR package_path[MAX_PATH];
853 DWORD size;
854 UINT r;
855
856 static const WCHAR backslash[] = {'\\',0};
857
858 size = MAX_PATH;
859 MSI_GetPropertyW(package, cszSourceDir, package_path, &size);
860 lstrcatW(package_path, backslash);
861 lstrcatW(package_path, source);
862
863 TRACE("Installing package %s concurrently\n", debugstr_w(package_path));
864
865 info = do_msidbCAConcurrentInstall(package, type, package_path, target, action);
866
867 r = wait_thread_handle(info);
868 release_custom_action_data( info );
869 return r;
870 }
871
872 static UINT HANDLE_CustomType1(MSIPACKAGE *package, LPCWSTR source,
873 LPCWSTR target, const INT type, LPCWSTR action)
874 {
875 msi_custom_action_info *info;
876 WCHAR tmp_file[MAX_PATH];
877 UINT r;
878
879 r = store_binary_to_temp(package, source, tmp_file);
880 if (r != ERROR_SUCCESS)
881 return r;
882
883 TRACE("Calling function %s from %s\n",debugstr_w(target),
884 debugstr_w(tmp_file));
885
886 if (!strchrW(tmp_file,'.'))
887 {
888 static const WCHAR dot[]={'.',0};
889 strcatW(tmp_file,dot);
890 }
891
892 info = do_msidbCustomActionTypeDll( package, type, tmp_file, target, action );
893
894 r = wait_thread_handle( info );
895 release_custom_action_data( info );
896 return r;
897 }
898
899 static UINT HANDLE_CustomType2(MSIPACKAGE *package, LPCWSTR source,
900 LPCWSTR target, const INT type, LPCWSTR action)
901 {
902 WCHAR tmp_file[MAX_PATH];
903 STARTUPINFOW si;
904 PROCESS_INFORMATION info;
905 BOOL rc;
906 INT len;
907 WCHAR *deformated = NULL;
908 WCHAR *cmd;
909 static const WCHAR spc[] = {' ',0};
910 UINT r;
911
912 memset(&si,0,sizeof(STARTUPINFOW));
913
914 r = store_binary_to_temp(package, source, tmp_file);
915 if (r != ERROR_SUCCESS)
916 return r;
917
918 deformat_string(package,target,&deformated);
919
920 len = strlenW(tmp_file)+2;
921
922 if (deformated)
923 len += strlenW(deformated);
924
925 cmd = msi_alloc(sizeof(WCHAR)*len);
926
927 strcpyW(cmd,tmp_file);
928 if (deformated)
929 {
930 strcatW(cmd,spc);
931 strcatW(cmd,deformated);
932
933 msi_free(deformated);
934 }
935
936 TRACE("executing exe %s\n", debugstr_w(cmd));
937
938 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
939 c_collen, &si, &info);
940 msi_free(cmd);
941
942 if ( !rc )
943 {
944 ERR("Unable to execute command %s\n", debugstr_w(cmd));
945 return ERROR_SUCCESS;
946 }
947 CloseHandle( info.hThread );
948
949 r = wait_process_handle(package, type, info.hProcess, action);
950
951 return r;
952 }
953
954 static UINT HANDLE_CustomType17(MSIPACKAGE *package, LPCWSTR source,
955 LPCWSTR target, const INT type, LPCWSTR action)
956 {
957 msi_custom_action_info *info;
958 MSIFILE *file;
959 UINT r;
960
961 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
962
963 file = get_loaded_file( package, source );
964 if (!file)
965 {
966 ERR("invalid file key %s\n", debugstr_w( source ));
967 return ERROR_FUNCTION_FAILED;
968 }
969
970 info = do_msidbCustomActionTypeDll( package, type, file->TargetPath, target, action );
971
972 r = wait_thread_handle( info );
973 release_custom_action_data( info );
974 return r;
975 }
976
977 static UINT HANDLE_CustomType18(MSIPACKAGE *package, LPCWSTR source,
978 LPCWSTR target, const INT type, LPCWSTR action)
979 {
980 STARTUPINFOW si;
981 PROCESS_INFORMATION info;
982 BOOL rc;
983 WCHAR *deformated;
984 WCHAR *cmd;
985 INT len;
986 static const WCHAR spc[] = {' ',0};
987 MSIFILE *file;
988
989 memset(&si,0,sizeof(STARTUPINFOW));
990
991 file = get_loaded_file(package,source);
992 if( !file )
993 return ERROR_FUNCTION_FAILED;
994
995 len = lstrlenW( file->TargetPath );
996
997 deformat_string(package,target,&deformated);
998 if (deformated)
999 len += strlenW(deformated);
1000 len += 2;
1001
1002 cmd = msi_alloc(len * sizeof(WCHAR));
1003
1004 lstrcpyW( cmd, file->TargetPath);
1005 if (deformated)
1006 {
1007 strcatW(cmd, spc);
1008 strcatW(cmd, deformated);
1009
1010 msi_free(deformated);
1011 }
1012
1013 TRACE("executing exe %s\n", debugstr_w(cmd));
1014
1015 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1016 c_collen, &si, &info);
1017
1018 if ( !rc )
1019 {
1020 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1021 msi_free(cmd);
1022 return ERROR_SUCCESS;
1023 }
1024 msi_free(cmd);
1025 CloseHandle( info.hThread );
1026
1027 return wait_process_handle(package, type, info.hProcess, action);
1028 }
1029
1030 static UINT HANDLE_CustomType19(MSIPACKAGE *package, LPCWSTR source,
1031 LPCWSTR target, const INT type, LPCWSTR action)
1032 {
1033 static const WCHAR query[] = {
1034 'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1035 'F','R','O','M',' ','`','E','r','r','o','r','`',' ',
1036 'W','H','E','R','E',' ','`','E','r','r','o','r','`',' ','=',' ',
1037 '%','s',0
1038 };
1039 MSIRECORD *row = 0;
1040 LPWSTR deformated = NULL;
1041
1042 deformat_string( package, target, &deformated );
1043
1044 /* first try treat the error as a number */
1045 row = MSI_QueryGetRecord( package->db, query, deformated );
1046 if( row )
1047 {
1048 LPCWSTR error = MSI_RecordGetString( row, 1 );
1049 if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
1050 MessageBoxW( NULL, error, NULL, MB_OK );
1051 msiobj_release( &row->hdr );
1052 }
1053 else if ((gUILevel & INSTALLUILEVEL_MASK) != INSTALLUILEVEL_NONE)
1054 MessageBoxW( NULL, deformated, NULL, MB_OK );
1055
1056 msi_free( deformated );
1057
1058 return ERROR_INSTALL_FAILURE;
1059 }
1060
1061 static UINT HANDLE_CustomType50(MSIPACKAGE *package, LPCWSTR source,
1062 LPCWSTR target, const INT type, LPCWSTR action)
1063 {
1064 STARTUPINFOW si;
1065 PROCESS_INFORMATION info;
1066 WCHAR *prop;
1067 BOOL rc;
1068 WCHAR *deformated;
1069 WCHAR *cmd;
1070 INT len;
1071 static const WCHAR spc[] = {' ',0};
1072
1073 memset(&si,0,sizeof(STARTUPINFOW));
1074 memset(&info,0,sizeof(PROCESS_INFORMATION));
1075
1076 prop = msi_dup_property( package, source );
1077 if (!prop)
1078 return ERROR_SUCCESS;
1079
1080 deformat_string(package,target,&deformated);
1081 len = strlenW(prop) + 2;
1082 if (deformated)
1083 len += strlenW(deformated);
1084
1085 cmd = msi_alloc(sizeof(WCHAR)*len);
1086
1087 strcpyW(cmd,prop);
1088 if (deformated)
1089 {
1090 strcatW(cmd,spc);
1091 strcatW(cmd,deformated);
1092
1093 msi_free(deformated);
1094 }
1095 msi_free(prop);
1096
1097 TRACE("executing exe %s\n", debugstr_w(cmd));
1098
1099 rc = CreateProcessW(NULL, cmd, NULL, NULL, FALSE, 0, NULL,
1100 c_collen, &si, &info);
1101
1102 if ( !rc )
1103 {
1104 ERR("Unable to execute command %s\n", debugstr_w(cmd));
1105 msi_free(cmd);
1106 return ERROR_SUCCESS;
1107 }
1108 msi_free(cmd);
1109
1110 CloseHandle( info.hThread );
1111
1112 return wait_process_handle(package, type, info.hProcess, action);
1113 }
1114
1115 static UINT HANDLE_CustomType34(MSIPACKAGE *package, LPCWSTR source,
1116 LPCWSTR target, const INT type, LPCWSTR action)
1117 {
1118 LPWSTR filename, deformated;
1119 STARTUPINFOW si;
1120 PROCESS_INFORMATION info;
1121 BOOL rc;
1122
1123 memset(&si,0,sizeof(STARTUPINFOW));
1124
1125 filename = resolve_folder(package, source, FALSE, FALSE, TRUE, NULL);
1126
1127 if (!filename)
1128 return ERROR_FUNCTION_FAILED;
1129
1130 SetCurrentDirectoryW(filename);
1131 msi_free(filename);
1132
1133 deformat_string(package,target,&deformated);
1134
1135 if (!deformated)
1136 return ERROR_FUNCTION_FAILED;
1137
1138 TRACE("executing exe %s\n", debugstr_w(deformated));
1139
1140 rc = CreateProcessW(NULL, deformated, NULL, NULL, FALSE, 0, NULL,
1141 c_collen, &si, &info);
1142
1143 if ( !rc )
1144 {
1145 ERR("Unable to execute command %s\n", debugstr_w(deformated));
1146 msi_free(deformated);
1147 return ERROR_SUCCESS;
1148 }
1149 msi_free(deformated);
1150 CloseHandle( info.hThread );
1151
1152 return wait_process_handle(package, type, info.hProcess, action);
1153 }
1154
1155 static DWORD ACTION_CallScript( const GUID *guid )
1156 {
1157 msi_custom_action_info *info;
1158 MSIHANDLE hPackage;
1159 UINT r = ERROR_FUNCTION_FAILED;
1160
1161 info = find_action_by_guid( guid );
1162 if (!info)
1163 {
1164 ERR("failed to find action %s\n", debugstr_guid( guid) );
1165 return r;
1166 }
1167
1168 TRACE("function %s, script %s\n", debugstr_w( info->target ), debugstr_w( info->source ) );
1169
1170 hPackage = alloc_msihandle( &info->package->hdr );
1171 if (hPackage)
1172 {
1173 r = call_script( hPackage, info->type, info->source, info->target, info->action );
1174 MsiCloseHandle( hPackage );
1175 }
1176 else
1177 ERR("failed to create handle for %p\n", info->package );
1178
1179 release_custom_action_data( info );
1180
1181 return S_OK;
1182 }
1183
1184 static DWORD WINAPI ScriptThread( LPVOID arg )
1185 {
1186 LPGUID guid = arg;
1187 DWORD rc = 0;
1188
1189 TRACE("custom action (%x) started\n", GetCurrentThreadId() );
1190
1191 rc = ACTION_CallScript( guid );
1192
1193 TRACE("custom action (%x) returned %i\n", GetCurrentThreadId(), rc );
1194
1195 MsiCloseAllHandles();
1196 return rc;
1197 }
1198
1199 static msi_custom_action_info *do_msidbCustomActionTypeScript(
1200 MSIPACKAGE *package, INT type, LPCWSTR script, LPCWSTR function, LPCWSTR action )
1201 {
1202 msi_custom_action_info *info;
1203
1204 info = msi_alloc( sizeof *info );
1205 if (!info)
1206 return NULL;
1207
1208 msiobj_addref( &package->hdr );
1209 info->refs = 2; /* 1 for our caller and 1 for thread we created */
1210 info->package = package;
1211 info->type = type;
1212 info->target = strdupW( function );
1213 info->source = strdupW( script );
1214 info->action = strdupW( action );
1215 CoCreateGuid( &info->guid );
1216
1217 EnterCriticalSection( &msi_custom_action_cs );
1218 list_add_tail( &msi_pending_custom_actions, &info->entry );
1219 LeaveCriticalSection( &msi_custom_action_cs );
1220
1221 info->handle = CreateThread( NULL, 0, ScriptThread, &info->guid, 0, NULL );
1222 if (!info->handle)
1223 {
1224 /* release both references */
1225 release_custom_action_data( info );
1226 release_custom_action_data( info );
1227 return NULL;
1228 }
1229
1230 return info;
1231 }
1232
1233 static UINT HANDLE_CustomType37_38(MSIPACKAGE *package, LPCWSTR source,
1234 LPCWSTR target, const INT type, LPCWSTR action)
1235 {
1236 UINT r;
1237 msi_custom_action_info *info;
1238
1239 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1240
1241 info = do_msidbCustomActionTypeScript( package, type, target, NULL, action );
1242
1243 r = wait_thread_handle( info );
1244 release_custom_action_data( info );
1245 return r;
1246 }
1247
1248 static UINT HANDLE_CustomType5_6(MSIPACKAGE *package, LPCWSTR source,
1249 LPCWSTR target, const INT type, LPCWSTR action)
1250 {
1251 static const WCHAR query[] = {
1252 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
1253 '`','B','i' ,'n','a','r','y','`',' ','W','H','E','R','E',' ',
1254 '`','N','a','m','e','`',' ','=',' ','\'','%','s','\'',0};
1255 MSIRECORD *row = 0;
1256 msi_custom_action_info *info;
1257 CHAR *buffer = NULL;
1258 WCHAR *bufferw = NULL;
1259 DWORD sz = 0;
1260 UINT r;
1261
1262 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1263
1264 row = MSI_QueryGetRecord(package->db, query, source);
1265 if (!row)
1266 return ERROR_FUNCTION_FAILED;
1267
1268 r = MSI_RecordReadStream(row, 2, NULL, &sz);
1269 if (r != ERROR_SUCCESS)
1270 return r;
1271
1272 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1273 if (!buffer)
1274 return ERROR_FUNCTION_FAILED;
1275
1276 r = MSI_RecordReadStream(row, 2, buffer, &sz);
1277 if (r != ERROR_SUCCESS)
1278 goto done;
1279
1280 buffer[sz] = 0;
1281 bufferw = strdupAtoW(buffer);
1282 if (!bufferw)
1283 {
1284 r = ERROR_FUNCTION_FAILED;
1285 goto done;
1286 }
1287
1288 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1289 r = wait_thread_handle( info );
1290 release_custom_action_data( info );
1291
1292 done:
1293 msi_free(bufferw);
1294 msi_free(buffer);
1295 return r;
1296 }
1297
1298 static UINT HANDLE_CustomType21_22(MSIPACKAGE *package, LPCWSTR source,
1299 LPCWSTR target, const INT type, LPCWSTR action)
1300 {
1301 msi_custom_action_info *info;
1302 MSIFILE *file;
1303 HANDLE hFile;
1304 DWORD sz, szHighWord = 0, read;
1305 CHAR *buffer=NULL;
1306 WCHAR *bufferw=NULL;
1307 BOOL bRet;
1308 UINT r;
1309
1310 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1311
1312 file = get_loaded_file(package,source);
1313 if (!file)
1314 {
1315 ERR("invalid file key %s\n", debugstr_w(source));
1316 return ERROR_FUNCTION_FAILED;
1317 }
1318
1319 hFile = CreateFileW(file->TargetPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
1320 if (hFile == INVALID_HANDLE_VALUE)
1321 return ERROR_FUNCTION_FAILED;
1322
1323 sz = GetFileSize(hFile, &szHighWord);
1324 if (sz == INVALID_FILE_SIZE || szHighWord != 0)
1325 {
1326 CloseHandle(hFile);
1327 return ERROR_FUNCTION_FAILED;
1328 }
1329
1330 buffer = msi_alloc(sizeof(CHAR)*(sz+1));
1331 if (!buffer)
1332 {
1333 CloseHandle(hFile);
1334 return ERROR_FUNCTION_FAILED;
1335 }
1336
1337 bRet = ReadFile(hFile, buffer, sz, &read, NULL);
1338 CloseHandle(hFile);
1339 if (!bRet)
1340 {
1341 r = ERROR_FUNCTION_FAILED;
1342 goto done;
1343 }
1344
1345 buffer[read] = 0;
1346 bufferw = strdupAtoW(buffer);
1347 if (!bufferw)
1348 {
1349 r = ERROR_FUNCTION_FAILED;
1350 goto done;
1351 }
1352
1353 info = do_msidbCustomActionTypeScript( package, type, bufferw, target, action );
1354 r = wait_thread_handle( info );
1355 release_custom_action_data( info );
1356
1357 done:
1358 msi_free(bufferw);
1359 msi_free(buffer);
1360 return r;
1361 }
1362
1363 static UINT HANDLE_CustomType53_54(MSIPACKAGE *package, LPCWSTR source,
1364 LPCWSTR target, const INT type, LPCWSTR action)
1365 {
1366 msi_custom_action_info *info;
1367 WCHAR *prop;
1368 UINT r;
1369
1370 TRACE("%s %s\n", debugstr_w(source), debugstr_w(target));
1371
1372 prop = msi_dup_property(package,source);
1373 if (!prop)
1374 return ERROR_SUCCESS;
1375
1376 info = do_msidbCustomActionTypeScript( package, type, prop, NULL, action );
1377 msi_free(prop);
1378 r = wait_thread_handle( info );
1379 release_custom_action_data( info );
1380 return r;
1381 }
1382
1383 void ACTION_FinishCustomActions(const MSIPACKAGE* package)
1384 {
1385 struct list *item;
1386 HANDLE *wait_handles;
1387 unsigned int handle_count, i;
1388 msi_custom_action_info *info, *cursor;
1389
1390 while ((item = list_head( &package->RunningActions )))
1391 {
1392 MSIRUNNINGACTION *action = LIST_ENTRY( item, MSIRUNNINGACTION, entry );
1393
1394 list_remove( &action->entry );
1395
1396 TRACE("waiting for %s\n", debugstr_w( action->name ) );
1397 msi_dialog_check_messages( action->handle );
1398
1399 CloseHandle( action->handle );
1400 msi_free( action->name );
1401 msi_free( action );
1402 }
1403
1404 EnterCriticalSection( &msi_custom_action_cs );
1405
1406 handle_count = list_count( &msi_pending_custom_actions );
1407 wait_handles = HeapAlloc( GetProcessHeap(), 0, handle_count * sizeof(HANDLE) );
1408
1409 handle_count = 0;
1410 LIST_FOR_EACH_ENTRY_SAFE( info, cursor, &msi_pending_custom_actions, msi_custom_action_info, entry )
1411 {
1412 if (info->package == package )
1413 {
1414 if (DuplicateHandle(GetCurrentProcess(), info->handle, GetCurrentProcess(), &wait_handles[handle_count], SYNCHRONIZE, FALSE, 0))
1415 handle_count++;
1416 }
1417 }
1418
1419 LeaveCriticalSection( &msi_custom_action_cs );
1420
1421 for (i = 0; i < handle_count; i++)
1422 {
1423 msi_dialog_check_messages( wait_handles[i] );
1424 CloseHandle( wait_handles[i] );
1425 }
1426
1427 HeapFree( GetProcessHeap(), 0, wait_handles );
1428 }
1429
1430 typedef struct _msi_custom_remote_impl {
1431 const IWineMsiRemoteCustomActionVtbl *lpVtbl;
1432 LONG refs;
1433 } msi_custom_remote_impl;
1434
1435 static inline msi_custom_remote_impl* mcr_from_IWineMsiRemoteCustomAction( IWineMsiRemoteCustomAction* iface )
1436 {
1437 return (msi_custom_remote_impl*) iface;
1438 }
1439
1440 static HRESULT WINAPI mcr_QueryInterface( IWineMsiRemoteCustomAction *iface,
1441 REFIID riid,LPVOID *ppobj)
1442 {
1443 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1444 IsEqualCLSID( riid, &IID_IWineMsiRemoteCustomAction ) )
1445 {
1446 IUnknown_AddRef( iface );
1447 *ppobj = iface;
1448 return S_OK;
1449 }
1450
1451 return E_NOINTERFACE;
1452 }
1453
1454 static ULONG WINAPI mcr_AddRef( IWineMsiRemoteCustomAction *iface )
1455 {
1456 msi_custom_remote_impl* This = mcr_from_IWineMsiRemoteCustomAction( iface );
1457
1458 return InterlockedIncrement( &This->refs );
1459 }
1460
1461 static ULONG WINAPI mcr_Release( IWineMsiRemoteCustomAction *iface )
1462 {
1463 msi_custom_remote_impl* This = mcr_from_IWineMsiRemoteCustomAction( iface );
1464 ULONG r;
1465
1466 r = InterlockedDecrement( &This->refs );
1467 if (r == 0)
1468 msi_free( This );
1469 return r;
1470 }
1471
1472 static HRESULT WINAPI mcr_GetActionInfo( IWineMsiRemoteCustomAction *iface, LPCGUID custom_action_guid,
1473 INT *type, MSIHANDLE *handle, BSTR *dll, BSTR *func, IWineMsiRemotePackage **remote_package )
1474 {
1475 msi_custom_action_info *info;
1476
1477 info = find_action_by_guid( custom_action_guid );
1478 if (!info)
1479 return E_FAIL;
1480
1481 *type = info->type;
1482 *handle = alloc_msihandle( &info->package->hdr );
1483 *dll = SysAllocString( info->source );
1484 *func = SysAllocString( info->target );
1485
1486 release_custom_action_data( info );
1487 return create_msi_remote_package( NULL, (LPVOID *)remote_package );
1488 }
1489
1490 static const IWineMsiRemoteCustomActionVtbl msi_custom_remote_vtbl =
1491 {
1492 mcr_QueryInterface,
1493 mcr_AddRef,
1494 mcr_Release,
1495 mcr_GetActionInfo,
1496 };
1497
1498 HRESULT create_msi_custom_remote( IUnknown *pOuter, LPVOID *ppObj )
1499 {
1500 msi_custom_remote_impl* This;
1501
1502 This = msi_alloc( sizeof *This );
1503 if (!This)
1504 return E_OUTOFMEMORY;
1505
1506 This->lpVtbl = &msi_custom_remote_vtbl;
1507 This->refs = 1;
1508
1509 *ppObj = This;
1510
1511 return S_OK;
1512 }