2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
42 #include "wine/unicode.h"
48 #include "msiserver.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
53 static void free_feature( MSIFEATURE
*feature
)
55 struct list
*item
, *cursor
;
57 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
59 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
60 list_remove( &fl
->entry
);
64 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
66 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
67 list_remove( &cl
->entry
);
70 msi_free( feature
->Feature
);
71 msi_free( feature
->Feature_Parent
);
72 msi_free( feature
->Directory
);
73 msi_free( feature
->Description
);
74 msi_free( feature
->Title
);
78 static void free_folder( MSIFOLDER
*folder
)
80 struct list
*item
, *cursor
;
82 LIST_FOR_EACH_SAFE( item
, cursor
, &folder
->children
)
84 FolderList
*fl
= LIST_ENTRY( item
, FolderList
, entry
);
85 list_remove( &fl
->entry
);
88 msi_free( folder
->Parent
);
89 msi_free( folder
->Directory
);
90 msi_free( folder
->TargetDefault
);
91 msi_free( folder
->SourceLongPath
);
92 msi_free( folder
->SourceShortPath
);
93 msi_free( folder
->ResolvedTarget
);
94 msi_free( folder
->ResolvedSource
);
98 static void free_extension( MSIEXTENSION
*ext
)
100 struct list
*item
, *cursor
;
102 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
104 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
106 list_remove( &verb
->entry
);
107 msi_free( verb
->Verb
);
108 msi_free( verb
->Command
);
109 msi_free( verb
->Argument
);
113 msi_free( ext
->Extension
);
114 msi_free( ext
->ProgIDText
);
118 static void free_assembly( MSIASSEMBLY
*assembly
)
120 msi_free( assembly
->feature
);
121 msi_free( assembly
->manifest
);
122 msi_free( assembly
->application
);
123 msi_free( assembly
->display_name
);
124 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
125 msi_free( assembly
->tempdir
);
126 msi_free( assembly
);
129 void msi_free_action_script( MSIPACKAGE
*package
, UINT script
)
132 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
133 msi_free( package
->script
->Actions
[script
][i
] );
135 msi_free( package
->script
->Actions
[script
] );
136 package
->script
->Actions
[script
] = NULL
;
137 package
->script
->ActionCount
[script
] = 0;
140 static void free_package_structures( MSIPACKAGE
*package
)
142 struct list
*item
, *cursor
;
144 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
146 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
147 list_remove( &feature
->entry
);
148 free_feature( feature
);
151 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
153 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
154 list_remove( &folder
->entry
);
155 free_folder( folder
);
158 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
160 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
162 list_remove( &file
->entry
);
163 msi_free( file
->File
);
164 msi_free( file
->FileName
);
165 msi_free( file
->ShortName
);
166 msi_free( file
->LongName
);
167 msi_free( file
->Version
);
168 msi_free( file
->Language
);
169 if (msi_is_global_assembly( file
->Component
)) DeleteFileW( file
->TargetPath
);
170 msi_free( file
->TargetPath
);
174 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
176 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
178 list_remove( &comp
->entry
);
179 msi_free( comp
->Component
);
180 msi_free( comp
->ComponentId
);
181 msi_free( comp
->Directory
);
182 msi_free( comp
->Condition
);
183 msi_free( comp
->KeyPath
);
184 msi_free( comp
->FullKeypath
);
185 if (comp
->assembly
) free_assembly( comp
->assembly
);
189 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->filepatches
)
191 MSIFILEPATCH
*patch
= LIST_ENTRY( item
, MSIFILEPATCH
, entry
);
193 list_remove( &patch
->entry
);
194 msi_free( patch
->path
);
198 /* clean up extension, progid, class and verb structures */
199 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
201 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
203 list_remove( &cls
->entry
);
204 msi_free( cls
->clsid
);
205 msi_free( cls
->Context
);
206 msi_free( cls
->Description
);
207 msi_free( cls
->FileTypeMask
);
208 msi_free( cls
->IconPath
);
209 msi_free( cls
->DefInprocHandler
);
210 msi_free( cls
->DefInprocHandler32
);
211 msi_free( cls
->Argument
);
212 msi_free( cls
->ProgIDText
);
216 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
218 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
220 list_remove( &ext
->entry
);
221 free_extension( ext
);
224 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
226 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
228 list_remove( &progid
->entry
);
229 msi_free( progid
->ProgID
);
230 msi_free( progid
->Description
);
231 msi_free( progid
->IconPath
);
235 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
237 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
239 list_remove( &mt
->entry
);
240 msi_free( mt
->suffix
);
241 msi_free( mt
->clsid
);
242 msi_free( mt
->ContentType
);
246 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
248 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
250 list_remove( &appid
->entry
);
251 msi_free( appid
->AppID
);
252 msi_free( appid
->RemoteServerName
);
253 msi_free( appid
->LocalServer
);
254 msi_free( appid
->ServiceParameters
);
255 msi_free( appid
->DllSurrogate
);
259 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
261 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
263 list_remove( &info
->entry
);
264 msi_free( info
->value
);
268 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
270 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
272 list_remove( &info
->entry
);
273 msi_free( info
->volume_label
);
274 msi_free( info
->disk_prompt
);
283 for (i
= 0; i
< SCRIPT_MAX
; i
++)
284 msi_free_action_script( package
, i
);
286 for (j
= 0; j
< package
->script
->UniqueActionsCount
; j
++)
287 msi_free( package
->script
->UniqueActions
[j
] );
289 msi_free( package
->script
->UniqueActions
);
290 msi_free( package
->script
);
293 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->binaries
)
295 MSIBINARY
*binary
= LIST_ENTRY( item
, MSIBINARY
, entry
);
297 list_remove( &binary
->entry
);
299 FreeLibrary( binary
->module
);
300 if (!DeleteFileW( binary
->tmpfile
))
301 ERR("failed to delete %s (%u)\n", debugstr_w(binary
->tmpfile
), GetLastError());
302 msi_free( binary
->source
);
303 msi_free( binary
->tmpfile
);
307 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->cabinet_streams
)
309 MSICABINETSTREAM
*cab
= LIST_ENTRY( item
, MSICABINETSTREAM
, entry
);
311 list_remove( &cab
->entry
);
312 IStorage_Release( cab
->storage
);
313 msi_free( cab
->stream
);
317 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
319 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
321 list_remove( &patch
->entry
);
322 if (patch
->delete_on_close
&& !DeleteFileW( patch
->localfile
))
324 ERR("failed to delete %s (%u)\n", debugstr_w(patch
->localfile
), GetLastError());
326 msi_free_patchinfo( patch
);
329 msi_free( package
->BaseURL
);
330 msi_free( package
->PackagePath
);
331 msi_free( package
->ProductCode
);
332 msi_free( package
->ActionFormat
);
333 msi_free( package
->LastAction
);
334 msi_free( package
->LastActionTemplate
);
335 msi_free( package
->langids
);
337 /* cleanup control event subscriptions */
338 msi_event_cleanup_all_subscriptions( package
);
341 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
343 MSIPACKAGE
*package
= (MSIPACKAGE
*)arg
;
345 msi_destroy_assembly_caches( package
);
347 if( package
->dialog
)
348 msi_dialog_destroy( package
->dialog
);
350 msiobj_release( &package
->db
->hdr
);
351 free_package_structures(package
);
352 CloseHandle( package
->log_file
);
354 if (package
->delete_on_close
) DeleteFileW( package
->localfile
);
355 msi_free( package
->localfile
);
356 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_TERMINATE
, 0);
359 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
361 static const WCHAR query
[] = {
362 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
363 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
364 '`','_','P','r','o','p','e','r','t','y','`',' ',
365 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
366 'T','E','M','P','O','R','A','R','Y',',',' ',
367 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
368 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
369 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
370 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
374 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
375 if (rc
!= ERROR_SUCCESS
)
378 rc
= MSI_ViewExecute(view
, 0);
380 msiobj_release(&view
->hdr
);
384 UINT
msi_clone_properties( MSIDATABASE
*db
)
386 static const WCHAR query_select
[] = {
387 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
388 '`','P','r','o','p','e','r','t','y','`',0};
389 static const WCHAR query_insert
[] = {
390 'I','N','S','E','R','T',' ','I','N','T','O',' ',
391 '`','_','P','r','o','p','e','r','t','y','`',' ',
392 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
393 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
394 static const WCHAR query_update
[] = {
395 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
396 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
397 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
398 MSIQUERY
*view_select
;
401 rc
= MSI_DatabaseOpenViewW( db
, query_select
, &view_select
);
402 if (rc
!= ERROR_SUCCESS
)
405 rc
= MSI_ViewExecute( view_select
, 0 );
406 if (rc
!= ERROR_SUCCESS
)
408 MSI_ViewClose( view_select
);
409 msiobj_release( &view_select
->hdr
);
415 MSIQUERY
*view_insert
, *view_update
;
416 MSIRECORD
*rec_select
;
418 rc
= MSI_ViewFetch( view_select
, &rec_select
);
419 if (rc
!= ERROR_SUCCESS
)
422 rc
= MSI_DatabaseOpenViewW( db
, query_insert
, &view_insert
);
423 if (rc
!= ERROR_SUCCESS
)
425 msiobj_release( &rec_select
->hdr
);
429 rc
= MSI_ViewExecute( view_insert
, rec_select
);
430 MSI_ViewClose( view_insert
);
431 msiobj_release( &view_insert
->hdr
);
432 if (rc
!= ERROR_SUCCESS
)
434 MSIRECORD
*rec_update
;
436 TRACE("insert failed, trying update\n");
438 rc
= MSI_DatabaseOpenViewW( db
, query_update
, &view_update
);
439 if (rc
!= ERROR_SUCCESS
)
441 WARN("open view failed %u\n", rc
);
442 msiobj_release( &rec_select
->hdr
);
446 rec_update
= MSI_CreateRecord( 2 );
447 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
448 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
449 rc
= MSI_ViewExecute( view_update
, rec_update
);
450 if (rc
!= ERROR_SUCCESS
)
451 WARN("update failed %u\n", rc
);
453 MSI_ViewClose( view_update
);
454 msiobj_release( &view_update
->hdr
);
455 msiobj_release( &rec_update
->hdr
);
458 msiobj_release( &rec_select
->hdr
);
461 MSI_ViewClose( view_select
);
462 msiobj_release( &view_select
->hdr
);
469 * Sets the "Installed" property to indicate that
470 * the product is installed for the current user.
472 static UINT
set_installed_prop( MSIPACKAGE
*package
)
477 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
479 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
480 if (r
== ERROR_SUCCESS
)
483 msi_set_property( package
->db
, szInstalled
, szOne
, -1 );
488 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
492 LPWSTR sid_str
= NULL
, dom
= NULL
;
493 DWORD size
, dom_size
;
495 UINT r
= ERROR_FUNCTION_FAILED
;
498 GetUserNameW( NULL
, &size
);
500 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
502 return ERROR_OUTOFMEMORY
;
504 if (!GetUserNameW( user_name
, &size
))
509 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
511 psid
= msi_alloc( size
);
512 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
515 r
= ERROR_OUTOFMEMORY
;
519 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
522 if (!ConvertSidToStringSidW( psid
, &sid_str
))
525 r
= msi_set_property( package
->db
, szUserSID
, sid_str
, -1 );
528 LocalFree( sid_str
);
531 msi_free( user_name
);
536 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
541 DWORD index
= 0, size
;
543 WCHAR name
[MAX_PATH
];
544 WCHAR windir
[MAX_PATH
];
546 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
547 static const WCHAR sub
[] = {
548 'S','o','f','t','w','a','r','e','\\',
549 'M','i','c','r','o','s','o','f','t','\\',
550 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
553 static const WCHAR subdir
[] = {
554 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
555 'F','r','a','m','e','w','o','r','k','\\',0
558 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
559 if (res
!= ERROR_SUCCESS
)
562 GetWindowsDirectoryW(windir
, MAX_PATH
);
566 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
570 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
571 if (strcmpW( ver
, name
) < 0)
574 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
575 check
= msi_alloc(size
* sizeof(WCHAR
));
583 lstrcpyW(check
, windir
);
584 lstrcatW(check
, szBackSlash
);
585 lstrcatW(check
, subdir
);
586 lstrcatW(check
, name
);
587 lstrcatW(check
, szBackSlash
);
588 lstrcatW(check
, fusion
);
590 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
601 RegCloseKey(netsetup
);
605 typedef struct tagLANGANDCODEPAGE
611 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
615 LPVOID version
= NULL
;
617 LPWSTR fusion
, verstr
;
618 LANGANDCODEPAGE
*translate
;
620 static const WCHAR netasm
[] = {
621 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
623 static const WCHAR translation
[] = {
624 '\\','V','a','r','F','i','l','e','I','n','f','o',
625 '\\','T','r','a','n','s','l','a','t','i','o','n',0
627 static const WCHAR verfmt
[] = {
628 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
629 '\\','%','0','4','x','%','0','4','x',
630 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
633 fusion
= get_fusion_filename(package
);
637 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
641 version
= msi_alloc(size
);
645 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
648 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
651 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
653 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
656 if (!val_len
|| !verstr
)
659 msi_set_property( package
->db
, netasm
, verstr
, -1 );
666 static VOID
set_installer_properties(MSIPACKAGE
*package
)
669 OSVERSIONINFOEXW OSVersion
;
672 WCHAR pth
[MAX_PATH
], verstr
[11], bufstr
[22];
675 LPWSTR username
, companyname
;
676 SYSTEM_INFO sys_info
;
677 SYSTEMTIME systemtime
;
680 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
681 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
682 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
683 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
684 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
685 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
686 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
687 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
688 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
689 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
690 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
691 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
692 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
693 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
694 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
695 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
696 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
697 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
698 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
699 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
700 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
701 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
702 static const WCHAR szFormat
[] = {'%','u',0};
703 static const WCHAR szFormat2
[] = {'%','u','.','%','u',0};
704 static const WCHAR szWindowsBuild
[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
705 static const WCHAR szServicePackLevel
[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
706 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
707 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
708 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
709 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
710 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
711 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
712 static const WCHAR szIntFormat
[] = {'%','d',0};
713 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
714 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
715 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
716 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
717 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 };
718 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
719 static const WCHAR szUserInfo
[] = {
720 'S','O','F','T','W','A','R','E','\\',
721 'M','i','c','r','o','s','o','f','t','\\',
722 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
723 'U','s','e','r',' ','I','n','f','o',0
725 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
726 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
727 static const WCHAR szCurrentVersion
[] = {
728 'S','O','F','T','W','A','R','E','\\',
729 'M','i','c','r','o','s','o','f','t','\\',
730 'W','i','n','d','o','w','s',' ','N','T','\\',
731 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
733 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
734 static const WCHAR szRegisteredOrganization
[] = {
735 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
737 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
738 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
739 static const WCHAR szDate
[] = {'D','a','t','e',0};
740 static const WCHAR szTime
[] = {'T','i','m','e',0};
741 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
742 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
743 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
744 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
745 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
746 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
747 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
748 static const WCHAR szComputerName
[] = {'C','o','m','p','u','t','e','r','N','a','m','e',0};
749 static const WCHAR szBrowseProperty
[] = {'_','B','r','o','w','s','e','P','r','o','p','e','r','t','y',0};
750 static const WCHAR szInstallDir
[] = {'I','N','S','T','A','L','L','D','I','R',0};
753 * Other things that probably should be set:
755 * VirtualMemory ShellAdvSupport DefaultUIFont PackagecodeChanging
756 * CaptionHeight BorderTop BorderSide TextHeight RedirectedDllSupport
759 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
760 strcatW(pth
, szBackSlash
);
761 msi_set_property( package
->db
, szCommonAppDataFolder
, pth
, -1 );
763 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
764 strcatW(pth
, szBackSlash
);
765 msi_set_property( package
->db
, szFavoritesFolder
, pth
, -1 );
767 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
768 strcatW(pth
, szBackSlash
);
769 msi_set_property( package
->db
, szFontsFolder
, pth
, -1 );
771 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
772 strcatW(pth
, szBackSlash
);
773 msi_set_property( package
->db
, szSendToFolder
, pth
, -1 );
775 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
776 strcatW(pth
, szBackSlash
);
777 msi_set_property( package
->db
, szStartMenuFolder
, pth
, -1 );
779 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
780 strcatW(pth
, szBackSlash
);
781 msi_set_property( package
->db
, szStartupFolder
, pth
, -1 );
783 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
784 strcatW(pth
, szBackSlash
);
785 msi_set_property( package
->db
, szTemplateFolder
, pth
, -1 );
787 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
788 strcatW(pth
, szBackSlash
);
789 msi_set_property( package
->db
, szDesktopFolder
, pth
, -1 );
791 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
792 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
793 strcatW(pth
, szBackSlash
);
794 msi_set_property( package
->db
, szProgramMenuFolder
, pth
, -1 );
796 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
797 strcatW(pth
, szBackSlash
);
798 msi_set_property( package
->db
, szAdminToolsFolder
, pth
, -1 );
800 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
801 strcatW(pth
, szBackSlash
);
802 msi_set_property( package
->db
, szAppDataFolder
, pth
, -1 );
804 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
805 strcatW(pth
, szBackSlash
);
806 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
807 msi_set_property( package
->db
, szSystem16Folder
, pth
, -1 );
809 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
810 strcatW(pth
, szBackSlash
);
811 msi_set_property( package
->db
, szLocalAppDataFolder
, pth
, -1 );
813 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
814 strcatW(pth
, szBackSlash
);
815 msi_set_property( package
->db
, szMyPicturesFolder
, pth
, -1 );
817 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
818 strcatW(pth
, szBackSlash
);
819 msi_set_property( package
->db
, szPersonalFolder
, pth
, -1 );
821 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
822 strcatW(pth
, szBackSlash
);
823 msi_set_property( package
->db
, szWindowsFolder
, pth
, -1 );
825 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
826 strcatW(pth
, szBackSlash
);
827 msi_set_property( package
->db
, szPrintHoodFolder
, pth
, -1 );
829 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
830 strcatW(pth
, szBackSlash
);
831 msi_set_property( package
->db
, szNetHoodFolder
, pth
, -1 );
833 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
834 strcatW(pth
, szBackSlash
);
835 msi_set_property( package
->db
, szRecentFolder
, pth
, -1 );
837 /* Physical Memory is specified in MB. Using total amount. */
838 msex
.dwLength
= sizeof(msex
);
839 GlobalMemoryStatusEx( &msex
);
840 len
= sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
841 msi_set_property( package
->db
, szPhysicalMemory
, bufstr
, len
);
843 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
844 ptr
= strchrW(pth
,'\\');
845 if (ptr
) *(ptr
+ 1) = 0;
846 msi_set_property( package
->db
, szWindowsVolume
, pth
, -1 );
848 len
= GetTempPathW(MAX_PATH
, pth
);
849 msi_set_property( package
->db
, szTempFolder
, pth
, len
);
851 /* in a wine environment the user is always admin and privileged */
852 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
853 msi_set_property( package
->db
, szPrivileged
, szOne
, -1 );
855 /* set the os things */
856 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
857 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
858 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
859 len
= sprintfW( verstr
, szFormat
, verval
);
860 switch (OSVersion
.dwPlatformId
)
862 case VER_PLATFORM_WIN32_WINDOWS
:
863 msi_set_property( package
->db
, szVersion9x
, verstr
, len
);
865 case VER_PLATFORM_WIN32_NT
:
866 msi_set_property( package
->db
, szVersionNT
, verstr
, len
);
867 len
= sprintfW( bufstr
, szFormat
,OSVersion
.wProductType
);
868 msi_set_property( package
->db
, szMsiNTProductType
, bufstr
, len
);
871 len
= sprintfW( bufstr
, szFormat
, OSVersion
.dwBuildNumber
);
872 msi_set_property( package
->db
, szWindowsBuild
, bufstr
, len
);
873 len
= sprintfW( bufstr
, szFormat
, OSVersion
.wServicePackMajor
);
874 msi_set_property( package
->db
, szServicePackLevel
, bufstr
, len
);
876 len
= sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
877 msi_set_property( package
->db
, szVersionMsi
, bufstr
, len
);
878 len
= sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100 );
879 msi_set_property( package
->db
, szVersionDatabase
, bufstr
, len
);
881 GetNativeSystemInfo( &sys_info
);
882 len
= sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
883 msi_set_property( package
->db
, szIntel
, bufstr
, len
);
884 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
886 GetSystemDirectoryW( pth
, MAX_PATH
);
887 PathAddBackslashW( pth
);
888 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
890 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
891 PathAddBackslashW( pth
);
892 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
894 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
895 PathAddBackslashW( pth
);
896 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
898 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
900 msi_set_property( package
->db
, szMsiAMD64
, bufstr
, -1 );
901 msi_set_property( package
->db
, szMsix64
, bufstr
, -1 );
902 msi_set_property( package
->db
, szVersionNT64
, verstr
, -1 );
904 GetSystemDirectoryW( pth
, MAX_PATH
);
905 PathAddBackslashW( pth
);
906 msi_set_property( package
->db
, szSystem64Folder
, pth
, -1 );
908 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
909 PathAddBackslashW( pth
);
910 msi_set_property( package
->db
, szSystemFolder
, pth
, -1 );
912 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
913 PathAddBackslashW( pth
);
914 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
, -1 );
916 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
917 PathAddBackslashW( pth
);
918 msi_set_property( package
->db
, szProgramFilesFolder
, pth
, -1 );
920 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
921 PathAddBackslashW( pth
);
922 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
, -1 );
924 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
925 PathAddBackslashW( pth
);
926 msi_set_property( package
->db
, szCommonFilesFolder
, pth
, -1 );
929 /* Screen properties. */
931 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, HORZRES
) );
932 msi_set_property( package
->db
, szScreenX
, bufstr
, len
);
933 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, VERTRES
) );
934 msi_set_property( package
->db
, szScreenY
, bufstr
, len
);
935 len
= sprintfW( bufstr
, szIntFormat
, GetDeviceCaps(dc
, BITSPIXEL
) );
936 msi_set_property( package
->db
, szColorBits
, bufstr
, len
);
939 /* USERNAME and COMPANYNAME */
940 username
= msi_dup_property( package
->db
, szUSERNAME
);
941 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
943 if ((!username
|| !companyname
) &&
944 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
947 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
948 msi_set_property( package
->db
, szUSERNAME
, username
, -1 );
950 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
951 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
954 if ((!username
|| !companyname
) &&
955 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
958 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
959 msi_set_property( package
->db
, szUSERNAME
, username
, -1 );
961 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
962 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
, -1 );
965 msi_free( username
);
966 msi_free( companyname
);
968 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
969 ERR("Failed to set the UserSID property\n");
971 /* Date and time properties */
972 GetSystemTime( &systemtime
);
973 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
974 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
975 msi_set_property( package
->db
, szDate
, bufstr
, -1 );
977 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
979 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
980 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
981 &systemtime
, NULL
, bufstr
,
982 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
983 msi_set_property( package
->db
, szTime
, bufstr
, -1 );
985 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
987 set_msi_assembly_prop( package
);
989 langid
= GetUserDefaultLangID();
990 len
= sprintfW( bufstr
, szIntFormat
, langid
);
991 msi_set_property( package
->db
, szUserLanguageID
, bufstr
, len
);
993 langid
= GetSystemDefaultLangID();
994 len
= sprintfW( bufstr
, szIntFormat
, langid
);
995 msi_set_property( package
->db
, szSystemLangID
, bufstr
, len
);
997 len
= sprintfW( bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
) );
998 msi_set_property( package
->db
, szProductState
, bufstr
, len
);
1001 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1004 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
1006 if (GetUserNameW( username
, &len
))
1007 msi_set_property( package
->db
, szLogonUser
, username
, len
- 1 );
1008 msi_free( username
);
1012 if (!GetComputerNameW( NULL
, &len
) && GetLastError() == ERROR_BUFFER_OVERFLOW
)
1014 WCHAR
*computername
;
1015 if ((computername
= msi_alloc( len
* sizeof(WCHAR
) )))
1017 if (GetComputerNameW( computername
, &len
))
1018 msi_set_property( package
->db
, szComputerName
, computername
, len
);
1019 msi_free( computername
);
1022 msi_set_property( package
->db
, szBrowseProperty
, szInstallDir
, -1 );
1025 static MSIPACKAGE
*msi_alloc_package( void )
1027 MSIPACKAGE
*package
;
1029 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1033 list_init( &package
->components
);
1034 list_init( &package
->features
);
1035 list_init( &package
->files
);
1036 list_init( &package
->filepatches
);
1037 list_init( &package
->tempfiles
);
1038 list_init( &package
->folders
);
1039 list_init( &package
->subscriptions
);
1040 list_init( &package
->appids
);
1041 list_init( &package
->classes
);
1042 list_init( &package
->mimes
);
1043 list_init( &package
->extensions
);
1044 list_init( &package
->progids
);
1045 list_init( &package
->RunningActions
);
1046 list_init( &package
->sourcelist_info
);
1047 list_init( &package
->sourcelist_media
);
1048 list_init( &package
->patches
);
1049 list_init( &package
->binaries
);
1050 list_init( &package
->cabinet_streams
);
1056 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1061 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1063 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1064 if (r
!= ERROR_SUCCESS
)
1067 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1073 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1075 /* FIXME: this should depend on the user's privileges */
1076 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1078 TRACE("resetting ALLUSERS property from 2 to 1\n");
1079 msi_set_property( package
->db
, szAllUsers
, szOne
, -1 );
1081 msi_set_property( package
->db
, szAdminUser
, szOne
, -1 );
1084 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1086 static const WCHAR fmtW
[] = {'%','u',0};
1087 MSIPACKAGE
*package
;
1094 package
= msi_alloc_package();
1097 msiobj_addref( &db
->hdr
);
1100 package
->LastAction
= NULL
;
1101 package
->LastActionTemplate
= NULL
;
1102 package
->LastActionResult
= MSI_NULL_INTEGER
;
1103 package
->WordCount
= 0;
1104 package
->PackagePath
= strdupW( db
->path
);
1105 package
->BaseURL
= strdupW( base_url
);
1107 create_temp_property_table( package
);
1108 msi_clone_properties( package
->db
);
1109 msi_adjust_privilege_properties( package
);
1111 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1112 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1114 set_installer_properties( package
);
1116 package
->ui_level
= gUILevel
;
1117 len
= sprintfW( uilevel
, fmtW
, gUILevel
& INSTALLUILEVEL_MASK
);
1118 msi_set_property( package
->db
, szUILevel
, uilevel
, len
);
1120 r
= msi_load_suminfo_properties( package
);
1121 if (r
!= ERROR_SUCCESS
)
1123 msiobj_release( &package
->hdr
);
1127 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1128 msi_load_admin_properties( package
);
1130 package
->log_file
= INVALID_HANDLE_VALUE
;
1135 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1137 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1141 /* call will always fail, because size is 0,
1142 * but will return ERROR_FILE_NOT_FOUND first
1143 * if the file doesn't exist
1145 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1146 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1148 cache_entry
= msi_alloc( size
);
1149 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1151 UINT error
= GetLastError();
1152 msi_free( cache_entry
);
1156 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1157 msi_free( cache_entry
);
1158 return ERROR_SUCCESS
;
1161 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1164 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1165 return ERROR_FUNCTION_FAILED
;
1168 return ERROR_SUCCESS
;
1171 UINT
msi_create_empty_local_file( LPWSTR path
, LPCWSTR suffix
)
1173 static const WCHAR szInstaller
[] = {
1174 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1175 static const WCHAR fmt
[] = {'%','x',0};
1176 DWORD time
, len
, i
, offset
;
1179 time
= GetTickCount();
1180 GetWindowsDirectoryW( path
, MAX_PATH
);
1181 strcatW( path
, szInstaller
);
1182 CreateDirectoryW( path
, NULL
);
1184 len
= strlenW(path
);
1185 for (i
= 0; i
< 0x10000; i
++)
1187 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1188 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1189 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1190 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1191 if (handle
!= INVALID_HANDLE_VALUE
)
1193 CloseHandle(handle
);
1196 if (GetLastError() != ERROR_FILE_EXISTS
&&
1197 GetLastError() != ERROR_SHARING_VIOLATION
)
1198 return ERROR_FUNCTION_FAILED
;
1201 return ERROR_SUCCESS
;
1204 static enum platform
parse_platform( const WCHAR
*str
)
1206 if (!str
[0] || !strcmpW( str
, szIntel
)) return PLATFORM_INTEL
;
1207 else if (!strcmpW( str
, szIntel64
)) return PLATFORM_INTEL64
;
1208 else if (!strcmpW( str
, szX64
) || !strcmpW( str
, szAMD64
)) return PLATFORM_X64
;
1209 else if (!strcmpW( str
, szARM
)) return PLATFORM_ARM
;
1210 return PLATFORM_UNKNOWN
;
1213 static UINT
parse_suminfo( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1215 WCHAR
*template, *p
, *q
, *platform
;
1218 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1219 TRACE("version: %d\n", package
->version
);
1221 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1223 return ERROR_SUCCESS
; /* native accepts missing template property */
1225 TRACE("template: %s\n", debugstr_w(template));
1227 p
= strchrW( template, ';' );
1230 WARN("invalid template string %s\n", debugstr_w(template));
1231 msi_free( template );
1232 return ERROR_PATCH_PACKAGE_INVALID
;
1235 platform
= template;
1236 if ((q
= strchrW( platform
, ',' ))) *q
= 0;
1237 package
->platform
= parse_platform( platform
);
1238 while (package
->platform
== PLATFORM_UNKNOWN
&& q
)
1241 if ((q
= strchrW( platform
, ',' ))) *q
= 0;
1242 package
->platform
= parse_platform( platform
);
1244 if (package
->platform
== PLATFORM_UNKNOWN
)
1246 WARN("unknown platform %s\n", debugstr_w(template));
1247 msi_free( template );
1248 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1253 msi_free( template );
1254 return ERROR_SUCCESS
;
1257 for (q
= p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1259 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1260 if (!package
->langids
)
1262 msi_free( template );
1263 return ERROR_OUTOFMEMORY
;
1269 q
= strchrW( p
, ',' );
1271 package
->langids
[i
] = atoiW( p
);
1276 package
->num_langids
= i
+ 1;
1278 msi_free( template );
1279 return ERROR_SUCCESS
;
1282 static UINT
validate_package( MSIPACKAGE
*package
)
1286 if (package
->platform
== PLATFORM_INTEL64
)
1287 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1289 if (package
->platform
== PLATFORM_ARM
)
1290 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1292 if (package
->platform
== PLATFORM_X64
)
1294 if (!is_64bit
&& !is_wow64
)
1295 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1296 if (package
->version
< 200)
1297 return ERROR_INSTALL_PACKAGE_INVALID
;
1299 if (!package
->num_langids
)
1301 return ERROR_SUCCESS
;
1303 for (i
= 0; i
< package
->num_langids
; i
++)
1305 LANGID langid
= package
->langids
[i
];
1307 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1309 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1311 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1313 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1315 if (IsValidLocale( langid
, LCID_INSTALLED
))
1316 return ERROR_SUCCESS
;
1318 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1321 static WCHAR
*get_product_code( MSIDATABASE
*db
)
1323 static const WCHAR query
[] = {
1324 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1325 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',' ',
1326 'W','H','E','R','E',' ','`','P','r','o','p','e','r','t','y','`','=',
1327 '\'','P','r','o','d','u','c','t','C','o','d','e','\'',0};
1332 if (MSI_DatabaseOpenViewW( db
, query
, &view
) != ERROR_SUCCESS
)
1336 if (MSI_ViewExecute( view
, 0 ) != ERROR_SUCCESS
)
1338 MSI_ViewClose( view
);
1339 msiobj_release( &view
->hdr
);
1342 if (MSI_ViewFetch( view
, &rec
) == ERROR_SUCCESS
)
1344 ret
= strdupW( MSI_RecordGetString( rec
, 1 ) );
1345 msiobj_release( &rec
->hdr
);
1347 MSI_ViewClose( view
);
1348 msiobj_release( &view
->hdr
);
1352 static UINT
get_registered_local_package( const WCHAR
*product
, const WCHAR
*package
, WCHAR
*localfile
)
1354 MSIINSTALLCONTEXT context
;
1355 HKEY product_key
, props_key
;
1356 WCHAR
*registered_package
= NULL
, unsquashed
[GUID_SIZE
];
1359 r
= msi_locate_product( product
, &context
);
1360 if (r
!= ERROR_SUCCESS
)
1363 r
= MSIREG_OpenProductKey( product
, NULL
, context
, &product_key
, FALSE
);
1364 if (r
!= ERROR_SUCCESS
)
1367 r
= MSIREG_OpenInstallProps( product
, context
, NULL
, &props_key
, FALSE
);
1368 if (r
!= ERROR_SUCCESS
)
1370 RegCloseKey( product_key
);
1373 r
= ERROR_FUNCTION_FAILED
;
1374 registered_package
= msi_reg_get_val_str( product_key
, INSTALLPROPERTY_PACKAGECODEW
);
1375 if (!registered_package
)
1378 unsquash_guid( registered_package
, unsquashed
);
1379 if (!strcmpiW( package
, unsquashed
))
1381 WCHAR
*filename
= msi_reg_get_val_str( props_key
, INSTALLPROPERTY_LOCALPACKAGEW
);
1385 strcpyW( localfile
, filename
);
1386 msi_free( filename
);
1390 msi_free( registered_package
);
1391 RegCloseKey( props_key
);
1392 RegCloseKey( product_key
);
1396 static WCHAR
*get_package_code( MSIDATABASE
*db
)
1402 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1403 if (r
!= ERROR_SUCCESS
)
1405 r
= msi_get_db_suminfo( db
, 0, &si
);
1406 if (r
!= ERROR_SUCCESS
)
1408 WARN("failed to load summary info %u\n", r
);
1412 ret
= msi_suminfo_dup_string( si
, PID_REVNUMBER
);
1413 msiobj_release( &si
->hdr
);
1417 static UINT
get_local_package( const WCHAR
*filename
, WCHAR
*localfile
)
1419 WCHAR
*product_code
, *package_code
;
1423 if ((r
= MSI_OpenDatabaseW( filename
, MSIDBOPEN_READONLY
, &db
)) != ERROR_SUCCESS
)
1425 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1426 return ERROR_FILE_NOT_FOUND
;
1429 if (!(product_code
= get_product_code( db
)))
1431 msiobj_release( &db
->hdr
);
1432 return ERROR_INSTALL_PACKAGE_INVALID
;
1434 if (!(package_code
= get_package_code( db
)))
1436 msi_free( product_code
);
1437 msiobj_release( &db
->hdr
);
1438 return ERROR_INSTALL_PACKAGE_INVALID
;
1440 r
= get_registered_local_package( product_code
, package_code
, localfile
);
1441 msi_free( package_code
);
1442 msi_free( product_code
);
1443 msiobj_release( &db
->hdr
);
1447 UINT
msi_set_original_database_property( MSIDATABASE
*db
, const WCHAR
*package
)
1451 if (UrlIsW( package
, URLIS_URL
))
1452 r
= msi_set_property( db
, szOriginalDatabase
, package
, -1 );
1453 else if (package
[0] == '#')
1454 r
= msi_set_property( db
, szOriginalDatabase
, db
->path
, -1 );
1460 if (!(len
= GetFullPathNameW( package
, 0, NULL
, NULL
))) return GetLastError();
1461 if (!(path
= msi_alloc( len
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
1462 len
= GetFullPathNameW( package
, len
, path
, NULL
);
1463 r
= msi_set_property( db
, szOriginalDatabase
, path
, len
);
1469 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1471 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1473 MSIPACKAGE
*package
;
1475 MSIRECORD
*data_row
, *info_row
;
1476 LPWSTR ptr
, base_url
= NULL
;
1478 WCHAR localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1479 LPCWSTR file
= szPackage
;
1482 BOOL delete_on_close
= FALSE
;
1484 static const WCHAR date_format
[] =
1485 {'M','/','d','/','y','y','y','y',0};
1486 static const WCHAR time_format
[] =
1487 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1488 WCHAR timet
[100], datet
[100], info_template
[1024], info_message
[1024];
1490 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1492 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_INITIALIZE
, 0);
1495 if( szPackage
[0] == '#' )
1497 handle
= atoiW(&szPackage
[1]);
1498 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1501 IWineMsiRemoteDatabase
*remote_database
;
1503 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1504 if ( !remote_database
)
1505 return ERROR_INVALID_HANDLE
;
1507 IWineMsiRemoteDatabase_Release( remote_database
);
1508 WARN("MsiOpenPackage not allowed during a custom action!\n");
1510 return ERROR_FUNCTION_FAILED
;
1515 if ( UrlIsW( szPackage
, URLIS_URL
) )
1517 r
= msi_download_file( szPackage
, cachefile
);
1518 if (r
!= ERROR_SUCCESS
)
1523 base_url
= strdupW( szPackage
);
1525 return ERROR_OUTOFMEMORY
;
1527 ptr
= strrchrW( base_url
, '/' );
1528 if (ptr
) *(ptr
+ 1) = '\0';
1530 r
= get_local_package( file
, localfile
);
1531 if (r
!= ERROR_SUCCESS
|| GetFileAttributesW( localfile
) == INVALID_FILE_ATTRIBUTES
)
1533 r
= msi_create_empty_local_file( localfile
, dotmsi
);
1534 if (r
!= ERROR_SUCCESS
)
1536 msi_free ( base_url
);
1540 if (!CopyFileW( file
, localfile
, FALSE
))
1543 WARN("unable to copy package %s to %s (%u)\n", debugstr_w(file
), debugstr_w(localfile
), r
);
1544 DeleteFileW( localfile
);
1545 msi_free ( base_url
);
1548 delete_on_close
= TRUE
;
1550 TRACE("opening package %s\n", debugstr_w( localfile
));
1551 r
= MSI_OpenDatabaseW( localfile
, MSIDBOPEN_TRANSACT
, &db
);
1552 if (r
!= ERROR_SUCCESS
)
1554 msi_free ( base_url
);
1558 package
= MSI_CreatePackage( db
, base_url
);
1559 msi_free( base_url
);
1560 msiobj_release( &db
->hdr
);
1561 if (!package
) return ERROR_INSTALL_PACKAGE_INVALID
;
1562 package
->localfile
= strdupW( localfile
);
1563 package
->delete_on_close
= delete_on_close
;
1565 r
= msi_get_suminfo( db
->storage
, 0, &si
);
1566 if (r
!= ERROR_SUCCESS
)
1568 r
= msi_get_db_suminfo( db
, 0, &si
);
1569 if (r
!= ERROR_SUCCESS
)
1571 WARN("failed to load summary info\n");
1572 msiobj_release( &package
->hdr
);
1573 return ERROR_INSTALL_PACKAGE_INVALID
;
1576 r
= parse_suminfo( si
, package
);
1577 msiobj_release( &si
->hdr
);
1578 if (r
!= ERROR_SUCCESS
)
1580 WARN("failed to parse summary info %u\n", r
);
1581 msiobj_release( &package
->hdr
);
1584 r
= validate_package( package
);
1585 if (r
!= ERROR_SUCCESS
)
1587 msiobj_release( &package
->hdr
);
1590 msi_set_property( package
->db
, szDatabase
, db
->path
, -1 );
1591 set_installed_prop( package
);
1592 msi_set_context( package
);
1596 WCHAR patch_code
[GUID_SIZE
];
1597 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1598 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1599 if (r
!= ERROR_SUCCESS
)
1602 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1604 r
= msi_apply_registered_patch( package
, patch_code
);
1605 if (r
!= ERROR_SUCCESS
)
1607 ERR("registered patch failed to apply %u\n", r
);
1608 msiobj_release( &package
->hdr
);
1613 if (index
) msi_adjust_privilege_properties( package
);
1615 r
= msi_set_original_database_property( package
->db
, szPackage
);
1616 if (r
!= ERROR_SUCCESS
)
1618 msiobj_release( &package
->hdr
);
1622 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1623 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1625 /* FIXME: when should these messages be sent? */
1626 data_row
= MSI_CreateRecord(3);
1628 return ERROR_OUTOFMEMORY
;
1629 MSI_RecordSetStringW(data_row
, 0, NULL
);
1630 MSI_RecordSetInteger(data_row
, 1, 0);
1631 MSI_RecordSetInteger(data_row
, 2, package
->num_langids
? package
->langids
[0] : 0);
1632 MSI_RecordSetInteger(data_row
, 3, msi_get_string_table_codepage(package
->db
->strings
));
1633 MSI_ProcessMessageVerbatim(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1635 info_row
= MSI_CreateRecord(0);
1638 msiobj_release(&data_row
->hdr
);
1639 return ERROR_OUTOFMEMORY
;
1641 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, time_format
, timet
, 100);
1642 GetDateFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, date_format
, datet
, 100);
1643 LoadStringW(msi_hInstance
, IDS_INFO_LOGGINGSTART
, info_template
, 1024);
1644 sprintfW(info_message
, info_template
, datet
, timet
);
1645 MSI_RecordSetStringW(info_row
, 0, info_message
);
1646 MSI_ProcessMessage(package
, INSTALLMESSAGE_INFO
|MB_ICONHAND
, info_row
);
1648 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1650 productname
= msi_dup_property(package
->db
, INSTALLPROPERTY_PRODUCTNAMEW
);
1651 MSI_RecordSetInteger(data_row
, 1, 1);
1652 MSI_RecordSetStringW(data_row
, 2, productname
);
1653 MSI_RecordSetStringW(data_row
, 3, NULL
);
1654 MSI_ProcessMessage(package
, INSTALLMESSAGE_COMMONDATA
, data_row
);
1656 msi_free(productname
);
1657 msiobj_release(&info_row
->hdr
);
1658 msiobj_release(&data_row
->hdr
);
1660 *pPackage
= package
;
1661 return ERROR_SUCCESS
;
1664 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1666 MSIPACKAGE
*package
= NULL
;
1669 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1671 if( !szPackage
|| !phPackage
)
1672 return ERROR_INVALID_PARAMETER
;
1676 FIXME("Should create an empty database and package\n");
1677 return ERROR_FUNCTION_FAILED
;
1681 FIXME("dwOptions %08x not supported\n", dwOptions
);
1683 ret
= MSI_OpenPackageW( szPackage
, &package
);
1684 if( ret
== ERROR_SUCCESS
)
1686 *phPackage
= alloc_msihandle( &package
->hdr
);
1688 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1689 msiobj_release( &package
->hdr
);
1692 MSI_ProcessMessage(NULL
, INSTALLMESSAGE_TERMINATE
, 0);
1697 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1699 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1702 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1704 LPWSTR szwPack
= NULL
;
1709 szwPack
= strdupAtoW( szPackage
);
1711 return ERROR_OUTOFMEMORY
;
1714 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1716 msi_free( szwPack
);
1721 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1723 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1726 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1728 MSIPACKAGE
*package
;
1729 MSIHANDLE handle
= 0;
1730 IUnknown
*remote_unk
;
1731 IWineMsiRemotePackage
*remote_package
;
1733 TRACE("(%d)\n",hInstall
);
1735 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1738 handle
= alloc_msihandle( &package
->db
->hdr
);
1739 msiobj_release( &package
->hdr
);
1741 else if ((remote_unk
= msi_get_remote(hInstall
)))
1743 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1744 (LPVOID
*)&remote_package
) == S_OK
)
1746 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1747 IWineMsiRemotePackage_Release(remote_package
);
1751 WARN("remote handle %d is not a package\n", hInstall
);
1753 IUnknown_Release(remote_unk
);
1759 static INT
internal_ui_handler(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
, LPCWSTR message
)
1761 static const WCHAR szActionData
[] = {'A','c','t','i','o','n','D','a','t','a',0};
1762 static const WCHAR szActionText
[] = {'A','c','t','i','o','n','T','e','x','t',0};
1763 static const WCHAR szSetProgress
[] = {'S','e','t','P','r','o','g','r','e','s','s',0};
1764 static const WCHAR szWindows_Installer
[] =
1765 {'W','i','n','d','o','w','s',' ','I','n','s','t','a','l','l','e','r',0};
1767 if (!package
|| (package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
)
1770 /* todo: check if message needs additional styles (topmost/foreground/modality?) */
1772 switch (eMessageType
& 0xff000000)
1774 case INSTALLMESSAGE_FATALEXIT
:
1775 case INSTALLMESSAGE_ERROR
:
1776 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1777 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1778 if (!(eMessageType
& MB_ICONMASK
))
1779 eMessageType
|= MB_ICONEXCLAMATION
;
1780 return MessageBoxW(gUIhwnd
, message
, szWindows_Installer
, eMessageType
& 0x00ffffff);
1781 case INSTALLMESSAGE_WARNING
:
1782 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1783 if (!(eMessageType
& MB_ICONMASK
))
1784 eMessageType
|= MB_ICONASTERISK
;
1785 return MessageBoxW(gUIhwnd
, message
, szWindows_Installer
, eMessageType
& 0x00ffffff);
1786 case INSTALLMESSAGE_USER
:
1787 if (package
->ui_level
& INSTALLUILEVEL_PROGRESSONLY
) return 0;
1788 if (!(eMessageType
& MB_ICONMASK
))
1789 eMessageType
|= MB_USERICON
;
1790 return MessageBoxW(gUIhwnd
, message
, szWindows_Installer
, eMessageType
& 0x00ffffff);
1791 case INSTALLMESSAGE_INFO
:
1792 case INSTALLMESSAGE_INITIALIZE
:
1793 case INSTALLMESSAGE_TERMINATE
:
1795 case INSTALLMESSAGE_SHOWDIALOG
:
1797 LPWSTR dialog
= msi_dup_record_field(record
, 0);
1798 UINT rc
= ACTION_DialogBox(package
, dialog
);
1800 return (rc
== ERROR_SUCCESS
);
1802 case INSTALLMESSAGE_ACTIONSTART
:
1805 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1806 if (!uirow
) return -1;
1807 deformat_string(package
, MSI_RecordGetString(record
, 2), &deformatted
);
1808 MSI_RecordSetStringW(uirow
, 1, deformatted
);
1809 msi_event_fire(package
, szActionText
, uirow
);
1811 msi_free(deformatted
);
1812 msiobj_release(&uirow
->hdr
);
1815 case INSTALLMESSAGE_ACTIONDATA
:
1817 MSIRECORD
*uirow
= MSI_CreateRecord(1);
1818 if (!uirow
) return -1;
1819 MSI_RecordSetStringW(uirow
, 1, message
);
1820 msi_event_fire(package
, szActionData
, uirow
);
1821 msiobj_release(&uirow
->hdr
);
1823 if (package
->action_progress_increment
)
1825 uirow
= MSI_CreateRecord(2);
1826 if (!uirow
) return -1;
1827 MSI_RecordSetInteger(uirow
, 1, 2);
1828 MSI_RecordSetInteger(uirow
, 2, package
->action_progress_increment
);
1829 msi_event_fire(package
, szSetProgress
, uirow
);
1830 msiobj_release(&uirow
->hdr
);
1834 case INSTALLMESSAGE_PROGRESS
:
1835 msi_event_fire(package
, szSetProgress
, record
);
1837 case INSTALLMESSAGE_COMMONDATA
:
1838 switch (MSI_RecordGetInteger(record
, 1))
1849 FIXME("internal UI not implemented for message 0x%08x (UI level = %x)", eMessageType
, package
->ui_level
);
1854 INT
MSI_ProcessMessageVerbatim(MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1856 LPWSTR message
= {0};
1857 DWORD len
, log_type
= 0;
1862 TRACE("%x\n", eMessageType
);
1863 if (TRACE_ON(msi
)) dump_record(record
);
1865 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_FATALEXIT
)
1866 log_type
|= INSTALLLOGMODE_FATALEXIT
;
1867 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1868 log_type
|= INSTALLLOGMODE_ERROR
;
1869 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1870 log_type
|= INSTALLLOGMODE_WARNING
;
1871 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1872 log_type
|= INSTALLLOGMODE_USER
;
1873 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1874 log_type
|= INSTALLLOGMODE_INFO
;
1875 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_RESOLVESOURCE
)
1876 log_type
|= INSTALLLOGMODE_RESOLVESOURCE
;
1877 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_OUTOFDISKSPACE
)
1878 log_type
|= INSTALLLOGMODE_OUTOFDISKSPACE
;
1879 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1880 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1881 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1882 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1883 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1884 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1885 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1886 log_type
|= INSTALLLOGMODE_PROGRESS
;
1887 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
)
1888 log_type
|= INSTALLLOGMODE_INITIALIZE
;
1889 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
1890 log_type
|= INSTALLLOGMODE_TERMINATE
;
1891 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_SHOWDIALOG
)
1892 log_type
|= INSTALLLOGMODE_SHOWDIALOG
;
1894 if (!package
|| !record
)
1897 res
= MSI_FormatRecordW(package
, record
, message
, &len
);
1898 if (res
!= ERROR_SUCCESS
&& res
!= ERROR_MORE_DATA
)
1901 message
= msi_alloc(len
* sizeof(WCHAR
));
1902 if (!message
) return ERROR_OUTOFMEMORY
;
1903 MSI_FormatRecordW(package
, record
, message
, &len
);
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 (gUIHandlerRecord
&& (gUIFilterRecord
& log_type
))
1913 MSIHANDLE rec
= alloc_msihandle(&record
->hdr
);
1914 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, hRecord=%u)\n",
1915 gUIHandlerRecord
, gUIContextRecord
, eMessageType
, rec
);
1916 rc
= gUIHandlerRecord( gUIContextRecord
, eMessageType
, rec
);
1917 MsiCloseHandle( rec
);
1919 if (!rc
&& gUIHandlerW
&& (gUIFilter
& log_type
))
1921 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1922 gUIHandlerW
, gUIContext
, eMessageType
, debugstr_w(message
));
1923 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1925 else if (!rc
&& gUIHandlerA
&& (gUIFilter
& log_type
))
1927 TRACE("Calling UI handler %p(pvContext=%p, iMessageType=%08x, szMessage=%s)\n",
1928 gUIHandlerA
, gUIContext
, eMessageType
, debugstr_a(msg
));
1929 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1933 rc
= internal_ui_handler(package
, eMessageType
, record
, message
);
1935 if (!rc
&& package
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1936 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1939 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1940 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1943 msi_free( message
);
1948 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1950 switch (eMessageType
& 0xff000000)
1952 case INSTALLMESSAGE_FATALEXIT
:
1953 case INSTALLMESSAGE_ERROR
:
1954 case INSTALLMESSAGE_WARNING
:
1955 case INSTALLMESSAGE_USER
:
1956 case INSTALLMESSAGE_INFO
:
1957 case INSTALLMESSAGE_OUTOFDISKSPACE
:
1958 if (MSI_RecordGetInteger(record
, 1) != MSI_NULL_INTEGER
)
1960 WCHAR template_prefix
[1024];
1961 WCHAR
*template_rec
, *template;
1964 if (MSI_RecordIsNull(record
, 0))
1966 LoadStringW(msi_hInstance
, IDS_INSTALLERROR
, template_prefix
, 1024);
1967 MSI_RecordSetStringW(record
, 0, template_prefix
);
1971 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1974 switch(eMessageType
& 0xff000000)
1976 case INSTALLMESSAGE_FATALEXIT
: prefix_id
= IDS_FATALEXIT
; break;
1977 case INSTALLMESSAGE_ERROR
: prefix_id
= IDS_ERROR
; break;
1978 case INSTALLMESSAGE_WARNING
: prefix_id
= IDS_WARNING
; break;
1979 case INSTALLMESSAGE_INFO
: prefix_id
= IDS_INFO
; break;
1980 case INSTALLMESSAGE_OUTOFDISKSPACE
: prefix_id
= IDS_OUTOFDISKSPACE
; break;
1983 LoadStringW(msi_hInstance
, prefix_id
, template_prefix
, 1024);
1985 template_rec
= msi_dup_record_field(record
, 0);
1986 if (!template_rec
) return ERROR_OUTOFMEMORY
;
1988 template = msi_alloc((strlenW(template_rec
) + strlenW(template_prefix
) + 1) * sizeof(WCHAR
));
1989 if (!template) return ERROR_OUTOFMEMORY
;
1991 strcpyW(template, template_prefix
);
1992 strcatW(template, template_rec
);
1993 MSI_RecordSetStringW(record
, 0, template);
1995 msi_free(template_rec
);
1999 case INSTALLMESSAGE_ACTIONSTART
:
2001 WCHAR template_s
[1024];
2002 static const WCHAR time_format
[] =
2003 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
2004 WCHAR timet
[100], template[1024];
2006 LoadStringW(msi_hInstance
, IDS_ACTIONSTART
, template_s
, 1024);
2007 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, time_format
, timet
, 100);
2008 sprintfW(template, template_s
, timet
);
2009 MSI_RecordSetStringW(record
, 0, template);
2011 msi_free(package
->LastAction
);
2012 msi_free(package
->LastActionTemplate
);
2013 package
->LastAction
= msi_dup_record_field(record
, 1);
2014 if (!package
->LastAction
) package
->LastAction
= strdupW(szEmpty
);
2015 package
->LastActionTemplate
= msi_dup_record_field(record
, 3);
2018 case INSTALLMESSAGE_ACTIONDATA
:
2019 if (package
->LastAction
&& package
->LastActionTemplate
)
2021 static const WCHAR template_s
[] =
2022 {'{','{','%','s',':',' ','}','}','%','s',0};
2025 template = msi_alloc((strlenW(package
->LastAction
) + strlenW(package
->LastActionTemplate
) + 7) * sizeof(WCHAR
));
2026 if (!template) return ERROR_OUTOFMEMORY
;
2027 sprintfW(template, template_s
, package
->LastAction
, package
->LastActionTemplate
);
2028 MSI_RecordSetStringW(record
, 0, template);
2032 case INSTALLMESSAGE_COMMONDATA
:
2034 WCHAR
template[1024];
2035 LoadStringW(msi_hInstance
, IDS_COMMONDATA
, template, 1024);
2036 MSI_RecordSetStringW(record
, 0, template);
2041 return MSI_ProcessMessageVerbatim(package
, eMessageType
, record
);
2044 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
2047 UINT ret
= ERROR_INVALID_HANDLE
;
2048 MSIPACKAGE
*package
= NULL
;
2049 MSIRECORD
*record
= NULL
;
2051 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INITIALIZE
||
2052 (eMessageType
& 0xff000000) == INSTALLMESSAGE_TERMINATE
)
2055 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
&&
2056 MsiRecordGetInteger(hRecord
, 1) != 2)
2059 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2063 IWineMsiRemotePackage
*remote_package
;
2065 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2066 if (!remote_package
)
2067 return ERROR_INVALID_HANDLE
;
2069 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
2071 IWineMsiRemotePackage_Release( remote_package
);
2075 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2076 return HRESULT_CODE(hr
);
2078 return ERROR_FUNCTION_FAILED
;
2081 return ERROR_SUCCESS
;
2084 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
2088 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
2091 msiobj_release( &package
->hdr
);
2093 msiobj_release( &record
->hdr
);
2100 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
2102 LPWSTR szwName
= NULL
, szwValue
= NULL
;
2103 UINT r
= ERROR_OUTOFMEMORY
;
2105 szwName
= strdupAtoW( szName
);
2106 if( szName
&& !szwName
)
2109 szwValue
= strdupAtoW( szValue
);
2110 if( szValue
&& !szwValue
)
2113 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
2116 msi_free( szwName
);
2117 msi_free( szwValue
);
2122 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
2126 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
2130 msi_free( folder
->ResolvedSource
);
2131 folder
->ResolvedSource
= NULL
;
2135 msi_free( folder
->ResolvedTarget
);
2136 folder
->ResolvedTarget
= NULL
;
2141 UINT
msi_set_property( MSIDATABASE
*db
, const WCHAR
*name
, const WCHAR
*value
, int len
)
2143 static const WCHAR insert_query
[] = {
2144 'I','N','S','E','R','T',' ','I','N','T','O',' ',
2145 '`','_','P','r','o','p','e','r','t','y','`',' ',
2146 '(','`','_','P','r','o','p','e','r','t','y','`',',','`','V','a','l','u','e','`',')',' ',
2147 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
2148 static const WCHAR update_query
[] = {
2149 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
2150 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ','W','H','E','R','E',' ',
2151 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2152 static const WCHAR delete_query
[] = {
2153 'D','E','L','E','T','E',' ','F','R','O','M',' ',
2154 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
2155 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
2157 MSIRECORD
*row
= NULL
;
2162 TRACE("%p %s %s %d\n", db
, debugstr_w(name
), debugstr_wn(value
, len
), len
);
2165 return ERROR_INVALID_PARAMETER
;
2167 /* this one is weird... */
2169 return value
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
2171 if (value
&& len
< 0) len
= strlenW( value
);
2173 rc
= msi_get_property( db
, name
, 0, &sz
);
2174 if (!value
|| (!*value
&& !len
))
2176 sprintfW( query
, delete_query
, name
);
2178 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
2180 sprintfW( query
, update_query
, name
);
2181 row
= MSI_CreateRecord(1);
2182 msi_record_set_string( row
, 1, value
, len
);
2186 strcpyW( query
, insert_query
);
2187 row
= MSI_CreateRecord(2);
2188 msi_record_set_string( row
, 1, name
, -1 );
2189 msi_record_set_string( row
, 2, value
, len
);
2192 rc
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2193 if (rc
== ERROR_SUCCESS
)
2195 rc
= MSI_ViewExecute(view
, row
);
2196 MSI_ViewClose(view
);
2197 msiobj_release(&view
->hdr
);
2199 if (row
) msiobj_release(&row
->hdr
);
2203 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2205 MSIPACKAGE
*package
;
2208 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2212 BSTR name
= NULL
, value
= NULL
;
2213 IWineMsiRemotePackage
*remote_package
;
2215 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2216 if (!remote_package
)
2217 return ERROR_INVALID_HANDLE
;
2219 name
= SysAllocString( szName
);
2220 value
= SysAllocString( szValue
);
2221 if ((!name
&& szName
) || (!value
&& szValue
))
2223 SysFreeString( name
);
2224 SysFreeString( value
);
2225 IWineMsiRemotePackage_Release( remote_package
);
2226 return ERROR_OUTOFMEMORY
;
2229 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2231 SysFreeString( name
);
2232 SysFreeString( value
);
2233 IWineMsiRemotePackage_Release( remote_package
);
2237 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2238 return HRESULT_CODE(hr
);
2240 return ERROR_FUNCTION_FAILED
;
2243 return ERROR_SUCCESS
;
2246 ret
= msi_set_property( package
->db
, szName
, szValue
, -1 );
2247 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, szSourceDir
))
2248 msi_reset_folders( package
, TRUE
);
2250 msiobj_release( &package
->hdr
);
2254 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2256 static const WCHAR query
[]= {
2257 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2258 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',' ',
2259 'W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`','=','?',0};
2260 MSIRECORD
*rec
, *row
= NULL
;
2264 if (!name
|| !*name
)
2267 rec
= MSI_CreateRecord(1);
2271 MSI_RecordSetStringW(rec
, 1, name
);
2273 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2274 if (r
== ERROR_SUCCESS
)
2276 MSI_ViewExecute(view
, rec
);
2277 MSI_ViewFetch(view
, &row
);
2278 MSI_ViewClose(view
);
2279 msiobj_release(&view
->hdr
);
2281 msiobj_release(&rec
->hdr
);
2285 /* internal function, not compatible with MsiGetPropertyW */
2286 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2287 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2290 UINT rc
= ERROR_FUNCTION_FAILED
;
2292 TRACE("%p %s %p %p\n", db
, debugstr_w(szName
), szValueBuf
, pchValueBuf
);
2294 row
= msi_get_property_row( db
, szName
);
2296 if (*pchValueBuf
> 0)
2301 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2302 msiobj_release(&row
->hdr
);
2305 if (rc
== ERROR_SUCCESS
)
2306 TRACE("returning %s for property %s\n", debugstr_wn(szValueBuf
, *pchValueBuf
),
2307 debugstr_w(szName
));
2308 else if (rc
== ERROR_MORE_DATA
)
2309 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2310 debugstr_w(szName
));
2314 TRACE("property %s not found\n", debugstr_w(szName
));
2320 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2326 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2327 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2331 str
= msi_alloc(sz
* sizeof(WCHAR
));
2332 r
= msi_get_property(db
, prop
, str
, &sz
);
2333 if (r
!= ERROR_SUCCESS
)
2342 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2344 LPWSTR str
= msi_dup_property( db
, prop
);
2345 int val
= str
? atoiW(str
) : def
;
2350 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2351 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2353 MSIPACKAGE
*package
;
2354 MSIRECORD
*row
= NULL
;
2355 UINT r
= ERROR_FUNCTION_FAILED
;
2359 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2360 szValueBuf
->str
.w
, pchValueBuf
);
2363 return ERROR_INVALID_PARAMETER
;
2365 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2369 IWineMsiRemotePackage
*remote_package
;
2370 LPWSTR value
= NULL
;
2373 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2374 if (!remote_package
)
2375 return ERROR_INVALID_HANDLE
;
2377 bname
= SysAllocString( name
);
2380 IWineMsiRemotePackage_Release( remote_package
);
2381 return ERROR_OUTOFMEMORY
;
2384 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2389 value
= msi_alloc(len
* sizeof(WCHAR
));
2392 r
= ERROR_OUTOFMEMORY
;
2396 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, value
, &len
);
2400 r
= msi_strcpy_to_awstring( value
, len
, szValueBuf
, pchValueBuf
);
2402 /* Bug required by Adobe installers */
2403 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2404 *pchValueBuf
*= sizeof(WCHAR
);
2407 IWineMsiRemotePackage_Release(remote_package
);
2408 SysFreeString(bname
);
2413 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2414 return HRESULT_CODE(hr
);
2416 return ERROR_FUNCTION_FAILED
;
2422 row
= msi_get_property_row( package
->db
, name
);
2424 val
= msi_record_get_string( row
, 1, (int *)&len
);
2429 r
= msi_strcpy_to_awstring( val
, len
, szValueBuf
, pchValueBuf
);
2432 msiobj_release( &row
->hdr
);
2433 msiobj_release( &package
->hdr
);
2438 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2439 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2445 val
.unicode
= FALSE
;
2446 val
.str
.a
= szValueBuf
;
2448 name
= strdupAtoW( szName
);
2449 if (szName
&& !name
)
2450 return ERROR_OUTOFMEMORY
;
2452 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2457 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2458 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2463 val
.str
.w
= szValueBuf
;
2465 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2468 typedef struct _msi_remote_package_impl
{
2469 IWineMsiRemotePackage IWineMsiRemotePackage_iface
;
2472 } msi_remote_package_impl
;
2474 static inline msi_remote_package_impl
*impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage
*iface
)
2476 return CONTAINING_RECORD(iface
, msi_remote_package_impl
, IWineMsiRemotePackage_iface
);
2479 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2480 REFIID riid
,LPVOID
*ppobj
)
2482 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2483 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2485 IWineMsiRemotePackage_AddRef( iface
);
2490 return E_NOINTERFACE
;
2493 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2495 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2497 return InterlockedIncrement( &This
->refs
);
2500 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2502 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2505 r
= InterlockedDecrement( &This
->refs
);
2508 MsiCloseHandle( This
->package
);
2514 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2516 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2517 This
->package
= handle
;
2521 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2523 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2524 IWineMsiRemoteDatabase
*rdb
= NULL
;
2528 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2529 if (FAILED(hr
) || !rdb
)
2531 ERR("Failed to create remote database\n");
2535 hdb
= MsiGetActiveDatabase(This
->package
);
2537 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2540 ERR("Failed to set the database handle\n");
2544 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2548 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
, DWORD
*size
)
2550 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2551 UINT r
= MsiGetPropertyW(This
->package
, property
, value
, size
);
2552 if (r
!= ERROR_SUCCESS
) return HRESULT_FROM_WIN32(r
);
2556 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2558 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2559 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2560 return HRESULT_FROM_WIN32(r
);
2563 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2565 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2566 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2567 return HRESULT_FROM_WIN32(r
);
2570 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2572 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2573 UINT r
= MsiDoActionW(This
->package
, action
);
2574 return HRESULT_FROM_WIN32(r
);
2577 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2579 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2580 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2581 return HRESULT_FROM_WIN32(r
);
2584 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2586 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2587 UINT r
= MsiGetTargetPathW(This
->package
, folder
, value
, size
);
2588 return HRESULT_FROM_WIN32(r
);
2591 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2593 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2594 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2595 return HRESULT_FROM_WIN32(r
);
2598 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2600 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2601 UINT r
= MsiGetSourcePathW(This
->package
, folder
, value
, size
);
2602 return HRESULT_FROM_WIN32(r
);
2605 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2607 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2608 *ret
= MsiGetMode(This
->package
, mode
);
2612 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2614 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2615 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2616 return HRESULT_FROM_WIN32(r
);
2619 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2620 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2622 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2623 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2624 return HRESULT_FROM_WIN32(r
);
2627 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2629 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2630 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2631 return HRESULT_FROM_WIN32(r
);
2634 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2635 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2637 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2638 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2639 return HRESULT_FROM_WIN32(r
);
2642 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2644 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2645 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2646 return HRESULT_FROM_WIN32(r
);
2649 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2651 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2652 *language
= MsiGetLanguage(This
->package
);
2656 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2658 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2659 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2660 return HRESULT_FROM_WIN32(r
);
2663 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2667 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2668 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2669 if (r
== ERROR_SUCCESS
)
2671 *value
= SysAllocStringLen(NULL
, size
);
2673 return E_OUTOFMEMORY
;
2675 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2677 return HRESULT_FROM_WIN32(r
);
2680 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2682 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2683 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2684 return HRESULT_FROM_WIN32(r
);
2687 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2688 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2690 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2691 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2692 return HRESULT_FROM_WIN32(r
);
2695 static HRESULT WINAPI
mrp_EnumComponentCosts( IWineMsiRemotePackage
*iface
, BSTR component
,
2696 DWORD index
, INSTALLSTATE state
, BSTR drive
,
2697 DWORD
*buflen
, INT
*cost
, INT
*temp
)
2699 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2700 UINT r
= MsiEnumComponentCostsW(This
->package
, component
, index
, state
, drive
, buflen
, cost
, temp
);
2701 return HRESULT_FROM_WIN32(r
);
2704 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2710 mrp_GetActiveDatabase
,
2721 mrp_GetFeatureState
,
2722 mrp_SetFeatureState
,
2723 mrp_GetComponentState
,
2724 mrp_SetComponentState
,
2726 mrp_SetInstallLevel
,
2728 mrp_EvaluateCondition
,
2730 mrp_EnumComponentCosts
2733 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2735 msi_remote_package_impl
* This
;
2737 This
= msi_alloc( sizeof *This
);
2739 return E_OUTOFMEMORY
;
2741 This
->IWineMsiRemotePackage_iface
.lpVtbl
= &msi_remote_package_vtbl
;
2745 *ppObj
= &This
->IWineMsiRemotePackage_iface
;
2750 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2751 LPCWSTR property
, LPWSTR value
)
2753 MSISOURCELISTINFO
*info
;
2755 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2757 if (!strcmpW( info
->value
, value
)) return ERROR_SUCCESS
;
2760 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2762 return ERROR_OUTOFMEMORY
;
2764 info
->context
= context
;
2765 info
->options
= options
;
2766 info
->property
= property
;
2767 info
->value
= strdupW(value
);
2768 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2770 return ERROR_SUCCESS
;
2773 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2774 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2778 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2780 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2783 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2785 return ERROR_OUTOFMEMORY
;
2787 disk
->context
= context
;
2788 disk
->options
= options
;
2789 disk
->disk_id
= disk_id
;
2790 disk
->volume_label
= strdupW(volume_label
);
2791 disk
->disk_prompt
= strdupW(disk_prompt
);
2792 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2794 return ERROR_SUCCESS
;