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