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->ProductCode, package->platform, &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->filepatches );
1069 list_init( &package->tempfiles );
1070 list_init( &package->folders );
1071 list_init( &package->subscriptions );
1072 list_init( &package->appids );
1073 list_init( &package->classes );
1074 list_init( &package->mimes );
1075 list_init( &package->extensions );
1076 list_init( &package->progids );
1077 list_init( &package->RunningActions );
1078 list_init( &package->sourcelist_info );
1079 list_init( &package->sourcelist_media );
1080 list_init( &package->patches );
1081 list_init( &package->binaries );
1087 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1092 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1094 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1095 if (r != ERROR_SUCCESS)
1098 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1104 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1106 /* FIXME: this should depend on the user's privileges */
1107 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1109 TRACE("resetting ALLUSERS property from 2 to 1\n");
1110 msi_set_property( package->db, szAllUsers, szOne );
1112 msi_set_property( package->db, szAdminUser, szOne );
1115 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1117 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
1118 static const WCHAR szpi[] = {'%','i',0};
1119 MSIPACKAGE *package;
1125 package = msi_alloc_package();
1128 msiobj_addref( &db->hdr );
1131 package->WordCount = 0;
1132 package->PackagePath = strdupW( db->path );
1133 package->BaseURL = strdupW( base_url );
1135 create_temp_property_table( package );
1136 msi_clone_properties( package );
1137 msi_adjust_privilege_properties( package );
1139 package->ProductCode = msi_dup_property( package->db, szProductCode );
1140 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1142 set_installed_prop( package );
1143 set_installer_properties( package );
1145 sprintfW(uilevel,szpi,gUILevel);
1146 msi_set_property(package->db, szLevel, uilevel);
1148 r = msi_load_summary_properties( package );
1149 if (r != ERROR_SUCCESS)
1151 msiobj_release( &package->hdr );
1155 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1156 msi_load_admin_properties( package );
1158 package->log_file = INVALID_HANDLE_VALUE;
1165 * copy_package_to_temp [internal]
1167 * copy the msi file to a temp file to prevent locking a CD
1168 * with a multi disc install
1170 * FIXME: I think this is wrong, and instead of copying the package,
1171 * we should read all the tables to memory, then open the
1172 * database to read binary streams on demand.
1174 static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
1176 WCHAR path[MAX_PATH];
1178 GetTempPathW( MAX_PATH, path );
1179 GetTempFileNameW( path, szMsi, 0, filename );
1181 if( !CopyFileW( szPackage, filename, FALSE ) )
1183 UINT error = GetLastError();
1184 if ( error == ERROR_FILE_NOT_FOUND )
1185 ERR("can't find %s\n", debugstr_w(szPackage));
1187 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
1188 DeleteFileW( filename );
1192 return ERROR_SUCCESS;
1195 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1197 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1201 /* call will always fail, becase size is 0,
1202 * but will return ERROR_FILE_NOT_FOUND first
1203 * if the file doesn't exist
1205 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1206 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1208 cache_entry = msi_alloc( size );
1209 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1211 UINT error = GetLastError();
1212 msi_free( cache_entry );
1216 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1217 msi_free( cache_entry );
1218 return ERROR_SUCCESS;
1221 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1224 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1225 return ERROR_FUNCTION_FAILED;
1228 return ERROR_SUCCESS;
1231 UINT msi_get_local_package_name( LPWSTR path, LPCWSTR suffix )
1233 static const WCHAR szInstaller[] = {
1234 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1235 static const WCHAR fmt[] = {'%','x',0};
1236 DWORD time, len, i, offset;
1239 time = GetTickCount();
1240 GetWindowsDirectoryW( path, MAX_PATH );
1241 strcatW( path, szInstaller );
1242 CreateDirectoryW( path, NULL );
1244 len = strlenW(path);
1245 for (i = 0; i < 0x10000; i++)
1247 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1248 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1249 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1250 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1251 if (handle != INVALID_HANDLE_VALUE)
1253 CloseHandle(handle);
1256 if (GetLastError() != ERROR_FILE_EXISTS &&
1257 GetLastError() != ERROR_SHARING_VIOLATION)
1258 return ERROR_FUNCTION_FAILED;
1261 return ERROR_SUCCESS;
1264 static UINT apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
1268 WCHAR patch_file[MAX_PATH];
1269 MSIDATABASE *patch_db;
1270 MSIPATCHINFO *patch_info;
1273 len = sizeof(patch_file) / sizeof(WCHAR);
1274 r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
1275 INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
1276 if (r != ERROR_SUCCESS)
1278 ERR("failed to get patch filename %u\n", r);
1282 r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
1283 if (r != ERROR_SUCCESS)
1285 ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
1289 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
1292 msiobj_release( &patch_db->hdr );
1293 return ERROR_FUNCTION_FAILED;
1296 r = msi_parse_patch_summary( si, &patch_info );
1297 msiobj_release( &si->hdr );
1298 if (r != ERROR_SUCCESS)
1300 ERR("failed to parse patch summary %u\n", r);
1301 msiobj_release( &patch_db->hdr );
1305 patch_info->localfile = strdupW( patch_file );
1306 if (!patch_info->localfile)
1308 msiobj_release( &patch_db->hdr );
1309 return ERROR_OUTOFMEMORY;
1312 r = msi_apply_patch_db( package, patch_db, patch_info );
1313 msiobj_release( &patch_db->hdr );
1314 if (r != ERROR_SUCCESS)
1316 ERR("failed to apply patch %u\n", r);
1317 msi_free( patch_info->patchcode );
1318 msi_free( patch_info->transforms );
1319 msi_free( patch_info->localfile );
1320 msi_free( patch_info );
1325 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1327 WCHAR *template, *p, *q;
1330 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1331 TRACE("version: %d\n", package->version);
1333 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1335 return ERROR_SUCCESS; /* native accepts missing template property */
1337 TRACE("template: %s\n", debugstr_w(template));
1339 p = strchrW( template, ';' );
1342 WARN("invalid template string %s\n", debugstr_w(template));
1343 msi_free( template );
1344 return ERROR_PATCH_PACKAGE_INVALID;
1347 if (!template[0] || !strcmpW( template, szIntel ))
1348 package->platform = PLATFORM_INTEL;
1349 else if (!strcmpW( template, szIntel64 ))
1350 package->platform = PLATFORM_INTEL64;
1351 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1352 package->platform = PLATFORM_X64;
1355 WARN("unknown platform %s\n", debugstr_w(template));
1356 msi_free( template );
1357 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1362 msi_free( template );
1363 return ERROR_SUCCESS;
1366 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1368 package->langids = msi_alloc( count * sizeof(LANGID) );
1369 if (!package->langids)
1371 msi_free( template );
1372 return ERROR_OUTOFMEMORY;
1378 q = strchrW( p, ',' );
1380 package->langids[i] = atoiW( p );
1385 package->num_langids = i + 1;
1387 msi_free( template );
1388 return ERROR_SUCCESS;
1391 static UINT validate_package( MSIPACKAGE *package )
1396 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1397 if (package->platform == PLATFORM_X64)
1399 if (!is_64bit && !is_wow64)
1400 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1401 if (package->version < 200)
1402 return ERROR_INSTALL_PACKAGE_INVALID;
1404 if (!package->num_langids)
1406 return ERROR_SUCCESS;
1408 for (i = 0; i < package->num_langids; i++)
1410 LANGID langid = package->langids[i];
1412 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1414 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1416 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1418 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1420 if (IsValidLocale( langid, LCID_INSTALLED ))
1421 return ERROR_SUCCESS;
1423 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1426 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1428 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
1429 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1430 MSIDATABASE *db = NULL;
1431 MSIPACKAGE *package;
1433 LPWSTR ptr, base_url = NULL;
1435 WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
1436 LPCWSTR file = szPackage;
1440 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1442 if( szPackage[0] == '#' )
1444 handle = atoiW(&szPackage[1]);
1445 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1448 IWineMsiRemoteDatabase *remote_database;
1450 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1451 if ( !remote_database )
1452 return ERROR_INVALID_HANDLE;
1454 IWineMsiRemoteDatabase_Release( remote_database );
1455 WARN("MsiOpenPackage not allowed during a custom action!\n");
1457 return ERROR_FUNCTION_FAILED;
1462 if ( UrlIsW( szPackage, URLIS_URL ) )
1464 r = msi_download_file( szPackage, cachefile );
1465 if ( r != ERROR_SUCCESS )
1468 r = copy_package_to_temp( cachefile, temppath );
1469 if ( r != ERROR_SUCCESS )
1474 base_url = strdupW( szPackage );
1476 return ERROR_OUTOFMEMORY;
1478 ptr = strrchrW( base_url, '/' );
1479 if (ptr) *(ptr + 1) = '\0';
1483 r = copy_package_to_temp( szPackage, temppath );
1484 if ( r != ERROR_SUCCESS )
1490 r = msi_get_local_package_name( localfile, dotmsi );
1491 if (r != ERROR_SUCCESS)
1494 TRACE("Copying to local package %s\n", debugstr_w(localfile));
1496 if (!CopyFileW( file, localfile, FALSE ))
1498 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1499 debugstr_w(file), debugstr_w(localfile), GetLastError());
1500 return GetLastError();
1503 TRACE("Opening relocated package %s\n", debugstr_w( file ));
1505 /* transforms that add binary streams require that we open the database
1506 * read/write, which is safe because we always create a copy that is thrown
1507 * away when we're done.
1509 r = MSI_OpenDatabaseW( file, MSIDBOPEN_TRANSACT, &db );
1510 if( r != ERROR_SUCCESS )
1512 if (file != szPackage)
1513 DeleteFileW( file );
1515 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
1516 return ERROR_FILE_NOT_FOUND;
1521 db->localfile = strdupW( localfile );
1524 package = MSI_CreatePackage( db, base_url );
1525 msi_free( base_url );
1526 msiobj_release( &db->hdr );
1529 if (file != szPackage)
1530 DeleteFileW( file );
1532 return ERROR_INSTALL_PACKAGE_INVALID;
1535 if( file != szPackage )
1536 track_tempfile( package, file );
1538 si = MSI_GetSummaryInformationW( db->storage, 0 );
1541 WARN("failed to load summary info %u\n", r);
1542 msiobj_release( &package->hdr );
1543 return ERROR_INSTALL_PACKAGE_INVALID;
1546 r = msi_parse_summary( si, package );
1547 msiobj_release( &si->hdr );
1548 if (r != ERROR_SUCCESS)
1550 WARN("failed to parse summary info %u\n", r);
1551 msiobj_release( &package->hdr );
1555 r = validate_package( package );
1556 if (r != ERROR_SUCCESS)
1558 msiobj_release( &package->hdr );
1561 msi_set_property( package->db, Database, db->path );
1563 if( UrlIsW( szPackage, URLIS_URL ) )
1564 msi_set_property( package->db, szOriginalDatabase, szPackage );
1565 else if( szPackage[0] == '#' )
1566 msi_set_property( package->db, szOriginalDatabase, db->path );
1569 WCHAR fullpath[MAX_PATH];
1571 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1572 msi_set_property( package->db, szOriginalDatabase, fullpath );
1575 msi_set_context( package );
1579 WCHAR patch_code[GUID_SIZE];
1580 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1581 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1582 if (r != ERROR_SUCCESS)
1585 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1587 r = apply_registered_patch( package, patch_code );
1588 if (r != ERROR_SUCCESS)
1590 ERR("registered patch failed to apply %u\n", r);
1591 msiobj_release( &package->hdr );
1600 msi_clone_properties( package );
1601 msi_adjust_privilege_properties( package );
1605 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1606 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1608 *pPackage = package;
1609 return ERROR_SUCCESS;
1612 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1614 MSIPACKAGE *package = NULL;
1617 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1619 if( !szPackage || !phPackage )
1620 return ERROR_INVALID_PARAMETER;
1624 FIXME("Should create an empty database and package\n");
1625 return ERROR_FUNCTION_FAILED;
1629 FIXME("dwOptions %08x not supported\n", dwOptions);
1631 ret = MSI_OpenPackageW( szPackage, &package );
1632 if( ret == ERROR_SUCCESS )
1634 *phPackage = alloc_msihandle( &package->hdr );
1636 ret = ERROR_NOT_ENOUGH_MEMORY;
1637 msiobj_release( &package->hdr );
1643 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1645 return MsiOpenPackageExW( szPackage, 0, phPackage );
1648 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1650 LPWSTR szwPack = NULL;
1655 szwPack = strdupAtoW( szPackage );
1657 return ERROR_OUTOFMEMORY;
1660 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1662 msi_free( szwPack );
1667 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1669 return MsiOpenPackageExA( szPackage, 0, phPackage );
1672 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1674 MSIPACKAGE *package;
1675 MSIHANDLE handle = 0;
1676 IUnknown *remote_unk;
1677 IWineMsiRemotePackage *remote_package;
1679 TRACE("(%d)\n",hInstall);
1681 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1684 handle = alloc_msihandle( &package->db->hdr );
1685 msiobj_release( &package->hdr );
1687 else if ((remote_unk = msi_get_remote(hInstall)))
1689 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1690 (LPVOID *)&remote_package) == S_OK)
1692 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1693 IWineMsiRemotePackage_Release(remote_package);
1697 WARN("remote handle %d is not a package\n", hInstall);
1699 IUnknown_Release(remote_unk);
1705 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1708 static const WCHAR szActionData[] =
1709 {'A','c','t','i','o','n','D','a','t','a',0};
1710 static const WCHAR szSetProgress[] =
1711 {'S','e','t','P','r','o','g','r','e','s','s',0};
1712 static const WCHAR szActionText[] =
1713 {'A','c','t','i','o','n','T','e','x','t',0};
1715 DWORD sz, total_size = 0, log_type = 0;
1720 TRACE("%x\n", eMessageType);
1722 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1723 log_type |= INSTALLLOGMODE_ERROR;
1724 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1725 log_type |= INSTALLLOGMODE_WARNING;
1726 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1727 log_type |= INSTALLLOGMODE_USER;
1728 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1729 log_type |= INSTALLLOGMODE_INFO;
1730 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1731 log_type |= INSTALLLOGMODE_COMMONDATA;
1732 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1733 log_type |= INSTALLLOGMODE_ACTIONSTART;
1734 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1735 log_type |= INSTALLLOGMODE_ACTIONDATA;
1737 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1740 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1742 static const WCHAR template_s[]=
1743 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1744 static const WCHAR format[] =
1745 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1747 LPCWSTR action_text, action;
1748 LPWSTR deformatted = NULL;
1750 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1752 action = MSI_RecordGetString(record, 1);
1753 action_text = MSI_RecordGetString(record, 2);
1755 if (!action || !action_text)
1758 deformat_string(package, action_text, &deformatted);
1760 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1762 len += strlenW(deformatted);
1763 message = msi_alloc(len*sizeof(WCHAR));
1764 sprintfW(message, template_s, timet, action);
1766 strcatW(message, deformatted);
1767 msi_free(deformatted);
1772 message = msi_alloc(1*sizeof (WCHAR));
1774 msg_field = MSI_RecordGetFieldCount(record);
1775 for (i = 1; i <= msg_field; i++)
1779 static const WCHAR format[] = { '%','i',':',' ',0};
1781 MSI_RecordGetStringW(record,i,NULL,&sz);
1783 total_size+=sz*sizeof(WCHAR);
1784 tmp = msi_alloc(sz*sizeof(WCHAR));
1785 message = msi_realloc(message,total_size*sizeof (WCHAR));
1787 MSI_RecordGetStringW(record,i,tmp,&sz);
1791 sprintfW(number,format,i);
1792 strcatW(message,number);
1794 strcatW(message,tmp);
1796 strcatW(message, szSpace);
1802 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1803 gUIFilter, log_type, debugstr_w(message));
1805 /* convert it to ASCII */
1806 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1807 msg = msi_alloc( len );
1808 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1810 if (gUIHandlerW && (gUIFilter & log_type))
1812 rc = gUIHandlerW( gUIContext, eMessageType, message );
1814 else if (gUIHandlerA && (gUIFilter & log_type))
1816 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1818 else if (gUIHandlerRecord && (gUIFilter & log_type))
1820 MSIHANDLE rec = MsiCreateRecord( 1 );
1821 MsiRecordSetStringW( rec, 0, message );
1822 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1823 MsiCloseHandle( rec );
1826 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1827 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1830 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1831 WriteFile( package->log_file, "\n", 1, &written, NULL );
1834 msi_free( message );
1836 switch (eMessageType & 0xff000000)
1838 case INSTALLMESSAGE_ACTIONDATA:
1839 /* FIXME: format record here instead of in ui_actiondata to get the
1840 * correct action data for external scripts */
1841 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1843 case INSTALLMESSAGE_ACTIONSTART:
1847 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1849 deformat_string(package, action_text, &deformated);
1850 uirow = MSI_CreateRecord(1);
1851 MSI_RecordSetStringW(uirow, 1, deformated);
1852 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1853 msi_free(deformated);
1855 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1857 msiobj_release(&uirow->hdr);
1860 case INSTALLMESSAGE_PROGRESS:
1861 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1865 return ERROR_SUCCESS;
1868 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1871 UINT ret = ERROR_INVALID_HANDLE;
1872 MSIPACKAGE *package = NULL;
1873 MSIRECORD *record = NULL;
1875 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1879 IWineMsiRemotePackage *remote_package;
1881 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1882 if (!remote_package)
1883 return ERROR_INVALID_HANDLE;
1885 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1887 IWineMsiRemotePackage_Release( remote_package );
1891 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1892 return HRESULT_CODE(hr);
1894 return ERROR_FUNCTION_FAILED;
1897 return ERROR_SUCCESS;
1900 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1904 ret = MSI_ProcessMessage( package, eMessageType, record );
1907 msiobj_release( &package->hdr );
1909 msiobj_release( &record->hdr );
1916 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1918 LPWSTR szwName = NULL, szwValue = NULL;
1919 UINT r = ERROR_OUTOFMEMORY;
1921 szwName = strdupAtoW( szName );
1922 if( szName && !szwName )
1925 szwValue = strdupAtoW( szValue );
1926 if( szValue && !szwValue )
1929 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1932 msi_free( szwName );
1933 msi_free( szwValue );
1938 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1942 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1946 msi_free( folder->ResolvedSource );
1947 folder->ResolvedSource = NULL;
1951 msi_free( folder->ResolvedTarget );
1952 folder->ResolvedTarget = NULL;
1957 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1960 MSIRECORD *row = NULL;
1965 static const WCHAR Insert[] = {
1966 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1967 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1968 '`','_','P','r','o','p','e','r','t','y','`',',',
1969 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1970 ,' ','(','?',',','?',')',0};
1971 static const WCHAR Update[] = {
1972 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1973 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1974 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1975 ' ','=',' ','\'','%','s','\'',0};
1976 static const WCHAR Delete[] = {
1977 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1978 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1979 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1981 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
1984 return ERROR_INVALID_PARAMETER;
1986 /* this one is weird... */
1988 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1990 rc = msi_get_property(db, szName, 0, &sz);
1991 if (!szValue || !*szValue)
1993 sprintfW(Query, Delete, szName);
1995 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1997 sprintfW(Query, Update, szName);
1999 row = MSI_CreateRecord(1);
2000 MSI_RecordSetStringW(row, 1, szValue);
2004 strcpyW(Query, Insert);
2006 row = MSI_CreateRecord(2);
2007 MSI_RecordSetStringW(row, 1, szName);
2008 MSI_RecordSetStringW(row, 2, szValue);
2011 rc = MSI_DatabaseOpenViewW(db, Query, &view);
2012 if (rc == ERROR_SUCCESS)
2014 rc = MSI_ViewExecute(view, row);
2015 MSI_ViewClose(view);
2016 msiobj_release(&view->hdr);
2020 msiobj_release(&row->hdr);
2025 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2027 MSIPACKAGE *package;
2030 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2034 BSTR name = NULL, value = NULL;
2035 IWineMsiRemotePackage *remote_package;
2037 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2038 if (!remote_package)
2039 return ERROR_INVALID_HANDLE;
2041 name = SysAllocString( szName );
2042 value = SysAllocString( szValue );
2043 if ((!name && szName) || (!value && szValue))
2045 SysFreeString( name );
2046 SysFreeString( value );
2047 IWineMsiRemotePackage_Release( remote_package );
2048 return ERROR_OUTOFMEMORY;
2051 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2053 SysFreeString( name );
2054 SysFreeString( value );
2055 IWineMsiRemotePackage_Release( remote_package );
2059 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2060 return HRESULT_CODE(hr);
2062 return ERROR_FUNCTION_FAILED;
2065 return ERROR_SUCCESS;
2068 ret = msi_set_property( package->db, szName, szValue );
2069 if (ret == ERROR_SUCCESS && !strcmpW( szName, cszSourceDir ))
2070 msi_reset_folders( package, TRUE );
2072 msiobj_release( &package->hdr );
2076 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2079 MSIRECORD *rec, *row = NULL;
2082 static const WCHAR query[]= {
2083 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2084 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2085 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2088 if (!name || !*name)
2091 rec = MSI_CreateRecord(1);
2095 MSI_RecordSetStringW(rec, 1, name);
2097 r = MSI_DatabaseOpenViewW(db, query, &view);
2098 if (r == ERROR_SUCCESS)
2100 MSI_ViewExecute(view, rec);
2101 MSI_ViewFetch(view, &row);
2102 MSI_ViewClose(view);
2103 msiobj_release(&view->hdr);
2106 msiobj_release(&rec->hdr);
2110 /* internal function, not compatible with MsiGetPropertyW */
2111 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2112 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2115 UINT rc = ERROR_FUNCTION_FAILED;
2117 row = msi_get_property_row( db, szName );
2119 if (*pchValueBuf > 0)
2124 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2125 msiobj_release(&row->hdr);
2128 if (rc == ERROR_SUCCESS)
2129 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2130 debugstr_w(szName));
2131 else if (rc == ERROR_MORE_DATA)
2132 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2133 debugstr_w(szName));
2137 TRACE("property %s not found\n", debugstr_w(szName));
2143 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2149 r = msi_get_property(db, prop, NULL, &sz);
2150 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2154 str = msi_alloc(sz * sizeof(WCHAR));
2155 r = msi_get_property(db, prop, str, &sz);
2156 if (r != ERROR_SUCCESS)
2165 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2167 LPWSTR str = msi_dup_property( db, prop );
2168 int val = str ? atoiW(str) : def;
2173 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2174 awstring *szValueBuf, LPDWORD pchValueBuf )
2176 MSIPACKAGE *package;
2177 MSIRECORD *row = NULL;
2178 UINT r = ERROR_FUNCTION_FAILED;
2181 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2182 szValueBuf->str.w, pchValueBuf );
2185 return ERROR_INVALID_PARAMETER;
2187 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2191 IWineMsiRemotePackage *remote_package;
2192 LPWSTR value = NULL;
2196 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2197 if (!remote_package)
2198 return ERROR_INVALID_HANDLE;
2200 bname = SysAllocString( name );
2203 IWineMsiRemotePackage_Release( remote_package );
2204 return ERROR_OUTOFMEMORY;
2208 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2213 value = msi_alloc(len * sizeof(WCHAR));
2216 r = ERROR_OUTOFMEMORY;
2220 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
2224 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2226 /* Bug required by Adobe installers */
2227 if (!szValueBuf->unicode && !szValueBuf->str.a)
2228 *pchValueBuf *= sizeof(WCHAR);
2231 IWineMsiRemotePackage_Release(remote_package);
2232 SysFreeString(bname);
2237 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2238 return HRESULT_CODE(hr);
2240 return ERROR_FUNCTION_FAILED;
2246 row = msi_get_property_row( package->db, name );
2248 val = MSI_RecordGetString( row, 1 );
2253 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2256 msiobj_release( &row->hdr );
2257 msiobj_release( &package->hdr );
2262 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2263 LPSTR szValueBuf, LPDWORD pchValueBuf )
2269 val.unicode = FALSE;
2270 val.str.a = szValueBuf;
2272 name = strdupAtoW( szName );
2273 if (szName && !name)
2274 return ERROR_OUTOFMEMORY;
2276 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2281 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2282 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2287 val.str.w = szValueBuf;
2289 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2292 typedef struct _msi_remote_package_impl {
2293 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2296 } msi_remote_package_impl;
2298 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2300 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2303 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2304 REFIID riid,LPVOID *ppobj)
2306 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2307 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2309 IUnknown_AddRef( iface );
2314 return E_NOINTERFACE;
2317 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2319 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2321 return InterlockedIncrement( &This->refs );
2324 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2326 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2329 r = InterlockedDecrement( &This->refs );
2332 MsiCloseHandle( This->package );
2338 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2340 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2341 This->package = handle;
2345 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2347 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2348 IWineMsiRemoteDatabase *rdb = NULL;
2352 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2353 if (FAILED(hr) || !rdb)
2355 ERR("Failed to create remote database\n");
2359 hdb = MsiGetActiveDatabase(This->package);
2361 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2364 ERR("Failed to set the database handle\n");
2368 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2372 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
2374 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2377 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
2378 if (r != ERROR_SUCCESS)
2379 return HRESULT_FROM_WIN32(r);
2384 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2386 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2387 UINT r = MsiSetPropertyW(This->package, property, value);
2388 return HRESULT_FROM_WIN32(r);
2391 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2393 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2394 UINT r = MsiProcessMessage(This->package, message, record);
2395 return HRESULT_FROM_WIN32(r);
2398 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2400 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2401 UINT r = MsiDoActionW(This->package, action);
2402 return HRESULT_FROM_WIN32(r);
2405 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2407 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2408 UINT r = MsiSequenceW(This->package, table, sequence);
2409 return HRESULT_FROM_WIN32(r);
2412 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2414 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2415 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2416 return HRESULT_FROM_WIN32(r);
2419 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2421 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2422 UINT r = MsiSetTargetPathW(This->package, folder, value);
2423 return HRESULT_FROM_WIN32(r);
2426 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2428 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2429 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2430 return HRESULT_FROM_WIN32(r);
2433 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2435 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2436 *ret = MsiGetMode(This->package, mode);
2440 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2442 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2443 UINT r = MsiSetMode(This->package, mode, state);
2444 return HRESULT_FROM_WIN32(r);
2447 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2448 INSTALLSTATE *installed, INSTALLSTATE *action )
2450 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2451 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2452 return HRESULT_FROM_WIN32(r);
2455 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2457 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2458 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2459 return HRESULT_FROM_WIN32(r);
2462 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2463 INSTALLSTATE *installed, INSTALLSTATE *action )
2465 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2466 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2467 return HRESULT_FROM_WIN32(r);
2470 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2472 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2473 UINT r = MsiSetComponentStateW(This->package, component, state);
2474 return HRESULT_FROM_WIN32(r);
2477 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2479 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2480 *language = MsiGetLanguage(This->package);
2484 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2486 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2487 UINT r = MsiSetInstallLevel(This->package, level);
2488 return HRESULT_FROM_WIN32(r);
2491 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2495 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2496 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2497 if (r == ERROR_SUCCESS)
2499 *value = SysAllocStringLen(NULL, size);
2501 return E_OUTOFMEMORY;
2503 r = MsiFormatRecordW(This->package, record, *value, &size);
2505 return HRESULT_FROM_WIN32(r);
2508 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2510 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2511 UINT r = MsiEvaluateConditionW(This->package, condition);
2512 return HRESULT_FROM_WIN32(r);
2515 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2516 INT cost_tree, INSTALLSTATE state, INT *cost )
2518 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2519 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2520 return HRESULT_FROM_WIN32(r);
2523 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2529 mrp_GetActiveDatabase,
2540 mrp_GetFeatureState,
2541 mrp_SetFeatureState,
2542 mrp_GetComponentState,
2543 mrp_SetComponentState,
2545 mrp_SetInstallLevel,
2547 mrp_EvaluateCondition,
2551 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2553 msi_remote_package_impl* This;
2555 This = msi_alloc( sizeof *This );
2557 return E_OUTOFMEMORY;
2559 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2568 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2569 LPCWSTR property, LPWSTR value)
2571 MSISOURCELISTINFO *info;
2573 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2575 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2578 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2580 return ERROR_OUTOFMEMORY;
2582 info->context = context;
2583 info->options = options;
2584 info->property = property;
2585 info->value = strdupW(value);
2586 list_add_head(&package->sourcelist_info, &info->entry);
2588 return ERROR_SUCCESS;
2591 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2592 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2596 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2598 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2601 disk = msi_alloc(sizeof(MSIMEDIADISK));
2603 return ERROR_OUTOFMEMORY;
2605 disk->context = context;
2606 disk->options = options;
2607 disk->disk_id = disk_id;
2608 disk->volume_label = strdupW(volume_label);
2609 disk->disk_prompt = strdupW(disk_prompt);
2610 list_add_head(&package->sourcelist_media, &disk->entry);
2612 return ERROR_SUCCESS;