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