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->display_name );
116 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
117 msi_free( assembly->tempdir );
118 msi_free( assembly );
121 static void free_package_structures( MSIPACKAGE *package )
124 struct list *item, *cursor;
126 TRACE("Freeing package action data\n");
128 remove_tracked_tempfiles(package);
130 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
132 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
133 list_remove( &feature->entry );
134 free_feature( feature );
137 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
139 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
141 list_remove( &folder->entry );
142 msi_free( folder->Parent );
143 msi_free( folder->Directory );
144 msi_free( folder->TargetDefault );
145 msi_free( folder->SourceLongPath );
146 msi_free( folder->SourceShortPath );
147 msi_free( folder->ResolvedTarget );
148 msi_free( folder->ResolvedSource );
149 msi_free( folder->Property );
153 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
155 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
157 list_remove( &comp->entry );
158 msi_free( comp->Component );
159 msi_free( comp->ComponentId );
160 msi_free( comp->Directory );
161 msi_free( comp->Condition );
162 msi_free( comp->KeyPath );
163 msi_free( comp->FullKeypath );
164 if (comp->assembly) free_assembly( comp->assembly );
168 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
170 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
172 list_remove( &file->entry );
173 msi_free( file->File );
174 msi_free( file->FileName );
175 msi_free( file->ShortName );
176 msi_free( file->LongName );
177 msi_free( file->Version );
178 msi_free( file->Language );
179 msi_free( file->TargetPath );
183 /* clean up extension, progid, class and verb structures */
184 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
186 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
188 list_remove( &cls->entry );
189 msi_free( cls->clsid );
190 msi_free( cls->Context );
191 msi_free( cls->Description );
192 msi_free( cls->FileTypeMask );
193 msi_free( cls->IconPath );
194 msi_free( cls->DefInprocHandler );
195 msi_free( cls->DefInprocHandler32 );
196 msi_free( cls->Argument );
197 msi_free( cls->ProgIDText );
201 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
203 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
205 list_remove( &ext->entry );
206 free_extension( ext );
209 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
211 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
213 list_remove( &progid->entry );
214 msi_free( progid->ProgID );
215 msi_free( progid->Description );
216 msi_free( progid->IconPath );
220 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
222 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
224 list_remove( &mt->entry );
225 msi_free( mt->suffix );
226 msi_free( mt->clsid );
227 msi_free( mt->ContentType );
231 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
233 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
235 list_remove( &appid->entry );
236 msi_free( appid->AppID );
237 msi_free( appid->RemoteServerName );
238 msi_free( appid->LocalServer );
239 msi_free( appid->ServiceParameters );
240 msi_free( appid->DllSurrogate );
244 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
246 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
248 list_remove( &info->entry );
249 msi_free( info->value );
253 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
255 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
257 list_remove( &info->entry );
258 msi_free( info->volume_label );
259 msi_free( info->disk_prompt );
265 for (i = 0; i < TOTAL_SCRIPTS; i++)
266 msi_free_action_script( package, i );
268 for (i = 0; i < package->script->UniqueActionsCount; i++)
269 msi_free( package->script->UniqueActions[i] );
271 msi_free( package->script->UniqueActions );
272 msi_free( package->script );
275 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
277 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
279 list_remove( &patch->entry );
280 msi_free( patch->patchcode );
281 msi_free( patch->transforms );
282 msi_free( patch->localfile );
286 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
288 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
290 list_remove( &binary->entry );
292 FreeLibrary( binary->module );
293 if (!DeleteFileW( binary->tmpfile ))
294 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
295 msi_free( binary->source );
296 msi_free( binary->tmpfile );
300 msi_free( package->BaseURL );
301 msi_free( package->PackagePath );
302 msi_free( package->ProductCode );
303 msi_free( package->ActionFormat );
304 msi_free( package->LastAction );
305 msi_free( package->langids );
307 /* cleanup control event subscriptions */
308 ControlEvent_CleanupSubscriptions( package );
311 static void MSI_FreePackage( MSIOBJECTHDR *arg)
313 MSIPACKAGE *package= (MSIPACKAGE*) arg;
315 if( package->dialog )
316 msi_dialog_destroy( package->dialog );
318 msiobj_release( &package->db->hdr );
319 free_package_structures(package);
320 CloseHandle( package->log_file );
322 if (package->cache_net) IAssemblyCache_Release( package->cache_net );
323 if (package->cache_sxs) IAssemblyCache_Release( package->cache_sxs );
326 static UINT create_temp_property_table(MSIPACKAGE *package)
328 MSIQUERY *view = NULL;
331 static const WCHAR CreateSql[] = {
332 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
333 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
334 '`','_','P','r','o','p','e','r','t','y','`',' ',
335 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
336 'T','E','M','P','O','R','A','R','Y',',',' ',
337 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
338 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
339 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
340 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
342 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
343 if (rc != ERROR_SUCCESS)
346 rc = MSI_ViewExecute(view, 0);
348 msiobj_release(&view->hdr);
352 UINT msi_clone_properties(MSIPACKAGE *package)
354 MSIQUERY *view_select = NULL;
357 static const WCHAR query_select[] = {
358 'S','E','L','E','C','T',' ','*',' ',
359 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
360 static const WCHAR query_insert[] = {
361 'I','N','S','E','R','T',' ','i','n','t','o',' ',
362 '`','_','P','r','o','p','e','r','t','y','`',' ',
363 '(','`','_','P','r','o','p','e','r','t','y','`',',',
364 '`','V','a','l','u','e','`',')',' ',
365 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
366 static const WCHAR query_update[] = {
367 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
368 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
369 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
371 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
372 if (rc != ERROR_SUCCESS)
375 rc = MSI_ViewExecute( view_select, 0 );
376 if (rc != ERROR_SUCCESS)
378 MSI_ViewClose( view_select );
379 msiobj_release( &view_select->hdr );
385 MSIQUERY *view_insert, *view_update;
386 MSIRECORD *rec_select;
388 rc = MSI_ViewFetch( view_select, &rec_select );
389 if (rc != ERROR_SUCCESS)
392 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
393 if (rc != ERROR_SUCCESS)
395 msiobj_release( &rec_select->hdr );
399 rc = MSI_ViewExecute( view_insert, rec_select );
400 MSI_ViewClose( view_insert );
401 msiobj_release( &view_insert->hdr );
402 if (rc != ERROR_SUCCESS)
404 MSIRECORD *rec_update;
406 TRACE("insert failed, trying update\n");
408 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
409 if (rc != ERROR_SUCCESS)
411 WARN("open view failed %u\n", rc);
412 msiobj_release( &rec_select->hdr );
416 rec_update = MSI_CreateRecord( 2 );
417 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
418 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
419 rc = MSI_ViewExecute( view_update, rec_update );
420 if (rc != ERROR_SUCCESS)
421 WARN("update failed %u\n", rc);
423 MSI_ViewClose( view_update );
424 msiobj_release( &view_update->hdr );
425 msiobj_release( &rec_update->hdr );
428 msiobj_release( &rec_select->hdr );
431 MSI_ViewClose( view_select );
432 msiobj_release( &view_select->hdr );
439 * Sets the "Installed" property to indicate that
440 * the product is installed for the current user.
442 static UINT set_installed_prop( MSIPACKAGE *package )
447 r = MSIREG_OpenUninstallKey( package, &hkey, FALSE );
448 if (r == ERROR_SUCCESS)
451 msi_set_property( package->db, szInstalled, szOne );
457 static UINT set_user_sid_prop( MSIPACKAGE *package )
461 LPWSTR sid_str = NULL, dom = NULL;
462 DWORD size, dom_size;
464 UINT r = ERROR_FUNCTION_FAILED;
467 GetUserNameW( NULL, &size );
469 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
471 return ERROR_OUTOFMEMORY;
473 if (!GetUserNameW( user_name, &size ))
478 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
480 psid = msi_alloc( size );
481 dom = msi_alloc( dom_size*sizeof (WCHAR) );
484 r = ERROR_OUTOFMEMORY;
488 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
491 if (!ConvertSidToStringSidW( psid, &sid_str ))
494 r = msi_set_property( package->db, szUserSID, sid_str );
497 LocalFree( sid_str );
500 msi_free( user_name );
505 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
510 DWORD index = 0, size;
512 WCHAR name[MAX_PATH];
513 WCHAR windir[MAX_PATH];
515 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
516 static const WCHAR sub[] = {
517 'S','o','f','t','w','a','r','e','\\',
518 'M','i','c','r','o','s','o','f','t','\\',
519 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
522 static const WCHAR subdir[] = {
523 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
524 'F','r','a','m','e','w','o','r','k','\\',0
527 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
528 if (res != ERROR_SUCCESS)
531 GetWindowsDirectoryW(windir, MAX_PATH);
535 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
539 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
540 if (strcmpW( ver, name ) < 0)
543 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
544 check = msi_alloc(size * sizeof(WCHAR));
552 lstrcpyW(check, windir);
553 lstrcatW(check, szBackSlash);
554 lstrcatW(check, subdir);
555 lstrcatW(check, name);
556 lstrcatW(check, szBackSlash);
557 lstrcatW(check, fusion);
559 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
570 RegCloseKey(netsetup);
574 typedef struct tagLANGANDCODEPAGE
580 static void set_msi_assembly_prop(MSIPACKAGE *package)
584 LPVOID version = NULL;
586 LPWSTR fusion, verstr;
587 LANGANDCODEPAGE *translate;
589 static const WCHAR netasm[] = {
590 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
592 static const WCHAR translation[] = {
593 '\\','V','a','r','F','i','l','e','I','n','f','o',
594 '\\','T','r','a','n','s','l','a','t','i','o','n',0
596 static const WCHAR verfmt[] = {
597 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
598 '\\','%','0','4','x','%','0','4','x',
599 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
602 fusion = get_fusion_filename(package);
606 size = GetFileVersionInfoSizeW(fusion, &handle);
609 version = msi_alloc(size);
610 if (!version) return;
612 if (!GetFileVersionInfoW(fusion, handle, size, version))
615 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
618 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
620 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
623 if (!val_len || !verstr)
626 msi_set_property(package->db, netasm, verstr);
633 static VOID set_installer_properties(MSIPACKAGE *package)
637 OSVERSIONINFOEXW OSVersion;
640 WCHAR verstr[10], bufstr[20];
643 LPWSTR username, companyname;
644 SYSTEM_INFO sys_info;
645 SYSTEMTIME systemtime;
648 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
649 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
650 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
651 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
652 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
653 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
654 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
655 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
656 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
657 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
658 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
659 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
660 static const WCHAR szAppDataFolder[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
661 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
662 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
663 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
664 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
665 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
666 static const WCHAR szWindowsFolder[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
667 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
668 static const WCHAR szTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
669 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
670 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
671 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
672 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
673 static const WCHAR szFormat[] = {'%','l','i',0};
674 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
675 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
676 static const WCHAR szSix[] = {'6',0 };
677 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
678 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
679 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
680 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
681 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
682 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
683 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
684 static const WCHAR szIntFormat[] = {'%','d',0};
685 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
686 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
687 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
688 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
689 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 };
690 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
691 static const WCHAR szUserInfo[] = {
692 'S','O','F','T','W','A','R','E','\\',
693 'M','i','c','r','o','s','o','f','t','\\',
694 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
695 'U','s','e','r',' ','I','n','f','o',0
697 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
698 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
699 static const WCHAR szCurrentVersion[] = {
700 'S','O','F','T','W','A','R','E','\\',
701 'M','i','c','r','o','s','o','f','t','\\',
702 'W','i','n','d','o','w','s',' ','N','T','\\',
703 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
705 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
706 static const WCHAR szRegisteredOrganization[] = {
707 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
709 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
710 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
711 static const WCHAR szDate[] = {'D','a','t','e',0};
712 static const WCHAR szTime[] = {'T','i','m','e',0};
713 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
714 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
715 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
716 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
717 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
718 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
719 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
722 * Other things that probably should be set:
724 * ComputerName VirtualMemory
725 * ShellAdvSupport DefaultUIFont PackagecodeChanging
726 * CaptionHeight BorderTop BorderSide TextHeight
727 * RedirectedDllSupport
730 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
731 strcatW(pth, szBackSlash);
732 msi_set_property(package->db, szCommonAppDataFolder, pth);
734 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
735 strcatW(pth, szBackSlash);
736 msi_set_property(package->db, szFavoritesFolder, pth);
738 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
739 strcatW(pth, szBackSlash);
740 msi_set_property(package->db, szFontsFolder, pth);
742 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
743 strcatW(pth, szBackSlash);
744 msi_set_property(package->db, szSendToFolder, pth);
746 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
747 strcatW(pth, szBackSlash);
748 msi_set_property(package->db, szStartMenuFolder, pth);
750 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
751 strcatW(pth, szBackSlash);
752 msi_set_property(package->db, szStartupFolder, pth);
754 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
755 strcatW(pth, szBackSlash);
756 msi_set_property(package->db, szTemplateFolder, pth);
758 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
759 strcatW(pth, szBackSlash);
760 msi_set_property(package->db, szDesktopFolder, pth);
762 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
763 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
764 strcatW(pth, szBackSlash);
765 msi_set_property(package->db, szProgramMenuFolder, pth);
767 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
768 strcatW(pth, szBackSlash);
769 msi_set_property(package->db, szAdminToolsFolder, pth);
771 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
772 strcatW(pth, szBackSlash);
773 msi_set_property(package->db, szAppDataFolder, pth);
775 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
776 strcatW(pth, szBackSlash);
777 msi_set_property(package->db, szSystemFolder, pth);
778 msi_set_property(package->db, szSystem16Folder, pth);
780 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
781 strcatW(pth, szBackSlash);
782 msi_set_property(package->db, szLocalAppDataFolder, pth);
784 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
785 strcatW(pth, szBackSlash);
786 msi_set_property(package->db, szMyPicturesFolder, pth);
788 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
789 strcatW(pth, szBackSlash);
790 msi_set_property(package->db, szPersonalFolder, pth);
792 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
793 strcatW(pth, szBackSlash);
794 msi_set_property(package->db, szWindowsFolder, pth);
796 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
797 strcatW(pth, szBackSlash);
798 msi_set_property(package->db, szPrintHoodFolder, pth);
800 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
801 strcatW(pth, szBackSlash);
802 msi_set_property(package->db, szNetHoodFolder, pth);
804 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
805 strcatW(pth, szBackSlash);
806 msi_set_property(package->db, szRecentFolder, pth);
808 /* Physical Memory is specified in MB. Using total amount. */
809 msex.dwLength = sizeof(msex);
810 GlobalMemoryStatusEx( &msex );
811 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
812 msi_set_property(package->db, szPhysicalMemory, bufstr);
814 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
815 ptr = strchrW(pth,'\\');
816 if (ptr) *(ptr + 1) = 0;
817 msi_set_property(package->db, szWindowsVolume, pth);
819 GetTempPathW(MAX_PATH,pth);
820 msi_set_property(package->db, szTempFolder, pth);
822 /* in a wine environment the user is always admin and privileged */
823 msi_set_property(package->db, szAdminUser, szOne);
824 msi_set_property(package->db, szPrivileged, szOne);
826 /* set the os things */
827 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
828 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
829 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
830 sprintfW(verstr, szFormat, verval);
831 switch (OSVersion.dwPlatformId)
833 case VER_PLATFORM_WIN32_WINDOWS:
834 msi_set_property(package->db, szVersion9x, verstr);
836 case VER_PLATFORM_WIN32_NT:
837 msi_set_property(package->db, szVersionNT, verstr);
838 sprintfW(verstr, szFormat,OSVersion.wProductType);
839 msi_set_property(package->db, szMsiNTProductType, verstr);
842 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
843 msi_set_property(package->db, szWindowsBuild, verstr);
844 /* just fudge this */
845 msi_set_property(package->db, szServicePackLevel, szSix);
847 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
848 msi_set_property( package->db, szVersionMsi, bufstr );
849 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
850 msi_set_property( package->db, szVersionDatabase, bufstr );
852 GetNativeSystemInfo( &sys_info );
853 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
854 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
856 msi_set_property( package->db, szIntel, bufstr );
858 GetSystemDirectoryW( pth, MAX_PATH );
859 PathAddBackslashW( pth );
860 msi_set_property( package->db, szSystemFolder, pth );
862 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
863 PathAddBackslashW( pth );
864 msi_set_property( package->db, szProgramFilesFolder, pth );
866 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
867 PathAddBackslashW( pth );
868 msi_set_property( package->db, szCommonFilesFolder, pth );
870 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
872 msi_set_property( package->db, szMsiAMD64, bufstr );
873 msi_set_property( package->db, szMsix64, bufstr );
874 msi_set_property( package->db, szVersionNT64, verstr );
876 GetSystemDirectoryW( pth, MAX_PATH );
877 PathAddBackslashW( pth );
878 msi_set_property( package->db, szSystem64Folder, pth );
880 GetSystemWow64DirectoryW( pth, MAX_PATH );
881 PathAddBackslashW( pth );
882 msi_set_property( package->db, szSystemFolder, pth );
884 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
885 PathAddBackslashW( pth );
886 msi_set_property( package->db, szProgramFiles64Folder, pth );
888 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
889 PathAddBackslashW( pth );
890 msi_set_property( package->db, szProgramFilesFolder, pth );
892 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
893 PathAddBackslashW( pth );
894 msi_set_property( package->db, szCommonFiles64Folder, pth );
896 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
897 PathAddBackslashW( pth );
898 msi_set_property( package->db, szCommonFilesFolder, pth );
901 /* Screen properties. */
903 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
904 msi_set_property( package->db, szScreenX, bufstr );
905 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
906 msi_set_property( package->db, szScreenY, bufstr );
907 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
908 msi_set_property( package->db, szColorBits, bufstr );
911 /* USERNAME and COMPANYNAME */
912 username = msi_dup_property( package->db, szUSERNAME );
913 companyname = msi_dup_property( package->db, szCOMPANYNAME );
915 if ((!username || !companyname) &&
916 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
919 (username = msi_reg_get_val_str( hkey, szDefName )))
920 msi_set_property( package->db, szUSERNAME, username );
922 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
923 msi_set_property( package->db, szCOMPANYNAME, companyname );
926 if ((!username || !companyname) &&
927 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
930 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
931 msi_set_property( package->db, szUSERNAME, username );
933 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
934 msi_set_property( package->db, szCOMPANYNAME, companyname );
937 msi_free( username );
938 msi_free( companyname );
940 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
941 ERR("Failed to set the UserSID property\n");
943 /* Date and time properties */
944 GetSystemTime( &systemtime );
945 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
946 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
947 msi_set_property( package->db, szDate, bufstr );
949 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
951 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
952 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
953 &systemtime, NULL, bufstr,
954 sizeof(bufstr)/sizeof(bufstr[0]) ))
955 msi_set_property( package->db, szTime, bufstr );
957 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
959 set_msi_assembly_prop( package );
961 langid = GetUserDefaultLangID();
962 sprintfW(bufstr, szIntFormat, langid);
963 msi_set_property( package->db, szUserLanguageID, bufstr );
965 langid = GetSystemDefaultLangID();
966 sprintfW(bufstr, szIntFormat, langid);
967 msi_set_property( package->db, szSystemLangID, bufstr );
969 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
970 msi_set_property( package->db, szProductState, bufstr );
973 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_MORE_DATA)
976 if ((username = msi_alloc( len * sizeof(WCHAR) )))
978 if (GetUserNameW( username, &len ))
979 msi_set_property( package->db, szLogonUser, username );
980 msi_free( username );
985 static UINT msi_load_summary_properties( MSIPACKAGE *package )
989 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
993 static const WCHAR szPackageCode[] = {
994 'P','a','c','k','a','g','e','C','o','d','e',0};
997 ERR("Unable to allocate handle\n");
998 return ERROR_OUTOFMEMORY;
1001 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1002 MsiCloseHandle(hdb);
1003 if (rc != ERROR_SUCCESS)
1005 ERR("Unable to open Summary Information\n");
1009 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1010 &count, NULL, NULL, NULL );
1011 if (rc != ERROR_SUCCESS)
1013 WARN("Unable to query page count: %d\n", rc);
1017 /* load package code property */
1019 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1020 NULL, NULL, NULL, &len );
1021 if (rc != ERROR_MORE_DATA)
1023 WARN("Unable to query revision number: %d\n", rc);
1024 rc = ERROR_FUNCTION_FAILED;
1029 package_code = msi_alloc( len * sizeof(WCHAR) );
1030 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1031 NULL, NULL, package_code, &len );
1032 if (rc != ERROR_SUCCESS)
1034 WARN("Unable to query rev number: %d\n", rc);
1038 msi_set_property( package->db, szPackageCode, package_code );
1039 msi_free( package_code );
1041 /* load package attributes */
1043 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1044 &count, NULL, NULL, NULL );
1045 package->WordCount = count;
1048 MsiCloseHandle(suminfo);
1052 static MSIPACKAGE *msi_alloc_package( void )
1054 MSIPACKAGE *package;
1056 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1060 list_init( &package->components );
1061 list_init( &package->features );
1062 list_init( &package->files );
1063 list_init( &package->tempfiles );
1064 list_init( &package->folders );
1065 list_init( &package->subscriptions );
1066 list_init( &package->appids );
1067 list_init( &package->classes );
1068 list_init( &package->mimes );
1069 list_init( &package->extensions );
1070 list_init( &package->progids );
1071 list_init( &package->RunningActions );
1072 list_init( &package->sourcelist_info );
1073 list_init( &package->sourcelist_media );
1074 list_init( &package->patches );
1075 list_init( &package->binaries );
1081 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1086 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1088 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1089 if (r != ERROR_SUCCESS)
1092 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1098 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1100 /* FIXME: this should depend on the user's privileges */
1101 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1103 TRACE("resetting ALLUSERS property from 2 to 1\n");
1104 msi_set_property( package->db, szAllUsers, szOne );
1106 msi_set_property( package->db, szAdminUser, szOne );
1109 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1111 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
1112 static const WCHAR szpi[] = {'%','i',0};
1113 MSIPACKAGE *package;
1119 package = msi_alloc_package();
1122 msiobj_addref( &db->hdr );
1125 package->WordCount = 0;
1126 package->PackagePath = strdupW( db->path );
1127 package->BaseURL = strdupW( base_url );
1129 create_temp_property_table( package );
1130 msi_clone_properties( package );
1131 msi_adjust_privilege_properties( package );
1133 package->ProductCode = msi_dup_property( package->db, szProductCode );
1134 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1136 set_installed_prop( package );
1137 set_installer_properties( package );
1139 sprintfW(uilevel,szpi,gUILevel);
1140 msi_set_property(package->db, szLevel, uilevel);
1142 r = msi_load_summary_properties( package );
1143 if (r != ERROR_SUCCESS)
1145 msiobj_release( &package->hdr );
1149 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1150 msi_load_admin_properties( package );
1152 package->log_file = INVALID_HANDLE_VALUE;
1159 * copy_package_to_temp [internal]
1161 * copy the msi file to a temp file to prevent locking a CD
1162 * with a multi disc install
1164 * FIXME: I think this is wrong, and instead of copying the package,
1165 * we should read all the tables to memory, then open the
1166 * database to read binary streams on demand.
1168 static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
1170 WCHAR path[MAX_PATH];
1172 GetTempPathW( MAX_PATH, path );
1173 GetTempFileNameW( path, szMsi, 0, filename );
1175 if( !CopyFileW( szPackage, filename, FALSE ) )
1177 UINT error = GetLastError();
1178 if ( error == ERROR_FILE_NOT_FOUND )
1179 ERR("can't find %s\n", debugstr_w(szPackage));
1181 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
1182 DeleteFileW( filename );
1186 return ERROR_SUCCESS;
1189 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1191 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1195 /* call will always fail, becase size is 0,
1196 * but will return ERROR_FILE_NOT_FOUND first
1197 * if the file doesn't exist
1199 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1200 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1202 cache_entry = msi_alloc( size );
1203 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1205 UINT error = GetLastError();
1206 msi_free( cache_entry );
1210 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1211 msi_free( cache_entry );
1212 return ERROR_SUCCESS;
1215 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1218 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1219 return ERROR_FUNCTION_FAILED;
1222 return ERROR_SUCCESS;
1225 UINT msi_get_local_package_name( LPWSTR path, LPCWSTR suffix )
1227 static const WCHAR szInstaller[] = {
1228 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1229 static const WCHAR fmt[] = {'%','x',0};
1230 DWORD time, len, i, offset;
1233 time = GetTickCount();
1234 GetWindowsDirectoryW( path, MAX_PATH );
1235 strcatW( path, szInstaller );
1236 CreateDirectoryW( path, NULL );
1238 len = strlenW(path);
1239 for (i = 0; i < 0x10000; i++)
1241 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1242 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1243 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1244 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1245 if (handle != INVALID_HANDLE_VALUE)
1247 CloseHandle(handle);
1250 if (GetLastError() != ERROR_FILE_EXISTS &&
1251 GetLastError() != ERROR_SHARING_VIOLATION)
1252 return ERROR_FUNCTION_FAILED;
1255 return ERROR_SUCCESS;
1258 static UINT apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
1262 WCHAR patch_file[MAX_PATH];
1263 MSIDATABASE *patch_db;
1264 MSIPATCHINFO *patch_info;
1267 len = sizeof(patch_file) / sizeof(WCHAR);
1268 r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
1269 INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
1270 if (r != ERROR_SUCCESS)
1272 ERR("failed to get patch filename %u\n", r);
1276 r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
1277 if (r != ERROR_SUCCESS)
1279 ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
1283 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
1286 msiobj_release( &patch_db->hdr );
1287 return ERROR_FUNCTION_FAILED;
1290 r = msi_parse_patch_summary( si, &patch_info );
1291 msiobj_release( &si->hdr );
1292 if (r != ERROR_SUCCESS)
1294 ERR("failed to parse patch summary %u\n", r);
1295 msiobj_release( &patch_db->hdr );
1299 patch_info->localfile = strdupW( patch_file );
1300 if (!patch_info->localfile)
1302 msiobj_release( &patch_db->hdr );
1303 return ERROR_OUTOFMEMORY;
1306 r = msi_apply_patch_db( package, patch_db, patch_info );
1307 msiobj_release( &patch_db->hdr );
1308 if (r != ERROR_SUCCESS)
1310 ERR("failed to apply patch %u\n", r);
1311 msi_free( patch_info->patchcode );
1312 msi_free( patch_info->transforms );
1313 msi_free( patch_info->localfile );
1314 msi_free( patch_info );
1319 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1321 WCHAR *template, *p, *q;
1324 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1325 TRACE("version: %d\n", package->version);
1327 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1329 return ERROR_SUCCESS; /* native accepts missing template property */
1331 TRACE("template: %s\n", debugstr_w(template));
1333 p = strchrW( template, ';' );
1336 WARN("invalid template string %s\n", debugstr_w(template));
1337 msi_free( template );
1338 return ERROR_PATCH_PACKAGE_INVALID;
1341 if (!template[0] || !strcmpW( template, szIntel ))
1342 package->platform = PLATFORM_INTEL;
1343 else if (!strcmpW( template, szIntel64 ))
1344 package->platform = PLATFORM_INTEL64;
1345 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1346 package->platform = PLATFORM_X64;
1349 WARN("unknown platform %s\n", debugstr_w(template));
1350 msi_free( template );
1351 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1356 msi_free( template );
1357 return ERROR_SUCCESS;
1360 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1362 package->langids = msi_alloc( count * sizeof(LANGID) );
1363 if (!package->langids)
1365 msi_free( template );
1366 return ERROR_OUTOFMEMORY;
1372 q = strchrW( p, ',' );
1374 package->langids[i] = atoiW( p );
1379 package->num_langids = i + 1;
1381 msi_free( template );
1382 return ERROR_SUCCESS;
1385 static UINT validate_package( MSIPACKAGE *package )
1390 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1391 if (package->platform == PLATFORM_X64)
1393 if (!is_64bit && !is_wow64)
1394 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1395 if (package->version < 200)
1396 return ERROR_INSTALL_PACKAGE_INVALID;
1398 if (!package->num_langids)
1400 return ERROR_SUCCESS;
1402 for (i = 0; i < package->num_langids; i++)
1404 LANGID langid = package->langids[i];
1406 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1408 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1410 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1412 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1414 if (IsValidLocale( langid, LCID_INSTALLED ))
1415 return ERROR_SUCCESS;
1417 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1420 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1422 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
1423 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1424 MSIDATABASE *db = NULL;
1425 MSIPACKAGE *package;
1427 LPWSTR ptr, base_url = NULL;
1429 WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
1430 LPCWSTR file = szPackage;
1434 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1436 if( szPackage[0] == '#' )
1438 handle = atoiW(&szPackage[1]);
1439 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1442 IWineMsiRemoteDatabase *remote_database;
1444 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1445 if ( !remote_database )
1446 return ERROR_INVALID_HANDLE;
1448 IWineMsiRemoteDatabase_Release( remote_database );
1449 WARN("MsiOpenPackage not allowed during a custom action!\n");
1451 return ERROR_FUNCTION_FAILED;
1456 if ( UrlIsW( szPackage, URLIS_URL ) )
1458 r = msi_download_file( szPackage, cachefile );
1459 if ( r != ERROR_SUCCESS )
1462 r = copy_package_to_temp( cachefile, temppath );
1463 if ( r != ERROR_SUCCESS )
1468 base_url = strdupW( szPackage );
1470 return ERROR_OUTOFMEMORY;
1472 ptr = strrchrW( base_url, '/' );
1473 if (ptr) *(ptr + 1) = '\0';
1477 r = copy_package_to_temp( szPackage, temppath );
1478 if ( r != ERROR_SUCCESS )
1484 r = msi_get_local_package_name( localfile, dotmsi );
1485 if (r != ERROR_SUCCESS)
1488 TRACE("Copying to local package %s\n", debugstr_w(localfile));
1490 if (!CopyFileW( file, localfile, FALSE ))
1492 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1493 debugstr_w(file), debugstr_w(localfile), GetLastError());
1494 return GetLastError();
1497 TRACE("Opening relocated package %s\n", debugstr_w( file ));
1499 /* transforms that add binary streams require that we open the database
1500 * read/write, which is safe because we always create a copy that is thrown
1501 * away when we're done.
1503 r = MSI_OpenDatabaseW( file, MSIDBOPEN_TRANSACT, &db );
1504 if( r != ERROR_SUCCESS )
1506 if (file != szPackage)
1507 DeleteFileW( file );
1509 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
1510 return ERROR_FILE_NOT_FOUND;
1515 db->localfile = strdupW( localfile );
1518 package = MSI_CreatePackage( db, base_url );
1519 msi_free( base_url );
1520 msiobj_release( &db->hdr );
1523 if (file != szPackage)
1524 DeleteFileW( file );
1526 return ERROR_INSTALL_PACKAGE_INVALID;
1529 if( file != szPackage )
1530 track_tempfile( package, file );
1532 si = MSI_GetSummaryInformationW( db->storage, 0 );
1535 WARN("failed to load summary info %u\n", r);
1536 msiobj_release( &package->hdr );
1537 return ERROR_INSTALL_PACKAGE_INVALID;
1540 r = msi_parse_summary( si, package );
1541 msiobj_release( &si->hdr );
1542 if (r != ERROR_SUCCESS)
1544 WARN("failed to parse summary info %u\n", r);
1545 msiobj_release( &package->hdr );
1549 r = validate_package( package );
1550 if (r != ERROR_SUCCESS)
1552 msiobj_release( &package->hdr );
1555 msi_set_property( package->db, Database, db->path );
1557 if( UrlIsW( szPackage, URLIS_URL ) )
1558 msi_set_property( package->db, szOriginalDatabase, szPackage );
1559 else if( szPackage[0] == '#' )
1560 msi_set_property( package->db, szOriginalDatabase, db->path );
1563 WCHAR fullpath[MAX_PATH];
1565 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1566 msi_set_property( package->db, szOriginalDatabase, fullpath );
1569 msi_set_context( package );
1573 WCHAR patch_code[GUID_SIZE];
1574 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1575 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1576 if (r != ERROR_SUCCESS)
1579 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1581 r = apply_registered_patch( package, patch_code );
1582 if (r != ERROR_SUCCESS)
1584 ERR("registered patch failed to apply %u\n", r);
1585 msiobj_release( &package->hdr );
1594 msi_clone_properties( package );
1595 msi_adjust_privilege_properties( package );
1599 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1600 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1602 *pPackage = package;
1603 return ERROR_SUCCESS;
1606 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1608 MSIPACKAGE *package = NULL;
1611 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1613 if( !szPackage || !phPackage )
1614 return ERROR_INVALID_PARAMETER;
1618 FIXME("Should create an empty database and package\n");
1619 return ERROR_FUNCTION_FAILED;
1623 FIXME("dwOptions %08x not supported\n", dwOptions);
1625 ret = MSI_OpenPackageW( szPackage, &package );
1626 if( ret == ERROR_SUCCESS )
1628 *phPackage = alloc_msihandle( &package->hdr );
1630 ret = ERROR_NOT_ENOUGH_MEMORY;
1631 msiobj_release( &package->hdr );
1637 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1639 return MsiOpenPackageExW( szPackage, 0, phPackage );
1642 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1644 LPWSTR szwPack = NULL;
1649 szwPack = strdupAtoW( szPackage );
1651 return ERROR_OUTOFMEMORY;
1654 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1656 msi_free( szwPack );
1661 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1663 return MsiOpenPackageExA( szPackage, 0, phPackage );
1666 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1668 MSIPACKAGE *package;
1669 MSIHANDLE handle = 0;
1670 IUnknown *remote_unk;
1671 IWineMsiRemotePackage *remote_package;
1673 TRACE("(%d)\n",hInstall);
1675 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1678 handle = alloc_msihandle( &package->db->hdr );
1679 msiobj_release( &package->hdr );
1681 else if ((remote_unk = msi_get_remote(hInstall)))
1683 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1684 (LPVOID *)&remote_package) == S_OK)
1686 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1687 IWineMsiRemotePackage_Release(remote_package);
1691 WARN("remote handle %d is not a package\n", hInstall);
1693 IUnknown_Release(remote_unk);
1699 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1702 static const WCHAR szActionData[] =
1703 {'A','c','t','i','o','n','D','a','t','a',0};
1704 static const WCHAR szSetProgress[] =
1705 {'S','e','t','P','r','o','g','r','e','s','s',0};
1706 static const WCHAR szActionText[] =
1707 {'A','c','t','i','o','n','T','e','x','t',0};
1709 DWORD sz, total_size = 0, log_type = 0;
1714 TRACE("%x\n", eMessageType);
1716 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1717 log_type |= INSTALLLOGMODE_ERROR;
1718 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1719 log_type |= INSTALLLOGMODE_WARNING;
1720 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1721 log_type |= INSTALLLOGMODE_USER;
1722 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1723 log_type |= INSTALLLOGMODE_INFO;
1724 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1725 log_type |= INSTALLLOGMODE_COMMONDATA;
1726 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1727 log_type |= INSTALLLOGMODE_ACTIONSTART;
1728 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1729 log_type |= INSTALLLOGMODE_ACTIONDATA;
1731 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1734 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1736 static const WCHAR template_s[]=
1737 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1738 static const WCHAR format[] =
1739 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1741 LPCWSTR action_text, action;
1742 LPWSTR deformatted = NULL;
1744 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1746 action = MSI_RecordGetString(record, 1);
1747 action_text = MSI_RecordGetString(record, 2);
1749 if (!action || !action_text)
1752 deformat_string(package, action_text, &deformatted);
1754 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1756 len += strlenW(deformatted);
1757 message = msi_alloc(len*sizeof(WCHAR));
1758 sprintfW(message, template_s, timet, action);
1760 strcatW(message, deformatted);
1761 msi_free(deformatted);
1766 message = msi_alloc(1*sizeof (WCHAR));
1768 msg_field = MSI_RecordGetFieldCount(record);
1769 for (i = 1; i <= msg_field; i++)
1773 static const WCHAR format[] = { '%','i',':',' ',0};
1775 MSI_RecordGetStringW(record,i,NULL,&sz);
1777 total_size+=sz*sizeof(WCHAR);
1778 tmp = msi_alloc(sz*sizeof(WCHAR));
1779 message = msi_realloc(message,total_size*sizeof (WCHAR));
1781 MSI_RecordGetStringW(record,i,tmp,&sz);
1785 sprintfW(number,format,i);
1786 strcatW(message,number);
1788 strcatW(message,tmp);
1790 strcatW(message, szSpace);
1796 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1797 gUIFilter, log_type, debugstr_w(message));
1799 /* convert it to ASCII */
1800 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1801 msg = msi_alloc( len );
1802 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1804 if (gUIHandlerW && (gUIFilter & log_type))
1806 rc = gUIHandlerW( gUIContext, eMessageType, message );
1808 else if (gUIHandlerA && (gUIFilter & log_type))
1810 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1812 else if (gUIHandlerRecord && (gUIFilter & log_type))
1814 MSIHANDLE rec = MsiCreateRecord( 1 );
1815 MsiRecordSetStringW( rec, 0, message );
1816 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1817 MsiCloseHandle( rec );
1820 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1821 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1824 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1825 WriteFile( package->log_file, "\n", 1, &written, NULL );
1828 msi_free( message );
1830 switch (eMessageType & 0xff000000)
1832 case INSTALLMESSAGE_ACTIONDATA:
1833 /* FIXME: format record here instead of in ui_actiondata to get the
1834 * correct action data for external scripts */
1835 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1837 case INSTALLMESSAGE_ACTIONSTART:
1841 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1843 deformat_string(package, action_text, &deformated);
1844 uirow = MSI_CreateRecord(1);
1845 MSI_RecordSetStringW(uirow, 1, deformated);
1846 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1847 msi_free(deformated);
1849 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1851 msiobj_release(&uirow->hdr);
1854 case INSTALLMESSAGE_PROGRESS:
1855 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1859 return ERROR_SUCCESS;
1862 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1865 UINT ret = ERROR_INVALID_HANDLE;
1866 MSIPACKAGE *package = NULL;
1867 MSIRECORD *record = NULL;
1869 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1873 IWineMsiRemotePackage *remote_package;
1875 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1876 if (!remote_package)
1877 return ERROR_INVALID_HANDLE;
1879 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1881 IWineMsiRemotePackage_Release( remote_package );
1885 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1886 return HRESULT_CODE(hr);
1888 return ERROR_FUNCTION_FAILED;
1891 return ERROR_SUCCESS;
1894 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1898 ret = MSI_ProcessMessage( package, eMessageType, record );
1901 msiobj_release( &package->hdr );
1903 msiobj_release( &record->hdr );
1910 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1912 LPWSTR szwName = NULL, szwValue = NULL;
1913 UINT r = ERROR_OUTOFMEMORY;
1915 szwName = strdupAtoW( szName );
1916 if( szName && !szwName )
1919 szwValue = strdupAtoW( szValue );
1920 if( szValue && !szwValue )
1923 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1926 msi_free( szwName );
1927 msi_free( szwValue );
1932 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1936 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1940 msi_free( folder->ResolvedSource );
1941 folder->ResolvedSource = NULL;
1945 msi_free( folder->ResolvedTarget );
1946 folder->ResolvedTarget = NULL;
1951 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1954 MSIRECORD *row = NULL;
1959 static const WCHAR Insert[] = {
1960 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1961 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1962 '`','_','P','r','o','p','e','r','t','y','`',',',
1963 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1964 ,' ','(','?',',','?',')',0};
1965 static const WCHAR Update[] = {
1966 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1967 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1968 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1969 ' ','=',' ','\'','%','s','\'',0};
1970 static const WCHAR Delete[] = {
1971 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1972 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1973 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1975 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
1978 return ERROR_INVALID_PARAMETER;
1980 /* this one is weird... */
1982 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1984 rc = msi_get_property(db, szName, 0, &sz);
1985 if (!szValue || !*szValue)
1987 sprintfW(Query, Delete, szName);
1989 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1991 sprintfW(Query, Update, szName);
1993 row = MSI_CreateRecord(1);
1994 MSI_RecordSetStringW(row, 1, szValue);
1998 strcpyW(Query, Insert);
2000 row = MSI_CreateRecord(2);
2001 MSI_RecordSetStringW(row, 1, szName);
2002 MSI_RecordSetStringW(row, 2, szValue);
2005 rc = MSI_DatabaseOpenViewW(db, Query, &view);
2006 if (rc == ERROR_SUCCESS)
2008 rc = MSI_ViewExecute(view, row);
2009 MSI_ViewClose(view);
2010 msiobj_release(&view->hdr);
2014 msiobj_release(&row->hdr);
2019 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2021 MSIPACKAGE *package;
2024 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2028 BSTR name = NULL, value = NULL;
2029 IWineMsiRemotePackage *remote_package;
2031 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2032 if (!remote_package)
2033 return ERROR_INVALID_HANDLE;
2035 name = SysAllocString( szName );
2036 value = SysAllocString( szValue );
2037 if ((!name && szName) || (!value && szValue))
2039 SysFreeString( name );
2040 SysFreeString( value );
2041 IWineMsiRemotePackage_Release( remote_package );
2042 return ERROR_OUTOFMEMORY;
2045 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2047 SysFreeString( name );
2048 SysFreeString( value );
2049 IWineMsiRemotePackage_Release( remote_package );
2053 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2054 return HRESULT_CODE(hr);
2056 return ERROR_FUNCTION_FAILED;
2059 return ERROR_SUCCESS;
2062 ret = msi_set_property( package->db, szName, szValue );
2063 if (ret == ERROR_SUCCESS && !strcmpW( szName, cszSourceDir ))
2064 msi_reset_folders( package, TRUE );
2066 msiobj_release( &package->hdr );
2070 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2073 MSIRECORD *rec, *row = NULL;
2076 static const WCHAR query[]= {
2077 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2078 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2079 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2082 if (!name || !*name)
2085 rec = MSI_CreateRecord(1);
2089 MSI_RecordSetStringW(rec, 1, name);
2091 r = MSI_DatabaseOpenViewW(db, query, &view);
2092 if (r == ERROR_SUCCESS)
2094 MSI_ViewExecute(view, rec);
2095 MSI_ViewFetch(view, &row);
2096 MSI_ViewClose(view);
2097 msiobj_release(&view->hdr);
2100 msiobj_release(&rec->hdr);
2104 /* internal function, not compatible with MsiGetPropertyW */
2105 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2106 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2109 UINT rc = ERROR_FUNCTION_FAILED;
2111 row = msi_get_property_row( db, szName );
2113 if (*pchValueBuf > 0)
2118 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2119 msiobj_release(&row->hdr);
2122 if (rc == ERROR_SUCCESS)
2123 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2124 debugstr_w(szName));
2125 else if (rc == ERROR_MORE_DATA)
2126 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2127 debugstr_w(szName));
2131 TRACE("property %s not found\n", debugstr_w(szName));
2137 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2143 r = msi_get_property(db, prop, NULL, &sz);
2144 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2148 str = msi_alloc(sz * sizeof(WCHAR));
2149 r = msi_get_property(db, prop, str, &sz);
2150 if (r != ERROR_SUCCESS)
2159 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2161 LPWSTR str = msi_dup_property( db, prop );
2162 int val = str ? atoiW(str) : def;
2167 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2168 awstring *szValueBuf, LPDWORD pchValueBuf )
2170 MSIPACKAGE *package;
2171 MSIRECORD *row = NULL;
2172 UINT r = ERROR_FUNCTION_FAILED;
2175 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2176 szValueBuf->str.w, pchValueBuf );
2179 return ERROR_INVALID_PARAMETER;
2181 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2185 IWineMsiRemotePackage *remote_package;
2186 LPWSTR value = NULL;
2190 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2191 if (!remote_package)
2192 return ERROR_INVALID_HANDLE;
2194 bname = SysAllocString( name );
2197 IWineMsiRemotePackage_Release( remote_package );
2198 return ERROR_OUTOFMEMORY;
2202 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2207 value = msi_alloc(len * sizeof(WCHAR));
2210 r = ERROR_OUTOFMEMORY;
2214 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
2218 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2220 /* Bug required by Adobe installers */
2221 if (!szValueBuf->unicode && !szValueBuf->str.a)
2222 *pchValueBuf *= sizeof(WCHAR);
2225 IWineMsiRemotePackage_Release(remote_package);
2226 SysFreeString(bname);
2231 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2232 return HRESULT_CODE(hr);
2234 return ERROR_FUNCTION_FAILED;
2240 row = msi_get_property_row( package->db, name );
2242 val = MSI_RecordGetString( row, 1 );
2247 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2250 msiobj_release( &row->hdr );
2251 msiobj_release( &package->hdr );
2256 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2257 LPSTR szValueBuf, LPDWORD pchValueBuf )
2263 val.unicode = FALSE;
2264 val.str.a = szValueBuf;
2266 name = strdupAtoW( szName );
2267 if (szName && !name)
2268 return ERROR_OUTOFMEMORY;
2270 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2275 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2276 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2281 val.str.w = szValueBuf;
2283 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2286 typedef struct _msi_remote_package_impl {
2287 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2290 } msi_remote_package_impl;
2292 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2294 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2297 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2298 REFIID riid,LPVOID *ppobj)
2300 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2301 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2303 IUnknown_AddRef( iface );
2308 return E_NOINTERFACE;
2311 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2313 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2315 return InterlockedIncrement( &This->refs );
2318 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2320 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2323 r = InterlockedDecrement( &This->refs );
2326 MsiCloseHandle( This->package );
2332 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2334 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2335 This->package = handle;
2339 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2341 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2342 IWineMsiRemoteDatabase *rdb = NULL;
2346 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2347 if (FAILED(hr) || !rdb)
2349 ERR("Failed to create remote database\n");
2353 hdb = MsiGetActiveDatabase(This->package);
2355 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2358 ERR("Failed to set the database handle\n");
2362 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2366 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
2368 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2371 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
2372 if (r != ERROR_SUCCESS)
2373 return HRESULT_FROM_WIN32(r);
2378 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2380 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2381 UINT r = MsiSetPropertyW(This->package, property, value);
2382 return HRESULT_FROM_WIN32(r);
2385 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2387 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2388 UINT r = MsiProcessMessage(This->package, message, record);
2389 return HRESULT_FROM_WIN32(r);
2392 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2394 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2395 UINT r = MsiDoActionW(This->package, action);
2396 return HRESULT_FROM_WIN32(r);
2399 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2401 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2402 UINT r = MsiSequenceW(This->package, table, sequence);
2403 return HRESULT_FROM_WIN32(r);
2406 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2408 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2409 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2410 return HRESULT_FROM_WIN32(r);
2413 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2415 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2416 UINT r = MsiSetTargetPathW(This->package, folder, value);
2417 return HRESULT_FROM_WIN32(r);
2420 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2422 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2423 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2424 return HRESULT_FROM_WIN32(r);
2427 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2429 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2430 *ret = MsiGetMode(This->package, mode);
2434 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2436 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2437 UINT r = MsiSetMode(This->package, mode, state);
2438 return HRESULT_FROM_WIN32(r);
2441 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2442 INSTALLSTATE *installed, INSTALLSTATE *action )
2444 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2445 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2446 return HRESULT_FROM_WIN32(r);
2449 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2451 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2452 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2453 return HRESULT_FROM_WIN32(r);
2456 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2457 INSTALLSTATE *installed, INSTALLSTATE *action )
2459 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2460 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2461 return HRESULT_FROM_WIN32(r);
2464 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2466 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2467 UINT r = MsiSetComponentStateW(This->package, component, state);
2468 return HRESULT_FROM_WIN32(r);
2471 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2473 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2474 *language = MsiGetLanguage(This->package);
2478 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2480 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2481 UINT r = MsiSetInstallLevel(This->package, level);
2482 return HRESULT_FROM_WIN32(r);
2485 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2489 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2490 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2491 if (r == ERROR_SUCCESS)
2493 *value = SysAllocStringLen(NULL, size);
2495 return E_OUTOFMEMORY;
2497 r = MsiFormatRecordW(This->package, record, *value, &size);
2499 return HRESULT_FROM_WIN32(r);
2502 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2504 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2505 UINT r = MsiEvaluateConditionW(This->package, condition);
2506 return HRESULT_FROM_WIN32(r);
2509 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2510 INT cost_tree, INSTALLSTATE state, INT *cost )
2512 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2513 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2514 return HRESULT_FROM_WIN32(r);
2517 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2523 mrp_GetActiveDatabase,
2534 mrp_GetFeatureState,
2535 mrp_SetFeatureState,
2536 mrp_GetComponentState,
2537 mrp_SetComponentState,
2539 mrp_SetInstallLevel,
2541 mrp_EvaluateCondition,
2545 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2547 msi_remote_package_impl* This;
2549 This = msi_alloc( sizeof *This );
2551 return E_OUTOFMEMORY;
2553 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2562 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2563 LPCWSTR property, LPWSTR value)
2565 MSISOURCELISTINFO *info;
2567 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2569 return ERROR_OUTOFMEMORY;
2571 info->context = context;
2572 info->options = options;
2573 info->property = property;
2574 info->value = strdupW(value);
2575 list_add_head(&package->sourcelist_info, &info->entry);
2577 return ERROR_SUCCESS;
2580 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2581 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2585 disk = msi_alloc(sizeof(MSIMEDIADISK));
2587 return ERROR_OUTOFMEMORY;
2589 disk->context = context;
2590 disk->options = options;
2591 disk->disk_id = disk_id;
2592 disk->volume_label = strdupW(volume_label);
2593 disk->disk_prompt = strdupW(disk_prompt);
2594 list_add_head(&package->sourcelist_media, &disk->entry);
2596 return ERROR_SUCCESS;