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 )
153 static const WCHAR szInstalled[] = {
154 'I','n','s','t','a','l','l','e','d',0 };
155 WCHAR val[2] = { '1', 0 };
159 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
160 if (r == ERROR_SUCCESS)
163 MSI_SetPropertyW( package, szInstalled, val );
169 static UINT set_user_sid_prop( MSIPACKAGE *package )
173 LPWSTR sid_str = NULL, dom = NULL;
174 DWORD size, dom_size;
176 UINT r = ERROR_FUNCTION_FAILED;
178 static const WCHAR user_sid[] = {'U','s','e','r','S','I','D',0};
181 GetUserNameW( NULL, &size );
183 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
185 return ERROR_OUTOFMEMORY;
187 if (!GetUserNameW( user_name, &size ))
192 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
194 psid = msi_alloc( size );
195 dom = msi_alloc( dom_size*sizeof (WCHAR) );
198 r = ERROR_OUTOFMEMORY;
202 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
205 if (!ConvertSidToStringSidW( psid, &sid_str ))
208 r = MSI_SetPropertyW( package, user_sid, sid_str );
211 LocalFree( sid_str );
214 msi_free( user_name );
219 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
224 DWORD index = 0, size;
226 WCHAR name[MAX_PATH];
227 WCHAR windir[MAX_PATH];
229 static const WCHAR backslash[] = {'\\',0};
230 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
231 static const WCHAR sub[] = {
232 'S','o','f','t','w','a','r','e','\\',
233 'M','i','c','r','o','s','o','f','t','\\',
234 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
237 static const WCHAR subdir[] = {
238 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
239 'F','r','a','m','e','w','o','r','k','\\',0
242 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
243 if (res != ERROR_SUCCESS)
246 GetWindowsDirectoryW(windir, MAX_PATH);
250 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
254 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
255 if (lstrcmpW(ver, name) < 0)
258 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
259 check = msi_alloc(size * sizeof(WCHAR));
267 lstrcpyW(check, windir);
268 lstrcatW(check, backslash);
269 lstrcatW(check, subdir);
270 lstrcatW(check, name);
271 lstrcatW(check, backslash);
272 lstrcatW(check, fusion);
274 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
285 RegCloseKey(netsetup);
289 typedef struct tagLANGANDCODEPAGE
295 static void set_msi_assembly_prop(MSIPACKAGE *package)
299 LPVOID version = NULL;
301 LPWSTR fusion, verstr;
302 LANGANDCODEPAGE *translate;
304 static const WCHAR netasm[] = {
305 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
307 static const WCHAR translation[] = {
308 '\\','V','a','r','F','i','l','e','I','n','f','o',
309 '\\','T','r','a','n','s','l','a','t','i','o','n',0
311 static const WCHAR verfmt[] = {
312 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
313 '\\','%','0','4','x','%','0','4','x',
314 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
317 fusion = get_fusion_filename(package);
321 size = GetFileVersionInfoSizeW(fusion, &handle);
324 version = msi_alloc(size);
325 if (!version) return;
327 if (!GetFileVersionInfoW(fusion, handle, size, version))
330 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
333 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
335 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
338 if (!val_len || !verstr)
341 MSI_SetPropertyW(package, netasm, verstr);
348 static VOID set_installer_properties(MSIPACKAGE *package)
352 OSVERSIONINFOEXW OSVersion;
355 WCHAR verstr[10], bufstr[20];
358 LPWSTR username, companyname;
359 SYSTEM_INFO sys_info;
360 SYSTEMTIME systemtime;
363 static const WCHAR cszbs[]={'\\',0};
364 static const WCHAR CFF[] =
365 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
366 static const WCHAR PFF[] =
367 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
368 static const WCHAR CADF[] =
369 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
370 static const WCHAR FaF[] =
371 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
372 static const WCHAR FoF[] =
373 {'F','o','n','t','s','F','o','l','d','e','r',0};
374 static const WCHAR SendTF[] =
375 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
376 static const WCHAR SMF[] =
377 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
378 static const WCHAR StF[] =
379 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
380 static const WCHAR TemplF[] =
381 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
382 static const WCHAR DF[] =
383 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
384 static const WCHAR PMF[] =
385 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
386 static const WCHAR ATF[] =
387 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
388 static const WCHAR ADF[] =
389 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
390 static const WCHAR SF[] =
391 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
392 static const WCHAR SF16[] =
393 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
394 static const WCHAR LADF[] =
395 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
396 static const WCHAR MPF[] =
397 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
398 static const WCHAR PF[] =
399 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
400 static const WCHAR WF[] =
401 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
402 static const WCHAR WV[] =
403 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
404 static const WCHAR TF[]=
405 {'T','e','m','p','F','o','l','d','e','r',0};
406 static const WCHAR szAdminUser[] =
407 {'A','d','m','i','n','U','s','e','r',0};
408 static const WCHAR szPriv[] =
409 {'P','r','i','v','i','l','e','g','e','d',0};
410 static const WCHAR szOne[] =
412 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
413 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
414 static const WCHAR szMsiNTProductType[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
415 static const WCHAR szFormat[] = {'%','l','i',0};
416 static const WCHAR szWinBuild[] =
417 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
418 static const WCHAR szSPL[] =
419 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
420 static const WCHAR szSix[] = {'6',0 };
422 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
423 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
424 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
425 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
426 /* Screen properties */
427 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
428 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
429 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
430 static const WCHAR szIntFormat[] = {'%','d',0};
431 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
432 static const WCHAR szUserInfo[] = {
433 'S','O','F','T','W','A','R','E','\\',
434 'M','i','c','r','o','s','o','f','t','\\',
435 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
436 'U','s','e','r',' ','I','n','f','o',0
438 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
439 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
440 static const WCHAR szCurrentVersion[] = {
441 'S','O','F','T','W','A','R','E','\\',
442 'M','i','c','r','o','s','o','f','t','\\',
443 'W','i','n','d','o','w','s',' ','N','T','\\',
444 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
446 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
447 static const WCHAR szRegisteredOrg[] = {
448 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
450 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
451 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
452 static const WCHAR szDate[] = {'D','a','t','e',0};
453 static const WCHAR szTime[] = {'T','i','m','e',0};
454 static const WCHAR szUserLangID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
455 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
456 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
459 * Other things that probably should be set:
461 * ComputerName LogonUser VirtualMemory
462 * ShellAdvSupport DefaultUIFont PackagecodeChanging
463 * CaptionHeight BorderTop BorderSide TextHeight
464 * RedirectedDllSupport
467 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
469 MSI_SetPropertyW(package, CFF, pth);
471 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
473 MSI_SetPropertyW(package, PFF, pth);
475 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
477 MSI_SetPropertyW(package, CADF, pth);
479 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
481 MSI_SetPropertyW(package, FaF, pth);
483 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
485 MSI_SetPropertyW(package, FoF, pth);
487 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
489 MSI_SetPropertyW(package, SendTF, pth);
491 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
493 MSI_SetPropertyW(package, SMF, pth);
495 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
497 MSI_SetPropertyW(package, StF, pth);
499 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
501 MSI_SetPropertyW(package, TemplF, pth);
503 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
505 MSI_SetPropertyW(package, DF, pth);
507 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
509 MSI_SetPropertyW(package, PMF, pth);
511 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
513 MSI_SetPropertyW(package, ATF, pth);
515 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
517 MSI_SetPropertyW(package, ADF, pth);
519 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
521 MSI_SetPropertyW(package, SF, pth);
522 MSI_SetPropertyW(package, SF16, pth);
524 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
526 MSI_SetPropertyW(package, LADF, pth);
528 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
530 MSI_SetPropertyW(package, MPF, pth);
532 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
534 MSI_SetPropertyW(package, PF, pth);
536 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
538 MSI_SetPropertyW(package, WF, pth);
540 /* Physical Memory is specified in MB. Using total amount. */
541 msex.dwLength = sizeof(msex);
542 GlobalMemoryStatusEx( &msex );
543 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys/1024/1024));
544 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
546 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
547 ptr = strchrW(pth,'\\');
550 MSI_SetPropertyW(package, WV, pth);
552 GetTempPathW(MAX_PATH,pth);
553 MSI_SetPropertyW(package, TF, pth);
556 /* in a wine environment the user is always admin and privileged */
557 MSI_SetPropertyW(package,szAdminUser,szOne);
558 MSI_SetPropertyW(package,szPriv,szOne);
560 /* set the os things */
561 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
562 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
563 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
564 sprintfW(verstr,szFormat,verval);
565 switch (OSVersion.dwPlatformId)
567 case VER_PLATFORM_WIN32_WINDOWS:
568 MSI_SetPropertyW(package,v9x,verstr);
570 case VER_PLATFORM_WIN32_NT:
571 MSI_SetPropertyW(package,vNT,verstr);
572 sprintfW(verstr,szFormat,OSVersion.wProductType);
573 MSI_SetPropertyW(package,szMsiNTProductType,verstr);
576 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
577 MSI_SetPropertyW(package,szWinBuild,verstr);
578 /* just fudge this */
579 MSI_SetPropertyW(package,szSPL,szSix);
581 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
582 MSI_SetPropertyW( package, szVersionMsi, bufstr );
583 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
584 MSI_SetPropertyW( package, szVersionDatabase, bufstr );
586 GetSystemInfo( &sys_info );
587 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
589 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
590 MSI_SetPropertyW( package, szIntel, bufstr );
593 /* Screen properties. */
595 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
596 MSI_SetPropertyW( package, szScreenX, bufstr );
597 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
598 MSI_SetPropertyW( package, szScreenY, bufstr );
599 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
600 MSI_SetPropertyW( package, szColorBits, bufstr );
603 /* USERNAME and COMPANYNAME */
604 username = msi_dup_property( package, szUSERNAME );
605 companyname = msi_dup_property( package, szCOMPANYNAME );
607 if ((!username || !companyname) &&
608 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
611 (username = msi_reg_get_val_str( hkey, szDefName )))
612 MSI_SetPropertyW( package, szUSERNAME, username );
614 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
615 MSI_SetPropertyW( package, szCOMPANYNAME, companyname );
618 if ((!username || !companyname) &&
619 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
622 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
623 MSI_SetPropertyW( package, szUSERNAME, username );
625 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrg )))
626 MSI_SetPropertyW( package, szCOMPANYNAME, companyname );
629 msi_free( username );
630 msi_free( companyname );
632 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
633 ERR("Failed to set the UserSID property\n");
635 /* Date and time properties */
636 GetSystemTime( &systemtime );
637 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
638 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
639 MSI_SetPropertyW( package, szDate, bufstr );
641 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
643 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
644 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
645 &systemtime, NULL, bufstr,
646 sizeof(bufstr)/sizeof(bufstr[0]) ))
647 MSI_SetPropertyW( package, szTime, bufstr );
649 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
651 set_msi_assembly_prop( package );
653 langid = GetUserDefaultLangID();
654 sprintfW(bufstr, szIntFormat, langid);
656 MSI_SetPropertyW( package, szUserLangID, bufstr );
658 langid = GetSystemDefaultLangID();
659 sprintfW(bufstr, szIntFormat, langid);
661 MSI_SetPropertyW( package, szSystemLangID, bufstr );
663 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
664 MSI_SetPropertyW( package, szProductState, bufstr );
667 static UINT msi_load_summary_properties( MSIPACKAGE *package )
671 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
675 static const WCHAR szPackageCode[] = {
676 'P','a','c','k','a','g','e','C','o','d','e',0};
679 ERR("Unable to allocate handle\n");
680 return ERROR_OUTOFMEMORY;
683 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
685 if (rc != ERROR_SUCCESS)
687 ERR("Unable to open Summary Information\n");
691 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
692 &count, NULL, NULL, NULL );
693 if (rc != ERROR_SUCCESS)
695 WARN("Unable to query page count: %d\n", rc);
699 /* load package code property */
701 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
702 NULL, NULL, NULL, &len );
703 if (rc != ERROR_MORE_DATA)
705 WARN("Unable to query revision number: %d\n", rc);
706 rc = ERROR_FUNCTION_FAILED;
711 package_code = msi_alloc( len * sizeof(WCHAR) );
712 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
713 NULL, NULL, package_code, &len );
714 if (rc != ERROR_SUCCESS)
716 WARN("Unable to query rev number: %d\n", rc);
720 MSI_SetPropertyW( package, szPackageCode, package_code );
721 msi_free( package_code );
723 /* load package attributes */
725 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
726 &count, NULL, NULL, NULL );
727 package->WordCount = count;
730 MsiCloseHandle(suminfo);
734 static MSIPACKAGE *msi_alloc_package( void )
738 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
742 list_init( &package->components );
743 list_init( &package->features );
744 list_init( &package->files );
745 list_init( &package->tempfiles );
746 list_init( &package->folders );
747 list_init( &package->subscriptions );
748 list_init( &package->appids );
749 list_init( &package->classes );
750 list_init( &package->mimes );
751 list_init( &package->extensions );
752 list_init( &package->progids );
753 list_init( &package->RunningActions );
754 list_init( &package->sourcelist_info );
755 list_init( &package->sourcelist_media );
757 package->patch = NULL;
758 package->ActionFormat = NULL;
759 package->LastAction = NULL;
760 package->dialog = NULL;
761 package->next_dialog = NULL;
762 package->scheduled_action_running = FALSE;
763 package->commit_action_running = FALSE;
764 package->rollback_action_running = FALSE;
770 static UINT msi_load_admin_properties(MSIPACKAGE *package)
775 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
777 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
778 if (r != ERROR_SUCCESS)
781 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
787 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
789 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
790 static const WCHAR szpi[] = {'%','i',0};
791 static const WCHAR szProductCode[] = {
792 'P','r','o','d','u','c','t','C','o','d','e',0};
799 package = msi_alloc_package();
802 msiobj_addref( &db->hdr );
805 package->WordCount = 0;
806 package->PackagePath = strdupW( db->path );
807 package->BaseURL = strdupW( base_url );
809 create_temp_property_table( package );
810 msi_clone_properties( package );
812 package->ProductCode = msi_dup_property( package, szProductCode );
813 set_installed_prop( package );
814 set_installer_properties( package );
816 sprintfW(uilevel,szpi,gUILevel);
817 MSI_SetPropertyW(package, szLevel, uilevel);
819 r = msi_load_summary_properties( package );
820 if (r != ERROR_SUCCESS)
822 msiobj_release( &package->hdr );
826 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
827 msi_load_admin_properties( package );
834 * copy_package_to_temp [internal]
836 * copy the msi file to a temp file to prevent locking a CD
837 * with a multi disc install
839 * FIXME: I think this is wrong, and instead of copying the package,
840 * we should read all the tables to memory, then open the
841 * database to read binary streams on demand.
843 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
845 WCHAR path[MAX_PATH];
846 static const WCHAR szMSI[] = {'m','s','i',0};
848 GetTempPathW( MAX_PATH, path );
849 GetTempFileNameW( path, szMSI, 0, filename );
851 if( !CopyFileW( szPackage, filename, FALSE ) )
853 DeleteFileW( filename );
854 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
858 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
862 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
864 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
868 /* call will always fail, becase size is 0,
869 * but will return ERROR_FILE_NOT_FOUND first
870 * if the file doesn't exist
872 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
873 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
875 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
876 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
878 HeapFree( GetProcessHeap(), 0, cache_entry );
882 lstrcpyW( filename, cache_entry->lpszLocalFileName );
883 HeapFree( GetProcessHeap(), 0, cache_entry );
887 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
894 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
896 static const WCHAR OriginalDatabase[] =
897 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
898 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
899 MSIDATABASE *db = NULL;
902 LPWSTR ptr, base_url = NULL;
904 WCHAR temppath[MAX_PATH];
905 LPCWSTR file = szPackage;
907 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
909 if( szPackage[0] == '#' )
911 handle = atoiW(&szPackage[1]);
912 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
915 IWineMsiRemoteDatabase *remote_database;
917 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
918 if ( !remote_database )
919 return ERROR_INVALID_HANDLE;
921 IWineMsiRemoteDatabase_Release( remote_database );
922 WARN("MsiOpenPackage not allowed during a custom action!\n");
924 return ERROR_FUNCTION_FAILED;
929 if ( UrlIsW( szPackage, URLIS_URL ) )
931 file = msi_download_file( szPackage, temppath );
933 base_url = strdupW( szPackage );
935 return ERROR_OUTOFMEMORY;
937 ptr = strrchrW( base_url, '/' );
938 if (ptr) *(ptr + 1) = '\0';
941 file = copy_package_to_temp( szPackage, temppath );
943 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
944 if( r != ERROR_SUCCESS )
946 if (file != szPackage)
949 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
950 return ERROR_FILE_NOT_FOUND;
956 package = MSI_CreatePackage( db, base_url );
957 msi_free( base_url );
958 msiobj_release( &db->hdr );
961 if (file != szPackage)
964 return ERROR_INSTALL_PACKAGE_INVALID;
967 if( file != szPackage )
968 track_tempfile( package, file );
970 MSI_SetPropertyW( package, Database, db->path );
972 if( UrlIsW( szPackage, URLIS_URL ) )
973 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
974 else if( szPackage[0] == '#' )
975 MSI_SetPropertyW( package, OriginalDatabase, db->path );
978 WCHAR fullpath[MAX_PATH];
980 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
981 MSI_SetPropertyW( package, OriginalDatabase, fullpath );
986 return ERROR_SUCCESS;
989 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
991 MSIPACKAGE *package = NULL;
994 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
996 if( !szPackage || !phPackage )
997 return ERROR_INVALID_PARAMETER;
1001 FIXME("Should create an empty database and package\n");
1002 return ERROR_FUNCTION_FAILED;
1006 FIXME("dwOptions %08x not supported\n", dwOptions);
1008 ret = MSI_OpenPackageW( szPackage, &package );
1009 if( ret == ERROR_SUCCESS )
1011 *phPackage = alloc_msihandle( &package->hdr );
1013 ret = ERROR_NOT_ENOUGH_MEMORY;
1014 msiobj_release( &package->hdr );
1020 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1022 return MsiOpenPackageExW( szPackage, 0, phPackage );
1025 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1027 LPWSTR szwPack = NULL;
1032 szwPack = strdupAtoW( szPackage );
1034 return ERROR_OUTOFMEMORY;
1037 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1039 msi_free( szwPack );
1044 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1046 return MsiOpenPackageExA( szPackage, 0, phPackage );
1049 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1051 MSIPACKAGE *package;
1052 MSIHANDLE handle = 0;
1053 IWineMsiRemotePackage *remote_package;
1055 TRACE("(%d)\n",hInstall);
1057 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1060 handle = alloc_msihandle( &package->db->hdr );
1061 msiobj_release( &package->hdr );
1063 else if ((remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall )))
1065 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1066 IWineMsiRemotePackage_Release(remote_package);
1072 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1075 static const WCHAR szActionData[] =
1076 {'A','c','t','i','o','n','D','a','t','a',0};
1077 static const WCHAR szSetProgress[] =
1078 {'S','e','t','P','r','o','g','r','e','s','s',0};
1079 static const WCHAR szActionText[] =
1080 {'A','c','t','i','o','n','T','e','x','t',0};
1084 DWORD total_size = 0;
1090 TRACE("%x\n", eMessageType);
1093 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1094 log_type |= INSTALLLOGMODE_ERROR;
1095 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1096 log_type |= INSTALLLOGMODE_WARNING;
1097 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1098 log_type |= INSTALLLOGMODE_USER;
1099 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1100 log_type |= INSTALLLOGMODE_INFO;
1101 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1102 log_type |= INSTALLLOGMODE_COMMONDATA;
1103 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1104 log_type |= INSTALLLOGMODE_ACTIONSTART;
1105 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1106 log_type |= INSTALLLOGMODE_ACTIONDATA;
1108 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1111 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1113 static const WCHAR template_s[]=
1114 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1115 static const WCHAR format[] =
1116 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1118 LPCWSTR action_text, action;
1119 LPWSTR deformatted = NULL;
1121 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1123 action = MSI_RecordGetString(record, 1);
1124 action_text = MSI_RecordGetString(record, 2);
1126 if (!action || !action_text)
1129 deformat_string(package, action_text, &deformatted);
1131 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1133 len += strlenW(deformatted);
1134 message = msi_alloc(len*sizeof(WCHAR));
1135 sprintfW(message, template_s, timet, action);
1137 strcatW(message, deformatted);
1138 msi_free(deformatted);
1143 message = msi_alloc(1*sizeof (WCHAR));
1145 msg_field = MSI_RecordGetFieldCount(record);
1146 for (i = 1; i <= msg_field; i++)
1150 static const WCHAR format[] = { '%','i',':',' ',0};
1151 static const WCHAR space[] = { ' ',0};
1153 MSI_RecordGetStringW(record,i,NULL,&sz);
1155 total_size+=sz*sizeof(WCHAR);
1156 tmp = msi_alloc(sz*sizeof(WCHAR));
1157 message = msi_realloc(message,total_size*sizeof (WCHAR));
1159 MSI_RecordGetStringW(record,i,tmp,&sz);
1163 sprintfW(number,format,i);
1164 strcatW(message,number);
1166 strcatW(message,tmp);
1168 strcatW(message,space);
1174 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
1175 debugstr_w(message));
1177 /* convert it to ASCII */
1178 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
1179 NULL, 0, NULL, NULL );
1180 msg = msi_alloc( len );
1181 WideCharToMultiByte( CP_ACP, 0, message, -1,
1182 msg, len, NULL, NULL );
1184 if (gUIHandlerA && (gUIFilter & log_type))
1186 rc = gUIHandlerA(gUIContext,eMessageType,msg);
1189 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
1190 INSTALLMESSAGE_PROGRESS))
1193 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
1194 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1196 if (log_file != INVALID_HANDLE_VALUE)
1198 SetFilePointer(log_file,0, NULL, FILE_END);
1199 WriteFile(log_file,msg,strlen(msg),&write,NULL);
1200 WriteFile(log_file,"\n",1,&write,NULL);
1201 CloseHandle(log_file);
1208 switch (eMessageType & 0xff000000)
1210 case INSTALLMESSAGE_ACTIONDATA:
1211 /* FIXME: format record here instead of in ui_actiondata to get the
1212 * correct action data for external scripts */
1213 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1215 case INSTALLMESSAGE_ACTIONSTART:
1219 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1221 deformat_string(package, action_text, &deformated);
1222 uirow = MSI_CreateRecord(1);
1223 MSI_RecordSetStringW(uirow, 1, deformated);
1224 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1225 msi_free(deformated);
1227 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1229 msiobj_release(&uirow->hdr);
1232 case INSTALLMESSAGE_PROGRESS:
1233 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1237 return ERROR_SUCCESS;
1240 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1243 UINT ret = ERROR_INVALID_HANDLE;
1244 MSIPACKAGE *package = NULL;
1245 MSIRECORD *record = NULL;
1247 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1251 IWineMsiRemotePackage *remote_package;
1253 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1254 if (!remote_package)
1255 return ERROR_INVALID_HANDLE;
1257 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1259 IWineMsiRemotePackage_Release( remote_package );
1263 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1264 return HRESULT_CODE(hr);
1266 return ERROR_FUNCTION_FAILED;
1269 return ERROR_SUCCESS;
1272 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1276 ret = MSI_ProcessMessage( package, eMessageType, record );
1279 msiobj_release( &package->hdr );
1281 msiobj_release( &record->hdr );
1288 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1290 LPWSTR szwName = NULL, szwValue = NULL;
1291 UINT r = ERROR_OUTOFMEMORY;
1293 szwName = strdupAtoW( szName );
1294 if( szName && !szwName )
1297 szwValue = strdupAtoW( szValue );
1298 if( szValue && !szwValue )
1301 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1304 msi_free( szwName );
1305 msi_free( szwValue );
1310 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
1313 MSIRECORD *row = NULL;
1318 static const WCHAR Insert[] = {
1319 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1320 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1321 '`','_','P','r','o','p','e','r','t','y','`',',',
1322 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1323 ,' ','(','?',',','?',')',0};
1324 static const WCHAR Update[] = {
1325 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1326 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1327 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1328 ' ','=',' ','\'','%','s','\'',0};
1329 static const WCHAR Delete[] = {
1330 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1331 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1332 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1334 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
1337 return ERROR_INVALID_PARAMETER;
1339 /* this one is weird... */
1341 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1343 rc = MSI_GetPropertyW(package, szName, 0, &sz);
1344 if (!szValue || !*szValue)
1346 sprintfW(Query, Delete, szName);
1348 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1350 sprintfW(Query, Update, szName);
1352 row = MSI_CreateRecord(1);
1353 MSI_RecordSetStringW(row, 1, szValue);
1357 strcpyW(Query, Insert);
1359 row = MSI_CreateRecord(2);
1360 MSI_RecordSetStringW(row, 1, szName);
1361 MSI_RecordSetStringW(row, 2, szValue);
1364 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1365 if (rc == ERROR_SUCCESS)
1367 rc = MSI_ViewExecute(view, row);
1368 MSI_ViewClose(view);
1369 msiobj_release(&view->hdr);
1373 msiobj_release(&row->hdr);
1375 if (rc == ERROR_SUCCESS && (!lstrcmpW(szName, cszSourceDir)))
1376 msi_reset_folders(package, TRUE);
1381 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1383 MSIPACKAGE *package;
1386 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1390 BSTR name = NULL, value = NULL;
1391 IWineMsiRemotePackage *remote_package;
1393 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1394 if (!remote_package)
1395 return ERROR_INVALID_HANDLE;
1397 name = SysAllocString( szName );
1398 value = SysAllocString( szValue );
1399 if ((!name && szName) || (!value && szValue))
1401 SysFreeString( name );
1402 SysFreeString( value );
1403 IWineMsiRemotePackage_Release( remote_package );
1404 return ERROR_OUTOFMEMORY;
1407 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
1409 SysFreeString( name );
1410 SysFreeString( value );
1411 IWineMsiRemotePackage_Release( remote_package );
1415 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1416 return HRESULT_CODE(hr);
1418 return ERROR_FUNCTION_FAILED;
1421 return ERROR_SUCCESS;
1424 ret = MSI_SetPropertyW( package, szName, szValue);
1425 msiobj_release( &package->hdr );
1429 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
1432 MSIRECORD *rec, *row = NULL;
1435 static const WCHAR query[]= {
1436 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1437 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1438 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1441 if (!name || !*name)
1444 rec = MSI_CreateRecord(1);
1448 MSI_RecordSetStringW(rec, 1, name);
1450 r = MSI_DatabaseOpenViewW(package->db, query, &view);
1451 if (r == ERROR_SUCCESS)
1453 MSI_ViewExecute(view, rec);
1454 MSI_ViewFetch(view, &row);
1455 MSI_ViewClose(view);
1456 msiobj_release(&view->hdr);
1459 msiobj_release(&rec->hdr);
1463 /* internal function, not compatible with MsiGetPropertyW */
1464 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
1465 LPWSTR szValueBuf, LPDWORD pchValueBuf )
1468 UINT rc = ERROR_FUNCTION_FAILED;
1470 row = MSI_GetPropertyRow( package, szName );
1472 if (*pchValueBuf > 0)
1477 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
1478 msiobj_release(&row->hdr);
1481 if (rc == ERROR_SUCCESS)
1482 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
1483 debugstr_w(szName));
1484 else if (rc == ERROR_MORE_DATA)
1485 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
1486 debugstr_w(szName));
1490 TRACE("property %s not found\n", debugstr_w(szName));
1496 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
1502 r = MSI_GetPropertyW(package, prop, NULL, &sz);
1503 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
1507 str = msi_alloc(sz * sizeof(WCHAR));
1508 r = MSI_GetPropertyW(package, prop, str, &sz);
1509 if (r != ERROR_SUCCESS)
1518 int msi_get_property_int(MSIPACKAGE *package, LPCWSTR prop, int def)
1520 LPWSTR str = msi_dup_property(package, prop);
1521 int val = str ? atoiW(str) : def;
1526 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1527 awstring *szValueBuf, LPDWORD pchValueBuf )
1529 static const WCHAR empty[] = {0};
1530 MSIPACKAGE *package;
1531 MSIRECORD *row = NULL;
1532 UINT r = ERROR_FUNCTION_FAILED;
1535 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
1536 szValueBuf->str.w, pchValueBuf );
1539 return ERROR_INVALID_PARAMETER;
1541 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1545 IWineMsiRemotePackage *remote_package;
1546 LPWSTR value = NULL;
1550 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
1551 if (!remote_package)
1552 return ERROR_INVALID_HANDLE;
1554 bname = SysAllocString( name );
1557 IWineMsiRemotePackage_Release( remote_package );
1558 return ERROR_OUTOFMEMORY;
1562 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
1567 value = msi_alloc(len * sizeof(WCHAR));
1570 r = ERROR_OUTOFMEMORY;
1574 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
1578 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
1580 /* Bug required by Adobe installers */
1581 if (!szValueBuf->unicode && !szValueBuf->str.a)
1582 *pchValueBuf *= sizeof(WCHAR);
1585 IWineMsiRemotePackage_Release(remote_package);
1586 SysFreeString(bname);
1591 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1592 return HRESULT_CODE(hr);
1594 return ERROR_FUNCTION_FAILED;
1600 row = MSI_GetPropertyRow( package, name );
1602 val = MSI_RecordGetString( row, 1 );
1607 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1610 msiobj_release( &row->hdr );
1611 msiobj_release( &package->hdr );
1616 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1617 LPSTR szValueBuf, LPDWORD pchValueBuf )
1623 val.unicode = FALSE;
1624 val.str.a = szValueBuf;
1626 name = strdupAtoW( szName );
1627 if (szName && !name)
1628 return ERROR_OUTOFMEMORY;
1630 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1635 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1636 LPWSTR szValueBuf, LPDWORD pchValueBuf )
1641 val.str.w = szValueBuf;
1643 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
1646 typedef struct _msi_remote_package_impl {
1647 const IWineMsiRemotePackageVtbl *lpVtbl;
1650 } msi_remote_package_impl;
1652 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
1654 return (msi_remote_package_impl*) iface;
1657 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
1658 REFIID riid,LPVOID *ppobj)
1660 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1661 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
1663 IUnknown_AddRef( iface );
1668 return E_NOINTERFACE;
1671 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
1673 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1675 return InterlockedIncrement( &This->refs );
1678 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
1680 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1683 r = InterlockedDecrement( &This->refs );
1686 MsiCloseHandle( This->package );
1692 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
1694 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1695 This->package = handle;
1699 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
1701 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1702 IWineMsiRemoteDatabase *rdb = NULL;
1706 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
1707 if (FAILED(hr) || !rdb)
1709 ERR("Failed to create remote database\n");
1713 hdb = MsiGetActiveDatabase(This->package);
1715 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
1718 ERR("Failed to set the database handle\n");
1722 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
1726 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
1728 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1731 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
1732 if (r != ERROR_SUCCESS)
1733 return HRESULT_FROM_WIN32(r);
1738 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
1740 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1741 UINT r = MsiSetPropertyW(This->package, property, value);
1742 return HRESULT_FROM_WIN32(r);
1745 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
1747 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1748 UINT r = MsiProcessMessage(This->package, message, record);
1749 return HRESULT_FROM_WIN32(r);
1752 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
1754 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1755 UINT r = MsiDoActionW(This->package, action);
1756 return HRESULT_FROM_WIN32(r);
1759 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
1761 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1762 UINT r = MsiSequenceW(This->package, table, sequence);
1763 return HRESULT_FROM_WIN32(r);
1766 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1768 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1769 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1770 return HRESULT_FROM_WIN32(r);
1773 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
1775 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1776 UINT r = MsiSetTargetPathW(This->package, folder, value);
1777 return HRESULT_FROM_WIN32(r);
1780 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1782 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1783 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1784 return HRESULT_FROM_WIN32(r);
1787 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
1789 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1790 *ret = MsiGetMode(This->package, mode);
1794 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
1795 INSTALLSTATE *installed, INSTALLSTATE *action )
1797 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1798 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
1799 return HRESULT_FROM_WIN32(r);
1802 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
1804 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1805 UINT r = MsiSetFeatureStateW(This->package, feature, state);
1806 return HRESULT_FROM_WIN32(r);
1809 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
1810 INSTALLSTATE *installed, INSTALLSTATE *action )
1812 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1813 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
1814 return HRESULT_FROM_WIN32(r);
1817 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
1819 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1820 UINT r = MsiSetComponentStateW(This->package, component, state);
1821 return HRESULT_FROM_WIN32(r);
1824 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
1826 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1827 *language = MsiGetLanguage(This->package);
1831 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
1833 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1834 UINT r = MsiSetInstallLevel(This->package, level);
1835 return HRESULT_FROM_WIN32(r);
1838 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
1842 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1843 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
1844 if (r == ERROR_SUCCESS)
1846 *value = SysAllocStringLen(NULL, size);
1848 return E_OUTOFMEMORY;
1850 r = MsiFormatRecordW(This->package, record, *value, &size);
1852 return HRESULT_FROM_WIN32(r);
1855 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
1857 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1858 UINT r = MsiEvaluateConditionW(This->package, condition);
1859 return HRESULT_FROM_WIN32(r);
1862 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
1868 mrp_GetActiveDatabase,
1878 mrp_GetFeatureState,
1879 mrp_SetFeatureState,
1880 mrp_GetComponentState,
1881 mrp_SetComponentState,
1883 mrp_SetInstallLevel,
1885 mrp_EvaluateCondition,
1888 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
1890 msi_remote_package_impl* This;
1892 This = msi_alloc( sizeof *This );
1894 return E_OUTOFMEMORY;
1896 This->lpVtbl = &msi_remote_package_vtbl;
1905 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
1906 LPCWSTR property, LPWSTR value)
1908 MSISOURCELISTINFO *info;
1910 info = msi_alloc(sizeof(MSISOURCELISTINFO));
1912 return ERROR_OUTOFMEMORY;
1914 info->context = context;
1915 info->options = options;
1916 info->property = property;
1917 info->value = strdupW(value);
1918 list_add_head(&package->sourcelist_info, &info->entry);
1920 return ERROR_SUCCESS;
1923 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
1924 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
1928 disk = msi_alloc(sizeof(MSIMEDIADISK));
1930 return ERROR_OUTOFMEMORY;
1932 disk->context = context;
1933 disk->options = options;
1934 disk->disk_id = disk_id;
1935 disk->volume_label = strdupW(volume_label);
1936 disk->disk_prompt = strdupW(disk_prompt);
1937 list_add_head(&package->sourcelist_media, &disk->entry);
1939 return ERROR_SUCCESS;