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
32 #include "wine/debug.h"
42 #include "wine/unicode.h"
48 #include "msiserver.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
52 static void remove_tracked_tempfiles( MSIPACKAGE
*package
)
54 struct list
*item
, *cursor
;
56 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->tempfiles
)
58 MSITEMPFILE
*temp
= LIST_ENTRY( item
, MSITEMPFILE
, entry
);
60 list_remove( &temp
->entry
);
61 TRACE("deleting temp file %s\n", debugstr_w( temp
->Path
));
62 if (!DeleteFileW( temp
->Path
))
63 ERR("failed to delete %s\n", debugstr_w( temp
->Path
));
64 msi_free( temp
->Path
);
69 static void free_feature( MSIFEATURE
*feature
)
71 struct list
*item
, *cursor
;
73 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
75 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
76 list_remove( &fl
->entry
);
80 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
82 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
83 list_remove( &cl
->entry
);
86 msi_free( feature
->Feature
);
87 msi_free( feature
->Feature_Parent
);
88 msi_free( feature
->Directory
);
89 msi_free( feature
->Description
);
90 msi_free( feature
->Title
);
94 static void free_extension( MSIEXTENSION
*ext
)
96 struct list
*item
, *cursor
;
98 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
100 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
102 list_remove( &verb
->entry
);
103 msi_free( verb
->Verb
);
104 msi_free( verb
->Command
);
105 msi_free( verb
->Argument
);
109 msi_free( ext
->Extension
);
110 msi_free( ext
->ProgIDText
);
114 static void free_assembly( MSIASSEMBLY
*assembly
)
116 msi_free( assembly
->display_name
);
117 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
118 msi_free( assembly
->tempdir
);
119 msi_free( assembly
);
122 static void free_package_structures( MSIPACKAGE
*package
)
125 struct list
*item
, *cursor
;
127 TRACE("Freeing package action data\n");
129 remove_tracked_tempfiles(package
);
131 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
133 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
134 list_remove( &feature
->entry
);
135 free_feature( feature
);
138 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
140 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
142 list_remove( &folder
->entry
);
143 msi_free( folder
->Parent
);
144 msi_free( folder
->Directory
);
145 msi_free( folder
->TargetDefault
);
146 msi_free( folder
->SourceLongPath
);
147 msi_free( folder
->SourceShortPath
);
148 msi_free( folder
->ResolvedTarget
);
149 msi_free( folder
->ResolvedSource
);
150 msi_free( folder
->Property
);
154 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
156 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
158 list_remove( &comp
->entry
);
159 msi_free( comp
->Component
);
160 msi_free( comp
->ComponentId
);
161 msi_free( comp
->Directory
);
162 msi_free( comp
->Condition
);
163 msi_free( comp
->KeyPath
);
164 msi_free( comp
->FullKeypath
);
165 if (comp
->assembly
) free_assembly( comp
->assembly
);
169 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
171 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
173 list_remove( &file
->entry
);
174 msi_free( file
->File
);
175 msi_free( file
->FileName
);
176 msi_free( file
->ShortName
);
177 msi_free( file
->LongName
);
178 msi_free( file
->Version
);
179 msi_free( file
->Language
);
180 msi_free( file
->TargetPath
);
184 /* clean up extension, progid, class and verb structures */
185 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
187 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
189 list_remove( &cls
->entry
);
190 msi_free( cls
->clsid
);
191 msi_free( cls
->Context
);
192 msi_free( cls
->Description
);
193 msi_free( cls
->FileTypeMask
);
194 msi_free( cls
->IconPath
);
195 msi_free( cls
->DefInprocHandler
);
196 msi_free( cls
->DefInprocHandler32
);
197 msi_free( cls
->Argument
);
198 msi_free( cls
->ProgIDText
);
202 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
204 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
206 list_remove( &ext
->entry
);
207 free_extension( ext
);
210 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
212 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
214 list_remove( &progid
->entry
);
215 msi_free( progid
->ProgID
);
216 msi_free( progid
->Description
);
217 msi_free( progid
->IconPath
);
221 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
223 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
225 list_remove( &mt
->entry
);
226 msi_free( mt
->suffix
);
227 msi_free( mt
->clsid
);
228 msi_free( mt
->ContentType
);
232 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
234 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
236 list_remove( &appid
->entry
);
237 msi_free( appid
->AppID
);
238 msi_free( appid
->RemoteServerName
);
239 msi_free( appid
->LocalServer
);
240 msi_free( appid
->ServiceParameters
);
241 msi_free( appid
->DllSurrogate
);
245 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
247 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
249 list_remove( &info
->entry
);
250 msi_free( info
->value
);
254 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
256 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
258 list_remove( &info
->entry
);
259 msi_free( info
->volume_label
);
260 msi_free( info
->disk_prompt
);
266 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
267 msi_free_action_script( package
, i
);
269 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
270 msi_free( package
->script
->UniqueActions
[i
] );
272 msi_free( package
->script
->UniqueActions
);
273 msi_free( package
->script
);
276 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
278 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
280 list_remove( &patch
->entry
);
281 msi_free( patch
->patchcode
);
282 msi_free( patch
->transforms
);
283 msi_free( patch
->localfile
);
287 msi_free( package
->BaseURL
);
288 msi_free( package
->PackagePath
);
289 msi_free( package
->ProductCode
);
290 msi_free( package
->ActionFormat
);
291 msi_free( package
->LastAction
);
292 msi_free( package
->langids
);
294 /* cleanup control event subscriptions */
295 ControlEvent_CleanupSubscriptions( package
);
298 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
300 MSIPACKAGE
*package
= (MSIPACKAGE
*) arg
;
302 if( package
->dialog
)
303 msi_dialog_destroy( package
->dialog
);
305 msiobj_release( &package
->db
->hdr
);
306 free_package_structures(package
);
307 CloseHandle( package
->log_file
);
309 if (package
->cache_net
) IAssemblyCache_Release( package
->cache_net
);
310 if (package
->cache_sxs
) IAssemblyCache_Release( package
->cache_sxs
);
313 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
315 MSIQUERY
*view
= NULL
;
318 static const WCHAR CreateSql
[] = {
319 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
320 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
321 '`','_','P','r','o','p','e','r','t','y','`',' ',
322 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
323 'T','E','M','P','O','R','A','R','Y',',',' ',
324 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
325 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
326 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
327 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
329 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &view
);
330 if (rc
!= ERROR_SUCCESS
)
333 rc
= MSI_ViewExecute(view
, 0);
335 msiobj_release(&view
->hdr
);
339 UINT
msi_clone_properties(MSIPACKAGE
*package
)
341 MSIQUERY
*view_select
= NULL
;
344 static const WCHAR query_select
[] = {
345 'S','E','L','E','C','T',' ','*',' ',
346 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
347 static const WCHAR query_insert
[] = {
348 'I','N','S','E','R','T',' ','i','n','t','o',' ',
349 '`','_','P','r','o','p','e','r','t','y','`',' ',
350 '(','`','_','P','r','o','p','e','r','t','y','`',',',
351 '`','V','a','l','u','e','`',')',' ',
352 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
353 static const WCHAR query_update
[] = {
354 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
355 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
356 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
358 rc
= MSI_DatabaseOpenViewW( package
->db
, query_select
, &view_select
);
359 if (rc
!= ERROR_SUCCESS
)
362 rc
= MSI_ViewExecute( view_select
, 0 );
363 if (rc
!= ERROR_SUCCESS
)
365 MSI_ViewClose( view_select
);
366 msiobj_release( &view_select
->hdr
);
372 MSIQUERY
*view_insert
, *view_update
;
373 MSIRECORD
*rec_select
;
375 rc
= MSI_ViewFetch( view_select
, &rec_select
);
376 if (rc
!= ERROR_SUCCESS
)
379 rc
= MSI_DatabaseOpenViewW( package
->db
, query_insert
, &view_insert
);
380 if (rc
!= ERROR_SUCCESS
)
382 msiobj_release( &rec_select
->hdr
);
386 rc
= MSI_ViewExecute( view_insert
, rec_select
);
387 MSI_ViewClose( view_insert
);
388 msiobj_release( &view_insert
->hdr
);
389 if (rc
!= ERROR_SUCCESS
)
391 MSIRECORD
*rec_update
;
393 TRACE("insert failed, trying update\n");
395 rc
= MSI_DatabaseOpenViewW( package
->db
, query_update
, &view_update
);
396 if (rc
!= ERROR_SUCCESS
)
398 WARN("open view failed %u\n", rc
);
399 msiobj_release( &rec_select
->hdr
);
403 rec_update
= MSI_CreateRecord( 2 );
404 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
405 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
406 rc
= MSI_ViewExecute( view_update
, rec_update
);
407 if (rc
!= ERROR_SUCCESS
)
408 WARN("update failed %u\n", rc
);
410 MSI_ViewClose( view_update
);
411 msiobj_release( &view_update
->hdr
);
412 msiobj_release( &rec_update
->hdr
);
415 msiobj_release( &rec_select
->hdr
);
418 MSI_ViewClose( view_select
);
419 msiobj_release( &view_select
->hdr
);
426 * Sets the "Installed" property to indicate that
427 * the product is installed for the current user.
429 static UINT
set_installed_prop( MSIPACKAGE
*package
)
434 r
= MSIREG_OpenUninstallKey( package
, &hkey
, FALSE
);
435 if (r
== ERROR_SUCCESS
)
438 msi_set_property( package
->db
, szInstalled
, szOne
);
444 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
448 LPWSTR sid_str
= NULL
, dom
= NULL
;
449 DWORD size
, dom_size
;
451 UINT r
= ERROR_FUNCTION_FAILED
;
454 GetUserNameW( NULL
, &size
);
456 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
458 return ERROR_OUTOFMEMORY
;
460 if (!GetUserNameW( user_name
, &size
))
465 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
467 psid
= msi_alloc( size
);
468 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
471 r
= ERROR_OUTOFMEMORY
;
475 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
478 if (!ConvertSidToStringSidW( psid
, &sid_str
))
481 r
= msi_set_property( package
->db
, szUserSID
, sid_str
);
484 LocalFree( sid_str
);
487 msi_free( user_name
);
492 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
497 DWORD index
= 0, size
;
499 WCHAR name
[MAX_PATH
];
500 WCHAR windir
[MAX_PATH
];
502 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
503 static const WCHAR sub
[] = {
504 'S','o','f','t','w','a','r','e','\\',
505 'M','i','c','r','o','s','o','f','t','\\',
506 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
509 static const WCHAR subdir
[] = {
510 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
511 'F','r','a','m','e','w','o','r','k','\\',0
514 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
515 if (res
!= ERROR_SUCCESS
)
518 GetWindowsDirectoryW(windir
, MAX_PATH
);
522 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
526 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
527 if (strcmpW( ver
, name
) < 0)
530 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
531 check
= msi_alloc(size
* sizeof(WCHAR
));
539 lstrcpyW(check
, windir
);
540 lstrcatW(check
, szBackSlash
);
541 lstrcatW(check
, subdir
);
542 lstrcatW(check
, name
);
543 lstrcatW(check
, szBackSlash
);
544 lstrcatW(check
, fusion
);
546 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
557 RegCloseKey(netsetup
);
561 typedef struct tagLANGANDCODEPAGE
567 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
571 LPVOID version
= NULL
;
573 LPWSTR fusion
, verstr
;
574 LANGANDCODEPAGE
*translate
;
576 static const WCHAR netasm
[] = {
577 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
579 static const WCHAR translation
[] = {
580 '\\','V','a','r','F','i','l','e','I','n','f','o',
581 '\\','T','r','a','n','s','l','a','t','i','o','n',0
583 static const WCHAR verfmt
[] = {
584 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
585 '\\','%','0','4','x','%','0','4','x',
586 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
589 fusion
= get_fusion_filename(package
);
593 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
596 version
= msi_alloc(size
);
597 if (!version
) return;
599 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
602 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
605 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
607 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
610 if (!val_len
|| !verstr
)
613 msi_set_property(package
->db
, netasm
, verstr
);
620 static VOID
set_installer_properties(MSIPACKAGE
*package
)
624 OSVERSIONINFOEXW OSVersion
;
627 WCHAR verstr
[10], bufstr
[20];
630 LPWSTR username
, companyname
;
631 SYSTEM_INFO sys_info
;
632 SYSTEMTIME systemtime
;
635 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
636 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
637 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
638 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
639 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
640 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
641 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
642 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
643 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
644 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
645 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
646 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
647 static const WCHAR szAppDataFolder
[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
648 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
649 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
650 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
651 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
652 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
653 static const WCHAR szWindowsFolder
[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
654 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
655 static const WCHAR szTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
656 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
657 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
658 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
659 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
660 static const WCHAR szFormat
[] = {'%','l','i',0};
661 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
662 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
663 static const WCHAR szSix
[] = {'6',0 };
664 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
665 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
666 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
667 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
668 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
669 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
670 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
671 static const WCHAR szIntFormat
[] = {'%','d',0};
672 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
673 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
674 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
675 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
676 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 };
677 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
678 static const WCHAR szUserInfo
[] = {
679 'S','O','F','T','W','A','R','E','\\',
680 'M','i','c','r','o','s','o','f','t','\\',
681 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
682 'U','s','e','r',' ','I','n','f','o',0
684 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
685 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
686 static const WCHAR szCurrentVersion
[] = {
687 'S','O','F','T','W','A','R','E','\\',
688 'M','i','c','r','o','s','o','f','t','\\',
689 'W','i','n','d','o','w','s',' ','N','T','\\',
690 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
692 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
693 static const WCHAR szRegisteredOrganization
[] = {
694 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
696 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
697 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
698 static const WCHAR szDate
[] = {'D','a','t','e',0};
699 static const WCHAR szTime
[] = {'T','i','m','e',0};
700 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
701 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
702 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
703 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
704 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
705 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
706 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
709 * Other things that probably should be set:
711 * ComputerName VirtualMemory
712 * ShellAdvSupport DefaultUIFont PackagecodeChanging
713 * CaptionHeight BorderTop BorderSide TextHeight
714 * RedirectedDllSupport
717 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
718 strcatW(pth
, szBackSlash
);
719 msi_set_property(package
->db
, szCommonAppDataFolder
, pth
);
721 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
722 strcatW(pth
, szBackSlash
);
723 msi_set_property(package
->db
, szFavoritesFolder
, pth
);
725 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
726 strcatW(pth
, szBackSlash
);
727 msi_set_property(package
->db
, szFontsFolder
, pth
);
729 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
730 strcatW(pth
, szBackSlash
);
731 msi_set_property(package
->db
, szSendToFolder
, pth
);
733 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
734 strcatW(pth
, szBackSlash
);
735 msi_set_property(package
->db
, szStartMenuFolder
, pth
);
737 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
738 strcatW(pth
, szBackSlash
);
739 msi_set_property(package
->db
, szStartupFolder
, pth
);
741 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
742 strcatW(pth
, szBackSlash
);
743 msi_set_property(package
->db
, szTemplateFolder
, pth
);
745 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
746 strcatW(pth
, szBackSlash
);
747 msi_set_property(package
->db
, szDesktopFolder
, pth
);
749 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
750 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
751 strcatW(pth
, szBackSlash
);
752 msi_set_property(package
->db
, szProgramMenuFolder
, pth
);
754 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
755 strcatW(pth
, szBackSlash
);
756 msi_set_property(package
->db
, szAdminToolsFolder
, pth
);
758 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
759 strcatW(pth
, szBackSlash
);
760 msi_set_property(package
->db
, szAppDataFolder
, pth
);
762 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
763 strcatW(pth
, szBackSlash
);
764 msi_set_property(package
->db
, szSystemFolder
, pth
);
765 msi_set_property(package
->db
, szSystem16Folder
, pth
);
767 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
768 strcatW(pth
, szBackSlash
);
769 msi_set_property(package
->db
, szLocalAppDataFolder
, pth
);
771 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
772 strcatW(pth
, szBackSlash
);
773 msi_set_property(package
->db
, szMyPicturesFolder
, pth
);
775 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
776 strcatW(pth
, szBackSlash
);
777 msi_set_property(package
->db
, szPersonalFolder
, pth
);
779 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
780 strcatW(pth
, szBackSlash
);
781 msi_set_property(package
->db
, szWindowsFolder
, pth
);
783 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
784 strcatW(pth
, szBackSlash
);
785 msi_set_property(package
->db
, szPrintHoodFolder
, pth
);
787 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
788 strcatW(pth
, szBackSlash
);
789 msi_set_property(package
->db
, szNetHoodFolder
, pth
);
791 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
792 strcatW(pth
, szBackSlash
);
793 msi_set_property(package
->db
, szRecentFolder
, pth
);
795 /* Physical Memory is specified in MB. Using total amount. */
796 msex
.dwLength
= sizeof(msex
);
797 GlobalMemoryStatusEx( &msex
);
798 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
799 msi_set_property(package
->db
, szPhysicalMemory
, bufstr
);
801 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
802 ptr
= strchrW(pth
,'\\');
803 if (ptr
) *(ptr
+ 1) = 0;
804 msi_set_property(package
->db
, szWindowsVolume
, pth
);
806 GetTempPathW(MAX_PATH
,pth
);
807 msi_set_property(package
->db
, szTempFolder
, pth
);
809 /* in a wine environment the user is always admin and privileged */
810 msi_set_property(package
->db
, szAdminUser
, szOne
);
811 msi_set_property(package
->db
, szPrivileged
, szOne
);
813 /* set the os things */
814 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
815 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
816 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
817 sprintfW(verstr
, szFormat
, verval
);
818 switch (OSVersion
.dwPlatformId
)
820 case VER_PLATFORM_WIN32_WINDOWS
:
821 msi_set_property(package
->db
, szVersion9x
, verstr
);
823 case VER_PLATFORM_WIN32_NT
:
824 msi_set_property(package
->db
, szVersionNT
, verstr
);
825 sprintfW(verstr
, szFormat
,OSVersion
.wProductType
);
826 msi_set_property(package
->db
, szMsiNTProductType
, verstr
);
829 sprintfW(verstr
, szFormat
, OSVersion
.dwBuildNumber
);
830 msi_set_property(package
->db
, szWindowsBuild
, verstr
);
831 /* just fudge this */
832 msi_set_property(package
->db
, szServicePackLevel
, szSix
);
834 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
835 msi_set_property( package
->db
, szVersionMsi
, bufstr
);
836 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
837 msi_set_property( package
->db
, szVersionDatabase
, bufstr
);
839 GetNativeSystemInfo( &sys_info
);
840 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
841 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
843 msi_set_property( package
->db
, szIntel
, bufstr
);
845 GetSystemDirectoryW( pth
, MAX_PATH
);
846 PathAddBackslashW( pth
);
847 msi_set_property( package
->db
, szSystemFolder
, pth
);
849 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
850 PathAddBackslashW( pth
);
851 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
853 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
854 PathAddBackslashW( pth
);
855 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
857 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
859 msi_set_property( package
->db
, szMsiAMD64
, bufstr
);
860 msi_set_property( package
->db
, szMsix64
, bufstr
);
861 msi_set_property( package
->db
, szVersionNT64
, verstr
);
863 GetSystemDirectoryW( pth
, MAX_PATH
);
864 PathAddBackslashW( pth
);
865 msi_set_property( package
->db
, szSystem64Folder
, pth
);
867 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
868 PathAddBackslashW( pth
);
869 msi_set_property( package
->db
, szSystemFolder
, pth
);
871 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
872 PathAddBackslashW( pth
);
873 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
);
875 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
876 PathAddBackslashW( pth
);
877 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
879 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
880 PathAddBackslashW( pth
);
881 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
);
883 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
884 PathAddBackslashW( pth
);
885 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
888 /* Screen properties. */
890 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
891 msi_set_property( package
->db
, szScreenX
, bufstr
);
892 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
893 msi_set_property( package
->db
, szScreenY
, bufstr
);
894 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
895 msi_set_property( package
->db
, szColorBits
, bufstr
);
898 /* USERNAME and COMPANYNAME */
899 username
= msi_dup_property( package
->db
, szUSERNAME
);
900 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
902 if ((!username
|| !companyname
) &&
903 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
906 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
907 msi_set_property( package
->db
, szUSERNAME
, username
);
909 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
910 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
913 if ((!username
|| !companyname
) &&
914 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
917 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
918 msi_set_property( package
->db
, szUSERNAME
, username
);
920 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
921 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
924 msi_free( username
);
925 msi_free( companyname
);
927 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
928 ERR("Failed to set the UserSID property\n");
930 /* Date and time properties */
931 GetSystemTime( &systemtime
);
932 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
933 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
934 msi_set_property( package
->db
, szDate
, bufstr
);
936 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
938 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
939 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
940 &systemtime
, NULL
, bufstr
,
941 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
942 msi_set_property( package
->db
, szTime
, bufstr
);
944 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
946 set_msi_assembly_prop( package
);
948 langid
= GetUserDefaultLangID();
949 sprintfW(bufstr
, szIntFormat
, langid
);
950 msi_set_property( package
->db
, szUserLanguageID
, bufstr
);
952 langid
= GetSystemDefaultLangID();
953 sprintfW(bufstr
, szIntFormat
, langid
);
954 msi_set_property( package
->db
, szSystemLangID
, bufstr
);
956 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
957 msi_set_property( package
->db
, szProductState
, bufstr
);
960 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_MORE_DATA
)
963 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
965 if (GetUserNameW( username
, &len
))
966 msi_set_property( package
->db
, szLogonUser
, username
);
967 msi_free( username
);
972 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
976 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
980 static const WCHAR szPackageCode
[] = {
981 'P','a','c','k','a','g','e','C','o','d','e',0};
984 ERR("Unable to allocate handle\n");
985 return ERROR_OUTOFMEMORY
;
988 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
990 if (rc
!= ERROR_SUCCESS
)
992 ERR("Unable to open Summary Information\n");
996 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
997 &count
, NULL
, NULL
, NULL
);
998 if (rc
!= ERROR_SUCCESS
)
1000 WARN("Unable to query page count: %d\n", rc
);
1004 /* load package code property */
1006 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1007 NULL
, NULL
, NULL
, &len
);
1008 if (rc
!= ERROR_MORE_DATA
)
1010 WARN("Unable to query revision number: %d\n", rc
);
1011 rc
= ERROR_FUNCTION_FAILED
;
1016 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
1017 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1018 NULL
, NULL
, package_code
, &len
);
1019 if (rc
!= ERROR_SUCCESS
)
1021 WARN("Unable to query rev number: %d\n", rc
);
1025 msi_set_property( package
->db
, szPackageCode
, package_code
);
1026 msi_free( package_code
);
1028 /* load package attributes */
1030 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
1031 &count
, NULL
, NULL
, NULL
);
1032 package
->WordCount
= count
;
1035 MsiCloseHandle(suminfo
);
1039 static MSIPACKAGE
*msi_alloc_package( void )
1041 MSIPACKAGE
*package
;
1043 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1047 list_init( &package
->components
);
1048 list_init( &package
->features
);
1049 list_init( &package
->files
);
1050 list_init( &package
->tempfiles
);
1051 list_init( &package
->folders
);
1052 list_init( &package
->subscriptions
);
1053 list_init( &package
->appids
);
1054 list_init( &package
->classes
);
1055 list_init( &package
->mimes
);
1056 list_init( &package
->extensions
);
1057 list_init( &package
->progids
);
1058 list_init( &package
->RunningActions
);
1059 list_init( &package
->sourcelist_info
);
1060 list_init( &package
->sourcelist_media
);
1061 list_init( &package
->patches
);
1067 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1072 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1074 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1075 if (r
!= ERROR_SUCCESS
)
1078 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1084 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1086 /* FIXME: this should depend on the user's privileges */
1087 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1089 TRACE("resetting ALLUSERS property from 2 to 1\n");
1090 msi_set_property( package
->db
, szAllUsers
, szOne
);
1092 msi_set_property( package
->db
, szAdminUser
, szOne
);
1095 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1097 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
1098 static const WCHAR szpi
[] = {'%','i',0};
1099 MSIPACKAGE
*package
;
1105 package
= msi_alloc_package();
1108 msiobj_addref( &db
->hdr
);
1111 package
->WordCount
= 0;
1112 package
->PackagePath
= strdupW( db
->path
);
1113 package
->BaseURL
= strdupW( base_url
);
1115 create_temp_property_table( package
);
1116 msi_clone_properties( package
);
1117 msi_adjust_privilege_properties( package
);
1119 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1120 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1122 set_installed_prop( package
);
1123 set_installer_properties( package
);
1125 sprintfW(uilevel
,szpi
,gUILevel
);
1126 msi_set_property(package
->db
, szLevel
, uilevel
);
1128 r
= msi_load_summary_properties( package
);
1129 if (r
!= ERROR_SUCCESS
)
1131 msiobj_release( &package
->hdr
);
1135 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1136 msi_load_admin_properties( package
);
1138 package
->log_file
= INVALID_HANDLE_VALUE
;
1145 * copy_package_to_temp [internal]
1147 * copy the msi file to a temp file to prevent locking a CD
1148 * with a multi disc install
1150 * FIXME: I think this is wrong, and instead of copying the package,
1151 * we should read all the tables to memory, then open the
1152 * database to read binary streams on demand.
1154 static UINT
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
1156 WCHAR path
[MAX_PATH
];
1158 GetTempPathW( MAX_PATH
, path
);
1159 GetTempFileNameW( path
, szMsi
, 0, filename
);
1161 if( !CopyFileW( szPackage
, filename
, FALSE
) )
1163 UINT error
= GetLastError();
1164 if ( error
== ERROR_FILE_NOT_FOUND
)
1165 ERR("can't find %s\n", debugstr_w(szPackage
));
1167 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage
), debugstr_w(filename
), error
);
1168 DeleteFileW( filename
);
1172 return ERROR_SUCCESS
;
1175 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1177 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1181 /* call will always fail, becase size is 0,
1182 * but will return ERROR_FILE_NOT_FOUND first
1183 * if the file doesn't exist
1185 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1186 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1188 cache_entry
= msi_alloc( size
);
1189 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1191 UINT error
= GetLastError();
1192 msi_free( cache_entry
);
1196 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1197 msi_free( cache_entry
);
1198 return ERROR_SUCCESS
;
1201 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1204 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1205 return ERROR_FUNCTION_FAILED
;
1208 return ERROR_SUCCESS
;
1211 UINT
msi_get_local_package_name( LPWSTR path
, LPCWSTR suffix
)
1213 static const WCHAR szInstaller
[] = {
1214 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1215 static const WCHAR fmt
[] = {'%','x',0};
1216 DWORD time
, len
, i
, offset
;
1219 time
= GetTickCount();
1220 GetWindowsDirectoryW( path
, MAX_PATH
);
1221 strcatW( path
, szInstaller
);
1222 CreateDirectoryW( path
, NULL
);
1224 len
= strlenW(path
);
1225 for (i
= 0; i
< 0x10000; i
++)
1227 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1228 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1229 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1230 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1231 if (handle
!= INVALID_HANDLE_VALUE
)
1233 CloseHandle(handle
);
1236 if (GetLastError() != ERROR_FILE_EXISTS
&&
1237 GetLastError() != ERROR_SHARING_VIOLATION
)
1238 return ERROR_FUNCTION_FAILED
;
1241 return ERROR_SUCCESS
;
1244 static UINT
apply_registered_patch( MSIPACKAGE
*package
, LPCWSTR patch_code
)
1248 WCHAR patch_file
[MAX_PATH
];
1249 MSIDATABASE
*patch_db
;
1250 MSIPATCHINFO
*patch_info
;
1253 len
= sizeof(patch_file
) / sizeof(WCHAR
);
1254 r
= MsiGetPatchInfoExW( patch_code
, package
->ProductCode
, NULL
, package
->Context
,
1255 INSTALLPROPERTY_LOCALPACKAGEW
, patch_file
, &len
);
1256 if (r
!= ERROR_SUCCESS
)
1258 ERR("failed to get patch filename %u\n", r
);
1262 r
= MSI_OpenDatabaseW( patch_file
, MSIDBOPEN_READONLY
+ MSIDBOPEN_PATCHFILE
, &patch_db
);
1263 if (r
!= ERROR_SUCCESS
)
1265 ERR("failed to open patch database %s\n", debugstr_w( patch_file
));
1269 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
1272 msiobj_release( &patch_db
->hdr
);
1273 return ERROR_FUNCTION_FAILED
;
1276 r
= msi_parse_patch_summary( si
, &patch_info
);
1277 msiobj_release( &si
->hdr
);
1278 if (r
!= ERROR_SUCCESS
)
1280 ERR("failed to parse patch summary %u\n", r
);
1281 msiobj_release( &patch_db
->hdr
);
1285 patch_info
->localfile
= strdupW( patch_file
);
1286 if (!patch_info
->localfile
)
1288 msiobj_release( &patch_db
->hdr
);
1289 return ERROR_OUTOFMEMORY
;
1292 r
= msi_apply_patch_db( package
, patch_db
, patch_info
);
1293 msiobj_release( &patch_db
->hdr
);
1294 if (r
!= ERROR_SUCCESS
)
1296 ERR("failed to apply patch %u\n", r
);
1297 msi_free( patch_info
->patchcode
);
1298 msi_free( patch_info
->transforms
);
1299 msi_free( patch_info
->localfile
);
1300 msi_free( patch_info
);
1305 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1307 WCHAR
*template, *p
, *q
;
1310 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1311 TRACE("version: %d\n", package
->version
);
1313 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1315 return ERROR_SUCCESS
; /* native accepts missing template property */
1317 TRACE("template: %s\n", debugstr_w(template));
1319 p
= strchrW( template, ';' );
1322 WARN("invalid template string %s\n", debugstr_w(template));
1323 msi_free( template );
1324 return ERROR_PATCH_PACKAGE_INVALID
;
1327 if (!template[0] || !strcmpW( template, szIntel
))
1328 package
->platform
= PLATFORM_INTEL
;
1329 else if (!strcmpW( template, szIntel64
))
1330 package
->platform
= PLATFORM_INTEL64
;
1331 else if (!strcmpW( template, szX64
))
1332 package
->platform
= PLATFORM_X64
;
1335 WARN("unknown platform %s\n", debugstr_w(template));
1336 msi_free( template );
1337 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1341 for (q
= ++p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1343 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1344 if (!package
->langids
)
1346 msi_free( template );
1347 return ERROR_OUTOFMEMORY
;
1353 q
= strchrW( p
, ',' );
1355 package
->langids
[i
] = atoiW( p
);
1360 package
->num_langids
= i
+ 1;
1362 msi_free( template );
1363 return ERROR_SUCCESS
;
1366 static UINT
validate_package( MSIPACKAGE
*package
)
1371 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1372 if (package
->platform
== PLATFORM_X64
)
1374 if (!is_64bit
&& !is_wow64
)
1375 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1376 if (package
->version
< 200)
1377 return ERROR_INSTALL_PACKAGE_INVALID
;
1379 if (!package
->num_langids
)
1381 return ERROR_SUCCESS
;
1383 for (i
= 0; i
< package
->num_langids
; i
++)
1385 if (!package
->langids
[i
] || IsValidLocale( package
->langids
[i
], LCID_INSTALLED
))
1386 return ERROR_SUCCESS
;
1388 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1391 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1393 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
1394 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1395 MSIDATABASE
*db
= NULL
;
1396 MSIPACKAGE
*package
;
1398 LPWSTR ptr
, base_url
= NULL
;
1400 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1401 LPCWSTR file
= szPackage
;
1405 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1407 if( szPackage
[0] == '#' )
1409 handle
= atoiW(&szPackage
[1]);
1410 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1413 IWineMsiRemoteDatabase
*remote_database
;
1415 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1416 if ( !remote_database
)
1417 return ERROR_INVALID_HANDLE
;
1419 IWineMsiRemoteDatabase_Release( remote_database
);
1420 WARN("MsiOpenPackage not allowed during a custom action!\n");
1422 return ERROR_FUNCTION_FAILED
;
1427 if ( UrlIsW( szPackage
, URLIS_URL
) )
1429 r
= msi_download_file( szPackage
, cachefile
);
1430 if ( r
!= ERROR_SUCCESS
)
1433 r
= copy_package_to_temp( cachefile
, temppath
);
1434 if ( r
!= ERROR_SUCCESS
)
1439 base_url
= strdupW( szPackage
);
1441 return ERROR_OUTOFMEMORY
;
1443 ptr
= strrchrW( base_url
, '/' );
1444 if (ptr
) *(ptr
+ 1) = '\0';
1448 r
= copy_package_to_temp( szPackage
, temppath
);
1449 if ( r
!= ERROR_SUCCESS
)
1455 r
= msi_get_local_package_name( localfile
, dotmsi
);
1456 if (r
!= ERROR_SUCCESS
)
1459 TRACE("Copying to local package %s\n", debugstr_w(localfile
));
1461 if (!CopyFileW( file
, localfile
, FALSE
))
1463 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1464 debugstr_w(file
), debugstr_w(localfile
), GetLastError());
1465 return GetLastError();
1468 TRACE("Opening relocated package %s\n", debugstr_w( file
));
1470 /* transforms that add binary streams require that we open the database
1471 * read/write, which is safe because we always create a copy that is thrown
1472 * away when we're done.
1474 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_TRANSACT
, &db
);
1475 if( r
!= ERROR_SUCCESS
)
1477 if (file
!= szPackage
)
1478 DeleteFileW( file
);
1480 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
1481 return ERROR_FILE_NOT_FOUND
;
1486 db
->localfile
= strdupW( localfile
);
1489 package
= MSI_CreatePackage( db
, base_url
);
1490 msi_free( base_url
);
1491 msiobj_release( &db
->hdr
);
1494 if (file
!= szPackage
)
1495 DeleteFileW( file
);
1497 return ERROR_INSTALL_PACKAGE_INVALID
;
1500 if( file
!= szPackage
)
1501 track_tempfile( package
, file
);
1503 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1506 WARN("failed to load summary info %u\n", r
);
1507 msiobj_release( &package
->hdr
);
1508 return ERROR_INSTALL_PACKAGE_INVALID
;
1511 r
= msi_parse_summary( si
, package
);
1512 msiobj_release( &si
->hdr
);
1513 if (r
!= ERROR_SUCCESS
)
1515 WARN("failed to parse summary info %u\n", r
);
1516 msiobj_release( &package
->hdr
);
1520 r
= validate_package( package
);
1521 if (r
!= ERROR_SUCCESS
)
1523 msiobj_release( &package
->hdr
);
1526 msi_set_property( package
->db
, Database
, db
->path
);
1528 if( UrlIsW( szPackage
, URLIS_URL
) )
1529 msi_set_property( package
->db
, szOriginalDatabase
, szPackage
);
1530 else if( szPackage
[0] == '#' )
1531 msi_set_property( package
->db
, szOriginalDatabase
, db
->path
);
1534 WCHAR fullpath
[MAX_PATH
];
1536 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1537 msi_set_property( package
->db
, szOriginalDatabase
, fullpath
);
1540 msi_set_context( package
);
1544 WCHAR patch_code
[GUID_SIZE
];
1545 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1546 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1547 if (r
!= ERROR_SUCCESS
)
1550 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1552 r
= apply_registered_patch( package
, patch_code
);
1553 if (r
!= ERROR_SUCCESS
)
1555 ERR("registered patch failed to apply %u\n", r
);
1556 msiobj_release( &package
->hdr
);
1565 msi_clone_properties( package
);
1566 msi_adjust_privilege_properties( package
);
1570 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1571 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1573 *pPackage
= package
;
1574 return ERROR_SUCCESS
;
1577 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1579 MSIPACKAGE
*package
= NULL
;
1582 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1584 if( !szPackage
|| !phPackage
)
1585 return ERROR_INVALID_PARAMETER
;
1589 FIXME("Should create an empty database and package\n");
1590 return ERROR_FUNCTION_FAILED
;
1594 FIXME("dwOptions %08x not supported\n", dwOptions
);
1596 ret
= MSI_OpenPackageW( szPackage
, &package
);
1597 if( ret
== ERROR_SUCCESS
)
1599 *phPackage
= alloc_msihandle( &package
->hdr
);
1601 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1602 msiobj_release( &package
->hdr
);
1608 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1610 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1613 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1615 LPWSTR szwPack
= NULL
;
1620 szwPack
= strdupAtoW( szPackage
);
1622 return ERROR_OUTOFMEMORY
;
1625 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1627 msi_free( szwPack
);
1632 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1634 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1637 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1639 MSIPACKAGE
*package
;
1640 MSIHANDLE handle
= 0;
1641 IUnknown
*remote_unk
;
1642 IWineMsiRemotePackage
*remote_package
;
1644 TRACE("(%d)\n",hInstall
);
1646 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1649 handle
= alloc_msihandle( &package
->db
->hdr
);
1650 msiobj_release( &package
->hdr
);
1652 else if ((remote_unk
= msi_get_remote(hInstall
)))
1654 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1655 (LPVOID
*)&remote_package
) == S_OK
)
1657 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1658 IWineMsiRemotePackage_Release(remote_package
);
1662 WARN("remote handle %d is not a package\n", hInstall
);
1664 IUnknown_Release(remote_unk
);
1670 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1673 static const WCHAR szActionData
[] =
1674 {'A','c','t','i','o','n','D','a','t','a',0};
1675 static const WCHAR szSetProgress
[] =
1676 {'S','e','t','P','r','o','g','r','e','s','s',0};
1677 static const WCHAR szActionText
[] =
1678 {'A','c','t','i','o','n','T','e','x','t',0};
1680 DWORD sz
, total_size
= 0, log_type
= 0;
1685 TRACE("%x\n", eMessageType
);
1687 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1688 log_type
|= INSTALLLOGMODE_ERROR
;
1689 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1690 log_type
|= INSTALLLOGMODE_WARNING
;
1691 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1692 log_type
|= INSTALLLOGMODE_USER
;
1693 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1694 log_type
|= INSTALLLOGMODE_INFO
;
1695 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1696 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1697 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1698 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1699 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1700 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1702 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1705 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1707 static const WCHAR template_s
[]=
1708 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1709 static const WCHAR format
[] =
1710 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1712 LPCWSTR action_text
, action
;
1713 LPWSTR deformatted
= NULL
;
1715 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1717 action
= MSI_RecordGetString(record
, 1);
1718 action_text
= MSI_RecordGetString(record
, 2);
1720 if (!action
|| !action_text
)
1723 deformat_string(package
, action_text
, &deformatted
);
1725 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1727 len
+= strlenW(deformatted
);
1728 message
= msi_alloc(len
*sizeof(WCHAR
));
1729 sprintfW(message
, template_s
, timet
, action
);
1731 strcatW(message
, deformatted
);
1732 msi_free(deformatted
);
1737 message
= msi_alloc(1*sizeof (WCHAR
));
1739 msg_field
= MSI_RecordGetFieldCount(record
);
1740 for (i
= 1; i
<= msg_field
; i
++)
1744 static const WCHAR format
[] = { '%','i',':',' ',0};
1746 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1748 total_size
+=sz
*sizeof(WCHAR
);
1749 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1750 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1752 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1756 sprintfW(number
,format
,i
);
1757 strcatW(message
,number
);
1759 strcatW(message
,tmp
);
1761 strcatW(message
, szSpace
);
1767 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1768 gUIFilter
, log_type
, debugstr_w(message
));
1770 /* convert it to ASCII */
1771 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1772 msg
= msi_alloc( len
);
1773 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1775 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1777 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1779 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1781 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1783 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1785 MSIHANDLE rec
= MsiCreateRecord( 1 );
1786 MsiRecordSetStringW( rec
, 0, message
);
1787 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1788 MsiCloseHandle( rec
);
1791 if (!rc
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1792 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1795 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1796 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1799 msi_free( message
);
1801 switch (eMessageType
& 0xff000000)
1803 case INSTALLMESSAGE_ACTIONDATA
:
1804 /* FIXME: format record here instead of in ui_actiondata to get the
1805 * correct action data for external scripts */
1806 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1808 case INSTALLMESSAGE_ACTIONSTART
:
1812 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1814 deformat_string(package
, action_text
, &deformated
);
1815 uirow
= MSI_CreateRecord(1);
1816 MSI_RecordSetStringW(uirow
, 1, deformated
);
1817 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1818 msi_free(deformated
);
1820 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1822 msiobj_release(&uirow
->hdr
);
1825 case INSTALLMESSAGE_PROGRESS
:
1826 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1830 return ERROR_SUCCESS
;
1833 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1836 UINT ret
= ERROR_INVALID_HANDLE
;
1837 MSIPACKAGE
*package
= NULL
;
1838 MSIRECORD
*record
= NULL
;
1840 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1844 IWineMsiRemotePackage
*remote_package
;
1846 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1847 if (!remote_package
)
1848 return ERROR_INVALID_HANDLE
;
1850 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1852 IWineMsiRemotePackage_Release( remote_package
);
1856 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1857 return HRESULT_CODE(hr
);
1859 return ERROR_FUNCTION_FAILED
;
1862 return ERROR_SUCCESS
;
1865 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1869 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1872 msiobj_release( &package
->hdr
);
1874 msiobj_release( &record
->hdr
);
1881 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1883 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1884 UINT r
= ERROR_OUTOFMEMORY
;
1886 szwName
= strdupAtoW( szName
);
1887 if( szName
&& !szwName
)
1890 szwValue
= strdupAtoW( szValue
);
1891 if( szValue
&& !szwValue
)
1894 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1897 msi_free( szwName
);
1898 msi_free( szwValue
);
1903 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
1907 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
1911 msi_free( folder
->ResolvedSource
);
1912 folder
->ResolvedSource
= NULL
;
1916 msi_free( folder
->ResolvedTarget
);
1917 folder
->ResolvedTarget
= NULL
;
1922 UINT
msi_set_property( MSIDATABASE
*db
, LPCWSTR szName
, LPCWSTR szValue
)
1925 MSIRECORD
*row
= NULL
;
1930 static const WCHAR Insert
[] = {
1931 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1932 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1933 '`','_','P','r','o','p','e','r','t','y','`',',',
1934 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1935 ,' ','(','?',',','?',')',0};
1936 static const WCHAR Update
[] = {
1937 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1938 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1939 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1940 ' ','=',' ','\'','%','s','\'',0};
1941 static const WCHAR Delete
[] = {
1942 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1943 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1944 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1946 TRACE("%p %s %s\n", db
, debugstr_w(szName
), debugstr_w(szValue
));
1949 return ERROR_INVALID_PARAMETER
;
1951 /* this one is weird... */
1953 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1955 rc
= msi_get_property(db
, szName
, 0, &sz
);
1956 if (!szValue
|| !*szValue
)
1958 sprintfW(Query
, Delete
, szName
);
1960 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1962 sprintfW(Query
, Update
, szName
);
1964 row
= MSI_CreateRecord(1);
1965 MSI_RecordSetStringW(row
, 1, szValue
);
1969 strcpyW(Query
, Insert
);
1971 row
= MSI_CreateRecord(2);
1972 MSI_RecordSetStringW(row
, 1, szName
);
1973 MSI_RecordSetStringW(row
, 2, szValue
);
1976 rc
= MSI_DatabaseOpenViewW(db
, Query
, &view
);
1977 if (rc
== ERROR_SUCCESS
)
1979 rc
= MSI_ViewExecute(view
, row
);
1980 MSI_ViewClose(view
);
1981 msiobj_release(&view
->hdr
);
1985 msiobj_release(&row
->hdr
);
1990 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1992 MSIPACKAGE
*package
;
1995 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1999 BSTR name
= NULL
, value
= NULL
;
2000 IWineMsiRemotePackage
*remote_package
;
2002 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2003 if (!remote_package
)
2004 return ERROR_INVALID_HANDLE
;
2006 name
= SysAllocString( szName
);
2007 value
= SysAllocString( szValue
);
2008 if ((!name
&& szName
) || (!value
&& szValue
))
2010 SysFreeString( name
);
2011 SysFreeString( value
);
2012 IWineMsiRemotePackage_Release( remote_package
);
2013 return ERROR_OUTOFMEMORY
;
2016 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2018 SysFreeString( name
);
2019 SysFreeString( value
);
2020 IWineMsiRemotePackage_Release( remote_package
);
2024 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2025 return HRESULT_CODE(hr
);
2027 return ERROR_FUNCTION_FAILED
;
2030 return ERROR_SUCCESS
;
2033 ret
= msi_set_property( package
->db
, szName
, szValue
);
2034 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, cszSourceDir
))
2035 msi_reset_folders( package
, TRUE
);
2037 msiobj_release( &package
->hdr
);
2041 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2044 MSIRECORD
*rec
, *row
= NULL
;
2047 static const WCHAR query
[]= {
2048 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2049 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2050 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2053 if (!name
|| !*name
)
2056 rec
= MSI_CreateRecord(1);
2060 MSI_RecordSetStringW(rec
, 1, name
);
2062 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2063 if (r
== ERROR_SUCCESS
)
2065 MSI_ViewExecute(view
, rec
);
2066 MSI_ViewFetch(view
, &row
);
2067 MSI_ViewClose(view
);
2068 msiobj_release(&view
->hdr
);
2071 msiobj_release(&rec
->hdr
);
2075 /* internal function, not compatible with MsiGetPropertyW */
2076 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2077 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2080 UINT rc
= ERROR_FUNCTION_FAILED
;
2082 row
= msi_get_property_row( db
, szName
);
2084 if (*pchValueBuf
> 0)
2089 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2090 msiobj_release(&row
->hdr
);
2093 if (rc
== ERROR_SUCCESS
)
2094 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
2095 debugstr_w(szName
));
2096 else if (rc
== ERROR_MORE_DATA
)
2097 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2098 debugstr_w(szName
));
2102 TRACE("property %s not found\n", debugstr_w(szName
));
2108 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2114 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2115 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2119 str
= msi_alloc(sz
* sizeof(WCHAR
));
2120 r
= msi_get_property(db
, prop
, str
, &sz
);
2121 if (r
!= ERROR_SUCCESS
)
2130 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2132 LPWSTR str
= msi_dup_property( db
, prop
);
2133 int val
= str
? atoiW(str
) : def
;
2138 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2139 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2141 MSIPACKAGE
*package
;
2142 MSIRECORD
*row
= NULL
;
2143 UINT r
= ERROR_FUNCTION_FAILED
;
2146 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2147 szValueBuf
->str
.w
, pchValueBuf
);
2150 return ERROR_INVALID_PARAMETER
;
2152 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2156 IWineMsiRemotePackage
*remote_package
;
2157 LPWSTR value
= NULL
;
2161 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2162 if (!remote_package
)
2163 return ERROR_INVALID_HANDLE
;
2165 bname
= SysAllocString( name
);
2168 IWineMsiRemotePackage_Release( remote_package
);
2169 return ERROR_OUTOFMEMORY
;
2173 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2178 value
= msi_alloc(len
* sizeof(WCHAR
));
2181 r
= ERROR_OUTOFMEMORY
;
2185 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
2189 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
2191 /* Bug required by Adobe installers */
2192 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2193 *pchValueBuf
*= sizeof(WCHAR
);
2196 IWineMsiRemotePackage_Release(remote_package
);
2197 SysFreeString(bname
);
2202 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2203 return HRESULT_CODE(hr
);
2205 return ERROR_FUNCTION_FAILED
;
2211 row
= msi_get_property_row( package
->db
, name
);
2213 val
= MSI_RecordGetString( row
, 1 );
2218 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
2221 msiobj_release( &row
->hdr
);
2222 msiobj_release( &package
->hdr
);
2227 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2228 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2234 val
.unicode
= FALSE
;
2235 val
.str
.a
= szValueBuf
;
2237 name
= strdupAtoW( szName
);
2238 if (szName
&& !name
)
2239 return ERROR_OUTOFMEMORY
;
2241 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2246 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2247 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2252 val
.str
.w
= szValueBuf
;
2254 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2257 typedef struct _msi_remote_package_impl
{
2258 const IWineMsiRemotePackageVtbl
*lpVtbl
;
2261 } msi_remote_package_impl
;
2263 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
2265 return (msi_remote_package_impl
*) iface
;
2268 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2269 REFIID riid
,LPVOID
*ppobj
)
2271 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2272 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2274 IUnknown_AddRef( iface
);
2279 return E_NOINTERFACE
;
2282 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2284 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2286 return InterlockedIncrement( &This
->refs
);
2289 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2291 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2294 r
= InterlockedDecrement( &This
->refs
);
2297 MsiCloseHandle( This
->package
);
2303 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2305 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2306 This
->package
= handle
;
2310 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2312 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2313 IWineMsiRemoteDatabase
*rdb
= NULL
;
2317 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2318 if (FAILED(hr
) || !rdb
)
2320 ERR("Failed to create remote database\n");
2324 hdb
= MsiGetActiveDatabase(This
->package
);
2326 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2329 ERR("Failed to set the database handle\n");
2333 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2337 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
2339 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2342 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
2343 if (r
!= ERROR_SUCCESS
)
2344 return HRESULT_FROM_WIN32(r
);
2349 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2351 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2352 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2353 return HRESULT_FROM_WIN32(r
);
2356 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2358 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2359 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2360 return HRESULT_FROM_WIN32(r
);
2363 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2365 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2366 UINT r
= MsiDoActionW(This
->package
, action
);
2367 return HRESULT_FROM_WIN32(r
);
2370 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2372 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2373 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2374 return HRESULT_FROM_WIN32(r
);
2377 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2379 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2380 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2381 return HRESULT_FROM_WIN32(r
);
2384 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2386 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2387 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2388 return HRESULT_FROM_WIN32(r
);
2391 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2393 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2394 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2395 return HRESULT_FROM_WIN32(r
);
2398 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2400 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2401 *ret
= MsiGetMode(This
->package
, mode
);
2405 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2407 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2408 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2409 return HRESULT_FROM_WIN32(r
);
2412 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2413 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2415 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2416 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2417 return HRESULT_FROM_WIN32(r
);
2420 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2422 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2423 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2424 return HRESULT_FROM_WIN32(r
);
2427 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2428 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2430 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2431 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2432 return HRESULT_FROM_WIN32(r
);
2435 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2437 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2438 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2439 return HRESULT_FROM_WIN32(r
);
2442 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2444 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2445 *language
= MsiGetLanguage(This
->package
);
2449 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2451 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2452 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2453 return HRESULT_FROM_WIN32(r
);
2456 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2460 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2461 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2462 if (r
== ERROR_SUCCESS
)
2464 *value
= SysAllocStringLen(NULL
, size
);
2466 return E_OUTOFMEMORY
;
2468 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2470 return HRESULT_FROM_WIN32(r
);
2473 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2475 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2476 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2477 return HRESULT_FROM_WIN32(r
);
2480 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2481 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2483 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2484 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2485 return HRESULT_FROM_WIN32(r
);
2488 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2494 mrp_GetActiveDatabase
,
2505 mrp_GetFeatureState
,
2506 mrp_SetFeatureState
,
2507 mrp_GetComponentState
,
2508 mrp_SetComponentState
,
2510 mrp_SetInstallLevel
,
2512 mrp_EvaluateCondition
,
2516 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2518 msi_remote_package_impl
* This
;
2520 This
= msi_alloc( sizeof *This
);
2522 return E_OUTOFMEMORY
;
2524 This
->lpVtbl
= &msi_remote_package_vtbl
;
2533 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2534 LPCWSTR property
, LPWSTR value
)
2536 MSISOURCELISTINFO
*info
;
2538 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2540 return ERROR_OUTOFMEMORY
;
2542 info
->context
= context
;
2543 info
->options
= options
;
2544 info
->property
= property
;
2545 info
->value
= strdupW(value
);
2546 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2548 return ERROR_SUCCESS
;
2551 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2552 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2556 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2558 return ERROR_OUTOFMEMORY
;
2560 disk
->context
= context
;
2561 disk
->options
= options
;
2562 disk
->disk_id
= disk_id
;
2563 disk
->volume_label
= strdupW(volume_label
);
2564 disk
->disk_prompt
= strdupW(disk_prompt
);
2565 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2567 return ERROR_SUCCESS
;