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_extension( MSIEXTENSION *ext )
95 struct list *item, *cursor;
97 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
99 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
101 list_remove( &verb->entry );
102 msi_free( verb->Verb );
103 msi_free( verb->Command );
104 msi_free( verb->Argument );
108 msi_free( ext->Extension );
109 msi_free( ext->ProgIDText );
113 static void free_assembly( MSIASSEMBLY *assembly )
115 msi_free( assembly->feature );
116 msi_free( assembly->manifest );
117 msi_free( assembly->application );
118 msi_free( assembly->display_name );
119 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
120 msi_free( assembly->tempdir );
121 msi_free( assembly );
124 static void free_package_structures( MSIPACKAGE *package )
127 struct list *item, *cursor;
129 TRACE("Freeing package action data\n");
131 remove_tracked_tempfiles(package);
133 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
135 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
136 list_remove( &feature->entry );
137 free_feature( feature );
140 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
142 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
144 list_remove( &folder->entry );
145 msi_free( folder->Parent );
146 msi_free( folder->Directory );
147 msi_free( folder->TargetDefault );
148 msi_free( folder->SourceLongPath );
149 msi_free( folder->SourceShortPath );
150 msi_free( folder->ResolvedTarget );
151 msi_free( folder->ResolvedSource );
152 msi_free( folder->Property );
156 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
158 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
160 list_remove( &comp->entry );
161 msi_free( comp->Component );
162 msi_free( comp->ComponentId );
163 msi_free( comp->Directory );
164 msi_free( comp->Condition );
165 msi_free( comp->KeyPath );
166 msi_free( comp->FullKeypath );
167 if (comp->assembly) free_assembly( comp->assembly );
171 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
173 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
175 list_remove( &file->entry );
176 msi_free( file->File );
177 msi_free( file->FileName );
178 msi_free( file->ShortName );
179 msi_free( file->LongName );
180 msi_free( file->Version );
181 msi_free( file->Language );
182 msi_free( file->TargetPath );
186 /* clean up extension, progid, class and verb structures */
187 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
189 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
191 list_remove( &cls->entry );
192 msi_free( cls->clsid );
193 msi_free( cls->Context );
194 msi_free( cls->Description );
195 msi_free( cls->FileTypeMask );
196 msi_free( cls->IconPath );
197 msi_free( cls->DefInprocHandler );
198 msi_free( cls->DefInprocHandler32 );
199 msi_free( cls->Argument );
200 msi_free( cls->ProgIDText );
204 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
206 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
208 list_remove( &ext->entry );
209 free_extension( ext );
212 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
214 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
216 list_remove( &progid->entry );
217 msi_free( progid->ProgID );
218 msi_free( progid->Description );
219 msi_free( progid->IconPath );
223 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
225 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
227 list_remove( &mt->entry );
228 msi_free( mt->suffix );
229 msi_free( mt->clsid );
230 msi_free( mt->ContentType );
234 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
236 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
238 list_remove( &appid->entry );
239 msi_free( appid->AppID );
240 msi_free( appid->RemoteServerName );
241 msi_free( appid->LocalServer );
242 msi_free( appid->ServiceParameters );
243 msi_free( appid->DllSurrogate );
247 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
249 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
251 list_remove( &info->entry );
252 msi_free( info->value );
256 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
258 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
260 list_remove( &info->entry );
261 msi_free( info->volume_label );
262 msi_free( info->disk_prompt );
268 for (i = 0; i < TOTAL_SCRIPTS; i++)
269 msi_free_action_script( package, i );
271 for (i = 0; i < package->script->UniqueActionsCount; i++)
272 msi_free( package->script->UniqueActions[i] );
274 msi_free( package->script->UniqueActions );
275 msi_free( package->script );
278 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
280 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
282 list_remove( &patch->entry );
283 msi_free( patch->patchcode );
284 msi_free( patch->transforms );
285 msi_free( patch->localfile );
289 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
291 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
293 list_remove( &binary->entry );
295 FreeLibrary( binary->module );
296 if (!DeleteFileW( binary->tmpfile ))
297 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
298 msi_free( binary->source );
299 msi_free( binary->tmpfile );
303 msi_free( package->BaseURL );
304 msi_free( package->PackagePath );
305 msi_free( package->ProductCode );
306 msi_free( package->ActionFormat );
307 msi_free( package->LastAction );
308 msi_free( package->langids );
310 /* cleanup control event subscriptions */
311 ControlEvent_CleanupSubscriptions( package );
314 static void MSI_FreePackage( MSIOBJECTHDR *arg)
317 MSIPACKAGE *package = (MSIPACKAGE *)arg;
319 if( package->dialog )
320 msi_dialog_destroy( package->dialog );
322 msiobj_release( &package->db->hdr );
323 free_package_structures(package);
324 CloseHandle( package->log_file );
326 for (i = 0; i < CLR_VERSION_MAX; i++)
327 if (package->cache_net[i]) IAssemblyCache_Release( package->cache_net[i] );
328 if (package->cache_sxs) IAssemblyCache_Release( package->cache_sxs );
331 static UINT create_temp_property_table(MSIPACKAGE *package)
333 MSIQUERY *view = NULL;
336 static const WCHAR CreateSql[] = {
337 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
338 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
339 '`','_','P','r','o','p','e','r','t','y','`',' ',
340 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
341 'T','E','M','P','O','R','A','R','Y',',',' ',
342 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
343 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
344 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
345 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
347 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
348 if (rc != ERROR_SUCCESS)
351 rc = MSI_ViewExecute(view, 0);
353 msiobj_release(&view->hdr);
357 UINT msi_clone_properties(MSIPACKAGE *package)
359 MSIQUERY *view_select = NULL;
362 static const WCHAR query_select[] = {
363 'S','E','L','E','C','T',' ','*',' ',
364 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
365 static const WCHAR query_insert[] = {
366 'I','N','S','E','R','T',' ','i','n','t','o',' ',
367 '`','_','P','r','o','p','e','r','t','y','`',' ',
368 '(','`','_','P','r','o','p','e','r','t','y','`',',',
369 '`','V','a','l','u','e','`',')',' ',
370 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
371 static const WCHAR query_update[] = {
372 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
373 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
374 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
376 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
377 if (rc != ERROR_SUCCESS)
380 rc = MSI_ViewExecute( view_select, 0 );
381 if (rc != ERROR_SUCCESS)
383 MSI_ViewClose( view_select );
384 msiobj_release( &view_select->hdr );
390 MSIQUERY *view_insert, *view_update;
391 MSIRECORD *rec_select;
393 rc = MSI_ViewFetch( view_select, &rec_select );
394 if (rc != ERROR_SUCCESS)
397 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
398 if (rc != ERROR_SUCCESS)
400 msiobj_release( &rec_select->hdr );
404 rc = MSI_ViewExecute( view_insert, rec_select );
405 MSI_ViewClose( view_insert );
406 msiobj_release( &view_insert->hdr );
407 if (rc != ERROR_SUCCESS)
409 MSIRECORD *rec_update;
411 TRACE("insert failed, trying update\n");
413 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
414 if (rc != ERROR_SUCCESS)
416 WARN("open view failed %u\n", rc);
417 msiobj_release( &rec_select->hdr );
421 rec_update = MSI_CreateRecord( 2 );
422 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
423 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
424 rc = MSI_ViewExecute( view_update, rec_update );
425 if (rc != ERROR_SUCCESS)
426 WARN("update failed %u\n", rc);
428 MSI_ViewClose( view_update );
429 msiobj_release( &view_update->hdr );
430 msiobj_release( &rec_update->hdr );
433 msiobj_release( &rec_select->hdr );
436 MSI_ViewClose( view_select );
437 msiobj_release( &view_select->hdr );
444 * Sets the "Installed" property to indicate that
445 * the product is installed for the current user.
447 static UINT set_installed_prop( MSIPACKAGE *package )
452 r = MSIREG_OpenUninstallKey( package, &hkey, FALSE );
453 if (r == ERROR_SUCCESS)
456 msi_set_property( package->db, szInstalled, szOne );
462 static UINT set_user_sid_prop( MSIPACKAGE *package )
466 LPWSTR sid_str = NULL, dom = NULL;
467 DWORD size, dom_size;
469 UINT r = ERROR_FUNCTION_FAILED;
472 GetUserNameW( NULL, &size );
474 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
476 return ERROR_OUTOFMEMORY;
478 if (!GetUserNameW( user_name, &size ))
483 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
485 psid = msi_alloc( size );
486 dom = msi_alloc( dom_size*sizeof (WCHAR) );
489 r = ERROR_OUTOFMEMORY;
493 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
496 if (!ConvertSidToStringSidW( psid, &sid_str ))
499 r = msi_set_property( package->db, szUserSID, sid_str );
502 LocalFree( sid_str );
505 msi_free( user_name );
510 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
515 DWORD index = 0, size;
517 WCHAR name[MAX_PATH];
518 WCHAR windir[MAX_PATH];
520 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
521 static const WCHAR sub[] = {
522 'S','o','f','t','w','a','r','e','\\',
523 'M','i','c','r','o','s','o','f','t','\\',
524 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
527 static const WCHAR subdir[] = {
528 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
529 'F','r','a','m','e','w','o','r','k','\\',0
532 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
533 if (res != ERROR_SUCCESS)
536 GetWindowsDirectoryW(windir, MAX_PATH);
540 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
544 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
545 if (strcmpW( ver, name ) < 0)
548 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
549 check = msi_alloc(size * sizeof(WCHAR));
557 lstrcpyW(check, windir);
558 lstrcatW(check, szBackSlash);
559 lstrcatW(check, subdir);
560 lstrcatW(check, name);
561 lstrcatW(check, szBackSlash);
562 lstrcatW(check, fusion);
564 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
575 RegCloseKey(netsetup);
579 typedef struct tagLANGANDCODEPAGE
585 static void set_msi_assembly_prop(MSIPACKAGE *package)
589 LPVOID version = NULL;
591 LPWSTR fusion, verstr;
592 LANGANDCODEPAGE *translate;
594 static const WCHAR netasm[] = {
595 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
597 static const WCHAR translation[] = {
598 '\\','V','a','r','F','i','l','e','I','n','f','o',
599 '\\','T','r','a','n','s','l','a','t','i','o','n',0
601 static const WCHAR verfmt[] = {
602 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
603 '\\','%','0','4','x','%','0','4','x',
604 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
607 fusion = get_fusion_filename(package);
611 size = GetFileVersionInfoSizeW(fusion, &handle);
614 version = msi_alloc(size);
615 if (!version) return;
617 if (!GetFileVersionInfoW(fusion, handle, size, version))
620 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
623 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
625 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
628 if (!val_len || !verstr)
631 msi_set_property(package->db, netasm, verstr);
638 static VOID set_installer_properties(MSIPACKAGE *package)
642 OSVERSIONINFOEXW OSVersion;
645 WCHAR verstr[10], bufstr[20];
648 LPWSTR username, companyname;
649 SYSTEM_INFO sys_info;
650 SYSTEMTIME systemtime;
653 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
654 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
655 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
656 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
657 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
658 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
659 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
660 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
661 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
662 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
663 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
664 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
665 static const WCHAR szAppDataFolder[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
666 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
667 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
668 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
669 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
670 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
671 static const WCHAR szWindowsFolder[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
672 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
673 static const WCHAR szTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
674 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
675 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
676 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
677 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
678 static const WCHAR szFormat[] = {'%','l','i',0};
679 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
680 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
681 static const WCHAR szSix[] = {'6',0 };
682 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
683 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
684 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
685 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
686 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
687 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
688 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
689 static const WCHAR szIntFormat[] = {'%','d',0};
690 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
691 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
692 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
693 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
694 static const WCHAR szProgramFiles64Folder[] = { 'P','r','o','g','r','a','m','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
695 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
696 static const WCHAR szUserInfo[] = {
697 'S','O','F','T','W','A','R','E','\\',
698 'M','i','c','r','o','s','o','f','t','\\',
699 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
700 'U','s','e','r',' ','I','n','f','o',0
702 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
703 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
704 static const WCHAR szCurrentVersion[] = {
705 'S','O','F','T','W','A','R','E','\\',
706 'M','i','c','r','o','s','o','f','t','\\',
707 'W','i','n','d','o','w','s',' ','N','T','\\',
708 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
710 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
711 static const WCHAR szRegisteredOrganization[] = {
712 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
714 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
715 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
716 static const WCHAR szDate[] = {'D','a','t','e',0};
717 static const WCHAR szTime[] = {'T','i','m','e',0};
718 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
719 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
720 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
721 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
722 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
723 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
724 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
727 * Other things that probably should be set:
729 * ComputerName VirtualMemory
730 * ShellAdvSupport DefaultUIFont PackagecodeChanging
731 * CaptionHeight BorderTop BorderSide TextHeight
732 * RedirectedDllSupport
735 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
736 strcatW(pth, szBackSlash);
737 msi_set_property(package->db, szCommonAppDataFolder, pth);
739 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
740 strcatW(pth, szBackSlash);
741 msi_set_property(package->db, szFavoritesFolder, pth);
743 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
744 strcatW(pth, szBackSlash);
745 msi_set_property(package->db, szFontsFolder, pth);
747 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
748 strcatW(pth, szBackSlash);
749 msi_set_property(package->db, szSendToFolder, pth);
751 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
752 strcatW(pth, szBackSlash);
753 msi_set_property(package->db, szStartMenuFolder, pth);
755 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
756 strcatW(pth, szBackSlash);
757 msi_set_property(package->db, szStartupFolder, pth);
759 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
760 strcatW(pth, szBackSlash);
761 msi_set_property(package->db, szTemplateFolder, pth);
763 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
764 strcatW(pth, szBackSlash);
765 msi_set_property(package->db, szDesktopFolder, pth);
767 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
768 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
769 strcatW(pth, szBackSlash);
770 msi_set_property(package->db, szProgramMenuFolder, pth);
772 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
773 strcatW(pth, szBackSlash);
774 msi_set_property(package->db, szAdminToolsFolder, pth);
776 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
777 strcatW(pth, szBackSlash);
778 msi_set_property(package->db, szAppDataFolder, pth);
780 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
781 strcatW(pth, szBackSlash);
782 msi_set_property(package->db, szSystemFolder, pth);
783 msi_set_property(package->db, szSystem16Folder, pth);
785 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
786 strcatW(pth, szBackSlash);
787 msi_set_property(package->db, szLocalAppDataFolder, pth);
789 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
790 strcatW(pth, szBackSlash);
791 msi_set_property(package->db, szMyPicturesFolder, pth);
793 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
794 strcatW(pth, szBackSlash);
795 msi_set_property(package->db, szPersonalFolder, pth);
797 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
798 strcatW(pth, szBackSlash);
799 msi_set_property(package->db, szWindowsFolder, pth);
801 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
802 strcatW(pth, szBackSlash);
803 msi_set_property(package->db, szPrintHoodFolder, pth);
805 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
806 strcatW(pth, szBackSlash);
807 msi_set_property(package->db, szNetHoodFolder, pth);
809 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
810 strcatW(pth, szBackSlash);
811 msi_set_property(package->db, szRecentFolder, pth);
813 /* Physical Memory is specified in MB. Using total amount. */
814 msex.dwLength = sizeof(msex);
815 GlobalMemoryStatusEx( &msex );
816 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
817 msi_set_property(package->db, szPhysicalMemory, bufstr);
819 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
820 ptr = strchrW(pth,'\\');
821 if (ptr) *(ptr + 1) = 0;
822 msi_set_property(package->db, szWindowsVolume, pth);
824 GetTempPathW(MAX_PATH,pth);
825 msi_set_property(package->db, szTempFolder, pth);
827 /* in a wine environment the user is always admin and privileged */
828 msi_set_property(package->db, szAdminUser, szOne);
829 msi_set_property(package->db, szPrivileged, szOne);
831 /* set the os things */
832 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
833 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
834 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
835 sprintfW(verstr, szFormat, verval);
836 switch (OSVersion.dwPlatformId)
838 case VER_PLATFORM_WIN32_WINDOWS:
839 msi_set_property(package->db, szVersion9x, verstr);
841 case VER_PLATFORM_WIN32_NT:
842 msi_set_property(package->db, szVersionNT, verstr);
843 sprintfW(verstr, szFormat,OSVersion.wProductType);
844 msi_set_property(package->db, szMsiNTProductType, verstr);
847 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
848 msi_set_property(package->db, szWindowsBuild, verstr);
849 /* just fudge this */
850 msi_set_property(package->db, szServicePackLevel, szSix);
852 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
853 msi_set_property( package->db, szVersionMsi, bufstr );
854 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
855 msi_set_property( package->db, szVersionDatabase, bufstr );
857 GetNativeSystemInfo( &sys_info );
858 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
859 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
861 msi_set_property( package->db, szIntel, bufstr );
863 GetSystemDirectoryW( pth, MAX_PATH );
864 PathAddBackslashW( pth );
865 msi_set_property( package->db, szSystemFolder, pth );
867 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
868 PathAddBackslashW( pth );
869 msi_set_property( package->db, szProgramFilesFolder, pth );
871 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
872 PathAddBackslashW( pth );
873 msi_set_property( package->db, szCommonFilesFolder, pth );
875 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
877 msi_set_property( package->db, szMsiAMD64, bufstr );
878 msi_set_property( package->db, szMsix64, bufstr );
879 msi_set_property( package->db, szVersionNT64, verstr );
881 GetSystemDirectoryW( pth, MAX_PATH );
882 PathAddBackslashW( pth );
883 msi_set_property( package->db, szSystem64Folder, pth );
885 GetSystemWow64DirectoryW( pth, MAX_PATH );
886 PathAddBackslashW( pth );
887 msi_set_property( package->db, szSystemFolder, pth );
889 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
890 PathAddBackslashW( pth );
891 msi_set_property( package->db, szProgramFiles64Folder, pth );
893 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
894 PathAddBackslashW( pth );
895 msi_set_property( package->db, szProgramFilesFolder, pth );
897 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
898 PathAddBackslashW( pth );
899 msi_set_property( package->db, szCommonFiles64Folder, pth );
901 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
902 PathAddBackslashW( pth );
903 msi_set_property( package->db, szCommonFilesFolder, pth );
906 /* Screen properties. */
908 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
909 msi_set_property( package->db, szScreenX, bufstr );
910 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
911 msi_set_property( package->db, szScreenY, bufstr );
912 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
913 msi_set_property( package->db, szColorBits, bufstr );
916 /* USERNAME and COMPANYNAME */
917 username = msi_dup_property( package->db, szUSERNAME );
918 companyname = msi_dup_property( package->db, szCOMPANYNAME );
920 if ((!username || !companyname) &&
921 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
924 (username = msi_reg_get_val_str( hkey, szDefName )))
925 msi_set_property( package->db, szUSERNAME, username );
927 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
928 msi_set_property( package->db, szCOMPANYNAME, companyname );
931 if ((!username || !companyname) &&
932 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
935 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
936 msi_set_property( package->db, szUSERNAME, username );
938 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
939 msi_set_property( package->db, szCOMPANYNAME, companyname );
942 msi_free( username );
943 msi_free( companyname );
945 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
946 ERR("Failed to set the UserSID property\n");
948 /* Date and time properties */
949 GetSystemTime( &systemtime );
950 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
951 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
952 msi_set_property( package->db, szDate, bufstr );
954 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
956 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
957 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
958 &systemtime, NULL, bufstr,
959 sizeof(bufstr)/sizeof(bufstr[0]) ))
960 msi_set_property( package->db, szTime, bufstr );
962 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
964 set_msi_assembly_prop( package );
966 langid = GetUserDefaultLangID();
967 sprintfW(bufstr, szIntFormat, langid);
968 msi_set_property( package->db, szUserLanguageID, bufstr );
970 langid = GetSystemDefaultLangID();
971 sprintfW(bufstr, szIntFormat, langid);
972 msi_set_property( package->db, szSystemLangID, bufstr );
974 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
975 msi_set_property( package->db, szProductState, bufstr );
978 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_MORE_DATA)
981 if ((username = msi_alloc( len * sizeof(WCHAR) )))
983 if (GetUserNameW( username, &len ))
984 msi_set_property( package->db, szLogonUser, username );
985 msi_free( username );
990 static UINT msi_load_summary_properties( MSIPACKAGE *package )
994 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
998 static const WCHAR szPackageCode[] = {
999 'P','a','c','k','a','g','e','C','o','d','e',0};
1002 ERR("Unable to allocate handle\n");
1003 return ERROR_OUTOFMEMORY;
1006 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1007 MsiCloseHandle(hdb);
1008 if (rc != ERROR_SUCCESS)
1010 ERR("Unable to open Summary Information\n");
1014 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1015 &count, NULL, NULL, NULL );
1016 if (rc != ERROR_SUCCESS)
1018 WARN("Unable to query page count: %d\n", rc);
1022 /* load package code property */
1024 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1025 NULL, NULL, NULL, &len );
1026 if (rc != ERROR_MORE_DATA)
1028 WARN("Unable to query revision number: %d\n", rc);
1029 rc = ERROR_FUNCTION_FAILED;
1034 package_code = msi_alloc( len * sizeof(WCHAR) );
1035 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1036 NULL, NULL, package_code, &len );
1037 if (rc != ERROR_SUCCESS)
1039 WARN("Unable to query rev number: %d\n", rc);
1043 msi_set_property( package->db, szPackageCode, package_code );
1044 msi_free( package_code );
1046 /* load package attributes */
1048 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1049 &count, NULL, NULL, NULL );
1050 package->WordCount = count;
1053 MsiCloseHandle(suminfo);
1057 static MSIPACKAGE *msi_alloc_package( void )
1059 MSIPACKAGE *package;
1061 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1065 list_init( &package->components );
1066 list_init( &package->features );
1067 list_init( &package->files );
1068 list_init( &package->tempfiles );
1069 list_init( &package->folders );
1070 list_init( &package->subscriptions );
1071 list_init( &package->appids );
1072 list_init( &package->classes );
1073 list_init( &package->mimes );
1074 list_init( &package->extensions );
1075 list_init( &package->progids );
1076 list_init( &package->RunningActions );
1077 list_init( &package->sourcelist_info );
1078 list_init( &package->sourcelist_media );
1079 list_init( &package->patches );
1080 list_init( &package->binaries );
1086 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1091 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1093 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1094 if (r != ERROR_SUCCESS)
1097 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1103 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1105 /* FIXME: this should depend on the user's privileges */
1106 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1108 TRACE("resetting ALLUSERS property from 2 to 1\n");
1109 msi_set_property( package->db, szAllUsers, szOne );
1111 msi_set_property( package->db, szAdminUser, szOne );
1114 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1116 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
1117 static const WCHAR szpi[] = {'%','i',0};
1118 MSIPACKAGE *package;
1124 package = msi_alloc_package();
1127 msiobj_addref( &db->hdr );
1130 package->WordCount = 0;
1131 package->PackagePath = strdupW( db->path );
1132 package->BaseURL = strdupW( base_url );
1134 create_temp_property_table( package );
1135 msi_clone_properties( package );
1136 msi_adjust_privilege_properties( package );
1138 package->ProductCode = msi_dup_property( package->db, szProductCode );
1139 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1141 set_installed_prop( package );
1142 set_installer_properties( package );
1144 sprintfW(uilevel,szpi,gUILevel);
1145 msi_set_property(package->db, szLevel, uilevel);
1147 r = msi_load_summary_properties( package );
1148 if (r != ERROR_SUCCESS)
1150 msiobj_release( &package->hdr );
1154 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1155 msi_load_admin_properties( package );
1157 package->log_file = INVALID_HANDLE_VALUE;
1164 * copy_package_to_temp [internal]
1166 * copy the msi file to a temp file to prevent locking a CD
1167 * with a multi disc install
1169 * FIXME: I think this is wrong, and instead of copying the package,
1170 * we should read all the tables to memory, then open the
1171 * database to read binary streams on demand.
1173 static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
1175 WCHAR path[MAX_PATH];
1177 GetTempPathW( MAX_PATH, path );
1178 GetTempFileNameW( path, szMsi, 0, filename );
1180 if( !CopyFileW( szPackage, filename, FALSE ) )
1182 UINT error = GetLastError();
1183 if ( error == ERROR_FILE_NOT_FOUND )
1184 ERR("can't find %s\n", debugstr_w(szPackage));
1186 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
1187 DeleteFileW( filename );
1191 return ERROR_SUCCESS;
1194 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1196 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1200 /* call will always fail, becase size is 0,
1201 * but will return ERROR_FILE_NOT_FOUND first
1202 * if the file doesn't exist
1204 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1205 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1207 cache_entry = msi_alloc( size );
1208 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1210 UINT error = GetLastError();
1211 msi_free( cache_entry );
1215 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1216 msi_free( cache_entry );
1217 return ERROR_SUCCESS;
1220 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1223 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1224 return ERROR_FUNCTION_FAILED;
1227 return ERROR_SUCCESS;
1230 UINT msi_get_local_package_name( LPWSTR path, LPCWSTR suffix )
1232 static const WCHAR szInstaller[] = {
1233 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1234 static const WCHAR fmt[] = {'%','x',0};
1235 DWORD time, len, i, offset;
1238 time = GetTickCount();
1239 GetWindowsDirectoryW( path, MAX_PATH );
1240 strcatW( path, szInstaller );
1241 CreateDirectoryW( path, NULL );
1243 len = strlenW(path);
1244 for (i = 0; i < 0x10000; i++)
1246 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1247 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1248 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1249 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1250 if (handle != INVALID_HANDLE_VALUE)
1252 CloseHandle(handle);
1255 if (GetLastError() != ERROR_FILE_EXISTS &&
1256 GetLastError() != ERROR_SHARING_VIOLATION)
1257 return ERROR_FUNCTION_FAILED;
1260 return ERROR_SUCCESS;
1263 static UINT apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
1267 WCHAR patch_file[MAX_PATH];
1268 MSIDATABASE *patch_db;
1269 MSIPATCHINFO *patch_info;
1272 len = sizeof(patch_file) / sizeof(WCHAR);
1273 r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
1274 INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
1275 if (r != ERROR_SUCCESS)
1277 ERR("failed to get patch filename %u\n", r);
1281 r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
1282 if (r != ERROR_SUCCESS)
1284 ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
1288 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
1291 msiobj_release( &patch_db->hdr );
1292 return ERROR_FUNCTION_FAILED;
1295 r = msi_parse_patch_summary( si, &patch_info );
1296 msiobj_release( &si->hdr );
1297 if (r != ERROR_SUCCESS)
1299 ERR("failed to parse patch summary %u\n", r);
1300 msiobj_release( &patch_db->hdr );
1304 patch_info->localfile = strdupW( patch_file );
1305 if (!patch_info->localfile)
1307 msiobj_release( &patch_db->hdr );
1308 return ERROR_OUTOFMEMORY;
1311 r = msi_apply_patch_db( package, patch_db, patch_info );
1312 msiobj_release( &patch_db->hdr );
1313 if (r != ERROR_SUCCESS)
1315 ERR("failed to apply patch %u\n", r);
1316 msi_free( patch_info->patchcode );
1317 msi_free( patch_info->transforms );
1318 msi_free( patch_info->localfile );
1319 msi_free( patch_info );
1324 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1326 WCHAR *template, *p, *q;
1329 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1330 TRACE("version: %d\n", package->version);
1332 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1334 return ERROR_SUCCESS; /* native accepts missing template property */
1336 TRACE("template: %s\n", debugstr_w(template));
1338 p = strchrW( template, ';' );
1341 WARN("invalid template string %s\n", debugstr_w(template));
1342 msi_free( template );
1343 return ERROR_PATCH_PACKAGE_INVALID;
1346 if (!template[0] || !strcmpW( template, szIntel ))
1347 package->platform = PLATFORM_INTEL;
1348 else if (!strcmpW( template, szIntel64 ))
1349 package->platform = PLATFORM_INTEL64;
1350 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1351 package->platform = PLATFORM_X64;
1354 WARN("unknown platform %s\n", debugstr_w(template));
1355 msi_free( template );
1356 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1361 msi_free( template );
1362 return ERROR_SUCCESS;
1365 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1367 package->langids = msi_alloc( count * sizeof(LANGID) );
1368 if (!package->langids)
1370 msi_free( template );
1371 return ERROR_OUTOFMEMORY;
1377 q = strchrW( p, ',' );
1379 package->langids[i] = atoiW( p );
1384 package->num_langids = i + 1;
1386 msi_free( template );
1387 return ERROR_SUCCESS;
1390 static UINT validate_package( MSIPACKAGE *package )
1395 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1396 if (package->platform == PLATFORM_X64)
1398 if (!is_64bit && !is_wow64)
1399 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1400 if (package->version < 200)
1401 return ERROR_INSTALL_PACKAGE_INVALID;
1403 if (!package->num_langids)
1405 return ERROR_SUCCESS;
1407 for (i = 0; i < package->num_langids; i++)
1409 LANGID langid = package->langids[i];
1411 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1413 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1415 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1417 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1419 if (IsValidLocale( langid, LCID_INSTALLED ))
1420 return ERROR_SUCCESS;
1422 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1425 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1427 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
1428 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1429 MSIDATABASE *db = NULL;
1430 MSIPACKAGE *package;
1432 LPWSTR ptr, base_url = NULL;
1434 WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
1435 LPCWSTR file = szPackage;
1439 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1441 if( szPackage[0] == '#' )
1443 handle = atoiW(&szPackage[1]);
1444 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1447 IWineMsiRemoteDatabase *remote_database;
1449 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1450 if ( !remote_database )
1451 return ERROR_INVALID_HANDLE;
1453 IWineMsiRemoteDatabase_Release( remote_database );
1454 WARN("MsiOpenPackage not allowed during a custom action!\n");
1456 return ERROR_FUNCTION_FAILED;
1461 if ( UrlIsW( szPackage, URLIS_URL ) )
1463 r = msi_download_file( szPackage, cachefile );
1464 if ( r != ERROR_SUCCESS )
1467 r = copy_package_to_temp( cachefile, temppath );
1468 if ( r != ERROR_SUCCESS )
1473 base_url = strdupW( szPackage );
1475 return ERROR_OUTOFMEMORY;
1477 ptr = strrchrW( base_url, '/' );
1478 if (ptr) *(ptr + 1) = '\0';
1482 r = copy_package_to_temp( szPackage, temppath );
1483 if ( r != ERROR_SUCCESS )
1489 r = msi_get_local_package_name( localfile, dotmsi );
1490 if (r != ERROR_SUCCESS)
1493 TRACE("Copying to local package %s\n", debugstr_w(localfile));
1495 if (!CopyFileW( file, localfile, FALSE ))
1497 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1498 debugstr_w(file), debugstr_w(localfile), GetLastError());
1499 return GetLastError();
1502 TRACE("Opening relocated package %s\n", debugstr_w( file ));
1504 /* transforms that add binary streams require that we open the database
1505 * read/write, which is safe because we always create a copy that is thrown
1506 * away when we're done.
1508 r = MSI_OpenDatabaseW( file, MSIDBOPEN_TRANSACT, &db );
1509 if( r != ERROR_SUCCESS )
1511 if (file != szPackage)
1512 DeleteFileW( file );
1514 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
1515 return ERROR_FILE_NOT_FOUND;
1520 db->localfile = strdupW( localfile );
1523 package = MSI_CreatePackage( db, base_url );
1524 msi_free( base_url );
1525 msiobj_release( &db->hdr );
1528 if (file != szPackage)
1529 DeleteFileW( file );
1531 return ERROR_INSTALL_PACKAGE_INVALID;
1534 if( file != szPackage )
1535 track_tempfile( package, file );
1537 si = MSI_GetSummaryInformationW( db->storage, 0 );
1540 WARN("failed to load summary info %u\n", r);
1541 msiobj_release( &package->hdr );
1542 return ERROR_INSTALL_PACKAGE_INVALID;
1545 r = msi_parse_summary( si, package );
1546 msiobj_release( &si->hdr );
1547 if (r != ERROR_SUCCESS)
1549 WARN("failed to parse summary info %u\n", r);
1550 msiobj_release( &package->hdr );
1554 r = validate_package( package );
1555 if (r != ERROR_SUCCESS)
1557 msiobj_release( &package->hdr );
1560 msi_set_property( package->db, Database, db->path );
1562 if( UrlIsW( szPackage, URLIS_URL ) )
1563 msi_set_property( package->db, szOriginalDatabase, szPackage );
1564 else if( szPackage[0] == '#' )
1565 msi_set_property( package->db, szOriginalDatabase, db->path );
1568 WCHAR fullpath[MAX_PATH];
1570 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1571 msi_set_property( package->db, szOriginalDatabase, fullpath );
1574 msi_set_context( package );
1578 WCHAR patch_code[GUID_SIZE];
1579 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1580 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1581 if (r != ERROR_SUCCESS)
1584 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1586 r = apply_registered_patch( package, patch_code );
1587 if (r != ERROR_SUCCESS)
1589 ERR("registered patch failed to apply %u\n", r);
1590 msiobj_release( &package->hdr );
1599 msi_clone_properties( package );
1600 msi_adjust_privilege_properties( package );
1604 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1605 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1607 *pPackage = package;
1608 return ERROR_SUCCESS;
1611 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1613 MSIPACKAGE *package = NULL;
1616 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1618 if( !szPackage || !phPackage )
1619 return ERROR_INVALID_PARAMETER;
1623 FIXME("Should create an empty database and package\n");
1624 return ERROR_FUNCTION_FAILED;
1628 FIXME("dwOptions %08x not supported\n", dwOptions);
1630 ret = MSI_OpenPackageW( szPackage, &package );
1631 if( ret == ERROR_SUCCESS )
1633 *phPackage = alloc_msihandle( &package->hdr );
1635 ret = ERROR_NOT_ENOUGH_MEMORY;
1636 msiobj_release( &package->hdr );
1642 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1644 return MsiOpenPackageExW( szPackage, 0, phPackage );
1647 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1649 LPWSTR szwPack = NULL;
1654 szwPack = strdupAtoW( szPackage );
1656 return ERROR_OUTOFMEMORY;
1659 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1661 msi_free( szwPack );
1666 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1668 return MsiOpenPackageExA( szPackage, 0, phPackage );
1671 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1673 MSIPACKAGE *package;
1674 MSIHANDLE handle = 0;
1675 IUnknown *remote_unk;
1676 IWineMsiRemotePackage *remote_package;
1678 TRACE("(%d)\n",hInstall);
1680 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1683 handle = alloc_msihandle( &package->db->hdr );
1684 msiobj_release( &package->hdr );
1686 else if ((remote_unk = msi_get_remote(hInstall)))
1688 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1689 (LPVOID *)&remote_package) == S_OK)
1691 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1692 IWineMsiRemotePackage_Release(remote_package);
1696 WARN("remote handle %d is not a package\n", hInstall);
1698 IUnknown_Release(remote_unk);
1704 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1707 static const WCHAR szActionData[] =
1708 {'A','c','t','i','o','n','D','a','t','a',0};
1709 static const WCHAR szSetProgress[] =
1710 {'S','e','t','P','r','o','g','r','e','s','s',0};
1711 static const WCHAR szActionText[] =
1712 {'A','c','t','i','o','n','T','e','x','t',0};
1714 DWORD sz, total_size = 0, log_type = 0;
1719 TRACE("%x\n", eMessageType);
1721 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1722 log_type |= INSTALLLOGMODE_ERROR;
1723 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1724 log_type |= INSTALLLOGMODE_WARNING;
1725 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1726 log_type |= INSTALLLOGMODE_USER;
1727 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1728 log_type |= INSTALLLOGMODE_INFO;
1729 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1730 log_type |= INSTALLLOGMODE_COMMONDATA;
1731 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1732 log_type |= INSTALLLOGMODE_ACTIONSTART;
1733 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1734 log_type |= INSTALLLOGMODE_ACTIONDATA;
1736 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1739 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1741 static const WCHAR template_s[]=
1742 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1743 static const WCHAR format[] =
1744 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1746 LPCWSTR action_text, action;
1747 LPWSTR deformatted = NULL;
1749 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1751 action = MSI_RecordGetString(record, 1);
1752 action_text = MSI_RecordGetString(record, 2);
1754 if (!action || !action_text)
1757 deformat_string(package, action_text, &deformatted);
1759 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1761 len += strlenW(deformatted);
1762 message = msi_alloc(len*sizeof(WCHAR));
1763 sprintfW(message, template_s, timet, action);
1765 strcatW(message, deformatted);
1766 msi_free(deformatted);
1771 message = msi_alloc(1*sizeof (WCHAR));
1773 msg_field = MSI_RecordGetFieldCount(record);
1774 for (i = 1; i <= msg_field; i++)
1778 static const WCHAR format[] = { '%','i',':',' ',0};
1780 MSI_RecordGetStringW(record,i,NULL,&sz);
1782 total_size+=sz*sizeof(WCHAR);
1783 tmp = msi_alloc(sz*sizeof(WCHAR));
1784 message = msi_realloc(message,total_size*sizeof (WCHAR));
1786 MSI_RecordGetStringW(record,i,tmp,&sz);
1790 sprintfW(number,format,i);
1791 strcatW(message,number);
1793 strcatW(message,tmp);
1795 strcatW(message, szSpace);
1801 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1802 gUIFilter, log_type, debugstr_w(message));
1804 /* convert it to ASCII */
1805 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1806 msg = msi_alloc( len );
1807 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1809 if (gUIHandlerW && (gUIFilter & log_type))
1811 rc = gUIHandlerW( gUIContext, eMessageType, message );
1813 else if (gUIHandlerA && (gUIFilter & log_type))
1815 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1817 else if (gUIHandlerRecord && (gUIFilter & log_type))
1819 MSIHANDLE rec = MsiCreateRecord( 1 );
1820 MsiRecordSetStringW( rec, 0, message );
1821 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1822 MsiCloseHandle( rec );
1825 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1826 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1829 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1830 WriteFile( package->log_file, "\n", 1, &written, NULL );
1833 msi_free( message );
1835 switch (eMessageType & 0xff000000)
1837 case INSTALLMESSAGE_ACTIONDATA:
1838 /* FIXME: format record here instead of in ui_actiondata to get the
1839 * correct action data for external scripts */
1840 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1842 case INSTALLMESSAGE_ACTIONSTART:
1846 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1848 deformat_string(package, action_text, &deformated);
1849 uirow = MSI_CreateRecord(1);
1850 MSI_RecordSetStringW(uirow, 1, deformated);
1851 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1852 msi_free(deformated);
1854 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1856 msiobj_release(&uirow->hdr);
1859 case INSTALLMESSAGE_PROGRESS:
1860 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1864 return ERROR_SUCCESS;
1867 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1870 UINT ret = ERROR_INVALID_HANDLE;
1871 MSIPACKAGE *package = NULL;
1872 MSIRECORD *record = NULL;
1874 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1878 IWineMsiRemotePackage *remote_package;
1880 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1881 if (!remote_package)
1882 return ERROR_INVALID_HANDLE;
1884 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1886 IWineMsiRemotePackage_Release( remote_package );
1890 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1891 return HRESULT_CODE(hr);
1893 return ERROR_FUNCTION_FAILED;
1896 return ERROR_SUCCESS;
1899 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1903 ret = MSI_ProcessMessage( package, eMessageType, record );
1906 msiobj_release( &package->hdr );
1908 msiobj_release( &record->hdr );
1915 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1917 LPWSTR szwName = NULL, szwValue = NULL;
1918 UINT r = ERROR_OUTOFMEMORY;
1920 szwName = strdupAtoW( szName );
1921 if( szName && !szwName )
1924 szwValue = strdupAtoW( szValue );
1925 if( szValue && !szwValue )
1928 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1931 msi_free( szwName );
1932 msi_free( szwValue );
1937 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1941 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1945 msi_free( folder->ResolvedSource );
1946 folder->ResolvedSource = NULL;
1950 msi_free( folder->ResolvedTarget );
1951 folder->ResolvedTarget = NULL;
1956 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1959 MSIRECORD *row = NULL;
1964 static const WCHAR Insert[] = {
1965 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1966 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1967 '`','_','P','r','o','p','e','r','t','y','`',',',
1968 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1969 ,' ','(','?',',','?',')',0};
1970 static const WCHAR Update[] = {
1971 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1972 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1973 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1974 ' ','=',' ','\'','%','s','\'',0};
1975 static const WCHAR Delete[] = {
1976 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1977 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1978 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1980 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
1983 return ERROR_INVALID_PARAMETER;
1985 /* this one is weird... */
1987 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1989 rc = msi_get_property(db, szName, 0, &sz);
1990 if (!szValue || !*szValue)
1992 sprintfW(Query, Delete, szName);
1994 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1996 sprintfW(Query, Update, szName);
1998 row = MSI_CreateRecord(1);
1999 MSI_RecordSetStringW(row, 1, szValue);
2003 strcpyW(Query, Insert);
2005 row = MSI_CreateRecord(2);
2006 MSI_RecordSetStringW(row, 1, szName);
2007 MSI_RecordSetStringW(row, 2, szValue);
2010 rc = MSI_DatabaseOpenViewW(db, Query, &view);
2011 if (rc == ERROR_SUCCESS)
2013 rc = MSI_ViewExecute(view, row);
2014 MSI_ViewClose(view);
2015 msiobj_release(&view->hdr);
2019 msiobj_release(&row->hdr);
2024 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2026 MSIPACKAGE *package;
2029 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2033 BSTR name = NULL, value = NULL;
2034 IWineMsiRemotePackage *remote_package;
2036 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2037 if (!remote_package)
2038 return ERROR_INVALID_HANDLE;
2040 name = SysAllocString( szName );
2041 value = SysAllocString( szValue );
2042 if ((!name && szName) || (!value && szValue))
2044 SysFreeString( name );
2045 SysFreeString( value );
2046 IWineMsiRemotePackage_Release( remote_package );
2047 return ERROR_OUTOFMEMORY;
2050 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2052 SysFreeString( name );
2053 SysFreeString( value );
2054 IWineMsiRemotePackage_Release( remote_package );
2058 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2059 return HRESULT_CODE(hr);
2061 return ERROR_FUNCTION_FAILED;
2064 return ERROR_SUCCESS;
2067 ret = msi_set_property( package->db, szName, szValue );
2068 if (ret == ERROR_SUCCESS && !strcmpW( szName, cszSourceDir ))
2069 msi_reset_folders( package, TRUE );
2071 msiobj_release( &package->hdr );
2075 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2078 MSIRECORD *rec, *row = NULL;
2081 static const WCHAR query[]= {
2082 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2083 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2084 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2087 if (!name || !*name)
2090 rec = MSI_CreateRecord(1);
2094 MSI_RecordSetStringW(rec, 1, name);
2096 r = MSI_DatabaseOpenViewW(db, query, &view);
2097 if (r == ERROR_SUCCESS)
2099 MSI_ViewExecute(view, rec);
2100 MSI_ViewFetch(view, &row);
2101 MSI_ViewClose(view);
2102 msiobj_release(&view->hdr);
2105 msiobj_release(&rec->hdr);
2109 /* internal function, not compatible with MsiGetPropertyW */
2110 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2111 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2114 UINT rc = ERROR_FUNCTION_FAILED;
2116 row = msi_get_property_row( db, szName );
2118 if (*pchValueBuf > 0)
2123 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2124 msiobj_release(&row->hdr);
2127 if (rc == ERROR_SUCCESS)
2128 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2129 debugstr_w(szName));
2130 else if (rc == ERROR_MORE_DATA)
2131 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2132 debugstr_w(szName));
2136 TRACE("property %s not found\n", debugstr_w(szName));
2142 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2148 r = msi_get_property(db, prop, NULL, &sz);
2149 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2153 str = msi_alloc(sz * sizeof(WCHAR));
2154 r = msi_get_property(db, prop, str, &sz);
2155 if (r != ERROR_SUCCESS)
2164 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2166 LPWSTR str = msi_dup_property( db, prop );
2167 int val = str ? atoiW(str) : def;
2172 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2173 awstring *szValueBuf, LPDWORD pchValueBuf )
2175 MSIPACKAGE *package;
2176 MSIRECORD *row = NULL;
2177 UINT r = ERROR_FUNCTION_FAILED;
2180 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2181 szValueBuf->str.w, pchValueBuf );
2184 return ERROR_INVALID_PARAMETER;
2186 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2190 IWineMsiRemotePackage *remote_package;
2191 LPWSTR value = NULL;
2195 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2196 if (!remote_package)
2197 return ERROR_INVALID_HANDLE;
2199 bname = SysAllocString( name );
2202 IWineMsiRemotePackage_Release( remote_package );
2203 return ERROR_OUTOFMEMORY;
2207 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2212 value = msi_alloc(len * sizeof(WCHAR));
2215 r = ERROR_OUTOFMEMORY;
2219 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
2223 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2225 /* Bug required by Adobe installers */
2226 if (!szValueBuf->unicode && !szValueBuf->str.a)
2227 *pchValueBuf *= sizeof(WCHAR);
2230 IWineMsiRemotePackage_Release(remote_package);
2231 SysFreeString(bname);
2236 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2237 return HRESULT_CODE(hr);
2239 return ERROR_FUNCTION_FAILED;
2245 row = msi_get_property_row( package->db, name );
2247 val = MSI_RecordGetString( row, 1 );
2252 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2255 msiobj_release( &row->hdr );
2256 msiobj_release( &package->hdr );
2261 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2262 LPSTR szValueBuf, LPDWORD pchValueBuf )
2268 val.unicode = FALSE;
2269 val.str.a = szValueBuf;
2271 name = strdupAtoW( szName );
2272 if (szName && !name)
2273 return ERROR_OUTOFMEMORY;
2275 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2280 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2281 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2286 val.str.w = szValueBuf;
2288 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2291 typedef struct _msi_remote_package_impl {
2292 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2295 } msi_remote_package_impl;
2297 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2299 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2302 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2303 REFIID riid,LPVOID *ppobj)
2305 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2306 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2308 IUnknown_AddRef( iface );
2313 return E_NOINTERFACE;
2316 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2318 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2320 return InterlockedIncrement( &This->refs );
2323 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2325 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2328 r = InterlockedDecrement( &This->refs );
2331 MsiCloseHandle( This->package );
2337 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2339 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2340 This->package = handle;
2344 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2346 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2347 IWineMsiRemoteDatabase *rdb = NULL;
2351 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2352 if (FAILED(hr) || !rdb)
2354 ERR("Failed to create remote database\n");
2358 hdb = MsiGetActiveDatabase(This->package);
2360 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2363 ERR("Failed to set the database handle\n");
2367 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2371 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
2373 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2376 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
2377 if (r != ERROR_SUCCESS)
2378 return HRESULT_FROM_WIN32(r);
2383 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2385 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2386 UINT r = MsiSetPropertyW(This->package, property, value);
2387 return HRESULT_FROM_WIN32(r);
2390 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2392 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2393 UINT r = MsiProcessMessage(This->package, message, record);
2394 return HRESULT_FROM_WIN32(r);
2397 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2399 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2400 UINT r = MsiDoActionW(This->package, action);
2401 return HRESULT_FROM_WIN32(r);
2404 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2406 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2407 UINT r = MsiSequenceW(This->package, table, sequence);
2408 return HRESULT_FROM_WIN32(r);
2411 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2413 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2414 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2415 return HRESULT_FROM_WIN32(r);
2418 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2420 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2421 UINT r = MsiSetTargetPathW(This->package, folder, value);
2422 return HRESULT_FROM_WIN32(r);
2425 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2427 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2428 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2429 return HRESULT_FROM_WIN32(r);
2432 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2434 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2435 *ret = MsiGetMode(This->package, mode);
2439 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2441 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2442 UINT r = MsiSetMode(This->package, mode, state);
2443 return HRESULT_FROM_WIN32(r);
2446 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2447 INSTALLSTATE *installed, INSTALLSTATE *action )
2449 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2450 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2451 return HRESULT_FROM_WIN32(r);
2454 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2456 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2457 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2458 return HRESULT_FROM_WIN32(r);
2461 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2462 INSTALLSTATE *installed, INSTALLSTATE *action )
2464 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2465 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2466 return HRESULT_FROM_WIN32(r);
2469 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2471 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2472 UINT r = MsiSetComponentStateW(This->package, component, state);
2473 return HRESULT_FROM_WIN32(r);
2476 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2478 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2479 *language = MsiGetLanguage(This->package);
2483 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2485 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2486 UINT r = MsiSetInstallLevel(This->package, level);
2487 return HRESULT_FROM_WIN32(r);
2490 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2494 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2495 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2496 if (r == ERROR_SUCCESS)
2498 *value = SysAllocStringLen(NULL, size);
2500 return E_OUTOFMEMORY;
2502 r = MsiFormatRecordW(This->package, record, *value, &size);
2504 return HRESULT_FROM_WIN32(r);
2507 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2509 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2510 UINT r = MsiEvaluateConditionW(This->package, condition);
2511 return HRESULT_FROM_WIN32(r);
2514 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2515 INT cost_tree, INSTALLSTATE state, INT *cost )
2517 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2518 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2519 return HRESULT_FROM_WIN32(r);
2522 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2528 mrp_GetActiveDatabase,
2539 mrp_GetFeatureState,
2540 mrp_SetFeatureState,
2541 mrp_GetComponentState,
2542 mrp_SetComponentState,
2544 mrp_SetInstallLevel,
2546 mrp_EvaluateCondition,
2550 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2552 msi_remote_package_impl* This;
2554 This = msi_alloc( sizeof *This );
2556 return E_OUTOFMEMORY;
2558 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2567 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2568 LPCWSTR property, LPWSTR value)
2570 MSISOURCELISTINFO *info;
2572 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2574 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2577 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2579 return ERROR_OUTOFMEMORY;
2581 info->context = context;
2582 info->options = options;
2583 info->property = property;
2584 info->value = strdupW(value);
2585 list_add_head(&package->sourcelist_info, &info->entry);
2587 return ERROR_SUCCESS;
2590 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2591 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2595 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2597 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2600 disk = msi_alloc(sizeof(MSIMEDIADISK));
2602 return ERROR_OUTOFMEMORY;
2604 disk->context = context;
2605 disk->options = options;
2606 disk->disk_id = disk_id;
2607 disk->volume_label = strdupW(volume_label);
2608 disk->disk_prompt = strdupW(disk_prompt);
2609 list_add_head(&package->sourcelist_media, &disk->entry);
2611 return ERROR_SUCCESS;