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 DeleteFileW( temp->Path );
63 msi_free( temp->Path );
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 );
79 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
81 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
82 list_remove( &cl->entry );
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 );
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 );
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 );
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 );
128 msi_free( ext->Extension );
129 msi_free( ext->ProgIDText );
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 )
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 )
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 );
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 );
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 );
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 );
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 );
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 );
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 );
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 );
286 for (i = 0; i < TOTAL_SCRIPTS; 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->patches )
298 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
300 list_remove( &patch->entry );
301 msi_free( patch->patchcode );
302 msi_free( patch->transforms );
303 msi_free( patch->localfile );
304 msi_free( patch->filename );
308 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
310 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
312 list_remove( &binary->entry );
314 FreeLibrary( binary->module );
315 if (!DeleteFileW( binary->tmpfile ))
316 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
317 msi_free( binary->source );
318 msi_free( binary->tmpfile );
322 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
324 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
326 list_remove( &cab->entry );
327 IStorage_Release( cab->storage );
328 msi_free( cab->stream );
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)
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};
380 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
381 if (rc != ERROR_SUCCESS)
384 rc = MSI_ViewExecute(view, 0);
386 msiobj_release(&view->hdr);
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;
407 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
408 if (rc != ERROR_SUCCESS)
411 rc = MSI_ViewExecute( view_select, 0 );
412 if (rc != ERROR_SUCCESS)
414 MSI_ViewClose( view_select );
415 msiobj_release( &view_select->hdr );
421 MSIQUERY *view_insert, *view_update;
422 MSIRECORD *rec_select;
424 rc = MSI_ViewFetch( view_select, &rec_select );
425 if (rc != ERROR_SUCCESS)
428 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
429 if (rc != ERROR_SUCCESS)
431 msiobj_release( &rec_select->hdr );
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 );
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 );
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 )
483 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
485 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
486 if (r == ERROR_SUCCESS)
489 msi_set_property( package->db, szInstalled, szOne );
494 static UINT set_user_sid_prop( MSIPACKAGE *package )
498 LPWSTR sid_str = NULL, dom = NULL;
499 DWORD size, dom_size;
501 UINT r = ERROR_FUNCTION_FAILED;
504 GetUserNameW( NULL, &size );
506 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
508 return ERROR_OUTOFMEMORY;
510 if (!GetUserNameW( user_name, &size ))
515 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
517 psid = msi_alloc( size );
518 dom = msi_alloc( dom_size*sizeof (WCHAR) );
521 r = ERROR_OUTOFMEMORY;
525 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
528 if (!ConvertSidToStringSidW( psid, &sid_str ))
531 r = msi_set_property( package->db, szUserSID, sid_str );
534 LocalFree( sid_str );
537 msi_free( user_name );
542 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
547 DWORD index = 0, size;
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','\\',
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)
568 GetWindowsDirectoryW(windir, MAX_PATH);
572 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
576 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
577 if (strcmpW( ver, name ) < 0)
580 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
581 check = msi_alloc(size * sizeof(WCHAR));
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)
607 RegCloseKey(netsetup);
611 typedef struct tagLANGANDCODEPAGE
617 static void set_msi_assembly_prop(MSIPACKAGE *package)
621 LPVOID version = NULL;
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);
643 size = GetFileVersionInfoSizeW(fusion, &handle);
646 version = msi_alloc(size);
647 if (!version) return;
649 if (!GetFileVersionInfoW(fusion, handle, size, version))
652 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
655 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
657 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
660 if (!val_len || !verstr)
663 msi_set_property(package->db, netasm, verstr);
670 static VOID set_installer_properties(MSIPACKAGE *package)
674 OSVERSIONINFOEXW OSVersion;
677 WCHAR verstr[10], bufstr[20];
680 LPWSTR username, companyname;
681 SYSTEM_INFO sys_info;
682 SYSTEMTIME systemtime;
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};
756 * Other things that probably should be set:
758 * ComputerName VirtualMemory
759 * ShellAdvSupport DefaultUIFont PackagecodeChanging
760 * CaptionHeight BorderTop BorderSide TextHeight
761 * RedirectedDllSupport
764 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
765 strcatW(pth, szBackSlash);
766 msi_set_property(package->db, szCommonAppDataFolder, pth);
768 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
769 strcatW(pth, szBackSlash);
770 msi_set_property(package->db, szFavoritesFolder, pth);
772 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
773 strcatW(pth, szBackSlash);
774 msi_set_property(package->db, szFontsFolder, pth);
776 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
777 strcatW(pth, szBackSlash);
778 msi_set_property(package->db, szSendToFolder, pth);
780 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
781 strcatW(pth, szBackSlash);
782 msi_set_property(package->db, szStartMenuFolder, pth);
784 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
785 strcatW(pth, szBackSlash);
786 msi_set_property(package->db, szStartupFolder, pth);
788 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
789 strcatW(pth, szBackSlash);
790 msi_set_property(package->db, szTemplateFolder, pth);
792 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
793 strcatW(pth, szBackSlash);
794 msi_set_property(package->db, szDesktopFolder, pth);
796 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
797 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
798 strcatW(pth, szBackSlash);
799 msi_set_property(package->db, szProgramMenuFolder, pth);
801 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
802 strcatW(pth, szBackSlash);
803 msi_set_property(package->db, szAdminToolsFolder, pth);
805 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
806 strcatW(pth, szBackSlash);
807 msi_set_property(package->db, szAppDataFolder, pth);
809 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
810 strcatW(pth, szBackSlash);
811 msi_set_property(package->db, szSystemFolder, pth);
812 msi_set_property(package->db, szSystem16Folder, pth);
814 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
815 strcatW(pth, szBackSlash);
816 msi_set_property(package->db, szLocalAppDataFolder, pth);
818 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
819 strcatW(pth, szBackSlash);
820 msi_set_property(package->db, szMyPicturesFolder, pth);
822 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
823 strcatW(pth, szBackSlash);
824 msi_set_property(package->db, szPersonalFolder, pth);
826 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
827 strcatW(pth, szBackSlash);
828 msi_set_property(package->db, szWindowsFolder, pth);
830 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
831 strcatW(pth, szBackSlash);
832 msi_set_property(package->db, szPrintHoodFolder, pth);
834 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
835 strcatW(pth, szBackSlash);
836 msi_set_property(package->db, szNetHoodFolder, pth);
838 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
839 strcatW(pth, szBackSlash);
840 msi_set_property(package->db, szRecentFolder, pth);
842 /* Physical Memory is specified in MB. Using total amount. */
843 msex.dwLength = sizeof(msex);
844 GlobalMemoryStatusEx( &msex );
845 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
846 msi_set_property(package->db, szPhysicalMemory, bufstr);
848 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
849 ptr = strchrW(pth,'\\');
850 if (ptr) *(ptr + 1) = 0;
851 msi_set_property(package->db, szWindowsVolume, pth);
853 GetTempPathW(MAX_PATH,pth);
854 msi_set_property(package->db, szTempFolder, pth);
856 /* in a wine environment the user is always admin and privileged */
857 msi_set_property(package->db, szAdminUser, szOne);
858 msi_set_property(package->db, szPrivileged, szOne);
860 /* set the os things */
861 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
862 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
863 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
864 sprintfW(verstr, szFormat, verval);
865 switch (OSVersion.dwPlatformId)
867 case VER_PLATFORM_WIN32_WINDOWS:
868 msi_set_property(package->db, szVersion9x, verstr);
870 case VER_PLATFORM_WIN32_NT:
871 msi_set_property(package->db, szVersionNT, verstr);
872 sprintfW(verstr, szFormat,OSVersion.wProductType);
873 msi_set_property(package->db, szMsiNTProductType, verstr);
876 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
877 msi_set_property(package->db, szWindowsBuild, verstr);
878 /* just fudge this */
879 msi_set_property(package->db, szServicePackLevel, szSix);
881 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
882 msi_set_property( package->db, szVersionMsi, bufstr );
883 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
884 msi_set_property( package->db, szVersionDatabase, bufstr );
886 GetNativeSystemInfo( &sys_info );
887 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
888 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
890 msi_set_property( package->db, szIntel, bufstr );
892 GetSystemDirectoryW( pth, MAX_PATH );
893 PathAddBackslashW( pth );
894 msi_set_property( package->db, szSystemFolder, pth );
896 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
897 PathAddBackslashW( pth );
898 msi_set_property( package->db, szProgramFilesFolder, pth );
900 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
901 PathAddBackslashW( pth );
902 msi_set_property( package->db, szCommonFilesFolder, pth );
904 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
906 msi_set_property( package->db, szMsiAMD64, bufstr );
907 msi_set_property( package->db, szMsix64, bufstr );
908 msi_set_property( package->db, szVersionNT64, verstr );
910 GetSystemDirectoryW( pth, MAX_PATH );
911 PathAddBackslashW( pth );
912 msi_set_property( package->db, szSystem64Folder, pth );
914 GetSystemWow64DirectoryW( pth, MAX_PATH );
915 PathAddBackslashW( pth );
916 msi_set_property( package->db, szSystemFolder, pth );
918 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
919 PathAddBackslashW( pth );
920 msi_set_property( package->db, szProgramFiles64Folder, pth );
922 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
923 PathAddBackslashW( pth );
924 msi_set_property( package->db, szProgramFilesFolder, pth );
926 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
927 PathAddBackslashW( pth );
928 msi_set_property( package->db, szCommonFiles64Folder, pth );
930 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
931 PathAddBackslashW( pth );
932 msi_set_property( package->db, szCommonFilesFolder, pth );
935 /* Screen properties. */
937 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
938 msi_set_property( package->db, szScreenX, bufstr );
939 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
940 msi_set_property( package->db, szScreenY, bufstr );
941 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
942 msi_set_property( package->db, szColorBits, bufstr );
945 /* USERNAME and COMPANYNAME */
946 username = msi_dup_property( package->db, szUSERNAME );
947 companyname = msi_dup_property( package->db, szCOMPANYNAME );
949 if ((!username || !companyname) &&
950 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
953 (username = msi_reg_get_val_str( hkey, szDefName )))
954 msi_set_property( package->db, szUSERNAME, username );
956 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
957 msi_set_property( package->db, szCOMPANYNAME, companyname );
960 if ((!username || !companyname) &&
961 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
964 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
965 msi_set_property( package->db, szUSERNAME, username );
967 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
968 msi_set_property( package->db, szCOMPANYNAME, companyname );
971 msi_free( username );
972 msi_free( companyname );
974 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
975 ERR("Failed to set the UserSID property\n");
977 /* Date and time properties */
978 GetSystemTime( &systemtime );
979 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
980 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
981 msi_set_property( package->db, szDate, bufstr );
983 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
985 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
986 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
987 &systemtime, NULL, bufstr,
988 sizeof(bufstr)/sizeof(bufstr[0]) ))
989 msi_set_property( package->db, szTime, bufstr );
991 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
993 set_msi_assembly_prop( package );
995 langid = GetUserDefaultLangID();
996 sprintfW(bufstr, szIntFormat, langid);
997 msi_set_property( package->db, szUserLanguageID, bufstr );
999 langid = GetSystemDefaultLangID();
1000 sprintfW(bufstr, szIntFormat, langid);
1001 msi_set_property( package->db, szSystemLangID, bufstr );
1003 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
1004 msi_set_property( package->db, szProductState, bufstr );
1007 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1010 if ((username = msi_alloc( len * sizeof(WCHAR) )))
1012 if (GetUserNameW( username, &len ))
1013 msi_set_property( package->db, szLogonUser, username );
1014 msi_free( username );
1019 static UINT msi_load_summary_properties( MSIPACKAGE *package )
1023 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
1026 LPWSTR package_code;
1027 static const WCHAR szPackageCode[] = {
1028 'P','a','c','k','a','g','e','C','o','d','e',0};
1031 ERR("Unable to allocate handle\n");
1032 return ERROR_OUTOFMEMORY;
1035 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1036 MsiCloseHandle(hdb);
1037 if (rc != ERROR_SUCCESS)
1039 ERR("Unable to open Summary Information\n");
1043 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1044 &count, NULL, NULL, NULL );
1045 if (rc != ERROR_SUCCESS)
1047 WARN("Unable to query page count: %d\n", rc);
1051 /* load package code property */
1053 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1054 NULL, NULL, NULL, &len );
1055 if (rc != ERROR_MORE_DATA)
1057 WARN("Unable to query revision number: %d\n", rc);
1058 rc = ERROR_FUNCTION_FAILED;
1063 package_code = msi_alloc( len * sizeof(WCHAR) );
1064 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1065 NULL, NULL, package_code, &len );
1066 if (rc != ERROR_SUCCESS)
1068 WARN("Unable to query rev number: %d\n", rc);
1072 msi_set_property( package->db, szPackageCode, package_code );
1073 msi_free( package_code );
1075 /* load package attributes */
1077 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1078 &count, NULL, NULL, NULL );
1079 package->WordCount = count;
1082 MsiCloseHandle(suminfo);
1086 static MSIPACKAGE *msi_alloc_package( void )
1088 MSIPACKAGE *package;
1090 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1094 list_init( &package->components );
1095 list_init( &package->features );
1096 list_init( &package->files );
1097 list_init( &package->filepatches );
1098 list_init( &package->tempfiles );
1099 list_init( &package->folders );
1100 list_init( &package->subscriptions );
1101 list_init( &package->appids );
1102 list_init( &package->classes );
1103 list_init( &package->mimes );
1104 list_init( &package->extensions );
1105 list_init( &package->progids );
1106 list_init( &package->RunningActions );
1107 list_init( &package->sourcelist_info );
1108 list_init( &package->sourcelist_media );
1109 list_init( &package->patches );
1110 list_init( &package->binaries );
1111 list_init( &package->cabinet_streams );
1117 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1122 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1124 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1125 if (r != ERROR_SUCCESS)
1128 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1134 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1136 /* FIXME: this should depend on the user's privileges */
1137 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1139 TRACE("resetting ALLUSERS property from 2 to 1\n");
1140 msi_set_property( package->db, szAllUsers, szOne );
1142 msi_set_property( package->db, szAdminUser, szOne );
1145 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1147 static const WCHAR szpi[] = {'%','i',0};
1148 MSIPACKAGE *package;
1154 package = msi_alloc_package();
1157 msiobj_addref( &db->hdr );
1160 package->WordCount = 0;
1161 package->PackagePath = strdupW( db->path );
1162 package->BaseURL = strdupW( base_url );
1164 create_temp_property_table( package );
1165 msi_clone_properties( package );
1166 msi_adjust_privilege_properties( package );
1168 package->ProductCode = msi_dup_property( package->db, szProductCode );
1169 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1171 set_installed_prop( package );
1172 set_installer_properties( package );
1174 sprintfW(uilevel,szpi,gUILevel);
1175 msi_set_property(package->db, szUILevel, uilevel);
1177 r = msi_load_summary_properties( package );
1178 if (r != ERROR_SUCCESS)
1180 msiobj_release( &package->hdr );
1184 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1185 msi_load_admin_properties( package );
1187 package->log_file = INVALID_HANDLE_VALUE;
1192 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1194 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1198 /* call will always fail, because size is 0,
1199 * but will return ERROR_FILE_NOT_FOUND first
1200 * if the file doesn't exist
1202 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1203 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1205 cache_entry = msi_alloc( size );
1206 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1208 UINT error = GetLastError();
1209 msi_free( cache_entry );
1213 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1214 msi_free( cache_entry );
1215 return ERROR_SUCCESS;
1218 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1221 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1222 return ERROR_FUNCTION_FAILED;
1225 return ERROR_SUCCESS;
1228 UINT msi_create_empty_local_file( LPWSTR path, LPCWSTR suffix )
1230 static const WCHAR szInstaller[] = {
1231 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1232 static const WCHAR fmt[] = {'%','x',0};
1233 DWORD time, len, i, offset;
1236 time = GetTickCount();
1237 GetWindowsDirectoryW( path, MAX_PATH );
1238 strcatW( path, szInstaller );
1239 CreateDirectoryW( path, NULL );
1241 len = strlenW(path);
1242 for (i = 0; i < 0x10000; i++)
1244 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1245 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1246 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1247 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1248 if (handle != INVALID_HANDLE_VALUE)
1250 CloseHandle(handle);
1253 if (GetLastError() != ERROR_FILE_EXISTS &&
1254 GetLastError() != ERROR_SHARING_VIOLATION)
1255 return ERROR_FUNCTION_FAILED;
1258 return ERROR_SUCCESS;
1261 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1263 WCHAR *template, *p, *q;
1266 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1267 TRACE("version: %d\n", package->version);
1269 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1271 return ERROR_SUCCESS; /* native accepts missing template property */
1273 TRACE("template: %s\n", debugstr_w(template));
1275 p = strchrW( template, ';' );
1278 WARN("invalid template string %s\n", debugstr_w(template));
1279 msi_free( template );
1280 return ERROR_PATCH_PACKAGE_INVALID;
1283 if (!template[0] || !strcmpW( template, szIntel ))
1284 package->platform = PLATFORM_INTEL;
1285 else if (!strcmpW( template, szIntel64 ))
1286 package->platform = PLATFORM_INTEL64;
1287 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1288 package->platform = PLATFORM_X64;
1291 WARN("unknown platform %s\n", debugstr_w(template));
1292 msi_free( template );
1293 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1298 msi_free( template );
1299 return ERROR_SUCCESS;
1302 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1304 package->langids = msi_alloc( count * sizeof(LANGID) );
1305 if (!package->langids)
1307 msi_free( template );
1308 return ERROR_OUTOFMEMORY;
1314 q = strchrW( p, ',' );
1316 package->langids[i] = atoiW( p );
1321 package->num_langids = i + 1;
1323 msi_free( template );
1324 return ERROR_SUCCESS;
1327 static UINT validate_package( MSIPACKAGE *package )
1332 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1333 if (package->platform == PLATFORM_X64)
1335 if (!is_64bit && !is_wow64)
1336 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1337 if (package->version < 200)
1338 return ERROR_INSTALL_PACKAGE_INVALID;
1340 if (!package->num_langids)
1342 return ERROR_SUCCESS;
1344 for (i = 0; i < package->num_langids; i++)
1346 LANGID langid = package->langids[i];
1348 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1350 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1352 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1354 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1356 if (IsValidLocale( langid, LCID_INSTALLED ))
1357 return ERROR_SUCCESS;
1359 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1362 int msi_track_tempfile( MSIPACKAGE *package, const WCHAR *path )
1366 TRACE("%s\n", debugstr_w(path));
1368 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
1370 if (!strcmpW( path, temp->Path )) return 0;
1372 if (!(temp = msi_alloc_zero( sizeof (MSITEMPFILE) ))) return -1;
1373 list_add_head( &package->tempfiles, &temp->entry );
1374 temp->Path = strdupW( path );
1378 static WCHAR *get_product_code( MSIDATABASE *db )
1380 static const WCHAR query[] = {
1381 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1382 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1383 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1384 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1389 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1393 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1395 MSI_ViewClose( view );
1396 msiobj_release( &view->hdr );
1399 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1401 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1402 msiobj_release( &rec->hdr );
1404 MSI_ViewClose( view );
1405 msiobj_release( &view->hdr );
1409 static UINT get_registered_local_package( const WCHAR *product, const WCHAR *package, WCHAR *localfile )
1411 MSIINSTALLCONTEXT context;
1412 HKEY product_key, props_key;
1413 WCHAR *registered_package = NULL, unsquashed[GUID_SIZE];
1416 r = msi_locate_product( product, &context );
1417 if (r != ERROR_SUCCESS)
1420 r = MSIREG_OpenProductKey( product, NULL, context, &product_key, FALSE );
1421 if (r != ERROR_SUCCESS)
1424 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1425 if (r != ERROR_SUCCESS)
1427 RegCloseKey( product_key );
1430 r = ERROR_FUNCTION_FAILED;
1431 registered_package = msi_reg_get_val_str( product_key, INSTALLPROPERTY_PACKAGECODEW );
1432 if (!registered_package)
1435 unsquash_guid( registered_package, unsquashed );
1436 if (!strcmpiW( package, unsquashed ))
1438 WCHAR *filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1439 strcpyW( localfile, filename );
1440 msi_free( filename );
1444 msi_free( registered_package );
1445 RegCloseKey( props_key );
1446 RegCloseKey( product_key );
1450 static WCHAR *get_package_code( MSIDATABASE *db )
1455 if (!(si = MSI_GetSummaryInformationW( db->storage, 0 )))
1457 WARN("failed to load summary info\n");
1460 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1461 msiobj_release( &si->hdr );
1465 static UINT get_local_package( const WCHAR *filename, WCHAR *localfile )
1467 WCHAR *product_code, *package_code;
1471 if ((r = MSI_OpenDatabaseW( filename, MSIDBOPEN_READONLY, &db )) != ERROR_SUCCESS)
1473 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1474 return ERROR_FILE_NOT_FOUND;
1477 if (!(product_code = get_product_code( db )))
1479 msiobj_release( &db->hdr );
1480 return ERROR_INSTALL_PACKAGE_INVALID;
1482 if (!(package_code = get_package_code( db )))
1484 msi_free( product_code );
1485 msiobj_release( &db->hdr );
1486 return ERROR_INSTALL_PACKAGE_INVALID;
1488 r = get_registered_local_package( product_code, package_code, localfile );
1489 msi_free( package_code );
1490 msi_free( product_code );
1491 msiobj_release( &db->hdr );
1495 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1497 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1499 MSIPACKAGE *package;
1501 LPWSTR ptr, base_url = NULL;
1503 WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
1504 LPCWSTR file = szPackage;
1507 BOOL delete_on_close = FALSE;
1509 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1511 if( szPackage[0] == '#' )
1513 handle = atoiW(&szPackage[1]);
1514 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1517 IWineMsiRemoteDatabase *remote_database;
1519 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1520 if ( !remote_database )
1521 return ERROR_INVALID_HANDLE;
1523 IWineMsiRemoteDatabase_Release( remote_database );
1524 WARN("MsiOpenPackage not allowed during a custom action!\n");
1526 return ERROR_FUNCTION_FAILED;
1531 if ( UrlIsW( szPackage, URLIS_URL ) )
1533 r = msi_download_file( szPackage, cachefile );
1534 if (r != ERROR_SUCCESS)
1539 base_url = strdupW( szPackage );
1541 return ERROR_OUTOFMEMORY;
1543 ptr = strrchrW( base_url, '/' );
1544 if (ptr) *(ptr + 1) = '\0';
1546 r = get_local_package( file, localfile );
1547 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1549 r = msi_create_empty_local_file( localfile, dotmsi );
1550 if (r != ERROR_SUCCESS)
1553 if (!CopyFileW( file, localfile, FALSE ))
1556 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1557 DeleteFileW( localfile );
1560 delete_on_close = TRUE;
1562 TRACE("opening package %s\n", debugstr_w( localfile ));
1563 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1564 if (r != ERROR_SUCCESS)
1567 package = MSI_CreatePackage( db, base_url );
1568 msi_free( base_url );
1569 msiobj_release( &db->hdr );
1570 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1571 package->localfile = strdupW( localfile );
1572 package->delete_on_close = delete_on_close;
1574 si = MSI_GetSummaryInformationW( db->storage, 0 );
1577 WARN("failed to load summary info\n");
1578 msiobj_release( &package->hdr );
1579 return ERROR_INSTALL_PACKAGE_INVALID;
1581 r = msi_parse_summary( si, package );
1582 msiobj_release( &si->hdr );
1583 if (r != ERROR_SUCCESS)
1585 WARN("failed to parse summary info %u\n", r);
1586 msiobj_release( &package->hdr );
1589 r = validate_package( package );
1590 if (r != ERROR_SUCCESS)
1592 msiobj_release( &package->hdr );
1595 msi_set_property( package->db, szDatabase, db->path );
1597 if( UrlIsW( szPackage, URLIS_URL ) )
1598 msi_set_property( package->db, szOriginalDatabase, szPackage );
1599 else if( szPackage[0] == '#' )
1600 msi_set_property( package->db, szOriginalDatabase, db->path );
1603 WCHAR fullpath[MAX_PATH];
1605 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1606 msi_set_property( package->db, szOriginalDatabase, fullpath );
1608 msi_set_context( package );
1612 WCHAR patch_code[GUID_SIZE];
1613 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1614 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1615 if (r != ERROR_SUCCESS)
1618 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1620 r = msi_apply_registered_patch( package, patch_code );
1621 if (r != ERROR_SUCCESS)
1623 ERR("registered patch failed to apply %u\n", r);
1624 msiobj_release( &package->hdr );
1631 msi_clone_properties( package );
1632 msi_adjust_privilege_properties( package );
1635 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1636 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1637 *pPackage = package;
1638 return ERROR_SUCCESS;
1641 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1643 MSIPACKAGE *package = NULL;
1646 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1648 if( !szPackage || !phPackage )
1649 return ERROR_INVALID_PARAMETER;
1653 FIXME("Should create an empty database and package\n");
1654 return ERROR_FUNCTION_FAILED;
1658 FIXME("dwOptions %08x not supported\n", dwOptions);
1660 ret = MSI_OpenPackageW( szPackage, &package );
1661 if( ret == ERROR_SUCCESS )
1663 *phPackage = alloc_msihandle( &package->hdr );
1665 ret = ERROR_NOT_ENOUGH_MEMORY;
1666 msiobj_release( &package->hdr );
1672 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1674 return MsiOpenPackageExW( szPackage, 0, phPackage );
1677 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1679 LPWSTR szwPack = NULL;
1684 szwPack = strdupAtoW( szPackage );
1686 return ERROR_OUTOFMEMORY;
1689 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1691 msi_free( szwPack );
1696 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1698 return MsiOpenPackageExA( szPackage, 0, phPackage );
1701 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1703 MSIPACKAGE *package;
1704 MSIHANDLE handle = 0;
1705 IUnknown *remote_unk;
1706 IWineMsiRemotePackage *remote_package;
1708 TRACE("(%d)\n",hInstall);
1710 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1713 handle = alloc_msihandle( &package->db->hdr );
1714 msiobj_release( &package->hdr );
1716 else if ((remote_unk = msi_get_remote(hInstall)))
1718 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1719 (LPVOID *)&remote_package) == S_OK)
1721 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1722 IWineMsiRemotePackage_Release(remote_package);
1726 WARN("remote handle %d is not a package\n", hInstall);
1728 IUnknown_Release(remote_unk);
1734 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1736 static const WCHAR szActionData[] =
1737 {'A','c','t','i','o','n','D','a','t','a',0};
1738 static const WCHAR szSetProgress[] =
1739 {'S','e','t','P','r','o','g','r','e','s','s',0};
1740 static const WCHAR szActionText[] =
1741 {'A','c','t','i','o','n','T','e','x','t',0};
1743 DWORD i, len, total_len, log_type = 0;
1747 TRACE("%x\n", eMessageType);
1749 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1750 log_type |= INSTALLLOGMODE_ERROR;
1751 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1752 log_type |= INSTALLLOGMODE_WARNING;
1753 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1754 log_type |= INSTALLLOGMODE_USER;
1755 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1756 log_type |= INSTALLLOGMODE_INFO;
1757 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1758 log_type |= INSTALLLOGMODE_COMMONDATA;
1759 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1760 log_type |= INSTALLLOGMODE_ACTIONSTART;
1761 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1762 log_type |= INSTALLLOGMODE_ACTIONDATA;
1764 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1767 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1769 static const WCHAR template_s[]=
1770 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1771 static const WCHAR format[] =
1772 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1774 LPCWSTR action_text, action;
1775 LPWSTR deformatted = NULL;
1777 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1779 action = MSI_RecordGetString(record, 1);
1780 action_text = MSI_RecordGetString(record, 2);
1782 if (!action || !action_text)
1785 deformat_string(package, action_text, &deformatted);
1787 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1789 len += strlenW(deformatted);
1790 message = msi_alloc(len*sizeof(WCHAR));
1791 sprintfW(message, template_s, timet, action);
1793 strcatW(message, deformatted);
1794 msi_free(deformatted);
1798 static const WCHAR format[] = {'%','u',':',' ',0};
1799 UINT count = MSI_RecordGetFieldCount( record );
1803 for (i = 1; i <= count; i++)
1806 MSI_RecordGetStringW( record, i, NULL, &len );
1807 total_len += len + 13;
1809 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1810 if (!p) return ERROR_OUTOFMEMORY;
1812 for (i = 1; i <= count; i++)
1816 len = sprintfW( p, format, i );
1821 MSI_RecordGetStringW( record, i, p, &len );
1824 if (count > 1 && total_len)
1833 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1834 gUIFilter, log_type, debugstr_w(message));
1836 /* convert it to ASCII */
1837 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1838 msg = msi_alloc( len );
1839 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1841 if (gUIHandlerW && (gUIFilter & log_type))
1843 rc = gUIHandlerW( gUIContext, eMessageType, message );
1845 else if (gUIHandlerA && (gUIFilter & log_type))
1847 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1849 else if (gUIHandlerRecord && (gUIFilter & log_type))
1851 MSIHANDLE rec = MsiCreateRecord( 1 );
1852 MsiRecordSetStringW( rec, 0, message );
1853 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1854 MsiCloseHandle( rec );
1857 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1858 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1861 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1862 WriteFile( package->log_file, "\n", 1, &written, NULL );
1865 msi_free( message );
1867 switch (eMessageType & 0xff000000)
1869 case INSTALLMESSAGE_ACTIONDATA:
1870 /* FIXME: format record here instead of in ui_actiondata to get the
1871 * correct action data for external scripts */
1872 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1874 case INSTALLMESSAGE_ACTIONSTART:
1878 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1880 deformat_string(package, action_text, &deformated);
1881 uirow = MSI_CreateRecord(1);
1882 MSI_RecordSetStringW(uirow, 1, deformated);
1883 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1884 msi_free(deformated);
1886 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1888 msiobj_release(&uirow->hdr);
1891 case INSTALLMESSAGE_PROGRESS:
1892 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1896 return ERROR_SUCCESS;
1899 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1902 UINT ret = ERROR_INVALID_HANDLE;
1903 MSIPACKAGE *package = NULL;
1904 MSIRECORD *record = NULL;
1906 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1910 IWineMsiRemotePackage *remote_package;
1912 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1913 if (!remote_package)
1914 return ERROR_INVALID_HANDLE;
1916 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1918 IWineMsiRemotePackage_Release( remote_package );
1922 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1923 return HRESULT_CODE(hr);
1925 return ERROR_FUNCTION_FAILED;
1928 return ERROR_SUCCESS;
1931 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1935 ret = MSI_ProcessMessage( package, eMessageType, record );
1938 msiobj_release( &package->hdr );
1940 msiobj_release( &record->hdr );
1947 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1949 LPWSTR szwName = NULL, szwValue = NULL;
1950 UINT r = ERROR_OUTOFMEMORY;
1952 szwName = strdupAtoW( szName );
1953 if( szName && !szwName )
1956 szwValue = strdupAtoW( szValue );
1957 if( szValue && !szwValue )
1960 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1963 msi_free( szwName );
1964 msi_free( szwValue );
1969 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1973 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1977 msi_free( folder->ResolvedSource );
1978 folder->ResolvedSource = NULL;
1982 msi_free( folder->ResolvedTarget );
1983 folder->ResolvedTarget = NULL;
1988 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1990 static const WCHAR insert_query[] = {
1991 'I','N','S','E','R','T',' ','I','N','T','O',' ',
1992 '`','_','P','r','o','p','e','r','t','y','`',' ',
1993 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
1994 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
1995 static const WCHAR update_query[] = {
1996 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
1997 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
1998 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1999 static const WCHAR delete_query[] = {
2000 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2001 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2002 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2004 MSIRECORD *row = NULL;
2009 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
2012 return ERROR_INVALID_PARAMETER;
2014 /* this one is weird... */
2016 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2018 rc = msi_get_property(db, szName, 0, &sz);
2019 if (!szValue || !*szValue)
2021 sprintfW(query, delete_query, szName);
2023 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2025 sprintfW(query, update_query, szName);
2027 row = MSI_CreateRecord(1);
2028 MSI_RecordSetStringW(row, 1, szValue);
2032 strcpyW(query, insert_query);
2034 row = MSI_CreateRecord(2);
2035 MSI_RecordSetStringW(row, 1, szName);
2036 MSI_RecordSetStringW(row, 2, szValue);
2039 rc = MSI_DatabaseOpenViewW(db, query, &view);
2040 if (rc == ERROR_SUCCESS)
2042 rc = MSI_ViewExecute(view, row);
2043 MSI_ViewClose(view);
2044 msiobj_release(&view->hdr);
2046 if (row) msiobj_release(&row->hdr);
2050 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2052 MSIPACKAGE *package;
2055 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2059 BSTR name = NULL, value = NULL;
2060 IWineMsiRemotePackage *remote_package;
2062 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2063 if (!remote_package)
2064 return ERROR_INVALID_HANDLE;
2066 name = SysAllocString( szName );
2067 value = SysAllocString( szValue );
2068 if ((!name && szName) || (!value && szValue))
2070 SysFreeString( name );
2071 SysFreeString( value );
2072 IWineMsiRemotePackage_Release( remote_package );
2073 return ERROR_OUTOFMEMORY;
2076 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2078 SysFreeString( name );
2079 SysFreeString( value );
2080 IWineMsiRemotePackage_Release( remote_package );
2084 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2085 return HRESULT_CODE(hr);
2087 return ERROR_FUNCTION_FAILED;
2090 return ERROR_SUCCESS;
2093 ret = msi_set_property( package->db, szName, szValue );
2094 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2095 msi_reset_folders( package, TRUE );
2097 msiobj_release( &package->hdr );
2101 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2103 static const WCHAR query[]= {
2104 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2105 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2106 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2107 MSIRECORD *rec, *row = NULL;
2111 if (!name || !*name)
2114 rec = MSI_CreateRecord(1);
2118 MSI_RecordSetStringW(rec, 1, name);
2120 r = MSI_DatabaseOpenViewW(db, query, &view);
2121 if (r == ERROR_SUCCESS)
2123 MSI_ViewExecute(view, rec);
2124 MSI_ViewFetch(view, &row);
2125 MSI_ViewClose(view);
2126 msiobj_release(&view->hdr);
2128 msiobj_release(&rec->hdr);
2132 /* internal function, not compatible with MsiGetPropertyW */
2133 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2134 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2137 UINT rc = ERROR_FUNCTION_FAILED;
2139 row = msi_get_property_row( db, szName );
2141 if (*pchValueBuf > 0)
2146 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2147 msiobj_release(&row->hdr);
2150 if (rc == ERROR_SUCCESS)
2151 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2152 debugstr_w(szName));
2153 else if (rc == ERROR_MORE_DATA)
2154 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2155 debugstr_w(szName));
2159 TRACE("property %s not found\n", debugstr_w(szName));
2165 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2171 r = msi_get_property(db, prop, NULL, &sz);
2172 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2176 str = msi_alloc(sz * sizeof(WCHAR));
2177 r = msi_get_property(db, prop, str, &sz);
2178 if (r != ERROR_SUCCESS)
2187 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2189 LPWSTR str = msi_dup_property( db, prop );
2190 int val = str ? atoiW(str) : def;
2195 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2196 awstring *szValueBuf, LPDWORD pchValueBuf )
2198 MSIPACKAGE *package;
2199 MSIRECORD *row = NULL;
2200 UINT r = ERROR_FUNCTION_FAILED;
2203 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2204 szValueBuf->str.w, pchValueBuf );
2207 return ERROR_INVALID_PARAMETER;
2209 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2213 IWineMsiRemotePackage *remote_package;
2214 LPWSTR value = NULL;
2218 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2219 if (!remote_package)
2220 return ERROR_INVALID_HANDLE;
2222 bname = SysAllocString( name );
2225 IWineMsiRemotePackage_Release( remote_package );
2226 return ERROR_OUTOFMEMORY;
2230 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2235 value = msi_alloc(len * sizeof(WCHAR));
2238 r = ERROR_OUTOFMEMORY;
2242 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, value, &len );
2246 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2248 /* Bug required by Adobe installers */
2249 if (!szValueBuf->unicode && !szValueBuf->str.a)
2250 *pchValueBuf *= sizeof(WCHAR);
2253 IWineMsiRemotePackage_Release(remote_package);
2254 SysFreeString(bname);
2259 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2260 return HRESULT_CODE(hr);
2262 return ERROR_FUNCTION_FAILED;
2268 row = msi_get_property_row( package->db, name );
2270 val = MSI_RecordGetString( row, 1 );
2275 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2278 msiobj_release( &row->hdr );
2279 msiobj_release( &package->hdr );
2284 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2285 LPSTR szValueBuf, LPDWORD pchValueBuf )
2291 val.unicode = FALSE;
2292 val.str.a = szValueBuf;
2294 name = strdupAtoW( szName );
2295 if (szName && !name)
2296 return ERROR_OUTOFMEMORY;
2298 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2303 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2304 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2309 val.str.w = szValueBuf;
2311 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2314 typedef struct _msi_remote_package_impl {
2315 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2318 } msi_remote_package_impl;
2320 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2322 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2325 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2326 REFIID riid,LPVOID *ppobj)
2328 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2329 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2331 IUnknown_AddRef( iface );
2336 return E_NOINTERFACE;
2339 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2341 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2343 return InterlockedIncrement( &This->refs );
2346 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2348 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2351 r = InterlockedDecrement( &This->refs );
2354 MsiCloseHandle( This->package );
2360 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2362 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2363 This->package = handle;
2367 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2369 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2370 IWineMsiRemoteDatabase *rdb = NULL;
2374 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2375 if (FAILED(hr) || !rdb)
2377 ERR("Failed to create remote database\n");
2381 hdb = MsiGetActiveDatabase(This->package);
2383 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2386 ERR("Failed to set the database handle\n");
2390 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2394 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value, DWORD *size )
2396 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2397 UINT r = MsiGetPropertyW(This->package, property, value, size);
2398 if (r != ERROR_SUCCESS) return HRESULT_FROM_WIN32(r);
2402 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2404 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2405 UINT r = MsiSetPropertyW(This->package, property, value);
2406 return HRESULT_FROM_WIN32(r);
2409 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2411 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2412 UINT r = MsiProcessMessage(This->package, message, record);
2413 return HRESULT_FROM_WIN32(r);
2416 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2418 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2419 UINT r = MsiDoActionW(This->package, action);
2420 return HRESULT_FROM_WIN32(r);
2423 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2425 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2426 UINT r = MsiSequenceW(This->package, table, sequence);
2427 return HRESULT_FROM_WIN32(r);
2430 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2432 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2433 UINT r = MsiGetTargetPathW(This->package, folder, value, size);
2434 return HRESULT_FROM_WIN32(r);
2437 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2439 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2440 UINT r = MsiSetTargetPathW(This->package, folder, value);
2441 return HRESULT_FROM_WIN32(r);
2444 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2446 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2447 UINT r = MsiGetSourcePathW(This->package, folder, value, size);
2448 return HRESULT_FROM_WIN32(r);
2451 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2453 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2454 *ret = MsiGetMode(This->package, mode);
2458 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2460 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2461 UINT r = MsiSetMode(This->package, mode, state);
2462 return HRESULT_FROM_WIN32(r);
2465 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2466 INSTALLSTATE *installed, INSTALLSTATE *action )
2468 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2469 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2470 return HRESULT_FROM_WIN32(r);
2473 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2475 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2476 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2477 return HRESULT_FROM_WIN32(r);
2480 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2481 INSTALLSTATE *installed, INSTALLSTATE *action )
2483 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2484 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2485 return HRESULT_FROM_WIN32(r);
2488 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2490 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2491 UINT r = MsiSetComponentStateW(This->package, component, state);
2492 return HRESULT_FROM_WIN32(r);
2495 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2497 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2498 *language = MsiGetLanguage(This->package);
2502 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2504 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2505 UINT r = MsiSetInstallLevel(This->package, level);
2506 return HRESULT_FROM_WIN32(r);
2509 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2513 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2514 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2515 if (r == ERROR_SUCCESS)
2517 *value = SysAllocStringLen(NULL, size);
2519 return E_OUTOFMEMORY;
2521 r = MsiFormatRecordW(This->package, record, *value, &size);
2523 return HRESULT_FROM_WIN32(r);
2526 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2528 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2529 UINT r = MsiEvaluateConditionW(This->package, condition);
2530 return HRESULT_FROM_WIN32(r);
2533 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2534 INT cost_tree, INSTALLSTATE state, INT *cost )
2536 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2537 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2538 return HRESULT_FROM_WIN32(r);
2541 static HRESULT WINAPI mrp_EnumComponentCosts( IWineMsiRemotePackage *iface, BSTR component,
2542 DWORD index, INSTALLSTATE state, BSTR drive,
2543 DWORD *buflen, INT *cost, INT *temp )
2545 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2546 UINT r = MsiEnumComponentCostsW(This->package, component, index, state, drive, buflen, cost, temp);
2547 return HRESULT_FROM_WIN32(r);
2550 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2556 mrp_GetActiveDatabase,
2567 mrp_GetFeatureState,
2568 mrp_SetFeatureState,
2569 mrp_GetComponentState,
2570 mrp_SetComponentState,
2572 mrp_SetInstallLevel,
2574 mrp_EvaluateCondition,
2576 mrp_EnumComponentCosts
2579 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2581 msi_remote_package_impl* This;
2583 This = msi_alloc( sizeof *This );
2585 return E_OUTOFMEMORY;
2587 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2596 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2597 LPCWSTR property, LPWSTR value)
2599 MSISOURCELISTINFO *info;
2601 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2603 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2606 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2608 return ERROR_OUTOFMEMORY;
2610 info->context = context;
2611 info->options = options;
2612 info->property = property;
2613 info->value = strdupW(value);
2614 list_add_head(&package->sourcelist_info, &info->entry);
2616 return ERROR_SUCCESS;
2619 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2620 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2624 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2626 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2629 disk = msi_alloc(sizeof(MSIMEDIADISK));
2631 return ERROR_OUTOFMEMORY;
2633 disk->context = context;
2634 disk->options = options;
2635 disk->disk_id = disk_id;
2636 disk->volume_label = strdupW(volume_label);
2637 disk->disk_prompt = strdupW(disk_prompt);
2638 list_add_head(&package->sourcelist_media, &disk->entry);
2640 return ERROR_SUCCESS;