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