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
);
298 CloseHandle( package
->log_file
);
301 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
303 MSIQUERY
*view
= NULL
;
306 static const WCHAR CreateSql
[] = {
307 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
308 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
309 '`','_','P','r','o','p','e','r','t','y','`',' ',
310 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
311 'T','E','M','P','O','R','A','R','Y',',',' ',
312 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
313 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
314 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
315 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
317 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &view
);
318 if (rc
!= ERROR_SUCCESS
)
321 rc
= MSI_ViewExecute(view
, 0);
323 msiobj_release(&view
->hdr
);
327 UINT
msi_clone_properties(MSIPACKAGE
*package
)
329 MSIQUERY
*view_select
= NULL
;
332 static const WCHAR query_select
[] = {
333 'S','E','L','E','C','T',' ','*',' ',
334 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
335 static const WCHAR query_insert
[] = {
336 'I','N','S','E','R','T',' ','i','n','t','o',' ',
337 '`','_','P','r','o','p','e','r','t','y','`',' ',
338 '(','`','_','P','r','o','p','e','r','t','y','`',',',
339 '`','V','a','l','u','e','`',')',' ',
340 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
341 static const WCHAR query_update
[] = {
342 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
343 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
344 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
346 rc
= MSI_DatabaseOpenViewW( package
->db
, query_select
, &view_select
);
347 if (rc
!= ERROR_SUCCESS
)
350 rc
= MSI_ViewExecute( view_select
, 0 );
351 if (rc
!= ERROR_SUCCESS
)
353 MSI_ViewClose( view_select
);
354 msiobj_release( &view_select
->hdr
);
360 MSIQUERY
*view_insert
, *view_update
;
361 MSIRECORD
*rec_select
;
363 rc
= MSI_ViewFetch( view_select
, &rec_select
);
364 if (rc
!= ERROR_SUCCESS
)
367 rc
= MSI_DatabaseOpenViewW( package
->db
, query_insert
, &view_insert
);
368 if (rc
!= ERROR_SUCCESS
)
370 msiobj_release( &rec_select
->hdr
);
374 rc
= MSI_ViewExecute( view_insert
, rec_select
);
375 MSI_ViewClose( view_insert
);
376 msiobj_release( &view_insert
->hdr
);
377 if (rc
!= ERROR_SUCCESS
)
379 MSIRECORD
*rec_update
;
381 TRACE("insert failed, trying update\n");
383 rc
= MSI_DatabaseOpenViewW( package
->db
, query_update
, &view_update
);
384 if (rc
!= ERROR_SUCCESS
)
386 WARN("open view failed %u\n", rc
);
387 msiobj_release( &rec_select
->hdr
);
391 rec_update
= MSI_CreateRecord( 2 );
392 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
393 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
394 rc
= MSI_ViewExecute( view_update
, rec_update
);
395 if (rc
!= ERROR_SUCCESS
)
396 WARN("update failed %u\n", rc
);
398 MSI_ViewClose( view_update
);
399 msiobj_release( &view_update
->hdr
);
400 msiobj_release( &rec_update
->hdr
);
403 msiobj_release( &rec_select
->hdr
);
406 MSI_ViewClose( view_select
);
407 msiobj_release( &view_select
->hdr
);
414 * Sets the "Installed" property to indicate that
415 * the product is installed for the current user.
417 static UINT
set_installed_prop( MSIPACKAGE
*package
)
422 r
= MSIREG_OpenUninstallKey( package
, &hkey
, FALSE
);
423 if (r
== ERROR_SUCCESS
)
426 msi_set_property( package
->db
, szInstalled
, szOne
);
432 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
436 LPWSTR sid_str
= NULL
, dom
= NULL
;
437 DWORD size
, dom_size
;
439 UINT r
= ERROR_FUNCTION_FAILED
;
442 GetUserNameW( NULL
, &size
);
444 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
446 return ERROR_OUTOFMEMORY
;
448 if (!GetUserNameW( user_name
, &size
))
453 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
455 psid
= msi_alloc( size
);
456 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
459 r
= ERROR_OUTOFMEMORY
;
463 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
466 if (!ConvertSidToStringSidW( psid
, &sid_str
))
469 r
= msi_set_property( package
->db
, szUserSID
, sid_str
);
472 LocalFree( sid_str
);
475 msi_free( user_name
);
480 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
485 DWORD index
= 0, size
;
487 WCHAR name
[MAX_PATH
];
488 WCHAR windir
[MAX_PATH
];
490 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
491 static const WCHAR sub
[] = {
492 'S','o','f','t','w','a','r','e','\\',
493 'M','i','c','r','o','s','o','f','t','\\',
494 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
497 static const WCHAR subdir
[] = {
498 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
499 'F','r','a','m','e','w','o','r','k','\\',0
502 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
503 if (res
!= ERROR_SUCCESS
)
506 GetWindowsDirectoryW(windir
, MAX_PATH
);
510 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
514 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
515 if (strcmpW( ver
, name
) < 0)
518 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
519 check
= msi_alloc(size
* sizeof(WCHAR
));
527 lstrcpyW(check
, windir
);
528 lstrcatW(check
, szBackSlash
);
529 lstrcatW(check
, subdir
);
530 lstrcatW(check
, name
);
531 lstrcatW(check
, szBackSlash
);
532 lstrcatW(check
, fusion
);
534 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
545 RegCloseKey(netsetup
);
549 typedef struct tagLANGANDCODEPAGE
555 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
559 LPVOID version
= NULL
;
561 LPWSTR fusion
, verstr
;
562 LANGANDCODEPAGE
*translate
;
564 static const WCHAR netasm
[] = {
565 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
567 static const WCHAR translation
[] = {
568 '\\','V','a','r','F','i','l','e','I','n','f','o',
569 '\\','T','r','a','n','s','l','a','t','i','o','n',0
571 static const WCHAR verfmt
[] = {
572 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
573 '\\','%','0','4','x','%','0','4','x',
574 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
577 fusion
= get_fusion_filename(package
);
581 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
584 version
= msi_alloc(size
);
585 if (!version
) return;
587 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
590 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
593 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
595 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
598 if (!val_len
|| !verstr
)
601 msi_set_property(package
->db
, netasm
, verstr
);
608 static VOID
set_installer_properties(MSIPACKAGE
*package
)
612 OSVERSIONINFOEXW OSVersion
;
615 WCHAR verstr
[10], bufstr
[20];
618 LPWSTR username
, companyname
;
619 SYSTEM_INFO sys_info
;
620 SYSTEMTIME systemtime
;
623 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
624 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
625 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
626 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
627 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
628 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
629 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
630 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
631 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
632 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
633 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
634 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
635 static const WCHAR szAppDataFolder
[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
636 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
637 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
638 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
639 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
640 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
641 static const WCHAR szWindowsFolder
[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
642 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
643 static const WCHAR szTempFolder
[]= {'T','e','m','p','F','o','l','d','e','r',0};
644 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
645 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
646 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
647 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
648 static const WCHAR szFormat
[] = {'%','l','i',0};
649 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
650 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
651 static const WCHAR szSix
[] = {'6',0 };
652 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
653 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
654 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
655 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
656 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
657 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
658 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
659 static const WCHAR szIntFormat
[] = {'%','d',0};
660 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
661 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
662 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
663 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
664 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 };
665 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
666 static const WCHAR szUserInfo
[] = {
667 'S','O','F','T','W','A','R','E','\\',
668 'M','i','c','r','o','s','o','f','t','\\',
669 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
670 'U','s','e','r',' ','I','n','f','o',0
672 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
673 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
674 static const WCHAR szCurrentVersion
[] = {
675 'S','O','F','T','W','A','R','E','\\',
676 'M','i','c','r','o','s','o','f','t','\\',
677 'W','i','n','d','o','w','s',' ','N','T','\\',
678 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
680 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
681 static const WCHAR szRegisteredOrganization
[] = {
682 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
684 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
685 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
686 static const WCHAR szDate
[] = {'D','a','t','e',0};
687 static const WCHAR szTime
[] = {'T','i','m','e',0};
688 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
689 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
690 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
691 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
692 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
693 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
694 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
697 * Other things that probably should be set:
699 * ComputerName VirtualMemory
700 * ShellAdvSupport DefaultUIFont PackagecodeChanging
701 * CaptionHeight BorderTop BorderSide TextHeight
702 * RedirectedDllSupport
705 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
706 strcatW(pth
, szBackSlash
);
707 msi_set_property(package
->db
, szCommonAppDataFolder
, pth
);
709 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
710 strcatW(pth
, szBackSlash
);
711 msi_set_property(package
->db
, szFavoritesFolder
, pth
);
713 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
714 strcatW(pth
, szBackSlash
);
715 msi_set_property(package
->db
, szFontsFolder
, pth
);
717 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
718 strcatW(pth
, szBackSlash
);
719 msi_set_property(package
->db
, szSendToFolder
, pth
);
721 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
722 strcatW(pth
, szBackSlash
);
723 msi_set_property(package
->db
, szStartMenuFolder
, pth
);
725 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
726 strcatW(pth
, szBackSlash
);
727 msi_set_property(package
->db
, szStartupFolder
, pth
);
729 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
730 strcatW(pth
, szBackSlash
);
731 msi_set_property(package
->db
, szTemplateFolder
, pth
);
733 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
734 strcatW(pth
, szBackSlash
);
735 msi_set_property(package
->db
, szDesktopFolder
, pth
);
737 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
738 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
739 strcatW(pth
, szBackSlash
);
740 msi_set_property(package
->db
, szProgramMenuFolder
, pth
);
742 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
743 strcatW(pth
, szBackSlash
);
744 msi_set_property(package
->db
, szAdminToolsFolder
, pth
);
746 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
747 strcatW(pth
, szBackSlash
);
748 msi_set_property(package
->db
, szAppDataFolder
, pth
);
750 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
751 strcatW(pth
, szBackSlash
);
752 msi_set_property(package
->db
, szSystemFolder
, pth
);
753 msi_set_property(package
->db
, szSystem16Folder
, pth
);
755 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
756 strcatW(pth
, szBackSlash
);
757 msi_set_property(package
->db
, szLocalAppDataFolder
, pth
);
759 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
760 strcatW(pth
, szBackSlash
);
761 msi_set_property(package
->db
, szMyPicturesFolder
, pth
);
763 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
764 strcatW(pth
, szBackSlash
);
765 msi_set_property(package
->db
, szPersonalFolder
, pth
);
767 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
768 strcatW(pth
, szBackSlash
);
769 msi_set_property(package
->db
, szWindowsFolder
, pth
);
771 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
772 strcatW(pth
, szBackSlash
);
773 msi_set_property(package
->db
, szPrintHoodFolder
, pth
);
775 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
776 strcatW(pth
, szBackSlash
);
777 msi_set_property(package
->db
, szNetHoodFolder
, pth
);
779 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
780 strcatW(pth
, szBackSlash
);
781 msi_set_property(package
->db
, szRecentFolder
, pth
);
783 /* Physical Memory is specified in MB. Using total amount. */
784 msex
.dwLength
= sizeof(msex
);
785 GlobalMemoryStatusEx( &msex
);
786 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
787 msi_set_property(package
->db
, szPhysicalMemory
, bufstr
);
789 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
790 ptr
= strchrW(pth
,'\\');
791 if (ptr
) *(ptr
+ 1) = 0;
792 msi_set_property(package
->db
, szWindowsVolume
, pth
);
794 GetTempPathW(MAX_PATH
,pth
);
795 msi_set_property(package
->db
, szTempFolder
, pth
);
797 /* in a wine environment the user is always admin and privileged */
798 msi_set_property(package
->db
, szAdminUser
, szOne
);
799 msi_set_property(package
->db
, szPrivileged
, szOne
);
801 /* set the os things */
802 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
803 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
804 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
805 sprintfW(verstr
, szFormat
, verval
);
806 switch (OSVersion
.dwPlatformId
)
808 case VER_PLATFORM_WIN32_WINDOWS
:
809 msi_set_property(package
->db
, szVersion9x
, verstr
);
811 case VER_PLATFORM_WIN32_NT
:
812 msi_set_property(package
->db
, szVersionNT
, verstr
);
813 sprintfW(verstr
, szFormat
,OSVersion
.wProductType
);
814 msi_set_property(package
->db
, szMsiNTProductType
, verstr
);
817 sprintfW(verstr
, szFormat
, OSVersion
.dwBuildNumber
);
818 msi_set_property(package
->db
, szWindowsBuild
, verstr
);
819 /* just fudge this */
820 msi_set_property(package
->db
, szServicePackLevel
, szSix
);
822 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
823 msi_set_property( package
->db
, szVersionMsi
, bufstr
);
824 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
825 msi_set_property( package
->db
, szVersionDatabase
, bufstr
);
827 GetNativeSystemInfo( &sys_info
);
828 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
829 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
831 msi_set_property( package
->db
, szIntel
, bufstr
);
833 GetSystemDirectoryW( pth
, MAX_PATH
);
834 PathAddBackslashW( pth
);
835 msi_set_property( package
->db
, szSystemFolder
, pth
);
837 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
838 PathAddBackslashW( pth
);
839 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
841 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
842 PathAddBackslashW( pth
);
843 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
845 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
847 msi_set_property( package
->db
, szMsiAMD64
, bufstr
);
848 msi_set_property( package
->db
, szMsix64
, bufstr
);
849 msi_set_property( package
->db
, szVersionNT64
, verstr
);
851 GetSystemDirectoryW( pth
, MAX_PATH
);
852 PathAddBackslashW( pth
);
853 msi_set_property( package
->db
, szSystem64Folder
, pth
);
855 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
856 PathAddBackslashW( pth
);
857 msi_set_property( package
->db
, szSystemFolder
, pth
);
859 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
860 PathAddBackslashW( pth
);
861 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
);
863 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
864 PathAddBackslashW( pth
);
865 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
867 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
868 PathAddBackslashW( pth
);
869 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
);
871 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
872 PathAddBackslashW( pth
);
873 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
876 /* Screen properties. */
878 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
879 msi_set_property( package
->db
, szScreenX
, bufstr
);
880 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
881 msi_set_property( package
->db
, szScreenY
, bufstr
);
882 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
883 msi_set_property( package
->db
, szColorBits
, bufstr
);
886 /* USERNAME and COMPANYNAME */
887 username
= msi_dup_property( package
->db
, szUSERNAME
);
888 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
890 if ((!username
|| !companyname
) &&
891 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
894 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
895 msi_set_property( package
->db
, szUSERNAME
, username
);
897 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
898 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
901 if ((!username
|| !companyname
) &&
902 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
905 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
906 msi_set_property( package
->db
, szUSERNAME
, username
);
908 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
909 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
912 msi_free( username
);
913 msi_free( companyname
);
915 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
916 ERR("Failed to set the UserSID property\n");
918 /* Date and time properties */
919 GetSystemTime( &systemtime
);
920 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
921 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
922 msi_set_property( package
->db
, szDate
, bufstr
);
924 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
926 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
927 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
928 &systemtime
, NULL
, bufstr
,
929 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
930 msi_set_property( package
->db
, szTime
, bufstr
);
932 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
934 set_msi_assembly_prop( package
);
936 langid
= GetUserDefaultLangID();
937 sprintfW(bufstr
, szIntFormat
, langid
);
938 msi_set_property( package
->db
, szUserLanguageID
, bufstr
);
940 langid
= GetSystemDefaultLangID();
941 sprintfW(bufstr
, szIntFormat
, langid
);
942 msi_set_property( package
->db
, szSystemLangID
, bufstr
);
944 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
945 msi_set_property( package
->db
, szProductState
, bufstr
);
948 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_MORE_DATA
)
951 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
953 if (GetUserNameW( username
, &len
))
954 msi_set_property( package
->db
, szLogonUser
, username
);
955 msi_free( username
);
960 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
964 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
968 static const WCHAR szPackageCode
[] = {
969 'P','a','c','k','a','g','e','C','o','d','e',0};
972 ERR("Unable to allocate handle\n");
973 return ERROR_OUTOFMEMORY
;
976 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
978 if (rc
!= ERROR_SUCCESS
)
980 ERR("Unable to open Summary Information\n");
984 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
985 &count
, NULL
, NULL
, NULL
);
986 if (rc
!= ERROR_SUCCESS
)
988 WARN("Unable to query page count: %d\n", rc
);
992 /* load package code property */
994 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
995 NULL
, NULL
, NULL
, &len
);
996 if (rc
!= ERROR_MORE_DATA
)
998 WARN("Unable to query revision number: %d\n", rc
);
999 rc
= ERROR_FUNCTION_FAILED
;
1004 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
1005 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1006 NULL
, NULL
, package_code
, &len
);
1007 if (rc
!= ERROR_SUCCESS
)
1009 WARN("Unable to query rev number: %d\n", rc
);
1013 msi_set_property( package
->db
, szPackageCode
, package_code
);
1014 msi_free( package_code
);
1016 /* load package attributes */
1018 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
1019 &count
, NULL
, NULL
, NULL
);
1020 package
->WordCount
= count
;
1023 MsiCloseHandle(suminfo
);
1027 static MSIPACKAGE
*msi_alloc_package( void )
1029 MSIPACKAGE
*package
;
1031 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1035 list_init( &package
->components
);
1036 list_init( &package
->features
);
1037 list_init( &package
->files
);
1038 list_init( &package
->tempfiles
);
1039 list_init( &package
->folders
);
1040 list_init( &package
->subscriptions
);
1041 list_init( &package
->appids
);
1042 list_init( &package
->classes
);
1043 list_init( &package
->mimes
);
1044 list_init( &package
->extensions
);
1045 list_init( &package
->progids
);
1046 list_init( &package
->RunningActions
);
1047 list_init( &package
->sourcelist_info
);
1048 list_init( &package
->sourcelist_media
);
1049 list_init( &package
->patches
);
1055 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1060 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1062 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1063 if (r
!= ERROR_SUCCESS
)
1066 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1072 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1074 /* FIXME: this should depend on the user's privileges */
1075 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1077 TRACE("resetting ALLUSERS property from 2 to 1\n");
1078 msi_set_property( package
->db
, szAllUsers
, szOne
);
1080 msi_set_property( package
->db
, szAdminUser
, szOne
);
1083 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1085 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
1086 static const WCHAR szpi
[] = {'%','i',0};
1087 MSIPACKAGE
*package
;
1093 package
= msi_alloc_package();
1096 msiobj_addref( &db
->hdr
);
1099 package
->WordCount
= 0;
1100 package
->PackagePath
= strdupW( db
->path
);
1101 package
->BaseURL
= strdupW( base_url
);
1103 create_temp_property_table( package
);
1104 msi_clone_properties( package
);
1105 msi_adjust_privilege_properties( package
);
1107 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1108 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1110 set_installed_prop( package
);
1111 set_installer_properties( package
);
1113 sprintfW(uilevel
,szpi
,gUILevel
);
1114 msi_set_property(package
->db
, szLevel
, uilevel
);
1116 r
= msi_load_summary_properties( package
);
1117 if (r
!= ERROR_SUCCESS
)
1119 msiobj_release( &package
->hdr
);
1123 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1124 msi_load_admin_properties( package
);
1126 package
->log_file
= INVALID_HANDLE_VALUE
;
1133 * copy_package_to_temp [internal]
1135 * copy the msi file to a temp file to prevent locking a CD
1136 * with a multi disc install
1138 * FIXME: I think this is wrong, and instead of copying the package,
1139 * we should read all the tables to memory, then open the
1140 * database to read binary streams on demand.
1142 static UINT
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
1144 WCHAR path
[MAX_PATH
];
1146 GetTempPathW( MAX_PATH
, path
);
1147 GetTempFileNameW( path
, szMsi
, 0, filename
);
1149 if( !CopyFileW( szPackage
, filename
, FALSE
) )
1151 UINT error
= GetLastError();
1152 if ( error
== ERROR_FILE_NOT_FOUND
)
1153 ERR("can't find %s\n", debugstr_w(szPackage
));
1155 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage
), debugstr_w(filename
), error
);
1156 DeleteFileW( filename
);
1160 return ERROR_SUCCESS
;
1163 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1165 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1169 /* call will always fail, becase size is 0,
1170 * but will return ERROR_FILE_NOT_FOUND first
1171 * if the file doesn't exist
1173 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1174 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1176 cache_entry
= msi_alloc( size
);
1177 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1179 UINT error
= GetLastError();
1180 msi_free( cache_entry
);
1184 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1185 msi_free( cache_entry
);
1186 return ERROR_SUCCESS
;
1189 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1192 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1193 return ERROR_FUNCTION_FAILED
;
1196 return ERROR_SUCCESS
;
1199 UINT
msi_get_local_package_name( LPWSTR path
, LPCWSTR suffix
)
1201 static const WCHAR szInstaller
[] = {
1202 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1203 static const WCHAR fmt
[] = {'%','x',0};
1204 DWORD time
, len
, i
, offset
;
1207 time
= GetTickCount();
1208 GetWindowsDirectoryW( path
, MAX_PATH
);
1209 strcatW( path
, szInstaller
);
1210 CreateDirectoryW( path
, NULL
);
1212 len
= strlenW(path
);
1213 for (i
= 0; i
< 0x10000; i
++)
1215 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1216 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1217 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1218 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1219 if (handle
!= INVALID_HANDLE_VALUE
)
1221 CloseHandle(handle
);
1224 if (GetLastError() != ERROR_FILE_EXISTS
&&
1225 GetLastError() != ERROR_SHARING_VIOLATION
)
1226 return ERROR_FUNCTION_FAILED
;
1229 return ERROR_SUCCESS
;
1232 static UINT
apply_registered_patch( MSIPACKAGE
*package
, LPCWSTR patch_code
)
1236 WCHAR patch_file
[MAX_PATH
];
1237 MSIDATABASE
*patch_db
;
1238 MSIPATCHINFO
*patch_info
;
1241 len
= sizeof(patch_file
) / sizeof(WCHAR
);
1242 r
= MsiGetPatchInfoExW( patch_code
, package
->ProductCode
, NULL
, package
->Context
,
1243 INSTALLPROPERTY_LOCALPACKAGEW
, patch_file
, &len
);
1244 if (r
!= ERROR_SUCCESS
)
1246 ERR("failed to get patch filename %u\n", r
);
1250 r
= MSI_OpenDatabaseW( patch_file
, MSIDBOPEN_READONLY
+ MSIDBOPEN_PATCHFILE
, &patch_db
);
1251 if (r
!= ERROR_SUCCESS
)
1253 ERR("failed to open patch database %s\n", debugstr_w( patch_file
));
1257 si
= MSI_GetSummaryInformationW( patch_db
->storage
, 0 );
1260 msiobj_release( &patch_db
->hdr
);
1261 return ERROR_FUNCTION_FAILED
;
1264 r
= msi_parse_patch_summary( si
, &patch_info
);
1265 msiobj_release( &si
->hdr
);
1266 if (r
!= ERROR_SUCCESS
)
1268 ERR("failed to parse patch summary %u\n", r
);
1269 msiobj_release( &patch_db
->hdr
);
1273 patch_info
->localfile
= strdupW( patch_file
);
1274 if (!patch_info
->localfile
)
1276 msiobj_release( &patch_db
->hdr
);
1277 return ERROR_OUTOFMEMORY
;
1280 r
= msi_apply_patch_db( package
, patch_db
, patch_info
);
1281 msiobj_release( &patch_db
->hdr
);
1282 if (r
!= ERROR_SUCCESS
)
1284 ERR("failed to apply patch %u\n", r
);
1285 msi_free( patch_info
->patchcode
);
1286 msi_free( patch_info
->transforms
);
1287 msi_free( patch_info
->localfile
);
1288 msi_free( patch_info
);
1293 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1295 WCHAR
*template, *p
, *q
;
1298 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1299 TRACE("version: %d\n", package
->version
);
1301 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1303 return ERROR_SUCCESS
; /* native accepts missing template property */
1305 TRACE("template: %s\n", debugstr_w(template));
1307 p
= strchrW( template, ';' );
1310 WARN("invalid template string %s\n", debugstr_w(template));
1311 msi_free( template );
1312 return ERROR_PATCH_PACKAGE_INVALID
;
1315 if (!template[0] || !strcmpW( template, szIntel
))
1316 package
->platform
= PLATFORM_INTEL
;
1317 else if (!strcmpW( template, szIntel64
))
1318 package
->platform
= PLATFORM_INTEL64
;
1319 else if (!strcmpW( template, szX64
))
1320 package
->platform
= PLATFORM_X64
;
1323 WARN("unknown platform %s\n", debugstr_w(template));
1324 msi_free( template );
1325 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1329 for (q
= ++p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1331 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1332 if (!package
->langids
)
1334 msi_free( template );
1335 return ERROR_OUTOFMEMORY
;
1341 q
= strchrW( p
, ',' );
1343 package
->langids
[i
] = atoiW( p
);
1348 package
->num_langids
= i
+ 1;
1350 msi_free( template );
1351 return ERROR_SUCCESS
;
1354 static UINT
validate_package( MSIPACKAGE
*package
)
1359 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1360 if (package
->platform
== PLATFORM_X64
)
1362 if (!is_64bit
&& !is_wow64
)
1363 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1364 if (package
->version
< 200)
1365 return ERROR_INSTALL_PACKAGE_INVALID
;
1367 if (!package
->num_langids
)
1369 return ERROR_SUCCESS
;
1371 for (i
= 0; i
< package
->num_langids
; i
++)
1373 if (!package
->langids
[i
] || IsValidLocale( package
->langids
[i
], LCID_INSTALLED
))
1374 return ERROR_SUCCESS
;
1376 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1379 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1381 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
1382 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1383 MSIDATABASE
*db
= NULL
;
1384 MSIPACKAGE
*package
;
1386 LPWSTR ptr
, base_url
= NULL
;
1388 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1389 LPCWSTR file
= szPackage
;
1393 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1395 if( szPackage
[0] == '#' )
1397 handle
= atoiW(&szPackage
[1]);
1398 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1401 IWineMsiRemoteDatabase
*remote_database
;
1403 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1404 if ( !remote_database
)
1405 return ERROR_INVALID_HANDLE
;
1407 IWineMsiRemoteDatabase_Release( remote_database
);
1408 WARN("MsiOpenPackage not allowed during a custom action!\n");
1410 return ERROR_FUNCTION_FAILED
;
1415 if ( UrlIsW( szPackage
, URLIS_URL
) )
1417 r
= msi_download_file( szPackage
, cachefile
);
1418 if ( r
!= ERROR_SUCCESS
)
1421 r
= copy_package_to_temp( cachefile
, temppath
);
1422 if ( r
!= ERROR_SUCCESS
)
1427 base_url
= strdupW( szPackage
);
1429 return ERROR_OUTOFMEMORY
;
1431 ptr
= strrchrW( base_url
, '/' );
1432 if (ptr
) *(ptr
+ 1) = '\0';
1436 r
= copy_package_to_temp( szPackage
, temppath
);
1437 if ( r
!= ERROR_SUCCESS
)
1443 r
= msi_get_local_package_name( localfile
, dotmsi
);
1444 if (r
!= ERROR_SUCCESS
)
1447 TRACE("Copying to local package %s\n", debugstr_w(localfile
));
1449 if (!CopyFileW( file
, localfile
, FALSE
))
1451 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1452 debugstr_w(file
), debugstr_w(localfile
), GetLastError());
1453 return GetLastError();
1456 TRACE("Opening relocated package %s\n", debugstr_w( file
));
1458 /* transforms that add binary streams require that we open the database
1459 * read/write, which is safe because we always create a copy that is thrown
1460 * away when we're done.
1462 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_TRANSACT
, &db
);
1463 if( r
!= ERROR_SUCCESS
)
1465 if (file
!= szPackage
)
1466 DeleteFileW( file
);
1468 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
1469 return ERROR_FILE_NOT_FOUND
;
1474 db
->localfile
= strdupW( localfile
);
1477 package
= MSI_CreatePackage( db
, base_url
);
1478 msi_free( base_url
);
1479 msiobj_release( &db
->hdr
);
1482 if (file
!= szPackage
)
1483 DeleteFileW( file
);
1485 return ERROR_INSTALL_PACKAGE_INVALID
;
1488 if( file
!= szPackage
)
1489 track_tempfile( package
, file
);
1491 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1494 WARN("failed to load summary info %u\n", r
);
1495 msiobj_release( &package
->hdr
);
1496 return ERROR_INSTALL_PACKAGE_INVALID
;
1499 r
= msi_parse_summary( si
, package
);
1500 msiobj_release( &si
->hdr
);
1501 if (r
!= ERROR_SUCCESS
)
1503 WARN("failed to parse summary info %u\n", r
);
1504 msiobj_release( &package
->hdr
);
1508 r
= validate_package( package
);
1509 if (r
!= ERROR_SUCCESS
)
1511 msiobj_release( &package
->hdr
);
1514 msi_set_property( package
->db
, Database
, db
->path
);
1516 if( UrlIsW( szPackage
, URLIS_URL
) )
1517 msi_set_property( package
->db
, szOriginalDatabase
, szPackage
);
1518 else if( szPackage
[0] == '#' )
1519 msi_set_property( package
->db
, szOriginalDatabase
, db
->path
);
1522 WCHAR fullpath
[MAX_PATH
];
1524 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1525 msi_set_property( package
->db
, szOriginalDatabase
, fullpath
);
1528 msi_set_context( package
);
1532 WCHAR patch_code
[GUID_SIZE
];
1533 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1534 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1535 if (r
!= ERROR_SUCCESS
)
1538 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1540 r
= apply_registered_patch( package
, patch_code
);
1541 if (r
!= ERROR_SUCCESS
)
1543 ERR("registered patch failed to apply %u\n", r
);
1544 msiobj_release( &package
->hdr
);
1553 msi_clone_properties( package
);
1554 msi_adjust_privilege_properties( package
);
1558 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1559 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1561 *pPackage
= package
;
1562 return ERROR_SUCCESS
;
1565 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1567 MSIPACKAGE
*package
= NULL
;
1570 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1572 if( !szPackage
|| !phPackage
)
1573 return ERROR_INVALID_PARAMETER
;
1577 FIXME("Should create an empty database and package\n");
1578 return ERROR_FUNCTION_FAILED
;
1582 FIXME("dwOptions %08x not supported\n", dwOptions
);
1584 ret
= MSI_OpenPackageW( szPackage
, &package
);
1585 if( ret
== ERROR_SUCCESS
)
1587 *phPackage
= alloc_msihandle( &package
->hdr
);
1589 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1590 msiobj_release( &package
->hdr
);
1596 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1598 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1601 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1603 LPWSTR szwPack
= NULL
;
1608 szwPack
= strdupAtoW( szPackage
);
1610 return ERROR_OUTOFMEMORY
;
1613 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1615 msi_free( szwPack
);
1620 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1622 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1625 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1627 MSIPACKAGE
*package
;
1628 MSIHANDLE handle
= 0;
1629 IUnknown
*remote_unk
;
1630 IWineMsiRemotePackage
*remote_package
;
1632 TRACE("(%d)\n",hInstall
);
1634 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1637 handle
= alloc_msihandle( &package
->db
->hdr
);
1638 msiobj_release( &package
->hdr
);
1640 else if ((remote_unk
= msi_get_remote(hInstall
)))
1642 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1643 (LPVOID
*)&remote_package
) == S_OK
)
1645 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1646 IWineMsiRemotePackage_Release(remote_package
);
1650 WARN("remote handle %d is not a package\n", hInstall
);
1652 IUnknown_Release(remote_unk
);
1658 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1661 static const WCHAR szActionData
[] =
1662 {'A','c','t','i','o','n','D','a','t','a',0};
1663 static const WCHAR szSetProgress
[] =
1664 {'S','e','t','P','r','o','g','r','e','s','s',0};
1665 static const WCHAR szActionText
[] =
1666 {'A','c','t','i','o','n','T','e','x','t',0};
1668 DWORD sz
, total_size
= 0, log_type
= 0;
1673 TRACE("%x\n", eMessageType
);
1675 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1676 log_type
|= INSTALLLOGMODE_ERROR
;
1677 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1678 log_type
|= INSTALLLOGMODE_WARNING
;
1679 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1680 log_type
|= INSTALLLOGMODE_USER
;
1681 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1682 log_type
|= INSTALLLOGMODE_INFO
;
1683 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1684 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1685 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1686 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1687 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1688 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1690 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1693 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1695 static const WCHAR template_s
[]=
1696 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1697 static const WCHAR format
[] =
1698 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1700 LPCWSTR action_text
, action
;
1701 LPWSTR deformatted
= NULL
;
1703 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1705 action
= MSI_RecordGetString(record
, 1);
1706 action_text
= MSI_RecordGetString(record
, 2);
1708 if (!action
|| !action_text
)
1711 deformat_string(package
, action_text
, &deformatted
);
1713 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1715 len
+= strlenW(deformatted
);
1716 message
= msi_alloc(len
*sizeof(WCHAR
));
1717 sprintfW(message
, template_s
, timet
, action
);
1719 strcatW(message
, deformatted
);
1720 msi_free(deformatted
);
1725 message
= msi_alloc(1*sizeof (WCHAR
));
1727 msg_field
= MSI_RecordGetFieldCount(record
);
1728 for (i
= 1; i
<= msg_field
; i
++)
1732 static const WCHAR format
[] = { '%','i',':',' ',0};
1734 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1736 total_size
+=sz
*sizeof(WCHAR
);
1737 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1738 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1740 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1744 sprintfW(number
,format
,i
);
1745 strcatW(message
,number
);
1747 strcatW(message
,tmp
);
1749 strcatW(message
, szSpace
);
1755 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1756 gUIFilter
, log_type
, debugstr_w(message
));
1758 /* convert it to ASCII */
1759 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1760 msg
= msi_alloc( len
);
1761 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1763 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1765 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1767 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1769 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1771 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1773 MSIHANDLE rec
= MsiCreateRecord( 1 );
1774 MsiRecordSetStringW( rec
, 0, message
);
1775 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1776 MsiCloseHandle( rec
);
1779 if (!rc
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1780 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1783 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1784 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1787 msi_free( message
);
1789 switch (eMessageType
& 0xff000000)
1791 case INSTALLMESSAGE_ACTIONDATA
:
1792 /* FIXME: format record here instead of in ui_actiondata to get the
1793 * correct action data for external scripts */
1794 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1796 case INSTALLMESSAGE_ACTIONSTART
:
1800 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1802 deformat_string(package
, action_text
, &deformated
);
1803 uirow
= MSI_CreateRecord(1);
1804 MSI_RecordSetStringW(uirow
, 1, deformated
);
1805 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1806 msi_free(deformated
);
1808 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1810 msiobj_release(&uirow
->hdr
);
1813 case INSTALLMESSAGE_PROGRESS
:
1814 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1818 return ERROR_SUCCESS
;
1821 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1824 UINT ret
= ERROR_INVALID_HANDLE
;
1825 MSIPACKAGE
*package
= NULL
;
1826 MSIRECORD
*record
= NULL
;
1828 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1832 IWineMsiRemotePackage
*remote_package
;
1834 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1835 if (!remote_package
)
1836 return ERROR_INVALID_HANDLE
;
1838 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1840 IWineMsiRemotePackage_Release( remote_package
);
1844 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1845 return HRESULT_CODE(hr
);
1847 return ERROR_FUNCTION_FAILED
;
1850 return ERROR_SUCCESS
;
1853 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1857 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1860 msiobj_release( &package
->hdr
);
1862 msiobj_release( &record
->hdr
);
1869 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1871 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1872 UINT r
= ERROR_OUTOFMEMORY
;
1874 szwName
= strdupAtoW( szName
);
1875 if( szName
&& !szwName
)
1878 szwValue
= strdupAtoW( szValue
);
1879 if( szValue
&& !szwValue
)
1882 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1885 msi_free( szwName
);
1886 msi_free( szwValue
);
1891 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
1895 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
1899 msi_free( folder
->ResolvedSource
);
1900 folder
->ResolvedSource
= NULL
;
1904 msi_free( folder
->ResolvedTarget
);
1905 folder
->ResolvedTarget
= NULL
;
1910 UINT
msi_set_property( MSIDATABASE
*db
, LPCWSTR szName
, LPCWSTR szValue
)
1913 MSIRECORD
*row
= NULL
;
1918 static const WCHAR Insert
[] = {
1919 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1920 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1921 '`','_','P','r','o','p','e','r','t','y','`',',',
1922 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1923 ,' ','(','?',',','?',')',0};
1924 static const WCHAR Update
[] = {
1925 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1926 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1927 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1928 ' ','=',' ','\'','%','s','\'',0};
1929 static const WCHAR Delete
[] = {
1930 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1931 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1932 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1934 TRACE("%p %s %s\n", db
, debugstr_w(szName
), debugstr_w(szValue
));
1937 return ERROR_INVALID_PARAMETER
;
1939 /* this one is weird... */
1941 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1943 rc
= msi_get_property(db
, szName
, 0, &sz
);
1944 if (!szValue
|| !*szValue
)
1946 sprintfW(Query
, Delete
, szName
);
1948 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1950 sprintfW(Query
, Update
, szName
);
1952 row
= MSI_CreateRecord(1);
1953 MSI_RecordSetStringW(row
, 1, szValue
);
1957 strcpyW(Query
, Insert
);
1959 row
= MSI_CreateRecord(2);
1960 MSI_RecordSetStringW(row
, 1, szName
);
1961 MSI_RecordSetStringW(row
, 2, szValue
);
1964 rc
= MSI_DatabaseOpenViewW(db
, Query
, &view
);
1965 if (rc
== ERROR_SUCCESS
)
1967 rc
= MSI_ViewExecute(view
, row
);
1968 MSI_ViewClose(view
);
1969 msiobj_release(&view
->hdr
);
1973 msiobj_release(&row
->hdr
);
1978 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1980 MSIPACKAGE
*package
;
1983 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1987 BSTR name
= NULL
, value
= NULL
;
1988 IWineMsiRemotePackage
*remote_package
;
1990 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1991 if (!remote_package
)
1992 return ERROR_INVALID_HANDLE
;
1994 name
= SysAllocString( szName
);
1995 value
= SysAllocString( szValue
);
1996 if ((!name
&& szName
) || (!value
&& szValue
))
1998 SysFreeString( name
);
1999 SysFreeString( value
);
2000 IWineMsiRemotePackage_Release( remote_package
);
2001 return ERROR_OUTOFMEMORY
;
2004 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2006 SysFreeString( name
);
2007 SysFreeString( value
);
2008 IWineMsiRemotePackage_Release( remote_package
);
2012 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2013 return HRESULT_CODE(hr
);
2015 return ERROR_FUNCTION_FAILED
;
2018 return ERROR_SUCCESS
;
2021 ret
= msi_set_property( package
->db
, szName
, szValue
);
2022 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, cszSourceDir
))
2023 msi_reset_folders( package
, TRUE
);
2025 msiobj_release( &package
->hdr
);
2029 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2032 MSIRECORD
*rec
, *row
= NULL
;
2035 static const WCHAR query
[]= {
2036 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2037 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2038 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2041 if (!name
|| !*name
)
2044 rec
= MSI_CreateRecord(1);
2048 MSI_RecordSetStringW(rec
, 1, name
);
2050 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2051 if (r
== ERROR_SUCCESS
)
2053 MSI_ViewExecute(view
, rec
);
2054 MSI_ViewFetch(view
, &row
);
2055 MSI_ViewClose(view
);
2056 msiobj_release(&view
->hdr
);
2059 msiobj_release(&rec
->hdr
);
2063 /* internal function, not compatible with MsiGetPropertyW */
2064 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2065 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2068 UINT rc
= ERROR_FUNCTION_FAILED
;
2070 row
= msi_get_property_row( db
, szName
);
2072 if (*pchValueBuf
> 0)
2077 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2078 msiobj_release(&row
->hdr
);
2081 if (rc
== ERROR_SUCCESS
)
2082 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
2083 debugstr_w(szName
));
2084 else if (rc
== ERROR_MORE_DATA
)
2085 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2086 debugstr_w(szName
));
2090 TRACE("property %s not found\n", debugstr_w(szName
));
2096 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2102 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2103 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2107 str
= msi_alloc(sz
* sizeof(WCHAR
));
2108 r
= msi_get_property(db
, prop
, str
, &sz
);
2109 if (r
!= ERROR_SUCCESS
)
2118 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2120 LPWSTR str
= msi_dup_property( db
, prop
);
2121 int val
= str
? atoiW(str
) : def
;
2126 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2127 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2129 MSIPACKAGE
*package
;
2130 MSIRECORD
*row
= NULL
;
2131 UINT r
= ERROR_FUNCTION_FAILED
;
2134 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2135 szValueBuf
->str
.w
, pchValueBuf
);
2138 return ERROR_INVALID_PARAMETER
;
2140 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2144 IWineMsiRemotePackage
*remote_package
;
2145 LPWSTR value
= NULL
;
2149 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2150 if (!remote_package
)
2151 return ERROR_INVALID_HANDLE
;
2153 bname
= SysAllocString( name
);
2156 IWineMsiRemotePackage_Release( remote_package
);
2157 return ERROR_OUTOFMEMORY
;
2161 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2166 value
= msi_alloc(len
* sizeof(WCHAR
));
2169 r
= ERROR_OUTOFMEMORY
;
2173 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
2177 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
2179 /* Bug required by Adobe installers */
2180 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2181 *pchValueBuf
*= sizeof(WCHAR
);
2184 IWineMsiRemotePackage_Release(remote_package
);
2185 SysFreeString(bname
);
2190 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2191 return HRESULT_CODE(hr
);
2193 return ERROR_FUNCTION_FAILED
;
2199 row
= msi_get_property_row( package
->db
, name
);
2201 val
= MSI_RecordGetString( row
, 1 );
2206 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
2209 msiobj_release( &row
->hdr
);
2210 msiobj_release( &package
->hdr
);
2215 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2216 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2222 val
.unicode
= FALSE
;
2223 val
.str
.a
= szValueBuf
;
2225 name
= strdupAtoW( szName
);
2226 if (szName
&& !name
)
2227 return ERROR_OUTOFMEMORY
;
2229 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2234 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2235 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2240 val
.str
.w
= szValueBuf
;
2242 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2245 typedef struct _msi_remote_package_impl
{
2246 const IWineMsiRemotePackageVtbl
*lpVtbl
;
2249 } msi_remote_package_impl
;
2251 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
2253 return (msi_remote_package_impl
*) iface
;
2256 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2257 REFIID riid
,LPVOID
*ppobj
)
2259 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2260 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2262 IUnknown_AddRef( iface
);
2267 return E_NOINTERFACE
;
2270 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2272 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2274 return InterlockedIncrement( &This
->refs
);
2277 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2279 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2282 r
= InterlockedDecrement( &This
->refs
);
2285 MsiCloseHandle( This
->package
);
2291 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2293 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2294 This
->package
= handle
;
2298 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2300 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2301 IWineMsiRemoteDatabase
*rdb
= NULL
;
2305 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2306 if (FAILED(hr
) || !rdb
)
2308 ERR("Failed to create remote database\n");
2312 hdb
= MsiGetActiveDatabase(This
->package
);
2314 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2317 ERR("Failed to set the database handle\n");
2321 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2325 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
2327 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2330 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
2331 if (r
!= ERROR_SUCCESS
)
2332 return HRESULT_FROM_WIN32(r
);
2337 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2339 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2340 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2341 return HRESULT_FROM_WIN32(r
);
2344 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2346 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2347 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2348 return HRESULT_FROM_WIN32(r
);
2351 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2353 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2354 UINT r
= MsiDoActionW(This
->package
, action
);
2355 return HRESULT_FROM_WIN32(r
);
2358 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2360 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2361 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2362 return HRESULT_FROM_WIN32(r
);
2365 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2367 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2368 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2369 return HRESULT_FROM_WIN32(r
);
2372 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2374 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2375 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2376 return HRESULT_FROM_WIN32(r
);
2379 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2381 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2382 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2383 return HRESULT_FROM_WIN32(r
);
2386 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2388 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2389 *ret
= MsiGetMode(This
->package
, mode
);
2393 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2395 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2396 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2397 return HRESULT_FROM_WIN32(r
);
2400 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2401 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2403 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2404 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2405 return HRESULT_FROM_WIN32(r
);
2408 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2410 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2411 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2412 return HRESULT_FROM_WIN32(r
);
2415 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2416 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2418 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2419 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2420 return HRESULT_FROM_WIN32(r
);
2423 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2425 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2426 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2427 return HRESULT_FROM_WIN32(r
);
2430 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2432 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2433 *language
= MsiGetLanguage(This
->package
);
2437 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2439 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2440 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2441 return HRESULT_FROM_WIN32(r
);
2444 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2448 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2449 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2450 if (r
== ERROR_SUCCESS
)
2452 *value
= SysAllocStringLen(NULL
, size
);
2454 return E_OUTOFMEMORY
;
2456 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2458 return HRESULT_FROM_WIN32(r
);
2461 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2463 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2464 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2465 return HRESULT_FROM_WIN32(r
);
2468 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2469 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2471 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2472 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2473 return HRESULT_FROM_WIN32(r
);
2476 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2482 mrp_GetActiveDatabase
,
2493 mrp_GetFeatureState
,
2494 mrp_SetFeatureState
,
2495 mrp_GetComponentState
,
2496 mrp_SetComponentState
,
2498 mrp_SetInstallLevel
,
2500 mrp_EvaluateCondition
,
2504 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2506 msi_remote_package_impl
* This
;
2508 This
= msi_alloc( sizeof *This
);
2510 return E_OUTOFMEMORY
;
2512 This
->lpVtbl
= &msi_remote_package_vtbl
;
2521 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2522 LPCWSTR property
, LPWSTR value
)
2524 MSISOURCELISTINFO
*info
;
2526 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2528 return ERROR_OUTOFMEMORY
;
2530 info
->context
= context
;
2531 info
->options
= options
;
2532 info
->property
= property
;
2533 info
->value
= strdupW(value
);
2534 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2536 return ERROR_SUCCESS
;
2539 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2540 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2544 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2546 return ERROR_OUTOFMEMORY
;
2548 disk
->context
= context
;
2549 disk
->options
= options
;
2550 disk
->disk_id
= disk_id
;
2551 disk
->volume_label
= strdupW(volume_label
);
2552 disk
->disk_prompt
= strdupW(disk_prompt
);
2553 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2555 return ERROR_SUCCESS
;