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_package_structures( MSIPACKAGE
*package
)
117 struct list
*item
, *cursor
;
119 TRACE("Freeing package action data\n");
121 remove_tracked_tempfiles(package
);
123 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
125 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
126 list_remove( &feature
->entry
);
127 free_feature( feature
);
130 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
132 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
134 list_remove( &folder
->entry
);
135 msi_free( folder
->Parent
);
136 msi_free( folder
->Directory
);
137 msi_free( folder
->TargetDefault
);
138 msi_free( folder
->SourceLongPath
);
139 msi_free( folder
->SourceShortPath
);
140 msi_free( folder
->ResolvedTarget
);
141 msi_free( folder
->ResolvedSource
);
142 msi_free( folder
->Property
);
146 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
148 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
150 list_remove( &comp
->entry
);
151 msi_free( comp
->Component
);
152 msi_free( comp
->ComponentId
);
153 msi_free( comp
->Directory
);
154 msi_free( comp
->Condition
);
155 msi_free( comp
->KeyPath
);
156 msi_free( comp
->FullKeypath
);
160 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
162 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
164 list_remove( &file
->entry
);
165 msi_free( file
->File
);
166 msi_free( file
->FileName
);
167 msi_free( file
->ShortName
);
168 msi_free( file
->LongName
);
169 msi_free( file
->Version
);
170 msi_free( file
->Language
);
171 msi_free( file
->TargetPath
);
175 /* clean up extension, progid, class and verb structures */
176 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
178 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
180 list_remove( &cls
->entry
);
181 msi_free( cls
->clsid
);
182 msi_free( cls
->Context
);
183 msi_free( cls
->Description
);
184 msi_free( cls
->FileTypeMask
);
185 msi_free( cls
->IconPath
);
186 msi_free( cls
->DefInprocHandler
);
187 msi_free( cls
->DefInprocHandler32
);
188 msi_free( cls
->Argument
);
189 msi_free( cls
->ProgIDText
);
193 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
195 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
197 list_remove( &ext
->entry
);
198 free_extension( ext
);
201 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
203 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
205 list_remove( &progid
->entry
);
206 msi_free( progid
->ProgID
);
207 msi_free( progid
->Description
);
208 msi_free( progid
->IconPath
);
212 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
214 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
216 list_remove( &mt
->entry
);
217 msi_free( mt
->suffix
);
218 msi_free( mt
->clsid
);
219 msi_free( mt
->ContentType
);
223 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
225 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
227 list_remove( &appid
->entry
);
228 msi_free( appid
->AppID
);
229 msi_free( appid
->RemoteServerName
);
230 msi_free( appid
->LocalServer
);
231 msi_free( appid
->ServiceParameters
);
232 msi_free( appid
->DllSurrogate
);
236 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
238 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
240 list_remove( &info
->entry
);
241 msi_free( info
->value
);
245 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
247 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
249 list_remove( &info
->entry
);
250 msi_free( info
->volume_label
);
251 msi_free( info
->disk_prompt
);
257 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
258 msi_free_action_script( package
, i
);
260 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
261 msi_free( package
->script
->UniqueActions
[i
] );
263 msi_free( package
->script
->UniqueActions
);
264 msi_free( package
->script
);
267 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
269 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
271 list_remove( &patch
->entry
);
272 msi_free( patch
->patchcode
);
273 msi_free( patch
->transforms
);
274 msi_free( patch
->localfile
);
278 msi_free( package
->BaseURL
);
279 msi_free( package
->PackagePath
);
280 msi_free( package
->ProductCode
);
281 msi_free( package
->ActionFormat
);
282 msi_free( package
->LastAction
);
283 msi_free( package
->langids
);
285 /* cleanup control event subscriptions */
286 ControlEvent_CleanupSubscriptions( package
);
289 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
291 MSIPACKAGE
*package
= (MSIPACKAGE
*) arg
;
293 if( package
->dialog
)
294 msi_dialog_destroy( package
->dialog
);
296 msiobj_release( &package
->db
->hdr
);
297 free_package_structures(package
);
300 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
302 MSIQUERY
*view
= NULL
;
305 static const WCHAR CreateSql
[] = {
306 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
307 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
308 '`','_','P','r','o','p','e','r','t','y','`',' ',
309 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
310 'T','E','M','P','O','R','A','R','Y',',',' ',
311 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
312 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
313 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
314 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
316 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &view
);
317 if (rc
!= ERROR_SUCCESS
)
320 rc
= MSI_ViewExecute(view
, 0);
322 msiobj_release(&view
->hdr
);
326 UINT
msi_clone_properties(MSIPACKAGE
*package
)
328 MSIQUERY
*view_select
= NULL
;
331 static const WCHAR query_select
[] = {
332 'S','E','L','E','C','T',' ','*',' ',
333 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
334 static const WCHAR query_insert
[] = {
335 'I','N','S','E','R','T',' ','i','n','t','o',' ',
336 '`','_','P','r','o','p','e','r','t','y','`',' ',
337 '(','`','_','P','r','o','p','e','r','t','y','`',',',
338 '`','V','a','l','u','e','`',')',' ',
339 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
340 static const WCHAR query_update
[] = {
341 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
342 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
343 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
345 rc
= MSI_DatabaseOpenViewW( package
->db
, query_select
, &view_select
);
346 if (rc
!= ERROR_SUCCESS
)
349 rc
= MSI_ViewExecute( view_select
, 0 );
350 if (rc
!= ERROR_SUCCESS
)
352 MSI_ViewClose( view_select
);
353 msiobj_release( &view_select
->hdr
);
359 MSIQUERY
*view_insert
, *view_update
;
360 MSIRECORD
*rec_select
;
362 rc
= MSI_ViewFetch( view_select
, &rec_select
);
363 if (rc
!= ERROR_SUCCESS
)
366 rc
= MSI_DatabaseOpenViewW( package
->db
, query_insert
, &view_insert
);
367 if (rc
!= ERROR_SUCCESS
)
369 msiobj_release( &rec_select
->hdr
);
373 rc
= MSI_ViewExecute( view_insert
, rec_select
);
374 MSI_ViewClose( view_insert
);
375 msiobj_release( &view_insert
->hdr
);
376 if (rc
!= ERROR_SUCCESS
)
378 MSIRECORD
*rec_update
;
380 TRACE("insert failed, trying update\n");
382 rc
= MSI_DatabaseOpenViewW( package
->db
, query_update
, &view_update
);
383 if (rc
!= ERROR_SUCCESS
)
385 WARN("open view failed %u\n", rc
);
386 msiobj_release( &rec_select
->hdr
);
390 rec_update
= MSI_CreateRecord( 2 );
391 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
392 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
393 rc
= MSI_ViewExecute( view_update
, rec_update
);
394 if (rc
!= ERROR_SUCCESS
)
395 WARN("update failed %u\n", rc
);
397 MSI_ViewClose( view_update
);
398 msiobj_release( &view_update
->hdr
);
399 msiobj_release( &rec_update
->hdr
);
402 msiobj_release( &rec_select
->hdr
);
405 MSI_ViewClose( view_select
);
406 msiobj_release( &view_select
->hdr
);
413 * Sets the "Installed" property to indicate that
414 * the product is installed for the current user.
416 static UINT
set_installed_prop( MSIPACKAGE
*package
)
421 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, &hkey
, FALSE
);
422 if (r
== ERROR_SUCCESS
)
425 msi_set_property( package
->db
, szInstalled
, szOne
);
431 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
435 LPWSTR sid_str
= NULL
, dom
= NULL
;
436 DWORD size
, dom_size
;
438 UINT r
= ERROR_FUNCTION_FAILED
;
441 GetUserNameW( NULL
, &size
);
443 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
445 return ERROR_OUTOFMEMORY
;
447 if (!GetUserNameW( user_name
, &size
))
452 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
454 psid
= msi_alloc( size
);
455 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
458 r
= ERROR_OUTOFMEMORY
;
462 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
465 if (!ConvertSidToStringSidW( psid
, &sid_str
))
468 r
= msi_set_property( package
->db
, szUserSID
, sid_str
);
471 LocalFree( sid_str
);
474 msi_free( user_name
);
479 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
484 DWORD index
= 0, size
;
486 WCHAR name
[MAX_PATH
];
487 WCHAR windir
[MAX_PATH
];
489 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
490 static const WCHAR sub
[] = {
491 'S','o','f','t','w','a','r','e','\\',
492 'M','i','c','r','o','s','o','f','t','\\',
493 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
496 static const WCHAR subdir
[] = {
497 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
498 'F','r','a','m','e','w','o','r','k','\\',0
501 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
502 if (res
!= ERROR_SUCCESS
)
505 GetWindowsDirectoryW(windir
, MAX_PATH
);
509 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
513 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
514 if (lstrcmpW(ver
, name
) < 0)
517 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
518 check
= msi_alloc(size
* sizeof(WCHAR
));
526 lstrcpyW(check
, windir
);
527 lstrcatW(check
, szBackSlash
);
528 lstrcatW(check
, subdir
);
529 lstrcatW(check
, name
);
530 lstrcatW(check
, szBackSlash
);
531 lstrcatW(check
, fusion
);
533 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
544 RegCloseKey(netsetup
);
548 typedef struct tagLANGANDCODEPAGE
554 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
558 LPVOID version
= NULL
;
560 LPWSTR fusion
, verstr
;
561 LANGANDCODEPAGE
*translate
;
563 static const WCHAR netasm
[] = {
564 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
566 static const WCHAR translation
[] = {
567 '\\','V','a','r','F','i','l','e','I','n','f','o',
568 '\\','T','r','a','n','s','l','a','t','i','o','n',0
570 static const WCHAR verfmt
[] = {
571 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
572 '\\','%','0','4','x','%','0','4','x',
573 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
576 fusion
= get_fusion_filename(package
);
580 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
583 version
= msi_alloc(size
);
584 if (!version
) return;
586 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
589 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
592 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
594 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
597 if (!val_len
|| !verstr
)
600 msi_set_property(package
->db
, netasm
, verstr
);
607 static VOID
set_installer_properties(MSIPACKAGE
*package
)
611 OSVERSIONINFOEXW OSVersion
;
614 WCHAR verstr
[10], bufstr
[20];
617 LPWSTR username
, companyname
;
618 SYSTEM_INFO sys_info
;
619 SYSTEMTIME systemtime
;
622 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
623 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
624 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
625 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
626 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
627 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
628 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
629 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
630 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
631 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
632 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
633 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
634 static const WCHAR szAppDataFolder
[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
635 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
636 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
637 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
638 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
639 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
640 static const WCHAR szWindowsFolder
[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
641 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
642 static const WCHAR szTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
643 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
644 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
645 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
646 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
647 static const WCHAR szFormat
[] = {'%','l','i',0};
648 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
649 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
650 static const WCHAR szSix
[] = {'6',0 };
651 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
652 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
653 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
654 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
655 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
656 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
657 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
658 static const WCHAR szIntFormat
[] = {'%','d',0};
659 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
660 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
661 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
662 static const WCHAR szUserInfo
[] = {
663 'S','O','F','T','W','A','R','E','\\',
664 'M','i','c','r','o','s','o','f','t','\\',
665 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
666 'U','s','e','r',' ','I','n','f','o',0
668 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
669 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
670 static const WCHAR szCurrentVersion
[] = {
671 'S','O','F','T','W','A','R','E','\\',
672 'M','i','c','r','o','s','o','f','t','\\',
673 'W','i','n','d','o','w','s',' ','N','T','\\',
674 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
676 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
677 static const WCHAR szRegisteredOrganization
[] = {
678 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
680 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
681 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
682 static const WCHAR szDate
[] = {'D','a','t','e',0};
683 static const WCHAR szTime
[] = {'T','i','m','e',0};
684 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
685 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
686 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
687 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
688 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
689 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
690 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
693 * Other things that probably should be set:
695 * ComputerName VirtualMemory
696 * ShellAdvSupport DefaultUIFont PackagecodeChanging
697 * CaptionHeight BorderTop BorderSide TextHeight
698 * RedirectedDllSupport
701 SHGetFolderPathW(NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
702 strcatW(pth
, szBackSlash
);
703 msi_set_property(package
->db
, szCommonFilesFolder
, pth
);
705 SHGetFolderPathW(NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
706 strcatW(pth
, szBackSlash
);
707 msi_set_property(package
->db
, szProgramFilesFolder
, pth
);
709 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
710 strcatW(pth
, szBackSlash
);
711 msi_set_property(package
->db
, szCommonAppDataFolder
, pth
);
713 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
714 strcatW(pth
, szBackSlash
);
715 msi_set_property(package
->db
, szFavoritesFolder
, pth
);
717 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
718 strcatW(pth
, szBackSlash
);
719 msi_set_property(package
->db
, szFontsFolder
, pth
);
721 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
722 strcatW(pth
, szBackSlash
);
723 msi_set_property(package
->db
, szSendToFolder
, pth
);
725 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
726 strcatW(pth
, szBackSlash
);
727 msi_set_property(package
->db
, szStartMenuFolder
, pth
);
729 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
730 strcatW(pth
, szBackSlash
);
731 msi_set_property(package
->db
, szStartupFolder
, pth
);
733 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
734 strcatW(pth
, szBackSlash
);
735 msi_set_property(package
->db
, szTemplateFolder
, pth
);
737 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
738 strcatW(pth
, szBackSlash
);
739 msi_set_property(package
->db
, szDesktopFolder
, pth
);
741 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
742 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
743 strcatW(pth
, szBackSlash
);
744 msi_set_property(package
->db
, szProgramMenuFolder
, pth
);
746 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
747 strcatW(pth
, szBackSlash
);
748 msi_set_property(package
->db
, szAdminToolsFolder
, pth
);
750 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
751 strcatW(pth
, szBackSlash
);
752 msi_set_property(package
->db
, szAppDataFolder
, pth
);
754 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
755 strcatW(pth
, szBackSlash
);
756 msi_set_property(package
->db
, szSystemFolder
, pth
);
757 msi_set_property(package
->db
, szSystem16Folder
, pth
);
759 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
760 strcatW(pth
, szBackSlash
);
761 msi_set_property(package
->db
, szLocalAppDataFolder
, pth
);
763 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
764 strcatW(pth
, szBackSlash
);
765 msi_set_property(package
->db
, szMyPicturesFolder
, pth
);
767 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
768 strcatW(pth
, szBackSlash
);
769 msi_set_property(package
->db
, szPersonalFolder
, pth
);
771 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
772 strcatW(pth
, szBackSlash
);
773 msi_set_property(package
->db
, szWindowsFolder
, pth
);
775 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
776 strcatW(pth
, szBackSlash
);
777 msi_set_property(package
->db
, szPrintHoodFolder
, pth
);
779 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
780 strcatW(pth
, szBackSlash
);
781 msi_set_property(package
->db
, szNetHoodFolder
, pth
);
783 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
784 strcatW(pth
, szBackSlash
);
785 msi_set_property(package
->db
, szRecentFolder
, pth
);
787 /* Physical Memory is specified in MB. Using total amount. */
788 msex
.dwLength
= sizeof(msex
);
789 GlobalMemoryStatusEx( &msex
);
790 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
791 msi_set_property(package
->db
, szPhysicalMemory
, bufstr
);
793 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
794 ptr
= strchrW(pth
,'\\');
795 if (ptr
) *(ptr
+ 1) = 0;
796 msi_set_property(package
->db
, szWindowsVolume
, pth
);
798 GetTempPathW(MAX_PATH
,pth
);
799 msi_set_property(package
->db
, szTempFolder
, pth
);
801 /* in a wine environment the user is always admin and privileged */
802 msi_set_property(package
->db
, szAdminUser
, szOne
);
803 msi_set_property(package
->db
, szPrivileged
, szOne
);
805 /* set the os things */
806 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
807 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
808 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
809 sprintfW(verstr
, szFormat
, verval
);
810 switch (OSVersion
.dwPlatformId
)
812 case VER_PLATFORM_WIN32_WINDOWS
:
813 msi_set_property(package
->db
, szVersion9x
, verstr
);
815 case VER_PLATFORM_WIN32_NT
:
816 msi_set_property(package
->db
, szVersionNT
, verstr
);
817 sprintfW(verstr
, szFormat
,OSVersion
.wProductType
);
818 msi_set_property(package
->db
, szMsiNTProductType
, verstr
);
821 sprintfW(verstr
, szFormat
, OSVersion
.dwBuildNumber
);
822 msi_set_property(package
->db
, szWindowsBuild
, verstr
);
823 /* just fudge this */
824 msi_set_property(package
->db
, szServicePackLevel
, szSix
);
826 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
827 msi_set_property( package
->db
, szVersionMsi
, bufstr
);
828 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
829 msi_set_property( package
->db
, szVersionDatabase
, bufstr
);
831 GetSystemInfo( &sys_info
);
832 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
834 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
835 msi_set_property( package
->db
, szIntel
, bufstr
);
837 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
839 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
840 msi_set_property( package
->db
, szMsiAMD64
, bufstr
);
841 msi_set_property( package
->db
, szMsix64
, bufstr
);
843 GetSystemDirectoryW( pth
, MAX_PATH
);
844 msi_set_property( package
->db
, szSystem64Folder
, pth
);
847 /* Screen properties. */
849 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
850 msi_set_property( package
->db
, szScreenX
, bufstr
);
851 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
852 msi_set_property( package
->db
, szScreenY
, bufstr
);
853 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
854 msi_set_property( package
->db
, szColorBits
, bufstr
);
857 /* USERNAME and COMPANYNAME */
858 username
= msi_dup_property( package
->db
, szUSERNAME
);
859 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
861 if ((!username
|| !companyname
) &&
862 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
865 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
866 msi_set_property( package
->db
, szUSERNAME
, username
);
868 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
869 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
872 if ((!username
|| !companyname
) &&
873 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
876 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
877 msi_set_property( package
->db
, szUSERNAME
, username
);
879 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
880 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
883 msi_free( username
);
884 msi_free( companyname
);
886 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
887 ERR("Failed to set the UserSID property\n");
889 /* Date and time properties */
890 GetSystemTime( &systemtime
);
891 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
892 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
893 msi_set_property( package
->db
, szDate
, bufstr
);
895 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
897 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
898 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
899 &systemtime
, NULL
, bufstr
,
900 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
901 msi_set_property( package
->db
, szTime
, bufstr
);
903 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
905 set_msi_assembly_prop( package
);
907 langid
= GetUserDefaultLangID();
908 sprintfW(bufstr
, szIntFormat
, langid
);
909 msi_set_property( package
->db
, szUserLanguageID
, bufstr
);
911 langid
= GetSystemDefaultLangID();
912 sprintfW(bufstr
, szIntFormat
, langid
);
913 msi_set_property( package
->db
, szSystemLangID
, bufstr
);
915 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
916 msi_set_property( package
->db
, szProductState
, bufstr
);
919 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_MORE_DATA
)
922 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
924 if (GetUserNameW( username
, &len
))
925 msi_set_property( package
->db
, szLogonUser
, username
);
926 msi_free( username
);
931 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
935 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
939 static const WCHAR szPackageCode
[] = {
940 'P','a','c','k','a','g','e','C','o','d','e',0};
943 ERR("Unable to allocate handle\n");
944 return ERROR_OUTOFMEMORY
;
947 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
949 if (rc
!= ERROR_SUCCESS
)
951 ERR("Unable to open Summary Information\n");
955 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
956 &count
, NULL
, NULL
, NULL
);
957 if (rc
!= ERROR_SUCCESS
)
959 WARN("Unable to query page count: %d\n", rc
);
963 /* load package code property */
965 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
966 NULL
, NULL
, NULL
, &len
);
967 if (rc
!= ERROR_MORE_DATA
)
969 WARN("Unable to query revision number: %d\n", rc
);
970 rc
= ERROR_FUNCTION_FAILED
;
975 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
976 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
977 NULL
, NULL
, package_code
, &len
);
978 if (rc
!= ERROR_SUCCESS
)
980 WARN("Unable to query rev number: %d\n", rc
);
984 msi_set_property( package
->db
, szPackageCode
, package_code
);
985 msi_free( package_code
);
987 /* load package attributes */
989 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
990 &count
, NULL
, NULL
, NULL
);
991 package
->WordCount
= count
;
994 MsiCloseHandle(suminfo
);
998 static MSIPACKAGE
*msi_alloc_package( void )
1000 MSIPACKAGE
*package
;
1002 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1006 list_init( &package
->components
);
1007 list_init( &package
->features
);
1008 list_init( &package
->files
);
1009 list_init( &package
->tempfiles
);
1010 list_init( &package
->folders
);
1011 list_init( &package
->subscriptions
);
1012 list_init( &package
->appids
);
1013 list_init( &package
->classes
);
1014 list_init( &package
->mimes
);
1015 list_init( &package
->extensions
);
1016 list_init( &package
->progids
);
1017 list_init( &package
->RunningActions
);
1018 list_init( &package
->sourcelist_info
);
1019 list_init( &package
->sourcelist_media
);
1020 list_init( &package
->patches
);
1026 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1031 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1033 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1034 if (r
!= ERROR_SUCCESS
)
1037 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1043 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1045 /* FIXME: this should depend on the user's privileges */
1046 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1048 TRACE("resetting ALLUSERS property from 2 to 1\n");
1049 msi_set_property( package
->db
, szAllUsers
, szOne
);
1051 msi_set_property( package
->db
, szAdminUser
, szOne
);
1054 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1056 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
1057 static const WCHAR szpi
[] = {'%','i',0};
1058 MSIPACKAGE
*package
;
1064 package
= msi_alloc_package();
1067 msiobj_addref( &db
->hdr
);
1070 package
->WordCount
= 0;
1071 package
->PackagePath
= strdupW( db
->path
);
1072 package
->BaseURL
= strdupW( base_url
);
1074 create_temp_property_table( package
);
1075 msi_clone_properties( package
);
1076 msi_adjust_privilege_properties( package
);
1078 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1079 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1081 set_installed_prop( package
);
1082 set_installer_properties( package
);
1084 sprintfW(uilevel
,szpi
,gUILevel
);
1085 msi_set_property(package
->db
, szLevel
, uilevel
);
1087 r
= msi_load_summary_properties( package
);
1088 if (r
!= ERROR_SUCCESS
)
1090 msiobj_release( &package
->hdr
);
1094 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1095 msi_load_admin_properties( package
);
1102 * copy_package_to_temp [internal]
1104 * copy the msi file to a temp file to prevent locking a CD
1105 * with a multi disc install
1107 * FIXME: I think this is wrong, and instead of copying the package,
1108 * we should read all the tables to memory, then open the
1109 * database to read binary streams on demand.
1111 static UINT
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
1113 WCHAR path
[MAX_PATH
];
1115 GetTempPathW( MAX_PATH
, path
);
1116 GetTempFileNameW( path
, szMsi
, 0, filename
);
1118 if( !CopyFileW( szPackage
, filename
, FALSE
) )
1120 UINT error
= GetLastError();
1121 if ( error
== ERROR_FILE_NOT_FOUND
)
1122 ERR("can't find %s\n", debugstr_w(szPackage
));
1124 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage
), debugstr_w(filename
), error
);
1125 DeleteFileW( filename
);
1129 return ERROR_SUCCESS
;
1132 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1134 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1138 /* call will always fail, becase size is 0,
1139 * but will return ERROR_FILE_NOT_FOUND first
1140 * if the file doesn't exist
1142 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1143 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1145 cache_entry
= msi_alloc( size
);
1146 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1148 UINT error
= GetLastError();
1149 msi_free( cache_entry
);
1153 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1154 msi_free( cache_entry
);
1155 return ERROR_SUCCESS
;
1158 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1161 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1162 return ERROR_FUNCTION_FAILED
;
1165 return ERROR_SUCCESS
;
1168 UINT
msi_get_local_package_name( LPWSTR path
, LPCWSTR suffix
)
1170 static const WCHAR szInstaller
[] = {
1171 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1172 static const WCHAR fmt
[] = {'%','x',0};
1173 DWORD time
, len
, i
, offset
;
1176 time
= GetTickCount();
1177 GetWindowsDirectoryW( path
, MAX_PATH
);
1178 strcatW( path
, szInstaller
);
1179 CreateDirectoryW( path
, NULL
);
1181 len
= strlenW(path
);
1182 for (i
= 0; i
< 0x10000; i
++)
1184 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1185 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1186 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1187 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1188 if (handle
!= INVALID_HANDLE_VALUE
)
1190 CloseHandle(handle
);
1193 if (GetLastError() != ERROR_FILE_EXISTS
&&
1194 GetLastError() != ERROR_SHARING_VIOLATION
)
1195 return ERROR_FUNCTION_FAILED
;
1198 return ERROR_SUCCESS
;
1201 static UINT
apply_registered_patch( MSIPACKAGE
*package
, LPCWSTR patch_code
)
1205 WCHAR patch_file
[MAX_PATH
];
1206 MSIDATABASE
*patch_db
;
1207 MSIPATCHINFO
*patch_info
;
1210 len
= sizeof(patch_file
) / sizeof(WCHAR
);
1211 r
= MsiGetPatchInfoExW( patch_code
, package
->ProductCode
, NULL
, package
->Context
,
1212 INSTALLPROPERTY_LOCALPACKAGEW
, patch_file
, &len
);
1213 if (r
!= ERROR_SUCCESS
)
1215 ERR("failed to get patch filename %u\n", r
);
1219 r
= MSI_OpenDatabaseW( patch_file
, MSIDBOPEN_READONLY
+ MSIDBOPEN_PATCHFILE
, &patch_db
);
1220 if (r
!= ERROR_SUCCESS
)
1222 ERR("failed to open patch database %s\n", debugstr_w( patch_file
));
1226 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
1229 msiobj_release( &patch_db
->hdr
);
1230 return ERROR_FUNCTION_FAILED
;
1233 r
= msi_parse_patch_summary( si
, &patch_info
);
1234 msiobj_release( &si
->hdr
);
1235 if (r
!= ERROR_SUCCESS
)
1237 ERR("failed to parse patch summary %u\n", r
);
1238 msiobj_release( &patch_db
->hdr
);
1242 patch_info
->localfile
= strdupW( patch_file
);
1243 if (!patch_info
->localfile
)
1245 msiobj_release( &patch_db
->hdr
);
1246 return ERROR_OUTOFMEMORY
;
1249 r
= msi_apply_patch_db( package
, patch_db
, patch_info
);
1250 msiobj_release( &patch_db
->hdr
);
1251 if (r
!= ERROR_SUCCESS
)
1253 ERR("failed to apply patch %u\n", r
);
1254 msi_free( patch_info
->patchcode
);
1255 msi_free( patch_info
->transforms
);
1256 msi_free( patch_info
->localfile
);
1257 msi_free( patch_info
);
1262 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1264 WCHAR
*template, *p
, *q
;
1267 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1269 return ERROR_SUCCESS
; /* native accepts missing template property */
1271 TRACE("template: %s\n", debugstr_w(template));
1273 p
= strchrW( template, ';' );
1276 WARN("invalid template string %s\n", debugstr_w(template));
1277 msi_free( template );
1278 return ERROR_PATCH_PACKAGE_INVALID
;
1281 if (!template[0] || !strcmpW( template, szIntel
))
1282 package
->platform
= PLATFORM_INTEL
;
1283 else if (!strcmpW( template, szIntel64
))
1284 package
->platform
= PLATFORM_INTEL64
;
1285 else if (!strcmpW( template, szX64
))
1286 package
->platform
= PLATFORM_X64
;
1289 WARN("unknown platform %s\n", debugstr_w(template));
1290 msi_free( template );
1291 return ERROR_PATCH_PACKAGE_INVALID
;
1295 for (q
= ++p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1297 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1298 if (!package
->langids
)
1300 msi_free( template );
1301 return ERROR_OUTOFMEMORY
;
1307 q
= strchrW( p
, ',' );
1309 package
->langids
[i
] = atoiW( p
);
1314 package
->num_langids
= i
+ 1;
1316 msi_free( template );
1317 return ERROR_SUCCESS
;
1320 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1322 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
1323 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1324 MSIDATABASE
*db
= NULL
;
1325 MSIPACKAGE
*package
;
1327 LPWSTR ptr
, base_url
= NULL
;
1329 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1330 LPCWSTR file
= szPackage
;
1334 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1336 if( szPackage
[0] == '#' )
1338 handle
= atoiW(&szPackage
[1]);
1339 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1342 IWineMsiRemoteDatabase
*remote_database
;
1344 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1345 if ( !remote_database
)
1346 return ERROR_INVALID_HANDLE
;
1348 IWineMsiRemoteDatabase_Release( remote_database
);
1349 WARN("MsiOpenPackage not allowed during a custom action!\n");
1351 return ERROR_FUNCTION_FAILED
;
1356 if ( UrlIsW( szPackage
, URLIS_URL
) )
1358 r
= msi_download_file( szPackage
, cachefile
);
1359 if ( r
!= ERROR_SUCCESS
)
1362 r
= copy_package_to_temp( cachefile
, temppath
);
1363 if ( r
!= ERROR_SUCCESS
)
1368 base_url
= strdupW( szPackage
);
1370 return ERROR_OUTOFMEMORY
;
1372 ptr
= strrchrW( base_url
, '/' );
1373 if (ptr
) *(ptr
+ 1) = '\0';
1377 r
= copy_package_to_temp( szPackage
, temppath
);
1378 if ( r
!= ERROR_SUCCESS
)
1384 r
= msi_get_local_package_name( localfile
, dotmsi
);
1385 if (r
!= ERROR_SUCCESS
)
1388 TRACE("Copying to local package %s\n", debugstr_w(localfile
));
1390 if (!CopyFileW( file
, localfile
, FALSE
))
1392 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1393 debugstr_w(file
), debugstr_w(localfile
), GetLastError());
1394 return GetLastError();
1397 TRACE("Opening relocated package %s\n", debugstr_w( file
));
1399 /* transforms that add binary streams require that we open the database
1400 * read/write, which is safe because we always create a copy that is thrown
1401 * away when we're done.
1403 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_TRANSACT
, &db
);
1404 if( r
!= ERROR_SUCCESS
)
1406 if (file
!= szPackage
)
1407 DeleteFileW( file
);
1409 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
1410 return ERROR_FILE_NOT_FOUND
;
1415 db
->localfile
= strdupW( localfile
);
1418 package
= MSI_CreatePackage( db
, base_url
);
1419 msi_free( base_url
);
1420 msiobj_release( &db
->hdr
);
1423 if (file
!= szPackage
)
1424 DeleteFileW( file
);
1426 return ERROR_INSTALL_PACKAGE_INVALID
;
1429 if( file
!= szPackage
)
1430 track_tempfile( package
, file
);
1432 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1435 WARN("failed to load summary info %u\n", r
);
1436 msiobj_release( &package
->hdr
);
1437 return ERROR_INSTALL_PACKAGE_INVALID
;
1440 r
= msi_parse_summary( si
, package
);
1441 msiobj_release( &si
->hdr
);
1442 if (r
!= ERROR_SUCCESS
)
1444 WARN("failed to parse summary info %u\n", r
);
1445 msiobj_release( &package
->hdr
);
1449 msi_set_property( package
->db
, Database
, db
->path
);
1451 if( UrlIsW( szPackage
, URLIS_URL
) )
1452 msi_set_property( package
->db
, szOriginalDatabase
, szPackage
);
1453 else if( szPackage
[0] == '#' )
1454 msi_set_property( package
->db
, szOriginalDatabase
, db
->path
);
1457 WCHAR fullpath
[MAX_PATH
];
1459 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1460 msi_set_property( package
->db
, szOriginalDatabase
, fullpath
);
1463 msi_set_context( package
);
1467 WCHAR patch_code
[GUID_SIZE
];
1468 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1469 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1470 if (r
!= ERROR_SUCCESS
)
1473 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1475 r
= apply_registered_patch( package
, patch_code
);
1476 if (r
!= ERROR_SUCCESS
)
1478 ERR("registered patch failed to apply %u\n", r
);
1479 msiobj_release( &package
->hdr
);
1488 msi_clone_properties( package
);
1489 msi_adjust_privilege_properties( package
);
1492 *pPackage
= package
;
1493 return ERROR_SUCCESS
;
1496 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1498 MSIPACKAGE
*package
= NULL
;
1501 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1503 if( !szPackage
|| !phPackage
)
1504 return ERROR_INVALID_PARAMETER
;
1508 FIXME("Should create an empty database and package\n");
1509 return ERROR_FUNCTION_FAILED
;
1513 FIXME("dwOptions %08x not supported\n", dwOptions
);
1515 ret
= MSI_OpenPackageW( szPackage
, &package
);
1516 if( ret
== ERROR_SUCCESS
)
1518 *phPackage
= alloc_msihandle( &package
->hdr
);
1520 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1521 msiobj_release( &package
->hdr
);
1527 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1529 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1532 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1534 LPWSTR szwPack
= NULL
;
1539 szwPack
= strdupAtoW( szPackage
);
1541 return ERROR_OUTOFMEMORY
;
1544 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1546 msi_free( szwPack
);
1551 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1553 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1556 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1558 MSIPACKAGE
*package
;
1559 MSIHANDLE handle
= 0;
1560 IUnknown
*remote_unk
;
1561 IWineMsiRemotePackage
*remote_package
;
1563 TRACE("(%d)\n",hInstall
);
1565 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1568 handle
= alloc_msihandle( &package
->db
->hdr
);
1569 msiobj_release( &package
->hdr
);
1571 else if ((remote_unk
= msi_get_remote(hInstall
)))
1573 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1574 (LPVOID
*)&remote_package
) == S_OK
)
1576 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1577 IWineMsiRemotePackage_Release(remote_package
);
1581 WARN("remote handle %d is not a package\n", hInstall
);
1583 IUnknown_Release(remote_unk
);
1589 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1592 static const WCHAR szActionData
[] =
1593 {'A','c','t','i','o','n','D','a','t','a',0};
1594 static const WCHAR szSetProgress
[] =
1595 {'S','e','t','P','r','o','g','r','e','s','s',0};
1596 static const WCHAR szActionText
[] =
1597 {'A','c','t','i','o','n','T','e','x','t',0};
1601 DWORD total_size
= 0;
1607 TRACE("%x\n", eMessageType
);
1610 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1611 log_type
|= INSTALLLOGMODE_ERROR
;
1612 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1613 log_type
|= INSTALLLOGMODE_WARNING
;
1614 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1615 log_type
|= INSTALLLOGMODE_USER
;
1616 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1617 log_type
|= INSTALLLOGMODE_INFO
;
1618 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1619 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1620 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1621 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1622 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1623 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1625 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1628 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1630 static const WCHAR template_s
[]=
1631 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1632 static const WCHAR format
[] =
1633 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1635 LPCWSTR action_text
, action
;
1636 LPWSTR deformatted
= NULL
;
1638 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1640 action
= MSI_RecordGetString(record
, 1);
1641 action_text
= MSI_RecordGetString(record
, 2);
1643 if (!action
|| !action_text
)
1646 deformat_string(package
, action_text
, &deformatted
);
1648 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1650 len
+= strlenW(deformatted
);
1651 message
= msi_alloc(len
*sizeof(WCHAR
));
1652 sprintfW(message
, template_s
, timet
, action
);
1654 strcatW(message
, deformatted
);
1655 msi_free(deformatted
);
1660 message
= msi_alloc(1*sizeof (WCHAR
));
1662 msg_field
= MSI_RecordGetFieldCount(record
);
1663 for (i
= 1; i
<= msg_field
; i
++)
1667 static const WCHAR format
[] = { '%','i',':',' ',0};
1669 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1671 total_size
+=sz
*sizeof(WCHAR
);
1672 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1673 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1675 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1679 sprintfW(number
,format
,i
);
1680 strcatW(message
,number
);
1682 strcatW(message
,tmp
);
1684 strcatW(message
, szSpace
);
1690 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1691 gUIFilter
, log_type
, debugstr_w(message
));
1693 /* convert it to ASCII */
1694 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1695 msg
= msi_alloc( len
);
1696 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1698 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1700 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1702 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1704 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1706 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1708 MSIHANDLE rec
= MsiCreateRecord( 1 );
1709 MsiRecordSetStringW( rec
, 0, message
);
1710 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1711 MsiCloseHandle( rec
);
1714 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
1715 INSTALLMESSAGE_PROGRESS
))
1718 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
1719 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1721 if (log_file
!= INVALID_HANDLE_VALUE
)
1723 SetFilePointer(log_file
,0, NULL
, FILE_END
);
1724 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
1725 WriteFile(log_file
,"\n",1,&write
,NULL
);
1726 CloseHandle(log_file
);
1730 msi_free( message
);
1732 switch (eMessageType
& 0xff000000)
1734 case INSTALLMESSAGE_ACTIONDATA
:
1735 /* FIXME: format record here instead of in ui_actiondata to get the
1736 * correct action data for external scripts */
1737 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1739 case INSTALLMESSAGE_ACTIONSTART
:
1743 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1745 deformat_string(package
, action_text
, &deformated
);
1746 uirow
= MSI_CreateRecord(1);
1747 MSI_RecordSetStringW(uirow
, 1, deformated
);
1748 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1749 msi_free(deformated
);
1751 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1753 msiobj_release(&uirow
->hdr
);
1756 case INSTALLMESSAGE_PROGRESS
:
1757 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1761 return ERROR_SUCCESS
;
1764 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1767 UINT ret
= ERROR_INVALID_HANDLE
;
1768 MSIPACKAGE
*package
= NULL
;
1769 MSIRECORD
*record
= NULL
;
1771 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1775 IWineMsiRemotePackage
*remote_package
;
1777 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1778 if (!remote_package
)
1779 return ERROR_INVALID_HANDLE
;
1781 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1783 IWineMsiRemotePackage_Release( remote_package
);
1787 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1788 return HRESULT_CODE(hr
);
1790 return ERROR_FUNCTION_FAILED
;
1793 return ERROR_SUCCESS
;
1796 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1800 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1803 msiobj_release( &package
->hdr
);
1805 msiobj_release( &record
->hdr
);
1812 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1814 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1815 UINT r
= ERROR_OUTOFMEMORY
;
1817 szwName
= strdupAtoW( szName
);
1818 if( szName
&& !szwName
)
1821 szwValue
= strdupAtoW( szValue
);
1822 if( szValue
&& !szwValue
)
1825 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1828 msi_free( szwName
);
1829 msi_free( szwValue
);
1834 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
1838 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
1842 msi_free( folder
->ResolvedSource
);
1843 folder
->ResolvedSource
= NULL
;
1847 msi_free( folder
->ResolvedTarget
);
1848 folder
->ResolvedTarget
= NULL
;
1853 UINT
msi_set_property( MSIDATABASE
*db
, LPCWSTR szName
, LPCWSTR szValue
)
1856 MSIRECORD
*row
= NULL
;
1861 static const WCHAR Insert
[] = {
1862 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1863 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1864 '`','_','P','r','o','p','e','r','t','y','`',',',
1865 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1866 ,' ','(','?',',','?',')',0};
1867 static const WCHAR Update
[] = {
1868 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1869 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1870 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1871 ' ','=',' ','\'','%','s','\'',0};
1872 static const WCHAR Delete
[] = {
1873 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1874 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1875 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1877 TRACE("%p %s %s\n", db
, debugstr_w(szName
), debugstr_w(szValue
));
1880 return ERROR_INVALID_PARAMETER
;
1882 /* this one is weird... */
1884 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1886 rc
= msi_get_property(db
, szName
, 0, &sz
);
1887 if (!szValue
|| !*szValue
)
1889 sprintfW(Query
, Delete
, szName
);
1891 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1893 sprintfW(Query
, Update
, szName
);
1895 row
= MSI_CreateRecord(1);
1896 MSI_RecordSetStringW(row
, 1, szValue
);
1900 strcpyW(Query
, Insert
);
1902 row
= MSI_CreateRecord(2);
1903 MSI_RecordSetStringW(row
, 1, szName
);
1904 MSI_RecordSetStringW(row
, 2, szValue
);
1907 rc
= MSI_DatabaseOpenViewW(db
, Query
, &view
);
1908 if (rc
== ERROR_SUCCESS
)
1910 rc
= MSI_ViewExecute(view
, row
);
1911 MSI_ViewClose(view
);
1912 msiobj_release(&view
->hdr
);
1916 msiobj_release(&row
->hdr
);
1921 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1923 MSIPACKAGE
*package
;
1926 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1930 BSTR name
= NULL
, value
= NULL
;
1931 IWineMsiRemotePackage
*remote_package
;
1933 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1934 if (!remote_package
)
1935 return ERROR_INVALID_HANDLE
;
1937 name
= SysAllocString( szName
);
1938 value
= SysAllocString( szValue
);
1939 if ((!name
&& szName
) || (!value
&& szValue
))
1941 SysFreeString( name
);
1942 SysFreeString( value
);
1943 IWineMsiRemotePackage_Release( remote_package
);
1944 return ERROR_OUTOFMEMORY
;
1947 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
1949 SysFreeString( name
);
1950 SysFreeString( value
);
1951 IWineMsiRemotePackage_Release( remote_package
);
1955 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1956 return HRESULT_CODE(hr
);
1958 return ERROR_FUNCTION_FAILED
;
1961 return ERROR_SUCCESS
;
1964 ret
= msi_set_property( package
->db
, szName
, szValue
);
1965 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, cszSourceDir
))
1966 msi_reset_folders( package
, TRUE
);
1968 msiobj_release( &package
->hdr
);
1972 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
1975 MSIRECORD
*rec
, *row
= NULL
;
1978 static const WCHAR query
[]= {
1979 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1980 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1981 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1984 if (!name
|| !*name
)
1987 rec
= MSI_CreateRecord(1);
1991 MSI_RecordSetStringW(rec
, 1, name
);
1993 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
1994 if (r
== ERROR_SUCCESS
)
1996 MSI_ViewExecute(view
, rec
);
1997 MSI_ViewFetch(view
, &row
);
1998 MSI_ViewClose(view
);
1999 msiobj_release(&view
->hdr
);
2002 msiobj_release(&rec
->hdr
);
2006 /* internal function, not compatible with MsiGetPropertyW */
2007 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2008 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2011 UINT rc
= ERROR_FUNCTION_FAILED
;
2013 row
= msi_get_property_row( db
, szName
);
2015 if (*pchValueBuf
> 0)
2020 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2021 msiobj_release(&row
->hdr
);
2024 if (rc
== ERROR_SUCCESS
)
2025 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
2026 debugstr_w(szName
));
2027 else if (rc
== ERROR_MORE_DATA
)
2028 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2029 debugstr_w(szName
));
2033 TRACE("property %s not found\n", debugstr_w(szName
));
2039 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2045 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2046 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2050 str
= msi_alloc(sz
* sizeof(WCHAR
));
2051 r
= msi_get_property(db
, prop
, str
, &sz
);
2052 if (r
!= ERROR_SUCCESS
)
2061 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2063 LPWSTR str
= msi_dup_property( db
, prop
);
2064 int val
= str
? atoiW(str
) : def
;
2069 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2070 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2072 MSIPACKAGE
*package
;
2073 MSIRECORD
*row
= NULL
;
2074 UINT r
= ERROR_FUNCTION_FAILED
;
2077 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2078 szValueBuf
->str
.w
, pchValueBuf
);
2081 return ERROR_INVALID_PARAMETER
;
2083 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2087 IWineMsiRemotePackage
*remote_package
;
2088 LPWSTR value
= NULL
;
2092 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2093 if (!remote_package
)
2094 return ERROR_INVALID_HANDLE
;
2096 bname
= SysAllocString( name
);
2099 IWineMsiRemotePackage_Release( remote_package
);
2100 return ERROR_OUTOFMEMORY
;
2104 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2109 value
= msi_alloc(len
* sizeof(WCHAR
));
2112 r
= ERROR_OUTOFMEMORY
;
2116 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
2120 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
2122 /* Bug required by Adobe installers */
2123 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2124 *pchValueBuf
*= sizeof(WCHAR
);
2127 IWineMsiRemotePackage_Release(remote_package
);
2128 SysFreeString(bname
);
2133 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2134 return HRESULT_CODE(hr
);
2136 return ERROR_FUNCTION_FAILED
;
2142 row
= msi_get_property_row( package
->db
, name
);
2144 val
= MSI_RecordGetString( row
, 1 );
2149 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
2152 msiobj_release( &row
->hdr
);
2153 msiobj_release( &package
->hdr
);
2158 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2159 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2165 val
.unicode
= FALSE
;
2166 val
.str
.a
= szValueBuf
;
2168 name
= strdupAtoW( szName
);
2169 if (szName
&& !name
)
2170 return ERROR_OUTOFMEMORY
;
2172 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2177 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2178 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2183 val
.str
.w
= szValueBuf
;
2185 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2188 typedef struct _msi_remote_package_impl
{
2189 const IWineMsiRemotePackageVtbl
*lpVtbl
;
2192 } msi_remote_package_impl
;
2194 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
2196 return (msi_remote_package_impl
*) iface
;
2199 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2200 REFIID riid
,LPVOID
*ppobj
)
2202 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2203 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2205 IUnknown_AddRef( iface
);
2210 return E_NOINTERFACE
;
2213 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2215 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2217 return InterlockedIncrement( &This
->refs
);
2220 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2222 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2225 r
= InterlockedDecrement( &This
->refs
);
2228 MsiCloseHandle( This
->package
);
2234 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2236 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2237 This
->package
= handle
;
2241 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2243 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2244 IWineMsiRemoteDatabase
*rdb
= NULL
;
2248 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2249 if (FAILED(hr
) || !rdb
)
2251 ERR("Failed to create remote database\n");
2255 hdb
= MsiGetActiveDatabase(This
->package
);
2257 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2260 ERR("Failed to set the database handle\n");
2264 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2268 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
2270 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2273 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
2274 if (r
!= ERROR_SUCCESS
)
2275 return HRESULT_FROM_WIN32(r
);
2280 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2282 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2283 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2284 return HRESULT_FROM_WIN32(r
);
2287 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2289 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2290 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2291 return HRESULT_FROM_WIN32(r
);
2294 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2296 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2297 UINT r
= MsiDoActionW(This
->package
, action
);
2298 return HRESULT_FROM_WIN32(r
);
2301 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2303 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2304 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2305 return HRESULT_FROM_WIN32(r
);
2308 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2310 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2311 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2312 return HRESULT_FROM_WIN32(r
);
2315 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2317 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2318 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2319 return HRESULT_FROM_WIN32(r
);
2322 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2324 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2325 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2326 return HRESULT_FROM_WIN32(r
);
2329 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2331 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2332 *ret
= MsiGetMode(This
->package
, mode
);
2336 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2338 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2339 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2340 return HRESULT_FROM_WIN32(r
);
2343 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2344 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2346 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2347 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2348 return HRESULT_FROM_WIN32(r
);
2351 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2353 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2354 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2355 return HRESULT_FROM_WIN32(r
);
2358 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2359 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2361 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2362 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2363 return HRESULT_FROM_WIN32(r
);
2366 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2368 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2369 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2370 return HRESULT_FROM_WIN32(r
);
2373 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2375 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2376 *language
= MsiGetLanguage(This
->package
);
2380 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2382 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2383 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2384 return HRESULT_FROM_WIN32(r
);
2387 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2391 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2392 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2393 if (r
== ERROR_SUCCESS
)
2395 *value
= SysAllocStringLen(NULL
, size
);
2397 return E_OUTOFMEMORY
;
2399 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2401 return HRESULT_FROM_WIN32(r
);
2404 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2406 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2407 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2408 return HRESULT_FROM_WIN32(r
);
2411 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2412 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2414 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2415 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2416 return HRESULT_FROM_WIN32(r
);
2419 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2425 mrp_GetActiveDatabase
,
2436 mrp_GetFeatureState
,
2437 mrp_SetFeatureState
,
2438 mrp_GetComponentState
,
2439 mrp_SetComponentState
,
2441 mrp_SetInstallLevel
,
2443 mrp_EvaluateCondition
,
2447 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2449 msi_remote_package_impl
* This
;
2451 This
= msi_alloc( sizeof *This
);
2453 return E_OUTOFMEMORY
;
2455 This
->lpVtbl
= &msi_remote_package_vtbl
;
2464 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2465 LPCWSTR property
, LPWSTR value
)
2467 MSISOURCELISTINFO
*info
;
2469 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2471 return ERROR_OUTOFMEMORY
;
2473 info
->context
= context
;
2474 info
->options
= options
;
2475 info
->property
= property
;
2476 info
->value
= strdupW(value
);
2477 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2479 return ERROR_SUCCESS
;
2482 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2483 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2487 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2489 return ERROR_OUTOFMEMORY
;
2491 disk
->context
= context
;
2492 disk
->options
= options
;
2493 disk
->disk_id
= disk_id
;
2494 disk
->volume_label
= strdupW(volume_label
);
2495 disk
->disk_prompt
= strdupW(disk_prompt
);
2496 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2498 return ERROR_SUCCESS
;