2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
42 #include "wine/unicode.h"
48 #include "msiserver.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
52 static void remove_tracked_tempfiles( MSIPACKAGE
*package
)
54 struct list
*item
, *cursor
;
56 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->tempfiles
)
58 MSITEMPFILE
*temp
= LIST_ENTRY( item
, MSITEMPFILE
, entry
);
60 list_remove( &temp
->entry
);
61 TRACE("deleting temp file %s\n", debugstr_w( temp
->Path
));
62 DeleteFileW( temp
->Path
);
63 msi_free( temp
->Path
);
68 static void free_feature( MSIFEATURE
*feature
)
70 struct list
*item
, *cursor
;
72 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
74 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
75 list_remove( &fl
->entry
);
79 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
81 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
82 list_remove( &cl
->entry
);
85 msi_free( feature
->Feature
);
86 msi_free( feature
->Feature_Parent
);
87 msi_free( feature
->Directory
);
88 msi_free( feature
->Description
);
89 msi_free( feature
->Title
);
93 static void free_folder( MSIFOLDER
*folder
)
95 struct list
*item
, *cursor
;
97 LIST_FOR_EACH_SAFE( item
, cursor
, &folder
->children
)
99 FolderList
*fl
= LIST_ENTRY( item
, FolderList
, entry
);
100 list_remove( &fl
->entry
);
103 msi_free( folder
->Parent
);
104 msi_free( folder
->Directory
);
105 msi_free( folder
->TargetDefault
);
106 msi_free( folder
->SourceLongPath
);
107 msi_free( folder
->SourceShortPath
);
108 msi_free( folder
->ResolvedTarget
);
109 msi_free( folder
->ResolvedSource
);
113 static void free_extension( MSIEXTENSION
*ext
)
115 struct list
*item
, *cursor
;
117 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
119 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
121 list_remove( &verb
->entry
);
122 msi_free( verb
->Verb
);
123 msi_free( verb
->Command
);
124 msi_free( verb
->Argument
);
128 msi_free( ext
->Extension
);
129 msi_free( ext
->ProgIDText
);
133 static void free_assembly( MSIASSEMBLY
*assembly
)
135 msi_free( assembly
->feature
);
136 msi_free( assembly
->manifest
);
137 msi_free( assembly
->application
);
138 msi_free( assembly
->display_name
);
139 if (assembly
->tempdir
) RemoveDirectoryW( assembly
->tempdir
);
140 msi_free( assembly
->tempdir
);
141 msi_free( assembly
);
144 void msi_free_action_script( MSIPACKAGE
*package
, UINT script
)
147 for (i
= 0; i
< package
->script
->ActionCount
[script
]; i
++)
148 msi_free( package
->script
->Actions
[script
][i
] );
150 msi_free( package
->script
->Actions
[script
] );
151 package
->script
->Actions
[script
] = NULL
;
152 package
->script
->ActionCount
[script
] = 0;
155 static void free_package_structures( MSIPACKAGE
*package
)
158 struct list
*item
, *cursor
;
160 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
162 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
163 list_remove( &feature
->entry
);
164 free_feature( feature
);
167 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
169 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
170 list_remove( &folder
->entry
);
171 free_folder( folder
);
174 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
176 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
178 list_remove( &comp
->entry
);
179 msi_free( comp
->Component
);
180 msi_free( comp
->ComponentId
);
181 msi_free( comp
->Directory
);
182 msi_free( comp
->Condition
);
183 msi_free( comp
->KeyPath
);
184 msi_free( comp
->FullKeypath
);
185 if (comp
->assembly
) free_assembly( comp
->assembly
);
189 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
191 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
193 list_remove( &file
->entry
);
194 msi_free( file
->File
);
195 msi_free( file
->FileName
);
196 msi_free( file
->ShortName
);
197 msi_free( file
->LongName
);
198 msi_free( file
->Version
);
199 msi_free( file
->Language
);
200 msi_free( file
->TargetPath
);
204 /* clean up extension, progid, class and verb structures */
205 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
207 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
209 list_remove( &cls
->entry
);
210 msi_free( cls
->clsid
);
211 msi_free( cls
->Context
);
212 msi_free( cls
->Description
);
213 msi_free( cls
->FileTypeMask
);
214 msi_free( cls
->IconPath
);
215 msi_free( cls
->DefInprocHandler
);
216 msi_free( cls
->DefInprocHandler32
);
217 msi_free( cls
->Argument
);
218 msi_free( cls
->ProgIDText
);
222 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
224 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
226 list_remove( &ext
->entry
);
227 free_extension( ext
);
230 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
232 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
234 list_remove( &progid
->entry
);
235 msi_free( progid
->ProgID
);
236 msi_free( progid
->Description
);
237 msi_free( progid
->IconPath
);
241 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
243 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
245 list_remove( &mt
->entry
);
246 msi_free( mt
->suffix
);
247 msi_free( mt
->clsid
);
248 msi_free( mt
->ContentType
);
252 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
254 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
256 list_remove( &appid
->entry
);
257 msi_free( appid
->AppID
);
258 msi_free( appid
->RemoteServerName
);
259 msi_free( appid
->LocalServer
);
260 msi_free( appid
->ServiceParameters
);
261 msi_free( appid
->DllSurrogate
);
265 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
267 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
269 list_remove( &info
->entry
);
270 msi_free( info
->value
);
274 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
276 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
278 list_remove( &info
->entry
);
279 msi_free( info
->volume_label
);
280 msi_free( info
->disk_prompt
);
286 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
287 msi_free_action_script( package
, i
);
289 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
290 msi_free( package
->script
->UniqueActions
[i
] );
292 msi_free( package
->script
->UniqueActions
);
293 msi_free( package
->script
);
296 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->patches
)
298 MSIPATCHINFO
*patch
= LIST_ENTRY( item
, MSIPATCHINFO
, entry
);
300 list_remove( &patch
->entry
);
301 msi_free( patch
->patchcode
);
302 msi_free( patch
->transforms
);
303 msi_free( patch
->localfile
);
304 msi_free( patch
->filename
);
308 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->binaries
)
310 MSIBINARY
*binary
= LIST_ENTRY( item
, MSIBINARY
, entry
);
312 list_remove( &binary
->entry
);
314 FreeLibrary( binary
->module
);
315 if (!DeleteFileW( binary
->tmpfile
))
316 ERR("failed to delete %s (%u)\n", debugstr_w(binary
->tmpfile
), GetLastError());
317 msi_free( binary
->source
);
318 msi_free( binary
->tmpfile
);
322 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->cabinet_streams
)
324 MSICABINETSTREAM
*cab
= LIST_ENTRY( item
, MSICABINETSTREAM
, entry
);
326 list_remove( &cab
->entry
);
327 IStorage_Release( cab
->storage
);
328 msi_free( cab
->stream
);
332 msi_free( package
->BaseURL
);
333 msi_free( package
->PackagePath
);
334 msi_free( package
->ProductCode
);
335 msi_free( package
->ActionFormat
);
336 msi_free( package
->LastAction
);
337 msi_free( package
->langids
);
339 remove_tracked_tempfiles(package
);
341 /* cleanup control event subscriptions */
342 ControlEvent_CleanupSubscriptions( package
);
345 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
348 MSIPACKAGE
*package
= (MSIPACKAGE
*)arg
;
350 if( package
->dialog
)
351 msi_dialog_destroy( package
->dialog
);
353 msiobj_release( &package
->db
->hdr
);
354 free_package_structures(package
);
355 CloseHandle( package
->log_file
);
357 for (i
= 0; i
< CLR_VERSION_MAX
; i
++)
358 if (package
->cache_net
[i
]) IAssemblyCache_Release( package
->cache_net
[i
] );
359 if (package
->cache_sxs
) IAssemblyCache_Release( package
->cache_sxs
);
361 if (package
->localfile
)
363 DeleteFileW( package
->localfile
);
364 msi_free( package
->localfile
);
368 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
370 MSIQUERY
*view
= NULL
;
373 static const WCHAR CreateSql
[] = {
374 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
375 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
376 '`','_','P','r','o','p','e','r','t','y','`',' ',
377 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
378 'T','E','M','P','O','R','A','R','Y',',',' ',
379 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
380 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
381 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
382 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
384 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &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 MSIQUERY
*view_select
= NULL
;
399 static const WCHAR query_select
[] = {
400 'S','E','L','E','C','T',' ','*',' ',
401 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
402 static const WCHAR query_insert
[] = {
403 'I','N','S','E','R','T',' ','i','n','t','o',' ',
404 '`','_','P','r','o','p','e','r','t','y','`',' ',
405 '(','`','_','P','r','o','p','e','r','t','y','`',',',
406 '`','V','a','l','u','e','`',')',' ',
407 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
408 static const WCHAR query_update
[] = {
409 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
410 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
411 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
413 rc
= MSI_DatabaseOpenViewW( package
->db
, query_select
, &view_select
);
414 if (rc
!= ERROR_SUCCESS
)
417 rc
= MSI_ViewExecute( view_select
, 0 );
418 if (rc
!= ERROR_SUCCESS
)
420 MSI_ViewClose( view_select
);
421 msiobj_release( &view_select
->hdr
);
427 MSIQUERY
*view_insert
, *view_update
;
428 MSIRECORD
*rec_select
;
430 rc
= MSI_ViewFetch( view_select
, &rec_select
);
431 if (rc
!= ERROR_SUCCESS
)
434 rc
= MSI_DatabaseOpenViewW( package
->db
, query_insert
, &view_insert
);
435 if (rc
!= ERROR_SUCCESS
)
437 msiobj_release( &rec_select
->hdr
);
441 rc
= MSI_ViewExecute( view_insert
, rec_select
);
442 MSI_ViewClose( view_insert
);
443 msiobj_release( &view_insert
->hdr
);
444 if (rc
!= ERROR_SUCCESS
)
446 MSIRECORD
*rec_update
;
448 TRACE("insert failed, trying update\n");
450 rc
= MSI_DatabaseOpenViewW( package
->db
, query_update
, &view_update
);
451 if (rc
!= ERROR_SUCCESS
)
453 WARN("open view failed %u\n", rc
);
454 msiobj_release( &rec_select
->hdr
);
458 rec_update
= MSI_CreateRecord( 2 );
459 MSI_RecordCopyField( rec_select
, 1, rec_update
, 2 );
460 MSI_RecordCopyField( rec_select
, 2, rec_update
, 1 );
461 rc
= MSI_ViewExecute( view_update
, rec_update
);
462 if (rc
!= ERROR_SUCCESS
)
463 WARN("update failed %u\n", rc
);
465 MSI_ViewClose( view_update
);
466 msiobj_release( &view_update
->hdr
);
467 msiobj_release( &rec_update
->hdr
);
470 msiobj_release( &rec_select
->hdr
);
473 MSI_ViewClose( view_select
);
474 msiobj_release( &view_select
->hdr
);
481 * Sets the "Installed" property to indicate that
482 * the product is installed for the current user.
484 static UINT
set_installed_prop( MSIPACKAGE
*package
)
489 if (!package
->ProductCode
) return ERROR_FUNCTION_FAILED
;
491 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, package
->platform
, &hkey
, FALSE
);
492 if (r
== ERROR_SUCCESS
)
495 msi_set_property( package
->db
, szInstalled
, szOne
);
500 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
504 LPWSTR sid_str
= NULL
, dom
= NULL
;
505 DWORD size
, dom_size
;
507 UINT r
= ERROR_FUNCTION_FAILED
;
510 GetUserNameW( NULL
, &size
);
512 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
514 return ERROR_OUTOFMEMORY
;
516 if (!GetUserNameW( user_name
, &size
))
521 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
523 psid
= msi_alloc( size
);
524 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
527 r
= ERROR_OUTOFMEMORY
;
531 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
534 if (!ConvertSidToStringSidW( psid
, &sid_str
))
537 r
= msi_set_property( package
->db
, szUserSID
, sid_str
);
540 LocalFree( sid_str
);
543 msi_free( user_name
);
548 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
553 DWORD index
= 0, size
;
555 WCHAR name
[MAX_PATH
];
556 WCHAR windir
[MAX_PATH
];
558 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
559 static const WCHAR sub
[] = {
560 'S','o','f','t','w','a','r','e','\\',
561 'M','i','c','r','o','s','o','f','t','\\',
562 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
565 static const WCHAR subdir
[] = {
566 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
567 'F','r','a','m','e','w','o','r','k','\\',0
570 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
571 if (res
!= ERROR_SUCCESS
)
574 GetWindowsDirectoryW(windir
, MAX_PATH
);
578 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
582 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
583 if (strcmpW( ver
, name
) < 0)
586 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
587 check
= msi_alloc(size
* sizeof(WCHAR
));
595 lstrcpyW(check
, windir
);
596 lstrcatW(check
, szBackSlash
);
597 lstrcatW(check
, subdir
);
598 lstrcatW(check
, name
);
599 lstrcatW(check
, szBackSlash
);
600 lstrcatW(check
, fusion
);
602 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
613 RegCloseKey(netsetup
);
617 typedef struct tagLANGANDCODEPAGE
623 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
627 LPVOID version
= NULL
;
629 LPWSTR fusion
, verstr
;
630 LANGANDCODEPAGE
*translate
;
632 static const WCHAR netasm
[] = {
633 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
635 static const WCHAR translation
[] = {
636 '\\','V','a','r','F','i','l','e','I','n','f','o',
637 '\\','T','r','a','n','s','l','a','t','i','o','n',0
639 static const WCHAR verfmt
[] = {
640 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
641 '\\','%','0','4','x','%','0','4','x',
642 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
645 fusion
= get_fusion_filename(package
);
649 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
652 version
= msi_alloc(size
);
653 if (!version
) return;
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
);
676 static VOID
set_installer_properties(MSIPACKAGE
*package
)
680 OSVERSIONINFOEXW OSVersion
;
683 WCHAR verstr
[10], bufstr
[20];
686 LPWSTR username
, companyname
;
687 SYSTEM_INFO sys_info
;
688 SYSTEMTIME systemtime
;
691 static const WCHAR szCommonFilesFolder
[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
692 static const WCHAR szProgramFilesFolder
[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
693 static const WCHAR szCommonAppDataFolder
[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
694 static const WCHAR szFavoritesFolder
[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
695 static const WCHAR szFontsFolder
[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
696 static const WCHAR szSendToFolder
[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
697 static const WCHAR szStartMenuFolder
[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
698 static const WCHAR szStartupFolder
[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
699 static const WCHAR szTemplateFolder
[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
700 static const WCHAR szDesktopFolder
[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
701 static const WCHAR szProgramMenuFolder
[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
702 static const WCHAR szAdminToolsFolder
[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
703 static const WCHAR szSystemFolder
[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
704 static const WCHAR szSystem16Folder
[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
705 static const WCHAR szLocalAppDataFolder
[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
706 static const WCHAR szMyPicturesFolder
[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
707 static const WCHAR szPersonalFolder
[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
708 static const WCHAR szWindowsVolume
[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
709 static const WCHAR szPrivileged
[] = {'P','r','i','v','i','l','e','g','e','d',0};
710 static const WCHAR szVersion9x
[] = {'V','e','r','s','i','o','n','9','X',0};
711 static const WCHAR szVersionNT
[] = {'V','e','r','s','i','o','n','N','T',0};
712 static const WCHAR szMsiNTProductType
[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
713 static const WCHAR szFormat
[] = {'%','l','i',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 szSix
[] = {'6',0 };
717 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
718 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
719 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
720 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
721 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
722 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
723 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
724 static const WCHAR szIntFormat
[] = {'%','d',0};
725 static const WCHAR szMsiAMD64
[] = { 'M','s','i','A','M','D','6','4',0 };
726 static const WCHAR szMsix64
[] = { 'M','s','i','x','6','4',0 };
727 static const WCHAR szSystem64Folder
[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
728 static const WCHAR szCommonFiles64Folder
[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
729 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 };
730 static const WCHAR szVersionNT64
[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
731 static const WCHAR szUserInfo
[] = {
732 'S','O','F','T','W','A','R','E','\\',
733 'M','i','c','r','o','s','o','f','t','\\',
734 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
735 'U','s','e','r',' ','I','n','f','o',0
737 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
738 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
739 static const WCHAR szCurrentVersion
[] = {
740 'S','O','F','T','W','A','R','E','\\',
741 'M','i','c','r','o','s','o','f','t','\\',
742 'W','i','n','d','o','w','s',' ','N','T','\\',
743 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
745 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
746 static const WCHAR szRegisteredOrganization
[] = {
747 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
749 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
750 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
751 static const WCHAR szDate
[] = {'D','a','t','e',0};
752 static const WCHAR szTime
[] = {'T','i','m','e',0};
753 static const WCHAR szUserLanguageID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
754 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
755 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
756 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
757 static const WCHAR szNetHoodFolder
[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
758 static const WCHAR szPrintHoodFolder
[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
759 static const WCHAR szRecentFolder
[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
762 * Other things that probably should be set:
764 * ComputerName VirtualMemory
765 * ShellAdvSupport DefaultUIFont PackagecodeChanging
766 * CaptionHeight BorderTop BorderSide TextHeight
767 * RedirectedDllSupport
770 SHGetFolderPathW(NULL
, CSIDL_COMMON_APPDATA
, NULL
, 0, pth
);
771 strcatW(pth
, szBackSlash
);
772 msi_set_property(package
->db
, szCommonAppDataFolder
, pth
);
774 SHGetFolderPathW(NULL
, CSIDL_FAVORITES
, NULL
, 0, pth
);
775 strcatW(pth
, szBackSlash
);
776 msi_set_property(package
->db
, szFavoritesFolder
, pth
);
778 SHGetFolderPathW(NULL
, CSIDL_FONTS
, NULL
, 0, pth
);
779 strcatW(pth
, szBackSlash
);
780 msi_set_property(package
->db
, szFontsFolder
, pth
);
782 SHGetFolderPathW(NULL
, CSIDL_SENDTO
, NULL
, 0, pth
);
783 strcatW(pth
, szBackSlash
);
784 msi_set_property(package
->db
, szSendToFolder
, pth
);
786 SHGetFolderPathW(NULL
, CSIDL_STARTMENU
, NULL
, 0, pth
);
787 strcatW(pth
, szBackSlash
);
788 msi_set_property(package
->db
, szStartMenuFolder
, pth
);
790 SHGetFolderPathW(NULL
, CSIDL_STARTUP
, NULL
, 0, pth
);
791 strcatW(pth
, szBackSlash
);
792 msi_set_property(package
->db
, szStartupFolder
, pth
);
794 SHGetFolderPathW(NULL
, CSIDL_TEMPLATES
, NULL
, 0, pth
);
795 strcatW(pth
, szBackSlash
);
796 msi_set_property(package
->db
, szTemplateFolder
, pth
);
798 SHGetFolderPathW(NULL
, CSIDL_DESKTOP
, NULL
, 0, pth
);
799 strcatW(pth
, szBackSlash
);
800 msi_set_property(package
->db
, szDesktopFolder
, pth
);
802 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
803 SHGetFolderPathW(NULL
, CSIDL_PROGRAMS
, NULL
, 0, pth
);
804 strcatW(pth
, szBackSlash
);
805 msi_set_property(package
->db
, szProgramMenuFolder
, pth
);
807 SHGetFolderPathW(NULL
, CSIDL_ADMINTOOLS
, NULL
, 0, pth
);
808 strcatW(pth
, szBackSlash
);
809 msi_set_property(package
->db
, szAdminToolsFolder
, pth
);
811 SHGetFolderPathW(NULL
, CSIDL_APPDATA
, NULL
, 0, pth
);
812 strcatW(pth
, szBackSlash
);
813 msi_set_property(package
->db
, szAppDataFolder
, pth
);
815 SHGetFolderPathW(NULL
, CSIDL_SYSTEM
, NULL
, 0, pth
);
816 strcatW(pth
, szBackSlash
);
817 msi_set_property(package
->db
, szSystemFolder
, pth
);
818 msi_set_property(package
->db
, szSystem16Folder
, pth
);
820 SHGetFolderPathW(NULL
, CSIDL_LOCAL_APPDATA
, NULL
, 0, pth
);
821 strcatW(pth
, szBackSlash
);
822 msi_set_property(package
->db
, szLocalAppDataFolder
, pth
);
824 SHGetFolderPathW(NULL
, CSIDL_MYPICTURES
, NULL
, 0, pth
);
825 strcatW(pth
, szBackSlash
);
826 msi_set_property(package
->db
, szMyPicturesFolder
, pth
);
828 SHGetFolderPathW(NULL
, CSIDL_PERSONAL
, NULL
, 0, pth
);
829 strcatW(pth
, szBackSlash
);
830 msi_set_property(package
->db
, szPersonalFolder
, pth
);
832 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
833 strcatW(pth
, szBackSlash
);
834 msi_set_property(package
->db
, szWindowsFolder
, pth
);
836 SHGetFolderPathW(NULL
, CSIDL_PRINTHOOD
, NULL
, 0, pth
);
837 strcatW(pth
, szBackSlash
);
838 msi_set_property(package
->db
, szPrintHoodFolder
, pth
);
840 SHGetFolderPathW(NULL
, CSIDL_NETHOOD
, NULL
, 0, pth
);
841 strcatW(pth
, szBackSlash
);
842 msi_set_property(package
->db
, szNetHoodFolder
, pth
);
844 SHGetFolderPathW(NULL
, CSIDL_RECENT
, NULL
, 0, pth
);
845 strcatW(pth
, szBackSlash
);
846 msi_set_property(package
->db
, szRecentFolder
, pth
);
848 /* Physical Memory is specified in MB. Using total amount. */
849 msex
.dwLength
= sizeof(msex
);
850 GlobalMemoryStatusEx( &msex
);
851 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/ 1024 / 1024) );
852 msi_set_property(package
->db
, szPhysicalMemory
, bufstr
);
854 SHGetFolderPathW(NULL
, CSIDL_WINDOWS
, NULL
, 0, pth
);
855 ptr
= strchrW(pth
,'\\');
856 if (ptr
) *(ptr
+ 1) = 0;
857 msi_set_property(package
->db
, szWindowsVolume
, pth
);
859 GetTempPathW(MAX_PATH
,pth
);
860 msi_set_property(package
->db
, szTempFolder
, pth
);
862 /* in a wine environment the user is always admin and privileged */
863 msi_set_property(package
->db
, szAdminUser
, szOne
);
864 msi_set_property(package
->db
, szPrivileged
, szOne
);
866 /* set the os things */
867 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
868 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
869 verval
= OSVersion
.dwMinorVersion
+ OSVersion
.dwMajorVersion
* 100;
870 sprintfW(verstr
, szFormat
, verval
);
871 switch (OSVersion
.dwPlatformId
)
873 case VER_PLATFORM_WIN32_WINDOWS
:
874 msi_set_property(package
->db
, szVersion9x
, verstr
);
876 case VER_PLATFORM_WIN32_NT
:
877 msi_set_property(package
->db
, szVersionNT
, verstr
);
878 sprintfW(verstr
, szFormat
,OSVersion
.wProductType
);
879 msi_set_property(package
->db
, szMsiNTProductType
, verstr
);
882 sprintfW(verstr
, szFormat
, OSVersion
.dwBuildNumber
);
883 msi_set_property(package
->db
, szWindowsBuild
, verstr
);
884 /* just fudge this */
885 msi_set_property(package
->db
, szServicePackLevel
, szSix
);
887 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
888 msi_set_property( package
->db
, szVersionMsi
, bufstr
);
889 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
890 msi_set_property( package
->db
, szVersionDatabase
, bufstr
);
892 GetNativeSystemInfo( &sys_info
);
893 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
894 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
896 msi_set_property( package
->db
, szIntel
, bufstr
);
898 GetSystemDirectoryW( pth
, MAX_PATH
);
899 PathAddBackslashW( pth
);
900 msi_set_property( package
->db
, szSystemFolder
, pth
);
902 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
903 PathAddBackslashW( pth
);
904 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
906 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
907 PathAddBackslashW( pth
);
908 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
910 else if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
912 msi_set_property( package
->db
, szMsiAMD64
, bufstr
);
913 msi_set_property( package
->db
, szMsix64
, bufstr
);
914 msi_set_property( package
->db
, szVersionNT64
, verstr
);
916 GetSystemDirectoryW( pth
, MAX_PATH
);
917 PathAddBackslashW( pth
);
918 msi_set_property( package
->db
, szSystem64Folder
, pth
);
920 GetSystemWow64DirectoryW( pth
, MAX_PATH
);
921 PathAddBackslashW( pth
);
922 msi_set_property( package
->db
, szSystemFolder
, pth
);
924 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES
, NULL
, 0, pth
);
925 PathAddBackslashW( pth
);
926 msi_set_property( package
->db
, szProgramFiles64Folder
, pth
);
928 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILESX86
, NULL
, 0, pth
);
929 PathAddBackslashW( pth
);
930 msi_set_property( package
->db
, szProgramFilesFolder
, pth
);
932 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMON
, NULL
, 0, pth
);
933 PathAddBackslashW( pth
);
934 msi_set_property( package
->db
, szCommonFiles64Folder
, pth
);
936 SHGetFolderPathW( NULL
, CSIDL_PROGRAM_FILES_COMMONX86
, NULL
, 0, pth
);
937 PathAddBackslashW( pth
);
938 msi_set_property( package
->db
, szCommonFilesFolder
, pth
);
941 /* Screen properties. */
943 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
944 msi_set_property( package
->db
, szScreenX
, bufstr
);
945 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
946 msi_set_property( package
->db
, szScreenY
, bufstr
);
947 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
948 msi_set_property( package
->db
, szColorBits
, bufstr
);
951 /* USERNAME and COMPANYNAME */
952 username
= msi_dup_property( package
->db
, szUSERNAME
);
953 companyname
= msi_dup_property( package
->db
, szCOMPANYNAME
);
955 if ((!username
|| !companyname
) &&
956 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
959 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
960 msi_set_property( package
->db
, szUSERNAME
, username
);
962 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
963 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
966 if ((!username
|| !companyname
) &&
967 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
970 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
971 msi_set_property( package
->db
, szUSERNAME
, username
);
973 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrganization
)))
974 msi_set_property( package
->db
, szCOMPANYNAME
, companyname
);
977 msi_free( username
);
978 msi_free( companyname
);
980 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
981 ERR("Failed to set the UserSID property\n");
983 /* Date and time properties */
984 GetSystemTime( &systemtime
);
985 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
986 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
987 msi_set_property( package
->db
, szDate
, bufstr
);
989 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
991 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
992 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
993 &systemtime
, NULL
, bufstr
,
994 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
995 msi_set_property( package
->db
, szTime
, bufstr
);
997 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
999 set_msi_assembly_prop( package
);
1001 langid
= GetUserDefaultLangID();
1002 sprintfW(bufstr
, szIntFormat
, langid
);
1003 msi_set_property( package
->db
, szUserLanguageID
, bufstr
);
1005 langid
= GetSystemDefaultLangID();
1006 sprintfW(bufstr
, szIntFormat
, langid
);
1007 msi_set_property( package
->db
, szSystemLangID
, bufstr
);
1009 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
1010 msi_set_property( package
->db
, szProductState
, bufstr
);
1013 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_INSUFFICIENT_BUFFER
)
1016 if ((username
= msi_alloc( len
* sizeof(WCHAR
) )))
1018 if (GetUserNameW( username
, &len
))
1019 msi_set_property( package
->db
, szLogonUser
, username
);
1020 msi_free( username
);
1025 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
1029 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
1032 LPWSTR package_code
;
1033 static const WCHAR szPackageCode
[] = {
1034 'P','a','c','k','a','g','e','C','o','d','e',0};
1037 ERR("Unable to allocate handle\n");
1038 return ERROR_OUTOFMEMORY
;
1041 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
1042 MsiCloseHandle(hdb
);
1043 if (rc
!= ERROR_SUCCESS
)
1045 ERR("Unable to open Summary Information\n");
1049 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
1050 &count
, NULL
, NULL
, NULL
);
1051 if (rc
!= ERROR_SUCCESS
)
1053 WARN("Unable to query page count: %d\n", rc
);
1057 /* load package code property */
1059 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1060 NULL
, NULL
, NULL
, &len
);
1061 if (rc
!= ERROR_MORE_DATA
)
1063 WARN("Unable to query revision number: %d\n", rc
);
1064 rc
= ERROR_FUNCTION_FAILED
;
1069 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
1070 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
1071 NULL
, NULL
, package_code
, &len
);
1072 if (rc
!= ERROR_SUCCESS
)
1074 WARN("Unable to query rev number: %d\n", rc
);
1078 msi_set_property( package
->db
, szPackageCode
, package_code
);
1079 msi_free( package_code
);
1081 /* load package attributes */
1083 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
1084 &count
, NULL
, NULL
, NULL
);
1085 package
->WordCount
= count
;
1088 MsiCloseHandle(suminfo
);
1092 static MSIPACKAGE
*msi_alloc_package( void )
1094 MSIPACKAGE
*package
;
1096 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
1100 list_init( &package
->components
);
1101 list_init( &package
->features
);
1102 list_init( &package
->files
);
1103 list_init( &package
->filepatches
);
1104 list_init( &package
->tempfiles
);
1105 list_init( &package
->folders
);
1106 list_init( &package
->subscriptions
);
1107 list_init( &package
->appids
);
1108 list_init( &package
->classes
);
1109 list_init( &package
->mimes
);
1110 list_init( &package
->extensions
);
1111 list_init( &package
->progids
);
1112 list_init( &package
->RunningActions
);
1113 list_init( &package
->sourcelist_info
);
1114 list_init( &package
->sourcelist_media
);
1115 list_init( &package
->patches
);
1116 list_init( &package
->binaries
);
1117 list_init( &package
->cabinet_streams
);
1123 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1128 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1130 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1131 if (r
!= ERROR_SUCCESS
)
1134 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1140 void msi_adjust_privilege_properties( MSIPACKAGE
*package
)
1142 /* FIXME: this should depend on the user's privileges */
1143 if (msi_get_property_int( package
->db
, szAllUsers
, 0 ) == 2)
1145 TRACE("resetting ALLUSERS property from 2 to 1\n");
1146 msi_set_property( package
->db
, szAllUsers
, szOne
);
1148 msi_set_property( package
->db
, szAdminUser
, szOne
);
1151 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1153 static const WCHAR szpi
[] = {'%','i',0};
1154 MSIPACKAGE
*package
;
1160 package
= msi_alloc_package();
1163 msiobj_addref( &db
->hdr
);
1166 package
->WordCount
= 0;
1167 package
->PackagePath
= strdupW( db
->path
);
1168 package
->BaseURL
= strdupW( base_url
);
1170 create_temp_property_table( package
);
1171 msi_clone_properties( package
);
1172 msi_adjust_privilege_properties( package
);
1174 package
->ProductCode
= msi_dup_property( package
->db
, szProductCode
);
1175 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1177 set_installed_prop( package
);
1178 set_installer_properties( package
);
1180 sprintfW(uilevel
,szpi
,gUILevel
);
1181 msi_set_property(package
->db
, szUILevel
, uilevel
);
1183 r
= msi_load_summary_properties( package
);
1184 if (r
!= ERROR_SUCCESS
)
1186 msiobj_release( &package
->hdr
);
1190 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1191 msi_load_admin_properties( package
);
1193 package
->log_file
= INVALID_HANDLE_VALUE
;
1200 * copy_package_to_temp [internal]
1202 * copy the msi file to a temp file to prevent locking a CD
1203 * with a multi disc install
1205 * FIXME: I think this is wrong, and instead of copying the package,
1206 * we should read all the tables to memory, then open the
1207 * database to read binary streams on demand.
1209 static UINT
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
1211 WCHAR path
[MAX_PATH
];
1213 GetTempPathW( MAX_PATH
, path
);
1214 GetTempFileNameW( path
, szMsi
, 0, filename
);
1216 if( !CopyFileW( szPackage
, filename
, FALSE
) )
1218 UINT error
= GetLastError();
1219 if ( error
== ERROR_FILE_NOT_FOUND
)
1220 ERR("can't find %s\n", debugstr_w(szPackage
));
1222 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage
), debugstr_w(filename
), error
);
1223 DeleteFileW( filename
);
1227 return ERROR_SUCCESS
;
1230 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1232 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1236 /* call will always fail, becase size is 0,
1237 * but will return ERROR_FILE_NOT_FOUND first
1238 * if the file doesn't exist
1240 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1241 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1243 cache_entry
= msi_alloc( size
);
1244 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1246 UINT error
= GetLastError();
1247 msi_free( cache_entry
);
1251 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1252 msi_free( cache_entry
);
1253 return ERROR_SUCCESS
;
1256 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1259 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1260 return ERROR_FUNCTION_FAILED
;
1263 return ERROR_SUCCESS
;
1266 UINT
msi_get_local_package_name( LPWSTR path
, LPCWSTR suffix
)
1268 static const WCHAR szInstaller
[] = {
1269 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1270 static const WCHAR fmt
[] = {'%','x',0};
1271 DWORD time
, len
, i
, offset
;
1274 time
= GetTickCount();
1275 GetWindowsDirectoryW( path
, MAX_PATH
);
1276 strcatW( path
, szInstaller
);
1277 CreateDirectoryW( path
, NULL
);
1279 len
= strlenW(path
);
1280 for (i
= 0; i
< 0x10000; i
++)
1282 offset
= snprintfW( path
+ len
, MAX_PATH
- len
, fmt
, (time
+ i
) & 0xffff );
1283 memcpy( path
+ len
+ offset
, suffix
, (strlenW( suffix
) + 1) * sizeof(WCHAR
) );
1284 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1285 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1286 if (handle
!= INVALID_HANDLE_VALUE
)
1288 CloseHandle(handle
);
1291 if (GetLastError() != ERROR_FILE_EXISTS
&&
1292 GetLastError() != ERROR_SHARING_VIOLATION
)
1293 return ERROR_FUNCTION_FAILED
;
1296 return ERROR_SUCCESS
;
1299 static UINT
msi_parse_summary( MSISUMMARYINFO
*si
, MSIPACKAGE
*package
)
1301 WCHAR
*template, *p
, *q
;
1304 package
->version
= msi_suminfo_get_int32( si
, PID_PAGECOUNT
);
1305 TRACE("version: %d\n", package
->version
);
1307 template = msi_suminfo_dup_string( si
, PID_TEMPLATE
);
1309 return ERROR_SUCCESS
; /* native accepts missing template property */
1311 TRACE("template: %s\n", debugstr_w(template));
1313 p
= strchrW( template, ';' );
1316 WARN("invalid template string %s\n", debugstr_w(template));
1317 msi_free( template );
1318 return ERROR_PATCH_PACKAGE_INVALID
;
1321 if (!template[0] || !strcmpW( template, szIntel
))
1322 package
->platform
= PLATFORM_INTEL
;
1323 else if (!strcmpW( template, szIntel64
))
1324 package
->platform
= PLATFORM_INTEL64
;
1325 else if (!strcmpW( template, szX64
) || !strcmpW( template, szAMD64
))
1326 package
->platform
= PLATFORM_X64
;
1329 WARN("unknown platform %s\n", debugstr_w(template));
1330 msi_free( template );
1331 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1336 msi_free( template );
1337 return ERROR_SUCCESS
;
1340 for (q
= p
; (q
= strchrW( q
, ',' )); q
++) count
++;
1342 package
->langids
= msi_alloc( count
* sizeof(LANGID
) );
1343 if (!package
->langids
)
1345 msi_free( template );
1346 return ERROR_OUTOFMEMORY
;
1352 q
= strchrW( p
, ',' );
1354 package
->langids
[i
] = atoiW( p
);
1359 package
->num_langids
= i
+ 1;
1361 msi_free( template );
1362 return ERROR_SUCCESS
;
1365 static UINT
validate_package( MSIPACKAGE
*package
)
1370 IsWow64Process( GetCurrentProcess(), &is_wow64
);
1371 if (package
->platform
== PLATFORM_X64
)
1373 if (!is_64bit
&& !is_wow64
)
1374 return ERROR_INSTALL_PLATFORM_UNSUPPORTED
;
1375 if (package
->version
< 200)
1376 return ERROR_INSTALL_PACKAGE_INVALID
;
1378 if (!package
->num_langids
)
1380 return ERROR_SUCCESS
;
1382 for (i
= 0; i
< package
->num_langids
; i
++)
1384 LANGID langid
= package
->langids
[i
];
1386 if (PRIMARYLANGID( langid
) == LANG_NEUTRAL
)
1388 langid
= MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid
) );
1390 if (SUBLANGID( langid
) == SUBLANG_NEUTRAL
)
1392 langid
= MAKELANGID( PRIMARYLANGID( langid
), SUBLANGID( GetSystemDefaultLangID() ) );
1394 if (IsValidLocale( langid
, LCID_INSTALLED
))
1395 return ERROR_SUCCESS
;
1397 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED
;
1400 int msi_track_tempfile( MSIPACKAGE
*package
, const WCHAR
*path
)
1404 TRACE("%s\n", debugstr_w(path
));
1406 LIST_FOR_EACH_ENTRY( temp
, &package
->tempfiles
, MSITEMPFILE
, entry
)
1408 if (!strcmpW( path
, temp
->Path
)) return 0;
1410 if (!(temp
= msi_alloc_zero( sizeof (MSITEMPFILE
) ))) return -1;
1411 list_add_head( &package
->tempfiles
, &temp
->entry
);
1412 temp
->Path
= strdupW( path
);
1416 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1418 static const WCHAR dotmsi
[] = {'.','m','s','i',0};
1419 MSIDATABASE
*db
= NULL
;
1420 MSIPACKAGE
*package
;
1422 LPWSTR ptr
, base_url
= NULL
;
1424 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1425 LPCWSTR file
= szPackage
;
1429 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1431 if( szPackage
[0] == '#' )
1433 handle
= atoiW(&szPackage
[1]);
1434 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1437 IWineMsiRemoteDatabase
*remote_database
;
1439 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1440 if ( !remote_database
)
1441 return ERROR_INVALID_HANDLE
;
1443 IWineMsiRemoteDatabase_Release( remote_database
);
1444 WARN("MsiOpenPackage not allowed during a custom action!\n");
1446 return ERROR_FUNCTION_FAILED
;
1451 if ( UrlIsW( szPackage
, URLIS_URL
) )
1453 r
= msi_download_file( szPackage
, cachefile
);
1454 if ( r
!= ERROR_SUCCESS
)
1457 r
= copy_package_to_temp( cachefile
, temppath
);
1458 if ( r
!= ERROR_SUCCESS
)
1463 base_url
= strdupW( szPackage
);
1465 return ERROR_OUTOFMEMORY
;
1467 ptr
= strrchrW( base_url
, '/' );
1468 if (ptr
) *(ptr
+ 1) = '\0';
1472 r
= copy_package_to_temp( szPackage
, temppath
);
1473 if ( r
!= ERROR_SUCCESS
)
1478 TRACE("Opening relocated package %s\n", debugstr_w( file
));
1480 /* transforms that add binary streams require that we open the database
1481 * read/write, which is safe because we always create a copy that is thrown
1482 * away when we're done.
1484 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_TRANSACT
, &db
);
1485 if( r
!= ERROR_SUCCESS
)
1487 if (file
!= szPackage
)
1488 DeleteFileW( file
);
1490 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
1491 return ERROR_FILE_NOT_FOUND
;
1497 r
= msi_get_local_package_name( localfile
, dotmsi
);
1498 if (r
!= ERROR_SUCCESS
)
1501 package
= MSI_CreatePackage( db
, base_url
);
1502 msi_free( base_url
);
1503 msiobj_release( &db
->hdr
);
1506 if (file
!= szPackage
)
1507 DeleteFileW( file
);
1509 return ERROR_INSTALL_PACKAGE_INVALID
;
1511 if (file
!= szPackage
) msi_track_tempfile( package
, file
);
1512 package
->localfile
= strdupW( localfile
);
1514 si
= MSI_GetSummaryInformationW( db
->storage
, 0 );
1517 WARN("failed to load summary info\n");
1518 msiobj_release( &package
->hdr
);
1519 return ERROR_INSTALL_PACKAGE_INVALID
;
1522 r
= msi_parse_summary( si
, package
);
1523 msiobj_release( &si
->hdr
);
1524 if (r
!= ERROR_SUCCESS
)
1526 WARN("failed to parse summary info %u\n", r
);
1527 msiobj_release( &package
->hdr
);
1531 r
= validate_package( package
);
1532 if (r
!= ERROR_SUCCESS
)
1534 msiobj_release( &package
->hdr
);
1537 msi_set_property( package
->db
, szDatabase
, db
->path
);
1539 if( UrlIsW( szPackage
, URLIS_URL
) )
1540 msi_set_property( package
->db
, szOriginalDatabase
, szPackage
);
1541 else if( szPackage
[0] == '#' )
1542 msi_set_property( package
->db
, szOriginalDatabase
, db
->path
);
1545 WCHAR fullpath
[MAX_PATH
];
1547 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1548 msi_set_property( package
->db
, szOriginalDatabase
, fullpath
);
1551 msi_set_context( package
);
1555 WCHAR patch_code
[GUID_SIZE
];
1556 r
= MsiEnumPatchesExW( package
->ProductCode
, NULL
, package
->Context
,
1557 MSIPATCHSTATE_APPLIED
, index
, patch_code
, NULL
, NULL
, NULL
, NULL
);
1558 if (r
!= ERROR_SUCCESS
)
1561 TRACE("found registered patch %s\n", debugstr_w(patch_code
));
1563 r
= msi_apply_registered_patch( package
, patch_code
);
1564 if (r
!= ERROR_SUCCESS
)
1566 ERR("registered patch failed to apply %u\n", r
);
1567 msiobj_release( &package
->hdr
);
1576 msi_clone_properties( package
);
1577 msi_adjust_privilege_properties( package
);
1581 package
->log_file
= CreateFileW( gszLogFile
, GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
,
1582 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1584 *pPackage
= package
;
1585 return ERROR_SUCCESS
;
1588 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1590 MSIPACKAGE
*package
= NULL
;
1593 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1595 if( !szPackage
|| !phPackage
)
1596 return ERROR_INVALID_PARAMETER
;
1600 FIXME("Should create an empty database and package\n");
1601 return ERROR_FUNCTION_FAILED
;
1605 FIXME("dwOptions %08x not supported\n", dwOptions
);
1607 ret
= MSI_OpenPackageW( szPackage
, &package
);
1608 if( ret
== ERROR_SUCCESS
)
1610 *phPackage
= alloc_msihandle( &package
->hdr
);
1612 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1613 msiobj_release( &package
->hdr
);
1619 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1621 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1624 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1626 LPWSTR szwPack
= NULL
;
1631 szwPack
= strdupAtoW( szPackage
);
1633 return ERROR_OUTOFMEMORY
;
1636 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1638 msi_free( szwPack
);
1643 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1645 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1648 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1650 MSIPACKAGE
*package
;
1651 MSIHANDLE handle
= 0;
1652 IUnknown
*remote_unk
;
1653 IWineMsiRemotePackage
*remote_package
;
1655 TRACE("(%d)\n",hInstall
);
1657 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1660 handle
= alloc_msihandle( &package
->db
->hdr
);
1661 msiobj_release( &package
->hdr
);
1663 else if ((remote_unk
= msi_get_remote(hInstall
)))
1665 if (IUnknown_QueryInterface(remote_unk
, &IID_IWineMsiRemotePackage
,
1666 (LPVOID
*)&remote_package
) == S_OK
)
1668 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1669 IWineMsiRemotePackage_Release(remote_package
);
1673 WARN("remote handle %d is not a package\n", hInstall
);
1675 IUnknown_Release(remote_unk
);
1681 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
, MSIRECORD
*record
)
1683 static const WCHAR szActionData
[] =
1684 {'A','c','t','i','o','n','D','a','t','a',0};
1685 static const WCHAR szSetProgress
[] =
1686 {'S','e','t','P','r','o','g','r','e','s','s',0};
1687 static const WCHAR szActionText
[] =
1688 {'A','c','t','i','o','n','T','e','x','t',0};
1690 DWORD i
, len
, total_len
, log_type
= 0;
1694 TRACE("%x\n", eMessageType
);
1696 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1697 log_type
|= INSTALLLOGMODE_ERROR
;
1698 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1699 log_type
|= INSTALLLOGMODE_WARNING
;
1700 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1701 log_type
|= INSTALLLOGMODE_USER
;
1702 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1703 log_type
|= INSTALLLOGMODE_INFO
;
1704 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1705 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1706 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1707 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1708 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1709 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1711 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1714 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1716 static const WCHAR template_s
[]=
1717 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1718 static const WCHAR format
[] =
1719 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1721 LPCWSTR action_text
, action
;
1722 LPWSTR deformatted
= NULL
;
1724 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1726 action
= MSI_RecordGetString(record
, 1);
1727 action_text
= MSI_RecordGetString(record
, 2);
1729 if (!action
|| !action_text
)
1732 deformat_string(package
, action_text
, &deformatted
);
1734 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1736 len
+= strlenW(deformatted
);
1737 message
= msi_alloc(len
*sizeof(WCHAR
));
1738 sprintfW(message
, template_s
, timet
, action
);
1740 strcatW(message
, deformatted
);
1741 msi_free(deformatted
);
1745 static const WCHAR format
[] = {'%','u',':',' ',0};
1746 UINT count
= MSI_RecordGetFieldCount( record
);
1750 for (i
= 1; i
<= count
; i
++)
1753 MSI_RecordGetStringW( record
, i
, NULL
, &len
);
1754 total_len
+= len
+ 13;
1756 p
= message
= msi_alloc( total_len
* sizeof(WCHAR
) );
1757 if (!p
) return ERROR_OUTOFMEMORY
;
1759 for (i
= 1; i
<= count
; i
++)
1763 len
= sprintfW( p
, format
, i
);
1768 MSI_RecordGetStringW( record
, i
, p
, &len
);
1771 if (count
> 1 && total_len
)
1780 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1781 gUIFilter
, log_type
, debugstr_w(message
));
1783 /* convert it to ASCII */
1784 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1785 msg
= msi_alloc( len
);
1786 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1788 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1790 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1792 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1794 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1796 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1798 MSIHANDLE rec
= MsiCreateRecord( 1 );
1799 MsiRecordSetStringW( rec
, 0, message
);
1800 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1801 MsiCloseHandle( rec
);
1804 if (!rc
&& package
->log_file
!= INVALID_HANDLE_VALUE
&&
1805 (eMessageType
& 0xff000000) != INSTALLMESSAGE_PROGRESS
)
1808 WriteFile( package
->log_file
, msg
, len
- 1, &written
, NULL
);
1809 WriteFile( package
->log_file
, "\n", 1, &written
, NULL
);
1812 msi_free( message
);
1814 switch (eMessageType
& 0xff000000)
1816 case INSTALLMESSAGE_ACTIONDATA
:
1817 /* FIXME: format record here instead of in ui_actiondata to get the
1818 * correct action data for external scripts */
1819 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1821 case INSTALLMESSAGE_ACTIONSTART
:
1825 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1827 deformat_string(package
, action_text
, &deformated
);
1828 uirow
= MSI_CreateRecord(1);
1829 MSI_RecordSetStringW(uirow
, 1, deformated
);
1830 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1831 msi_free(deformated
);
1833 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1835 msiobj_release(&uirow
->hdr
);
1838 case INSTALLMESSAGE_PROGRESS
:
1839 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1843 return ERROR_SUCCESS
;
1846 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1849 UINT ret
= ERROR_INVALID_HANDLE
;
1850 MSIPACKAGE
*package
= NULL
;
1851 MSIRECORD
*record
= NULL
;
1853 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1857 IWineMsiRemotePackage
*remote_package
;
1859 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1860 if (!remote_package
)
1861 return ERROR_INVALID_HANDLE
;
1863 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1865 IWineMsiRemotePackage_Release( remote_package
);
1869 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1870 return HRESULT_CODE(hr
);
1872 return ERROR_FUNCTION_FAILED
;
1875 return ERROR_SUCCESS
;
1878 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1882 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1885 msiobj_release( &package
->hdr
);
1887 msiobj_release( &record
->hdr
);
1894 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1896 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1897 UINT r
= ERROR_OUTOFMEMORY
;
1899 szwName
= strdupAtoW( szName
);
1900 if( szName
&& !szwName
)
1903 szwValue
= strdupAtoW( szValue
);
1904 if( szValue
&& !szwValue
)
1907 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1910 msi_free( szwName
);
1911 msi_free( szwValue
);
1916 void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
1920 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
1924 msi_free( folder
->ResolvedSource
);
1925 folder
->ResolvedSource
= NULL
;
1929 msi_free( folder
->ResolvedTarget
);
1930 folder
->ResolvedTarget
= NULL
;
1935 UINT
msi_set_property( MSIDATABASE
*db
, LPCWSTR szName
, LPCWSTR szValue
)
1938 MSIRECORD
*row
= NULL
;
1943 static const WCHAR Insert
[] = {
1944 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1945 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1946 '`','_','P','r','o','p','e','r','t','y','`',',',
1947 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1948 ,' ','(','?',',','?',')',0};
1949 static const WCHAR Update
[] = {
1950 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1951 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1952 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1953 ' ','=',' ','\'','%','s','\'',0};
1954 static const WCHAR Delete
[] = {
1955 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1956 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1957 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1959 TRACE("%p %s %s\n", db
, debugstr_w(szName
), debugstr_w(szValue
));
1962 return ERROR_INVALID_PARAMETER
;
1964 /* this one is weird... */
1966 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1968 rc
= msi_get_property(db
, szName
, 0, &sz
);
1969 if (!szValue
|| !*szValue
)
1971 sprintfW(Query
, Delete
, szName
);
1973 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1975 sprintfW(Query
, Update
, szName
);
1977 row
= MSI_CreateRecord(1);
1978 MSI_RecordSetStringW(row
, 1, szValue
);
1982 strcpyW(Query
, Insert
);
1984 row
= MSI_CreateRecord(2);
1985 MSI_RecordSetStringW(row
, 1, szName
);
1986 MSI_RecordSetStringW(row
, 2, szValue
);
1989 rc
= MSI_DatabaseOpenViewW(db
, Query
, &view
);
1990 if (rc
== ERROR_SUCCESS
)
1992 rc
= MSI_ViewExecute(view
, row
);
1993 MSI_ViewClose(view
);
1994 msiobj_release(&view
->hdr
);
1998 msiobj_release(&row
->hdr
);
2003 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
2005 MSIPACKAGE
*package
;
2008 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
2012 BSTR name
= NULL
, value
= NULL
;
2013 IWineMsiRemotePackage
*remote_package
;
2015 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
2016 if (!remote_package
)
2017 return ERROR_INVALID_HANDLE
;
2019 name
= SysAllocString( szName
);
2020 value
= SysAllocString( szValue
);
2021 if ((!name
&& szName
) || (!value
&& szValue
))
2023 SysFreeString( name
);
2024 SysFreeString( value
);
2025 IWineMsiRemotePackage_Release( remote_package
);
2026 return ERROR_OUTOFMEMORY
;
2029 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
2031 SysFreeString( name
);
2032 SysFreeString( value
);
2033 IWineMsiRemotePackage_Release( remote_package
);
2037 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2038 return HRESULT_CODE(hr
);
2040 return ERROR_FUNCTION_FAILED
;
2043 return ERROR_SUCCESS
;
2046 ret
= msi_set_property( package
->db
, szName
, szValue
);
2047 if (ret
== ERROR_SUCCESS
&& !strcmpW( szName
, szSourceDir
))
2048 msi_reset_folders( package
, TRUE
);
2050 msiobj_release( &package
->hdr
);
2054 static MSIRECORD
*msi_get_property_row( MSIDATABASE
*db
, LPCWSTR name
)
2057 MSIRECORD
*rec
, *row
= NULL
;
2060 static const WCHAR query
[]= {
2061 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2062 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2063 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2066 if (!name
|| !*name
)
2069 rec
= MSI_CreateRecord(1);
2073 MSI_RecordSetStringW(rec
, 1, name
);
2075 r
= MSI_DatabaseOpenViewW(db
, query
, &view
);
2076 if (r
== ERROR_SUCCESS
)
2078 MSI_ViewExecute(view
, rec
);
2079 MSI_ViewFetch(view
, &row
);
2080 MSI_ViewClose(view
);
2081 msiobj_release(&view
->hdr
);
2084 msiobj_release(&rec
->hdr
);
2088 /* internal function, not compatible with MsiGetPropertyW */
2089 UINT
msi_get_property( MSIDATABASE
*db
, LPCWSTR szName
,
2090 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2093 UINT rc
= ERROR_FUNCTION_FAILED
;
2095 row
= msi_get_property_row( db
, szName
);
2097 if (*pchValueBuf
> 0)
2102 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
2103 msiobj_release(&row
->hdr
);
2106 if (rc
== ERROR_SUCCESS
)
2107 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
2108 debugstr_w(szName
));
2109 else if (rc
== ERROR_MORE_DATA
)
2110 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
2111 debugstr_w(szName
));
2115 TRACE("property %s not found\n", debugstr_w(szName
));
2121 LPWSTR
msi_dup_property(MSIDATABASE
*db
, LPCWSTR prop
)
2127 r
= msi_get_property(db
, prop
, NULL
, &sz
);
2128 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
2132 str
= msi_alloc(sz
* sizeof(WCHAR
));
2133 r
= msi_get_property(db
, prop
, str
, &sz
);
2134 if (r
!= ERROR_SUCCESS
)
2143 int msi_get_property_int( MSIDATABASE
*db
, LPCWSTR prop
, int def
)
2145 LPWSTR str
= msi_dup_property( db
, prop
);
2146 int val
= str
? atoiW(str
) : def
;
2151 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
2152 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
2154 MSIPACKAGE
*package
;
2155 MSIRECORD
*row
= NULL
;
2156 UINT r
= ERROR_FUNCTION_FAILED
;
2159 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
2160 szValueBuf
->str
.w
, pchValueBuf
);
2163 return ERROR_INVALID_PARAMETER
;
2165 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
2169 IWineMsiRemotePackage
*remote_package
;
2170 LPWSTR value
= NULL
;
2174 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
2175 if (!remote_package
)
2176 return ERROR_INVALID_HANDLE
;
2178 bname
= SysAllocString( name
);
2181 IWineMsiRemotePackage_Release( remote_package
);
2182 return ERROR_OUTOFMEMORY
;
2186 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
2191 value
= msi_alloc(len
* sizeof(WCHAR
));
2194 r
= ERROR_OUTOFMEMORY
;
2198 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, value
, &len
);
2202 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
2204 /* Bug required by Adobe installers */
2205 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
2206 *pchValueBuf
*= sizeof(WCHAR
);
2209 IWineMsiRemotePackage_Release(remote_package
);
2210 SysFreeString(bname
);
2215 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
2216 return HRESULT_CODE(hr
);
2218 return ERROR_FUNCTION_FAILED
;
2224 row
= msi_get_property_row( package
->db
, name
);
2226 val
= MSI_RecordGetString( row
, 1 );
2231 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
2234 msiobj_release( &row
->hdr
);
2235 msiobj_release( &package
->hdr
);
2240 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
2241 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
2247 val
.unicode
= FALSE
;
2248 val
.str
.a
= szValueBuf
;
2250 name
= strdupAtoW( szName
);
2251 if (szName
&& !name
)
2252 return ERROR_OUTOFMEMORY
;
2254 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
2259 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
2260 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
2265 val
.str
.w
= szValueBuf
;
2267 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
2270 typedef struct _msi_remote_package_impl
{
2271 IWineMsiRemotePackage IWineMsiRemotePackage_iface
;
2274 } msi_remote_package_impl
;
2276 static inline msi_remote_package_impl
*impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage
*iface
)
2278 return CONTAINING_RECORD(iface
, msi_remote_package_impl
, IWineMsiRemotePackage_iface
);
2281 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
2282 REFIID riid
,LPVOID
*ppobj
)
2284 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
2285 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
2287 IUnknown_AddRef( iface
);
2292 return E_NOINTERFACE
;
2295 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2297 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2299 return InterlockedIncrement( &This
->refs
);
2302 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2304 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2307 r
= InterlockedDecrement( &This
->refs
);
2310 MsiCloseHandle( This
->package
);
2316 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2318 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2319 This
->package
= handle
;
2323 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2325 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2326 IWineMsiRemoteDatabase
*rdb
= NULL
;
2330 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2331 if (FAILED(hr
) || !rdb
)
2333 ERR("Failed to create remote database\n");
2337 hdb
= MsiGetActiveDatabase(This
->package
);
2339 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2342 ERR("Failed to set the database handle\n");
2346 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2350 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
, DWORD
*size
)
2352 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2353 UINT r
= MsiGetPropertyW(This
->package
, property
, value
, size
);
2354 if (r
!= ERROR_SUCCESS
) return HRESULT_FROM_WIN32(r
);
2358 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2360 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2361 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2362 return HRESULT_FROM_WIN32(r
);
2365 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2367 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2368 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2369 return HRESULT_FROM_WIN32(r
);
2372 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2374 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2375 UINT r
= MsiDoActionW(This
->package
, action
);
2376 return HRESULT_FROM_WIN32(r
);
2379 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2381 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2382 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2383 return HRESULT_FROM_WIN32(r
);
2386 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2388 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2389 UINT r
= MsiGetTargetPathW(This
->package
, folder
, value
, size
);
2390 return HRESULT_FROM_WIN32(r
);
2393 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2395 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2396 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2397 return HRESULT_FROM_WIN32(r
);
2400 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
, DWORD
*size
)
2402 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2403 UINT r
= MsiGetSourcePathW(This
->package
, folder
, value
, size
);
2404 return HRESULT_FROM_WIN32(r
);
2407 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2409 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2410 *ret
= MsiGetMode(This
->package
, mode
);
2414 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2416 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2417 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2418 return HRESULT_FROM_WIN32(r
);
2421 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2422 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2424 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2425 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2426 return HRESULT_FROM_WIN32(r
);
2429 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2431 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2432 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2433 return HRESULT_FROM_WIN32(r
);
2436 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2437 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2439 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2440 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2441 return HRESULT_FROM_WIN32(r
);
2444 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2446 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2447 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2448 return HRESULT_FROM_WIN32(r
);
2451 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2453 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2454 *language
= MsiGetLanguage(This
->package
);
2458 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2460 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2461 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2462 return HRESULT_FROM_WIN32(r
);
2465 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2469 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2470 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2471 if (r
== ERROR_SUCCESS
)
2473 *value
= SysAllocStringLen(NULL
, size
);
2475 return E_OUTOFMEMORY
;
2477 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2479 return HRESULT_FROM_WIN32(r
);
2482 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2484 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2485 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2486 return HRESULT_FROM_WIN32(r
);
2489 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2490 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2492 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2493 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2494 return HRESULT_FROM_WIN32(r
);
2497 static HRESULT WINAPI
mrp_EnumComponentCosts( IWineMsiRemotePackage
*iface
, BSTR component
,
2498 DWORD index
, INSTALLSTATE state
, BSTR drive
,
2499 DWORD
*buflen
, INT
*cost
, INT
*temp
)
2501 msi_remote_package_impl
* This
= impl_from_IWineMsiRemotePackage( iface
);
2502 UINT r
= MsiEnumComponentCostsW(This
->package
, component
, index
, state
, drive
, buflen
, cost
, temp
);
2503 return HRESULT_FROM_WIN32(r
);
2506 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2512 mrp_GetActiveDatabase
,
2523 mrp_GetFeatureState
,
2524 mrp_SetFeatureState
,
2525 mrp_GetComponentState
,
2526 mrp_SetComponentState
,
2528 mrp_SetInstallLevel
,
2530 mrp_EvaluateCondition
,
2532 mrp_EnumComponentCosts
2535 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2537 msi_remote_package_impl
* This
;
2539 This
= msi_alloc( sizeof *This
);
2541 return E_OUTOFMEMORY
;
2543 This
->IWineMsiRemotePackage_iface
.lpVtbl
= &msi_remote_package_vtbl
;
2552 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2553 LPCWSTR property
, LPWSTR value
)
2555 MSISOURCELISTINFO
*info
;
2557 LIST_FOR_EACH_ENTRY( info
, &package
->sourcelist_info
, MSISOURCELISTINFO
, entry
)
2559 if (!strcmpW( info
->value
, value
)) return ERROR_SUCCESS
;
2562 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2564 return ERROR_OUTOFMEMORY
;
2566 info
->context
= context
;
2567 info
->options
= options
;
2568 info
->property
= property
;
2569 info
->value
= strdupW(value
);
2570 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2572 return ERROR_SUCCESS
;
2575 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2576 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2580 LIST_FOR_EACH_ENTRY( disk
, &package
->sourcelist_media
, MSIMEDIADISK
, entry
)
2582 if (disk
->disk_id
== disk_id
) return ERROR_SUCCESS
;
2585 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2587 return ERROR_OUTOFMEMORY
;
2589 disk
->context
= context
;
2590 disk
->options
= options
;
2591 disk
->disk_id
= disk_id
;
2592 disk
->volume_label
= strdupW(volume_label
);
2593 disk
->disk_prompt
= strdupW(disk_prompt
);
2594 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2596 return ERROR_SUCCESS
;