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',' ',
70 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
71 '`','_','P','r','o','p','e','r','t','y','`',' ',
72 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
73 'T','E','M','P','O','R','A','R','Y',',',' ',
74 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
75 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
76 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
77 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
79 rc
= MSI_DatabaseOpenViewW(package
->db
, CreateSql
, &view
);
80 if (rc
!= ERROR_SUCCESS
)
83 rc
= MSI_ViewExecute(view
, 0);
85 msiobj_release(&view
->hdr
);
89 UINT
msi_clone_properties(MSIPACKAGE
*package
)
91 MSIQUERY
*view
= NULL
;
94 static const WCHAR Query
[] = {
95 'S','E','L','E','C','T',' ','*',' ',
96 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
97 static const WCHAR Insert
[] = {
98 'I','N','S','E','R','T',' ','i','n','t','o',' ',
99 '`','_','P','r','o','p','e','r','t','y','`',' ',
100 '(','`','_','P','r','o','p','e','r','t','y','`',',',
101 '`','V','a','l','u','e','`',')',' ',
102 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
104 /* clone the existing properties */
105 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
106 if (rc
!= ERROR_SUCCESS
)
109 rc
= MSI_ViewExecute(view
, 0);
110 if (rc
!= ERROR_SUCCESS
)
113 msiobj_release(&view
->hdr
);
122 rc
= MSI_ViewFetch(view
, &row
);
123 if (rc
!= ERROR_SUCCESS
)
126 rc
= MSI_DatabaseOpenViewW(package
->db
, Insert
, &view2
);
127 if (rc
!= ERROR_SUCCESS
)
129 msiobj_release(&row
->hdr
);
133 MSI_ViewExecute(view2
, row
);
134 MSI_ViewClose(view2
);
135 msiobj_release(&view2
->hdr
);
136 msiobj_release(&row
->hdr
);
140 msiobj_release(&view
->hdr
);
148 * Sets the "Installed" property to indicate that
149 * the product is installed for the current user.
151 static UINT
set_installed_prop( MSIPACKAGE
*package
)
156 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, &hkey
, FALSE
);
157 if (r
== ERROR_SUCCESS
)
160 MSI_SetPropertyW( package
, szInstalled
, szOne
);
166 static UINT
set_user_sid_prop( MSIPACKAGE
*package
)
170 LPWSTR sid_str
= NULL
, dom
= NULL
;
171 DWORD size
, dom_size
;
173 UINT r
= ERROR_FUNCTION_FAILED
;
176 GetUserNameW( NULL
, &size
);
178 user_name
= msi_alloc( (size
+ 1) * sizeof(WCHAR
) );
180 return ERROR_OUTOFMEMORY
;
182 if (!GetUserNameW( user_name
, &size
))
187 LookupAccountNameW( NULL
, user_name
, NULL
, &size
, NULL
, &dom_size
, &use
);
189 psid
= msi_alloc( size
);
190 dom
= msi_alloc( dom_size
*sizeof (WCHAR
) );
193 r
= ERROR_OUTOFMEMORY
;
197 if (!LookupAccountNameW( NULL
, user_name
, psid
, &size
, dom
, &dom_size
, &use
))
200 if (!ConvertSidToStringSidW( psid
, &sid_str
))
203 r
= MSI_SetPropertyW( package
, szUserSID
, sid_str
);
206 LocalFree( sid_str
);
209 msi_free( user_name
);
214 static LPWSTR
get_fusion_filename(MSIPACKAGE
*package
)
219 DWORD index
= 0, size
;
221 WCHAR name
[MAX_PATH
];
222 WCHAR windir
[MAX_PATH
];
224 static const WCHAR fusion
[] = {'f','u','s','i','o','n','.','d','l','l',0};
225 static const WCHAR sub
[] = {
226 'S','o','f','t','w','a','r','e','\\',
227 'M','i','c','r','o','s','o','f','t','\\',
228 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
231 static const WCHAR subdir
[] = {
232 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
233 'F','r','a','m','e','w','o','r','k','\\',0
236 res
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
, sub
, 0, KEY_ENUMERATE_SUB_KEYS
, &netsetup
);
237 if (res
!= ERROR_SUCCESS
)
240 GetWindowsDirectoryW(windir
, MAX_PATH
);
244 while (RegEnumKeyExW(netsetup
, index
, name
, &size
, NULL
, NULL
, NULL
, NULL
) == ERROR_SUCCESS
)
248 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
249 if (lstrcmpW(ver
, name
) < 0)
252 size
= lstrlenW(windir
) + lstrlenW(subdir
) + lstrlenW(name
) +lstrlenW(fusion
) + 3;
253 check
= msi_alloc(size
* sizeof(WCHAR
));
261 lstrcpyW(check
, windir
);
262 lstrcatW(check
, szBackSlash
);
263 lstrcatW(check
, subdir
);
264 lstrcatW(check
, name
);
265 lstrcatW(check
, szBackSlash
);
266 lstrcatW(check
, fusion
);
268 if(GetFileAttributesW(check
) != INVALID_FILE_ATTRIBUTES
)
279 RegCloseKey(netsetup
);
283 typedef struct tagLANGANDCODEPAGE
289 static void set_msi_assembly_prop(MSIPACKAGE
*package
)
293 LPVOID version
= NULL
;
295 LPWSTR fusion
, verstr
;
296 LANGANDCODEPAGE
*translate
;
298 static const WCHAR netasm
[] = {
299 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
301 static const WCHAR translation
[] = {
302 '\\','V','a','r','F','i','l','e','I','n','f','o',
303 '\\','T','r','a','n','s','l','a','t','i','o','n',0
305 static const WCHAR verfmt
[] = {
306 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
307 '\\','%','0','4','x','%','0','4','x',
308 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
311 fusion
= get_fusion_filename(package
);
315 size
= GetFileVersionInfoSizeW(fusion
, &handle
);
318 version
= msi_alloc(size
);
319 if (!version
) return;
321 if (!GetFileVersionInfoW(fusion
, handle
, size
, version
))
324 if (!VerQueryValueW(version
, translation
, (LPVOID
*)&translate
, &val_len
))
327 sprintfW(buf
, verfmt
, translate
[0].wLanguage
, translate
[0].wCodePage
);
329 if (!VerQueryValueW(version
, buf
, (LPVOID
*)&verstr
, &val_len
))
332 if (!val_len
|| !verstr
)
335 MSI_SetPropertyW(package
, netasm
, verstr
);
342 static VOID
set_installer_properties(MSIPACKAGE
*package
)
346 OSVERSIONINFOEXW OSVersion
;
349 WCHAR verstr
[10], bufstr
[20];
352 LPWSTR username
, companyname
;
353 SYSTEM_INFO sys_info
;
354 SYSTEMTIME systemtime
;
357 static const WCHAR CFF
[] =
358 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
359 static const WCHAR PFF
[] =
360 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
361 static const WCHAR CADF
[] =
362 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
363 static const WCHAR FaF
[] =
364 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
365 static const WCHAR FoF
[] =
366 {'F','o','n','t','s','F','o','l','d','e','r',0};
367 static const WCHAR SendTF
[] =
368 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
369 static const WCHAR SMF
[] =
370 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
371 static const WCHAR StF
[] =
372 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
373 static const WCHAR TemplF
[] =
374 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
375 static const WCHAR DF
[] =
376 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
377 static const WCHAR PMF
[] =
378 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
379 static const WCHAR ATF
[] =
380 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
381 static const WCHAR ADF
[] =
382 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
383 static const WCHAR SF
[] =
384 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
385 static const WCHAR SF16
[] =
386 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
387 static const WCHAR LADF
[] =
388 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
389 static const WCHAR MPF
[] =
390 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
391 static const WCHAR PF
[] =
392 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
393 static const WCHAR WF
[] =
394 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
395 static const WCHAR WV
[] =
396 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
397 static const WCHAR TF
[]=
398 {'T','e','m','p','F','o','l','d','e','r',0};
399 static const WCHAR szAdminUser
[] =
400 {'A','d','m','i','n','U','s','e','r',0};
401 static const WCHAR szPriv
[] =
402 {'P','r','i','v','i','l','e','g','e','d',0};
403 static const WCHAR v9x
[] = { 'V','e','r','s','i','o','n','9','X',0 };
404 static const WCHAR vNT
[] = { 'V','e','r','s','i','o','n','N','T',0 };
405 static const WCHAR szMsiNTProductType
[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
406 static const WCHAR szFormat
[] = {'%','l','i',0};
407 static const WCHAR szWinBuild
[] =
408 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
409 static const WCHAR szSPL
[] =
410 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
411 static const WCHAR szSix
[] = {'6',0 };
413 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
414 static const WCHAR szVersionDatabase
[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
415 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
416 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
417 /* Screen properties */
418 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
419 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
420 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
421 static const WCHAR szIntFormat
[] = {'%','d',0};
422 static const WCHAR szIntel
[] = { 'I','n','t','e','l',0 };
423 static const WCHAR szUserInfo
[] = {
424 'S','O','F','T','W','A','R','E','\\',
425 'M','i','c','r','o','s','o','f','t','\\',
426 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
427 'U','s','e','r',' ','I','n','f','o',0
429 static const WCHAR szDefName
[] = { 'D','e','f','N','a','m','e',0 };
430 static const WCHAR szDefCompany
[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
431 static const WCHAR szCurrentVersion
[] = {
432 'S','O','F','T','W','A','R','E','\\',
433 'M','i','c','r','o','s','o','f','t','\\',
434 'W','i','n','d','o','w','s',' ','N','T','\\',
435 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
437 static const WCHAR szRegisteredUser
[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
438 static const WCHAR szRegisteredOrg
[] = {
439 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
441 static const WCHAR szUSERNAME
[] = {'U','S','E','R','N','A','M','E',0};
442 static const WCHAR szCOMPANYNAME
[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
443 static const WCHAR szDate
[] = {'D','a','t','e',0};
444 static const WCHAR szTime
[] = {'T','i','m','e',0};
445 static const WCHAR szUserLangID
[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
446 static const WCHAR szSystemLangID
[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
447 static const WCHAR szProductState
[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
450 * Other things that probably should be set:
452 * ComputerName LogonUser VirtualMemory
453 * ShellAdvSupport DefaultUIFont PackagecodeChanging
454 * CaptionHeight BorderTop BorderSide TextHeight
455 * RedirectedDllSupport
458 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
459 strcatW(pth
, szBackSlash
);
460 MSI_SetPropertyW(package
, CFF
, pth
);
462 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
463 strcatW(pth
, szBackSlash
);
464 MSI_SetPropertyW(package
, PFF
, pth
);
466 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
467 strcatW(pth
, szBackSlash
);
468 MSI_SetPropertyW(package
, CADF
, pth
);
470 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
471 strcatW(pth
, szBackSlash
);
472 MSI_SetPropertyW(package
, FaF
, pth
);
474 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
475 strcatW(pth
, szBackSlash
);
476 MSI_SetPropertyW(package
, FoF
, pth
);
478 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
479 strcatW(pth
, szBackSlash
);
480 MSI_SetPropertyW(package
, SendTF
, pth
);
482 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
483 strcatW(pth
, szBackSlash
);
484 MSI_SetPropertyW(package
, SMF
, pth
);
486 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
487 strcatW(pth
, szBackSlash
);
488 MSI_SetPropertyW(package
, StF
, pth
);
490 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
491 strcatW(pth
, szBackSlash
);
492 MSI_SetPropertyW(package
, TemplF
, pth
);
494 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
495 strcatW(pth
, szBackSlash
);
496 MSI_SetPropertyW(package
, DF
, pth
);
498 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
499 strcatW(pth
, szBackSlash
);
500 MSI_SetPropertyW(package
, PMF
, pth
);
502 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
503 strcatW(pth
, szBackSlash
);
504 MSI_SetPropertyW(package
, ATF
, pth
);
506 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
507 strcatW(pth
, szBackSlash
);
508 MSI_SetPropertyW(package
, ADF
, pth
);
510 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
511 strcatW(pth
, szBackSlash
);
512 MSI_SetPropertyW(package
, SF
, pth
);
513 MSI_SetPropertyW(package
, SF16
, pth
);
515 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
516 strcatW(pth
, szBackSlash
);
517 MSI_SetPropertyW(package
, LADF
, pth
);
519 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
520 strcatW(pth
, szBackSlash
);
521 MSI_SetPropertyW(package
, MPF
, pth
);
523 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
524 strcatW(pth
, szBackSlash
);
525 MSI_SetPropertyW(package
, PF
, pth
);
527 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
528 strcatW(pth
, szBackSlash
);
529 MSI_SetPropertyW(package
, WF
, pth
);
531 /* Physical Memory is specified in MB. Using total amount. */
532 msex
.dwLength
= sizeof(msex
);
533 GlobalMemoryStatusEx( &msex
);
534 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
535 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
537 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
538 ptr
= strchrW(pth
,'\\');
541 MSI_SetPropertyW(package
, WV
, pth
);
543 GetTempPathW(MAX_PATH
,pth
);
544 MSI_SetPropertyW(package
, TF
, pth
);
547 /* in a wine environment the user is always admin and privileged */
548 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
549 MSI_SetPropertyW(package
,szPriv
,szOne
);
551 /* set the os things */
552 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
553 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
554 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
555 sprintfW(verstr
,szFormat
,verval
);
556 switch (OSVersion
.dwPlatformId
)
558 case VER_PLATFORM_WIN32_WINDOWS
:
559 MSI_SetPropertyW(package
,v9x
,verstr
);
561 case VER_PLATFORM_WIN32_NT
:
562 MSI_SetPropertyW(package
,vNT
,verstr
);
563 sprintfW(verstr
,szFormat
,OSVersion
.wProductType
);
564 MSI_SetPropertyW(package
,szMsiNTProductType
,verstr
);
567 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
568 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
569 /* just fudge this */
570 MSI_SetPropertyW(package
,szSPL
,szSix
);
572 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
573 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
574 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
575 MSI_SetPropertyW( package
, szVersionDatabase
, bufstr
);
577 GetSystemInfo( &sys_info
);
578 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
580 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
581 MSI_SetPropertyW( package
, szIntel
, bufstr
);
584 /* Screen properties. */
586 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
587 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
588 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
589 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
590 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
591 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
594 /* USERNAME and COMPANYNAME */
595 username
= msi_dup_property( package
, szUSERNAME
);
596 companyname
= msi_dup_property( package
, szCOMPANYNAME
);
598 if ((!username
|| !companyname
) &&
599 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
602 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
603 MSI_SetPropertyW( package
, szUSERNAME
, username
);
605 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
606 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
609 if ((!username
|| !companyname
) &&
610 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
613 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
614 MSI_SetPropertyW( package
, szUSERNAME
, username
);
616 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrg
)))
617 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
620 msi_free( username
);
621 msi_free( companyname
);
623 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
624 ERR("Failed to set the UserSID property\n");
626 /* Date and time properties */
627 GetSystemTime( &systemtime
);
628 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
629 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
630 MSI_SetPropertyW( package
, szDate
, bufstr
);
632 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
634 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
635 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
636 &systemtime
, NULL
, bufstr
,
637 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
638 MSI_SetPropertyW( package
, szTime
, bufstr
);
640 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
642 set_msi_assembly_prop( package
);
644 langid
= GetUserDefaultLangID();
645 sprintfW(bufstr
, szIntFormat
, langid
);
647 MSI_SetPropertyW( package
, szUserLangID
, bufstr
);
649 langid
= GetSystemDefaultLangID();
650 sprintfW(bufstr
, szIntFormat
, langid
);
652 MSI_SetPropertyW( package
, szSystemLangID
, bufstr
);
654 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
655 MSI_SetPropertyW( package
, szProductState
, bufstr
);
658 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
662 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
666 static const WCHAR szPackageCode
[] = {
667 'P','a','c','k','a','g','e','C','o','d','e',0};
670 ERR("Unable to allocate handle\n");
671 return ERROR_OUTOFMEMORY
;
674 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
676 if (rc
!= ERROR_SUCCESS
)
678 ERR("Unable to open Summary Information\n");
682 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
683 &count
, NULL
, NULL
, NULL
);
684 if (rc
!= ERROR_SUCCESS
)
686 WARN("Unable to query page count: %d\n", rc
);
690 /* load package code property */
692 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
693 NULL
, NULL
, NULL
, &len
);
694 if (rc
!= ERROR_MORE_DATA
)
696 WARN("Unable to query revision number: %d\n", rc
);
697 rc
= ERROR_FUNCTION_FAILED
;
702 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
703 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
704 NULL
, NULL
, package_code
, &len
);
705 if (rc
!= ERROR_SUCCESS
)
707 WARN("Unable to query rev number: %d\n", rc
);
711 MSI_SetPropertyW( package
, szPackageCode
, package_code
);
712 msi_free( package_code
);
714 /* load package attributes */
716 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
717 &count
, NULL
, NULL
, NULL
);
718 package
->WordCount
= count
;
721 MsiCloseHandle(suminfo
);
725 static MSIPACKAGE
*msi_alloc_package( void )
729 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
733 list_init( &package
->components
);
734 list_init( &package
->features
);
735 list_init( &package
->files
);
736 list_init( &package
->tempfiles
);
737 list_init( &package
->folders
);
738 list_init( &package
->subscriptions
);
739 list_init( &package
->appids
);
740 list_init( &package
->classes
);
741 list_init( &package
->mimes
);
742 list_init( &package
->extensions
);
743 list_init( &package
->progids
);
744 list_init( &package
->RunningActions
);
745 list_init( &package
->sourcelist_info
);
746 list_init( &package
->sourcelist_media
);
752 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
757 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
759 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
760 if (r
!= ERROR_SUCCESS
)
763 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
769 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
771 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
772 static const WCHAR szpi
[] = {'%','i',0};
779 package
= msi_alloc_package();
782 msiobj_addref( &db
->hdr
);
785 package
->WordCount
= 0;
786 package
->PackagePath
= strdupW( db
->path
);
787 package
->BaseURL
= strdupW( base_url
);
789 create_temp_property_table( package
);
790 msi_clone_properties( package
);
792 package
->ProductCode
= msi_dup_property( package
, szProductCode
);
793 set_installed_prop( package
);
794 set_installer_properties( package
);
796 sprintfW(uilevel
,szpi
,gUILevel
);
797 MSI_SetPropertyW(package
, szLevel
, uilevel
);
799 r
= msi_load_summary_properties( package
);
800 if (r
!= ERROR_SUCCESS
)
802 msiobj_release( &package
->hdr
);
806 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
807 msi_load_admin_properties( package
);
814 * copy_package_to_temp [internal]
816 * copy the msi file to a temp file to prevent locking a CD
817 * with a multi disc install
819 * FIXME: I think this is wrong, and instead of copying the package,
820 * we should read all the tables to memory, then open the
821 * database to read binary streams on demand.
823 static LPCWSTR
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
825 WCHAR path
[MAX_PATH
];
827 GetTempPathW( MAX_PATH
, path
);
828 GetTempFileNameW( path
, szMsi
, 0, filename
);
830 if( !CopyFileW( szPackage
, filename
, FALSE
) )
832 DeleteFileW( filename
);
833 ERR("failed to copy package %s\n", debugstr_w(szPackage
) );
837 TRACE("Opening relocated package %s\n", debugstr_w( filename
));
841 LPCWSTR
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
843 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
847 /* call will always fail, becase size is 0,
848 * but will return ERROR_FILE_NOT_FOUND first
849 * if the file doesn't exist
851 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
852 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
854 cache_entry
= HeapAlloc( GetProcessHeap(), 0, size
);
855 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
857 HeapFree( GetProcessHeap(), 0, cache_entry
);
861 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
862 HeapFree( GetProcessHeap(), 0, cache_entry
);
866 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
873 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
875 static const WCHAR OriginalDatabase
[] =
876 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
877 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
878 MSIDATABASE
*db
= NULL
;
881 LPWSTR ptr
, base_url
= NULL
;
883 WCHAR temppath
[MAX_PATH
];
884 LPCWSTR file
= szPackage
;
886 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
888 if( szPackage
[0] == '#' )
890 handle
= atoiW(&szPackage
[1]);
891 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
894 IWineMsiRemoteDatabase
*remote_database
;
896 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
897 if ( !remote_database
)
898 return ERROR_INVALID_HANDLE
;
900 IWineMsiRemoteDatabase_Release( remote_database
);
901 WARN("MsiOpenPackage not allowed during a custom action!\n");
903 return ERROR_FUNCTION_FAILED
;
908 if ( UrlIsW( szPackage
, URLIS_URL
) )
910 file
= msi_download_file( szPackage
, temppath
);
912 base_url
= strdupW( szPackage
);
914 return ERROR_OUTOFMEMORY
;
916 ptr
= strrchrW( base_url
, '/' );
917 if (ptr
) *(ptr
+ 1) = '\0';
920 file
= copy_package_to_temp( szPackage
, temppath
);
922 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
923 if( r
!= ERROR_SUCCESS
)
925 if (file
!= szPackage
)
928 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
929 return ERROR_FILE_NOT_FOUND
;
935 package
= MSI_CreatePackage( db
, base_url
);
936 msi_free( base_url
);
937 msiobj_release( &db
->hdr
);
940 if (file
!= szPackage
)
943 return ERROR_INSTALL_PACKAGE_INVALID
;
946 if( file
!= szPackage
)
947 track_tempfile( package
, file
);
949 MSI_SetPropertyW( package
, Database
, db
->path
);
951 if( UrlIsW( szPackage
, URLIS_URL
) )
952 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
953 else if( szPackage
[0] == '#' )
954 MSI_SetPropertyW( package
, OriginalDatabase
, db
->path
);
957 WCHAR fullpath
[MAX_PATH
];
959 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
960 MSI_SetPropertyW( package
, OriginalDatabase
, fullpath
);
963 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
966 return ERROR_SUCCESS
;
969 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
971 MSIPACKAGE
*package
= NULL
;
974 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
976 if( !szPackage
|| !phPackage
)
977 return ERROR_INVALID_PARAMETER
;
981 FIXME("Should create an empty database and package\n");
982 return ERROR_FUNCTION_FAILED
;
986 FIXME("dwOptions %08x not supported\n", dwOptions
);
988 ret
= MSI_OpenPackageW( szPackage
, &package
);
989 if( ret
== ERROR_SUCCESS
)
991 *phPackage
= alloc_msihandle( &package
->hdr
);
993 ret
= ERROR_NOT_ENOUGH_MEMORY
;
994 msiobj_release( &package
->hdr
);
1000 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1002 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1005 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1007 LPWSTR szwPack
= NULL
;
1012 szwPack
= strdupAtoW( szPackage
);
1014 return ERROR_OUTOFMEMORY
;
1017 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1019 msi_free( szwPack
);
1024 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1026 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1029 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1031 MSIPACKAGE
*package
;
1032 MSIHANDLE handle
= 0;
1033 IWineMsiRemotePackage
*remote_package
;
1035 TRACE("(%d)\n",hInstall
);
1037 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1040 handle
= alloc_msihandle( &package
->db
->hdr
);
1041 msiobj_release( &package
->hdr
);
1043 else if ((remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
)))
1045 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1046 IWineMsiRemotePackage_Release(remote_package
);
1052 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1055 static const WCHAR szActionData
[] =
1056 {'A','c','t','i','o','n','D','a','t','a',0};
1057 static const WCHAR szSetProgress
[] =
1058 {'S','e','t','P','r','o','g','r','e','s','s',0};
1059 static const WCHAR szActionText
[] =
1060 {'A','c','t','i','o','n','T','e','x','t',0};
1064 DWORD total_size
= 0;
1070 TRACE("%x\n", eMessageType
);
1073 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1074 log_type
|= INSTALLLOGMODE_ERROR
;
1075 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1076 log_type
|= INSTALLLOGMODE_WARNING
;
1077 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1078 log_type
|= INSTALLLOGMODE_USER
;
1079 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1080 log_type
|= INSTALLLOGMODE_INFO
;
1081 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1082 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1083 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1084 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1085 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1086 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1088 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1091 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1093 static const WCHAR template_s
[]=
1094 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1095 static const WCHAR format
[] =
1096 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1098 LPCWSTR action_text
, action
;
1099 LPWSTR deformatted
= NULL
;
1101 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1103 action
= MSI_RecordGetString(record
, 1);
1104 action_text
= MSI_RecordGetString(record
, 2);
1106 if (!action
|| !action_text
)
1109 deformat_string(package
, action_text
, &deformatted
);
1111 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1113 len
+= strlenW(deformatted
);
1114 message
= msi_alloc(len
*sizeof(WCHAR
));
1115 sprintfW(message
, template_s
, timet
, action
);
1117 strcatW(message
, deformatted
);
1118 msi_free(deformatted
);
1123 message
= msi_alloc(1*sizeof (WCHAR
));
1125 msg_field
= MSI_RecordGetFieldCount(record
);
1126 for (i
= 1; i
<= msg_field
; i
++)
1130 static const WCHAR format
[] = { '%','i',':',' ',0};
1132 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1134 total_size
+=sz
*sizeof(WCHAR
);
1135 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1136 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1138 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1142 sprintfW(number
,format
,i
);
1143 strcatW(message
,number
);
1145 strcatW(message
,tmp
);
1147 strcatW(message
, szSpace
);
1153 TRACE("(%p %x %x %s)\n", gUIHandlerA
, gUIFilter
, log_type
,
1154 debugstr_w(message
));
1156 /* convert it to ASCII */
1157 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1,
1158 NULL
, 0, NULL
, NULL
);
1159 msg
= msi_alloc( len
);
1160 WideCharToMultiByte( CP_ACP
, 0, message
, -1,
1161 msg
, len
, NULL
, NULL
);
1163 if (gUIHandlerA
&& (gUIFilter
& log_type
))
1165 rc
= gUIHandlerA(gUIContext
,eMessageType
,msg
);
1168 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
1169 INSTALLMESSAGE_PROGRESS
))
1172 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
1173 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1175 if (log_file
!= INVALID_HANDLE_VALUE
)
1177 SetFilePointer(log_file
,0, NULL
, FILE_END
);
1178 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
1179 WriteFile(log_file
,"\n",1,&write
,NULL
);
1180 CloseHandle(log_file
);
1187 switch (eMessageType
& 0xff000000)
1189 case INSTALLMESSAGE_ACTIONDATA
:
1190 /* FIXME: format record here instead of in ui_actiondata to get the
1191 * correct action data for external scripts */
1192 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1194 case INSTALLMESSAGE_ACTIONSTART
:
1198 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1200 deformat_string(package
, action_text
, &deformated
);
1201 uirow
= MSI_CreateRecord(1);
1202 MSI_RecordSetStringW(uirow
, 1, deformated
);
1203 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1204 msi_free(deformated
);
1206 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1208 msiobj_release(&uirow
->hdr
);
1211 case INSTALLMESSAGE_PROGRESS
:
1212 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1216 return ERROR_SUCCESS
;
1219 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1222 UINT ret
= ERROR_INVALID_HANDLE
;
1223 MSIPACKAGE
*package
= NULL
;
1224 MSIRECORD
*record
= NULL
;
1226 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1230 IWineMsiRemotePackage
*remote_package
;
1232 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1233 if (!remote_package
)
1234 return ERROR_INVALID_HANDLE
;
1236 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1238 IWineMsiRemotePackage_Release( remote_package
);
1242 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1243 return HRESULT_CODE(hr
);
1245 return ERROR_FUNCTION_FAILED
;
1248 return ERROR_SUCCESS
;
1251 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1255 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1258 msiobj_release( &package
->hdr
);
1260 msiobj_release( &record
->hdr
);
1267 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1269 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1270 UINT r
= ERROR_OUTOFMEMORY
;
1272 szwName
= strdupAtoW( szName
);
1273 if( szName
&& !szwName
)
1276 szwValue
= strdupAtoW( szValue
);
1277 if( szValue
&& !szwValue
)
1280 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1283 msi_free( szwName
);
1284 msi_free( szwValue
);
1289 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
1292 MSIRECORD
*row
= NULL
;
1297 static const WCHAR Insert
[] = {
1298 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1299 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1300 '`','_','P','r','o','p','e','r','t','y','`',',',
1301 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1302 ,' ','(','?',',','?',')',0};
1303 static const WCHAR Update
[] = {
1304 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1305 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1306 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1307 ' ','=',' ','\'','%','s','\'',0};
1308 static const WCHAR Delete
[] = {
1309 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1310 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1311 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1313 TRACE("%p %s %s\n", package
, debugstr_w(szName
), debugstr_w(szValue
));
1316 return ERROR_INVALID_PARAMETER
;
1318 /* this one is weird... */
1320 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1322 rc
= MSI_GetPropertyW(package
, szName
, 0, &sz
);
1323 if (!szValue
|| !*szValue
)
1325 sprintfW(Query
, Delete
, szName
);
1327 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1329 sprintfW(Query
, Update
, szName
);
1331 row
= MSI_CreateRecord(1);
1332 MSI_RecordSetStringW(row
, 1, szValue
);
1336 strcpyW(Query
, Insert
);
1338 row
= MSI_CreateRecord(2);
1339 MSI_RecordSetStringW(row
, 1, szName
);
1340 MSI_RecordSetStringW(row
, 2, szValue
);
1343 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1344 if (rc
== ERROR_SUCCESS
)
1346 rc
= MSI_ViewExecute(view
, row
);
1347 MSI_ViewClose(view
);
1348 msiobj_release(&view
->hdr
);
1352 msiobj_release(&row
->hdr
);
1354 if (rc
== ERROR_SUCCESS
&& (!lstrcmpW(szName
, cszSourceDir
)))
1355 msi_reset_folders(package
, TRUE
);
1360 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1362 MSIPACKAGE
*package
;
1365 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1369 BSTR name
= NULL
, value
= NULL
;
1370 IWineMsiRemotePackage
*remote_package
;
1372 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1373 if (!remote_package
)
1374 return ERROR_INVALID_HANDLE
;
1376 name
= SysAllocString( szName
);
1377 value
= SysAllocString( szValue
);
1378 if ((!name
&& szName
) || (!value
&& szValue
))
1380 SysFreeString( name
);
1381 SysFreeString( value
);
1382 IWineMsiRemotePackage_Release( remote_package
);
1383 return ERROR_OUTOFMEMORY
;
1386 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
1388 SysFreeString( name
);
1389 SysFreeString( value
);
1390 IWineMsiRemotePackage_Release( remote_package
);
1394 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1395 return HRESULT_CODE(hr
);
1397 return ERROR_FUNCTION_FAILED
;
1400 return ERROR_SUCCESS
;
1403 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
1404 msiobj_release( &package
->hdr
);
1408 static MSIRECORD
*MSI_GetPropertyRow( MSIPACKAGE
*package
, LPCWSTR name
)
1411 MSIRECORD
*rec
, *row
= NULL
;
1414 static const WCHAR query
[]= {
1415 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1416 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1417 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1420 if (!name
|| !*name
)
1423 rec
= MSI_CreateRecord(1);
1427 MSI_RecordSetStringW(rec
, 1, name
);
1429 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1430 if (r
== ERROR_SUCCESS
)
1432 MSI_ViewExecute(view
, rec
);
1433 MSI_ViewFetch(view
, &row
);
1434 MSI_ViewClose(view
);
1435 msiobj_release(&view
->hdr
);
1438 msiobj_release(&rec
->hdr
);
1442 /* internal function, not compatible with MsiGetPropertyW */
1443 UINT
MSI_GetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
,
1444 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1447 UINT rc
= ERROR_FUNCTION_FAILED
;
1449 row
= MSI_GetPropertyRow( package
, szName
);
1451 if (*pchValueBuf
> 0)
1456 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
1457 msiobj_release(&row
->hdr
);
1460 if (rc
== ERROR_SUCCESS
)
1461 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
1462 debugstr_w(szName
));
1463 else if (rc
== ERROR_MORE_DATA
)
1464 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
1465 debugstr_w(szName
));
1469 TRACE("property %s not found\n", debugstr_w(szName
));
1475 LPWSTR
msi_dup_property(MSIPACKAGE
*package
, LPCWSTR prop
)
1481 r
= MSI_GetPropertyW(package
, prop
, NULL
, &sz
);
1482 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1486 str
= msi_alloc(sz
* sizeof(WCHAR
));
1487 r
= MSI_GetPropertyW(package
, prop
, str
, &sz
);
1488 if (r
!= ERROR_SUCCESS
)
1497 int msi_get_property_int(MSIPACKAGE
*package
, LPCWSTR prop
, int def
)
1499 LPWSTR str
= msi_dup_property(package
, prop
);
1500 int val
= str
? atoiW(str
) : def
;
1505 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
1506 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
1508 MSIPACKAGE
*package
;
1509 MSIRECORD
*row
= NULL
;
1510 UINT r
= ERROR_FUNCTION_FAILED
;
1513 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
1514 szValueBuf
->str
.w
, pchValueBuf
);
1517 return ERROR_INVALID_PARAMETER
;
1519 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
1523 IWineMsiRemotePackage
*remote_package
;
1524 LPWSTR value
= NULL
;
1528 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
1529 if (!remote_package
)
1530 return ERROR_INVALID_HANDLE
;
1532 bname
= SysAllocString( name
);
1535 IWineMsiRemotePackage_Release( remote_package
);
1536 return ERROR_OUTOFMEMORY
;
1540 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
1545 value
= msi_alloc(len
* sizeof(WCHAR
));
1548 r
= ERROR_OUTOFMEMORY
;
1552 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
1556 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
1558 /* Bug required by Adobe installers */
1559 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
1560 *pchValueBuf
*= sizeof(WCHAR
);
1563 IWineMsiRemotePackage_Release(remote_package
);
1564 SysFreeString(bname
);
1569 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1570 return HRESULT_CODE(hr
);
1572 return ERROR_FUNCTION_FAILED
;
1578 row
= MSI_GetPropertyRow( package
, name
);
1580 val
= MSI_RecordGetString( row
, 1 );
1585 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
1588 msiobj_release( &row
->hdr
);
1589 msiobj_release( &package
->hdr
);
1594 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
1595 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
1601 val
.unicode
= FALSE
;
1602 val
.str
.a
= szValueBuf
;
1604 name
= strdupAtoW( szName
);
1605 if (szName
&& !name
)
1606 return ERROR_OUTOFMEMORY
;
1608 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
1613 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
1614 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1619 val
.str
.w
= szValueBuf
;
1621 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
1624 typedef struct _msi_remote_package_impl
{
1625 const IWineMsiRemotePackageVtbl
*lpVtbl
;
1628 } msi_remote_package_impl
;
1630 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
1632 return (msi_remote_package_impl
*) iface
;
1635 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
1636 REFIID riid
,LPVOID
*ppobj
)
1638 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
1639 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
1641 IUnknown_AddRef( iface
);
1646 return E_NOINTERFACE
;
1649 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
1651 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1653 return InterlockedIncrement( &This
->refs
);
1656 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
1658 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1661 r
= InterlockedDecrement( &This
->refs
);
1664 MsiCloseHandle( This
->package
);
1670 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
1672 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1673 This
->package
= handle
;
1677 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
1679 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1680 IWineMsiRemoteDatabase
*rdb
= NULL
;
1684 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
1685 if (FAILED(hr
) || !rdb
)
1687 ERR("Failed to create remote database\n");
1691 hdb
= MsiGetActiveDatabase(This
->package
);
1693 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
1696 ERR("Failed to set the database handle\n");
1700 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
1704 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
1706 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1709 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
1710 if (r
!= ERROR_SUCCESS
)
1711 return HRESULT_FROM_WIN32(r
);
1716 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
1718 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1719 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
1720 return HRESULT_FROM_WIN32(r
);
1723 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
1725 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1726 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
1727 return HRESULT_FROM_WIN32(r
);
1730 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
1732 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1733 UINT r
= MsiDoActionW(This
->package
, action
);
1734 return HRESULT_FROM_WIN32(r
);
1737 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
1739 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1740 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
1741 return HRESULT_FROM_WIN32(r
);
1744 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
1746 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1747 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
1748 return HRESULT_FROM_WIN32(r
);
1751 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
1753 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1754 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
1755 return HRESULT_FROM_WIN32(r
);
1758 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
1760 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1761 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
1762 return HRESULT_FROM_WIN32(r
);
1765 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
1767 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1768 *ret
= MsiGetMode(This
->package
, mode
);
1772 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
1773 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
1775 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1776 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
1777 return HRESULT_FROM_WIN32(r
);
1780 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
1782 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1783 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
1784 return HRESULT_FROM_WIN32(r
);
1787 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
1788 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
1790 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1791 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
1792 return HRESULT_FROM_WIN32(r
);
1795 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
1797 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1798 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
1799 return HRESULT_FROM_WIN32(r
);
1802 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
1804 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1805 *language
= MsiGetLanguage(This
->package
);
1809 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
1811 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1812 UINT r
= MsiSetInstallLevel(This
->package
, level
);
1813 return HRESULT_FROM_WIN32(r
);
1816 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
1820 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1821 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
1822 if (r
== ERROR_SUCCESS
)
1824 *value
= SysAllocStringLen(NULL
, size
);
1826 return E_OUTOFMEMORY
;
1828 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
1830 return HRESULT_FROM_WIN32(r
);
1833 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
1835 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1836 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
1837 return HRESULT_FROM_WIN32(r
);
1840 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
1846 mrp_GetActiveDatabase
,
1856 mrp_GetFeatureState
,
1857 mrp_SetFeatureState
,
1858 mrp_GetComponentState
,
1859 mrp_SetComponentState
,
1861 mrp_SetInstallLevel
,
1863 mrp_EvaluateCondition
,
1866 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
1868 msi_remote_package_impl
* This
;
1870 This
= msi_alloc( sizeof *This
);
1872 return E_OUTOFMEMORY
;
1874 This
->lpVtbl
= &msi_remote_package_vtbl
;
1883 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
1884 LPCWSTR property
, LPWSTR value
)
1886 MSISOURCELISTINFO
*info
;
1888 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
1890 return ERROR_OUTOFMEMORY
;
1892 info
->context
= context
;
1893 info
->options
= options
;
1894 info
->property
= property
;
1895 info
->value
= strdupW(value
);
1896 list_add_head(&package
->sourcelist_info
, &info
->entry
);
1898 return ERROR_SUCCESS
;
1901 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
1902 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
1906 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
1908 return ERROR_OUTOFMEMORY
;
1910 disk
->context
= context
;
1911 disk
->options
= options
;
1912 disk
->disk_id
= disk_id
;
1913 disk
->volume_label
= strdupW(volume_label
);
1914 disk
->disk_prompt
= strdupW(disk_prompt
);
1915 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
1917 return ERROR_SUCCESS
;