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 DeleteFileW( temp
->Path
);
63 msi_free( temp
->Path
);
68 static void free_feature( MSIFEATURE
*feature
)
70 struct list
*item
, *cursor
;
72 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
74 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
75 list_remove( &fl
->entry
);
79 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
81 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
82 list_remove( &cl
->entry
);
85 msi_free( feature
->Feature
);
86 msi_free( feature
->Feature_Parent
);
87 msi_free( feature
->Directory
);
88 msi_free( feature
->Description
);
89 msi_free( feature
->Title
);
93 static void free_folder( MSIFOLDER
*folder
)
95 struct list
*item
, *cursor
;
97 LIST_FOR_EACH_SAFE( item
, cursor
, &folder
->children
)
99 FolderList
*fl
= LIST_ENTRY( item
, FolderList
, entry
);
100 list_remove( &fl
->entry
);
103 msi_free( folder
->Parent
);
104 msi_free( folder
->Directory
);
105 msi_free( folder
->TargetDefault
);
106 msi_free( folder
->SourceLongPath
);
107 msi_free( folder
->SourceShortPath
);
108 msi_free( folder
->ResolvedTarget
);
109 msi_free( folder
->ResolvedSource
);
113 static void free_extension( MSIEXTENSION
*ext
)
115 struct list
*item
, *cursor
;
117 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
119 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
121 list_remove( &verb
->entry
);
122 msi_free( verb
->Verb
);
123 msi_free( verb
->Command
);
124 msi_free( verb
->Argument
);
128 msi_free( ext
->Extension
);
129 msi_free( ext
->ProgIDText
);
133 static void free_assembly( MSIASSEMBLY
*assembly
)
135 msi_free( assembly
->feature
);
136 msi_free( assembly
->manifest
);
137 msi_free( assembly
->application
);
138 msi_free( assembly
->display_name
);
139 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
140 msi_free( assembly
->tempdir
);
141 msi_free( assembly
);
144 void msi_free_action_script( MSIPACKAGE
*package
, UINT script
)
147 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
148 msi_free( package
->script
->Actions
[script
][i
] );
150 msi_free( package
->script
->Actions
[script
] );
151 package
->script
->Actions
[script
] = NULL
;
152 package
->script
->ActionCount
[script
] = 0;
155 static void free_package_structures( MSIPACKAGE
*package
)
158 struct list
*item
, *cursor
;
160 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
162 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
163 list_remove( &feature
->entry
);
164 free_feature( feature
);
167 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
169 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
170 list_remove( &folder
->entry
);
171 free_folder( folder
);
174 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
176 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
178 list_remove( &comp
->entry
);
179 msi_free( comp
->Component
);
180 msi_free( comp
->ComponentId
);
181 msi_free( comp
->Directory
);
182 msi_free( comp
->Condition
);
183 msi_free( comp
->KeyPath
);
184 msi_free( comp
->FullKeypath
);
185 if (comp
->assembly
) free_assembly( comp
->assembly
);
189 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
191 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
193 list_remove( &file
->entry
);
194 msi_free( file
->File
);
195 msi_free( file
->FileName
);
196 msi_free( file
->ShortName
);
197 msi_free( file
->LongName
);
198 msi_free( file
->Version
);
199 msi_free( file
->Language
);
200 msi_free( file
->TargetPath
);
204 /* clean up extension, progid, class and verb structures */
205 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
207 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
209 list_remove( &cls
->entry
);
210 msi_free( cls
->clsid
);
211 msi_free( cls
->Context
);
212 msi_free( cls
->Description
);
213 msi_free( cls
->FileTypeMask
);
214 msi_free( cls
->IconPath
);
215 msi_free( cls
->DefInprocHandler
);
216 msi_free( cls
->DefInprocHandler32
);
217 msi_free( cls
->Argument
);
218 msi_free( cls
->ProgIDText
);
222 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
224 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
226 list_remove( &ext
->entry
);
227 free_extension( ext
);
230 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
232 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
234 list_remove( &progid
->entry
);
235 msi_free( progid
->ProgID
);
236 msi_free( progid
->Description
);
237 msi_free( progid
->IconPath
);
241 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
243 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
245 list_remove( &mt
->entry
);
246 msi_free( mt
->suffix
);
247 msi_free( mt
->clsid
);
248 msi_free( mt
->ContentType
);
252 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
254 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
256 list_remove( &appid
->entry
);
257 msi_free( appid
->AppID
);
258 msi_free( appid
->RemoteServerName
);
259 msi_free( appid
->LocalServer
);
260 msi_free( appid
->ServiceParameters
);
261 msi_free( appid
->DllSurrogate
);
265 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
267 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
269 list_remove( &info
->entry
);
270 msi_free( info
->value
);
274 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
276 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
278 list_remove( &info
->entry
);
279 msi_free( info
->volume_label
);
280 msi_free( info
->disk_prompt
);
286 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
287 msi_free_action_script( package
, i
);
289 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
290 msi_free( package
->script
->UniqueActions
[i
] );
292 msi_free( package
->script
->UniqueActions
);
293 msi_free( package
->script
);
296 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
298 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
300 list_remove( &patch
->entry
);
301 msi_free( patch
->patchcode
);
302 msi_free( patch
->transforms
);
303 msi_free( patch
->localfile
);
304 msi_free( patch
->filename
);
308 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->binaries
)
310 MSIBINARY
*binary
= LIST_ENTRY( item
, MSIBINARY
, entry
);
312 list_remove( &binary
->entry
);
314 FreeLibrary( binary
->module
);
315 if (!DeleteFileW( binary
->tmpfile
))
316 ERR("failed to delete %s (%u)\n", debugstr_w(binary
->tmpfile
), GetLastError());
317 msi_free( binary
->source
);
318 msi_free( binary
->tmpfile
);
322 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->cabinet_streams
)
324 MSICABINETSTREAM
*cab
= LIST_ENTRY( item
, MSICABINETSTREAM
, entry
);
326 list_remove( &cab
->entry
);
327 IStorage_Release( cab
->storage
);
328 msi_free( cab
->stream
);
332 msi_free( package
->BaseURL
);
333 msi_free( package
->PackagePath
);
334 msi_free( package
->ProductCode
);
335 msi_free( package
->ActionFormat
);
336 msi_free( package
->LastAction
);
337 msi_free( package
->langids
);
339 remove_tracked_tempfiles(package
);
341 /* cleanup control event subscriptions */
342 ControlEvent_CleanupSubscriptions( package
);
345 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
348 MSIPACKAGE
*package
= (MSIPACKAGE
*)arg
;
350 if( package
->dialog
)
351 msi_dialog_destroy( package
->dialog
);
353 msiobj_release( &package
->db
->hdr
);
354 free_package_structures(package
);
355 CloseHandle( package
->log_file
);
357 for (i
= 0; i
< CLR_VERSION_MAX
; i
++)
358 if (package
->cache_net
[i
]) IAssemblyCache_Release( package
->cache_net
[i
] );
359 if (package
->cache_sxs
) IAssemblyCache_Release( package
->cache_sxs
);
361 if (package
->localfile
)
363 DeleteFileW( package
->localfile
);
364 msi_free( package
->localfile
);
368 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
370 static const WCHAR query
[] = {
371 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
372 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
373 '`','_','P','r','o','p','e','r','t','y','`',' ',
374 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
375 'T','E','M','P','O','R','A','R','Y',',',' ',
376 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
377 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
378 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
379 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
383 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
384 if (rc
!= ERROR_SUCCESS
)
387 rc
= MSI_ViewExecute(view
, 0);
389 msiobj_release(&view
->hdr
);
393 UINT
msi_clone_properties(MSIPACKAGE
*package
)
395 static const WCHAR query_select
[] = {
396 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
397 '`','P','r','o','p','e','r','t','y','`',0};
398 static const WCHAR query_insert
[] = {
399 'I','N','S','E','R','T',' ','I','N','T','O',' ',
400 '`','_','P','r','o','p','e','r','t','y','`',' ',
401 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
402 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
403 static const WCHAR query_update
[] = {
404 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
405 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
406 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
407 MSIQUERY
*view_select
;
410 rc
= MSI_DatabaseOpenViewW( package
->db
, query_select
, &view_select
);
411 if (rc
!= ERROR_SUCCESS
)
414 rc
= MSI_ViewExecute( view_select
, 0 );
415 if (rc
!= ERROR_SUCCESS
)
417 MSI_ViewClose( view_select
);
418 msiobj_release( &view_select
->hdr
);
424 MSIQUERY
*view_insert
, *view_update
;
425 MSIRECORD
*rec_select
;
427 rc
= MSI_ViewFetch( view_select
, &rec_select
);
428 if (rc
!= ERROR_SUCCESS
)
431 rc
= MSI_DatabaseOpenViewW( package
->db
, query_insert
, &view_insert
);
432 if (rc
!= ERROR_SUCCESS
)
434 msiobj_release( &rec_select
->hdr
);
438 rc
= MSI_ViewExecute( view_insert
, rec_select
);
439 MSI_ViewClose( view_insert
);
440 msiobj_release( &view_insert
->hdr
);
441 if (rc
!= ERROR_SUCCESS
)
443 MSIRECORD
*rec_update
;
445 TRACE("insert failed, trying update\n");
447 rc
= MSI_DatabaseOpenViewW( package
->db
, query_update
, &view_update
);
448 if (rc
!= ERROR_SUCCESS
)
450 WARN("open view failed %u\n", rc
);
451 msiobj_release( &rec_select
->hdr
);
455 rec_update
= MSI_CreateRecord( 2 );
456 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
457 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
458 rc
= MSI_ViewExecute( view_update
, rec_update
);
459 if (rc
!= ERROR_SUCCESS
)
460 WARN("update failed %u\n", rc
);
462 MSI_ViewClose( view_update
);
463 msiobj_release( &view_update
->hdr
);
464 msiobj_release( &rec_update
->hdr
);
467 msiobj_release( &rec_select
->hdr
);
470 MSI_ViewClose( view_select
);
471 msiobj_release( &view_select
->hdr
);
478 * Sets the "Installed" property to indicate that
479 * the product is installed for the current user.
481 static UINT
set_installed_prop( MSIPACKAGE
*package
)
486 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
488 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
489 if (r
== ERROR_SUCCESS
)
492 msi_set_property( package
->db
, szInstalled
, szOne
);
497 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
501 LPWSTR sid_str
= NULL
, dom
= NULL
;
502 DWORD size
, dom_size
;
504 UINT r
= ERROR_FUNCTION_FAILED
;
507 GetUserNameW( NULL
, &size
);
509 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
511 return ERROR_OUTOFMEMORY
;
513 if (!GetUserNameW( user_name
, &size
))
518 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
520 psid
= msi_alloc( size
);
521 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
524 r
= ERROR_OUTOFMEMORY
;
528 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
531 if (!ConvertSidToStringSidW( psid
, &sid_str
))
534 r
= msi_set_property( package
->db
, szUserSID
, sid_str
);
537 LocalFree( sid_str
);
540 msi_free( user_name
);
545 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
550 DWORD index
= 0, size
;
552 WCHAR name
[MAX_PATH
];
553 WCHAR windir
[MAX_PATH
];
555 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
556 static const WCHAR sub
[] = {
557 'S','o','f','t','w','a','r','e','\\',
558 'M','i','c','r','o','s','o','f','t','\\',
559 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
562 static const WCHAR subdir
[] = {
563 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
564 'F','r','a','m','e','w','o','r','k','\\',0
567 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
568 if (res
!= ERROR_SUCCESS
)
571 GetWindowsDirectoryW(windir
, MAX_PATH
);
575 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
579 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
580 if (strcmpW( ver
, name
) < 0)
583 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
584 check
= msi_alloc(size
* sizeof(WCHAR
));
592 lstrcpyW(check
, windir
);
593 lstrcatW(check
, szBackSlash
);
594 lstrcatW(check
, subdir
);
595 lstrcatW(check
, name
);
596 lstrcatW(check
, szBackSlash
);
597 lstrcatW(check
, fusion
);
599 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
610 RegCloseKey(netsetup
);
614 typedef struct tagLANGANDCODEPAGE
620 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
624 LPVOID version
= NULL
;
626 LPWSTR fusion
, verstr
;
627 LANGANDCODEPAGE
*translate
;
629 static const WCHAR netasm
[] = {
630 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
632 static const WCHAR translation
[] = {
633 '\\','V','a','r','F','i','l','e','I','n','f','o',
634 '\\','T','r','a','n','s','l','a','t','i','o','n',0
636 static const WCHAR verfmt
[] = {
637 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
638 '\\','%','0','4','x','%','0','4','x',
639 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
642 fusion
= get_fusion_filename(package
);
646 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
649 version
= msi_alloc(size
);
650 if (!version
) return;
652 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
655 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
658 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
660 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
663 if (!val_len
|| !verstr
)
666 msi_set_property(package
->db
, netasm
, verstr
);
673 static VOID
set_installer_properties(MSIPACKAGE
*package
)
677 OSVERSIONINFOEXW OSVersion
;
680 WCHAR verstr
[10], bufstr
[20];
683 LPWSTR username
, companyname
;
684 SYSTEM_INFO sys_info
;
685 SYSTEMTIME systemtime
;
688 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
689 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
690 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
691 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
692 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
693 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
694 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
695 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
696 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
697 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
698 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
699 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
700 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
701 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
702 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
703 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
704 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
705 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
706 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
707 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
708 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
709 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
710 static const WCHAR szFormat
[] = {'%','l','i',0};
711 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
712 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
713 static const WCHAR szSix
[] = {'6',0 };
714 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
715 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
716 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
717 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
718 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
719 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
720 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
721 static const WCHAR szIntFormat
[] = {'%','d',0};
722 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
723 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
724 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
725 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
726 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 };
727 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
728 static const WCHAR szUserInfo
[] = {
729 'S','O','F','T','W','A','R','E','\\',
730 'M','i','c','r','o','s','o','f','t','\\',
731 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
732 'U','s','e','r',' ','I','n','f','o',0
734 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
735 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
736 static const WCHAR szCurrentVersion
[] = {
737 'S','O','F','T','W','A','R','E','\\',
738 'M','i','c','r','o','s','o','f','t','\\',
739 'W','i','n','d','o','w','s',' ','N','T','\\',
740 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
742 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
743 static const WCHAR szRegisteredOrganization
[] = {
744 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
746 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
747 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
748 static const WCHAR szDate
[] = {'D','a','t','e',0};
749 static const WCHAR szTime
[] = {'T','i','m','e',0};
750 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
751 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
752 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
753 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
754 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
755 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
756 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
759 * Other things that probably should be set:
761 * ComputerName VirtualMemory
762 * ShellAdvSupport DefaultUIFont PackagecodeChanging
763 * CaptionHeight BorderTop BorderSide TextHeight
764 * RedirectedDllSupport
767 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
768 strcatW(pth
, szBackSlash
);
769 msi_set_property(package
->db
, szCommonAppDataFolder
, pth
);
771 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
772 strcatW(pth
, szBackSlash
);
773 msi_set_property(package
->db
, szFavoritesFolder
, pth
);
775 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
776 strcatW(pth
, szBackSlash
);
777 msi_set_property(package
->db
, szFontsFolder
, pth
);
779 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
780 strcatW(pth
, szBackSlash
);
781 msi_set_property(package
->db
, szSendToFolder
, pth
);
783 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
784 strcatW(pth
, szBackSlash
);
785 msi_set_property(package
->db
, szStartMenuFolder
, pth
);
787 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
788 strcatW(pth
, szBackSlash
);
789 msi_set_property(package
->db
, szStartupFolder
, pth
);
791 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
792 strcatW(pth
, szBackSlash
);
793 msi_set_property(package
->db
, szTemplateFolder
, pth
);
795 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
796 strcatW(pth
, szBackSlash
);
797 msi_set_property(package
->db
, szDesktopFolder
, pth
);
799 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
800 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
801 strcatW(pth
, szBackSlash
);
802 msi_set_property(package
->db
, szProgramMenuFolder
, pth
);
804 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
805 strcatW(pth
, szBackSlash
);
806 msi_set_property(package
->db
, szAdminToolsFolder
, pth
);
808 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
809 strcatW(pth
, szBackSlash
);
810 msi_set_property(package
->db
, szAppDataFolder
, pth
);
812 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
813 strcatW(pth
, szBackSlash
);
814 msi_set_property(package
->db
, szSystemFolder
, pth
);
815 msi_set_property(package
->db
, szSystem16Folder
, pth
);
817 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
818 strcatW(pth
, szBackSlash
);
819 msi_set_property(package
->db
, szLocalAppDataFolder
, pth
);
821 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
822 strcatW(pth
, szBackSlash
);
823 msi_set_property(package
->db
, szMyPicturesFolder
, pth
);
825 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
826 strcatW(pth
, szBackSlash
);
827 msi_set_property(package
->db
, szPersonalFolder
, pth
);
829 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
830 strcatW(pth
, szBackSlash
);
831 msi_set_property(package
->db
, szWindowsFolder
, pth
);
833 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
834 strcatW(pth
, szBackSlash
);
835 msi_set_property(package
->db
, szPrintHoodFolder
, pth
);
837 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
838 strcatW(pth
, szBackSlash
);
839 msi_set_property(package
->db
, szNetHoodFolder
, pth
);
841 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
842 strcatW(pth
, szBackSlash
);
843 msi_set_property(package
->db
, szRecentFolder
, pth
);
845 /* Physical Memory is specified in MB. Using total amount. */
846 msex
.dwLength
= sizeof(msex
);
847 GlobalMemoryStatusEx( &msex
);
848 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
849 msi_set_property(package
->db
, szPhysicalMemory
, bufstr
);
851 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
852 ptr
= strchrW(pth
,'\\');
853 if (ptr
) *(ptr
+ 1) = 0;
854 msi_set_property(package
->db
, szWindowsVolume
, pth
);
856 GetTempPathW(MAX_PATH
,pth
);
857 msi_set_property(package
->db
, szTempFolder
, pth
);
859 /* in a wine environment the user is always admin and privileged */
860 msi_set_property(package
->db
, szAdminUser
, szOne
);
861 msi_set_property(package
->db
, szPrivileged
, szOne
);
863 /* set the os things */
864 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
865 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
866 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
867 sprintfW(verstr
, szFormat
, verval
);
868 switch (OSVersion
.dwPlatformId
)
870 case VER_PLATFORM_WIN32_WINDOWS
:
871 msi_set_property(package
->db
, szVersion9x
, verstr
);
873 case VER_PLATFORM_WIN32_NT
:
874 msi_set_property(package
->db
, szVersionNT
, verstr
);
875 sprintfW(verstr
, szFormat
,OSVersion
.wProductType
);
876 msi_set_property(package
->db
, szMsiNTProductType
, verstr
);
879 sprintfW(verstr
, szFormat
, OSVersion
.dwBuildNumber
);
880 msi_set_property(package
->db
, szWindowsBuild
, verstr
);
881 /* just fudge this */
882 msi_set_property(package
->db
, szServicePackLevel
, szSix
);
884 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
885 msi_set_property( package
->db
, szVersionMsi
, bufstr
);
886 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
887 msi_set_property( package
->db
, szVersionDatabase
, bufstr
);
889 GetNativeSystemInfo( &sys_info
);
890 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
891 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
893 msi_set_property( package
->db
, szIntel
, bufstr
);
895 GetSystemDirectoryW( pth
, MAX_PATH
);
896 PathAddBackslashW( pth
);
897 msi_set_property( package
->db
, szSystemFolder
, pth
);
899 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
900 PathAddBackslashW( pth
);
901 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
903 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
904 PathAddBackslashW( pth
);
905 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
907 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
909 msi_set_property( package
->db
, szMsiAMD64
, bufstr
);
910 msi_set_property( package
->db
, szMsix64
, bufstr
);
911 msi_set_property( package
->db
, szVersionNT64
, verstr
);
913 GetSystemDirectoryW( pth
, MAX_PATH
);
914 PathAddBackslashW( pth
);
915 msi_set_property( package
->db
, szSystem64Folder
, pth
);
917 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
918 PathAddBackslashW( pth
);
919 msi_set_property( package
->db
, szSystemFolder
, pth
);
921 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
922 PathAddBackslashW( pth
);
923 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
);
925 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
926 PathAddBackslashW( pth
);
927 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
929 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
930 PathAddBackslashW( pth
);
931 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
);
933 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
934 PathAddBackslashW( pth
);
935 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
938 /* Screen properties. */
940 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
941 msi_set_property( package
->db
, szScreenX
, bufstr
);
942 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
943 msi_set_property( package
->db
, szScreenY
, bufstr
);
944 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
945 msi_set_property( package
->db
, szColorBits
, bufstr
);
948 /* USERNAME and COMPANYNAME */
949 username
= msi_dup_property( package
->db
, szUSERNAME
);
950 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
952 if ((!username
|| !companyname
) &&
953 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
956 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
957 msi_set_property( package
->db
, szUSERNAME
, username
);
959 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
960 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
963 if ((!username
|| !companyname
) &&
964 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
967 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
968 msi_set_property( package
->db
, szUSERNAME
, username
);
970 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
971 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
974 msi_free( username
);
975 msi_free( companyname
);
977 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
978 ERR("Failed to set the UserSID property\n");
980 /* Date and time properties */
981 GetSystemTime( &systemtime
);
982 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
983 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
984 msi_set_property( package
->db
, szDate
, bufstr
);
986 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
988 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
989 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
990 &systemtime
, NULL
, bufstr
,
991 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
992 msi_set_property( package
->db
, szTime
, bufstr
);
994 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
996 set_msi_assembly_prop( package
);
998 langid
= GetUserDefaultLangID();
999 sprintfW(bufstr
, szIntFormat
, langid
);
1000 msi_set_property( package
->db
, szUserLanguageID
, bufstr
);
1002 langid
= GetSystemDefaultLangID();
1003 sprintfW(bufstr
, szIntFormat
, langid
);
1004 msi_set_property( package
->db
, szSystemLangID
, bufstr
);
1006 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
1007 msi_set_property( package
->db
, szProductState
, bufstr
);
1010 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1013 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
1015 if (GetUserNameW( username
, &len
))
1016 msi_set_property( package
->db
, szLogonUser
, username
);
1017 msi_free( username
);
1022 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
1026 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
1029 LPWSTR package_code
;
1030 static const WCHAR szPackageCode
[] = {
1031 'P','a','c','k','a','g','e','C','o','d','e',0};
1034 ERR("Unable to allocate handle\n");
1035 return ERROR_OUTOFMEMORY
;
1038 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
1039 MsiCloseHandle(hdb
);
1040 if (rc
!= ERROR_SUCCESS
)
1042 ERR("Unable to open Summary Information\n");
1046 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
1047 &count
, NULL
, NULL
, NULL
);
1048 if (rc
!= ERROR_SUCCESS
)
1050 WARN("Unable to query page count: %d\n", rc
);
1054 /* load package code property */
1056 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1057 NULL
, NULL
, NULL
, &len
);
1058 if (rc
!= ERROR_MORE_DATA
)
1060 WARN("Unable to query revision number: %d\n", rc
);
1061 rc
= ERROR_FUNCTION_FAILED
;
1066 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
1067 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1068 NULL
, NULL
, package_code
, &len
);
1069 if (rc
!= ERROR_SUCCESS
)
1071 WARN("Unable to query rev number: %d\n", rc
);
1075 msi_set_property( package
->db
, szPackageCode
, package_code
);
1076 msi_free( package_code
);
1078 /* load package attributes */
1080 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
1081 &count
, NULL
, NULL
, NULL
);
1082 package
->WordCount
= count
;
1085 MsiCloseHandle(suminfo
);
1089 static MSIPACKAGE
*msi_alloc_package( void )
1091 MSIPACKAGE
*package
;
1093 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1097 list_init( &package
->components
);
1098 list_init( &package
->features
);
1099 list_init( &package
->files
);
1100 list_init( &package
->filepatches
);
1101 list_init( &package
->tempfiles
);
1102 list_init( &package
->folders
);
1103 list_init( &package
->subscriptions
);
1104 list_init( &package
->appids
);
1105 list_init( &package
->classes
);
1106 list_init( &package
->mimes
);
1107 list_init( &package
->extensions
);
1108 list_init( &package
->progids
);
1109 list_init( &package
->RunningActions
);
1110 list_init( &package
->sourcelist_info
);
1111 list_init( &package
->sourcelist_media
);
1112 list_init( &package
->patches
);
1113 list_init( &package
->binaries
);
1114 list_init( &package
->cabinet_streams
);
1120 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1125 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1127 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1128 if (r
!= ERROR_SUCCESS
)
1131 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1137 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1139 /* FIXME: this should depend on the user's privileges */
1140 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1142 TRACE("resetting ALLUSERS property from 2 to 1\n");
1143 msi_set_property( package
->db
, szAllUsers
, szOne
);
1145 msi_set_property( package
->db
, szAdminUser
, szOne
);
1148 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1150 static const WCHAR szpi
[] = {'%','i',0};
1151 MSIPACKAGE
*package
;
1157 package
= msi_alloc_package();
1160 msiobj_addref( &db
->hdr
);
1163 package
->WordCount
= 0;
1164 package
->PackagePath
= strdupW( db
->path
);
1165 package
->BaseURL
= strdupW( base_url
);
1167 create_temp_property_table( package
);
1168 msi_clone_properties( package
);
1169 msi_adjust_privilege_properties( package
);
1171 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1172 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1174 set_installed_prop( package
);
1175 set_installer_properties( package
);
1177 sprintfW(uilevel
,szpi
,gUILevel
);
1178 msi_set_property(package
->db
, szUILevel
, uilevel
);
1180 r
= msi_load_summary_properties( package
);
1181 if (r
!= ERROR_SUCCESS
)
1183 msiobj_release( &package
->hdr
);
1187 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1188 msi_load_admin_properties( package
);
1190 package
->log_file
= INVALID_HANDLE_VALUE
;
1197 * copy_package_to_temp [internal]
1199 * copy the msi file to a temp file to prevent locking a CD
1200 * with a multi disc install
1202 * FIXME: I think this is wrong, and instead of copying the package,
1203 * we should read all the tables to memory, then open the
1204 * database to read binary streams on demand.
1206 static UINT
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
1208 WCHAR path
[MAX_PATH
];
1210 GetTempPathW( MAX_PATH
, path
);
1211 GetTempFileNameW( path
, szMsi
, 0, filename
);
1213 if( !CopyFileW( szPackage
, filename
, FALSE
) )
1215 UINT error
= GetLastError();
1216 if ( error
== ERROR_FILE_NOT_FOUND
)
1217 ERR("can't find %s\n", debugstr_w(szPackage
));
1219 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage
), debugstr_w(filename
), error
);
1220 DeleteFileW( filename
);
1224 return ERROR_SUCCESS
;
1227 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1229 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1233 /* call will always fail, because size is 0,
1234 * but will return ERROR_FILE_NOT_FOUND first
1235 * if the file doesn't exist
1237 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1238 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1240 cache_entry
= msi_alloc( size
);
1241 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1243 UINT error
= GetLastError();
1244 msi_free( cache_entry
);
1248 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1249 msi_free( cache_entry
);
1250 return ERROR_SUCCESS
;
1253 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1256 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1257 return ERROR_FUNCTION_FAILED
;
1260 return ERROR_SUCCESS
;
1263 UINT
msi_get_local_package_name( LPWSTR path
, LPCWSTR suffix
)
1265 static const WCHAR szInstaller
[] = {
1266 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1267 static const WCHAR fmt
[] = {'%','x',0};
1268 DWORD time
, len
, i
, offset
;
1271 time
= GetTickCount();
1272 GetWindowsDirectoryW( path
, MAX_PATH
);
1273 strcatW( path
, szInstaller
);
1274 CreateDirectoryW( path
, NULL
);
1276 len
= strlenW(path
);
1277 for (i
= 0; i
< 0x10000; i
++)
1279 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1280 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1281 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1282 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1283 if (handle
!= INVALID_HANDLE_VALUE
)
1285 CloseHandle(handle
);
1288 if (GetLastError() != ERROR_FILE_EXISTS
&&
1289 GetLastError() != ERROR_SHARING_VIOLATION
)
1290 return ERROR_FUNCTION_FAILED
;
1293 return ERROR_SUCCESS
;
1296 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1298 WCHAR
*template, *p
, *q
;
1301 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1302 TRACE("version: %d\n", package
->version
);
1304 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1306 return ERROR_SUCCESS
; /* native accepts missing template property */
1308 TRACE("template: %s\n", debugstr_w(template));
1310 p
= strchrW( template, ';' );
1313 WARN("invalid template string %s\n", debugstr_w(template));
1314 msi_free( template );
1315 return ERROR_PATCH_PACKAGE_INVALID
;
1318 if (!template[0] || !strcmpW( template, szIntel
))
1319 package
->platform
= PLATFORM_INTEL
;
1320 else if (!strcmpW( template, szIntel64
))
1321 package
->platform
= PLATFORM_INTEL64
;
1322 else if (!strcmpW( template, szX64
) || !strcmpW( template, szAMD64
))
1323 package
->platform
= PLATFORM_X64
;
1326 WARN("unknown platform %s\n", debugstr_w(template));
1327 msi_free( template );
1328 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1333 msi_free( template );
1334 return ERROR_SUCCESS
;
1337 for (q
= p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1339 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1340 if (!package
->langids
)
1342 msi_free( template );
1343 return ERROR_OUTOFMEMORY
;
1349 q
= strchrW( p
, ',' );
1351 package
->langids
[i
] = atoiW( p
);
1356 package
->num_langids
= i
+ 1;
1358 msi_free( template );
1359 return ERROR_SUCCESS
;
1362 static UINT
validate_package( MSIPACKAGE
*package
)
1367 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1368 if (package
->platform
== PLATFORM_X64
)
1370 if (!is_64bit
&& !is_wow64
)
1371 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1372 if (package
->version
< 200)
1373 return ERROR_INSTALL_PACKAGE_INVALID
;
1375 if (!package
->num_langids
)
1377 return ERROR_SUCCESS
;
1379 for (i
= 0; i
< package
->num_langids
; i
++)
1381 LANGID langid
= package
->langids
[i
];
1383 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1385 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1387 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1389 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1391 if (IsValidLocale( langid
, LCID_INSTALLED
))
1392 return ERROR_SUCCESS
;
1394 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1397 int msi_track_tempfile( MSIPACKAGE
*package
, const WCHAR
*path
)
1401 TRACE("%s\n", debugstr_w(path
));
1403 LIST_FOR_EACH_ENTRY( temp
, &package
->tempfiles
, MSITEMPFILE
, entry
)
1405 if (!strcmpW( path
, temp
->Path
)) return 0;
1407 if (!(temp
= msi_alloc_zero( sizeof (MSITEMPFILE
) ))) return -1;
1408 list_add_head( &package
->tempfiles
, &temp
->entry
);
1409 temp
->Path
= strdupW( path
);
1413 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1415 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1416 MSIDATABASE
*db
= NULL
;
1417 MSIPACKAGE
*package
;
1419 LPWSTR ptr
, base_url
= NULL
;
1421 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1422 LPCWSTR file
= szPackage
;
1426 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1428 if( szPackage
[0] == '#' )
1430 handle
= atoiW(&szPackage
[1]);
1431 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1434 IWineMsiRemoteDatabase
*remote_database
;
1436 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1437 if ( !remote_database
)
1438 return ERROR_INVALID_HANDLE
;
1440 IWineMsiRemoteDatabase_Release( remote_database
);
1441 WARN("MsiOpenPackage not allowed during a custom action!\n");
1443 return ERROR_FUNCTION_FAILED
;
1448 if ( UrlIsW( szPackage
, URLIS_URL
) )
1450 r
= msi_download_file( szPackage
, cachefile
);
1451 if ( r
!= ERROR_SUCCESS
)
1454 r
= copy_package_to_temp( cachefile
, temppath
);
1455 if ( r
!= ERROR_SUCCESS
)
1460 base_url
= strdupW( szPackage
);
1462 return ERROR_OUTOFMEMORY
;
1464 ptr
= strrchrW( base_url
, '/' );
1465 if (ptr
) *(ptr
+ 1) = '\0';
1469 r
= copy_package_to_temp( szPackage
, temppath
);
1470 if ( r
!= ERROR_SUCCESS
)
1475 TRACE("Opening relocated package %s\n", debugstr_w( file
));
1477 /* transforms that add binary streams require that we open the database
1478 * read/write, which is safe because we always create a copy that is thrown
1479 * away when we're done.
1481 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_TRANSACT
, &db
);
1482 if( r
!= ERROR_SUCCESS
)
1484 if (file
!= szPackage
)
1485 DeleteFileW( file
);
1487 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
1488 return ERROR_FILE_NOT_FOUND
;
1494 r
= msi_get_local_package_name( localfile
, dotmsi
);
1495 if (r
!= ERROR_SUCCESS
)
1498 package
= MSI_CreatePackage( db
, base_url
);
1499 msi_free( base_url
);
1500 msiobj_release( &db
->hdr
);
1503 if (file
!= szPackage
)
1504 DeleteFileW( file
);
1506 return ERROR_INSTALL_PACKAGE_INVALID
;
1508 if (file
!= szPackage
) msi_track_tempfile( package
, file
);
1509 package
->localfile
= strdupW( localfile
);
1511 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1514 WARN("failed to load summary info\n");
1515 msiobj_release( &package
->hdr
);
1516 return ERROR_INSTALL_PACKAGE_INVALID
;
1519 r
= msi_parse_summary( si
, package
);
1520 msiobj_release( &si
->hdr
);
1521 if (r
!= ERROR_SUCCESS
)
1523 WARN("failed to parse summary info %u\n", r
);
1524 msiobj_release( &package
->hdr
);
1528 r
= validate_package( package
);
1529 if (r
!= ERROR_SUCCESS
)
1531 msiobj_release( &package
->hdr
);
1534 msi_set_property( package
->db
, szDatabase
, db
->path
);
1536 if( UrlIsW( szPackage
, URLIS_URL
) )
1537 msi_set_property( package
->db
, szOriginalDatabase
, szPackage
);
1538 else if( szPackage
[0] == '#' )
1539 msi_set_property( package
->db
, szOriginalDatabase
, db
->path
);
1542 WCHAR fullpath
[MAX_PATH
];
1544 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1545 msi_set_property( package
->db
, szOriginalDatabase
, fullpath
);
1548 msi_set_context( package
);
1552 WCHAR patch_code
[GUID_SIZE
];
1553 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1554 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1555 if (r
!= ERROR_SUCCESS
)
1558 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1560 r
= msi_apply_registered_patch( package
, patch_code
);
1561 if (r
!= ERROR_SUCCESS
)
1563 ERR("registered patch failed to apply %u\n", r
);
1564 msiobj_release( &package
->hdr
);
1573 msi_clone_properties( package
);
1574 msi_adjust_privilege_properties( package
);
1578 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1579 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1581 *pPackage
= package
;
1582 return ERROR_SUCCESS
;
1585 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1587 MSIPACKAGE
*package
= NULL
;
1590 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1592 if( !szPackage
|| !phPackage
)
1593 return ERROR_INVALID_PARAMETER
;
1597 FIXME("Should create an empty database and package\n");
1598 return ERROR_FUNCTION_FAILED
;
1602 FIXME("dwOptions %08x not supported\n", dwOptions
);
1604 ret
= MSI_OpenPackageW( szPackage
, &package
);
1605 if( ret
== ERROR_SUCCESS
)
1607 *phPackage
= alloc_msihandle( &package
->hdr
);
1609 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1610 msiobj_release( &package
->hdr
);
1616 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1618 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1621 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1623 LPWSTR szwPack
= NULL
;
1628 szwPack
= strdupAtoW( szPackage
);
1630 return ERROR_OUTOFMEMORY
;
1633 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1635 msi_free( szwPack
);
1640 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1642 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1645 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1647 MSIPACKAGE
*package
;
1648 MSIHANDLE handle
= 0;
1649 IUnknown
*remote_unk
;
1650 IWineMsiRemotePackage
*remote_package
;
1652 TRACE("(%d)\n",hInstall
);
1654 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1657 handle
= alloc_msihandle( &package
->db
->hdr
);
1658 msiobj_release( &package
->hdr
);
1660 else if ((remote_unk
= msi_get_remote(hInstall
)))
1662 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1663 (LPVOID
*)&remote_package
) == S_OK
)
1665 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1666 IWineMsiRemotePackage_Release(remote_package
);
1670 WARN("remote handle %d is not a package\n", hInstall
);
1672 IUnknown_Release(remote_unk
);
1678 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1680 static const WCHAR szActionData
[] =
1681 {'A','c','t','i','o','n','D','a','t','a',0};
1682 static const WCHAR szSetProgress
[] =
1683 {'S','e','t','P','r','o','g','r','e','s','s',0};
1684 static const WCHAR szActionText
[] =
1685 {'A','c','t','i','o','n','T','e','x','t',0};
1687 DWORD i
, len
, total_len
, log_type
= 0;
1691 TRACE("%x\n", eMessageType
);
1693 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1694 log_type
|= INSTALLLOGMODE_ERROR
;
1695 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1696 log_type
|= INSTALLLOGMODE_WARNING
;
1697 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1698 log_type
|= INSTALLLOGMODE_USER
;
1699 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1700 log_type
|= INSTALLLOGMODE_INFO
;
1701 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1702 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1703 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1704 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1705 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1706 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1708 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1711 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1713 static const WCHAR template_s
[]=
1714 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1715 static const WCHAR format
[] =
1716 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1718 LPCWSTR action_text
, action
;
1719 LPWSTR deformatted
= NULL
;
1721 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1723 action
= MSI_RecordGetString(record
, 1);
1724 action_text
= MSI_RecordGetString(record
, 2);
1726 if (!action
|| !action_text
)
1729 deformat_string(package
, action_text
, &deformatted
);
1731 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1733 len
+= strlenW(deformatted
);
1734 message
= msi_alloc(len
*sizeof(WCHAR
));
1735 sprintfW(message
, template_s
, timet
, action
);
1737 strcatW(message
, deformatted
);
1738 msi_free(deformatted
);
1742 static const WCHAR format
[] = {'%','u',':',' ',0};
1743 UINT count
= MSI_RecordGetFieldCount( record
);
1747 for (i
= 1; i
<= count
; i
++)
1750 MSI_RecordGetStringW( record
, i
, NULL
, &len
);
1751 total_len
+= len
+ 13;
1753 p
= message
= msi_alloc( total_len
* sizeof(WCHAR
) );
1754 if (!p
) return ERROR_OUTOFMEMORY
;
1756 for (i
= 1; i
<= count
; i
++)
1760 len
= sprintfW( p
, format
, i
);
1765 MSI_RecordGetStringW( record
, i
, p
, &len
);
1768 if (count
> 1 && total_len
)
1777 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1778 gUIFilter
, log_type
, debugstr_w(message
));
1780 /* convert it to ASCII */
1781 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1782 msg
= msi_alloc( len
);
1783 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1785 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1787 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1789 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1791 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1793 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1795 MSIHANDLE rec
= MsiCreateRecord( 1 );
1796 MsiRecordSetStringW( rec
, 0, message
);
1797 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1798 MsiCloseHandle( rec
);
1801 if (!rc
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1802 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1805 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1806 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1809 msi_free( message
);
1811 switch (eMessageType
& 0xff000000)
1813 case INSTALLMESSAGE_ACTIONDATA
:
1814 /* FIXME: format record here instead of in ui_actiondata to get the
1815 * correct action data for external scripts */
1816 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1818 case INSTALLMESSAGE_ACTIONSTART
:
1822 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1824 deformat_string(package
, action_text
, &deformated
);
1825 uirow
= MSI_CreateRecord(1);
1826 MSI_RecordSetStringW(uirow
, 1, deformated
);
1827 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1828 msi_free(deformated
);
1830 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1832 msiobj_release(&uirow
->hdr
);
1835 case INSTALLMESSAGE_PROGRESS
:
1836 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1840 return ERROR_SUCCESS
;
1843 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1846 UINT ret
= ERROR_INVALID_HANDLE
;
1847 MSIPACKAGE
*package
= NULL
;
1848 MSIRECORD
*record
= NULL
;
1850 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1854 IWineMsiRemotePackage
*remote_package
;
1856 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1857 if (!remote_package
)
1858 return ERROR_INVALID_HANDLE
;
1860 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1862 IWineMsiRemotePackage_Release( remote_package
);
1866 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1867 return HRESULT_CODE(hr
);
1869 return ERROR_FUNCTION_FAILED
;
1872 return ERROR_SUCCESS
;
1875 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1879 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1882 msiobj_release( &package
->hdr
);
1884 msiobj_release( &record
->hdr
);
1891 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1893 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1894 UINT r
= ERROR_OUTOFMEMORY
;
1896 szwName
= strdupAtoW( szName
);
1897 if( szName
&& !szwName
)
1900 szwValue
= strdupAtoW( szValue
);
1901 if( szValue
&& !szwValue
)
1904 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1907 msi_free( szwName
);
1908 msi_free( szwValue
);
1913 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
1917 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
1921 msi_free( folder
->ResolvedSource
);
1922 folder
->ResolvedSource
= NULL
;
1926 msi_free( folder
->ResolvedTarget
);
1927 folder
->ResolvedTarget
= NULL
;
1932 UINT
msi_set_property( MSIDATABASE
*db
, LPCWSTR szName
, LPCWSTR szValue
)
1934 static const WCHAR insert_query
[] = {
1935 'I','N','S','E','R','T',' ','I','N','T','O',' ',
1936 '`','_','P','r','o','p','e','r','t','y','`',' ',
1937 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
1938 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
1939 static const WCHAR update_query
[] = {
1940 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
1941 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
1942 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1943 static const WCHAR delete_query
[] = {
1944 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1945 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1946 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1948 MSIRECORD
*row
= NULL
;
1953 TRACE("%p %s %s\n", db
, debugstr_w(szName
), debugstr_w(szValue
));
1956 return ERROR_INVALID_PARAMETER
;
1958 /* this one is weird... */
1960 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1962 rc
= msi_get_property(db
, szName
, 0, &sz
);
1963 if (!szValue
|| !*szValue
)
1965 sprintfW(query
, delete_query
, szName
);
1967 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1969 sprintfW(query
, update_query
, szName
);
1971 row
= MSI_CreateRecord(1);
1972 MSI_RecordSetStringW(row
, 1, szValue
);
1976 strcpyW(query
, insert_query
);
1978 row
= MSI_CreateRecord(2);
1979 MSI_RecordSetStringW(row
, 1, szName
);
1980 MSI_RecordSetStringW(row
, 2, szValue
);
1983 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
1984 if (rc
== ERROR_SUCCESS
)
1986 rc
= MSI_ViewExecute(view
, row
);
1987 MSI_ViewClose(view
);
1988 msiobj_release(&view
->hdr
);
1990 if (row
) msiobj_release(&row
->hdr
);
1994 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1996 MSIPACKAGE
*package
;
1999 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2003 BSTR name
= NULL
, value
= NULL
;
2004 IWineMsiRemotePackage
*remote_package
;
2006 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2007 if (!remote_package
)
2008 return ERROR_INVALID_HANDLE
;
2010 name
= SysAllocString( szName
);
2011 value
= SysAllocString( szValue
);
2012 if ((!name
&& szName
) || (!value
&& szValue
))
2014 SysFreeString( name
);
2015 SysFreeString( value
);
2016 IWineMsiRemotePackage_Release( remote_package
);
2017 return ERROR_OUTOFMEMORY
;
2020 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2022 SysFreeString( name
);
2023 SysFreeString( value
);
2024 IWineMsiRemotePackage_Release( remote_package
);
2028 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2029 return HRESULT_CODE(hr
);
2031 return ERROR_FUNCTION_FAILED
;
2034 return ERROR_SUCCESS
;
2037 ret
= msi_set_property( package
->db
, szName
, szValue
);
2038 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, szSourceDir
))
2039 msi_reset_folders( package
, TRUE
);
2041 msiobj_release( &package
->hdr
);
2045 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2047 static const WCHAR query
[]= {
2048 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2049 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2050 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2051 MSIRECORD
*rec
, *row
= NULL
;
2055 if (!name
|| !*name
)
2058 rec
= MSI_CreateRecord(1);
2062 MSI_RecordSetStringW(rec
, 1, name
);
2064 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2065 if (r
== ERROR_SUCCESS
)
2067 MSI_ViewExecute(view
, rec
);
2068 MSI_ViewFetch(view
, &row
);
2069 MSI_ViewClose(view
);
2070 msiobj_release(&view
->hdr
);
2072 msiobj_release(&rec
->hdr
);
2076 /* internal function, not compatible with MsiGetPropertyW */
2077 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2078 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2081 UINT rc
= ERROR_FUNCTION_FAILED
;
2083 row
= msi_get_property_row( db
, szName
);
2085 if (*pchValueBuf
> 0)
2090 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2091 msiobj_release(&row
->hdr
);
2094 if (rc
== ERROR_SUCCESS
)
2095 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
2096 debugstr_w(szName
));
2097 else if (rc
== ERROR_MORE_DATA
)
2098 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2099 debugstr_w(szName
));
2103 TRACE("property %s not found\n", debugstr_w(szName
));
2109 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2115 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2116 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2120 str
= msi_alloc(sz
* sizeof(WCHAR
));
2121 r
= msi_get_property(db
, prop
, str
, &sz
);
2122 if (r
!= ERROR_SUCCESS
)
2131 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2133 LPWSTR str
= msi_dup_property( db
, prop
);
2134 int val
= str
? atoiW(str
) : def
;
2139 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2140 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2142 MSIPACKAGE
*package
;
2143 MSIRECORD
*row
= NULL
;
2144 UINT r
= ERROR_FUNCTION_FAILED
;
2147 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2148 szValueBuf
->str
.w
, pchValueBuf
);
2151 return ERROR_INVALID_PARAMETER
;
2153 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2157 IWineMsiRemotePackage
*remote_package
;
2158 LPWSTR value
= NULL
;
2162 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2163 if (!remote_package
)
2164 return ERROR_INVALID_HANDLE
;
2166 bname
= SysAllocString( name
);
2169 IWineMsiRemotePackage_Release( remote_package
);
2170 return ERROR_OUTOFMEMORY
;
2174 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2179 value
= msi_alloc(len
* sizeof(WCHAR
));
2182 r
= ERROR_OUTOFMEMORY
;
2186 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, value
, &len
);
2190 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
2192 /* Bug required by Adobe installers */
2193 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2194 *pchValueBuf
*= sizeof(WCHAR
);
2197 IWineMsiRemotePackage_Release(remote_package
);
2198 SysFreeString(bname
);
2203 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2204 return HRESULT_CODE(hr
);
2206 return ERROR_FUNCTION_FAILED
;
2212 row
= msi_get_property_row( package
->db
, name
);
2214 val
= MSI_RecordGetString( row
, 1 );
2219 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
2222 msiobj_release( &row
->hdr
);
2223 msiobj_release( &package
->hdr
);
2228 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2229 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2235 val
.unicode
= FALSE
;
2236 val
.str
.a
= szValueBuf
;
2238 name
= strdupAtoW( szName
);
2239 if (szName
&& !name
)
2240 return ERROR_OUTOFMEMORY
;
2242 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2247 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2248 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2253 val
.str
.w
= szValueBuf
;
2255 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2258 typedef struct _msi_remote_package_impl
{
2259 IWineMsiRemotePackage IWineMsiRemotePackage_iface
;
2262 } msi_remote_package_impl
;
2264 static inline msi_remote_package_impl
*impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage
*iface
)
2266 return CONTAINING_RECORD(iface
, msi_remote_package_impl
, IWineMsiRemotePackage_iface
);
2269 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2270 REFIID riid
,LPVOID
*ppobj
)
2272 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2273 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2275 IUnknown_AddRef( iface
);
2280 return E_NOINTERFACE
;
2283 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2285 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2287 return InterlockedIncrement( &This
->refs
);
2290 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2292 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2295 r
= InterlockedDecrement( &This
->refs
);
2298 MsiCloseHandle( This
->package
);
2304 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2306 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2307 This
->package
= handle
;
2311 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2313 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2314 IWineMsiRemoteDatabase
*rdb
= NULL
;
2318 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2319 if (FAILED(hr
) || !rdb
)
2321 ERR("Failed to create remote database\n");
2325 hdb
= MsiGetActiveDatabase(This
->package
);
2327 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2330 ERR("Failed to set the database handle\n");
2334 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2338 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
, DWORD
*size
)
2340 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2341 UINT r
= MsiGetPropertyW(This
->package
, property
, value
, size
);
2342 if (r
!= ERROR_SUCCESS
) return HRESULT_FROM_WIN32(r
);
2346 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2348 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2349 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2350 return HRESULT_FROM_WIN32(r
);
2353 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2355 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2356 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2357 return HRESULT_FROM_WIN32(r
);
2360 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2362 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2363 UINT r
= MsiDoActionW(This
->package
, action
);
2364 return HRESULT_FROM_WIN32(r
);
2367 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2369 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2370 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2371 return HRESULT_FROM_WIN32(r
);
2374 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2376 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2377 UINT r
= MsiGetTargetPathW(This
->package
, folder
, value
, size
);
2378 return HRESULT_FROM_WIN32(r
);
2381 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2383 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2384 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2385 return HRESULT_FROM_WIN32(r
);
2388 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2390 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2391 UINT r
= MsiGetSourcePathW(This
->package
, folder
, value
, size
);
2392 return HRESULT_FROM_WIN32(r
);
2395 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2397 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2398 *ret
= MsiGetMode(This
->package
, mode
);
2402 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2404 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2405 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2406 return HRESULT_FROM_WIN32(r
);
2409 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2410 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2412 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2413 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2414 return HRESULT_FROM_WIN32(r
);
2417 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2419 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2420 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2421 return HRESULT_FROM_WIN32(r
);
2424 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2425 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2427 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2428 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2429 return HRESULT_FROM_WIN32(r
);
2432 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2434 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2435 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2436 return HRESULT_FROM_WIN32(r
);
2439 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2441 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2442 *language
= MsiGetLanguage(This
->package
);
2446 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2448 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2449 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2450 return HRESULT_FROM_WIN32(r
);
2453 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2457 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2458 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2459 if (r
== ERROR_SUCCESS
)
2461 *value
= SysAllocStringLen(NULL
, size
);
2463 return E_OUTOFMEMORY
;
2465 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2467 return HRESULT_FROM_WIN32(r
);
2470 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2472 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2473 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2474 return HRESULT_FROM_WIN32(r
);
2477 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2478 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2480 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2481 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2482 return HRESULT_FROM_WIN32(r
);
2485 static HRESULT WINAPI
mrp_EnumComponentCosts( IWineMsiRemotePackage
*iface
, BSTR component
,
2486 DWORD index
, INSTALLSTATE state
, BSTR drive
,
2487 DWORD
*buflen
, INT
*cost
, INT
*temp
)
2489 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2490 UINT r
= MsiEnumComponentCostsW(This
->package
, component
, index
, state
, drive
, buflen
, cost
, temp
);
2491 return HRESULT_FROM_WIN32(r
);
2494 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2500 mrp_GetActiveDatabase
,
2511 mrp_GetFeatureState
,
2512 mrp_SetFeatureState
,
2513 mrp_GetComponentState
,
2514 mrp_SetComponentState
,
2516 mrp_SetInstallLevel
,
2518 mrp_EvaluateCondition
,
2520 mrp_EnumComponentCosts
2523 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2525 msi_remote_package_impl
* This
;
2527 This
= msi_alloc( sizeof *This
);
2529 return E_OUTOFMEMORY
;
2531 This
->IWineMsiRemotePackage_iface
.lpVtbl
= &msi_remote_package_vtbl
;
2540 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2541 LPCWSTR property
, LPWSTR value
)
2543 MSISOURCELISTINFO
*info
;
2545 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2547 if (!strcmpW( info
->value
, value
)) return ERROR_SUCCESS
;
2550 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2552 return ERROR_OUTOFMEMORY
;
2554 info
->context
= context
;
2555 info
->options
= options
;
2556 info
->property
= property
;
2557 info
->value
= strdupW(value
);
2558 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2560 return ERROR_SUCCESS
;
2563 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2564 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2568 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2570 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2573 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2575 return ERROR_OUTOFMEMORY
;
2577 disk
->context
= context
;
2578 disk
->options
= options
;
2579 disk
->disk_id
= disk_id
;
2580 disk
->volume_label
= strdupW(volume_label
);
2581 disk
->disk_prompt
= strdupW(disk_prompt
);
2582 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2584 return ERROR_SUCCESS
;