[MSI] Sync with Wine Staging 1.7.37. CORE-9246
[reactos.git] / reactos / dll / win32 / msi / package.c
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
3 *
4 * Copyright 2004 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 "msipriv.h"
22
23 #include <wininet.h>
24
25 WINE_DEFAULT_DEBUG_CHANNEL(msi);
26
27 static void remove_tracked_tempfiles( MSIPACKAGE *package )
28 {
29 struct list *item, *cursor;
30
31 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
32 {
33 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
34
35 list_remove( &temp->entry );
36 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
37 DeleteFileW( temp->Path );
38 msi_free( temp->Path );
39 msi_free( temp );
40 }
41 }
42
43 static void free_feature( MSIFEATURE *feature )
44 {
45 struct list *item, *cursor;
46
47 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
48 {
49 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
50 list_remove( &fl->entry );
51 msi_free( fl );
52 }
53
54 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
55 {
56 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
57 list_remove( &cl->entry );
58 msi_free( cl );
59 }
60 msi_free( feature->Feature );
61 msi_free( feature->Feature_Parent );
62 msi_free( feature->Directory );
63 msi_free( feature->Description );
64 msi_free( feature->Title );
65 msi_free( feature );
66 }
67
68 static void free_folder( MSIFOLDER *folder )
69 {
70 struct list *item, *cursor;
71
72 LIST_FOR_EACH_SAFE( item, cursor, &folder->children )
73 {
74 FolderList *fl = LIST_ENTRY( item, FolderList, entry );
75 list_remove( &fl->entry );
76 msi_free( fl );
77 }
78 msi_free( folder->Parent );
79 msi_free( folder->Directory );
80 msi_free( folder->TargetDefault );
81 msi_free( folder->SourceLongPath );
82 msi_free( folder->SourceShortPath );
83 msi_free( folder->ResolvedTarget );
84 msi_free( folder->ResolvedSource );
85 msi_free( folder );
86 }
87
88 static void free_extension( MSIEXTENSION *ext )
89 {
90 struct list *item, *cursor;
91
92 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
93 {
94 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
95
96 list_remove( &verb->entry );
97 msi_free( verb->Verb );
98 msi_free( verb->Command );
99 msi_free( verb->Argument );
100 msi_free( verb );
101 }
102
103 msi_free( ext->Extension );
104 msi_free( ext->ProgIDText );
105 msi_free( ext );
106 }
107
108 static void free_assembly( MSIASSEMBLY *assembly )
109 {
110 msi_free( assembly->feature );
111 msi_free( assembly->manifest );
112 msi_free( assembly->application );
113 msi_free( assembly->display_name );
114 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
115 msi_free( assembly->tempdir );
116 msi_free( assembly );
117 }
118
119 void msi_free_action_script( MSIPACKAGE *package, UINT script )
120 {
121 UINT i;
122 for (i = 0; i < package->script->ActionCount[script]; i++)
123 msi_free( package->script->Actions[script][i] );
124
125 msi_free( package->script->Actions[script] );
126 package->script->Actions[script] = NULL;
127 package->script->ActionCount[script] = 0;
128 }
129
130 static void free_package_structures( MSIPACKAGE *package )
131 {
132 struct list *item, *cursor;
133
134 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
135 {
136 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
137 list_remove( &feature->entry );
138 free_feature( feature );
139 }
140
141 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
142 {
143 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
144 list_remove( &folder->entry );
145 free_folder( folder );
146 }
147
148 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
149 {
150 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
151
152 list_remove( &comp->entry );
153 msi_free( comp->Component );
154 msi_free( comp->ComponentId );
155 msi_free( comp->Directory );
156 msi_free( comp->Condition );
157 msi_free( comp->KeyPath );
158 msi_free( comp->FullKeypath );
159 if (comp->assembly) free_assembly( comp->assembly );
160 msi_free( comp );
161 }
162
163 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
164 {
165 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
166
167 list_remove( &file->entry );
168 msi_free( file->File );
169 msi_free( file->FileName );
170 msi_free( file->ShortName );
171 msi_free( file->LongName );
172 msi_free( file->Version );
173 msi_free( file->Language );
174 msi_free( file->TargetPath );
175 msi_free( file );
176 }
177
178 /* clean up extension, progid, class and verb structures */
179 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
180 {
181 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
182
183 list_remove( &cls->entry );
184 msi_free( cls->clsid );
185 msi_free( cls->Context );
186 msi_free( cls->Description );
187 msi_free( cls->FileTypeMask );
188 msi_free( cls->IconPath );
189 msi_free( cls->DefInprocHandler );
190 msi_free( cls->DefInprocHandler32 );
191 msi_free( cls->Argument );
192 msi_free( cls->ProgIDText );
193 msi_free( cls );
194 }
195
196 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
197 {
198 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
199
200 list_remove( &ext->entry );
201 free_extension( ext );
202 }
203
204 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
205 {
206 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
207
208 list_remove( &progid->entry );
209 msi_free( progid->ProgID );
210 msi_free( progid->Description );
211 msi_free( progid->IconPath );
212 msi_free( progid );
213 }
214
215 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
216 {
217 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
218
219 list_remove( &mt->entry );
220 msi_free( mt->suffix );
221 msi_free( mt->clsid );
222 msi_free( mt->ContentType );
223 msi_free( mt );
224 }
225
226 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
227 {
228 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
229
230 list_remove( &appid->entry );
231 msi_free( appid->AppID );
232 msi_free( appid->RemoteServerName );
233 msi_free( appid->LocalServer );
234 msi_free( appid->ServiceParameters );
235 msi_free( appid->DllSurrogate );
236 msi_free( appid );
237 }
238
239 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
240 {
241 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
242
243 list_remove( &info->entry );
244 msi_free( info->value );
245 msi_free( info );
246 }
247
248 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
249 {
250 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
251
252 list_remove( &info->entry );
253 msi_free( info->volume_label );
254 msi_free( info->disk_prompt );
255 msi_free( info );
256 }
257
258 if (package->script)
259 {
260 INT i;
261 UINT j;
262
263 for (i = 0; i < SCRIPT_MAX; i++)
264 msi_free_action_script( package, i );
265
266 for (j = 0; j < package->script->UniqueActionsCount; j++)
267 msi_free( package->script->UniqueActions[j] );
268
269 msi_free( package->script->UniqueActions );
270 msi_free( package->script );
271 }
272
273 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
274 {
275 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
276
277 list_remove( &binary->entry );
278 if (binary->module)
279 FreeLibrary( binary->module );
280 if (!DeleteFileW( binary->tmpfile ))
281 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
282 msi_free( binary->source );
283 msi_free( binary->tmpfile );
284 msi_free( binary );
285 }
286
287 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
288 {
289 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
290
291 list_remove( &cab->entry );
292 IStorage_Release( cab->storage );
293 msi_free( cab->stream );
294 msi_free( cab );
295 }
296
297 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
298 {
299 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
300
301 list_remove( &patch->entry );
302 if (patch->delete_on_close && !DeleteFileW( patch->localfile ))
303 {
304 ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError());
305 }
306 msi_free_patchinfo( patch );
307 }
308
309 msi_free( package->BaseURL );
310 msi_free( package->PackagePath );
311 msi_free( package->ProductCode );
312 msi_free( package->ActionFormat );
313 msi_free( package->LastAction );
314 msi_free( package->langids );
315
316 remove_tracked_tempfiles(package);
317
318 /* cleanup control event subscriptions */
319 msi_event_cleanup_all_subscriptions( package );
320 }
321
322 static void MSI_FreePackage( MSIOBJECTHDR *arg)
323 {
324 MSIPACKAGE *package = (MSIPACKAGE *)arg;
325
326 msi_destroy_assembly_caches( package );
327
328 if( package->dialog )
329 msi_dialog_destroy( package->dialog );
330
331 msiobj_release( &package->db->hdr );
332 free_package_structures(package);
333 CloseHandle( package->log_file );
334
335 if (package->delete_on_close) DeleteFileW( package->localfile );
336 msi_free( package->localfile );
337 }
338
339 static UINT create_temp_property_table(MSIPACKAGE *package)
340 {
341 static const WCHAR query[] = {
342 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
343 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
344 '`','_','P','r','o','p','e','r','t','y','`',' ',
345 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
346 'T','E','M','P','O','R','A','R','Y',',',' ',
347 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
348 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
349 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
350 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
351 MSIQUERY *view;
352 UINT rc;
353
354 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
355 if (rc != ERROR_SUCCESS)
356 return rc;
357
358 rc = MSI_ViewExecute(view, 0);
359 MSI_ViewClose(view);
360 msiobj_release(&view->hdr);
361 return rc;
362 }
363
364 UINT msi_clone_properties( MSIDATABASE *db )
365 {
366 static const WCHAR query_select[] = {
367 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
368 '`','P','r','o','p','e','r','t','y','`',0};
369 static const WCHAR query_insert[] = {
370 'I','N','S','E','R','T',' ','I','N','T','O',' ',
371 '`','_','P','r','o','p','e','r','t','y','`',' ',
372 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
373 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
374 static const WCHAR query_update[] = {
375 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
376 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
377 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
378 MSIQUERY *view_select;
379 UINT rc;
380
381 rc = MSI_DatabaseOpenViewW( db, query_select, &view_select );
382 if (rc != ERROR_SUCCESS)
383 return rc;
384
385 rc = MSI_ViewExecute( view_select, 0 );
386 if (rc != ERROR_SUCCESS)
387 {
388 MSI_ViewClose( view_select );
389 msiobj_release( &view_select->hdr );
390 return rc;
391 }
392
393 while (1)
394 {
395 MSIQUERY *view_insert, *view_update;
396 MSIRECORD *rec_select;
397
398 rc = MSI_ViewFetch( view_select, &rec_select );
399 if (rc != ERROR_SUCCESS)
400 break;
401
402 rc = MSI_DatabaseOpenViewW( db, query_insert, &view_insert );
403 if (rc != ERROR_SUCCESS)
404 {
405 msiobj_release( &rec_select->hdr );
406 continue;
407 }
408
409 rc = MSI_ViewExecute( view_insert, rec_select );
410 MSI_ViewClose( view_insert );
411 msiobj_release( &view_insert->hdr );
412 if (rc != ERROR_SUCCESS)
413 {
414 MSIRECORD *rec_update;
415
416 TRACE("insert failed, trying update\n");
417
418 rc = MSI_DatabaseOpenViewW( db, query_update, &view_update );
419 if (rc != ERROR_SUCCESS)
420 {
421 WARN("open view failed %u\n", rc);
422 msiobj_release( &rec_select->hdr );
423 continue;
424 }
425
426 rec_update = MSI_CreateRecord( 2 );
427 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
428 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
429 rc = MSI_ViewExecute( view_update, rec_update );
430 if (rc != ERROR_SUCCESS)
431 WARN("update failed %u\n", rc);
432
433 MSI_ViewClose( view_update );
434 msiobj_release( &view_update->hdr );
435 msiobj_release( &rec_update->hdr );
436 }
437
438 msiobj_release( &rec_select->hdr );
439 }
440
441 MSI_ViewClose( view_select );
442 msiobj_release( &view_select->hdr );
443 return rc;
444 }
445
446 /*
447 * set_installed_prop
448 *
449 * Sets the "Installed" property to indicate that
450 * the product is installed for the current user.
451 */
452 static UINT set_installed_prop( MSIPACKAGE *package )
453 {
454 HKEY hkey;
455 UINT r;
456
457 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
458
459 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
460 if (r == ERROR_SUCCESS)
461 {
462 RegCloseKey( hkey );
463 msi_set_property( package->db, szInstalled, szOne, -1 );
464 }
465 return r;
466 }
467
468 static UINT set_user_sid_prop( MSIPACKAGE *package )
469 {
470 SID_NAME_USE use;
471 LPWSTR user_name;
472 LPWSTR sid_str = NULL, dom = NULL;
473 DWORD size, dom_size;
474 PSID psid = NULL;
475 UINT r = ERROR_FUNCTION_FAILED;
476
477 size = 0;
478 GetUserNameW( NULL, &size );
479
480 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
481 if (!user_name)
482 return ERROR_OUTOFMEMORY;
483
484 if (!GetUserNameW( user_name, &size ))
485 goto done;
486
487 size = 0;
488 dom_size = 0;
489 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
490
491 psid = msi_alloc( size );
492 dom = msi_alloc( dom_size*sizeof (WCHAR) );
493 if (!psid || !dom)
494 {
495 r = ERROR_OUTOFMEMORY;
496 goto done;
497 }
498
499 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
500 goto done;
501
502 if (!ConvertSidToStringSidW( psid, &sid_str ))
503 goto done;
504
505 r = msi_set_property( package->db, szUserSID, sid_str, -1 );
506
507 done:
508 LocalFree( sid_str );
509 msi_free( dom );
510 msi_free( psid );
511 msi_free( user_name );
512
513 return r;
514 }
515
516 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
517 {
518 HKEY netsetup;
519 LONG res;
520 LPWSTR file = NULL;
521 DWORD index = 0, size;
522 WCHAR ver[MAX_PATH];
523 WCHAR name[MAX_PATH];
524 WCHAR windir[MAX_PATH];
525
526 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
527 static const WCHAR sub[] = {
528 'S','o','f','t','w','a','r','e','\\',
529 'M','i','c','r','o','s','o','f','t','\\',
530 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
531 'N','D','P',0
532 };
533 static const WCHAR subdir[] = {
534 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
535 'F','r','a','m','e','w','o','r','k','\\',0
536 };
537
538 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
539 if (res != ERROR_SUCCESS)
540 return NULL;
541
542 GetWindowsDirectoryW(windir, MAX_PATH);
543
544 ver[0] = '\0';
545 size = MAX_PATH;
546 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
547 {
548 index++;
549
550 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
551 if (strcmpW( ver, name ) < 0)
552 {
553 LPWSTR check;
554 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
555 check = msi_alloc(size * sizeof(WCHAR));
556
557 if (!check)
558 {
559 msi_free(file);
560 return NULL;
561 }
562
563 lstrcpyW(check, windir);
564 lstrcatW(check, szBackSlash);
565 lstrcatW(check, subdir);
566 lstrcatW(check, name);
567 lstrcatW(check, szBackSlash);
568 lstrcatW(check, fusion);
569
570 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
571 {
572 msi_free(file);
573 file = check;
574 lstrcpyW(ver, name);
575 }
576 else
577 msi_free(check);
578 }
579 }
580
581 RegCloseKey(netsetup);
582 return file;
583 }
584
585 typedef struct tagLANGANDCODEPAGE
586 {
587 WORD wLanguage;
588 WORD wCodePage;
589 } LANGANDCODEPAGE;
590
591 static void set_msi_assembly_prop(MSIPACKAGE *package)
592 {
593 UINT val_len;
594 DWORD size, handle;
595 LPVOID version = NULL;
596 WCHAR buf[MAX_PATH];
597 LPWSTR fusion, verstr;
598 LANGANDCODEPAGE *translate;
599
600 static const WCHAR netasm[] = {
601 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
602 };
603 static const WCHAR translation[] = {
604 '\\','V','a','r','F','i','l','e','I','n','f','o',
605 '\\','T','r','a','n','s','l','a','t','i','o','n',0
606 };
607 static const WCHAR verfmt[] = {
608 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
609 '\\','%','0','4','x','%','0','4','x',
610 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
611 };
612
613 fusion = get_fusion_filename(package);
614 if (!fusion)
615 return;
616
617 size = GetFileVersionInfoSizeW(fusion, &handle);
618 if (!size)
619 goto done;
620
621 version = msi_alloc(size);
622 if (!version)
623 goto done;
624
625 if (!GetFileVersionInfoW(fusion, handle, size, version))
626 goto done;
627
628 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
629 goto done;
630
631 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
632
633 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
634 goto done;
635
636 if (!val_len || !verstr)
637 goto done;
638
639 msi_set_property( package->db, netasm, verstr, -1 );
640
641 done:
642 msi_free(fusion);
643 msi_free(version);
644 }
645
646 static VOID set_installer_properties(MSIPACKAGE *package)
647 {
648 WCHAR *ptr;
649 OSVERSIONINFOEXW OSVersion;
650 MEMORYSTATUSEX msex;
651 DWORD verval, len;
652 WCHAR pth[MAX_PATH], verstr[11], bufstr[22];
653 HDC dc;
654 HKEY hkey;
655 LPWSTR username, companyname;
656 SYSTEM_INFO sys_info;
657 SYSTEMTIME systemtime;
658 LANGID langid;
659
660 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
661 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
662 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
663 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
664 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
665 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
666 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
667 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
668 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
669 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
670 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
671 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
672 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
673 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
674 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
675 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
676 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
677 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
678 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
679 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
680 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
681 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
682 static const WCHAR szFormat[] = {'%','u',0};
683 static const WCHAR szFormat2[] = {'%','u','.','%','u',0};
684 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
685 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
686 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
687 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
688 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
689 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
690 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
691 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
692 static const WCHAR szIntFormat[] = {'%','d',0};
693 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
694 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
695 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
696 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
697 static const WCHAR szProgramFiles64Folder[] = { 'P','r','o','g','r','a','m','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
698 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
699 static const WCHAR szUserInfo[] = {
700 'S','O','F','T','W','A','R','E','\\',
701 'M','i','c','r','o','s','o','f','t','\\',
702 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
703 'U','s','e','r',' ','I','n','f','o',0
704 };
705 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
706 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
707 static const WCHAR szCurrentVersion[] = {
708 'S','O','F','T','W','A','R','E','\\',
709 'M','i','c','r','o','s','o','f','t','\\',
710 'W','i','n','d','o','w','s',' ','N','T','\\',
711 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
712 };
713 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
714 static const WCHAR szRegisteredOrganization[] = {
715 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
716 };
717 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
718 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
719 static const WCHAR szDate[] = {'D','a','t','e',0};
720 static const WCHAR szTime[] = {'T','i','m','e',0};
721 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
722 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
723 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
724 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
725 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
726 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
727 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
728 static const WCHAR szComputerName[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
729 static const WCHAR szBrowseProperty[] = {'_','B','r','o','w','s','e','P','r','o','p','e','r','t','y',0};
730 static const WCHAR szInstallDir[] = {'I','N','S','T','A','L','L','D','I','R',0};
731
732 /*
733 * Other things that probably should be set:
734 *
735 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
736 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
737 */
738
739 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
740 strcatW(pth, szBackSlash);
741 msi_set_property( package->db, szCommonAppDataFolder, pth, -1 );
742
743 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
744 strcatW(pth, szBackSlash);
745 msi_set_property( package->db, szFavoritesFolder, pth, -1 );
746
747 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
748 strcatW(pth, szBackSlash);
749 msi_set_property( package->db, szFontsFolder, pth, -1 );
750
751 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
752 strcatW(pth, szBackSlash);
753 msi_set_property( package->db, szSendToFolder, pth, -1 );
754
755 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
756 strcatW(pth, szBackSlash);
757 msi_set_property( package->db, szStartMenuFolder, pth, -1 );
758
759 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
760 strcatW(pth, szBackSlash);
761 msi_set_property( package->db, szStartupFolder, pth, -1 );
762
763 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
764 strcatW(pth, szBackSlash);
765 msi_set_property( package->db, szTemplateFolder, pth, -1 );
766
767 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
768 strcatW(pth, szBackSlash);
769 msi_set_property( package->db, szDesktopFolder, pth, -1 );
770
771 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
772 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
773 strcatW(pth, szBackSlash);
774 msi_set_property( package->db, szProgramMenuFolder, pth, -1 );
775
776 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
777 strcatW(pth, szBackSlash);
778 msi_set_property( package->db, szAdminToolsFolder, pth, -1 );
779
780 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
781 strcatW(pth, szBackSlash);
782 msi_set_property( package->db, szAppDataFolder, pth, -1 );
783
784 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
785 strcatW(pth, szBackSlash);
786 msi_set_property( package->db, szSystemFolder, pth, -1 );
787 msi_set_property( package->db, szSystem16Folder, pth, -1 );
788
789 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
790 strcatW(pth, szBackSlash);
791 msi_set_property( package->db, szLocalAppDataFolder, pth, -1 );
792
793 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
794 strcatW(pth, szBackSlash);
795 msi_set_property( package->db, szMyPicturesFolder, pth, -1 );
796
797 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
798 strcatW(pth, szBackSlash);
799 msi_set_property( package->db, szPersonalFolder, pth, -1 );
800
801 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
802 strcatW(pth, szBackSlash);
803 msi_set_property( package->db, szWindowsFolder, pth, -1 );
804
805 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
806 strcatW(pth, szBackSlash);
807 msi_set_property( package->db, szPrintHoodFolder, pth, -1 );
808
809 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
810 strcatW(pth, szBackSlash);
811 msi_set_property( package->db, szNetHoodFolder, pth, -1 );
812
813 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
814 strcatW(pth, szBackSlash);
815 msi_set_property( package->db, szRecentFolder, pth, -1 );
816
817 /* Physical Memory is specified in MB. Using total amount. */
818 msex.dwLength = sizeof(msex);
819 GlobalMemoryStatusEx( &msex );
820 len = sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
821 msi_set_property( package->db, szPhysicalMemory, bufstr, len );
822
823 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
824 ptr = strchrW(pth,'\\');
825 if (ptr) *(ptr + 1) = 0;
826 msi_set_property( package->db, szWindowsVolume, pth, -1 );
827
828 len = GetTempPathW(MAX_PATH, pth);
829 msi_set_property( package->db, szTempFolder, pth, len );
830
831 /* in a wine environment the user is always admin and privileged */
832 msi_set_property( package->db, szAdminUser, szOne, -1 );
833 msi_set_property( package->db, szPrivileged, szOne, -1 );
834
835 /* set the os things */
836 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
837 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
838 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
839 len = sprintfW( verstr, szFormat, verval );
840 switch (OSVersion.dwPlatformId)
841 {
842 case VER_PLATFORM_WIN32_WINDOWS:
843 msi_set_property( package->db, szVersion9x, verstr, len );
844 break;
845 case VER_PLATFORM_WIN32_NT:
846 msi_set_property( package->db, szVersionNT, verstr, len );
847 len = sprintfW( bufstr, szFormat,OSVersion.wProductType );
848 msi_set_property( package->db, szMsiNTProductType, bufstr, len );
849 break;
850 }
851 len = sprintfW( bufstr, szFormat, OSVersion.dwBuildNumber );
852 msi_set_property( package->db, szWindowsBuild, bufstr, len );
853 len = sprintfW( bufstr, szFormat, OSVersion.wServicePackMajor );
854 msi_set_property( package->db, szServicePackLevel, bufstr, len );
855
856 len = sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION );
857 msi_set_property( package->db, szVersionMsi, bufstr, len );
858 len = sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100 );
859 msi_set_property( package->db, szVersionDatabase, bufstr, len );
860
861 GetNativeSystemInfo( &sys_info );
862 len = sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
863 msi_set_property( package->db, szIntel, bufstr, len );
864 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
865 {
866 GetSystemDirectoryW( pth, MAX_PATH );
867 PathAddBackslashW( pth );
868 msi_set_property( package->db, szSystemFolder, pth, -1 );
869
870 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
871 PathAddBackslashW( pth );
872 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
873
874 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
875 PathAddBackslashW( pth );
876 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
877 }
878 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
879 {
880 msi_set_property( package->db, szMsiAMD64, bufstr, -1 );
881 msi_set_property( package->db, szMsix64, bufstr, -1 );
882 msi_set_property( package->db, szVersionNT64, verstr, -1 );
883
884 GetSystemDirectoryW( pth, MAX_PATH );
885 PathAddBackslashW( pth );
886 msi_set_property( package->db, szSystem64Folder, pth, -1 );
887
888 GetSystemWow64DirectoryW( pth, MAX_PATH );
889 PathAddBackslashW( pth );
890 msi_set_property( package->db, szSystemFolder, pth, -1 );
891
892 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
893 PathAddBackslashW( pth );
894 msi_set_property( package->db, szProgramFiles64Folder, pth, -1 );
895
896 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
897 PathAddBackslashW( pth );
898 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
899
900 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
901 PathAddBackslashW( pth );
902 msi_set_property( package->db, szCommonFiles64Folder, pth, -1 );
903
904 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
905 PathAddBackslashW( pth );
906 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
907 }
908
909 /* Screen properties. */
910 dc = GetDC(0);
911 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, HORZRES) );
912 msi_set_property( package->db, szScreenX, bufstr, len );
913 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, VERTRES) );
914 msi_set_property( package->db, szScreenY, bufstr, len );
915 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, BITSPIXEL) );
916 msi_set_property( package->db, szColorBits, bufstr, len );
917 ReleaseDC(0, dc);
918
919 /* USERNAME and COMPANYNAME */
920 username = msi_dup_property( package->db, szUSERNAME );
921 companyname = msi_dup_property( package->db, szCOMPANYNAME );
922
923 if ((!username || !companyname) &&
924 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
925 {
926 if (!username &&
927 (username = msi_reg_get_val_str( hkey, szDefName )))
928 msi_set_property( package->db, szUSERNAME, username, -1 );
929 if (!companyname &&
930 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
931 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
932 CloseHandle( hkey );
933 }
934 if ((!username || !companyname) &&
935 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
936 {
937 if (!username &&
938 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
939 msi_set_property( package->db, szUSERNAME, username, -1 );
940 if (!companyname &&
941 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
942 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
943 CloseHandle( hkey );
944 }
945 msi_free( username );
946 msi_free( companyname );
947
948 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
949 ERR("Failed to set the UserSID property\n");
950
951 /* Date and time properties */
952 GetSystemTime( &systemtime );
953 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
954 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
955 msi_set_property( package->db, szDate, bufstr, -1 );
956 else
957 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
958
959 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
960 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
961 &systemtime, NULL, bufstr,
962 sizeof(bufstr)/sizeof(bufstr[0]) ))
963 msi_set_property( package->db, szTime, bufstr, -1 );
964 else
965 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
966
967 set_msi_assembly_prop( package );
968
969 langid = GetUserDefaultLangID();
970 len = sprintfW( bufstr, szIntFormat, langid );
971 msi_set_property( package->db, szUserLanguageID, bufstr, len );
972
973 langid = GetSystemDefaultLangID();
974 len = sprintfW( bufstr, szIntFormat, langid );
975 msi_set_property( package->db, szSystemLangID, bufstr, len );
976
977 len = sprintfW( bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode) );
978 msi_set_property( package->db, szProductState, bufstr, len );
979
980 len = 0;
981 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
982 {
983 WCHAR *username;
984 if ((username = msi_alloc( len * sizeof(WCHAR) )))
985 {
986 if (GetUserNameW( username, &len ))
987 msi_set_property( package->db, szLogonUser, username, len - 1 );
988 msi_free( username );
989 }
990 }
991 len = 0;
992 if (!GetComputerNameW( NULL, &len ) && GetLastError() == ERROR_BUFFER_OVERFLOW)
993 {
994 WCHAR *computername;
995 if ((computername = msi_alloc( len * sizeof(WCHAR) )))
996 {
997 if (GetComputerNameW( computername, &len ))
998 msi_set_property( package->db, szComputerName, computername, len );
999 msi_free( computername );
1000 }
1001 }
1002 msi_set_property( package->db, szBrowseProperty, szInstallDir, -1 );
1003 }
1004
1005 static UINT msi_load_summary_properties( MSIPACKAGE *package )
1006 {
1007 UINT rc;
1008 MSIHANDLE suminfo;
1009 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
1010 INT count;
1011 DWORD len;
1012 LPWSTR package_code;
1013 static const WCHAR szPackageCode[] = {
1014 'P','a','c','k','a','g','e','C','o','d','e',0};
1015
1016 if (!hdb) {
1017 ERR("Unable to allocate handle\n");
1018 return ERROR_OUTOFMEMORY;
1019 }
1020
1021 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1022 MsiCloseHandle(hdb);
1023 if (rc != ERROR_SUCCESS)
1024 {
1025 ERR("Unable to open Summary Information\n");
1026 return rc;
1027 }
1028
1029 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1030 &count, NULL, NULL, NULL );
1031 if (rc != ERROR_SUCCESS)
1032 {
1033 WARN("Unable to query page count: %d\n", rc);
1034 goto done;
1035 }
1036
1037 /* load package code property */
1038 len = 0;
1039 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1040 NULL, NULL, NULL, &len );
1041 if (rc != ERROR_MORE_DATA)
1042 {
1043 WARN("Unable to query revision number: %d\n", rc);
1044 rc = ERROR_FUNCTION_FAILED;
1045 goto done;
1046 }
1047
1048 len++;
1049 package_code = msi_alloc( len * sizeof(WCHAR) );
1050 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1051 NULL, NULL, package_code, &len );
1052 if (rc != ERROR_SUCCESS)
1053 {
1054 WARN("Unable to query rev number: %d\n", rc);
1055 msi_free( package_code );
1056 goto done;
1057 }
1058
1059 msi_set_property( package->db, szPackageCode, package_code, len );
1060 msi_free( package_code );
1061
1062 /* load package attributes */
1063 count = 0;
1064 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1065 &count, NULL, NULL, NULL );
1066 package->WordCount = count;
1067
1068 done:
1069 MsiCloseHandle(suminfo);
1070 return rc;
1071 }
1072
1073 static MSIPACKAGE *msi_alloc_package( void )
1074 {
1075 MSIPACKAGE *package;
1076
1077 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1078 MSI_FreePackage );
1079 if( package )
1080 {
1081 list_init( &package->components );
1082 list_init( &package->features );
1083 list_init( &package->files );
1084 list_init( &package->filepatches );
1085 list_init( &package->tempfiles );
1086 list_init( &package->folders );
1087 list_init( &package->subscriptions );
1088 list_init( &package->appids );
1089 list_init( &package->classes );
1090 list_init( &package->mimes );
1091 list_init( &package->extensions );
1092 list_init( &package->progids );
1093 list_init( &package->RunningActions );
1094 list_init( &package->sourcelist_info );
1095 list_init( &package->sourcelist_media );
1096 list_init( &package->patches );
1097 list_init( &package->binaries );
1098 list_init( &package->cabinet_streams );
1099 }
1100
1101 return package;
1102 }
1103
1104 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1105 {
1106 BYTE *data;
1107 UINT r, sz;
1108
1109 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1110
1111 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1112 if (r != ERROR_SUCCESS)
1113 return r;
1114
1115 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1116
1117 msi_free(data);
1118 return r;
1119 }
1120
1121 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1122 {
1123 /* FIXME: this should depend on the user's privileges */
1124 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1125 {
1126 TRACE("resetting ALLUSERS property from 2 to 1\n");
1127 msi_set_property( package->db, szAllUsers, szOne, -1 );
1128 }
1129 msi_set_property( package->db, szAdminUser, szOne, -1 );
1130 }
1131
1132 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1133 {
1134 static const WCHAR fmtW[] = {'%','u',0};
1135 MSIPACKAGE *package;
1136 WCHAR uilevel[11];
1137 int len;
1138 UINT r;
1139
1140 TRACE("%p\n", db);
1141
1142 package = msi_alloc_package();
1143 if (package)
1144 {
1145 msiobj_addref( &db->hdr );
1146 package->db = db;
1147
1148 package->WordCount = 0;
1149 package->PackagePath = strdupW( db->path );
1150 package->BaseURL = strdupW( base_url );
1151
1152 create_temp_property_table( package );
1153 msi_clone_properties( package->db );
1154 msi_adjust_privilege_properties( package );
1155
1156 package->ProductCode = msi_dup_property( package->db, szProductCode );
1157 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1158
1159 set_installer_properties( package );
1160
1161 package->ui_level = gUILevel;
1162 len = sprintfW( uilevel, fmtW, gUILevel & INSTALLUILEVEL_MASK );
1163 msi_set_property( package->db, szUILevel, uilevel, len );
1164
1165 r = msi_load_summary_properties( package );
1166 if (r != ERROR_SUCCESS)
1167 {
1168 msiobj_release( &package->hdr );
1169 return NULL;
1170 }
1171
1172 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1173 msi_load_admin_properties( package );
1174
1175 package->log_file = INVALID_HANDLE_VALUE;
1176 }
1177 return package;
1178 }
1179
1180 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1181 {
1182 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1183 DWORD size = 0;
1184 HRESULT hr;
1185
1186 /* call will always fail, because size is 0,
1187 * but will return ERROR_FILE_NOT_FOUND first
1188 * if the file doesn't exist
1189 */
1190 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1191 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1192 {
1193 cache_entry = msi_alloc( size );
1194 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1195 {
1196 UINT error = GetLastError();
1197 msi_free( cache_entry );
1198 return error;
1199 }
1200
1201 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1202 msi_free( cache_entry );
1203 return ERROR_SUCCESS;
1204 }
1205
1206 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1207 if ( FAILED(hr) )
1208 {
1209 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1210 return ERROR_FUNCTION_FAILED;
1211 }
1212
1213 return ERROR_SUCCESS;
1214 }
1215
1216 UINT msi_create_empty_local_file( LPWSTR path, LPCWSTR suffix )
1217 {
1218 static const WCHAR szInstaller[] = {
1219 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1220 static const WCHAR fmt[] = {'%','x',0};
1221 DWORD time, len, i, offset;
1222 HANDLE handle;
1223
1224 time = GetTickCount();
1225 GetWindowsDirectoryW( path, MAX_PATH );
1226 strcatW( path, szInstaller );
1227 CreateDirectoryW( path, NULL );
1228
1229 len = strlenW(path);
1230 for (i = 0; i < 0x10000; i++)
1231 {
1232 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1233 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1234 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1235 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1236 if (handle != INVALID_HANDLE_VALUE)
1237 {
1238 CloseHandle(handle);
1239 break;
1240 }
1241 if (GetLastError() != ERROR_FILE_EXISTS &&
1242 GetLastError() != ERROR_SHARING_VIOLATION)
1243 return ERROR_FUNCTION_FAILED;
1244 }
1245
1246 return ERROR_SUCCESS;
1247 }
1248
1249 enum platform parse_platform( const WCHAR *str )
1250 {
1251 if (!str[0] || !strcmpW( str, szIntel )) return PLATFORM_INTEL;
1252 else if (!strcmpW( str, szIntel64 )) return PLATFORM_INTEL64;
1253 else if (!strcmpW( str, szX64 ) || !strcmpW( str, szAMD64 )) return PLATFORM_X64;
1254 else if (!strcmpW( str, szARM )) return PLATFORM_ARM;
1255 return PLATFORM_UNKNOWN;
1256 }
1257
1258 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1259 {
1260 WCHAR *template, *p, *q, *platform;
1261 DWORD i, count;
1262
1263 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1264 TRACE("version: %d\n", package->version);
1265
1266 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1267 if (!template)
1268 return ERROR_SUCCESS; /* native accepts missing template property */
1269
1270 TRACE("template: %s\n", debugstr_w(template));
1271
1272 p = strchrW( template, ';' );
1273 if (!p)
1274 {
1275 WARN("invalid template string %s\n", debugstr_w(template));
1276 msi_free( template );
1277 return ERROR_PATCH_PACKAGE_INVALID;
1278 }
1279 *p = 0;
1280 platform = template;
1281 if ((q = strchrW( platform, ',' ))) *q = 0;
1282 package->platform = parse_platform( platform );
1283 while (package->platform == PLATFORM_UNKNOWN && q)
1284 {
1285 platform = q + 1;
1286 if ((q = strchrW( platform, ',' ))) *q = 0;
1287 package->platform = parse_platform( platform );
1288 }
1289 if (package->platform == PLATFORM_UNKNOWN)
1290 {
1291 WARN("unknown platform %s\n", debugstr_w(template));
1292 msi_free( template );
1293 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1294 }
1295 p++;
1296 if (!*p)
1297 {
1298 msi_free( template );
1299 return ERROR_SUCCESS;
1300 }
1301 count = 1;
1302 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1303
1304 package->langids = msi_alloc( count * sizeof(LANGID) );
1305 if (!package->langids)
1306 {
1307 msi_free( template );
1308 return ERROR_OUTOFMEMORY;
1309 }
1310
1311 i = 0;
1312 while (*p)
1313 {
1314 q = strchrW( p, ',' );
1315 if (q) *q = 0;
1316 package->langids[i] = atoiW( p );
1317 if (!q) break;
1318 p = q + 1;
1319 i++;
1320 }
1321 package->num_langids = i + 1;
1322
1323 msi_free( template );
1324 return ERROR_SUCCESS;
1325 }
1326
1327 static UINT validate_package( MSIPACKAGE *package )
1328 {
1329 UINT i;
1330
1331 if (package->platform == PLATFORM_INTEL64)
1332 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1333 #ifndef __arm__
1334 if (package->platform == PLATFORM_ARM)
1335 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1336 #endif
1337 if (package->platform == PLATFORM_X64)
1338 {
1339 if (!is_64bit && !is_wow64)
1340 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1341 if (package->version < 200)
1342 return ERROR_INSTALL_PACKAGE_INVALID;
1343 }
1344 if (!package->num_langids)
1345 {
1346 return ERROR_SUCCESS;
1347 }
1348 for (i = 0; i < package->num_langids; i++)
1349 {
1350 LANGID langid = package->langids[i];
1351
1352 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1353 {
1354 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1355 }
1356 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1357 {
1358 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1359 }
1360 if (IsValidLocale( langid, LCID_INSTALLED ))
1361 return ERROR_SUCCESS;
1362 }
1363 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1364 }
1365
1366 int msi_track_tempfile( MSIPACKAGE *package, const WCHAR *path )
1367 {
1368 MSITEMPFILE *temp;
1369
1370 TRACE("%s\n", debugstr_w(path));
1371
1372 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
1373 {
1374 if (!strcmpW( path, temp->Path )) return 0;
1375 }
1376 if (!(temp = msi_alloc_zero( sizeof (MSITEMPFILE) ))) return -1;
1377 list_add_head( &package->tempfiles, &temp->entry );
1378 temp->Path = strdupW( path );
1379 return 0;
1380 }
1381
1382 static WCHAR *get_product_code( MSIDATABASE *db )
1383 {
1384 static const WCHAR query[] = {
1385 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1386 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1387 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1388 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1389 MSIQUERY *view;
1390 MSIRECORD *rec;
1391 WCHAR *ret = NULL;
1392
1393 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1394 {
1395 return NULL;
1396 }
1397 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1398 {
1399 MSI_ViewClose( view );
1400 msiobj_release( &view->hdr );
1401 return NULL;
1402 }
1403 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1404 {
1405 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1406 msiobj_release( &rec->hdr );
1407 }
1408 MSI_ViewClose( view );
1409 msiobj_release( &view->hdr );
1410 return ret;
1411 }
1412
1413 static UINT get_registered_local_package( const WCHAR *product, const WCHAR *package, WCHAR *localfile )
1414 {
1415 MSIINSTALLCONTEXT context;
1416 HKEY product_key, props_key;
1417 WCHAR *registered_package = NULL, unsquashed[GUID_SIZE];
1418 UINT r;
1419
1420 r = msi_locate_product( product, &context );
1421 if (r != ERROR_SUCCESS)
1422 return r;
1423
1424 r = MSIREG_OpenProductKey( product, NULL, context, &product_key, FALSE );
1425 if (r != ERROR_SUCCESS)
1426 return r;
1427
1428 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1429 if (r != ERROR_SUCCESS)
1430 {
1431 RegCloseKey( product_key );
1432 return r;
1433 }
1434 r = ERROR_FUNCTION_FAILED;
1435 registered_package = msi_reg_get_val_str( product_key, INSTALLPROPERTY_PACKAGECODEW );
1436 if (!registered_package)
1437 goto done;
1438
1439 unsquash_guid( registered_package, unsquashed );
1440 if (!strcmpiW( package, unsquashed ))
1441 {
1442 WCHAR *filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1443 if (!filename)
1444 goto done;
1445
1446 strcpyW( localfile, filename );
1447 msi_free( filename );
1448 r = ERROR_SUCCESS;
1449 }
1450 done:
1451 msi_free( registered_package );
1452 RegCloseKey( props_key );
1453 RegCloseKey( product_key );
1454 return r;
1455 }
1456
1457 static WCHAR *get_package_code( MSIDATABASE *db )
1458 {
1459 WCHAR *ret;
1460 MSISUMMARYINFO *si;
1461
1462 if (!(si = MSI_GetSummaryInformationW( db->storage, 0 )))
1463 {
1464 WARN("failed to load summary info\n");
1465 return NULL;
1466 }
1467 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1468 msiobj_release( &si->hdr );
1469 return ret;
1470 }
1471
1472 static UINT get_local_package( const WCHAR *filename, WCHAR *localfile )
1473 {
1474 WCHAR *product_code, *package_code;
1475 MSIDATABASE *db;
1476 UINT r;
1477
1478 if ((r = MSI_OpenDatabaseW( filename, MSIDBOPEN_READONLY, &db )) != ERROR_SUCCESS)
1479 {
1480 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1481 return ERROR_FILE_NOT_FOUND;
1482 return r;
1483 }
1484 if (!(product_code = get_product_code( db )))
1485 {
1486 msiobj_release( &db->hdr );
1487 return ERROR_INSTALL_PACKAGE_INVALID;
1488 }
1489 if (!(package_code = get_package_code( db )))
1490 {
1491 msi_free( product_code );
1492 msiobj_release( &db->hdr );
1493 return ERROR_INSTALL_PACKAGE_INVALID;
1494 }
1495 r = get_registered_local_package( product_code, package_code, localfile );
1496 msi_free( package_code );
1497 msi_free( product_code );
1498 msiobj_release( &db->hdr );
1499 return r;
1500 }
1501
1502 UINT msi_set_original_database_property( MSIDATABASE *db, const WCHAR *package )
1503 {
1504 UINT r;
1505
1506 if (UrlIsW( package, URLIS_URL ))
1507 r = msi_set_property( db, szOriginalDatabase, package, -1 );
1508 else if (package[0] == '#')
1509 r = msi_set_property( db, szOriginalDatabase, db->path, -1 );
1510 else
1511 {
1512 DWORD len;
1513 WCHAR *path;
1514
1515 if (!(len = GetFullPathNameW( package, 0, NULL, NULL ))) return GetLastError();
1516 if (!(path = msi_alloc( len * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
1517 len = GetFullPathNameW( package, len, path, NULL );
1518 r = msi_set_property( db, szOriginalDatabase, path, len );
1519 msi_free( path );
1520 }
1521 return r;
1522 }
1523
1524 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1525 {
1526 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1527 MSIDATABASE *db;
1528 MSIPACKAGE *package;
1529 MSIHANDLE handle;
1530 LPWSTR ptr, base_url = NULL;
1531 UINT r;
1532 WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
1533 LPCWSTR file = szPackage;
1534 DWORD index = 0;
1535 MSISUMMARYINFO *si;
1536 BOOL delete_on_close = FALSE;
1537
1538 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1539
1540 localfile[0] = 0;
1541 if( szPackage[0] == '#' )
1542 {
1543 handle = atoiW(&szPackage[1]);
1544 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1545 if( !db )
1546 {
1547 IWineMsiRemoteDatabase *remote_database;
1548
1549 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1550 if ( !remote_database )
1551 return ERROR_INVALID_HANDLE;
1552
1553 IWineMsiRemoteDatabase_Release( remote_database );
1554 WARN("MsiOpenPackage not allowed during a custom action!\n");
1555
1556 return ERROR_FUNCTION_FAILED;
1557 }
1558 }
1559 else
1560 {
1561 if ( UrlIsW( szPackage, URLIS_URL ) )
1562 {
1563 r = msi_download_file( szPackage, cachefile );
1564 if (r != ERROR_SUCCESS)
1565 return r;
1566
1567 file = cachefile;
1568
1569 base_url = strdupW( szPackage );
1570 if (!base_url)
1571 return ERROR_OUTOFMEMORY;
1572
1573 ptr = strrchrW( base_url, '/' );
1574 if (ptr) *(ptr + 1) = '\0';
1575 }
1576 r = get_local_package( file, localfile );
1577 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1578 {
1579 r = msi_create_empty_local_file( localfile, dotmsi );
1580 if (r != ERROR_SUCCESS)
1581 {
1582 msi_free ( base_url );
1583 return r;
1584 }
1585
1586 if (!CopyFileW( file, localfile, FALSE ))
1587 {
1588 r = GetLastError();
1589 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1590 DeleteFileW( localfile );
1591 msi_free ( base_url );
1592 return r;
1593 }
1594 delete_on_close = TRUE;
1595 }
1596 TRACE("opening package %s\n", debugstr_w( localfile ));
1597 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1598 if (r != ERROR_SUCCESS)
1599 {
1600 msi_free ( base_url );
1601 return r;
1602 }
1603 }
1604 package = MSI_CreatePackage( db, base_url );
1605 msi_free( base_url );
1606 msiobj_release( &db->hdr );
1607 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1608 package->localfile = strdupW( localfile );
1609 package->delete_on_close = delete_on_close;
1610
1611 si = MSI_GetSummaryInformationW( db->storage, 0 );
1612 if (!si)
1613 {
1614 WARN("failed to load summary info\n");
1615 msiobj_release( &package->hdr );
1616 return ERROR_INSTALL_PACKAGE_INVALID;
1617 }
1618 r = msi_parse_summary( si, package );
1619 msiobj_release( &si->hdr );
1620 if (r != ERROR_SUCCESS)
1621 {
1622 WARN("failed to parse summary info %u\n", r);
1623 msiobj_release( &package->hdr );
1624 return r;
1625 }
1626 r = validate_package( package );
1627 if (r != ERROR_SUCCESS)
1628 {
1629 msiobj_release( &package->hdr );
1630 return r;
1631 }
1632 msi_set_property( package->db, szDatabase, db->path, -1 );
1633 set_installed_prop( package );
1634 msi_set_context( package );
1635
1636 while (1)
1637 {
1638 WCHAR patch_code[GUID_SIZE];
1639 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1640 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1641 if (r != ERROR_SUCCESS)
1642 break;
1643
1644 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1645
1646 r = msi_apply_registered_patch( package, patch_code );
1647 if (r != ERROR_SUCCESS)
1648 {
1649 ERR("registered patch failed to apply %u\n", r);
1650 msiobj_release( &package->hdr );
1651 return r;
1652 }
1653 index++;
1654 }
1655 if (index) msi_adjust_privilege_properties( package );
1656
1657 r = msi_set_original_database_property( package->db, szPackage );
1658 if (r != ERROR_SUCCESS)
1659 {
1660 msiobj_release( &package->hdr );
1661 return r;
1662 }
1663 if (gszLogFile)
1664 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1665 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1666 *pPackage = package;
1667 return ERROR_SUCCESS;
1668 }
1669
1670 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1671 {
1672 MSIPACKAGE *package = NULL;
1673 UINT ret;
1674
1675 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1676
1677 if( !szPackage || !phPackage )
1678 return ERROR_INVALID_PARAMETER;
1679
1680 if ( !*szPackage )
1681 {
1682 FIXME("Should create an empty database and package\n");
1683 return ERROR_FUNCTION_FAILED;
1684 }
1685
1686 if( dwOptions )
1687 FIXME("dwOptions %08x not supported\n", dwOptions);
1688
1689 ret = MSI_OpenPackageW( szPackage, &package );
1690 if( ret == ERROR_SUCCESS )
1691 {
1692 *phPackage = alloc_msihandle( &package->hdr );
1693 if (! *phPackage)
1694 ret = ERROR_NOT_ENOUGH_MEMORY;
1695 msiobj_release( &package->hdr );
1696 }
1697
1698 return ret;
1699 }
1700
1701 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1702 {
1703 return MsiOpenPackageExW( szPackage, 0, phPackage );
1704 }
1705
1706 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1707 {
1708 LPWSTR szwPack = NULL;
1709 UINT ret;
1710
1711 if( szPackage )
1712 {
1713 szwPack = strdupAtoW( szPackage );
1714 if( !szwPack )
1715 return ERROR_OUTOFMEMORY;
1716 }
1717
1718 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1719
1720 msi_free( szwPack );
1721
1722 return ret;
1723 }
1724
1725 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1726 {
1727 return MsiOpenPackageExA( szPackage, 0, phPackage );
1728 }
1729
1730 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1731 {
1732 MSIPACKAGE *package;
1733 MSIHANDLE handle = 0;
1734 IUnknown *remote_unk;
1735 IWineMsiRemotePackage *remote_package;
1736
1737 TRACE("(%d)\n",hInstall);
1738
1739 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1740 if( package)
1741 {
1742 handle = alloc_msihandle( &package->db->hdr );
1743 msiobj_release( &package->hdr );
1744 }
1745 else if ((remote_unk = msi_get_remote(hInstall)))
1746 {
1747 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1748 (LPVOID *)&remote_package) == S_OK)
1749 {
1750 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1751 IWineMsiRemotePackage_Release(remote_package);
1752 }
1753 else
1754 {
1755 WARN("remote handle %d is not a package\n", hInstall);
1756 }
1757 IUnknown_Release(remote_unk);
1758 }
1759
1760 return handle;
1761 }
1762
1763 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1764 {
1765 static const WCHAR szActionData[] = {'A','c','t','i','o','n','D','a','t','a',0};
1766 static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1767 static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0};
1768 MSIRECORD *uirow;
1769 LPWSTR deformated, message;
1770 DWORD i, len, total_len, log_type = 0;
1771 INT rc = 0;
1772 char *msg;
1773
1774 TRACE("%x\n", eMessageType);
1775
1776 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_FATALEXIT)
1777 log_type |= INSTALLLOGMODE_FATALEXIT;
1778 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1779 log_type |= INSTALLLOGMODE_ERROR;
1780 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1781 log_type |= INSTALLLOGMODE_WARNING;
1782 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1783 log_type |= INSTALLLOGMODE_USER;
1784 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1785 log_type |= INSTALLLOGMODE_INFO;
1786 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE)
1787 log_type |= INSTALLLOGMODE_RESOLVESOURCE;
1788 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE)
1789 log_type |= INSTALLLOGMODE_OUTOFDISKSPACE;
1790 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1791 log_type |= INSTALLLOGMODE_COMMONDATA;
1792 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1793 log_type |= INSTALLLOGMODE_ACTIONSTART;
1794 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1795 log_type |= INSTALLLOGMODE_ACTIONDATA;
1796 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1797 log_type |= INSTALLLOGMODE_PROGRESS;
1798 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INITIALIZE)
1799 log_type |= INSTALLLOGMODE_INITIALIZE;
1800 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_TERMINATE)
1801 log_type |= INSTALLLOGMODE_TERMINATE;
1802 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_SHOWDIALOG)
1803 log_type |= INSTALLLOGMODE_SHOWDIALOG;
1804
1805 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1806 {
1807 static const WCHAR template_s[]=
1808 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1809 static const WCHAR format[] =
1810 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1811 WCHAR timet[0x100];
1812 LPCWSTR action_text, action;
1813 LPWSTR deformatted = NULL;
1814
1815 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1816
1817 action = MSI_RecordGetString(record, 1);
1818 action_text = MSI_RecordGetString(record, 2);
1819
1820 if (!action || !action_text)
1821 return IDOK;
1822
1823 deformat_string(package, action_text, &deformatted);
1824
1825 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1826 if (deformatted)
1827 len += strlenW(deformatted);
1828 message = msi_alloc(len*sizeof(WCHAR));
1829 sprintfW(message, template_s, timet, action);
1830 if (deformatted)
1831 strcatW(message, deformatted);
1832 msi_free(deformatted);
1833 }
1834 else
1835 {
1836 static const WCHAR format[] = {'%','u',':',' ',0};
1837 UINT count = MSI_RecordGetFieldCount( record );
1838 WCHAR *p;
1839
1840 total_len = 1;
1841 for (i = 1; i <= count; i++)
1842 {
1843 len = 0;
1844 MSI_RecordGetStringW( record, i, NULL, &len );
1845 total_len += len + 13;
1846 }
1847 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1848 if (!p) return ERROR_OUTOFMEMORY;
1849
1850 for (i = 1; i <= count; i++)
1851 {
1852 if (count > 1)
1853 {
1854 len = sprintfW( p, format, i );
1855 total_len -= len;
1856 p += len;
1857 }
1858 len = total_len;
1859 MSI_RecordGetStringW( record, i, p, &len );
1860 total_len -= len;
1861 p += len;
1862 if (count > 1 && total_len)
1863 {
1864 *p++ = ' ';
1865 total_len--;
1866 }
1867 }
1868 p[0] = 0;
1869 }
1870
1871 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1872 gUIFilter, log_type, debugstr_w(message));
1873
1874 /* convert it to ASCII */
1875 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1876 msg = msi_alloc( len );
1877 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1878
1879 if (gUIHandlerW && (gUIFilter & log_type))
1880 {
1881 rc = gUIHandlerW( gUIContext, eMessageType, message );
1882 }
1883 else if (gUIHandlerA && (gUIFilter & log_type))
1884 {
1885 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1886 }
1887 else if (gUIHandlerRecord && (gUIFilter & log_type))
1888 {
1889 MSIHANDLE rec = MsiCreateRecord( 1 );
1890 MsiRecordSetStringW( rec, 0, message );
1891 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1892 MsiCloseHandle( rec );
1893 }
1894
1895 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1896 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1897 {
1898 DWORD written;
1899 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1900 WriteFile( package->log_file, "\n", 1, &written, NULL );
1901 }
1902 msi_free( msg );
1903 msi_free( message );
1904
1905 switch (eMessageType & 0xff000000)
1906 {
1907 case INSTALLMESSAGE_ACTIONDATA:
1908 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1909 uirow = MSI_CreateRecord(1);
1910 MSI_RecordSetStringW(uirow, 1, deformated);
1911 msi_free(deformated);
1912
1913 msi_event_fire( package, szActionData, uirow );
1914 msiobj_release(&uirow->hdr);
1915
1916 if (package->action_progress_increment)
1917 {
1918 uirow = MSI_CreateRecord(2);
1919 MSI_RecordSetInteger(uirow, 1, 2);
1920 MSI_RecordSetInteger(uirow, 2, package->action_progress_increment);
1921 msi_event_fire( package, szSetProgress, uirow );
1922 msiobj_release(&uirow->hdr);
1923 }
1924 break;
1925
1926 case INSTALLMESSAGE_ACTIONSTART:
1927 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1928 uirow = MSI_CreateRecord(1);
1929 MSI_RecordSetStringW(uirow, 1, deformated);
1930 msi_free(deformated);
1931
1932 msi_event_fire( package, szActionText, uirow );
1933
1934 msiobj_release(&uirow->hdr);
1935 break;
1936
1937 case INSTALLMESSAGE_PROGRESS:
1938 msi_event_fire( package, szSetProgress, record );
1939 break;
1940 }
1941
1942 return ERROR_SUCCESS;
1943 }
1944
1945 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1946 MSIHANDLE hRecord)
1947 {
1948 UINT ret = ERROR_INVALID_HANDLE;
1949 MSIPACKAGE *package = NULL;
1950 MSIRECORD *record = NULL;
1951
1952 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1953 if( !package )
1954 {
1955 HRESULT hr;
1956 IWineMsiRemotePackage *remote_package;
1957
1958 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1959 if (!remote_package)
1960 return ERROR_INVALID_HANDLE;
1961
1962 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1963
1964 IWineMsiRemotePackage_Release( remote_package );
1965
1966 if (FAILED(hr))
1967 {
1968 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1969 return HRESULT_CODE(hr);
1970
1971 return ERROR_FUNCTION_FAILED;
1972 }
1973
1974 return ERROR_SUCCESS;
1975 }
1976
1977 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1978 if( !record )
1979 goto out;
1980
1981 ret = MSI_ProcessMessage( package, eMessageType, record );
1982
1983 out:
1984 msiobj_release( &package->hdr );
1985 if( record )
1986 msiobj_release( &record->hdr );
1987
1988 return ret;
1989 }
1990
1991 /* property code */
1992
1993 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1994 {
1995 LPWSTR szwName = NULL, szwValue = NULL;
1996 UINT r = ERROR_OUTOFMEMORY;
1997
1998 szwName = strdupAtoW( szName );
1999 if( szName && !szwName )
2000 goto end;
2001
2002 szwValue = strdupAtoW( szValue );
2003 if( szValue && !szwValue )
2004 goto end;
2005
2006 r = MsiSetPropertyW( hInstall, szwName, szwValue);
2007
2008 end:
2009 msi_free( szwName );
2010 msi_free( szwValue );
2011
2012 return r;
2013 }
2014
2015 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
2016 {
2017 MSIFOLDER *folder;
2018
2019 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
2020 {
2021 if ( source )
2022 {
2023 msi_free( folder->ResolvedSource );
2024 folder->ResolvedSource = NULL;
2025 }
2026 else
2027 {
2028 msi_free( folder->ResolvedTarget );
2029 folder->ResolvedTarget = NULL;
2030 }
2031 }
2032 }
2033
2034 UINT msi_set_property( MSIDATABASE *db, const WCHAR *name, const WCHAR *value, int len )
2035 {
2036 static const WCHAR insert_query[] = {
2037 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2038 '`','_','P','r','o','p','e','r','t','y','`',' ',
2039 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2040 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2041 static const WCHAR update_query[] = {
2042 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2043 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2044 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2045 static const WCHAR delete_query[] = {
2046 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2047 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2048 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2049 MSIQUERY *view;
2050 MSIRECORD *row = NULL;
2051 DWORD sz = 0;
2052 WCHAR query[1024];
2053 UINT rc;
2054
2055 TRACE("%p %s %s %d\n", db, debugstr_w(name), debugstr_wn(value, len), len);
2056
2057 if (!name)
2058 return ERROR_INVALID_PARAMETER;
2059
2060 /* this one is weird... */
2061 if (!name[0])
2062 return value ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2063
2064 if (value && len < 0) len = strlenW( value );
2065
2066 rc = msi_get_property( db, name, 0, &sz );
2067 if (!value || (!*value && !len))
2068 {
2069 sprintfW( query, delete_query, name );
2070 }
2071 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2072 {
2073 sprintfW( query, update_query, name );
2074 row = MSI_CreateRecord(1);
2075 msi_record_set_string( row, 1, value, len );
2076 }
2077 else
2078 {
2079 strcpyW( query, insert_query );
2080 row = MSI_CreateRecord(2);
2081 msi_record_set_string( row, 1, name, -1 );
2082 msi_record_set_string( row, 2, value, len );
2083 }
2084
2085 rc = MSI_DatabaseOpenViewW(db, query, &view);
2086 if (rc == ERROR_SUCCESS)
2087 {
2088 rc = MSI_ViewExecute(view, row);
2089 MSI_ViewClose(view);
2090 msiobj_release(&view->hdr);
2091 }
2092 if (row) msiobj_release(&row->hdr);
2093 return rc;
2094 }
2095
2096 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2097 {
2098 MSIPACKAGE *package;
2099 UINT ret;
2100
2101 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2102 if( !package )
2103 {
2104 HRESULT hr;
2105 BSTR name = NULL, value = NULL;
2106 IWineMsiRemotePackage *remote_package;
2107
2108 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2109 if (!remote_package)
2110 return ERROR_INVALID_HANDLE;
2111
2112 name = SysAllocString( szName );
2113 value = SysAllocString( szValue );
2114 if ((!name && szName) || (!value && szValue))
2115 {
2116 SysFreeString( name );
2117 SysFreeString( value );
2118 IWineMsiRemotePackage_Release( remote_package );
2119 return ERROR_OUTOFMEMORY;
2120 }
2121
2122 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2123
2124 SysFreeString( name );
2125 SysFreeString( value );
2126 IWineMsiRemotePackage_Release( remote_package );
2127
2128 if (FAILED(hr))
2129 {
2130 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2131 return HRESULT_CODE(hr);
2132
2133 return ERROR_FUNCTION_FAILED;
2134 }
2135
2136 return ERROR_SUCCESS;
2137 }
2138
2139 ret = msi_set_property( package->db, szName, szValue, -1 );
2140 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2141 msi_reset_folders( package, TRUE );
2142
2143 msiobj_release( &package->hdr );
2144 return ret;
2145 }
2146
2147 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2148 {
2149 static const WCHAR query[]= {
2150 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2151 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2152 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2153 MSIRECORD *rec, *row = NULL;
2154 MSIQUERY *view;
2155 UINT r;
2156
2157 if (!name || !*name)
2158 return NULL;
2159
2160 rec = MSI_CreateRecord(1);
2161 if (!rec)
2162 return NULL;
2163
2164 MSI_RecordSetStringW(rec, 1, name);
2165
2166 r = MSI_DatabaseOpenViewW(db, query, &view);
2167 if (r == ERROR_SUCCESS)
2168 {
2169 MSI_ViewExecute(view, rec);
2170 MSI_ViewFetch(view, &row);
2171 MSI_ViewClose(view);
2172 msiobj_release(&view->hdr);
2173 }
2174 msiobj_release(&rec->hdr);
2175 return row;
2176 }
2177
2178 /* internal function, not compatible with MsiGetPropertyW */
2179 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2180 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2181 {
2182 MSIRECORD *row;
2183 UINT rc = ERROR_FUNCTION_FAILED;
2184
2185 row = msi_get_property_row( db, szName );
2186
2187 if (*pchValueBuf > 0)
2188 szValueBuf[0] = 0;
2189
2190 if (row)
2191 {
2192 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2193 msiobj_release(&row->hdr);
2194 }
2195
2196 if (rc == ERROR_SUCCESS)
2197 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf, *pchValueBuf),
2198 debugstr_w(szName));
2199 else if (rc == ERROR_MORE_DATA)
2200 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2201 debugstr_w(szName));
2202 else
2203 {
2204 *pchValueBuf = 0;
2205 TRACE("property %s not found\n", debugstr_w(szName));
2206 }
2207
2208 return rc;
2209 }
2210
2211 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2212 {
2213 DWORD sz = 0;
2214 LPWSTR str;
2215 UINT r;
2216
2217 r = msi_get_property(db, prop, NULL, &sz);
2218 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2219 return NULL;
2220
2221 sz++;
2222 str = msi_alloc(sz * sizeof(WCHAR));
2223 r = msi_get_property(db, prop, str, &sz);
2224 if (r != ERROR_SUCCESS)
2225 {
2226 msi_free(str);
2227 str = NULL;
2228 }
2229
2230 return str;
2231 }
2232
2233 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2234 {
2235 LPWSTR str = msi_dup_property( db, prop );
2236 int val = str ? atoiW(str) : def;
2237 msi_free(str);
2238 return val;
2239 }
2240
2241 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2242 awstring *szValueBuf, LPDWORD pchValueBuf )
2243 {
2244 MSIPACKAGE *package;
2245 MSIRECORD *row = NULL;
2246 UINT r = ERROR_FUNCTION_FAILED;
2247 LPCWSTR val = NULL;
2248 DWORD len = 0;
2249
2250 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2251 szValueBuf->str.w, pchValueBuf );
2252
2253 if (!name)
2254 return ERROR_INVALID_PARAMETER;
2255
2256 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2257 if (!package)
2258 {
2259 HRESULT hr;
2260 IWineMsiRemotePackage *remote_package;
2261 LPWSTR value = NULL;
2262 BSTR bname;
2263
2264 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2265 if (!remote_package)
2266 return ERROR_INVALID_HANDLE;
2267
2268 bname = SysAllocString( name );
2269 if (!bname)
2270 {
2271 IWineMsiRemotePackage_Release( remote_package );
2272 return ERROR_OUTOFMEMORY;
2273 }
2274
2275 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2276 if (FAILED(hr))
2277 goto done;
2278
2279 len++;
2280 value = msi_alloc(len * sizeof(WCHAR));
2281 if (!value)
2282 {
2283 r = ERROR_OUTOFMEMORY;
2284 goto done;
2285 }
2286
2287 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, value, &len );
2288 if (FAILED(hr))
2289 goto done;
2290
2291 r = msi_strcpy_to_awstring( value, len, szValueBuf, pchValueBuf );
2292
2293 /* Bug required by Adobe installers */
2294 if (!szValueBuf->unicode && !szValueBuf->str.a)
2295 *pchValueBuf *= sizeof(WCHAR);
2296
2297 done:
2298 IWineMsiRemotePackage_Release(remote_package);
2299 SysFreeString(bname);
2300 msi_free(value);
2301
2302 if (FAILED(hr))
2303 {
2304 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2305 return HRESULT_CODE(hr);
2306
2307 return ERROR_FUNCTION_FAILED;
2308 }
2309
2310 return r;
2311 }
2312
2313 row = msi_get_property_row( package->db, name );
2314 if (row)
2315 val = msi_record_get_string( row, 1, (int *)&len );
2316
2317 if (!val)
2318 val = szEmpty;
2319
2320 r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
2321
2322 if (row)
2323 msiobj_release( &row->hdr );
2324 msiobj_release( &package->hdr );
2325
2326 return r;
2327 }
2328
2329 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2330 LPSTR szValueBuf, LPDWORD pchValueBuf )
2331 {
2332 awstring val;
2333 LPWSTR name;
2334 UINT r;
2335
2336 val.unicode = FALSE;
2337 val.str.a = szValueBuf;
2338
2339 name = strdupAtoW( szName );
2340 if (szName && !name)
2341 return ERROR_OUTOFMEMORY;
2342
2343 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2344 msi_free( name );
2345 return r;
2346 }
2347
2348 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2349 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2350 {
2351 awstring val;
2352
2353 val.unicode = TRUE;
2354 val.str.w = szValueBuf;
2355
2356 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2357 }
2358
2359 typedef struct _msi_remote_package_impl {
2360 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2361 MSIHANDLE package;
2362 LONG refs;
2363 } msi_remote_package_impl;
2364
2365 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2366 {
2367 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2368 }
2369
2370 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2371 REFIID riid,LPVOID *ppobj)
2372 {
2373 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2374 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2375 {
2376 IWineMsiRemotePackage_AddRef( iface );
2377 *ppobj = iface;
2378 return S_OK;
2379 }
2380
2381 return E_NOINTERFACE;
2382 }
2383
2384 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2385 {
2386 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2387
2388 return InterlockedIncrement( &This->refs );
2389 }
2390
2391 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2392 {
2393 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2394 ULONG r;
2395
2396 r = InterlockedDecrement( &This->refs );
2397 if (r == 0)
2398 {
2399 MsiCloseHandle( This->package );
2400 msi_free( This );
2401 }
2402 return r;
2403 }
2404
2405 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2406 {
2407 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2408 This->package = handle;
2409 return S_OK;
2410 }
2411
2412 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2413 {
2414 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2415 IWineMsiRemoteDatabase *rdb = NULL;
2416 HRESULT hr;
2417 MSIHANDLE hdb;
2418
2419 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2420 if (FAILED(hr) || !rdb)
2421 {
2422 ERR("Failed to create remote database\n");
2423 return hr;
2424 }
2425
2426 hdb = MsiGetActiveDatabase(This->package);
2427
2428 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2429 if (FAILED(hr))
2430 {
2431 ERR("Failed to set the database handle\n");
2432 return hr;
2433 }
2434
2435 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2436 return S_OK;
2437 }
2438
2439 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value, DWORD *size )
2440 {
2441 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2442 UINT r = MsiGetPropertyW(This->package, property, value, size);
2443 if (r != ERROR_SUCCESS) return HRESULT_FROM_WIN32(r);
2444 return S_OK;
2445 }
2446
2447 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2448 {
2449 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2450 UINT r = MsiSetPropertyW(This->package, property, value);
2451 return HRESULT_FROM_WIN32(r);
2452 }
2453
2454 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2455 {
2456 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2457 UINT r = MsiProcessMessage(This->package, message, record);
2458 return HRESULT_FROM_WIN32(r);
2459 }
2460
2461 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2462 {
2463 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2464 UINT r = MsiDoActionW(This->package, action);
2465 return HRESULT_FROM_WIN32(r);
2466 }
2467
2468 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2469 {
2470 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2471 UINT r = MsiSequenceW(This->package, table, sequence);
2472 return HRESULT_FROM_WIN32(r);
2473 }
2474
2475 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2476 {
2477 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2478 UINT r = MsiGetTargetPathW(This->package, folder, value, size);
2479 return HRESULT_FROM_WIN32(r);
2480 }
2481
2482 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2483 {
2484 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2485 UINT r = MsiSetTargetPathW(This->package, folder, value);
2486 return HRESULT_FROM_WIN32(r);
2487 }
2488
2489 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2490 {
2491 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2492 UINT r = MsiGetSourcePathW(This->package, folder, value, size);
2493 return HRESULT_FROM_WIN32(r);
2494 }
2495
2496 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2497 {
2498 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2499 *ret = MsiGetMode(This->package, mode);
2500 return S_OK;
2501 }
2502
2503 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2504 {
2505 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2506 UINT r = MsiSetMode(This->package, mode, state);
2507 return HRESULT_FROM_WIN32(r);
2508 }
2509
2510 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2511 INSTALLSTATE *installed, INSTALLSTATE *action )
2512 {
2513 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2514 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2515 return HRESULT_FROM_WIN32(r);
2516 }
2517
2518 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2519 {
2520 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2521 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2522 return HRESULT_FROM_WIN32(r);
2523 }
2524
2525 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2526 INSTALLSTATE *installed, INSTALLSTATE *action )
2527 {
2528 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2529 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2530 return HRESULT_FROM_WIN32(r);
2531 }
2532
2533 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2534 {
2535 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2536 UINT r = MsiSetComponentStateW(This->package, component, state);
2537 return HRESULT_FROM_WIN32(r);
2538 }
2539
2540 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2541 {
2542 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2543 *language = MsiGetLanguage(This->package);
2544 return S_OK;
2545 }
2546
2547 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2548 {
2549 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2550 UINT r = MsiSetInstallLevel(This->package, level);
2551 return HRESULT_FROM_WIN32(r);
2552 }
2553
2554 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2555 BSTR *value)
2556 {
2557 DWORD size = 0;
2558 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2559 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2560 if (r == ERROR_SUCCESS)
2561 {
2562 *value = SysAllocStringLen(NULL, size);
2563 if (!*value)
2564 return E_OUTOFMEMORY;
2565 size++;
2566 r = MsiFormatRecordW(This->package, record, *value, &size);
2567 }
2568 return HRESULT_FROM_WIN32(r);
2569 }
2570
2571 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2572 {
2573 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2574 UINT r = MsiEvaluateConditionW(This->package, condition);
2575 return HRESULT_FROM_WIN32(r);
2576 }
2577
2578 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2579 INT cost_tree, INSTALLSTATE state, INT *cost )
2580 {
2581 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2582 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2583 return HRESULT_FROM_WIN32(r);
2584 }
2585
2586 static HRESULT WINAPI mrp_EnumComponentCosts( IWineMsiRemotePackage *iface, BSTR component,
2587 DWORD index, INSTALLSTATE state, BSTR drive,
2588 DWORD *buflen, INT *cost, INT *temp )
2589 {
2590 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2591 UINT r = MsiEnumComponentCostsW(This->package, component, index, state, drive, buflen, cost, temp);
2592 return HRESULT_FROM_WIN32(r);
2593 }
2594
2595 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2596 {
2597 mrp_QueryInterface,
2598 mrp_AddRef,
2599 mrp_Release,
2600 mrp_SetMsiHandle,
2601 mrp_GetActiveDatabase,
2602 mrp_GetProperty,
2603 mrp_SetProperty,
2604 mrp_ProcessMessage,
2605 mrp_DoAction,
2606 mrp_Sequence,
2607 mrp_GetTargetPath,
2608 mrp_SetTargetPath,
2609 mrp_GetSourcePath,
2610 mrp_GetMode,
2611 mrp_SetMode,
2612 mrp_GetFeatureState,
2613 mrp_SetFeatureState,
2614 mrp_GetComponentState,
2615 mrp_SetComponentState,
2616 mrp_GetLanguage,
2617 mrp_SetInstallLevel,
2618 mrp_FormatRecord,
2619 mrp_EvaluateCondition,
2620 mrp_GetFeatureCost,
2621 mrp_EnumComponentCosts
2622 };
2623
2624 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2625 {
2626 msi_remote_package_impl* This;
2627
2628 This = msi_alloc( sizeof *This );
2629 if (!This)
2630 return E_OUTOFMEMORY;
2631
2632 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2633 This->package = 0;
2634 This->refs = 1;
2635
2636 *ppObj = This;
2637
2638 return S_OK;
2639 }
2640
2641 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2642 LPCWSTR property, LPWSTR value)
2643 {
2644 MSISOURCELISTINFO *info;
2645
2646 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2647 {
2648 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2649 }
2650
2651 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2652 if (!info)
2653 return ERROR_OUTOFMEMORY;
2654
2655 info->context = context;
2656 info->options = options;
2657 info->property = property;
2658 info->value = strdupW(value);
2659 list_add_head(&package->sourcelist_info, &info->entry);
2660
2661 return ERROR_SUCCESS;
2662 }
2663
2664 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2665 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2666 {
2667 MSIMEDIADISK *disk;
2668
2669 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2670 {
2671 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2672 }
2673
2674 disk = msi_alloc(sizeof(MSIMEDIADISK));
2675 if (!disk)
2676 return ERROR_OUTOFMEMORY;
2677
2678 disk->context = context;
2679 disk->options = options;
2680 disk->disk_id = disk_id;
2681 disk->volume_label = strdupW(volume_label);
2682 disk->disk_prompt = strdupW(disk_prompt);
2683 list_add_head(&package->sourcelist_media, &disk->entry);
2684
2685 return ERROR_SUCCESS;
2686 }