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
46 #include "wine/heap.h"
47 #include "wine/debug.h"
48 #include "wine/exception.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
);
67 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
69 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
70 list_remove( &cl
->entry
);
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
);
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
);
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
);
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
);
116 msi_free( ext
->Extension
);
117 msi_free( ext
->ProgIDText
);
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
)
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
;
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
)
365 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"CREATE TABLE `_Property` ( `_Property` CHAR(56) NOT NULL TEMPORARY, "
366 L
"`Value` CHAR(98) NOT NULL TEMPORARY PRIMARY KEY `_Property`) HOLD", &view
);
367 if (rc
!= ERROR_SUCCESS
)
370 rc
= MSI_ViewExecute(view
, 0);
372 msiobj_release(&view
->hdr
);
376 UINT
msi_clone_properties( MSIDATABASE
*db
)
378 MSIQUERY
*view_select
;
381 rc
= MSI_DatabaseOpenViewW( db
, L
"SELECT * FROM `Property`", &view_select
);
382 if (rc
!= ERROR_SUCCESS
)
385 rc
= MSI_ViewExecute( view_select
, 0 );
386 if (rc
!= ERROR_SUCCESS
)
388 MSI_ViewClose( view_select
);
389 msiobj_release( &view_select
->hdr
);
395 MSIQUERY
*view_insert
, *view_update
;
396 MSIRECORD
*rec_select
;
398 rc
= MSI_ViewFetch( view_select
, &rec_select
);
399 if (rc
!= ERROR_SUCCESS
)
402 rc
= MSI_DatabaseOpenViewW( db
, L
"INSERT INTO `_Property` (`_Property`,`Value`) VALUES (?,?)", &view_insert
);
403 if (rc
!= ERROR_SUCCESS
)
405 msiobj_release( &rec_select
->hdr
);
409 rc
= MSI_ViewExecute( view_insert
, rec_select
);
410 MSI_ViewClose( view_insert
);
411 msiobj_release( &view_insert
->hdr
);
412 if (rc
!= ERROR_SUCCESS
)
414 MSIRECORD
*rec_update
;
416 TRACE("insert failed, trying update\n");
418 rc
= MSI_DatabaseOpenViewW( db
, L
"UPDATE `_Property` SET `Value` = ? WHERE `_Property` = ?", &view_update
);
419 if (rc
!= ERROR_SUCCESS
)
421 WARN("open view failed %u\n", rc
);
422 msiobj_release( &rec_select
->hdr
);
426 rec_update
= MSI_CreateRecord( 2 );
427 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
428 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
429 rc
= MSI_ViewExecute( view_update
, rec_update
);
430 if (rc
!= ERROR_SUCCESS
)
431 WARN("update failed %u\n", rc
);
433 MSI_ViewClose( view_update
);
434 msiobj_release( &view_update
->hdr
);
435 msiobj_release( &rec_update
->hdr
);
438 msiobj_release( &rec_select
->hdr
);
441 MSI_ViewClose( view_select
);
442 msiobj_release( &view_select
->hdr
);
449 * Sets the "Installed" property to indicate that
450 * the product is installed for the current user.
452 static UINT
set_installed_prop( MSIPACKAGE
*package
)
457 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
459 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
460 if (r
== ERROR_SUCCESS
)
463 msi_set_property( package
->db
, L
"Installed", L
"1", -1 );
468 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
472 LPWSTR sid_str
= NULL
, dom
= NULL
;
473 DWORD size
, dom_size
;
475 UINT r
= ERROR_FUNCTION_FAILED
;
478 GetUserNameW( NULL
, &size
);
480 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
482 return ERROR_OUTOFMEMORY
;
484 if (!GetUserNameW( user_name
, &size
))
489 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
491 psid
= msi_alloc( size
);
492 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
495 r
= ERROR_OUTOFMEMORY
;
499 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
502 if (!ConvertSidToStringSidW( psid
, &sid_str
))
505 r
= msi_set_property( package
->db
, L
"UserSID", sid_str
, -1 );
508 LocalFree( sid_str
);
511 msi_free( user_name
);
516 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
520 DWORD size
, len
, type
;
521 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], *filename
= NULL
;
523 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\NET Framework Setup\\NDP", 0, KEY_CREATE_SUB_KEY
,
525 if (res
!= ERROR_SUCCESS
)
528 if (!RegCreateKeyExW(netsetup
, L
"v4\\Client", 0, NULL
, 0, KEY_QUERY_VALUE
, NULL
, &hkey
, NULL
))
531 if (!RegQueryValueExW(hkey
, L
"InstallPath", NULL
, &type
, (BYTE
*)path
, &size
))
533 len
= lstrlenW(path
) + lstrlenW(L
"fusion.dll") + 2;
534 if (!(filename
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
536 lstrcpyW(filename
, path
);
537 lstrcatW(filename
, L
"\\");
538 lstrcatW(filename
, L
"fusion.dll");
539 if (GetFileAttributesW(filename
) != INVALID_FILE_ATTRIBUTES
)
541 TRACE( "found %s\n", debugstr_w(filename
) );
543 RegCloseKey(netsetup
);
550 if (!RegCreateKeyExW(netsetup
, L
"v2.0.50727", 0, NULL
, 0, KEY_QUERY_VALUE
, NULL
, &hkey
, NULL
))
553 GetWindowsDirectoryW(windir
, MAX_PATH
);
554 len
= lstrlenW(windir
) + lstrlenW(L
"Microsoft.NET\\Framework\\") + lstrlenW(L
"v2.0.50727") +
555 lstrlenW(L
"fusion.dll") + 3;
556 if (!(filename
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
558 lstrcpyW(filename
, windir
);
559 lstrcatW(filename
, L
"\\");
560 lstrcatW(filename
, L
"Microsoft.NET\\Framework\\");
561 lstrcatW(filename
, L
"v2.0.50727");
562 lstrcatW(filename
, L
"\\");
563 lstrcatW(filename
, L
"fusion.dll");
564 if (GetFileAttributesW(filename
) != INVALID_FILE_ATTRIBUTES
)
566 TRACE( "found %s\n", debugstr_w(filename
) );
567 RegCloseKey(netsetup
);
572 RegCloseKey(netsetup
);
576 typedef struct tagLANGANDCODEPAGE
582 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
586 LPVOID version
= NULL
;
588 LPWSTR fusion
, verstr
;
589 LANGANDCODEPAGE
*translate
;
591 fusion
= get_fusion_filename(package
);
595 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
599 version
= msi_alloc(size
);
603 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
606 if (!VerQueryValueW(version
, L
"\\VarFileInfo\\Translation", (LPVOID
*)&translate
, &val_len
))
609 swprintf(buf
, ARRAY_SIZE(buf
), L
"\\StringFileInfo\\%04x%04x\\ProductVersion", translate
[0].wLanguage
,
610 translate
[0].wCodePage
);
612 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
615 if (!val_len
|| !verstr
)
618 msi_set_property( package
->db
, L
"MsiNetAssemblySupport", verstr
, -1 );
625 static VOID
set_installer_properties(MSIPACKAGE
*package
)
628 RTL_OSVERSIONINFOEXW OSVersion
;
630 DWORD verval
, len
, type
;
631 WCHAR pth
[MAX_PATH
], verstr
[11], bufstr
[22];
634 LPWSTR username
, companyname
;
635 SYSTEM_INFO sys_info
;
639 * Other things that probably should be set:
641 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
642 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
645 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
646 lstrcatW(pth
, L
"\\");
647 msi_set_property( package
->db
, L
"CommonAppDataFolder", pth
, -1 );
649 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
650 lstrcatW(pth
, L
"\\");
651 msi_set_property( package
->db
, L
"FavoritesFolder", pth
, -1 );
653 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
654 lstrcatW(pth
, L
"\\");
655 msi_set_property( package
->db
, L
"FontsFolder", pth
, -1 );
657 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
658 lstrcatW(pth
, L
"\\");
659 msi_set_property( package
->db
, L
"SendToFolder", pth
, -1 );
661 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
662 lstrcatW(pth
, L
"\\");
663 msi_set_property( package
->db
, L
"StartMenuFolder", pth
, -1 );
665 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
666 lstrcatW(pth
, L
"\\");
667 msi_set_property( package
->db
, L
"StartupFolder", pth
, -1 );
669 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
670 lstrcatW(pth
, L
"\\");
671 msi_set_property( package
->db
, L
"TemplateFolder", pth
, -1 );
673 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
674 lstrcatW(pth
, L
"\\");
675 msi_set_property( package
->db
, L
"DesktopFolder", pth
, -1 );
677 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
678 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
679 lstrcatW(pth
, L
"\\");
680 msi_set_property( package
->db
, L
"ProgramMenuFolder", pth
, -1 );
682 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
683 lstrcatW(pth
, L
"\\");
684 msi_set_property( package
->db
, L
"AdminToolsFolder", pth
, -1 );
686 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
687 lstrcatW(pth
, L
"\\");
688 msi_set_property( package
->db
, L
"AppDataFolder", pth
, -1 );
690 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
691 lstrcatW(pth
, L
"\\");
692 msi_set_property( package
->db
, L
"SystemFolder", pth
, -1 );
693 msi_set_property( package
->db
, L
"System16Folder", pth
, -1 );
695 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
696 lstrcatW(pth
, L
"\\");
697 msi_set_property( package
->db
, L
"LocalAppDataFolder", pth
, -1 );
699 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
700 lstrcatW(pth
, L
"\\");
701 msi_set_property( package
->db
, L
"MyPicturesFolder", pth
, -1 );
703 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
704 lstrcatW(pth
, L
"\\");
705 msi_set_property( package
->db
, L
"PersonalFolder", pth
, -1 );
707 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
708 lstrcatW(pth
, L
"\\");
709 msi_set_property( package
->db
, L
"WindowsFolder", pth
, -1 );
711 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
712 lstrcatW(pth
, L
"\\");
713 msi_set_property( package
->db
, L
"PrintHoodFolder", pth
, -1 );
715 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
716 lstrcatW(pth
, L
"\\");
717 msi_set_property( package
->db
, L
"NetHoodFolder", pth
, -1 );
719 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
720 lstrcatW(pth
, L
"\\");
721 msi_set_property( package
->db
, L
"RecentFolder", pth
, -1 );
723 /* Physical Memory is specified in MB. Using total amount. */
724 msex
.dwLength
= sizeof(msex
);
725 GlobalMemoryStatusEx( &msex
);
726 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
727 msi_set_property( package
->db
, L
"PhysicalMemory", bufstr
, len
);
729 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
730 ptr
= wcschr(pth
,'\\');
731 if (ptr
) *(ptr
+ 1) = 0;
732 msi_set_property( package
->db
, L
"WindowsVolume", pth
, -1 );
734 len
= GetTempPathW(MAX_PATH
, pth
);
735 msi_set_property( package
->db
, L
"TempFolder", pth
, len
);
737 /* in a wine environment the user is always admin and privileged */
738 msi_set_property( package
->db
, L
"AdminUser", L
"1", -1 );
739 msi_set_property( package
->db
, L
"Privileged", L
"1", -1 );
740 msi_set_property( package
->db
, L
"MsiRunningElevated", L
"1", -1 );
742 /* set the os things */
743 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVersion
);
744 RtlGetVersion(&OSVersion
);
745 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
749 OSVersion
.dwBuildNumber
= 9600;
751 len
= swprintf( verstr
, ARRAY_SIZE(verstr
), L
"%u", verval
);
752 switch (OSVersion
.dwPlatformId
)
754 case VER_PLATFORM_WIN32_WINDOWS
:
755 msi_set_property( package
->db
, L
"Version9X", verstr
, len
);
757 case VER_PLATFORM_WIN32_NT
:
758 msi_set_property( package
->db
, L
"VersionNT", verstr
, len
);
759 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", OSVersion
.wProductType
);
760 msi_set_property( package
->db
, L
"MsiNTProductType", bufstr
, len
);
763 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", OSVersion
.dwBuildNumber
);
764 msi_set_property( package
->db
, L
"WindowsBuild", bufstr
, len
);
765 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", OSVersion
.wServicePackMajor
);
766 msi_set_property( package
->db
, L
"ServicePackLevel", bufstr
, len
);
768 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u.%u", MSI_MAJORVERSION
, MSI_MINORVERSION
);
769 msi_set_property( package
->db
, L
"VersionMsi", bufstr
, len
);
770 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", MSI_MAJORVERSION
* 100 );
771 msi_set_property( package
->db
, L
"VersionDatabase", bufstr
, len
);
773 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0,
774 KEY_QUERY_VALUE
| KEY_WOW64_64KEY
, &hkey
);
776 GetNativeSystemInfo( &sys_info
);
777 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", sys_info
.wProcessorLevel
);
778 msi_set_property( package
->db
, L
"Intel", bufstr
, len
);
779 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
781 GetSystemDirectoryW( pth
, MAX_PATH
);
782 PathAddBackslashW( pth
);
783 msi_set_property( package
->db
, L
"SystemFolder", pth
, -1 );
786 RegQueryValueExW(hkey
, L
"ProgramFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
787 PathAddBackslashW( pth
);
788 msi_set_property( package
->db
, L
"ProgramFilesFolder", pth
, -1 );
791 RegQueryValueExW(hkey
, L
"CommonFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
792 PathAddBackslashW( pth
);
793 msi_set_property( package
->db
, L
"CommonFilesFolder", pth
, -1 );
795 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
797 msi_set_property( package
->db
, L
"MsiAMD64", bufstr
, -1 );
798 msi_set_property( package
->db
, L
"Msix64", bufstr
, -1 );
799 msi_set_property( package
->db
, L
"VersionNT64", verstr
, -1 );
801 GetSystemDirectoryW( pth
, MAX_PATH
);
802 PathAddBackslashW( pth
);
803 msi_set_property( package
->db
, L
"System64Folder", pth
, -1 );
805 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
806 PathAddBackslashW( pth
);
807 msi_set_property( package
->db
, L
"SystemFolder", pth
, -1 );
810 RegQueryValueExW(hkey
, L
"ProgramFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
811 PathAddBackslashW( pth
);
812 msi_set_property( package
->db
, L
"ProgramFiles64Folder", pth
, -1 );
815 RegQueryValueExW(hkey
, L
"ProgramFilesDir (x86)", 0, &type
, (BYTE
*)pth
, &len
);
816 PathAddBackslashW( pth
);
817 msi_set_property( package
->db
, L
"ProgramFilesFolder", pth
, -1 );
820 RegQueryValueExW(hkey
, L
"CommonFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
821 PathAddBackslashW( pth
);
822 msi_set_property( package
->db
, L
"CommonFiles64Folder", pth
, -1 );
825 RegQueryValueExW(hkey
, L
"CommonFilesDir (x86)", 0, &type
, (BYTE
*)pth
, &len
);
826 PathAddBackslashW( pth
);
827 msi_set_property( package
->db
, L
"CommonFilesFolder", pth
, -1 );
832 /* Screen properties. */
834 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", GetDeviceCaps(dc
, HORZRES
) );
835 msi_set_property( package
->db
, L
"ScreenX", bufstr
, len
);
836 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", GetDeviceCaps(dc
, VERTRES
) );
837 msi_set_property( package
->db
, L
"ScreenY", bufstr
, len
);
838 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", GetDeviceCaps(dc
, BITSPIXEL
) );
839 msi_set_property( package
->db
, L
"ColorBits", bufstr
, len
);
842 /* USERNAME and COMPANYNAME */
843 username
= msi_dup_property( package
->db
, L
"USERNAME" );
844 companyname
= msi_dup_property( package
->db
, L
"COMPANYNAME" );
846 if ((!username
|| !companyname
) &&
847 RegOpenKeyW( HKEY_CURRENT_USER
, L
"SOFTWARE\\Microsoft\\MS Setup (ACME)\\User Info", &hkey
) == ERROR_SUCCESS
)
850 (username
= msi_reg_get_val_str( hkey
, L
"DefName" )))
851 msi_set_property( package
->db
, L
"USERNAME", username
, -1 );
853 (companyname
= msi_reg_get_val_str( hkey
, L
"DefCompany" )))
854 msi_set_property( package
->db
, L
"COMPANYNAME", companyname
, -1 );
857 if ((!username
|| !companyname
) &&
858 RegOpenKeyExW( HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0,
859 KEY_QUERY_VALUE
|KEY_WOW64_64KEY
, &hkey
) == ERROR_SUCCESS
)
862 (username
= msi_reg_get_val_str( hkey
, L
"RegisteredOwner" )))
863 msi_set_property( package
->db
, L
"USERNAME", username
, -1 );
865 (companyname
= msi_reg_get_val_str( hkey
, L
"RegisteredOrganization" )))
866 msi_set_property( package
->db
, L
"COMPANYNAME", companyname
, -1 );
869 msi_free( username
);
870 msi_free( companyname
);
872 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
873 ERR("Failed to set the UserSID property\n");
875 set_msi_assembly_prop( package
);
877 langid
= GetUserDefaultLangID();
878 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", langid
);
879 msi_set_property( package
->db
, L
"UserLanguageID", bufstr
, len
);
881 langid
= GetSystemDefaultLangID();
882 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", langid
);
883 msi_set_property( package
->db
, L
"SystemLanguageID", bufstr
, len
);
885 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", MsiQueryProductStateW(package
->ProductCode
) );
886 msi_set_property( package
->db
, L
"ProductState", bufstr
, len
);
889 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
892 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
894 if (GetUserNameW( username
, &len
))
895 msi_set_property( package
->db
, L
"LogonUser", username
, len
- 1 );
896 msi_free( username
);
900 if (!GetComputerNameW( NULL
, &len
) && GetLastError() == ERROR_BUFFER_OVERFLOW
)
903 if ((computername
= msi_alloc( len
* sizeof(WCHAR
) )))
905 if (GetComputerNameW( computername
, &len
))
906 msi_set_property( package
->db
, L
"ComputerName", computername
, len
);
907 msi_free( computername
);
912 static MSIPACKAGE
*msi_alloc_package( void )
916 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
920 list_init( &package
->components
);
921 list_init( &package
->features
);
922 list_init( &package
->files
);
923 list_init( &package
->filepatches
);
924 list_init( &package
->tempfiles
);
925 list_init( &package
->folders
);
926 list_init( &package
->subscriptions
);
927 list_init( &package
->appids
);
928 list_init( &package
->classes
);
929 list_init( &package
->mimes
);
930 list_init( &package
->extensions
);
931 list_init( &package
->progids
);
932 list_init( &package
->RunningActions
);
933 list_init( &package
->sourcelist_info
);
934 list_init( &package
->sourcelist_media
);
935 list_init( &package
->patches
);
936 list_init( &package
->binaries
);
937 list_init( &package
->cabinet_streams
);
943 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
948 r
= read_stream_data(package
->db
->storage
, L
"AdminProperties", FALSE
, &data
, &sz
);
949 if (r
!= ERROR_SUCCESS
)
952 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
958 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
960 /* FIXME: this should depend on the user's privileges */
961 if (msi_get_property_int( package
->db
, L
"ALLUSERS", 0 ) == 2)
963 TRACE("resetting ALLUSERS property from 2 to 1\n");
964 msi_set_property( package
->db
, L
"ALLUSERS", L
"1", -1 );
966 msi_set_property( package
->db
, L
"AdminUser", L
"1", -1 );
967 msi_set_property( package
->db
, L
"Privileged", L
"1", -1 );
968 msi_set_property( package
->db
, L
"MsiRunningElevated", L
"1", -1 );
971 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
)
980 package
= msi_alloc_package();
983 msiobj_addref( &db
->hdr
);
986 package
->LastAction
= NULL
;
987 package
->LastActionTemplate
= NULL
;
988 package
->LastActionResult
= MSI_NULL_INTEGER
;
989 package
->WordCount
= 0;
990 package
->PackagePath
= strdupW( db
->path
);
992 create_temp_property_table( package
);
993 msi_clone_properties( package
->db
);
994 msi_adjust_privilege_properties( package
);
996 package
->ProductCode
= msi_dup_property( package
->db
, L
"ProductCode" );
998 set_installer_properties( package
);
1000 package
->ui_level
= gUILevel
;
1001 len
= swprintf( uilevel
, ARRAY_SIZE(uilevel
), L
"%u", gUILevel
& INSTALLUILEVEL_MASK
);
1002 msi_set_property( package
->db
, L
"UILevel", uilevel
, len
);
1004 r
= msi_load_suminfo_properties( package
);
1005 if (r
!= ERROR_SUCCESS
)
1007 msiobj_release( &package
->hdr
);
1011 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1012 msi_load_admin_properties( package
);
1014 package
->log_file
= INVALID_HANDLE_VALUE
;
1015 package
->script
= SCRIPT_NONE
;
1020 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1022 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1026 /* call will always fail, because size is 0,
1027 * but will return ERROR_FILE_NOT_FOUND first
1028 * if the file doesn't exist
1030 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1031 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1033 cache_entry
= msi_alloc( size
);
1034 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1036 UINT error
= GetLastError();
1037 msi_free( cache_entry
);
1041 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1042 msi_free( cache_entry
);
1043 return ERROR_SUCCESS
;
1046 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1049 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1050 return ERROR_FUNCTION_FAILED
;
1053 return ERROR_SUCCESS
;
1056 UINT
msi_create_empty_local_file( LPWSTR path
, LPCWSTR suffix
)
1058 DWORD time
, len
, i
, offset
;
1061 time
= GetTickCount();
1062 GetWindowsDirectoryW( path
, MAX_PATH
);
1063 lstrcatW( path
, L
"\\Installer\\" );
1064 CreateDirectoryW( path
, NULL
);
1066 len
= lstrlenW(path
);
1067 for (i
= 0; i
< 0x10000; i
++)
1069 offset
= swprintf( path
+ len
, MAX_PATH
- len
, L
"%x", (time
+ i
) & 0xffff );
1070 memcpy( path
+ len
+ offset
, suffix
, (lstrlenW( suffix
) + 1) * sizeof(WCHAR
) );
1071 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1072 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1073 if (handle
!= INVALID_HANDLE_VALUE
)
1075 CloseHandle(handle
);
1078 if (GetLastError() != ERROR_FILE_EXISTS
&&
1079 GetLastError() != ERROR_SHARING_VIOLATION
)
1080 return ERROR_FUNCTION_FAILED
;
1083 return ERROR_SUCCESS
;
1086 static enum platform
parse_platform( const WCHAR
*str
)
1088 if (!str
[0] || !wcscmp( str
, L
"Intel" )) return PLATFORM_INTEL
;
1089 else if (!wcscmp( str
, L
"Intel64" )) return PLATFORM_INTEL64
;
1090 else if (!wcscmp( str
, L
"x64" ) || !wcscmp( str
, L
"AMD64" )) return PLATFORM_X64
;
1091 else if (!wcscmp( str
, L
"Arm" )) return PLATFORM_ARM
;
1092 else if (!wcscmp( str
, L
"Arm64" )) return PLATFORM_ARM64
;
1093 return PLATFORM_UNRECOGNIZED
;
1096 static UINT
parse_suminfo( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1098 WCHAR
*template, *p
, *q
, *platform
;
1101 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1102 TRACE("version: %d\n", package
->version
);
1104 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1106 return ERROR_SUCCESS
; /* native accepts missing template property */
1108 TRACE("template: %s\n", debugstr_w(template));
1110 p
= wcschr( template, ';' );
1113 WARN("invalid template string %s\n", debugstr_w(template));
1114 msi_free( template );
1115 return ERROR_PATCH_PACKAGE_INVALID
;
1118 platform
= template;
1119 if ((q
= wcschr( platform
, ',' ))) *q
= 0;
1120 package
->platform
= parse_platform( platform
);
1121 while (package
->platform
== PLATFORM_UNRECOGNIZED
&& q
)
1124 if ((q
= wcschr( platform
, ',' ))) *q
= 0;
1125 package
->platform
= parse_platform( platform
);
1127 if (package
->platform
== PLATFORM_UNRECOGNIZED
)
1129 WARN("unknown platform %s\n", debugstr_w(template));
1130 msi_free( template );
1131 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1136 msi_free( template );
1137 return ERROR_SUCCESS
;
1140 for (q
= p
; (q
= wcschr( q
, ',' )); q
++) count
++;
1142 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1143 if (!package
->langids
)
1145 msi_free( template );
1146 return ERROR_OUTOFMEMORY
;
1152 q
= wcschr( p
, ',' );
1154 package
->langids
[i
] = wcstol( p
, NULL
, 10 );
1159 package
->num_langids
= i
+ 1;
1161 msi_free( template );
1162 return ERROR_SUCCESS
;
1165 static UINT
validate_package( MSIPACKAGE
*package
)
1169 if (package
->platform
== PLATFORM_INTEL64
)
1170 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1172 if (package
->platform
== PLATFORM_ARM
)
1173 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1176 if (package
->platform
== PLATFORM_ARM64
)
1177 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1179 if (package
->platform
== PLATFORM_X64
)
1181 if (!is_64bit
&& !is_wow64
)
1182 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1183 if (package
->version
< 200)
1184 return ERROR_INSTALL_PACKAGE_INVALID
;
1186 if (!package
->num_langids
)
1188 return ERROR_SUCCESS
;
1190 for (i
= 0; i
< package
->num_langids
; i
++)
1192 LANGID langid
= package
->langids
[i
];
1194 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1196 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1198 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1200 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1202 if (IsValidLocale( langid
, LCID_INSTALLED
))
1203 return ERROR_SUCCESS
;
1205 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1208 static WCHAR
*get_property( MSIDATABASE
*db
, const WCHAR
*prop
)
1210 WCHAR query
[MAX_PATH
];
1215 swprintf(query
, ARRAY_SIZE(query
), L
"SELECT `Value` FROM `Property` WHERE `Property`='%s'", prop
);
1216 if (MSI_DatabaseOpenViewW( db
, query
, &view
) != ERROR_SUCCESS
)
1220 if (MSI_ViewExecute( view
, 0 ) != ERROR_SUCCESS
)
1222 MSI_ViewClose( view
);
1223 msiobj_release( &view
->hdr
);
1226 if (MSI_ViewFetch( view
, &rec
) == ERROR_SUCCESS
)
1228 ret
= strdupW( MSI_RecordGetString( rec
, 1 ) );
1229 msiobj_release( &rec
->hdr
);
1231 MSI_ViewClose( view
);
1232 msiobj_release( &view
->hdr
);
1236 static WCHAR
*get_product_code( MSIDATABASE
*db
)
1238 return get_property( db
, L
"ProductCode" );
1241 static WCHAR
*get_product_version( MSIDATABASE
*db
)
1243 return get_property( db
, L
"ProductVersion" );
1246 static UINT
get_registered_local_package( const WCHAR
*product
, WCHAR
*localfile
)
1248 MSIINSTALLCONTEXT context
;
1253 r
= msi_locate_product( product
, &context
);
1254 if (r
!= ERROR_SUCCESS
)
1257 r
= MSIREG_OpenInstallProps( product
, context
, NULL
, &props_key
, FALSE
);
1258 if (r
!= ERROR_SUCCESS
)
1261 filename
= msi_reg_get_val_str( props_key
, INSTALLPROPERTY_LOCALPACKAGEW
);
1262 RegCloseKey( props_key
);
1264 return ERROR_FUNCTION_FAILED
;
1266 lstrcpyW( localfile
, filename
);
1267 msi_free( filename
);
1268 return ERROR_SUCCESS
;
1271 WCHAR
*msi_get_package_code( MSIDATABASE
*db
)
1277 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1278 if (r
!= ERROR_SUCCESS
)
1280 r
= msi_get_db_suminfo( db
, 0, &si
);
1281 if (r
!= ERROR_SUCCESS
)
1283 WARN("failed to load summary info %u\n", r
);
1287 ret
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
1288 msiobj_release( &si
->hdr
);
1292 static UINT
get_local_package( MSIDATABASE
*db
, WCHAR
*localfile
)
1294 WCHAR
*product_code
;
1297 if (!(product_code
= get_product_code( db
)))
1298 return ERROR_INSTALL_PACKAGE_INVALID
;
1299 r
= get_registered_local_package( product_code
, localfile
);
1300 msi_free( product_code
);
1304 UINT
msi_set_original_database_property( MSIDATABASE
*db
, const WCHAR
*package
)
1308 if (UrlIsW( package
, URLIS_URL
))
1309 r
= msi_set_property( db
, L
"OriginalDatabase", package
, -1 );
1310 else if (package
[0] == '#')
1311 r
= msi_set_property( db
, L
"OriginalDatabase", db
->path
, -1 );
1317 if (!(len
= GetFullPathNameW( package
, 0, NULL
, NULL
))) return GetLastError();
1318 if (!(path
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1319 len
= GetFullPathNameW( package
, len
, path
, NULL
);
1320 r
= msi_set_property( db
, L
"OriginalDatabase", path
, len
);
1326 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, DWORD dwOptions
, MSIPACKAGE
**pPackage
)
1329 MSIPACKAGE
*package
;
1331 MSIRECORD
*data_row
, *info_row
;
1333 WCHAR localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1334 LPCWSTR file
= szPackage
;
1337 BOOL delete_on_close
= FALSE
;
1338 WCHAR
*info_template
, *productname
, *product_code
;
1339 MSIINSTALLCONTEXT context
;
1341 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1343 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_INITIALIZE
, 0);
1346 if( szPackage
[0] == '#' )
1348 handle
= wcstol(&szPackage
[1], NULL
, 10);
1349 if (!(db
= msihandle2msiinfo(handle
, MSIHANDLETYPE_DATABASE
)))
1350 return ERROR_INVALID_HANDLE
;
1354 WCHAR
*product_version
= NULL
;
1356 if ( UrlIsW( szPackage
, URLIS_URL
) )
1358 r
= msi_download_file( szPackage
, cachefile
);
1359 if (r
!= ERROR_SUCCESS
)
1364 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
1365 if (r
!= ERROR_SUCCESS
)
1367 if (GetFileAttributesW( file
) == INVALID_FILE_ATTRIBUTES
)
1368 return ERROR_FILE_NOT_FOUND
;
1371 r
= get_local_package( db
, localfile
);
1372 if (r
!= ERROR_SUCCESS
|| GetFileAttributesW( localfile
) == INVALID_FILE_ATTRIBUTES
)
1374 DWORD localfile_attr
;
1376 r
= msi_create_empty_local_file( localfile
, L
".msi" );
1377 if (r
!= ERROR_SUCCESS
)
1379 msiobj_release( &db
->hdr
);
1383 if (!CopyFileW( file
, localfile
, FALSE
))
1386 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file
), debugstr_w(localfile
), r
);
1387 DeleteFileW( localfile
);
1388 msiobj_release( &db
->hdr
);
1391 delete_on_close
= TRUE
;
1393 /* Remove read-only bit, we are opening it with write access in MSI_OpenDatabaseW below. */
1394 localfile_attr
= GetFileAttributesW( localfile
);
1395 if (localfile_attr
& FILE_ATTRIBUTE_READONLY
)
1396 SetFileAttributesW( localfile
, localfile_attr
& ~FILE_ATTRIBUTE_READONLY
);
1398 else if (dwOptions
& WINE_OPENPACKAGEFLAGS_RECACHE
)
1400 if (!CopyFileW( file
, localfile
, FALSE
))
1403 WARN("unable to update cached package (%u)\n", r
);
1404 msiobj_release( &db
->hdr
);
1409 product_version
= get_product_version( db
);
1410 msiobj_release( &db
->hdr
);
1411 TRACE("opening package %s\n", debugstr_w( localfile
));
1412 r
= MSI_OpenDatabaseW( localfile
, MSIDBOPEN_TRANSACT
, &db
);
1413 if (r
!= ERROR_SUCCESS
)
1416 if (product_version
)
1418 WCHAR
*cache_version
= get_product_version( db
);
1419 if (!product_version
!= !cache_version
||
1420 (product_version
&& wcscmp(product_version
, cache_version
)))
1422 msiobj_release( &db
->hdr
);
1423 msi_free(product_version
);
1424 msi_free(cache_version
);
1425 return ERROR_PRODUCT_VERSION
;
1427 msi_free(product_version
);
1428 msi_free(cache_version
);
1431 package
= MSI_CreatePackage( db
);
1432 msiobj_release( &db
->hdr
);
1433 if (!package
) return ERROR_INSTALL_PACKAGE_INVALID
;
1434 package
->localfile
= strdupW( localfile
);
1435 package
->delete_on_close
= delete_on_close
;
1437 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1438 if (r
!= ERROR_SUCCESS
)
1440 r
= msi_get_db_suminfo( db
, 0, &si
);
1441 if (r
!= ERROR_SUCCESS
)
1443 WARN("failed to load summary info\n");
1444 msiobj_release( &package
->hdr
);
1445 return ERROR_INSTALL_PACKAGE_INVALID
;
1448 r
= parse_suminfo( si
, package
);
1449 msiobj_release( &si
->hdr
);
1450 if (r
!= ERROR_SUCCESS
)
1452 WARN("failed to parse summary info %u\n", r
);
1453 msiobj_release( &package
->hdr
);
1456 r
= validate_package( package
);
1457 if (r
!= ERROR_SUCCESS
)
1459 msiobj_release( &package
->hdr
);
1462 msi_set_property( package
->db
, L
"DATABASE", db
->path
, -1 );
1463 set_installed_prop( package
);
1464 msi_set_context( package
);
1466 product_code
= get_product_code( db
);
1467 if (msi_locate_product( product_code
, &context
) == ERROR_SUCCESS
)
1469 TRACE("product already registered\n");
1470 msi_set_property( package
->db
, L
"ProductToBeRegistered", L
"1", -1 );
1472 msi_free(product_code
);
1476 WCHAR patch_code
[GUID_SIZE
];
1477 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1478 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1479 if (r
!= ERROR_SUCCESS
)
1482 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1484 r
= msi_apply_registered_patch( package
, patch_code
);
1485 if (r
!= ERROR_SUCCESS
)
1487 ERR("registered patch failed to apply %u\n", r
);
1488 msiobj_release( &package
->hdr
);
1493 if (index
) msi_adjust_privilege_properties( package
);
1495 r
= msi_set_original_database_property( package
->db
, szPackage
);
1496 if (r
!= ERROR_SUCCESS
)
1498 msiobj_release( &package
->hdr
);
1502 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1503 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1505 if (!msi_init_assembly_caches( package
))
1507 ERR("can't initialize assembly caches\n");
1508 msiobj_release( &package
->hdr
);
1509 return ERROR_FUNCTION_FAILED
;
1512 /* FIXME: when should these messages be sent? */
1513 data_row
= MSI_CreateRecord(3);
1515 return ERROR_OUTOFMEMORY
;
1516 MSI_RecordSetStringW(data_row
, 0, NULL
);
1517 MSI_RecordSetInteger(data_row
, 1, 0);
1518 MSI_RecordSetInteger(data_row
, 2, package
->num_langids
? package
->langids
[0] : 0);
1519 MSI_RecordSetInteger(data_row
, 3, msi_get_string_table_codepage(package
->db
->strings
));
1520 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1522 info_row
= MSI_CreateRecord(0);
1525 msiobj_release(&data_row
->hdr
);
1526 return ERROR_OUTOFMEMORY
;
1528 info_template
= msi_get_error_message(package
->db
, MSIERR_INFO_LOGGINGSTART
);
1529 MSI_RecordSetStringW(info_row
, 0, info_template
);
1530 msi_free(info_template
);
1531 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, info_row
);
1533 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1535 productname
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
1536 MSI_RecordSetInteger(data_row
, 1, 1);
1537 MSI_RecordSetStringW(data_row
, 2, productname
);
1538 MSI_RecordSetStringW(data_row
, 3, NULL
);
1539 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1541 msi_free(productname
);
1542 msiobj_release(&info_row
->hdr
);
1543 msiobj_release(&data_row
->hdr
);
1545 *pPackage
= package
;
1546 return ERROR_SUCCESS
;
1549 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1551 MSIPACKAGE
*package
= NULL
;
1554 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1556 if( !szPackage
|| !phPackage
)
1557 return ERROR_INVALID_PARAMETER
;
1561 FIXME("Should create an empty database and package\n");
1562 return ERROR_FUNCTION_FAILED
;
1566 FIXME("dwOptions %08x not supported\n", dwOptions
);
1568 ret
= MSI_OpenPackageW( szPackage
, 0, &package
);
1569 if( ret
== ERROR_SUCCESS
)
1571 *phPackage
= alloc_msihandle( &package
->hdr
);
1573 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1574 msiobj_release( &package
->hdr
);
1577 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_TERMINATE
, 0);
1582 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1584 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1587 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1589 LPWSTR szwPack
= NULL
;
1594 szwPack
= strdupAtoW( szPackage
);
1596 return ERROR_OUTOFMEMORY
;
1599 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1601 msi_free( szwPack
);
1606 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1608 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1611 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1613 MSIPACKAGE
*package
;
1614 MSIHANDLE handle
= 0;
1617 TRACE("(%d)\n",hInstall
);
1619 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1622 handle
= alloc_msihandle( &package
->db
->hdr
);
1623 msiobj_release( &package
->hdr
);
1625 else if ((remote
= msi_get_remote(hInstall
)))
1629 handle
= remote_GetActiveDatabase(remote
);
1630 handle
= alloc_msi_remote_handle(handle
);
1632 __EXCEPT(rpc_filter
)
1642 static INT
internal_ui_handler(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
, LPCWSTR message
)
1644 if (!package
|| (package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
1647 /* todo: check if message needs additional styles (topmost/foreground/modality?) */
1649 switch (eMessageType
& 0xff000000)
1651 case INSTALLMESSAGE_FATALEXIT
:
1652 case INSTALLMESSAGE_ERROR
:
1653 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1654 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1655 if (!(eMessageType
& MB_ICONMASK
))
1656 eMessageType
|= MB_ICONEXCLAMATION
;
1657 return MessageBoxW(gUIhwnd
, message
, L
"Windows Installer", eMessageType
& 0x00ffffff);
1658 case INSTALLMESSAGE_WARNING
:
1659 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1660 if (!(eMessageType
& MB_ICONMASK
))
1661 eMessageType
|= MB_ICONASTERISK
;
1662 return MessageBoxW(gUIhwnd
, message
, L
"Windows Installer", eMessageType
& 0x00ffffff);
1663 case INSTALLMESSAGE_USER
:
1664 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1665 if (!(eMessageType
& MB_ICONMASK
))
1666 eMessageType
|= MB_USERICON
;
1667 return MessageBoxW(gUIhwnd
, message
, L
"Windows Installer", eMessageType
& 0x00ffffff);
1668 case INSTALLMESSAGE_INFO
:
1669 case INSTALLMESSAGE_INITIALIZE
:
1670 case INSTALLMESSAGE_TERMINATE
:
1671 case INSTALLMESSAGE_INSTALLSTART
:
1672 case INSTALLMESSAGE_INSTALLEND
:
1674 case INSTALLMESSAGE_SHOWDIALOG
:
1676 LPWSTR dialog
= msi_dup_record_field(record
, 0);
1677 INT rc
= ACTION_DialogBox(package
, dialog
);
1681 case INSTALLMESSAGE_ACTIONSTART
:
1684 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1685 if (!uirow
) return -1;
1686 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformatted
);
1687 MSI_RecordSetStringW(uirow
, 1, deformatted
);
1688 msi_event_fire(package
, L
"ActionText", uirow
);
1690 msi_free(deformatted
);
1691 msiobj_release(&uirow
->hdr
);
1694 case INSTALLMESSAGE_ACTIONDATA
:
1696 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1697 if (!uirow
) return -1;
1698 MSI_RecordSetStringW(uirow
, 1, message
);
1699 msi_event_fire(package
, L
"ActionData", uirow
);
1700 msiobj_release(&uirow
->hdr
);
1702 if (package
->action_progress_increment
)
1704 uirow
= MSI_CreateRecord(2);
1705 if (!uirow
) return -1;
1706 MSI_RecordSetInteger(uirow
, 1, 2);
1707 MSI_RecordSetInteger(uirow
, 2, package
->action_progress_increment
);
1708 msi_event_fire(package
, L
"SetProgress", uirow
);
1709 msiobj_release(&uirow
->hdr
);
1713 case INSTALLMESSAGE_PROGRESS
:
1714 msi_event_fire(package
, L
"SetProgress", record
);
1716 case INSTALLMESSAGE_COMMONDATA
:
1717 switch (MSI_RecordGetInteger(record
, 1))
1728 FIXME("internal UI not implemented for message 0x%08x (UI level = %x)\n", eMessageType
, package
->ui_level
);
1740 {2726, L
"DEBUG: Error [1]: Action not found: [2]"},
1744 static LPCWSTR
get_internal_error_message(int error
)
1748 while (internal_errors
[i
].id
!= 0)
1750 if (internal_errors
[i
].id
== error
)
1751 return internal_errors
[i
].text
;
1755 FIXME("missing error message %d\n", error
);
1759 /* Returned string must be freed */
1760 LPWSTR
msi_get_error_message(MSIDATABASE
*db
, int error
)
1765 if ((record
= MSI_QueryGetRecord(db
, L
"SELECT `Message` FROM `Error` WHERE `Error` = %d", error
)))
1767 ret
= msi_dup_record_field(record
, 1);
1768 msiobj_release(&record
->hdr
);
1770 else if (error
< 2000)
1772 int len
= LoadStringW(msi_hInstance
, IDS_ERROR_BASE
+ error
, (LPWSTR
) &ret
, 0);
1775 ret
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
1776 LoadStringW(msi_hInstance
, IDS_ERROR_BASE
+ error
, ret
, len
+ 1);
1785 INT
MSI_ProcessMessageVerbatim(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1787 LPWSTR message
= {0};
1789 DWORD log_type
= 1 << (eMessageType
>> 24);
1794 TRACE("%x\n", eMessageType
);
1795 if (TRACE_ON(msi
)) dump_record(record
);
1797 if (!package
|| !record
)
1800 res
= MSI_FormatRecordW(package
, record
, message
, &len
);
1801 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
1804 message
= msi_alloc(len
* sizeof(WCHAR
));
1805 if (!message
) return ERROR_OUTOFMEMORY
;
1806 MSI_FormatRecordW(package
, record
, message
, &len
);
1809 /* convert it to ANSI */
1810 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1811 msg
= msi_alloc( len
);
1812 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1814 if (gUIHandlerRecord
&& (gUIFilterRecord
& log_type
))
1816 MSIHANDLE rec
= alloc_msihandle(&record
->hdr
);
1817 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, hRecord=%u)\n",
1818 gUIHandlerRecord
, gUIContextRecord
, eMessageType
, rec
);
1819 rc
= gUIHandlerRecord( gUIContextRecord
, eMessageType
, rec
);
1820 MsiCloseHandle( rec
);
1822 if (!rc
&& gUIHandlerW
&& (gUIFilter
& log_type
))
1824 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1825 gUIHandlerW
, gUIContext
, eMessageType
, debugstr_w(message
));
1826 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1828 else if (!rc
&& gUIHandlerA
&& (gUIFilter
& log_type
))
1830 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1831 gUIHandlerA
, gUIContext
, eMessageType
, debugstr_a(msg
));
1832 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1836 rc
= internal_ui_handler(package
, eMessageType
, record
, message
);
1838 if (!rc
&& package
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1839 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1842 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1843 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1846 msi_free( message
);
1851 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1853 switch (eMessageType
& 0xff000000)
1855 case INSTALLMESSAGE_FATALEXIT
:
1856 case INSTALLMESSAGE_ERROR
:
1857 case INSTALLMESSAGE_WARNING
:
1858 case INSTALLMESSAGE_USER
:
1859 case INSTALLMESSAGE_INFO
:
1860 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1861 if (MSI_RecordGetInteger(record
, 1) != MSI_NULL_INTEGER
)
1866 LPWSTR template_rec
= NULL
, template_prefix
= NULL
;
1867 int error
= MSI_RecordGetInteger(record
, 1);
1869 if (MSI_RecordIsNull(record
, 0))
1873 template_rec
= msi_get_error_message(package
->db
, error
);
1875 if (!template_rec
&& error
>= 2000)
1877 /* internal error, not localized */
1878 if ((template_rec
= (LPWSTR
) get_internal_error_message(error
)))
1880 MSI_RecordSetStringW(record
, 0, template_rec
);
1881 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_INFO
, record
);
1883 template_rec
= msi_get_error_message(package
->db
, MSIERR_INSTALLERROR
);
1884 MSI_RecordSetStringW(record
, 0, template_rec
);
1885 MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
1886 msi_free(template_rec
);
1892 template_rec
= msi_dup_record_field(record
, 0);
1894 template_prefix
= msi_get_error_message(package
->db
, eMessageType
>> 24);
1895 if (!template_prefix
) template_prefix
= strdupW(L
"");
1899 /* always returns 0 */
1900 MSI_RecordSetStringW(record
, 0, template_prefix
);
1901 MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
1902 msi_free(template_prefix
);
1906 template = msi_alloc((lstrlenW(template_rec
) + lstrlenW(template_prefix
) + 1) * sizeof(WCHAR
));
1907 if (!template) return ERROR_OUTOFMEMORY
;
1909 lstrcpyW(template, template_prefix
);
1910 lstrcatW(template, template_rec
);
1911 MSI_RecordSetStringW(record
, 0, template);
1913 msi_free(template_prefix
);
1914 msi_free(template_rec
);
1918 case INSTALLMESSAGE_ACTIONSTART
:
1920 WCHAR
*template = msi_get_error_message(package
->db
, MSIERR_ACTIONSTART
);
1921 MSI_RecordSetStringW(record
, 0, template);
1924 msi_free(package
->LastAction
);
1925 msi_free(package
->LastActionTemplate
);
1926 package
->LastAction
= msi_dup_record_field(record
, 1);
1927 if (!package
->LastAction
) package
->LastAction
= strdupW(L
"");
1928 package
->LastActionTemplate
= msi_dup_record_field(record
, 3);
1931 case INSTALLMESSAGE_ACTIONDATA
:
1932 if (package
->LastAction
&& package
->LastActionTemplate
)
1934 size_t len
= lstrlenW(package
->LastAction
) + lstrlenW(package
->LastActionTemplate
) + 7;
1935 WCHAR
*template = msi_alloc(len
* sizeof(WCHAR
));
1936 if (!template) return ERROR_OUTOFMEMORY
;
1937 swprintf(template, len
, L
"{{%s: }}%s", package
->LastAction
, package
->LastActionTemplate
);
1938 MSI_RecordSetStringW(record
, 0, template);
1942 case INSTALLMESSAGE_COMMONDATA
:
1944 WCHAR
*template = msi_get_error_message(package
->db
, MSIERR_COMMONDATA
);
1945 MSI_RecordSetStringW(record
, 0, template);
1951 return MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
1954 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1957 UINT ret
= ERROR_INVALID_HANDLE
;
1958 MSIPACKAGE
*package
= NULL
;
1959 MSIRECORD
*record
= NULL
;
1961 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
||
1962 (eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
1965 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
&&
1966 MsiRecordGetInteger(hRecord
, 1) != 2)
1969 record
= msihandle2msiinfo(hRecord
, MSIHANDLETYPE_RECORD
);
1971 return ERROR_INVALID_HANDLE
;
1973 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1978 if (!(remote
= msi_get_remote(hInstall
)))
1979 return ERROR_INVALID_HANDLE
;
1983 ret
= remote_ProcessMessage(remote
, eMessageType
, (struct wire_record
*)&record
->count
);
1985 __EXCEPT(rpc_filter
)
1987 ret
= GetExceptionCode();
1991 msiobj_release(&record
->hdr
);
1995 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1997 msiobj_release( &record
->hdr
);
1998 msiobj_release( &package
->hdr
);
2004 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
2006 LPWSTR szwName
= NULL
, szwValue
= NULL
;
2007 UINT r
= ERROR_OUTOFMEMORY
;
2009 szwName
= strdupAtoW( szName
);
2010 if( szName
&& !szwName
)
2013 szwValue
= strdupAtoW( szValue
);
2014 if( szValue
&& !szwValue
)
2017 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
2020 msi_free( szwName
);
2021 msi_free( szwValue
);
2026 void msi_reset_source_folders( MSIPACKAGE
*package
)
2030 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
2032 msi_free( folder
->ResolvedSource
);
2033 folder
->ResolvedSource
= NULL
;
2037 UINT
msi_set_property( MSIDATABASE
*db
, const WCHAR
*name
, const WCHAR
*value
, int len
)
2040 MSIRECORD
*row
= NULL
;
2045 TRACE("%p %s %s %d\n", db
, debugstr_w(name
), debugstr_wn(value
, len
), len
);
2048 return ERROR_INVALID_PARAMETER
;
2050 /* this one is weird... */
2052 return value
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
2054 if (value
&& len
< 0) len
= lstrlenW( value
);
2056 rc
= msi_get_property( db
, name
, 0, &sz
);
2057 if (!value
|| (!*value
&& !len
))
2059 swprintf( query
, ARRAY_SIZE(query
), L
"DELETE FROM `_Property` WHERE `_Property` = '%s'", name
);
2061 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
2063 swprintf( query
, ARRAY_SIZE(query
), L
"UPDATE `_Property` SET `Value` = ? WHERE `_Property` = '%s'", name
);
2064 row
= MSI_CreateRecord(1);
2065 msi_record_set_string( row
, 1, value
, len
);
2069 lstrcpyW( query
, L
"INSERT INTO `_Property` (`_Property`,`Value`) VALUES (?,?)" );
2070 row
= MSI_CreateRecord(2);
2071 msi_record_set_string( row
, 1, name
, -1 );
2072 msi_record_set_string( row
, 2, value
, len
);
2075 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2076 if (rc
== ERROR_SUCCESS
)
2078 rc
= MSI_ViewExecute(view
, row
);
2079 MSI_ViewClose(view
);
2080 msiobj_release(&view
->hdr
);
2082 if (row
) msiobj_release(&row
->hdr
);
2086 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2088 MSIPACKAGE
*package
;
2091 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2096 if (!(remote
= msi_get_remote(hInstall
)))
2097 return ERROR_INVALID_HANDLE
;
2101 ret
= remote_SetProperty(remote
, szName
, szValue
);
2103 __EXCEPT(rpc_filter
)
2105 ret
= GetExceptionCode();
2112 ret
= msi_set_property( package
->db
, szName
, szValue
, -1 );
2113 if (ret
== ERROR_SUCCESS
&& !wcscmp( szName
, L
"SourceDir" ))
2114 msi_reset_source_folders( package
);
2116 msiobj_release( &package
->hdr
);
2120 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2122 MSIRECORD
*rec
, *row
= NULL
;
2128 if (!name
|| !*name
)
2131 if (!wcscmp(name
, L
"Date"))
2133 length
= GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, NULL
, 0);
2136 buffer
= msi_alloc(length
* sizeof(WCHAR
));
2137 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, buffer
, length
);
2139 row
= MSI_CreateRecord(1);
2145 MSI_RecordSetStringW(row
, 1, buffer
);
2149 else if (!wcscmp(name
, L
"Time"))
2151 length
= GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOTIMEMARKER
, NULL
, NULL
, NULL
, 0);
2154 buffer
= msi_alloc(length
* sizeof(WCHAR
));
2155 GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOTIMEMARKER
, NULL
, NULL
, buffer
, length
);
2157 row
= MSI_CreateRecord(1);
2163 MSI_RecordSetStringW(row
, 1, buffer
);
2168 rec
= MSI_CreateRecord(1);
2172 MSI_RecordSetStringW(rec
, 1, name
);
2174 r
= MSI_DatabaseOpenViewW(db
, L
"SELECT `Value` FROM `_Property` WHERE `_Property`=?", &view
);
2175 if (r
== ERROR_SUCCESS
)
2177 MSI_ViewExecute(view
, rec
);
2178 MSI_ViewFetch(view
, &row
);
2179 MSI_ViewClose(view
);
2180 msiobj_release(&view
->hdr
);
2182 msiobj_release(&rec
->hdr
);
2186 /* internal function, not compatible with MsiGetPropertyW */
2187 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2188 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2191 UINT rc
= ERROR_FUNCTION_FAILED
;
2193 TRACE("%p %s %p %p\n", db
, debugstr_w(szName
), szValueBuf
, pchValueBuf
);
2195 row
= msi_get_property_row( db
, szName
);
2197 if (*pchValueBuf
> 0)
2202 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2203 msiobj_release(&row
->hdr
);
2206 if (rc
== ERROR_SUCCESS
)
2207 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf
, *pchValueBuf
),
2208 debugstr_w(szName
));
2209 else if (rc
== ERROR_MORE_DATA
)
2210 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2211 debugstr_w(szName
));
2215 TRACE("property %s not found\n", debugstr_w(szName
));
2221 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2227 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2228 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2232 str
= msi_alloc(sz
* sizeof(WCHAR
));
2233 r
= msi_get_property(db
, prop
, str
, &sz
);
2234 if (r
!= ERROR_SUCCESS
)
2243 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2245 LPWSTR str
= msi_dup_property( db
, prop
);
2246 int val
= str
? wcstol(str
, NULL
, 10) : def
;
2251 UINT WINAPI
MsiGetPropertyA(MSIHANDLE hinst
, const char *name
, char *buf
, DWORD
*sz
)
2253 const WCHAR
*value
= L
"";
2254 MSIPACKAGE
*package
;
2261 return ERROR_INVALID_PARAMETER
;
2263 if (!(nameW
= strdupAtoW(name
)))
2264 return ERROR_OUTOFMEMORY
;
2266 package
= msihandle2msiinfo(hinst
, MSIHANDLETYPE_PACKAGE
);
2269 WCHAR
*value
= NULL
, *tmp
;
2273 if (!(remote
= msi_get_remote(hinst
)))
2276 return ERROR_INVALID_HANDLE
;
2281 r
= remote_GetProperty(remote
, nameW
, &value
, &len
);
2283 __EXCEPT(rpc_filter
)
2285 r
= GetExceptionCode();
2293 /* String might contain embedded nulls.
2294 * Native returns the correct size but truncates the string. */
2295 tmp
= heap_alloc_zero((len
+ 1) * sizeof(WCHAR
));
2298 midl_user_free(value
);
2299 return ERROR_OUTOFMEMORY
;
2301 lstrcpyW(tmp
, value
);
2303 r
= msi_strncpyWtoA(tmp
, len
, buf
, sz
, TRUE
);
2307 midl_user_free(value
);
2311 row
= msi_get_property_row(package
->db
, nameW
);
2313 value
= msi_record_get_string(row
, 1, &len
);
2315 r
= msi_strncpyWtoA(value
, len
, buf
, sz
, FALSE
);
2318 if (row
) msiobj_release(&row
->hdr
);
2319 msiobj_release(&package
->hdr
);
2323 UINT WINAPI
MsiGetPropertyW(MSIHANDLE hinst
, const WCHAR
*name
, WCHAR
*buf
, DWORD
*sz
)
2325 const WCHAR
*value
= L
"";
2326 MSIPACKAGE
*package
;
2332 return ERROR_INVALID_PARAMETER
;
2334 package
= msihandle2msiinfo(hinst
, MSIHANDLETYPE_PACKAGE
);
2337 WCHAR
*value
= NULL
, *tmp
;
2341 if (!(remote
= msi_get_remote(hinst
)))
2342 return ERROR_INVALID_HANDLE
;
2346 r
= remote_GetProperty(remote
, name
, &value
, &len
);
2348 __EXCEPT(rpc_filter
)
2350 r
= GetExceptionCode();
2356 /* String might contain embedded nulls.
2357 * Native returns the correct size but truncates the string. */
2358 tmp
= heap_alloc_zero((len
+ 1) * sizeof(WCHAR
));
2361 midl_user_free(value
);
2362 return ERROR_OUTOFMEMORY
;
2364 lstrcpyW(tmp
, value
);
2366 r
= msi_strncpyW(tmp
, len
, buf
, sz
);
2370 midl_user_free(value
);
2374 row
= msi_get_property_row(package
->db
, name
);
2376 value
= msi_record_get_string(row
, 1, &len
);
2378 r
= msi_strncpyW(value
, len
, buf
, sz
);
2380 if (row
) msiobj_release(&row
->hdr
);
2381 msiobj_release(&package
->hdr
);
2385 MSIHANDLE __cdecl
s_remote_GetActiveDatabase(MSIHANDLE hinst
)
2387 return MsiGetActiveDatabase(hinst
);
2390 UINT __cdecl
s_remote_GetProperty(MSIHANDLE hinst
, LPCWSTR property
, LPWSTR
*value
, DWORD
*size
)
2396 r
= MsiGetPropertyW(hinst
, property
, empty
, size
);
2397 if (r
== ERROR_MORE_DATA
)
2400 *value
= midl_user_allocate(*size
* sizeof(WCHAR
));
2402 return ERROR_OUTOFMEMORY
;
2403 r
= MsiGetPropertyW(hinst
, property
, *value
, size
);
2408 UINT __cdecl
s_remote_SetProperty(MSIHANDLE hinst
, LPCWSTR property
, LPCWSTR value
)
2410 return MsiSetPropertyW(hinst
, property
, value
);
2413 int __cdecl
s_remote_ProcessMessage(MSIHANDLE hinst
, INSTALLMESSAGE message
, struct wire_record
*remote_rec
)
2419 if ((r
= unmarshal_record(remote_rec
, &rec
)))
2422 ret
= MsiProcessMessage(hinst
, message
, rec
);
2424 MsiCloseHandle(rec
);
2428 UINT __cdecl
s_remote_DoAction(MSIHANDLE hinst
, LPCWSTR action
)
2430 return MsiDoActionW(hinst
, action
);
2433 UINT __cdecl
s_remote_Sequence(MSIHANDLE hinst
, LPCWSTR table
, int sequence
)
2435 return MsiSequenceW(hinst
, table
, sequence
);
2438 UINT __cdecl
s_remote_GetTargetPath(MSIHANDLE hinst
, LPCWSTR folder
, LPWSTR
*value
)
2444 r
= MsiGetTargetPathW(hinst
, folder
, empty
, &size
);
2445 if (r
== ERROR_MORE_DATA
)
2447 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2449 return ERROR_OUTOFMEMORY
;
2450 r
= MsiGetTargetPathW(hinst
, folder
, *value
, &size
);
2455 UINT __cdecl
s_remote_SetTargetPath(MSIHANDLE hinst
, LPCWSTR folder
, LPCWSTR value
)
2457 return MsiSetTargetPathW(hinst
, folder
, value
);
2460 UINT __cdecl
s_remote_GetSourcePath(MSIHANDLE hinst
, LPCWSTR folder
, LPWSTR
*value
)
2466 r
= MsiGetSourcePathW(hinst
, folder
, empty
, &size
);
2467 if (r
== ERROR_MORE_DATA
)
2469 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2471 return ERROR_OUTOFMEMORY
;
2472 r
= MsiGetSourcePathW(hinst
, folder
, *value
, &size
);
2477 BOOL __cdecl
s_remote_GetMode(MSIHANDLE hinst
, MSIRUNMODE mode
)
2479 return MsiGetMode(hinst
, mode
);
2482 UINT __cdecl
s_remote_SetMode(MSIHANDLE hinst
, MSIRUNMODE mode
, BOOL state
)
2484 return MsiSetMode(hinst
, mode
, state
);
2487 UINT __cdecl
s_remote_GetFeatureState(MSIHANDLE hinst
, LPCWSTR feature
,
2488 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2490 return MsiGetFeatureStateW(hinst
, feature
, installed
, action
);
2493 UINT __cdecl
s_remote_SetFeatureState(MSIHANDLE hinst
, LPCWSTR feature
, INSTALLSTATE state
)
2495 return MsiSetFeatureStateW(hinst
, feature
, state
);
2498 UINT __cdecl
s_remote_GetComponentState(MSIHANDLE hinst
, LPCWSTR component
,
2499 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2501 return MsiGetComponentStateW(hinst
, component
, installed
, action
);
2504 UINT __cdecl
s_remote_SetComponentState(MSIHANDLE hinst
, LPCWSTR component
, INSTALLSTATE state
)
2506 return MsiSetComponentStateW(hinst
, component
, state
);
2509 LANGID __cdecl
s_remote_GetLanguage(MSIHANDLE hinst
)
2511 return MsiGetLanguage(hinst
);
2514 UINT __cdecl
s_remote_SetInstallLevel(MSIHANDLE hinst
, int level
)
2516 return MsiSetInstallLevel(hinst
, level
);
2519 UINT __cdecl
s_remote_FormatRecord(MSIHANDLE hinst
, struct wire_record
*remote_rec
, LPWSTR
*value
)
2526 if ((r
= unmarshal_record(remote_rec
, &rec
)))
2529 r
= MsiFormatRecordW(hinst
, rec
, empty
, &size
);
2530 if (r
== ERROR_MORE_DATA
)
2532 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2535 MsiCloseHandle(rec
);
2536 return ERROR_OUTOFMEMORY
;
2538 r
= MsiFormatRecordW(hinst
, rec
, *value
, &size
);
2541 MsiCloseHandle(rec
);
2545 MSICONDITION __cdecl
s_remote_EvaluateCondition(MSIHANDLE hinst
, LPCWSTR condition
)
2547 return MsiEvaluateConditionW(hinst
, condition
);
2550 UINT __cdecl
s_remote_GetFeatureCost(MSIHANDLE hinst
, LPCWSTR feature
,
2551 MSICOSTTREE cost_tree
, INSTALLSTATE state
, INT
*cost
)
2553 return MsiGetFeatureCostW(hinst
, feature
, cost_tree
, state
, cost
);
2556 UINT __cdecl
s_remote_EnumComponentCosts(MSIHANDLE hinst
, LPCWSTR component
,
2557 DWORD index
, INSTALLSTATE state
, LPWSTR drive
, INT
*cost
, INT
*temp
)
2560 return MsiEnumComponentCostsW(hinst
, component
, index
, state
, drive
, &size
, cost
, temp
);
2563 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2564 LPCWSTR property
, LPWSTR value
)
2566 MSISOURCELISTINFO
*info
;
2568 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2570 if (!wcscmp( info
->value
, value
)) return ERROR_SUCCESS
;
2573 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2575 return ERROR_OUTOFMEMORY
;
2577 info
->context
= context
;
2578 info
->options
= options
;
2579 info
->property
= property
;
2580 info
->value
= strdupW(value
);
2581 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2583 return ERROR_SUCCESS
;
2586 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2587 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2591 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2593 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2596 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2598 return ERROR_OUTOFMEMORY
;
2600 disk
->context
= context
;
2601 disk
->options
= options
;
2602 disk
->disk_id
= disk_id
;
2603 disk
->volume_label
= strdupW(volume_label
);
2604 disk
->disk_prompt
= strdupW(disk_prompt
);
2605 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2607 return ERROR_SUCCESS
;