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/debug.h"
47 #include "wine/exception.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
55 static void free_feature( MSIFEATURE
*feature
)
57 struct list
*item
, *cursor
;
59 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
61 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
62 list_remove( &fl
->entry
);
66 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
68 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
69 list_remove( &cl
->entry
);
72 msi_free( feature
->Feature
);
73 msi_free( feature
->Feature_Parent
);
74 msi_free( feature
->Directory
);
75 msi_free( feature
->Description
);
76 msi_free( feature
->Title
);
80 static void free_folder( MSIFOLDER
*folder
)
82 struct list
*item
, *cursor
;
84 LIST_FOR_EACH_SAFE( item
, cursor
, &folder
->children
)
86 FolderList
*fl
= LIST_ENTRY( item
, FolderList
, entry
);
87 list_remove( &fl
->entry
);
90 msi_free( folder
->Parent
);
91 msi_free( folder
->Directory
);
92 msi_free( folder
->TargetDefault
);
93 msi_free( folder
->SourceLongPath
);
94 msi_free( folder
->SourceShortPath
);
95 msi_free( folder
->ResolvedTarget
);
96 msi_free( folder
->ResolvedSource
);
100 static void free_extension( MSIEXTENSION
*ext
)
102 struct list
*item
, *cursor
;
104 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
106 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
108 list_remove( &verb
->entry
);
109 msi_free( verb
->Verb
);
110 msi_free( verb
->Command
);
111 msi_free( verb
->Argument
);
115 msi_free( ext
->Extension
);
116 msi_free( ext
->ProgIDText
);
120 static void free_assembly( MSIASSEMBLY
*assembly
)
122 msi_free( assembly
->feature
);
123 msi_free( assembly
->manifest
);
124 msi_free( assembly
->application
);
125 msi_free( assembly
->display_name
);
126 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
127 msi_free( assembly
->tempdir
);
128 msi_free( assembly
);
131 void msi_free_action_script( MSIPACKAGE
*package
, UINT script
)
134 for (i
= 0; i
< package
->script_actions_count
[script
]; i
++)
135 msi_free( package
->script_actions
[script
][i
] );
137 msi_free( package
->script_actions
[script
] );
138 package
->script_actions
[script
] = NULL
;
139 package
->script_actions_count
[script
] = 0;
142 static void free_package_structures( MSIPACKAGE
*package
)
144 struct list
*item
, *cursor
;
147 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
149 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
150 list_remove( &feature
->entry
);
151 free_feature( feature
);
154 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
156 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
157 list_remove( &folder
->entry
);
158 free_folder( folder
);
161 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
163 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
165 list_remove( &file
->entry
);
166 msi_free( file
->File
);
167 msi_free( file
->FileName
);
168 msi_free( file
->ShortName
);
169 msi_free( file
->LongName
);
170 msi_free( file
->Version
);
171 msi_free( file
->Language
);
172 if (msi_is_global_assembly( file
->Component
)) DeleteFileW( file
->TargetPath
);
173 msi_free( file
->TargetPath
);
177 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
179 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
181 list_remove( &comp
->entry
);
182 msi_free( comp
->Component
);
183 msi_free( comp
->ComponentId
);
184 msi_free( comp
->Directory
);
185 msi_free( comp
->Condition
);
186 msi_free( comp
->KeyPath
);
187 msi_free( comp
->FullKeypath
);
188 if (comp
->assembly
) free_assembly( comp
->assembly
);
192 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->filepatches
)
194 MSIFILEPATCH
*patch
= LIST_ENTRY( item
, MSIFILEPATCH
, entry
);
196 list_remove( &patch
->entry
);
197 msi_free( patch
->path
);
201 /* clean up extension, progid, class and verb structures */
202 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
204 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
206 list_remove( &cls
->entry
);
207 msi_free( cls
->clsid
);
208 msi_free( cls
->Context
);
209 msi_free( cls
->Description
);
210 msi_free( cls
->FileTypeMask
);
211 msi_free( cls
->IconPath
);
212 msi_free( cls
->DefInprocHandler
);
213 msi_free( cls
->DefInprocHandler32
);
214 msi_free( cls
->Argument
);
215 msi_free( cls
->ProgIDText
);
219 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
221 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
223 list_remove( &ext
->entry
);
224 free_extension( ext
);
227 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
229 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
231 list_remove( &progid
->entry
);
232 msi_free( progid
->ProgID
);
233 msi_free( progid
->Description
);
234 msi_free( progid
->IconPath
);
238 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
240 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
242 list_remove( &mt
->entry
);
243 msi_free( mt
->suffix
);
244 msi_free( mt
->clsid
);
245 msi_free( mt
->ContentType
);
249 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
251 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
253 list_remove( &appid
->entry
);
254 msi_free( appid
->AppID
);
255 msi_free( appid
->RemoteServerName
);
256 msi_free( appid
->LocalServer
);
257 msi_free( appid
->ServiceParameters
);
258 msi_free( appid
->DllSurrogate
);
262 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
264 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
266 list_remove( &info
->entry
);
267 msi_free( info
->value
);
271 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
273 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
275 list_remove( &info
->entry
);
276 msi_free( info
->volume_label
);
277 msi_free( info
->disk_prompt
);
281 for (i
= 0; i
< SCRIPT_MAX
; i
++)
282 msi_free_action_script( package
, i
);
284 for (i
= 0; i
< package
->unique_actions_count
; i
++)
285 msi_free( package
->unique_actions
[i
] );
286 msi_free( package
->unique_actions
);
288 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->binaries
)
290 MSIBINARY
*binary
= LIST_ENTRY( item
, MSIBINARY
, entry
);
292 list_remove( &binary
->entry
);
293 if (!DeleteFileW( binary
->tmpfile
))
294 ERR("failed to delete %s (%u)\n", debugstr_w(binary
->tmpfile
), GetLastError());
295 msi_free( binary
->source
);
296 msi_free( binary
->tmpfile
);
300 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->cabinet_streams
)
302 MSICABINETSTREAM
*cab
= LIST_ENTRY( item
, MSICABINETSTREAM
, entry
);
304 list_remove( &cab
->entry
);
305 IStorage_Release( cab
->storage
);
306 msi_free( cab
->stream
);
310 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
312 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
314 list_remove( &patch
->entry
);
315 if (patch
->delete_on_close
&& !DeleteFileW( patch
->localfile
))
317 ERR("failed to delete %s (%u)\n", debugstr_w(patch
->localfile
), GetLastError());
319 msi_free_patchinfo( patch
);
322 msi_free( package
->PackagePath
);
323 msi_free( package
->ProductCode
);
324 msi_free( package
->ActionFormat
);
325 msi_free( package
->LastAction
);
326 msi_free( package
->LastActionTemplate
);
327 msi_free( package
->langids
);
329 /* cleanup control event subscriptions */
330 msi_event_cleanup_all_subscriptions( package
);
333 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
335 MSIPACKAGE
*package
= (MSIPACKAGE
*)arg
;
337 msi_destroy_assembly_caches( package
);
339 if( package
->dialog
)
340 msi_dialog_destroy( package
->dialog
);
342 msiobj_release( &package
->db
->hdr
);
343 free_package_structures(package
);
344 CloseHandle( package
->log_file
);
345 if (package
->rpc_server_started
)
346 RpcServerUnregisterIf(s_IWineMsiRemote_v0_0_s_ifspec
, NULL
, FALSE
);
348 RpcBindingFree(&rpc_handle
);
349 if (package
->custom_server_32_process
)
350 custom_stop_server(package
->custom_server_32_process
, package
->custom_server_32_pipe
);
351 if (package
->custom_server_64_process
)
352 custom_stop_server(package
->custom_server_64_process
, package
->custom_server_64_pipe
);
354 if (package
->delete_on_close
) DeleteFileW( package
->localfile
);
355 msi_free( package
->localfile
);
356 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_TERMINATE
, 0);
359 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
364 rc
= MSI_DatabaseOpenViewW(package
->db
, L
"CREATE TABLE `_Property` ( `_Property` CHAR(56) NOT NULL TEMPORARY, "
365 L
"`Value` CHAR(98) NOT NULL TEMPORARY PRIMARY KEY `_Property`) HOLD", &view
);
366 if (rc
!= ERROR_SUCCESS
)
369 rc
= MSI_ViewExecute(view
, 0);
371 msiobj_release(&view
->hdr
);
375 UINT
msi_clone_properties( MSIDATABASE
*db
)
377 MSIQUERY
*view_select
;
380 rc
= MSI_DatabaseOpenViewW( db
, L
"SELECT * FROM `Property`", &view_select
);
381 if (rc
!= ERROR_SUCCESS
)
384 rc
= MSI_ViewExecute( view_select
, 0 );
385 if (rc
!= ERROR_SUCCESS
)
387 MSI_ViewClose( view_select
);
388 msiobj_release( &view_select
->hdr
);
394 MSIQUERY
*view_insert
, *view_update
;
395 MSIRECORD
*rec_select
;
397 rc
= MSI_ViewFetch( view_select
, &rec_select
);
398 if (rc
!= ERROR_SUCCESS
)
401 rc
= MSI_DatabaseOpenViewW( db
, L
"INSERT INTO `_Property` (`_Property`,`Value`) VALUES (?,?)", &view_insert
);
402 if (rc
!= ERROR_SUCCESS
)
404 msiobj_release( &rec_select
->hdr
);
408 rc
= MSI_ViewExecute( view_insert
, rec_select
);
409 MSI_ViewClose( view_insert
);
410 msiobj_release( &view_insert
->hdr
);
411 if (rc
!= ERROR_SUCCESS
)
413 MSIRECORD
*rec_update
;
415 TRACE("insert failed, trying update\n");
417 rc
= MSI_DatabaseOpenViewW( db
, L
"UPDATE `_Property` SET `Value` = ? WHERE `_Property` = ?", &view_update
);
418 if (rc
!= ERROR_SUCCESS
)
420 WARN("open view failed %u\n", rc
);
421 msiobj_release( &rec_select
->hdr
);
425 rec_update
= MSI_CreateRecord( 2 );
426 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
427 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
428 rc
= MSI_ViewExecute( view_update
, rec_update
);
429 if (rc
!= ERROR_SUCCESS
)
430 WARN("update failed %u\n", rc
);
432 MSI_ViewClose( view_update
);
433 msiobj_release( &view_update
->hdr
);
434 msiobj_release( &rec_update
->hdr
);
437 msiobj_release( &rec_select
->hdr
);
440 MSI_ViewClose( view_select
);
441 msiobj_release( &view_select
->hdr
);
448 * Sets the "Installed" property to indicate that
449 * the product is installed for the current user.
451 static UINT
set_installed_prop( MSIPACKAGE
*package
)
456 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
458 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
459 if (r
== ERROR_SUCCESS
)
462 msi_set_property( package
->db
, L
"Installed", L
"1", -1 );
467 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
471 LPWSTR sid_str
= NULL
, dom
= NULL
;
472 DWORD size
, dom_size
;
474 UINT r
= ERROR_FUNCTION_FAILED
;
477 GetUserNameW( NULL
, &size
);
479 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
481 return ERROR_OUTOFMEMORY
;
483 if (!GetUserNameW( user_name
, &size
))
488 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
490 psid
= msi_alloc( size
);
491 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
494 r
= ERROR_OUTOFMEMORY
;
498 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
501 if (!ConvertSidToStringSidW( psid
, &sid_str
))
504 r
= msi_set_property( package
->db
, L
"UserSID", sid_str
, -1 );
507 LocalFree( sid_str
);
510 msi_free( user_name
);
515 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
519 DWORD size
, len
, type
;
520 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], *filename
= NULL
;
522 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"Software\\Microsoft\\NET Framework Setup\\NDP", 0, KEY_CREATE_SUB_KEY
,
524 if (res
!= ERROR_SUCCESS
)
527 if (!RegCreateKeyExW(netsetup
, L
"v4\\Client", 0, NULL
, 0, KEY_QUERY_VALUE
, NULL
, &hkey
, NULL
))
530 if (!RegQueryValueExW(hkey
, L
"InstallPath", NULL
, &type
, (BYTE
*)path
, &size
))
532 len
= lstrlenW(path
) + lstrlenW(L
"fusion.dll") + 2;
533 if (!(filename
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
535 lstrcpyW(filename
, path
);
536 lstrcatW(filename
, L
"\\");
537 lstrcatW(filename
, L
"fusion.dll");
538 if (GetFileAttributesW(filename
) != INVALID_FILE_ATTRIBUTES
)
540 TRACE( "found %s\n", debugstr_w(filename
) );
542 RegCloseKey(netsetup
);
549 if (!RegCreateKeyExW(netsetup
, L
"v2.0.50727", 0, NULL
, 0, KEY_QUERY_VALUE
, NULL
, &hkey
, NULL
))
552 GetWindowsDirectoryW(windir
, MAX_PATH
);
553 len
= lstrlenW(windir
) + lstrlenW(L
"Microsoft.NET\\Framework\\") + lstrlenW(L
"v2.0.50727") +
554 lstrlenW(L
"fusion.dll") + 3;
555 if (!(filename
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
557 lstrcpyW(filename
, windir
);
558 lstrcatW(filename
, L
"\\");
559 lstrcatW(filename
, L
"Microsoft.NET\\Framework\\");
560 lstrcatW(filename
, L
"v2.0.50727");
561 lstrcatW(filename
, L
"\\");
562 lstrcatW(filename
, L
"fusion.dll");
563 if (GetFileAttributesW(filename
) != INVALID_FILE_ATTRIBUTES
)
565 TRACE( "found %s\n", debugstr_w(filename
) );
566 RegCloseKey(netsetup
);
571 RegCloseKey(netsetup
);
575 typedef struct tagLANGANDCODEPAGE
581 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
585 LPVOID version
= NULL
;
587 LPWSTR fusion
, verstr
;
588 LANGANDCODEPAGE
*translate
;
590 fusion
= get_fusion_filename(package
);
594 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
598 version
= msi_alloc(size
);
602 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
605 if (!VerQueryValueW(version
, L
"\\VarFileInfo\\Translation", (LPVOID
*)&translate
, &val_len
))
608 swprintf(buf
, ARRAY_SIZE(buf
), L
"\\StringFileInfo\\%04x%04x\\ProductVersion", translate
[0].wLanguage
,
609 translate
[0].wCodePage
);
611 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
614 if (!val_len
|| !verstr
)
617 msi_set_property( package
->db
, L
"MsiNetAssemblySupport", verstr
, -1 );
624 static VOID
set_installer_properties(MSIPACKAGE
*package
)
627 RTL_OSVERSIONINFOEXW OSVersion
;
629 DWORD verval
, len
, type
;
630 WCHAR pth
[MAX_PATH
], verstr
[11], bufstr
[22];
633 LPWSTR username
, companyname
;
634 SYSTEM_INFO sys_info
;
638 * Other things that probably should be set:
640 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
641 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
644 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
645 lstrcatW(pth
, L
"\\");
646 msi_set_property( package
->db
, L
"CommonAppDataFolder", pth
, -1 );
648 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
649 lstrcatW(pth
, L
"\\");
650 msi_set_property( package
->db
, L
"FavoritesFolder", pth
, -1 );
652 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
653 lstrcatW(pth
, L
"\\");
654 msi_set_property( package
->db
, L
"FontsFolder", pth
, -1 );
656 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
657 lstrcatW(pth
, L
"\\");
658 msi_set_property( package
->db
, L
"SendToFolder", pth
, -1 );
660 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
661 lstrcatW(pth
, L
"\\");
662 msi_set_property( package
->db
, L
"StartMenuFolder", pth
, -1 );
664 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
665 lstrcatW(pth
, L
"\\");
666 msi_set_property( package
->db
, L
"StartupFolder", pth
, -1 );
668 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
669 lstrcatW(pth
, L
"\\");
670 msi_set_property( package
->db
, L
"TemplateFolder", pth
, -1 );
672 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
673 lstrcatW(pth
, L
"\\");
674 msi_set_property( package
->db
, L
"DesktopFolder", pth
, -1 );
676 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
677 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
678 lstrcatW(pth
, L
"\\");
679 msi_set_property( package
->db
, L
"ProgramMenuFolder", pth
, -1 );
681 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
682 lstrcatW(pth
, L
"\\");
683 msi_set_property( package
->db
, L
"AdminToolsFolder", pth
, -1 );
685 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
686 lstrcatW(pth
, L
"\\");
687 msi_set_property( package
->db
, L
"AppDataFolder", pth
, -1 );
689 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
690 lstrcatW(pth
, L
"\\");
691 msi_set_property( package
->db
, L
"SystemFolder", pth
, -1 );
692 msi_set_property( package
->db
, L
"System16Folder", pth
, -1 );
694 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
695 lstrcatW(pth
, L
"\\");
696 msi_set_property( package
->db
, L
"LocalAppDataFolder", pth
, -1 );
698 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
699 lstrcatW(pth
, L
"\\");
700 msi_set_property( package
->db
, L
"MyPicturesFolder", pth
, -1 );
702 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
703 lstrcatW(pth
, L
"\\");
704 msi_set_property( package
->db
, L
"PersonalFolder", pth
, -1 );
706 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
707 lstrcatW(pth
, L
"\\");
708 msi_set_property( package
->db
, L
"WindowsFolder", pth
, -1 );
710 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
711 lstrcatW(pth
, L
"\\");
712 msi_set_property( package
->db
, L
"PrintHoodFolder", pth
, -1 );
714 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
715 lstrcatW(pth
, L
"\\");
716 msi_set_property( package
->db
, L
"NetHoodFolder", pth
, -1 );
718 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
719 lstrcatW(pth
, L
"\\");
720 msi_set_property( package
->db
, L
"RecentFolder", pth
, -1 );
722 /* Physical Memory is specified in MB. Using total amount. */
723 msex
.dwLength
= sizeof(msex
);
724 GlobalMemoryStatusEx( &msex
);
725 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
726 msi_set_property( package
->db
, L
"PhysicalMemory", bufstr
, len
);
728 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
729 ptr
= wcschr(pth
,'\\');
730 if (ptr
) *(ptr
+ 1) = 0;
731 msi_set_property( package
->db
, L
"WindowsVolume", pth
, -1 );
733 len
= GetTempPathW(MAX_PATH
, pth
);
734 msi_set_property( package
->db
, L
"TempFolder", pth
, len
);
736 /* in a wine environment the user is always admin and privileged */
737 msi_set_property( package
->db
, L
"AdminUser", L
"1", -1 );
738 msi_set_property( package
->db
, L
"Privileged", L
"1", -1 );
739 msi_set_property( package
->db
, L
"MsiRunningElevated", L
"1", -1 );
741 /* set the os things */
742 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVersion
);
743 RtlGetVersion(&OSVersion
);
744 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
748 OSVersion
.dwBuildNumber
= 9600;
750 len
= swprintf( verstr
, ARRAY_SIZE(verstr
), L
"%u", verval
);
751 switch (OSVersion
.dwPlatformId
)
753 case VER_PLATFORM_WIN32_WINDOWS
:
754 msi_set_property( package
->db
, L
"Version9X", verstr
, len
);
756 case VER_PLATFORM_WIN32_NT
:
757 msi_set_property( package
->db
, L
"VersionNT", verstr
, len
);
758 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", OSVersion
.wProductType
);
759 msi_set_property( package
->db
, L
"MsiNTProductType", bufstr
, len
);
762 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", OSVersion
.dwBuildNumber
);
763 msi_set_property( package
->db
, L
"WindowsBuild", bufstr
, len
);
764 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", OSVersion
.wServicePackMajor
);
765 msi_set_property( package
->db
, L
"ServicePackLevel", bufstr
, len
);
767 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u.%u", MSI_MAJORVERSION
, MSI_MINORVERSION
);
768 msi_set_property( package
->db
, L
"VersionMsi", bufstr
, len
);
769 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%u", MSI_MAJORVERSION
* 100 );
770 msi_set_property( package
->db
, L
"VersionDatabase", bufstr
, len
);
772 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", 0,
773 KEY_QUERY_VALUE
| KEY_WOW64_64KEY
, &hkey
);
775 GetNativeSystemInfo( &sys_info
);
776 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", sys_info
.wProcessorLevel
);
777 msi_set_property( package
->db
, L
"Intel", bufstr
, len
);
778 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
780 GetSystemDirectoryW( pth
, MAX_PATH
);
781 PathAddBackslashW( pth
);
782 msi_set_property( package
->db
, L
"SystemFolder", pth
, -1 );
785 RegQueryValueExW(hkey
, L
"ProgramFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
786 PathAddBackslashW( pth
);
787 msi_set_property( package
->db
, L
"ProgramFilesFolder", pth
, -1 );
790 RegQueryValueExW(hkey
, L
"CommonFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
791 PathAddBackslashW( pth
);
792 msi_set_property( package
->db
, L
"CommonFilesFolder", pth
, -1 );
794 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
796 msi_set_property( package
->db
, L
"MsiAMD64", bufstr
, -1 );
797 msi_set_property( package
->db
, L
"Msix64", bufstr
, -1 );
798 msi_set_property( package
->db
, L
"VersionNT64", verstr
, -1 );
800 GetSystemDirectoryW( pth
, MAX_PATH
);
801 PathAddBackslashW( pth
);
802 msi_set_property( package
->db
, L
"System64Folder", pth
, -1 );
804 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
805 PathAddBackslashW( pth
);
806 msi_set_property( package
->db
, L
"SystemFolder", pth
, -1 );
809 RegQueryValueExW(hkey
, L
"ProgramFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
810 PathAddBackslashW( pth
);
811 msi_set_property( package
->db
, L
"ProgramFiles64Folder", pth
, -1 );
814 RegQueryValueExW(hkey
, L
"ProgramFilesDir (x86)", 0, &type
, (BYTE
*)pth
, &len
);
815 PathAddBackslashW( pth
);
816 msi_set_property( package
->db
, L
"ProgramFilesFolder", pth
, -1 );
819 RegQueryValueExW(hkey
, L
"CommonFilesDir", 0, &type
, (BYTE
*)pth
, &len
);
820 PathAddBackslashW( pth
);
821 msi_set_property( package
->db
, L
"CommonFiles64Folder", pth
, -1 );
824 RegQueryValueExW(hkey
, L
"CommonFilesDir (x86)", 0, &type
, (BYTE
*)pth
, &len
);
825 PathAddBackslashW( pth
);
826 msi_set_property( package
->db
, L
"CommonFilesFolder", pth
, -1 );
831 /* Screen properties. */
833 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", GetDeviceCaps(dc
, HORZRES
) );
834 msi_set_property( package
->db
, L
"ScreenX", bufstr
, len
);
835 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", GetDeviceCaps(dc
, VERTRES
) );
836 msi_set_property( package
->db
, L
"ScreenY", bufstr
, len
);
837 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", GetDeviceCaps(dc
, BITSPIXEL
) );
838 msi_set_property( package
->db
, L
"ColorBits", bufstr
, len
);
841 /* USERNAME and COMPANYNAME */
842 username
= msi_dup_property( package
->db
, L
"USERNAME" );
843 companyname
= msi_dup_property( package
->db
, L
"COMPANYNAME" );
845 if ((!username
|| !companyname
) &&
846 RegOpenKeyW( HKEY_CURRENT_USER
, L
"SOFTWARE\\Microsoft\\MS Setup (ACME)\\User Info", &hkey
) == ERROR_SUCCESS
)
849 (username
= msi_reg_get_val_str( hkey
, L
"DefName" )))
850 msi_set_property( package
->db
, L
"USERNAME", username
, -1 );
852 (companyname
= msi_reg_get_val_str( hkey
, L
"DefCompany" )))
853 msi_set_property( package
->db
, L
"COMPANYNAME", companyname
, -1 );
856 if ((!username
|| !companyname
) &&
857 RegOpenKeyExW( HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0,
858 KEY_QUERY_VALUE
|KEY_WOW64_64KEY
, &hkey
) == ERROR_SUCCESS
)
861 (username
= msi_reg_get_val_str( hkey
, L
"RegisteredOwner" )))
862 msi_set_property( package
->db
, L
"USERNAME", username
, -1 );
864 (companyname
= msi_reg_get_val_str( hkey
, L
"RegisteredOrganization" )))
865 msi_set_property( package
->db
, L
"COMPANYNAME", companyname
, -1 );
868 msi_free( username
);
869 msi_free( companyname
);
871 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
872 ERR("Failed to set the UserSID property\n");
874 set_msi_assembly_prop( package
);
876 langid
= GetUserDefaultLangID();
877 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", langid
);
878 msi_set_property( package
->db
, L
"UserLanguageID", bufstr
, len
);
880 langid
= GetSystemDefaultLangID();
881 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", langid
);
882 msi_set_property( package
->db
, L
"SystemLanguageID", bufstr
, len
);
884 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), L
"%d", MsiQueryProductStateW(package
->ProductCode
) );
885 msi_set_property( package
->db
, L
"ProductState", bufstr
, len
);
888 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
891 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
893 if (GetUserNameW( username
, &len
))
894 msi_set_property( package
->db
, L
"LogonUser", username
, len
- 1 );
895 msi_free( username
);
899 if (!GetComputerNameW( NULL
, &len
) && GetLastError() == ERROR_BUFFER_OVERFLOW
)
902 if ((computername
= msi_alloc( len
* sizeof(WCHAR
) )))
904 if (GetComputerNameW( computername
, &len
))
905 msi_set_property( package
->db
, L
"ComputerName", computername
, len
);
906 msi_free( computername
);
911 static MSIPACKAGE
*msi_alloc_package( void )
915 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
919 list_init( &package
->components
);
920 list_init( &package
->features
);
921 list_init( &package
->files
);
922 list_init( &package
->filepatches
);
923 list_init( &package
->tempfiles
);
924 list_init( &package
->folders
);
925 list_init( &package
->subscriptions
);
926 list_init( &package
->appids
);
927 list_init( &package
->classes
);
928 list_init( &package
->mimes
);
929 list_init( &package
->extensions
);
930 list_init( &package
->progids
);
931 list_init( &package
->RunningActions
);
932 list_init( &package
->sourcelist_info
);
933 list_init( &package
->sourcelist_media
);
934 list_init( &package
->patches
);
935 list_init( &package
->binaries
);
936 list_init( &package
->cabinet_streams
);
942 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
947 r
= read_stream_data(package
->db
->storage
, L
"AdminProperties", FALSE
, &data
, &sz
);
948 if (r
!= ERROR_SUCCESS
)
951 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
957 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
959 /* FIXME: this should depend on the user's privileges */
960 if (msi_get_property_int( package
->db
, L
"ALLUSERS", 0 ) == 2)
962 TRACE("resetting ALLUSERS property from 2 to 1\n");
963 msi_set_property( package
->db
, L
"ALLUSERS", L
"1", -1 );
965 msi_set_property( package
->db
, L
"AdminUser", L
"1", -1 );
966 msi_set_property( package
->db
, L
"Privileged", L
"1", -1 );
967 msi_set_property( package
->db
, L
"MsiRunningElevated", L
"1", -1 );
970 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
)
979 package
= msi_alloc_package();
982 msiobj_addref( &db
->hdr
);
985 package
->LastAction
= NULL
;
986 package
->LastActionTemplate
= NULL
;
987 package
->LastActionResult
= MSI_NULL_INTEGER
;
988 package
->WordCount
= 0;
989 package
->PackagePath
= strdupW( db
->path
);
991 create_temp_property_table( package
);
992 msi_clone_properties( package
->db
);
993 msi_adjust_privilege_properties( package
);
995 package
->ProductCode
= msi_dup_property( package
->db
, L
"ProductCode" );
997 set_installer_properties( package
);
999 package
->ui_level
= gUILevel
;
1000 len
= swprintf( uilevel
, ARRAY_SIZE(uilevel
), L
"%u", gUILevel
& INSTALLUILEVEL_MASK
);
1001 msi_set_property( package
->db
, L
"UILevel", uilevel
, len
);
1003 r
= msi_load_suminfo_properties( package
);
1004 if (r
!= ERROR_SUCCESS
)
1006 msiobj_release( &package
->hdr
);
1010 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1011 msi_load_admin_properties( package
);
1013 package
->log_file
= INVALID_HANDLE_VALUE
;
1014 package
->script
= SCRIPT_NONE
;
1019 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1021 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1025 /* call will always fail, because size is 0,
1026 * but will return ERROR_FILE_NOT_FOUND first
1027 * if the file doesn't exist
1029 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1030 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1032 cache_entry
= msi_alloc( size
);
1033 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1035 UINT error
= GetLastError();
1036 msi_free( cache_entry
);
1040 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1041 msi_free( cache_entry
);
1042 return ERROR_SUCCESS
;
1045 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1048 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1049 return ERROR_FUNCTION_FAILED
;
1052 return ERROR_SUCCESS
;
1055 UINT
msi_create_empty_local_file( LPWSTR path
, LPCWSTR suffix
)
1057 DWORD time
, len
, i
, offset
;
1060 time
= GetTickCount();
1061 GetWindowsDirectoryW( path
, MAX_PATH
);
1062 lstrcatW( path
, L
"\\Installer\\" );
1063 CreateDirectoryW( path
, NULL
);
1065 len
= lstrlenW(path
);
1066 for (i
= 0; i
< 0x10000; i
++)
1068 offset
= swprintf( path
+ len
, MAX_PATH
- len
, L
"%x", (time
+ i
) & 0xffff );
1069 memcpy( path
+ len
+ offset
, suffix
, (lstrlenW( suffix
) + 1) * sizeof(WCHAR
) );
1070 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1071 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1072 if (handle
!= INVALID_HANDLE_VALUE
)
1074 CloseHandle(handle
);
1077 if (GetLastError() != ERROR_FILE_EXISTS
&&
1078 GetLastError() != ERROR_SHARING_VIOLATION
)
1079 return ERROR_FUNCTION_FAILED
;
1082 return ERROR_SUCCESS
;
1085 static enum platform
parse_platform( const WCHAR
*str
)
1087 if (!str
[0] || !wcscmp( str
, L
"Intel" )) return PLATFORM_INTEL
;
1088 else if (!wcscmp( str
, L
"Intel64" )) return PLATFORM_INTEL64
;
1089 else if (!wcscmp( str
, L
"x64" ) || !wcscmp( str
, L
"AMD64" )) return PLATFORM_X64
;
1090 else if (!wcscmp( str
, L
"Arm" )) return PLATFORM_ARM
;
1091 else if (!wcscmp( str
, L
"Arm64" )) return PLATFORM_ARM64
;
1092 return PLATFORM_UNRECOGNIZED
;
1095 static UINT
parse_suminfo( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1097 WCHAR
*template, *p
, *q
, *platform
;
1100 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1101 TRACE("version: %d\n", package
->version
);
1103 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1105 return ERROR_SUCCESS
; /* native accepts missing template property */
1107 TRACE("template: %s\n", debugstr_w(template));
1109 p
= wcschr( template, ';' );
1112 WARN("invalid template string %s\n", debugstr_w(template));
1113 msi_free( template );
1114 return ERROR_PATCH_PACKAGE_INVALID
;
1117 platform
= template;
1118 if ((q
= wcschr( platform
, ',' ))) *q
= 0;
1119 package
->platform
= parse_platform( platform
);
1120 while (package
->platform
== PLATFORM_UNRECOGNIZED
&& q
)
1123 if ((q
= wcschr( platform
, ',' ))) *q
= 0;
1124 package
->platform
= parse_platform( platform
);
1126 if (package
->platform
== PLATFORM_UNRECOGNIZED
)
1128 WARN("unknown platform %s\n", debugstr_w(template));
1129 msi_free( template );
1130 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1135 msi_free( template );
1136 return ERROR_SUCCESS
;
1139 for (q
= p
; (q
= wcschr( q
, ',' )); q
++) count
++;
1141 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1142 if (!package
->langids
)
1144 msi_free( template );
1145 return ERROR_OUTOFMEMORY
;
1151 q
= wcschr( p
, ',' );
1153 package
->langids
[i
] = wcstol( p
, NULL
, 10 );
1158 package
->num_langids
= i
+ 1;
1160 msi_free( template );
1161 return ERROR_SUCCESS
;
1164 static UINT
validate_package( MSIPACKAGE
*package
)
1168 if (package
->platform
== PLATFORM_INTEL64
)
1169 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1171 if (package
->platform
== PLATFORM_ARM
)
1172 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1175 if (package
->platform
== PLATFORM_ARM64
)
1176 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1178 if (package
->platform
== PLATFORM_X64
)
1180 if (!is_64bit
&& !is_wow64
)
1181 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1182 if (package
->version
< 200)
1183 return ERROR_INSTALL_PACKAGE_INVALID
;
1185 if (!package
->num_langids
)
1187 return ERROR_SUCCESS
;
1189 for (i
= 0; i
< package
->num_langids
; i
++)
1191 LANGID langid
= package
->langids
[i
];
1193 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1195 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1197 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1199 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1201 if (IsValidLocale( langid
, LCID_INSTALLED
))
1202 return ERROR_SUCCESS
;
1204 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1207 static WCHAR
*get_property( MSIDATABASE
*db
, const WCHAR
*prop
)
1209 WCHAR query
[MAX_PATH
];
1214 swprintf(query
, ARRAY_SIZE(query
), L
"SELECT `Value` FROM `Property` WHERE `Property`='%s'", prop
);
1215 if (MSI_DatabaseOpenViewW( db
, query
, &view
) != ERROR_SUCCESS
)
1219 if (MSI_ViewExecute( view
, 0 ) != ERROR_SUCCESS
)
1221 MSI_ViewClose( view
);
1222 msiobj_release( &view
->hdr
);
1225 if (MSI_ViewFetch( view
, &rec
) == ERROR_SUCCESS
)
1227 ret
= strdupW( MSI_RecordGetString( rec
, 1 ) );
1228 msiobj_release( &rec
->hdr
);
1230 MSI_ViewClose( view
);
1231 msiobj_release( &view
->hdr
);
1235 static WCHAR
*get_product_code( MSIDATABASE
*db
)
1237 return get_property( db
, L
"ProductCode" );
1240 static WCHAR
*get_product_version( MSIDATABASE
*db
)
1242 return get_property( db
, L
"ProductVersion" );
1245 static UINT
get_registered_local_package( const WCHAR
*product
, WCHAR
*localfile
)
1247 MSIINSTALLCONTEXT context
;
1252 r
= msi_locate_product( product
, &context
);
1253 if (r
!= ERROR_SUCCESS
)
1256 r
= MSIREG_OpenInstallProps( product
, context
, NULL
, &props_key
, FALSE
);
1257 if (r
!= ERROR_SUCCESS
)
1260 filename
= msi_reg_get_val_str( props_key
, INSTALLPROPERTY_LOCALPACKAGEW
);
1261 RegCloseKey( props_key
);
1263 return ERROR_FUNCTION_FAILED
;
1265 lstrcpyW( localfile
, filename
);
1266 msi_free( filename
);
1267 return ERROR_SUCCESS
;
1270 WCHAR
*msi_get_package_code( MSIDATABASE
*db
)
1276 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1277 if (r
!= ERROR_SUCCESS
)
1279 r
= msi_get_db_suminfo( db
, 0, &si
);
1280 if (r
!= ERROR_SUCCESS
)
1282 WARN("failed to load summary info %u\n", r
);
1286 ret
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
1287 msiobj_release( &si
->hdr
);
1291 static UINT
get_local_package( MSIDATABASE
*db
, WCHAR
*localfile
)
1293 WCHAR
*product_code
;
1296 if (!(product_code
= get_product_code( db
)))
1297 return ERROR_INSTALL_PACKAGE_INVALID
;
1298 r
= get_registered_local_package( product_code
, localfile
);
1299 msi_free( product_code
);
1303 UINT
msi_set_original_database_property( MSIDATABASE
*db
, const WCHAR
*package
)
1307 if (UrlIsW( package
, URLIS_URL
))
1308 r
= msi_set_property( db
, L
"OriginalDatabase", package
, -1 );
1309 else if (package
[0] == '#')
1310 r
= msi_set_property( db
, L
"OriginalDatabase", db
->path
, -1 );
1316 if (!(len
= GetFullPathNameW( package
, 0, NULL
, NULL
))) return GetLastError();
1317 if (!(path
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1318 len
= GetFullPathNameW( package
, len
, path
, NULL
);
1319 r
= msi_set_property( db
, L
"OriginalDatabase", path
, len
);
1325 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, DWORD dwOptions
, MSIPACKAGE
**pPackage
)
1328 MSIPACKAGE
*package
;
1330 MSIRECORD
*data_row
, *info_row
;
1332 WCHAR localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1333 LPCWSTR file
= szPackage
;
1336 BOOL delete_on_close
= FALSE
;
1337 WCHAR
*info_template
, *productname
, *product_code
;
1338 MSIINSTALLCONTEXT context
;
1340 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1342 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_INITIALIZE
, 0);
1345 if( szPackage
[0] == '#' )
1347 handle
= wcstol(&szPackage
[1], NULL
, 10);
1348 if (!(db
= msihandle2msiinfo(handle
, MSIHANDLETYPE_DATABASE
)))
1349 return ERROR_INVALID_HANDLE
;
1353 WCHAR
*product_version
= NULL
;
1355 if ( UrlIsW( szPackage
, URLIS_URL
) )
1357 r
= msi_download_file( szPackage
, cachefile
);
1358 if (r
!= ERROR_SUCCESS
)
1363 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
1364 if (r
!= ERROR_SUCCESS
)
1366 if (GetFileAttributesW( file
) == INVALID_FILE_ATTRIBUTES
)
1367 return ERROR_FILE_NOT_FOUND
;
1370 r
= get_local_package( db
, localfile
);
1371 if (r
!= ERROR_SUCCESS
|| GetFileAttributesW( localfile
) == INVALID_FILE_ATTRIBUTES
)
1373 DWORD localfile_attr
;
1375 r
= msi_create_empty_local_file( localfile
, L
".msi" );
1376 if (r
!= ERROR_SUCCESS
)
1378 msiobj_release( &db
->hdr
);
1382 if (!CopyFileW( file
, localfile
, FALSE
))
1385 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file
), debugstr_w(localfile
), r
);
1386 DeleteFileW( localfile
);
1387 msiobj_release( &db
->hdr
);
1390 delete_on_close
= TRUE
;
1392 /* Remove read-only bit, we are opening it with write access in MSI_OpenDatabaseW below. */
1393 localfile_attr
= GetFileAttributesW( localfile
);
1394 if (localfile_attr
& FILE_ATTRIBUTE_READONLY
)
1395 SetFileAttributesW( localfile
, localfile_attr
& ~FILE_ATTRIBUTE_READONLY
);
1397 else if (dwOptions
& WINE_OPENPACKAGEFLAGS_RECACHE
)
1399 if (!CopyFileW( file
, localfile
, FALSE
))
1402 WARN("unable to update cached package (%u)\n", r
);
1403 msiobj_release( &db
->hdr
);
1408 product_version
= get_product_version( db
);
1409 msiobj_release( &db
->hdr
);
1410 TRACE("opening package %s\n", debugstr_w( localfile
));
1411 r
= MSI_OpenDatabaseW( localfile
, MSIDBOPEN_TRANSACT
, &db
);
1412 if (r
!= ERROR_SUCCESS
)
1415 if (product_version
)
1417 WCHAR
*cache_version
= get_product_version( db
);
1418 if (!product_version
!= !cache_version
||
1419 (product_version
&& wcscmp(product_version
, cache_version
)))
1421 msiobj_release( &db
->hdr
);
1422 msi_free(product_version
);
1423 msi_free(cache_version
);
1424 return ERROR_PRODUCT_VERSION
;
1426 msi_free(product_version
);
1427 msi_free(cache_version
);
1430 package
= MSI_CreatePackage( db
);
1431 msiobj_release( &db
->hdr
);
1432 if (!package
) return ERROR_INSTALL_PACKAGE_INVALID
;
1433 package
->localfile
= strdupW( localfile
);
1434 package
->delete_on_close
= delete_on_close
;
1436 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1437 if (r
!= ERROR_SUCCESS
)
1439 r
= msi_get_db_suminfo( db
, 0, &si
);
1440 if (r
!= ERROR_SUCCESS
)
1442 WARN("failed to load summary info\n");
1443 msiobj_release( &package
->hdr
);
1444 return ERROR_INSTALL_PACKAGE_INVALID
;
1447 r
= parse_suminfo( si
, package
);
1448 msiobj_release( &si
->hdr
);
1449 if (r
!= ERROR_SUCCESS
)
1451 WARN("failed to parse summary info %u\n", r
);
1452 msiobj_release( &package
->hdr
);
1455 r
= validate_package( package
);
1456 if (r
!= ERROR_SUCCESS
)
1458 msiobj_release( &package
->hdr
);
1461 msi_set_property( package
->db
, L
"DATABASE", db
->path
, -1 );
1462 set_installed_prop( package
);
1463 msi_set_context( package
);
1465 product_code
= get_product_code( db
);
1466 if (msi_locate_product( product_code
, &context
) == ERROR_SUCCESS
)
1468 TRACE("product already registered\n");
1469 msi_set_property( package
->db
, L
"ProductToBeRegistered", L
"1", -1 );
1471 msi_free(product_code
);
1475 WCHAR patch_code
[GUID_SIZE
];
1476 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1477 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1478 if (r
!= ERROR_SUCCESS
)
1481 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1483 r
= msi_apply_registered_patch( package
, patch_code
);
1484 if (r
!= ERROR_SUCCESS
)
1486 ERR("registered patch failed to apply %u\n", r
);
1487 msiobj_release( &package
->hdr
);
1492 if (index
) msi_adjust_privilege_properties( package
);
1494 r
= msi_set_original_database_property( package
->db
, szPackage
);
1495 if (r
!= ERROR_SUCCESS
)
1497 msiobj_release( &package
->hdr
);
1501 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1502 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1504 if (!msi_init_assembly_caches( package
))
1506 ERR("can't initialize assembly caches\n");
1507 msiobj_release( &package
->hdr
);
1508 return ERROR_FUNCTION_FAILED
;
1511 /* FIXME: when should these messages be sent? */
1512 data_row
= MSI_CreateRecord(3);
1514 return ERROR_OUTOFMEMORY
;
1515 MSI_RecordSetStringW(data_row
, 0, NULL
);
1516 MSI_RecordSetInteger(data_row
, 1, 0);
1517 MSI_RecordSetInteger(data_row
, 2, package
->num_langids
? package
->langids
[0] : 0);
1518 MSI_RecordSetInteger(data_row
, 3, msi_get_string_table_codepage(package
->db
->strings
));
1519 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1521 info_row
= MSI_CreateRecord(0);
1524 msiobj_release(&data_row
->hdr
);
1525 return ERROR_OUTOFMEMORY
;
1527 info_template
= msi_get_error_message(package
->db
, MSIERR_INFO_LOGGINGSTART
);
1528 MSI_RecordSetStringW(info_row
, 0, info_template
);
1529 msi_free(info_template
);
1530 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, info_row
);
1532 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1534 productname
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
1535 MSI_RecordSetInteger(data_row
, 1, 1);
1536 MSI_RecordSetStringW(data_row
, 2, productname
);
1537 MSI_RecordSetStringW(data_row
, 3, NULL
);
1538 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1540 msi_free(productname
);
1541 msiobj_release(&info_row
->hdr
);
1542 msiobj_release(&data_row
->hdr
);
1544 *pPackage
= package
;
1545 return ERROR_SUCCESS
;
1548 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1550 MSIPACKAGE
*package
= NULL
;
1553 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1555 if( !szPackage
|| !phPackage
)
1556 return ERROR_INVALID_PARAMETER
;
1560 FIXME("Should create an empty database and package\n");
1561 return ERROR_FUNCTION_FAILED
;
1565 FIXME("dwOptions %08x not supported\n", dwOptions
);
1567 ret
= MSI_OpenPackageW( szPackage
, 0, &package
);
1568 if( ret
== ERROR_SUCCESS
)
1570 *phPackage
= alloc_msihandle( &package
->hdr
);
1572 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1573 msiobj_release( &package
->hdr
);
1576 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_TERMINATE
, 0);
1581 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1583 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1586 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1588 LPWSTR szwPack
= NULL
;
1593 szwPack
= strdupAtoW( szPackage
);
1595 return ERROR_OUTOFMEMORY
;
1598 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1600 msi_free( szwPack
);
1605 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1607 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1610 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1612 MSIPACKAGE
*package
;
1613 MSIHANDLE handle
= 0;
1616 TRACE("(%d)\n",hInstall
);
1618 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1621 handle
= alloc_msihandle( &package
->db
->hdr
);
1622 msiobj_release( &package
->hdr
);
1624 else if ((remote
= msi_get_remote(hInstall
)))
1628 handle
= remote_GetActiveDatabase(remote
);
1629 handle
= alloc_msi_remote_handle(handle
);
1631 __EXCEPT(rpc_filter
)
1641 static INT
internal_ui_handler(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
, LPCWSTR message
)
1643 if (!package
|| (package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
1646 /* todo: check if message needs additional styles (topmost/foreground/modality?) */
1648 switch (eMessageType
& 0xff000000)
1650 case INSTALLMESSAGE_FATALEXIT
:
1651 case INSTALLMESSAGE_ERROR
:
1652 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1653 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1654 if (!(eMessageType
& MB_ICONMASK
))
1655 eMessageType
|= MB_ICONEXCLAMATION
;
1656 return MessageBoxW(gUIhwnd
, message
, L
"Windows Installer", eMessageType
& 0x00ffffff);
1657 case INSTALLMESSAGE_WARNING
:
1658 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1659 if (!(eMessageType
& MB_ICONMASK
))
1660 eMessageType
|= MB_ICONASTERISK
;
1661 return MessageBoxW(gUIhwnd
, message
, L
"Windows Installer", eMessageType
& 0x00ffffff);
1662 case INSTALLMESSAGE_USER
:
1663 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1664 if (!(eMessageType
& MB_ICONMASK
))
1665 eMessageType
|= MB_USERICON
;
1666 return MessageBoxW(gUIhwnd
, message
, L
"Windows Installer", eMessageType
& 0x00ffffff);
1667 case INSTALLMESSAGE_INFO
:
1668 case INSTALLMESSAGE_INITIALIZE
:
1669 case INSTALLMESSAGE_TERMINATE
:
1670 case INSTALLMESSAGE_INSTALLSTART
:
1671 case INSTALLMESSAGE_INSTALLEND
:
1673 case INSTALLMESSAGE_SHOWDIALOG
:
1675 LPWSTR dialog
= msi_dup_record_field(record
, 0);
1676 INT rc
= ACTION_DialogBox(package
, dialog
);
1680 case INSTALLMESSAGE_ACTIONSTART
:
1683 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1684 if (!uirow
) return -1;
1685 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformatted
);
1686 MSI_RecordSetStringW(uirow
, 1, deformatted
);
1687 msi_event_fire(package
, L
"ActionText", uirow
);
1689 msi_free(deformatted
);
1690 msiobj_release(&uirow
->hdr
);
1693 case INSTALLMESSAGE_ACTIONDATA
:
1695 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1696 if (!uirow
) return -1;
1697 MSI_RecordSetStringW(uirow
, 1, message
);
1698 msi_event_fire(package
, L
"ActionData", uirow
);
1699 msiobj_release(&uirow
->hdr
);
1701 if (package
->action_progress_increment
)
1703 uirow
= MSI_CreateRecord(2);
1704 if (!uirow
) return -1;
1705 MSI_RecordSetInteger(uirow
, 1, 2);
1706 MSI_RecordSetInteger(uirow
, 2, package
->action_progress_increment
);
1707 msi_event_fire(package
, L
"SetProgress", uirow
);
1708 msiobj_release(&uirow
->hdr
);
1712 case INSTALLMESSAGE_PROGRESS
:
1713 msi_event_fire(package
, L
"SetProgress", record
);
1715 case INSTALLMESSAGE_COMMONDATA
:
1716 switch (MSI_RecordGetInteger(record
, 1))
1727 FIXME("internal UI not implemented for message 0x%08x (UI level = %x)\n", eMessageType
, package
->ui_level
);
1739 {2726, L
"DEBUG: Error [1]: Action not found: [2]"},
1743 static LPCWSTR
get_internal_error_message(int error
)
1747 while (internal_errors
[i
].id
!= 0)
1749 if (internal_errors
[i
].id
== error
)
1750 return internal_errors
[i
].text
;
1754 FIXME("missing error message %d\n", error
);
1758 /* Returned string must be freed */
1759 LPWSTR
msi_get_error_message(MSIDATABASE
*db
, int error
)
1764 if ((record
= MSI_QueryGetRecord(db
, L
"SELECT `Message` FROM `Error` WHERE `Error` = %d", error
)))
1766 ret
= msi_dup_record_field(record
, 1);
1767 msiobj_release(&record
->hdr
);
1769 else if (error
< 2000)
1771 int len
= LoadStringW(msi_hInstance
, IDS_ERROR_BASE
+ error
, (LPWSTR
) &ret
, 0);
1774 ret
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
1775 LoadStringW(msi_hInstance
, IDS_ERROR_BASE
+ error
, ret
, len
+ 1);
1784 INT
MSI_ProcessMessageVerbatim(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1786 LPWSTR message
= {0};
1788 DWORD log_type
= 1 << (eMessageType
>> 24);
1793 TRACE("%x\n", eMessageType
);
1794 if (TRACE_ON(msi
)) dump_record(record
);
1796 if (!package
|| !record
)
1799 res
= MSI_FormatRecordW(package
, record
, message
, &len
);
1800 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
1803 message
= msi_alloc(len
* sizeof(WCHAR
));
1804 if (!message
) return ERROR_OUTOFMEMORY
;
1805 MSI_FormatRecordW(package
, record
, message
, &len
);
1808 /* convert it to ANSI */
1809 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1810 msg
= msi_alloc( len
);
1811 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1813 if (gUIHandlerRecord
&& (gUIFilterRecord
& log_type
))
1815 MSIHANDLE rec
= alloc_msihandle(&record
->hdr
);
1816 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, hRecord=%u)\n",
1817 gUIHandlerRecord
, gUIContextRecord
, eMessageType
, rec
);
1818 rc
= gUIHandlerRecord( gUIContextRecord
, eMessageType
, rec
);
1819 MsiCloseHandle( rec
);
1821 if (!rc
&& gUIHandlerW
&& (gUIFilter
& log_type
))
1823 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1824 gUIHandlerW
, gUIContext
, eMessageType
, debugstr_w(message
));
1825 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1827 else if (!rc
&& gUIHandlerA
&& (gUIFilter
& log_type
))
1829 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1830 gUIHandlerA
, gUIContext
, eMessageType
, debugstr_a(msg
));
1831 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1835 rc
= internal_ui_handler(package
, eMessageType
, record
, message
);
1837 if (!rc
&& package
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1838 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1841 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1842 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1845 msi_free( message
);
1850 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1852 switch (eMessageType
& 0xff000000)
1854 case INSTALLMESSAGE_FATALEXIT
:
1855 case INSTALLMESSAGE_ERROR
:
1856 case INSTALLMESSAGE_WARNING
:
1857 case INSTALLMESSAGE_USER
:
1858 case INSTALLMESSAGE_INFO
:
1859 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1860 if (MSI_RecordGetInteger(record
, 1) != MSI_NULL_INTEGER
)
1865 LPWSTR template_rec
= NULL
, template_prefix
= NULL
;
1866 int error
= MSI_RecordGetInteger(record
, 1);
1868 if (MSI_RecordIsNull(record
, 0))
1872 template_rec
= msi_get_error_message(package
->db
, error
);
1874 if (!template_rec
&& error
>= 2000)
1876 /* internal error, not localized */
1877 if ((template_rec
= (LPWSTR
) get_internal_error_message(error
)))
1879 MSI_RecordSetStringW(record
, 0, template_rec
);
1880 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_INFO
, record
);
1882 template_rec
= msi_get_error_message(package
->db
, MSIERR_INSTALLERROR
);
1883 MSI_RecordSetStringW(record
, 0, template_rec
);
1884 MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
1885 msi_free(template_rec
);
1891 template_rec
= msi_dup_record_field(record
, 0);
1893 template_prefix
= msi_get_error_message(package
->db
, eMessageType
>> 24);
1894 if (!template_prefix
) template_prefix
= strdupW(L
"");
1898 /* always returns 0 */
1899 MSI_RecordSetStringW(record
, 0, template_prefix
);
1900 MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
1901 msi_free(template_prefix
);
1905 template = msi_alloc((lstrlenW(template_rec
) + lstrlenW(template_prefix
) + 1) * sizeof(WCHAR
));
1906 if (!template) return ERROR_OUTOFMEMORY
;
1908 lstrcpyW(template, template_prefix
);
1909 lstrcatW(template, template_rec
);
1910 MSI_RecordSetStringW(record
, 0, template);
1912 msi_free(template_prefix
);
1913 msi_free(template_rec
);
1917 case INSTALLMESSAGE_ACTIONSTART
:
1919 WCHAR
*template = msi_get_error_message(package
->db
, MSIERR_ACTIONSTART
);
1920 MSI_RecordSetStringW(record
, 0, template);
1923 msi_free(package
->LastAction
);
1924 msi_free(package
->LastActionTemplate
);
1925 package
->LastAction
= msi_dup_record_field(record
, 1);
1926 if (!package
->LastAction
) package
->LastAction
= strdupW(L
"");
1927 package
->LastActionTemplate
= msi_dup_record_field(record
, 3);
1930 case INSTALLMESSAGE_ACTIONDATA
:
1931 if (package
->LastAction
&& package
->LastActionTemplate
)
1933 size_t len
= lstrlenW(package
->LastAction
) + lstrlenW(package
->LastActionTemplate
) + 7;
1934 WCHAR
*template = msi_alloc(len
* sizeof(WCHAR
));
1935 if (!template) return ERROR_OUTOFMEMORY
;
1936 swprintf(template, len
, L
"{{%s: }}%s", package
->LastAction
, package
->LastActionTemplate
);
1937 MSI_RecordSetStringW(record
, 0, template);
1941 case INSTALLMESSAGE_COMMONDATA
:
1943 WCHAR
*template = msi_get_error_message(package
->db
, MSIERR_COMMONDATA
);
1944 MSI_RecordSetStringW(record
, 0, template);
1950 return MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
1953 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1956 UINT ret
= ERROR_INVALID_HANDLE
;
1957 MSIPACKAGE
*package
= NULL
;
1958 MSIRECORD
*record
= NULL
;
1960 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
||
1961 (eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
1964 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
&&
1965 MsiRecordGetInteger(hRecord
, 1) != 2)
1968 record
= msihandle2msiinfo(hRecord
, MSIHANDLETYPE_RECORD
);
1970 return ERROR_INVALID_HANDLE
;
1972 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1977 if (!(remote
= msi_get_remote(hInstall
)))
1978 return ERROR_INVALID_HANDLE
;
1982 ret
= remote_ProcessMessage(remote
, eMessageType
, (struct wire_record
*)&record
->count
);
1984 __EXCEPT(rpc_filter
)
1986 ret
= GetExceptionCode();
1990 msiobj_release(&record
->hdr
);
1994 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1996 msiobj_release( &record
->hdr
);
1997 msiobj_release( &package
->hdr
);
2003 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
2005 LPWSTR szwName
= NULL
, szwValue
= NULL
;
2006 UINT r
= ERROR_OUTOFMEMORY
;
2008 szwName
= strdupAtoW( szName
);
2009 if( szName
&& !szwName
)
2012 szwValue
= strdupAtoW( szValue
);
2013 if( szValue
&& !szwValue
)
2016 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
2019 msi_free( szwName
);
2020 msi_free( szwValue
);
2025 void msi_reset_source_folders( MSIPACKAGE
*package
)
2029 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
2031 msi_free( folder
->ResolvedSource
);
2032 folder
->ResolvedSource
= NULL
;
2036 UINT
msi_set_property( MSIDATABASE
*db
, const WCHAR
*name
, const WCHAR
*value
, int len
)
2039 MSIRECORD
*row
= NULL
;
2044 TRACE("%p %s %s %d\n", db
, debugstr_w(name
), debugstr_wn(value
, len
), len
);
2047 return ERROR_INVALID_PARAMETER
;
2049 /* this one is weird... */
2051 return value
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
2053 if (value
&& len
< 0) len
= lstrlenW( value
);
2055 rc
= msi_get_property( db
, name
, 0, &sz
);
2056 if (!value
|| (!*value
&& !len
))
2058 swprintf( query
, ARRAY_SIZE(query
), L
"DELETE FROM `_Property` WHERE `_Property` = '%s'", name
);
2060 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
2062 swprintf( query
, ARRAY_SIZE(query
), L
"UPDATE `_Property` SET `Value` = ? WHERE `_Property` = '%s'", name
);
2063 row
= MSI_CreateRecord(1);
2064 msi_record_set_string( row
, 1, value
, len
);
2068 lstrcpyW( query
, L
"INSERT INTO `_Property` (`_Property`,`Value`) VALUES (?,?)" );
2069 row
= MSI_CreateRecord(2);
2070 msi_record_set_string( row
, 1, name
, -1 );
2071 msi_record_set_string( row
, 2, value
, len
);
2074 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2075 if (rc
== ERROR_SUCCESS
)
2077 rc
= MSI_ViewExecute(view
, row
);
2078 MSI_ViewClose(view
);
2079 msiobj_release(&view
->hdr
);
2081 if (row
) msiobj_release(&row
->hdr
);
2085 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2087 MSIPACKAGE
*package
;
2090 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2095 if (!(remote
= msi_get_remote(hInstall
)))
2096 return ERROR_INVALID_HANDLE
;
2100 ret
= remote_SetProperty(remote
, szName
, szValue
);
2102 __EXCEPT(rpc_filter
)
2104 ret
= GetExceptionCode();
2111 ret
= msi_set_property( package
->db
, szName
, szValue
, -1 );
2112 if (ret
== ERROR_SUCCESS
&& !wcscmp( szName
, L
"SourceDir" ))
2113 msi_reset_source_folders( package
);
2115 msiobj_release( &package
->hdr
);
2119 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2121 MSIRECORD
*rec
, *row
= NULL
;
2127 if (!name
|| !*name
)
2130 if (!wcscmp(name
, L
"Date"))
2132 length
= GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, NULL
, 0);
2135 buffer
= msi_alloc(length
* sizeof(WCHAR
));
2136 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, buffer
, length
);
2138 row
= MSI_CreateRecord(1);
2144 MSI_RecordSetStringW(row
, 1, buffer
);
2148 else if (!wcscmp(name
, L
"Time"))
2150 length
= GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOTIMEMARKER
, NULL
, NULL
, NULL
, 0);
2153 buffer
= msi_alloc(length
* sizeof(WCHAR
));
2154 GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOTIMEMARKER
, NULL
, NULL
, buffer
, length
);
2156 row
= MSI_CreateRecord(1);
2162 MSI_RecordSetStringW(row
, 1, buffer
);
2167 rec
= MSI_CreateRecord(1);
2171 MSI_RecordSetStringW(rec
, 1, name
);
2173 r
= MSI_DatabaseOpenViewW(db
, L
"SELECT `Value` FROM `_Property` WHERE `_Property`=?", &view
);
2174 if (r
== ERROR_SUCCESS
)
2176 MSI_ViewExecute(view
, rec
);
2177 MSI_ViewFetch(view
, &row
);
2178 MSI_ViewClose(view
);
2179 msiobj_release(&view
->hdr
);
2181 msiobj_release(&rec
->hdr
);
2185 /* internal function, not compatible with MsiGetPropertyW */
2186 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2187 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2190 UINT rc
= ERROR_FUNCTION_FAILED
;
2192 TRACE("%p %s %p %p\n", db
, debugstr_w(szName
), szValueBuf
, pchValueBuf
);
2194 row
= msi_get_property_row( db
, szName
);
2196 if (*pchValueBuf
> 0)
2201 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2202 msiobj_release(&row
->hdr
);
2205 if (rc
== ERROR_SUCCESS
)
2206 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf
, *pchValueBuf
),
2207 debugstr_w(szName
));
2208 else if (rc
== ERROR_MORE_DATA
)
2209 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2210 debugstr_w(szName
));
2214 TRACE("property %s not found\n", debugstr_w(szName
));
2220 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2226 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2227 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2231 str
= msi_alloc(sz
* sizeof(WCHAR
));
2232 r
= msi_get_property(db
, prop
, str
, &sz
);
2233 if (r
!= ERROR_SUCCESS
)
2242 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2244 LPWSTR str
= msi_dup_property( db
, prop
);
2245 int val
= str
? wcstol(str
, NULL
, 10) : def
;
2250 UINT WINAPI
MsiGetPropertyA(MSIHANDLE hinst
, const char *name
, char *buf
, DWORD
*sz
)
2252 const WCHAR
*value
= L
"";
2253 MSIPACKAGE
*package
;
2260 return ERROR_INVALID_PARAMETER
;
2262 if (!(nameW
= strdupAtoW(name
)))
2263 return ERROR_OUTOFMEMORY
;
2265 package
= msihandle2msiinfo(hinst
, MSIHANDLETYPE_PACKAGE
);
2268 WCHAR
*value
= NULL
, *tmp
;
2272 if (!(remote
= msi_get_remote(hinst
)))
2275 return ERROR_INVALID_HANDLE
;
2280 r
= remote_GetProperty(remote
, nameW
, &value
, &len
);
2282 __EXCEPT(rpc_filter
)
2284 r
= GetExceptionCode();
2292 /* String might contain embedded nulls.
2293 * Native returns the correct size but truncates the string. */
2294 tmp
= calloc(1, (len
+ 1) * sizeof(WCHAR
));
2297 midl_user_free(value
);
2298 return ERROR_OUTOFMEMORY
;
2300 lstrcpyW(tmp
, value
);
2302 r
= msi_strncpyWtoA(tmp
, len
, buf
, sz
, TRUE
);
2306 midl_user_free(value
);
2310 row
= msi_get_property_row(package
->db
, nameW
);
2312 value
= msi_record_get_string(row
, 1, &len
);
2314 r
= msi_strncpyWtoA(value
, len
, buf
, sz
, FALSE
);
2317 if (row
) msiobj_release(&row
->hdr
);
2318 msiobj_release(&package
->hdr
);
2322 UINT WINAPI
MsiGetPropertyW(MSIHANDLE hinst
, const WCHAR
*name
, WCHAR
*buf
, DWORD
*sz
)
2324 const WCHAR
*value
= L
"";
2325 MSIPACKAGE
*package
;
2331 return ERROR_INVALID_PARAMETER
;
2333 package
= msihandle2msiinfo(hinst
, MSIHANDLETYPE_PACKAGE
);
2336 WCHAR
*value
= NULL
, *tmp
;
2340 if (!(remote
= msi_get_remote(hinst
)))
2341 return ERROR_INVALID_HANDLE
;
2345 r
= remote_GetProperty(remote
, name
, &value
, &len
);
2347 __EXCEPT(rpc_filter
)
2349 r
= GetExceptionCode();
2355 /* String might contain embedded nulls.
2356 * Native returns the correct size but truncates the string. */
2357 tmp
= calloc(1, (len
+ 1) * sizeof(WCHAR
));
2360 midl_user_free(value
);
2361 return ERROR_OUTOFMEMORY
;
2363 lstrcpyW(tmp
, value
);
2365 r
= msi_strncpyW(tmp
, len
, buf
, sz
);
2369 midl_user_free(value
);
2373 row
= msi_get_property_row(package
->db
, name
);
2375 value
= msi_record_get_string(row
, 1, &len
);
2377 r
= msi_strncpyW(value
, len
, buf
, sz
);
2379 if (row
) msiobj_release(&row
->hdr
);
2380 msiobj_release(&package
->hdr
);
2384 MSIHANDLE __cdecl
s_remote_GetActiveDatabase(MSIHANDLE hinst
)
2386 return MsiGetActiveDatabase(hinst
);
2389 UINT __cdecl
s_remote_GetProperty(MSIHANDLE hinst
, LPCWSTR property
, LPWSTR
*value
, DWORD
*size
)
2395 r
= MsiGetPropertyW(hinst
, property
, empty
, size
);
2396 if (r
== ERROR_MORE_DATA
)
2399 *value
= midl_user_allocate(*size
* sizeof(WCHAR
));
2401 return ERROR_OUTOFMEMORY
;
2402 r
= MsiGetPropertyW(hinst
, property
, *value
, size
);
2407 UINT __cdecl
s_remote_SetProperty(MSIHANDLE hinst
, LPCWSTR property
, LPCWSTR value
)
2409 return MsiSetPropertyW(hinst
, property
, value
);
2412 int __cdecl
s_remote_ProcessMessage(MSIHANDLE hinst
, INSTALLMESSAGE message
, struct wire_record
*remote_rec
)
2418 if ((r
= unmarshal_record(remote_rec
, &rec
)))
2421 ret
= MsiProcessMessage(hinst
, message
, rec
);
2423 MsiCloseHandle(rec
);
2427 UINT __cdecl
s_remote_DoAction(MSIHANDLE hinst
, LPCWSTR action
)
2429 return MsiDoActionW(hinst
, action
);
2432 UINT __cdecl
s_remote_Sequence(MSIHANDLE hinst
, LPCWSTR table
, int sequence
)
2434 return MsiSequenceW(hinst
, table
, sequence
);
2437 UINT __cdecl
s_remote_GetTargetPath(MSIHANDLE hinst
, LPCWSTR folder
, LPWSTR
*value
)
2443 r
= MsiGetTargetPathW(hinst
, folder
, empty
, &size
);
2444 if (r
== ERROR_MORE_DATA
)
2446 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2448 return ERROR_OUTOFMEMORY
;
2449 r
= MsiGetTargetPathW(hinst
, folder
, *value
, &size
);
2454 UINT __cdecl
s_remote_SetTargetPath(MSIHANDLE hinst
, LPCWSTR folder
, LPCWSTR value
)
2456 return MsiSetTargetPathW(hinst
, folder
, value
);
2459 UINT __cdecl
s_remote_GetSourcePath(MSIHANDLE hinst
, LPCWSTR folder
, LPWSTR
*value
)
2465 r
= MsiGetSourcePathW(hinst
, folder
, empty
, &size
);
2466 if (r
== ERROR_MORE_DATA
)
2468 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2470 return ERROR_OUTOFMEMORY
;
2471 r
= MsiGetSourcePathW(hinst
, folder
, *value
, &size
);
2476 BOOL __cdecl
s_remote_GetMode(MSIHANDLE hinst
, MSIRUNMODE mode
)
2478 return MsiGetMode(hinst
, mode
);
2481 UINT __cdecl
s_remote_SetMode(MSIHANDLE hinst
, MSIRUNMODE mode
, BOOL state
)
2483 return MsiSetMode(hinst
, mode
, state
);
2486 UINT __cdecl
s_remote_GetFeatureState(MSIHANDLE hinst
, LPCWSTR feature
,
2487 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2489 return MsiGetFeatureStateW(hinst
, feature
, installed
, action
);
2492 UINT __cdecl
s_remote_SetFeatureState(MSIHANDLE hinst
, LPCWSTR feature
, INSTALLSTATE state
)
2494 return MsiSetFeatureStateW(hinst
, feature
, state
);
2497 UINT __cdecl
s_remote_GetComponentState(MSIHANDLE hinst
, LPCWSTR component
,
2498 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2500 return MsiGetComponentStateW(hinst
, component
, installed
, action
);
2503 UINT __cdecl
s_remote_SetComponentState(MSIHANDLE hinst
, LPCWSTR component
, INSTALLSTATE state
)
2505 return MsiSetComponentStateW(hinst
, component
, state
);
2508 LANGID __cdecl
s_remote_GetLanguage(MSIHANDLE hinst
)
2510 return MsiGetLanguage(hinst
);
2513 UINT __cdecl
s_remote_SetInstallLevel(MSIHANDLE hinst
, int level
)
2515 return MsiSetInstallLevel(hinst
, level
);
2518 UINT __cdecl
s_remote_FormatRecord(MSIHANDLE hinst
, struct wire_record
*remote_rec
, LPWSTR
*value
)
2525 if ((r
= unmarshal_record(remote_rec
, &rec
)))
2528 r
= MsiFormatRecordW(hinst
, rec
, empty
, &size
);
2529 if (r
== ERROR_MORE_DATA
)
2531 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2534 MsiCloseHandle(rec
);
2535 return ERROR_OUTOFMEMORY
;
2537 r
= MsiFormatRecordW(hinst
, rec
, *value
, &size
);
2540 MsiCloseHandle(rec
);
2544 MSICONDITION __cdecl
s_remote_EvaluateCondition(MSIHANDLE hinst
, LPCWSTR condition
)
2546 return MsiEvaluateConditionW(hinst
, condition
);
2549 UINT __cdecl
s_remote_GetFeatureCost(MSIHANDLE hinst
, LPCWSTR feature
,
2550 MSICOSTTREE cost_tree
, INSTALLSTATE state
, INT
*cost
)
2552 return MsiGetFeatureCostW(hinst
, feature
, cost_tree
, state
, cost
);
2555 UINT __cdecl
s_remote_EnumComponentCosts(MSIHANDLE hinst
, LPCWSTR component
,
2556 DWORD index
, INSTALLSTATE state
, LPWSTR drive
, INT
*cost
, INT
*temp
)
2559 return MsiEnumComponentCostsW(hinst
, component
, index
, state
, drive
, &size
, cost
, temp
);
2562 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2563 LPCWSTR property
, LPWSTR value
)
2565 MSISOURCELISTINFO
*info
;
2567 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2569 if (!wcscmp( info
->value
, value
)) return ERROR_SUCCESS
;
2572 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2574 return ERROR_OUTOFMEMORY
;
2576 info
->context
= context
;
2577 info
->options
= options
;
2578 info
->property
= property
;
2579 info
->value
= strdupW(value
);
2580 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2582 return ERROR_SUCCESS
;
2585 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2586 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2590 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2592 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2595 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2597 return ERROR_OUTOFMEMORY
;
2599 disk
->context
= context
;
2600 disk
->options
= options
;
2601 disk
->disk_id
= disk_id
;
2602 disk
->volume_label
= strdupW(volume_label
);
2603 disk
->disk_prompt
= strdupW(disk_prompt
);
2604 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2606 return ERROR_SUCCESS
;