gdi32: Store and return ABC metrics from get_glyph_outline.
[wine.git] / dlls / msi / package.c
blob3055175773be579ddf1eb33848a986de522a478b
1 /*
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
23 #define COBJMACROS
25 #include <stdarg.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wingdi.h"
32 #include "wine/debug.h"
33 #include "msi.h"
34 #include "msiquery.h"
35 #include "objidl.h"
36 #include "wincrypt.h"
37 #include "winuser.h"
38 #include "wininet.h"
39 #include "winver.h"
40 #include "urlmon.h"
41 #include "shlobj.h"
42 #include "wine/unicode.h"
43 #include "objbase.h"
44 #include "msidefs.h"
45 #include "sddl.h"
47 #include "msipriv.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 );
64 msi_free( temp );
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 );
76 msi_free( fl );
79 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
81 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
82 list_remove( &cl->entry );
83 msi_free( cl );
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 );
90 msi_free( feature );
93 static void free_folder( MSIFOLDER *folder )
95 struct list *item, *cursor;
97 LIST_FOR_EACH_SAFE( item, cursor, &folder->children )
99 FolderList *fl = LIST_ENTRY( item, FolderList, entry );
100 list_remove( &fl->entry );
101 msi_free( fl );
103 msi_free( folder->Parent );
104 msi_free( folder->Directory );
105 msi_free( folder->TargetDefault );
106 msi_free( folder->SourceLongPath );
107 msi_free( folder->SourceShortPath );
108 msi_free( folder->ResolvedTarget );
109 msi_free( folder->ResolvedSource );
110 msi_free( folder );
113 static void free_extension( MSIEXTENSION *ext )
115 struct list *item, *cursor;
117 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
119 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
121 list_remove( &verb->entry );
122 msi_free( verb->Verb );
123 msi_free( verb->Command );
124 msi_free( verb->Argument );
125 msi_free( verb );
128 msi_free( ext->Extension );
129 msi_free( ext->ProgIDText );
130 msi_free( ext );
133 static void free_assembly( MSIASSEMBLY *assembly )
135 msi_free( assembly->feature );
136 msi_free( assembly->manifest );
137 msi_free( assembly->application );
138 msi_free( assembly->display_name );
139 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
140 msi_free( assembly->tempdir );
141 msi_free( assembly );
144 void msi_free_action_script( MSIPACKAGE *package, UINT script )
146 UINT i;
147 for (i = 0; i < package->script->ActionCount[script]; i++)
148 msi_free( package->script->Actions[script][i] );
150 msi_free( package->script->Actions[script] );
151 package->script->Actions[script] = NULL;
152 package->script->ActionCount[script] = 0;
155 static void free_package_structures( MSIPACKAGE *package )
157 INT i;
158 struct list *item, *cursor;
160 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
162 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
163 list_remove( &feature->entry );
164 free_feature( feature );
167 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
169 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
170 list_remove( &folder->entry );
171 free_folder( folder );
174 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
176 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
178 list_remove( &comp->entry );
179 msi_free( comp->Component );
180 msi_free( comp->ComponentId );
181 msi_free( comp->Directory );
182 msi_free( comp->Condition );
183 msi_free( comp->KeyPath );
184 msi_free( comp->FullKeypath );
185 if (comp->assembly) free_assembly( comp->assembly );
186 msi_free( comp );
189 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
191 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
193 list_remove( &file->entry );
194 msi_free( file->File );
195 msi_free( file->FileName );
196 msi_free( file->ShortName );
197 msi_free( file->LongName );
198 msi_free( file->Version );
199 msi_free( file->Language );
200 msi_free( file->TargetPath );
201 msi_free( file );
204 /* clean up extension, progid, class and verb structures */
205 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
207 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
209 list_remove( &cls->entry );
210 msi_free( cls->clsid );
211 msi_free( cls->Context );
212 msi_free( cls->Description );
213 msi_free( cls->FileTypeMask );
214 msi_free( cls->IconPath );
215 msi_free( cls->DefInprocHandler );
216 msi_free( cls->DefInprocHandler32 );
217 msi_free( cls->Argument );
218 msi_free( cls->ProgIDText );
219 msi_free( cls );
222 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
224 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
226 list_remove( &ext->entry );
227 free_extension( ext );
230 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
232 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
234 list_remove( &progid->entry );
235 msi_free( progid->ProgID );
236 msi_free( progid->Description );
237 msi_free( progid->IconPath );
238 msi_free( progid );
241 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
243 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
245 list_remove( &mt->entry );
246 msi_free( mt->suffix );
247 msi_free( mt->clsid );
248 msi_free( mt->ContentType );
249 msi_free( mt );
252 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
254 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
256 list_remove( &appid->entry );
257 msi_free( appid->AppID );
258 msi_free( appid->RemoteServerName );
259 msi_free( appid->LocalServer );
260 msi_free( appid->ServiceParameters );
261 msi_free( appid->DllSurrogate );
262 msi_free( appid );
265 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
267 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
269 list_remove( &info->entry );
270 msi_free( info->value );
271 msi_free( info );
274 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
276 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
278 list_remove( &info->entry );
279 msi_free( info->volume_label );
280 msi_free( info->disk_prompt );
281 msi_free( info );
284 if (package->script)
286 for (i = 0; i < SCRIPT_MAX; i++)
287 msi_free_action_script( package, i );
289 for (i = 0; i < package->script->UniqueActionsCount; i++)
290 msi_free( package->script->UniqueActions[i] );
292 msi_free( package->script->UniqueActions );
293 msi_free( package->script );
296 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
298 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
300 list_remove( &binary->entry );
301 if (binary->module)
302 FreeLibrary( binary->module );
303 if (!DeleteFileW( binary->tmpfile ))
304 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
305 msi_free( binary->source );
306 msi_free( binary->tmpfile );
307 msi_free( binary );
310 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
312 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
314 list_remove( &cab->entry );
315 IStorage_Release( cab->storage );
316 msi_free( cab->stream );
317 msi_free( cab );
320 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
322 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
324 list_remove( &patch->entry );
325 if (patch->delete_on_close && !DeleteFileW( patch->localfile ))
327 ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError());
329 msi_free_patchinfo( patch );
332 msi_free( package->BaseURL );
333 msi_free( package->PackagePath );
334 msi_free( package->ProductCode );
335 msi_free( package->ActionFormat );
336 msi_free( package->LastAction );
337 msi_free( package->langids );
339 remove_tracked_tempfiles(package);
341 /* cleanup control event subscriptions */
342 ControlEvent_CleanupSubscriptions( package );
345 static void MSI_FreePackage( MSIOBJECTHDR *arg)
347 MSIPACKAGE *package = (MSIPACKAGE *)arg;
349 msi_destroy_assembly_caches( package );
351 if( package->dialog )
352 msi_dialog_destroy( package->dialog );
354 msiobj_release( &package->db->hdr );
355 free_package_structures(package);
356 CloseHandle( package->log_file );
358 if (package->delete_on_close) DeleteFileW( package->localfile );
359 msi_free( package->localfile );
362 static UINT create_temp_property_table(MSIPACKAGE *package)
364 static const WCHAR query[] = {
365 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
366 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
367 '`','_','P','r','o','p','e','r','t','y','`',' ',
368 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
369 'T','E','M','P','O','R','A','R','Y',',',' ',
370 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
371 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
372 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
373 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
374 MSIQUERY *view;
375 UINT rc;
377 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
378 if (rc != ERROR_SUCCESS)
379 return rc;
381 rc = MSI_ViewExecute(view, 0);
382 MSI_ViewClose(view);
383 msiobj_release(&view->hdr);
384 return rc;
387 UINT msi_clone_properties(MSIPACKAGE *package)
389 static const WCHAR query_select[] = {
390 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
391 '`','P','r','o','p','e','r','t','y','`',0};
392 static const WCHAR query_insert[] = {
393 'I','N','S','E','R','T',' ','I','N','T','O',' ',
394 '`','_','P','r','o','p','e','r','t','y','`',' ',
395 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
396 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
397 static const WCHAR query_update[] = {
398 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
399 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
400 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
401 MSIQUERY *view_select;
402 UINT rc;
404 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
405 if (rc != ERROR_SUCCESS)
406 return rc;
408 rc = MSI_ViewExecute( view_select, 0 );
409 if (rc != ERROR_SUCCESS)
411 MSI_ViewClose( view_select );
412 msiobj_release( &view_select->hdr );
413 return rc;
416 while (1)
418 MSIQUERY *view_insert, *view_update;
419 MSIRECORD *rec_select;
421 rc = MSI_ViewFetch( view_select, &rec_select );
422 if (rc != ERROR_SUCCESS)
423 break;
425 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
426 if (rc != ERROR_SUCCESS)
428 msiobj_release( &rec_select->hdr );
429 continue;
432 rc = MSI_ViewExecute( view_insert, rec_select );
433 MSI_ViewClose( view_insert );
434 msiobj_release( &view_insert->hdr );
435 if (rc != ERROR_SUCCESS)
437 MSIRECORD *rec_update;
439 TRACE("insert failed, trying update\n");
441 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
442 if (rc != ERROR_SUCCESS)
444 WARN("open view failed %u\n", rc);
445 msiobj_release( &rec_select->hdr );
446 continue;
449 rec_update = MSI_CreateRecord( 2 );
450 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
451 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
452 rc = MSI_ViewExecute( view_update, rec_update );
453 if (rc != ERROR_SUCCESS)
454 WARN("update failed %u\n", rc);
456 MSI_ViewClose( view_update );
457 msiobj_release( &view_update->hdr );
458 msiobj_release( &rec_update->hdr );
461 msiobj_release( &rec_select->hdr );
464 MSI_ViewClose( view_select );
465 msiobj_release( &view_select->hdr );
466 return rc;
470 * set_installed_prop
472 * Sets the "Installed" property to indicate that
473 * the product is installed for the current user.
475 static UINT set_installed_prop( MSIPACKAGE *package )
477 HKEY hkey;
478 UINT r;
480 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
482 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
483 if (r == ERROR_SUCCESS)
485 RegCloseKey( hkey );
486 msi_set_property( package->db, szInstalled, szOne, -1 );
488 return r;
491 static UINT set_user_sid_prop( MSIPACKAGE *package )
493 SID_NAME_USE use;
494 LPWSTR user_name;
495 LPWSTR sid_str = NULL, dom = NULL;
496 DWORD size, dom_size;
497 PSID psid = NULL;
498 UINT r = ERROR_FUNCTION_FAILED;
500 size = 0;
501 GetUserNameW( NULL, &size );
503 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
504 if (!user_name)
505 return ERROR_OUTOFMEMORY;
507 if (!GetUserNameW( user_name, &size ))
508 goto done;
510 size = 0;
511 dom_size = 0;
512 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
514 psid = msi_alloc( size );
515 dom = msi_alloc( dom_size*sizeof (WCHAR) );
516 if (!psid || !dom)
518 r = ERROR_OUTOFMEMORY;
519 goto done;
522 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
523 goto done;
525 if (!ConvertSidToStringSidW( psid, &sid_str ))
526 goto done;
528 r = msi_set_property( package->db, szUserSID, sid_str, -1 );
530 done:
531 LocalFree( sid_str );
532 msi_free( dom );
533 msi_free( psid );
534 msi_free( user_name );
536 return r;
539 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
541 HKEY netsetup;
542 LONG res;
543 LPWSTR file = NULL;
544 DWORD index = 0, size;
545 WCHAR ver[MAX_PATH];
546 WCHAR name[MAX_PATH];
547 WCHAR windir[MAX_PATH];
549 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
550 static const WCHAR sub[] = {
551 'S','o','f','t','w','a','r','e','\\',
552 'M','i','c','r','o','s','o','f','t','\\',
553 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
554 'N','D','P',0
556 static const WCHAR subdir[] = {
557 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
558 'F','r','a','m','e','w','o','r','k','\\',0
561 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
562 if (res != ERROR_SUCCESS)
563 return NULL;
565 GetWindowsDirectoryW(windir, MAX_PATH);
567 ver[0] = '\0';
568 size = MAX_PATH;
569 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
571 index++;
573 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
574 if (strcmpW( ver, name ) < 0)
576 LPWSTR check;
577 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
578 check = msi_alloc(size * sizeof(WCHAR));
580 if (!check)
582 msi_free(file);
583 return NULL;
586 lstrcpyW(check, windir);
587 lstrcatW(check, szBackSlash);
588 lstrcatW(check, subdir);
589 lstrcatW(check, name);
590 lstrcatW(check, szBackSlash);
591 lstrcatW(check, fusion);
593 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
595 msi_free(file);
596 file = check;
597 lstrcpyW(ver, name);
599 else
600 msi_free(check);
604 RegCloseKey(netsetup);
605 return file;
608 typedef struct tagLANGANDCODEPAGE
610 WORD wLanguage;
611 WORD wCodePage;
612 } LANGANDCODEPAGE;
614 static void set_msi_assembly_prop(MSIPACKAGE *package)
616 UINT val_len;
617 DWORD size, handle;
618 LPVOID version = NULL;
619 WCHAR buf[MAX_PATH];
620 LPWSTR fusion, verstr;
621 LANGANDCODEPAGE *translate;
623 static const WCHAR netasm[] = {
624 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
626 static const WCHAR translation[] = {
627 '\\','V','a','r','F','i','l','e','I','n','f','o',
628 '\\','T','r','a','n','s','l','a','t','i','o','n',0
630 static const WCHAR verfmt[] = {
631 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
632 '\\','%','0','4','x','%','0','4','x',
633 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
636 fusion = get_fusion_filename(package);
637 if (!fusion)
638 return;
640 size = GetFileVersionInfoSizeW(fusion, &handle);
641 if (!size)
642 goto done;
644 version = msi_alloc(size);
645 if (!version)
646 goto done;
648 if (!GetFileVersionInfoW(fusion, handle, size, version))
649 goto done;
651 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
652 goto done;
654 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
656 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
657 goto done;
659 if (!val_len || !verstr)
660 goto done;
662 msi_set_property( package->db, netasm, verstr, -1 );
664 done:
665 msi_free(fusion);
666 msi_free(version);
669 static VOID set_installer_properties(MSIPACKAGE *package)
671 WCHAR *ptr;
672 OSVERSIONINFOEXW OSVersion;
673 MEMORYSTATUSEX msex;
674 DWORD verval, len;
675 WCHAR pth[MAX_PATH], verstr[11], bufstr[22];
676 HDC dc;
677 HKEY hkey;
678 LPWSTR username, companyname;
679 SYSTEM_INFO sys_info;
680 SYSTEMTIME systemtime;
681 LANGID langid;
683 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
684 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
685 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
686 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
687 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
688 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
689 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
690 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
691 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
692 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
693 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
694 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
695 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
696 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
697 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
698 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
699 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
700 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
701 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
702 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
703 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
704 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
705 static const WCHAR szFormat[] = {'%','u',0};
706 static const WCHAR szFormat2[] = {'%','u','.','%','u',0};
707 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
708 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
709 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
710 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
711 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
712 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
713 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
714 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
715 static const WCHAR szIntFormat[] = {'%','d',0};
716 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
717 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
718 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
719 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
720 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 };
721 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
722 static const WCHAR szUserInfo[] = {
723 'S','O','F','T','W','A','R','E','\\',
724 'M','i','c','r','o','s','o','f','t','\\',
725 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
726 'U','s','e','r',' ','I','n','f','o',0
728 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
729 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
730 static const WCHAR szCurrentVersion[] = {
731 'S','O','F','T','W','A','R','E','\\',
732 'M','i','c','r','o','s','o','f','t','\\',
733 'W','i','n','d','o','w','s',' ','N','T','\\',
734 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
736 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
737 static const WCHAR szRegisteredOrganization[] = {
738 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
740 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
741 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
742 static const WCHAR szDate[] = {'D','a','t','e',0};
743 static const WCHAR szTime[] = {'T','i','m','e',0};
744 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
745 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
746 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
747 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
748 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
749 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
750 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
751 static const WCHAR szComputerName[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
754 * Other things that probably should be set:
756 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
757 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
760 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
761 strcatW(pth, szBackSlash);
762 msi_set_property( package->db, szCommonAppDataFolder, pth, -1 );
764 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
765 strcatW(pth, szBackSlash);
766 msi_set_property( package->db, szFavoritesFolder, pth, -1 );
768 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
769 strcatW(pth, szBackSlash);
770 msi_set_property( package->db, szFontsFolder, pth, -1 );
772 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
773 strcatW(pth, szBackSlash);
774 msi_set_property( package->db, szSendToFolder, pth, -1 );
776 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
777 strcatW(pth, szBackSlash);
778 msi_set_property( package->db, szStartMenuFolder, pth, -1 );
780 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
781 strcatW(pth, szBackSlash);
782 msi_set_property( package->db, szStartupFolder, pth, -1 );
784 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
785 strcatW(pth, szBackSlash);
786 msi_set_property( package->db, szTemplateFolder, pth, -1 );
788 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
789 strcatW(pth, szBackSlash);
790 msi_set_property( package->db, szDesktopFolder, pth, -1 );
792 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
793 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
794 strcatW(pth, szBackSlash);
795 msi_set_property( package->db, szProgramMenuFolder, pth, -1 );
797 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
798 strcatW(pth, szBackSlash);
799 msi_set_property( package->db, szAdminToolsFolder, pth, -1 );
801 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
802 strcatW(pth, szBackSlash);
803 msi_set_property( package->db, szAppDataFolder, pth, -1 );
805 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
806 strcatW(pth, szBackSlash);
807 msi_set_property( package->db, szSystemFolder, pth, -1 );
808 msi_set_property( package->db, szSystem16Folder, pth, -1 );
810 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
811 strcatW(pth, szBackSlash);
812 msi_set_property( package->db, szLocalAppDataFolder, pth, -1 );
814 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
815 strcatW(pth, szBackSlash);
816 msi_set_property( package->db, szMyPicturesFolder, pth, -1 );
818 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
819 strcatW(pth, szBackSlash);
820 msi_set_property( package->db, szPersonalFolder, pth, -1 );
822 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
823 strcatW(pth, szBackSlash);
824 msi_set_property( package->db, szWindowsFolder, pth, -1 );
826 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
827 strcatW(pth, szBackSlash);
828 msi_set_property( package->db, szPrintHoodFolder, pth, -1 );
830 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
831 strcatW(pth, szBackSlash);
832 msi_set_property( package->db, szNetHoodFolder, pth, -1 );
834 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
835 strcatW(pth, szBackSlash);
836 msi_set_property( package->db, szRecentFolder, pth, -1 );
838 /* Physical Memory is specified in MB. Using total amount. */
839 msex.dwLength = sizeof(msex);
840 GlobalMemoryStatusEx( &msex );
841 len = sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
842 msi_set_property( package->db, szPhysicalMemory, bufstr, len );
844 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
845 ptr = strchrW(pth,'\\');
846 if (ptr) *(ptr + 1) = 0;
847 msi_set_property( package->db, szWindowsVolume, pth, -1 );
849 len = GetTempPathW(MAX_PATH, pth);
850 msi_set_property( package->db, szTempFolder, pth, len );
852 /* in a wine environment the user is always admin and privileged */
853 msi_set_property( package->db, szAdminUser, szOne, -1 );
854 msi_set_property( package->db, szPrivileged, szOne, -1 );
856 /* set the os things */
857 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
858 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
859 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
860 len = sprintfW( verstr, szFormat, verval );
861 switch (OSVersion.dwPlatformId)
863 case VER_PLATFORM_WIN32_WINDOWS:
864 msi_set_property( package->db, szVersion9x, verstr, len );
865 break;
866 case VER_PLATFORM_WIN32_NT:
867 msi_set_property( package->db, szVersionNT, verstr, len );
868 len = sprintfW( verstr, szFormat,OSVersion.wProductType );
869 msi_set_property( package->db, szMsiNTProductType, verstr, len );
870 break;
872 len = sprintfW( verstr, szFormat, OSVersion.dwBuildNumber );
873 msi_set_property( package->db, szWindowsBuild, verstr, len );
874 len = sprintfW( verstr, szFormat, OSVersion.wServicePackMajor );
875 msi_set_property( package->db, szServicePackLevel, verstr, len );
877 len = sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION );
878 msi_set_property( package->db, szVersionMsi, bufstr, len );
879 len = sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100 );
880 msi_set_property( package->db, szVersionDatabase, bufstr, len );
882 GetNativeSystemInfo( &sys_info );
883 len = sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
884 msi_set_property( package->db, szIntel, bufstr, len );
885 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
887 GetSystemDirectoryW( pth, MAX_PATH );
888 PathAddBackslashW( pth );
889 msi_set_property( package->db, szSystemFolder, pth, -1 );
891 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
892 PathAddBackslashW( pth );
893 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
895 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
896 PathAddBackslashW( pth );
897 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
899 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
901 msi_set_property( package->db, szMsiAMD64, bufstr, -1 );
902 msi_set_property( package->db, szMsix64, bufstr, -1 );
903 msi_set_property( package->db, szVersionNT64, verstr, -1 );
905 GetSystemDirectoryW( pth, MAX_PATH );
906 PathAddBackslashW( pth );
907 msi_set_property( package->db, szSystem64Folder, pth, -1 );
909 GetSystemWow64DirectoryW( pth, MAX_PATH );
910 PathAddBackslashW( pth );
911 msi_set_property( package->db, szSystemFolder, pth, -1 );
913 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
914 PathAddBackslashW( pth );
915 msi_set_property( package->db, szProgramFiles64Folder, pth, -1 );
917 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
918 PathAddBackslashW( pth );
919 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
921 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
922 PathAddBackslashW( pth );
923 msi_set_property( package->db, szCommonFiles64Folder, pth, -1 );
925 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
926 PathAddBackslashW( pth );
927 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
930 /* Screen properties. */
931 dc = GetDC(0);
932 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, HORZRES) );
933 msi_set_property( package->db, szScreenX, bufstr, len );
934 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, VERTRES) );
935 msi_set_property( package->db, szScreenY, bufstr, len );
936 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, BITSPIXEL) );
937 msi_set_property( package->db, szColorBits, bufstr, len );
938 ReleaseDC(0, dc);
940 /* USERNAME and COMPANYNAME */
941 username = msi_dup_property( package->db, szUSERNAME );
942 companyname = msi_dup_property( package->db, szCOMPANYNAME );
944 if ((!username || !companyname) &&
945 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
947 if (!username &&
948 (username = msi_reg_get_val_str( hkey, szDefName )))
949 msi_set_property( package->db, szUSERNAME, username, -1 );
950 if (!companyname &&
951 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
952 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
953 CloseHandle( hkey );
955 if ((!username || !companyname) &&
956 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
958 if (!username &&
959 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
960 msi_set_property( package->db, szUSERNAME, username, -1 );
961 if (!companyname &&
962 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
963 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
964 CloseHandle( hkey );
966 msi_free( username );
967 msi_free( companyname );
969 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
970 ERR("Failed to set the UserSID property\n");
972 /* Date and time properties */
973 GetSystemTime( &systemtime );
974 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
975 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
976 msi_set_property( package->db, szDate, bufstr, -1 );
977 else
978 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
980 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
981 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
982 &systemtime, NULL, bufstr,
983 sizeof(bufstr)/sizeof(bufstr[0]) ))
984 msi_set_property( package->db, szTime, bufstr, -1 );
985 else
986 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
988 set_msi_assembly_prop( package );
990 langid = GetUserDefaultLangID();
991 len = sprintfW( bufstr, szIntFormat, langid );
992 msi_set_property( package->db, szUserLanguageID, bufstr, len );
994 langid = GetSystemDefaultLangID();
995 len = sprintfW( bufstr, szIntFormat, langid );
996 msi_set_property( package->db, szSystemLangID, bufstr, len );
998 len = sprintfW( bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode) );
999 msi_set_property( package->db, szProductState, bufstr, len );
1001 len = 0;
1002 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1004 WCHAR *username;
1005 if ((username = msi_alloc( len * sizeof(WCHAR) )))
1007 if (GetUserNameW( username, &len ))
1008 msi_set_property( package->db, szLogonUser, username, len - 1 );
1009 msi_free( username );
1012 len = 0;
1013 if (!GetComputerNameW( NULL, &len ) && GetLastError() == ERROR_BUFFER_OVERFLOW)
1015 WCHAR *computername;
1016 if ((computername = msi_alloc( len * sizeof(WCHAR) )))
1018 if (GetComputerNameW( computername, &len ))
1019 msi_set_property( package->db, szComputerName, computername, len - 1 );
1020 msi_free( computername );
1025 static UINT msi_load_summary_properties( MSIPACKAGE *package )
1027 UINT rc;
1028 MSIHANDLE suminfo;
1029 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
1030 INT count;
1031 DWORD len;
1032 LPWSTR package_code;
1033 static const WCHAR szPackageCode[] = {
1034 'P','a','c','k','a','g','e','C','o','d','e',0};
1036 if (!hdb) {
1037 ERR("Unable to allocate handle\n");
1038 return ERROR_OUTOFMEMORY;
1041 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1042 MsiCloseHandle(hdb);
1043 if (rc != ERROR_SUCCESS)
1045 ERR("Unable to open Summary Information\n");
1046 return rc;
1049 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1050 &count, NULL, NULL, NULL );
1051 if (rc != ERROR_SUCCESS)
1053 WARN("Unable to query page count: %d\n", rc);
1054 goto done;
1057 /* load package code property */
1058 len = 0;
1059 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1060 NULL, NULL, NULL, &len );
1061 if (rc != ERROR_MORE_DATA)
1063 WARN("Unable to query revision number: %d\n", rc);
1064 rc = ERROR_FUNCTION_FAILED;
1065 goto done;
1068 len++;
1069 package_code = msi_alloc( len * sizeof(WCHAR) );
1070 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1071 NULL, NULL, package_code, &len );
1072 if (rc != ERROR_SUCCESS)
1074 WARN("Unable to query rev number: %d\n", rc);
1075 goto done;
1078 msi_set_property( package->db, szPackageCode, package_code, len );
1079 msi_free( package_code );
1081 /* load package attributes */
1082 count = 0;
1083 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1084 &count, NULL, NULL, NULL );
1085 package->WordCount = count;
1087 done:
1088 MsiCloseHandle(suminfo);
1089 return rc;
1092 static MSIPACKAGE *msi_alloc_package( void )
1094 MSIPACKAGE *package;
1096 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1097 MSI_FreePackage );
1098 if( package )
1100 list_init( &package->components );
1101 list_init( &package->features );
1102 list_init( &package->files );
1103 list_init( &package->filepatches );
1104 list_init( &package->tempfiles );
1105 list_init( &package->folders );
1106 list_init( &package->subscriptions );
1107 list_init( &package->appids );
1108 list_init( &package->classes );
1109 list_init( &package->mimes );
1110 list_init( &package->extensions );
1111 list_init( &package->progids );
1112 list_init( &package->RunningActions );
1113 list_init( &package->sourcelist_info );
1114 list_init( &package->sourcelist_media );
1115 list_init( &package->patches );
1116 list_init( &package->binaries );
1117 list_init( &package->cabinet_streams );
1120 return package;
1123 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1125 BYTE *data;
1126 UINT r, sz;
1128 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1130 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1131 if (r != ERROR_SUCCESS)
1132 return r;
1134 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1136 msi_free(data);
1137 return r;
1140 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1142 /* FIXME: this should depend on the user's privileges */
1143 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1145 TRACE("resetting ALLUSERS property from 2 to 1\n");
1146 msi_set_property( package->db, szAllUsers, szOne, -1 );
1148 msi_set_property( package->db, szAdminUser, szOne, -1 );
1151 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1153 static const WCHAR fmtW[] = {'%','u',0};
1154 MSIPACKAGE *package;
1155 WCHAR uilevel[11];
1156 int len;
1157 UINT r;
1159 TRACE("%p\n", db);
1161 package = msi_alloc_package();
1162 if (package)
1164 msiobj_addref( &db->hdr );
1165 package->db = db;
1167 package->WordCount = 0;
1168 package->PackagePath = strdupW( db->path );
1169 package->BaseURL = strdupW( base_url );
1171 create_temp_property_table( package );
1172 msi_clone_properties( package );
1173 msi_adjust_privilege_properties( package );
1175 package->ProductCode = msi_dup_property( package->db, szProductCode );
1176 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1178 set_installed_prop( package );
1179 set_installer_properties( package );
1181 package->ui_level = gUILevel;
1182 len = sprintfW( uilevel, fmtW, gUILevel & INSTALLUILEVEL_MASK );
1183 msi_set_property( package->db, szUILevel, uilevel, len );
1185 r = msi_load_summary_properties( package );
1186 if (r != ERROR_SUCCESS)
1188 msiobj_release( &package->hdr );
1189 return NULL;
1192 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1193 msi_load_admin_properties( package );
1195 package->log_file = INVALID_HANDLE_VALUE;
1197 return package;
1200 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1202 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1203 DWORD size = 0;
1204 HRESULT hr;
1206 /* call will always fail, because size is 0,
1207 * but will return ERROR_FILE_NOT_FOUND first
1208 * if the file doesn't exist
1210 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1211 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1213 cache_entry = msi_alloc( size );
1214 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1216 UINT error = GetLastError();
1217 msi_free( cache_entry );
1218 return error;
1221 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1222 msi_free( cache_entry );
1223 return ERROR_SUCCESS;
1226 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1227 if ( FAILED(hr) )
1229 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1230 return ERROR_FUNCTION_FAILED;
1233 return ERROR_SUCCESS;
1236 UINT msi_create_empty_local_file( LPWSTR path, LPCWSTR suffix )
1238 static const WCHAR szInstaller[] = {
1239 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1240 static const WCHAR fmt[] = {'%','x',0};
1241 DWORD time, len, i, offset;
1242 HANDLE handle;
1244 time = GetTickCount();
1245 GetWindowsDirectoryW( path, MAX_PATH );
1246 strcatW( path, szInstaller );
1247 CreateDirectoryW( path, NULL );
1249 len = strlenW(path);
1250 for (i = 0; i < 0x10000; i++)
1252 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1253 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1254 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1255 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1256 if (handle != INVALID_HANDLE_VALUE)
1258 CloseHandle(handle);
1259 break;
1261 if (GetLastError() != ERROR_FILE_EXISTS &&
1262 GetLastError() != ERROR_SHARING_VIOLATION)
1263 return ERROR_FUNCTION_FAILED;
1266 return ERROR_SUCCESS;
1269 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1271 WCHAR *template, *p, *q;
1272 DWORD i, count;
1274 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1275 TRACE("version: %d\n", package->version);
1277 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1278 if (!template)
1279 return ERROR_SUCCESS; /* native accepts missing template property */
1281 TRACE("template: %s\n", debugstr_w(template));
1283 p = strchrW( template, ';' );
1284 if (!p)
1286 WARN("invalid template string %s\n", debugstr_w(template));
1287 msi_free( template );
1288 return ERROR_PATCH_PACKAGE_INVALID;
1290 *p = 0;
1291 if ((q = strchrW( template, ',' ))) *q = 0;
1292 if (!template[0] || !strcmpW( template, szIntel ))
1293 package->platform = PLATFORM_INTEL;
1294 else if (!strcmpW( template, szIntel64 ))
1295 package->platform = PLATFORM_INTEL64;
1296 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1297 package->platform = PLATFORM_X64;
1298 else if (!strcmpW( template, szARM ))
1299 package->platform = PLATFORM_ARM;
1300 else
1302 WARN("unknown platform %s\n", debugstr_w(template));
1303 msi_free( template );
1304 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1306 p++;
1307 if (!*p)
1309 msi_free( template );
1310 return ERROR_SUCCESS;
1312 count = 1;
1313 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1315 package->langids = msi_alloc( count * sizeof(LANGID) );
1316 if (!package->langids)
1318 msi_free( template );
1319 return ERROR_OUTOFMEMORY;
1322 i = 0;
1323 while (*p)
1325 q = strchrW( p, ',' );
1326 if (q) *q = 0;
1327 package->langids[i] = atoiW( p );
1328 if (!q) break;
1329 p = q + 1;
1330 i++;
1332 package->num_langids = i + 1;
1334 msi_free( template );
1335 return ERROR_SUCCESS;
1338 static UINT validate_package( MSIPACKAGE *package )
1340 UINT i;
1342 if (package->platform == PLATFORM_INTEL64)
1343 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1344 #ifndef __arm__
1345 if (package->platform == PLATFORM_ARM)
1346 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1347 #endif
1348 if (package->platform == PLATFORM_X64)
1350 if (!is_64bit && !is_wow64)
1351 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1352 if (package->version < 200)
1353 return ERROR_INSTALL_PACKAGE_INVALID;
1355 if (!package->num_langids)
1357 return ERROR_SUCCESS;
1359 for (i = 0; i < package->num_langids; i++)
1361 LANGID langid = package->langids[i];
1363 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1365 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1367 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1369 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1371 if (IsValidLocale( langid, LCID_INSTALLED ))
1372 return ERROR_SUCCESS;
1374 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1377 int msi_track_tempfile( MSIPACKAGE *package, const WCHAR *path )
1379 MSITEMPFILE *temp;
1381 TRACE("%s\n", debugstr_w(path));
1383 LIST_FOR_EACH_ENTRY( temp, &package->tempfiles, MSITEMPFILE, entry )
1385 if (!strcmpW( path, temp->Path )) return 0;
1387 if (!(temp = msi_alloc_zero( sizeof (MSITEMPFILE) ))) return -1;
1388 list_add_head( &package->tempfiles, &temp->entry );
1389 temp->Path = strdupW( path );
1390 return 0;
1393 static WCHAR *get_product_code( MSIDATABASE *db )
1395 static const WCHAR query[] = {
1396 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1397 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1398 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1399 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1400 MSIQUERY *view;
1401 MSIRECORD *rec;
1402 WCHAR *ret = NULL;
1404 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1406 return NULL;
1408 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1410 MSI_ViewClose( view );
1411 msiobj_release( &view->hdr );
1412 return NULL;
1414 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1416 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1417 msiobj_release( &rec->hdr );
1419 MSI_ViewClose( view );
1420 msiobj_release( &view->hdr );
1421 return ret;
1424 static UINT get_registered_local_package( const WCHAR *product, const WCHAR *package, WCHAR *localfile )
1426 MSIINSTALLCONTEXT context;
1427 HKEY product_key, props_key;
1428 WCHAR *registered_package = NULL, unsquashed[GUID_SIZE];
1429 UINT r;
1431 r = msi_locate_product( product, &context );
1432 if (r != ERROR_SUCCESS)
1433 return r;
1435 r = MSIREG_OpenProductKey( product, NULL, context, &product_key, FALSE );
1436 if (r != ERROR_SUCCESS)
1437 return r;
1439 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1440 if (r != ERROR_SUCCESS)
1442 RegCloseKey( product_key );
1443 return r;
1445 r = ERROR_FUNCTION_FAILED;
1446 registered_package = msi_reg_get_val_str( product_key, INSTALLPROPERTY_PACKAGECODEW );
1447 if (!registered_package)
1448 goto done;
1450 unsquash_guid( registered_package, unsquashed );
1451 if (!strcmpiW( package, unsquashed ))
1453 WCHAR *filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1454 if (!filename)
1455 goto done;
1457 strcpyW( localfile, filename );
1458 msi_free( filename );
1459 r = ERROR_SUCCESS;
1461 done:
1462 msi_free( registered_package );
1463 RegCloseKey( props_key );
1464 RegCloseKey( product_key );
1465 return r;
1468 static WCHAR *get_package_code( MSIDATABASE *db )
1470 WCHAR *ret;
1471 MSISUMMARYINFO *si;
1473 if (!(si = MSI_GetSummaryInformationW( db->storage, 0 )))
1475 WARN("failed to load summary info\n");
1476 return NULL;
1478 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1479 msiobj_release( &si->hdr );
1480 return ret;
1483 static UINT get_local_package( const WCHAR *filename, WCHAR *localfile )
1485 WCHAR *product_code, *package_code;
1486 MSIDATABASE *db;
1487 UINT r;
1489 if ((r = MSI_OpenDatabaseW( filename, MSIDBOPEN_READONLY, &db )) != ERROR_SUCCESS)
1491 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1492 return ERROR_FILE_NOT_FOUND;
1493 return r;
1495 if (!(product_code = get_product_code( db )))
1497 msiobj_release( &db->hdr );
1498 return ERROR_INSTALL_PACKAGE_INVALID;
1500 if (!(package_code = get_package_code( db )))
1502 msi_free( product_code );
1503 msiobj_release( &db->hdr );
1504 return ERROR_INSTALL_PACKAGE_INVALID;
1506 r = get_registered_local_package( product_code, package_code, localfile );
1507 msi_free( package_code );
1508 msi_free( product_code );
1509 msiobj_release( &db->hdr );
1510 return r;
1513 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1515 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1516 MSIDATABASE *db;
1517 MSIPACKAGE *package;
1518 MSIHANDLE handle;
1519 LPWSTR ptr, base_url = NULL;
1520 UINT r;
1521 WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
1522 LPCWSTR file = szPackage;
1523 DWORD index = 0;
1524 MSISUMMARYINFO *si;
1525 BOOL delete_on_close = FALSE;
1527 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1529 localfile[0] = 0;
1530 if( szPackage[0] == '#' )
1532 handle = atoiW(&szPackage[1]);
1533 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1534 if( !db )
1536 IWineMsiRemoteDatabase *remote_database;
1538 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1539 if ( !remote_database )
1540 return ERROR_INVALID_HANDLE;
1542 IWineMsiRemoteDatabase_Release( remote_database );
1543 WARN("MsiOpenPackage not allowed during a custom action!\n");
1545 return ERROR_FUNCTION_FAILED;
1548 else
1550 if ( UrlIsW( szPackage, URLIS_URL ) )
1552 r = msi_download_file( szPackage, cachefile );
1553 if (r != ERROR_SUCCESS)
1554 return r;
1556 file = cachefile;
1558 base_url = strdupW( szPackage );
1559 if (!base_url)
1560 return ERROR_OUTOFMEMORY;
1562 ptr = strrchrW( base_url, '/' );
1563 if (ptr) *(ptr + 1) = '\0';
1565 r = get_local_package( file, localfile );
1566 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1568 r = msi_create_empty_local_file( localfile, dotmsi );
1569 if (r != ERROR_SUCCESS)
1571 msi_free ( base_url );
1572 return r;
1575 if (!CopyFileW( file, localfile, FALSE ))
1577 r = GetLastError();
1578 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1579 DeleteFileW( localfile );
1580 msi_free ( base_url );
1581 return r;
1583 delete_on_close = TRUE;
1585 TRACE("opening package %s\n", debugstr_w( localfile ));
1586 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1587 if (r != ERROR_SUCCESS)
1589 msi_free ( base_url );
1590 return r;
1593 package = MSI_CreatePackage( db, base_url );
1594 msi_free( base_url );
1595 msiobj_release( &db->hdr );
1596 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1597 package->localfile = strdupW( localfile );
1598 package->delete_on_close = delete_on_close;
1600 si = MSI_GetSummaryInformationW( db->storage, 0 );
1601 if (!si)
1603 WARN("failed to load summary info\n");
1604 msiobj_release( &package->hdr );
1605 return ERROR_INSTALL_PACKAGE_INVALID;
1607 r = msi_parse_summary( si, package );
1608 msiobj_release( &si->hdr );
1609 if (r != ERROR_SUCCESS)
1611 WARN("failed to parse summary info %u\n", r);
1612 msiobj_release( &package->hdr );
1613 return r;
1615 r = validate_package( package );
1616 if (r != ERROR_SUCCESS)
1618 msiobj_release( &package->hdr );
1619 return r;
1621 msi_set_property( package->db, szDatabase, db->path, -1 );
1623 if( UrlIsW( szPackage, URLIS_URL ) )
1624 msi_set_property( package->db, szOriginalDatabase, szPackage, -1 );
1625 else if( szPackage[0] == '#' )
1626 msi_set_property( package->db, szOriginalDatabase, db->path, -1 );
1627 else
1629 WCHAR fullpath[MAX_PATH];
1630 DWORD len = GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1631 msi_set_property( package->db, szOriginalDatabase, fullpath, len );
1633 msi_set_context( package );
1635 while (1)
1637 WCHAR patch_code[GUID_SIZE];
1638 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1639 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1640 if (r != ERROR_SUCCESS)
1641 break;
1643 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1645 r = msi_apply_registered_patch( package, patch_code );
1646 if (r != ERROR_SUCCESS)
1648 ERR("registered patch failed to apply %u\n", r);
1649 msiobj_release( &package->hdr );
1650 return r;
1652 index++;
1654 if (index)
1656 msi_clone_properties( package );
1657 msi_adjust_privilege_properties( package );
1659 if (gszLogFile)
1660 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1661 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1662 *pPackage = package;
1663 return ERROR_SUCCESS;
1666 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1668 MSIPACKAGE *package = NULL;
1669 UINT ret;
1671 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1673 if( !szPackage || !phPackage )
1674 return ERROR_INVALID_PARAMETER;
1676 if ( !*szPackage )
1678 FIXME("Should create an empty database and package\n");
1679 return ERROR_FUNCTION_FAILED;
1682 if( dwOptions )
1683 FIXME("dwOptions %08x not supported\n", dwOptions);
1685 ret = MSI_OpenPackageW( szPackage, &package );
1686 if( ret == ERROR_SUCCESS )
1688 *phPackage = alloc_msihandle( &package->hdr );
1689 if (! *phPackage)
1690 ret = ERROR_NOT_ENOUGH_MEMORY;
1691 msiobj_release( &package->hdr );
1694 return ret;
1697 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1699 return MsiOpenPackageExW( szPackage, 0, phPackage );
1702 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1704 LPWSTR szwPack = NULL;
1705 UINT ret;
1707 if( szPackage )
1709 szwPack = strdupAtoW( szPackage );
1710 if( !szwPack )
1711 return ERROR_OUTOFMEMORY;
1714 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1716 msi_free( szwPack );
1718 return ret;
1721 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1723 return MsiOpenPackageExA( szPackage, 0, phPackage );
1726 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1728 MSIPACKAGE *package;
1729 MSIHANDLE handle = 0;
1730 IUnknown *remote_unk;
1731 IWineMsiRemotePackage *remote_package;
1733 TRACE("(%d)\n",hInstall);
1735 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1736 if( package)
1738 handle = alloc_msihandle( &package->db->hdr );
1739 msiobj_release( &package->hdr );
1741 else if ((remote_unk = msi_get_remote(hInstall)))
1743 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1744 (LPVOID *)&remote_package) == S_OK)
1746 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1747 IWineMsiRemotePackage_Release(remote_package);
1749 else
1751 WARN("remote handle %d is not a package\n", hInstall);
1753 IUnknown_Release(remote_unk);
1756 return handle;
1759 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1761 static const WCHAR szActionData[] = {'A','c','t','i','o','n','D','a','t','a',0};
1762 static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1763 static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0};
1764 MSIRECORD *uirow;
1765 LPWSTR deformated, message;
1766 DWORD i, len, total_len, log_type = 0;
1767 INT rc = 0;
1768 char *msg;
1770 TRACE("%x\n", eMessageType);
1772 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_FATALEXIT)
1773 log_type |= INSTALLLOGMODE_FATALEXIT;
1774 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1775 log_type |= INSTALLLOGMODE_ERROR;
1776 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1777 log_type |= INSTALLLOGMODE_WARNING;
1778 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1779 log_type |= INSTALLLOGMODE_USER;
1780 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1781 log_type |= INSTALLLOGMODE_INFO;
1782 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE)
1783 log_type |= INSTALLLOGMODE_RESOLVESOURCE;
1784 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE)
1785 log_type |= INSTALLLOGMODE_OUTOFDISKSPACE;
1786 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1787 log_type |= INSTALLLOGMODE_COMMONDATA;
1788 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1789 log_type |= INSTALLLOGMODE_ACTIONSTART;
1790 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1791 log_type |= INSTALLLOGMODE_ACTIONDATA;
1792 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1793 log_type |= INSTALLLOGMODE_PROGRESS;
1794 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INITIALIZE)
1795 log_type |= INSTALLLOGMODE_INITIALIZE;
1796 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_TERMINATE)
1797 log_type |= INSTALLLOGMODE_TERMINATE;
1798 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_SHOWDIALOG)
1799 log_type |= INSTALLLOGMODE_SHOWDIALOG;
1801 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1803 static const WCHAR template_s[]=
1804 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1805 static const WCHAR format[] =
1806 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1807 WCHAR timet[0x100];
1808 LPCWSTR action_text, action;
1809 LPWSTR deformatted = NULL;
1811 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1813 action = MSI_RecordGetString(record, 1);
1814 action_text = MSI_RecordGetString(record, 2);
1816 if (!action || !action_text)
1817 return IDOK;
1819 deformat_string(package, action_text, &deformatted);
1821 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1822 if (deformatted)
1823 len += strlenW(deformatted);
1824 message = msi_alloc(len*sizeof(WCHAR));
1825 sprintfW(message, template_s, timet, action);
1826 if (deformatted)
1827 strcatW(message, deformatted);
1828 msi_free(deformatted);
1830 else
1832 static const WCHAR format[] = {'%','u',':',' ',0};
1833 UINT count = MSI_RecordGetFieldCount( record );
1834 WCHAR *p;
1836 total_len = 1;
1837 for (i = 1; i <= count; i++)
1839 len = 0;
1840 MSI_RecordGetStringW( record, i, NULL, &len );
1841 total_len += len + 13;
1843 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1844 if (!p) return ERROR_OUTOFMEMORY;
1846 for (i = 1; i <= count; i++)
1848 if (count > 1)
1850 len = sprintfW( p, format, i );
1851 total_len -= len;
1852 p += len;
1854 len = total_len;
1855 MSI_RecordGetStringW( record, i, p, &len );
1856 total_len -= len;
1857 p += len;
1858 if (count > 1 && total_len)
1860 *p++ = ' ';
1861 total_len--;
1864 p[0] = 0;
1867 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1868 gUIFilter, log_type, debugstr_w(message));
1870 /* convert it to ASCII */
1871 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1872 msg = msi_alloc( len );
1873 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1875 if (gUIHandlerW && (gUIFilter & log_type))
1877 rc = gUIHandlerW( gUIContext, eMessageType, message );
1879 else if (gUIHandlerA && (gUIFilter & log_type))
1881 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1883 else if (gUIHandlerRecord && (gUIFilter & log_type))
1885 MSIHANDLE rec = MsiCreateRecord( 1 );
1886 MsiRecordSetStringW( rec, 0, message );
1887 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1888 MsiCloseHandle( rec );
1891 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1892 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1894 DWORD written;
1895 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1896 WriteFile( package->log_file, "\n", 1, &written, NULL );
1898 msi_free( msg );
1899 msi_free( message );
1901 switch (eMessageType & 0xff000000)
1903 case INSTALLMESSAGE_ACTIONDATA:
1904 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1905 uirow = MSI_CreateRecord(1);
1906 MSI_RecordSetStringW(uirow, 1, deformated);
1907 msi_free(deformated);
1909 ControlEvent_FireSubscribedEvent(package, szActionData, uirow);
1910 msiobj_release(&uirow->hdr);
1912 if (package->action_progress_increment)
1914 uirow = MSI_CreateRecord(2);
1915 MSI_RecordSetInteger(uirow, 1, 2);
1916 MSI_RecordSetInteger(uirow, 2, package->action_progress_increment);
1917 ControlEvent_FireSubscribedEvent(package, szSetProgress, uirow);
1918 msiobj_release(&uirow->hdr);
1920 break;
1922 case INSTALLMESSAGE_ACTIONSTART:
1923 deformat_string(package, MSI_RecordGetString(record, 2), &deformated);
1924 uirow = MSI_CreateRecord(1);
1925 MSI_RecordSetStringW(uirow, 1, deformated);
1926 msi_free(deformated);
1928 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1930 msiobj_release(&uirow->hdr);
1931 break;
1933 case INSTALLMESSAGE_PROGRESS:
1934 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1935 break;
1938 return ERROR_SUCCESS;
1941 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1942 MSIHANDLE hRecord)
1944 UINT ret = ERROR_INVALID_HANDLE;
1945 MSIPACKAGE *package = NULL;
1946 MSIRECORD *record = NULL;
1948 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1949 if( !package )
1951 HRESULT hr;
1952 IWineMsiRemotePackage *remote_package;
1954 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1955 if (!remote_package)
1956 return ERROR_INVALID_HANDLE;
1958 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1960 IWineMsiRemotePackage_Release( remote_package );
1962 if (FAILED(hr))
1964 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1965 return HRESULT_CODE(hr);
1967 return ERROR_FUNCTION_FAILED;
1970 return ERROR_SUCCESS;
1973 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1974 if( !record )
1975 goto out;
1977 ret = MSI_ProcessMessage( package, eMessageType, record );
1979 out:
1980 msiobj_release( &package->hdr );
1981 if( record )
1982 msiobj_release( &record->hdr );
1984 return ret;
1987 /* property code */
1989 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1991 LPWSTR szwName = NULL, szwValue = NULL;
1992 UINT r = ERROR_OUTOFMEMORY;
1994 szwName = strdupAtoW( szName );
1995 if( szName && !szwName )
1996 goto end;
1998 szwValue = strdupAtoW( szValue );
1999 if( szValue && !szwValue )
2000 goto end;
2002 r = MsiSetPropertyW( hInstall, szwName, szwValue);
2004 end:
2005 msi_free( szwName );
2006 msi_free( szwValue );
2008 return r;
2011 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
2013 MSIFOLDER *folder;
2015 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
2017 if ( source )
2019 msi_free( folder->ResolvedSource );
2020 folder->ResolvedSource = NULL;
2022 else
2024 msi_free( folder->ResolvedTarget );
2025 folder->ResolvedTarget = NULL;
2030 UINT msi_set_property( MSIDATABASE *db, const WCHAR *name, const WCHAR *value, int len )
2032 static const WCHAR insert_query[] = {
2033 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2034 '`','_','P','r','o','p','e','r','t','y','`',' ',
2035 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2036 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2037 static const WCHAR update_query[] = {
2038 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2039 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2040 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2041 static const WCHAR delete_query[] = {
2042 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2043 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2044 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2045 MSIQUERY *view;
2046 MSIRECORD *row = NULL;
2047 DWORD sz = 0;
2048 WCHAR query[1024];
2049 UINT rc;
2051 TRACE("%p %s %s %d\n", db, debugstr_w(name), debugstr_wn(value, len), len);
2053 if (!name)
2054 return ERROR_INVALID_PARAMETER;
2056 /* this one is weird... */
2057 if (!name[0])
2058 return value ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2060 if (value && len < 0) len = strlenW( value );
2062 rc = msi_get_property( db, name, 0, &sz );
2063 if (!value || (!*value && !len))
2065 sprintfW( query, delete_query, name );
2067 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2069 sprintfW( query, update_query, name );
2070 row = MSI_CreateRecord(1);
2071 msi_record_set_string( row, 1, value, len );
2073 else
2075 strcpyW( query, insert_query );
2076 row = MSI_CreateRecord(2);
2077 msi_record_set_string( row, 1, name, -1 );
2078 msi_record_set_string( row, 2, value, len );
2081 rc = MSI_DatabaseOpenViewW(db, query, &view);
2082 if (rc == ERROR_SUCCESS)
2084 rc = MSI_ViewExecute(view, row);
2085 MSI_ViewClose(view);
2086 msiobj_release(&view->hdr);
2088 if (row) msiobj_release(&row->hdr);
2089 return rc;
2092 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2094 MSIPACKAGE *package;
2095 UINT ret;
2097 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2098 if( !package )
2100 HRESULT hr;
2101 BSTR name = NULL, value = NULL;
2102 IWineMsiRemotePackage *remote_package;
2104 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2105 if (!remote_package)
2106 return ERROR_INVALID_HANDLE;
2108 name = SysAllocString( szName );
2109 value = SysAllocString( szValue );
2110 if ((!name && szName) || (!value && szValue))
2112 SysFreeString( name );
2113 SysFreeString( value );
2114 IWineMsiRemotePackage_Release( remote_package );
2115 return ERROR_OUTOFMEMORY;
2118 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2120 SysFreeString( name );
2121 SysFreeString( value );
2122 IWineMsiRemotePackage_Release( remote_package );
2124 if (FAILED(hr))
2126 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2127 return HRESULT_CODE(hr);
2129 return ERROR_FUNCTION_FAILED;
2132 return ERROR_SUCCESS;
2135 ret = msi_set_property( package->db, szName, szValue, -1 );
2136 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2137 msi_reset_folders( package, TRUE );
2139 msiobj_release( &package->hdr );
2140 return ret;
2143 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2145 static const WCHAR query[]= {
2146 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2147 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2148 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2149 MSIRECORD *rec, *row = NULL;
2150 MSIQUERY *view;
2151 UINT r;
2153 if (!name || !*name)
2154 return NULL;
2156 rec = MSI_CreateRecord(1);
2157 if (!rec)
2158 return NULL;
2160 MSI_RecordSetStringW(rec, 1, name);
2162 r = MSI_DatabaseOpenViewW(db, query, &view);
2163 if (r == ERROR_SUCCESS)
2165 MSI_ViewExecute(view, rec);
2166 MSI_ViewFetch(view, &row);
2167 MSI_ViewClose(view);
2168 msiobj_release(&view->hdr);
2170 msiobj_release(&rec->hdr);
2171 return row;
2174 /* internal function, not compatible with MsiGetPropertyW */
2175 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2176 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2178 MSIRECORD *row;
2179 UINT rc = ERROR_FUNCTION_FAILED;
2181 row = msi_get_property_row( db, szName );
2183 if (*pchValueBuf > 0)
2184 szValueBuf[0] = 0;
2186 if (row)
2188 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2189 msiobj_release(&row->hdr);
2192 if (rc == ERROR_SUCCESS)
2193 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf, *pchValueBuf),
2194 debugstr_w(szName));
2195 else if (rc == ERROR_MORE_DATA)
2196 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2197 debugstr_w(szName));
2198 else
2200 *pchValueBuf = 0;
2201 TRACE("property %s not found\n", debugstr_w(szName));
2204 return rc;
2207 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2209 DWORD sz = 0;
2210 LPWSTR str;
2211 UINT r;
2213 r = msi_get_property(db, prop, NULL, &sz);
2214 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2215 return NULL;
2217 sz++;
2218 str = msi_alloc(sz * sizeof(WCHAR));
2219 r = msi_get_property(db, prop, str, &sz);
2220 if (r != ERROR_SUCCESS)
2222 msi_free(str);
2223 str = NULL;
2226 return str;
2229 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2231 LPWSTR str = msi_dup_property( db, prop );
2232 int val = str ? atoiW(str) : def;
2233 msi_free(str);
2234 return val;
2237 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2238 awstring *szValueBuf, LPDWORD pchValueBuf )
2240 MSIPACKAGE *package;
2241 MSIRECORD *row = NULL;
2242 UINT r = ERROR_FUNCTION_FAILED;
2243 LPCWSTR val = NULL;
2244 DWORD len = 0;
2246 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2247 szValueBuf->str.w, pchValueBuf );
2249 if (!name)
2250 return ERROR_INVALID_PARAMETER;
2252 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2253 if (!package)
2255 HRESULT hr;
2256 IWineMsiRemotePackage *remote_package;
2257 LPWSTR value = NULL;
2258 BSTR bname;
2260 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2261 if (!remote_package)
2262 return ERROR_INVALID_HANDLE;
2264 bname = SysAllocString( name );
2265 if (!bname)
2267 IWineMsiRemotePackage_Release( remote_package );
2268 return ERROR_OUTOFMEMORY;
2271 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2272 if (FAILED(hr))
2273 goto done;
2275 len++;
2276 value = msi_alloc(len * sizeof(WCHAR));
2277 if (!value)
2279 r = ERROR_OUTOFMEMORY;
2280 goto done;
2283 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, value, &len );
2284 if (FAILED(hr))
2285 goto done;
2287 r = msi_strcpy_to_awstring( value, len, szValueBuf, pchValueBuf );
2289 /* Bug required by Adobe installers */
2290 if (!szValueBuf->unicode && !szValueBuf->str.a)
2291 *pchValueBuf *= sizeof(WCHAR);
2293 done:
2294 IWineMsiRemotePackage_Release(remote_package);
2295 SysFreeString(bname);
2296 msi_free(value);
2298 if (FAILED(hr))
2300 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2301 return HRESULT_CODE(hr);
2303 return ERROR_FUNCTION_FAILED;
2306 return r;
2309 row = msi_get_property_row( package->db, name );
2310 if (row)
2311 val = msi_record_get_string( row, 1, (int *)&len );
2313 if (!val)
2314 val = szEmpty;
2316 r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
2318 if (row)
2319 msiobj_release( &row->hdr );
2320 msiobj_release( &package->hdr );
2322 return r;
2325 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2326 LPSTR szValueBuf, LPDWORD pchValueBuf )
2328 awstring val;
2329 LPWSTR name;
2330 UINT r;
2332 val.unicode = FALSE;
2333 val.str.a = szValueBuf;
2335 name = strdupAtoW( szName );
2336 if (szName && !name)
2337 return ERROR_OUTOFMEMORY;
2339 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2340 msi_free( name );
2341 return r;
2344 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2345 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2347 awstring val;
2349 val.unicode = TRUE;
2350 val.str.w = szValueBuf;
2352 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2355 typedef struct _msi_remote_package_impl {
2356 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2357 MSIHANDLE package;
2358 LONG refs;
2359 } msi_remote_package_impl;
2361 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2363 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2366 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2367 REFIID riid,LPVOID *ppobj)
2369 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2370 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2372 IWineMsiRemotePackage_AddRef( iface );
2373 *ppobj = iface;
2374 return S_OK;
2377 return E_NOINTERFACE;
2380 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2382 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2384 return InterlockedIncrement( &This->refs );
2387 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2389 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2390 ULONG r;
2392 r = InterlockedDecrement( &This->refs );
2393 if (r == 0)
2395 MsiCloseHandle( This->package );
2396 msi_free( This );
2398 return r;
2401 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2403 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2404 This->package = handle;
2405 return S_OK;
2408 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2410 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2411 IWineMsiRemoteDatabase *rdb = NULL;
2412 HRESULT hr;
2413 MSIHANDLE hdb;
2415 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2416 if (FAILED(hr) || !rdb)
2418 ERR("Failed to create remote database\n");
2419 return hr;
2422 hdb = MsiGetActiveDatabase(This->package);
2424 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2425 if (FAILED(hr))
2427 ERR("Failed to set the database handle\n");
2428 return hr;
2431 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2432 return S_OK;
2435 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value, DWORD *size )
2437 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2438 UINT r = MsiGetPropertyW(This->package, property, value, size);
2439 if (r != ERROR_SUCCESS) return HRESULT_FROM_WIN32(r);
2440 return S_OK;
2443 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2445 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2446 UINT r = MsiSetPropertyW(This->package, property, value);
2447 return HRESULT_FROM_WIN32(r);
2450 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2452 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2453 UINT r = MsiProcessMessage(This->package, message, record);
2454 return HRESULT_FROM_WIN32(r);
2457 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2459 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2460 UINT r = MsiDoActionW(This->package, action);
2461 return HRESULT_FROM_WIN32(r);
2464 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2466 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2467 UINT r = MsiSequenceW(This->package, table, sequence);
2468 return HRESULT_FROM_WIN32(r);
2471 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2473 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2474 UINT r = MsiGetTargetPathW(This->package, folder, value, size);
2475 return HRESULT_FROM_WIN32(r);
2478 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2480 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2481 UINT r = MsiSetTargetPathW(This->package, folder, value);
2482 return HRESULT_FROM_WIN32(r);
2485 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value, DWORD *size )
2487 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2488 UINT r = MsiGetSourcePathW(This->package, folder, value, size);
2489 return HRESULT_FROM_WIN32(r);
2492 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2494 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2495 *ret = MsiGetMode(This->package, mode);
2496 return S_OK;
2499 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2501 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2502 UINT r = MsiSetMode(This->package, mode, state);
2503 return HRESULT_FROM_WIN32(r);
2506 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2507 INSTALLSTATE *installed, INSTALLSTATE *action )
2509 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2510 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2511 return HRESULT_FROM_WIN32(r);
2514 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2516 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2517 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2518 return HRESULT_FROM_WIN32(r);
2521 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2522 INSTALLSTATE *installed, INSTALLSTATE *action )
2524 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2525 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2526 return HRESULT_FROM_WIN32(r);
2529 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2531 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2532 UINT r = MsiSetComponentStateW(This->package, component, state);
2533 return HRESULT_FROM_WIN32(r);
2536 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2538 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2539 *language = MsiGetLanguage(This->package);
2540 return S_OK;
2543 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2545 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2546 UINT r = MsiSetInstallLevel(This->package, level);
2547 return HRESULT_FROM_WIN32(r);
2550 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2551 BSTR *value)
2553 DWORD size = 0;
2554 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2555 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2556 if (r == ERROR_SUCCESS)
2558 *value = SysAllocStringLen(NULL, size);
2559 if (!*value)
2560 return E_OUTOFMEMORY;
2561 size++;
2562 r = MsiFormatRecordW(This->package, record, *value, &size);
2564 return HRESULT_FROM_WIN32(r);
2567 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2569 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2570 UINT r = MsiEvaluateConditionW(This->package, condition);
2571 return HRESULT_FROM_WIN32(r);
2574 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2575 INT cost_tree, INSTALLSTATE state, INT *cost )
2577 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2578 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2579 return HRESULT_FROM_WIN32(r);
2582 static HRESULT WINAPI mrp_EnumComponentCosts( IWineMsiRemotePackage *iface, BSTR component,
2583 DWORD index, INSTALLSTATE state, BSTR drive,
2584 DWORD *buflen, INT *cost, INT *temp )
2586 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2587 UINT r = MsiEnumComponentCostsW(This->package, component, index, state, drive, buflen, cost, temp);
2588 return HRESULT_FROM_WIN32(r);
2591 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2593 mrp_QueryInterface,
2594 mrp_AddRef,
2595 mrp_Release,
2596 mrp_SetMsiHandle,
2597 mrp_GetActiveDatabase,
2598 mrp_GetProperty,
2599 mrp_SetProperty,
2600 mrp_ProcessMessage,
2601 mrp_DoAction,
2602 mrp_Sequence,
2603 mrp_GetTargetPath,
2604 mrp_SetTargetPath,
2605 mrp_GetSourcePath,
2606 mrp_GetMode,
2607 mrp_SetMode,
2608 mrp_GetFeatureState,
2609 mrp_SetFeatureState,
2610 mrp_GetComponentState,
2611 mrp_SetComponentState,
2612 mrp_GetLanguage,
2613 mrp_SetInstallLevel,
2614 mrp_FormatRecord,
2615 mrp_EvaluateCondition,
2616 mrp_GetFeatureCost,
2617 mrp_EnumComponentCosts
2620 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2622 msi_remote_package_impl* This;
2624 This = msi_alloc( sizeof *This );
2625 if (!This)
2626 return E_OUTOFMEMORY;
2628 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2629 This->package = 0;
2630 This->refs = 1;
2632 *ppObj = This;
2634 return S_OK;
2637 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2638 LPCWSTR property, LPWSTR value)
2640 MSISOURCELISTINFO *info;
2642 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2644 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2647 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2648 if (!info)
2649 return ERROR_OUTOFMEMORY;
2651 info->context = context;
2652 info->options = options;
2653 info->property = property;
2654 info->value = strdupW(value);
2655 list_add_head(&package->sourcelist_info, &info->entry);
2657 return ERROR_SUCCESS;
2660 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2661 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2663 MSIMEDIADISK *disk;
2665 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2667 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2670 disk = msi_alloc(sizeof(MSIMEDIADISK));
2671 if (!disk)
2672 return ERROR_OUTOFMEMORY;
2674 disk->context = context;
2675 disk->options = options;
2676 disk->disk_id = disk_id;
2677 disk->volume_label = strdupW(volume_label);
2678 disk->disk_prompt = strdupW(disk_prompt);
2679 list_add_head(&package->sourcelist_media, &disk->entry);
2681 return ERROR_SUCCESS;