urlmon: Correctly handle BINDF_NO_UI in handle_http_error.
[wine/multimedia.git] / dlls / msi / package.c
blobb1668d3bf08df265e615f28ca82f76e54eee3baf
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
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.
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.
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
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
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"
47 #include "msipriv.h"
48 #include "msiserver.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 static void remove_tracked_tempfiles( MSIPACKAGE *package )
54 struct list *item, *cursor;
56 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
58 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
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 );
68 static void free_feature( MSIFEATURE *feature )
70 struct list *item, *cursor;
72 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
74 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
75 list_remove( &fl->entry );
76 msi_free( fl );
79 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
81 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
82 list_remove( &cl->entry );
83 msi_free( cl );
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 );
93 static void free_folder( MSIFOLDER *folder )
95 struct list *item, *cursor;
97 LIST_FOR_EACH_SAFE( item, cursor, &folder->children )
99 FolderList *fl = LIST_ENTRY( item, FolderList, entry );
100 list_remove( &fl->entry );
101 msi_free( fl );
103 msi_free( folder->Parent );
104 msi_free( folder->Directory );
105 msi_free( folder->TargetDefault );
106 msi_free( folder->SourceLongPath );
107 msi_free( folder->SourceShortPath );
108 msi_free( folder->ResolvedTarget );
109 msi_free( folder->ResolvedSource );
110 msi_free( folder );
113 static void free_extension( MSIEXTENSION *ext )
115 struct list *item, *cursor;
117 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
119 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
121 list_remove( &verb->entry );
122 msi_free( verb->Verb );
123 msi_free( verb->Command );
124 msi_free( verb->Argument );
125 msi_free( verb );
128 msi_free( ext->Extension );
129 msi_free( ext->ProgIDText );
130 msi_free( ext );
133 static void free_assembly( MSIASSEMBLY *assembly )
135 msi_free( assembly->feature );
136 msi_free( assembly->manifest );
137 msi_free( assembly->application );
138 msi_free( assembly->display_name );
139 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
140 msi_free( assembly->tempdir );
141 msi_free( assembly );
144 void msi_free_action_script( MSIPACKAGE *package, UINT script )
146 UINT i;
147 for (i = 0; i < package->script->ActionCount[script]; i++)
148 msi_free( package->script->Actions[script][i] );
150 msi_free( package->script->Actions[script] );
151 package->script->Actions[script] = NULL;
152 package->script->ActionCount[script] = 0;
155 static void free_package_structures( MSIPACKAGE *package )
157 INT i;
158 struct list *item, *cursor;
160 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
162 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
163 list_remove( &feature->entry );
164 free_feature( feature );
167 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
169 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
170 list_remove( &folder->entry );
171 free_folder( folder );
174 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
176 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
178 list_remove( &comp->entry );
179 msi_free( comp->Component );
180 msi_free( comp->ComponentId );
181 msi_free( comp->Directory );
182 msi_free( comp->Condition );
183 msi_free( comp->KeyPath );
184 msi_free( comp->FullKeypath );
185 if (comp->assembly) free_assembly( comp->assembly );
186 msi_free( comp );
189 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
191 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
193 list_remove( &file->entry );
194 msi_free( file->File );
195 msi_free( file->FileName );
196 msi_free( file->ShortName );
197 msi_free( file->LongName );
198 msi_free( file->Version );
199 msi_free( file->Language );
200 msi_free( file->TargetPath );
201 msi_free( file );
204 /* clean up extension, progid, class and verb structures */
205 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
207 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
209 list_remove( &cls->entry );
210 msi_free( cls->clsid );
211 msi_free( cls->Context );
212 msi_free( cls->Description );
213 msi_free( cls->FileTypeMask );
214 msi_free( cls->IconPath );
215 msi_free( cls->DefInprocHandler );
216 msi_free( cls->DefInprocHandler32 );
217 msi_free( cls->Argument );
218 msi_free( cls->ProgIDText );
219 msi_free( cls );
222 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
224 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
226 list_remove( &ext->entry );
227 free_extension( ext );
230 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
232 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
234 list_remove( &progid->entry );
235 msi_free( progid->ProgID );
236 msi_free( progid->Description );
237 msi_free( progid->IconPath );
238 msi_free( progid );
241 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
243 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
245 list_remove( &mt->entry );
246 msi_free( mt->suffix );
247 msi_free( mt->clsid );
248 msi_free( mt->ContentType );
249 msi_free( mt );
252 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
254 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
256 list_remove( &appid->entry );
257 msi_free( appid->AppID );
258 msi_free( appid->RemoteServerName );
259 msi_free( appid->LocalServer );
260 msi_free( appid->ServiceParameters );
261 msi_free( appid->DllSurrogate );
262 msi_free( appid );
265 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
267 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
269 list_remove( &info->entry );
270 msi_free( info->value );
271 msi_free( info );
274 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
276 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
278 list_remove( &info->entry );
279 msi_free( info->volume_label );
280 msi_free( info->disk_prompt );
281 msi_free( info );
284 if (package->script)
286 for (i = 0; i < SCRIPT_MAX; i++)
287 msi_free_action_script( package, i );
289 for (i = 0; i < package->script->UniqueActionsCount; i++)
290 msi_free( package->script->UniqueActions[i] );
292 msi_free( package->script->UniqueActions );
293 msi_free( package->script );
296 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
298 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
300 list_remove( &binary->entry );
301 if (binary->module)
302 FreeLibrary( binary->module );
303 if (!DeleteFileW( binary->tmpfile ))
304 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
305 msi_free( binary->source );
306 msi_free( binary->tmpfile );
307 msi_free( binary );
310 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
312 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
314 list_remove( &cab->entry );
315 IStorage_Release( cab->storage );
316 msi_free( cab->stream );
317 msi_free( cab );
320 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
322 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
324 list_remove( &patch->entry );
325 if (patch->delete_on_close && !DeleteFileW( patch->localfile ))
327 ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError());
329 msi_free_patchinfo( patch );
332 msi_free( package->BaseURL );
333 msi_free( package->PackagePath );
334 msi_free( package->ProductCode );
335 msi_free( package->ActionFormat );
336 msi_free( package->LastAction );
337 msi_free( package->langids );
339 remove_tracked_tempfiles(package);
341 /* cleanup control event subscriptions */
342 ControlEvent_CleanupSubscriptions( package );
345 static void MSI_FreePackage( MSIOBJECTHDR *arg)
347 UINT i;
348 MSIPACKAGE *package = (MSIPACKAGE *)arg;
350 if( package->dialog )
351 msi_dialog_destroy( package->dialog );
353 msiobj_release( &package->db->hdr );
354 free_package_structures(package);
355 CloseHandle( package->log_file );
357 for (i = 0; i < CLR_VERSION_MAX; i++)
358 if (package->cache_net[i]) IAssemblyCache_Release( package->cache_net[i] );
359 if (package->cache_sxs) IAssemblyCache_Release( package->cache_sxs );
361 if (package->delete_on_close) DeleteFileW( package->localfile );
362 msi_free( package->localfile );
365 static UINT create_temp_property_table(MSIPACKAGE *package)
367 static const WCHAR query[] = {
368 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
369 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
370 '`','_','P','r','o','p','e','r','t','y','`',' ',
371 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
372 'T','E','M','P','O','R','A','R','Y',',',' ',
373 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
374 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
375 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
376 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
377 MSIQUERY *view;
378 UINT rc;
380 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
381 if (rc != ERROR_SUCCESS)
382 return rc;
384 rc = MSI_ViewExecute(view, 0);
385 MSI_ViewClose(view);
386 msiobj_release(&view->hdr);
387 return rc;
390 UINT msi_clone_properties(MSIPACKAGE *package)
392 static const WCHAR query_select[] = {
393 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
394 '`','P','r','o','p','e','r','t','y','`',0};
395 static const WCHAR query_insert[] = {
396 'I','N','S','E','R','T',' ','I','N','T','O',' ',
397 '`','_','P','r','o','p','e','r','t','y','`',' ',
398 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
399 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
400 static const WCHAR query_update[] = {
401 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
402 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
403 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
404 MSIQUERY *view_select;
405 UINT rc;
407 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
408 if (rc != ERROR_SUCCESS)
409 return rc;
411 rc = MSI_ViewExecute( view_select, 0 );
412 if (rc != ERROR_SUCCESS)
414 MSI_ViewClose( view_select );
415 msiobj_release( &view_select->hdr );
416 return rc;
419 while (1)
421 MSIQUERY *view_insert, *view_update;
422 MSIRECORD *rec_select;
424 rc = MSI_ViewFetch( view_select, &rec_select );
425 if (rc != ERROR_SUCCESS)
426 break;
428 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
429 if (rc != ERROR_SUCCESS)
431 msiobj_release( &rec_select->hdr );
432 continue;
435 rc = MSI_ViewExecute( view_insert, rec_select );
436 MSI_ViewClose( view_insert );
437 msiobj_release( &view_insert->hdr );
438 if (rc != ERROR_SUCCESS)
440 MSIRECORD *rec_update;
442 TRACE("insert failed, trying update\n");
444 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
445 if (rc != ERROR_SUCCESS)
447 WARN("open view failed %u\n", rc);
448 msiobj_release( &rec_select->hdr );
449 continue;
452 rec_update = MSI_CreateRecord( 2 );
453 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
454 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
455 rc = MSI_ViewExecute( view_update, rec_update );
456 if (rc != ERROR_SUCCESS)
457 WARN("update failed %u\n", rc);
459 MSI_ViewClose( view_update );
460 msiobj_release( &view_update->hdr );
461 msiobj_release( &rec_update->hdr );
464 msiobj_release( &rec_select->hdr );
467 MSI_ViewClose( view_select );
468 msiobj_release( &view_select->hdr );
469 return rc;
473 * set_installed_prop
475 * Sets the "Installed" property to indicate that
476 * the product is installed for the current user.
478 static UINT set_installed_prop( MSIPACKAGE *package )
480 HKEY hkey;
481 UINT r;
483 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
485 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
486 if (r == ERROR_SUCCESS)
488 RegCloseKey( hkey );
489 msi_set_property( package->db, szInstalled, szOne );
491 return r;
494 static UINT set_user_sid_prop( MSIPACKAGE *package )
496 SID_NAME_USE use;
497 LPWSTR user_name;
498 LPWSTR sid_str = NULL, dom = NULL;
499 DWORD size, dom_size;
500 PSID psid = NULL;
501 UINT r = ERROR_FUNCTION_FAILED;
503 size = 0;
504 GetUserNameW( NULL, &size );
506 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
507 if (!user_name)
508 return ERROR_OUTOFMEMORY;
510 if (!GetUserNameW( user_name, &size ))
511 goto done;
513 size = 0;
514 dom_size = 0;
515 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
517 psid = msi_alloc( size );
518 dom = msi_alloc( dom_size*sizeof (WCHAR) );
519 if (!psid || !dom)
521 r = ERROR_OUTOFMEMORY;
522 goto done;
525 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
526 goto done;
528 if (!ConvertSidToStringSidW( psid, &sid_str ))
529 goto done;
531 r = msi_set_property( package->db, szUserSID, sid_str );
533 done:
534 LocalFree( sid_str );
535 msi_free( dom );
536 msi_free( psid );
537 msi_free( user_name );
539 return r;
542 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
544 HKEY netsetup;
545 LONG res;
546 LPWSTR file = NULL;
547 DWORD index = 0, size;
548 WCHAR ver[MAX_PATH];
549 WCHAR name[MAX_PATH];
550 WCHAR windir[MAX_PATH];
552 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
553 static const WCHAR sub[] = {
554 'S','o','f','t','w','a','r','e','\\',
555 'M','i','c','r','o','s','o','f','t','\\',
556 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
557 'N','D','P',0
559 static const WCHAR subdir[] = {
560 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
561 'F','r','a','m','e','w','o','r','k','\\',0
564 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
565 if (res != ERROR_SUCCESS)
566 return NULL;
568 GetWindowsDirectoryW(windir, MAX_PATH);
570 ver[0] = '\0';
571 size = MAX_PATH;
572 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
574 index++;
576 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
577 if (strcmpW( ver, name ) < 0)
579 LPWSTR check;
580 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
581 check = msi_alloc(size * sizeof(WCHAR));
583 if (!check)
585 msi_free(file);
586 return NULL;
589 lstrcpyW(check, windir);
590 lstrcatW(check, szBackSlash);
591 lstrcatW(check, subdir);
592 lstrcatW(check, name);
593 lstrcatW(check, szBackSlash);
594 lstrcatW(check, fusion);
596 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
598 msi_free(file);
599 file = check;
600 lstrcpyW(ver, name);
602 else
603 msi_free(check);
607 RegCloseKey(netsetup);
608 return file;
611 typedef struct tagLANGANDCODEPAGE
613 WORD wLanguage;
614 WORD wCodePage;
615 } LANGANDCODEPAGE;
617 static void set_msi_assembly_prop(MSIPACKAGE *package)
619 UINT val_len;
620 DWORD size, handle;
621 LPVOID version = NULL;
622 WCHAR buf[MAX_PATH];
623 LPWSTR fusion, verstr;
624 LANGANDCODEPAGE *translate;
626 static const WCHAR netasm[] = {
627 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
629 static const WCHAR translation[] = {
630 '\\','V','a','r','F','i','l','e','I','n','f','o',
631 '\\','T','r','a','n','s','l','a','t','i','o','n',0
633 static const WCHAR verfmt[] = {
634 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
635 '\\','%','0','4','x','%','0','4','x',
636 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
639 fusion = get_fusion_filename(package);
640 if (!fusion)
641 return;
643 size = GetFileVersionInfoSizeW(fusion, &handle);
644 if (!size) return;
646 version = msi_alloc(size);
647 if (!version) return;
649 if (!GetFileVersionInfoW(fusion, handle, size, version))
650 goto done;
652 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
653 goto done;
655 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
657 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
658 goto done;
660 if (!val_len || !verstr)
661 goto done;
663 msi_set_property(package->db, netasm, verstr);
665 done:
666 msi_free(fusion);
667 msi_free(version);
670 static VOID set_installer_properties(MSIPACKAGE *package)
672 WCHAR pth[MAX_PATH];
673 WCHAR *ptr;
674 OSVERSIONINFOEXW OSVersion;
675 MEMORYSTATUSEX msex;
676 DWORD verval, len;
677 WCHAR verstr[10], bufstr[20];
678 HDC dc;
679 HKEY hkey;
680 LPWSTR username, companyname;
681 SYSTEM_INFO sys_info;
682 SYSTEMTIME systemtime;
683 LANGID langid;
685 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
686 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
687 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
688 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
689 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
690 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
691 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
692 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
693 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
694 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
695 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
696 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
697 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
698 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
699 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
700 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
701 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
702 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
703 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
704 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
705 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
706 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
707 static const WCHAR szFormat[] = {'%','l','i',0};
708 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
709 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
710 static const WCHAR szSix[] = {'6',0 };
711 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
712 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
713 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
714 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
715 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
716 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
717 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
718 static const WCHAR szIntFormat[] = {'%','d',0};
719 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
720 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
721 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
722 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
723 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 };
724 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
725 static const WCHAR szUserInfo[] = {
726 'S','O','F','T','W','A','R','E','\\',
727 'M','i','c','r','o','s','o','f','t','\\',
728 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
729 'U','s','e','r',' ','I','n','f','o',0
731 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
732 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
733 static const WCHAR szCurrentVersion[] = {
734 'S','O','F','T','W','A','R','E','\\',
735 'M','i','c','r','o','s','o','f','t','\\',
736 'W','i','n','d','o','w','s',' ','N','T','\\',
737 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
739 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
740 static const WCHAR szRegisteredOrganization[] = {
741 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
743 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
744 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
745 static const WCHAR szDate[] = {'D','a','t','e',0};
746 static const WCHAR szTime[] = {'T','i','m','e',0};
747 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
748 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
749 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
750 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
751 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
752 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
753 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
754 static const WCHAR szComputerName[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
757 * Other things that probably should be set:
759 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
760 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
763 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
764 strcatW(pth, szBackSlash);
765 msi_set_property(package->db, szCommonAppDataFolder, pth);
767 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
768 strcatW(pth, szBackSlash);
769 msi_set_property(package->db, szFavoritesFolder, pth);
771 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
772 strcatW(pth, szBackSlash);
773 msi_set_property(package->db, szFontsFolder, pth);
775 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
776 strcatW(pth, szBackSlash);
777 msi_set_property(package->db, szSendToFolder, pth);
779 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
780 strcatW(pth, szBackSlash);
781 msi_set_property(package->db, szStartMenuFolder, pth);
783 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
784 strcatW(pth, szBackSlash);
785 msi_set_property(package->db, szStartupFolder, pth);
787 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
788 strcatW(pth, szBackSlash);
789 msi_set_property(package->db, szTemplateFolder, pth);
791 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
792 strcatW(pth, szBackSlash);
793 msi_set_property(package->db, szDesktopFolder, pth);
795 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
796 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
797 strcatW(pth, szBackSlash);
798 msi_set_property(package->db, szProgramMenuFolder, pth);
800 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
801 strcatW(pth, szBackSlash);
802 msi_set_property(package->db, szAdminToolsFolder, pth);
804 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
805 strcatW(pth, szBackSlash);
806 msi_set_property(package->db, szAppDataFolder, pth);
808 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
809 strcatW(pth, szBackSlash);
810 msi_set_property(package->db, szSystemFolder, pth);
811 msi_set_property(package->db, szSystem16Folder, pth);
813 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
814 strcatW(pth, szBackSlash);
815 msi_set_property(package->db, szLocalAppDataFolder, pth);
817 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
818 strcatW(pth, szBackSlash);
819 msi_set_property(package->db, szMyPicturesFolder, pth);
821 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
822 strcatW(pth, szBackSlash);
823 msi_set_property(package->db, szPersonalFolder, pth);
825 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
826 strcatW(pth, szBackSlash);
827 msi_set_property(package->db, szWindowsFolder, pth);
829 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
830 strcatW(pth, szBackSlash);
831 msi_set_property(package->db, szPrintHoodFolder, pth);
833 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
834 strcatW(pth, szBackSlash);
835 msi_set_property(package->db, szNetHoodFolder, pth);
837 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
838 strcatW(pth, szBackSlash);
839 msi_set_property(package->db, szRecentFolder, pth);
841 /* Physical Memory is specified in MB. Using total amount. */
842 msex.dwLength = sizeof(msex);
843 GlobalMemoryStatusEx( &msex );
844 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
845 msi_set_property(package->db, szPhysicalMemory, bufstr);
847 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
848 ptr = strchrW(pth,'\\');
849 if (ptr) *(ptr + 1) = 0;
850 msi_set_property(package->db, szWindowsVolume, pth);
852 GetTempPathW(MAX_PATH,pth);
853 msi_set_property(package->db, szTempFolder, pth);
855 /* in a wine environment the user is always admin and privileged */
856 msi_set_property(package->db, szAdminUser, szOne);
857 msi_set_property(package->db, szPrivileged, szOne);
859 /* set the os things */
860 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
861 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
862 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
863 sprintfW(verstr, szFormat, verval);
864 switch (OSVersion.dwPlatformId)
866 case VER_PLATFORM_WIN32_WINDOWS:
867 msi_set_property(package->db, szVersion9x, verstr);
868 break;
869 case VER_PLATFORM_WIN32_NT:
870 msi_set_property(package->db, szVersionNT, verstr);
871 sprintfW(verstr, szFormat,OSVersion.wProductType);
872 msi_set_property(package->db, szMsiNTProductType, verstr);
873 break;
875 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
876 msi_set_property(package->db, szWindowsBuild, verstr);
877 /* just fudge this */
878 msi_set_property(package->db, szServicePackLevel, szSix);
880 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
881 msi_set_property( package->db, szVersionMsi, bufstr );
882 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
883 msi_set_property( package->db, szVersionDatabase, bufstr );
885 GetNativeSystemInfo( &sys_info );
886 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
887 msi_set_property( package->db, szIntel, bufstr );
888 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
890 GetSystemDirectoryW( pth, MAX_PATH );
891 PathAddBackslashW( pth );
892 msi_set_property( package->db, szSystemFolder, pth );
894 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
895 PathAddBackslashW( pth );
896 msi_set_property( package->db, szProgramFilesFolder, pth );
898 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
899 PathAddBackslashW( pth );
900 msi_set_property( package->db, szCommonFilesFolder, pth );
902 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
904 msi_set_property( package->db, szMsiAMD64, bufstr );
905 msi_set_property( package->db, szMsix64, bufstr );
906 msi_set_property( package->db, szVersionNT64, verstr );
908 GetSystemDirectoryW( pth, MAX_PATH );
909 PathAddBackslashW( pth );
910 msi_set_property( package->db, szSystem64Folder, pth );
912 GetSystemWow64DirectoryW( pth, MAX_PATH );
913 PathAddBackslashW( pth );
914 msi_set_property( package->db, szSystemFolder, pth );
916 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
917 PathAddBackslashW( pth );
918 msi_set_property( package->db, szProgramFiles64Folder, pth );
920 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
921 PathAddBackslashW( pth );
922 msi_set_property( package->db, szProgramFilesFolder, pth );
924 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
925 PathAddBackslashW( pth );
926 msi_set_property( package->db, szCommonFiles64Folder, pth );
928 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
929 PathAddBackslashW( pth );
930 msi_set_property( package->db, szCommonFilesFolder, pth );
933 /* Screen properties. */
934 dc = GetDC(0);
935 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
936 msi_set_property( package->db, szScreenX, bufstr );
937 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
938 msi_set_property( package->db, szScreenY, bufstr );
939 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
940 msi_set_property( package->db, szColorBits, bufstr );
941 ReleaseDC(0, dc);
943 /* USERNAME and COMPANYNAME */
944 username = msi_dup_property( package->db, szUSERNAME );
945 companyname = msi_dup_property( package->db, szCOMPANYNAME );
947 if ((!username || !companyname) &&
948 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
950 if (!username &&
951 (username = msi_reg_get_val_str( hkey, szDefName )))
952 msi_set_property( package->db, szUSERNAME, username );
953 if (!companyname &&
954 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
955 msi_set_property( package->db, szCOMPANYNAME, companyname );
956 CloseHandle( hkey );
958 if ((!username || !companyname) &&
959 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
961 if (!username &&
962 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
963 msi_set_property( package->db, szUSERNAME, username );
964 if (!companyname &&
965 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
966 msi_set_property( package->db, szCOMPANYNAME, companyname );
967 CloseHandle( hkey );
969 msi_free( username );
970 msi_free( companyname );
972 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
973 ERR("Failed to set the UserSID property\n");
975 /* Date and time properties */
976 GetSystemTime( &systemtime );
977 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
978 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
979 msi_set_property( package->db, szDate, bufstr );
980 else
981 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
983 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
984 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
985 &systemtime, NULL, bufstr,
986 sizeof(bufstr)/sizeof(bufstr[0]) ))
987 msi_set_property( package->db, szTime, bufstr );
988 else
989 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
991 set_msi_assembly_prop( package );
993 langid = GetUserDefaultLangID();
994 sprintfW(bufstr, szIntFormat, langid);
995 msi_set_property( package->db, szUserLanguageID, bufstr );
997 langid = GetSystemDefaultLangID();
998 sprintfW(bufstr, szIntFormat, langid);
999 msi_set_property( package->db, szSystemLangID, bufstr );
1001 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
1002 msi_set_property( package->db, szProductState, bufstr );
1004 len = 0;
1005 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1007 WCHAR *username;
1008 if ((username = msi_alloc( len * sizeof(WCHAR) )))
1010 if (GetUserNameW( username, &len ))
1011 msi_set_property( package->db, szLogonUser, username );
1012 msi_free( username );
1015 len = 0;
1016 if (!GetComputerNameW( NULL, &len ) && GetLastError() == ERROR_BUFFER_OVERFLOW)
1018 WCHAR *computername;
1019 if ((computername = msi_alloc( len * sizeof(WCHAR) )))
1021 if (GetComputerNameW( computername, &len ))
1022 msi_set_property( package->db, szComputerName, computername );
1023 msi_free( computername );
1028 static UINT msi_load_summary_properties( MSIPACKAGE *package )
1030 UINT rc;
1031 MSIHANDLE suminfo;
1032 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
1033 INT count;
1034 DWORD len;
1035 LPWSTR package_code;
1036 static const WCHAR szPackageCode[] = {
1037 'P','a','c','k','a','g','e','C','o','d','e',0};
1039 if (!hdb) {
1040 ERR("Unable to allocate handle\n");
1041 return ERROR_OUTOFMEMORY;
1044 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1045 MsiCloseHandle(hdb);
1046 if (rc != ERROR_SUCCESS)
1048 ERR("Unable to open Summary Information\n");
1049 return rc;
1052 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1053 &count, NULL, NULL, NULL );
1054 if (rc != ERROR_SUCCESS)
1056 WARN("Unable to query page count: %d\n", rc);
1057 goto done;
1060 /* load package code property */
1061 len = 0;
1062 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1063 NULL, NULL, NULL, &len );
1064 if (rc != ERROR_MORE_DATA)
1066 WARN("Unable to query revision number: %d\n", rc);
1067 rc = ERROR_FUNCTION_FAILED;
1068 goto done;
1071 len++;
1072 package_code = msi_alloc( len * sizeof(WCHAR) );
1073 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1074 NULL, NULL, package_code, &len );
1075 if (rc != ERROR_SUCCESS)
1077 WARN("Unable to query rev number: %d\n", rc);
1078 goto done;
1081 msi_set_property( package->db, szPackageCode, package_code );
1082 msi_free( package_code );
1084 /* load package attributes */
1085 count = 0;
1086 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1087 &count, NULL, NULL, NULL );
1088 package->WordCount = count;
1090 done:
1091 MsiCloseHandle(suminfo);
1092 return rc;
1095 static MSIPACKAGE *msi_alloc_package( void )
1097 MSIPACKAGE *package;
1099 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1100 MSI_FreePackage );
1101 if( package )
1103 list_init( &package->components );
1104 list_init( &package->features );
1105 list_init( &package->files );
1106 list_init( &package->filepatches );
1107 list_init( &package->tempfiles );
1108 list_init( &package->folders );
1109 list_init( &package->subscriptions );
1110 list_init( &package->appids );
1111 list_init( &package->classes );
1112 list_init( &package->mimes );
1113 list_init( &package->extensions );
1114 list_init( &package->progids );
1115 list_init( &package->RunningActions );
1116 list_init( &package->sourcelist_info );
1117 list_init( &package->sourcelist_media );
1118 list_init( &package->patches );
1119 list_init( &package->binaries );
1120 list_init( &package->cabinet_streams );
1123 return package;
1126 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1128 BYTE *data;
1129 UINT r, sz;
1131 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1133 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1134 if (r != ERROR_SUCCESS)
1135 return r;
1137 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1139 msi_free(data);
1140 return r;
1143 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1145 /* FIXME: this should depend on the user's privileges */
1146 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1148 TRACE("resetting ALLUSERS property from 2 to 1\n");
1149 msi_set_property( package->db, szAllUsers, szOne );
1151 msi_set_property( package->db, szAdminUser, szOne );
1154 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1156 static const WCHAR fmtW[] = {'%','u',0};
1157 MSIPACKAGE *package;
1158 WCHAR uilevel[11];
1159 UINT r;
1161 TRACE("%p\n", db);
1163 package = msi_alloc_package();
1164 if (package)
1166 msiobj_addref( &db->hdr );
1167 package->db = db;
1169 package->WordCount = 0;
1170 package->PackagePath = strdupW( db->path );
1171 package->BaseURL = strdupW( base_url );
1173 create_temp_property_table( package );
1174 msi_clone_properties( package );
1175 msi_adjust_privilege_properties( package );
1177 package->ProductCode = msi_dup_property( package->db, szProductCode );
1178 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1180 set_installed_prop( package );
1181 set_installer_properties( package );
1183 package->ui_level = gUILevel;
1184 sprintfW( uilevel, fmtW, gUILevel & INSTALLUILEVEL_MASK );
1185 msi_set_property(package->db, szUILevel, uilevel);
1187 r = msi_load_summary_properties( package );
1188 if (r != ERROR_SUCCESS)
1190 msiobj_release( &package->hdr );
1191 return NULL;
1194 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1195 msi_load_admin_properties( package );
1197 package->log_file = INVALID_HANDLE_VALUE;
1199 return package;
1202 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1204 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1205 DWORD size = 0;
1206 HRESULT hr;
1208 /* call will always fail, because size is 0,
1209 * but will return ERROR_FILE_NOT_FOUND first
1210 * if the file doesn't exist
1212 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1213 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1215 cache_entry = msi_alloc( size );
1216 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1218 UINT error = GetLastError();
1219 msi_free( cache_entry );
1220 return error;
1223 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1224 msi_free( cache_entry );
1225 return ERROR_SUCCESS;
1228 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1229 if ( FAILED(hr) )
1231 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1232 return ERROR_FUNCTION_FAILED;
1235 return ERROR_SUCCESS;
1238 UINT msi_create_empty_local_file( LPWSTR path, LPCWSTR suffix )
1240 static const WCHAR szInstaller[] = {
1241 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1242 static const WCHAR fmt[] = {'%','x',0};
1243 DWORD time, len, i, offset;
1244 HANDLE handle;
1246 time = GetTickCount();
1247 GetWindowsDirectoryW( path, MAX_PATH );
1248 strcatW( path, szInstaller );
1249 CreateDirectoryW( path, NULL );
1251 len = strlenW(path);
1252 for (i = 0; i < 0x10000; i++)
1254 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1255 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1256 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1257 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1258 if (handle != INVALID_HANDLE_VALUE)
1260 CloseHandle(handle);
1261 break;
1263 if (GetLastError() != ERROR_FILE_EXISTS &&
1264 GetLastError() != ERROR_SHARING_VIOLATION)
1265 return ERROR_FUNCTION_FAILED;
1268 return ERROR_SUCCESS;
1271 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1273 WCHAR *template, *p, *q;
1274 DWORD i, count;
1276 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1277 TRACE("version: %d\n", package->version);
1279 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1280 if (!template)
1281 return ERROR_SUCCESS; /* native accepts missing template property */
1283 TRACE("template: %s\n", debugstr_w(template));
1285 p = strchrW( template, ';' );
1286 if (!p)
1288 WARN("invalid template string %s\n", debugstr_w(template));
1289 msi_free( template );
1290 return ERROR_PATCH_PACKAGE_INVALID;
1292 *p = 0;
1293 if ((q = strchrW( template, ',' ))) *q = 0;
1294 if (!template[0] || !strcmpW( template, szIntel ))
1295 package->platform = PLATFORM_INTEL;
1296 else if (!strcmpW( template, szIntel64 ))
1297 package->platform = PLATFORM_INTEL64;
1298 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1299 package->platform = PLATFORM_X64;
1300 else if (!strcmpW( template, szARM ))
1301 package->platform = PLATFORM_ARM;
1302 else
1304 WARN("unknown platform %s\n", debugstr_w(template));
1305 msi_free( template );
1306 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1308 p++;
1309 if (!*p)
1311 msi_free( template );
1312 return ERROR_SUCCESS;
1314 count = 1;
1315 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1317 package->langids = msi_alloc( count * sizeof(LANGID) );
1318 if (!package->langids)
1320 msi_free( template );
1321 return ERROR_OUTOFMEMORY;
1324 i = 0;
1325 while (*p)
1327 q = strchrW( p, ',' );
1328 if (q) *q = 0;
1329 package->langids[i] = atoiW( p );
1330 if (!q) break;
1331 p = q + 1;
1332 i++;
1334 package->num_langids = i + 1;
1336 msi_free( template );
1337 return ERROR_SUCCESS;
1340 static UINT validate_package( MSIPACKAGE *package )
1342 BOOL is_wow64;
1343 UINT i;
1345 if (package->platform == PLATFORM_INTEL64)
1346 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1347 #ifndef __arm__
1348 if (package->platform == PLATFORM_ARM)
1349 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1350 #endif
1351 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1352 if (package->platform == PLATFORM_X64)
1354 if (!is_64bit && !is_wow64)
1355 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1356 if (package->version < 200)
1357 return ERROR_INSTALL_PACKAGE_INVALID;
1359 if (!package->num_langids)
1361 return ERROR_SUCCESS;
1363 for (i = 0; i < package->num_langids; i++)
1365 LANGID langid = package->langids[i];
1367 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1369 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1371 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1373 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1375 if (IsValidLocale( langid, LCID_INSTALLED ))
1376 return ERROR_SUCCESS;
1378 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1381 int msi_track_tempfile( MSIPACKAGE *package, const WCHAR *path )
1383 MSITEMPFILE *temp;
1385 TRACE("%s\n", debugstr_w(path));
1387 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
1389 if (!strcmpW( path, temp->Path )) return 0;
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;
1397 static WCHAR *get_product_code( MSIDATABASE *db )
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;
1408 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1410 return NULL;
1412 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1414 MSI_ViewClose( view );
1415 msiobj_release( &view->hdr );
1416 return NULL;
1418 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1420 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1421 msiobj_release( &rec->hdr );
1423 MSI_ViewClose( view );
1424 msiobj_release( &view->hdr );
1425 return ret;
1428 static UINT get_registered_local_package( const WCHAR *product, const WCHAR *package, WCHAR *localfile )
1430 MSIINSTALLCONTEXT context;
1431 HKEY product_key, props_key;
1432 WCHAR *registered_package = NULL, unsquashed[GUID_SIZE];
1433 UINT r;
1435 r = msi_locate_product( product, &context );
1436 if (r != ERROR_SUCCESS)
1437 return r;
1439 r = MSIREG_OpenProductKey( product, NULL, context, &product_key, FALSE );
1440 if (r != ERROR_SUCCESS)
1441 return r;
1443 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1444 if (r != ERROR_SUCCESS)
1446 RegCloseKey( product_key );
1447 return r;
1449 r = ERROR_FUNCTION_FAILED;
1450 registered_package = msi_reg_get_val_str( product_key, INSTALLPROPERTY_PACKAGECODEW );
1451 if (!registered_package)
1452 goto done;
1454 unsquash_guid( registered_package, unsquashed );
1455 if (!strcmpiW( package, unsquashed ))
1457 WCHAR *filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1458 if (!filename)
1459 goto done;
1461 strcpyW( localfile, filename );
1462 msi_free( filename );
1463 r = ERROR_SUCCESS;
1465 done:
1466 msi_free( registered_package );
1467 RegCloseKey( props_key );
1468 RegCloseKey( product_key );
1469 return r;
1472 static WCHAR *get_package_code( MSIDATABASE *db )
1474 WCHAR *ret;
1475 MSISUMMARYINFO *si;
1477 if (!(si = MSI_GetSummaryInformationW( db->storage, 0 )))
1479 WARN("failed to load summary info\n");
1480 return NULL;
1482 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1483 msiobj_release( &si->hdr );
1484 return ret;
1487 static UINT get_local_package( const WCHAR *filename, WCHAR *localfile )
1489 WCHAR *product_code, *package_code;
1490 MSIDATABASE *db;
1491 UINT r;
1493 if ((r = MSI_OpenDatabaseW( filename, MSIDBOPEN_READONLY, &db )) != ERROR_SUCCESS)
1495 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1496 return ERROR_FILE_NOT_FOUND;
1497 return r;
1499 if (!(product_code = get_product_code( db )))
1501 msiobj_release( &db->hdr );
1502 return ERROR_INSTALL_PACKAGE_INVALID;
1504 if (!(package_code = get_package_code( db )))
1506 msi_free( product_code );
1507 msiobj_release( &db->hdr );
1508 return ERROR_INSTALL_PACKAGE_INVALID;
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;
1517 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
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;
1531 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1533 localfile[0] = 0;
1534 if( szPackage[0] == '#' )
1536 handle = atoiW(&szPackage[1]);
1537 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1538 if( !db )
1540 IWineMsiRemoteDatabase *remote_database;
1542 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1543 if ( !remote_database )
1544 return ERROR_INVALID_HANDLE;
1546 IWineMsiRemoteDatabase_Release( remote_database );
1547 WARN("MsiOpenPackage not allowed during a custom action!\n");
1549 return ERROR_FUNCTION_FAILED;
1552 else
1554 if ( UrlIsW( szPackage, URLIS_URL ) )
1556 r = msi_download_file( szPackage, cachefile );
1557 if (r != ERROR_SUCCESS)
1558 return r;
1560 file = cachefile;
1562 base_url = strdupW( szPackage );
1563 if (!base_url)
1564 return ERROR_OUTOFMEMORY;
1566 ptr = strrchrW( base_url, '/' );
1567 if (ptr) *(ptr + 1) = '\0';
1569 r = get_local_package( file, localfile );
1570 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1572 r = msi_create_empty_local_file( localfile, dotmsi );
1573 if (r != ERROR_SUCCESS)
1574 return r;
1576 if (!CopyFileW( file, localfile, FALSE ))
1578 r = GetLastError();
1579 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1580 DeleteFileW( localfile );
1581 return r;
1583 delete_on_close = TRUE;
1585 TRACE("opening package %s\n", debugstr_w( localfile ));
1586 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1587 if (r != ERROR_SUCCESS)
1588 return r;
1590 package = MSI_CreatePackage( db, base_url );
1591 msi_free( base_url );
1592 msiobj_release( &db->hdr );
1593 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1594 package->localfile = strdupW( localfile );
1595 package->delete_on_close = delete_on_close;
1597 si = MSI_GetSummaryInformationW( db->storage, 0 );
1598 if (!si)
1600 WARN("failed to load summary info\n");
1601 msiobj_release( &package->hdr );
1602 return ERROR_INSTALL_PACKAGE_INVALID;
1604 r = msi_parse_summary( si, package );
1605 msiobj_release( &si->hdr );
1606 if (r != ERROR_SUCCESS)
1608 WARN("failed to parse summary info %u\n", r);
1609 msiobj_release( &package->hdr );
1610 return r;
1612 r = validate_package( package );
1613 if (r != ERROR_SUCCESS)
1615 msiobj_release( &package->hdr );
1616 return r;
1618 msi_set_property( package->db, szDatabase, db->path );
1620 if( UrlIsW( szPackage, URLIS_URL ) )
1621 msi_set_property( package->db, szOriginalDatabase, szPackage );
1622 else if( szPackage[0] == '#' )
1623 msi_set_property( package->db, szOriginalDatabase, db->path );
1624 else
1626 WCHAR fullpath[MAX_PATH];
1628 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1629 msi_set_property( package->db, szOriginalDatabase, fullpath );
1631 msi_set_context( package );
1633 while (1)
1635 WCHAR patch_code[GUID_SIZE];
1636 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1637 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1638 if (r != ERROR_SUCCESS)
1639 break;
1641 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1643 r = msi_apply_registered_patch( package, patch_code );
1644 if (r != ERROR_SUCCESS)
1646 ERR("registered patch failed to apply %u\n", r);
1647 msiobj_release( &package->hdr );
1648 return r;
1650 index++;
1652 if (index)
1654 msi_clone_properties( package );
1655 msi_adjust_privilege_properties( package );
1657 if (gszLogFile)
1658 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1659 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1660 *pPackage = package;
1661 return ERROR_SUCCESS;
1664 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1666 MSIPACKAGE *package = NULL;
1667 UINT ret;
1669 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1671 if( !szPackage || !phPackage )
1672 return ERROR_INVALID_PARAMETER;
1674 if ( !*szPackage )
1676 FIXME("Should create an empty database and package\n");
1677 return ERROR_FUNCTION_FAILED;
1680 if( dwOptions )
1681 FIXME("dwOptions %08x not supported\n", dwOptions);
1683 ret = MSI_OpenPackageW( szPackage, &package );
1684 if( ret == ERROR_SUCCESS )
1686 *phPackage = alloc_msihandle( &package->hdr );
1687 if (! *phPackage)
1688 ret = ERROR_NOT_ENOUGH_MEMORY;
1689 msiobj_release( &package->hdr );
1692 return ret;
1695 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1697 return MsiOpenPackageExW( szPackage, 0, phPackage );
1700 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1702 LPWSTR szwPack = NULL;
1703 UINT ret;
1705 if( szPackage )
1707 szwPack = strdupAtoW( szPackage );
1708 if( !szwPack )
1709 return ERROR_OUTOFMEMORY;
1712 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1714 msi_free( szwPack );
1716 return ret;
1719 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1721 return MsiOpenPackageExA( szPackage, 0, phPackage );
1724 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1726 MSIPACKAGE *package;
1727 MSIHANDLE handle = 0;
1728 IUnknown *remote_unk;
1729 IWineMsiRemotePackage *remote_package;
1731 TRACE("(%d)\n",hInstall);
1733 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1734 if( package)
1736 handle = alloc_msihandle( &package->db->hdr );
1737 msiobj_release( &package->hdr );
1739 else if ((remote_unk = msi_get_remote(hInstall)))
1741 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1742 (LPVOID *)&remote_package) == S_OK)
1744 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1745 IWineMsiRemotePackage_Release(remote_package);
1747 else
1749 WARN("remote handle %d is not a package\n", hInstall);
1751 IUnknown_Release(remote_unk);
1754 return handle;
1757 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1759 static const WCHAR szActionData[] = {'A','c','t','i','o','n','D','a','t','a',0};
1760 static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1761 static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0};
1762 MSIRECORD *uirow;
1763 LPWSTR deformated, message;
1764 DWORD i, len, total_len, log_type = 0;
1765 INT rc = 0;
1766 char *msg;
1768 TRACE("%x\n", eMessageType);
1770 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_FATALEXIT)
1771 log_type |= INSTALLLOGMODE_FATALEXIT;
1772 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1773 log_type |= INSTALLLOGMODE_ERROR;
1774 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1775 log_type |= INSTALLLOGMODE_WARNING;
1776 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1777 log_type |= INSTALLLOGMODE_USER;
1778 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1779 log_type |= INSTALLLOGMODE_INFO;
1780 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE)
1781 log_type |= INSTALLLOGMODE_RESOLVESOURCE;
1782 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE)
1783 log_type |= INSTALLLOGMODE_OUTOFDISKSPACE;
1784 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1785 log_type |= INSTALLLOGMODE_COMMONDATA;
1786 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1787 log_type |= INSTALLLOGMODE_ACTIONSTART;
1788 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1789 log_type |= INSTALLLOGMODE_ACTIONDATA;
1790 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1791 log_type |= INSTALLLOGMODE_PROGRESS;
1792 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INITIALIZE)
1793 log_type |= INSTALLLOGMODE_INITIALIZE;
1794 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_TERMINATE)
1795 log_type |= INSTALLLOGMODE_TERMINATE;
1796 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_SHOWDIALOG)
1797 log_type |= INSTALLLOGMODE_SHOWDIALOG;
1799 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1801 static const WCHAR template_s[]=
1802 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1803 static const WCHAR format[] =
1804 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1805 WCHAR timet[0x100];
1806 LPCWSTR action_text, action;
1807 LPWSTR deformatted = NULL;
1809 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1811 action = MSI_RecordGetString(record, 1);
1812 action_text = MSI_RecordGetString(record, 2);
1814 if (!action || !action_text)
1815 return IDOK;
1817 deformat_string(package, action_text, &deformatted);
1819 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1820 if (deformatted)
1821 len += strlenW(deformatted);
1822 message = msi_alloc(len*sizeof(WCHAR));
1823 sprintfW(message, template_s, timet, action);
1824 if (deformatted)
1825 strcatW(message, deformatted);
1826 msi_free(deformatted);
1828 else
1830 static const WCHAR format[] = {'%','u',':',' ',0};
1831 UINT count = MSI_RecordGetFieldCount( record );
1832 WCHAR *p;
1834 total_len = 1;
1835 for (i = 1; i <= count; i++)
1837 len = 0;
1838 MSI_RecordGetStringW( record, i, NULL, &len );
1839 total_len += len + 13;
1841 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1842 if (!p) return ERROR_OUTOFMEMORY;
1844 for (i = 1; i <= count; i++)
1846 if (count > 1)
1848 len = sprintfW( p, format, i );
1849 total_len -= len;
1850 p += len;
1852 len = total_len;
1853 MSI_RecordGetStringW( record, i, p, &len );
1854 total_len -= len;
1855 p += len;
1856 if (count > 1 && total_len)
1858 *p++ = ' ';
1859 total_len--;
1862 p[0] = 0;
1865 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1866 gUIFilter, log_type, debugstr_w(message));
1868 /* convert it to ASCII */
1869 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1870 msg = msi_alloc( len );
1871 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1873 if (gUIHandlerW && (gUIFilter & log_type))
1875 rc = gUIHandlerW( gUIContext, eMessageType, message );
1877 else if (gUIHandlerA && (gUIFilter & log_type))
1879 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1881 else if (gUIHandlerRecord && (gUIFilter & log_type))
1883 MSIHANDLE rec = MsiCreateRecord( 1 );
1884 MsiRecordSetStringW( rec, 0, message );
1885 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1886 MsiCloseHandle( rec );
1889 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1890 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1892 DWORD written;
1893 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1894 WriteFile( package->log_file, "\n", 1, &written, NULL );
1896 msi_free( msg );
1897 msi_free( message );
1899 switch (eMessageType & 0xff000000)
1901 case INSTALLMESSAGE_ACTIONDATA:
1902 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1903 uirow = MSI_CreateRecord(1);
1904 MSI_RecordSetStringW(uirow, 1, deformated);
1905 msi_free(deformated);
1907 ControlEvent_FireSubscribedEvent(package, szActionData, uirow);
1908 msiobj_release(&uirow->hdr);
1910 if (package->action_progress_increment)
1912 uirow = MSI_CreateRecord(2);
1913 MSI_RecordSetInteger(uirow, 1, 2);
1914 MSI_RecordSetInteger(uirow, 2, package->action_progress_increment);
1915 ControlEvent_FireSubscribedEvent(package, szSetProgress, uirow);
1916 msiobj_release(&uirow->hdr);
1918 break;
1920 case INSTALLMESSAGE_ACTIONSTART:
1921 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1922 uirow = MSI_CreateRecord(1);
1923 MSI_RecordSetStringW(uirow, 1, deformated);
1924 msi_free(deformated);
1926 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1928 msiobj_release(&uirow->hdr);
1929 break;
1931 case INSTALLMESSAGE_PROGRESS:
1932 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1933 break;
1936 return ERROR_SUCCESS;
1939 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1940 MSIHANDLE hRecord)
1942 UINT ret = ERROR_INVALID_HANDLE;
1943 MSIPACKAGE *package = NULL;
1944 MSIRECORD *record = NULL;
1946 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1947 if( !package )
1949 HRESULT hr;
1950 IWineMsiRemotePackage *remote_package;
1952 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1953 if (!remote_package)
1954 return ERROR_INVALID_HANDLE;
1956 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1958 IWineMsiRemotePackage_Release( remote_package );
1960 if (FAILED(hr))
1962 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1963 return HRESULT_CODE(hr);
1965 return ERROR_FUNCTION_FAILED;
1968 return ERROR_SUCCESS;
1971 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1972 if( !record )
1973 goto out;
1975 ret = MSI_ProcessMessage( package, eMessageType, record );
1977 out:
1978 msiobj_release( &package->hdr );
1979 if( record )
1980 msiobj_release( &record->hdr );
1982 return ret;
1985 /* property code */
1987 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1989 LPWSTR szwName = NULL, szwValue = NULL;
1990 UINT r = ERROR_OUTOFMEMORY;
1992 szwName = strdupAtoW( szName );
1993 if( szName && !szwName )
1994 goto end;
1996 szwValue = strdupAtoW( szValue );
1997 if( szValue && !szwValue )
1998 goto end;
2000 r = MsiSetPropertyW( hInstall, szwName, szwValue);
2002 end:
2003 msi_free( szwName );
2004 msi_free( szwValue );
2006 return r;
2009 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
2011 MSIFOLDER *folder;
2013 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
2015 if ( source )
2017 msi_free( folder->ResolvedSource );
2018 folder->ResolvedSource = NULL;
2020 else
2022 msi_free( folder->ResolvedTarget );
2023 folder->ResolvedTarget = NULL;
2028 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
2030 static const WCHAR insert_query[] = {
2031 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2032 '`','_','P','r','o','p','e','r','t','y','`',' ',
2033 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2034 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2035 static const WCHAR update_query[] = {
2036 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2037 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2038 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2039 static const WCHAR delete_query[] = {
2040 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2041 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2042 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2043 MSIQUERY *view;
2044 MSIRECORD *row = NULL;
2045 DWORD sz = 0;
2046 WCHAR query[1024];
2047 UINT rc;
2049 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
2051 if (!szName)
2052 return ERROR_INVALID_PARAMETER;
2054 /* this one is weird... */
2055 if (!szName[0])
2056 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2058 rc = msi_get_property(db, szName, 0, &sz);
2059 if (!szValue || !*szValue)
2061 sprintfW(query, delete_query, szName);
2063 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2065 sprintfW(query, update_query, szName);
2067 row = MSI_CreateRecord(1);
2068 MSI_RecordSetStringW(row, 1, szValue);
2070 else
2072 strcpyW(query, insert_query);
2074 row = MSI_CreateRecord(2);
2075 MSI_RecordSetStringW(row, 1, szName);
2076 MSI_RecordSetStringW(row, 2, szValue);
2079 rc = MSI_DatabaseOpenViewW(db, query, &view);
2080 if (rc == ERROR_SUCCESS)
2082 rc = MSI_ViewExecute(view, row);
2083 MSI_ViewClose(view);
2084 msiobj_release(&view->hdr);
2086 if (row) msiobj_release(&row->hdr);
2087 return rc;
2090 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2092 MSIPACKAGE *package;
2093 UINT ret;
2095 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2096 if( !package )
2098 HRESULT hr;
2099 BSTR name = NULL, value = NULL;
2100 IWineMsiRemotePackage *remote_package;
2102 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2103 if (!remote_package)
2104 return ERROR_INVALID_HANDLE;
2106 name = SysAllocString( szName );
2107 value = SysAllocString( szValue );
2108 if ((!name && szName) || (!value && szValue))
2110 SysFreeString( name );
2111 SysFreeString( value );
2112 IWineMsiRemotePackage_Release( remote_package );
2113 return ERROR_OUTOFMEMORY;
2116 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2118 SysFreeString( name );
2119 SysFreeString( value );
2120 IWineMsiRemotePackage_Release( remote_package );
2122 if (FAILED(hr))
2124 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2125 return HRESULT_CODE(hr);
2127 return ERROR_FUNCTION_FAILED;
2130 return ERROR_SUCCESS;
2133 ret = msi_set_property( package->db, szName, szValue );
2134 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2135 msi_reset_folders( package, TRUE );
2137 msiobj_release( &package->hdr );
2138 return ret;
2141 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2143 static const WCHAR query[]= {
2144 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2145 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2146 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2147 MSIRECORD *rec, *row = NULL;
2148 MSIQUERY *view;
2149 UINT r;
2151 if (!name || !*name)
2152 return NULL;
2154 rec = MSI_CreateRecord(1);
2155 if (!rec)
2156 return NULL;
2158 MSI_RecordSetStringW(rec, 1, name);
2160 r = MSI_DatabaseOpenViewW(db, query, &view);
2161 if (r == ERROR_SUCCESS)
2163 MSI_ViewExecute(view, rec);
2164 MSI_ViewFetch(view, &row);
2165 MSI_ViewClose(view);
2166 msiobj_release(&view->hdr);
2168 msiobj_release(&rec->hdr);
2169 return row;
2172 /* internal function, not compatible with MsiGetPropertyW */
2173 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2174 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2176 MSIRECORD *row;
2177 UINT rc = ERROR_FUNCTION_FAILED;
2179 row = msi_get_property_row( db, szName );
2181 if (*pchValueBuf > 0)
2182 szValueBuf[0] = 0;
2184 if (row)
2186 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2187 msiobj_release(&row->hdr);
2190 if (rc == ERROR_SUCCESS)
2191 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2192 debugstr_w(szName));
2193 else if (rc == ERROR_MORE_DATA)
2194 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2195 debugstr_w(szName));
2196 else
2198 *pchValueBuf = 0;
2199 TRACE("property %s not found\n", debugstr_w(szName));
2202 return rc;
2205 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2207 DWORD sz = 0;
2208 LPWSTR str;
2209 UINT r;
2211 r = msi_get_property(db, prop, NULL, &sz);
2212 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2213 return NULL;
2215 sz++;
2216 str = msi_alloc(sz * sizeof(WCHAR));
2217 r = msi_get_property(db, prop, str, &sz);
2218 if (r != ERROR_SUCCESS)
2220 msi_free(str);
2221 str = NULL;
2224 return str;
2227 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2229 LPWSTR str = msi_dup_property( db, prop );
2230 int val = str ? atoiW(str) : def;
2231 msi_free(str);
2232 return val;
2235 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2236 awstring *szValueBuf, LPDWORD pchValueBuf )
2238 MSIPACKAGE *package;
2239 MSIRECORD *row = NULL;
2240 UINT r = ERROR_FUNCTION_FAILED;
2241 LPCWSTR val = NULL;
2243 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2244 szValueBuf->str.w, pchValueBuf );
2246 if (!name)
2247 return ERROR_INVALID_PARAMETER;
2249 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2250 if (!package)
2252 HRESULT hr;
2253 IWineMsiRemotePackage *remote_package;
2254 LPWSTR value = NULL;
2255 BSTR bname;
2256 DWORD len;
2258 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2259 if (!remote_package)
2260 return ERROR_INVALID_HANDLE;
2262 bname = SysAllocString( name );
2263 if (!bname)
2265 IWineMsiRemotePackage_Release( remote_package );
2266 return ERROR_OUTOFMEMORY;
2269 len = 0;
2270 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2271 if (FAILED(hr))
2272 goto done;
2274 len++;
2275 value = msi_alloc(len * sizeof(WCHAR));
2276 if (!value)
2278 r = ERROR_OUTOFMEMORY;
2279 goto done;
2282 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, value, &len );
2283 if (FAILED(hr))
2284 goto done;
2286 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2288 /* Bug required by Adobe installers */
2289 if (!szValueBuf->unicode && !szValueBuf->str.a)
2290 *pchValueBuf *= sizeof(WCHAR);
2292 done:
2293 IWineMsiRemotePackage_Release(remote_package);
2294 SysFreeString(bname);
2295 msi_free(value);
2297 if (FAILED(hr))
2299 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2300 return HRESULT_CODE(hr);
2302 return ERROR_FUNCTION_FAILED;
2305 return r;
2308 row = msi_get_property_row( package->db, name );
2309 if (row)
2310 val = MSI_RecordGetString( row, 1 );
2312 if (!val)
2313 val = szEmpty;
2315 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2317 if (row)
2318 msiobj_release( &row->hdr );
2319 msiobj_release( &package->hdr );
2321 return r;
2324 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2325 LPSTR szValueBuf, LPDWORD pchValueBuf )
2327 awstring val;
2328 LPWSTR name;
2329 UINT r;
2331 val.unicode = FALSE;
2332 val.str.a = szValueBuf;
2334 name = strdupAtoW( szName );
2335 if (szName && !name)
2336 return ERROR_OUTOFMEMORY;
2338 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2339 msi_free( name );
2340 return r;
2343 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2344 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2346 awstring val;
2348 val.unicode = TRUE;
2349 val.str.w = szValueBuf;
2351 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2354 typedef struct _msi_remote_package_impl {
2355 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2356 MSIHANDLE package;
2357 LONG refs;
2358 } msi_remote_package_impl;
2360 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2362 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2365 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2366 REFIID riid,LPVOID *ppobj)
2368 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2369 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2371 IUnknown_AddRef( iface );
2372 *ppobj = iface;
2373 return S_OK;
2376 return E_NOINTERFACE;
2379 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2381 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2383 return InterlockedIncrement( &This->refs );
2386 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2388 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2389 ULONG r;
2391 r = InterlockedDecrement( &This->refs );
2392 if (r == 0)
2394 MsiCloseHandle( This->package );
2395 msi_free( This );
2397 return r;
2400 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2402 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2403 This->package = handle;
2404 return S_OK;
2407 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2409 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2410 IWineMsiRemoteDatabase *rdb = NULL;
2411 HRESULT hr;
2412 MSIHANDLE hdb;
2414 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2415 if (FAILED(hr) || !rdb)
2417 ERR("Failed to create remote database\n");
2418 return hr;
2421 hdb = MsiGetActiveDatabase(This->package);
2423 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2424 if (FAILED(hr))
2426 ERR("Failed to set the database handle\n");
2427 return hr;
2430 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2431 return S_OK;
2434 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value, DWORD *size )
2436 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2437 UINT r = MsiGetPropertyW(This->package, property, value, size);
2438 if (r != ERROR_SUCCESS) return HRESULT_FROM_WIN32(r);
2439 return S_OK;
2442 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2444 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2445 UINT r = MsiSetPropertyW(This->package, property, value);
2446 return HRESULT_FROM_WIN32(r);
2449 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2451 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2452 UINT r = MsiProcessMessage(This->package, message, record);
2453 return HRESULT_FROM_WIN32(r);
2456 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2458 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2459 UINT r = MsiDoActionW(This->package, action);
2460 return HRESULT_FROM_WIN32(r);
2463 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2465 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2466 UINT r = MsiSequenceW(This->package, table, sequence);
2467 return HRESULT_FROM_WIN32(r);
2470 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2472 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2473 UINT r = MsiGetTargetPathW(This->package, folder, value, size);
2474 return HRESULT_FROM_WIN32(r);
2477 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2479 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2480 UINT r = MsiSetTargetPathW(This->package, folder, value);
2481 return HRESULT_FROM_WIN32(r);
2484 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2486 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2487 UINT r = MsiGetSourcePathW(This->package, folder, value, size);
2488 return HRESULT_FROM_WIN32(r);
2491 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2493 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2494 *ret = MsiGetMode(This->package, mode);
2495 return S_OK;
2498 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2500 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2501 UINT r = MsiSetMode(This->package, mode, state);
2502 return HRESULT_FROM_WIN32(r);
2505 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2506 INSTALLSTATE *installed, INSTALLSTATE *action )
2508 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2509 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2510 return HRESULT_FROM_WIN32(r);
2513 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2515 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2516 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2517 return HRESULT_FROM_WIN32(r);
2520 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2521 INSTALLSTATE *installed, INSTALLSTATE *action )
2523 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2524 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2525 return HRESULT_FROM_WIN32(r);
2528 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2530 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2531 UINT r = MsiSetComponentStateW(This->package, component, state);
2532 return HRESULT_FROM_WIN32(r);
2535 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2537 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2538 *language = MsiGetLanguage(This->package);
2539 return S_OK;
2542 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2544 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2545 UINT r = MsiSetInstallLevel(This->package, level);
2546 return HRESULT_FROM_WIN32(r);
2549 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2550 BSTR *value)
2552 DWORD size = 0;
2553 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2554 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2555 if (r == ERROR_SUCCESS)
2557 *value = SysAllocStringLen(NULL, size);
2558 if (!*value)
2559 return E_OUTOFMEMORY;
2560 size++;
2561 r = MsiFormatRecordW(This->package, record, *value, &size);
2563 return HRESULT_FROM_WIN32(r);
2566 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2568 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2569 UINT r = MsiEvaluateConditionW(This->package, condition);
2570 return HRESULT_FROM_WIN32(r);
2573 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2574 INT cost_tree, INSTALLSTATE state, INT *cost )
2576 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2577 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2578 return HRESULT_FROM_WIN32(r);
2581 static HRESULT WINAPI mrp_EnumComponentCosts( IWineMsiRemotePackage *iface, BSTR component,
2582 DWORD index, INSTALLSTATE state, BSTR drive,
2583 DWORD *buflen, INT *cost, INT *temp )
2585 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2586 UINT r = MsiEnumComponentCostsW(This->package, component, index, state, drive, buflen, cost, temp);
2587 return HRESULT_FROM_WIN32(r);
2590 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2592 mrp_QueryInterface,
2593 mrp_AddRef,
2594 mrp_Release,
2595 mrp_SetMsiHandle,
2596 mrp_GetActiveDatabase,
2597 mrp_GetProperty,
2598 mrp_SetProperty,
2599 mrp_ProcessMessage,
2600 mrp_DoAction,
2601 mrp_Sequence,
2602 mrp_GetTargetPath,
2603 mrp_SetTargetPath,
2604 mrp_GetSourcePath,
2605 mrp_GetMode,
2606 mrp_SetMode,
2607 mrp_GetFeatureState,
2608 mrp_SetFeatureState,
2609 mrp_GetComponentState,
2610 mrp_SetComponentState,
2611 mrp_GetLanguage,
2612 mrp_SetInstallLevel,
2613 mrp_FormatRecord,
2614 mrp_EvaluateCondition,
2615 mrp_GetFeatureCost,
2616 mrp_EnumComponentCosts
2619 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2621 msi_remote_package_impl* This;
2623 This = msi_alloc( sizeof *This );
2624 if (!This)
2625 return E_OUTOFMEMORY;
2627 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2628 This->package = 0;
2629 This->refs = 1;
2631 *ppObj = This;
2633 return S_OK;
2636 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2637 LPCWSTR property, LPWSTR value)
2639 MSISOURCELISTINFO *info;
2641 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2643 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2646 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2647 if (!info)
2648 return ERROR_OUTOFMEMORY;
2650 info->context = context;
2651 info->options = options;
2652 info->property = property;
2653 info->value = strdupW(value);
2654 list_add_head(&package->sourcelist_info, &info->entry);
2656 return ERROR_SUCCESS;
2659 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2660 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2662 MSIMEDIADISK *disk;
2664 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2666 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2669 disk = msi_alloc(sizeof(MSIMEDIADISK));
2670 if (!disk)
2671 return ERROR_OUTOFMEMORY;
2673 disk->context = context;
2674 disk->options = options;
2675 disk->disk_id = disk_id;
2676 disk->volume_label = strdupW(volume_label);
2677 disk->disk_prompt = strdupW(disk_prompt);
2678 list_add_head(&package->sourcelist_media, &disk->entry);
2680 return ERROR_SUCCESS;