50343597fa71278da46d551898aa78f4bde6a446
[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(MSIPACKAGE *package)
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( package->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( package->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( package->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 goto done;
1056 }
1057
1058 msi_set_property( package->db, szPackageCode, package_code, len );
1059 msi_free( package_code );
1060
1061 /* load package attributes */
1062 count = 0;
1063 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1064 &count, NULL, NULL, NULL );
1065 package->WordCount = count;
1066
1067 done:
1068 MsiCloseHandle(suminfo);
1069 return rc;
1070 }
1071
1072 static MSIPACKAGE *msi_alloc_package( void )
1073 {
1074 MSIPACKAGE *package;
1075
1076 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1077 MSI_FreePackage );
1078 if( package )
1079 {
1080 list_init( &package->components );
1081 list_init( &package->features );
1082 list_init( &package->files );
1083 list_init( &package->filepatches );
1084 list_init( &package->tempfiles );
1085 list_init( &package->folders );
1086 list_init( &package->subscriptions );
1087 list_init( &package->appids );
1088 list_init( &package->classes );
1089 list_init( &package->mimes );
1090 list_init( &package->extensions );
1091 list_init( &package->progids );
1092 list_init( &package->RunningActions );
1093 list_init( &package->sourcelist_info );
1094 list_init( &package->sourcelist_media );
1095 list_init( &package->patches );
1096 list_init( &package->binaries );
1097 list_init( &package->cabinet_streams );
1098 }
1099
1100 return package;
1101 }
1102
1103 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1104 {
1105 BYTE *data;
1106 UINT r, sz;
1107
1108 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1109
1110 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1111 if (r != ERROR_SUCCESS)
1112 return r;
1113
1114 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1115
1116 msi_free(data);
1117 return r;
1118 }
1119
1120 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1121 {
1122 /* FIXME: this should depend on the user's privileges */
1123 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1124 {
1125 TRACE("resetting ALLUSERS property from 2 to 1\n");
1126 msi_set_property( package->db, szAllUsers, szOne, -1 );
1127 }
1128 msi_set_property( package->db, szAdminUser, szOne, -1 );
1129 }
1130
1131 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1132 {
1133 static const WCHAR fmtW[] = {'%','u',0};
1134 MSIPACKAGE *package;
1135 WCHAR uilevel[11];
1136 int len;
1137 UINT r;
1138
1139 TRACE("%p\n", db);
1140
1141 package = msi_alloc_package();
1142 if (package)
1143 {
1144 msiobj_addref( &db->hdr );
1145 package->db = db;
1146
1147 package->WordCount = 0;
1148 package->PackagePath = strdupW( db->path );
1149 package->BaseURL = strdupW( base_url );
1150
1151 create_temp_property_table( package );
1152 msi_clone_properties( package );
1153 msi_adjust_privilege_properties( package );
1154
1155 package->ProductCode = msi_dup_property( package->db, szProductCode );
1156 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1157
1158 set_installed_prop( package );
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 static enum platform parse_platform( 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 msi_set_context( package );
1634
1635 while (1)
1636 {
1637 WCHAR patch_code[GUID_SIZE];
1638 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1639 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1640 if (r != ERROR_SUCCESS)
1641 break;
1642
1643 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1644
1645 r = msi_apply_registered_patch( package, patch_code );
1646 if (r != ERROR_SUCCESS)
1647 {
1648 ERR("registered patch failed to apply %u\n", r);
1649 msiobj_release( &package->hdr );
1650 return r;
1651 }
1652 index++;
1653 }
1654 if (index)
1655 {
1656 msi_clone_properties( package );
1657 msi_adjust_privilege_properties( package );
1658 }
1659 r = msi_set_original_database_property( package->db, szPackage );
1660 if (r != ERROR_SUCCESS)
1661 {
1662 msiobj_release( &package->hdr );
1663 return r;
1664 }
1665 if (gszLogFile)
1666 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1667 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1668 *pPackage = package;
1669 return ERROR_SUCCESS;
1670 }
1671
1672 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1673 {
1674 MSIPACKAGE *package = NULL;
1675 UINT ret;
1676
1677 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1678
1679 if( !szPackage || !phPackage )
1680 return ERROR_INVALID_PARAMETER;
1681
1682 if ( !*szPackage )
1683 {
1684 FIXME("Should create an empty database and package\n");
1685 return ERROR_FUNCTION_FAILED;
1686 }
1687
1688 if( dwOptions )
1689 FIXME("dwOptions %08x not supported\n", dwOptions);
1690
1691 ret = MSI_OpenPackageW( szPackage, &package );
1692 if( ret == ERROR_SUCCESS )
1693 {
1694 *phPackage = alloc_msihandle( &package->hdr );
1695 if (! *phPackage)
1696 ret = ERROR_NOT_ENOUGH_MEMORY;
1697 msiobj_release( &package->hdr );
1698 }
1699
1700 return ret;
1701 }
1702
1703 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1704 {
1705 return MsiOpenPackageExW( szPackage, 0, phPackage );
1706 }
1707
1708 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1709 {
1710 LPWSTR szwPack = NULL;
1711 UINT ret;
1712
1713 if( szPackage )
1714 {
1715 szwPack = strdupAtoW( szPackage );
1716 if( !szwPack )
1717 return ERROR_OUTOFMEMORY;
1718 }
1719
1720 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1721
1722 msi_free( szwPack );
1723
1724 return ret;
1725 }
1726
1727 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1728 {
1729 return MsiOpenPackageExA( szPackage, 0, phPackage );
1730 }
1731
1732 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1733 {
1734 MSIPACKAGE *package;
1735 MSIHANDLE handle = 0;
1736 IUnknown *remote_unk;
1737 IWineMsiRemotePackage *remote_package;
1738
1739 TRACE("(%d)\n",hInstall);
1740
1741 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1742 if( package)
1743 {
1744 handle = alloc_msihandle( &package->db->hdr );
1745 msiobj_release( &package->hdr );
1746 }
1747 else if ((remote_unk = msi_get_remote(hInstall)))
1748 {
1749 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1750 (LPVOID *)&remote_package) == S_OK)
1751 {
1752 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1753 IWineMsiRemotePackage_Release(remote_package);
1754 }
1755 else
1756 {
1757 WARN("remote handle %d is not a package\n", hInstall);
1758 }
1759 IUnknown_Release(remote_unk);
1760 }
1761
1762 return handle;
1763 }
1764
1765 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1766 {
1767 static const WCHAR szActionData[] = {'A','c','t','i','o','n','D','a','t','a',0};
1768 static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1769 static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0};
1770 MSIRECORD *uirow;
1771 LPWSTR deformated, message;
1772 DWORD i, len, total_len, log_type = 0;
1773 INT rc = 0;
1774 char *msg;
1775
1776 TRACE("%x\n", eMessageType);
1777
1778 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_FATALEXIT)
1779 log_type |= INSTALLLOGMODE_FATALEXIT;
1780 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1781 log_type |= INSTALLLOGMODE_ERROR;
1782 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1783 log_type |= INSTALLLOGMODE_WARNING;
1784 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1785 log_type |= INSTALLLOGMODE_USER;
1786 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1787 log_type |= INSTALLLOGMODE_INFO;
1788 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE)
1789 log_type |= INSTALLLOGMODE_RESOLVESOURCE;
1790 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE)
1791 log_type |= INSTALLLOGMODE_OUTOFDISKSPACE;
1792 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1793 log_type |= INSTALLLOGMODE_COMMONDATA;
1794 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1795 log_type |= INSTALLLOGMODE_ACTIONSTART;
1796 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1797 log_type |= INSTALLLOGMODE_ACTIONDATA;
1798 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1799 log_type |= INSTALLLOGMODE_PROGRESS;
1800 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INITIALIZE)
1801 log_type |= INSTALLLOGMODE_INITIALIZE;
1802 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_TERMINATE)
1803 log_type |= INSTALLLOGMODE_TERMINATE;
1804 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_SHOWDIALOG)
1805 log_type |= INSTALLLOGMODE_SHOWDIALOG;
1806
1807 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1808 {
1809 static const WCHAR template_s[]=
1810 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1811 static const WCHAR format[] =
1812 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1813 WCHAR timet[0x100];
1814 LPCWSTR action_text, action;
1815 LPWSTR deformatted = NULL;
1816
1817 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1818
1819 action = MSI_RecordGetString(record, 1);
1820 action_text = MSI_RecordGetString(record, 2);
1821
1822 if (!action || !action_text)
1823 return IDOK;
1824
1825 deformat_string(package, action_text, &deformatted);
1826
1827 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1828 if (deformatted)
1829 len += strlenW(deformatted);
1830 message = msi_alloc(len*sizeof(WCHAR));
1831 sprintfW(message, template_s, timet, action);
1832 if (deformatted)
1833 strcatW(message, deformatted);
1834 msi_free(deformatted);
1835 }
1836 else
1837 {
1838 static const WCHAR format[] = {'%','u',':',' ',0};
1839 UINT count = MSI_RecordGetFieldCount( record );
1840 WCHAR *p;
1841
1842 total_len = 1;
1843 for (i = 1; i <= count; i++)
1844 {
1845 len = 0;
1846 MSI_RecordGetStringW( record, i, NULL, &len );
1847 total_len += len + 13;
1848 }
1849 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1850 if (!p) return ERROR_OUTOFMEMORY;
1851
1852 for (i = 1; i <= count; i++)
1853 {
1854 if (count > 1)
1855 {
1856 len = sprintfW( p, format, i );
1857 total_len -= len;
1858 p += len;
1859 }
1860 len = total_len;
1861 MSI_RecordGetStringW( record, i, p, &len );
1862 total_len -= len;
1863 p += len;
1864 if (count > 1 && total_len)
1865 {
1866 *p++ = ' ';
1867 total_len--;
1868 }
1869 }
1870 p[0] = 0;
1871 }
1872
1873 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1874 gUIFilter, log_type, debugstr_w(message));
1875
1876 /* convert it to ASCII */
1877 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1878 msg = msi_alloc( len );
1879 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1880
1881 if (gUIHandlerW && (gUIFilter & log_type))
1882 {
1883 rc = gUIHandlerW( gUIContext, eMessageType, message );
1884 }
1885 else if (gUIHandlerA && (gUIFilter & log_type))
1886 {
1887 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1888 }
1889 else if (gUIHandlerRecord && (gUIFilter & log_type))
1890 {
1891 MSIHANDLE rec = MsiCreateRecord( 1 );
1892 MsiRecordSetStringW( rec, 0, message );
1893 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1894 MsiCloseHandle( rec );
1895 }
1896
1897 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1898 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1899 {
1900 DWORD written;
1901 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1902 WriteFile( package->log_file, "\n", 1, &written, NULL );
1903 }
1904 msi_free( msg );
1905 msi_free( message );
1906
1907 switch (eMessageType & 0xff000000)
1908 {
1909 case INSTALLMESSAGE_ACTIONDATA:
1910 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1911 uirow = MSI_CreateRecord(1);
1912 MSI_RecordSetStringW(uirow, 1, deformated);
1913 msi_free(deformated);
1914
1915 msi_event_fire( package, szActionData, uirow );
1916 msiobj_release(&uirow->hdr);
1917
1918 if (package->action_progress_increment)
1919 {
1920 uirow = MSI_CreateRecord(2);
1921 MSI_RecordSetInteger(uirow, 1, 2);
1922 MSI_RecordSetInteger(uirow, 2, package->action_progress_increment);
1923 msi_event_fire( package, szSetProgress, uirow );
1924 msiobj_release(&uirow->hdr);
1925 }
1926 break;
1927
1928 case INSTALLMESSAGE_ACTIONSTART:
1929 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1930 uirow = MSI_CreateRecord(1);
1931 MSI_RecordSetStringW(uirow, 1, deformated);
1932 msi_free(deformated);
1933
1934 msi_event_fire( package, szActionText, uirow );
1935
1936 msiobj_release(&uirow->hdr);
1937 break;
1938
1939 case INSTALLMESSAGE_PROGRESS:
1940 msi_event_fire( package, szSetProgress, record );
1941 break;
1942 }
1943
1944 return ERROR_SUCCESS;
1945 }
1946
1947 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1948 MSIHANDLE hRecord)
1949 {
1950 UINT ret = ERROR_INVALID_HANDLE;
1951 MSIPACKAGE *package = NULL;
1952 MSIRECORD *record = NULL;
1953
1954 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1955 if( !package )
1956 {
1957 HRESULT hr;
1958 IWineMsiRemotePackage *remote_package;
1959
1960 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1961 if (!remote_package)
1962 return ERROR_INVALID_HANDLE;
1963
1964 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1965
1966 IWineMsiRemotePackage_Release( remote_package );
1967
1968 if (FAILED(hr))
1969 {
1970 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1971 return HRESULT_CODE(hr);
1972
1973 return ERROR_FUNCTION_FAILED;
1974 }
1975
1976 return ERROR_SUCCESS;
1977 }
1978
1979 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1980 if( !record )
1981 goto out;
1982
1983 ret = MSI_ProcessMessage( package, eMessageType, record );
1984
1985 out:
1986 msiobj_release( &package->hdr );
1987 if( record )
1988 msiobj_release( &record->hdr );
1989
1990 return ret;
1991 }
1992
1993 /* property code */
1994
1995 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1996 {
1997 LPWSTR szwName = NULL, szwValue = NULL;
1998 UINT r = ERROR_OUTOFMEMORY;
1999
2000 szwName = strdupAtoW( szName );
2001 if( szName && !szwName )
2002 goto end;
2003
2004 szwValue = strdupAtoW( szValue );
2005 if( szValue && !szwValue )
2006 goto end;
2007
2008 r = MsiSetPropertyW( hInstall, szwName, szwValue);
2009
2010 end:
2011 msi_free( szwName );
2012 msi_free( szwValue );
2013
2014 return r;
2015 }
2016
2017 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
2018 {
2019 MSIFOLDER *folder;
2020
2021 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
2022 {
2023 if ( source )
2024 {
2025 msi_free( folder->ResolvedSource );
2026 folder->ResolvedSource = NULL;
2027 }
2028 else
2029 {
2030 msi_free( folder->ResolvedTarget );
2031 folder->ResolvedTarget = NULL;
2032 }
2033 }
2034 }
2035
2036 UINT msi_set_property( MSIDATABASE *db, const WCHAR *name, const WCHAR *value, int len )
2037 {
2038 static const WCHAR insert_query[] = {
2039 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2040 '`','_','P','r','o','p','e','r','t','y','`',' ',
2041 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2042 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2043 static const WCHAR update_query[] = {
2044 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2045 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2046 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2047 static const WCHAR delete_query[] = {
2048 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2049 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2050 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2051 MSIQUERY *view;
2052 MSIRECORD *row = NULL;
2053 DWORD sz = 0;
2054 WCHAR query[1024];
2055 UINT rc;
2056
2057 TRACE("%p %s %s %d\n", db, debugstr_w(name), debugstr_wn(value, len), len);
2058
2059 if (!name)
2060 return ERROR_INVALID_PARAMETER;
2061
2062 /* this one is weird... */
2063 if (!name[0])
2064 return value ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2065
2066 if (value && len < 0) len = strlenW( value );
2067
2068 rc = msi_get_property( db, name, 0, &sz );
2069 if (!value || (!*value && !len))
2070 {
2071 sprintfW( query, delete_query, name );
2072 }
2073 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2074 {
2075 sprintfW( query, update_query, name );
2076 row = MSI_CreateRecord(1);
2077 msi_record_set_string( row, 1, value, len );
2078 }
2079 else
2080 {
2081 strcpyW( query, insert_query );
2082 row = MSI_CreateRecord(2);
2083 msi_record_set_string( row, 1, name, -1 );
2084 msi_record_set_string( row, 2, value, len );
2085 }
2086
2087 rc = MSI_DatabaseOpenViewW(db, query, &view);
2088 if (rc == ERROR_SUCCESS)
2089 {
2090 rc = MSI_ViewExecute(view, row);
2091 MSI_ViewClose(view);
2092 msiobj_release(&view->hdr);
2093 }
2094 if (row) msiobj_release(&row->hdr);
2095 return rc;
2096 }
2097
2098 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2099 {
2100 MSIPACKAGE *package;
2101 UINT ret;
2102
2103 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2104 if( !package )
2105 {
2106 HRESULT hr;
2107 BSTR name = NULL, value = NULL;
2108 IWineMsiRemotePackage *remote_package;
2109
2110 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2111 if (!remote_package)
2112 return ERROR_INVALID_HANDLE;
2113
2114 name = SysAllocString( szName );
2115 value = SysAllocString( szValue );
2116 if ((!name && szName) || (!value && szValue))
2117 {
2118 SysFreeString( name );
2119 SysFreeString( value );
2120 IWineMsiRemotePackage_Release( remote_package );
2121 return ERROR_OUTOFMEMORY;
2122 }
2123
2124 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2125
2126 SysFreeString( name );
2127 SysFreeString( value );
2128 IWineMsiRemotePackage_Release( remote_package );
2129
2130 if (FAILED(hr))
2131 {
2132 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2133 return HRESULT_CODE(hr);
2134
2135 return ERROR_FUNCTION_FAILED;
2136 }
2137
2138 return ERROR_SUCCESS;
2139 }
2140
2141 ret = msi_set_property( package->db, szName, szValue, -1 );
2142 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2143 msi_reset_folders( package, TRUE );
2144
2145 msiobj_release( &package->hdr );
2146 return ret;
2147 }
2148
2149 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2150 {
2151 static const WCHAR query[]= {
2152 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2153 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2154 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2155 MSIRECORD *rec, *row = NULL;
2156 MSIQUERY *view;
2157 UINT r;
2158
2159 if (!name || !*name)
2160 return NULL;
2161
2162 rec = MSI_CreateRecord(1);
2163 if (!rec)
2164 return NULL;
2165
2166 MSI_RecordSetStringW(rec, 1, name);
2167
2168 r = MSI_DatabaseOpenViewW(db, query, &view);
2169 if (r == ERROR_SUCCESS)
2170 {
2171 MSI_ViewExecute(view, rec);
2172 MSI_ViewFetch(view, &row);
2173 MSI_ViewClose(view);
2174 msiobj_release(&view->hdr);
2175 }
2176 msiobj_release(&rec->hdr);
2177 return row;
2178 }
2179
2180 /* internal function, not compatible with MsiGetPropertyW */
2181 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2182 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2183 {
2184 MSIRECORD *row;
2185 UINT rc = ERROR_FUNCTION_FAILED;
2186
2187 row = msi_get_property_row( db, szName );
2188
2189 if (*pchValueBuf > 0)
2190 szValueBuf[0] = 0;
2191
2192 if (row)
2193 {
2194 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2195 msiobj_release(&row->hdr);
2196 }
2197
2198 if (rc == ERROR_SUCCESS)
2199 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf, *pchValueBuf),
2200 debugstr_w(szName));
2201 else if (rc == ERROR_MORE_DATA)
2202 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2203 debugstr_w(szName));
2204 else
2205 {
2206 *pchValueBuf = 0;
2207 TRACE("property %s not found\n", debugstr_w(szName));
2208 }
2209
2210 return rc;
2211 }
2212
2213 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2214 {
2215 DWORD sz = 0;
2216 LPWSTR str;
2217 UINT r;
2218
2219 r = msi_get_property(db, prop, NULL, &sz);
2220 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2221 return NULL;
2222
2223 sz++;
2224 str = msi_alloc(sz * sizeof(WCHAR));
2225 r = msi_get_property(db, prop, str, &sz);
2226 if (r != ERROR_SUCCESS)
2227 {
2228 msi_free(str);
2229 str = NULL;
2230 }
2231
2232 return str;
2233 }
2234
2235 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2236 {
2237 LPWSTR str = msi_dup_property( db, prop );
2238 int val = str ? atoiW(str) : def;
2239 msi_free(str);
2240 return val;
2241 }
2242
2243 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2244 awstring *szValueBuf, LPDWORD pchValueBuf )
2245 {
2246 MSIPACKAGE *package;
2247 MSIRECORD *row = NULL;
2248 UINT r = ERROR_FUNCTION_FAILED;
2249 LPCWSTR val = NULL;
2250 DWORD len = 0;
2251
2252 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2253 szValueBuf->str.w, pchValueBuf );
2254
2255 if (!name)
2256 return ERROR_INVALID_PARAMETER;
2257
2258 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2259 if (!package)
2260 {
2261 HRESULT hr;
2262 IWineMsiRemotePackage *remote_package;
2263 LPWSTR value = NULL;
2264 BSTR bname;
2265
2266 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2267 if (!remote_package)
2268 return ERROR_INVALID_HANDLE;
2269
2270 bname = SysAllocString( name );
2271 if (!bname)
2272 {
2273 IWineMsiRemotePackage_Release( remote_package );
2274 return ERROR_OUTOFMEMORY;
2275 }
2276
2277 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2278 if (FAILED(hr))
2279 goto done;
2280
2281 len++;
2282 value = msi_alloc(len * sizeof(WCHAR));
2283 if (!value)
2284 {
2285 r = ERROR_OUTOFMEMORY;
2286 goto done;
2287 }
2288
2289 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, value, &len );
2290 if (FAILED(hr))
2291 goto done;
2292
2293 r = msi_strcpy_to_awstring( value, len, szValueBuf, pchValueBuf );
2294
2295 /* Bug required by Adobe installers */
2296 if (!szValueBuf->unicode && !szValueBuf->str.a)
2297 *pchValueBuf *= sizeof(WCHAR);
2298
2299 done:
2300 IWineMsiRemotePackage_Release(remote_package);
2301 SysFreeString(bname);
2302 msi_free(value);
2303
2304 if (FAILED(hr))
2305 {
2306 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2307 return HRESULT_CODE(hr);
2308
2309 return ERROR_FUNCTION_FAILED;
2310 }
2311
2312 return r;
2313 }
2314
2315 row = msi_get_property_row( package->db, name );
2316 if (row)
2317 val = msi_record_get_string( row, 1, (int *)&len );
2318
2319 if (!val)
2320 val = szEmpty;
2321
2322 r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
2323
2324 if (row)
2325 msiobj_release( &row->hdr );
2326 msiobj_release( &package->hdr );
2327
2328 return r;
2329 }
2330
2331 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2332 LPSTR szValueBuf, LPDWORD pchValueBuf )
2333 {
2334 awstring val;
2335 LPWSTR name;
2336 UINT r;
2337
2338 val.unicode = FALSE;
2339 val.str.a = szValueBuf;
2340
2341 name = strdupAtoW( szName );
2342 if (szName && !name)
2343 return ERROR_OUTOFMEMORY;
2344
2345 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2346 msi_free( name );
2347 return r;
2348 }
2349
2350 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2351 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2352 {
2353 awstring val;
2354
2355 val.unicode = TRUE;
2356 val.str.w = szValueBuf;
2357
2358 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2359 }
2360
2361 typedef struct _msi_remote_package_impl {
2362 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2363 MSIHANDLE package;
2364 LONG refs;
2365 } msi_remote_package_impl;
2366
2367 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2368 {
2369 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2370 }
2371
2372 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2373 REFIID riid,LPVOID *ppobj)
2374 {
2375 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2376 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2377 {
2378 IWineMsiRemotePackage_AddRef( iface );
2379 *ppobj = iface;
2380 return S_OK;
2381 }
2382
2383 return E_NOINTERFACE;
2384 }
2385
2386 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2387 {
2388 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2389
2390 return InterlockedIncrement( &This->refs );
2391 }
2392
2393 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2394 {
2395 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2396 ULONG r;
2397
2398 r = InterlockedDecrement( &This->refs );
2399 if (r == 0)
2400 {
2401 MsiCloseHandle( This->package );
2402 msi_free( This );
2403 }
2404 return r;
2405 }
2406
2407 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2408 {
2409 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2410 This->package = handle;
2411 return S_OK;
2412 }
2413
2414 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2415 {
2416 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2417 IWineMsiRemoteDatabase *rdb = NULL;
2418 HRESULT hr;
2419 MSIHANDLE hdb;
2420
2421 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2422 if (FAILED(hr) || !rdb)
2423 {
2424 ERR("Failed to create remote database\n");
2425 return hr;
2426 }
2427
2428 hdb = MsiGetActiveDatabase(This->package);
2429
2430 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2431 if (FAILED(hr))
2432 {
2433 ERR("Failed to set the database handle\n");
2434 return hr;
2435 }
2436
2437 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2438 return S_OK;
2439 }
2440
2441 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value, DWORD *size )
2442 {
2443 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2444 UINT r = MsiGetPropertyW(This->package, property, value, size);
2445 if (r != ERROR_SUCCESS) return HRESULT_FROM_WIN32(r);
2446 return S_OK;
2447 }
2448
2449 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2450 {
2451 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2452 UINT r = MsiSetPropertyW(This->package, property, value);
2453 return HRESULT_FROM_WIN32(r);
2454 }
2455
2456 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2457 {
2458 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2459 UINT r = MsiProcessMessage(This->package, message, record);
2460 return HRESULT_FROM_WIN32(r);
2461 }
2462
2463 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2464 {
2465 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2466 UINT r = MsiDoActionW(This->package, action);
2467 return HRESULT_FROM_WIN32(r);
2468 }
2469
2470 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2471 {
2472 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2473 UINT r = MsiSequenceW(This->package, table, sequence);
2474 return HRESULT_FROM_WIN32(r);
2475 }
2476
2477 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2478 {
2479 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2480 UINT r = MsiGetTargetPathW(This->package, folder, value, size);
2481 return HRESULT_FROM_WIN32(r);
2482 }
2483
2484 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2485 {
2486 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2487 UINT r = MsiSetTargetPathW(This->package, folder, value);
2488 return HRESULT_FROM_WIN32(r);
2489 }
2490
2491 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2492 {
2493 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2494 UINT r = MsiGetSourcePathW(This->package, folder, value, size);
2495 return HRESULT_FROM_WIN32(r);
2496 }
2497
2498 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2499 {
2500 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2501 *ret = MsiGetMode(This->package, mode);
2502 return S_OK;
2503 }
2504
2505 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2506 {
2507 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2508 UINT r = MsiSetMode(This->package, mode, state);
2509 return HRESULT_FROM_WIN32(r);
2510 }
2511
2512 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2513 INSTALLSTATE *installed, INSTALLSTATE *action )
2514 {
2515 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2516 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2517 return HRESULT_FROM_WIN32(r);
2518 }
2519
2520 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2521 {
2522 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2523 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2524 return HRESULT_FROM_WIN32(r);
2525 }
2526
2527 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2528 INSTALLSTATE *installed, INSTALLSTATE *action )
2529 {
2530 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2531 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2532 return HRESULT_FROM_WIN32(r);
2533 }
2534
2535 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2536 {
2537 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2538 UINT r = MsiSetComponentStateW(This->package, component, state);
2539 return HRESULT_FROM_WIN32(r);
2540 }
2541
2542 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2543 {
2544 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2545 *language = MsiGetLanguage(This->package);
2546 return S_OK;
2547 }
2548
2549 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2550 {
2551 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2552 UINT r = MsiSetInstallLevel(This->package, level);
2553 return HRESULT_FROM_WIN32(r);
2554 }
2555
2556 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2557 BSTR *value)
2558 {
2559 DWORD size = 0;
2560 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2561 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2562 if (r == ERROR_SUCCESS)
2563 {
2564 *value = SysAllocStringLen(NULL, size);
2565 if (!*value)
2566 return E_OUTOFMEMORY;
2567 size++;
2568 r = MsiFormatRecordW(This->package, record, *value, &size);
2569 }
2570 return HRESULT_FROM_WIN32(r);
2571 }
2572
2573 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2574 {
2575 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2576 UINT r = MsiEvaluateConditionW(This->package, condition);
2577 return HRESULT_FROM_WIN32(r);
2578 }
2579
2580 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2581 INT cost_tree, INSTALLSTATE state, INT *cost )
2582 {
2583 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2584 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2585 return HRESULT_FROM_WIN32(r);
2586 }
2587
2588 static HRESULT WINAPI mrp_EnumComponentCosts( IWineMsiRemotePackage *iface, BSTR component,
2589 DWORD index, INSTALLSTATE state, BSTR drive,
2590 DWORD *buflen, INT *cost, INT *temp )
2591 {
2592 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2593 UINT r = MsiEnumComponentCostsW(This->package, component, index, state, drive, buflen, cost, temp);
2594 return HRESULT_FROM_WIN32(r);
2595 }
2596
2597 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2598 {
2599 mrp_QueryInterface,
2600 mrp_AddRef,
2601 mrp_Release,
2602 mrp_SetMsiHandle,
2603 mrp_GetActiveDatabase,
2604 mrp_GetProperty,
2605 mrp_SetProperty,
2606 mrp_ProcessMessage,
2607 mrp_DoAction,
2608 mrp_Sequence,
2609 mrp_GetTargetPath,
2610 mrp_SetTargetPath,
2611 mrp_GetSourcePath,
2612 mrp_GetMode,
2613 mrp_SetMode,
2614 mrp_GetFeatureState,
2615 mrp_SetFeatureState,
2616 mrp_GetComponentState,
2617 mrp_SetComponentState,
2618 mrp_GetLanguage,
2619 mrp_SetInstallLevel,
2620 mrp_FormatRecord,
2621 mrp_EvaluateCondition,
2622 mrp_GetFeatureCost,
2623 mrp_EnumComponentCosts
2624 };
2625
2626 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2627 {
2628 msi_remote_package_impl* This;
2629
2630 This = msi_alloc( sizeof *This );
2631 if (!This)
2632 return E_OUTOFMEMORY;
2633
2634 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2635 This->package = 0;
2636 This->refs = 1;
2637
2638 *ppObj = This;
2639
2640 return S_OK;
2641 }
2642
2643 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2644 LPCWSTR property, LPWSTR value)
2645 {
2646 MSISOURCELISTINFO *info;
2647
2648 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2649 {
2650 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2651 }
2652
2653 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2654 if (!info)
2655 return ERROR_OUTOFMEMORY;
2656
2657 info->context = context;
2658 info->options = options;
2659 info->property = property;
2660 info->value = strdupW(value);
2661 list_add_head(&package->sourcelist_info, &info->entry);
2662
2663 return ERROR_SUCCESS;
2664 }
2665
2666 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2667 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2668 {
2669 MSIMEDIADISK *disk;
2670
2671 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2672 {
2673 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2674 }
2675
2676 disk = msi_alloc(sizeof(MSIMEDIADISK));
2677 if (!disk)
2678 return ERROR_OUTOFMEMORY;
2679
2680 disk->context = context;
2681 disk->options = options;
2682 disk->disk_id = disk_id;
2683 disk->volume_label = strdupW(volume_label);
2684 disk->disk_prompt = strdupW(disk_prompt);
2685 list_add_head(&package->sourcelist_media, &disk->entry);
2686
2687 return ERROR_SUCCESS;
2688 }