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->binaries )
298 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
300 list_remove( &binary->entry );
302 FreeLibrary( binary->module );
303 if (!DeleteFileW( binary->tmpfile ))
304 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
305 msi_free( binary->source );
306 msi_free( binary->tmpfile );
310 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
312 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
314 list_remove( &cab->entry );
315 IStorage_Release( cab->storage );
316 msi_free( cab->stream );
320 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
322 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
324 list_remove( &patch->entry );
325 if (patch->delete_on_close && !DeleteFileW( patch->localfile ))
327 ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError());
329 msi_free_patchinfo( patch );
332 msi_free( package->BaseURL );
333 msi_free( package->PackagePath );
334 msi_free( package->ProductCode );
335 msi_free( package->ActionFormat );
336 msi_free( package->LastAction );
337 msi_free( package->langids );
339 remove_tracked_tempfiles(package);
341 /* cleanup control event subscriptions */
342 ControlEvent_CleanupSubscriptions( package );
345 static void MSI_FreePackage( MSIOBJECTHDR *arg)
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 ((q = strchrW( template, ',' ))) *q = 0;
1284 if (!template[0] || !strcmpW( template, szIntel ))
1285 package->platform = PLATFORM_INTEL;
1286 else if (!strcmpW( template, szIntel64 ))
1287 package->platform = PLATFORM_INTEL64;
1288 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1289 package->platform = PLATFORM_X64;
1292 WARN("unknown platform %s\n", debugstr_w(template));
1293 msi_free( template );
1294 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1299 msi_free( template );
1300 return ERROR_SUCCESS;
1303 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1305 package->langids = msi_alloc( count * sizeof(LANGID) );
1306 if (!package->langids)
1308 msi_free( template );
1309 return ERROR_OUTOFMEMORY;
1315 q = strchrW( p, ',' );
1317 package->langids[i] = atoiW( p );
1322 package->num_langids = i + 1;
1324 msi_free( template );
1325 return ERROR_SUCCESS;
1328 static UINT validate_package( MSIPACKAGE *package )
1333 if (package->platform == PLATFORM_INTEL64)
1335 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1337 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1338 if (package->platform == PLATFORM_X64)
1340 if (!is_64bit && !is_wow64)
1341 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1342 if (package->version < 200)
1343 return ERROR_INSTALL_PACKAGE_INVALID;
1345 if (!package->num_langids)
1347 return ERROR_SUCCESS;
1349 for (i = 0; i < package->num_langids; i++)
1351 LANGID langid = package->langids[i];
1353 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1355 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1357 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1359 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1361 if (IsValidLocale( langid, LCID_INSTALLED ))
1362 return ERROR_SUCCESS;
1364 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1367 int msi_track_tempfile( MSIPACKAGE *package, const WCHAR *path )
1371 TRACE("%s\n", debugstr_w(path));
1373 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
1375 if (!strcmpW( path, temp->Path )) return 0;
1377 if (!(temp = msi_alloc_zero( sizeof (MSITEMPFILE) ))) return -1;
1378 list_add_head( &package->tempfiles, &temp->entry );
1379 temp->Path = strdupW( path );
1383 static WCHAR *get_product_code( MSIDATABASE *db )
1385 static const WCHAR query[] = {
1386 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1387 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1388 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1389 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1394 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1398 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1400 MSI_ViewClose( view );
1401 msiobj_release( &view->hdr );
1404 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1406 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1407 msiobj_release( &rec->hdr );
1409 MSI_ViewClose( view );
1410 msiobj_release( &view->hdr );
1414 static UINT get_registered_local_package( const WCHAR *product, const WCHAR *package, WCHAR *localfile )
1416 MSIINSTALLCONTEXT context;
1417 HKEY product_key, props_key;
1418 WCHAR *registered_package = NULL, unsquashed[GUID_SIZE];
1421 r = msi_locate_product( product, &context );
1422 if (r != ERROR_SUCCESS)
1425 r = MSIREG_OpenProductKey( product, NULL, context, &product_key, FALSE );
1426 if (r != ERROR_SUCCESS)
1429 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1430 if (r != ERROR_SUCCESS)
1432 RegCloseKey( product_key );
1435 r = ERROR_FUNCTION_FAILED;
1436 registered_package = msi_reg_get_val_str( product_key, INSTALLPROPERTY_PACKAGECODEW );
1437 if (!registered_package)
1440 unsquash_guid( registered_package, unsquashed );
1441 if (!strcmpiW( package, unsquashed ))
1443 WCHAR *filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1444 strcpyW( localfile, filename );
1445 msi_free( filename );
1449 msi_free( registered_package );
1450 RegCloseKey( props_key );
1451 RegCloseKey( product_key );
1455 static WCHAR *get_package_code( MSIDATABASE *db )
1460 if (!(si = MSI_GetSummaryInformationW( db->storage, 0 )))
1462 WARN("failed to load summary info\n");
1465 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1466 msiobj_release( &si->hdr );
1470 static UINT get_local_package( const WCHAR *filename, WCHAR *localfile )
1472 WCHAR *product_code, *package_code;
1476 if ((r = MSI_OpenDatabaseW( filename, MSIDBOPEN_READONLY, &db )) != ERROR_SUCCESS)
1478 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1479 return ERROR_FILE_NOT_FOUND;
1482 if (!(product_code = get_product_code( db )))
1484 msiobj_release( &db->hdr );
1485 return ERROR_INSTALL_PACKAGE_INVALID;
1487 if (!(package_code = get_package_code( db )))
1489 msi_free( product_code );
1490 msiobj_release( &db->hdr );
1491 return ERROR_INSTALL_PACKAGE_INVALID;
1493 r = get_registered_local_package( product_code, package_code, localfile );
1494 msi_free( package_code );
1495 msi_free( product_code );
1496 msiobj_release( &db->hdr );
1500 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1502 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1504 MSIPACKAGE *package;
1506 LPWSTR ptr, base_url = NULL;
1508 WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
1509 LPCWSTR file = szPackage;
1512 BOOL delete_on_close = FALSE;
1514 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1517 if( szPackage[0] == '#' )
1519 handle = atoiW(&szPackage[1]);
1520 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1523 IWineMsiRemoteDatabase *remote_database;
1525 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1526 if ( !remote_database )
1527 return ERROR_INVALID_HANDLE;
1529 IWineMsiRemoteDatabase_Release( remote_database );
1530 WARN("MsiOpenPackage not allowed during a custom action!\n");
1532 return ERROR_FUNCTION_FAILED;
1537 if ( UrlIsW( szPackage, URLIS_URL ) )
1539 r = msi_download_file( szPackage, cachefile );
1540 if (r != ERROR_SUCCESS)
1545 base_url = strdupW( szPackage );
1547 return ERROR_OUTOFMEMORY;
1549 ptr = strrchrW( base_url, '/' );
1550 if (ptr) *(ptr + 1) = '\0';
1552 r = get_local_package( file, localfile );
1553 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1555 r = msi_create_empty_local_file( localfile, dotmsi );
1556 if (r != ERROR_SUCCESS)
1559 if (!CopyFileW( file, localfile, FALSE ))
1562 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1563 DeleteFileW( localfile );
1566 delete_on_close = TRUE;
1568 TRACE("opening package %s\n", debugstr_w( localfile ));
1569 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1570 if (r != ERROR_SUCCESS)
1573 package = MSI_CreatePackage( db, base_url );
1574 msi_free( base_url );
1575 msiobj_release( &db->hdr );
1576 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1577 package->localfile = strdupW( localfile );
1578 package->delete_on_close = delete_on_close;
1580 si = MSI_GetSummaryInformationW( db->storage, 0 );
1583 WARN("failed to load summary info\n");
1584 msiobj_release( &package->hdr );
1585 return ERROR_INSTALL_PACKAGE_INVALID;
1587 r = msi_parse_summary( si, package );
1588 msiobj_release( &si->hdr );
1589 if (r != ERROR_SUCCESS)
1591 WARN("failed to parse summary info %u\n", r);
1592 msiobj_release( &package->hdr );
1595 r = validate_package( package );
1596 if (r != ERROR_SUCCESS)
1598 msiobj_release( &package->hdr );
1601 msi_set_property( package->db, szDatabase, db->path );
1603 if( UrlIsW( szPackage, URLIS_URL ) )
1604 msi_set_property( package->db, szOriginalDatabase, szPackage );
1605 else if( szPackage[0] == '#' )
1606 msi_set_property( package->db, szOriginalDatabase, db->path );
1609 WCHAR fullpath[MAX_PATH];
1611 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1612 msi_set_property( package->db, szOriginalDatabase, fullpath );
1614 msi_set_context( package );
1618 WCHAR patch_code[GUID_SIZE];
1619 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1620 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1621 if (r != ERROR_SUCCESS)
1624 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1626 r = msi_apply_registered_patch( package, patch_code );
1627 if (r != ERROR_SUCCESS)
1629 ERR("registered patch failed to apply %u\n", r);
1630 msiobj_release( &package->hdr );
1637 msi_clone_properties( package );
1638 msi_adjust_privilege_properties( package );
1641 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1642 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1643 *pPackage = package;
1644 return ERROR_SUCCESS;
1647 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1649 MSIPACKAGE *package = NULL;
1652 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1654 if( !szPackage || !phPackage )
1655 return ERROR_INVALID_PARAMETER;
1659 FIXME("Should create an empty database and package\n");
1660 return ERROR_FUNCTION_FAILED;
1664 FIXME("dwOptions %08x not supported\n", dwOptions);
1666 ret = MSI_OpenPackageW( szPackage, &package );
1667 if( ret == ERROR_SUCCESS )
1669 *phPackage = alloc_msihandle( &package->hdr );
1671 ret = ERROR_NOT_ENOUGH_MEMORY;
1672 msiobj_release( &package->hdr );
1678 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1680 return MsiOpenPackageExW( szPackage, 0, phPackage );
1683 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1685 LPWSTR szwPack = NULL;
1690 szwPack = strdupAtoW( szPackage );
1692 return ERROR_OUTOFMEMORY;
1695 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1697 msi_free( szwPack );
1702 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1704 return MsiOpenPackageExA( szPackage, 0, phPackage );
1707 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1709 MSIPACKAGE *package;
1710 MSIHANDLE handle = 0;
1711 IUnknown *remote_unk;
1712 IWineMsiRemotePackage *remote_package;
1714 TRACE("(%d)\n",hInstall);
1716 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1719 handle = alloc_msihandle( &package->db->hdr );
1720 msiobj_release( &package->hdr );
1722 else if ((remote_unk = msi_get_remote(hInstall)))
1724 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1725 (LPVOID *)&remote_package) == S_OK)
1727 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1728 IWineMsiRemotePackage_Release(remote_package);
1732 WARN("remote handle %d is not a package\n", hInstall);
1734 IUnknown_Release(remote_unk);
1740 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1742 static const WCHAR szActionData[] =
1743 {'A','c','t','i','o','n','D','a','t','a',0};
1744 static const WCHAR szSetProgress[] =
1745 {'S','e','t','P','r','o','g','r','e','s','s',0};
1746 static const WCHAR szActionText[] =
1747 {'A','c','t','i','o','n','T','e','x','t',0};
1749 DWORD i, len, total_len, log_type = 0;
1753 TRACE("%x\n", eMessageType);
1755 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1756 log_type |= INSTALLLOGMODE_ERROR;
1757 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1758 log_type |= INSTALLLOGMODE_WARNING;
1759 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1760 log_type |= INSTALLLOGMODE_USER;
1761 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1762 log_type |= INSTALLLOGMODE_INFO;
1763 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1764 log_type |= INSTALLLOGMODE_COMMONDATA;
1765 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1766 log_type |= INSTALLLOGMODE_ACTIONSTART;
1767 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1768 log_type |= INSTALLLOGMODE_ACTIONDATA;
1770 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1773 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1775 static const WCHAR template_s[]=
1776 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1777 static const WCHAR format[] =
1778 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1780 LPCWSTR action_text, action;
1781 LPWSTR deformatted = NULL;
1783 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1785 action = MSI_RecordGetString(record, 1);
1786 action_text = MSI_RecordGetString(record, 2);
1788 if (!action || !action_text)
1791 deformat_string(package, action_text, &deformatted);
1793 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1795 len += strlenW(deformatted);
1796 message = msi_alloc(len*sizeof(WCHAR));
1797 sprintfW(message, template_s, timet, action);
1799 strcatW(message, deformatted);
1800 msi_free(deformatted);
1804 static const WCHAR format[] = {'%','u',':',' ',0};
1805 UINT count = MSI_RecordGetFieldCount( record );
1809 for (i = 1; i <= count; i++)
1812 MSI_RecordGetStringW( record, i, NULL, &len );
1813 total_len += len + 13;
1815 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1816 if (!p) return ERROR_OUTOFMEMORY;
1818 for (i = 1; i <= count; i++)
1822 len = sprintfW( p, format, i );
1827 MSI_RecordGetStringW( record, i, p, &len );
1830 if (count > 1 && total_len)
1839 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1840 gUIFilter, log_type, debugstr_w(message));
1842 /* convert it to ASCII */
1843 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1844 msg = msi_alloc( len );
1845 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1847 if (gUIHandlerW && (gUIFilter & log_type))
1849 rc = gUIHandlerW( gUIContext, eMessageType, message );
1851 else if (gUIHandlerA && (gUIFilter & log_type))
1853 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1855 else if (gUIHandlerRecord && (gUIFilter & log_type))
1857 MSIHANDLE rec = MsiCreateRecord( 1 );
1858 MsiRecordSetStringW( rec, 0, message );
1859 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1860 MsiCloseHandle( rec );
1863 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1864 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1867 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1868 WriteFile( package->log_file, "\n", 1, &written, NULL );
1871 msi_free( message );
1873 switch (eMessageType & 0xff000000)
1875 case INSTALLMESSAGE_ACTIONDATA:
1876 /* FIXME: format record here instead of in ui_actiondata to get the
1877 * correct action data for external scripts */
1878 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1880 case INSTALLMESSAGE_ACTIONSTART:
1884 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1886 deformat_string(package, action_text, &deformated);
1887 uirow = MSI_CreateRecord(1);
1888 MSI_RecordSetStringW(uirow, 1, deformated);
1889 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1890 msi_free(deformated);
1892 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1894 msiobj_release(&uirow->hdr);
1897 case INSTALLMESSAGE_PROGRESS:
1898 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1902 return ERROR_SUCCESS;
1905 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1908 UINT ret = ERROR_INVALID_HANDLE;
1909 MSIPACKAGE *package = NULL;
1910 MSIRECORD *record = NULL;
1912 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1916 IWineMsiRemotePackage *remote_package;
1918 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1919 if (!remote_package)
1920 return ERROR_INVALID_HANDLE;
1922 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1924 IWineMsiRemotePackage_Release( remote_package );
1928 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1929 return HRESULT_CODE(hr);
1931 return ERROR_FUNCTION_FAILED;
1934 return ERROR_SUCCESS;
1937 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1941 ret = MSI_ProcessMessage( package, eMessageType, record );
1944 msiobj_release( &package->hdr );
1946 msiobj_release( &record->hdr );
1953 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1955 LPWSTR szwName = NULL, szwValue = NULL;
1956 UINT r = ERROR_OUTOFMEMORY;
1958 szwName = strdupAtoW( szName );
1959 if( szName && !szwName )
1962 szwValue = strdupAtoW( szValue );
1963 if( szValue && !szwValue )
1966 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1969 msi_free( szwName );
1970 msi_free( szwValue );
1975 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1979 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1983 msi_free( folder->ResolvedSource );
1984 folder->ResolvedSource = NULL;
1988 msi_free( folder->ResolvedTarget );
1989 folder->ResolvedTarget = NULL;
1994 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1996 static const WCHAR insert_query[] = {
1997 'I','N','S','E','R','T',' ','I','N','T','O',' ',
1998 '`','_','P','r','o','p','e','r','t','y','`',' ',
1999 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2000 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2001 static const WCHAR update_query[] = {
2002 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2003 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2004 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2005 static const WCHAR delete_query[] = {
2006 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2007 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2008 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2010 MSIRECORD *row = NULL;
2015 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
2018 return ERROR_INVALID_PARAMETER;
2020 /* this one is weird... */
2022 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2024 rc = msi_get_property(db, szName, 0, &sz);
2025 if (!szValue || !*szValue)
2027 sprintfW(query, delete_query, szName);
2029 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2031 sprintfW(query, update_query, szName);
2033 row = MSI_CreateRecord(1);
2034 MSI_RecordSetStringW(row, 1, szValue);
2038 strcpyW(query, insert_query);
2040 row = MSI_CreateRecord(2);
2041 MSI_RecordSetStringW(row, 1, szName);
2042 MSI_RecordSetStringW(row, 2, szValue);
2045 rc = MSI_DatabaseOpenViewW(db, query, &view);
2046 if (rc == ERROR_SUCCESS)
2048 rc = MSI_ViewExecute(view, row);
2049 MSI_ViewClose(view);
2050 msiobj_release(&view->hdr);
2052 if (row) msiobj_release(&row->hdr);
2056 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2058 MSIPACKAGE *package;
2061 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2065 BSTR name = NULL, value = NULL;
2066 IWineMsiRemotePackage *remote_package;
2068 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2069 if (!remote_package)
2070 return ERROR_INVALID_HANDLE;
2072 name = SysAllocString( szName );
2073 value = SysAllocString( szValue );
2074 if ((!name && szName) || (!value && szValue))
2076 SysFreeString( name );
2077 SysFreeString( value );
2078 IWineMsiRemotePackage_Release( remote_package );
2079 return ERROR_OUTOFMEMORY;
2082 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2084 SysFreeString( name );
2085 SysFreeString( value );
2086 IWineMsiRemotePackage_Release( remote_package );
2090 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2091 return HRESULT_CODE(hr);
2093 return ERROR_FUNCTION_FAILED;
2096 return ERROR_SUCCESS;
2099 ret = msi_set_property( package->db, szName, szValue );
2100 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2101 msi_reset_folders( package, TRUE );
2103 msiobj_release( &package->hdr );
2107 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2109 static const WCHAR query[]= {
2110 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2111 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2112 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2113 MSIRECORD *rec, *row = NULL;
2117 if (!name || !*name)
2120 rec = MSI_CreateRecord(1);
2124 MSI_RecordSetStringW(rec, 1, name);
2126 r = MSI_DatabaseOpenViewW(db, query, &view);
2127 if (r == ERROR_SUCCESS)
2129 MSI_ViewExecute(view, rec);
2130 MSI_ViewFetch(view, &row);
2131 MSI_ViewClose(view);
2132 msiobj_release(&view->hdr);
2134 msiobj_release(&rec->hdr);
2138 /* internal function, not compatible with MsiGetPropertyW */
2139 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2140 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2143 UINT rc = ERROR_FUNCTION_FAILED;
2145 row = msi_get_property_row( db, szName );
2147 if (*pchValueBuf > 0)
2152 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2153 msiobj_release(&row->hdr);
2156 if (rc == ERROR_SUCCESS)
2157 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2158 debugstr_w(szName));
2159 else if (rc == ERROR_MORE_DATA)
2160 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2161 debugstr_w(szName));
2165 TRACE("property %s not found\n", debugstr_w(szName));
2171 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2177 r = msi_get_property(db, prop, NULL, &sz);
2178 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2182 str = msi_alloc(sz * sizeof(WCHAR));
2183 r = msi_get_property(db, prop, str, &sz);
2184 if (r != ERROR_SUCCESS)
2193 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2195 LPWSTR str = msi_dup_property( db, prop );
2196 int val = str ? atoiW(str) : def;
2201 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2202 awstring *szValueBuf, LPDWORD pchValueBuf )
2204 MSIPACKAGE *package;
2205 MSIRECORD *row = NULL;
2206 UINT r = ERROR_FUNCTION_FAILED;
2209 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2210 szValueBuf->str.w, pchValueBuf );
2213 return ERROR_INVALID_PARAMETER;
2215 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2219 IWineMsiRemotePackage *remote_package;
2220 LPWSTR value = NULL;
2224 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2225 if (!remote_package)
2226 return ERROR_INVALID_HANDLE;
2228 bname = SysAllocString( name );
2231 IWineMsiRemotePackage_Release( remote_package );
2232 return ERROR_OUTOFMEMORY;
2236 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2241 value = msi_alloc(len * sizeof(WCHAR));
2244 r = ERROR_OUTOFMEMORY;
2248 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, value, &len );
2252 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2254 /* Bug required by Adobe installers */
2255 if (!szValueBuf->unicode && !szValueBuf->str.a)
2256 *pchValueBuf *= sizeof(WCHAR);
2259 IWineMsiRemotePackage_Release(remote_package);
2260 SysFreeString(bname);
2265 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2266 return HRESULT_CODE(hr);
2268 return ERROR_FUNCTION_FAILED;
2274 row = msi_get_property_row( package->db, name );
2276 val = MSI_RecordGetString( row, 1 );
2281 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2284 msiobj_release( &row->hdr );
2285 msiobj_release( &package->hdr );
2290 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2291 LPSTR szValueBuf, LPDWORD pchValueBuf )
2297 val.unicode = FALSE;
2298 val.str.a = szValueBuf;
2300 name = strdupAtoW( szName );
2301 if (szName && !name)
2302 return ERROR_OUTOFMEMORY;
2304 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2309 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2310 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2315 val.str.w = szValueBuf;
2317 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2320 typedef struct _msi_remote_package_impl {
2321 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2324 } msi_remote_package_impl;
2326 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2328 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2331 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2332 REFIID riid,LPVOID *ppobj)
2334 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2335 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2337 IUnknown_AddRef( iface );
2342 return E_NOINTERFACE;
2345 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2347 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2349 return InterlockedIncrement( &This->refs );
2352 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2354 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2357 r = InterlockedDecrement( &This->refs );
2360 MsiCloseHandle( This->package );
2366 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2368 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2369 This->package = handle;
2373 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2375 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2376 IWineMsiRemoteDatabase *rdb = NULL;
2380 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2381 if (FAILED(hr) || !rdb)
2383 ERR("Failed to create remote database\n");
2387 hdb = MsiGetActiveDatabase(This->package);
2389 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2392 ERR("Failed to set the database handle\n");
2396 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2400 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value, DWORD *size )
2402 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2403 UINT r = MsiGetPropertyW(This->package, property, value, size);
2404 if (r != ERROR_SUCCESS) return HRESULT_FROM_WIN32(r);
2408 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2410 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2411 UINT r = MsiSetPropertyW(This->package, property, value);
2412 return HRESULT_FROM_WIN32(r);
2415 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2417 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2418 UINT r = MsiProcessMessage(This->package, message, record);
2419 return HRESULT_FROM_WIN32(r);
2422 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2424 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2425 UINT r = MsiDoActionW(This->package, action);
2426 return HRESULT_FROM_WIN32(r);
2429 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2431 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2432 UINT r = MsiSequenceW(This->package, table, sequence);
2433 return HRESULT_FROM_WIN32(r);
2436 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2438 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2439 UINT r = MsiGetTargetPathW(This->package, folder, value, size);
2440 return HRESULT_FROM_WIN32(r);
2443 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2445 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2446 UINT r = MsiSetTargetPathW(This->package, folder, value);
2447 return HRESULT_FROM_WIN32(r);
2450 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2452 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2453 UINT r = MsiGetSourcePathW(This->package, folder, value, size);
2454 return HRESULT_FROM_WIN32(r);
2457 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2459 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2460 *ret = MsiGetMode(This->package, mode);
2464 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2466 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2467 UINT r = MsiSetMode(This->package, mode, state);
2468 return HRESULT_FROM_WIN32(r);
2471 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2472 INSTALLSTATE *installed, INSTALLSTATE *action )
2474 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2475 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2476 return HRESULT_FROM_WIN32(r);
2479 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2481 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2482 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2483 return HRESULT_FROM_WIN32(r);
2486 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2487 INSTALLSTATE *installed, INSTALLSTATE *action )
2489 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2490 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2491 return HRESULT_FROM_WIN32(r);
2494 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2496 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2497 UINT r = MsiSetComponentStateW(This->package, component, state);
2498 return HRESULT_FROM_WIN32(r);
2501 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2503 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2504 *language = MsiGetLanguage(This->package);
2508 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2510 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2511 UINT r = MsiSetInstallLevel(This->package, level);
2512 return HRESULT_FROM_WIN32(r);
2515 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2519 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2520 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2521 if (r == ERROR_SUCCESS)
2523 *value = SysAllocStringLen(NULL, size);
2525 return E_OUTOFMEMORY;
2527 r = MsiFormatRecordW(This->package, record, *value, &size);
2529 return HRESULT_FROM_WIN32(r);
2532 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2534 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2535 UINT r = MsiEvaluateConditionW(This->package, condition);
2536 return HRESULT_FROM_WIN32(r);
2539 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2540 INT cost_tree, INSTALLSTATE state, INT *cost )
2542 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2543 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2544 return HRESULT_FROM_WIN32(r);
2547 static HRESULT WINAPI mrp_EnumComponentCosts( IWineMsiRemotePackage *iface, BSTR component,
2548 DWORD index, INSTALLSTATE state, BSTR drive,
2549 DWORD *buflen, INT *cost, INT *temp )
2551 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2552 UINT r = MsiEnumComponentCostsW(This->package, component, index, state, drive, buflen, cost, temp);
2553 return HRESULT_FROM_WIN32(r);
2556 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2562 mrp_GetActiveDatabase,
2573 mrp_GetFeatureState,
2574 mrp_SetFeatureState,
2575 mrp_GetComponentState,
2576 mrp_SetComponentState,
2578 mrp_SetInstallLevel,
2580 mrp_EvaluateCondition,
2582 mrp_EnumComponentCosts
2585 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2587 msi_remote_package_impl* This;
2589 This = msi_alloc( sizeof *This );
2591 return E_OUTOFMEMORY;
2593 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2602 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2603 LPCWSTR property, LPWSTR value)
2605 MSISOURCELISTINFO *info;
2607 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2609 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2612 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2614 return ERROR_OUTOFMEMORY;
2616 info->context = context;
2617 info->options = options;
2618 info->property = property;
2619 info->value = strdupW(value);
2620 list_add_head(&package->sourcelist_info, &info->entry);
2622 return ERROR_SUCCESS;
2625 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2626 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2630 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2632 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2635 disk = msi_alloc(sizeof(MSIMEDIADISK));
2637 return ERROR_OUTOFMEMORY;
2639 disk->context = context;
2640 disk->options = options;
2641 disk->disk_id = disk_id;
2642 disk->volume_label = strdupW(volume_label);
2643 disk->disk_prompt = strdupW(disk_prompt);
2644 list_add_head(&package->sourcelist_media, &disk->entry);
2646 return ERROR_SUCCESS;