mstask: Implement ITask::DeleteTrigger().
[wine.git] / dlls / msi / package.c
blob179091863d609e65ed0175c78690346010b1af21
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 "msi.h"
33 #include "msiquery.h"
34 #include "objidl.h"
35 #include "wincrypt.h"
36 #include "winuser.h"
37 #include "wininet.h"
38 #include "winver.h"
39 #include "urlmon.h"
40 #include "shlobj.h"
41 #include "objbase.h"
42 #include "msidefs.h"
43 #include "sddl.h"
45 #include "wine/heap.h"
46 #include "wine/debug.h"
47 #include "wine/unicode.h"
49 #include "msipriv.h"
50 #include "winemsi.h"
51 #include "resource.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(msi);
55 static void free_feature( MSIFEATURE *feature )
57 struct list *item, *cursor;
59 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
61 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
62 list_remove( &fl->entry );
63 msi_free( fl );
66 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
68 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
69 list_remove( &cl->entry );
70 msi_free( cl );
72 msi_free( feature->Feature );
73 msi_free( feature->Feature_Parent );
74 msi_free( feature->Directory );
75 msi_free( feature->Description );
76 msi_free( feature->Title );
77 msi_free( feature );
80 static void free_folder( MSIFOLDER *folder )
82 struct list *item, *cursor;
84 LIST_FOR_EACH_SAFE( item, cursor, &folder->children )
86 FolderList *fl = LIST_ENTRY( item, FolderList, entry );
87 list_remove( &fl->entry );
88 msi_free( fl );
90 msi_free( folder->Parent );
91 msi_free( folder->Directory );
92 msi_free( folder->TargetDefault );
93 msi_free( folder->SourceLongPath );
94 msi_free( folder->SourceShortPath );
95 msi_free( folder->ResolvedTarget );
96 msi_free( folder->ResolvedSource );
97 msi_free( folder );
100 static void free_extension( MSIEXTENSION *ext )
102 struct list *item, *cursor;
104 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
106 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
108 list_remove( &verb->entry );
109 msi_free( verb->Verb );
110 msi_free( verb->Command );
111 msi_free( verb->Argument );
112 msi_free( verb );
115 msi_free( ext->Extension );
116 msi_free( ext->ProgIDText );
117 msi_free( ext );
120 static void free_assembly( MSIASSEMBLY *assembly )
122 msi_free( assembly->feature );
123 msi_free( assembly->manifest );
124 msi_free( assembly->application );
125 msi_free( assembly->display_name );
126 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
127 msi_free( assembly->tempdir );
128 msi_free( assembly );
131 void msi_free_action_script( MSIPACKAGE *package, UINT script )
133 UINT i;
134 for (i = 0; i < package->script_actions_count[script]; i++)
135 msi_free( package->script_actions[script][i] );
137 msi_free( package->script_actions[script] );
138 package->script_actions[script] = NULL;
139 package->script_actions_count[script] = 0;
142 static void free_package_structures( MSIPACKAGE *package )
144 struct list *item, *cursor;
145 int i;
147 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
149 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
150 list_remove( &feature->entry );
151 free_feature( feature );
154 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
156 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
157 list_remove( &folder->entry );
158 free_folder( folder );
161 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
163 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
165 list_remove( &file->entry );
166 msi_free( file->File );
167 msi_free( file->FileName );
168 msi_free( file->ShortName );
169 msi_free( file->LongName );
170 msi_free( file->Version );
171 msi_free( file->Language );
172 if (msi_is_global_assembly( file->Component )) DeleteFileW( file->TargetPath );
173 msi_free( file->TargetPath );
174 msi_free( file );
177 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
179 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
181 list_remove( &comp->entry );
182 msi_free( comp->Component );
183 msi_free( comp->ComponentId );
184 msi_free( comp->Directory );
185 msi_free( comp->Condition );
186 msi_free( comp->KeyPath );
187 msi_free( comp->FullKeypath );
188 if (comp->assembly) free_assembly( comp->assembly );
189 msi_free( comp );
192 LIST_FOR_EACH_SAFE( item, cursor, &package->filepatches )
194 MSIFILEPATCH *patch = LIST_ENTRY( item, MSIFILEPATCH, entry );
196 list_remove( &patch->entry );
197 msi_free( patch->path );
198 msi_free( patch );
201 /* clean up extension, progid, class and verb structures */
202 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
204 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
206 list_remove( &cls->entry );
207 msi_free( cls->clsid );
208 msi_free( cls->Context );
209 msi_free( cls->Description );
210 msi_free( cls->FileTypeMask );
211 msi_free( cls->IconPath );
212 msi_free( cls->DefInprocHandler );
213 msi_free( cls->DefInprocHandler32 );
214 msi_free( cls->Argument );
215 msi_free( cls->ProgIDText );
216 msi_free( cls );
219 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
221 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
223 list_remove( &ext->entry );
224 free_extension( ext );
227 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
229 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
231 list_remove( &progid->entry );
232 msi_free( progid->ProgID );
233 msi_free( progid->Description );
234 msi_free( progid->IconPath );
235 msi_free( progid );
238 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
240 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
242 list_remove( &mt->entry );
243 msi_free( mt->suffix );
244 msi_free( mt->clsid );
245 msi_free( mt->ContentType );
246 msi_free( mt );
249 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
251 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
253 list_remove( &appid->entry );
254 msi_free( appid->AppID );
255 msi_free( appid->RemoteServerName );
256 msi_free( appid->LocalServer );
257 msi_free( appid->ServiceParameters );
258 msi_free( appid->DllSurrogate );
259 msi_free( appid );
262 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
264 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
266 list_remove( &info->entry );
267 msi_free( info->value );
268 msi_free( info );
271 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
273 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
275 list_remove( &info->entry );
276 msi_free( info->volume_label );
277 msi_free( info->disk_prompt );
278 msi_free( info );
281 for (i = 0; i < SCRIPT_MAX; i++)
282 msi_free_action_script( package, i );
284 for (i = 0; i < package->unique_actions_count; i++)
285 msi_free( package->unique_actions[i] );
286 msi_free( package->unique_actions);
288 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
290 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
292 list_remove( &binary->entry );
293 if (binary->module)
294 FreeLibrary( binary->module );
295 if (!DeleteFileW( binary->tmpfile ))
296 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
297 msi_free( binary->source );
298 msi_free( binary->tmpfile );
299 msi_free( binary );
302 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
304 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
306 list_remove( &cab->entry );
307 IStorage_Release( cab->storage );
308 msi_free( cab->stream );
309 msi_free( cab );
312 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
314 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
316 list_remove( &patch->entry );
317 if (patch->delete_on_close && !DeleteFileW( patch->localfile ))
319 ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError());
321 msi_free_patchinfo( patch );
324 msi_free( package->PackagePath );
325 msi_free( package->ProductCode );
326 msi_free( package->ActionFormat );
327 msi_free( package->LastAction );
328 msi_free( package->LastActionTemplate );
329 msi_free( package->langids );
331 /* cleanup control event subscriptions */
332 msi_event_cleanup_all_subscriptions( package );
335 static void MSI_FreePackage( MSIOBJECTHDR *arg)
337 MSIPACKAGE *package = (MSIPACKAGE *)arg;
339 msi_destroy_assembly_caches( package );
341 if( package->dialog )
342 msi_dialog_destroy( package->dialog );
344 msiobj_release( &package->db->hdr );
345 free_package_structures(package);
346 CloseHandle( package->log_file );
348 if (package->delete_on_close) DeleteFileW( package->localfile );
349 msi_free( package->localfile );
350 MSI_ProcessMessage(NULL, INSTALLMESSAGE_TERMINATE, 0);
353 static UINT create_temp_property_table(MSIPACKAGE *package)
355 static const WCHAR query[] = {
356 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
357 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
358 '`','_','P','r','o','p','e','r','t','y','`',' ',
359 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
360 'T','E','M','P','O','R','A','R','Y',',',' ',
361 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
362 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
363 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
364 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
365 MSIQUERY *view;
366 UINT rc;
368 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
369 if (rc != ERROR_SUCCESS)
370 return rc;
372 rc = MSI_ViewExecute(view, 0);
373 MSI_ViewClose(view);
374 msiobj_release(&view->hdr);
375 return rc;
378 UINT msi_clone_properties( MSIDATABASE *db )
380 static const WCHAR query_select[] = {
381 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
382 '`','P','r','o','p','e','r','t','y','`',0};
383 static const WCHAR query_insert[] = {
384 'I','N','S','E','R','T',' ','I','N','T','O',' ',
385 '`','_','P','r','o','p','e','r','t','y','`',' ',
386 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
387 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
388 static const WCHAR query_update[] = {
389 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
390 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
391 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
392 MSIQUERY *view_select;
393 UINT rc;
395 rc = MSI_DatabaseOpenViewW( db, query_select, &view_select );
396 if (rc != ERROR_SUCCESS)
397 return rc;
399 rc = MSI_ViewExecute( view_select, 0 );
400 if (rc != ERROR_SUCCESS)
402 MSI_ViewClose( view_select );
403 msiobj_release( &view_select->hdr );
404 return rc;
407 while (1)
409 MSIQUERY *view_insert, *view_update;
410 MSIRECORD *rec_select;
412 rc = MSI_ViewFetch( view_select, &rec_select );
413 if (rc != ERROR_SUCCESS)
414 break;
416 rc = MSI_DatabaseOpenViewW( db, query_insert, &view_insert );
417 if (rc != ERROR_SUCCESS)
419 msiobj_release( &rec_select->hdr );
420 continue;
423 rc = MSI_ViewExecute( view_insert, rec_select );
424 MSI_ViewClose( view_insert );
425 msiobj_release( &view_insert->hdr );
426 if (rc != ERROR_SUCCESS)
428 MSIRECORD *rec_update;
430 TRACE("insert failed, trying update\n");
432 rc = MSI_DatabaseOpenViewW( db, query_update, &view_update );
433 if (rc != ERROR_SUCCESS)
435 WARN("open view failed %u\n", rc);
436 msiobj_release( &rec_select->hdr );
437 continue;
440 rec_update = MSI_CreateRecord( 2 );
441 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
442 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
443 rc = MSI_ViewExecute( view_update, rec_update );
444 if (rc != ERROR_SUCCESS)
445 WARN("update failed %u\n", rc);
447 MSI_ViewClose( view_update );
448 msiobj_release( &view_update->hdr );
449 msiobj_release( &rec_update->hdr );
452 msiobj_release( &rec_select->hdr );
455 MSI_ViewClose( view_select );
456 msiobj_release( &view_select->hdr );
457 return rc;
461 * set_installed_prop
463 * Sets the "Installed" property to indicate that
464 * the product is installed for the current user.
466 static UINT set_installed_prop( MSIPACKAGE *package )
468 HKEY hkey;
469 UINT r;
471 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
473 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
474 if (r == ERROR_SUCCESS)
476 RegCloseKey( hkey );
477 msi_set_property( package->db, szInstalled, szOne, -1 );
479 return r;
482 static UINT set_user_sid_prop( MSIPACKAGE *package )
484 SID_NAME_USE use;
485 LPWSTR user_name;
486 LPWSTR sid_str = NULL, dom = NULL;
487 DWORD size, dom_size;
488 PSID psid = NULL;
489 UINT r = ERROR_FUNCTION_FAILED;
491 size = 0;
492 GetUserNameW( NULL, &size );
494 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
495 if (!user_name)
496 return ERROR_OUTOFMEMORY;
498 if (!GetUserNameW( user_name, &size ))
499 goto done;
501 size = 0;
502 dom_size = 0;
503 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
505 psid = msi_alloc( size );
506 dom = msi_alloc( dom_size*sizeof (WCHAR) );
507 if (!psid || !dom)
509 r = ERROR_OUTOFMEMORY;
510 goto done;
513 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
514 goto done;
516 if (!ConvertSidToStringSidW( psid, &sid_str ))
517 goto done;
519 r = msi_set_property( package->db, szUserSID, sid_str, -1 );
521 done:
522 LocalFree( sid_str );
523 msi_free( dom );
524 msi_free( psid );
525 msi_free( user_name );
527 return r;
530 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
532 static const WCHAR fusion[] =
533 {'f','u','s','i','o','n','.','d','l','l',0};
534 static const WCHAR subkey[] =
535 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
536 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\','N','D','P',0};
537 static const WCHAR subdir[] =
538 {'M','i','c','r','o','s','o','f','t','.','N','E','T','\\','F','r','a','m','e','w','o','r','k','\\',0};
539 static const WCHAR v2050727[] =
540 {'v','2','.','0','.','5','0','7','2','7',0};
541 static const WCHAR v4client[] =
542 {'v','4','\\','C','l','i','e','n','t',0};
543 static const WCHAR installpath[] =
544 {'I','n','s','t','a','l','l','P','a','t','h',0};
545 HKEY netsetup, hkey;
546 LONG res;
547 DWORD size, len, type;
548 WCHAR windir[MAX_PATH], path[MAX_PATH], *filename = NULL;
550 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, subkey, 0, KEY_CREATE_SUB_KEY, &netsetup);
551 if (res != ERROR_SUCCESS)
552 return NULL;
554 if (!RegCreateKeyExW(netsetup, v4client, 0, NULL, 0, KEY_QUERY_VALUE, NULL, &hkey, NULL))
556 size = sizeof(path)/sizeof(path[0]);
557 if (!RegQueryValueExW(hkey, installpath, NULL, &type, (BYTE *)path, &size))
559 len = strlenW(path) + strlenW(fusion) + 2;
560 if (!(filename = msi_alloc(len * sizeof(WCHAR)))) return NULL;
562 strcpyW(filename, path);
563 strcatW(filename, szBackSlash);
564 strcatW(filename, fusion);
565 if (GetFileAttributesW(filename) != INVALID_FILE_ATTRIBUTES)
567 TRACE( "found %s\n", debugstr_w(filename) );
568 RegCloseKey(hkey);
569 RegCloseKey(netsetup);
570 return filename;
573 RegCloseKey(hkey);
576 if (!RegCreateKeyExW(netsetup, v2050727, 0, NULL, 0, KEY_QUERY_VALUE, NULL, &hkey, NULL))
578 RegCloseKey(hkey);
579 GetWindowsDirectoryW(windir, MAX_PATH);
580 len = strlenW(windir) + strlenW(subdir) + strlenW(v2050727) + strlenW(fusion) + 3;
581 if (!(filename = msi_alloc(len * sizeof(WCHAR)))) return NULL;
583 strcpyW(filename, windir);
584 strcatW(filename, szBackSlash);
585 strcatW(filename, subdir);
586 strcatW(filename, v2050727);
587 strcatW(filename, szBackSlash);
588 strcatW(filename, fusion);
589 if (GetFileAttributesW(filename) != INVALID_FILE_ATTRIBUTES)
591 TRACE( "found %s\n", debugstr_w(filename) );
592 RegCloseKey(netsetup);
593 return filename;
597 RegCloseKey(netsetup);
598 return filename;
601 typedef struct tagLANGANDCODEPAGE
603 WORD wLanguage;
604 WORD wCodePage;
605 } LANGANDCODEPAGE;
607 static void set_msi_assembly_prop(MSIPACKAGE *package)
609 UINT val_len;
610 DWORD size, handle;
611 LPVOID version = NULL;
612 WCHAR buf[MAX_PATH];
613 LPWSTR fusion, verstr;
614 LANGANDCODEPAGE *translate;
616 static const WCHAR netasm[] = {
617 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
619 static const WCHAR translation[] = {
620 '\\','V','a','r','F','i','l','e','I','n','f','o',
621 '\\','T','r','a','n','s','l','a','t','i','o','n',0
623 static const WCHAR verfmt[] = {
624 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
625 '\\','%','0','4','x','%','0','4','x',
626 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
629 fusion = get_fusion_filename(package);
630 if (!fusion)
631 return;
633 size = GetFileVersionInfoSizeW(fusion, &handle);
634 if (!size)
635 goto done;
637 version = msi_alloc(size);
638 if (!version)
639 goto done;
641 if (!GetFileVersionInfoW(fusion, handle, size, version))
642 goto done;
644 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
645 goto done;
647 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
649 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
650 goto done;
652 if (!val_len || !verstr)
653 goto done;
655 msi_set_property( package->db, netasm, verstr, -1 );
657 done:
658 msi_free(fusion);
659 msi_free(version);
662 static VOID set_installer_properties(MSIPACKAGE *package)
664 WCHAR *ptr;
665 OSVERSIONINFOEXW OSVersion;
666 MEMORYSTATUSEX msex;
667 DWORD verval, len;
668 WCHAR pth[MAX_PATH], verstr[11], bufstr[22];
669 HDC dc;
670 HKEY hkey;
671 LPWSTR username, companyname;
672 SYSTEM_INFO sys_info;
673 LANGID langid;
675 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
676 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
677 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
678 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
679 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
680 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
681 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
682 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
683 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
684 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
685 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
686 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
687 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
688 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
689 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
690 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
691 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
692 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
693 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
694 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
695 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
696 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
697 static const WCHAR szFormat[] = {'%','u',0};
698 static const WCHAR szFormat2[] = {'%','u','.','%','u',0};
699 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
700 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
701 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
702 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
703 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
704 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
705 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
706 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
707 static const WCHAR szIntFormat[] = {'%','d',0};
708 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
709 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
710 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
711 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
712 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 };
713 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
714 static const WCHAR szUserInfo[] = {
715 'S','O','F','T','W','A','R','E','\\',
716 'M','i','c','r','o','s','o','f','t','\\',
717 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
718 'U','s','e','r',' ','I','n','f','o',0
720 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
721 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
722 static const WCHAR szCurrentVersion[] = {
723 'S','O','F','T','W','A','R','E','\\',
724 'M','i','c','r','o','s','o','f','t','\\',
725 'W','i','n','d','o','w','s',' ','N','T','\\',
726 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
728 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
729 static const WCHAR szRegisteredOrganization[] = {
730 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
732 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
733 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
734 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
735 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
736 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
737 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
738 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
739 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
740 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
741 static const WCHAR szComputerName[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
744 * Other things that probably should be set:
746 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
747 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
750 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
751 strcatW(pth, szBackSlash);
752 msi_set_property( package->db, szCommonAppDataFolder, pth, -1 );
754 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
755 strcatW(pth, szBackSlash);
756 msi_set_property( package->db, szFavoritesFolder, pth, -1 );
758 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
759 strcatW(pth, szBackSlash);
760 msi_set_property( package->db, szFontsFolder, pth, -1 );
762 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
763 strcatW(pth, szBackSlash);
764 msi_set_property( package->db, szSendToFolder, pth, -1 );
766 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
767 strcatW(pth, szBackSlash);
768 msi_set_property( package->db, szStartMenuFolder, pth, -1 );
770 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
771 strcatW(pth, szBackSlash);
772 msi_set_property( package->db, szStartupFolder, pth, -1 );
774 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
775 strcatW(pth, szBackSlash);
776 msi_set_property( package->db, szTemplateFolder, pth, -1 );
778 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
779 strcatW(pth, szBackSlash);
780 msi_set_property( package->db, szDesktopFolder, pth, -1 );
782 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
783 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
784 strcatW(pth, szBackSlash);
785 msi_set_property( package->db, szProgramMenuFolder, pth, -1 );
787 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
788 strcatW(pth, szBackSlash);
789 msi_set_property( package->db, szAdminToolsFolder, pth, -1 );
791 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
792 strcatW(pth, szBackSlash);
793 msi_set_property( package->db, szAppDataFolder, pth, -1 );
795 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
796 strcatW(pth, szBackSlash);
797 msi_set_property( package->db, szSystemFolder, pth, -1 );
798 msi_set_property( package->db, szSystem16Folder, pth, -1 );
800 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
801 strcatW(pth, szBackSlash);
802 msi_set_property( package->db, szLocalAppDataFolder, pth, -1 );
804 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
805 strcatW(pth, szBackSlash);
806 msi_set_property( package->db, szMyPicturesFolder, pth, -1 );
808 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
809 strcatW(pth, szBackSlash);
810 msi_set_property( package->db, szPersonalFolder, pth, -1 );
812 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
813 strcatW(pth, szBackSlash);
814 msi_set_property( package->db, szWindowsFolder, pth, -1 );
816 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
817 strcatW(pth, szBackSlash);
818 msi_set_property( package->db, szPrintHoodFolder, pth, -1 );
820 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
821 strcatW(pth, szBackSlash);
822 msi_set_property( package->db, szNetHoodFolder, pth, -1 );
824 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
825 strcatW(pth, szBackSlash);
826 msi_set_property( package->db, szRecentFolder, pth, -1 );
828 /* Physical Memory is specified in MB. Using total amount. */
829 msex.dwLength = sizeof(msex);
830 GlobalMemoryStatusEx( &msex );
831 len = sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
832 msi_set_property( package->db, szPhysicalMemory, bufstr, len );
834 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
835 ptr = strchrW(pth,'\\');
836 if (ptr) *(ptr + 1) = 0;
837 msi_set_property( package->db, szWindowsVolume, pth, -1 );
839 len = GetTempPathW(MAX_PATH, pth);
840 msi_set_property( package->db, szTempFolder, pth, len );
842 /* in a wine environment the user is always admin and privileged */
843 msi_set_property( package->db, szAdminUser, szOne, -1 );
844 msi_set_property( package->db, szPrivileged, szOne, -1 );
846 /* set the os things */
847 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
848 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
849 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
850 len = sprintfW( verstr, szFormat, verval );
851 switch (OSVersion.dwPlatformId)
853 case VER_PLATFORM_WIN32_WINDOWS:
854 msi_set_property( package->db, szVersion9x, verstr, len );
855 break;
856 case VER_PLATFORM_WIN32_NT:
857 msi_set_property( package->db, szVersionNT, verstr, len );
858 len = sprintfW( bufstr, szFormat,OSVersion.wProductType );
859 msi_set_property( package->db, szMsiNTProductType, bufstr, len );
860 break;
862 len = sprintfW( bufstr, szFormat, OSVersion.dwBuildNumber );
863 msi_set_property( package->db, szWindowsBuild, bufstr, len );
864 len = sprintfW( bufstr, szFormat, OSVersion.wServicePackMajor );
865 msi_set_property( package->db, szServicePackLevel, bufstr, len );
867 len = sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION );
868 msi_set_property( package->db, szVersionMsi, bufstr, len );
869 len = sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100 );
870 msi_set_property( package->db, szVersionDatabase, bufstr, len );
872 GetNativeSystemInfo( &sys_info );
873 len = sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
874 msi_set_property( package->db, szIntel, bufstr, len );
875 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
877 GetSystemDirectoryW( pth, MAX_PATH );
878 PathAddBackslashW( pth );
879 msi_set_property( package->db, szSystemFolder, pth, -1 );
881 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
882 PathAddBackslashW( pth );
883 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
885 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
886 PathAddBackslashW( pth );
887 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
889 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
891 msi_set_property( package->db, szMsiAMD64, bufstr, -1 );
892 msi_set_property( package->db, szMsix64, bufstr, -1 );
893 msi_set_property( package->db, szVersionNT64, verstr, -1 );
895 GetSystemDirectoryW( pth, MAX_PATH );
896 PathAddBackslashW( pth );
897 msi_set_property( package->db, szSystem64Folder, pth, -1 );
899 GetSystemWow64DirectoryW( pth, MAX_PATH );
900 PathAddBackslashW( pth );
901 msi_set_property( package->db, szSystemFolder, pth, -1 );
903 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
904 PathAddBackslashW( pth );
905 msi_set_property( package->db, szProgramFiles64Folder, pth, -1 );
907 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
908 PathAddBackslashW( pth );
909 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
911 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
912 PathAddBackslashW( pth );
913 msi_set_property( package->db, szCommonFiles64Folder, pth, -1 );
915 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
916 PathAddBackslashW( pth );
917 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
920 /* Screen properties. */
921 dc = GetDC(0);
922 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, HORZRES) );
923 msi_set_property( package->db, szScreenX, bufstr, len );
924 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, VERTRES) );
925 msi_set_property( package->db, szScreenY, bufstr, len );
926 len = sprintfW( bufstr, szIntFormat, GetDeviceCaps(dc, BITSPIXEL) );
927 msi_set_property( package->db, szColorBits, bufstr, len );
928 ReleaseDC(0, dc);
930 /* USERNAME and COMPANYNAME */
931 username = msi_dup_property( package->db, szUSERNAME );
932 companyname = msi_dup_property( package->db, szCOMPANYNAME );
934 if ((!username || !companyname) &&
935 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
937 if (!username &&
938 (username = msi_reg_get_val_str( hkey, szDefName )))
939 msi_set_property( package->db, szUSERNAME, username, -1 );
940 if (!companyname &&
941 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
942 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
943 CloseHandle( hkey );
945 if ((!username || !companyname) &&
946 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
948 if (!username &&
949 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
950 msi_set_property( package->db, szUSERNAME, username, -1 );
951 if (!companyname &&
952 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
953 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
954 CloseHandle( hkey );
956 msi_free( username );
957 msi_free( companyname );
959 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
960 ERR("Failed to set the UserSID property\n");
962 set_msi_assembly_prop( package );
964 langid = GetUserDefaultLangID();
965 len = sprintfW( bufstr, szIntFormat, langid );
966 msi_set_property( package->db, szUserLanguageID, bufstr, len );
968 langid = GetSystemDefaultLangID();
969 len = sprintfW( bufstr, szIntFormat, langid );
970 msi_set_property( package->db, szSystemLangID, bufstr, len );
972 len = sprintfW( bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode) );
973 msi_set_property( package->db, szProductState, bufstr, len );
975 len = 0;
976 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
978 WCHAR *username;
979 if ((username = msi_alloc( len * sizeof(WCHAR) )))
981 if (GetUserNameW( username, &len ))
982 msi_set_property( package->db, szLogonUser, username, len - 1 );
983 msi_free( username );
986 len = 0;
987 if (!GetComputerNameW( NULL, &len ) && GetLastError() == ERROR_BUFFER_OVERFLOW)
989 WCHAR *computername;
990 if ((computername = msi_alloc( len * sizeof(WCHAR) )))
992 if (GetComputerNameW( computername, &len ))
993 msi_set_property( package->db, szComputerName, computername, len );
994 msi_free( computername );
999 static MSIPACKAGE *msi_alloc_package( void )
1001 MSIPACKAGE *package;
1003 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1004 MSI_FreePackage );
1005 if( package )
1007 list_init( &package->components );
1008 list_init( &package->features );
1009 list_init( &package->files );
1010 list_init( &package->filepatches );
1011 list_init( &package->tempfiles );
1012 list_init( &package->folders );
1013 list_init( &package->subscriptions );
1014 list_init( &package->appids );
1015 list_init( &package->classes );
1016 list_init( &package->mimes );
1017 list_init( &package->extensions );
1018 list_init( &package->progids );
1019 list_init( &package->RunningActions );
1020 list_init( &package->sourcelist_info );
1021 list_init( &package->sourcelist_media );
1022 list_init( &package->patches );
1023 list_init( &package->binaries );
1024 list_init( &package->cabinet_streams );
1027 return package;
1030 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1032 BYTE *data;
1033 UINT r, sz;
1035 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1037 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1038 if (r != ERROR_SUCCESS)
1039 return r;
1041 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1043 msi_free(data);
1044 return r;
1047 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1049 /* FIXME: this should depend on the user's privileges */
1050 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1052 TRACE("resetting ALLUSERS property from 2 to 1\n");
1053 msi_set_property( package->db, szAllUsers, szOne, -1 );
1055 msi_set_property( package->db, szAdminUser, szOne, -1 );
1058 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
1060 static const WCHAR fmtW[] = {'%','u',0};
1061 MSIPACKAGE *package;
1062 WCHAR uilevel[11];
1063 int len;
1064 UINT r;
1066 TRACE("%p\n", db);
1068 package = msi_alloc_package();
1069 if (package)
1071 msiobj_addref( &db->hdr );
1072 package->db = db;
1074 package->LastAction = NULL;
1075 package->LastActionTemplate = NULL;
1076 package->LastActionResult = MSI_NULL_INTEGER;
1077 package->WordCount = 0;
1078 package->PackagePath = strdupW( db->path );
1080 create_temp_property_table( package );
1081 msi_clone_properties( package->db );
1082 msi_adjust_privilege_properties( package );
1084 package->ProductCode = msi_dup_property( package->db, szProductCode );
1086 set_installer_properties( package );
1088 package->ui_level = gUILevel;
1089 len = sprintfW( uilevel, fmtW, gUILevel & INSTALLUILEVEL_MASK );
1090 msi_set_property( package->db, szUILevel, uilevel, len );
1092 r = msi_load_suminfo_properties( package );
1093 if (r != ERROR_SUCCESS)
1095 msiobj_release( &package->hdr );
1096 return NULL;
1099 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1100 msi_load_admin_properties( package );
1102 package->log_file = INVALID_HANDLE_VALUE;
1104 return package;
1107 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1109 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1110 DWORD size = 0;
1111 HRESULT hr;
1113 /* call will always fail, because size is 0,
1114 * but will return ERROR_FILE_NOT_FOUND first
1115 * if the file doesn't exist
1117 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1118 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1120 cache_entry = msi_alloc( size );
1121 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1123 UINT error = GetLastError();
1124 msi_free( cache_entry );
1125 return error;
1128 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1129 msi_free( cache_entry );
1130 return ERROR_SUCCESS;
1133 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1134 if ( FAILED(hr) )
1136 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1137 return ERROR_FUNCTION_FAILED;
1140 return ERROR_SUCCESS;
1143 UINT msi_create_empty_local_file( LPWSTR path, LPCWSTR suffix )
1145 static const WCHAR szInstaller[] = {
1146 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1147 static const WCHAR fmt[] = {'%','x',0};
1148 DWORD time, len, i, offset;
1149 HANDLE handle;
1151 time = GetTickCount();
1152 GetWindowsDirectoryW( path, MAX_PATH );
1153 strcatW( path, szInstaller );
1154 CreateDirectoryW( path, NULL );
1156 len = strlenW(path);
1157 for (i = 0; i < 0x10000; i++)
1159 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1160 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1161 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1162 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1163 if (handle != INVALID_HANDLE_VALUE)
1165 CloseHandle(handle);
1166 break;
1168 if (GetLastError() != ERROR_FILE_EXISTS &&
1169 GetLastError() != ERROR_SHARING_VIOLATION)
1170 return ERROR_FUNCTION_FAILED;
1173 return ERROR_SUCCESS;
1176 static enum platform parse_platform( const WCHAR *str )
1178 if (!str[0] || !strcmpW( str, szIntel )) return PLATFORM_INTEL;
1179 else if (!strcmpW( str, szIntel64 )) return PLATFORM_INTEL64;
1180 else if (!strcmpW( str, szX64 ) || !strcmpW( str, szAMD64 )) return PLATFORM_X64;
1181 else if (!strcmpW( str, szARM )) return PLATFORM_ARM;
1182 return PLATFORM_UNKNOWN;
1185 static UINT parse_suminfo( MSISUMMARYINFO *si, MSIPACKAGE *package )
1187 WCHAR *template, *p, *q, *platform;
1188 DWORD i, count;
1190 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1191 TRACE("version: %d\n", package->version);
1193 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1194 if (!template)
1195 return ERROR_SUCCESS; /* native accepts missing template property */
1197 TRACE("template: %s\n", debugstr_w(template));
1199 p = strchrW( template, ';' );
1200 if (!p)
1202 WARN("invalid template string %s\n", debugstr_w(template));
1203 msi_free( template );
1204 return ERROR_PATCH_PACKAGE_INVALID;
1206 *p = 0;
1207 platform = template;
1208 if ((q = strchrW( platform, ',' ))) *q = 0;
1209 package->platform = parse_platform( platform );
1210 while (package->platform == PLATFORM_UNKNOWN && q)
1212 platform = q + 1;
1213 if ((q = strchrW( platform, ',' ))) *q = 0;
1214 package->platform = parse_platform( platform );
1216 if (package->platform == PLATFORM_UNKNOWN)
1218 WARN("unknown platform %s\n", debugstr_w(template));
1219 msi_free( template );
1220 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1222 p++;
1223 if (!*p)
1225 msi_free( template );
1226 return ERROR_SUCCESS;
1228 count = 1;
1229 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1231 package->langids = msi_alloc( count * sizeof(LANGID) );
1232 if (!package->langids)
1234 msi_free( template );
1235 return ERROR_OUTOFMEMORY;
1238 i = 0;
1239 while (*p)
1241 q = strchrW( p, ',' );
1242 if (q) *q = 0;
1243 package->langids[i] = atoiW( p );
1244 if (!q) break;
1245 p = q + 1;
1246 i++;
1248 package->num_langids = i + 1;
1250 msi_free( template );
1251 return ERROR_SUCCESS;
1254 static UINT validate_package( MSIPACKAGE *package )
1256 UINT i;
1258 if (package->platform == PLATFORM_INTEL64)
1259 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1260 #ifndef __arm__
1261 if (package->platform == PLATFORM_ARM)
1262 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1263 #endif
1264 if (package->platform == PLATFORM_X64)
1266 if (!is_64bit && !is_wow64)
1267 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1268 if (package->version < 200)
1269 return ERROR_INSTALL_PACKAGE_INVALID;
1271 if (!package->num_langids)
1273 return ERROR_SUCCESS;
1275 for (i = 0; i < package->num_langids; i++)
1277 LANGID langid = package->langids[i];
1279 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1281 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1283 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1285 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1287 if (IsValidLocale( langid, LCID_INSTALLED ))
1288 return ERROR_SUCCESS;
1290 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1293 static WCHAR *get_product_code( MSIDATABASE *db )
1295 static const WCHAR query[] = {
1296 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1297 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1298 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1299 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1300 MSIQUERY *view;
1301 MSIRECORD *rec;
1302 WCHAR *ret = NULL;
1304 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1306 return NULL;
1308 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1310 MSI_ViewClose( view );
1311 msiobj_release( &view->hdr );
1312 return NULL;
1314 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1316 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1317 msiobj_release( &rec->hdr );
1319 MSI_ViewClose( view );
1320 msiobj_release( &view->hdr );
1321 return ret;
1324 static UINT get_registered_local_package( const WCHAR *product, const WCHAR *package, WCHAR *localfile )
1326 MSIINSTALLCONTEXT context;
1327 HKEY product_key, props_key;
1328 WCHAR *registered_package = NULL, unsquashed[GUID_SIZE];
1329 UINT r;
1331 r = msi_locate_product( product, &context );
1332 if (r != ERROR_SUCCESS)
1333 return r;
1335 r = MSIREG_OpenProductKey( product, NULL, context, &product_key, FALSE );
1336 if (r != ERROR_SUCCESS)
1337 return r;
1339 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1340 if (r != ERROR_SUCCESS)
1342 RegCloseKey( product_key );
1343 return r;
1345 r = ERROR_FUNCTION_FAILED;
1346 registered_package = msi_reg_get_val_str( product_key, INSTALLPROPERTY_PACKAGECODEW );
1347 if (!registered_package)
1348 goto done;
1350 unsquash_guid( registered_package, unsquashed );
1351 if (!strcmpiW( package, unsquashed ))
1353 WCHAR *filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1354 if (!filename)
1355 goto done;
1357 strcpyW( localfile, filename );
1358 msi_free( filename );
1359 r = ERROR_SUCCESS;
1361 done:
1362 msi_free( registered_package );
1363 RegCloseKey( props_key );
1364 RegCloseKey( product_key );
1365 return r;
1368 static WCHAR *get_package_code( MSIDATABASE *db )
1370 WCHAR *ret;
1371 MSISUMMARYINFO *si;
1372 UINT r;
1374 r = msi_get_suminfo( db->storage, 0, &si );
1375 if (r != ERROR_SUCCESS)
1377 r = msi_get_db_suminfo( db, 0, &si );
1378 if (r != ERROR_SUCCESS)
1380 WARN("failed to load summary info %u\n", r);
1381 return NULL;
1384 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1385 msiobj_release( &si->hdr );
1386 return ret;
1389 static UINT get_local_package( const WCHAR *filename, WCHAR *localfile )
1391 WCHAR *product_code, *package_code;
1392 MSIDATABASE *db;
1393 UINT r;
1395 if ((r = MSI_OpenDatabaseW( filename, MSIDBOPEN_READONLY, &db )) != ERROR_SUCCESS)
1397 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1398 return ERROR_FILE_NOT_FOUND;
1399 return r;
1401 if (!(product_code = get_product_code( db )))
1403 msiobj_release( &db->hdr );
1404 return ERROR_INSTALL_PACKAGE_INVALID;
1406 if (!(package_code = get_package_code( db )))
1408 msi_free( product_code );
1409 msiobj_release( &db->hdr );
1410 return ERROR_INSTALL_PACKAGE_INVALID;
1412 r = get_registered_local_package( product_code, package_code, localfile );
1413 msi_free( package_code );
1414 msi_free( product_code );
1415 msiobj_release( &db->hdr );
1416 return r;
1419 UINT msi_set_original_database_property( MSIDATABASE *db, const WCHAR *package )
1421 UINT r;
1423 if (UrlIsW( package, URLIS_URL ))
1424 r = msi_set_property( db, szOriginalDatabase, package, -1 );
1425 else if (package[0] == '#')
1426 r = msi_set_property( db, szOriginalDatabase, db->path, -1 );
1427 else
1429 DWORD len;
1430 WCHAR *path;
1432 if (!(len = GetFullPathNameW( package, 0, NULL, NULL ))) return GetLastError();
1433 if (!(path = msi_alloc( len * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
1434 len = GetFullPathNameW( package, len, path, NULL );
1435 r = msi_set_property( db, szOriginalDatabase, path, len );
1436 msi_free( path );
1438 return r;
1441 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1443 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1444 MSIDATABASE *db;
1445 MSIPACKAGE *package;
1446 MSIHANDLE handle;
1447 MSIRECORD *data_row, *info_row;
1448 UINT r;
1449 WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
1450 LPCWSTR file = szPackage;
1451 DWORD index = 0;
1452 MSISUMMARYINFO *si;
1453 BOOL delete_on_close = FALSE;
1454 WCHAR *info_template, *productname;
1456 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1458 MSI_ProcessMessage(NULL, INSTALLMESSAGE_INITIALIZE, 0);
1460 localfile[0] = 0;
1461 if( szPackage[0] == '#' )
1463 handle = atoiW(&szPackage[1]);
1464 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1465 if( !db )
1467 MSIHANDLE remote;
1469 if (!(remote = msi_get_remote(handle)))
1470 return ERROR_INVALID_HANDLE;
1472 WARN("MsiOpenPackage not allowed during a custom action!\n");
1474 return ERROR_FUNCTION_FAILED;
1477 else
1479 if ( UrlIsW( szPackage, URLIS_URL ) )
1481 r = msi_download_file( szPackage, cachefile );
1482 if (r != ERROR_SUCCESS)
1483 return r;
1485 file = cachefile;
1487 r = get_local_package( file, localfile );
1488 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1490 r = msi_create_empty_local_file( localfile, dotmsi );
1491 if (r != ERROR_SUCCESS)
1492 return r;
1494 if (!CopyFileW( file, localfile, FALSE ))
1496 r = GetLastError();
1497 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1498 DeleteFileW( localfile );
1499 return r;
1501 delete_on_close = TRUE;
1503 TRACE("opening package %s\n", debugstr_w( localfile ));
1504 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1505 if (r != ERROR_SUCCESS)
1506 return r;
1508 package = MSI_CreatePackage( db );
1509 msiobj_release( &db->hdr );
1510 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1511 package->localfile = strdupW( localfile );
1512 package->delete_on_close = delete_on_close;
1514 r = msi_get_suminfo( db->storage, 0, &si );
1515 if (r != ERROR_SUCCESS)
1517 r = msi_get_db_suminfo( db, 0, &si );
1518 if (r != ERROR_SUCCESS)
1520 WARN("failed to load summary info\n");
1521 msiobj_release( &package->hdr );
1522 return ERROR_INSTALL_PACKAGE_INVALID;
1525 r = parse_suminfo( si, package );
1526 msiobj_release( &si->hdr );
1527 if (r != ERROR_SUCCESS)
1529 WARN("failed to parse summary info %u\n", r);
1530 msiobj_release( &package->hdr );
1531 return r;
1533 r = validate_package( package );
1534 if (r != ERROR_SUCCESS)
1536 msiobj_release( &package->hdr );
1537 return r;
1539 msi_set_property( package->db, szDatabase, db->path, -1 );
1540 set_installed_prop( package );
1541 msi_set_context( package );
1543 while (1)
1545 WCHAR patch_code[GUID_SIZE];
1546 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1547 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1548 if (r != ERROR_SUCCESS)
1549 break;
1551 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1553 r = msi_apply_registered_patch( package, patch_code );
1554 if (r != ERROR_SUCCESS)
1556 ERR("registered patch failed to apply %u\n", r);
1557 msiobj_release( &package->hdr );
1558 return r;
1560 index++;
1562 if (index) msi_adjust_privilege_properties( package );
1564 r = msi_set_original_database_property( package->db, szPackage );
1565 if (r != ERROR_SUCCESS)
1567 msiobj_release( &package->hdr );
1568 return r;
1570 if (gszLogFile)
1571 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1572 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1574 /* FIXME: when should these messages be sent? */
1575 data_row = MSI_CreateRecord(3);
1576 if (!data_row)
1577 return ERROR_OUTOFMEMORY;
1578 MSI_RecordSetStringW(data_row, 0, NULL);
1579 MSI_RecordSetInteger(data_row, 1, 0);
1580 MSI_RecordSetInteger(data_row, 2, package->num_langids ? package->langids[0] : 0);
1581 MSI_RecordSetInteger(data_row, 3, msi_get_string_table_codepage(package->db->strings));
1582 MSI_ProcessMessageVerbatim(package, INSTALLMESSAGE_COMMONDATA, data_row);
1584 info_row = MSI_CreateRecord(0);
1585 if (!info_row)
1587 msiobj_release(&data_row->hdr);
1588 return ERROR_OUTOFMEMORY;
1590 info_template = msi_get_error_message(package->db, MSIERR_INFO_LOGGINGSTART);
1591 MSI_RecordSetStringW(info_row, 0, info_template);
1592 msi_free(info_template);
1593 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO|MB_ICONHAND, info_row);
1595 MSI_ProcessMessage(package, INSTALLMESSAGE_COMMONDATA, data_row);
1597 productname = msi_dup_property(package->db, INSTALLPROPERTY_PRODUCTNAMEW);
1598 MSI_RecordSetInteger(data_row, 1, 1);
1599 MSI_RecordSetStringW(data_row, 2, productname);
1600 MSI_RecordSetStringW(data_row, 3, NULL);
1601 MSI_ProcessMessage(package, INSTALLMESSAGE_COMMONDATA, data_row);
1603 msi_free(productname);
1604 msiobj_release(&info_row->hdr);
1605 msiobj_release(&data_row->hdr);
1607 *pPackage = package;
1608 return ERROR_SUCCESS;
1611 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1613 MSIPACKAGE *package = NULL;
1614 UINT ret;
1616 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1618 if( !szPackage || !phPackage )
1619 return ERROR_INVALID_PARAMETER;
1621 if ( !*szPackage )
1623 FIXME("Should create an empty database and package\n");
1624 return ERROR_FUNCTION_FAILED;
1627 if( dwOptions )
1628 FIXME("dwOptions %08x not supported\n", dwOptions);
1630 ret = MSI_OpenPackageW( szPackage, &package );
1631 if( ret == ERROR_SUCCESS )
1633 *phPackage = alloc_msihandle( &package->hdr );
1634 if (! *phPackage)
1635 ret = ERROR_NOT_ENOUGH_MEMORY;
1636 msiobj_release( &package->hdr );
1638 else
1639 MSI_ProcessMessage(NULL, INSTALLMESSAGE_TERMINATE, 0);
1641 return ret;
1644 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1646 return MsiOpenPackageExW( szPackage, 0, phPackage );
1649 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1651 LPWSTR szwPack = NULL;
1652 UINT ret;
1654 if( szPackage )
1656 szwPack = strdupAtoW( szPackage );
1657 if( !szwPack )
1658 return ERROR_OUTOFMEMORY;
1661 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1663 msi_free( szwPack );
1665 return ret;
1668 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1670 return MsiOpenPackageExA( szPackage, 0, phPackage );
1673 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1675 MSIPACKAGE *package;
1676 MSIHANDLE handle = 0;
1677 MSIHANDLE remote;
1679 TRACE("(%d)\n",hInstall);
1681 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1682 if( package)
1684 handle = alloc_msihandle( &package->db->hdr );
1685 msiobj_release( &package->hdr );
1687 else if ((remote = msi_get_remote(hInstall)))
1689 handle = remote_GetActiveDatabase(remote);
1690 handle = alloc_msi_remote_handle(handle);
1693 return handle;
1696 static INT internal_ui_handler(MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record, LPCWSTR message)
1698 static const WCHAR szActionData[] = {'A','c','t','i','o','n','D','a','t','a',0};
1699 static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0};
1700 static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1701 static const WCHAR szWindows_Installer[] =
1702 {'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0};
1704 if (!package || (package->ui_level & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE)
1705 return 0;
1707 /* todo: check if message needs additional styles (topmost/foreground/modality?) */
1709 switch (eMessageType & 0xff000000)
1711 case INSTALLMESSAGE_FATALEXIT:
1712 case INSTALLMESSAGE_ERROR:
1713 case INSTALLMESSAGE_OUTOFDISKSPACE:
1714 if (package->ui_level & INSTALLUILEVEL_PROGRESSONLY) return 0;
1715 if (!(eMessageType & MB_ICONMASK))
1716 eMessageType |= MB_ICONEXCLAMATION;
1717 return MessageBoxW(gUIhwnd, message, szWindows_Installer, eMessageType & 0x00ffffff);
1718 case INSTALLMESSAGE_WARNING:
1719 if (package->ui_level & INSTALLUILEVEL_PROGRESSONLY) return 0;
1720 if (!(eMessageType & MB_ICONMASK))
1721 eMessageType |= MB_ICONASTERISK;
1722 return MessageBoxW(gUIhwnd, message, szWindows_Installer, eMessageType & 0x00ffffff);
1723 case INSTALLMESSAGE_USER:
1724 if (package->ui_level & INSTALLUILEVEL_PROGRESSONLY) return 0;
1725 if (!(eMessageType & MB_ICONMASK))
1726 eMessageType |= MB_USERICON;
1727 return MessageBoxW(gUIhwnd, message, szWindows_Installer, eMessageType & 0x00ffffff);
1728 case INSTALLMESSAGE_INFO:
1729 case INSTALLMESSAGE_INITIALIZE:
1730 case INSTALLMESSAGE_TERMINATE:
1731 case INSTALLMESSAGE_INSTALLSTART:
1732 case INSTALLMESSAGE_INSTALLEND:
1733 return 0;
1734 case INSTALLMESSAGE_SHOWDIALOG:
1736 LPWSTR dialog = msi_dup_record_field(record, 0);
1737 INT rc = ACTION_DialogBox(package, dialog);
1738 msi_free(dialog);
1739 return rc;
1741 case INSTALLMESSAGE_ACTIONSTART:
1743 LPWSTR deformatted;
1744 MSIRECORD *uirow = MSI_CreateRecord(1);
1745 if (!uirow) return -1;
1746 deformat_string(package, MSI_RecordGetString(record, 2), &deformatted);
1747 MSI_RecordSetStringW(uirow, 1, deformatted);
1748 msi_event_fire(package, szActionText, uirow);
1750 msi_free(deformatted);
1751 msiobj_release(&uirow->hdr);
1752 return 1;
1754 case INSTALLMESSAGE_ACTIONDATA:
1756 MSIRECORD *uirow = MSI_CreateRecord(1);
1757 if (!uirow) return -1;
1758 MSI_RecordSetStringW(uirow, 1, message);
1759 msi_event_fire(package, szActionData, uirow);
1760 msiobj_release(&uirow->hdr);
1762 if (package->action_progress_increment)
1764 uirow = MSI_CreateRecord(2);
1765 if (!uirow) return -1;
1766 MSI_RecordSetInteger(uirow, 1, 2);
1767 MSI_RecordSetInteger(uirow, 2, package->action_progress_increment);
1768 msi_event_fire(package, szSetProgress, uirow);
1769 msiobj_release(&uirow->hdr);
1771 return 1;
1773 case INSTALLMESSAGE_PROGRESS:
1774 msi_event_fire(package, szSetProgress, record);
1775 return 1;
1776 case INSTALLMESSAGE_COMMONDATA:
1777 switch (MSI_RecordGetInteger(record, 1))
1779 case 0:
1780 case 1:
1781 /* do nothing */
1782 return 0;
1783 default:
1784 /* fall through */
1787 default:
1788 FIXME("internal UI not implemented for message 0x%08x (UI level = %x)\n", eMessageType, package->ui_level);
1789 return 0;
1793 static const WCHAR szActionNotFound[] = {'D','E','B','U','G',':',' ','E','r','r','o','r',' ','[','1',']',':',' ',' ','A','c','t','i','o','n',' ','n','o','t',' ','f','o','u','n','d',':',' ','[','2',']',0};
1795 static const struct
1797 int id;
1798 const WCHAR *text;
1800 internal_errors[] =
1802 {2726, szActionNotFound},
1806 static LPCWSTR get_internal_error_message(int error)
1808 int i = 0;
1810 while (internal_errors[i].id != 0)
1812 if (internal_errors[i].id == error)
1813 return internal_errors[i].text;
1814 i++;
1817 FIXME("missing error message %d\n", error);
1818 return NULL;
1821 /* Returned string must be freed */
1822 LPWSTR msi_get_error_message(MSIDATABASE *db, int error)
1824 static const WCHAR query[] =
1825 {'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1826 'F','R','O','M',' ','`','E','r','r','o','r','`',' ','W','H','E','R','E',' ',
1827 '`','E','r','r','o','r','`',' ','=',' ','%','i',0};
1828 MSIRECORD *record;
1829 LPWSTR ret = NULL;
1831 if ((record = MSI_QueryGetRecord(db, query, error)))
1833 ret = msi_dup_record_field(record, 1);
1834 msiobj_release(&record->hdr);
1836 else if (error < 2000)
1838 int len = LoadStringW(msi_hInstance, IDS_ERROR_BASE + error, (LPWSTR) &ret, 0);
1839 if (len)
1841 ret = msi_alloc((len + 1) * sizeof(WCHAR));
1842 LoadStringW(msi_hInstance, IDS_ERROR_BASE + error, ret, len + 1);
1844 else
1845 ret = NULL;
1848 return ret;
1851 INT MSI_ProcessMessageVerbatim(MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record)
1853 LPWSTR message = {0};
1854 DWORD len;
1855 DWORD log_type = 1 << (eMessageType >> 24);
1856 UINT res;
1857 INT rc = 0;
1858 char *msg;
1860 TRACE("%x\n", eMessageType);
1861 if (TRACE_ON(msi)) dump_record(record);
1863 if (!package || !record)
1864 message = NULL;
1865 else {
1866 res = MSI_FormatRecordW(package, record, message, &len);
1867 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1868 return res;
1869 len++;
1870 message = msi_alloc(len * sizeof(WCHAR));
1871 if (!message) return ERROR_OUTOFMEMORY;
1872 MSI_FormatRecordW(package, record, message, &len);
1875 /* convert it to ASCII */
1876 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1877 msg = msi_alloc( len );
1878 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1880 if (gUIHandlerRecord && (gUIFilterRecord & log_type))
1882 MSIHANDLE rec = alloc_msihandle(&record->hdr);
1883 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, hRecord=%u)\n",
1884 gUIHandlerRecord, gUIContextRecord, eMessageType, rec);
1885 rc = gUIHandlerRecord( gUIContextRecord, eMessageType, rec );
1886 MsiCloseHandle( rec );
1888 if (!rc && gUIHandlerW && (gUIFilter & log_type))
1890 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1891 gUIHandlerW, gUIContext, eMessageType, debugstr_w(message));
1892 rc = gUIHandlerW( gUIContext, eMessageType, message );
1894 else if (!rc && gUIHandlerA && (gUIFilter & log_type))
1896 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1897 gUIHandlerA, gUIContext, eMessageType, debugstr_a(msg));
1898 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1901 if (!rc)
1902 rc = internal_ui_handler(package, eMessageType, record, message);
1904 if (!rc && package && package->log_file != INVALID_HANDLE_VALUE &&
1905 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1907 DWORD written;
1908 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1909 WriteFile( package->log_file, "\n", 1, &written, NULL );
1911 msi_free( msg );
1912 msi_free( message );
1914 return rc;
1917 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1919 switch (eMessageType & 0xff000000)
1921 case INSTALLMESSAGE_FATALEXIT:
1922 case INSTALLMESSAGE_ERROR:
1923 case INSTALLMESSAGE_WARNING:
1924 case INSTALLMESSAGE_USER:
1925 case INSTALLMESSAGE_INFO:
1926 case INSTALLMESSAGE_OUTOFDISKSPACE:
1927 if (MSI_RecordGetInteger(record, 1) != MSI_NULL_INTEGER)
1929 /* error message */
1931 LPWSTR template;
1932 LPWSTR template_rec = NULL, template_prefix = NULL;
1933 int error = MSI_RecordGetInteger(record, 1);
1935 if (MSI_RecordIsNull(record, 0))
1937 if (error >= 32)
1939 template_rec = msi_get_error_message(package->db, error);
1941 if (!template_rec && error >= 2000)
1943 /* internal error, not localized */
1944 if ((template_rec = (LPWSTR) get_internal_error_message(error)))
1946 MSI_RecordSetStringW(record, 0, template_rec);
1947 MSI_ProcessMessageVerbatim(package, INSTALLMESSAGE_INFO, record);
1949 template_rec = msi_get_error_message(package->db, MSIERR_INSTALLERROR);
1950 MSI_RecordSetStringW(record, 0, template_rec);
1951 MSI_ProcessMessageVerbatim(package, eMessageType, record);
1952 msi_free(template_rec);
1953 return 0;
1957 else
1958 template_rec = msi_dup_record_field(record, 0);
1960 template_prefix = msi_get_error_message(package->db, eMessageType >> 24);
1961 if (!template_prefix) template_prefix = strdupW(szEmpty);
1963 if (!template_rec)
1965 /* always returns 0 */
1966 MSI_RecordSetStringW(record, 0, template_prefix);
1967 MSI_ProcessMessageVerbatim(package, eMessageType, record);
1968 msi_free(template_prefix);
1969 return 0;
1972 template = msi_alloc((strlenW(template_rec) + strlenW(template_prefix) + 1) * sizeof(WCHAR));
1973 if (!template) return ERROR_OUTOFMEMORY;
1975 strcpyW(template, template_prefix);
1976 strcatW(template, template_rec);
1977 MSI_RecordSetStringW(record, 0, template);
1979 msi_free(template_prefix);
1980 msi_free(template_rec);
1981 msi_free(template);
1983 break;
1984 case INSTALLMESSAGE_ACTIONSTART:
1986 WCHAR *template = msi_get_error_message(package->db, MSIERR_ACTIONSTART);
1987 MSI_RecordSetStringW(record, 0, template);
1988 msi_free(template);
1990 msi_free(package->LastAction);
1991 msi_free(package->LastActionTemplate);
1992 package->LastAction = msi_dup_record_field(record, 1);
1993 if (!package->LastAction) package->LastAction = strdupW(szEmpty);
1994 package->LastActionTemplate = msi_dup_record_field(record, 3);
1995 break;
1997 case INSTALLMESSAGE_ACTIONDATA:
1998 if (package->LastAction && package->LastActionTemplate)
2000 static const WCHAR template_s[] =
2001 {'{','{','%','s',':',' ','}','}','%','s',0};
2002 WCHAR *template;
2004 template = msi_alloc((strlenW(package->LastAction) + strlenW(package->LastActionTemplate) + 7) * sizeof(WCHAR));
2005 if (!template) return ERROR_OUTOFMEMORY;
2006 sprintfW(template, template_s, package->LastAction, package->LastActionTemplate);
2007 MSI_RecordSetStringW(record, 0, template);
2008 msi_free(template);
2010 break;
2011 case INSTALLMESSAGE_COMMONDATA:
2013 WCHAR *template = msi_get_error_message(package->db, MSIERR_COMMONDATA);
2014 MSI_RecordSetStringW(record, 0, template);
2015 msi_free(template);
2017 break;
2020 return MSI_ProcessMessageVerbatim(package, eMessageType, record);
2023 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
2024 MSIHANDLE hRecord)
2026 UINT ret = ERROR_INVALID_HANDLE;
2027 MSIPACKAGE *package = NULL;
2028 MSIRECORD *record = NULL;
2030 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INITIALIZE ||
2031 (eMessageType & 0xff000000) == INSTALLMESSAGE_TERMINATE)
2032 return -1;
2034 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA &&
2035 MsiRecordGetInteger(hRecord, 1) != 2)
2036 return -1;
2038 record = msihandle2msiinfo(hRecord, MSIHANDLETYPE_RECORD);
2039 if (!record)
2040 return ERROR_INVALID_HANDLE;
2042 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
2043 if( !package )
2045 MSIHANDLE remote;
2047 if (!(remote = msi_get_remote(hInstall)))
2048 return ERROR_INVALID_HANDLE;
2050 ret = remote_ProcessMessage(remote, eMessageType, (struct wire_record *)&record->count);
2052 msiobj_release(&record->hdr);
2053 return ret;
2056 ret = MSI_ProcessMessage( package, eMessageType, record );
2058 msiobj_release( &package->hdr );
2059 return ret;
2062 /* property code */
2064 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
2066 LPWSTR szwName = NULL, szwValue = NULL;
2067 UINT r = ERROR_OUTOFMEMORY;
2069 szwName = strdupAtoW( szName );
2070 if( szName && !szwName )
2071 goto end;
2073 szwValue = strdupAtoW( szValue );
2074 if( szValue && !szwValue )
2075 goto end;
2077 r = MsiSetPropertyW( hInstall, szwName, szwValue);
2079 end:
2080 msi_free( szwName );
2081 msi_free( szwValue );
2083 return r;
2086 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
2088 MSIFOLDER *folder;
2090 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
2092 if ( source )
2094 msi_free( folder->ResolvedSource );
2095 folder->ResolvedSource = NULL;
2097 else
2099 msi_free( folder->ResolvedTarget );
2100 folder->ResolvedTarget = NULL;
2105 UINT msi_set_property( MSIDATABASE *db, const WCHAR *name, const WCHAR *value, int len )
2107 static const WCHAR insert_query[] = {
2108 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2109 '`','_','P','r','o','p','e','r','t','y','`',' ',
2110 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2111 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2112 static const WCHAR update_query[] = {
2113 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2114 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2115 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2116 static const WCHAR delete_query[] = {
2117 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2118 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2119 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2120 MSIQUERY *view;
2121 MSIRECORD *row = NULL;
2122 DWORD sz = 0;
2123 WCHAR query[1024];
2124 UINT rc;
2126 TRACE("%p %s %s %d\n", db, debugstr_w(name), debugstr_wn(value, len), len);
2128 if (!name)
2129 return ERROR_INVALID_PARAMETER;
2131 /* this one is weird... */
2132 if (!name[0])
2133 return value ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2135 if (value && len < 0) len = strlenW( value );
2137 rc = msi_get_property( db, name, 0, &sz );
2138 if (!value || (!*value && !len))
2140 sprintfW( query, delete_query, name );
2142 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2144 sprintfW( query, update_query, name );
2145 row = MSI_CreateRecord(1);
2146 msi_record_set_string( row, 1, value, len );
2148 else
2150 strcpyW( query, insert_query );
2151 row = MSI_CreateRecord(2);
2152 msi_record_set_string( row, 1, name, -1 );
2153 msi_record_set_string( row, 2, value, len );
2156 rc = MSI_DatabaseOpenViewW(db, query, &view);
2157 if (rc == ERROR_SUCCESS)
2159 rc = MSI_ViewExecute(view, row);
2160 MSI_ViewClose(view);
2161 msiobj_release(&view->hdr);
2163 if (row) msiobj_release(&row->hdr);
2164 return rc;
2167 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2169 MSIPACKAGE *package;
2170 UINT ret;
2172 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2173 if( !package )
2175 MSIHANDLE remote;
2177 if (!(remote = msi_get_remote(hInstall)))
2178 return ERROR_INVALID_HANDLE;
2180 return remote_SetProperty(remote, szName, szValue);
2183 ret = msi_set_property( package->db, szName, szValue, -1 );
2184 if (ret == ERROR_SUCCESS && !strcmpW( szName, szSourceDir ))
2185 msi_reset_folders( package, TRUE );
2187 msiobj_release( &package->hdr );
2188 return ret;
2191 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2193 static const WCHAR query[]= {
2194 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2195 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2196 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2197 MSIRECORD *rec, *row = NULL;
2198 MSIQUERY *view;
2199 UINT r;
2201 static const WCHAR szDate[] = {'D','a','t','e',0};
2202 static const WCHAR szTime[] = {'T','i','m','e',0};
2203 WCHAR *buffer;
2204 int length;
2206 if (!name || !*name)
2207 return NULL;
2209 if (!strcmpW(name, szDate))
2211 length = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, NULL, 0);
2212 if (!length)
2213 return NULL;
2214 buffer = msi_alloc(length * sizeof(WCHAR));
2215 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, buffer, length);
2217 row = MSI_CreateRecord(1);
2218 if (!row)
2220 msi_free(buffer);
2221 return NULL;
2223 MSI_RecordSetStringW(row, 1, buffer);
2224 msi_free(buffer);
2225 return row;
2227 else if (!strcmpW(name, szTime))
2229 length = GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER, NULL, NULL, NULL, 0);
2230 if (!length)
2231 return NULL;
2232 buffer = msi_alloc(length * sizeof(WCHAR));
2233 GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER, NULL, NULL, buffer, length);
2235 row = MSI_CreateRecord(1);
2236 if (!row)
2238 msi_free(buffer);
2239 return NULL;
2241 MSI_RecordSetStringW(row, 1, buffer);
2242 msi_free(buffer);
2243 return row;
2246 rec = MSI_CreateRecord(1);
2247 if (!rec)
2248 return NULL;
2250 MSI_RecordSetStringW(rec, 1, name);
2252 r = MSI_DatabaseOpenViewW(db, query, &view);
2253 if (r == ERROR_SUCCESS)
2255 MSI_ViewExecute(view, rec);
2256 MSI_ViewFetch(view, &row);
2257 MSI_ViewClose(view);
2258 msiobj_release(&view->hdr);
2260 msiobj_release(&rec->hdr);
2261 return row;
2264 /* internal function, not compatible with MsiGetPropertyW */
2265 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2266 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2268 MSIRECORD *row;
2269 UINT rc = ERROR_FUNCTION_FAILED;
2271 TRACE("%p %s %p %p\n", db, debugstr_w(szName), szValueBuf, pchValueBuf);
2273 row = msi_get_property_row( db, szName );
2275 if (*pchValueBuf > 0)
2276 szValueBuf[0] = 0;
2278 if (row)
2280 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2281 msiobj_release(&row->hdr);
2284 if (rc == ERROR_SUCCESS)
2285 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf, *pchValueBuf),
2286 debugstr_w(szName));
2287 else if (rc == ERROR_MORE_DATA)
2288 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2289 debugstr_w(szName));
2290 else
2292 *pchValueBuf = 0;
2293 TRACE("property %s not found\n", debugstr_w(szName));
2296 return rc;
2299 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2301 DWORD sz = 0;
2302 LPWSTR str;
2303 UINT r;
2305 r = msi_get_property(db, prop, NULL, &sz);
2306 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2307 return NULL;
2309 sz++;
2310 str = msi_alloc(sz * sizeof(WCHAR));
2311 r = msi_get_property(db, prop, str, &sz);
2312 if (r != ERROR_SUCCESS)
2314 msi_free(str);
2315 str = NULL;
2318 return str;
2321 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2323 LPWSTR str = msi_dup_property( db, prop );
2324 int val = str ? atoiW(str) : def;
2325 msi_free(str);
2326 return val;
2329 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2330 awstring *szValueBuf, LPDWORD pchValueBuf )
2332 MSIPACKAGE *package;
2333 MSIRECORD *row = NULL;
2334 UINT r = ERROR_FUNCTION_FAILED;
2335 LPCWSTR val = NULL;
2336 DWORD len = 0;
2338 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2339 szValueBuf->str.w, pchValueBuf );
2341 if (!name)
2342 return ERROR_INVALID_PARAMETER;
2344 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2345 if (!package)
2347 LPWSTR value = NULL, buffer;
2348 MSIHANDLE remote;
2350 if (!(remote = msi_get_remote(handle)))
2351 return ERROR_INVALID_HANDLE;
2353 r = remote_GetProperty(remote, name, &value, &len);
2354 if (r != ERROR_SUCCESS)
2355 return r;
2357 /* String might contain embedded nulls.
2358 * Native returns the correct size but truncates the string. */
2359 buffer = heap_alloc_zero((len + 1) * sizeof(WCHAR));
2360 if (!buffer)
2362 midl_user_free(value);
2363 return ERROR_OUTOFMEMORY;
2365 strcpyW(buffer, value);
2367 r = msi_strcpy_to_awstring(buffer, len, szValueBuf, pchValueBuf);
2369 /* Bug required by Adobe installers */
2370 if (pchValueBuf && !szValueBuf->unicode && !szValueBuf->str.a)
2371 *pchValueBuf *= sizeof(WCHAR);
2373 heap_free(buffer);
2374 midl_user_free(value);
2375 return r;
2378 row = msi_get_property_row( package->db, name );
2379 if (row)
2380 val = msi_record_get_string( row, 1, (int *)&len );
2382 if (!val)
2383 val = szEmpty;
2385 r = msi_strcpy_to_awstring( val, len, szValueBuf, pchValueBuf );
2387 if (row)
2388 msiobj_release( &row->hdr );
2389 msiobj_release( &package->hdr );
2391 return r;
2394 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2395 LPSTR szValueBuf, LPDWORD pchValueBuf )
2397 awstring val;
2398 LPWSTR name;
2399 UINT r;
2401 val.unicode = FALSE;
2402 val.str.a = szValueBuf;
2404 name = strdupAtoW( szName );
2405 if (szName && !name)
2406 return ERROR_OUTOFMEMORY;
2408 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2409 msi_free( name );
2410 return r;
2413 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2414 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2416 awstring val;
2418 val.unicode = TRUE;
2419 val.str.w = szValueBuf;
2421 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2424 MSIHANDLE __cdecl remote_GetActiveDatabase(MSIHANDLE hinst)
2426 return MsiGetActiveDatabase(hinst);
2429 UINT __cdecl remote_GetProperty(MSIHANDLE hinst, LPCWSTR property, LPWSTR *value, DWORD *size)
2431 WCHAR empty[1];
2432 UINT r;
2434 *size = 0;
2435 r = MsiGetPropertyW(hinst, property, empty, size);
2436 if (r == ERROR_MORE_DATA)
2438 ++*size;
2439 *value = midl_user_allocate(*size * sizeof(WCHAR));
2440 if (!*value)
2441 return ERROR_OUTOFMEMORY;
2442 r = MsiGetPropertyW(hinst, property, *value, size);
2444 return r;
2447 UINT __cdecl remote_SetProperty(MSIHANDLE hinst, LPCWSTR property, LPCWSTR value)
2449 return MsiSetPropertyW(hinst, property, value);
2452 int __cdecl remote_ProcessMessage(MSIHANDLE hinst, INSTALLMESSAGE message, struct wire_record *remote_rec)
2454 MSIHANDLE rec;
2455 int ret;
2456 UINT r;
2458 if ((r = unmarshal_record(remote_rec, &rec)))
2459 return r;
2461 ret = MsiProcessMessage(hinst, message, rec);
2463 MsiCloseHandle(rec);
2464 return ret;
2467 UINT __cdecl remote_DoAction(MSIHANDLE hinst, LPCWSTR action)
2469 return MsiDoActionW(hinst, action);
2472 UINT __cdecl remote_Sequence(MSIHANDLE hinst, LPCWSTR table, int sequence)
2474 return MsiSequenceW(hinst, table, sequence);
2477 UINT __cdecl remote_GetTargetPath(MSIHANDLE hinst, LPCWSTR folder, LPWSTR *value)
2479 WCHAR empty[1];
2480 DWORD size = 0;
2481 UINT r;
2483 r = MsiGetTargetPathW(hinst, folder, empty, &size);
2484 if (r == ERROR_MORE_DATA)
2486 *value = midl_user_allocate(++size * sizeof(WCHAR));
2487 if (!*value)
2488 return ERROR_OUTOFMEMORY;
2489 r = MsiGetTargetPathW(hinst, folder, *value, &size);
2491 return r;
2494 UINT __cdecl remote_SetTargetPath(MSIHANDLE hinst, LPCWSTR folder, LPCWSTR value)
2496 return MsiSetTargetPathW(hinst, folder, value);
2499 UINT __cdecl remote_GetSourcePath(MSIHANDLE hinst, LPCWSTR folder, LPWSTR *value)
2501 WCHAR empty[1];
2502 DWORD size = 1;
2503 UINT r;
2505 r = MsiGetSourcePathW(hinst, folder, empty, &size);
2506 if (r == ERROR_MORE_DATA)
2508 *value = midl_user_allocate(++size * sizeof(WCHAR));
2509 if (!*value)
2510 return ERROR_OUTOFMEMORY;
2511 r = MsiGetSourcePathW(hinst, folder, *value, &size);
2513 return r;
2516 HRESULT __cdecl remote_GetMode(MSIHANDLE hinst, MSIRUNMODE mode, BOOL *ret)
2518 *ret = MsiGetMode(hinst, mode);
2519 return S_OK;
2522 HRESULT __cdecl remote_SetMode(MSIHANDLE hinst, MSIRUNMODE mode, BOOL state)
2524 UINT r = MsiSetMode(hinst, mode, state);
2525 return HRESULT_FROM_WIN32(r);
2528 HRESULT __cdecl remote_GetFeatureState(MSIHANDLE hinst, BSTR feature,
2529 INSTALLSTATE *installed, INSTALLSTATE *action)
2531 UINT r = MsiGetFeatureStateW(hinst, feature, installed, action);
2532 return HRESULT_FROM_WIN32(r);
2535 HRESULT __cdecl remote_SetFeatureState(MSIHANDLE hinst, BSTR feature, INSTALLSTATE state)
2537 UINT r = MsiSetFeatureStateW(hinst, feature, state);
2538 return HRESULT_FROM_WIN32(r);
2541 HRESULT __cdecl remote_GetComponentState(MSIHANDLE hinst, BSTR component,
2542 INSTALLSTATE *installed, INSTALLSTATE *action)
2544 UINT r = MsiGetComponentStateW(hinst, component, installed, action);
2545 return HRESULT_FROM_WIN32(r);
2548 HRESULT __cdecl remote_SetComponentState(MSIHANDLE hinst, BSTR component, INSTALLSTATE state)
2550 UINT r = MsiSetComponentStateW(hinst, component, state);
2551 return HRESULT_FROM_WIN32(r);
2554 HRESULT __cdecl remote_GetLanguage(MSIHANDLE hinst, LANGID *language)
2556 *language = MsiGetLanguage(hinst);
2557 return S_OK;
2560 HRESULT __cdecl remote_SetInstallLevel(MSIHANDLE hinst, int level)
2562 UINT r = MsiSetInstallLevel(hinst, level);
2563 return HRESULT_FROM_WIN32(r);
2566 HRESULT __cdecl remote_FormatRecord(MSIHANDLE hinst, MSIHANDLE record,
2567 BSTR *value)
2569 DWORD size = 0;
2570 UINT r = MsiFormatRecordW(hinst, record, NULL, &size);
2571 if (r == ERROR_SUCCESS)
2573 *value = SysAllocStringLen(NULL, size);
2574 if (!*value)
2575 return E_OUTOFMEMORY;
2576 size++;
2577 r = MsiFormatRecordW(hinst, record, *value, &size);
2579 return HRESULT_FROM_WIN32(r);
2582 HRESULT __cdecl remote_EvaluateCondition(MSIHANDLE hinst, BSTR condition)
2584 UINT r = MsiEvaluateConditionW(hinst, condition);
2585 return HRESULT_FROM_WIN32(r);
2588 HRESULT __cdecl remote_GetFeatureCost(MSIHANDLE hinst, BSTR feature,
2589 INT cost_tree, INSTALLSTATE state, INT *cost)
2591 UINT r = MsiGetFeatureCostW(hinst, feature, cost_tree, state, cost);
2592 return HRESULT_FROM_WIN32(r);
2595 HRESULT __cdecl remote_EnumComponentCosts(MSIHANDLE hinst, BSTR component,
2596 DWORD index, INSTALLSTATE state, BSTR drive,
2597 DWORD *buflen, INT *cost, INT *temp)
2599 UINT r = MsiEnumComponentCostsW(hinst, component, index, state, drive, buflen, cost, temp);
2600 return HRESULT_FROM_WIN32(r);
2603 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2604 LPCWSTR property, LPWSTR value)
2606 MSISOURCELISTINFO *info;
2608 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2610 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2613 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2614 if (!info)
2615 return ERROR_OUTOFMEMORY;
2617 info->context = context;
2618 info->options = options;
2619 info->property = property;
2620 info->value = strdupW(value);
2621 list_add_head(&package->sourcelist_info, &info->entry);
2623 return ERROR_SUCCESS;
2626 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2627 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2629 MSIMEDIADISK *disk;
2631 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2633 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2636 disk = msi_alloc(sizeof(MSIMEDIADISK));
2637 if (!disk)
2638 return ERROR_OUTOFMEMORY;
2640 disk->context = context;
2641 disk->options = options;
2642 disk->disk_id = disk_id;
2643 disk->volume_label = strdupW(volume_label);
2644 disk->disk_prompt = strdupW(disk_prompt);
2645 list_add_head(&package->sourcelist_media, &disk->entry);
2647 return ERROR_SUCCESS;