setupapi: Add stub for CM_Get_Device_Interface_Alias{A,W}.
[wine.git] / dlls / msi / package.c
blob7b64362b10dceeed99ad0b7a3929e6aab2014d38
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 "winternl.h"
31 #include "shlwapi.h"
32 #include "wingdi.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 "objbase.h"
43 #include "msidefs.h"
44 #include "sddl.h"
46 #include "wine/heap.h"
47 #include "wine/debug.h"
48 #include "wine/exception.h"
50 #include "msipriv.h"
51 #include "winemsi.h"
52 #include "resource.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(msi);
56 static void free_feature( MSIFEATURE *feature )
58 struct list *item, *cursor;
60 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
62 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
63 list_remove( &fl->entry );
64 msi_free( fl );
67 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
69 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
70 list_remove( &cl->entry );
71 msi_free( cl );
73 msi_free( feature->Feature );
74 msi_free( feature->Feature_Parent );
75 msi_free( feature->Directory );
76 msi_free( feature->Description );
77 msi_free( feature->Title );
78 msi_free( feature );
81 static void free_folder( MSIFOLDER *folder )
83 struct list *item, *cursor;
85 LIST_FOR_EACH_SAFE( item, cursor, &folder->children )
87 FolderList *fl = LIST_ENTRY( item, FolderList, entry );
88 list_remove( &fl->entry );
89 msi_free( fl );
91 msi_free( folder->Parent );
92 msi_free( folder->Directory );
93 msi_free( folder->TargetDefault );
94 msi_free( folder->SourceLongPath );
95 msi_free( folder->SourceShortPath );
96 msi_free( folder->ResolvedTarget );
97 msi_free( folder->ResolvedSource );
98 msi_free( folder );
101 static void free_extension( MSIEXTENSION *ext )
103 struct list *item, *cursor;
105 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
107 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
109 list_remove( &verb->entry );
110 msi_free( verb->Verb );
111 msi_free( verb->Command );
112 msi_free( verb->Argument );
113 msi_free( verb );
116 msi_free( ext->Extension );
117 msi_free( ext->ProgIDText );
118 msi_free( ext );
121 static void free_assembly( MSIASSEMBLY *assembly )
123 msi_free( assembly->feature );
124 msi_free( assembly->manifest );
125 msi_free( assembly->application );
126 msi_free( assembly->display_name );
127 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
128 msi_free( assembly->tempdir );
129 msi_free( assembly );
132 void msi_free_action_script( MSIPACKAGE *package, UINT script )
134 UINT i;
135 for (i = 0; i < package->script_actions_count[script]; i++)
136 msi_free( package->script_actions[script][i] );
138 msi_free( package->script_actions[script] );
139 package->script_actions[script] = NULL;
140 package->script_actions_count[script] = 0;
143 static void free_package_structures( MSIPACKAGE *package )
145 struct list *item, *cursor;
146 int i;
148 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
150 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
151 list_remove( &feature->entry );
152 free_feature( feature );
155 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
157 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
158 list_remove( &folder->entry );
159 free_folder( folder );
162 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
164 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
166 list_remove( &file->entry );
167 msi_free( file->File );
168 msi_free( file->FileName );
169 msi_free( file->ShortName );
170 msi_free( file->LongName );
171 msi_free( file->Version );
172 msi_free( file->Language );
173 if (msi_is_global_assembly( file->Component )) DeleteFileW( file->TargetPath );
174 msi_free( file->TargetPath );
175 msi_free( file );
178 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
180 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
182 list_remove( &comp->entry );
183 msi_free( comp->Component );
184 msi_free( comp->ComponentId );
185 msi_free( comp->Directory );
186 msi_free( comp->Condition );
187 msi_free( comp->KeyPath );
188 msi_free( comp->FullKeypath );
189 if (comp->assembly) free_assembly( comp->assembly );
190 msi_free( comp );
193 LIST_FOR_EACH_SAFE( item, cursor, &package->filepatches )
195 MSIFILEPATCH *patch = LIST_ENTRY( item, MSIFILEPATCH, entry );
197 list_remove( &patch->entry );
198 msi_free( patch->path );
199 msi_free( patch );
202 /* clean up extension, progid, class and verb structures */
203 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
205 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
207 list_remove( &cls->entry );
208 msi_free( cls->clsid );
209 msi_free( cls->Context );
210 msi_free( cls->Description );
211 msi_free( cls->FileTypeMask );
212 msi_free( cls->IconPath );
213 msi_free( cls->DefInprocHandler );
214 msi_free( cls->DefInprocHandler32 );
215 msi_free( cls->Argument );
216 msi_free( cls->ProgIDText );
217 msi_free( cls );
220 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
222 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
224 list_remove( &ext->entry );
225 free_extension( ext );
228 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
230 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
232 list_remove( &progid->entry );
233 msi_free( progid->ProgID );
234 msi_free( progid->Description );
235 msi_free( progid->IconPath );
236 msi_free( progid );
239 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
241 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
243 list_remove( &mt->entry );
244 msi_free( mt->suffix );
245 msi_free( mt->clsid );
246 msi_free( mt->ContentType );
247 msi_free( mt );
250 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
252 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
254 list_remove( &appid->entry );
255 msi_free( appid->AppID );
256 msi_free( appid->RemoteServerName );
257 msi_free( appid->LocalServer );
258 msi_free( appid->ServiceParameters );
259 msi_free( appid->DllSurrogate );
260 msi_free( appid );
263 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
265 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
267 list_remove( &info->entry );
268 msi_free( info->value );
269 msi_free( info );
272 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
274 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
276 list_remove( &info->entry );
277 msi_free( info->volume_label );
278 msi_free( info->disk_prompt );
279 msi_free( info );
282 for (i = 0; i < SCRIPT_MAX; i++)
283 msi_free_action_script( package, i );
285 for (i = 0; i < package->unique_actions_count; i++)
286 msi_free( package->unique_actions[i] );
287 msi_free( package->unique_actions);
289 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
291 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
293 list_remove( &binary->entry );
294 if (!DeleteFileW( binary->tmpfile ))
295 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
296 msi_free( binary->source );
297 msi_free( binary->tmpfile );
298 msi_free( binary );
301 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
303 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
305 list_remove( &cab->entry );
306 IStorage_Release( cab->storage );
307 msi_free( cab->stream );
308 msi_free( cab );
311 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
313 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
315 list_remove( &patch->entry );
316 if (patch->delete_on_close && !DeleteFileW( patch->localfile ))
318 ERR("failed to delete %s (%u)\n", debugstr_w(patch->localfile), GetLastError());
320 msi_free_patchinfo( patch );
323 msi_free( package->PackagePath );
324 msi_free( package->ProductCode );
325 msi_free( package->ActionFormat );
326 msi_free( package->LastAction );
327 msi_free( package->LastActionTemplate );
328 msi_free( package->langids );
330 /* cleanup control event subscriptions */
331 msi_event_cleanup_all_subscriptions( package );
334 static void MSI_FreePackage( MSIOBJECTHDR *arg)
336 MSIPACKAGE *package = (MSIPACKAGE *)arg;
338 msi_destroy_assembly_caches( package );
340 if( package->dialog )
341 msi_dialog_destroy( package->dialog );
343 msiobj_release( &package->db->hdr );
344 free_package_structures(package);
345 CloseHandle( package->log_file );
346 if (package->rpc_server_started)
347 RpcServerUnregisterIf(s_IWineMsiRemote_v0_0_s_ifspec, NULL, FALSE);
348 if (rpc_handle)
349 RpcBindingFree(&rpc_handle);
350 if (package->custom_server_32_process)
351 custom_stop_server(package->custom_server_32_process, package->custom_server_32_pipe);
352 if (package->custom_server_64_process)
353 custom_stop_server(package->custom_server_64_process, package->custom_server_64_pipe);
355 if (package->delete_on_close) DeleteFileW( package->localfile );
356 msi_free( package->localfile );
357 MSI_ProcessMessage(NULL, INSTALLMESSAGE_TERMINATE, 0);
360 static UINT create_temp_property_table(MSIPACKAGE *package)
362 static const WCHAR query[] = {
363 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
364 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
365 '`','_','P','r','o','p','e','r','t','y','`',' ',
366 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
367 'T','E','M','P','O','R','A','R','Y',',',' ',
368 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
369 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
370 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
371 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
372 MSIQUERY *view;
373 UINT rc;
375 rc = MSI_DatabaseOpenViewW(package->db, query, &view);
376 if (rc != ERROR_SUCCESS)
377 return rc;
379 rc = MSI_ViewExecute(view, 0);
380 MSI_ViewClose(view);
381 msiobj_release(&view->hdr);
382 return rc;
385 UINT msi_clone_properties( MSIDATABASE *db )
387 static const WCHAR query_select[] = {
388 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
389 '`','P','r','o','p','e','r','t','y','`',0};
390 static const WCHAR query_insert[] = {
391 'I','N','S','E','R','T',' ','I','N','T','O',' ',
392 '`','_','P','r','o','p','e','r','t','y','`',' ',
393 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
394 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
395 static const WCHAR query_update[] = {
396 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
397 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
398 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
399 MSIQUERY *view_select;
400 UINT rc;
402 rc = MSI_DatabaseOpenViewW( db, query_select, &view_select );
403 if (rc != ERROR_SUCCESS)
404 return rc;
406 rc = MSI_ViewExecute( view_select, 0 );
407 if (rc != ERROR_SUCCESS)
409 MSI_ViewClose( view_select );
410 msiobj_release( &view_select->hdr );
411 return rc;
414 while (1)
416 MSIQUERY *view_insert, *view_update;
417 MSIRECORD *rec_select;
419 rc = MSI_ViewFetch( view_select, &rec_select );
420 if (rc != ERROR_SUCCESS)
421 break;
423 rc = MSI_DatabaseOpenViewW( db, query_insert, &view_insert );
424 if (rc != ERROR_SUCCESS)
426 msiobj_release( &rec_select->hdr );
427 continue;
430 rc = MSI_ViewExecute( view_insert, rec_select );
431 MSI_ViewClose( view_insert );
432 msiobj_release( &view_insert->hdr );
433 if (rc != ERROR_SUCCESS)
435 MSIRECORD *rec_update;
437 TRACE("insert failed, trying update\n");
439 rc = MSI_DatabaseOpenViewW( db, query_update, &view_update );
440 if (rc != ERROR_SUCCESS)
442 WARN("open view failed %u\n", rc);
443 msiobj_release( &rec_select->hdr );
444 continue;
447 rec_update = MSI_CreateRecord( 2 );
448 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
449 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
450 rc = MSI_ViewExecute( view_update, rec_update );
451 if (rc != ERROR_SUCCESS)
452 WARN("update failed %u\n", rc);
454 MSI_ViewClose( view_update );
455 msiobj_release( &view_update->hdr );
456 msiobj_release( &rec_update->hdr );
459 msiobj_release( &rec_select->hdr );
462 MSI_ViewClose( view_select );
463 msiobj_release( &view_select->hdr );
464 return rc;
468 * set_installed_prop
470 * Sets the "Installed" property to indicate that
471 * the product is installed for the current user.
473 static UINT set_installed_prop( MSIPACKAGE *package )
475 HKEY hkey;
476 UINT r;
478 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
480 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
481 if (r == ERROR_SUCCESS)
483 RegCloseKey( hkey );
484 msi_set_property( package->db, szInstalled, szOne, -1 );
486 return r;
489 static UINT set_user_sid_prop( MSIPACKAGE *package )
491 SID_NAME_USE use;
492 LPWSTR user_name;
493 LPWSTR sid_str = NULL, dom = NULL;
494 DWORD size, dom_size;
495 PSID psid = NULL;
496 UINT r = ERROR_FUNCTION_FAILED;
498 size = 0;
499 GetUserNameW( NULL, &size );
501 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
502 if (!user_name)
503 return ERROR_OUTOFMEMORY;
505 if (!GetUserNameW( user_name, &size ))
506 goto done;
508 size = 0;
509 dom_size = 0;
510 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
512 psid = msi_alloc( size );
513 dom = msi_alloc( dom_size*sizeof (WCHAR) );
514 if (!psid || !dom)
516 r = ERROR_OUTOFMEMORY;
517 goto done;
520 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
521 goto done;
523 if (!ConvertSidToStringSidW( psid, &sid_str ))
524 goto done;
526 r = msi_set_property( package->db, szUserSID, sid_str, -1 );
528 done:
529 LocalFree( sid_str );
530 msi_free( dom );
531 msi_free( psid );
532 msi_free( user_name );
534 return r;
537 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
539 static const WCHAR fusion[] =
540 {'f','u','s','i','o','n','.','d','l','l',0};
541 static const WCHAR subkey[] =
542 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
543 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\','N','D','P',0};
544 static const WCHAR subdir[] =
545 {'M','i','c','r','o','s','o','f','t','.','N','E','T','\\','F','r','a','m','e','w','o','r','k','\\',0};
546 static const WCHAR v2050727[] =
547 {'v','2','.','0','.','5','0','7','2','7',0};
548 static const WCHAR v4client[] =
549 {'v','4','\\','C','l','i','e','n','t',0};
550 static const WCHAR installpath[] =
551 {'I','n','s','t','a','l','l','P','a','t','h',0};
552 HKEY netsetup, hkey;
553 LONG res;
554 DWORD size, len, type;
555 WCHAR windir[MAX_PATH], path[MAX_PATH], *filename = NULL;
557 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, subkey, 0, KEY_CREATE_SUB_KEY, &netsetup);
558 if (res != ERROR_SUCCESS)
559 return NULL;
561 if (!RegCreateKeyExW(netsetup, v4client, 0, NULL, 0, KEY_QUERY_VALUE, NULL, &hkey, NULL))
563 size = ARRAY_SIZE(path);
564 if (!RegQueryValueExW(hkey, installpath, NULL, &type, (BYTE *)path, &size))
566 len = lstrlenW(path) + lstrlenW(fusion) + 2;
567 if (!(filename = msi_alloc(len * sizeof(WCHAR)))) return NULL;
569 lstrcpyW(filename, path);
570 lstrcatW(filename, szBackSlash);
571 lstrcatW(filename, fusion);
572 if (GetFileAttributesW(filename) != INVALID_FILE_ATTRIBUTES)
574 TRACE( "found %s\n", debugstr_w(filename) );
575 RegCloseKey(hkey);
576 RegCloseKey(netsetup);
577 return filename;
580 RegCloseKey(hkey);
583 if (!RegCreateKeyExW(netsetup, v2050727, 0, NULL, 0, KEY_QUERY_VALUE, NULL, &hkey, NULL))
585 RegCloseKey(hkey);
586 GetWindowsDirectoryW(windir, MAX_PATH);
587 len = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(v2050727) + lstrlenW(fusion) + 3;
588 if (!(filename = msi_alloc(len * sizeof(WCHAR)))) return NULL;
590 lstrcpyW(filename, windir);
591 lstrcatW(filename, szBackSlash);
592 lstrcatW(filename, subdir);
593 lstrcatW(filename, v2050727);
594 lstrcatW(filename, szBackSlash);
595 lstrcatW(filename, fusion);
596 if (GetFileAttributesW(filename) != INVALID_FILE_ATTRIBUTES)
598 TRACE( "found %s\n", debugstr_w(filename) );
599 RegCloseKey(netsetup);
600 return filename;
604 RegCloseKey(netsetup);
605 return filename;
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 swprintf(buf, ARRAY_SIZE(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 RTL_OSVERSIONINFOEXW OSVersion;
673 MEMORYSTATUSEX msex;
674 DWORD verval, len, type;
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 LANGID langid;
682 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
683 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
684 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
685 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
686 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
687 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
688 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
689 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
690 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
691 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
692 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
693 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
694 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
695 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
696 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
697 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
698 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
699 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
700 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
701 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
702 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
703 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
704 static const WCHAR szFormat[] = {'%','u',0};
705 static const WCHAR szFormat2[] = {'%','u','.','%','u',0};
706 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
707 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
708 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
709 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
710 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
711 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
712 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
713 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
714 static const WCHAR szIntFormat[] = {'%','d',0};
715 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
716 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
717 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
718 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
719 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 };
720 static const WCHAR szProgramFilesDir[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
721 static const WCHAR szProgramFilesDirx86[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
722 static const WCHAR szCommonFilesDir[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0};
723 static const WCHAR szCommonFilesDirx86[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
724 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
725 static const WCHAR szUserInfo[] = {
726 'S','O','F','T','W','A','R','E','\\',
727 'M','i','c','r','o','s','o','f','t','\\',
728 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
729 'U','s','e','r',' ','I','n','f','o',0
731 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
732 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
733 static const WCHAR szCurrentVersion[] = {
734 'S','O','F','T','W','A','R','E','\\',
735 'M','i','c','r','o','s','o','f','t','\\',
736 'W','i','n','d','o','w','s','\\',
737 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
739 static const WCHAR szCurrentVersionNT[] = {
740 'S','O','F','T','W','A','R','E','\\',
741 'M','i','c','r','o','s','o','f','t','\\',
742 'W','i','n','d','o','w','s',' ','N','T','\\',
743 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
745 static const WCHAR szRegisteredOwner[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
746 static const WCHAR szRegisteredOrganization[] = {
747 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
749 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
750 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
751 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
752 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
753 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
754 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
755 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
756 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
757 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
758 static const WCHAR szComputerName[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
761 * Other things that probably should be set:
763 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
764 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
767 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
768 lstrcatW(pth, szBackSlash);
769 msi_set_property( package->db, szCommonAppDataFolder, pth, -1 );
771 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
772 lstrcatW(pth, szBackSlash);
773 msi_set_property( package->db, szFavoritesFolder, pth, -1 );
775 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
776 lstrcatW(pth, szBackSlash);
777 msi_set_property( package->db, szFontsFolder, pth, -1 );
779 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
780 lstrcatW(pth, szBackSlash);
781 msi_set_property( package->db, szSendToFolder, pth, -1 );
783 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
784 lstrcatW(pth, szBackSlash);
785 msi_set_property( package->db, szStartMenuFolder, pth, -1 );
787 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
788 lstrcatW(pth, szBackSlash);
789 msi_set_property( package->db, szStartupFolder, pth, -1 );
791 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
792 lstrcatW(pth, szBackSlash);
793 msi_set_property( package->db, szTemplateFolder, pth, -1 );
795 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
796 lstrcatW(pth, szBackSlash);
797 msi_set_property( package->db, szDesktopFolder, pth, -1 );
799 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
800 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
801 lstrcatW(pth, szBackSlash);
802 msi_set_property( package->db, szProgramMenuFolder, pth, -1 );
804 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
805 lstrcatW(pth, szBackSlash);
806 msi_set_property( package->db, szAdminToolsFolder, pth, -1 );
808 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
809 lstrcatW(pth, szBackSlash);
810 msi_set_property( package->db, szAppDataFolder, pth, -1 );
812 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
813 lstrcatW(pth, szBackSlash);
814 msi_set_property( package->db, szSystemFolder, pth, -1 );
815 msi_set_property( package->db, szSystem16Folder, pth, -1 );
817 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
818 lstrcatW(pth, szBackSlash);
819 msi_set_property( package->db, szLocalAppDataFolder, pth, -1 );
821 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
822 lstrcatW(pth, szBackSlash);
823 msi_set_property( package->db, szMyPicturesFolder, pth, -1 );
825 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
826 lstrcatW(pth, szBackSlash);
827 msi_set_property( package->db, szPersonalFolder, pth, -1 );
829 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
830 lstrcatW(pth, szBackSlash);
831 msi_set_property( package->db, szWindowsFolder, pth, -1 );
833 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
834 lstrcatW(pth, szBackSlash);
835 msi_set_property( package->db, szPrintHoodFolder, pth, -1 );
837 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
838 lstrcatW(pth, szBackSlash);
839 msi_set_property( package->db, szNetHoodFolder, pth, -1 );
841 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
842 lstrcatW(pth, szBackSlash);
843 msi_set_property( package->db, szRecentFolder, pth, -1 );
845 /* Physical Memory is specified in MB. Using total amount. */
846 msex.dwLength = sizeof(msex);
847 GlobalMemoryStatusEx( &msex );
848 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
849 msi_set_property( package->db, szPhysicalMemory, bufstr, len );
851 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
852 ptr = wcschr(pth,'\\');
853 if (ptr) *(ptr + 1) = 0;
854 msi_set_property( package->db, szWindowsVolume, pth, -1 );
856 len = GetTempPathW(MAX_PATH, pth);
857 msi_set_property( package->db, szTempFolder, pth, len );
859 /* in a wine environment the user is always admin and privileged */
860 msi_set_property( package->db, szAdminUser, szOne, -1 );
861 msi_set_property( package->db, szPrivileged, szOne, -1 );
863 /* set the os things */
864 OSVersion.dwOSVersionInfoSize = sizeof(OSVersion);
865 RtlGetVersion(&OSVersion);
866 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
867 if (verval > 603)
869 verval = 603;
870 OSVersion.dwBuildNumber = 9600;
872 len = swprintf( verstr, ARRAY_SIZE(verstr), szFormat, verval );
873 switch (OSVersion.dwPlatformId)
875 case VER_PLATFORM_WIN32_WINDOWS:
876 msi_set_property( package->db, szVersion9x, verstr, len );
877 break;
878 case VER_PLATFORM_WIN32_NT:
879 msi_set_property( package->db, szVersionNT, verstr, len );
880 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szFormat,OSVersion.wProductType );
881 msi_set_property( package->db, szMsiNTProductType, bufstr, len );
882 break;
884 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szFormat, OSVersion.dwBuildNumber );
885 msi_set_property( package->db, szWindowsBuild, bufstr, len );
886 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szFormat, OSVersion.wServicePackMajor );
887 msi_set_property( package->db, szServicePackLevel, bufstr, len );
889 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION );
890 msi_set_property( package->db, szVersionMsi, bufstr, len );
891 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szFormat, MSI_MAJORVERSION * 100 );
892 msi_set_property( package->db, szVersionDatabase, bufstr, len );
894 RegOpenKeyExW(HKEY_LOCAL_MACHINE, szCurrentVersion, 0,
895 KEY_QUERY_VALUE | KEY_WOW64_64KEY, &hkey);
897 GetNativeSystemInfo( &sys_info );
898 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, sys_info.wProcessorLevel );
899 msi_set_property( package->db, szIntel, bufstr, len );
900 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
902 GetSystemDirectoryW( pth, MAX_PATH );
903 PathAddBackslashW( pth );
904 msi_set_property( package->db, szSystemFolder, pth, -1 );
906 len = MAX_PATH;
907 RegQueryValueExW(hkey, szProgramFilesDir, 0, &type, (BYTE *)pth, &len);
908 PathAddBackslashW( pth );
909 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
911 len = MAX_PATH;
912 RegQueryValueExW(hkey, szCommonFilesDir, 0, &type, (BYTE *)pth, &len);
913 PathAddBackslashW( pth );
914 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
916 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
918 msi_set_property( package->db, szMsiAMD64, bufstr, -1 );
919 msi_set_property( package->db, szMsix64, bufstr, -1 );
920 msi_set_property( package->db, szVersionNT64, verstr, -1 );
922 GetSystemDirectoryW( pth, MAX_PATH );
923 PathAddBackslashW( pth );
924 msi_set_property( package->db, szSystem64Folder, pth, -1 );
926 GetSystemWow64DirectoryW( pth, MAX_PATH );
927 PathAddBackslashW( pth );
928 msi_set_property( package->db, szSystemFolder, pth, -1 );
930 len = MAX_PATH;
931 RegQueryValueExW(hkey, szProgramFilesDir, 0, &type, (BYTE *)pth, &len);
932 PathAddBackslashW( pth );
933 msi_set_property( package->db, szProgramFiles64Folder, pth, -1 );
935 len = MAX_PATH;
936 RegQueryValueExW(hkey, szProgramFilesDirx86, 0, &type, (BYTE *)pth, &len);
937 PathAddBackslashW( pth );
938 msi_set_property( package->db, szProgramFilesFolder, pth, -1 );
940 len = MAX_PATH;
941 RegQueryValueExW(hkey, szCommonFilesDir, 0, &type, (BYTE *)pth, &len);
942 PathAddBackslashW( pth );
943 msi_set_property( package->db, szCommonFiles64Folder, pth, -1 );
945 len = MAX_PATH;
946 RegQueryValueExW(hkey, szCommonFilesDirx86, 0, &type, (BYTE *)pth, &len);
947 PathAddBackslashW( pth );
948 msi_set_property( package->db, szCommonFilesFolder, pth, -1 );
951 RegCloseKey(hkey);
953 /* Screen properties. */
954 dc = GetDC(0);
955 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, GetDeviceCaps(dc, HORZRES) );
956 msi_set_property( package->db, szScreenX, bufstr, len );
957 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, GetDeviceCaps(dc, VERTRES) );
958 msi_set_property( package->db, szScreenY, bufstr, len );
959 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, GetDeviceCaps(dc, BITSPIXEL) );
960 msi_set_property( package->db, szColorBits, bufstr, len );
961 ReleaseDC(0, dc);
963 /* USERNAME and COMPANYNAME */
964 username = msi_dup_property( package->db, szUSERNAME );
965 companyname = msi_dup_property( package->db, szCOMPANYNAME );
967 if ((!username || !companyname) &&
968 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
970 if (!username &&
971 (username = msi_reg_get_val_str( hkey, szDefName )))
972 msi_set_property( package->db, szUSERNAME, username, -1 );
973 if (!companyname &&
974 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
975 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
976 CloseHandle( hkey );
978 if ((!username || !companyname) &&
979 RegOpenKeyExW( HKEY_LOCAL_MACHINE, szCurrentVersionNT, 0, KEY_QUERY_VALUE|KEY_WOW64_64KEY,
980 &hkey ) == ERROR_SUCCESS)
982 if (!username &&
983 (username = msi_reg_get_val_str( hkey, szRegisteredOwner )))
984 msi_set_property( package->db, szUSERNAME, username, -1 );
985 if (!companyname &&
986 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
987 msi_set_property( package->db, szCOMPANYNAME, companyname, -1 );
988 CloseHandle( hkey );
990 msi_free( username );
991 msi_free( companyname );
993 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
994 ERR("Failed to set the UserSID property\n");
996 set_msi_assembly_prop( package );
998 langid = GetUserDefaultLangID();
999 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, langid );
1000 msi_set_property( package->db, szUserLanguageID, bufstr, len );
1002 langid = GetSystemDefaultLangID();
1003 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, langid );
1004 msi_set_property( package->db, szSystemLangID, bufstr, len );
1006 len = swprintf( bufstr, ARRAY_SIZE(bufstr), szIntFormat, MsiQueryProductStateW(package->ProductCode) );
1007 msi_set_property( package->db, szProductState, bufstr, len );
1009 len = 0;
1010 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
1012 WCHAR *username;
1013 if ((username = msi_alloc( len * sizeof(WCHAR) )))
1015 if (GetUserNameW( username, &len ))
1016 msi_set_property( package->db, szLogonUser, username, len - 1 );
1017 msi_free( username );
1020 len = 0;
1021 if (!GetComputerNameW( NULL, &len ) && GetLastError() == ERROR_BUFFER_OVERFLOW)
1023 WCHAR *computername;
1024 if ((computername = msi_alloc( len * sizeof(WCHAR) )))
1026 if (GetComputerNameW( computername, &len ))
1027 msi_set_property( package->db, szComputerName, computername, len );
1028 msi_free( computername );
1033 static MSIPACKAGE *msi_alloc_package( void )
1035 MSIPACKAGE *package;
1037 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1038 MSI_FreePackage );
1039 if( package )
1041 list_init( &package->components );
1042 list_init( &package->features );
1043 list_init( &package->files );
1044 list_init( &package->filepatches );
1045 list_init( &package->tempfiles );
1046 list_init( &package->folders );
1047 list_init( &package->subscriptions );
1048 list_init( &package->appids );
1049 list_init( &package->classes );
1050 list_init( &package->mimes );
1051 list_init( &package->extensions );
1052 list_init( &package->progids );
1053 list_init( &package->RunningActions );
1054 list_init( &package->sourcelist_info );
1055 list_init( &package->sourcelist_media );
1056 list_init( &package->patches );
1057 list_init( &package->binaries );
1058 list_init( &package->cabinet_streams );
1061 return package;
1064 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1066 BYTE *data;
1067 UINT r, sz;
1069 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1071 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1072 if (r != ERROR_SUCCESS)
1073 return r;
1075 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1077 msi_free(data);
1078 return r;
1081 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1083 /* FIXME: this should depend on the user's privileges */
1084 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1086 TRACE("resetting ALLUSERS property from 2 to 1\n");
1087 msi_set_property( package->db, szAllUsers, szOne, -1 );
1089 msi_set_property( package->db, szAdminUser, szOne, -1 );
1092 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
1094 static const WCHAR fmtW[] = {'%','u',0};
1095 MSIPACKAGE *package;
1096 WCHAR uilevel[11];
1097 int len;
1098 UINT r;
1100 TRACE("%p\n", db);
1102 package = msi_alloc_package();
1103 if (package)
1105 msiobj_addref( &db->hdr );
1106 package->db = db;
1108 package->LastAction = NULL;
1109 package->LastActionTemplate = NULL;
1110 package->LastActionResult = MSI_NULL_INTEGER;
1111 package->WordCount = 0;
1112 package->PackagePath = strdupW( db->path );
1114 create_temp_property_table( package );
1115 msi_clone_properties( package->db );
1116 msi_adjust_privilege_properties( package );
1118 package->ProductCode = msi_dup_property( package->db, szProductCode );
1120 set_installer_properties( package );
1122 package->ui_level = gUILevel;
1123 len = swprintf( uilevel, ARRAY_SIZE(uilevel), fmtW, gUILevel & INSTALLUILEVEL_MASK );
1124 msi_set_property( package->db, szUILevel, uilevel, len );
1126 r = msi_load_suminfo_properties( package );
1127 if (r != ERROR_SUCCESS)
1129 msiobj_release( &package->hdr );
1130 return NULL;
1133 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1134 msi_load_admin_properties( package );
1136 package->log_file = INVALID_HANDLE_VALUE;
1137 package->script = SCRIPT_NONE;
1139 return package;
1142 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1144 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1145 DWORD size = 0;
1146 HRESULT hr;
1148 /* call will always fail, because size is 0,
1149 * but will return ERROR_FILE_NOT_FOUND first
1150 * if the file doesn't exist
1152 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1153 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1155 cache_entry = msi_alloc( size );
1156 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1158 UINT error = GetLastError();
1159 msi_free( cache_entry );
1160 return error;
1163 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1164 msi_free( cache_entry );
1165 return ERROR_SUCCESS;
1168 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1169 if ( FAILED(hr) )
1171 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1172 return ERROR_FUNCTION_FAILED;
1175 return ERROR_SUCCESS;
1178 UINT msi_create_empty_local_file( LPWSTR path, LPCWSTR suffix )
1180 static const WCHAR szInstaller[] = {
1181 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1182 static const WCHAR fmt[] = {'%','x',0};
1183 DWORD time, len, i, offset;
1184 HANDLE handle;
1186 time = GetTickCount();
1187 GetWindowsDirectoryW( path, MAX_PATH );
1188 lstrcatW( path, szInstaller );
1189 CreateDirectoryW( path, NULL );
1191 len = lstrlenW(path);
1192 for (i = 0; i < 0x10000; i++)
1194 offset = swprintf( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1195 memcpy( path + len + offset, suffix, (lstrlenW( suffix ) + 1) * sizeof(WCHAR) );
1196 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1197 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1198 if (handle != INVALID_HANDLE_VALUE)
1200 CloseHandle(handle);
1201 break;
1203 if (GetLastError() != ERROR_FILE_EXISTS &&
1204 GetLastError() != ERROR_SHARING_VIOLATION)
1205 return ERROR_FUNCTION_FAILED;
1208 return ERROR_SUCCESS;
1211 static enum platform parse_platform( const WCHAR *str )
1213 if (!str[0] || !wcscmp( str, szIntel )) return PLATFORM_INTEL;
1214 else if (!wcscmp( str, szIntel64 )) return PLATFORM_INTEL64;
1215 else if (!wcscmp( str, szX64 ) || !wcscmp( str, szAMD64 )) return PLATFORM_X64;
1216 else if (!wcscmp( str, szARM )) return PLATFORM_ARM;
1217 else if (!wcscmp( str, szARM64 )) return PLATFORM_ARM64;
1218 return PLATFORM_UNRECOGNIZED;
1221 static UINT parse_suminfo( MSISUMMARYINFO *si, MSIPACKAGE *package )
1223 WCHAR *template, *p, *q, *platform;
1224 DWORD i, count;
1226 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1227 TRACE("version: %d\n", package->version);
1229 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1230 if (!template)
1231 return ERROR_SUCCESS; /* native accepts missing template property */
1233 TRACE("template: %s\n", debugstr_w(template));
1235 p = wcschr( template, ';' );
1236 if (!p)
1238 WARN("invalid template string %s\n", debugstr_w(template));
1239 msi_free( template );
1240 return ERROR_PATCH_PACKAGE_INVALID;
1242 *p = 0;
1243 platform = template;
1244 if ((q = wcschr( platform, ',' ))) *q = 0;
1245 package->platform = parse_platform( platform );
1246 while (package->platform == PLATFORM_UNRECOGNIZED && q)
1248 platform = q + 1;
1249 if ((q = wcschr( platform, ',' ))) *q = 0;
1250 package->platform = parse_platform( platform );
1252 if (package->platform == PLATFORM_UNRECOGNIZED)
1254 WARN("unknown platform %s\n", debugstr_w(template));
1255 msi_free( template );
1256 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1258 p++;
1259 if (!*p)
1261 msi_free( template );
1262 return ERROR_SUCCESS;
1264 count = 1;
1265 for (q = p; (q = wcschr( q, ',' )); q++) count++;
1267 package->langids = msi_alloc( count * sizeof(LANGID) );
1268 if (!package->langids)
1270 msi_free( template );
1271 return ERROR_OUTOFMEMORY;
1274 i = 0;
1275 while (*p)
1277 q = wcschr( p, ',' );
1278 if (q) *q = 0;
1279 package->langids[i] = wcstol( p, NULL, 10 );
1280 if (!q) break;
1281 p = q + 1;
1282 i++;
1284 package->num_langids = i + 1;
1286 msi_free( template );
1287 return ERROR_SUCCESS;
1290 static UINT validate_package( MSIPACKAGE *package )
1292 UINT i;
1294 if (package->platform == PLATFORM_INTEL64)
1295 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1296 #ifndef __arm__
1297 if (package->platform == PLATFORM_ARM)
1298 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1299 #endif
1300 #ifndef __aarch64__
1301 if (package->platform == PLATFORM_ARM64)
1302 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1303 #endif
1304 if (package->platform == PLATFORM_X64)
1306 if (!is_64bit && !is_wow64)
1307 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1308 if (package->version < 200)
1309 return ERROR_INSTALL_PACKAGE_INVALID;
1311 if (!package->num_langids)
1313 return ERROR_SUCCESS;
1315 for (i = 0; i < package->num_langids; i++)
1317 LANGID langid = package->langids[i];
1319 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1321 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1323 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1325 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1327 if (IsValidLocale( langid, LCID_INSTALLED ))
1328 return ERROR_SUCCESS;
1330 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1333 static WCHAR *get_property( MSIDATABASE *db, const WCHAR *prop )
1335 static const WCHAR select_query[] = {
1336 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1337 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1338 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1339 '\'','%','s','\'',0};
1340 WCHAR query[MAX_PATH];
1341 MSIQUERY *view;
1342 MSIRECORD *rec;
1343 WCHAR *ret = NULL;
1345 swprintf(query, ARRAY_SIZE(query), select_query, prop);
1346 if (MSI_DatabaseOpenViewW( db, query, &view ) != ERROR_SUCCESS)
1348 return NULL;
1350 if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
1352 MSI_ViewClose( view );
1353 msiobj_release( &view->hdr );
1354 return NULL;
1356 if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
1358 ret = strdupW( MSI_RecordGetString( rec, 1 ) );
1359 msiobj_release( &rec->hdr );
1361 MSI_ViewClose( view );
1362 msiobj_release( &view->hdr );
1363 return ret;
1366 static WCHAR *get_product_code( MSIDATABASE *db )
1368 return get_property( db, szProductCode );
1371 static WCHAR *get_product_version( MSIDATABASE *db )
1373 return get_property( db, szProductVersion );
1376 static UINT get_registered_local_package( const WCHAR *product, WCHAR *localfile )
1378 MSIINSTALLCONTEXT context;
1379 WCHAR *filename;
1380 HKEY props_key;
1381 UINT r;
1383 r = msi_locate_product( product, &context );
1384 if (r != ERROR_SUCCESS)
1385 return r;
1387 r = MSIREG_OpenInstallProps( product, context, NULL, &props_key, FALSE );
1388 if (r != ERROR_SUCCESS)
1389 return r;
1391 filename = msi_reg_get_val_str( props_key, INSTALLPROPERTY_LOCALPACKAGEW );
1392 RegCloseKey( props_key );
1393 if (!filename)
1394 return ERROR_FUNCTION_FAILED;
1396 lstrcpyW( localfile, filename );
1397 msi_free( filename );
1398 return ERROR_SUCCESS;
1401 WCHAR *msi_get_package_code( MSIDATABASE *db )
1403 WCHAR *ret;
1404 MSISUMMARYINFO *si;
1405 UINT r;
1407 r = msi_get_suminfo( db->storage, 0, &si );
1408 if (r != ERROR_SUCCESS)
1410 r = msi_get_db_suminfo( db, 0, &si );
1411 if (r != ERROR_SUCCESS)
1413 WARN("failed to load summary info %u\n", r);
1414 return NULL;
1417 ret = msi_suminfo_dup_string( si, PID_REVNUMBER );
1418 msiobj_release( &si->hdr );
1419 return ret;
1422 static UINT get_local_package( MSIDATABASE *db, WCHAR *localfile )
1424 WCHAR *product_code;
1425 UINT r;
1427 if (!(product_code = get_product_code( db )))
1428 return ERROR_INSTALL_PACKAGE_INVALID;
1429 r = get_registered_local_package( product_code, localfile );
1430 msi_free( product_code );
1431 return r;
1434 UINT msi_set_original_database_property( MSIDATABASE *db, const WCHAR *package )
1436 UINT r;
1438 if (UrlIsW( package, URLIS_URL ))
1439 r = msi_set_property( db, szOriginalDatabase, package, -1 );
1440 else if (package[0] == '#')
1441 r = msi_set_property( db, szOriginalDatabase, db->path, -1 );
1442 else
1444 DWORD len;
1445 WCHAR *path;
1447 if (!(len = GetFullPathNameW( package, 0, NULL, NULL ))) return GetLastError();
1448 if (!(path = msi_alloc( len * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
1449 len = GetFullPathNameW( package, len, path, NULL );
1450 r = msi_set_property( db, szOriginalDatabase, path, len );
1451 msi_free( path );
1453 return r;
1456 UINT MSI_OpenPackageW(LPCWSTR szPackage, DWORD dwOptions, MSIPACKAGE **pPackage)
1458 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1459 MSIDATABASE *db;
1460 MSIPACKAGE *package;
1461 MSIHANDLE handle;
1462 MSIRECORD *data_row, *info_row;
1463 UINT r;
1464 WCHAR localfile[MAX_PATH], cachefile[MAX_PATH];
1465 LPCWSTR file = szPackage;
1466 DWORD index = 0;
1467 MSISUMMARYINFO *si;
1468 BOOL delete_on_close = FALSE;
1469 WCHAR *info_template, *productname, *product_code;
1470 MSIINSTALLCONTEXT context;
1472 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1474 MSI_ProcessMessage(NULL, INSTALLMESSAGE_INITIALIZE, 0);
1476 localfile[0] = 0;
1477 if( szPackage[0] == '#' )
1479 handle = wcstol(&szPackage[1], NULL, 10);
1480 if (!(db = msihandle2msiinfo(handle, MSIHANDLETYPE_DATABASE)))
1481 return ERROR_INVALID_HANDLE;
1483 else
1485 WCHAR *product_version = NULL;
1487 if ( UrlIsW( szPackage, URLIS_URL ) )
1489 r = msi_download_file( szPackage, cachefile );
1490 if (r != ERROR_SUCCESS)
1491 return r;
1493 file = cachefile;
1495 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
1496 if (r != ERROR_SUCCESS)
1498 if (GetFileAttributesW( file ) == INVALID_FILE_ATTRIBUTES)
1499 return ERROR_FILE_NOT_FOUND;
1500 return r;
1502 r = get_local_package( db, localfile );
1503 if (r != ERROR_SUCCESS || GetFileAttributesW( localfile ) == INVALID_FILE_ATTRIBUTES)
1505 r = msi_create_empty_local_file( localfile, dotmsi );
1506 if (r != ERROR_SUCCESS)
1508 msiobj_release( &db->hdr );
1509 return r;
1512 if (!CopyFileW( file, localfile, FALSE ))
1514 r = GetLastError();
1515 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file), debugstr_w(localfile), r);
1516 DeleteFileW( localfile );
1517 msiobj_release( &db->hdr );
1518 return r;
1520 delete_on_close = TRUE;
1522 else if (dwOptions & WINE_OPENPACKAGEFLAGS_RECACHE)
1524 if (!CopyFileW( file, localfile, FALSE ))
1526 r = GetLastError();
1527 WARN("unable to update cached package (%u)\n", r);
1528 msiobj_release( &db->hdr );
1529 return r;
1532 else
1533 product_version = get_product_version( db );
1534 msiobj_release( &db->hdr );
1535 TRACE("opening package %s\n", debugstr_w( localfile ));
1536 r = MSI_OpenDatabaseW( localfile, MSIDBOPEN_TRANSACT, &db );
1537 if (r != ERROR_SUCCESS)
1538 return r;
1540 if (product_version)
1542 WCHAR *cache_version = get_product_version( db );
1543 if (!product_version != !cache_version ||
1544 (product_version && wcscmp(product_version, cache_version)))
1546 msiobj_release( &db->hdr );
1547 msi_free(product_version);
1548 msi_free(cache_version);
1549 return ERROR_PRODUCT_VERSION;
1551 msi_free(product_version);
1552 msi_free(cache_version);
1555 package = MSI_CreatePackage( db );
1556 msiobj_release( &db->hdr );
1557 if (!package) return ERROR_INSTALL_PACKAGE_INVALID;
1558 package->localfile = strdupW( localfile );
1559 package->delete_on_close = delete_on_close;
1561 r = msi_get_suminfo( db->storage, 0, &si );
1562 if (r != ERROR_SUCCESS)
1564 r = msi_get_db_suminfo( db, 0, &si );
1565 if (r != ERROR_SUCCESS)
1567 WARN("failed to load summary info\n");
1568 msiobj_release( &package->hdr );
1569 return ERROR_INSTALL_PACKAGE_INVALID;
1572 r = parse_suminfo( si, package );
1573 msiobj_release( &si->hdr );
1574 if (r != ERROR_SUCCESS)
1576 WARN("failed to parse summary info %u\n", r);
1577 msiobj_release( &package->hdr );
1578 return r;
1580 r = validate_package( package );
1581 if (r != ERROR_SUCCESS)
1583 msiobj_release( &package->hdr );
1584 return r;
1586 msi_set_property( package->db, szDatabase, db->path, -1 );
1587 set_installed_prop( package );
1588 msi_set_context( package );
1590 product_code = get_product_code( db );
1591 if (msi_locate_product( product_code, &context ) == ERROR_SUCCESS)
1593 TRACE("product already registered\n");
1594 msi_set_property( package->db, szProductToBeRegistered, szOne, -1 );
1596 msi_free(product_code);
1598 while (1)
1600 WCHAR patch_code[GUID_SIZE];
1601 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1602 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1603 if (r != ERROR_SUCCESS)
1604 break;
1606 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1608 r = msi_apply_registered_patch( package, patch_code );
1609 if (r != ERROR_SUCCESS)
1611 ERR("registered patch failed to apply %u\n", r);
1612 msiobj_release( &package->hdr );
1613 return r;
1615 index++;
1617 if (index) msi_adjust_privilege_properties( package );
1619 r = msi_set_original_database_property( package->db, szPackage );
1620 if (r != ERROR_SUCCESS)
1622 msiobj_release( &package->hdr );
1623 return r;
1625 if (gszLogFile)
1626 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1627 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1629 if (!msi_init_assembly_caches( package ))
1631 ERR("can't initialize assembly caches\n");
1632 msiobj_release( &package->hdr );
1633 return ERROR_FUNCTION_FAILED;
1636 /* FIXME: when should these messages be sent? */
1637 data_row = MSI_CreateRecord(3);
1638 if (!data_row)
1639 return ERROR_OUTOFMEMORY;
1640 MSI_RecordSetStringW(data_row, 0, NULL);
1641 MSI_RecordSetInteger(data_row, 1, 0);
1642 MSI_RecordSetInteger(data_row, 2, package->num_langids ? package->langids[0] : 0);
1643 MSI_RecordSetInteger(data_row, 3, msi_get_string_table_codepage(package->db->strings));
1644 MSI_ProcessMessageVerbatim(package, INSTALLMESSAGE_COMMONDATA, data_row);
1646 info_row = MSI_CreateRecord(0);
1647 if (!info_row)
1649 msiobj_release(&data_row->hdr);
1650 return ERROR_OUTOFMEMORY;
1652 info_template = msi_get_error_message(package->db, MSIERR_INFO_LOGGINGSTART);
1653 MSI_RecordSetStringW(info_row, 0, info_template);
1654 msi_free(info_template);
1655 MSI_ProcessMessage(package, INSTALLMESSAGE_INFO|MB_ICONHAND, info_row);
1657 MSI_ProcessMessage(package, INSTALLMESSAGE_COMMONDATA, data_row);
1659 productname = msi_dup_property(package->db, INSTALLPROPERTY_PRODUCTNAMEW);
1660 MSI_RecordSetInteger(data_row, 1, 1);
1661 MSI_RecordSetStringW(data_row, 2, productname);
1662 MSI_RecordSetStringW(data_row, 3, NULL);
1663 MSI_ProcessMessage(package, INSTALLMESSAGE_COMMONDATA, data_row);
1665 msi_free(productname);
1666 msiobj_release(&info_row->hdr);
1667 msiobj_release(&data_row->hdr);
1669 *pPackage = package;
1670 return ERROR_SUCCESS;
1673 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1675 MSIPACKAGE *package = NULL;
1676 UINT ret;
1678 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1680 if( !szPackage || !phPackage )
1681 return ERROR_INVALID_PARAMETER;
1683 if ( !*szPackage )
1685 FIXME("Should create an empty database and package\n");
1686 return ERROR_FUNCTION_FAILED;
1689 if( dwOptions )
1690 FIXME("dwOptions %08x not supported\n", dwOptions);
1692 ret = MSI_OpenPackageW( szPackage, 0, &package );
1693 if( ret == ERROR_SUCCESS )
1695 *phPackage = alloc_msihandle( &package->hdr );
1696 if (! *phPackage)
1697 ret = ERROR_NOT_ENOUGH_MEMORY;
1698 msiobj_release( &package->hdr );
1700 else
1701 MSI_ProcessMessage(NULL, INSTALLMESSAGE_TERMINATE, 0);
1703 return ret;
1706 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1708 return MsiOpenPackageExW( szPackage, 0, phPackage );
1711 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1713 LPWSTR szwPack = NULL;
1714 UINT ret;
1716 if( szPackage )
1718 szwPack = strdupAtoW( szPackage );
1719 if( !szwPack )
1720 return ERROR_OUTOFMEMORY;
1723 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1725 msi_free( szwPack );
1727 return ret;
1730 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1732 return MsiOpenPackageExA( szPackage, 0, phPackage );
1735 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1737 MSIPACKAGE *package;
1738 MSIHANDLE handle = 0;
1739 MSIHANDLE remote;
1741 TRACE("(%d)\n",hInstall);
1743 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1744 if( package)
1746 handle = alloc_msihandle( &package->db->hdr );
1747 msiobj_release( &package->hdr );
1749 else if ((remote = msi_get_remote(hInstall)))
1751 __TRY
1753 handle = remote_GetActiveDatabase(remote);
1754 handle = alloc_msi_remote_handle(handle);
1756 __EXCEPT(rpc_filter)
1758 handle = 0;
1760 __ENDTRY
1763 return handle;
1766 static INT internal_ui_handler(MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record, LPCWSTR message)
1768 static const WCHAR szActionData[] = {'A','c','t','i','o','n','D','a','t','a',0};
1769 static const WCHAR szActionText[] = {'A','c','t','i','o','n','T','e','x','t',0};
1770 static const WCHAR szSetProgress[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1771 static const WCHAR szWindows_Installer[] =
1772 {'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0};
1774 if (!package || (package->ui_level & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE)
1775 return 0;
1777 /* todo: check if message needs additional styles (topmost/foreground/modality?) */
1779 switch (eMessageType & 0xff000000)
1781 case INSTALLMESSAGE_FATALEXIT:
1782 case INSTALLMESSAGE_ERROR:
1783 case INSTALLMESSAGE_OUTOFDISKSPACE:
1784 if (package->ui_level & INSTALLUILEVEL_PROGRESSONLY) return 0;
1785 if (!(eMessageType & MB_ICONMASK))
1786 eMessageType |= MB_ICONEXCLAMATION;
1787 return MessageBoxW(gUIhwnd, message, szWindows_Installer, eMessageType & 0x00ffffff);
1788 case INSTALLMESSAGE_WARNING:
1789 if (package->ui_level & INSTALLUILEVEL_PROGRESSONLY) return 0;
1790 if (!(eMessageType & MB_ICONMASK))
1791 eMessageType |= MB_ICONASTERISK;
1792 return MessageBoxW(gUIhwnd, message, szWindows_Installer, eMessageType & 0x00ffffff);
1793 case INSTALLMESSAGE_USER:
1794 if (package->ui_level & INSTALLUILEVEL_PROGRESSONLY) return 0;
1795 if (!(eMessageType & MB_ICONMASK))
1796 eMessageType |= MB_USERICON;
1797 return MessageBoxW(gUIhwnd, message, szWindows_Installer, eMessageType & 0x00ffffff);
1798 case INSTALLMESSAGE_INFO:
1799 case INSTALLMESSAGE_INITIALIZE:
1800 case INSTALLMESSAGE_TERMINATE:
1801 case INSTALLMESSAGE_INSTALLSTART:
1802 case INSTALLMESSAGE_INSTALLEND:
1803 return 0;
1804 case INSTALLMESSAGE_SHOWDIALOG:
1806 LPWSTR dialog = msi_dup_record_field(record, 0);
1807 INT rc = ACTION_DialogBox(package, dialog);
1808 msi_free(dialog);
1809 return rc;
1811 case INSTALLMESSAGE_ACTIONSTART:
1813 LPWSTR deformatted;
1814 MSIRECORD *uirow = MSI_CreateRecord(1);
1815 if (!uirow) return -1;
1816 deformat_string(package, MSI_RecordGetString(record, 2), &deformatted);
1817 MSI_RecordSetStringW(uirow, 1, deformatted);
1818 msi_event_fire(package, szActionText, uirow);
1820 msi_free(deformatted);
1821 msiobj_release(&uirow->hdr);
1822 return 1;
1824 case INSTALLMESSAGE_ACTIONDATA:
1826 MSIRECORD *uirow = MSI_CreateRecord(1);
1827 if (!uirow) return -1;
1828 MSI_RecordSetStringW(uirow, 1, message);
1829 msi_event_fire(package, szActionData, uirow);
1830 msiobj_release(&uirow->hdr);
1832 if (package->action_progress_increment)
1834 uirow = MSI_CreateRecord(2);
1835 if (!uirow) return -1;
1836 MSI_RecordSetInteger(uirow, 1, 2);
1837 MSI_RecordSetInteger(uirow, 2, package->action_progress_increment);
1838 msi_event_fire(package, szSetProgress, uirow);
1839 msiobj_release(&uirow->hdr);
1841 return 1;
1843 case INSTALLMESSAGE_PROGRESS:
1844 msi_event_fire(package, szSetProgress, record);
1845 return 1;
1846 case INSTALLMESSAGE_COMMONDATA:
1847 switch (MSI_RecordGetInteger(record, 1))
1849 case 0:
1850 case 1:
1851 /* do nothing */
1852 return 0;
1853 default:
1854 /* fall through */
1857 default:
1858 FIXME("internal UI not implemented for message 0x%08x (UI level = %x)\n", eMessageType, package->ui_level);
1859 return 0;
1863 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};
1865 static const struct
1867 int id;
1868 const WCHAR *text;
1870 internal_errors[] =
1872 {2726, szActionNotFound},
1876 static LPCWSTR get_internal_error_message(int error)
1878 int i = 0;
1880 while (internal_errors[i].id != 0)
1882 if (internal_errors[i].id == error)
1883 return internal_errors[i].text;
1884 i++;
1887 FIXME("missing error message %d\n", error);
1888 return NULL;
1891 /* Returned string must be freed */
1892 LPWSTR msi_get_error_message(MSIDATABASE *db, int error)
1894 static const WCHAR query[] =
1895 {'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1896 'F','R','O','M',' ','`','E','r','r','o','r','`',' ','W','H','E','R','E',' ',
1897 '`','E','r','r','o','r','`',' ','=',' ','%','i',0};
1898 MSIRECORD *record;
1899 LPWSTR ret = NULL;
1901 if ((record = MSI_QueryGetRecord(db, query, error)))
1903 ret = msi_dup_record_field(record, 1);
1904 msiobj_release(&record->hdr);
1906 else if (error < 2000)
1908 int len = LoadStringW(msi_hInstance, IDS_ERROR_BASE + error, (LPWSTR) &ret, 0);
1909 if (len)
1911 ret = msi_alloc((len + 1) * sizeof(WCHAR));
1912 LoadStringW(msi_hInstance, IDS_ERROR_BASE + error, ret, len + 1);
1914 else
1915 ret = NULL;
1918 return ret;
1921 INT MSI_ProcessMessageVerbatim(MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record)
1923 LPWSTR message = {0};
1924 DWORD len;
1925 DWORD log_type = 1 << (eMessageType >> 24);
1926 UINT res;
1927 INT rc = 0;
1928 char *msg;
1930 TRACE("%x\n", eMessageType);
1931 if (TRACE_ON(msi)) dump_record(record);
1933 if (!package || !record)
1934 message = NULL;
1935 else {
1936 res = MSI_FormatRecordW(package, record, message, &len);
1937 if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
1938 return res;
1939 len++;
1940 message = msi_alloc(len * sizeof(WCHAR));
1941 if (!message) return ERROR_OUTOFMEMORY;
1942 MSI_FormatRecordW(package, record, message, &len);
1945 /* convert it to ASCII */
1946 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1947 msg = msi_alloc( len );
1948 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1950 if (gUIHandlerRecord && (gUIFilterRecord & log_type))
1952 MSIHANDLE rec = alloc_msihandle(&record->hdr);
1953 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, hRecord=%u)\n",
1954 gUIHandlerRecord, gUIContextRecord, eMessageType, rec);
1955 rc = gUIHandlerRecord( gUIContextRecord, eMessageType, rec );
1956 MsiCloseHandle( rec );
1958 if (!rc && gUIHandlerW && (gUIFilter & log_type))
1960 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1961 gUIHandlerW, gUIContext, eMessageType, debugstr_w(message));
1962 rc = gUIHandlerW( gUIContext, eMessageType, message );
1964 else if (!rc && gUIHandlerA && (gUIFilter & log_type))
1966 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1967 gUIHandlerA, gUIContext, eMessageType, debugstr_a(msg));
1968 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1971 if (!rc)
1972 rc = internal_ui_handler(package, eMessageType, record, message);
1974 if (!rc && package && package->log_file != INVALID_HANDLE_VALUE &&
1975 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1977 DWORD written;
1978 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1979 WriteFile( package->log_file, "\n", 1, &written, NULL );
1981 msi_free( msg );
1982 msi_free( message );
1984 return rc;
1987 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1989 switch (eMessageType & 0xff000000)
1991 case INSTALLMESSAGE_FATALEXIT:
1992 case INSTALLMESSAGE_ERROR:
1993 case INSTALLMESSAGE_WARNING:
1994 case INSTALLMESSAGE_USER:
1995 case INSTALLMESSAGE_INFO:
1996 case INSTALLMESSAGE_OUTOFDISKSPACE:
1997 if (MSI_RecordGetInteger(record, 1) != MSI_NULL_INTEGER)
1999 /* error message */
2001 LPWSTR template;
2002 LPWSTR template_rec = NULL, template_prefix = NULL;
2003 int error = MSI_RecordGetInteger(record, 1);
2005 if (MSI_RecordIsNull(record, 0))
2007 if (error >= 32)
2009 template_rec = msi_get_error_message(package->db, error);
2011 if (!template_rec && error >= 2000)
2013 /* internal error, not localized */
2014 if ((template_rec = (LPWSTR) get_internal_error_message(error)))
2016 MSI_RecordSetStringW(record, 0, template_rec);
2017 MSI_ProcessMessageVerbatim(package, INSTALLMESSAGE_INFO, record);
2019 template_rec = msi_get_error_message(package->db, MSIERR_INSTALLERROR);
2020 MSI_RecordSetStringW(record, 0, template_rec);
2021 MSI_ProcessMessageVerbatim(package, eMessageType, record);
2022 msi_free(template_rec);
2023 return 0;
2027 else
2028 template_rec = msi_dup_record_field(record, 0);
2030 template_prefix = msi_get_error_message(package->db, eMessageType >> 24);
2031 if (!template_prefix) template_prefix = strdupW(szEmpty);
2033 if (!template_rec)
2035 /* always returns 0 */
2036 MSI_RecordSetStringW(record, 0, template_prefix);
2037 MSI_ProcessMessageVerbatim(package, eMessageType, record);
2038 msi_free(template_prefix);
2039 return 0;
2042 template = msi_alloc((lstrlenW(template_rec) + lstrlenW(template_prefix) + 1) * sizeof(WCHAR));
2043 if (!template) return ERROR_OUTOFMEMORY;
2045 lstrcpyW(template, template_prefix);
2046 lstrcatW(template, template_rec);
2047 MSI_RecordSetStringW(record, 0, template);
2049 msi_free(template_prefix);
2050 msi_free(template_rec);
2051 msi_free(template);
2053 break;
2054 case INSTALLMESSAGE_ACTIONSTART:
2056 WCHAR *template = msi_get_error_message(package->db, MSIERR_ACTIONSTART);
2057 MSI_RecordSetStringW(record, 0, template);
2058 msi_free(template);
2060 msi_free(package->LastAction);
2061 msi_free(package->LastActionTemplate);
2062 package->LastAction = msi_dup_record_field(record, 1);
2063 if (!package->LastAction) package->LastAction = strdupW(szEmpty);
2064 package->LastActionTemplate = msi_dup_record_field(record, 3);
2065 break;
2067 case INSTALLMESSAGE_ACTIONDATA:
2068 if (package->LastAction && package->LastActionTemplate)
2070 static const WCHAR template_s[] =
2071 {'{','{','%','s',':',' ','}','}','%','s',0};
2072 size_t len = lstrlenW(package->LastAction) + lstrlenW(package->LastActionTemplate) + 7;
2073 WCHAR *template = msi_alloc(len * sizeof(WCHAR));
2074 if (!template) return ERROR_OUTOFMEMORY;
2075 swprintf(template, len, template_s, package->LastAction, package->LastActionTemplate);
2076 MSI_RecordSetStringW(record, 0, template);
2077 msi_free(template);
2079 break;
2080 case INSTALLMESSAGE_COMMONDATA:
2082 WCHAR *template = msi_get_error_message(package->db, MSIERR_COMMONDATA);
2083 MSI_RecordSetStringW(record, 0, template);
2084 msi_free(template);
2086 break;
2089 return MSI_ProcessMessageVerbatim(package, eMessageType, record);
2092 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
2093 MSIHANDLE hRecord)
2095 UINT ret = ERROR_INVALID_HANDLE;
2096 MSIPACKAGE *package = NULL;
2097 MSIRECORD *record = NULL;
2099 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INITIALIZE ||
2100 (eMessageType & 0xff000000) == INSTALLMESSAGE_TERMINATE)
2101 return -1;
2103 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA &&
2104 MsiRecordGetInteger(hRecord, 1) != 2)
2105 return -1;
2107 record = msihandle2msiinfo(hRecord, MSIHANDLETYPE_RECORD);
2108 if (!record)
2109 return ERROR_INVALID_HANDLE;
2111 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
2112 if( !package )
2114 MSIHANDLE remote;
2116 if (!(remote = msi_get_remote(hInstall)))
2117 return ERROR_INVALID_HANDLE;
2119 __TRY
2121 ret = remote_ProcessMessage(remote, eMessageType, (struct wire_record *)&record->count);
2123 __EXCEPT(rpc_filter)
2125 ret = GetExceptionCode();
2127 __ENDTRY
2129 msiobj_release(&record->hdr);
2130 return ret;
2133 ret = MSI_ProcessMessage( package, eMessageType, record );
2135 msiobj_release( &record->hdr );
2136 msiobj_release( &package->hdr );
2137 return ret;
2140 /* property code */
2142 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
2144 LPWSTR szwName = NULL, szwValue = NULL;
2145 UINT r = ERROR_OUTOFMEMORY;
2147 szwName = strdupAtoW( szName );
2148 if( szName && !szwName )
2149 goto end;
2151 szwValue = strdupAtoW( szValue );
2152 if( szValue && !szwValue )
2153 goto end;
2155 r = MsiSetPropertyW( hInstall, szwName, szwValue);
2157 end:
2158 msi_free( szwName );
2159 msi_free( szwValue );
2161 return r;
2164 void msi_reset_source_folders( MSIPACKAGE *package )
2166 MSIFOLDER *folder;
2168 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
2170 msi_free( folder->ResolvedSource );
2171 folder->ResolvedSource = NULL;
2175 UINT msi_set_property( MSIDATABASE *db, const WCHAR *name, const WCHAR *value, int len )
2177 static const WCHAR insert_query[] = {
2178 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2179 '`','_','P','r','o','p','e','r','t','y','`',' ',
2180 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2181 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2182 static const WCHAR update_query[] = {
2183 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2184 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2185 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2186 static const WCHAR delete_query[] = {
2187 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2188 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2189 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2190 MSIQUERY *view;
2191 MSIRECORD *row = NULL;
2192 DWORD sz = 0;
2193 WCHAR query[1024];
2194 UINT rc;
2196 TRACE("%p %s %s %d\n", db, debugstr_w(name), debugstr_wn(value, len), len);
2198 if (!name)
2199 return ERROR_INVALID_PARAMETER;
2201 /* this one is weird... */
2202 if (!name[0])
2203 return value ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2205 if (value && len < 0) len = lstrlenW( value );
2207 rc = msi_get_property( db, name, 0, &sz );
2208 if (!value || (!*value && !len))
2210 swprintf( query, ARRAY_SIZE(query), delete_query, name );
2212 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2214 swprintf( query, ARRAY_SIZE(query), update_query, name );
2215 row = MSI_CreateRecord(1);
2216 msi_record_set_string( row, 1, value, len );
2218 else
2220 lstrcpyW( query, insert_query );
2221 row = MSI_CreateRecord(2);
2222 msi_record_set_string( row, 1, name, -1 );
2223 msi_record_set_string( row, 2, value, len );
2226 rc = MSI_DatabaseOpenViewW(db, query, &view);
2227 if (rc == ERROR_SUCCESS)
2229 rc = MSI_ViewExecute(view, row);
2230 MSI_ViewClose(view);
2231 msiobj_release(&view->hdr);
2233 if (row) msiobj_release(&row->hdr);
2234 return rc;
2237 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2239 MSIPACKAGE *package;
2240 UINT ret;
2242 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2243 if( !package )
2245 MSIHANDLE remote;
2247 if (!(remote = msi_get_remote(hInstall)))
2248 return ERROR_INVALID_HANDLE;
2250 __TRY
2252 ret = remote_SetProperty(remote, szName, szValue);
2254 __EXCEPT(rpc_filter)
2256 ret = GetExceptionCode();
2258 __ENDTRY
2260 return ret;
2263 ret = msi_set_property( package->db, szName, szValue, -1 );
2264 if (ret == ERROR_SUCCESS && !wcscmp( szName, szSourceDir ))
2265 msi_reset_source_folders( package );
2267 msiobj_release( &package->hdr );
2268 return ret;
2271 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2273 static const WCHAR query[]= {
2274 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2275 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2276 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2277 MSIRECORD *rec, *row = NULL;
2278 MSIQUERY *view;
2279 UINT r;
2281 static const WCHAR szDate[] = {'D','a','t','e',0};
2282 static const WCHAR szTime[] = {'T','i','m','e',0};
2283 WCHAR *buffer;
2284 int length;
2286 if (!name || !*name)
2287 return NULL;
2289 if (!wcscmp(name, szDate))
2291 length = GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, NULL, 0);
2292 if (!length)
2293 return NULL;
2294 buffer = msi_alloc(length * sizeof(WCHAR));
2295 GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, NULL, NULL, buffer, length);
2297 row = MSI_CreateRecord(1);
2298 if (!row)
2300 msi_free(buffer);
2301 return NULL;
2303 MSI_RecordSetStringW(row, 1, buffer);
2304 msi_free(buffer);
2305 return row;
2307 else if (!wcscmp(name, szTime))
2309 length = GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER, NULL, NULL, NULL, 0);
2310 if (!length)
2311 return NULL;
2312 buffer = msi_alloc(length * sizeof(WCHAR));
2313 GetTimeFormatW(LOCALE_USER_DEFAULT, TIME_NOTIMEMARKER, NULL, NULL, buffer, length);
2315 row = MSI_CreateRecord(1);
2316 if (!row)
2318 msi_free(buffer);
2319 return NULL;
2321 MSI_RecordSetStringW(row, 1, buffer);
2322 msi_free(buffer);
2323 return row;
2326 rec = MSI_CreateRecord(1);
2327 if (!rec)
2328 return NULL;
2330 MSI_RecordSetStringW(rec, 1, name);
2332 r = MSI_DatabaseOpenViewW(db, query, &view);
2333 if (r == ERROR_SUCCESS)
2335 MSI_ViewExecute(view, rec);
2336 MSI_ViewFetch(view, &row);
2337 MSI_ViewClose(view);
2338 msiobj_release(&view->hdr);
2340 msiobj_release(&rec->hdr);
2341 return row;
2344 /* internal function, not compatible with MsiGetPropertyW */
2345 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2346 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2348 MSIRECORD *row;
2349 UINT rc = ERROR_FUNCTION_FAILED;
2351 TRACE("%p %s %p %p\n", db, debugstr_w(szName), szValueBuf, pchValueBuf);
2353 row = msi_get_property_row( db, szName );
2355 if (*pchValueBuf > 0)
2356 szValueBuf[0] = 0;
2358 if (row)
2360 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2361 msiobj_release(&row->hdr);
2364 if (rc == ERROR_SUCCESS)
2365 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf, *pchValueBuf),
2366 debugstr_w(szName));
2367 else if (rc == ERROR_MORE_DATA)
2368 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2369 debugstr_w(szName));
2370 else
2372 *pchValueBuf = 0;
2373 TRACE("property %s not found\n", debugstr_w(szName));
2376 return rc;
2379 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2381 DWORD sz = 0;
2382 LPWSTR str;
2383 UINT r;
2385 r = msi_get_property(db, prop, NULL, &sz);
2386 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2387 return NULL;
2389 sz++;
2390 str = msi_alloc(sz * sizeof(WCHAR));
2391 r = msi_get_property(db, prop, str, &sz);
2392 if (r != ERROR_SUCCESS)
2394 msi_free(str);
2395 str = NULL;
2398 return str;
2401 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2403 LPWSTR str = msi_dup_property( db, prop );
2404 int val = str ? wcstol(str, NULL, 10) : def;
2405 msi_free(str);
2406 return val;
2409 UINT WINAPI MsiGetPropertyA(MSIHANDLE hinst, const char *name, char *buf, DWORD *sz)
2411 const WCHAR *value = szEmpty;
2412 MSIPACKAGE *package;
2413 MSIRECORD *row;
2414 WCHAR *nameW;
2415 int len = 0;
2416 UINT r;
2418 if (!name)
2419 return ERROR_INVALID_PARAMETER;
2421 if (!(nameW = strdupAtoW(name)))
2422 return ERROR_OUTOFMEMORY;
2424 package = msihandle2msiinfo(hinst, MSIHANDLETYPE_PACKAGE);
2425 if (!package)
2427 WCHAR *value = NULL, *tmp;
2428 MSIHANDLE remote;
2429 DWORD len;
2431 if (!(remote = msi_get_remote(hinst)))
2433 heap_free(nameW);
2434 return ERROR_INVALID_HANDLE;
2437 __TRY
2439 r = remote_GetProperty(remote, nameW, &value, &len);
2441 __EXCEPT(rpc_filter)
2443 r = GetExceptionCode();
2445 __ENDTRY
2447 heap_free(nameW);
2449 if (!r)
2451 /* String might contain embedded nulls.
2452 * Native returns the correct size but truncates the string. */
2453 tmp = heap_alloc_zero((len + 1) * sizeof(WCHAR));
2454 if (!tmp)
2456 midl_user_free(value);
2457 return ERROR_OUTOFMEMORY;
2459 lstrcpyW(tmp, value);
2461 r = msi_strncpyWtoA(tmp, len, buf, sz, TRUE);
2463 heap_free(tmp);
2465 midl_user_free(value);
2466 return r;
2469 row = msi_get_property_row(package->db, nameW);
2470 if (row)
2471 value = msi_record_get_string(row, 1, &len);
2473 r = msi_strncpyWtoA(value, len, buf, sz, FALSE);
2475 heap_free(nameW);
2476 if (row) msiobj_release(&row->hdr);
2477 msiobj_release(&package->hdr);
2478 return r;
2481 UINT WINAPI MsiGetPropertyW(MSIHANDLE hinst, const WCHAR *name, WCHAR *buf, DWORD *sz)
2483 const WCHAR *value = szEmpty;
2484 MSIPACKAGE *package;
2485 MSIRECORD *row;
2486 int len = 0;
2487 UINT r;
2489 if (!name)
2490 return ERROR_INVALID_PARAMETER;
2492 package = msihandle2msiinfo(hinst, MSIHANDLETYPE_PACKAGE);
2493 if (!package)
2495 WCHAR *value = NULL, *tmp;
2496 MSIHANDLE remote;
2497 DWORD len;
2499 if (!(remote = msi_get_remote(hinst)))
2500 return ERROR_INVALID_HANDLE;
2502 __TRY
2504 r = remote_GetProperty(remote, name, &value, &len);
2506 __EXCEPT(rpc_filter)
2508 r = GetExceptionCode();
2510 __ENDTRY
2512 if (!r)
2514 /* String might contain embedded nulls.
2515 * Native returns the correct size but truncates the string. */
2516 tmp = heap_alloc_zero((len + 1) * sizeof(WCHAR));
2517 if (!tmp)
2519 midl_user_free(value);
2520 return ERROR_OUTOFMEMORY;
2522 lstrcpyW(tmp, value);
2524 r = msi_strncpyW(tmp, len, buf, sz);
2526 heap_free(tmp);
2528 midl_user_free(value);
2529 return r;
2532 row = msi_get_property_row(package->db, name);
2533 if (row)
2534 value = msi_record_get_string(row, 1, &len);
2536 r = msi_strncpyW(value, len, buf, sz);
2538 if (row) msiobj_release(&row->hdr);
2539 msiobj_release(&package->hdr);
2540 return r;
2543 MSIHANDLE __cdecl s_remote_GetActiveDatabase(MSIHANDLE hinst)
2545 return MsiGetActiveDatabase(hinst);
2548 UINT __cdecl s_remote_GetProperty(MSIHANDLE hinst, LPCWSTR property, LPWSTR *value, DWORD *size)
2550 WCHAR empty[1];
2551 UINT r;
2553 *size = 0;
2554 r = MsiGetPropertyW(hinst, property, empty, size);
2555 if (r == ERROR_MORE_DATA)
2557 ++*size;
2558 *value = midl_user_allocate(*size * sizeof(WCHAR));
2559 if (!*value)
2560 return ERROR_OUTOFMEMORY;
2561 r = MsiGetPropertyW(hinst, property, *value, size);
2563 return r;
2566 UINT __cdecl s_remote_SetProperty(MSIHANDLE hinst, LPCWSTR property, LPCWSTR value)
2568 return MsiSetPropertyW(hinst, property, value);
2571 int __cdecl s_remote_ProcessMessage(MSIHANDLE hinst, INSTALLMESSAGE message, struct wire_record *remote_rec)
2573 MSIHANDLE rec;
2574 int ret;
2575 UINT r;
2577 if ((r = unmarshal_record(remote_rec, &rec)))
2578 return r;
2580 ret = MsiProcessMessage(hinst, message, rec);
2582 MsiCloseHandle(rec);
2583 return ret;
2586 UINT __cdecl s_remote_DoAction(MSIHANDLE hinst, LPCWSTR action)
2588 return MsiDoActionW(hinst, action);
2591 UINT __cdecl s_remote_Sequence(MSIHANDLE hinst, LPCWSTR table, int sequence)
2593 return MsiSequenceW(hinst, table, sequence);
2596 UINT __cdecl s_remote_GetTargetPath(MSIHANDLE hinst, LPCWSTR folder, LPWSTR *value)
2598 WCHAR empty[1];
2599 DWORD size = 0;
2600 UINT r;
2602 r = MsiGetTargetPathW(hinst, folder, empty, &size);
2603 if (r == ERROR_MORE_DATA)
2605 *value = midl_user_allocate(++size * sizeof(WCHAR));
2606 if (!*value)
2607 return ERROR_OUTOFMEMORY;
2608 r = MsiGetTargetPathW(hinst, folder, *value, &size);
2610 return r;
2613 UINT __cdecl s_remote_SetTargetPath(MSIHANDLE hinst, LPCWSTR folder, LPCWSTR value)
2615 return MsiSetTargetPathW(hinst, folder, value);
2618 UINT __cdecl s_remote_GetSourcePath(MSIHANDLE hinst, LPCWSTR folder, LPWSTR *value)
2620 WCHAR empty[1];
2621 DWORD size = 1;
2622 UINT r;
2624 r = MsiGetSourcePathW(hinst, folder, empty, &size);
2625 if (r == ERROR_MORE_DATA)
2627 *value = midl_user_allocate(++size * sizeof(WCHAR));
2628 if (!*value)
2629 return ERROR_OUTOFMEMORY;
2630 r = MsiGetSourcePathW(hinst, folder, *value, &size);
2632 return r;
2635 BOOL __cdecl s_remote_GetMode(MSIHANDLE hinst, MSIRUNMODE mode)
2637 return MsiGetMode(hinst, mode);
2640 UINT __cdecl s_remote_SetMode(MSIHANDLE hinst, MSIRUNMODE mode, BOOL state)
2642 return MsiSetMode(hinst, mode, state);
2645 UINT __cdecl s_remote_GetFeatureState(MSIHANDLE hinst, LPCWSTR feature,
2646 INSTALLSTATE *installed, INSTALLSTATE *action)
2648 return MsiGetFeatureStateW(hinst, feature, installed, action);
2651 UINT __cdecl s_remote_SetFeatureState(MSIHANDLE hinst, LPCWSTR feature, INSTALLSTATE state)
2653 return MsiSetFeatureStateW(hinst, feature, state);
2656 UINT __cdecl s_remote_GetComponentState(MSIHANDLE hinst, LPCWSTR component,
2657 INSTALLSTATE *installed, INSTALLSTATE *action)
2659 return MsiGetComponentStateW(hinst, component, installed, action);
2662 UINT __cdecl s_remote_SetComponentState(MSIHANDLE hinst, LPCWSTR component, INSTALLSTATE state)
2664 return MsiSetComponentStateW(hinst, component, state);
2667 LANGID __cdecl s_remote_GetLanguage(MSIHANDLE hinst)
2669 return MsiGetLanguage(hinst);
2672 UINT __cdecl s_remote_SetInstallLevel(MSIHANDLE hinst, int level)
2674 return MsiSetInstallLevel(hinst, level);
2677 UINT __cdecl s_remote_FormatRecord(MSIHANDLE hinst, struct wire_record *remote_rec, LPWSTR *value)
2679 WCHAR empty[1];
2680 DWORD size = 0;
2681 MSIHANDLE rec;
2682 UINT r;
2684 if ((r = unmarshal_record(remote_rec, &rec)))
2685 return r;
2687 r = MsiFormatRecordW(hinst, rec, empty, &size);
2688 if (r == ERROR_MORE_DATA)
2690 *value = midl_user_allocate(++size * sizeof(WCHAR));
2691 if (!*value)
2693 MsiCloseHandle(rec);
2694 return ERROR_OUTOFMEMORY;
2696 r = MsiFormatRecordW(hinst, rec, *value, &size);
2699 MsiCloseHandle(rec);
2700 return r;
2703 MSICONDITION __cdecl s_remote_EvaluateCondition(MSIHANDLE hinst, LPCWSTR condition)
2705 return MsiEvaluateConditionW(hinst, condition);
2708 UINT __cdecl s_remote_GetFeatureCost(MSIHANDLE hinst, LPCWSTR feature,
2709 MSICOSTTREE cost_tree, INSTALLSTATE state, INT *cost)
2711 return MsiGetFeatureCostW(hinst, feature, cost_tree, state, cost);
2714 UINT __cdecl s_remote_EnumComponentCosts(MSIHANDLE hinst, LPCWSTR component,
2715 DWORD index, INSTALLSTATE state, LPWSTR drive, INT *cost, INT *temp)
2717 DWORD size = 3;
2718 return MsiEnumComponentCostsW(hinst, component, index, state, drive, &size, cost, temp);
2721 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2722 LPCWSTR property, LPWSTR value)
2724 MSISOURCELISTINFO *info;
2726 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2728 if (!wcscmp( info->value, value )) return ERROR_SUCCESS;
2731 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2732 if (!info)
2733 return ERROR_OUTOFMEMORY;
2735 info->context = context;
2736 info->options = options;
2737 info->property = property;
2738 info->value = strdupW(value);
2739 list_add_head(&package->sourcelist_info, &info->entry);
2741 return ERROR_SUCCESS;
2744 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2745 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2747 MSIMEDIADISK *disk;
2749 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2751 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2754 disk = msi_alloc(sizeof(MSIMEDIADISK));
2755 if (!disk)
2756 return ERROR_OUTOFMEMORY;
2758 disk->context = context;
2759 disk->options = options;
2760 disk->disk_id = disk_id;
2761 disk->volume_label = strdupW(volume_label);
2762 disk->disk_prompt = strdupW(disk_prompt);
2763 list_add_head(&package->sourcelist_media, &disk->entry);
2765 return ERROR_SUCCESS;