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
37 #include <wine/debug.h>
39 //#include "msiquery.h"
41 //#include "wincrypt.h"
42 //#include "winuser.h"
47 #include <wine/unicode.h>
48 //#include "objbase.h"
49 //#include "msidefs.h"
53 #include <msiserver.h>
55 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
57 static void remove_tracked_tempfiles( MSIPACKAGE
*package
)
59 struct list
*item
, *cursor
;
61 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->tempfiles
)
63 MSITEMPFILE
*temp
= LIST_ENTRY( item
, MSITEMPFILE
, entry
);
65 list_remove( &temp
->entry
);
66 TRACE("deleting temp file %s\n", debugstr_w( temp
->Path
));
67 DeleteFileW( temp
->Path
);
68 msi_free( temp
->Path
);
73 static void free_feature( MSIFEATURE
*feature
)
75 struct list
*item
, *cursor
;
77 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
79 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
80 list_remove( &fl
->entry
);
84 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
86 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
87 list_remove( &cl
->entry
);
90 msi_free( feature
->Feature
);
91 msi_free( feature
->Feature_Parent
);
92 msi_free( feature
->Directory
);
93 msi_free( feature
->Description
);
94 msi_free( feature
->Title
);
98 static void free_folder( MSIFOLDER
*folder
)
100 struct list
*item
, *cursor
;
102 LIST_FOR_EACH_SAFE( item
, cursor
, &folder
->children
)
104 FolderList
*fl
= LIST_ENTRY( item
, FolderList
, entry
);
105 list_remove( &fl
->entry
);
108 msi_free( folder
->Parent
);
109 msi_free( folder
->Directory
);
110 msi_free( folder
->TargetDefault
);
111 msi_free( folder
->SourceLongPath
);
112 msi_free( folder
->SourceShortPath
);
113 msi_free( folder
->ResolvedTarget
);
114 msi_free( folder
->ResolvedSource
);
118 static void free_extension( MSIEXTENSION
*ext
)
120 struct list
*item
, *cursor
;
122 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
124 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
126 list_remove( &verb
->entry
);
127 msi_free( verb
->Verb
);
128 msi_free( verb
->Command
);
129 msi_free( verb
->Argument
);
133 msi_free( ext
->Extension
);
134 msi_free( ext
->ProgIDText
);
138 static void free_assembly( MSIASSEMBLY
*assembly
)
140 msi_free( assembly
->feature
);
141 msi_free( assembly
->manifest
);
142 msi_free( assembly
->application
);
143 msi_free( assembly
->display_name
);
144 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
145 msi_free( assembly
->tempdir
);
146 msi_free( assembly
);
149 void msi_free_action_script( MSIPACKAGE
*package
, UINT script
)
152 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
153 msi_free( package
->script
->Actions
[script
][i
] );
155 msi_free( package
->script
->Actions
[script
] );
156 package
->script
->Actions
[script
] = NULL
;
157 package
->script
->ActionCount
[script
] = 0;
160 static void free_package_structures( MSIPACKAGE
*package
)
162 struct list
*item
, *cursor
;
164 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
166 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
167 list_remove( &feature
->entry
);
168 free_feature( feature
);
171 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
173 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
174 list_remove( &folder
->entry
);
175 free_folder( folder
);
178 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
180 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
182 list_remove( &comp
->entry
);
183 msi_free( comp
->Component
);
184 msi_free( comp
->ComponentId
);
185 msi_free( comp
->Directory
);
186 msi_free( comp
->Condition
);
187 msi_free( comp
->KeyPath
);
188 msi_free( comp
->FullKeypath
);
189 if (comp
->assembly
) free_assembly( comp
->assembly
);
193 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
195 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
197 list_remove( &file
->entry
);
198 msi_free( file
->File
);
199 msi_free( file
->FileName
);
200 msi_free( file
->ShortName
);
201 msi_free( file
->LongName
);
202 msi_free( file
->Version
);
203 msi_free( file
->Language
);
204 msi_free( file
->TargetPath
);
208 /* clean up extension, progid, class and verb structures */
209 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
211 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
213 list_remove( &cls
->entry
);
214 msi_free( cls
->clsid
);
215 msi_free( cls
->Context
);
216 msi_free( cls
->Description
);
217 msi_free( cls
->FileTypeMask
);
218 msi_free( cls
->IconPath
);
219 msi_free( cls
->DefInprocHandler
);
220 msi_free( cls
->DefInprocHandler32
);
221 msi_free( cls
->Argument
);
222 msi_free( cls
->ProgIDText
);
226 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
228 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
230 list_remove( &ext
->entry
);
231 free_extension( ext
);
234 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
236 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
238 list_remove( &progid
->entry
);
239 msi_free( progid
->ProgID
);
240 msi_free( progid
->Description
);
241 msi_free( progid
->IconPath
);
245 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
247 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
249 list_remove( &mt
->entry
);
250 msi_free( mt
->suffix
);
251 msi_free( mt
->clsid
);
252 msi_free( mt
->ContentType
);
256 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
258 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
260 list_remove( &appid
->entry
);
261 msi_free( appid
->AppID
);
262 msi_free( appid
->RemoteServerName
);
263 msi_free( appid
->LocalServer
);
264 msi_free( appid
->ServiceParameters
);
265 msi_free( appid
->DllSurrogate
);
269 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
271 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
273 list_remove( &info
->entry
);
274 msi_free( info
->value
);
278 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
280 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
282 list_remove( &info
->entry
);
283 msi_free( info
->volume_label
);
284 msi_free( info
->disk_prompt
);
293 for (i
= 0; i
< SCRIPT_MAX
; i
++)
294 msi_free_action_script( package
, i
);
296 for (j
= 0; j
< package
->script
->UniqueActionsCount
; j
++)
297 msi_free( package
->script
->UniqueActions
[j
] );
299 msi_free( package
->script
->UniqueActions
);
300 msi_free( package
->script
);
303 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->binaries
)
305 MSIBINARY
*binary
= LIST_ENTRY( item
, MSIBINARY
, entry
);
307 list_remove( &binary
->entry
);
309 FreeLibrary( binary
->module
);
310 if (!DeleteFileW( binary
->tmpfile
))
311 ERR("failed to delete %s (%u)\n", debugstr_w(binary
->tmpfile
), GetLastError());
312 msi_free( binary
->source
);
313 msi_free( binary
->tmpfile
);
317 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->cabinet_streams
)
319 MSICABINETSTREAM
*cab
= LIST_ENTRY( item
, MSICABINETSTREAM
, entry
);
321 list_remove( &cab
->entry
);
322 IStorage_Release( cab
->storage
);
323 msi_free( cab
->stream
);
327 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
329 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
331 list_remove( &patch
->entry
);
332 if (patch
->delete_on_close
&& !DeleteFileW( patch
->localfile
))
334 ERR("failed to delete %s (%u)\n", debugstr_w(patch
->localfile
), GetLastError());
336 msi_free_patchinfo( patch
);
339 msi_free( package
->BaseURL
);
340 msi_free( package
->PackagePath
);
341 msi_free( package
->ProductCode
);
342 msi_free( package
->ActionFormat
);
343 msi_free( package
->LastAction
);
344 msi_free( package
->langids
);
346 remove_tracked_tempfiles(package
);
348 /* cleanup control event subscriptions */
349 ControlEvent_CleanupSubscriptions( package
);
352 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
354 MSIPACKAGE
*package
= (MSIPACKAGE
*)arg
;
356 msi_destroy_assembly_caches( package
);
358 if( package
->dialog
)
359 msi_dialog_destroy( package
->dialog
);
361 msiobj_release( &package
->db
->hdr
);
362 free_package_structures(package
);
363 CloseHandle( package
->log_file
);
365 if (package
->delete_on_close
) DeleteFileW( package
->localfile
);
366 msi_free( package
->localfile
);
369 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
371 static const WCHAR query
[] = {
372 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
373 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
374 '`','_','P','r','o','p','e','r','t','y','`',' ',
375 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
376 'T','E','M','P','O','R','A','R','Y',',',' ',
377 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
378 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
379 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
380 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
384 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
385 if (rc
!= ERROR_SUCCESS
)
388 rc
= MSI_ViewExecute(view
, 0);
390 msiobj_release(&view
->hdr
);
394 UINT
msi_clone_properties(MSIPACKAGE
*package
)
396 static const WCHAR query_select
[] = {
397 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
398 '`','P','r','o','p','e','r','t','y','`',0};
399 static const WCHAR query_insert
[] = {
400 'I','N','S','E','R','T',' ','I','N','T','O',' ',
401 '`','_','P','r','o','p','e','r','t','y','`',' ',
402 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
403 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
404 static const WCHAR query_update
[] = {
405 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
406 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
407 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
408 MSIQUERY
*view_select
;
411 rc
= MSI_DatabaseOpenViewW( package
->db
, query_select
, &view_select
);
412 if (rc
!= ERROR_SUCCESS
)
415 rc
= MSI_ViewExecute( view_select
, 0 );
416 if (rc
!= ERROR_SUCCESS
)
418 MSI_ViewClose( view_select
);
419 msiobj_release( &view_select
->hdr
);
425 MSIQUERY
*view_insert
, *view_update
;
426 MSIRECORD
*rec_select
;
428 rc
= MSI_ViewFetch( view_select
, &rec_select
);
429 if (rc
!= ERROR_SUCCESS
)
432 rc
= MSI_DatabaseOpenViewW( package
->db
, query_insert
, &view_insert
);
433 if (rc
!= ERROR_SUCCESS
)
435 msiobj_release( &rec_select
->hdr
);
439 rc
= MSI_ViewExecute( view_insert
, rec_select
);
440 MSI_ViewClose( view_insert
);
441 msiobj_release( &view_insert
->hdr
);
442 if (rc
!= ERROR_SUCCESS
)
444 MSIRECORD
*rec_update
;
446 TRACE("insert failed, trying update\n");
448 rc
= MSI_DatabaseOpenViewW( package
->db
, query_update
, &view_update
);
449 if (rc
!= ERROR_SUCCESS
)
451 WARN("open view failed %u\n", rc
);
452 msiobj_release( &rec_select
->hdr
);
456 rec_update
= MSI_CreateRecord( 2 );
457 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
458 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
459 rc
= MSI_ViewExecute( view_update
, rec_update
);
460 if (rc
!= ERROR_SUCCESS
)
461 WARN("update failed %u\n", rc
);
463 MSI_ViewClose( view_update
);
464 msiobj_release( &view_update
->hdr
);
465 msiobj_release( &rec_update
->hdr
);
468 msiobj_release( &rec_select
->hdr
);
471 MSI_ViewClose( view_select
);
472 msiobj_release( &view_select
->hdr
);
479 * Sets the "Installed" property to indicate that
480 * the product is installed for the current user.
482 static UINT
set_installed_prop( MSIPACKAGE
*package
)
487 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
489 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
490 if (r
== ERROR_SUCCESS
)
493 msi_set_property( package
->db
, szInstalled
, szOne
, -1 );
498 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
502 LPWSTR sid_str
= NULL
, dom
= NULL
;
503 DWORD size
, dom_size
;
505 UINT r
= ERROR_FUNCTION_FAILED
;
508 GetUserNameW( NULL
, &size
);
510 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
512 return ERROR_OUTOFMEMORY
;
514 if (!GetUserNameW( user_name
, &size
))
519 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
521 psid
= msi_alloc( size
);
522 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
525 r
= ERROR_OUTOFMEMORY
;
529 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
532 if (!ConvertSidToStringSidW( psid
, &sid_str
))
535 r
= msi_set_property( package
->db
, szUserSID
, sid_str
, -1 );
538 LocalFree( sid_str
);
541 msi_free( user_name
);
546 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
551 DWORD index
= 0, size
;
553 WCHAR name
[MAX_PATH
];
554 WCHAR windir
[MAX_PATH
];
556 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
557 static const WCHAR sub
[] = {
558 'S','o','f','t','w','a','r','e','\\',
559 'M','i','c','r','o','s','o','f','t','\\',
560 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
563 static const WCHAR subdir
[] = {
564 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
565 'F','r','a','m','e','w','o','r','k','\\',0
568 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
569 if (res
!= ERROR_SUCCESS
)
572 GetWindowsDirectoryW(windir
, MAX_PATH
);
576 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
580 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
581 if (strcmpW( ver
, name
) < 0)
584 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
585 check
= msi_alloc(size
* sizeof(WCHAR
));
593 lstrcpyW(check
, windir
);
594 lstrcatW(check
, szBackSlash
);
595 lstrcatW(check
, subdir
);
596 lstrcatW(check
, name
);
597 lstrcatW(check
, szBackSlash
);
598 lstrcatW(check
, fusion
);
600 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
611 RegCloseKey(netsetup
);
615 typedef struct tagLANGANDCODEPAGE
621 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
625 LPVOID version
= NULL
;
627 LPWSTR fusion
, verstr
;
628 LANGANDCODEPAGE
*translate
;
630 static const WCHAR netasm
[] = {
631 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
633 static const WCHAR translation
[] = {
634 '\\','V','a','r','F','i','l','e','I','n','f','o',
635 '\\','T','r','a','n','s','l','a','t','i','o','n',0
637 static const WCHAR verfmt
[] = {
638 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
639 '\\','%','0','4','x','%','0','4','x',
640 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
643 fusion
= get_fusion_filename(package
);
647 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
651 version
= msi_alloc(size
);
655 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
658 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
661 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
663 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
666 if (!val_len
|| !verstr
)
669 msi_set_property( package
->db
, netasm
, verstr
, -1 );
676 static VOID
set_installer_properties(MSIPACKAGE
*package
)
679 OSVERSIONINFOEXW OSVersion
;
682 WCHAR pth
[MAX_PATH
], verstr
[11], bufstr
[22];
685 LPWSTR username
, companyname
;
686 SYSTEM_INFO sys_info
;
687 SYSTEMTIME systemtime
;
690 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
691 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
692 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
693 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
694 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
695 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
696 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
697 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
698 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
699 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
700 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
701 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
702 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
703 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
704 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
705 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
706 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
707 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
708 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
709 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
710 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
711 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
712 static const WCHAR szFormat
[] = {'%','u',0};
713 static const WCHAR szFormat2
[] = {'%','u','.','%','u',0};
714 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
715 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
716 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
717 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
718 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
719 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
720 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
721 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
722 static const WCHAR szIntFormat
[] = {'%','d',0};
723 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
724 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
725 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
726 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
727 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 };
728 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
729 static const WCHAR szUserInfo
[] = {
730 'S','O','F','T','W','A','R','E','\\',
731 'M','i','c','r','o','s','o','f','t','\\',
732 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
733 'U','s','e','r',' ','I','n','f','o',0
735 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
736 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
737 static const WCHAR szCurrentVersion
[] = {
738 'S','O','F','T','W','A','R','E','\\',
739 'M','i','c','r','o','s','o','f','t','\\',
740 'W','i','n','d','o','w','s',' ','N','T','\\',
741 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
743 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
744 static const WCHAR szRegisteredOrganization
[] = {
745 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
747 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
748 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
749 static const WCHAR szDate
[] = {'D','a','t','e',0};
750 static const WCHAR szTime
[] = {'T','i','m','e',0};
751 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
752 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
753 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
754 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
755 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
756 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
757 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
758 static const WCHAR szComputerName
[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
759 static const WCHAR szBrowseProperty
[] = {'_','B','r','o','w','s','e','P','r','o','p','e','r','t','y',0};
760 static const WCHAR szInstallDir
[] = {'I','N','S','T','A','L','L','D','I','R',0};
763 * Other things that probably should be set:
765 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
766 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
769 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
770 strcatW(pth
, szBackSlash
);
771 msi_set_property( package
->db
, szCommonAppDataFolder
, pth
, -1 );
773 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
774 strcatW(pth
, szBackSlash
);
775 msi_set_property( package
->db
, szFavoritesFolder
, pth
, -1 );
777 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
778 strcatW(pth
, szBackSlash
);
779 msi_set_property( package
->db
, szFontsFolder
, pth
, -1 );
781 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
782 strcatW(pth
, szBackSlash
);
783 msi_set_property( package
->db
, szSendToFolder
, pth
, -1 );
785 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
786 strcatW(pth
, szBackSlash
);
787 msi_set_property( package
->db
, szStartMenuFolder
, pth
, -1 );
789 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
790 strcatW(pth
, szBackSlash
);
791 msi_set_property( package
->db
, szStartupFolder
, pth
, -1 );
793 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
794 strcatW(pth
, szBackSlash
);
795 msi_set_property( package
->db
, szTemplateFolder
, pth
, -1 );
797 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
798 strcatW(pth
, szBackSlash
);
799 msi_set_property( package
->db
, szDesktopFolder
, pth
, -1 );
801 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
802 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
803 strcatW(pth
, szBackSlash
);
804 msi_set_property( package
->db
, szProgramMenuFolder
, pth
, -1 );
806 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
807 strcatW(pth
, szBackSlash
);
808 msi_set_property( package
->db
, szAdminToolsFolder
, pth
, -1 );
810 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
811 strcatW(pth
, szBackSlash
);
812 msi_set_property( package
->db
, szAppDataFolder
, pth
, -1 );
814 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
815 strcatW(pth
, szBackSlash
);
816 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
817 msi_set_property( package
->db
, szSystem16Folder
, pth
, -1 );
819 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
820 strcatW(pth
, szBackSlash
);
821 msi_set_property( package
->db
, szLocalAppDataFolder
, pth
, -1 );
823 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
824 strcatW(pth
, szBackSlash
);
825 msi_set_property( package
->db
, szMyPicturesFolder
, pth
, -1 );
827 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
828 strcatW(pth
, szBackSlash
);
829 msi_set_property( package
->db
, szPersonalFolder
, pth
, -1 );
831 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
832 strcatW(pth
, szBackSlash
);
833 msi_set_property( package
->db
, szWindowsFolder
, pth
, -1 );
835 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
836 strcatW(pth
, szBackSlash
);
837 msi_set_property( package
->db
, szPrintHoodFolder
, pth
, -1 );
839 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
840 strcatW(pth
, szBackSlash
);
841 msi_set_property( package
->db
, szNetHoodFolder
, pth
, -1 );
843 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
844 strcatW(pth
, szBackSlash
);
845 msi_set_property( package
->db
, szRecentFolder
, pth
, -1 );
847 /* Physical Memory is specified in MB. Using total amount. */
848 msex
.dwLength
= sizeof(msex
);
849 GlobalMemoryStatusEx( &msex
);
850 len
= sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
851 msi_set_property( package
->db
, szPhysicalMemory
, bufstr
, len
);
853 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
854 ptr
= strchrW(pth
,'\\');
855 if (ptr
) *(ptr
+ 1) = 0;
856 msi_set_property( package
->db
, szWindowsVolume
, pth
, -1 );
858 len
= GetTempPathW(MAX_PATH
, pth
);
859 msi_set_property( package
->db
, szTempFolder
, pth
, len
);
861 /* in a wine environment the user is always admin and privileged */
862 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
863 msi_set_property( package
->db
, szPrivileged
, szOne
, -1 );
865 /* set the os things */
866 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
867 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
868 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
869 len
= sprintfW( verstr
, szFormat
, verval
);
870 switch (OSVersion
.dwPlatformId
)
872 case VER_PLATFORM_WIN32_WINDOWS
:
873 msi_set_property( package
->db
, szVersion9x
, verstr
, len
);
875 case VER_PLATFORM_WIN32_NT
:
876 msi_set_property( package
->db
, szVersionNT
, verstr
, len
);
877 len
= sprintfW( verstr
, szFormat
,OSVersion
.wProductType
);
878 msi_set_property( package
->db
, szMsiNTProductType
, verstr
, len
);
881 len
= sprintfW( verstr
, szFormat
, OSVersion
.dwBuildNumber
);
882 msi_set_property( package
->db
, szWindowsBuild
, verstr
, len
);
883 len
= sprintfW( verstr
, szFormat
, OSVersion
.wServicePackMajor
);
884 msi_set_property( package
->db
, szServicePackLevel
, verstr
, len
);
886 len
= sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
887 msi_set_property( package
->db
, szVersionMsi
, bufstr
, len
);
888 len
= sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100 );
889 msi_set_property( package
->db
, szVersionDatabase
, bufstr
, len
);
891 GetNativeSystemInfo( &sys_info
);
892 len
= sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
893 msi_set_property( package
->db
, szIntel
, bufstr
, len
);
894 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
896 GetSystemDirectoryW( pth
, MAX_PATH
);
897 PathAddBackslashW( pth
);
898 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
900 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
901 PathAddBackslashW( pth
);
902 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
904 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
905 PathAddBackslashW( pth
);
906 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
908 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
910 msi_set_property( package
->db
, szMsiAMD64
, bufstr
, -1 );
911 msi_set_property( package
->db
, szMsix64
, bufstr
, -1 );
912 msi_set_property( package
->db
, szVersionNT64
, verstr
, -1 );
914 GetSystemDirectoryW( pth
, MAX_PATH
);
915 PathAddBackslashW( pth
);
916 msi_set_property( package
->db
, szSystem64Folder
, pth
, -1 );
918 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
919 PathAddBackslashW( pth
);
920 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
922 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
923 PathAddBackslashW( pth
);
924 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
, -1 );
926 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
927 PathAddBackslashW( pth
);
928 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
930 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
931 PathAddBackslashW( pth
);
932 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
, -1 );
934 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
935 PathAddBackslashW( pth
);
936 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
939 /* Screen properties. */
941 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, HORZRES
) );
942 msi_set_property( package
->db
, szScreenX
, bufstr
, len
);
943 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, VERTRES
) );
944 msi_set_property( package
->db
, szScreenY
, bufstr
, len
);
945 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, BITSPIXEL
) );
946 msi_set_property( package
->db
, szColorBits
, bufstr
, len
);
949 /* USERNAME and COMPANYNAME */
950 username
= msi_dup_property( package
->db
, szUSERNAME
);
951 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
953 if ((!username
|| !companyname
) &&
954 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
957 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
958 msi_set_property( package
->db
, szUSERNAME
, username
, -1 );
960 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
961 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
964 if ((!username
|| !companyname
) &&
965 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
968 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
969 msi_set_property( package
->db
, szUSERNAME
, username
, -1 );
971 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
972 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
975 msi_free( username
);
976 msi_free( companyname
);
978 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
979 ERR("Failed to set the UserSID property\n");
981 /* Date and time properties */
982 GetSystemTime( &systemtime
);
983 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
984 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
985 msi_set_property( package
->db
, szDate
, bufstr
, -1 );
987 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
989 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
990 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
991 &systemtime
, NULL
, bufstr
,
992 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
993 msi_set_property( package
->db
, szTime
, bufstr
, -1 );
995 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
997 set_msi_assembly_prop( package
);
999 langid
= GetUserDefaultLangID();
1000 len
= sprintfW( bufstr
, szIntFormat
, langid
);
1001 msi_set_property( package
->db
, szUserLanguageID
, bufstr
, len
);
1003 langid
= GetSystemDefaultLangID();
1004 len
= sprintfW( bufstr
, szIntFormat
, langid
);
1005 msi_set_property( package
->db
, szSystemLangID
, bufstr
, len
);
1007 len
= sprintfW( bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
) );
1008 msi_set_property( package
->db
, szProductState
, bufstr
, len
);
1011 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1014 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
1016 if (GetUserNameW( username
, &len
))
1017 msi_set_property( package
->db
, szLogonUser
, username
, len
- 1 );
1018 msi_free( username
);
1022 if (!GetComputerNameW( NULL
, &len
) && GetLastError() == ERROR_BUFFER_OVERFLOW
)
1024 WCHAR
*computername
;
1025 if ((computername
= msi_alloc( len
* sizeof(WCHAR
) )))
1027 if (GetComputerNameW( computername
, &len
))
1028 msi_set_property( package
->db
, szComputerName
, computername
, len
- 1 );
1029 msi_free( computername
);
1032 msi_set_property( package
->db
, szBrowseProperty
, szInstallDir
, -1 );
1035 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
1039 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
1042 LPWSTR package_code
;
1043 static const WCHAR szPackageCode
[] = {
1044 'P','a','c','k','a','g','e','C','o','d','e',0};
1047 ERR("Unable to allocate handle\n");
1048 return ERROR_OUTOFMEMORY
;
1051 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
1052 MsiCloseHandle(hdb
);
1053 if (rc
!= ERROR_SUCCESS
)
1055 ERR("Unable to open Summary Information\n");
1059 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
1060 &count
, NULL
, NULL
, NULL
);
1061 if (rc
!= ERROR_SUCCESS
)
1063 WARN("Unable to query page count: %d\n", rc
);
1067 /* load package code property */
1069 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1070 NULL
, NULL
, NULL
, &len
);
1071 if (rc
!= ERROR_MORE_DATA
)
1073 WARN("Unable to query revision number: %d\n", rc
);
1074 rc
= ERROR_FUNCTION_FAILED
;
1079 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
1080 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1081 NULL
, NULL
, package_code
, &len
);
1082 if (rc
!= ERROR_SUCCESS
)
1084 WARN("Unable to query rev number: %d\n", rc
);
1088 msi_set_property( package
->db
, szPackageCode
, package_code
, len
);
1089 msi_free( package_code
);
1091 /* load package attributes */
1093 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
1094 &count
, NULL
, NULL
, NULL
);
1095 package
->WordCount
= count
;
1098 MsiCloseHandle(suminfo
);
1102 static MSIPACKAGE
*msi_alloc_package( void )
1104 MSIPACKAGE
*package
;
1106 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1110 list_init( &package
->components
);
1111 list_init( &package
->features
);
1112 list_init( &package
->files
);
1113 list_init( &package
->filepatches
);
1114 list_init( &package
->tempfiles
);
1115 list_init( &package
->folders
);
1116 list_init( &package
->subscriptions
);
1117 list_init( &package
->appids
);
1118 list_init( &package
->classes
);
1119 list_init( &package
->mimes
);
1120 list_init( &package
->extensions
);
1121 list_init( &package
->progids
);
1122 list_init( &package
->RunningActions
);
1123 list_init( &package
->sourcelist_info
);
1124 list_init( &package
->sourcelist_media
);
1125 list_init( &package
->patches
);
1126 list_init( &package
->binaries
);
1127 list_init( &package
->cabinet_streams
);
1133 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1138 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1140 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1141 if (r
!= ERROR_SUCCESS
)
1144 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1150 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1152 /* FIXME: this should depend on the user's privileges */
1153 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1155 TRACE("resetting ALLUSERS property from 2 to 1\n");
1156 msi_set_property( package
->db
, szAllUsers
, szOne
, -1 );
1158 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
1161 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1163 static const WCHAR fmtW
[] = {'%','u',0};
1164 MSIPACKAGE
*package
;
1171 package
= msi_alloc_package();
1174 msiobj_addref( &db
->hdr
);
1177 package
->WordCount
= 0;
1178 package
->PackagePath
= strdupW( db
->path
);
1179 package
->BaseURL
= strdupW( base_url
);
1181 create_temp_property_table( package
);
1182 msi_clone_properties( package
);
1183 msi_adjust_privilege_properties( package
);
1185 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1186 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1188 set_installed_prop( package
);
1189 set_installer_properties( package
);
1191 package
->ui_level
= gUILevel
;
1192 len
= sprintfW( uilevel
, fmtW
, gUILevel
& INSTALLUILEVEL_MASK
);
1193 msi_set_property( package
->db
, szUILevel
, uilevel
, len
);
1195 r
= msi_load_summary_properties( package
);
1196 if (r
!= ERROR_SUCCESS
)
1198 msiobj_release( &package
->hdr
);
1202 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1203 msi_load_admin_properties( package
);
1205 package
->log_file
= INVALID_HANDLE_VALUE
;
1210 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1212 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1216 /* call will always fail, because size is 0,
1217 * but will return ERROR_FILE_NOT_FOUND first
1218 * if the file doesn't exist
1220 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1221 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1223 cache_entry
= msi_alloc( size
);
1224 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1226 UINT error
= GetLastError();
1227 msi_free( cache_entry
);
1231 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1232 msi_free( cache_entry
);
1233 return ERROR_SUCCESS
;
1236 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1239 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1240 return ERROR_FUNCTION_FAILED
;
1243 return ERROR_SUCCESS
;
1246 UINT
msi_create_empty_local_file( LPWSTR path
, LPCWSTR suffix
)
1248 static const WCHAR szInstaller
[] = {
1249 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1250 static const WCHAR fmt
[] = {'%','x',0};
1251 DWORD time
, len
, i
, offset
;
1254 time
= GetTickCount();
1255 GetWindowsDirectoryW( path
, MAX_PATH
);
1256 strcatW( path
, szInstaller
);
1257 CreateDirectoryW( path
, NULL
);
1259 len
= strlenW(path
);
1260 for (i
= 0; i
< 0x10000; i
++)
1262 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1263 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1264 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1265 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1266 if (handle
!= INVALID_HANDLE_VALUE
)
1268 CloseHandle(handle
);
1271 if (GetLastError() != ERROR_FILE_EXISTS
&&
1272 GetLastError() != ERROR_SHARING_VIOLATION
)
1273 return ERROR_FUNCTION_FAILED
;
1276 return ERROR_SUCCESS
;
1279 static enum platform
parse_platform( WCHAR
*str
)
1281 if (!str
[0] || !strcmpW( str
, szIntel
)) return PLATFORM_INTEL
;
1282 else if (!strcmpW( str
, szIntel64
)) return PLATFORM_INTEL64
;
1283 else if (!strcmpW( str
, szX64
) || !strcmpW( str
, szAMD64
)) return PLATFORM_X64
;
1284 else if (!strcmpW( str
, szARM
)) return PLATFORM_ARM
;
1285 return PLATFORM_UNKNOWN
;
1288 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1290 WCHAR
*template, *p
, *q
, *platform
;
1293 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1294 TRACE("version: %d\n", package
->version
);
1296 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1298 return ERROR_SUCCESS
; /* native accepts missing template property */
1300 TRACE("template: %s\n", debugstr_w(template));
1302 p
= strchrW( template, ';' );
1305 WARN("invalid template string %s\n", debugstr_w(template));
1306 msi_free( template );
1307 return ERROR_PATCH_PACKAGE_INVALID
;
1310 platform
= template;
1311 if ((q
= strchrW( platform
, ',' ))) *q
= 0;
1312 package
->platform
= parse_platform( platform
);
1313 while (package
->platform
== PLATFORM_UNKNOWN
&& q
)
1316 if ((q
= strchrW( platform
, ',' ))) *q
= 0;
1317 package
->platform
= parse_platform( platform
);
1319 if (package
->platform
== PLATFORM_UNKNOWN
)
1321 WARN("unknown platform %s\n", debugstr_w(template));
1322 msi_free( template );
1323 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1328 msi_free( template );
1329 return ERROR_SUCCESS
;
1332 for (q
= p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1334 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1335 if (!package
->langids
)
1337 msi_free( template );
1338 return ERROR_OUTOFMEMORY
;
1344 q
= strchrW( p
, ',' );
1346 package
->langids
[i
] = atoiW( p
);
1351 package
->num_langids
= i
+ 1;
1353 msi_free( template );
1354 return ERROR_SUCCESS
;
1357 static UINT
validate_package( MSIPACKAGE
*package
)
1361 if (package
->platform
== PLATFORM_INTEL64
)
1362 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1364 if (package
->platform
== PLATFORM_ARM
)
1365 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1367 if (package
->platform
== PLATFORM_X64
)
1369 if (!is_64bit
&& !is_wow64
)
1370 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1371 if (package
->version
< 200)
1372 return ERROR_INSTALL_PACKAGE_INVALID
;
1374 if (!package
->num_langids
)
1376 return ERROR_SUCCESS
;
1378 for (i
= 0; i
< package
->num_langids
; i
++)
1380 LANGID langid
= package
->langids
[i
];
1382 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1384 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1386 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1388 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1390 if (IsValidLocale( langid
, LCID_INSTALLED
))
1391 return ERROR_SUCCESS
;
1393 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1396 int msi_track_tempfile( MSIPACKAGE
*package
, const WCHAR
*path
)
1400 TRACE("%s\n", debugstr_w(path
));
1402 LIST_FOR_EACH_ENTRY( temp
, &package
->tempfiles
, MSITEMPFILE
, entry
)
1404 if (!strcmpW( path
, temp
->Path
)) return 0;
1406 if (!(temp
= msi_alloc_zero( sizeof (MSITEMPFILE
) ))) return -1;
1407 list_add_head( &package
->tempfiles
, &temp
->entry
);
1408 temp
->Path
= strdupW( path
);
1412 static WCHAR
*get_product_code( MSIDATABASE
*db
)
1414 static const WCHAR query
[] = {
1415 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1416 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1417 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1418 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1423 if (MSI_DatabaseOpenViewW( db
, query
, &view
) != ERROR_SUCCESS
)
1427 if (MSI_ViewExecute( view
, 0 ) != ERROR_SUCCESS
)
1429 MSI_ViewClose( view
);
1430 msiobj_release( &view
->hdr
);
1433 if (MSI_ViewFetch( view
, &rec
) == ERROR_SUCCESS
)
1435 ret
= strdupW( MSI_RecordGetString( rec
, 1 ) );
1436 msiobj_release( &rec
->hdr
);
1438 MSI_ViewClose( view
);
1439 msiobj_release( &view
->hdr
);
1443 static UINT
get_registered_local_package( const WCHAR
*product
, const WCHAR
*package
, WCHAR
*localfile
)
1445 MSIINSTALLCONTEXT context
;
1446 HKEY product_key
, props_key
;
1447 WCHAR
*registered_package
= NULL
, unsquashed
[GUID_SIZE
];
1450 r
= msi_locate_product( product
, &context
);
1451 if (r
!= ERROR_SUCCESS
)
1454 r
= MSIREG_OpenProductKey( product
, NULL
, context
, &product_key
, FALSE
);
1455 if (r
!= ERROR_SUCCESS
)
1458 r
= MSIREG_OpenInstallProps( product
, context
, NULL
, &props_key
, FALSE
);
1459 if (r
!= ERROR_SUCCESS
)
1461 RegCloseKey( product_key
);
1464 r
= ERROR_FUNCTION_FAILED
;
1465 registered_package
= msi_reg_get_val_str( product_key
, INSTALLPROPERTY_PACKAGECODEW
);
1466 if (!registered_package
)
1469 unsquash_guid( registered_package
, unsquashed
);
1470 if (!strcmpiW( package
, unsquashed
))
1472 WCHAR
*filename
= msi_reg_get_val_str( props_key
, INSTALLPROPERTY_LOCALPACKAGEW
);
1476 strcpyW( localfile
, filename
);
1477 msi_free( filename
);
1481 msi_free( registered_package
);
1482 RegCloseKey( props_key
);
1483 RegCloseKey( product_key
);
1487 static WCHAR
*get_package_code( MSIDATABASE
*db
)
1492 if (!(si
= MSI_GetSummaryInformationW( db
->storage
, 0 )))
1494 WARN("failed to load summary info\n");
1497 ret
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
1498 msiobj_release( &si
->hdr
);
1502 static UINT
get_local_package( const WCHAR
*filename
, WCHAR
*localfile
)
1504 WCHAR
*product_code
, *package_code
;
1508 if ((r
= MSI_OpenDatabaseW( filename
, MSIDBOPEN_READONLY
, &db
)) != ERROR_SUCCESS
)
1510 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1511 return ERROR_FILE_NOT_FOUND
;
1514 if (!(product_code
= get_product_code( db
)))
1516 msiobj_release( &db
->hdr
);
1517 return ERROR_INSTALL_PACKAGE_INVALID
;
1519 if (!(package_code
= get_package_code( db
)))
1521 msi_free( product_code
);
1522 msiobj_release( &db
->hdr
);
1523 return ERROR_INSTALL_PACKAGE_INVALID
;
1525 r
= get_registered_local_package( product_code
, package_code
, localfile
);
1526 msi_free( package_code
);
1527 msi_free( product_code
);
1528 msiobj_release( &db
->hdr
);
1532 UINT
msi_set_original_database_property( MSIDATABASE
*db
, const WCHAR
*package
)
1536 if (UrlIsW( package
, URLIS_URL
))
1537 r
= msi_set_property( db
, szOriginalDatabase
, package
, -1 );
1538 else if (package
[0] == '#')
1539 r
= msi_set_property( db
, szOriginalDatabase
, db
->path
, -1 );
1545 if (!(len
= GetFullPathNameW( package
, 0, NULL
, NULL
))) return GetLastError();
1546 if (!(path
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1547 len
= GetFullPathNameW( package
, len
, path
, NULL
);
1548 r
= msi_set_property( db
, szOriginalDatabase
, path
, len
);
1554 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1556 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1558 MSIPACKAGE
*package
;
1560 LPWSTR ptr
, base_url
= NULL
;
1562 WCHAR localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1563 LPCWSTR file
= szPackage
;
1566 BOOL delete_on_close
= FALSE
;
1568 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1571 if( szPackage
[0] == '#' )
1573 handle
= atoiW(&szPackage
[1]);
1574 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1577 IWineMsiRemoteDatabase
*remote_database
;
1579 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1580 if ( !remote_database
)
1581 return ERROR_INVALID_HANDLE
;
1583 IWineMsiRemoteDatabase_Release( remote_database
);
1584 WARN("MsiOpenPackage not allowed during a custom action!\n");
1586 return ERROR_FUNCTION_FAILED
;
1591 if ( UrlIsW( szPackage
, URLIS_URL
) )
1593 r
= msi_download_file( szPackage
, cachefile
);
1594 if (r
!= ERROR_SUCCESS
)
1599 base_url
= strdupW( szPackage
);
1601 return ERROR_OUTOFMEMORY
;
1603 ptr
= strrchrW( base_url
, '/' );
1604 if (ptr
) *(ptr
+ 1) = '\0';
1606 r
= get_local_package( file
, localfile
);
1607 if (r
!= ERROR_SUCCESS
|| GetFileAttributesW( localfile
) == INVALID_FILE_ATTRIBUTES
)
1609 r
= msi_create_empty_local_file( localfile
, dotmsi
);
1610 if (r
!= ERROR_SUCCESS
)
1612 msi_free ( base_url
);
1616 if (!CopyFileW( file
, localfile
, FALSE
))
1619 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file
), debugstr_w(localfile
), r
);
1620 DeleteFileW( localfile
);
1621 msi_free ( base_url
);
1624 delete_on_close
= TRUE
;
1626 TRACE("opening package %s\n", debugstr_w( localfile
));
1627 r
= MSI_OpenDatabaseW( localfile
, MSIDBOPEN_TRANSACT
, &db
);
1628 if (r
!= ERROR_SUCCESS
)
1630 msi_free ( base_url
);
1634 package
= MSI_CreatePackage( db
, base_url
);
1635 msi_free( base_url
);
1636 msiobj_release( &db
->hdr
);
1637 if (!package
) return ERROR_INSTALL_PACKAGE_INVALID
;
1638 package
->localfile
= strdupW( localfile
);
1639 package
->delete_on_close
= delete_on_close
;
1641 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1644 WARN("failed to load summary info\n");
1645 msiobj_release( &package
->hdr
);
1646 return ERROR_INSTALL_PACKAGE_INVALID
;
1648 r
= msi_parse_summary( si
, package
);
1649 msiobj_release( &si
->hdr
);
1650 if (r
!= ERROR_SUCCESS
)
1652 WARN("failed to parse summary info %u\n", r
);
1653 msiobj_release( &package
->hdr
);
1656 r
= validate_package( package
);
1657 if (r
!= ERROR_SUCCESS
)
1659 msiobj_release( &package
->hdr
);
1662 msi_set_property( package
->db
, szDatabase
, db
->path
, -1 );
1663 msi_set_context( package
);
1667 WCHAR patch_code
[GUID_SIZE
];
1668 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1669 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1670 if (r
!= ERROR_SUCCESS
)
1673 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1675 r
= msi_apply_registered_patch( package
, patch_code
);
1676 if (r
!= ERROR_SUCCESS
)
1678 ERR("registered patch failed to apply %u\n", r
);
1679 msiobj_release( &package
->hdr
);
1686 msi_clone_properties( package
);
1687 msi_adjust_privilege_properties( package
);
1689 r
= msi_set_original_database_property( package
->db
, szPackage
);
1690 if (r
!= ERROR_SUCCESS
)
1692 msiobj_release( &package
->hdr
);
1696 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1697 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1698 *pPackage
= package
;
1699 return ERROR_SUCCESS
;
1702 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1704 MSIPACKAGE
*package
= NULL
;
1707 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1709 if( !szPackage
|| !phPackage
)
1710 return ERROR_INVALID_PARAMETER
;
1714 FIXME("Should create an empty database and package\n");
1715 return ERROR_FUNCTION_FAILED
;
1719 FIXME("dwOptions %08x not supported\n", dwOptions
);
1721 ret
= MSI_OpenPackageW( szPackage
, &package
);
1722 if( ret
== ERROR_SUCCESS
)
1724 *phPackage
= alloc_msihandle( &package
->hdr
);
1726 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1727 msiobj_release( &package
->hdr
);
1733 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1735 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1738 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1740 LPWSTR szwPack
= NULL
;
1745 szwPack
= strdupAtoW( szPackage
);
1747 return ERROR_OUTOFMEMORY
;
1750 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1752 msi_free( szwPack
);
1757 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1759 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1762 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1764 MSIPACKAGE
*package
;
1765 MSIHANDLE handle
= 0;
1766 IUnknown
*remote_unk
;
1767 IWineMsiRemotePackage
*remote_package
;
1769 TRACE("(%d)\n",hInstall
);
1771 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1774 handle
= alloc_msihandle( &package
->db
->hdr
);
1775 msiobj_release( &package
->hdr
);
1777 else if ((remote_unk
= msi_get_remote(hInstall
)))
1779 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1780 (LPVOID
*)&remote_package
) == S_OK
)
1782 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1783 IWineMsiRemotePackage_Release(remote_package
);
1787 WARN("remote handle %d is not a package\n", hInstall
);
1789 IUnknown_Release(remote_unk
);
1795 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1797 static const WCHAR szActionData
[] = {'A','c','t','i','o','n','D','a','t','a',0};
1798 static const WCHAR szSetProgress
[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1799 static const WCHAR szActionText
[] = {'A','c','t','i','o','n','T','e','x','t',0};
1801 LPWSTR deformated
, message
;
1802 DWORD i
, len
, total_len
, log_type
= 0;
1806 TRACE("%x\n", eMessageType
);
1808 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_FATALEXIT
)
1809 log_type
|= INSTALLLOGMODE_FATALEXIT
;
1810 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1811 log_type
|= INSTALLLOGMODE_ERROR
;
1812 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1813 log_type
|= INSTALLLOGMODE_WARNING
;
1814 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1815 log_type
|= INSTALLLOGMODE_USER
;
1816 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1817 log_type
|= INSTALLLOGMODE_INFO
;
1818 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE
)
1819 log_type
|= INSTALLLOGMODE_RESOLVESOURCE
;
1820 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE
)
1821 log_type
|= INSTALLLOGMODE_OUTOFDISKSPACE
;
1822 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1823 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1824 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1825 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1826 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1827 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1828 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1829 log_type
|= INSTALLLOGMODE_PROGRESS
;
1830 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
)
1831 log_type
|= INSTALLLOGMODE_INITIALIZE
;
1832 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
1833 log_type
|= INSTALLLOGMODE_TERMINATE
;
1834 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_SHOWDIALOG
)
1835 log_type
|= INSTALLLOGMODE_SHOWDIALOG
;
1837 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1839 static const WCHAR template_s
[]=
1840 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1841 static const WCHAR format
[] =
1842 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1844 LPCWSTR action_text
, action
;
1845 LPWSTR deformatted
= NULL
;
1847 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1849 action
= MSI_RecordGetString(record
, 1);
1850 action_text
= MSI_RecordGetString(record
, 2);
1852 if (!action
|| !action_text
)
1855 deformat_string(package
, action_text
, &deformatted
);
1857 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1859 len
+= strlenW(deformatted
);
1860 message
= msi_alloc(len
*sizeof(WCHAR
));
1861 sprintfW(message
, template_s
, timet
, action
);
1863 strcatW(message
, deformatted
);
1864 msi_free(deformatted
);
1868 static const WCHAR format
[] = {'%','u',':',' ',0};
1869 UINT count
= MSI_RecordGetFieldCount( record
);
1873 for (i
= 1; i
<= count
; i
++)
1876 MSI_RecordGetStringW( record
, i
, NULL
, &len
);
1877 total_len
+= len
+ 13;
1879 p
= message
= msi_alloc( total_len
* sizeof(WCHAR
) );
1880 if (!p
) return ERROR_OUTOFMEMORY
;
1882 for (i
= 1; i
<= count
; i
++)
1886 len
= sprintfW( p
, format
, i
);
1891 MSI_RecordGetStringW( record
, i
, p
, &len
);
1894 if (count
> 1 && total_len
)
1903 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1904 gUIFilter
, log_type
, debugstr_w(message
));
1906 /* convert it to ASCII */
1907 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1908 msg
= msi_alloc( len
);
1909 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1911 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1913 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1915 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1917 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1919 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1921 MSIHANDLE rec
= MsiCreateRecord( 1 );
1922 MsiRecordSetStringW( rec
, 0, message
);
1923 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1924 MsiCloseHandle( rec
);
1927 if (!rc
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1928 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1931 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1932 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1935 msi_free( message
);
1937 switch (eMessageType
& 0xff000000)
1939 case INSTALLMESSAGE_ACTIONDATA
:
1940 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformated
);
1941 uirow
= MSI_CreateRecord(1);
1942 MSI_RecordSetStringW(uirow
, 1, deformated
);
1943 msi_free(deformated
);
1945 ControlEvent_FireSubscribedEvent(package
, szActionData
, uirow
);
1946 msiobj_release(&uirow
->hdr
);
1948 if (package
->action_progress_increment
)
1950 uirow
= MSI_CreateRecord(2);
1951 MSI_RecordSetInteger(uirow
, 1, 2);
1952 MSI_RecordSetInteger(uirow
, 2, package
->action_progress_increment
);
1953 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, uirow
);
1954 msiobj_release(&uirow
->hdr
);
1958 case INSTALLMESSAGE_ACTIONSTART
:
1959 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformated
);
1960 uirow
= MSI_CreateRecord(1);
1961 MSI_RecordSetStringW(uirow
, 1, deformated
);
1962 msi_free(deformated
);
1964 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1966 msiobj_release(&uirow
->hdr
);
1969 case INSTALLMESSAGE_PROGRESS
:
1970 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1974 return ERROR_SUCCESS
;
1977 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1980 UINT ret
= ERROR_INVALID_HANDLE
;
1981 MSIPACKAGE
*package
= NULL
;
1982 MSIRECORD
*record
= NULL
;
1984 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1988 IWineMsiRemotePackage
*remote_package
;
1990 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1991 if (!remote_package
)
1992 return ERROR_INVALID_HANDLE
;
1994 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1996 IWineMsiRemotePackage_Release( remote_package
);
2000 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2001 return HRESULT_CODE(hr
);
2003 return ERROR_FUNCTION_FAILED
;
2006 return ERROR_SUCCESS
;
2009 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
2013 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
2016 msiobj_release( &package
->hdr
);
2018 msiobj_release( &record
->hdr
);
2025 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
2027 LPWSTR szwName
= NULL
, szwValue
= NULL
;
2028 UINT r
= ERROR_OUTOFMEMORY
;
2030 szwName
= strdupAtoW( szName
);
2031 if( szName
&& !szwName
)
2034 szwValue
= strdupAtoW( szValue
);
2035 if( szValue
&& !szwValue
)
2038 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
2041 msi_free( szwName
);
2042 msi_free( szwValue
);
2047 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
2051 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
2055 msi_free( folder
->ResolvedSource
);
2056 folder
->ResolvedSource
= NULL
;
2060 msi_free( folder
->ResolvedTarget
);
2061 folder
->ResolvedTarget
= NULL
;
2066 UINT
msi_set_property( MSIDATABASE
*db
, const WCHAR
*name
, const WCHAR
*value
, int len
)
2068 static const WCHAR insert_query
[] = {
2069 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2070 '`','_','P','r','o','p','e','r','t','y','`',' ',
2071 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2072 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2073 static const WCHAR update_query
[] = {
2074 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2075 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2076 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2077 static const WCHAR delete_query
[] = {
2078 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2079 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2080 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2082 MSIRECORD
*row
= NULL
;
2087 TRACE("%p %s %s %d\n", db
, debugstr_w(name
), debugstr_wn(value
, len
), len
);
2090 return ERROR_INVALID_PARAMETER
;
2092 /* this one is weird... */
2094 return value
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
2096 if (value
&& len
< 0) len
= strlenW( value
);
2098 rc
= msi_get_property( db
, name
, 0, &sz
);
2099 if (!value
|| (!*value
&& !len
))
2101 sprintfW( query
, delete_query
, name
);
2103 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
2105 sprintfW( query
, update_query
, name
);
2106 row
= MSI_CreateRecord(1);
2107 msi_record_set_string( row
, 1, value
, len
);
2111 strcpyW( query
, insert_query
);
2112 row
= MSI_CreateRecord(2);
2113 msi_record_set_string( row
, 1, name
, -1 );
2114 msi_record_set_string( row
, 2, value
, len
);
2117 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2118 if (rc
== ERROR_SUCCESS
)
2120 rc
= MSI_ViewExecute(view
, row
);
2121 MSI_ViewClose(view
);
2122 msiobj_release(&view
->hdr
);
2124 if (row
) msiobj_release(&row
->hdr
);
2128 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2130 MSIPACKAGE
*package
;
2133 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2137 BSTR name
= NULL
, value
= NULL
;
2138 IWineMsiRemotePackage
*remote_package
;
2140 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2141 if (!remote_package
)
2142 return ERROR_INVALID_HANDLE
;
2144 name
= SysAllocString( szName
);
2145 value
= SysAllocString( szValue
);
2146 if ((!name
&& szName
) || (!value
&& szValue
))
2148 SysFreeString( name
);
2149 SysFreeString( value
);
2150 IWineMsiRemotePackage_Release( remote_package
);
2151 return ERROR_OUTOFMEMORY
;
2154 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2156 SysFreeString( name
);
2157 SysFreeString( value
);
2158 IWineMsiRemotePackage_Release( remote_package
);
2162 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2163 return HRESULT_CODE(hr
);
2165 return ERROR_FUNCTION_FAILED
;
2168 return ERROR_SUCCESS
;
2171 ret
= msi_set_property( package
->db
, szName
, szValue
, -1 );
2172 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, szSourceDir
))
2173 msi_reset_folders( package
, TRUE
);
2175 msiobj_release( &package
->hdr
);
2179 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2181 static const WCHAR query
[]= {
2182 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2183 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2184 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2185 MSIRECORD
*rec
, *row
= NULL
;
2189 if (!name
|| !*name
)
2192 rec
= MSI_CreateRecord(1);
2196 MSI_RecordSetStringW(rec
, 1, name
);
2198 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2199 if (r
== ERROR_SUCCESS
)
2201 MSI_ViewExecute(view
, rec
);
2202 MSI_ViewFetch(view
, &row
);
2203 MSI_ViewClose(view
);
2204 msiobj_release(&view
->hdr
);
2206 msiobj_release(&rec
->hdr
);
2210 /* internal function, not compatible with MsiGetPropertyW */
2211 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2212 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2215 UINT rc
= ERROR_FUNCTION_FAILED
;
2217 row
= msi_get_property_row( db
, szName
);
2219 if (*pchValueBuf
> 0)
2224 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2225 msiobj_release(&row
->hdr
);
2228 if (rc
== ERROR_SUCCESS
)
2229 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf
, *pchValueBuf
),
2230 debugstr_w(szName
));
2231 else if (rc
== ERROR_MORE_DATA
)
2232 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2233 debugstr_w(szName
));
2237 TRACE("property %s not found\n", debugstr_w(szName
));
2243 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2249 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2250 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2254 str
= msi_alloc(sz
* sizeof(WCHAR
));
2255 r
= msi_get_property(db
, prop
, str
, &sz
);
2256 if (r
!= ERROR_SUCCESS
)
2265 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2267 LPWSTR str
= msi_dup_property( db
, prop
);
2268 int val
= str
? atoiW(str
) : def
;
2273 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2274 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2276 MSIPACKAGE
*package
;
2277 MSIRECORD
*row
= NULL
;
2278 UINT r
= ERROR_FUNCTION_FAILED
;
2282 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2283 szValueBuf
->str
.w
, pchValueBuf
);
2286 return ERROR_INVALID_PARAMETER
;
2288 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2292 IWineMsiRemotePackage
*remote_package
;
2293 LPWSTR value
= NULL
;
2296 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2297 if (!remote_package
)
2298 return ERROR_INVALID_HANDLE
;
2300 bname
= SysAllocString( name
);
2303 IWineMsiRemotePackage_Release( remote_package
);
2304 return ERROR_OUTOFMEMORY
;
2307 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2312 value
= msi_alloc(len
* sizeof(WCHAR
));
2315 r
= ERROR_OUTOFMEMORY
;
2319 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, value
, &len
);
2323 r
= msi_strcpy_to_awstring( value
, len
, szValueBuf
, pchValueBuf
);
2325 /* Bug required by Adobe installers */
2326 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2327 *pchValueBuf
*= sizeof(WCHAR
);
2330 IWineMsiRemotePackage_Release(remote_package
);
2331 SysFreeString(bname
);
2336 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2337 return HRESULT_CODE(hr
);
2339 return ERROR_FUNCTION_FAILED
;
2345 row
= msi_get_property_row( package
->db
, name
);
2347 val
= msi_record_get_string( row
, 1, (int *)&len
);
2352 r
= msi_strcpy_to_awstring( val
, len
, szValueBuf
, pchValueBuf
);
2355 msiobj_release( &row
->hdr
);
2356 msiobj_release( &package
->hdr
);
2361 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2362 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2368 val
.unicode
= FALSE
;
2369 val
.str
.a
= szValueBuf
;
2371 name
= strdupAtoW( szName
);
2372 if (szName
&& !name
)
2373 return ERROR_OUTOFMEMORY
;
2375 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2380 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2381 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2386 val
.str
.w
= szValueBuf
;
2388 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2391 typedef struct _msi_remote_package_impl
{
2392 IWineMsiRemotePackage IWineMsiRemotePackage_iface
;
2395 } msi_remote_package_impl
;
2397 static inline msi_remote_package_impl
*impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage
*iface
)
2399 return CONTAINING_RECORD(iface
, msi_remote_package_impl
, IWineMsiRemotePackage_iface
);
2402 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2403 REFIID riid
,LPVOID
*ppobj
)
2405 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2406 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2408 IWineMsiRemotePackage_AddRef( iface
);
2413 return E_NOINTERFACE
;
2416 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2418 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2420 return InterlockedIncrement( &This
->refs
);
2423 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2425 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2428 r
= InterlockedDecrement( &This
->refs
);
2431 MsiCloseHandle( This
->package
);
2437 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2439 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2440 This
->package
= handle
;
2444 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2446 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2447 IWineMsiRemoteDatabase
*rdb
= NULL
;
2451 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2452 if (FAILED(hr
) || !rdb
)
2454 ERR("Failed to create remote database\n");
2458 hdb
= MsiGetActiveDatabase(This
->package
);
2460 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2463 ERR("Failed to set the database handle\n");
2467 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2471 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
, DWORD
*size
)
2473 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2474 UINT r
= MsiGetPropertyW(This
->package
, property
, value
, size
);
2475 if (r
!= ERROR_SUCCESS
) return HRESULT_FROM_WIN32(r
);
2479 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2481 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2482 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2483 return HRESULT_FROM_WIN32(r
);
2486 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2488 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2489 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2490 return HRESULT_FROM_WIN32(r
);
2493 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2495 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2496 UINT r
= MsiDoActionW(This
->package
, action
);
2497 return HRESULT_FROM_WIN32(r
);
2500 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2502 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2503 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2504 return HRESULT_FROM_WIN32(r
);
2507 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2509 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2510 UINT r
= MsiGetTargetPathW(This
->package
, folder
, value
, size
);
2511 return HRESULT_FROM_WIN32(r
);
2514 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2516 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2517 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2518 return HRESULT_FROM_WIN32(r
);
2521 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2523 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2524 UINT r
= MsiGetSourcePathW(This
->package
, folder
, value
, size
);
2525 return HRESULT_FROM_WIN32(r
);
2528 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2530 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2531 *ret
= MsiGetMode(This
->package
, mode
);
2535 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2537 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2538 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2539 return HRESULT_FROM_WIN32(r
);
2542 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2543 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2545 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2546 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2547 return HRESULT_FROM_WIN32(r
);
2550 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2552 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2553 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2554 return HRESULT_FROM_WIN32(r
);
2557 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2558 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2560 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2561 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2562 return HRESULT_FROM_WIN32(r
);
2565 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2567 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2568 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2569 return HRESULT_FROM_WIN32(r
);
2572 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2574 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2575 *language
= MsiGetLanguage(This
->package
);
2579 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2581 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2582 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2583 return HRESULT_FROM_WIN32(r
);
2586 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2590 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2591 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2592 if (r
== ERROR_SUCCESS
)
2594 *value
= SysAllocStringLen(NULL
, size
);
2596 return E_OUTOFMEMORY
;
2598 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2600 return HRESULT_FROM_WIN32(r
);
2603 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2605 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2606 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2607 return HRESULT_FROM_WIN32(r
);
2610 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2611 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2613 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2614 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2615 return HRESULT_FROM_WIN32(r
);
2618 static HRESULT WINAPI
mrp_EnumComponentCosts( IWineMsiRemotePackage
*iface
, BSTR component
,
2619 DWORD index
, INSTALLSTATE state
, BSTR drive
,
2620 DWORD
*buflen
, INT
*cost
, INT
*temp
)
2622 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2623 UINT r
= MsiEnumComponentCostsW(This
->package
, component
, index
, state
, drive
, buflen
, cost
, temp
);
2624 return HRESULT_FROM_WIN32(r
);
2627 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2633 mrp_GetActiveDatabase
,
2644 mrp_GetFeatureState
,
2645 mrp_SetFeatureState
,
2646 mrp_GetComponentState
,
2647 mrp_SetComponentState
,
2649 mrp_SetInstallLevel
,
2651 mrp_EvaluateCondition
,
2653 mrp_EnumComponentCosts
2656 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2658 msi_remote_package_impl
* This
;
2660 This
= msi_alloc( sizeof *This
);
2662 return E_OUTOFMEMORY
;
2664 This
->IWineMsiRemotePackage_iface
.lpVtbl
= &msi_remote_package_vtbl
;
2673 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2674 LPCWSTR property
, LPWSTR value
)
2676 MSISOURCELISTINFO
*info
;
2678 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2680 if (!strcmpW( info
->value
, value
)) return ERROR_SUCCESS
;
2683 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2685 return ERROR_OUTOFMEMORY
;
2687 info
->context
= context
;
2688 info
->options
= options
;
2689 info
->property
= property
;
2690 info
->value
= strdupW(value
);
2691 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2693 return ERROR_SUCCESS
;
2696 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2697 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2701 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2703 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2706 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2708 return ERROR_OUTOFMEMORY
;
2710 disk
->context
= context
;
2711 disk
->options
= options
;
2712 disk
->disk_id
= disk_id
;
2713 disk
->volume_label
= strdupW(volume_label
);
2714 disk
->disk_prompt
= strdupW(disk_prompt
);
2715 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2717 return ERROR_SUCCESS
;