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
)
362 static const WCHAR query
[] = {
363 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
364 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
365 '`','_','P','r','o','p','e','r','t','y','`',' ',
366 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
367 'T','E','M','P','O','R','A','R','Y',',',' ',
368 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
369 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
370 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
371 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
375 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
376 if (rc
!= ERROR_SUCCESS
)
379 rc
= MSI_ViewExecute(view
, 0);
381 msiobj_release(&view
->hdr
);
385 UINT
msi_clone_properties( MSIDATABASE
*db
)
387 static const WCHAR query_select
[] = {
388 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
389 '`','P','r','o','p','e','r','t','y','`',0};
390 static const WCHAR query_insert
[] = {
391 'I','N','S','E','R','T',' ','I','N','T','O',' ',
392 '`','_','P','r','o','p','e','r','t','y','`',' ',
393 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
394 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
395 static const WCHAR query_update
[] = {
396 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
397 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
398 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
399 MSIQUERY
*view_select
;
402 rc
= MSI_DatabaseOpenViewW( db
, query_select
, &view_select
);
403 if (rc
!= ERROR_SUCCESS
)
406 rc
= MSI_ViewExecute( view_select
, 0 );
407 if (rc
!= ERROR_SUCCESS
)
409 MSI_ViewClose( view_select
);
410 msiobj_release( &view_select
->hdr
);
416 MSIQUERY
*view_insert
, *view_update
;
417 MSIRECORD
*rec_select
;
419 rc
= MSI_ViewFetch( view_select
, &rec_select
);
420 if (rc
!= ERROR_SUCCESS
)
423 rc
= MSI_DatabaseOpenViewW( db
, query_insert
, &view_insert
);
424 if (rc
!= ERROR_SUCCESS
)
426 msiobj_release( &rec_select
->hdr
);
430 rc
= MSI_ViewExecute( view_insert
, rec_select
);
431 MSI_ViewClose( view_insert
);
432 msiobj_release( &view_insert
->hdr
);
433 if (rc
!= ERROR_SUCCESS
)
435 MSIRECORD
*rec_update
;
437 TRACE("insert failed, trying update\n");
439 rc
= MSI_DatabaseOpenViewW( db
, query_update
, &view_update
);
440 if (rc
!= ERROR_SUCCESS
)
442 WARN("open view failed %u\n", rc
);
443 msiobj_release( &rec_select
->hdr
);
447 rec_update
= MSI_CreateRecord( 2 );
448 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
449 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
450 rc
= MSI_ViewExecute( view_update
, rec_update
);
451 if (rc
!= ERROR_SUCCESS
)
452 WARN("update failed %u\n", rc
);
454 MSI_ViewClose( view_update
);
455 msiobj_release( &view_update
->hdr
);
456 msiobj_release( &rec_update
->hdr
);
459 msiobj_release( &rec_select
->hdr
);
462 MSI_ViewClose( view_select
);
463 msiobj_release( &view_select
->hdr
);
470 * Sets the "Installed" property to indicate that
471 * the product is installed for the current user.
473 static UINT
set_installed_prop( MSIPACKAGE
*package
)
478 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
480 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
481 if (r
== ERROR_SUCCESS
)
484 msi_set_property( package
->db
, szInstalled
, szOne
, -1 );
489 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
493 LPWSTR sid_str
= NULL
, dom
= NULL
;
494 DWORD size
, dom_size
;
496 UINT r
= ERROR_FUNCTION_FAILED
;
499 GetUserNameW( NULL
, &size
);
501 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
503 return ERROR_OUTOFMEMORY
;
505 if (!GetUserNameW( user_name
, &size
))
510 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
512 psid
= msi_alloc( size
);
513 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
516 r
= ERROR_OUTOFMEMORY
;
520 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
523 if (!ConvertSidToStringSidW( psid
, &sid_str
))
526 r
= msi_set_property( package
->db
, szUserSID
, sid_str
, -1 );
529 LocalFree( sid_str
);
532 msi_free( user_name
);
537 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
539 static const WCHAR fusion
[] =
540 {'f','u','s','i','o','n','.','d','l','l',0};
541 static const WCHAR subkey
[] =
542 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
543 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\','N','D','P',0};
544 static const WCHAR subdir
[] =
545 {'M','i','c','r','o','s','o','f','t','.','N','E','T','\\','F','r','a','m','e','w','o','r','k','\\',0};
546 static const WCHAR v2050727
[] =
547 {'v','2','.','0','.','5','0','7','2','7',0};
548 static const WCHAR v4client
[] =
549 {'v','4','\\','C','l','i','e','n','t',0};
550 static const WCHAR installpath
[] =
551 {'I','n','s','t','a','l','l','P','a','t','h',0};
554 DWORD size
, len
, type
;
555 WCHAR windir
[MAX_PATH
], path
[MAX_PATH
], *filename
= NULL
;
557 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, subkey
, 0, KEY_CREATE_SUB_KEY
, &netsetup
);
558 if (res
!= ERROR_SUCCESS
)
561 if (!RegCreateKeyExW(netsetup
, v4client
, 0, NULL
, 0, KEY_QUERY_VALUE
, NULL
, &hkey
, NULL
))
563 size
= ARRAY_SIZE(path
);
564 if (!RegQueryValueExW(hkey
, installpath
, NULL
, &type
, (BYTE
*)path
, &size
))
566 len
= lstrlenW(path
) + lstrlenW(fusion
) + 2;
567 if (!(filename
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
569 lstrcpyW(filename
, path
);
570 lstrcatW(filename
, szBackSlash
);
571 lstrcatW(filename
, fusion
);
572 if (GetFileAttributesW(filename
) != INVALID_FILE_ATTRIBUTES
)
574 TRACE( "found %s\n", debugstr_w(filename
) );
576 RegCloseKey(netsetup
);
583 if (!RegCreateKeyExW(netsetup
, v2050727
, 0, NULL
, 0, KEY_QUERY_VALUE
, NULL
, &hkey
, NULL
))
586 GetWindowsDirectoryW(windir
, MAX_PATH
);
587 len
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(v2050727
) + lstrlenW(fusion
) + 3;
588 if (!(filename
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
590 lstrcpyW(filename
, windir
);
591 lstrcatW(filename
, szBackSlash
);
592 lstrcatW(filename
, subdir
);
593 lstrcatW(filename
, v2050727
);
594 lstrcatW(filename
, szBackSlash
);
595 lstrcatW(filename
, fusion
);
596 if (GetFileAttributesW(filename
) != INVALID_FILE_ATTRIBUTES
)
598 TRACE( "found %s\n", debugstr_w(filename
) );
599 RegCloseKey(netsetup
);
604 RegCloseKey(netsetup
);
608 typedef struct tagLANGANDCODEPAGE
614 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
618 LPVOID version
= NULL
;
620 LPWSTR fusion
, verstr
;
621 LANGANDCODEPAGE
*translate
;
623 static const WCHAR netasm
[] = {
624 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
626 static const WCHAR translation
[] = {
627 '\\','V','a','r','F','i','l','e','I','n','f','o',
628 '\\','T','r','a','n','s','l','a','t','i','o','n',0
630 static const WCHAR verfmt
[] = {
631 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
632 '\\','%','0','4','x','%','0','4','x',
633 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
636 fusion
= get_fusion_filename(package
);
640 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
644 version
= msi_alloc(size
);
648 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
651 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
654 swprintf(buf
, ARRAY_SIZE(buf
), verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
656 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
659 if (!val_len
|| !verstr
)
662 msi_set_property( package
->db
, netasm
, verstr
, -1 );
669 static VOID
set_installer_properties(MSIPACKAGE
*package
)
672 RTL_OSVERSIONINFOEXW OSVersion
;
674 DWORD verval
, len
, type
;
675 WCHAR pth
[MAX_PATH
], verstr
[11], bufstr
[22];
678 LPWSTR username
, companyname
;
679 SYSTEM_INFO sys_info
;
682 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
683 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
684 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
685 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
686 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
687 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
688 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
689 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
690 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
691 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
692 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
693 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
694 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
695 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
696 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
697 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
698 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
699 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
700 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
701 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
702 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
703 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
704 static const WCHAR szFormat
[] = {'%','u',0};
705 static const WCHAR szFormat2
[] = {'%','u','.','%','u',0};
706 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
707 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
708 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
709 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
710 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
711 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
712 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
713 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
714 static const WCHAR szIntFormat
[] = {'%','d',0};
715 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
716 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
717 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
718 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
719 static const WCHAR szProgramFiles64Folder
[] = { 'P','r','o','g','r','a','m','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
720 static const WCHAR szProgramFilesDir
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',0};
721 static const WCHAR szProgramFilesDirx86
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
722 static const WCHAR szCommonFilesDir
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',0};
723 static const WCHAR szCommonFilesDirx86
[] = {'C','o','m','m','o','n','F','i','l','e','s','D','i','r',' ','(','x','8','6',')',0};
724 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
725 static const WCHAR szUserInfo
[] = {
726 'S','O','F','T','W','A','R','E','\\',
727 'M','i','c','r','o','s','o','f','t','\\',
728 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
729 'U','s','e','r',' ','I','n','f','o',0
731 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
732 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
733 static const WCHAR szCurrentVersion
[] = {
734 'S','O','F','T','W','A','R','E','\\',
735 'M','i','c','r','o','s','o','f','t','\\',
736 'W','i','n','d','o','w','s','\\',
737 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
739 static const WCHAR szCurrentVersionNT
[] = {
740 'S','O','F','T','W','A','R','E','\\',
741 'M','i','c','r','o','s','o','f','t','\\',
742 'W','i','n','d','o','w','s',' ','N','T','\\',
743 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
745 static const WCHAR szRegisteredOwner
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
746 static const WCHAR szRegisteredOrganization
[] = {
747 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
749 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
750 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
751 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
752 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
753 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
754 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
755 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
756 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
757 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
758 static const WCHAR szComputerName
[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
761 * Other things that probably should be set:
763 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
764 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
767 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
768 lstrcatW(pth
, szBackSlash
);
769 msi_set_property( package
->db
, szCommonAppDataFolder
, pth
, -1 );
771 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
772 lstrcatW(pth
, szBackSlash
);
773 msi_set_property( package
->db
, szFavoritesFolder
, pth
, -1 );
775 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
776 lstrcatW(pth
, szBackSlash
);
777 msi_set_property( package
->db
, szFontsFolder
, pth
, -1 );
779 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
780 lstrcatW(pth
, szBackSlash
);
781 msi_set_property( package
->db
, szSendToFolder
, pth
, -1 );
783 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
784 lstrcatW(pth
, szBackSlash
);
785 msi_set_property( package
->db
, szStartMenuFolder
, pth
, -1 );
787 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
788 lstrcatW(pth
, szBackSlash
);
789 msi_set_property( package
->db
, szStartupFolder
, pth
, -1 );
791 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
792 lstrcatW(pth
, szBackSlash
);
793 msi_set_property( package
->db
, szTemplateFolder
, pth
, -1 );
795 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
796 lstrcatW(pth
, szBackSlash
);
797 msi_set_property( package
->db
, szDesktopFolder
, pth
, -1 );
799 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
800 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
801 lstrcatW(pth
, szBackSlash
);
802 msi_set_property( package
->db
, szProgramMenuFolder
, pth
, -1 );
804 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
805 lstrcatW(pth
, szBackSlash
);
806 msi_set_property( package
->db
, szAdminToolsFolder
, pth
, -1 );
808 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
809 lstrcatW(pth
, szBackSlash
);
810 msi_set_property( package
->db
, szAppDataFolder
, pth
, -1 );
812 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
813 lstrcatW(pth
, szBackSlash
);
814 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
815 msi_set_property( package
->db
, szSystem16Folder
, pth
, -1 );
817 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
818 lstrcatW(pth
, szBackSlash
);
819 msi_set_property( package
->db
, szLocalAppDataFolder
, pth
, -1 );
821 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
822 lstrcatW(pth
, szBackSlash
);
823 msi_set_property( package
->db
, szMyPicturesFolder
, pth
, -1 );
825 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
826 lstrcatW(pth
, szBackSlash
);
827 msi_set_property( package
->db
, szPersonalFolder
, pth
, -1 );
829 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
830 lstrcatW(pth
, szBackSlash
);
831 msi_set_property( package
->db
, szWindowsFolder
, pth
, -1 );
833 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
834 lstrcatW(pth
, szBackSlash
);
835 msi_set_property( package
->db
, szPrintHoodFolder
, pth
, -1 );
837 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
838 lstrcatW(pth
, szBackSlash
);
839 msi_set_property( package
->db
, szNetHoodFolder
, pth
, -1 );
841 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
842 lstrcatW(pth
, szBackSlash
);
843 msi_set_property( package
->db
, szRecentFolder
, pth
, -1 );
845 /* Physical Memory is specified in MB. Using total amount. */
846 msex
.dwLength
= sizeof(msex
);
847 GlobalMemoryStatusEx( &msex
);
848 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
849 msi_set_property( package
->db
, szPhysicalMemory
, bufstr
, len
);
851 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
852 ptr
= wcschr(pth
,'\\');
853 if (ptr
) *(ptr
+ 1) = 0;
854 msi_set_property( package
->db
, szWindowsVolume
, pth
, -1 );
856 len
= GetTempPathW(MAX_PATH
, pth
);
857 msi_set_property( package
->db
, szTempFolder
, pth
, len
);
859 /* in a wine environment the user is always admin and privileged */
860 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
861 msi_set_property( package
->db
, szPrivileged
, szOne
, -1 );
863 /* set the os things */
864 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVersion
);
865 RtlGetVersion(&OSVersion
);
866 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
870 OSVersion
.dwBuildNumber
= 9600;
872 len
= swprintf( verstr
, ARRAY_SIZE(verstr
), szFormat
, verval
);
873 switch (OSVersion
.dwPlatformId
)
875 case VER_PLATFORM_WIN32_WINDOWS
:
876 msi_set_property( package
->db
, szVersion9x
, verstr
, len
);
878 case VER_PLATFORM_WIN32_NT
:
879 msi_set_property( package
->db
, szVersionNT
, verstr
, len
);
880 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szFormat
,OSVersion
.wProductType
);
881 msi_set_property( package
->db
, szMsiNTProductType
, bufstr
, len
);
884 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szFormat
, OSVersion
.dwBuildNumber
);
885 msi_set_property( package
->db
, szWindowsBuild
, bufstr
, len
);
886 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szFormat
, OSVersion
.wServicePackMajor
);
887 msi_set_property( package
->db
, szServicePackLevel
, bufstr
, len
);
889 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
890 msi_set_property( package
->db
, szVersionMsi
, bufstr
, len
);
891 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szFormat
, MSI_MAJORVERSION
* 100 );
892 msi_set_property( package
->db
, szVersionDatabase
, bufstr
, len
);
894 RegOpenKeyExW(HKEY_LOCAL_MACHINE
, szCurrentVersion
, 0,
895 KEY_QUERY_VALUE
| KEY_WOW64_64KEY
, &hkey
);
897 GetNativeSystemInfo( &sys_info
);
898 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, sys_info
.wProcessorLevel
);
899 msi_set_property( package
->db
, szIntel
, bufstr
, len
);
900 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
902 GetSystemDirectoryW( pth
, MAX_PATH
);
903 PathAddBackslashW( pth
);
904 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
907 RegQueryValueExW(hkey
, szProgramFilesDir
, 0, &type
, (BYTE
*)pth
, &len
);
908 PathAddBackslashW( pth
);
909 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
912 RegQueryValueExW(hkey
, szCommonFilesDir
, 0, &type
, (BYTE
*)pth
, &len
);
913 PathAddBackslashW( pth
);
914 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
916 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
918 msi_set_property( package
->db
, szMsiAMD64
, bufstr
, -1 );
919 msi_set_property( package
->db
, szMsix64
, bufstr
, -1 );
920 msi_set_property( package
->db
, szVersionNT64
, verstr
, -1 );
922 GetSystemDirectoryW( pth
, MAX_PATH
);
923 PathAddBackslashW( pth
);
924 msi_set_property( package
->db
, szSystem64Folder
, pth
, -1 );
926 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
927 PathAddBackslashW( pth
);
928 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
931 RegQueryValueExW(hkey
, szProgramFilesDir
, 0, &type
, (BYTE
*)pth
, &len
);
932 PathAddBackslashW( pth
);
933 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
, -1 );
936 RegQueryValueExW(hkey
, szProgramFilesDirx86
, 0, &type
, (BYTE
*)pth
, &len
);
937 PathAddBackslashW( pth
);
938 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
941 RegQueryValueExW(hkey
, szCommonFilesDir
, 0, &type
, (BYTE
*)pth
, &len
);
942 PathAddBackslashW( pth
);
943 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
, -1 );
946 RegQueryValueExW(hkey
, szCommonFilesDirx86
, 0, &type
, (BYTE
*)pth
, &len
);
947 PathAddBackslashW( pth
);
948 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
953 /* Screen properties. */
955 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, GetDeviceCaps(dc
, HORZRES
) );
956 msi_set_property( package
->db
, szScreenX
, bufstr
, len
);
957 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, GetDeviceCaps(dc
, VERTRES
) );
958 msi_set_property( package
->db
, szScreenY
, bufstr
, len
);
959 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, GetDeviceCaps(dc
, BITSPIXEL
) );
960 msi_set_property( package
->db
, szColorBits
, bufstr
, len
);
963 /* USERNAME and COMPANYNAME */
964 username
= msi_dup_property( package
->db
, szUSERNAME
);
965 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
967 if ((!username
|| !companyname
) &&
968 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
971 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
972 msi_set_property( package
->db
, szUSERNAME
, username
, -1 );
974 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
975 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
978 if ((!username
|| !companyname
) &&
979 RegOpenKeyExW( HKEY_LOCAL_MACHINE
, szCurrentVersionNT
, 0, KEY_QUERY_VALUE
|KEY_WOW64_64KEY
,
980 &hkey
) == ERROR_SUCCESS
)
983 (username
= msi_reg_get_val_str( hkey
, szRegisteredOwner
)))
984 msi_set_property( package
->db
, szUSERNAME
, username
, -1 );
986 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
987 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
990 msi_free( username
);
991 msi_free( companyname
);
993 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
994 ERR("Failed to set the UserSID property\n");
996 set_msi_assembly_prop( package
);
998 langid
= GetUserDefaultLangID();
999 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, langid
);
1000 msi_set_property( package
->db
, szUserLanguageID
, bufstr
, len
);
1002 langid
= GetSystemDefaultLangID();
1003 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, langid
);
1004 msi_set_property( package
->db
, szSystemLangID
, bufstr
, len
);
1006 len
= swprintf( bufstr
, ARRAY_SIZE(bufstr
), szIntFormat
, MsiQueryProductStateW(package
->ProductCode
) );
1007 msi_set_property( package
->db
, szProductState
, bufstr
, len
);
1010 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1013 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
1015 if (GetUserNameW( username
, &len
))
1016 msi_set_property( package
->db
, szLogonUser
, username
, len
- 1 );
1017 msi_free( username
);
1021 if (!GetComputerNameW( NULL
, &len
) && GetLastError() == ERROR_BUFFER_OVERFLOW
)
1023 WCHAR
*computername
;
1024 if ((computername
= msi_alloc( len
* sizeof(WCHAR
) )))
1026 if (GetComputerNameW( computername
, &len
))
1027 msi_set_property( package
->db
, szComputerName
, computername
, len
);
1028 msi_free( computername
);
1033 static MSIPACKAGE
*msi_alloc_package( void )
1035 MSIPACKAGE
*package
;
1037 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1041 list_init( &package
->components
);
1042 list_init( &package
->features
);
1043 list_init( &package
->files
);
1044 list_init( &package
->filepatches
);
1045 list_init( &package
->tempfiles
);
1046 list_init( &package
->folders
);
1047 list_init( &package
->subscriptions
);
1048 list_init( &package
->appids
);
1049 list_init( &package
->classes
);
1050 list_init( &package
->mimes
);
1051 list_init( &package
->extensions
);
1052 list_init( &package
->progids
);
1053 list_init( &package
->RunningActions
);
1054 list_init( &package
->sourcelist_info
);
1055 list_init( &package
->sourcelist_media
);
1056 list_init( &package
->patches
);
1057 list_init( &package
->binaries
);
1058 list_init( &package
->cabinet_streams
);
1064 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1069 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1071 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1072 if (r
!= ERROR_SUCCESS
)
1075 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1081 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1083 /* FIXME: this should depend on the user's privileges */
1084 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1086 TRACE("resetting ALLUSERS property from 2 to 1\n");
1087 msi_set_property( package
->db
, szAllUsers
, szOne
, -1 );
1089 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
1092 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
)
1094 static const WCHAR fmtW
[] = {'%','u',0};
1095 MSIPACKAGE
*package
;
1102 package
= msi_alloc_package();
1105 msiobj_addref( &db
->hdr
);
1108 package
->LastAction
= NULL
;
1109 package
->LastActionTemplate
= NULL
;
1110 package
->LastActionResult
= MSI_NULL_INTEGER
;
1111 package
->WordCount
= 0;
1112 package
->PackagePath
= strdupW( db
->path
);
1114 create_temp_property_table( package
);
1115 msi_clone_properties( package
->db
);
1116 msi_adjust_privilege_properties( package
);
1118 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1120 set_installer_properties( package
);
1122 package
->ui_level
= gUILevel
;
1123 len
= swprintf( uilevel
, ARRAY_SIZE(uilevel
), fmtW
, gUILevel
& INSTALLUILEVEL_MASK
);
1124 msi_set_property( package
->db
, szUILevel
, uilevel
, len
);
1126 r
= msi_load_suminfo_properties( package
);
1127 if (r
!= ERROR_SUCCESS
)
1129 msiobj_release( &package
->hdr
);
1133 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1134 msi_load_admin_properties( package
);
1136 package
->log_file
= INVALID_HANDLE_VALUE
;
1137 package
->script
= SCRIPT_NONE
;
1142 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1144 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1148 /* call will always fail, because size is 0,
1149 * but will return ERROR_FILE_NOT_FOUND first
1150 * if the file doesn't exist
1152 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1153 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1155 cache_entry
= msi_alloc( size
);
1156 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1158 UINT error
= GetLastError();
1159 msi_free( cache_entry
);
1163 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1164 msi_free( cache_entry
);
1165 return ERROR_SUCCESS
;
1168 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1171 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1172 return ERROR_FUNCTION_FAILED
;
1175 return ERROR_SUCCESS
;
1178 UINT
msi_create_empty_local_file( LPWSTR path
, LPCWSTR suffix
)
1180 static const WCHAR szInstaller
[] = {
1181 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1182 static const WCHAR fmt
[] = {'%','x',0};
1183 DWORD time
, len
, i
, offset
;
1186 time
= GetTickCount();
1187 GetWindowsDirectoryW( path
, MAX_PATH
);
1188 lstrcatW( path
, szInstaller
);
1189 CreateDirectoryW( path
, NULL
);
1191 len
= lstrlenW(path
);
1192 for (i
= 0; i
< 0x10000; i
++)
1194 offset
= swprintf( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1195 memcpy( path
+ len
+ offset
, suffix
, (lstrlenW( suffix
) + 1) * sizeof(WCHAR
) );
1196 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1197 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1198 if (handle
!= INVALID_HANDLE_VALUE
)
1200 CloseHandle(handle
);
1203 if (GetLastError() != ERROR_FILE_EXISTS
&&
1204 GetLastError() != ERROR_SHARING_VIOLATION
)
1205 return ERROR_FUNCTION_FAILED
;
1208 return ERROR_SUCCESS
;
1211 static enum platform
parse_platform( const WCHAR
*str
)
1213 if (!str
[0] || !wcscmp( str
, szIntel
)) return PLATFORM_INTEL
;
1214 else if (!wcscmp( str
, szIntel64
)) return PLATFORM_INTEL64
;
1215 else if (!wcscmp( str
, szX64
) || !wcscmp( str
, szAMD64
)) return PLATFORM_X64
;
1216 else if (!wcscmp( str
, szARM
)) return PLATFORM_ARM
;
1217 else if (!wcscmp( str
, szARM64
)) return PLATFORM_ARM64
;
1218 return PLATFORM_UNRECOGNIZED
;
1221 static UINT
parse_suminfo( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1223 WCHAR
*template, *p
, *q
, *platform
;
1226 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1227 TRACE("version: %d\n", package
->version
);
1229 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1231 return ERROR_SUCCESS
; /* native accepts missing template property */
1233 TRACE("template: %s\n", debugstr_w(template));
1235 p
= wcschr( template, ';' );
1238 WARN("invalid template string %s\n", debugstr_w(template));
1239 msi_free( template );
1240 return ERROR_PATCH_PACKAGE_INVALID
;
1243 platform
= template;
1244 if ((q
= wcschr( platform
, ',' ))) *q
= 0;
1245 package
->platform
= parse_platform( platform
);
1246 while (package
->platform
== PLATFORM_UNRECOGNIZED
&& q
)
1249 if ((q
= wcschr( platform
, ',' ))) *q
= 0;
1250 package
->platform
= parse_platform( platform
);
1252 if (package
->platform
== PLATFORM_UNRECOGNIZED
)
1254 WARN("unknown platform %s\n", debugstr_w(template));
1255 msi_free( template );
1256 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1261 msi_free( template );
1262 return ERROR_SUCCESS
;
1265 for (q
= p
; (q
= wcschr( q
, ',' )); q
++) count
++;
1267 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1268 if (!package
->langids
)
1270 msi_free( template );
1271 return ERROR_OUTOFMEMORY
;
1277 q
= wcschr( p
, ',' );
1279 package
->langids
[i
] = wcstol( p
, NULL
, 10 );
1284 package
->num_langids
= i
+ 1;
1286 msi_free( template );
1287 return ERROR_SUCCESS
;
1290 static UINT
validate_package( MSIPACKAGE
*package
)
1294 if (package
->platform
== PLATFORM_INTEL64
)
1295 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1297 if (package
->platform
== PLATFORM_ARM
)
1298 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1301 if (package
->platform
== PLATFORM_ARM64
)
1302 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1304 if (package
->platform
== PLATFORM_X64
)
1306 if (!is_64bit
&& !is_wow64
)
1307 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1308 if (package
->version
< 200)
1309 return ERROR_INSTALL_PACKAGE_INVALID
;
1311 if (!package
->num_langids
)
1313 return ERROR_SUCCESS
;
1315 for (i
= 0; i
< package
->num_langids
; i
++)
1317 LANGID langid
= package
->langids
[i
];
1319 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1321 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1323 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1325 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1327 if (IsValidLocale( langid
, LCID_INSTALLED
))
1328 return ERROR_SUCCESS
;
1330 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1333 static WCHAR
*get_property( MSIDATABASE
*db
, const WCHAR
*prop
)
1335 static const WCHAR select_query
[] = {
1336 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1337 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1338 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1339 '\'','%','s','\'',0};
1340 WCHAR query
[MAX_PATH
];
1345 swprintf(query
, ARRAY_SIZE(query
), select_query
, prop
);
1346 if (MSI_DatabaseOpenViewW( db
, query
, &view
) != ERROR_SUCCESS
)
1350 if (MSI_ViewExecute( view
, 0 ) != ERROR_SUCCESS
)
1352 MSI_ViewClose( view
);
1353 msiobj_release( &view
->hdr
);
1356 if (MSI_ViewFetch( view
, &rec
) == ERROR_SUCCESS
)
1358 ret
= strdupW( MSI_RecordGetString( rec
, 1 ) );
1359 msiobj_release( &rec
->hdr
);
1361 MSI_ViewClose( view
);
1362 msiobj_release( &view
->hdr
);
1366 static WCHAR
*get_product_code( MSIDATABASE
*db
)
1368 return get_property( db
, szProductCode
);
1371 static WCHAR
*get_product_version( MSIDATABASE
*db
)
1373 return get_property( db
, szProductVersion
);
1376 static UINT
get_registered_local_package( const WCHAR
*product
, WCHAR
*localfile
)
1378 MSIINSTALLCONTEXT context
;
1383 r
= msi_locate_product( product
, &context
);
1384 if (r
!= ERROR_SUCCESS
)
1387 r
= MSIREG_OpenInstallProps( product
, context
, NULL
, &props_key
, FALSE
);
1388 if (r
!= ERROR_SUCCESS
)
1391 filename
= msi_reg_get_val_str( props_key
, INSTALLPROPERTY_LOCALPACKAGEW
);
1392 RegCloseKey( props_key
);
1394 return ERROR_FUNCTION_FAILED
;
1396 lstrcpyW( localfile
, filename
);
1397 msi_free( filename
);
1398 return ERROR_SUCCESS
;
1401 WCHAR
*msi_get_package_code( MSIDATABASE
*db
)
1407 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1408 if (r
!= ERROR_SUCCESS
)
1410 r
= msi_get_db_suminfo( db
, 0, &si
);
1411 if (r
!= ERROR_SUCCESS
)
1413 WARN("failed to load summary info %u\n", r
);
1417 ret
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
1418 msiobj_release( &si
->hdr
);
1422 static UINT
get_local_package( MSIDATABASE
*db
, WCHAR
*localfile
)
1424 WCHAR
*product_code
;
1427 if (!(product_code
= get_product_code( db
)))
1428 return ERROR_INSTALL_PACKAGE_INVALID
;
1429 r
= get_registered_local_package( product_code
, localfile
);
1430 msi_free( product_code
);
1434 UINT
msi_set_original_database_property( MSIDATABASE
*db
, const WCHAR
*package
)
1438 if (UrlIsW( package
, URLIS_URL
))
1439 r
= msi_set_property( db
, szOriginalDatabase
, package
, -1 );
1440 else if (package
[0] == '#')
1441 r
= msi_set_property( db
, szOriginalDatabase
, db
->path
, -1 );
1447 if (!(len
= GetFullPathNameW( package
, 0, NULL
, NULL
))) return GetLastError();
1448 if (!(path
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1449 len
= GetFullPathNameW( package
, len
, path
, NULL
);
1450 r
= msi_set_property( db
, szOriginalDatabase
, path
, len
);
1456 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, DWORD dwOptions
, MSIPACKAGE
**pPackage
)
1458 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1460 MSIPACKAGE
*package
;
1462 MSIRECORD
*data_row
, *info_row
;
1464 WCHAR localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1465 LPCWSTR file
= szPackage
;
1468 BOOL delete_on_close
= FALSE
;
1469 WCHAR
*info_template
, *productname
, *product_code
;
1470 MSIINSTALLCONTEXT context
;
1472 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1474 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_INITIALIZE
, 0);
1477 if( szPackage
[0] == '#' )
1479 handle
= wcstol(&szPackage
[1], NULL
, 10);
1480 if (!(db
= msihandle2msiinfo(handle
, MSIHANDLETYPE_DATABASE
)))
1481 return ERROR_INVALID_HANDLE
;
1485 WCHAR
*product_version
= NULL
;
1487 if ( UrlIsW( szPackage
, URLIS_URL
) )
1489 r
= msi_download_file( szPackage
, cachefile
);
1490 if (r
!= ERROR_SUCCESS
)
1495 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
1496 if (r
!= ERROR_SUCCESS
)
1498 if (GetFileAttributesW( file
) == INVALID_FILE_ATTRIBUTES
)
1499 return ERROR_FILE_NOT_FOUND
;
1502 r
= get_local_package( db
, localfile
);
1503 if (r
!= ERROR_SUCCESS
|| GetFileAttributesW( localfile
) == INVALID_FILE_ATTRIBUTES
)
1505 r
= msi_create_empty_local_file( localfile
, dotmsi
);
1506 if (r
!= ERROR_SUCCESS
)
1508 msiobj_release( &db
->hdr
);
1512 if (!CopyFileW( file
, localfile
, FALSE
))
1515 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file
), debugstr_w(localfile
), r
);
1516 DeleteFileW( localfile
);
1517 msiobj_release( &db
->hdr
);
1520 delete_on_close
= TRUE
;
1522 else if (dwOptions
& WINE_OPENPACKAGEFLAGS_RECACHE
)
1524 if (!CopyFileW( file
, localfile
, FALSE
))
1527 WARN("unable to update cached package (%u)\n", r
);
1528 msiobj_release( &db
->hdr
);
1533 product_version
= get_product_version( db
);
1534 msiobj_release( &db
->hdr
);
1535 TRACE("opening package %s\n", debugstr_w( localfile
));
1536 r
= MSI_OpenDatabaseW( localfile
, MSIDBOPEN_TRANSACT
, &db
);
1537 if (r
!= ERROR_SUCCESS
)
1540 if (product_version
)
1542 WCHAR
*cache_version
= get_product_version( db
);
1543 if (!product_version
!= !cache_version
||
1544 (product_version
&& wcscmp(product_version
, cache_version
)))
1546 msiobj_release( &db
->hdr
);
1547 msi_free(product_version
);
1548 msi_free(cache_version
);
1549 return ERROR_PRODUCT_VERSION
;
1551 msi_free(product_version
);
1552 msi_free(cache_version
);
1555 package
= MSI_CreatePackage( db
);
1556 msiobj_release( &db
->hdr
);
1557 if (!package
) return ERROR_INSTALL_PACKAGE_INVALID
;
1558 package
->localfile
= strdupW( localfile
);
1559 package
->delete_on_close
= delete_on_close
;
1561 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1562 if (r
!= ERROR_SUCCESS
)
1564 r
= msi_get_db_suminfo( db
, 0, &si
);
1565 if (r
!= ERROR_SUCCESS
)
1567 WARN("failed to load summary info\n");
1568 msiobj_release( &package
->hdr
);
1569 return ERROR_INSTALL_PACKAGE_INVALID
;
1572 r
= parse_suminfo( si
, package
);
1573 msiobj_release( &si
->hdr
);
1574 if (r
!= ERROR_SUCCESS
)
1576 WARN("failed to parse summary info %u\n", r
);
1577 msiobj_release( &package
->hdr
);
1580 r
= validate_package( package
);
1581 if (r
!= ERROR_SUCCESS
)
1583 msiobj_release( &package
->hdr
);
1586 msi_set_property( package
->db
, szDatabase
, db
->path
, -1 );
1587 set_installed_prop( package
);
1588 msi_set_context( package
);
1590 product_code
= get_product_code( db
);
1591 if (msi_locate_product( product_code
, &context
) == ERROR_SUCCESS
)
1593 TRACE("product already registered\n");
1594 msi_set_property( package
->db
, szProductToBeRegistered
, szOne
, -1 );
1596 msi_free(product_code
);
1600 WCHAR patch_code
[GUID_SIZE
];
1601 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1602 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1603 if (r
!= ERROR_SUCCESS
)
1606 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1608 r
= msi_apply_registered_patch( package
, patch_code
);
1609 if (r
!= ERROR_SUCCESS
)
1611 ERR("registered patch failed to apply %u\n", r
);
1612 msiobj_release( &package
->hdr
);
1617 if (index
) msi_adjust_privilege_properties( package
);
1619 r
= msi_set_original_database_property( package
->db
, szPackage
);
1620 if (r
!= ERROR_SUCCESS
)
1622 msiobj_release( &package
->hdr
);
1626 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1627 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1629 if (!msi_init_assembly_caches( package
))
1631 ERR("can't initialize assembly caches\n");
1632 msiobj_release( &package
->hdr
);
1633 return ERROR_FUNCTION_FAILED
;
1636 /* FIXME: when should these messages be sent? */
1637 data_row
= MSI_CreateRecord(3);
1639 return ERROR_OUTOFMEMORY
;
1640 MSI_RecordSetStringW(data_row
, 0, NULL
);
1641 MSI_RecordSetInteger(data_row
, 1, 0);
1642 MSI_RecordSetInteger(data_row
, 2, package
->num_langids
? package
->langids
[0] : 0);
1643 MSI_RecordSetInteger(data_row
, 3, msi_get_string_table_codepage(package
->db
->strings
));
1644 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1646 info_row
= MSI_CreateRecord(0);
1649 msiobj_release(&data_row
->hdr
);
1650 return ERROR_OUTOFMEMORY
;
1652 info_template
= msi_get_error_message(package
->db
, MSIERR_INFO_LOGGINGSTART
);
1653 MSI_RecordSetStringW(info_row
, 0, info_template
);
1654 msi_free(info_template
);
1655 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, info_row
);
1657 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1659 productname
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
1660 MSI_RecordSetInteger(data_row
, 1, 1);
1661 MSI_RecordSetStringW(data_row
, 2, productname
);
1662 MSI_RecordSetStringW(data_row
, 3, NULL
);
1663 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1665 msi_free(productname
);
1666 msiobj_release(&info_row
->hdr
);
1667 msiobj_release(&data_row
->hdr
);
1669 *pPackage
= package
;
1670 return ERROR_SUCCESS
;
1673 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1675 MSIPACKAGE
*package
= NULL
;
1678 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1680 if( !szPackage
|| !phPackage
)
1681 return ERROR_INVALID_PARAMETER
;
1685 FIXME("Should create an empty database and package\n");
1686 return ERROR_FUNCTION_FAILED
;
1690 FIXME("dwOptions %08x not supported\n", dwOptions
);
1692 ret
= MSI_OpenPackageW( szPackage
, 0, &package
);
1693 if( ret
== ERROR_SUCCESS
)
1695 *phPackage
= alloc_msihandle( &package
->hdr
);
1697 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1698 msiobj_release( &package
->hdr
);
1701 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_TERMINATE
, 0);
1706 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1708 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1711 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1713 LPWSTR szwPack
= NULL
;
1718 szwPack
= strdupAtoW( szPackage
);
1720 return ERROR_OUTOFMEMORY
;
1723 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1725 msi_free( szwPack
);
1730 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1732 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1735 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1737 MSIPACKAGE
*package
;
1738 MSIHANDLE handle
= 0;
1741 TRACE("(%d)\n",hInstall
);
1743 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1746 handle
= alloc_msihandle( &package
->db
->hdr
);
1747 msiobj_release( &package
->hdr
);
1749 else if ((remote
= msi_get_remote(hInstall
)))
1753 handle
= remote_GetActiveDatabase(remote
);
1754 handle
= alloc_msi_remote_handle(handle
);
1756 __EXCEPT(rpc_filter
)
1766 static INT
internal_ui_handler(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
, LPCWSTR message
)
1768 static const WCHAR szActionData
[] = {'A','c','t','i','o','n','D','a','t','a',0};
1769 static const WCHAR szActionText
[] = {'A','c','t','i','o','n','T','e','x','t',0};
1770 static const WCHAR szSetProgress
[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1771 static const WCHAR szWindows_Installer
[] =
1772 {'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0};
1774 if (!package
|| (package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
1777 /* todo: check if message needs additional styles (topmost/foreground/modality?) */
1779 switch (eMessageType
& 0xff000000)
1781 case INSTALLMESSAGE_FATALEXIT
:
1782 case INSTALLMESSAGE_ERROR
:
1783 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1784 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1785 if (!(eMessageType
& MB_ICONMASK
))
1786 eMessageType
|= MB_ICONEXCLAMATION
;
1787 return MessageBoxW(gUIhwnd
, message
, szWindows_Installer
, eMessageType
& 0x00ffffff);
1788 case INSTALLMESSAGE_WARNING
:
1789 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1790 if (!(eMessageType
& MB_ICONMASK
))
1791 eMessageType
|= MB_ICONASTERISK
;
1792 return MessageBoxW(gUIhwnd
, message
, szWindows_Installer
, eMessageType
& 0x00ffffff);
1793 case INSTALLMESSAGE_USER
:
1794 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1795 if (!(eMessageType
& MB_ICONMASK
))
1796 eMessageType
|= MB_USERICON
;
1797 return MessageBoxW(gUIhwnd
, message
, szWindows_Installer
, eMessageType
& 0x00ffffff);
1798 case INSTALLMESSAGE_INFO
:
1799 case INSTALLMESSAGE_INITIALIZE
:
1800 case INSTALLMESSAGE_TERMINATE
:
1801 case INSTALLMESSAGE_INSTALLSTART
:
1802 case INSTALLMESSAGE_INSTALLEND
:
1804 case INSTALLMESSAGE_SHOWDIALOG
:
1806 LPWSTR dialog
= msi_dup_record_field(record
, 0);
1807 INT rc
= ACTION_DialogBox(package
, dialog
);
1811 case INSTALLMESSAGE_ACTIONSTART
:
1814 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1815 if (!uirow
) return -1;
1816 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformatted
);
1817 MSI_RecordSetStringW(uirow
, 1, deformatted
);
1818 msi_event_fire(package
, szActionText
, uirow
);
1820 msi_free(deformatted
);
1821 msiobj_release(&uirow
->hdr
);
1824 case INSTALLMESSAGE_ACTIONDATA
:
1826 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1827 if (!uirow
) return -1;
1828 MSI_RecordSetStringW(uirow
, 1, message
);
1829 msi_event_fire(package
, szActionData
, uirow
);
1830 msiobj_release(&uirow
->hdr
);
1832 if (package
->action_progress_increment
)
1834 uirow
= MSI_CreateRecord(2);
1835 if (!uirow
) return -1;
1836 MSI_RecordSetInteger(uirow
, 1, 2);
1837 MSI_RecordSetInteger(uirow
, 2, package
->action_progress_increment
);
1838 msi_event_fire(package
, szSetProgress
, uirow
);
1839 msiobj_release(&uirow
->hdr
);
1843 case INSTALLMESSAGE_PROGRESS
:
1844 msi_event_fire(package
, szSetProgress
, record
);
1846 case INSTALLMESSAGE_COMMONDATA
:
1847 switch (MSI_RecordGetInteger(record
, 1))
1858 FIXME("internal UI not implemented for message 0x%08x (UI level = %x)\n", eMessageType
, package
->ui_level
);
1863 static const WCHAR szActionNotFound
[] = {'D','E','B','U','G',':',' ','E','r','r','o','r',' ','[','1',']',':',' ',' ','A','c','t','i','o','n',' ','n','o','t',' ','f','o','u','n','d',':',' ','[','2',']',0};
1872 {2726, szActionNotFound
},
1876 static LPCWSTR
get_internal_error_message(int error
)
1880 while (internal_errors
[i
].id
!= 0)
1882 if (internal_errors
[i
].id
== error
)
1883 return internal_errors
[i
].text
;
1887 FIXME("missing error message %d\n", error
);
1891 /* Returned string must be freed */
1892 LPWSTR
msi_get_error_message(MSIDATABASE
*db
, int error
)
1894 static const WCHAR query
[] =
1895 {'S','E','L','E','C','T',' ','`','M','e','s','s','a','g','e','`',' ',
1896 'F','R','O','M',' ','`','E','r','r','o','r','`',' ','W','H','E','R','E',' ',
1897 '`','E','r','r','o','r','`',' ','=',' ','%','i',0};
1901 if ((record
= MSI_QueryGetRecord(db
, query
, error
)))
1903 ret
= msi_dup_record_field(record
, 1);
1904 msiobj_release(&record
->hdr
);
1906 else if (error
< 2000)
1908 int len
= LoadStringW(msi_hInstance
, IDS_ERROR_BASE
+ error
, (LPWSTR
) &ret
, 0);
1911 ret
= msi_alloc((len
+ 1) * sizeof(WCHAR
));
1912 LoadStringW(msi_hInstance
, IDS_ERROR_BASE
+ error
, ret
, len
+ 1);
1921 INT
MSI_ProcessMessageVerbatim(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1923 LPWSTR message
= {0};
1925 DWORD log_type
= 1 << (eMessageType
>> 24);
1930 TRACE("%x\n", eMessageType
);
1931 if (TRACE_ON(msi
)) dump_record(record
);
1933 if (!package
|| !record
)
1936 res
= MSI_FormatRecordW(package
, record
, message
, &len
);
1937 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
1940 message
= msi_alloc(len
* sizeof(WCHAR
));
1941 if (!message
) return ERROR_OUTOFMEMORY
;
1942 MSI_FormatRecordW(package
, record
, message
, &len
);
1945 /* convert it to ASCII */
1946 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1947 msg
= msi_alloc( len
);
1948 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1950 if (gUIHandlerRecord
&& (gUIFilterRecord
& log_type
))
1952 MSIHANDLE rec
= alloc_msihandle(&record
->hdr
);
1953 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, hRecord=%u)\n",
1954 gUIHandlerRecord
, gUIContextRecord
, eMessageType
, rec
);
1955 rc
= gUIHandlerRecord( gUIContextRecord
, eMessageType
, rec
);
1956 MsiCloseHandle( rec
);
1958 if (!rc
&& gUIHandlerW
&& (gUIFilter
& log_type
))
1960 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1961 gUIHandlerW
, gUIContext
, eMessageType
, debugstr_w(message
));
1962 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1964 else if (!rc
&& gUIHandlerA
&& (gUIFilter
& log_type
))
1966 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1967 gUIHandlerA
, gUIContext
, eMessageType
, debugstr_a(msg
));
1968 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1972 rc
= internal_ui_handler(package
, eMessageType
, record
, message
);
1974 if (!rc
&& package
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1975 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1978 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1979 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1982 msi_free( message
);
1987 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1989 switch (eMessageType
& 0xff000000)
1991 case INSTALLMESSAGE_FATALEXIT
:
1992 case INSTALLMESSAGE_ERROR
:
1993 case INSTALLMESSAGE_WARNING
:
1994 case INSTALLMESSAGE_USER
:
1995 case INSTALLMESSAGE_INFO
:
1996 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1997 if (MSI_RecordGetInteger(record
, 1) != MSI_NULL_INTEGER
)
2002 LPWSTR template_rec
= NULL
, template_prefix
= NULL
;
2003 int error
= MSI_RecordGetInteger(record
, 1);
2005 if (MSI_RecordIsNull(record
, 0))
2009 template_rec
= msi_get_error_message(package
->db
, error
);
2011 if (!template_rec
&& error
>= 2000)
2013 /* internal error, not localized */
2014 if ((template_rec
= (LPWSTR
) get_internal_error_message(error
)))
2016 MSI_RecordSetStringW(record
, 0, template_rec
);
2017 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_INFO
, record
);
2019 template_rec
= msi_get_error_message(package
->db
, MSIERR_INSTALLERROR
);
2020 MSI_RecordSetStringW(record
, 0, template_rec
);
2021 MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
2022 msi_free(template_rec
);
2028 template_rec
= msi_dup_record_field(record
, 0);
2030 template_prefix
= msi_get_error_message(package
->db
, eMessageType
>> 24);
2031 if (!template_prefix
) template_prefix
= strdupW(szEmpty
);
2035 /* always returns 0 */
2036 MSI_RecordSetStringW(record
, 0, template_prefix
);
2037 MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
2038 msi_free(template_prefix
);
2042 template = msi_alloc((lstrlenW(template_rec
) + lstrlenW(template_prefix
) + 1) * sizeof(WCHAR
));
2043 if (!template) return ERROR_OUTOFMEMORY
;
2045 lstrcpyW(template, template_prefix
);
2046 lstrcatW(template, template_rec
);
2047 MSI_RecordSetStringW(record
, 0, template);
2049 msi_free(template_prefix
);
2050 msi_free(template_rec
);
2054 case INSTALLMESSAGE_ACTIONSTART
:
2056 WCHAR
*template = msi_get_error_message(package
->db
, MSIERR_ACTIONSTART
);
2057 MSI_RecordSetStringW(record
, 0, template);
2060 msi_free(package
->LastAction
);
2061 msi_free(package
->LastActionTemplate
);
2062 package
->LastAction
= msi_dup_record_field(record
, 1);
2063 if (!package
->LastAction
) package
->LastAction
= strdupW(szEmpty
);
2064 package
->LastActionTemplate
= msi_dup_record_field(record
, 3);
2067 case INSTALLMESSAGE_ACTIONDATA
:
2068 if (package
->LastAction
&& package
->LastActionTemplate
)
2070 static const WCHAR template_s
[] =
2071 {'{','{','%','s',':',' ','}','}','%','s',0};
2072 size_t len
= lstrlenW(package
->LastAction
) + lstrlenW(package
->LastActionTemplate
) + 7;
2073 WCHAR
*template = msi_alloc(len
* sizeof(WCHAR
));
2074 if (!template) return ERROR_OUTOFMEMORY
;
2075 swprintf(template, len
, template_s
, package
->LastAction
, package
->LastActionTemplate
);
2076 MSI_RecordSetStringW(record
, 0, template);
2080 case INSTALLMESSAGE_COMMONDATA
:
2082 WCHAR
*template = msi_get_error_message(package
->db
, MSIERR_COMMONDATA
);
2083 MSI_RecordSetStringW(record
, 0, template);
2089 return MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
2092 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
2095 UINT ret
= ERROR_INVALID_HANDLE
;
2096 MSIPACKAGE
*package
= NULL
;
2097 MSIRECORD
*record
= NULL
;
2099 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
||
2100 (eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
2103 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
&&
2104 MsiRecordGetInteger(hRecord
, 1) != 2)
2107 record
= msihandle2msiinfo(hRecord
, MSIHANDLETYPE_RECORD
);
2109 return ERROR_INVALID_HANDLE
;
2111 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2116 if (!(remote
= msi_get_remote(hInstall
)))
2117 return ERROR_INVALID_HANDLE
;
2121 ret
= remote_ProcessMessage(remote
, eMessageType
, (struct wire_record
*)&record
->count
);
2123 __EXCEPT(rpc_filter
)
2125 ret
= GetExceptionCode();
2129 msiobj_release(&record
->hdr
);
2133 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
2135 msiobj_release( &record
->hdr
);
2136 msiobj_release( &package
->hdr
);
2142 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
2144 LPWSTR szwName
= NULL
, szwValue
= NULL
;
2145 UINT r
= ERROR_OUTOFMEMORY
;
2147 szwName
= strdupAtoW( szName
);
2148 if( szName
&& !szwName
)
2151 szwValue
= strdupAtoW( szValue
);
2152 if( szValue
&& !szwValue
)
2155 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
2158 msi_free( szwName
);
2159 msi_free( szwValue
);
2164 void msi_reset_source_folders( MSIPACKAGE
*package
)
2168 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
2170 msi_free( folder
->ResolvedSource
);
2171 folder
->ResolvedSource
= NULL
;
2175 UINT
msi_set_property( MSIDATABASE
*db
, const WCHAR
*name
, const WCHAR
*value
, int len
)
2177 static const WCHAR insert_query
[] = {
2178 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2179 '`','_','P','r','o','p','e','r','t','y','`',' ',
2180 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2181 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2182 static const WCHAR update_query
[] = {
2183 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2184 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2185 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2186 static const WCHAR delete_query
[] = {
2187 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2188 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2189 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2191 MSIRECORD
*row
= NULL
;
2196 TRACE("%p %s %s %d\n", db
, debugstr_w(name
), debugstr_wn(value
, len
), len
);
2199 return ERROR_INVALID_PARAMETER
;
2201 /* this one is weird... */
2203 return value
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
2205 if (value
&& len
< 0) len
= lstrlenW( value
);
2207 rc
= msi_get_property( db
, name
, 0, &sz
);
2208 if (!value
|| (!*value
&& !len
))
2210 swprintf( query
, ARRAY_SIZE(query
), delete_query
, name
);
2212 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
2214 swprintf( query
, ARRAY_SIZE(query
), update_query
, name
);
2215 row
= MSI_CreateRecord(1);
2216 msi_record_set_string( row
, 1, value
, len
);
2220 lstrcpyW( query
, insert_query
);
2221 row
= MSI_CreateRecord(2);
2222 msi_record_set_string( row
, 1, name
, -1 );
2223 msi_record_set_string( row
, 2, value
, len
);
2226 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2227 if (rc
== ERROR_SUCCESS
)
2229 rc
= MSI_ViewExecute(view
, row
);
2230 MSI_ViewClose(view
);
2231 msiobj_release(&view
->hdr
);
2233 if (row
) msiobj_release(&row
->hdr
);
2237 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2239 MSIPACKAGE
*package
;
2242 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2247 if (!(remote
= msi_get_remote(hInstall
)))
2248 return ERROR_INVALID_HANDLE
;
2252 ret
= remote_SetProperty(remote
, szName
, szValue
);
2254 __EXCEPT(rpc_filter
)
2256 ret
= GetExceptionCode();
2263 ret
= msi_set_property( package
->db
, szName
, szValue
, -1 );
2264 if (ret
== ERROR_SUCCESS
&& !wcscmp( szName
, szSourceDir
))
2265 msi_reset_source_folders( package
);
2267 msiobj_release( &package
->hdr
);
2271 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2273 static const WCHAR query
[]= {
2274 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2275 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2276 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2277 MSIRECORD
*rec
, *row
= NULL
;
2281 static const WCHAR szDate
[] = {'D','a','t','e',0};
2282 static const WCHAR szTime
[] = {'T','i','m','e',0};
2286 if (!name
|| !*name
)
2289 if (!wcscmp(name
, szDate
))
2291 length
= GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, NULL
, 0);
2294 buffer
= msi_alloc(length
* sizeof(WCHAR
));
2295 GetDateFormatW(LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, NULL
, NULL
, buffer
, length
);
2297 row
= MSI_CreateRecord(1);
2303 MSI_RecordSetStringW(row
, 1, buffer
);
2307 else if (!wcscmp(name
, szTime
))
2309 length
= GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOTIMEMARKER
, NULL
, NULL
, NULL
, 0);
2312 buffer
= msi_alloc(length
* sizeof(WCHAR
));
2313 GetTimeFormatW(LOCALE_USER_DEFAULT
, TIME_NOTIMEMARKER
, NULL
, NULL
, buffer
, length
);
2315 row
= MSI_CreateRecord(1);
2321 MSI_RecordSetStringW(row
, 1, buffer
);
2326 rec
= MSI_CreateRecord(1);
2330 MSI_RecordSetStringW(rec
, 1, name
);
2332 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2333 if (r
== ERROR_SUCCESS
)
2335 MSI_ViewExecute(view
, rec
);
2336 MSI_ViewFetch(view
, &row
);
2337 MSI_ViewClose(view
);
2338 msiobj_release(&view
->hdr
);
2340 msiobj_release(&rec
->hdr
);
2344 /* internal function, not compatible with MsiGetPropertyW */
2345 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2346 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2349 UINT rc
= ERROR_FUNCTION_FAILED
;
2351 TRACE("%p %s %p %p\n", db
, debugstr_w(szName
), szValueBuf
, pchValueBuf
);
2353 row
= msi_get_property_row( db
, szName
);
2355 if (*pchValueBuf
> 0)
2360 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2361 msiobj_release(&row
->hdr
);
2364 if (rc
== ERROR_SUCCESS
)
2365 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf
, *pchValueBuf
),
2366 debugstr_w(szName
));
2367 else if (rc
== ERROR_MORE_DATA
)
2368 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2369 debugstr_w(szName
));
2373 TRACE("property %s not found\n", debugstr_w(szName
));
2379 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2385 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2386 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2390 str
= msi_alloc(sz
* sizeof(WCHAR
));
2391 r
= msi_get_property(db
, prop
, str
, &sz
);
2392 if (r
!= ERROR_SUCCESS
)
2401 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2403 LPWSTR str
= msi_dup_property( db
, prop
);
2404 int val
= str
? wcstol(str
, NULL
, 10) : def
;
2409 UINT WINAPI
MsiGetPropertyA(MSIHANDLE hinst
, const char *name
, char *buf
, DWORD
*sz
)
2411 const WCHAR
*value
= szEmpty
;
2412 MSIPACKAGE
*package
;
2419 return ERROR_INVALID_PARAMETER
;
2421 if (!(nameW
= strdupAtoW(name
)))
2422 return ERROR_OUTOFMEMORY
;
2424 package
= msihandle2msiinfo(hinst
, MSIHANDLETYPE_PACKAGE
);
2427 WCHAR
*value
= NULL
, *tmp
;
2431 if (!(remote
= msi_get_remote(hinst
)))
2434 return ERROR_INVALID_HANDLE
;
2439 r
= remote_GetProperty(remote
, nameW
, &value
, &len
);
2441 __EXCEPT(rpc_filter
)
2443 r
= GetExceptionCode();
2451 /* String might contain embedded nulls.
2452 * Native returns the correct size but truncates the string. */
2453 tmp
= heap_alloc_zero((len
+ 1) * sizeof(WCHAR
));
2456 midl_user_free(value
);
2457 return ERROR_OUTOFMEMORY
;
2459 lstrcpyW(tmp
, value
);
2461 r
= msi_strncpyWtoA(tmp
, len
, buf
, sz
, TRUE
);
2465 midl_user_free(value
);
2469 row
= msi_get_property_row(package
->db
, nameW
);
2471 value
= msi_record_get_string(row
, 1, &len
);
2473 r
= msi_strncpyWtoA(value
, len
, buf
, sz
, FALSE
);
2476 if (row
) msiobj_release(&row
->hdr
);
2477 msiobj_release(&package
->hdr
);
2481 UINT WINAPI
MsiGetPropertyW(MSIHANDLE hinst
, const WCHAR
*name
, WCHAR
*buf
, DWORD
*sz
)
2483 const WCHAR
*value
= szEmpty
;
2484 MSIPACKAGE
*package
;
2490 return ERROR_INVALID_PARAMETER
;
2492 package
= msihandle2msiinfo(hinst
, MSIHANDLETYPE_PACKAGE
);
2495 WCHAR
*value
= NULL
, *tmp
;
2499 if (!(remote
= msi_get_remote(hinst
)))
2500 return ERROR_INVALID_HANDLE
;
2504 r
= remote_GetProperty(remote
, name
, &value
, &len
);
2506 __EXCEPT(rpc_filter
)
2508 r
= GetExceptionCode();
2514 /* String might contain embedded nulls.
2515 * Native returns the correct size but truncates the string. */
2516 tmp
= heap_alloc_zero((len
+ 1) * sizeof(WCHAR
));
2519 midl_user_free(value
);
2520 return ERROR_OUTOFMEMORY
;
2522 lstrcpyW(tmp
, value
);
2524 r
= msi_strncpyW(tmp
, len
, buf
, sz
);
2528 midl_user_free(value
);
2532 row
= msi_get_property_row(package
->db
, name
);
2534 value
= msi_record_get_string(row
, 1, &len
);
2536 r
= msi_strncpyW(value
, len
, buf
, sz
);
2538 if (row
) msiobj_release(&row
->hdr
);
2539 msiobj_release(&package
->hdr
);
2543 MSIHANDLE __cdecl
s_remote_GetActiveDatabase(MSIHANDLE hinst
)
2545 return MsiGetActiveDatabase(hinst
);
2548 UINT __cdecl
s_remote_GetProperty(MSIHANDLE hinst
, LPCWSTR property
, LPWSTR
*value
, DWORD
*size
)
2554 r
= MsiGetPropertyW(hinst
, property
, empty
, size
);
2555 if (r
== ERROR_MORE_DATA
)
2558 *value
= midl_user_allocate(*size
* sizeof(WCHAR
));
2560 return ERROR_OUTOFMEMORY
;
2561 r
= MsiGetPropertyW(hinst
, property
, *value
, size
);
2566 UINT __cdecl
s_remote_SetProperty(MSIHANDLE hinst
, LPCWSTR property
, LPCWSTR value
)
2568 return MsiSetPropertyW(hinst
, property
, value
);
2571 int __cdecl
s_remote_ProcessMessage(MSIHANDLE hinst
, INSTALLMESSAGE message
, struct wire_record
*remote_rec
)
2577 if ((r
= unmarshal_record(remote_rec
, &rec
)))
2580 ret
= MsiProcessMessage(hinst
, message
, rec
);
2582 MsiCloseHandle(rec
);
2586 UINT __cdecl
s_remote_DoAction(MSIHANDLE hinst
, LPCWSTR action
)
2588 return MsiDoActionW(hinst
, action
);
2591 UINT __cdecl
s_remote_Sequence(MSIHANDLE hinst
, LPCWSTR table
, int sequence
)
2593 return MsiSequenceW(hinst
, table
, sequence
);
2596 UINT __cdecl
s_remote_GetTargetPath(MSIHANDLE hinst
, LPCWSTR folder
, LPWSTR
*value
)
2602 r
= MsiGetTargetPathW(hinst
, folder
, empty
, &size
);
2603 if (r
== ERROR_MORE_DATA
)
2605 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2607 return ERROR_OUTOFMEMORY
;
2608 r
= MsiGetTargetPathW(hinst
, folder
, *value
, &size
);
2613 UINT __cdecl
s_remote_SetTargetPath(MSIHANDLE hinst
, LPCWSTR folder
, LPCWSTR value
)
2615 return MsiSetTargetPathW(hinst
, folder
, value
);
2618 UINT __cdecl
s_remote_GetSourcePath(MSIHANDLE hinst
, LPCWSTR folder
, LPWSTR
*value
)
2624 r
= MsiGetSourcePathW(hinst
, folder
, empty
, &size
);
2625 if (r
== ERROR_MORE_DATA
)
2627 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2629 return ERROR_OUTOFMEMORY
;
2630 r
= MsiGetSourcePathW(hinst
, folder
, *value
, &size
);
2635 BOOL __cdecl
s_remote_GetMode(MSIHANDLE hinst
, MSIRUNMODE mode
)
2637 return MsiGetMode(hinst
, mode
);
2640 UINT __cdecl
s_remote_SetMode(MSIHANDLE hinst
, MSIRUNMODE mode
, BOOL state
)
2642 return MsiSetMode(hinst
, mode
, state
);
2645 UINT __cdecl
s_remote_GetFeatureState(MSIHANDLE hinst
, LPCWSTR feature
,
2646 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2648 return MsiGetFeatureStateW(hinst
, feature
, installed
, action
);
2651 UINT __cdecl
s_remote_SetFeatureState(MSIHANDLE hinst
, LPCWSTR feature
, INSTALLSTATE state
)
2653 return MsiSetFeatureStateW(hinst
, feature
, state
);
2656 UINT __cdecl
s_remote_GetComponentState(MSIHANDLE hinst
, LPCWSTR component
,
2657 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2659 return MsiGetComponentStateW(hinst
, component
, installed
, action
);
2662 UINT __cdecl
s_remote_SetComponentState(MSIHANDLE hinst
, LPCWSTR component
, INSTALLSTATE state
)
2664 return MsiSetComponentStateW(hinst
, component
, state
);
2667 LANGID __cdecl
s_remote_GetLanguage(MSIHANDLE hinst
)
2669 return MsiGetLanguage(hinst
);
2672 UINT __cdecl
s_remote_SetInstallLevel(MSIHANDLE hinst
, int level
)
2674 return MsiSetInstallLevel(hinst
, level
);
2677 UINT __cdecl
s_remote_FormatRecord(MSIHANDLE hinst
, struct wire_record
*remote_rec
, LPWSTR
*value
)
2684 if ((r
= unmarshal_record(remote_rec
, &rec
)))
2687 r
= MsiFormatRecordW(hinst
, rec
, empty
, &size
);
2688 if (r
== ERROR_MORE_DATA
)
2690 *value
= midl_user_allocate(++size
* sizeof(WCHAR
));
2693 MsiCloseHandle(rec
);
2694 return ERROR_OUTOFMEMORY
;
2696 r
= MsiFormatRecordW(hinst
, rec
, *value
, &size
);
2699 MsiCloseHandle(rec
);
2703 MSICONDITION __cdecl
s_remote_EvaluateCondition(MSIHANDLE hinst
, LPCWSTR condition
)
2705 return MsiEvaluateConditionW(hinst
, condition
);
2708 UINT __cdecl
s_remote_GetFeatureCost(MSIHANDLE hinst
, LPCWSTR feature
,
2709 MSICOSTTREE cost_tree
, INSTALLSTATE state
, INT
*cost
)
2711 return MsiGetFeatureCostW(hinst
, feature
, cost_tree
, state
, cost
);
2714 UINT __cdecl
s_remote_EnumComponentCosts(MSIHANDLE hinst
, LPCWSTR component
,
2715 DWORD index
, INSTALLSTATE state
, LPWSTR drive
, INT
*cost
, INT
*temp
)
2718 return MsiEnumComponentCostsW(hinst
, component
, index
, state
, drive
, &size
, cost
, temp
);
2721 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2722 LPCWSTR property
, LPWSTR value
)
2724 MSISOURCELISTINFO
*info
;
2726 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2728 if (!wcscmp( info
->value
, value
)) return ERROR_SUCCESS
;
2731 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2733 return ERROR_OUTOFMEMORY
;
2735 info
->context
= context
;
2736 info
->options
= options
;
2737 info
->property
= property
;
2738 info
->value
= strdupW(value
);
2739 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2741 return ERROR_SUCCESS
;
2744 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2745 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2749 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2751 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2754 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2756 return ERROR_OUTOFMEMORY
;
2758 disk
->context
= context
;
2759 disk
->options
= options
;
2760 disk
->disk_id
= disk_id
;
2761 disk
->volume_label
= strdupW(volume_label
);
2762 disk
->disk_prompt
= strdupW(disk_prompt
);
2763 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2765 return ERROR_SUCCESS
;