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 WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
36 #include <wine/debug.h>
38 //#include "msiquery.h"
40 //#include "wincrypt.h"
41 //#include "winuser.h"
46 #include <wine/unicode.h>
47 //#include "objbase.h"
48 //#include "msidefs.h"
52 #include <msiserver.h>
54 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
56 static void remove_tracked_tempfiles( MSIPACKAGE
*package
)
58 struct list
*item
, *cursor
;
60 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->tempfiles
)
62 MSITEMPFILE
*temp
= LIST_ENTRY( item
, MSITEMPFILE
, entry
);
64 list_remove( &temp
->entry
);
65 TRACE("deleting temp file %s\n", debugstr_w( temp
->Path
));
66 DeleteFileW( temp
->Path
);
67 msi_free( temp
->Path
);
72 static void free_feature( MSIFEATURE
*feature
)
74 struct list
*item
, *cursor
;
76 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
78 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
79 list_remove( &fl
->entry
);
83 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
85 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
86 list_remove( &cl
->entry
);
89 msi_free( feature
->Feature
);
90 msi_free( feature
->Feature_Parent
);
91 msi_free( feature
->Directory
);
92 msi_free( feature
->Description
);
93 msi_free( feature
->Title
);
97 static void free_folder( MSIFOLDER
*folder
)
99 struct list
*item
, *cursor
;
101 LIST_FOR_EACH_SAFE( item
, cursor
, &folder
->children
)
103 FolderList
*fl
= LIST_ENTRY( item
, FolderList
, entry
);
104 list_remove( &fl
->entry
);
107 msi_free( folder
->Parent
);
108 msi_free( folder
->Directory
);
109 msi_free( folder
->TargetDefault
);
110 msi_free( folder
->SourceLongPath
);
111 msi_free( folder
->SourceShortPath
);
112 msi_free( folder
->ResolvedTarget
);
113 msi_free( folder
->ResolvedSource
);
117 static void free_extension( MSIEXTENSION
*ext
)
119 struct list
*item
, *cursor
;
121 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
123 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
125 list_remove( &verb
->entry
);
126 msi_free( verb
->Verb
);
127 msi_free( verb
->Command
);
128 msi_free( verb
->Argument
);
132 msi_free( ext
->Extension
);
133 msi_free( ext
->ProgIDText
);
137 static void free_assembly( MSIASSEMBLY
*assembly
)
139 msi_free( assembly
->feature
);
140 msi_free( assembly
->manifest
);
141 msi_free( assembly
->application
);
142 msi_free( assembly
->display_name
);
143 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
144 msi_free( assembly
->tempdir
);
145 msi_free( assembly
);
148 void msi_free_action_script( MSIPACKAGE
*package
, UINT script
)
151 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
152 msi_free( package
->script
->Actions
[script
][i
] );
154 msi_free( package
->script
->Actions
[script
] );
155 package
->script
->Actions
[script
] = NULL
;
156 package
->script
->ActionCount
[script
] = 0;
159 static void free_package_structures( MSIPACKAGE
*package
)
161 struct list
*item
, *cursor
;
163 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
165 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
166 list_remove( &feature
->entry
);
167 free_feature( feature
);
170 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
172 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
173 list_remove( &folder
->entry
);
174 free_folder( folder
);
177 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
179 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
181 list_remove( &comp
->entry
);
182 msi_free( comp
->Component
);
183 msi_free( comp
->ComponentId
);
184 msi_free( comp
->Directory
);
185 msi_free( comp
->Condition
);
186 msi_free( comp
->KeyPath
);
187 msi_free( comp
->FullKeypath
);
188 if (comp
->assembly
) free_assembly( comp
->assembly
);
192 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
194 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
196 list_remove( &file
->entry
);
197 msi_free( file
->File
);
198 msi_free( file
->FileName
);
199 msi_free( file
->ShortName
);
200 msi_free( file
->LongName
);
201 msi_free( file
->Version
);
202 msi_free( file
->Language
);
203 msi_free( file
->TargetPath
);
207 /* clean up extension, progid, class and verb structures */
208 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
210 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
212 list_remove( &cls
->entry
);
213 msi_free( cls
->clsid
);
214 msi_free( cls
->Context
);
215 msi_free( cls
->Description
);
216 msi_free( cls
->FileTypeMask
);
217 msi_free( cls
->IconPath
);
218 msi_free( cls
->DefInprocHandler
);
219 msi_free( cls
->DefInprocHandler32
);
220 msi_free( cls
->Argument
);
221 msi_free( cls
->ProgIDText
);
225 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
227 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
229 list_remove( &ext
->entry
);
230 free_extension( ext
);
233 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
235 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
237 list_remove( &progid
->entry
);
238 msi_free( progid
->ProgID
);
239 msi_free( progid
->Description
);
240 msi_free( progid
->IconPath
);
244 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
246 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
248 list_remove( &mt
->entry
);
249 msi_free( mt
->suffix
);
250 msi_free( mt
->clsid
);
251 msi_free( mt
->ContentType
);
255 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
257 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
259 list_remove( &appid
->entry
);
260 msi_free( appid
->AppID
);
261 msi_free( appid
->RemoteServerName
);
262 msi_free( appid
->LocalServer
);
263 msi_free( appid
->ServiceParameters
);
264 msi_free( appid
->DllSurrogate
);
268 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
270 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
272 list_remove( &info
->entry
);
273 msi_free( info
->value
);
277 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
279 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
281 list_remove( &info
->entry
);
282 msi_free( info
->volume_label
);
283 msi_free( info
->disk_prompt
);
292 for (i
= 0; i
< SCRIPT_MAX
; i
++)
293 msi_free_action_script( package
, i
);
295 for (j
= 0; j
< package
->script
->UniqueActionsCount
; j
++)
296 msi_free( package
->script
->UniqueActions
[j
] );
298 msi_free( package
->script
->UniqueActions
);
299 msi_free( package
->script
);
302 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->binaries
)
304 MSIBINARY
*binary
= LIST_ENTRY( item
, MSIBINARY
, entry
);
306 list_remove( &binary
->entry
);
308 FreeLibrary( binary
->module
);
309 if (!DeleteFileW( binary
->tmpfile
))
310 ERR("failed to delete %s (%u)\n", debugstr_w(binary
->tmpfile
), GetLastError());
311 msi_free( binary
->source
);
312 msi_free( binary
->tmpfile
);
316 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->cabinet_streams
)
318 MSICABINETSTREAM
*cab
= LIST_ENTRY( item
, MSICABINETSTREAM
, entry
);
320 list_remove( &cab
->entry
);
321 IStorage_Release( cab
->storage
);
322 msi_free( cab
->stream
);
326 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
328 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
330 list_remove( &patch
->entry
);
331 if (patch
->delete_on_close
&& !DeleteFileW( patch
->localfile
))
333 ERR("failed to delete %s (%u)\n", debugstr_w(patch
->localfile
), GetLastError());
335 msi_free_patchinfo( patch
);
338 msi_free( package
->BaseURL
);
339 msi_free( package
->PackagePath
);
340 msi_free( package
->ProductCode
);
341 msi_free( package
->ActionFormat
);
342 msi_free( package
->LastAction
);
343 msi_free( package
->langids
);
345 remove_tracked_tempfiles(package
);
347 /* cleanup control event subscriptions */
348 ControlEvent_CleanupSubscriptions( package
);
351 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
353 MSIPACKAGE
*package
= (MSIPACKAGE
*)arg
;
355 msi_destroy_assembly_caches( package
);
357 if( package
->dialog
)
358 msi_dialog_destroy( package
->dialog
);
360 msiobj_release( &package
->db
->hdr
);
361 free_package_structures(package
);
362 CloseHandle( package
->log_file
);
364 if (package
->delete_on_close
) DeleteFileW( package
->localfile
);
365 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
, -1 );
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
, -1 );
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
);
650 version
= msi_alloc(size
);
654 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
657 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
660 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
662 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
665 if (!val_len
|| !verstr
)
668 msi_set_property( package
->db
, netasm
, verstr
, -1 );
675 static VOID
set_installer_properties(MSIPACKAGE
*package
)
678 OSVERSIONINFOEXW OSVersion
;
681 WCHAR pth
[MAX_PATH
], verstr
[11], bufstr
[22];
684 LPWSTR username
, companyname
;
685 SYSTEM_INFO sys_info
;
686 SYSTEMTIME systemtime
;
689 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
690 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
691 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
692 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
693 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
694 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
695 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
696 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
697 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
698 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
699 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
700 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
701 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
702 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
703 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
704 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
705 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
706 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
707 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
708 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
709 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
710 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
711 static const WCHAR szFormat
[] = {'%','u',0};
712 static const WCHAR szFormat2
[] = {'%','u','.','%','u',0};
713 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
714 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
715 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
716 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
717 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',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};
757 static const WCHAR szComputerName
[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
758 static const WCHAR szBrowseProperty
[] = {'_','B','r','o','w','s','e','P','r','o','p','e','r','t','y',0};
759 static const WCHAR szInstallDir
[] = {'I','N','S','T','A','L','L','D','I','R',0};
762 * Other things that probably should be set:
764 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
765 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
768 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
769 strcatW(pth
, szBackSlash
);
770 msi_set_property( package
->db
, szCommonAppDataFolder
, pth
, -1 );
772 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
773 strcatW(pth
, szBackSlash
);
774 msi_set_property( package
->db
, szFavoritesFolder
, pth
, -1 );
776 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
777 strcatW(pth
, szBackSlash
);
778 msi_set_property( package
->db
, szFontsFolder
, pth
, -1 );
780 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
781 strcatW(pth
, szBackSlash
);
782 msi_set_property( package
->db
, szSendToFolder
, pth
, -1 );
784 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
785 strcatW(pth
, szBackSlash
);
786 msi_set_property( package
->db
, szStartMenuFolder
, pth
, -1 );
788 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
789 strcatW(pth
, szBackSlash
);
790 msi_set_property( package
->db
, szStartupFolder
, pth
, -1 );
792 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
793 strcatW(pth
, szBackSlash
);
794 msi_set_property( package
->db
, szTemplateFolder
, pth
, -1 );
796 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
797 strcatW(pth
, szBackSlash
);
798 msi_set_property( package
->db
, szDesktopFolder
, pth
, -1 );
800 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
801 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
802 strcatW(pth
, szBackSlash
);
803 msi_set_property( package
->db
, szProgramMenuFolder
, pth
, -1 );
805 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
806 strcatW(pth
, szBackSlash
);
807 msi_set_property( package
->db
, szAdminToolsFolder
, pth
, -1 );
809 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
810 strcatW(pth
, szBackSlash
);
811 msi_set_property( package
->db
, szAppDataFolder
, pth
, -1 );
813 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
814 strcatW(pth
, szBackSlash
);
815 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
816 msi_set_property( package
->db
, szSystem16Folder
, pth
, -1 );
818 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
819 strcatW(pth
, szBackSlash
);
820 msi_set_property( package
->db
, szLocalAppDataFolder
, pth
, -1 );
822 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
823 strcatW(pth
, szBackSlash
);
824 msi_set_property( package
->db
, szMyPicturesFolder
, pth
, -1 );
826 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
827 strcatW(pth
, szBackSlash
);
828 msi_set_property( package
->db
, szPersonalFolder
, pth
, -1 );
830 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
831 strcatW(pth
, szBackSlash
);
832 msi_set_property( package
->db
, szWindowsFolder
, pth
, -1 );
834 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
835 strcatW(pth
, szBackSlash
);
836 msi_set_property( package
->db
, szPrintHoodFolder
, pth
, -1 );
838 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
839 strcatW(pth
, szBackSlash
);
840 msi_set_property( package
->db
, szNetHoodFolder
, pth
, -1 );
842 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
843 strcatW(pth
, szBackSlash
);
844 msi_set_property( package
->db
, szRecentFolder
, pth
, -1 );
846 /* Physical Memory is specified in MB. Using total amount. */
847 msex
.dwLength
= sizeof(msex
);
848 GlobalMemoryStatusEx( &msex
);
849 len
= sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
850 msi_set_property( package
->db
, szPhysicalMemory
, bufstr
, len
);
852 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
853 ptr
= strchrW(pth
,'\\');
854 if (ptr
) *(ptr
+ 1) = 0;
855 msi_set_property( package
->db
, szWindowsVolume
, pth
, -1 );
857 len
= GetTempPathW(MAX_PATH
, pth
);
858 msi_set_property( package
->db
, szTempFolder
, pth
, len
);
860 /* in a wine environment the user is always admin and privileged */
861 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
862 msi_set_property( package
->db
, szPrivileged
, szOne
, -1 );
864 /* set the os things */
865 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
866 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
867 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
868 len
= sprintfW( verstr
, szFormat
, verval
);
869 switch (OSVersion
.dwPlatformId
)
871 case VER_PLATFORM_WIN32_WINDOWS
:
872 msi_set_property( package
->db
, szVersion9x
, verstr
, len
);
874 case VER_PLATFORM_WIN32_NT
:
875 msi_set_property( package
->db
, szVersionNT
, verstr
, len
);
876 len
= sprintfW( verstr
, szFormat
,OSVersion
.wProductType
);
877 msi_set_property( package
->db
, szMsiNTProductType
, verstr
, len
);
880 len
= sprintfW( verstr
, szFormat
, OSVersion
.dwBuildNumber
);
881 msi_set_property( package
->db
, szWindowsBuild
, verstr
, len
);
882 len
= sprintfW( verstr
, szFormat
, OSVersion
.wServicePackMajor
);
883 msi_set_property( package
->db
, szServicePackLevel
, verstr
, len
);
885 len
= sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
886 msi_set_property( package
->db
, szVersionMsi
, bufstr
, len
);
887 len
= sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100 );
888 msi_set_property( package
->db
, szVersionDatabase
, bufstr
, len
);
890 GetNativeSystemInfo( &sys_info
);
891 len
= sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
892 msi_set_property( package
->db
, szIntel
, bufstr
, len
);
893 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
895 GetSystemDirectoryW( pth
, MAX_PATH
);
896 PathAddBackslashW( pth
);
897 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
899 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
900 PathAddBackslashW( pth
);
901 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
903 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
904 PathAddBackslashW( pth
);
905 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
907 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
909 msi_set_property( package
->db
, szMsiAMD64
, bufstr
, -1 );
910 msi_set_property( package
->db
, szMsix64
, bufstr
, -1 );
911 msi_set_property( package
->db
, szVersionNT64
, verstr
, -1 );
913 GetSystemDirectoryW( pth
, MAX_PATH
);
914 PathAddBackslashW( pth
);
915 msi_set_property( package
->db
, szSystem64Folder
, pth
, -1 );
917 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
918 PathAddBackslashW( pth
);
919 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
921 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
922 PathAddBackslashW( pth
);
923 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
, -1 );
925 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
926 PathAddBackslashW( pth
);
927 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
929 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
930 PathAddBackslashW( pth
);
931 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
, -1 );
933 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
934 PathAddBackslashW( pth
);
935 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
938 /* Screen properties. */
940 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, HORZRES
) );
941 msi_set_property( package
->db
, szScreenX
, bufstr
, len
);
942 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, VERTRES
) );
943 msi_set_property( package
->db
, szScreenY
, bufstr
, len
);
944 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, BITSPIXEL
) );
945 msi_set_property( package
->db
, szColorBits
, bufstr
, len
);
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
, -1 );
959 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
960 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
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
, -1 );
970 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
971 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
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
, -1 );
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
, -1 );
994 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
996 set_msi_assembly_prop( package
);
998 langid
= GetUserDefaultLangID();
999 len
= sprintfW( bufstr
, szIntFormat
, langid
);
1000 msi_set_property( package
->db
, szUserLanguageID
, bufstr
, len
);
1002 langid
= GetSystemDefaultLangID();
1003 len
= sprintfW( bufstr
, szIntFormat
, langid
);
1004 msi_set_property( package
->db
, szSystemLangID
, bufstr
, len
);
1006 len
= sprintfW( bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
) );
1007 msi_set_property( package
->db
, szProductState
, bufstr
, len
);
1010 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1013 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
1015 if (GetUserNameW( username
, &len
))
1016 msi_set_property( package
->db
, szLogonUser
, username
, len
- 1 );
1017 msi_free( username
);
1021 if (!GetComputerNameW( NULL
, &len
) && GetLastError() == ERROR_BUFFER_OVERFLOW
)
1023 WCHAR
*computername
;
1024 if ((computername
= msi_alloc( len
* sizeof(WCHAR
) )))
1026 if (GetComputerNameW( computername
, &len
))
1027 msi_set_property( package
->db
, szComputerName
, computername
, len
- 1 );
1028 msi_free( computername
);
1031 msi_set_property( package
->db
, szBrowseProperty
, szInstallDir
, -1 );
1034 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
1038 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
1041 LPWSTR package_code
;
1042 static const WCHAR szPackageCode
[] = {
1043 'P','a','c','k','a','g','e','C','o','d','e',0};
1046 ERR("Unable to allocate handle\n");
1047 return ERROR_OUTOFMEMORY
;
1050 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
1051 MsiCloseHandle(hdb
);
1052 if (rc
!= ERROR_SUCCESS
)
1054 ERR("Unable to open Summary Information\n");
1058 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
1059 &count
, NULL
, NULL
, NULL
);
1060 if (rc
!= ERROR_SUCCESS
)
1062 WARN("Unable to query page count: %d\n", rc
);
1066 /* load package code property */
1068 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1069 NULL
, NULL
, NULL
, &len
);
1070 if (rc
!= ERROR_MORE_DATA
)
1072 WARN("Unable to query revision number: %d\n", rc
);
1073 rc
= ERROR_FUNCTION_FAILED
;
1078 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
1079 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1080 NULL
, NULL
, package_code
, &len
);
1081 if (rc
!= ERROR_SUCCESS
)
1083 WARN("Unable to query rev number: %d\n", rc
);
1087 msi_set_property( package
->db
, szPackageCode
, package_code
, len
);
1088 msi_free( package_code
);
1090 /* load package attributes */
1092 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
1093 &count
, NULL
, NULL
, NULL
);
1094 package
->WordCount
= count
;
1097 MsiCloseHandle(suminfo
);
1101 static MSIPACKAGE
*msi_alloc_package( void )
1103 MSIPACKAGE
*package
;
1105 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1109 list_init( &package
->components
);
1110 list_init( &package
->features
);
1111 list_init( &package
->files
);
1112 list_init( &package
->filepatches
);
1113 list_init( &package
->tempfiles
);
1114 list_init( &package
->folders
);
1115 list_init( &package
->subscriptions
);
1116 list_init( &package
->appids
);
1117 list_init( &package
->classes
);
1118 list_init( &package
->mimes
);
1119 list_init( &package
->extensions
);
1120 list_init( &package
->progids
);
1121 list_init( &package
->RunningActions
);
1122 list_init( &package
->sourcelist_info
);
1123 list_init( &package
->sourcelist_media
);
1124 list_init( &package
->patches
);
1125 list_init( &package
->binaries
);
1126 list_init( &package
->cabinet_streams
);
1132 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1137 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1139 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1140 if (r
!= ERROR_SUCCESS
)
1143 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1149 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1151 /* FIXME: this should depend on the user's privileges */
1152 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1154 TRACE("resetting ALLUSERS property from 2 to 1\n");
1155 msi_set_property( package
->db
, szAllUsers
, szOne
, -1 );
1157 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
1160 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1162 static const WCHAR fmtW
[] = {'%','u',0};
1163 MSIPACKAGE
*package
;
1170 package
= msi_alloc_package();
1173 msiobj_addref( &db
->hdr
);
1176 package
->WordCount
= 0;
1177 package
->PackagePath
= strdupW( db
->path
);
1178 package
->BaseURL
= strdupW( base_url
);
1180 create_temp_property_table( package
);
1181 msi_clone_properties( package
);
1182 msi_adjust_privilege_properties( package
);
1184 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1185 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1187 set_installed_prop( package
);
1188 set_installer_properties( package
);
1190 package
->ui_level
= gUILevel
;
1191 len
= sprintfW( uilevel
, fmtW
, gUILevel
& INSTALLUILEVEL_MASK
);
1192 msi_set_property( package
->db
, szUILevel
, uilevel
, len
);
1194 r
= msi_load_summary_properties( package
);
1195 if (r
!= ERROR_SUCCESS
)
1197 msiobj_release( &package
->hdr
);
1201 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1202 msi_load_admin_properties( package
);
1204 package
->log_file
= INVALID_HANDLE_VALUE
;
1209 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1211 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1215 /* call will always fail, because size is 0,
1216 * but will return ERROR_FILE_NOT_FOUND first
1217 * if the file doesn't exist
1219 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1220 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1222 cache_entry
= msi_alloc( size
);
1223 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1225 UINT error
= GetLastError();
1226 msi_free( cache_entry
);
1230 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1231 msi_free( cache_entry
);
1232 return ERROR_SUCCESS
;
1235 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1238 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1239 return ERROR_FUNCTION_FAILED
;
1242 return ERROR_SUCCESS
;
1245 UINT
msi_create_empty_local_file( LPWSTR path
, LPCWSTR suffix
)
1247 static const WCHAR szInstaller
[] = {
1248 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1249 static const WCHAR fmt
[] = {'%','x',0};
1250 DWORD time
, len
, i
, offset
;
1253 time
= GetTickCount();
1254 GetWindowsDirectoryW( path
, MAX_PATH
);
1255 strcatW( path
, szInstaller
);
1256 CreateDirectoryW( path
, NULL
);
1258 len
= strlenW(path
);
1259 for (i
= 0; i
< 0x10000; i
++)
1261 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1262 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1263 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1264 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1265 if (handle
!= INVALID_HANDLE_VALUE
)
1267 CloseHandle(handle
);
1270 if (GetLastError() != ERROR_FILE_EXISTS
&&
1271 GetLastError() != ERROR_SHARING_VIOLATION
)
1272 return ERROR_FUNCTION_FAILED
;
1275 return ERROR_SUCCESS
;
1278 static enum platform
parse_platform( WCHAR
*str
)
1280 if (!str
[0] || !strcmpW( str
, szIntel
)) return PLATFORM_INTEL
;
1281 else if (!strcmpW( str
, szIntel64
)) return PLATFORM_INTEL64
;
1282 else if (!strcmpW( str
, szX64
) || !strcmpW( str
, szAMD64
)) return PLATFORM_X64
;
1283 else if (!strcmpW( str
, szARM
)) return PLATFORM_ARM
;
1284 return PLATFORM_UNKNOWN
;
1287 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1289 WCHAR
*template, *p
, *q
, *platform
;
1292 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1293 TRACE("version: %d\n", package
->version
);
1295 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1297 return ERROR_SUCCESS
; /* native accepts missing template property */
1299 TRACE("template: %s\n", debugstr_w(template));
1301 p
= strchrW( template, ';' );
1304 WARN("invalid template string %s\n", debugstr_w(template));
1305 msi_free( template );
1306 return ERROR_PATCH_PACKAGE_INVALID
;
1309 platform
= template;
1310 if ((q
= strchrW( platform
, ',' ))) *q
= 0;
1311 package
->platform
= parse_platform( platform
);
1312 while (package
->platform
== PLATFORM_UNKNOWN
&& q
)
1315 if ((q
= strchrW( platform
, ',' ))) *q
= 0;
1316 package
->platform
= parse_platform( platform
);
1318 if (package
->platform
== PLATFORM_UNKNOWN
)
1320 WARN("unknown platform %s\n", debugstr_w(template));
1321 msi_free( template );
1322 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1327 msi_free( template );
1328 return ERROR_SUCCESS
;
1331 for (q
= p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1333 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1334 if (!package
->langids
)
1336 msi_free( template );
1337 return ERROR_OUTOFMEMORY
;
1343 q
= strchrW( p
, ',' );
1345 package
->langids
[i
] = atoiW( p
);
1350 package
->num_langids
= i
+ 1;
1352 msi_free( template );
1353 return ERROR_SUCCESS
;
1356 static UINT
validate_package( MSIPACKAGE
*package
)
1360 if (package
->platform
== PLATFORM_INTEL64
)
1361 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1363 if (package
->platform
== PLATFORM_ARM
)
1364 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1366 if (package
->platform
== PLATFORM_X64
)
1368 if (!is_64bit
&& !is_wow64
)
1369 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1370 if (package
->version
< 200)
1371 return ERROR_INSTALL_PACKAGE_INVALID
;
1373 if (!package
->num_langids
)
1375 return ERROR_SUCCESS
;
1377 for (i
= 0; i
< package
->num_langids
; i
++)
1379 LANGID langid
= package
->langids
[i
];
1381 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1383 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1385 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1387 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1389 if (IsValidLocale( langid
, LCID_INSTALLED
))
1390 return ERROR_SUCCESS
;
1392 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1395 int msi_track_tempfile( MSIPACKAGE
*package
, const WCHAR
*path
)
1399 TRACE("%s\n", debugstr_w(path
));
1401 LIST_FOR_EACH_ENTRY( temp
, &package
->tempfiles
, MSITEMPFILE
, entry
)
1403 if (!strcmpW( path
, temp
->Path
)) return 0;
1405 if (!(temp
= msi_alloc_zero( sizeof (MSITEMPFILE
) ))) return -1;
1406 list_add_head( &package
->tempfiles
, &temp
->entry
);
1407 temp
->Path
= strdupW( path
);
1411 static WCHAR
*get_product_code( MSIDATABASE
*db
)
1413 static const WCHAR query
[] = {
1414 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1415 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1416 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1417 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1422 if (MSI_DatabaseOpenViewW( db
, query
, &view
) != ERROR_SUCCESS
)
1426 if (MSI_ViewExecute( view
, 0 ) != ERROR_SUCCESS
)
1428 MSI_ViewClose( view
);
1429 msiobj_release( &view
->hdr
);
1432 if (MSI_ViewFetch( view
, &rec
) == ERROR_SUCCESS
)
1434 ret
= strdupW( MSI_RecordGetString( rec
, 1 ) );
1435 msiobj_release( &rec
->hdr
);
1437 MSI_ViewClose( view
);
1438 msiobj_release( &view
->hdr
);
1442 static UINT
get_registered_local_package( const WCHAR
*product
, const WCHAR
*package
, WCHAR
*localfile
)
1444 MSIINSTALLCONTEXT context
;
1445 HKEY product_key
, props_key
;
1446 WCHAR
*registered_package
= NULL
, unsquashed
[GUID_SIZE
];
1449 r
= msi_locate_product( product
, &context
);
1450 if (r
!= ERROR_SUCCESS
)
1453 r
= MSIREG_OpenProductKey( product
, NULL
, context
, &product_key
, FALSE
);
1454 if (r
!= ERROR_SUCCESS
)
1457 r
= MSIREG_OpenInstallProps( product
, context
, NULL
, &props_key
, FALSE
);
1458 if (r
!= ERROR_SUCCESS
)
1460 RegCloseKey( product_key
);
1463 r
= ERROR_FUNCTION_FAILED
;
1464 registered_package
= msi_reg_get_val_str( product_key
, INSTALLPROPERTY_PACKAGECODEW
);
1465 if (!registered_package
)
1468 unsquash_guid( registered_package
, unsquashed
);
1469 if (!strcmpiW( package
, unsquashed
))
1471 WCHAR
*filename
= msi_reg_get_val_str( props_key
, INSTALLPROPERTY_LOCALPACKAGEW
);
1475 strcpyW( localfile
, filename
);
1476 msi_free( filename
);
1480 msi_free( registered_package
);
1481 RegCloseKey( props_key
);
1482 RegCloseKey( product_key
);
1486 static WCHAR
*get_package_code( MSIDATABASE
*db
)
1491 if (!(si
= MSI_GetSummaryInformationW( db
->storage
, 0 )))
1493 WARN("failed to load summary info\n");
1496 ret
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
1497 msiobj_release( &si
->hdr
);
1501 static UINT
get_local_package( const WCHAR
*filename
, WCHAR
*localfile
)
1503 WCHAR
*product_code
, *package_code
;
1507 if ((r
= MSI_OpenDatabaseW( filename
, MSIDBOPEN_READONLY
, &db
)) != ERROR_SUCCESS
)
1509 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1510 return ERROR_FILE_NOT_FOUND
;
1513 if (!(product_code
= get_product_code( db
)))
1515 msiobj_release( &db
->hdr
);
1516 return ERROR_INSTALL_PACKAGE_INVALID
;
1518 if (!(package_code
= get_package_code( db
)))
1520 msi_free( product_code
);
1521 msiobj_release( &db
->hdr
);
1522 return ERROR_INSTALL_PACKAGE_INVALID
;
1524 r
= get_registered_local_package( product_code
, package_code
, localfile
);
1525 msi_free( package_code
);
1526 msi_free( product_code
);
1527 msiobj_release( &db
->hdr
);
1531 UINT
msi_set_original_database_property( MSIDATABASE
*db
, const WCHAR
*package
)
1535 if (UrlIsW( package
, URLIS_URL
))
1536 r
= msi_set_property( db
, szOriginalDatabase
, package
, -1 );
1537 else if (package
[0] == '#')
1538 r
= msi_set_property( db
, szOriginalDatabase
, db
->path
, -1 );
1544 if (!(len
= GetFullPathNameW( package
, 0, NULL
, NULL
))) return GetLastError();
1545 if (!(path
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1546 len
= GetFullPathNameW( package
, len
, path
, NULL
);
1547 r
= msi_set_property( db
, szOriginalDatabase
, path
, len
);
1553 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1555 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1557 MSIPACKAGE
*package
;
1559 LPWSTR ptr
, base_url
= NULL
;
1561 WCHAR localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1562 LPCWSTR file
= szPackage
;
1565 BOOL delete_on_close
= FALSE
;
1567 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1570 if( szPackage
[0] == '#' )
1572 handle
= atoiW(&szPackage
[1]);
1573 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1576 IWineMsiRemoteDatabase
*remote_database
;
1578 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1579 if ( !remote_database
)
1580 return ERROR_INVALID_HANDLE
;
1582 IWineMsiRemoteDatabase_Release( remote_database
);
1583 WARN("MsiOpenPackage not allowed during a custom action!\n");
1585 return ERROR_FUNCTION_FAILED
;
1590 if ( UrlIsW( szPackage
, URLIS_URL
) )
1592 r
= msi_download_file( szPackage
, cachefile
);
1593 if (r
!= ERROR_SUCCESS
)
1598 base_url
= strdupW( szPackage
);
1600 return ERROR_OUTOFMEMORY
;
1602 ptr
= strrchrW( base_url
, '/' );
1603 if (ptr
) *(ptr
+ 1) = '\0';
1605 r
= get_local_package( file
, localfile
);
1606 if (r
!= ERROR_SUCCESS
|| GetFileAttributesW( localfile
) == INVALID_FILE_ATTRIBUTES
)
1608 r
= msi_create_empty_local_file( localfile
, dotmsi
);
1609 if (r
!= ERROR_SUCCESS
)
1611 msi_free ( base_url
);
1615 if (!CopyFileW( file
, localfile
, FALSE
))
1618 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file
), debugstr_w(localfile
), r
);
1619 DeleteFileW( localfile
);
1620 msi_free ( base_url
);
1623 delete_on_close
= TRUE
;
1625 TRACE("opening package %s\n", debugstr_w( localfile
));
1626 r
= MSI_OpenDatabaseW( localfile
, MSIDBOPEN_TRANSACT
, &db
);
1627 if (r
!= ERROR_SUCCESS
)
1629 msi_free ( base_url
);
1633 package
= MSI_CreatePackage( db
, base_url
);
1634 msi_free( base_url
);
1635 msiobj_release( &db
->hdr
);
1636 if (!package
) return ERROR_INSTALL_PACKAGE_INVALID
;
1637 package
->localfile
= strdupW( localfile
);
1638 package
->delete_on_close
= delete_on_close
;
1640 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1643 WARN("failed to load summary info\n");
1644 msiobj_release( &package
->hdr
);
1645 return ERROR_INSTALL_PACKAGE_INVALID
;
1647 r
= msi_parse_summary( si
, package
);
1648 msiobj_release( &si
->hdr
);
1649 if (r
!= ERROR_SUCCESS
)
1651 WARN("failed to parse summary info %u\n", r
);
1652 msiobj_release( &package
->hdr
);
1655 r
= validate_package( package
);
1656 if (r
!= ERROR_SUCCESS
)
1658 msiobj_release( &package
->hdr
);
1661 msi_set_property( package
->db
, szDatabase
, db
->path
, -1 );
1662 msi_set_context( package
);
1666 WCHAR patch_code
[GUID_SIZE
];
1667 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1668 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1669 if (r
!= ERROR_SUCCESS
)
1672 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1674 r
= msi_apply_registered_patch( package
, patch_code
);
1675 if (r
!= ERROR_SUCCESS
)
1677 ERR("registered patch failed to apply %u\n", r
);
1678 msiobj_release( &package
->hdr
);
1685 msi_clone_properties( package
);
1686 msi_adjust_privilege_properties( package
);
1688 r
= msi_set_original_database_property( package
->db
, szPackage
);
1689 if (r
!= ERROR_SUCCESS
)
1691 msiobj_release( &package
->hdr
);
1695 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1696 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1697 *pPackage
= package
;
1698 return ERROR_SUCCESS
;
1701 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1703 MSIPACKAGE
*package
= NULL
;
1706 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1708 if( !szPackage
|| !phPackage
)
1709 return ERROR_INVALID_PARAMETER
;
1713 FIXME("Should create an empty database and package\n");
1714 return ERROR_FUNCTION_FAILED
;
1718 FIXME("dwOptions %08x not supported\n", dwOptions
);
1720 ret
= MSI_OpenPackageW( szPackage
, &package
);
1721 if( ret
== ERROR_SUCCESS
)
1723 *phPackage
= alloc_msihandle( &package
->hdr
);
1725 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1726 msiobj_release( &package
->hdr
);
1732 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1734 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1737 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1739 LPWSTR szwPack
= NULL
;
1744 szwPack
= strdupAtoW( szPackage
);
1746 return ERROR_OUTOFMEMORY
;
1749 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1751 msi_free( szwPack
);
1756 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1758 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1761 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1763 MSIPACKAGE
*package
;
1764 MSIHANDLE handle
= 0;
1765 IUnknown
*remote_unk
;
1766 IWineMsiRemotePackage
*remote_package
;
1768 TRACE("(%d)\n",hInstall
);
1770 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1773 handle
= alloc_msihandle( &package
->db
->hdr
);
1774 msiobj_release( &package
->hdr
);
1776 else if ((remote_unk
= msi_get_remote(hInstall
)))
1778 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1779 (LPVOID
*)&remote_package
) == S_OK
)
1781 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1782 IWineMsiRemotePackage_Release(remote_package
);
1786 WARN("remote handle %d is not a package\n", hInstall
);
1788 IUnknown_Release(remote_unk
);
1794 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1796 static const WCHAR szActionData
[] = {'A','c','t','i','o','n','D','a','t','a',0};
1797 static const WCHAR szSetProgress
[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1798 static const WCHAR szActionText
[] = {'A','c','t','i','o','n','T','e','x','t',0};
1800 LPWSTR deformated
, message
;
1801 DWORD i
, len
, total_len
, log_type
= 0;
1805 TRACE("%x\n", eMessageType
);
1807 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_FATALEXIT
)
1808 log_type
|= INSTALLLOGMODE_FATALEXIT
;
1809 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1810 log_type
|= INSTALLLOGMODE_ERROR
;
1811 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1812 log_type
|= INSTALLLOGMODE_WARNING
;
1813 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1814 log_type
|= INSTALLLOGMODE_USER
;
1815 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1816 log_type
|= INSTALLLOGMODE_INFO
;
1817 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE
)
1818 log_type
|= INSTALLLOGMODE_RESOLVESOURCE
;
1819 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE
)
1820 log_type
|= INSTALLLOGMODE_OUTOFDISKSPACE
;
1821 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1822 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1823 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1824 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1825 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1826 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1827 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1828 log_type
|= INSTALLLOGMODE_PROGRESS
;
1829 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
)
1830 log_type
|= INSTALLLOGMODE_INITIALIZE
;
1831 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
1832 log_type
|= INSTALLLOGMODE_TERMINATE
;
1833 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_SHOWDIALOG
)
1834 log_type
|= INSTALLLOGMODE_SHOWDIALOG
;
1836 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1838 static const WCHAR template_s
[]=
1839 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1840 static const WCHAR format
[] =
1841 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1843 LPCWSTR action_text
, action
;
1844 LPWSTR deformatted
= NULL
;
1846 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1848 action
= MSI_RecordGetString(record
, 1);
1849 action_text
= MSI_RecordGetString(record
, 2);
1851 if (!action
|| !action_text
)
1854 deformat_string(package
, action_text
, &deformatted
);
1856 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1858 len
+= strlenW(deformatted
);
1859 message
= msi_alloc(len
*sizeof(WCHAR
));
1860 sprintfW(message
, template_s
, timet
, action
);
1862 strcatW(message
, deformatted
);
1863 msi_free(deformatted
);
1867 static const WCHAR format
[] = {'%','u',':',' ',0};
1868 UINT count
= MSI_RecordGetFieldCount( record
);
1872 for (i
= 1; i
<= count
; i
++)
1875 MSI_RecordGetStringW( record
, i
, NULL
, &len
);
1876 total_len
+= len
+ 13;
1878 p
= message
= msi_alloc( total_len
* sizeof(WCHAR
) );
1879 if (!p
) return ERROR_OUTOFMEMORY
;
1881 for (i
= 1; i
<= count
; i
++)
1885 len
= sprintfW( p
, format
, i
);
1890 MSI_RecordGetStringW( record
, i
, p
, &len
);
1893 if (count
> 1 && total_len
)
1902 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1903 gUIFilter
, log_type
, debugstr_w(message
));
1905 /* convert it to ASCII */
1906 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1907 msg
= msi_alloc( len
);
1908 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1910 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1912 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1914 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1916 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1918 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1920 MSIHANDLE rec
= MsiCreateRecord( 1 );
1921 MsiRecordSetStringW( rec
, 0, message
);
1922 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1923 MsiCloseHandle( rec
);
1926 if (!rc
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1927 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1930 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1931 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1934 msi_free( message
);
1936 switch (eMessageType
& 0xff000000)
1938 case INSTALLMESSAGE_ACTIONDATA
:
1939 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformated
);
1940 uirow
= MSI_CreateRecord(1);
1941 MSI_RecordSetStringW(uirow
, 1, deformated
);
1942 msi_free(deformated
);
1944 ControlEvent_FireSubscribedEvent(package
, szActionData
, uirow
);
1945 msiobj_release(&uirow
->hdr
);
1947 if (package
->action_progress_increment
)
1949 uirow
= MSI_CreateRecord(2);
1950 MSI_RecordSetInteger(uirow
, 1, 2);
1951 MSI_RecordSetInteger(uirow
, 2, package
->action_progress_increment
);
1952 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, uirow
);
1953 msiobj_release(&uirow
->hdr
);
1957 case INSTALLMESSAGE_ACTIONSTART
:
1958 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformated
);
1959 uirow
= MSI_CreateRecord(1);
1960 MSI_RecordSetStringW(uirow
, 1, deformated
);
1961 msi_free(deformated
);
1963 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1965 msiobj_release(&uirow
->hdr
);
1968 case INSTALLMESSAGE_PROGRESS
:
1969 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1973 return ERROR_SUCCESS
;
1976 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1979 UINT ret
= ERROR_INVALID_HANDLE
;
1980 MSIPACKAGE
*package
= NULL
;
1981 MSIRECORD
*record
= NULL
;
1983 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1987 IWineMsiRemotePackage
*remote_package
;
1989 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1990 if (!remote_package
)
1991 return ERROR_INVALID_HANDLE
;
1993 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1995 IWineMsiRemotePackage_Release( remote_package
);
1999 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2000 return HRESULT_CODE(hr
);
2002 return ERROR_FUNCTION_FAILED
;
2005 return ERROR_SUCCESS
;
2008 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
2012 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
2015 msiobj_release( &package
->hdr
);
2017 msiobj_release( &record
->hdr
);
2024 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
2026 LPWSTR szwName
= NULL
, szwValue
= NULL
;
2027 UINT r
= ERROR_OUTOFMEMORY
;
2029 szwName
= strdupAtoW( szName
);
2030 if( szName
&& !szwName
)
2033 szwValue
= strdupAtoW( szValue
);
2034 if( szValue
&& !szwValue
)
2037 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
2040 msi_free( szwName
);
2041 msi_free( szwValue
);
2046 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
2050 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
2054 msi_free( folder
->ResolvedSource
);
2055 folder
->ResolvedSource
= NULL
;
2059 msi_free( folder
->ResolvedTarget
);
2060 folder
->ResolvedTarget
= NULL
;
2065 UINT
msi_set_property( MSIDATABASE
*db
, const WCHAR
*name
, const WCHAR
*value
, int len
)
2067 static const WCHAR insert_query
[] = {
2068 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2069 '`','_','P','r','o','p','e','r','t','y','`',' ',
2070 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2071 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2072 static const WCHAR update_query
[] = {
2073 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2074 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2075 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2076 static const WCHAR delete_query
[] = {
2077 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2078 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2079 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2081 MSIRECORD
*row
= NULL
;
2086 TRACE("%p %s %s %d\n", db
, debugstr_w(name
), debugstr_wn(value
, len
), len
);
2089 return ERROR_INVALID_PARAMETER
;
2091 /* this one is weird... */
2093 return value
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
2095 if (value
&& len
< 0) len
= strlenW( value
);
2097 rc
= msi_get_property( db
, name
, 0, &sz
);
2098 if (!value
|| (!*value
&& !len
))
2100 sprintfW( query
, delete_query
, name
);
2102 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
2104 sprintfW( query
, update_query
, name
);
2105 row
= MSI_CreateRecord(1);
2106 msi_record_set_string( row
, 1, value
, len
);
2110 strcpyW( query
, insert_query
);
2111 row
= MSI_CreateRecord(2);
2112 msi_record_set_string( row
, 1, name
, -1 );
2113 msi_record_set_string( row
, 2, value
, len
);
2116 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2117 if (rc
== ERROR_SUCCESS
)
2119 rc
= MSI_ViewExecute(view
, row
);
2120 MSI_ViewClose(view
);
2121 msiobj_release(&view
->hdr
);
2123 if (row
) msiobj_release(&row
->hdr
);
2127 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2129 MSIPACKAGE
*package
;
2132 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2136 BSTR name
= NULL
, value
= NULL
;
2137 IWineMsiRemotePackage
*remote_package
;
2139 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2140 if (!remote_package
)
2141 return ERROR_INVALID_HANDLE
;
2143 name
= SysAllocString( szName
);
2144 value
= SysAllocString( szValue
);
2145 if ((!name
&& szName
) || (!value
&& szValue
))
2147 SysFreeString( name
);
2148 SysFreeString( value
);
2149 IWineMsiRemotePackage_Release( remote_package
);
2150 return ERROR_OUTOFMEMORY
;
2153 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2155 SysFreeString( name
);
2156 SysFreeString( value
);
2157 IWineMsiRemotePackage_Release( remote_package
);
2161 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2162 return HRESULT_CODE(hr
);
2164 return ERROR_FUNCTION_FAILED
;
2167 return ERROR_SUCCESS
;
2170 ret
= msi_set_property( package
->db
, szName
, szValue
, -1 );
2171 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, szSourceDir
))
2172 msi_reset_folders( package
, TRUE
);
2174 msiobj_release( &package
->hdr
);
2178 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2180 static const WCHAR query
[]= {
2181 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2182 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2183 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2184 MSIRECORD
*rec
, *row
= NULL
;
2188 if (!name
|| !*name
)
2191 rec
= MSI_CreateRecord(1);
2195 MSI_RecordSetStringW(rec
, 1, name
);
2197 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2198 if (r
== ERROR_SUCCESS
)
2200 MSI_ViewExecute(view
, rec
);
2201 MSI_ViewFetch(view
, &row
);
2202 MSI_ViewClose(view
);
2203 msiobj_release(&view
->hdr
);
2205 msiobj_release(&rec
->hdr
);
2209 /* internal function, not compatible with MsiGetPropertyW */
2210 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2211 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2214 UINT rc
= ERROR_FUNCTION_FAILED
;
2216 row
= msi_get_property_row( db
, szName
);
2218 if (*pchValueBuf
> 0)
2223 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2224 msiobj_release(&row
->hdr
);
2227 if (rc
== ERROR_SUCCESS
)
2228 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf
, *pchValueBuf
),
2229 debugstr_w(szName
));
2230 else if (rc
== ERROR_MORE_DATA
)
2231 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2232 debugstr_w(szName
));
2236 TRACE("property %s not found\n", debugstr_w(szName
));
2242 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2248 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2249 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2253 str
= msi_alloc(sz
* sizeof(WCHAR
));
2254 r
= msi_get_property(db
, prop
, str
, &sz
);
2255 if (r
!= ERROR_SUCCESS
)
2264 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2266 LPWSTR str
= msi_dup_property( db
, prop
);
2267 int val
= str
? atoiW(str
) : def
;
2272 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2273 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2275 MSIPACKAGE
*package
;
2276 MSIRECORD
*row
= NULL
;
2277 UINT r
= ERROR_FUNCTION_FAILED
;
2281 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2282 szValueBuf
->str
.w
, pchValueBuf
);
2285 return ERROR_INVALID_PARAMETER
;
2287 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2291 IWineMsiRemotePackage
*remote_package
;
2292 LPWSTR value
= NULL
;
2295 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2296 if (!remote_package
)
2297 return ERROR_INVALID_HANDLE
;
2299 bname
= SysAllocString( name
);
2302 IWineMsiRemotePackage_Release( remote_package
);
2303 return ERROR_OUTOFMEMORY
;
2306 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2311 value
= msi_alloc(len
* sizeof(WCHAR
));
2314 r
= ERROR_OUTOFMEMORY
;
2318 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, value
, &len
);
2322 r
= msi_strcpy_to_awstring( value
, len
, szValueBuf
, pchValueBuf
);
2324 /* Bug required by Adobe installers */
2325 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2326 *pchValueBuf
*= sizeof(WCHAR
);
2329 IWineMsiRemotePackage_Release(remote_package
);
2330 SysFreeString(bname
);
2335 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2336 return HRESULT_CODE(hr
);
2338 return ERROR_FUNCTION_FAILED
;
2344 row
= msi_get_property_row( package
->db
, name
);
2346 val
= msi_record_get_string( row
, 1, (int *)&len
);
2351 r
= msi_strcpy_to_awstring( val
, len
, szValueBuf
, pchValueBuf
);
2354 msiobj_release( &row
->hdr
);
2355 msiobj_release( &package
->hdr
);
2360 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2361 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2367 val
.unicode
= FALSE
;
2368 val
.str
.a
= szValueBuf
;
2370 name
= strdupAtoW( szName
);
2371 if (szName
&& !name
)
2372 return ERROR_OUTOFMEMORY
;
2374 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2379 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2380 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2385 val
.str
.w
= szValueBuf
;
2387 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2390 typedef struct _msi_remote_package_impl
{
2391 IWineMsiRemotePackage IWineMsiRemotePackage_iface
;
2394 } msi_remote_package_impl
;
2396 static inline msi_remote_package_impl
*impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage
*iface
)
2398 return CONTAINING_RECORD(iface
, msi_remote_package_impl
, IWineMsiRemotePackage_iface
);
2401 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2402 REFIID riid
,LPVOID
*ppobj
)
2404 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2405 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2407 IWineMsiRemotePackage_AddRef( iface
);
2412 return E_NOINTERFACE
;
2415 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2417 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2419 return InterlockedIncrement( &This
->refs
);
2422 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2424 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2427 r
= InterlockedDecrement( &This
->refs
);
2430 MsiCloseHandle( This
->package
);
2436 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2438 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2439 This
->package
= handle
;
2443 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2445 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2446 IWineMsiRemoteDatabase
*rdb
= NULL
;
2450 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2451 if (FAILED(hr
) || !rdb
)
2453 ERR("Failed to create remote database\n");
2457 hdb
= MsiGetActiveDatabase(This
->package
);
2459 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2462 ERR("Failed to set the database handle\n");
2466 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2470 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
, DWORD
*size
)
2472 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2473 UINT r
= MsiGetPropertyW(This
->package
, property
, value
, size
);
2474 if (r
!= ERROR_SUCCESS
) return HRESULT_FROM_WIN32(r
);
2478 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2480 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2481 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2482 return HRESULT_FROM_WIN32(r
);
2485 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2487 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2488 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2489 return HRESULT_FROM_WIN32(r
);
2492 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2494 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2495 UINT r
= MsiDoActionW(This
->package
, action
);
2496 return HRESULT_FROM_WIN32(r
);
2499 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2501 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2502 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2503 return HRESULT_FROM_WIN32(r
);
2506 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2508 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2509 UINT r
= MsiGetTargetPathW(This
->package
, folder
, value
, size
);
2510 return HRESULT_FROM_WIN32(r
);
2513 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2515 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2516 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2517 return HRESULT_FROM_WIN32(r
);
2520 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2522 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2523 UINT r
= MsiGetSourcePathW(This
->package
, folder
, value
, size
);
2524 return HRESULT_FROM_WIN32(r
);
2527 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2529 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2530 *ret
= MsiGetMode(This
->package
, mode
);
2534 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2536 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2537 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2538 return HRESULT_FROM_WIN32(r
);
2541 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2542 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2544 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2545 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2546 return HRESULT_FROM_WIN32(r
);
2549 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2551 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2552 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2553 return HRESULT_FROM_WIN32(r
);
2556 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2557 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2559 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2560 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2561 return HRESULT_FROM_WIN32(r
);
2564 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2566 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2567 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2568 return HRESULT_FROM_WIN32(r
);
2571 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2573 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2574 *language
= MsiGetLanguage(This
->package
);
2578 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2580 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2581 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2582 return HRESULT_FROM_WIN32(r
);
2585 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2589 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2590 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2591 if (r
== ERROR_SUCCESS
)
2593 *value
= SysAllocStringLen(NULL
, size
);
2595 return E_OUTOFMEMORY
;
2597 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2599 return HRESULT_FROM_WIN32(r
);
2602 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2604 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2605 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2606 return HRESULT_FROM_WIN32(r
);
2609 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2610 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2612 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2613 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2614 return HRESULT_FROM_WIN32(r
);
2617 static HRESULT WINAPI
mrp_EnumComponentCosts( IWineMsiRemotePackage
*iface
, BSTR component
,
2618 DWORD index
, INSTALLSTATE state
, BSTR drive
,
2619 DWORD
*buflen
, INT
*cost
, INT
*temp
)
2621 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2622 UINT r
= MsiEnumComponentCostsW(This
->package
, component
, index
, state
, drive
, buflen
, cost
, temp
);
2623 return HRESULT_FROM_WIN32(r
);
2626 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2632 mrp_GetActiveDatabase
,
2643 mrp_GetFeatureState
,
2644 mrp_SetFeatureState
,
2645 mrp_GetComponentState
,
2646 mrp_SetComponentState
,
2648 mrp_SetInstallLevel
,
2650 mrp_EvaluateCondition
,
2652 mrp_EnumComponentCosts
2655 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2657 msi_remote_package_impl
* This
;
2659 This
= msi_alloc( sizeof *This
);
2661 return E_OUTOFMEMORY
;
2663 This
->IWineMsiRemotePackage_iface
.lpVtbl
= &msi_remote_package_vtbl
;
2672 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2673 LPCWSTR property
, LPWSTR value
)
2675 MSISOURCELISTINFO
*info
;
2677 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2679 if (!strcmpW( info
->value
, value
)) return ERROR_SUCCESS
;
2682 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2684 return ERROR_OUTOFMEMORY
;
2686 info
->context
= context
;
2687 info
->options
= options
;
2688 info
->property
= property
;
2689 info
->value
= strdupW(value
);
2690 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2692 return ERROR_SUCCESS
;
2695 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2696 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2700 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2702 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2705 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2707 return ERROR_OUTOFMEMORY
;
2709 disk
->context
= context
;
2710 disk
->options
= options
;
2711 disk
->disk_id
= disk_id
;
2712 disk
->volume_label
= strdupW(volume_label
);
2713 disk
->disk_prompt
= strdupW(disk_prompt
);
2714 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2716 return ERROR_SUCCESS
;