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 if (!DeleteFileW( temp
->Path
))
63 ERR("failed to delete %s\n", debugstr_w( temp
->Path
));
64 msi_free( temp
->Path
);
69 static void free_feature( MSIFEATURE
*feature
)
71 struct list
*item
, *cursor
;
73 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Children
)
75 FeatureList
*fl
= LIST_ENTRY( item
, FeatureList
, entry
);
76 list_remove( &fl
->entry
);
80 LIST_FOR_EACH_SAFE( item
, cursor
, &feature
->Components
)
82 ComponentList
*cl
= LIST_ENTRY( item
, ComponentList
, entry
);
83 list_remove( &cl
->entry
);
86 msi_free( feature
->Feature
);
87 msi_free( feature
->Feature_Parent
);
88 msi_free( feature
->Directory
);
89 msi_free( feature
->Description
);
90 msi_free( feature
->Title
);
94 static void free_extension( MSIEXTENSION
*ext
)
96 struct list
*item
, *cursor
;
98 LIST_FOR_EACH_SAFE( item
, cursor
, &ext
->verbs
)
100 MSIVERB
*verb
= LIST_ENTRY( item
, MSIVERB
, entry
);
102 list_remove( &verb
->entry
);
103 msi_free( verb
->Verb
);
104 msi_free( verb
->Command
);
105 msi_free( verb
->Argument
);
109 msi_free( ext
->Extension
);
110 msi_free( ext
->ProgIDText
);
114 static void free_package_structures( MSIPACKAGE
*package
)
117 struct list
*item
, *cursor
;
119 TRACE("Freeing package action data\n");
121 remove_tracked_tempfiles(package
);
123 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->features
)
125 MSIFEATURE
*feature
= LIST_ENTRY( item
, MSIFEATURE
, entry
);
126 list_remove( &feature
->entry
);
127 free_feature( feature
);
130 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->folders
)
132 MSIFOLDER
*folder
= LIST_ENTRY( item
, MSIFOLDER
, entry
);
134 list_remove( &folder
->entry
);
135 msi_free( folder
->Parent
);
136 msi_free( folder
->Directory
);
137 msi_free( folder
->TargetDefault
);
138 msi_free( folder
->SourceLongPath
);
139 msi_free( folder
->SourceShortPath
);
140 msi_free( folder
->ResolvedTarget
);
141 msi_free( folder
->ResolvedSource
);
142 msi_free( folder
->Property
);
146 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->components
)
148 MSICOMPONENT
*comp
= LIST_ENTRY( item
, MSICOMPONENT
, entry
);
150 list_remove( &comp
->entry
);
151 msi_free( comp
->Component
);
152 msi_free( comp
->ComponentId
);
153 msi_free( comp
->Directory
);
154 msi_free( comp
->Condition
);
155 msi_free( comp
->KeyPath
);
156 msi_free( comp
->FullKeypath
);
160 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->files
)
162 MSIFILE
*file
= LIST_ENTRY( item
, MSIFILE
, entry
);
164 list_remove( &file
->entry
);
165 msi_free( file
->File
);
166 msi_free( file
->FileName
);
167 msi_free( file
->ShortName
);
168 msi_free( file
->LongName
);
169 msi_free( file
->Version
);
170 msi_free( file
->Language
);
171 msi_free( file
->TargetPath
);
175 /* clean up extension, progid, class and verb structures */
176 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->classes
)
178 MSICLASS
*cls
= LIST_ENTRY( item
, MSICLASS
, entry
);
180 list_remove( &cls
->entry
);
181 msi_free( cls
->clsid
);
182 msi_free( cls
->Context
);
183 msi_free( cls
->Description
);
184 msi_free( cls
->FileTypeMask
);
185 msi_free( cls
->IconPath
);
186 msi_free( cls
->DefInprocHandler
);
187 msi_free( cls
->DefInprocHandler32
);
188 msi_free( cls
->Argument
);
189 msi_free( cls
->ProgIDText
);
193 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->extensions
)
195 MSIEXTENSION
*ext
= LIST_ENTRY( item
, MSIEXTENSION
, entry
);
197 list_remove( &ext
->entry
);
198 free_extension( ext
);
201 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->progids
)
203 MSIPROGID
*progid
= LIST_ENTRY( item
, MSIPROGID
, entry
);
205 list_remove( &progid
->entry
);
206 msi_free( progid
->ProgID
);
207 msi_free( progid
->Description
);
208 msi_free( progid
->IconPath
);
212 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->mimes
)
214 MSIMIME
*mt
= LIST_ENTRY( item
, MSIMIME
, entry
);
216 list_remove( &mt
->entry
);
217 msi_free( mt
->clsid
);
218 msi_free( mt
->ContentType
);
222 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->appids
)
224 MSIAPPID
*appid
= LIST_ENTRY( item
, MSIAPPID
, entry
);
226 list_remove( &appid
->entry
);
227 msi_free( appid
->AppID
);
228 msi_free( appid
->RemoteServerName
);
229 msi_free( appid
->LocalServer
);
230 msi_free( appid
->ServiceParameters
);
231 msi_free( appid
->DllSurrogate
);
235 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_info
)
237 MSISOURCELISTINFO
*info
= LIST_ENTRY( item
, MSISOURCELISTINFO
, entry
);
239 list_remove( &info
->entry
);
240 msi_free( info
->value
);
244 LIST_FOR_EACH_SAFE( item
, cursor
, &package
->sourcelist_media
)
246 MSIMEDIADISK
*info
= LIST_ENTRY( item
, MSIMEDIADISK
, entry
);
248 list_remove( &info
->entry
);
249 msi_free( info
->volume_label
);
250 msi_free( info
->disk_prompt
);
256 for (i
= 0; i
< TOTAL_SCRIPTS
; i
++)
257 msi_free_action_script( package
, i
);
259 for (i
= 0; i
< package
->script
->UniqueActionsCount
; i
++)
260 msi_free( package
->script
->UniqueActions
[i
] );
262 msi_free( package
->script
->UniqueActions
);
263 msi_free( package
->script
);
268 msi_free( package
->patch
->patchcode
);
269 msi_free( package
->patch
->transforms
);
270 msi_free( package
->patch
);
273 msi_free( package
->BaseURL
);
274 msi_free( package
->PackagePath
);
275 msi_free( package
->ProductCode
);
276 msi_free( package
->ActionFormat
);
277 msi_free( package
->LastAction
);
279 /* cleanup control event subscriptions */
280 ControlEvent_CleanupSubscriptions( package
);
283 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
285 MSIPACKAGE
*package
= (MSIPACKAGE
*) arg
;
287 if( package
->dialog
)
288 msi_dialog_destroy( package
->dialog
);
290 msiobj_release( &package
->db
->hdr
);
291 free_package_structures(package
);
294 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
296 MSIQUERY
*view
= NULL
;
299 static const WCHAR CreateSql
[] = {
300 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
301 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
302 '`','_','P','r','o','p','e','r','t','y','`',' ',
303 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
304 'T','E','M','P','O','R','A','R','Y',',',' ',
305 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
306 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
307 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
308 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
310 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &view
);
311 if (rc
!= ERROR_SUCCESS
)
314 rc
= MSI_ViewExecute(view
, 0);
316 msiobj_release(&view
->hdr
);
320 UINT
msi_clone_properties(MSIPACKAGE
*package
)
322 MSIQUERY
*view
= NULL
;
325 static const WCHAR Query
[] = {
326 'S','E','L','E','C','T',' ','*',' ',
327 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
328 static const WCHAR Insert
[] = {
329 'I','N','S','E','R','T',' ','i','n','t','o',' ',
330 '`','_','P','r','o','p','e','r','t','y','`',' ',
331 '(','`','_','P','r','o','p','e','r','t','y','`',',',
332 '`','V','a','l','u','e','`',')',' ',
333 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
335 /* clone the existing properties */
336 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
337 if (rc
!= ERROR_SUCCESS
)
340 rc
= MSI_ViewExecute(view
, 0);
341 if (rc
!= ERROR_SUCCESS
)
344 msiobj_release(&view
->hdr
);
353 rc
= MSI_ViewFetch(view
, &row
);
354 if (rc
!= ERROR_SUCCESS
)
357 rc
= MSI_DatabaseOpenViewW(package
->db
, Insert
, &view2
);
358 if (rc
!= ERROR_SUCCESS
)
360 msiobj_release(&row
->hdr
);
364 MSI_ViewExecute(view2
, row
);
365 MSI_ViewClose(view2
);
366 msiobj_release(&view2
->hdr
);
367 msiobj_release(&row
->hdr
);
371 msiobj_release(&view
->hdr
);
379 * Sets the "Installed" property to indicate that
380 * the product is installed for the current user.
382 static UINT
set_installed_prop( MSIPACKAGE
*package
)
387 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, &hkey
, FALSE
);
388 if (r
== ERROR_SUCCESS
)
391 MSI_SetPropertyW( package
, szInstalled
, szOne
);
397 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
401 LPWSTR sid_str
= NULL
, dom
= NULL
;
402 DWORD size
, dom_size
;
404 UINT r
= ERROR_FUNCTION_FAILED
;
407 GetUserNameW( NULL
, &size
);
409 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
411 return ERROR_OUTOFMEMORY
;
413 if (!GetUserNameW( user_name
, &size
))
418 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
420 psid
= msi_alloc( size
);
421 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
424 r
= ERROR_OUTOFMEMORY
;
428 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
431 if (!ConvertSidToStringSidW( psid
, &sid_str
))
434 r
= MSI_SetPropertyW( package
, szUserSID
, sid_str
);
437 LocalFree( sid_str
);
440 msi_free( user_name
);
445 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
450 DWORD index
= 0, size
;
452 WCHAR name
[MAX_PATH
];
453 WCHAR windir
[MAX_PATH
];
455 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
456 static const WCHAR sub
[] = {
457 'S','o','f','t','w','a','r','e','\\',
458 'M','i','c','r','o','s','o','f','t','\\',
459 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
462 static const WCHAR subdir
[] = {
463 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
464 'F','r','a','m','e','w','o','r','k','\\',0
467 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
468 if (res
!= ERROR_SUCCESS
)
471 GetWindowsDirectoryW(windir
, MAX_PATH
);
475 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
479 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
480 if (lstrcmpW(ver
, name
) < 0)
483 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
484 check
= msi_alloc(size
* sizeof(WCHAR
));
492 lstrcpyW(check
, windir
);
493 lstrcatW(check
, szBackSlash
);
494 lstrcatW(check
, subdir
);
495 lstrcatW(check
, name
);
496 lstrcatW(check
, szBackSlash
);
497 lstrcatW(check
, fusion
);
499 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
510 RegCloseKey(netsetup
);
514 typedef struct tagLANGANDCODEPAGE
520 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
524 LPVOID version
= NULL
;
526 LPWSTR fusion
, verstr
;
527 LANGANDCODEPAGE
*translate
;
529 static const WCHAR netasm
[] = {
530 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
532 static const WCHAR translation
[] = {
533 '\\','V','a','r','F','i','l','e','I','n','f','o',
534 '\\','T','r','a','n','s','l','a','t','i','o','n',0
536 static const WCHAR verfmt
[] = {
537 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
538 '\\','%','0','4','x','%','0','4','x',
539 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
542 fusion
= get_fusion_filename(package
);
546 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
549 version
= msi_alloc(size
);
550 if (!version
) return;
552 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
555 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
558 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
560 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
563 if (!val_len
|| !verstr
)
566 MSI_SetPropertyW(package
, netasm
, verstr
);
573 static VOID
set_installer_properties(MSIPACKAGE
*package
)
577 OSVERSIONINFOEXW OSVersion
;
580 WCHAR verstr
[10], bufstr
[20];
583 LPWSTR username
, companyname
;
584 SYSTEM_INFO sys_info
;
585 SYSTEMTIME systemtime
;
588 static const WCHAR CFF
[] =
589 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
590 static const WCHAR PFF
[] =
591 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
592 static const WCHAR CADF
[] =
593 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
594 static const WCHAR FaF
[] =
595 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
596 static const WCHAR FoF
[] =
597 {'F','o','n','t','s','F','o','l','d','e','r',0};
598 static const WCHAR SendTF
[] =
599 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
600 static const WCHAR SMF
[] =
601 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
602 static const WCHAR StF
[] =
603 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
604 static const WCHAR TemplF
[] =
605 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
606 static const WCHAR DF
[] =
607 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
608 static const WCHAR PMF
[] =
609 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
610 static const WCHAR ATF
[] =
611 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
612 static const WCHAR ADF
[] =
613 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
614 static const WCHAR SF
[] =
615 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
616 static const WCHAR SF16
[] =
617 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
618 static const WCHAR LADF
[] =
619 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
620 static const WCHAR MPF
[] =
621 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
622 static const WCHAR PF
[] =
623 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
624 static const WCHAR WF
[] =
625 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
626 static const WCHAR WV
[] =
627 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
628 static const WCHAR TF
[]=
629 {'T','e','m','p','F','o','l','d','e','r',0};
630 static const WCHAR szAdminUser
[] =
631 {'A','d','m','i','n','U','s','e','r',0};
632 static const WCHAR szPriv
[] =
633 {'P','r','i','v','i','l','e','g','e','d',0};
634 static const WCHAR v9x
[] = { 'V','e','r','s','i','o','n','9','X',0 };
635 static const WCHAR vNT
[] = { 'V','e','r','s','i','o','n','N','T',0 };
636 static const WCHAR szMsiNTProductType
[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
637 static const WCHAR szFormat
[] = {'%','l','i',0};
638 static const WCHAR szWinBuild
[] =
639 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
640 static const WCHAR szSPL
[] =
641 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
642 static const WCHAR szSix
[] = {'6',0 };
644 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
645 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
646 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
647 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
648 /* Screen properties */
649 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
650 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
651 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
652 static const WCHAR szIntFormat
[] = {'%','d',0};
653 static const WCHAR szIntel
[] = { 'I','n','t','e','l',0 };
654 static const WCHAR szUserInfo
[] = {
655 'S','O','F','T','W','A','R','E','\\',
656 'M','i','c','r','o','s','o','f','t','\\',
657 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
658 'U','s','e','r',' ','I','n','f','o',0
660 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
661 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
662 static const WCHAR szCurrentVersion
[] = {
663 'S','O','F','T','W','A','R','E','\\',
664 'M','i','c','r','o','s','o','f','t','\\',
665 'W','i','n','d','o','w','s',' ','N','T','\\',
666 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
668 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
669 static const WCHAR szRegisteredOrg
[] = {
670 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
672 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
673 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
674 static const WCHAR szDate
[] = {'D','a','t','e',0};
675 static const WCHAR szTime
[] = {'T','i','m','e',0};
676 static const WCHAR szUserLangID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
677 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
678 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
679 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
682 * Other things that probably should be set:
684 * ComputerName VirtualMemory
685 * ShellAdvSupport DefaultUIFont PackagecodeChanging
686 * CaptionHeight BorderTop BorderSide TextHeight
687 * RedirectedDllSupport
690 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
691 strcatW(pth
, szBackSlash
);
692 MSI_SetPropertyW(package
, CFF
, pth
);
694 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
695 strcatW(pth
, szBackSlash
);
696 MSI_SetPropertyW(package
, PFF
, pth
);
698 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
699 strcatW(pth
, szBackSlash
);
700 MSI_SetPropertyW(package
, CADF
, pth
);
702 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
703 strcatW(pth
, szBackSlash
);
704 MSI_SetPropertyW(package
, FaF
, pth
);
706 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
707 strcatW(pth
, szBackSlash
);
708 MSI_SetPropertyW(package
, FoF
, pth
);
710 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
711 strcatW(pth
, szBackSlash
);
712 MSI_SetPropertyW(package
, SendTF
, pth
);
714 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
715 strcatW(pth
, szBackSlash
);
716 MSI_SetPropertyW(package
, SMF
, pth
);
718 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
719 strcatW(pth
, szBackSlash
);
720 MSI_SetPropertyW(package
, StF
, pth
);
722 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
723 strcatW(pth
, szBackSlash
);
724 MSI_SetPropertyW(package
, TemplF
, pth
);
726 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
727 strcatW(pth
, szBackSlash
);
728 MSI_SetPropertyW(package
, DF
, pth
);
730 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
731 strcatW(pth
, szBackSlash
);
732 MSI_SetPropertyW(package
, PMF
, pth
);
734 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
735 strcatW(pth
, szBackSlash
);
736 MSI_SetPropertyW(package
, ATF
, pth
);
738 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
739 strcatW(pth
, szBackSlash
);
740 MSI_SetPropertyW(package
, ADF
, pth
);
742 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
743 strcatW(pth
, szBackSlash
);
744 MSI_SetPropertyW(package
, SF
, pth
);
745 MSI_SetPropertyW(package
, SF16
, pth
);
747 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
748 strcatW(pth
, szBackSlash
);
749 MSI_SetPropertyW(package
, LADF
, pth
);
751 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
752 strcatW(pth
, szBackSlash
);
753 MSI_SetPropertyW(package
, MPF
, pth
);
755 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
756 strcatW(pth
, szBackSlash
);
757 MSI_SetPropertyW(package
, PF
, pth
);
759 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
760 strcatW(pth
, szBackSlash
);
761 MSI_SetPropertyW(package
, WF
, pth
);
763 /* Physical Memory is specified in MB. Using total amount. */
764 msex
.dwLength
= sizeof(msex
);
765 GlobalMemoryStatusEx( &msex
);
766 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
767 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
769 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
770 ptr
= strchrW(pth
,'\\');
773 MSI_SetPropertyW(package
, WV
, pth
);
775 GetTempPathW(MAX_PATH
,pth
);
776 MSI_SetPropertyW(package
, TF
, pth
);
779 /* in a wine environment the user is always admin and privileged */
780 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
781 MSI_SetPropertyW(package
,szPriv
,szOne
);
783 /* set the os things */
784 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
785 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
786 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
787 sprintfW(verstr
,szFormat
,verval
);
788 switch (OSVersion
.dwPlatformId
)
790 case VER_PLATFORM_WIN32_WINDOWS
:
791 MSI_SetPropertyW(package
,v9x
,verstr
);
793 case VER_PLATFORM_WIN32_NT
:
794 MSI_SetPropertyW(package
,vNT
,verstr
);
795 sprintfW(verstr
,szFormat
,OSVersion
.wProductType
);
796 MSI_SetPropertyW(package
,szMsiNTProductType
,verstr
);
799 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
800 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
801 /* just fudge this */
802 MSI_SetPropertyW(package
,szSPL
,szSix
);
804 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
805 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
806 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
807 MSI_SetPropertyW( package
, szVersionDatabase
, bufstr
);
809 GetSystemInfo( &sys_info
);
810 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
812 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
813 MSI_SetPropertyW( package
, szIntel
, bufstr
);
816 /* Screen properties. */
818 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
819 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
820 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
821 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
822 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
823 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
826 /* USERNAME and COMPANYNAME */
827 username
= msi_dup_property( package
, szUSERNAME
);
828 companyname
= msi_dup_property( package
, szCOMPANYNAME
);
830 if ((!username
|| !companyname
) &&
831 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
834 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
835 MSI_SetPropertyW( package
, szUSERNAME
, username
);
837 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
838 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
841 if ((!username
|| !companyname
) &&
842 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
845 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
846 MSI_SetPropertyW( package
, szUSERNAME
, username
);
848 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrg
)))
849 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
852 msi_free( username
);
853 msi_free( companyname
);
855 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
856 ERR("Failed to set the UserSID property\n");
858 /* Date and time properties */
859 GetSystemTime( &systemtime
);
860 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
861 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
862 MSI_SetPropertyW( package
, szDate
, bufstr
);
864 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
866 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
867 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
868 &systemtime
, NULL
, bufstr
,
869 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
870 MSI_SetPropertyW( package
, szTime
, bufstr
);
872 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
874 set_msi_assembly_prop( package
);
876 langid
= GetUserDefaultLangID();
877 sprintfW(bufstr
, szIntFormat
, langid
);
879 MSI_SetPropertyW( package
, szUserLangID
, bufstr
);
881 langid
= GetSystemDefaultLangID();
882 sprintfW(bufstr
, szIntFormat
, langid
);
884 MSI_SetPropertyW( package
, szSystemLangID
, bufstr
);
886 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
887 MSI_SetPropertyW( package
, szProductState
, bufstr
);
890 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_MORE_DATA
)
893 if ((username
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
895 if (GetUserNameW( username
, &len
))
896 MSI_SetPropertyW( package
, szLogonUser
, username
);
897 HeapFree( GetProcessHeap(), 0, username
);
902 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
906 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
910 static const WCHAR szPackageCode
[] = {
911 'P','a','c','k','a','g','e','C','o','d','e',0};
914 ERR("Unable to allocate handle\n");
915 return ERROR_OUTOFMEMORY
;
918 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
920 if (rc
!= ERROR_SUCCESS
)
922 ERR("Unable to open Summary Information\n");
926 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
927 &count
, NULL
, NULL
, NULL
);
928 if (rc
!= ERROR_SUCCESS
)
930 WARN("Unable to query page count: %d\n", rc
);
934 /* load package code property */
936 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
937 NULL
, NULL
, NULL
, &len
);
938 if (rc
!= ERROR_MORE_DATA
)
940 WARN("Unable to query revision number: %d\n", rc
);
941 rc
= ERROR_FUNCTION_FAILED
;
946 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
947 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
948 NULL
, NULL
, package_code
, &len
);
949 if (rc
!= ERROR_SUCCESS
)
951 WARN("Unable to query rev number: %d\n", rc
);
955 MSI_SetPropertyW( package
, szPackageCode
, package_code
);
956 msi_free( package_code
);
958 /* load package attributes */
960 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
961 &count
, NULL
, NULL
, NULL
);
962 package
->WordCount
= count
;
965 MsiCloseHandle(suminfo
);
969 static MSIPACKAGE
*msi_alloc_package( void )
973 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
977 list_init( &package
->components
);
978 list_init( &package
->features
);
979 list_init( &package
->files
);
980 list_init( &package
->tempfiles
);
981 list_init( &package
->folders
);
982 list_init( &package
->subscriptions
);
983 list_init( &package
->appids
);
984 list_init( &package
->classes
);
985 list_init( &package
->mimes
);
986 list_init( &package
->extensions
);
987 list_init( &package
->progids
);
988 list_init( &package
->RunningActions
);
989 list_init( &package
->sourcelist_info
);
990 list_init( &package
->sourcelist_media
);
996 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
1001 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1003 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
1004 if (r
!= ERROR_SUCCESS
)
1007 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
1013 static void adjust_allusers_property( MSIPACKAGE
*package
)
1015 /* FIXME: this should depend on the user's privileges */
1016 if (msi_get_property_int( package
, szAllUsers
, 0 ) == 2)
1018 TRACE("resetting ALLUSERS property from 2 to 1\n");
1019 MSI_SetPropertyW( package
, szAllUsers
, szOne
);
1023 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
1025 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
1026 static const WCHAR szpi
[] = {'%','i',0};
1027 MSIPACKAGE
*package
;
1033 package
= msi_alloc_package();
1036 msiobj_addref( &db
->hdr
);
1039 package
->WordCount
= 0;
1040 package
->PackagePath
= strdupW( db
->path
);
1041 package
->BaseURL
= strdupW( base_url
);
1043 create_temp_property_table( package
);
1044 msi_clone_properties( package
);
1046 package
->ProductCode
= msi_dup_property( package
, szProductCode
);
1047 set_installed_prop( package
);
1048 set_installer_properties( package
);
1050 sprintfW(uilevel
,szpi
,gUILevel
);
1051 MSI_SetPropertyW(package
, szLevel
, uilevel
);
1053 r
= msi_load_summary_properties( package
);
1054 if (r
!= ERROR_SUCCESS
)
1056 msiobj_release( &package
->hdr
);
1060 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
1061 msi_load_admin_properties( package
);
1063 adjust_allusers_property( package
);
1070 * copy_package_to_temp [internal]
1072 * copy the msi file to a temp file to prevent locking a CD
1073 * with a multi disc install
1075 * FIXME: I think this is wrong, and instead of copying the package,
1076 * we should read all the tables to memory, then open the
1077 * database to read binary streams on demand.
1079 static UINT
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
1081 WCHAR path
[MAX_PATH
];
1083 GetTempPathW( MAX_PATH
, path
);
1084 GetTempFileNameW( path
, szMsi
, 0, filename
);
1086 if( !CopyFileW( szPackage
, filename
, FALSE
) )
1088 UINT error
= GetLastError();
1089 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage
), debugstr_w(filename
), error
);
1090 DeleteFileW( filename
);
1094 return ERROR_SUCCESS
;
1097 UINT
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
1099 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
1103 /* call will always fail, becase size is 0,
1104 * but will return ERROR_FILE_NOT_FOUND first
1105 * if the file doesn't exist
1107 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
1108 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
1110 cache_entry
= HeapAlloc( GetProcessHeap(), 0, size
);
1111 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
1113 UINT error
= GetLastError();
1114 HeapFree( GetProcessHeap(), 0, cache_entry
);
1118 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
1119 HeapFree( GetProcessHeap(), 0, cache_entry
);
1120 return ERROR_SUCCESS
;
1123 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
1126 WARN("failed to download %s to cache file\n", debugstr_w(szUrl
));
1127 return ERROR_FUNCTION_FAILED
;
1130 return ERROR_SUCCESS
;
1133 static UINT
msi_get_local_package_name( LPWSTR path
)
1135 static const WCHAR szInstaller
[] = {
1136 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1137 static const WCHAR fmt
[] = { '%','x','.','m','s','i',0};
1141 time
= GetTickCount();
1142 GetWindowsDirectoryW( path
, MAX_PATH
);
1143 strcatW( path
, szInstaller
);
1144 CreateDirectoryW( path
, NULL
);
1146 len
= strlenW(path
);
1147 for (i
= 0; i
< 0x10000; i
++)
1149 snprintfW( &path
[len
], MAX_PATH
- len
, fmt
, (time
+ i
)&0xffff );
1150 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
1151 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
1152 if (handle
!= INVALID_HANDLE_VALUE
)
1154 CloseHandle(handle
);
1157 if (GetLastError() != ERROR_FILE_EXISTS
&&
1158 GetLastError() != ERROR_SHARING_VIOLATION
)
1159 return ERROR_FUNCTION_FAILED
;
1162 return ERROR_SUCCESS
;
1165 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
1167 static const WCHAR OriginalDatabase
[] =
1168 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
1169 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
1170 MSIDATABASE
*db
= NULL
;
1171 MSIPACKAGE
*package
;
1173 LPWSTR ptr
, base_url
= NULL
;
1175 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
], cachefile
[MAX_PATH
];
1176 LPCWSTR file
= szPackage
;
1178 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
1180 if( szPackage
[0] == '#' )
1182 handle
= atoiW(&szPackage
[1]);
1183 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
1186 IWineMsiRemoteDatabase
*remote_database
;
1188 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
1189 if ( !remote_database
)
1190 return ERROR_INVALID_HANDLE
;
1192 IWineMsiRemoteDatabase_Release( remote_database
);
1193 WARN("MsiOpenPackage not allowed during a custom action!\n");
1195 return ERROR_FUNCTION_FAILED
;
1200 if ( UrlIsW( szPackage
, URLIS_URL
) )
1202 r
= msi_download_file( szPackage
, cachefile
);
1203 if ( r
!= ERROR_SUCCESS
)
1206 r
= copy_package_to_temp( cachefile
, temppath
);
1207 if ( r
!= ERROR_SUCCESS
)
1212 base_url
= strdupW( szPackage
);
1214 return ERROR_OUTOFMEMORY
;
1216 ptr
= strrchrW( base_url
, '/' );
1217 if (ptr
) *(ptr
+ 1) = '\0';
1221 r
= copy_package_to_temp( szPackage
, temppath
);
1222 if ( r
!= ERROR_SUCCESS
)
1228 r
= msi_get_local_package_name( localfile
);
1229 if (r
!= ERROR_SUCCESS
)
1232 TRACE("Copying to local package %s\n", debugstr_w(localfile
));
1234 if (!CopyFileW( file
, localfile
, FALSE
))
1236 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1237 debugstr_w(file
), debugstr_w(localfile
), GetLastError());
1238 return GetLastError();
1241 TRACE("Opening relocated package %s\n", debugstr_w( file
));
1243 /* transforms that add binary streams require that we open the database
1244 * read/write, which is safe because we always create a copy that is thrown
1245 * away when we're done.
1247 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_DIRECT
, &db
);
1248 if( r
!= ERROR_SUCCESS
)
1250 if (file
!= szPackage
)
1251 DeleteFileW( file
);
1253 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
1254 return ERROR_FILE_NOT_FOUND
;
1259 db
->localfile
= strdupW( localfile
);
1262 package
= MSI_CreatePackage( db
, base_url
);
1263 msi_free( base_url
);
1264 msiobj_release( &db
->hdr
);
1267 if (file
!= szPackage
)
1268 DeleteFileW( file
);
1270 return ERROR_INSTALL_PACKAGE_INVALID
;
1273 if( file
!= szPackage
)
1274 track_tempfile( package
, file
);
1276 MSI_SetPropertyW( package
, Database
, db
->path
);
1278 if( UrlIsW( szPackage
, URLIS_URL
) )
1279 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
1280 else if( szPackage
[0] == '#' )
1281 MSI_SetPropertyW( package
, OriginalDatabase
, db
->path
);
1284 WCHAR fullpath
[MAX_PATH
];
1286 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1287 MSI_SetPropertyW( package
, OriginalDatabase
, fullpath
);
1290 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1291 *pPackage
= package
;
1293 return ERROR_SUCCESS
;
1296 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1298 MSIPACKAGE
*package
= NULL
;
1301 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1303 if( !szPackage
|| !phPackage
)
1304 return ERROR_INVALID_PARAMETER
;
1308 FIXME("Should create an empty database and package\n");
1309 return ERROR_FUNCTION_FAILED
;
1313 FIXME("dwOptions %08x not supported\n", dwOptions
);
1315 ret
= MSI_OpenPackageW( szPackage
, &package
);
1316 if( ret
== ERROR_SUCCESS
)
1318 *phPackage
= alloc_msihandle( &package
->hdr
);
1320 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1321 msiobj_release( &package
->hdr
);
1327 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1329 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1332 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1334 LPWSTR szwPack
= NULL
;
1339 szwPack
= strdupAtoW( szPackage
);
1341 return ERROR_OUTOFMEMORY
;
1344 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1346 msi_free( szwPack
);
1351 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1353 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1356 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1358 MSIPACKAGE
*package
;
1359 MSIHANDLE handle
= 0;
1360 IWineMsiRemotePackage
*remote_package
;
1362 TRACE("(%d)\n",hInstall
);
1364 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1367 handle
= alloc_msihandle( &package
->db
->hdr
);
1368 msiobj_release( &package
->hdr
);
1370 else if ((remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
)))
1372 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1373 IWineMsiRemotePackage_Release(remote_package
);
1379 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1382 static const WCHAR szActionData
[] =
1383 {'A','c','t','i','o','n','D','a','t','a',0};
1384 static const WCHAR szSetProgress
[] =
1385 {'S','e','t','P','r','o','g','r','e','s','s',0};
1386 static const WCHAR szActionText
[] =
1387 {'A','c','t','i','o','n','T','e','x','t',0};
1391 DWORD total_size
= 0;
1397 TRACE("%x\n", eMessageType
);
1400 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1401 log_type
|= INSTALLLOGMODE_ERROR
;
1402 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1403 log_type
|= INSTALLLOGMODE_WARNING
;
1404 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1405 log_type
|= INSTALLLOGMODE_USER
;
1406 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1407 log_type
|= INSTALLLOGMODE_INFO
;
1408 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1409 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1410 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1411 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1412 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1413 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1415 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1418 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1420 static const WCHAR template_s
[]=
1421 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1422 static const WCHAR format
[] =
1423 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1425 LPCWSTR action_text
, action
;
1426 LPWSTR deformatted
= NULL
;
1428 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1430 action
= MSI_RecordGetString(record
, 1);
1431 action_text
= MSI_RecordGetString(record
, 2);
1433 if (!action
|| !action_text
)
1436 deformat_string(package
, action_text
, &deformatted
);
1438 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1440 len
+= strlenW(deformatted
);
1441 message
= msi_alloc(len
*sizeof(WCHAR
));
1442 sprintfW(message
, template_s
, timet
, action
);
1444 strcatW(message
, deformatted
);
1445 msi_free(deformatted
);
1450 message
= msi_alloc(1*sizeof (WCHAR
));
1452 msg_field
= MSI_RecordGetFieldCount(record
);
1453 for (i
= 1; i
<= msg_field
; i
++)
1457 static const WCHAR format
[] = { '%','i',':',' ',0};
1459 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1461 total_size
+=sz
*sizeof(WCHAR
);
1462 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1463 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1465 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1469 sprintfW(number
,format
,i
);
1470 strcatW(message
,number
);
1472 strcatW(message
,tmp
);
1474 strcatW(message
, szSpace
);
1480 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1481 gUIFilter
, log_type
, debugstr_w(message
));
1483 /* convert it to ASCII */
1484 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1485 msg
= msi_alloc( len
);
1486 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1488 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1490 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1492 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1494 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1496 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1498 MSIHANDLE rec
= MsiCreateRecord( 1 );
1499 MsiRecordSetStringW( rec
, 0, message
);
1500 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1501 MsiCloseHandle( rec
);
1504 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
1505 INSTALLMESSAGE_PROGRESS
))
1508 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
1509 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1511 if (log_file
!= INVALID_HANDLE_VALUE
)
1513 SetFilePointer(log_file
,0, NULL
, FILE_END
);
1514 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
1515 WriteFile(log_file
,"\n",1,&write
,NULL
);
1516 CloseHandle(log_file
);
1520 msi_free( message
);
1522 switch (eMessageType
& 0xff000000)
1524 case INSTALLMESSAGE_ACTIONDATA
:
1525 /* FIXME: format record here instead of in ui_actiondata to get the
1526 * correct action data for external scripts */
1527 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1529 case INSTALLMESSAGE_ACTIONSTART
:
1533 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1535 deformat_string(package
, action_text
, &deformated
);
1536 uirow
= MSI_CreateRecord(1);
1537 MSI_RecordSetStringW(uirow
, 1, deformated
);
1538 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1539 msi_free(deformated
);
1541 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1543 msiobj_release(&uirow
->hdr
);
1546 case INSTALLMESSAGE_PROGRESS
:
1547 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1551 return ERROR_SUCCESS
;
1554 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1557 UINT ret
= ERROR_INVALID_HANDLE
;
1558 MSIPACKAGE
*package
= NULL
;
1559 MSIRECORD
*record
= NULL
;
1561 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1565 IWineMsiRemotePackage
*remote_package
;
1567 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1568 if (!remote_package
)
1569 return ERROR_INVALID_HANDLE
;
1571 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1573 IWineMsiRemotePackage_Release( remote_package
);
1577 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1578 return HRESULT_CODE(hr
);
1580 return ERROR_FUNCTION_FAILED
;
1583 return ERROR_SUCCESS
;
1586 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1590 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1593 msiobj_release( &package
->hdr
);
1595 msiobj_release( &record
->hdr
);
1602 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1604 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1605 UINT r
= ERROR_OUTOFMEMORY
;
1607 szwName
= strdupAtoW( szName
);
1608 if( szName
&& !szwName
)
1611 szwValue
= strdupAtoW( szValue
);
1612 if( szValue
&& !szwValue
)
1615 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1618 msi_free( szwName
);
1619 msi_free( szwValue
);
1624 static void msi_reset_folders( MSIPACKAGE
*package
, BOOL source
)
1628 LIST_FOR_EACH_ENTRY( folder
, &package
->folders
, MSIFOLDER
, entry
)
1632 msi_free( folder
->ResolvedSource
);
1633 folder
->ResolvedSource
= NULL
;
1637 msi_free( folder
->ResolvedTarget
);
1638 folder
->ResolvedTarget
= NULL
;
1643 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
1646 MSIRECORD
*row
= NULL
;
1651 static const WCHAR Insert
[] = {
1652 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1653 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1654 '`','_','P','r','o','p','e','r','t','y','`',',',
1655 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1656 ,' ','(','?',',','?',')',0};
1657 static const WCHAR Update
[] = {
1658 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1659 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1660 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1661 ' ','=',' ','\'','%','s','\'',0};
1662 static const WCHAR Delete
[] = {
1663 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1664 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1665 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1667 TRACE("%p %s %s\n", package
, debugstr_w(szName
), debugstr_w(szValue
));
1670 return ERROR_INVALID_PARAMETER
;
1672 /* this one is weird... */
1674 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1676 rc
= MSI_GetPropertyW(package
, szName
, 0, &sz
);
1677 if (!szValue
|| !*szValue
)
1679 sprintfW(Query
, Delete
, szName
);
1681 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1683 sprintfW(Query
, Update
, szName
);
1685 row
= MSI_CreateRecord(1);
1686 MSI_RecordSetStringW(row
, 1, szValue
);
1690 strcpyW(Query
, Insert
);
1692 row
= MSI_CreateRecord(2);
1693 MSI_RecordSetStringW(row
, 1, szName
);
1694 MSI_RecordSetStringW(row
, 2, szValue
);
1697 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1698 if (rc
== ERROR_SUCCESS
)
1700 rc
= MSI_ViewExecute(view
, row
);
1701 MSI_ViewClose(view
);
1702 msiobj_release(&view
->hdr
);
1706 msiobj_release(&row
->hdr
);
1708 if (rc
== ERROR_SUCCESS
&& (!lstrcmpW(szName
, cszSourceDir
)))
1709 msi_reset_folders(package
, TRUE
);
1714 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1716 MSIPACKAGE
*package
;
1719 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1723 BSTR name
= NULL
, value
= NULL
;
1724 IWineMsiRemotePackage
*remote_package
;
1726 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1727 if (!remote_package
)
1728 return ERROR_INVALID_HANDLE
;
1730 name
= SysAllocString( szName
);
1731 value
= SysAllocString( szValue
);
1732 if ((!name
&& szName
) || (!value
&& szValue
))
1734 SysFreeString( name
);
1735 SysFreeString( value
);
1736 IWineMsiRemotePackage_Release( remote_package
);
1737 return ERROR_OUTOFMEMORY
;
1740 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
1742 SysFreeString( name
);
1743 SysFreeString( value
);
1744 IWineMsiRemotePackage_Release( remote_package
);
1748 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1749 return HRESULT_CODE(hr
);
1751 return ERROR_FUNCTION_FAILED
;
1754 return ERROR_SUCCESS
;
1757 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
1758 msiobj_release( &package
->hdr
);
1762 static MSIRECORD
*MSI_GetPropertyRow( MSIPACKAGE
*package
, LPCWSTR name
)
1765 MSIRECORD
*rec
, *row
= NULL
;
1768 static const WCHAR query
[]= {
1769 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1770 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1771 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1774 if (!name
|| !*name
)
1777 rec
= MSI_CreateRecord(1);
1781 MSI_RecordSetStringW(rec
, 1, name
);
1783 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1784 if (r
== ERROR_SUCCESS
)
1786 MSI_ViewExecute(view
, rec
);
1787 MSI_ViewFetch(view
, &row
);
1788 MSI_ViewClose(view
);
1789 msiobj_release(&view
->hdr
);
1792 msiobj_release(&rec
->hdr
);
1796 /* internal function, not compatible with MsiGetPropertyW */
1797 UINT
MSI_GetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
,
1798 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1801 UINT rc
= ERROR_FUNCTION_FAILED
;
1803 row
= MSI_GetPropertyRow( package
, szName
);
1805 if (*pchValueBuf
> 0)
1810 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
1811 msiobj_release(&row
->hdr
);
1814 if (rc
== ERROR_SUCCESS
)
1815 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
1816 debugstr_w(szName
));
1817 else if (rc
== ERROR_MORE_DATA
)
1818 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
1819 debugstr_w(szName
));
1823 TRACE("property %s not found\n", debugstr_w(szName
));
1829 LPWSTR
msi_dup_property(MSIPACKAGE
*package
, LPCWSTR prop
)
1835 r
= MSI_GetPropertyW(package
, prop
, NULL
, &sz
);
1836 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1840 str
= msi_alloc(sz
* sizeof(WCHAR
));
1841 r
= MSI_GetPropertyW(package
, prop
, str
, &sz
);
1842 if (r
!= ERROR_SUCCESS
)
1851 int msi_get_property_int(MSIPACKAGE
*package
, LPCWSTR prop
, int def
)
1853 LPWSTR str
= msi_dup_property(package
, prop
);
1854 int val
= str
? atoiW(str
) : def
;
1859 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
1860 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
1862 MSIPACKAGE
*package
;
1863 MSIRECORD
*row
= NULL
;
1864 UINT r
= ERROR_FUNCTION_FAILED
;
1867 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
1868 szValueBuf
->str
.w
, pchValueBuf
);
1871 return ERROR_INVALID_PARAMETER
;
1873 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
1877 IWineMsiRemotePackage
*remote_package
;
1878 LPWSTR value
= NULL
;
1882 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
1883 if (!remote_package
)
1884 return ERROR_INVALID_HANDLE
;
1886 bname
= SysAllocString( name
);
1889 IWineMsiRemotePackage_Release( remote_package
);
1890 return ERROR_OUTOFMEMORY
;
1894 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
1899 value
= msi_alloc(len
* sizeof(WCHAR
));
1902 r
= ERROR_OUTOFMEMORY
;
1906 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
1910 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
1912 /* Bug required by Adobe installers */
1913 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
1914 *pchValueBuf
*= sizeof(WCHAR
);
1917 IWineMsiRemotePackage_Release(remote_package
);
1918 SysFreeString(bname
);
1923 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1924 return HRESULT_CODE(hr
);
1926 return ERROR_FUNCTION_FAILED
;
1932 row
= MSI_GetPropertyRow( package
, name
);
1934 val
= MSI_RecordGetString( row
, 1 );
1939 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
1942 msiobj_release( &row
->hdr
);
1943 msiobj_release( &package
->hdr
);
1948 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
1949 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
1955 val
.unicode
= FALSE
;
1956 val
.str
.a
= szValueBuf
;
1958 name
= strdupAtoW( szName
);
1959 if (szName
&& !name
)
1960 return ERROR_OUTOFMEMORY
;
1962 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
1967 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
1968 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1973 val
.str
.w
= szValueBuf
;
1975 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
1978 typedef struct _msi_remote_package_impl
{
1979 const IWineMsiRemotePackageVtbl
*lpVtbl
;
1982 } msi_remote_package_impl
;
1984 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
1986 return (msi_remote_package_impl
*) iface
;
1989 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
1990 REFIID riid
,LPVOID
*ppobj
)
1992 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
1993 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
1995 IUnknown_AddRef( iface
);
2000 return E_NOINTERFACE
;
2003 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
2005 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2007 return InterlockedIncrement( &This
->refs
);
2010 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
2012 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2015 r
= InterlockedDecrement( &This
->refs
);
2018 MsiCloseHandle( This
->package
);
2024 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
2026 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2027 This
->package
= handle
;
2031 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
2033 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2034 IWineMsiRemoteDatabase
*rdb
= NULL
;
2038 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
2039 if (FAILED(hr
) || !rdb
)
2041 ERR("Failed to create remote database\n");
2045 hdb
= MsiGetActiveDatabase(This
->package
);
2047 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
2050 ERR("Failed to set the database handle\n");
2054 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
2058 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
2060 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2063 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
2064 if (r
!= ERROR_SUCCESS
)
2065 return HRESULT_FROM_WIN32(r
);
2070 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
2072 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2073 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
2074 return HRESULT_FROM_WIN32(r
);
2077 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
2079 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2080 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
2081 return HRESULT_FROM_WIN32(r
);
2084 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
2086 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2087 UINT r
= MsiDoActionW(This
->package
, action
);
2088 return HRESULT_FROM_WIN32(r
);
2091 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
2093 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2094 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
2095 return HRESULT_FROM_WIN32(r
);
2098 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2100 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2101 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2102 return HRESULT_FROM_WIN32(r
);
2105 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
2107 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2108 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
2109 return HRESULT_FROM_WIN32(r
);
2112 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
2114 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2115 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
2116 return HRESULT_FROM_WIN32(r
);
2119 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
2121 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2122 *ret
= MsiGetMode(This
->package
, mode
);
2126 static HRESULT WINAPI
mrp_SetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL state
)
2128 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2129 UINT r
= MsiSetMode(This
->package
, mode
, state
);
2130 return HRESULT_FROM_WIN32(r
);
2133 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
2134 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2136 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2137 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
2138 return HRESULT_FROM_WIN32(r
);
2141 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
2143 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2144 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
2145 return HRESULT_FROM_WIN32(r
);
2148 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
2149 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
2151 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2152 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
2153 return HRESULT_FROM_WIN32(r
);
2156 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
2158 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2159 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
2160 return HRESULT_FROM_WIN32(r
);
2163 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
2165 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2166 *language
= MsiGetLanguage(This
->package
);
2170 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
2172 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2173 UINT r
= MsiSetInstallLevel(This
->package
, level
);
2174 return HRESULT_FROM_WIN32(r
);
2177 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
2181 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2182 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
2183 if (r
== ERROR_SUCCESS
)
2185 *value
= SysAllocStringLen(NULL
, size
);
2187 return E_OUTOFMEMORY
;
2189 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
2191 return HRESULT_FROM_WIN32(r
);
2194 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
2196 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2197 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
2198 return HRESULT_FROM_WIN32(r
);
2201 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
2202 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
2204 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
2205 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
2206 return HRESULT_FROM_WIN32(r
);
2209 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
2215 mrp_GetActiveDatabase
,
2226 mrp_GetFeatureState
,
2227 mrp_SetFeatureState
,
2228 mrp_GetComponentState
,
2229 mrp_SetComponentState
,
2231 mrp_SetInstallLevel
,
2233 mrp_EvaluateCondition
,
2237 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
2239 msi_remote_package_impl
* This
;
2241 This
= msi_alloc( sizeof *This
);
2243 return E_OUTOFMEMORY
;
2245 This
->lpVtbl
= &msi_remote_package_vtbl
;
2254 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2255 LPCWSTR property
, LPWSTR value
)
2257 MSISOURCELISTINFO
*info
;
2259 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
2261 return ERROR_OUTOFMEMORY
;
2263 info
->context
= context
;
2264 info
->options
= options
;
2265 info
->property
= property
;
2266 info
->value
= strdupW(value
);
2267 list_add_head(&package
->sourcelist_info
, &info
->entry
);
2269 return ERROR_SUCCESS
;
2272 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
2273 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
2277 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
2279 return ERROR_OUTOFMEMORY
;
2281 disk
->context
= context
;
2282 disk
->options
= options
;
2283 disk
->disk_id
= disk_id
;
2284 disk
->volume_label
= strdupW(volume_label
);
2285 disk
->disk_prompt
= strdupW(disk_prompt
);
2286 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2288 return ERROR_SUCCESS
;