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
32 #include "wine/debug.h"
42 #include "wine/unicode.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 if (!DeleteFileW( temp->Path ))
63 ERR("failed to delete %s\n", debugstr_w( temp->Path ));
64 msi_free( temp->Path );
69 static void free_feature( MSIFEATURE *feature )
71 struct list *item, *cursor;
73 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
75 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
76 list_remove( &fl->entry );
80 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
82 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
83 list_remove( &cl->entry );
86 msi_free( feature->Feature );
87 msi_free( feature->Feature_Parent );
88 msi_free( feature->Directory );
89 msi_free( feature->Description );
90 msi_free( feature->Title );
94 static void free_extension( MSIEXTENSION *ext )
96 struct list *item, *cursor;
98 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
100 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
102 list_remove( &verb->entry );
103 msi_free( verb->Verb );
104 msi_free( verb->Command );
105 msi_free( verb->Argument );
109 msi_free( ext->Extension );
110 msi_free( ext->ProgIDText );
114 static void free_package_structures( MSIPACKAGE *package )
117 struct list *item, *cursor;
119 TRACE("Freeing package action data\n");
121 remove_tracked_tempfiles(package);
123 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
125 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
126 list_remove( &feature->entry );
127 free_feature( feature );
130 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
132 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
134 list_remove( &folder->entry );
135 msi_free( folder->Parent );
136 msi_free( folder->Directory );
137 msi_free( folder->TargetDefault );
138 msi_free( folder->SourceLongPath );
139 msi_free( folder->SourceShortPath );
140 msi_free( folder->ResolvedTarget );
141 msi_free( folder->ResolvedSource );
142 msi_free( folder->Property );
146 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
148 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
150 list_remove( &comp->entry );
151 msi_free( comp->Component );
152 msi_free( comp->ComponentId );
153 msi_free( comp->Directory );
154 msi_free( comp->Condition );
155 msi_free( comp->KeyPath );
156 msi_free( comp->FullKeypath );
160 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
162 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
164 list_remove( &file->entry );
165 msi_free( file->File );
166 msi_free( file->FileName );
167 msi_free( file->ShortName );
168 msi_free( file->LongName );
169 msi_free( file->Version );
170 msi_free( file->Language );
171 msi_free( file->TargetPath );
175 /* clean up extension, progid, class and verb structures */
176 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
178 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
180 list_remove( &cls->entry );
181 msi_free( cls->clsid );
182 msi_free( cls->Context );
183 msi_free( cls->Description );
184 msi_free( cls->FileTypeMask );
185 msi_free( cls->IconPath );
186 msi_free( cls->DefInprocHandler );
187 msi_free( cls->DefInprocHandler32 );
188 msi_free( cls->Argument );
189 msi_free( cls->ProgIDText );
193 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
195 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
197 list_remove( &ext->entry );
198 free_extension( ext );
201 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
203 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
205 list_remove( &progid->entry );
206 msi_free( progid->ProgID );
207 msi_free( progid->Description );
208 msi_free( progid->IconPath );
212 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
214 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
216 list_remove( &mt->entry );
217 msi_free( mt->suffix );
218 msi_free( mt->clsid );
219 msi_free( mt->ContentType );
223 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
225 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
227 list_remove( &appid->entry );
228 msi_free( appid->AppID );
229 msi_free( appid->RemoteServerName );
230 msi_free( appid->LocalServer );
231 msi_free( appid->ServiceParameters );
232 msi_free( appid->DllSurrogate );
236 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
238 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
240 list_remove( &info->entry );
241 msi_free( info->value );
245 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
247 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
249 list_remove( &info->entry );
250 msi_free( info->volume_label );
251 msi_free( info->disk_prompt );
257 for (i = 0; i < TOTAL_SCRIPTS; i++)
258 msi_free_action_script( package, i );
260 for (i = 0; i < package->script->UniqueActionsCount; i++)
261 msi_free( package->script->UniqueActions[i] );
263 msi_free( package->script->UniqueActions );
264 msi_free( package->script );
267 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
269 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
271 list_remove( &patch->entry );
272 msi_free( patch->patchcode );
273 msi_free( patch->transforms );
274 msi_free( patch->localfile );
278 msi_free( package->BaseURL );
279 msi_free( package->PackagePath );
280 msi_free( package->ProductCode );
281 msi_free( package->ActionFormat );
282 msi_free( package->LastAction );
283 msi_free( package->langids );
285 /* cleanup control event subscriptions */
286 ControlEvent_CleanupSubscriptions( package );
289 static void MSI_FreePackage( MSIOBJECTHDR *arg)
291 MSIPACKAGE *package= (MSIPACKAGE*) arg;
293 if( package->dialog )
294 msi_dialog_destroy( package->dialog );
296 msiobj_release( &package->db->hdr );
297 free_package_structures(package);
300 static UINT create_temp_property_table(MSIPACKAGE *package)
302 MSIQUERY *view = NULL;
305 static const WCHAR CreateSql[] = {
306 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
307 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
308 '`','_','P','r','o','p','e','r','t','y','`',' ',
309 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
310 'T','E','M','P','O','R','A','R','Y',',',' ',
311 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
312 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
313 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
314 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
316 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
317 if (rc != ERROR_SUCCESS)
320 rc = MSI_ViewExecute(view, 0);
322 msiobj_release(&view->hdr);
326 UINT msi_clone_properties(MSIPACKAGE *package)
328 MSIQUERY *view_select = NULL;
331 static const WCHAR query_select[] = {
332 'S','E','L','E','C','T',' ','*',' ',
333 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
334 static const WCHAR query_insert[] = {
335 'I','N','S','E','R','T',' ','i','n','t','o',' ',
336 '`','_','P','r','o','p','e','r','t','y','`',' ',
337 '(','`','_','P','r','o','p','e','r','t','y','`',',',
338 '`','V','a','l','u','e','`',')',' ',
339 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
340 static const WCHAR query_update[] = {
341 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
342 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
343 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
345 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
346 if (rc != ERROR_SUCCESS)
349 rc = MSI_ViewExecute( view_select, 0 );
350 if (rc != ERROR_SUCCESS)
352 MSI_ViewClose( view_select );
353 msiobj_release( &view_select->hdr );
359 MSIQUERY *view_insert, *view_update;
360 MSIRECORD *rec_select;
362 rc = MSI_ViewFetch( view_select, &rec_select );
363 if (rc != ERROR_SUCCESS)
366 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
367 if (rc != ERROR_SUCCESS)
369 msiobj_release( &rec_select->hdr );
373 rc = MSI_ViewExecute( view_insert, rec_select );
374 MSI_ViewClose( view_insert );
375 msiobj_release( &view_insert->hdr );
376 if (rc != ERROR_SUCCESS)
378 MSIRECORD *rec_update;
380 TRACE("insert failed, trying update\n");
382 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
383 if (rc != ERROR_SUCCESS)
385 WARN("open view failed %u\n", rc);
386 msiobj_release( &rec_select->hdr );
390 rec_update = MSI_CreateRecord( 2 );
391 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
392 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
393 rc = MSI_ViewExecute( view_update, rec_update );
394 if (rc != ERROR_SUCCESS)
395 WARN("update failed %u\n", rc);
397 MSI_ViewClose( view_update );
398 msiobj_release( &view_update->hdr );
399 msiobj_release( &rec_update->hdr );
402 msiobj_release( &rec_select->hdr );
405 MSI_ViewClose( view_select );
406 msiobj_release( &view_select->hdr );
413 * Sets the "Installed" property to indicate that
414 * the product is installed for the current user.
416 static UINT set_installed_prop( MSIPACKAGE *package )
421 r = MSIREG_OpenUninstallKey( package, &hkey, FALSE );
422 if (r == ERROR_SUCCESS)
425 msi_set_property( package->db, szInstalled, szOne );
431 static UINT set_user_sid_prop( MSIPACKAGE *package )
435 LPWSTR sid_str = NULL, dom = NULL;
436 DWORD size, dom_size;
438 UINT r = ERROR_FUNCTION_FAILED;
441 GetUserNameW( NULL, &size );
443 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
445 return ERROR_OUTOFMEMORY;
447 if (!GetUserNameW( user_name, &size ))
452 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
454 psid = msi_alloc( size );
455 dom = msi_alloc( dom_size*sizeof (WCHAR) );
458 r = ERROR_OUTOFMEMORY;
462 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
465 if (!ConvertSidToStringSidW( psid, &sid_str ))
468 r = msi_set_property( package->db, szUserSID, sid_str );
471 LocalFree( sid_str );
474 msi_free( user_name );
479 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
484 DWORD index = 0, size;
486 WCHAR name[MAX_PATH];
487 WCHAR windir[MAX_PATH];
489 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
490 static const WCHAR sub[] = {
491 'S','o','f','t','w','a','r','e','\\',
492 'M','i','c','r','o','s','o','f','t','\\',
493 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
496 static const WCHAR subdir[] = {
497 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
498 'F','r','a','m','e','w','o','r','k','\\',0
501 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
502 if (res != ERROR_SUCCESS)
505 GetWindowsDirectoryW(windir, MAX_PATH);
509 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
513 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
514 if (strcmpW( ver, name ) < 0)
517 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
518 check = msi_alloc(size * sizeof(WCHAR));
526 lstrcpyW(check, windir);
527 lstrcatW(check, szBackSlash);
528 lstrcatW(check, subdir);
529 lstrcatW(check, name);
530 lstrcatW(check, szBackSlash);
531 lstrcatW(check, fusion);
533 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
544 RegCloseKey(netsetup);
548 typedef struct tagLANGANDCODEPAGE
554 static void set_msi_assembly_prop(MSIPACKAGE *package)
558 LPVOID version = NULL;
560 LPWSTR fusion, verstr;
561 LANGANDCODEPAGE *translate;
563 static const WCHAR netasm[] = {
564 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
566 static const WCHAR translation[] = {
567 '\\','V','a','r','F','i','l','e','I','n','f','o',
568 '\\','T','r','a','n','s','l','a','t','i','o','n',0
570 static const WCHAR verfmt[] = {
571 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
572 '\\','%','0','4','x','%','0','4','x',
573 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
576 fusion = get_fusion_filename(package);
580 size = GetFileVersionInfoSizeW(fusion, &handle);
583 version = msi_alloc(size);
584 if (!version) return;
586 if (!GetFileVersionInfoW(fusion, handle, size, version))
589 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
592 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
594 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
597 if (!val_len || !verstr)
600 msi_set_property(package->db, netasm, verstr);
607 static VOID set_installer_properties(MSIPACKAGE *package)
611 OSVERSIONINFOEXW OSVersion;
614 WCHAR verstr[10], bufstr[20];
617 LPWSTR username, companyname;
618 SYSTEM_INFO sys_info;
619 SYSTEMTIME systemtime;
622 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
623 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
624 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
625 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
626 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
627 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
628 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
629 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
630 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
631 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
632 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
633 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
634 static const WCHAR szAppDataFolder[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
635 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
636 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
637 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
638 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
639 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
640 static const WCHAR szWindowsFolder[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
641 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
642 static const WCHAR szTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
643 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
644 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
645 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
646 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
647 static const WCHAR szFormat[] = {'%','l','i',0};
648 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
649 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
650 static const WCHAR szSix[] = {'6',0 };
651 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
652 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
653 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
654 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
655 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
656 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
657 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
658 static const WCHAR szIntFormat[] = {'%','d',0};
659 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
660 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
661 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
662 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
663 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 };
664 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
665 static const WCHAR szUserInfo[] = {
666 'S','O','F','T','W','A','R','E','\\',
667 'M','i','c','r','o','s','o','f','t','\\',
668 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
669 'U','s','e','r',' ','I','n','f','o',0
671 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
672 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
673 static const WCHAR szCurrentVersion[] = {
674 'S','O','F','T','W','A','R','E','\\',
675 'M','i','c','r','o','s','o','f','t','\\',
676 'W','i','n','d','o','w','s',' ','N','T','\\',
677 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
679 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
680 static const WCHAR szRegisteredOrganization[] = {
681 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
683 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
684 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
685 static const WCHAR szDate[] = {'D','a','t','e',0};
686 static const WCHAR szTime[] = {'T','i','m','e',0};
687 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
688 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
689 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
690 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
691 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
692 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
693 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
696 * Other things that probably should be set:
698 * ComputerName VirtualMemory
699 * ShellAdvSupport DefaultUIFont PackagecodeChanging
700 * CaptionHeight BorderTop BorderSide TextHeight
701 * RedirectedDllSupport
704 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
705 strcatW(pth, szBackSlash);
706 msi_set_property(package->db, szCommonAppDataFolder, pth);
708 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
709 strcatW(pth, szBackSlash);
710 msi_set_property(package->db, szFavoritesFolder, pth);
712 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
713 strcatW(pth, szBackSlash);
714 msi_set_property(package->db, szFontsFolder, pth);
716 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
717 strcatW(pth, szBackSlash);
718 msi_set_property(package->db, szSendToFolder, pth);
720 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
721 strcatW(pth, szBackSlash);
722 msi_set_property(package->db, szStartMenuFolder, pth);
724 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
725 strcatW(pth, szBackSlash);
726 msi_set_property(package->db, szStartupFolder, pth);
728 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
729 strcatW(pth, szBackSlash);
730 msi_set_property(package->db, szTemplateFolder, pth);
732 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
733 strcatW(pth, szBackSlash);
734 msi_set_property(package->db, szDesktopFolder, pth);
736 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
737 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
738 strcatW(pth, szBackSlash);
739 msi_set_property(package->db, szProgramMenuFolder, pth);
741 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
742 strcatW(pth, szBackSlash);
743 msi_set_property(package->db, szAdminToolsFolder, pth);
745 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
746 strcatW(pth, szBackSlash);
747 msi_set_property(package->db, szAppDataFolder, pth);
749 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
750 strcatW(pth, szBackSlash);
751 msi_set_property(package->db, szSystemFolder, pth);
752 msi_set_property(package->db, szSystem16Folder, pth);
754 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
755 strcatW(pth, szBackSlash);
756 msi_set_property(package->db, szLocalAppDataFolder, pth);
758 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
759 strcatW(pth, szBackSlash);
760 msi_set_property(package->db, szMyPicturesFolder, pth);
762 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
763 strcatW(pth, szBackSlash);
764 msi_set_property(package->db, szPersonalFolder, pth);
766 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
767 strcatW(pth, szBackSlash);
768 msi_set_property(package->db, szWindowsFolder, pth);
770 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
771 strcatW(pth, szBackSlash);
772 msi_set_property(package->db, szPrintHoodFolder, pth);
774 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
775 strcatW(pth, szBackSlash);
776 msi_set_property(package->db, szNetHoodFolder, pth);
778 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
779 strcatW(pth, szBackSlash);
780 msi_set_property(package->db, szRecentFolder, pth);
782 /* Physical Memory is specified in MB. Using total amount. */
783 msex.dwLength = sizeof(msex);
784 GlobalMemoryStatusEx( &msex );
785 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
786 msi_set_property(package->db, szPhysicalMemory, bufstr);
788 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
789 ptr = strchrW(pth,'\\');
790 if (ptr) *(ptr + 1) = 0;
791 msi_set_property(package->db, szWindowsVolume, pth);
793 GetTempPathW(MAX_PATH,pth);
794 msi_set_property(package->db, szTempFolder, pth);
796 /* in a wine environment the user is always admin and privileged */
797 msi_set_property(package->db, szAdminUser, szOne);
798 msi_set_property(package->db, szPrivileged, szOne);
800 /* set the os things */
801 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
802 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
803 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
804 sprintfW(verstr, szFormat, verval);
805 switch (OSVersion.dwPlatformId)
807 case VER_PLATFORM_WIN32_WINDOWS:
808 msi_set_property(package->db, szVersion9x, verstr);
810 case VER_PLATFORM_WIN32_NT:
811 msi_set_property(package->db, szVersionNT, verstr);
812 sprintfW(verstr, szFormat,OSVersion.wProductType);
813 msi_set_property(package->db, szMsiNTProductType, verstr);
816 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
817 msi_set_property(package->db, szWindowsBuild, verstr);
818 /* just fudge this */
819 msi_set_property(package->db, szServicePackLevel, szSix);
821 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
822 msi_set_property( package->db, szVersionMsi, bufstr );
823 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
824 msi_set_property( package->db, szVersionDatabase, bufstr );
826 GetNativeSystemInfo( &sys_info );
827 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
828 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
830 msi_set_property( package->db, szIntel, bufstr );
832 GetSystemDirectoryW( pth, MAX_PATH );
833 PathAddBackslashW( pth );
834 msi_set_property( package->db, szSystemFolder, pth );
836 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
837 PathAddBackslashW( pth );
838 msi_set_property( package->db, szProgramFilesFolder, pth );
840 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
841 PathAddBackslashW( pth );
842 msi_set_property( package->db, szCommonFilesFolder, pth );
844 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
846 msi_set_property( package->db, szMsiAMD64, bufstr );
847 msi_set_property( package->db, szMsix64, bufstr );
848 msi_set_property( package->db, szVersionNT64, verstr );
850 GetSystemDirectoryW( pth, MAX_PATH );
851 PathAddBackslashW( pth );
852 msi_set_property( package->db, szSystem64Folder, pth );
854 GetSystemWow64DirectoryW( pth, MAX_PATH );
855 PathAddBackslashW( pth );
856 msi_set_property( package->db, szSystemFolder, pth );
858 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
859 PathAddBackslashW( pth );
860 msi_set_property( package->db, szProgramFiles64Folder, pth );
862 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
863 PathAddBackslashW( pth );
864 msi_set_property( package->db, szProgramFilesFolder, pth );
866 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
867 PathAddBackslashW( pth );
868 msi_set_property( package->db, szCommonFiles64Folder, pth );
870 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
871 PathAddBackslashW( pth );
872 msi_set_property( package->db, szCommonFilesFolder, pth );
875 /* Screen properties. */
877 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
878 msi_set_property( package->db, szScreenX, bufstr );
879 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
880 msi_set_property( package->db, szScreenY, bufstr );
881 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
882 msi_set_property( package->db, szColorBits, bufstr );
885 /* USERNAME and COMPANYNAME */
886 username = msi_dup_property( package->db, szUSERNAME );
887 companyname = msi_dup_property( package->db, szCOMPANYNAME );
889 if ((!username || !companyname) &&
890 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
893 (username = msi_reg_get_val_str( hkey, szDefName )))
894 msi_set_property( package->db, szUSERNAME, username );
896 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
897 msi_set_property( package->db, szCOMPANYNAME, companyname );
900 if ((!username || !companyname) &&
901 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
904 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
905 msi_set_property( package->db, szUSERNAME, username );
907 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
908 msi_set_property( package->db, szCOMPANYNAME, companyname );
911 msi_free( username );
912 msi_free( companyname );
914 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
915 ERR("Failed to set the UserSID property\n");
917 /* Date and time properties */
918 GetSystemTime( &systemtime );
919 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
920 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
921 msi_set_property( package->db, szDate, bufstr );
923 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
925 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
926 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
927 &systemtime, NULL, bufstr,
928 sizeof(bufstr)/sizeof(bufstr[0]) ))
929 msi_set_property( package->db, szTime, bufstr );
931 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
933 set_msi_assembly_prop( package );
935 langid = GetUserDefaultLangID();
936 sprintfW(bufstr, szIntFormat, langid);
937 msi_set_property( package->db, szUserLanguageID, bufstr );
939 langid = GetSystemDefaultLangID();
940 sprintfW(bufstr, szIntFormat, langid);
941 msi_set_property( package->db, szSystemLangID, bufstr );
943 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
944 msi_set_property( package->db, szProductState, bufstr );
947 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_MORE_DATA)
950 if ((username = msi_alloc( len * sizeof(WCHAR) )))
952 if (GetUserNameW( username, &len ))
953 msi_set_property( package->db, szLogonUser, username );
954 msi_free( username );
959 static UINT msi_load_summary_properties( MSIPACKAGE *package )
963 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
967 static const WCHAR szPackageCode[] = {
968 'P','a','c','k','a','g','e','C','o','d','e',0};
971 ERR("Unable to allocate handle\n");
972 return ERROR_OUTOFMEMORY;
975 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
977 if (rc != ERROR_SUCCESS)
979 ERR("Unable to open Summary Information\n");
983 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
984 &count, NULL, NULL, NULL );
985 if (rc != ERROR_SUCCESS)
987 WARN("Unable to query page count: %d\n", rc);
991 /* load package code property */
993 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
994 NULL, NULL, NULL, &len );
995 if (rc != ERROR_MORE_DATA)
997 WARN("Unable to query revision number: %d\n", rc);
998 rc = ERROR_FUNCTION_FAILED;
1003 package_code = msi_alloc( len * sizeof(WCHAR) );
1004 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1005 NULL, NULL, package_code, &len );
1006 if (rc != ERROR_SUCCESS)
1008 WARN("Unable to query rev number: %d\n", rc);
1012 msi_set_property( package->db, szPackageCode, package_code );
1013 msi_free( package_code );
1015 /* load package attributes */
1017 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1018 &count, NULL, NULL, NULL );
1019 package->WordCount = count;
1022 MsiCloseHandle(suminfo);
1026 static MSIPACKAGE *msi_alloc_package( void )
1028 MSIPACKAGE *package;
1030 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1034 list_init( &package->components );
1035 list_init( &package->features );
1036 list_init( &package->files );
1037 list_init( &package->tempfiles );
1038 list_init( &package->folders );
1039 list_init( &package->subscriptions );
1040 list_init( &package->appids );
1041 list_init( &package->classes );
1042 list_init( &package->mimes );
1043 list_init( &package->extensions );
1044 list_init( &package->progids );
1045 list_init( &package->RunningActions );
1046 list_init( &package->sourcelist_info );
1047 list_init( &package->sourcelist_media );
1048 list_init( &package->patches );
1054 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1059 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1061 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1062 if (r != ERROR_SUCCESS)
1065 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1071 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1073 /* FIXME: this should depend on the user's privileges */
1074 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1076 TRACE("resetting ALLUSERS property from 2 to 1\n");
1077 msi_set_property( package->db, szAllUsers, szOne );
1079 msi_set_property( package->db, szAdminUser, szOne );
1082 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1084 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
1085 static const WCHAR szpi[] = {'%','i',0};
1086 MSIPACKAGE *package;
1092 package = msi_alloc_package();
1095 msiobj_addref( &db->hdr );
1098 package->WordCount = 0;
1099 package->PackagePath = strdupW( db->path );
1100 package->BaseURL = strdupW( base_url );
1102 create_temp_property_table( package );
1103 msi_clone_properties( package );
1104 msi_adjust_privilege_properties( package );
1106 package->ProductCode = msi_dup_property( package->db, szProductCode );
1107 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1109 set_installed_prop( package );
1110 set_installer_properties( package );
1112 sprintfW(uilevel,szpi,gUILevel);
1113 msi_set_property(package->db, szLevel, uilevel);
1115 r = msi_load_summary_properties( package );
1116 if (r != ERROR_SUCCESS)
1118 msiobj_release( &package->hdr );
1122 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1123 msi_load_admin_properties( package );
1130 * copy_package_to_temp [internal]
1132 * copy the msi file to a temp file to prevent locking a CD
1133 * with a multi disc install
1135 * FIXME: I think this is wrong, and instead of copying the package,
1136 * we should read all the tables to memory, then open the
1137 * database to read binary streams on demand.
1139 static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
1141 WCHAR path[MAX_PATH];
1143 GetTempPathW( MAX_PATH, path );
1144 GetTempFileNameW( path, szMsi, 0, filename );
1146 if( !CopyFileW( szPackage, filename, FALSE ) )
1148 UINT error = GetLastError();
1149 if ( error == ERROR_FILE_NOT_FOUND )
1150 ERR("can't find %s\n", debugstr_w(szPackage));
1152 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
1153 DeleteFileW( filename );
1157 return ERROR_SUCCESS;
1160 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1162 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1166 /* call will always fail, becase size is 0,
1167 * but will return ERROR_FILE_NOT_FOUND first
1168 * if the file doesn't exist
1170 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1171 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1173 cache_entry = msi_alloc( size );
1174 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1176 UINT error = GetLastError();
1177 msi_free( cache_entry );
1181 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1182 msi_free( cache_entry );
1183 return ERROR_SUCCESS;
1186 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1189 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1190 return ERROR_FUNCTION_FAILED;
1193 return ERROR_SUCCESS;
1196 UINT msi_get_local_package_name( LPWSTR path, LPCWSTR suffix )
1198 static const WCHAR szInstaller[] = {
1199 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1200 static const WCHAR fmt[] = {'%','x',0};
1201 DWORD time, len, i, offset;
1204 time = GetTickCount();
1205 GetWindowsDirectoryW( path, MAX_PATH );
1206 strcatW( path, szInstaller );
1207 CreateDirectoryW( path, NULL );
1209 len = strlenW(path);
1210 for (i = 0; i < 0x10000; i++)
1212 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1213 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1214 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1215 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1216 if (handle != INVALID_HANDLE_VALUE)
1218 CloseHandle(handle);
1221 if (GetLastError() != ERROR_FILE_EXISTS &&
1222 GetLastError() != ERROR_SHARING_VIOLATION)
1223 return ERROR_FUNCTION_FAILED;
1226 return ERROR_SUCCESS;
1229 static UINT apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
1233 WCHAR patch_file[MAX_PATH];
1234 MSIDATABASE *patch_db;
1235 MSIPATCHINFO *patch_info;
1238 len = sizeof(patch_file) / sizeof(WCHAR);
1239 r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
1240 INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
1241 if (r != ERROR_SUCCESS)
1243 ERR("failed to get patch filename %u\n", r);
1247 r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
1248 if (r != ERROR_SUCCESS)
1250 ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
1254 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
1257 msiobj_release( &patch_db->hdr );
1258 return ERROR_FUNCTION_FAILED;
1261 r = msi_parse_patch_summary( si, &patch_info );
1262 msiobj_release( &si->hdr );
1263 if (r != ERROR_SUCCESS)
1265 ERR("failed to parse patch summary %u\n", r);
1266 msiobj_release( &patch_db->hdr );
1270 patch_info->localfile = strdupW( patch_file );
1271 if (!patch_info->localfile)
1273 msiobj_release( &patch_db->hdr );
1274 return ERROR_OUTOFMEMORY;
1277 r = msi_apply_patch_db( package, patch_db, patch_info );
1278 msiobj_release( &patch_db->hdr );
1279 if (r != ERROR_SUCCESS)
1281 ERR("failed to apply patch %u\n", r);
1282 msi_free( patch_info->patchcode );
1283 msi_free( patch_info->transforms );
1284 msi_free( patch_info->localfile );
1285 msi_free( patch_info );
1290 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1292 WCHAR *template, *p, *q;
1295 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1296 TRACE("version: %d\n", package->version);
1298 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1300 return ERROR_SUCCESS; /* native accepts missing template property */
1302 TRACE("template: %s\n", debugstr_w(template));
1304 p = strchrW( template, ';' );
1307 WARN("invalid template string %s\n", debugstr_w(template));
1308 msi_free( template );
1309 return ERROR_PATCH_PACKAGE_INVALID;
1312 if (!template[0] || !strcmpW( template, szIntel ))
1313 package->platform = PLATFORM_INTEL;
1314 else if (!strcmpW( template, szIntel64 ))
1315 package->platform = PLATFORM_INTEL64;
1316 else if (!strcmpW( template, szX64 ))
1317 package->platform = PLATFORM_X64;
1320 WARN("unknown platform %s\n", debugstr_w(template));
1321 msi_free( template );
1322 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1326 for (q = ++p; (q = strchrW( q, ',' )); q++) count++;
1328 package->langids = msi_alloc( count * sizeof(LANGID) );
1329 if (!package->langids)
1331 msi_free( template );
1332 return ERROR_OUTOFMEMORY;
1338 q = strchrW( p, ',' );
1340 package->langids[i] = atoiW( p );
1345 package->num_langids = i + 1;
1347 msi_free( template );
1348 return ERROR_SUCCESS;
1351 static UINT validate_package( MSIPACKAGE *package )
1356 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1357 if (package->platform == PLATFORM_X64)
1359 if (!is_64bit && !is_wow64)
1360 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1361 if (package->version < 200)
1362 return ERROR_INSTALL_PACKAGE_INVALID;
1364 if (!package->num_langids)
1366 return ERROR_SUCCESS;
1368 for (i = 0; i < package->num_langids; i++)
1370 if (!package->langids[i] || IsValidLocale( package->langids[i], LCID_INSTALLED ))
1371 return ERROR_SUCCESS;
1373 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1376 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1378 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
1379 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1380 MSIDATABASE *db = NULL;
1381 MSIPACKAGE *package;
1383 LPWSTR ptr, base_url = NULL;
1385 WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
1386 LPCWSTR file = szPackage;
1390 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1392 if( szPackage[0] == '#' )
1394 handle = atoiW(&szPackage[1]);
1395 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1398 IWineMsiRemoteDatabase *remote_database;
1400 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1401 if ( !remote_database )
1402 return ERROR_INVALID_HANDLE;
1404 IWineMsiRemoteDatabase_Release( remote_database );
1405 WARN("MsiOpenPackage not allowed during a custom action!\n");
1407 return ERROR_FUNCTION_FAILED;
1412 if ( UrlIsW( szPackage, URLIS_URL ) )
1414 r = msi_download_file( szPackage, cachefile );
1415 if ( r != ERROR_SUCCESS )
1418 r = copy_package_to_temp( cachefile, temppath );
1419 if ( r != ERROR_SUCCESS )
1424 base_url = strdupW( szPackage );
1426 return ERROR_OUTOFMEMORY;
1428 ptr = strrchrW( base_url, '/' );
1429 if (ptr) *(ptr + 1) = '\0';
1433 r = copy_package_to_temp( szPackage, temppath );
1434 if ( r != ERROR_SUCCESS )
1440 r = msi_get_local_package_name( localfile, dotmsi );
1441 if (r != ERROR_SUCCESS)
1444 TRACE("Copying to local package %s\n", debugstr_w(localfile));
1446 if (!CopyFileW( file, localfile, FALSE ))
1448 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1449 debugstr_w(file), debugstr_w(localfile), GetLastError());
1450 return GetLastError();
1453 TRACE("Opening relocated package %s\n", debugstr_w( file ));
1455 /* transforms that add binary streams require that we open the database
1456 * read/write, which is safe because we always create a copy that is thrown
1457 * away when we're done.
1459 r = MSI_OpenDatabaseW( file, MSIDBOPEN_TRANSACT, &db );
1460 if( r != ERROR_SUCCESS )
1462 if (file != szPackage)
1463 DeleteFileW( file );
1465 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
1466 return ERROR_FILE_NOT_FOUND;
1471 db->localfile = strdupW( localfile );
1474 package = MSI_CreatePackage( db, base_url );
1475 msi_free( base_url );
1476 msiobj_release( &db->hdr );
1479 if (file != szPackage)
1480 DeleteFileW( file );
1482 return ERROR_INSTALL_PACKAGE_INVALID;
1485 if( file != szPackage )
1486 track_tempfile( package, file );
1488 si = MSI_GetSummaryInformationW( db->storage, 0 );
1491 WARN("failed to load summary info %u\n", r);
1492 msiobj_release( &package->hdr );
1493 return ERROR_INSTALL_PACKAGE_INVALID;
1496 r = msi_parse_summary( si, package );
1497 msiobj_release( &si->hdr );
1498 if (r != ERROR_SUCCESS)
1500 WARN("failed to parse summary info %u\n", r);
1501 msiobj_release( &package->hdr );
1505 r = validate_package( package );
1506 if (r != ERROR_SUCCESS)
1508 msiobj_release( &package->hdr );
1511 msi_set_property( package->db, Database, db->path );
1513 if( UrlIsW( szPackage, URLIS_URL ) )
1514 msi_set_property( package->db, szOriginalDatabase, szPackage );
1515 else if( szPackage[0] == '#' )
1516 msi_set_property( package->db, szOriginalDatabase, db->path );
1519 WCHAR fullpath[MAX_PATH];
1521 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1522 msi_set_property( package->db, szOriginalDatabase, fullpath );
1525 msi_set_context( package );
1529 WCHAR patch_code[GUID_SIZE];
1530 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1531 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1532 if (r != ERROR_SUCCESS)
1535 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1537 r = apply_registered_patch( package, patch_code );
1538 if (r != ERROR_SUCCESS)
1540 ERR("registered patch failed to apply %u\n", r);
1541 msiobj_release( &package->hdr );
1550 msi_clone_properties( package );
1551 msi_adjust_privilege_properties( package );
1554 *pPackage = package;
1555 return ERROR_SUCCESS;
1558 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1560 MSIPACKAGE *package = NULL;
1563 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1565 if( !szPackage || !phPackage )
1566 return ERROR_INVALID_PARAMETER;
1570 FIXME("Should create an empty database and package\n");
1571 return ERROR_FUNCTION_FAILED;
1575 FIXME("dwOptions %08x not supported\n", dwOptions);
1577 ret = MSI_OpenPackageW( szPackage, &package );
1578 if( ret == ERROR_SUCCESS )
1580 *phPackage = alloc_msihandle( &package->hdr );
1582 ret = ERROR_NOT_ENOUGH_MEMORY;
1583 msiobj_release( &package->hdr );
1589 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1591 return MsiOpenPackageExW( szPackage, 0, phPackage );
1594 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1596 LPWSTR szwPack = NULL;
1601 szwPack = strdupAtoW( szPackage );
1603 return ERROR_OUTOFMEMORY;
1606 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1608 msi_free( szwPack );
1613 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1615 return MsiOpenPackageExA( szPackage, 0, phPackage );
1618 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1620 MSIPACKAGE *package;
1621 MSIHANDLE handle = 0;
1622 IUnknown *remote_unk;
1623 IWineMsiRemotePackage *remote_package;
1625 TRACE("(%d)\n",hInstall);
1627 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1630 handle = alloc_msihandle( &package->db->hdr );
1631 msiobj_release( &package->hdr );
1633 else if ((remote_unk = msi_get_remote(hInstall)))
1635 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1636 (LPVOID *)&remote_package) == S_OK)
1638 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1639 IWineMsiRemotePackage_Release(remote_package);
1643 WARN("remote handle %d is not a package\n", hInstall);
1645 IUnknown_Release(remote_unk);
1651 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1654 static const WCHAR szActionData[] =
1655 {'A','c','t','i','o','n','D','a','t','a',0};
1656 static const WCHAR szSetProgress[] =
1657 {'S','e','t','P','r','o','g','r','e','s','s',0};
1658 static const WCHAR szActionText[] =
1659 {'A','c','t','i','o','n','T','e','x','t',0};
1663 DWORD total_size = 0;
1669 TRACE("%x\n", eMessageType);
1672 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1673 log_type |= INSTALLLOGMODE_ERROR;
1674 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1675 log_type |= INSTALLLOGMODE_WARNING;
1676 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1677 log_type |= INSTALLLOGMODE_USER;
1678 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1679 log_type |= INSTALLLOGMODE_INFO;
1680 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1681 log_type |= INSTALLLOGMODE_COMMONDATA;
1682 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1683 log_type |= INSTALLLOGMODE_ACTIONSTART;
1684 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1685 log_type |= INSTALLLOGMODE_ACTIONDATA;
1687 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1690 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1692 static const WCHAR template_s[]=
1693 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1694 static const WCHAR format[] =
1695 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1697 LPCWSTR action_text, action;
1698 LPWSTR deformatted = NULL;
1700 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1702 action = MSI_RecordGetString(record, 1);
1703 action_text = MSI_RecordGetString(record, 2);
1705 if (!action || !action_text)
1708 deformat_string(package, action_text, &deformatted);
1710 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1712 len += strlenW(deformatted);
1713 message = msi_alloc(len*sizeof(WCHAR));
1714 sprintfW(message, template_s, timet, action);
1716 strcatW(message, deformatted);
1717 msi_free(deformatted);
1722 message = msi_alloc(1*sizeof (WCHAR));
1724 msg_field = MSI_RecordGetFieldCount(record);
1725 for (i = 1; i <= msg_field; i++)
1729 static const WCHAR format[] = { '%','i',':',' ',0};
1731 MSI_RecordGetStringW(record,i,NULL,&sz);
1733 total_size+=sz*sizeof(WCHAR);
1734 tmp = msi_alloc(sz*sizeof(WCHAR));
1735 message = msi_realloc(message,total_size*sizeof (WCHAR));
1737 MSI_RecordGetStringW(record,i,tmp,&sz);
1741 sprintfW(number,format,i);
1742 strcatW(message,number);
1744 strcatW(message,tmp);
1746 strcatW(message, szSpace);
1752 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1753 gUIFilter, log_type, debugstr_w(message));
1755 /* convert it to ASCII */
1756 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1757 msg = msi_alloc( len );
1758 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1760 if (gUIHandlerW && (gUIFilter & log_type))
1762 rc = gUIHandlerW( gUIContext, eMessageType, message );
1764 else if (gUIHandlerA && (gUIFilter & log_type))
1766 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1768 else if (gUIHandlerRecord && (gUIFilter & log_type))
1770 MSIHANDLE rec = MsiCreateRecord( 1 );
1771 MsiRecordSetStringW( rec, 0, message );
1772 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1773 MsiCloseHandle( rec );
1776 if (!rc && gszLogFile[0] && (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1779 HANDLE log_file = CreateFileW(gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1780 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1782 if (log_file != INVALID_HANDLE_VALUE)
1784 SetFilePointer(log_file,0, NULL, FILE_END);
1785 WriteFile(log_file,msg,strlen(msg),&write,NULL);
1786 WriteFile(log_file,"\n",1,&write,NULL);
1787 CloseHandle(log_file);
1791 msi_free( message );
1793 switch (eMessageType & 0xff000000)
1795 case INSTALLMESSAGE_ACTIONDATA:
1796 /* FIXME: format record here instead of in ui_actiondata to get the
1797 * correct action data for external scripts */
1798 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1800 case INSTALLMESSAGE_ACTIONSTART:
1804 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1806 deformat_string(package, action_text, &deformated);
1807 uirow = MSI_CreateRecord(1);
1808 MSI_RecordSetStringW(uirow, 1, deformated);
1809 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1810 msi_free(deformated);
1812 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1814 msiobj_release(&uirow->hdr);
1817 case INSTALLMESSAGE_PROGRESS:
1818 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1822 return ERROR_SUCCESS;
1825 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1828 UINT ret = ERROR_INVALID_HANDLE;
1829 MSIPACKAGE *package = NULL;
1830 MSIRECORD *record = NULL;
1832 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1836 IWineMsiRemotePackage *remote_package;
1838 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1839 if (!remote_package)
1840 return ERROR_INVALID_HANDLE;
1842 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1844 IWineMsiRemotePackage_Release( remote_package );
1848 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1849 return HRESULT_CODE(hr);
1851 return ERROR_FUNCTION_FAILED;
1854 return ERROR_SUCCESS;
1857 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1861 ret = MSI_ProcessMessage( package, eMessageType, record );
1864 msiobj_release( &package->hdr );
1866 msiobj_release( &record->hdr );
1873 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1875 LPWSTR szwName = NULL, szwValue = NULL;
1876 UINT r = ERROR_OUTOFMEMORY;
1878 szwName = strdupAtoW( szName );
1879 if( szName && !szwName )
1882 szwValue = strdupAtoW( szValue );
1883 if( szValue && !szwValue )
1886 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1889 msi_free( szwName );
1890 msi_free( szwValue );
1895 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1899 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1903 msi_free( folder->ResolvedSource );
1904 folder->ResolvedSource = NULL;
1908 msi_free( folder->ResolvedTarget );
1909 folder->ResolvedTarget = NULL;
1914 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1917 MSIRECORD *row = NULL;
1922 static const WCHAR Insert[] = {
1923 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1924 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1925 '`','_','P','r','o','p','e','r','t','y','`',',',
1926 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1927 ,' ','(','?',',','?',')',0};
1928 static const WCHAR Update[] = {
1929 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1930 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1931 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1932 ' ','=',' ','\'','%','s','\'',0};
1933 static const WCHAR Delete[] = {
1934 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1935 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1936 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1938 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
1941 return ERROR_INVALID_PARAMETER;
1943 /* this one is weird... */
1945 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1947 rc = msi_get_property(db, szName, 0, &sz);
1948 if (!szValue || !*szValue)
1950 sprintfW(Query, Delete, szName);
1952 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1954 sprintfW(Query, Update, szName);
1956 row = MSI_CreateRecord(1);
1957 MSI_RecordSetStringW(row, 1, szValue);
1961 strcpyW(Query, Insert);
1963 row = MSI_CreateRecord(2);
1964 MSI_RecordSetStringW(row, 1, szName);
1965 MSI_RecordSetStringW(row, 2, szValue);
1968 rc = MSI_DatabaseOpenViewW(db, Query, &view);
1969 if (rc == ERROR_SUCCESS)
1971 rc = MSI_ViewExecute(view, row);
1972 MSI_ViewClose(view);
1973 msiobj_release(&view->hdr);
1977 msiobj_release(&row->hdr);
1982 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1984 MSIPACKAGE *package;
1987 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1991 BSTR name = NULL, value = NULL;
1992 IWineMsiRemotePackage *remote_package;
1994 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1995 if (!remote_package)
1996 return ERROR_INVALID_HANDLE;
1998 name = SysAllocString( szName );
1999 value = SysAllocString( szValue );
2000 if ((!name && szName) || (!value && szValue))
2002 SysFreeString( name );
2003 SysFreeString( value );
2004 IWineMsiRemotePackage_Release( remote_package );
2005 return ERROR_OUTOFMEMORY;
2008 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2010 SysFreeString( name );
2011 SysFreeString( value );
2012 IWineMsiRemotePackage_Release( remote_package );
2016 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2017 return HRESULT_CODE(hr);
2019 return ERROR_FUNCTION_FAILED;
2022 return ERROR_SUCCESS;
2025 ret = msi_set_property( package->db, szName, szValue );
2026 if (ret == ERROR_SUCCESS && !strcmpW( szName, cszSourceDir ))
2027 msi_reset_folders( package, TRUE );
2029 msiobj_release( &package->hdr );
2033 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2036 MSIRECORD *rec, *row = NULL;
2039 static const WCHAR query[]= {
2040 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2041 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2042 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2045 if (!name || !*name)
2048 rec = MSI_CreateRecord(1);
2052 MSI_RecordSetStringW(rec, 1, name);
2054 r = MSI_DatabaseOpenViewW(db, query, &view);
2055 if (r == ERROR_SUCCESS)
2057 MSI_ViewExecute(view, rec);
2058 MSI_ViewFetch(view, &row);
2059 MSI_ViewClose(view);
2060 msiobj_release(&view->hdr);
2063 msiobj_release(&rec->hdr);
2067 /* internal function, not compatible with MsiGetPropertyW */
2068 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2069 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2072 UINT rc = ERROR_FUNCTION_FAILED;
2074 row = msi_get_property_row( db, szName );
2076 if (*pchValueBuf > 0)
2081 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2082 msiobj_release(&row->hdr);
2085 if (rc == ERROR_SUCCESS)
2086 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2087 debugstr_w(szName));
2088 else if (rc == ERROR_MORE_DATA)
2089 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2090 debugstr_w(szName));
2094 TRACE("property %s not found\n", debugstr_w(szName));
2100 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2106 r = msi_get_property(db, prop, NULL, &sz);
2107 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2111 str = msi_alloc(sz * sizeof(WCHAR));
2112 r = msi_get_property(db, prop, str, &sz);
2113 if (r != ERROR_SUCCESS)
2122 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2124 LPWSTR str = msi_dup_property( db, prop );
2125 int val = str ? atoiW(str) : def;
2130 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2131 awstring *szValueBuf, LPDWORD pchValueBuf )
2133 MSIPACKAGE *package;
2134 MSIRECORD *row = NULL;
2135 UINT r = ERROR_FUNCTION_FAILED;
2138 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2139 szValueBuf->str.w, pchValueBuf );
2142 return ERROR_INVALID_PARAMETER;
2144 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2148 IWineMsiRemotePackage *remote_package;
2149 LPWSTR value = NULL;
2153 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2154 if (!remote_package)
2155 return ERROR_INVALID_HANDLE;
2157 bname = SysAllocString( name );
2160 IWineMsiRemotePackage_Release( remote_package );
2161 return ERROR_OUTOFMEMORY;
2165 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2170 value = msi_alloc(len * sizeof(WCHAR));
2173 r = ERROR_OUTOFMEMORY;
2177 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
2181 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2183 /* Bug required by Adobe installers */
2184 if (!szValueBuf->unicode && !szValueBuf->str.a)
2185 *pchValueBuf *= sizeof(WCHAR);
2188 IWineMsiRemotePackage_Release(remote_package);
2189 SysFreeString(bname);
2194 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2195 return HRESULT_CODE(hr);
2197 return ERROR_FUNCTION_FAILED;
2203 row = msi_get_property_row( package->db, name );
2205 val = MSI_RecordGetString( row, 1 );
2210 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2213 msiobj_release( &row->hdr );
2214 msiobj_release( &package->hdr );
2219 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2220 LPSTR szValueBuf, LPDWORD pchValueBuf )
2226 val.unicode = FALSE;
2227 val.str.a = szValueBuf;
2229 name = strdupAtoW( szName );
2230 if (szName && !name)
2231 return ERROR_OUTOFMEMORY;
2233 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2238 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2239 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2244 val.str.w = szValueBuf;
2246 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2249 typedef struct _msi_remote_package_impl {
2250 const IWineMsiRemotePackageVtbl *lpVtbl;
2253 } msi_remote_package_impl;
2255 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
2257 return (msi_remote_package_impl*) iface;
2260 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2261 REFIID riid,LPVOID *ppobj)
2263 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2264 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2266 IUnknown_AddRef( iface );
2271 return E_NOINTERFACE;
2274 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2276 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2278 return InterlockedIncrement( &This->refs );
2281 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2283 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2286 r = InterlockedDecrement( &This->refs );
2289 MsiCloseHandle( This->package );
2295 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2297 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2298 This->package = handle;
2302 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2304 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2305 IWineMsiRemoteDatabase *rdb = NULL;
2309 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2310 if (FAILED(hr) || !rdb)
2312 ERR("Failed to create remote database\n");
2316 hdb = MsiGetActiveDatabase(This->package);
2318 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2321 ERR("Failed to set the database handle\n");
2325 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2329 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
2331 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2334 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
2335 if (r != ERROR_SUCCESS)
2336 return HRESULT_FROM_WIN32(r);
2341 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2343 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2344 UINT r = MsiSetPropertyW(This->package, property, value);
2345 return HRESULT_FROM_WIN32(r);
2348 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2350 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2351 UINT r = MsiProcessMessage(This->package, message, record);
2352 return HRESULT_FROM_WIN32(r);
2355 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2357 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2358 UINT r = MsiDoActionW(This->package, action);
2359 return HRESULT_FROM_WIN32(r);
2362 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2364 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2365 UINT r = MsiSequenceW(This->package, table, sequence);
2366 return HRESULT_FROM_WIN32(r);
2369 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2371 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2372 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2373 return HRESULT_FROM_WIN32(r);
2376 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2378 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2379 UINT r = MsiSetTargetPathW(This->package, folder, value);
2380 return HRESULT_FROM_WIN32(r);
2383 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2385 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2386 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2387 return HRESULT_FROM_WIN32(r);
2390 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2392 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2393 *ret = MsiGetMode(This->package, mode);
2397 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2399 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2400 UINT r = MsiSetMode(This->package, mode, state);
2401 return HRESULT_FROM_WIN32(r);
2404 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2405 INSTALLSTATE *installed, INSTALLSTATE *action )
2407 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2408 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2409 return HRESULT_FROM_WIN32(r);
2412 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2414 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2415 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2416 return HRESULT_FROM_WIN32(r);
2419 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2420 INSTALLSTATE *installed, INSTALLSTATE *action )
2422 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2423 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2424 return HRESULT_FROM_WIN32(r);
2427 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2429 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2430 UINT r = MsiSetComponentStateW(This->package, component, state);
2431 return HRESULT_FROM_WIN32(r);
2434 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2436 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2437 *language = MsiGetLanguage(This->package);
2441 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2443 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2444 UINT r = MsiSetInstallLevel(This->package, level);
2445 return HRESULT_FROM_WIN32(r);
2448 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2452 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2453 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2454 if (r == ERROR_SUCCESS)
2456 *value = SysAllocStringLen(NULL, size);
2458 return E_OUTOFMEMORY;
2460 r = MsiFormatRecordW(This->package, record, *value, &size);
2462 return HRESULT_FROM_WIN32(r);
2465 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2467 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2468 UINT r = MsiEvaluateConditionW(This->package, condition);
2469 return HRESULT_FROM_WIN32(r);
2472 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2473 INT cost_tree, INSTALLSTATE state, INT *cost )
2475 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2476 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2477 return HRESULT_FROM_WIN32(r);
2480 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2486 mrp_GetActiveDatabase,
2497 mrp_GetFeatureState,
2498 mrp_SetFeatureState,
2499 mrp_GetComponentState,
2500 mrp_SetComponentState,
2502 mrp_SetInstallLevel,
2504 mrp_EvaluateCondition,
2508 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2510 msi_remote_package_impl* This;
2512 This = msi_alloc( sizeof *This );
2514 return E_OUTOFMEMORY;
2516 This->lpVtbl = &msi_remote_package_vtbl;
2525 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2526 LPCWSTR property, LPWSTR value)
2528 MSISOURCELISTINFO *info;
2530 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2532 return ERROR_OUTOFMEMORY;
2534 info->context = context;
2535 info->options = options;
2536 info->property = property;
2537 info->value = strdupW(value);
2538 list_add_head(&package->sourcelist_info, &info->entry);
2540 return ERROR_SUCCESS;
2543 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2544 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2548 disk = msi_alloc(sizeof(MSIMEDIADISK));
2550 return ERROR_OUTOFMEMORY;
2552 disk->context = context;
2553 disk->options = options;
2554 disk->disk_id = disk_id;
2555 disk->volume_label = strdupW(volume_label);
2556 disk->disk_prompt = strdupW(disk_prompt);
2557 list_add_head(&package->sourcelist_media, &disk->entry);
2559 return ERROR_SUCCESS;