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 MSI_FreePackage( MSIOBJECTHDR
*arg
)
54 MSIPACKAGE
*package
= (MSIPACKAGE
*) arg
;
57 msi_dialog_destroy( package
->dialog
);
59 msiobj_release( &package
->db
->hdr
);
60 ACTION_free_package_structures(package
);
63 static UINT
create_temp_property_table(MSIPACKAGE
*package
)
65 MSIQUERY
*view
= NULL
;
68 static const WCHAR CreateSql
[] = {
69 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
70 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
71 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
72 'L','L',' ','T','E','M','P','O','R','A','R','Y',',',' ','`','V','a','l',
73 'u','e','`',' ','C','H','A','R','(','9','8',')',' ','N','O','T',' ','N',
74 'U','L','L',' ','T','E','M','P','O','R','A','R','Y',' ','P','R','I','M',
75 'A','R','Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y',
78 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &view
);
79 if (rc
!= ERROR_SUCCESS
)
82 rc
= MSI_ViewExecute(view
, 0);
84 msiobj_release(&view
->hdr
);
88 UINT
msi_clone_properties(MSIPACKAGE
*package
)
90 MSIQUERY
*view
= NULL
;
93 static const WCHAR Query
[] = {
94 'S','E','L','E','C','T',' ','*',' ',
95 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
96 static const WCHAR Insert
[] = {
97 'I','N','S','E','R','T',' ','i','n','t','o',' ',
98 '`','_','P','r','o','p','e','r','t','y','`',' ',
99 '(','`','_','P','r','o','p','e','r','t','y','`',',',
100 '`','V','a','l','u','e','`',')',' ',
101 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
103 /* clone the existing properties */
104 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
105 if (rc
!= ERROR_SUCCESS
)
108 rc
= MSI_ViewExecute(view
, 0);
109 if (rc
!= ERROR_SUCCESS
)
112 msiobj_release(&view
->hdr
);
121 rc
= MSI_ViewFetch(view
, &row
);
122 if (rc
!= ERROR_SUCCESS
)
125 rc
= MSI_DatabaseOpenViewW(package
->db
, Insert
, &view2
);
126 if (rc
!= ERROR_SUCCESS
)
128 msiobj_release(&row
->hdr
);
132 MSI_ViewExecute(view2
, row
);
133 MSI_ViewClose(view2
);
134 msiobj_release(&view2
->hdr
);
135 msiobj_release(&row
->hdr
);
139 msiobj_release(&view
->hdr
);
147 * Sets the "Installed" property to indicate that
148 * the product is installed for the current user.
150 static UINT
set_installed_prop( MSIPACKAGE
*package
)
152 static const WCHAR szInstalled
[] = {
153 'I','n','s','t','a','l','l','e','d',0 };
154 WCHAR val
[2] = { '1', 0 };
158 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, &hkey
, FALSE
);
159 if (r
== ERROR_SUCCESS
)
162 MSI_SetPropertyW( package
, szInstalled
, val
);
168 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
172 LPWSTR sid_str
= NULL
, dom
= NULL
;
173 DWORD size
, dom_size
;
175 UINT r
= ERROR_FUNCTION_FAILED
;
177 static const WCHAR user_sid
[] = {'U','s','e','r','S','I','D',0};
180 GetUserNameW( NULL
, &size
);
182 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
184 return ERROR_OUTOFMEMORY
;
186 if (!GetUserNameW( user_name
, &size
))
191 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
193 psid
= msi_alloc( size
);
194 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
197 r
= ERROR_OUTOFMEMORY
;
201 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
204 if (!ConvertSidToStringSidW( psid
, &sid_str
))
207 r
= MSI_SetPropertyW( package
, user_sid
, sid_str
);
210 LocalFree( sid_str
);
213 msi_free( user_name
);
218 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
223 DWORD index
= 0, size
;
225 WCHAR name
[MAX_PATH
];
226 WCHAR windir
[MAX_PATH
];
228 static const WCHAR backslash
[] = {'\\',0};
229 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
230 static const WCHAR sub
[] = {
231 'S','o','f','t','w','a','r','e','\\',
232 'M','i','c','r','o','s','o','f','t','\\',
233 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
236 static const WCHAR subdir
[] = {
237 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
238 'F','r','a','m','e','w','o','r','k','\\',0
241 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
242 if (res
!= ERROR_SUCCESS
)
247 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
250 if (lstrcmpW(ver
, name
) < 0)
254 RegCloseKey(netsetup
);
259 GetWindowsDirectoryW(windir
, MAX_PATH
);
261 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(ver
) +lstrlenW(fusion
) + 3;
262 file
= msi_alloc(size
* sizeof(WCHAR
));
266 lstrcpyW(file
, windir
);
267 lstrcatW(file
, backslash
);
268 lstrcatW(file
, subdir
);
270 lstrcatW(file
, backslash
);
271 lstrcatW(file
, fusion
);
276 typedef struct tagLANGANDCODEPAGE
282 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
286 LPVOID version
= NULL
;
288 LPWSTR fusion
, verstr
;
289 LANGANDCODEPAGE
*translate
;
291 static const WCHAR netasm
[] = {
292 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
294 static const WCHAR translation
[] = {
295 '\\','V','a','r','F','i','l','e','I','n','f','o',
296 '\\','T','r','a','n','s','l','a','t','i','o','n',0
298 static const WCHAR verfmt
[] = {
299 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
300 '\\','%','0','4','x','%','0','4','x',
301 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
304 fusion
= get_fusion_filename(package
);
308 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
311 version
= msi_alloc(size
);
312 if (!version
) return;
314 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
317 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
320 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
322 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
325 if (!val_len
|| !verstr
)
328 MSI_SetPropertyW(package
, netasm
, verstr
);
335 static VOID
set_installer_properties(MSIPACKAGE
*package
)
339 OSVERSIONINFOEXW OSVersion
;
342 WCHAR verstr
[10], bufstr
[20];
345 LPWSTR username
, companyname
;
346 SYSTEM_INFO sys_info
;
347 SYSTEMTIME systemtime
;
350 static const WCHAR cszbs
[]={'\\',0};
351 static const WCHAR CFF
[] =
352 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
353 static const WCHAR PFF
[] =
354 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
355 static const WCHAR CADF
[] =
356 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
357 static const WCHAR FaF
[] =
358 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
359 static const WCHAR FoF
[] =
360 {'F','o','n','t','s','F','o','l','d','e','r',0};
361 static const WCHAR SendTF
[] =
362 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
363 static const WCHAR SMF
[] =
364 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
365 static const WCHAR StF
[] =
366 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
367 static const WCHAR TemplF
[] =
368 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
369 static const WCHAR DF
[] =
370 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
371 static const WCHAR PMF
[] =
372 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
373 static const WCHAR ATF
[] =
374 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
375 static const WCHAR ADF
[] =
376 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
377 static const WCHAR SF
[] =
378 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
379 static const WCHAR SF16
[] =
380 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
381 static const WCHAR LADF
[] =
382 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
383 static const WCHAR MPF
[] =
384 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
385 static const WCHAR PF
[] =
386 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
387 static const WCHAR WF
[] =
388 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
389 static const WCHAR WV
[] =
390 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
391 static const WCHAR TF
[]=
392 {'T','e','m','p','F','o','l','d','e','r',0};
393 static const WCHAR szAdminUser
[] =
394 {'A','d','m','i','n','U','s','e','r',0};
395 static const WCHAR szPriv
[] =
396 {'P','r','i','v','i','l','e','g','e','d',0};
397 static const WCHAR szOne
[] =
399 static const WCHAR v9x
[] = { 'V','e','r','s','i','o','n','9','X',0 };
400 static const WCHAR vNT
[] = { 'V','e','r','s','i','o','n','N','T',0 };
401 static const WCHAR szMsiNTProductType
[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
402 static const WCHAR szFormat
[] = {'%','l','i',0};
403 static const WCHAR szWinBuild
[] =
404 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
405 static const WCHAR szSPL
[] =
406 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
407 static const WCHAR szSix
[] = {'6',0 };
409 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
410 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
411 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
412 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
413 /* Screen properties */
414 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
415 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
416 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
417 static const WCHAR szIntFormat
[] = {'%','d',0};
418 static const WCHAR szIntel
[] = { 'I','n','t','e','l',0 };
419 static const WCHAR szUserInfo
[] = {
420 'S','O','F','T','W','A','R','E','\\',
421 'M','i','c','r','o','s','o','f','t','\\',
422 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
423 'U','s','e','r',' ','I','n','f','o',0
425 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
426 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
427 static const WCHAR szCurrentVersion
[] = {
428 'S','O','F','T','W','A','R','E','\\',
429 'M','i','c','r','o','s','o','f','t','\\',
430 'W','i','n','d','o','w','s',' ','N','T','\\',
431 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
433 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
434 static const WCHAR szRegisteredOrg
[] = {
435 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
437 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
438 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
439 static const WCHAR szDate
[] = {'D','a','t','e',0};
440 static const WCHAR szTime
[] = {'T','i','m','e',0};
441 static const WCHAR szUserLangID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
444 * Other things that probably should be set:
446 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
447 * ShellAdvSupport DefaultUIFont PackagecodeChanging
448 * ProductState CaptionHeight BorderTop BorderSide TextHeight
449 * RedirectedDllSupport
452 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
454 MSI_SetPropertyW(package
, CFF
, pth
);
456 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
458 MSI_SetPropertyW(package
, PFF
, pth
);
460 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
462 MSI_SetPropertyW(package
, CADF
, pth
);
464 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
466 MSI_SetPropertyW(package
, FaF
, pth
);
468 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
470 MSI_SetPropertyW(package
, FoF
, pth
);
472 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
474 MSI_SetPropertyW(package
, SendTF
, pth
);
476 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
478 MSI_SetPropertyW(package
, SMF
, pth
);
480 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
482 MSI_SetPropertyW(package
, StF
, pth
);
484 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
486 MSI_SetPropertyW(package
, TemplF
, pth
);
488 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
490 MSI_SetPropertyW(package
, DF
, pth
);
492 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
494 MSI_SetPropertyW(package
, PMF
, pth
);
496 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
498 MSI_SetPropertyW(package
, ATF
, pth
);
500 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
502 MSI_SetPropertyW(package
, ADF
, pth
);
504 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
506 MSI_SetPropertyW(package
, SF
, pth
);
507 MSI_SetPropertyW(package
, SF16
, pth
);
509 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
511 MSI_SetPropertyW(package
, LADF
, pth
);
513 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
515 MSI_SetPropertyW(package
, MPF
, pth
);
517 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
519 MSI_SetPropertyW(package
, PF
, pth
);
521 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
523 MSI_SetPropertyW(package
, WF
, pth
);
525 /* Physical Memory is specified in MB. Using total amount. */
526 msex
.dwLength
= sizeof(msex
);
527 GlobalMemoryStatusEx( &msex
);
528 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
529 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
531 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
532 ptr
= strchrW(pth
,'\\');
535 MSI_SetPropertyW(package
, WV
, pth
);
537 GetTempPathW(MAX_PATH
,pth
);
538 MSI_SetPropertyW(package
, TF
, pth
);
541 /* in a wine environment the user is always admin and privileged */
542 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
543 MSI_SetPropertyW(package
,szPriv
,szOne
);
545 /* set the os things */
546 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
547 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
548 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
549 sprintfW(verstr
,szFormat
,verval
);
550 switch (OSVersion
.dwPlatformId
)
552 case VER_PLATFORM_WIN32_WINDOWS
:
553 MSI_SetPropertyW(package
,v9x
,verstr
);
555 case VER_PLATFORM_WIN32_NT
:
556 MSI_SetPropertyW(package
,vNT
,verstr
);
557 sprintfW(verstr
,szFormat
,OSVersion
.wProductType
);
558 MSI_SetPropertyW(package
,szMsiNTProductType
,verstr
);
561 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
562 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
563 /* just fudge this */
564 MSI_SetPropertyW(package
,szSPL
,szSix
);
566 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
567 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
568 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
569 MSI_SetPropertyW( package
, szVersionDatabase
, bufstr
);
571 GetSystemInfo( &sys_info
);
572 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
574 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
575 MSI_SetPropertyW( package
, szIntel
, bufstr
);
578 /* Screen properties. */
580 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
581 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
582 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
583 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
584 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
585 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
588 /* USERNAME and COMPANYNAME */
589 username
= msi_dup_property( package
, szUSERNAME
);
590 companyname
= msi_dup_property( package
, szCOMPANYNAME
);
592 if ((!username
|| !companyname
) &&
593 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
596 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
597 MSI_SetPropertyW( package
, szUSERNAME
, username
);
599 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
600 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
603 if ((!username
|| !companyname
) &&
604 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
607 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
608 MSI_SetPropertyW( package
, szUSERNAME
, username
);
610 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrg
)))
611 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
614 msi_free( username
);
615 msi_free( companyname
);
617 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
618 ERR("Failed to set the UserSID property\n");
620 /* Date and time properties */
621 GetSystemTime( &systemtime
);
622 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
623 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
624 MSI_SetPropertyW( package
, szDate
, bufstr
);
626 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
628 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
629 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
630 &systemtime
, NULL
, bufstr
,
631 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
632 MSI_SetPropertyW( package
, szTime
, bufstr
);
634 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
636 set_msi_assembly_prop( package
);
638 langid
= GetUserDefaultLangID();
639 sprintfW(bufstr
, szIntFormat
, langid
);
641 MSI_SetPropertyW( package
, szUserLangID
, bufstr
);
644 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
648 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
652 static const WCHAR szPackageCode
[] = {
653 'P','a','c','k','a','g','e','C','o','d','e',0};
656 ERR("Unable to allocate handle\n");
657 return ERROR_OUTOFMEMORY
;
660 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
662 if (rc
!= ERROR_SUCCESS
)
664 ERR("Unable to open Summary Information\n");
668 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
669 &count
, NULL
, NULL
, NULL
);
670 if (rc
!= ERROR_SUCCESS
)
672 WARN("Unable to query page count: %d\n", rc
);
676 /* load package code property */
678 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
679 NULL
, NULL
, NULL
, &len
);
680 if (rc
!= ERROR_MORE_DATA
)
682 WARN("Unable to query revision number: %d\n", rc
);
683 rc
= ERROR_FUNCTION_FAILED
;
688 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
689 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
690 NULL
, NULL
, package_code
, &len
);
691 if (rc
!= ERROR_SUCCESS
)
693 WARN("Unable to query rev number: %d\n", rc
);
697 MSI_SetPropertyW( package
, szPackageCode
, package_code
);
698 msi_free( package_code
);
700 /* load package attributes */
702 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
703 &count
, NULL
, NULL
, NULL
);
704 package
->WordCount
= count
;
707 MsiCloseHandle(suminfo
);
711 static MSIPACKAGE
*msi_alloc_package( void )
715 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
719 list_init( &package
->components
);
720 list_init( &package
->features
);
721 list_init( &package
->files
);
722 list_init( &package
->tempfiles
);
723 list_init( &package
->folders
);
724 list_init( &package
->subscriptions
);
725 list_init( &package
->appids
);
726 list_init( &package
->classes
);
727 list_init( &package
->mimes
);
728 list_init( &package
->extensions
);
729 list_init( &package
->progids
);
730 list_init( &package
->RunningActions
);
731 list_init( &package
->sourcelist_info
);
732 list_init( &package
->sourcelist_media
);
734 package
->ActionFormat
= NULL
;
735 package
->LastAction
= NULL
;
736 package
->dialog
= NULL
;
737 package
->next_dialog
= NULL
;
738 package
->scheduled_action_running
= FALSE
;
739 package
->commit_action_running
= FALSE
;
740 package
->rollback_action_running
= FALSE
;
746 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
751 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
753 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
754 if (r
!= ERROR_SUCCESS
)
757 r
= msi_parse_command_line(package
, (WCHAR
*)data
);
763 static UINT
msi_set_context(MSIPACKAGE
*package
)
770 static const WCHAR szOne
[] = {'1',0};
771 static const WCHAR szAllUsers
[] = {'A','L','L','U','S','E','R','S',0};
773 package
->Context
= MSIINSTALLCONTEXT_USERUNMANAGED
;
775 r
= MSI_GetPropertyW(package
, szAllUsers
, val
, &sz
);
776 if (r
== ERROR_SUCCESS
)
779 if (num
== 1 || num
== 2)
780 package
->Context
= MSIINSTALLCONTEXT_MACHINE
;
783 MSI_SetPropertyW(package
, szAllUsers
, szOne
);
784 return ERROR_SUCCESS
;
787 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
789 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
790 static const WCHAR szpi
[] = {'%','i',0};
791 static const WCHAR szProductCode
[] = {
792 'P','r','o','d','u','c','t','C','o','d','e',0};
799 package
= msi_alloc_package();
802 msiobj_addref( &db
->hdr
);
805 package
->WordCount
= 0;
806 package
->PackagePath
= strdupW( db
->path
);
807 package
->BaseURL
= strdupW( base_url
);
809 create_temp_property_table( package
);
810 msi_clone_properties( package
);
811 set_installer_properties(package
);
812 sprintfW(uilevel
,szpi
,gUILevel
);
813 MSI_SetPropertyW(package
, szLevel
, uilevel
);
815 package
->ProductCode
= msi_dup_property( package
, szProductCode
);
816 set_installed_prop( package
);
817 r
= msi_load_summary_properties( package
);
818 if (r
!= ERROR_SUCCESS
)
820 msiobj_release( &package
->hdr
);
824 if (package
->WordCount
& MSIWORDCOUNT_ADMINISTRATIVE
)
825 msi_load_admin_properties( package
);
827 msi_set_context( package
);
834 * copy_package_to_temp [internal]
836 * copy the msi file to a temp file to prevent locking a CD
837 * with a multi disc install
839 * FIXME: I think this is wrong, and instead of copying the package,
840 * we should read all the tables to memory, then open the
841 * database to read binary streams on demand.
843 static LPCWSTR
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
845 WCHAR path
[MAX_PATH
];
846 static const WCHAR szMSI
[] = {'m','s','i',0};
848 GetTempPathW( MAX_PATH
, path
);
849 GetTempFileNameW( path
, szMSI
, 0, filename
);
851 if( !CopyFileW( szPackage
, filename
, FALSE
) )
853 DeleteFileW( filename
);
854 ERR("failed to copy package %s\n", debugstr_w(szPackage
) );
858 TRACE("Opening relocated package %s\n", debugstr_w( filename
));
862 LPCWSTR
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
864 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
868 /* call will always fail, becase size is 0,
869 * but will return ERROR_FILE_NOT_FOUND first
870 * if the file doesn't exist
872 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
873 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
875 cache_entry
= HeapAlloc( GetProcessHeap(), 0, size
);
876 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
878 HeapFree( GetProcessHeap(), 0, cache_entry
);
882 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
883 HeapFree( GetProcessHeap(), 0, cache_entry
);
887 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
894 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
896 static const WCHAR OriginalDatabase
[] =
897 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
898 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
899 MSIDATABASE
*db
= NULL
;
902 LPWSTR ptr
, base_url
= NULL
;
904 WCHAR temppath
[MAX_PATH
];
905 LPCWSTR file
= szPackage
;
907 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
909 if( szPackage
[0] == '#' )
911 handle
= atoiW(&szPackage
[1]);
912 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
915 IWineMsiRemoteDatabase
*remote_database
;
917 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
918 if ( !remote_database
)
919 return ERROR_INVALID_HANDLE
;
921 IWineMsiRemoteDatabase_Release( remote_database
);
922 WARN("MsiOpenPackage not allowed during a custom action!\n");
924 return ERROR_FUNCTION_FAILED
;
929 if ( UrlIsW( szPackage
, URLIS_URL
) )
931 file
= msi_download_file( szPackage
, temppath
);
933 base_url
= strdupW( szPackage
);
935 return ERROR_OUTOFMEMORY
;
937 ptr
= strrchrW( base_url
, '/' );
938 if (ptr
) *(ptr
+ 1) = '\0';
941 file
= copy_package_to_temp( szPackage
, temppath
);
943 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
944 if( r
!= ERROR_SUCCESS
)
946 if (file
!= szPackage
)
949 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
950 return ERROR_FILE_NOT_FOUND
;
956 package
= MSI_CreatePackage( db
, base_url
);
957 msi_free( base_url
);
958 msiobj_release( &db
->hdr
);
961 if (file
!= szPackage
)
964 return ERROR_INSTALL_PACKAGE_INVALID
;
967 if( file
!= szPackage
)
968 track_tempfile( package
, file
);
970 MSI_SetPropertyW( package
, Database
, db
->path
);
972 if( UrlIsW( szPackage
, URLIS_URL
) )
973 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
974 else if( szPackage
[0] == '#' )
975 MSI_SetPropertyW( package
, OriginalDatabase
, db
->path
);
978 WCHAR fullpath
[MAX_PATH
];
980 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
981 MSI_SetPropertyW( package
, OriginalDatabase
, fullpath
);
986 return ERROR_SUCCESS
;
989 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
991 MSIPACKAGE
*package
= NULL
;
994 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
996 if( !szPackage
|| !phPackage
)
997 return ERROR_INVALID_PARAMETER
;
1001 FIXME("Should create an empty database and package\n");
1002 return ERROR_FUNCTION_FAILED
;
1006 FIXME("dwOptions %08x not supported\n", dwOptions
);
1008 ret
= MSI_OpenPackageW( szPackage
, &package
);
1009 if( ret
== ERROR_SUCCESS
)
1011 *phPackage
= alloc_msihandle( &package
->hdr
);
1013 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1014 msiobj_release( &package
->hdr
);
1020 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1022 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1025 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1027 LPWSTR szwPack
= NULL
;
1032 szwPack
= strdupAtoW( szPackage
);
1034 return ERROR_OUTOFMEMORY
;
1037 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1039 msi_free( szwPack
);
1044 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1046 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1049 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1051 MSIPACKAGE
*package
;
1052 MSIHANDLE handle
= 0;
1053 IWineMsiRemotePackage
*remote_package
;
1055 TRACE("(%ld)\n",hInstall
);
1057 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1060 handle
= alloc_msihandle( &package
->db
->hdr
);
1061 msiobj_release( &package
->hdr
);
1063 else if ((remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
)))
1065 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1066 IWineMsiRemotePackage_Release(remote_package
);
1072 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1075 static const WCHAR szActionData
[] =
1076 {'A','c','t','i','o','n','D','a','t','a',0};
1077 static const WCHAR szSetProgress
[] =
1078 {'S','e','t','P','r','o','g','r','e','s','s',0};
1079 static const WCHAR szActionText
[] =
1080 {'A','c','t','i','o','n','T','e','x','t',0};
1084 DWORD total_size
= 0;
1090 TRACE("%x\n", eMessageType
);
1093 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1094 log_type
|= INSTALLLOGMODE_ERROR
;
1095 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1096 log_type
|= INSTALLLOGMODE_WARNING
;
1097 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1098 log_type
|= INSTALLLOGMODE_USER
;
1099 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1100 log_type
|= INSTALLLOGMODE_INFO
;
1101 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1102 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1103 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1104 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1105 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1106 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1108 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1111 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1113 static const WCHAR template_s
[]=
1114 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1115 static const WCHAR format
[] =
1116 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1118 LPCWSTR action_text
, action
;
1119 LPWSTR deformatted
= NULL
;
1121 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1123 action
= MSI_RecordGetString(record
, 1);
1124 action_text
= MSI_RecordGetString(record
, 2);
1126 if (!action
|| !action_text
)
1129 deformat_string(package
, action_text
, &deformatted
);
1131 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1133 len
+= strlenW(deformatted
);
1134 message
= msi_alloc(len
*sizeof(WCHAR
));
1135 sprintfW(message
, template_s
, timet
, action
);
1137 strcatW(message
, deformatted
);
1138 msi_free(deformatted
);
1143 message
= msi_alloc(1*sizeof (WCHAR
));
1145 msg_field
= MSI_RecordGetFieldCount(record
);
1146 for (i
= 1; i
<= msg_field
; i
++)
1150 static const WCHAR format
[] = { '%','i',':',' ',0};
1151 static const WCHAR space
[] = { ' ',0};
1153 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1155 total_size
+=sz
*sizeof(WCHAR
);
1156 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1157 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1159 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1163 sprintfW(number
,format
,i
);
1164 strcatW(message
,number
);
1166 strcatW(message
,tmp
);
1168 strcatW(message
,space
);
1174 TRACE("(%p %x %x %s)\n", gUIHandlerA
, gUIFilter
, log_type
,
1175 debugstr_w(message
));
1177 /* convert it to ASCII */
1178 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1,
1179 NULL
, 0, NULL
, NULL
);
1180 msg
= msi_alloc( len
);
1181 WideCharToMultiByte( CP_ACP
, 0, message
, -1,
1182 msg
, len
, NULL
, NULL
);
1184 if (gUIHandlerA
&& (gUIFilter
& log_type
))
1186 rc
= gUIHandlerA(gUIContext
,eMessageType
,msg
);
1189 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
1190 INSTALLMESSAGE_PROGRESS
))
1193 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
1194 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1196 if (log_file
!= INVALID_HANDLE_VALUE
)
1198 SetFilePointer(log_file
,0, NULL
, FILE_END
);
1199 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
1200 WriteFile(log_file
,"\n",1,&write
,NULL
);
1201 CloseHandle(log_file
);
1208 switch (eMessageType
& 0xff000000)
1210 case INSTALLMESSAGE_ACTIONDATA
:
1211 /* FIXME: format record here instead of in ui_actiondata to get the
1212 * correct action data for external scripts */
1213 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1215 case INSTALLMESSAGE_ACTIONSTART
:
1219 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1221 deformat_string(package
, action_text
, &deformated
);
1222 uirow
= MSI_CreateRecord(1);
1223 MSI_RecordSetStringW(uirow
, 1, deformated
);
1224 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1225 msi_free(deformated
);
1227 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1229 msiobj_release(&uirow
->hdr
);
1232 case INSTALLMESSAGE_PROGRESS
:
1233 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1237 return ERROR_SUCCESS
;
1240 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1243 UINT ret
= ERROR_INVALID_HANDLE
;
1244 MSIPACKAGE
*package
= NULL
;
1245 MSIRECORD
*record
= NULL
;
1247 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1251 IWineMsiRemotePackage
*remote_package
;
1253 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1254 if (!remote_package
)
1255 return ERROR_INVALID_HANDLE
;
1257 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1259 IWineMsiRemotePackage_Release( remote_package
);
1263 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1264 return HRESULT_CODE(hr
);
1266 return ERROR_FUNCTION_FAILED
;
1269 return ERROR_SUCCESS
;
1272 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1276 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1279 msiobj_release( &package
->hdr
);
1281 msiobj_release( &record
->hdr
);
1288 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1290 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1291 UINT r
= ERROR_OUTOFMEMORY
;
1293 szwName
= strdupAtoW( szName
);
1294 if( szName
&& !szwName
)
1297 szwValue
= strdupAtoW( szValue
);
1298 if( szValue
&& !szwValue
)
1301 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1304 msi_free( szwName
);
1305 msi_free( szwValue
);
1310 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
1313 MSIRECORD
*row
= NULL
;
1318 static const WCHAR Insert
[] = {
1319 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1320 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1321 '`','_','P','r','o','p','e','r','t','y','`',',',
1322 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1323 ,' ','(','?',',','?',')',0};
1324 static const WCHAR Update
[] = {
1325 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1326 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1327 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1328 ' ','=',' ','\'','%','s','\'',0};
1329 static const WCHAR Delete
[] = {
1330 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1331 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1332 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1334 TRACE("%p %s %s\n", package
, debugstr_w(szName
), debugstr_w(szValue
));
1337 return ERROR_INVALID_PARAMETER
;
1339 /* this one is weird... */
1341 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1343 rc
= MSI_GetPropertyW(package
, szName
, 0, &sz
);
1344 if (!szValue
|| !*szValue
)
1346 sprintfW(Query
, Delete
, szName
);
1348 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1350 sprintfW(Query
, Update
, szName
);
1352 row
= MSI_CreateRecord(1);
1353 MSI_RecordSetStringW(row
, 1, szValue
);
1357 strcpyW(Query
, Insert
);
1359 row
= MSI_CreateRecord(2);
1360 MSI_RecordSetStringW(row
, 1, szName
);
1361 MSI_RecordSetStringW(row
, 2, szValue
);
1364 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1365 if (rc
== ERROR_SUCCESS
)
1367 rc
= MSI_ViewExecute(view
, row
);
1368 MSI_ViewClose(view
);
1369 msiobj_release(&view
->hdr
);
1372 msiobj_release(&row
->hdr
);
1377 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1379 MSIPACKAGE
*package
;
1382 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1386 BSTR name
= NULL
, value
= NULL
;
1387 IWineMsiRemotePackage
*remote_package
;
1389 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1390 if (!remote_package
)
1391 return ERROR_INVALID_HANDLE
;
1393 name
= SysAllocString( szName
);
1394 value
= SysAllocString( szValue
);
1395 if ((!name
&& szName
) || (!value
&& szValue
))
1397 SysFreeString( name
);
1398 SysFreeString( value
);
1399 IWineMsiRemotePackage_Release( remote_package
);
1400 return ERROR_OUTOFMEMORY
;
1403 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
1405 SysFreeString( name
);
1406 SysFreeString( value
);
1407 IWineMsiRemotePackage_Release( remote_package
);
1411 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1412 return HRESULT_CODE(hr
);
1414 return ERROR_FUNCTION_FAILED
;
1417 return ERROR_SUCCESS
;
1420 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
1421 msiobj_release( &package
->hdr
);
1425 static MSIRECORD
*MSI_GetPropertyRow( MSIPACKAGE
*package
, LPCWSTR name
)
1427 static const WCHAR query
[]= {
1428 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1429 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1430 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1431 '=','\'','%','s','\'',0};
1433 if (!name
|| !*name
)
1436 return MSI_QueryGetRecord( package
->db
, query
, name
);
1439 /* internal function, not compatible with MsiGetPropertyW */
1440 UINT
MSI_GetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
,
1441 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1444 UINT rc
= ERROR_FUNCTION_FAILED
;
1446 row
= MSI_GetPropertyRow( package
, szName
);
1448 if (*pchValueBuf
> 0)
1453 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
1454 msiobj_release(&row
->hdr
);
1457 if (rc
== ERROR_SUCCESS
)
1458 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
1459 debugstr_w(szName
));
1460 else if (rc
== ERROR_MORE_DATA
)
1461 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
1462 debugstr_w(szName
));
1466 TRACE("property %s not found\n", debugstr_w(szName
));
1472 LPWSTR
msi_dup_property(MSIPACKAGE
*package
, LPCWSTR prop
)
1478 r
= MSI_GetPropertyW(package
, prop
, NULL
, &sz
);
1479 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1483 str
= msi_alloc(sz
* sizeof(WCHAR
));
1484 r
= MSI_GetPropertyW(package
, prop
, str
, &sz
);
1485 if (r
!= ERROR_SUCCESS
)
1494 int msi_get_property_int(MSIPACKAGE
*package
, LPCWSTR prop
, int def
)
1496 LPWSTR str
= msi_dup_property(package
, prop
);
1497 int val
= str
? atoiW(str
) : def
;
1502 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
1503 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
1505 static const WCHAR empty
[] = {0};
1506 MSIPACKAGE
*package
;
1507 MSIRECORD
*row
= NULL
;
1508 UINT r
= ERROR_FUNCTION_FAILED
;
1511 TRACE("%lu %s %p %p\n", handle
, debugstr_w(name
),
1512 szValueBuf
->str
.w
, pchValueBuf
);
1515 return ERROR_INVALID_PARAMETER
;
1517 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
1521 IWineMsiRemotePackage
*remote_package
;
1522 LPWSTR value
= NULL
;
1526 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
1527 if (!remote_package
)
1528 return ERROR_INVALID_HANDLE
;
1530 bname
= SysAllocString( name
);
1533 IWineMsiRemotePackage_Release( remote_package
);
1534 return ERROR_OUTOFMEMORY
;
1538 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
1543 value
= msi_alloc(len
* sizeof(WCHAR
));
1546 r
= ERROR_OUTOFMEMORY
;
1550 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
1554 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
1556 /* Bug required by Adobe installers */
1557 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
1558 *pchValueBuf
*= sizeof(WCHAR
);
1561 IWineMsiRemotePackage_Release(remote_package
);
1562 SysFreeString(bname
);
1567 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1568 return HRESULT_CODE(hr
);
1570 return ERROR_FUNCTION_FAILED
;
1576 row
= MSI_GetPropertyRow( package
, name
);
1578 val
= MSI_RecordGetString( row
, 1 );
1583 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
1586 msiobj_release( &row
->hdr
);
1587 msiobj_release( &package
->hdr
);
1592 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
1593 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
1599 val
.unicode
= FALSE
;
1600 val
.str
.a
= szValueBuf
;
1602 name
= strdupAtoW( szName
);
1603 if (szName
&& !name
)
1604 return ERROR_OUTOFMEMORY
;
1606 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
1611 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
1612 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1617 val
.str
.w
= szValueBuf
;
1619 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
1622 typedef struct _msi_remote_package_impl
{
1623 const IWineMsiRemotePackageVtbl
*lpVtbl
;
1626 } msi_remote_package_impl
;
1628 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
1630 return (msi_remote_package_impl
*) iface
;
1633 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
1634 REFIID riid
,LPVOID
*ppobj
)
1636 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
1637 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
1639 IUnknown_AddRef( iface
);
1644 return E_NOINTERFACE
;
1647 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
1649 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1651 return InterlockedIncrement( &This
->refs
);
1654 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
1656 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1659 r
= InterlockedDecrement( &This
->refs
);
1662 MsiCloseHandle( This
->package
);
1668 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
1670 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1671 This
->package
= handle
;
1675 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
1677 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1678 IWineMsiRemoteDatabase
*rdb
= NULL
;
1682 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
1683 if (FAILED(hr
) || !rdb
)
1685 ERR("Failed to create remote database\n");
1689 hdb
= MsiGetActiveDatabase(This
->package
);
1691 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
1694 ERR("Failed to set the database handle\n");
1698 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
1702 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
1704 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1707 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
1708 if (r
!= ERROR_SUCCESS
)
1709 return HRESULT_FROM_WIN32(r
);
1714 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
1716 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1717 UINT r
= MsiSetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
);
1718 return HRESULT_FROM_WIN32(r
);
1721 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
1723 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1724 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
1725 return HRESULT_FROM_WIN32(r
);
1728 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
1730 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1731 UINT r
= MsiDoActionW(This
->package
, (LPWSTR
)action
);
1732 return HRESULT_FROM_WIN32(r
);
1735 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
1737 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1738 UINT r
= MsiSequenceW(This
->package
, (LPWSTR
)table
, sequence
);
1739 return HRESULT_FROM_WIN32(r
);
1742 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
1744 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1745 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
1746 return HRESULT_FROM_WIN32(r
);
1749 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
1751 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1752 UINT r
= MsiSetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
);
1753 return HRESULT_FROM_WIN32(r
);
1756 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
1758 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1759 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
1760 return HRESULT_FROM_WIN32(r
);
1763 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
1765 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1766 *ret
= MsiGetMode(This
->package
, mode
);
1770 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
1771 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
1773 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1774 UINT r
= MsiGetFeatureStateW(This
->package
, (LPWSTR
)feature
, installed
, action
);
1775 return HRESULT_FROM_WIN32(r
);
1778 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
1780 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1781 UINT r
= MsiSetFeatureStateW(This
->package
, (LPWSTR
)feature
, state
);
1782 return HRESULT_FROM_WIN32(r
);
1785 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
1786 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
1788 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1789 UINT r
= MsiGetComponentStateW(This
->package
, (LPWSTR
)component
, installed
, action
);
1790 return HRESULT_FROM_WIN32(r
);
1793 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
1795 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1796 UINT r
= MsiSetComponentStateW(This
->package
, (LPWSTR
)component
, state
);
1797 return HRESULT_FROM_WIN32(r
);
1800 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
1802 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1803 *language
= MsiGetLanguage(This
->package
);
1807 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
1809 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1810 UINT r
= MsiSetInstallLevel(This
->package
, level
);
1811 return HRESULT_FROM_WIN32(r
);
1814 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
1818 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1819 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
1820 if (r
== ERROR_SUCCESS
)
1822 *value
= SysAllocStringLen(NULL
, size
);
1824 return E_OUTOFMEMORY
;
1826 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
1828 return HRESULT_FROM_WIN32(r
);
1831 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
1833 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1834 UINT r
= MsiEvaluateConditionW(This
->package
, (LPWSTR
)condition
);
1835 return HRESULT_FROM_WIN32(r
);
1838 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
1844 mrp_GetActiveDatabase
,
1854 mrp_GetFeatureState
,
1855 mrp_SetFeatureState
,
1856 mrp_GetComponentState
,
1857 mrp_SetComponentState
,
1859 mrp_SetInstallLevel
,
1861 mrp_EvaluateCondition
,
1864 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
1866 msi_remote_package_impl
* This
;
1868 This
= msi_alloc( sizeof *This
);
1870 return E_OUTOFMEMORY
;
1872 This
->lpVtbl
= &msi_remote_package_vtbl
;
1881 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
1882 LPCWSTR property
, LPWSTR value
)
1884 MSISOURCELISTINFO
*info
;
1886 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
1888 return ERROR_OUTOFMEMORY
;
1890 info
->context
= context
;
1891 info
->options
= options
;
1892 info
->property
= property
;
1893 info
->value
= strdupW(value
);
1894 list_add_head(&package
->sourcelist_info
, &info
->entry
);
1896 return ERROR_SUCCESS
;
1899 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
1900 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
1904 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
1906 return ERROR_OUTOFMEMORY
;
1908 disk
->context
= context
;
1909 disk
->options
= options
;
1910 disk
->disk_id
= disk_id
;
1911 disk
->volume_label
= strdupW(volume_label
);
1912 disk
->disk_prompt
= strdupW(disk_prompt
);
1913 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
1915 return ERROR_SUCCESS
;