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};
448 static const WCHAR szLogonUser
[] = {'L','o','g','o','n','U','s','e','r',0};
451 * Other things that probably should be set:
453 * ComputerName VirtualMemory
454 * ShellAdvSupport DefaultUIFont PackagecodeChanging
455 * CaptionHeight BorderTop BorderSide TextHeight
456 * RedirectedDllSupport
459 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
460 strcatW(pth
, szBackSlash
);
461 MSI_SetPropertyW(package
, CFF
, pth
);
463 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
464 strcatW(pth
, szBackSlash
);
465 MSI_SetPropertyW(package
, PFF
, pth
);
467 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
468 strcatW(pth
, szBackSlash
);
469 MSI_SetPropertyW(package
, CADF
, pth
);
471 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
472 strcatW(pth
, szBackSlash
);
473 MSI_SetPropertyW(package
, FaF
, pth
);
475 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
476 strcatW(pth
, szBackSlash
);
477 MSI_SetPropertyW(package
, FoF
, pth
);
479 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
480 strcatW(pth
, szBackSlash
);
481 MSI_SetPropertyW(package
, SendTF
, pth
);
483 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
484 strcatW(pth
, szBackSlash
);
485 MSI_SetPropertyW(package
, SMF
, pth
);
487 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
488 strcatW(pth
, szBackSlash
);
489 MSI_SetPropertyW(package
, StF
, pth
);
491 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
492 strcatW(pth
, szBackSlash
);
493 MSI_SetPropertyW(package
, TemplF
, pth
);
495 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
496 strcatW(pth
, szBackSlash
);
497 MSI_SetPropertyW(package
, DF
, pth
);
499 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
500 strcatW(pth
, szBackSlash
);
501 MSI_SetPropertyW(package
, PMF
, pth
);
503 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
504 strcatW(pth
, szBackSlash
);
505 MSI_SetPropertyW(package
, ATF
, pth
);
507 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
508 strcatW(pth
, szBackSlash
);
509 MSI_SetPropertyW(package
, ADF
, pth
);
511 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
512 strcatW(pth
, szBackSlash
);
513 MSI_SetPropertyW(package
, SF
, pth
);
514 MSI_SetPropertyW(package
, SF16
, pth
);
516 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
517 strcatW(pth
, szBackSlash
);
518 MSI_SetPropertyW(package
, LADF
, pth
);
520 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
521 strcatW(pth
, szBackSlash
);
522 MSI_SetPropertyW(package
, MPF
, pth
);
524 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
525 strcatW(pth
, szBackSlash
);
526 MSI_SetPropertyW(package
, PF
, pth
);
528 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
529 strcatW(pth
, szBackSlash
);
530 MSI_SetPropertyW(package
, WF
, pth
);
532 /* Physical Memory is specified in MB. Using total amount. */
533 msex
.dwLength
= sizeof(msex
);
534 GlobalMemoryStatusEx( &msex
);
535 sprintfW( bufstr
, szIntFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
536 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
538 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
539 ptr
= strchrW(pth
,'\\');
542 MSI_SetPropertyW(package
, WV
, pth
);
544 GetTempPathW(MAX_PATH
,pth
);
545 MSI_SetPropertyW(package
, TF
, pth
);
548 /* in a wine environment the user is always admin and privileged */
549 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
550 MSI_SetPropertyW(package
,szPriv
,szOne
);
552 /* set the os things */
553 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOEXW
);
554 GetVersionExW((OSVERSIONINFOW
*)&OSVersion
);
555 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
556 sprintfW(verstr
,szFormat
,verval
);
557 switch (OSVersion
.dwPlatformId
)
559 case VER_PLATFORM_WIN32_WINDOWS
:
560 MSI_SetPropertyW(package
,v9x
,verstr
);
562 case VER_PLATFORM_WIN32_NT
:
563 MSI_SetPropertyW(package
,vNT
,verstr
);
564 sprintfW(verstr
,szFormat
,OSVersion
.wProductType
);
565 MSI_SetPropertyW(package
,szMsiNTProductType
,verstr
);
568 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
569 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
570 /* just fudge this */
571 MSI_SetPropertyW(package
,szSPL
,szSix
);
573 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
574 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
575 sprintfW( bufstr
, szFormat
, MSI_MAJORVERSION
* 100);
576 MSI_SetPropertyW( package
, szVersionDatabase
, bufstr
);
578 GetSystemInfo( &sys_info
);
579 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
581 sprintfW( bufstr
, szIntFormat
, sys_info
.wProcessorLevel
);
582 MSI_SetPropertyW( package
, szIntel
, bufstr
);
585 /* Screen properties. */
587 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, HORZRES
) );
588 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
589 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, VERTRES
));
590 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
591 sprintfW( bufstr
, szIntFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
592 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
595 /* USERNAME and COMPANYNAME */
596 username
= msi_dup_property( package
, szUSERNAME
);
597 companyname
= msi_dup_property( package
, szCOMPANYNAME
);
599 if ((!username
|| !companyname
) &&
600 RegOpenKeyW( HKEY_CURRENT_USER
, szUserInfo
, &hkey
) == ERROR_SUCCESS
)
603 (username
= msi_reg_get_val_str( hkey
, szDefName
)))
604 MSI_SetPropertyW( package
, szUSERNAME
, username
);
606 (companyname
= msi_reg_get_val_str( hkey
, szDefCompany
)))
607 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
610 if ((!username
|| !companyname
) &&
611 RegOpenKeyW( HKEY_LOCAL_MACHINE
, szCurrentVersion
, &hkey
) == ERROR_SUCCESS
)
614 (username
= msi_reg_get_val_str( hkey
, szRegisteredUser
)))
615 MSI_SetPropertyW( package
, szUSERNAME
, username
);
617 (companyname
= msi_reg_get_val_str( hkey
, szRegisteredOrg
)))
618 MSI_SetPropertyW( package
, szCOMPANYNAME
, companyname
);
621 msi_free( username
);
622 msi_free( companyname
);
624 if ( set_user_sid_prop( package
) != ERROR_SUCCESS
)
625 ERR("Failed to set the UserSID property\n");
627 /* Date and time properties */
628 GetSystemTime( &systemtime
);
629 if (GetDateFormatW( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &systemtime
,
630 NULL
, bufstr
, sizeof(bufstr
)/sizeof(bufstr
[0]) ))
631 MSI_SetPropertyW( package
, szDate
, bufstr
);
633 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
635 if (GetTimeFormatW( LOCALE_USER_DEFAULT
,
636 TIME_FORCE24HOURFORMAT
| TIME_NOTIMEMARKER
,
637 &systemtime
, NULL
, bufstr
,
638 sizeof(bufstr
)/sizeof(bufstr
[0]) ))
639 MSI_SetPropertyW( package
, szTime
, bufstr
);
641 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
643 set_msi_assembly_prop( package
);
645 langid
= GetUserDefaultLangID();
646 sprintfW(bufstr
, szIntFormat
, langid
);
648 MSI_SetPropertyW( package
, szUserLangID
, bufstr
);
650 langid
= GetSystemDefaultLangID();
651 sprintfW(bufstr
, szIntFormat
, langid
);
653 MSI_SetPropertyW( package
, szSystemLangID
, bufstr
);
655 sprintfW(bufstr
, szIntFormat
, MsiQueryProductStateW(package
->ProductCode
));
656 MSI_SetPropertyW( package
, szProductState
, bufstr
);
659 if (!GetUserNameW( NULL
, &len
) && GetLastError() == ERROR_MORE_DATA
)
662 if ((username
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) )))
664 if (GetUserNameW( username
, &len
))
665 MSI_SetPropertyW( package
, szLogonUser
, username
);
666 HeapFree( GetProcessHeap(), 0, username
);
671 static UINT
msi_load_summary_properties( MSIPACKAGE
*package
)
675 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
679 static const WCHAR szPackageCode
[] = {
680 'P','a','c','k','a','g','e','C','o','d','e',0};
683 ERR("Unable to allocate handle\n");
684 return ERROR_OUTOFMEMORY
;
687 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
689 if (rc
!= ERROR_SUCCESS
)
691 ERR("Unable to open Summary Information\n");
695 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_PAGECOUNT
, NULL
,
696 &count
, NULL
, NULL
, NULL
);
697 if (rc
!= ERROR_SUCCESS
)
699 WARN("Unable to query page count: %d\n", rc
);
703 /* load package code property */
705 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
706 NULL
, NULL
, NULL
, &len
);
707 if (rc
!= ERROR_MORE_DATA
)
709 WARN("Unable to query revision number: %d\n", rc
);
710 rc
= ERROR_FUNCTION_FAILED
;
715 package_code
= msi_alloc( len
* sizeof(WCHAR
) );
716 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_REVNUMBER
, NULL
,
717 NULL
, NULL
, package_code
, &len
);
718 if (rc
!= ERROR_SUCCESS
)
720 WARN("Unable to query rev number: %d\n", rc
);
724 MSI_SetPropertyW( package
, szPackageCode
, package_code
);
725 msi_free( package_code
);
727 /* load package attributes */
729 MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
730 &count
, NULL
, NULL
, NULL
);
731 package
->WordCount
= count
;
734 MsiCloseHandle(suminfo
);
738 static MSIPACKAGE
*msi_alloc_package( void )
742 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
746 list_init( &package
->components
);
747 list_init( &package
->features
);
748 list_init( &package
->files
);
749 list_init( &package
->tempfiles
);
750 list_init( &package
->folders
);
751 list_init( &package
->subscriptions
);
752 list_init( &package
->appids
);
753 list_init( &package
->classes
);
754 list_init( &package
->mimes
);
755 list_init( &package
->extensions
);
756 list_init( &package
->progids
);
757 list_init( &package
->RunningActions
);
758 list_init( &package
->sourcelist_info
);
759 list_init( &package
->sourcelist_media
);
765 static UINT
msi_load_admin_properties(MSIPACKAGE
*package
)
770 static const WCHAR stmname
[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
772 r
= read_stream_data(package
->db
->storage
, stmname
, FALSE
, &data
, &sz
);
773 if (r
!= ERROR_SUCCESS
)
776 r
= msi_parse_command_line(package
, (WCHAR
*)data
, TRUE
);
782 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
, LPCWSTR base_url
)
784 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
785 static const WCHAR szpi
[] = {'%','i',0};
792 package
= msi_alloc_package();
795 msiobj_addref( &db
->hdr
);
798 package
->WordCount
= 0;
799 package
->PackagePath
= strdupW( db
->path
);
800 package
->BaseURL
= strdupW( base_url
);
802 create_temp_property_table( package
);
803 msi_clone_properties( package
);
805 package
->ProductCode
= msi_dup_property( package
, szProductCode
);
806 set_installed_prop( package
);
807 set_installer_properties( package
);
809 sprintfW(uilevel
,szpi
,gUILevel
);
810 MSI_SetPropertyW(package
, szLevel
, uilevel
);
812 r
= msi_load_summary_properties( package
);
813 if (r
!= ERROR_SUCCESS
)
815 msiobj_release( &package
->hdr
);
819 if (package
->WordCount
& msidbSumInfoSourceTypeAdminImage
)
820 msi_load_admin_properties( package
);
827 * copy_package_to_temp [internal]
829 * copy the msi file to a temp file to prevent locking a CD
830 * with a multi disc install
832 * FIXME: I think this is wrong, and instead of copying the package,
833 * we should read all the tables to memory, then open the
834 * database to read binary streams on demand.
836 static LPCWSTR
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
838 WCHAR path
[MAX_PATH
];
840 GetTempPathW( MAX_PATH
, path
);
841 GetTempFileNameW( path
, szMsi
, 0, filename
);
843 if( !CopyFileW( szPackage
, filename
, FALSE
) )
845 DeleteFileW( filename
);
846 ERR("failed to copy package %s\n", debugstr_w(szPackage
) );
850 TRACE("Opening relocated package %s\n", debugstr_w( filename
));
854 LPCWSTR
msi_download_file( LPCWSTR szUrl
, LPWSTR filename
)
856 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
860 /* call will always fail, becase size is 0,
861 * but will return ERROR_FILE_NOT_FOUND first
862 * if the file doesn't exist
864 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
865 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
867 cache_entry
= HeapAlloc( GetProcessHeap(), 0, size
);
868 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
870 HeapFree( GetProcessHeap(), 0, cache_entry
);
874 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
875 HeapFree( GetProcessHeap(), 0, cache_entry
);
879 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
886 static UINT
msi_get_local_package_name( LPWSTR path
)
888 static const WCHAR szInstaller
[] = {
889 '\\','I','n','s','t','a','l','l','e','r','\\',0};
890 static const WCHAR fmt
[] = { '%','x','.','m','s','i',0};
894 time
= GetTickCount();
895 GetWindowsDirectoryW( path
, MAX_PATH
);
896 strcatW( path
, szInstaller
);
897 CreateDirectoryW( path
, NULL
);
900 for (i
= 0; i
< 0x10000; i
++)
902 snprintfW( &path
[len
], MAX_PATH
- len
, fmt
, (time
+ i
)&0xffff );
903 handle
= CreateFileW( path
, GENERIC_WRITE
, 0, NULL
,
904 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, 0 );
905 if (handle
!= INVALID_HANDLE_VALUE
)
910 if (GetLastError() != ERROR_FILE_EXISTS
&&
911 GetLastError() != ERROR_SHARING_VIOLATION
)
912 return ERROR_FUNCTION_FAILED
;
915 return ERROR_SUCCESS
;
918 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
920 static const WCHAR OriginalDatabase
[] =
921 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
922 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
923 MSIDATABASE
*db
= NULL
;
926 LPWSTR ptr
, base_url
= NULL
;
928 WCHAR temppath
[MAX_PATH
], localfile
[MAX_PATH
];
929 LPCWSTR file
= szPackage
;
931 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
933 if( szPackage
[0] == '#' )
935 handle
= atoiW(&szPackage
[1]);
936 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
939 IWineMsiRemoteDatabase
*remote_database
;
941 remote_database
= (IWineMsiRemoteDatabase
*)msi_get_remote( handle
);
942 if ( !remote_database
)
943 return ERROR_INVALID_HANDLE
;
945 IWineMsiRemoteDatabase_Release( remote_database
);
946 WARN("MsiOpenPackage not allowed during a custom action!\n");
948 return ERROR_FUNCTION_FAILED
;
953 if ( UrlIsW( szPackage
, URLIS_URL
) )
955 file
= msi_download_file( szPackage
, temppath
);
956 if ( file
!= szPackage
)
957 file
= copy_package_to_temp( file
, temppath
);
959 base_url
= strdupW( szPackage
);
961 return ERROR_OUTOFMEMORY
;
963 ptr
= strrchrW( base_url
, '/' );
964 if (ptr
) *(ptr
+ 1) = '\0';
967 file
= copy_package_to_temp( szPackage
, temppath
);
969 r
= msi_get_local_package_name( localfile
);
970 if (r
!= ERROR_SUCCESS
)
973 TRACE("Copying to local package %s\n", debugstr_w(localfile
));
975 if (!CopyFileW( file
, localfile
, FALSE
))
977 ERR("Unable to copy package (%s -> %s) (error %u)\n",
978 debugstr_w(file
), debugstr_w(localfile
), GetLastError());
979 return GetLastError();
982 /* transforms that add binary streams require that we open the database
983 * read/write, which is safe because we always create a copy that is thrown
984 * away when we're done.
986 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_DIRECT
, &db
);
987 if( r
!= ERROR_SUCCESS
)
989 if (file
!= szPackage
)
992 if (GetFileAttributesW(szPackage
) == INVALID_FILE_ATTRIBUTES
)
993 return ERROR_FILE_NOT_FOUND
;
998 db
->localfile
= strdupW( localfile
);
1001 package
= MSI_CreatePackage( db
, base_url
);
1002 msi_free( base_url
);
1003 msiobj_release( &db
->hdr
);
1006 if (file
!= szPackage
)
1007 DeleteFileW( file
);
1009 return ERROR_INSTALL_PACKAGE_INVALID
;
1012 if( file
!= szPackage
)
1013 track_tempfile( package
, file
);
1015 MSI_SetPropertyW( package
, Database
, db
->path
);
1017 if( UrlIsW( szPackage
, URLIS_URL
) )
1018 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
1019 else if( szPackage
[0] == '#' )
1020 MSI_SetPropertyW( package
, OriginalDatabase
, db
->path
);
1023 WCHAR fullpath
[MAX_PATH
];
1025 GetFullPathNameW( szPackage
, MAX_PATH
, fullpath
, NULL
);
1026 MSI_SetPropertyW( package
, OriginalDatabase
, fullpath
);
1029 package
->script
= msi_alloc_zero( sizeof(MSISCRIPT
) );
1030 *pPackage
= package
;
1032 return ERROR_SUCCESS
;
1035 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1037 MSIPACKAGE
*package
= NULL
;
1040 TRACE("%s %08x %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
1042 if( !szPackage
|| !phPackage
)
1043 return ERROR_INVALID_PARAMETER
;
1047 FIXME("Should create an empty database and package\n");
1048 return ERROR_FUNCTION_FAILED
;
1052 FIXME("dwOptions %08x not supported\n", dwOptions
);
1054 ret
= MSI_OpenPackageW( szPackage
, &package
);
1055 if( ret
== ERROR_SUCCESS
)
1057 *phPackage
= alloc_msihandle( &package
->hdr
);
1059 ret
= ERROR_NOT_ENOUGH_MEMORY
;
1060 msiobj_release( &package
->hdr
);
1066 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
1068 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
1071 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
1073 LPWSTR szwPack
= NULL
;
1078 szwPack
= strdupAtoW( szPackage
);
1080 return ERROR_OUTOFMEMORY
;
1083 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
1085 msi_free( szwPack
);
1090 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
1092 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
1095 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
1097 MSIPACKAGE
*package
;
1098 MSIHANDLE handle
= 0;
1099 IWineMsiRemotePackage
*remote_package
;
1101 TRACE("(%d)\n",hInstall
);
1103 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1106 handle
= alloc_msihandle( &package
->db
->hdr
);
1107 msiobj_release( &package
->hdr
);
1109 else if ((remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
)))
1111 IWineMsiRemotePackage_GetActiveDatabase(remote_package
, &handle
);
1112 IWineMsiRemotePackage_Release(remote_package
);
1118 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
1121 static const WCHAR szActionData
[] =
1122 {'A','c','t','i','o','n','D','a','t','a',0};
1123 static const WCHAR szSetProgress
[] =
1124 {'S','e','t','P','r','o','g','r','e','s','s',0};
1125 static const WCHAR szActionText
[] =
1126 {'A','c','t','i','o','n','T','e','x','t',0};
1130 DWORD total_size
= 0;
1136 TRACE("%x\n", eMessageType
);
1139 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
1140 log_type
|= INSTALLLOGMODE_ERROR
;
1141 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
1142 log_type
|= INSTALLLOGMODE_WARNING
;
1143 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
1144 log_type
|= INSTALLLOGMODE_USER
;
1145 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
1146 log_type
|= INSTALLLOGMODE_INFO
;
1147 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
1148 log_type
|= INSTALLLOGMODE_COMMONDATA
;
1149 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1150 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
1151 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
1152 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
1154 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
1157 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
1159 static const WCHAR template_s
[]=
1160 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1161 static const WCHAR format
[] =
1162 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1164 LPCWSTR action_text
, action
;
1165 LPWSTR deformatted
= NULL
;
1167 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
1169 action
= MSI_RecordGetString(record
, 1);
1170 action_text
= MSI_RecordGetString(record
, 2);
1172 if (!action
|| !action_text
)
1175 deformat_string(package
, action_text
, &deformatted
);
1177 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
1179 len
+= strlenW(deformatted
);
1180 message
= msi_alloc(len
*sizeof(WCHAR
));
1181 sprintfW(message
, template_s
, timet
, action
);
1183 strcatW(message
, deformatted
);
1184 msi_free(deformatted
);
1189 message
= msi_alloc(1*sizeof (WCHAR
));
1191 msg_field
= MSI_RecordGetFieldCount(record
);
1192 for (i
= 1; i
<= msg_field
; i
++)
1196 static const WCHAR format
[] = { '%','i',':',' ',0};
1198 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
1200 total_size
+=sz
*sizeof(WCHAR
);
1201 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
1202 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
1204 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
1208 sprintfW(number
,format
,i
);
1209 strcatW(message
,number
);
1211 strcatW(message
,tmp
);
1213 strcatW(message
, szSpace
);
1219 TRACE("%p %p %p %x %x %s\n", gUIHandlerA
, gUIHandlerW
, gUIHandlerRecord
,
1220 gUIFilter
, log_type
, debugstr_w(message
));
1222 /* convert it to ASCII */
1223 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1, NULL
, 0, NULL
, NULL
);
1224 msg
= msi_alloc( len
);
1225 WideCharToMultiByte( CP_ACP
, 0, message
, -1, msg
, len
, NULL
, NULL
);
1227 if (gUIHandlerW
&& (gUIFilter
& log_type
))
1229 rc
= gUIHandlerW( gUIContext
, eMessageType
, message
);
1231 else if (gUIHandlerA
&& (gUIFilter
& log_type
))
1233 rc
= gUIHandlerA( gUIContext
, eMessageType
, msg
);
1235 else if (gUIHandlerRecord
&& (gUIFilter
& log_type
))
1237 MSIHANDLE rec
= MsiCreateRecord( 1 );
1238 MsiRecordSetStringW( rec
, 0, message
);
1239 rc
= gUIHandlerRecord( gUIContext
, eMessageType
, rec
);
1240 MsiCloseHandle( rec
);
1243 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
1244 INSTALLMESSAGE_PROGRESS
))
1247 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
1248 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1250 if (log_file
!= INVALID_HANDLE_VALUE
)
1252 SetFilePointer(log_file
,0, NULL
, FILE_END
);
1253 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
1254 WriteFile(log_file
,"\n",1,&write
,NULL
);
1255 CloseHandle(log_file
);
1259 msi_free( message
);
1261 switch (eMessageType
& 0xff000000)
1263 case INSTALLMESSAGE_ACTIONDATA
:
1264 /* FIXME: format record here instead of in ui_actiondata to get the
1265 * correct action data for external scripts */
1266 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
1268 case INSTALLMESSAGE_ACTIONSTART
:
1272 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
1274 deformat_string(package
, action_text
, &deformated
);
1275 uirow
= MSI_CreateRecord(1);
1276 MSI_RecordSetStringW(uirow
, 1, deformated
);
1277 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
1278 msi_free(deformated
);
1280 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
1282 msiobj_release(&uirow
->hdr
);
1285 case INSTALLMESSAGE_PROGRESS
:
1286 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
1290 return ERROR_SUCCESS
;
1293 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
1296 UINT ret
= ERROR_INVALID_HANDLE
;
1297 MSIPACKAGE
*package
= NULL
;
1298 MSIRECORD
*record
= NULL
;
1300 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1304 IWineMsiRemotePackage
*remote_package
;
1306 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1307 if (!remote_package
)
1308 return ERROR_INVALID_HANDLE
;
1310 hr
= IWineMsiRemotePackage_ProcessMessage( remote_package
, eMessageType
, hRecord
);
1312 IWineMsiRemotePackage_Release( remote_package
);
1316 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1317 return HRESULT_CODE(hr
);
1319 return ERROR_FUNCTION_FAILED
;
1322 return ERROR_SUCCESS
;
1325 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
1329 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
1332 msiobj_release( &package
->hdr
);
1334 msiobj_release( &record
->hdr
);
1341 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
1343 LPWSTR szwName
= NULL
, szwValue
= NULL
;
1344 UINT r
= ERROR_OUTOFMEMORY
;
1346 szwName
= strdupAtoW( szName
);
1347 if( szName
&& !szwName
)
1350 szwValue
= strdupAtoW( szValue
);
1351 if( szValue
&& !szwValue
)
1354 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
1357 msi_free( szwName
);
1358 msi_free( szwValue
);
1363 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
1366 MSIRECORD
*row
= NULL
;
1371 static const WCHAR Insert
[] = {
1372 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1373 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1374 '`','_','P','r','o','p','e','r','t','y','`',',',
1375 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1376 ,' ','(','?',',','?',')',0};
1377 static const WCHAR Update
[] = {
1378 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1379 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1380 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1381 ' ','=',' ','\'','%','s','\'',0};
1382 static const WCHAR Delete
[] = {
1383 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1384 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1385 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1387 TRACE("%p %s %s\n", package
, debugstr_w(szName
), debugstr_w(szValue
));
1390 return ERROR_INVALID_PARAMETER
;
1392 /* this one is weird... */
1394 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
1396 rc
= MSI_GetPropertyW(package
, szName
, 0, &sz
);
1397 if (!szValue
|| !*szValue
)
1399 sprintfW(Query
, Delete
, szName
);
1401 else if (rc
== ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
1403 sprintfW(Query
, Update
, szName
);
1405 row
= MSI_CreateRecord(1);
1406 MSI_RecordSetStringW(row
, 1, szValue
);
1410 strcpyW(Query
, Insert
);
1412 row
= MSI_CreateRecord(2);
1413 MSI_RecordSetStringW(row
, 1, szName
);
1414 MSI_RecordSetStringW(row
, 2, szValue
);
1417 rc
= MSI_DatabaseOpenViewW(package
->db
, Query
, &view
);
1418 if (rc
== ERROR_SUCCESS
)
1420 rc
= MSI_ViewExecute(view
, row
);
1421 MSI_ViewClose(view
);
1422 msiobj_release(&view
->hdr
);
1426 msiobj_release(&row
->hdr
);
1428 if (rc
== ERROR_SUCCESS
&& (!lstrcmpW(szName
, cszSourceDir
)))
1429 msi_reset_folders(package
, TRUE
);
1434 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
1436 MSIPACKAGE
*package
;
1439 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
1443 BSTR name
= NULL
, value
= NULL
;
1444 IWineMsiRemotePackage
*remote_package
;
1446 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( hInstall
);
1447 if (!remote_package
)
1448 return ERROR_INVALID_HANDLE
;
1450 name
= SysAllocString( szName
);
1451 value
= SysAllocString( szValue
);
1452 if ((!name
&& szName
) || (!value
&& szValue
))
1454 SysFreeString( name
);
1455 SysFreeString( value
);
1456 IWineMsiRemotePackage_Release( remote_package
);
1457 return ERROR_OUTOFMEMORY
;
1460 hr
= IWineMsiRemotePackage_SetProperty( remote_package
, name
, value
);
1462 SysFreeString( name
);
1463 SysFreeString( value
);
1464 IWineMsiRemotePackage_Release( remote_package
);
1468 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1469 return HRESULT_CODE(hr
);
1471 return ERROR_FUNCTION_FAILED
;
1474 return ERROR_SUCCESS
;
1477 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
1478 msiobj_release( &package
->hdr
);
1482 static MSIRECORD
*MSI_GetPropertyRow( MSIPACKAGE
*package
, LPCWSTR name
)
1485 MSIRECORD
*rec
, *row
= NULL
;
1488 static const WCHAR query
[]= {
1489 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1490 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1491 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1494 if (!name
|| !*name
)
1497 rec
= MSI_CreateRecord(1);
1501 MSI_RecordSetStringW(rec
, 1, name
);
1503 r
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
1504 if (r
== ERROR_SUCCESS
)
1506 MSI_ViewExecute(view
, rec
);
1507 MSI_ViewFetch(view
, &row
);
1508 MSI_ViewClose(view
);
1509 msiobj_release(&view
->hdr
);
1512 msiobj_release(&rec
->hdr
);
1516 /* internal function, not compatible with MsiGetPropertyW */
1517 UINT
MSI_GetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
,
1518 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1521 UINT rc
= ERROR_FUNCTION_FAILED
;
1523 row
= MSI_GetPropertyRow( package
, szName
);
1525 if (*pchValueBuf
> 0)
1530 rc
= MSI_RecordGetStringW(row
, 1, szValueBuf
, pchValueBuf
);
1531 msiobj_release(&row
->hdr
);
1534 if (rc
== ERROR_SUCCESS
)
1535 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
1536 debugstr_w(szName
));
1537 else if (rc
== ERROR_MORE_DATA
)
1538 TRACE("need %d sized buffer for %s\n", *pchValueBuf
,
1539 debugstr_w(szName
));
1543 TRACE("property %s not found\n", debugstr_w(szName
));
1549 LPWSTR
msi_dup_property(MSIPACKAGE
*package
, LPCWSTR prop
)
1555 r
= MSI_GetPropertyW(package
, prop
, NULL
, &sz
);
1556 if (r
!= ERROR_SUCCESS
&& r
!= ERROR_MORE_DATA
)
1560 str
= msi_alloc(sz
* sizeof(WCHAR
));
1561 r
= MSI_GetPropertyW(package
, prop
, str
, &sz
);
1562 if (r
!= ERROR_SUCCESS
)
1571 int msi_get_property_int(MSIPACKAGE
*package
, LPCWSTR prop
, int def
)
1573 LPWSTR str
= msi_dup_property(package
, prop
);
1574 int val
= str
? atoiW(str
) : def
;
1579 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
1580 awstring
*szValueBuf
, LPDWORD pchValueBuf
)
1582 MSIPACKAGE
*package
;
1583 MSIRECORD
*row
= NULL
;
1584 UINT r
= ERROR_FUNCTION_FAILED
;
1587 TRACE("%u %s %p %p\n", handle
, debugstr_w(name
),
1588 szValueBuf
->str
.w
, pchValueBuf
);
1591 return ERROR_INVALID_PARAMETER
;
1593 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
1597 IWineMsiRemotePackage
*remote_package
;
1598 LPWSTR value
= NULL
;
1602 remote_package
= (IWineMsiRemotePackage
*)msi_get_remote( handle
);
1603 if (!remote_package
)
1604 return ERROR_INVALID_HANDLE
;
1606 bname
= SysAllocString( name
);
1609 IWineMsiRemotePackage_Release( remote_package
);
1610 return ERROR_OUTOFMEMORY
;
1614 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, NULL
, &len
);
1619 value
= msi_alloc(len
* sizeof(WCHAR
));
1622 r
= ERROR_OUTOFMEMORY
;
1626 hr
= IWineMsiRemotePackage_GetProperty( remote_package
, bname
, (BSTR
*)value
, &len
);
1630 r
= msi_strcpy_to_awstring( value
, szValueBuf
, pchValueBuf
);
1632 /* Bug required by Adobe installers */
1633 if (!szValueBuf
->unicode
&& !szValueBuf
->str
.a
)
1634 *pchValueBuf
*= sizeof(WCHAR
);
1637 IWineMsiRemotePackage_Release(remote_package
);
1638 SysFreeString(bname
);
1643 if (HRESULT_FACILITY(hr
) == FACILITY_WIN32
)
1644 return HRESULT_CODE(hr
);
1646 return ERROR_FUNCTION_FAILED
;
1652 row
= MSI_GetPropertyRow( package
, name
);
1654 val
= MSI_RecordGetString( row
, 1 );
1659 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
1662 msiobj_release( &row
->hdr
);
1663 msiobj_release( &package
->hdr
);
1668 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
1669 LPSTR szValueBuf
, LPDWORD pchValueBuf
)
1675 val
.unicode
= FALSE
;
1676 val
.str
.a
= szValueBuf
;
1678 name
= strdupAtoW( szName
);
1679 if (szName
&& !name
)
1680 return ERROR_OUTOFMEMORY
;
1682 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
1687 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
1688 LPWSTR szValueBuf
, LPDWORD pchValueBuf
)
1693 val
.str
.w
= szValueBuf
;
1695 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);
1698 typedef struct _msi_remote_package_impl
{
1699 const IWineMsiRemotePackageVtbl
*lpVtbl
;
1702 } msi_remote_package_impl
;
1704 static inline msi_remote_package_impl
* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage
* iface
)
1706 return (msi_remote_package_impl
*) iface
;
1709 static HRESULT WINAPI
mrp_QueryInterface( IWineMsiRemotePackage
*iface
,
1710 REFIID riid
,LPVOID
*ppobj
)
1712 if( IsEqualCLSID( riid
, &IID_IUnknown
) ||
1713 IsEqualCLSID( riid
, &IID_IWineMsiRemotePackage
) )
1715 IUnknown_AddRef( iface
);
1720 return E_NOINTERFACE
;
1723 static ULONG WINAPI
mrp_AddRef( IWineMsiRemotePackage
*iface
)
1725 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1727 return InterlockedIncrement( &This
->refs
);
1730 static ULONG WINAPI
mrp_Release( IWineMsiRemotePackage
*iface
)
1732 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1735 r
= InterlockedDecrement( &This
->refs
);
1738 MsiCloseHandle( This
->package
);
1744 static HRESULT WINAPI
mrp_SetMsiHandle( IWineMsiRemotePackage
*iface
, MSIHANDLE handle
)
1746 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1747 This
->package
= handle
;
1751 static HRESULT WINAPI
mrp_GetActiveDatabase( IWineMsiRemotePackage
*iface
, MSIHANDLE
*handle
)
1753 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1754 IWineMsiRemoteDatabase
*rdb
= NULL
;
1758 hr
= create_msi_remote_database( NULL
, (LPVOID
*)&rdb
);
1759 if (FAILED(hr
) || !rdb
)
1761 ERR("Failed to create remote database\n");
1765 hdb
= MsiGetActiveDatabase(This
->package
);
1767 hr
= IWineMsiRemoteDatabase_SetMsiHandle( rdb
, hdb
);
1770 ERR("Failed to set the database handle\n");
1774 *handle
= alloc_msi_remote_handle( (IUnknown
*)rdb
);
1778 static HRESULT WINAPI
mrp_GetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR
*value
, DWORD
*size
)
1780 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1783 r
= MsiGetPropertyW(This
->package
, (LPWSTR
)property
, (LPWSTR
)value
, size
);
1784 if (r
!= ERROR_SUCCESS
)
1785 return HRESULT_FROM_WIN32(r
);
1790 static HRESULT WINAPI
mrp_SetProperty( IWineMsiRemotePackage
*iface
, BSTR property
, BSTR value
)
1792 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1793 UINT r
= MsiSetPropertyW(This
->package
, property
, value
);
1794 return HRESULT_FROM_WIN32(r
);
1797 static HRESULT WINAPI
mrp_ProcessMessage( IWineMsiRemotePackage
*iface
, INSTALLMESSAGE message
, MSIHANDLE record
)
1799 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1800 UINT r
= MsiProcessMessage(This
->package
, message
, record
);
1801 return HRESULT_FROM_WIN32(r
);
1804 static HRESULT WINAPI
mrp_DoAction( IWineMsiRemotePackage
*iface
, BSTR action
)
1806 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1807 UINT r
= MsiDoActionW(This
->package
, action
);
1808 return HRESULT_FROM_WIN32(r
);
1811 static HRESULT WINAPI
mrp_Sequence( IWineMsiRemotePackage
*iface
, BSTR table
, int sequence
)
1813 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1814 UINT r
= MsiSequenceW(This
->package
, table
, sequence
);
1815 return HRESULT_FROM_WIN32(r
);
1818 static HRESULT WINAPI
mrp_GetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
1820 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1821 UINT r
= MsiGetTargetPathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
1822 return HRESULT_FROM_WIN32(r
);
1825 static HRESULT WINAPI
mrp_SetTargetPath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR value
)
1827 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1828 UINT r
= MsiSetTargetPathW(This
->package
, folder
, value
);
1829 return HRESULT_FROM_WIN32(r
);
1832 static HRESULT WINAPI
mrp_GetSourcePath( IWineMsiRemotePackage
*iface
, BSTR folder
, BSTR
*value
, DWORD
*size
)
1834 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1835 UINT r
= MsiGetSourcePathW(This
->package
, (LPWSTR
)folder
, (LPWSTR
)value
, size
);
1836 return HRESULT_FROM_WIN32(r
);
1839 static HRESULT WINAPI
mrp_GetMode( IWineMsiRemotePackage
*iface
, MSIRUNMODE mode
, BOOL
*ret
)
1841 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1842 *ret
= MsiGetMode(This
->package
, mode
);
1846 static HRESULT WINAPI
mrp_GetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
,
1847 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
1849 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1850 UINT r
= MsiGetFeatureStateW(This
->package
, feature
, installed
, action
);
1851 return HRESULT_FROM_WIN32(r
);
1854 static HRESULT WINAPI
mrp_SetFeatureState( IWineMsiRemotePackage
*iface
, BSTR feature
, INSTALLSTATE state
)
1856 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1857 UINT r
= MsiSetFeatureStateW(This
->package
, feature
, state
);
1858 return HRESULT_FROM_WIN32(r
);
1861 static HRESULT WINAPI
mrp_GetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
,
1862 INSTALLSTATE
*installed
, INSTALLSTATE
*action
)
1864 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1865 UINT r
= MsiGetComponentStateW(This
->package
, component
, installed
, action
);
1866 return HRESULT_FROM_WIN32(r
);
1869 static HRESULT WINAPI
mrp_SetComponentState( IWineMsiRemotePackage
*iface
, BSTR component
, INSTALLSTATE state
)
1871 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1872 UINT r
= MsiSetComponentStateW(This
->package
, component
, state
);
1873 return HRESULT_FROM_WIN32(r
);
1876 static HRESULT WINAPI
mrp_GetLanguage( IWineMsiRemotePackage
*iface
, LANGID
*language
)
1878 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1879 *language
= MsiGetLanguage(This
->package
);
1883 static HRESULT WINAPI
mrp_SetInstallLevel( IWineMsiRemotePackage
*iface
, int level
)
1885 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1886 UINT r
= MsiSetInstallLevel(This
->package
, level
);
1887 return HRESULT_FROM_WIN32(r
);
1890 static HRESULT WINAPI
mrp_FormatRecord( IWineMsiRemotePackage
*iface
, MSIHANDLE record
,
1894 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1895 UINT r
= MsiFormatRecordW(This
->package
, record
, NULL
, &size
);
1896 if (r
== ERROR_SUCCESS
)
1898 *value
= SysAllocStringLen(NULL
, size
);
1900 return E_OUTOFMEMORY
;
1902 r
= MsiFormatRecordW(This
->package
, record
, *value
, &size
);
1904 return HRESULT_FROM_WIN32(r
);
1907 static HRESULT WINAPI
mrp_EvaluateCondition( IWineMsiRemotePackage
*iface
, BSTR condition
)
1909 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1910 UINT r
= MsiEvaluateConditionW(This
->package
, condition
);
1911 return HRESULT_FROM_WIN32(r
);
1914 static HRESULT WINAPI
mrp_GetFeatureCost( IWineMsiRemotePackage
*iface
, BSTR feature
,
1915 INT cost_tree
, INSTALLSTATE state
, INT
*cost
)
1917 msi_remote_package_impl
* This
= mrp_from_IWineMsiRemotePackage( iface
);
1918 UINT r
= MsiGetFeatureCostW(This
->package
, feature
, cost_tree
, state
, cost
);
1919 return HRESULT_FROM_WIN32(r
);
1922 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl
=
1928 mrp_GetActiveDatabase
,
1938 mrp_GetFeatureState
,
1939 mrp_SetFeatureState
,
1940 mrp_GetComponentState
,
1941 mrp_SetComponentState
,
1943 mrp_SetInstallLevel
,
1945 mrp_EvaluateCondition
,
1949 HRESULT
create_msi_remote_package( IUnknown
*pOuter
, LPVOID
*ppObj
)
1951 msi_remote_package_impl
* This
;
1953 This
= msi_alloc( sizeof *This
);
1955 return E_OUTOFMEMORY
;
1957 This
->lpVtbl
= &msi_remote_package_vtbl
;
1966 UINT
msi_package_add_info(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
1967 LPCWSTR property
, LPWSTR value
)
1969 MSISOURCELISTINFO
*info
;
1971 info
= msi_alloc(sizeof(MSISOURCELISTINFO
));
1973 return ERROR_OUTOFMEMORY
;
1975 info
->context
= context
;
1976 info
->options
= options
;
1977 info
->property
= property
;
1978 info
->value
= strdupW(value
);
1979 list_add_head(&package
->sourcelist_info
, &info
->entry
);
1981 return ERROR_SUCCESS
;
1984 UINT
msi_package_add_media_disk(MSIPACKAGE
*package
, DWORD context
, DWORD options
,
1985 DWORD disk_id
, LPWSTR volume_label
, LPWSTR disk_prompt
)
1989 disk
= msi_alloc(sizeof(MSIMEDIADISK
));
1991 return ERROR_OUTOFMEMORY
;
1993 disk
->context
= context
;
1994 disk
->options
= options
;
1995 disk
->disk_id
= disk_id
;
1996 disk
->volume_label
= strdupW(volume_label
);
1997 disk
->disk_prompt
= strdupW(disk_prompt
);
1998 list_add_head(&package
->sourcelist_media
, &disk
->entry
);
2000 return ERROR_SUCCESS
;