2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
42 #include "wine/unicode.h"
48 #include "msiserver.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 static void MSI_FreePackage( MSIOBJECTHDR *arg)
54 MSIPACKAGE *package= (MSIPACKAGE*) arg;
57 msi_dialog_destroy( package->dialog );
59 msiobj_release( &package->db->hdr );
60 ACTION_free_package_structures(package);
63 static UINT create_temp_property_table(MSIPACKAGE *package)
65 MSIQUERY *view = NULL;
68 static const WCHAR CreateSql[] = {
69 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
70 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
71 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
72 'L','L',' ','T','E','M','P','O','R','A','R','Y',',',' ','`','V','a','l',
73 'u','e','`',' ','C','H','A','R','(','9','8',')',' ','N','O','T',' ','N',
74 'U','L','L',' ','T','E','M','P','O','R','A','R','Y',' ','P','R','I','M',
75 'A','R','Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y',
78 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
79 if (rc != ERROR_SUCCESS)
82 rc = MSI_ViewExecute(view, 0);
84 msiobj_release(&view->hdr);
88 UINT msi_clone_properties(MSIPACKAGE *package)
90 MSIQUERY *view = NULL;
93 static const WCHAR Query[] = {
94 'S','E','L','E','C','T',' ','*',' ',
95 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
96 static const WCHAR Insert[] = {
97 'I','N','S','E','R','T',' ','i','n','t','o',' ',
98 '`','_','P','r','o','p','e','r','t','y','`',' ',
99 '(','`','_','P','r','o','p','e','r','t','y','`',',',
100 '`','V','a','l','u','e','`',')',' ',
101 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
103 /* clone the existing properties */
104 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
105 if (rc != ERROR_SUCCESS)
108 rc = MSI_ViewExecute(view, 0);
109 if (rc != ERROR_SUCCESS)
112 msiobj_release(&view->hdr);
121 rc = MSI_ViewFetch(view, &row);
122 if (rc != ERROR_SUCCESS)
125 rc = MSI_DatabaseOpenViewW(package->db, Insert, &view2);
126 if (rc!= ERROR_SUCCESS)
129 rc = MSI_ViewExecute(view2, row);
130 MSI_ViewClose(view2);
131 msiobj_release(&view2->hdr);
133 if (rc == ERROR_SUCCESS)
134 msiobj_release(&row->hdr);
138 msiobj_release(&view->hdr);
146 * Sets the "Installed" property to indicate that
147 * the product is installed for the current user.
149 static UINT set_installed_prop( MSIPACKAGE *package )
151 static const WCHAR szInstalled[] = {
152 'I','n','s','t','a','l','l','e','d',0 };
153 WCHAR val[2] = { '1', 0 };
157 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
158 if (r == ERROR_SUCCESS)
161 MSI_SetPropertyW( package, szInstalled, val );
167 static UINT set_user_sid_prop( MSIPACKAGE *package )
171 LPWSTR sid_str = NULL, dom = NULL;
172 DWORD size, dom_size;
174 UINT r = ERROR_FUNCTION_FAILED;
176 static const WCHAR user_sid[] = {'U','s','e','r','S','I','D',0};
179 GetUserNameW( NULL, &size );
181 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
183 return ERROR_OUTOFMEMORY;
185 if (!GetUserNameW( user_name, &size ))
190 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
192 psid = msi_alloc( size );
193 dom = msi_alloc( dom_size*sizeof (WCHAR) );
196 r = ERROR_OUTOFMEMORY;
200 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
203 if (!ConvertSidToStringSidW( psid, &sid_str ))
206 r = MSI_SetPropertyW( package, user_sid, sid_str );
209 LocalFree( sid_str );
212 msi_free( user_name );
217 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
222 DWORD index = 0, size;
224 WCHAR name[MAX_PATH];
225 WCHAR windir[MAX_PATH];
227 static const WCHAR backslash[] = {'\\',0};
228 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
229 static const WCHAR sub[] = {
230 'S','o','f','t','w','a','r','e','\\',
231 'M','i','c','r','o','s','o','f','t','\\',
232 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
235 static const WCHAR subdir[] = {
236 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
237 'F','r','a','m','e','w','o','r','k','\\',0
240 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
241 if (res != ERROR_SUCCESS)
246 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
249 if (lstrcmpW(ver, name) < 0)
253 RegCloseKey(netsetup);
258 GetWindowsDirectoryW(windir, MAX_PATH);
260 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(ver) +lstrlenW(fusion) + 3;
261 file = msi_alloc(size * sizeof(WCHAR));
265 lstrcpyW(file, windir);
266 lstrcatW(file, backslash);
267 lstrcatW(file, subdir);
269 lstrcatW(file, backslash);
270 lstrcatW(file, fusion);
275 typedef struct tagLANGANDCODEPAGE
281 static void set_msi_assembly_prop(MSIPACKAGE *package)
285 LPVOID version = NULL;
287 LPWSTR fusion, verstr;
288 LANGANDCODEPAGE *translate;
290 static const WCHAR netasm[] = {
291 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
293 static const WCHAR translation[] = {
294 '\\','V','a','r','F','i','l','e','I','n','f','o',
295 '\\','T','r','a','n','s','l','a','t','i','o','n',0
297 static const WCHAR verfmt[] = {
298 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
299 '\\','%','0','4','x','%','0','4','x',
300 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
303 fusion = get_fusion_filename(package);
307 size = GetFileVersionInfoSizeW(fusion, &handle);
310 version = msi_alloc(size);
311 if (!version) return;
313 if (!GetFileVersionInfoW(fusion, handle, size, version))
316 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
319 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
321 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
324 if (!val_len || !verstr)
327 MSI_SetPropertyW(package, netasm, verstr);
335 * There are a whole slew of these we need to set
338 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
340 static VOID set_installer_properties(MSIPACKAGE *package)
344 OSVERSIONINFOEXW OSVersion;
347 WCHAR verstr[10], bufstr[20];
352 SYSTEM_INFO sys_info;
353 SYSTEMTIME systemtime;
355 static const WCHAR cszbs[]={'\\',0};
356 static const WCHAR CFF[] =
357 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
358 static const WCHAR PFF[] =
359 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
360 static const WCHAR CADF[] =
361 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
362 static const WCHAR FaF[] =
363 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
364 static const WCHAR FoF[] =
365 {'F','o','n','t','s','F','o','l','d','e','r',0};
366 static const WCHAR SendTF[] =
367 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
368 static const WCHAR SMF[] =
369 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
370 static const WCHAR StF[] =
371 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
372 static const WCHAR TemplF[] =
373 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
374 static const WCHAR DF[] =
375 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
376 static const WCHAR PMF[] =
377 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
378 static const WCHAR ATF[] =
379 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
380 static const WCHAR ADF[] =
381 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
382 static const WCHAR SF[] =
383 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
384 static const WCHAR SF16[] =
385 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
386 static const WCHAR LADF[] =
387 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
388 static const WCHAR MPF[] =
389 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
390 static const WCHAR PF[] =
391 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
392 static const WCHAR WF[] =
393 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
394 static const WCHAR WV[] =
395 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
396 static const WCHAR TF[]=
397 {'T','e','m','p','F','o','l','d','e','r',0};
398 static const WCHAR szAdminUser[] =
399 {'A','d','m','i','n','U','s','e','r',0};
400 static const WCHAR szPriv[] =
401 {'P','r','i','v','i','l','e','g','e','d',0};
402 static const WCHAR szOne[] =
404 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
405 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
406 static const WCHAR szMsiNTProductType[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
407 static const WCHAR szFormat[] = {'%','l','i',0};
408 static const WCHAR szWinBuild[] =
409 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
410 static const WCHAR szSPL[] =
411 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
412 static const WCHAR szSix[] = {'6',0 };
414 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
415 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
416 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
417 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
418 /* Screen properties */
419 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
420 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
421 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
422 static const WCHAR szScreenFormat[] = {'%','d',0};
423 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
424 static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
425 static const WCHAR szCurrentVersion[] = {
426 'S','O','F','T','W','A','R','E','\\',
427 'M','i','c','r','o','s','o','f','t','\\',
428 'W','i','n','d','o','w','s',' ','N','T','\\',
429 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
431 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
432 static const WCHAR szRegisteredOrg[] = {
433 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
435 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
436 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
437 static const WCHAR szDate[] = {'D','a','t','e',0};
438 static const WCHAR szTime[] = {'T','i','m','e',0};
441 * Other things that probably should be set:
443 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
444 * ShellAdvSupport DefaultUIFont PackagecodeChanging
445 * ProductState CaptionHeight BorderTop BorderSide TextHeight
446 * RedirectedDllSupport
449 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
451 MSI_SetPropertyW(package, CFF, pth);
453 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
455 MSI_SetPropertyW(package, PFF, pth);
457 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
459 MSI_SetPropertyW(package, CADF, pth);
461 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
463 MSI_SetPropertyW(package, FaF, pth);
465 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
467 MSI_SetPropertyW(package, FoF, pth);
469 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
471 MSI_SetPropertyW(package, SendTF, pth);
473 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
475 MSI_SetPropertyW(package, SMF, pth);
477 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
479 MSI_SetPropertyW(package, StF, pth);
481 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
483 MSI_SetPropertyW(package, TemplF, pth);
485 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
487 MSI_SetPropertyW(package, DF, pth);
489 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
491 MSI_SetPropertyW(package, PMF, pth);
493 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
495 MSI_SetPropertyW(package, ATF, pth);
497 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
499 MSI_SetPropertyW(package, ADF, pth);
501 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
503 MSI_SetPropertyW(package, SF, pth);
504 MSI_SetPropertyW(package, SF16, pth);
506 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
508 MSI_SetPropertyW(package, LADF, pth);
510 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
512 MSI_SetPropertyW(package, MPF, pth);
514 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
516 MSI_SetPropertyW(package, PF, pth);
518 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
520 MSI_SetPropertyW(package, WF, pth);
522 /* Physical Memory is specified in MB. Using total amount. */
523 msex.dwLength = sizeof(msex);
524 GlobalMemoryStatusEx( &msex );
525 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
526 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
528 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
529 ptr = strchrW(pth,'\\');
532 MSI_SetPropertyW(package, WV, pth);
534 GetTempPathW(MAX_PATH,pth);
535 MSI_SetPropertyW(package, TF, pth);
538 /* in a wine environment the user is always admin and privileged */
539 MSI_SetPropertyW(package,szAdminUser,szOne);
540 MSI_SetPropertyW(package,szPriv,szOne);
541 MSI_SetPropertyW(package, szAllUsers, szOne);
543 /* set the os things */
544 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
545 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
546 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
547 sprintfW(verstr,szFormat,verval);
548 switch (OSVersion.dwPlatformId)
550 case VER_PLATFORM_WIN32_WINDOWS:
551 MSI_SetPropertyW(package,v9x,verstr);
553 case VER_PLATFORM_WIN32_NT:
554 MSI_SetPropertyW(package,vNT,verstr);
555 sprintfW(verstr,szFormat,OSVersion.wProductType);
556 MSI_SetPropertyW(package,szMsiNTProductType,verstr);
559 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
560 MSI_SetPropertyW(package,szWinBuild,verstr);
561 /* just fudge this */
562 MSI_SetPropertyW(package,szSPL,szSix);
564 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
565 MSI_SetPropertyW( package, szVersionMsi, bufstr );
566 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
567 MSI_SetPropertyW( package, szVersionDatabase, bufstr );
569 GetSystemInfo( &sys_info );
570 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
572 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
573 MSI_SetPropertyW( package, szIntel, bufstr );
576 /* Screen properties. */
578 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
579 MSI_SetPropertyW( package, szScreenX, bufstr );
580 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
581 MSI_SetPropertyW( package, szScreenY, bufstr );
582 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
583 MSI_SetPropertyW( package, szColorBits, bufstr );
586 /* USERNAME and COMPANYNAME */
587 res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
588 if (res != ERROR_SUCCESS)
591 check = msi_dup_property( package, szUSERNAME );
594 LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
595 MSI_SetPropertyW( package, szUSERNAME, user );
601 check = msi_dup_property( package, szCOMPANYNAME );
604 LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
605 MSI_SetPropertyW( package, szCOMPANYNAME, company );
609 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
610 ERR("Failed to set the UserSID property\n");
612 /* Date and time properties */
613 GetSystemTime( &systemtime );
614 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
615 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
616 MSI_SetPropertyW( package, szDate, bufstr );
618 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
620 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
621 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
622 &systemtime, NULL, bufstr,
623 sizeof(bufstr)/sizeof(bufstr[0]) ))
624 MSI_SetPropertyW( package, szTime, bufstr );
626 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
628 set_msi_assembly_prop( package );
634 static UINT msi_load_summary_properties( MSIPACKAGE *package )
638 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
642 static const WCHAR szPackageCode[] = {
643 'P','a','c','k','a','g','e','C','o','d','e',0};
646 ERR("Unable to allocate handle\n");
649 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
651 if (rc != ERROR_SUCCESS)
653 ERR("Unable to open Summary Information\n");
657 /* load package attributes */
658 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
659 &word_count, NULL, NULL, NULL );
660 if (rc == ERROR_SUCCESS)
661 package->WordCount = word_count;
663 WARN("Unable to query word count\n");
665 /* load package code property */
667 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
668 NULL, NULL, NULL, &len );
669 if (rc == ERROR_MORE_DATA)
672 package_code = msi_alloc( len * sizeof(WCHAR) );
673 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
674 NULL, NULL, package_code, &len );
675 if (rc == ERROR_SUCCESS)
676 MSI_SetPropertyW( package, szPackageCode, package_code );
678 WARN("Unable to query rev number, %d\n", rc);
679 msi_free( package_code );
682 WARN("Unable to query rev number, %d\n", rc);
684 MsiCloseHandle(suminfo);
685 return ERROR_SUCCESS;
688 static MSIPACKAGE *msi_alloc_package( void )
692 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
696 list_init( &package->components );
697 list_init( &package->features );
698 list_init( &package->files );
699 list_init( &package->tempfiles );
700 list_init( &package->folders );
701 list_init( &package->subscriptions );
702 list_init( &package->appids );
703 list_init( &package->classes );
704 list_init( &package->mimes );
705 list_init( &package->extensions );
706 list_init( &package->progids );
707 list_init( &package->RunningActions );
708 list_init( &package->sourcelist_info );
709 list_init( &package->sourcelist_media );
711 package->ActionFormat = NULL;
712 package->LastAction = NULL;
713 package->dialog = NULL;
714 package->next_dialog = NULL;
715 package->scheduled_action_running = FALSE;
716 package->commit_action_running = FALSE;
717 package->rollback_action_running = FALSE;
723 static UINT msi_load_admin_properties(MSIPACKAGE *package)
728 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
730 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
731 if (r != ERROR_SUCCESS)
734 r = msi_parse_command_line(package, (WCHAR *)data);
740 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
742 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
743 static const WCHAR szpi[] = {'%','i',0};
744 static const WCHAR szProductCode[] = {
745 'P','r','o','d','u','c','t','C','o','d','e',0};
751 package = msi_alloc_package();
754 msiobj_addref( &db->hdr );
757 package->WordCount = 0;
758 package->PackagePath = strdupW( db->path );
759 package->BaseURL = strdupW( base_url );
761 create_temp_property_table( package );
762 msi_clone_properties( package );
763 set_installer_properties(package);
764 sprintfW(uilevel,szpi,gUILevel);
765 MSI_SetPropertyW(package, szLevel, uilevel);
767 package->ProductCode = msi_dup_property( package, szProductCode );
768 set_installed_prop( package );
769 msi_load_summary_properties( package );
771 if (package->WordCount & MSIWORDCOUNT_ADMINISTRATIVE)
772 msi_load_admin_properties( package );
779 * copy_package_to_temp [internal]
781 * copy the msi file to a temp file to prevent locking a CD
782 * with a multi disc install
784 * FIXME: I think this is wrong, and instead of copying the package,
785 * we should read all the tables to memory, then open the
786 * database to read binary streams on demand.
788 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
790 WCHAR path[MAX_PATH];
791 static const WCHAR szMSI[] = {'m','s','i',0};
793 GetTempPathW( MAX_PATH, path );
794 GetTempFileNameW( path, szMSI, 0, filename );
796 if( !CopyFileW( szPackage, filename, FALSE ) )
798 DeleteFileW( filename );
799 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
803 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
807 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
809 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
813 /* call will always fail, becase size is 0,
814 * but will return ERROR_FILE_NOT_FOUND first
815 * if the file doesn't exist
817 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
818 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
820 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
821 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
823 HeapFree( GetProcessHeap(), 0, cache_entry );
827 lstrcpyW( filename, cache_entry->lpszLocalFileName );
828 HeapFree( GetProcessHeap(), 0, cache_entry );
832 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
839 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
841 static const WCHAR OriginalDatabase[] =
842 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
843 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
844 MSIDATABASE *db = NULL;
847 LPWSTR ptr, base_url = NULL;
849 WCHAR temppath[MAX_PATH];
850 LPCWSTR file = szPackage;
852 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
854 if( szPackage[0] == '#' )
856 handle = atoiW(&szPackage[1]);
857 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
859 return ERROR_INVALID_HANDLE;
863 if ( UrlIsW( szPackage, URLIS_URL ) )
865 file = msi_download_file( szPackage, temppath );
867 base_url = strdupW( szPackage );
869 return ERROR_OUTOFMEMORY;
871 ptr = strrchrW( base_url, '/' );
872 if (ptr) *(ptr + 1) = '\0';
875 file = copy_package_to_temp( szPackage, temppath );
877 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
878 if( r != ERROR_SUCCESS )
880 if (GetLastError() == ERROR_FILE_NOT_FOUND)
881 msi_ui_error( 4, MB_OK | MB_ICONWARNING );
882 if (file != szPackage)
889 package = MSI_CreatePackage( db, base_url );
890 msi_free( base_url );
891 msiobj_release( &db->hdr );
894 if (file != szPackage)
896 return ERROR_FUNCTION_FAILED;
899 if( file != szPackage )
900 track_tempfile( package, file );
902 if( szPackage[0] != '#' )
904 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
905 MSI_SetPropertyW( package, Database, szPackage );
909 MSI_SetPropertyW( package, OriginalDatabase, db->path );
910 MSI_SetPropertyW( package, Database, db->path );
915 return ERROR_SUCCESS;
918 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
920 MSIPACKAGE *package = NULL;
923 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
925 if( szPackage == NULL )
926 return ERROR_INVALID_PARAMETER;
929 FIXME("dwOptions %08x not supported\n", dwOptions);
931 ret = MSI_OpenPackageW( szPackage, &package );
932 if( ret == ERROR_SUCCESS )
934 *phPackage = alloc_msihandle( &package->hdr );
936 ret = ERROR_NOT_ENOUGH_MEMORY;
937 msiobj_release( &package->hdr );
943 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
945 return MsiOpenPackageExW( szPackage, 0, phPackage );
948 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
950 LPWSTR szwPack = NULL;
955 szwPack = strdupAtoW( szPackage );
957 return ERROR_OUTOFMEMORY;
960 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
967 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
969 return MsiOpenPackageExA( szPackage, 0, phPackage );
972 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
975 MSIHANDLE handle = 0;
976 IWineMsiRemotePackage *remote_package;
978 TRACE("(%ld)\n",hInstall);
980 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
983 handle = alloc_msihandle( &package->db->hdr );
984 msiobj_release( &package->hdr );
986 else if ((remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall )))
988 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
989 IWineMsiRemotePackage_Release(remote_package);
995 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
998 static const WCHAR szActionData[] =
999 {'A','c','t','i','o','n','D','a','t','a',0};
1000 static const WCHAR szSetProgress[] =
1001 {'S','e','t','P','r','o','g','r','e','s','s',0};
1002 static const WCHAR szActionText[] =
1003 {'A','c','t','i','o','n','T','e','x','t',0};
1007 DWORD total_size = 0;
1013 TRACE("%x\n", eMessageType);
1016 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1017 log_type |= INSTALLLOGMODE_ERROR;
1018 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1019 log_type |= INSTALLLOGMODE_WARNING;
1020 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1021 log_type |= INSTALLLOGMODE_USER;
1022 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1023 log_type |= INSTALLLOGMODE_INFO;
1024 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1025 log_type |= INSTALLLOGMODE_COMMONDATA;
1026 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1027 log_type |= INSTALLLOGMODE_ACTIONSTART;
1028 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1029 log_type |= INSTALLLOGMODE_ACTIONDATA;
1031 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1034 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1036 static const WCHAR template_s[]=
1037 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1038 static const WCHAR format[] =
1039 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1041 LPCWSTR action_text, action;
1042 LPWSTR deformatted = NULL;
1044 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1046 action = MSI_RecordGetString(record, 1);
1047 action_text = MSI_RecordGetString(record, 2);
1049 if (!action || !action_text)
1052 deformat_string(package, action_text, &deformatted);
1054 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1056 len += strlenW(deformatted);
1057 message = msi_alloc(len*sizeof(WCHAR));
1058 sprintfW(message, template_s, timet, action);
1060 strcatW(message, deformatted);
1061 msi_free(deformatted);
1066 message = msi_alloc(1*sizeof (WCHAR));
1068 msg_field = MSI_RecordGetFieldCount(record);
1069 for (i = 1; i <= msg_field; i++)
1073 static const WCHAR format[] = { '%','i',':',' ',0};
1074 static const WCHAR space[] = { ' ',0};
1076 MSI_RecordGetStringW(record,i,NULL,&sz);
1078 total_size+=sz*sizeof(WCHAR);
1079 tmp = msi_alloc(sz*sizeof(WCHAR));
1080 message = msi_realloc(message,total_size*sizeof (WCHAR));
1082 MSI_RecordGetStringW(record,i,tmp,&sz);
1086 sprintfW(number,format,i);
1087 strcatW(message,number);
1089 strcatW(message,tmp);
1091 strcatW(message,space);
1097 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
1098 debugstr_w(message));
1100 /* convert it to ASCII */
1101 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
1102 NULL, 0, NULL, NULL );
1103 msg = msi_alloc( len );
1104 WideCharToMultiByte( CP_ACP, 0, message, -1,
1105 msg, len, NULL, NULL );
1107 if (gUIHandlerA && (gUIFilter & log_type))
1109 rc = gUIHandlerA(gUIContext,eMessageType,msg);
1112 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
1113 INSTALLMESSAGE_PROGRESS))
1116 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
1117 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1119 if (log_file != INVALID_HANDLE_VALUE)
1121 SetFilePointer(log_file,0, NULL, FILE_END);
1122 WriteFile(log_file,msg,strlen(msg),&write,NULL);
1123 WriteFile(log_file,"\n",1,&write,NULL);
1124 CloseHandle(log_file);
1131 switch (eMessageType & 0xff000000)
1133 case INSTALLMESSAGE_ACTIONDATA:
1134 /* FIXME: format record here instead of in ui_actiondata to get the
1135 * correct action data for external scripts */
1136 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1138 case INSTALLMESSAGE_ACTIONSTART:
1142 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1144 deformat_string(package, action_text, &deformated);
1145 uirow = MSI_CreateRecord(1);
1146 MSI_RecordSetStringW(uirow, 1, deformated);
1147 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1148 msi_free(deformated);
1150 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1152 msiobj_release(&uirow->hdr);
1155 case INSTALLMESSAGE_PROGRESS:
1156 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1160 return ERROR_SUCCESS;
1163 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1166 UINT ret = ERROR_INVALID_HANDLE;
1167 MSIPACKAGE *package = NULL;
1168 MSIRECORD *record = NULL;
1170 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1174 IWineMsiRemotePackage *remote_package;
1176 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1177 if (!remote_package)
1178 return ERROR_INVALID_HANDLE;
1180 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1182 IWineMsiRemotePackage_Release( remote_package );
1186 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1187 return HRESULT_CODE(hr);
1189 return ERROR_FUNCTION_FAILED;
1192 return ERROR_SUCCESS;
1195 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1199 ret = MSI_ProcessMessage( package, eMessageType, record );
1202 msiobj_release( &package->hdr );
1204 msiobj_release( &record->hdr );
1211 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1213 LPWSTR szwName = NULL, szwValue = NULL;
1214 UINT r = ERROR_OUTOFMEMORY;
1216 szwName = strdupAtoW( szName );
1217 if( szName && !szwName )
1220 szwValue = strdupAtoW( szValue );
1221 if( szValue && !szwValue )
1224 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1227 msi_free( szwName );
1228 msi_free( szwValue );
1233 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
1236 MSIRECORD *row = NULL;
1241 static const WCHAR Insert[] = {
1242 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1243 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1244 '`','_','P','r','o','p','e','r','t','y','`',',',
1245 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1246 ,' ','(','?',',','?',')',0};
1247 static const WCHAR Update[] = {
1248 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1249 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1250 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1251 ' ','=',' ','\'','%','s','\'',0};
1252 static const WCHAR Delete[] = {
1253 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1254 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1255 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1257 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
1260 return ERROR_INVALID_PARAMETER;
1262 /* this one is weird... */
1264 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1266 rc = MSI_GetPropertyW(package, szName, 0, &sz);
1267 if (!szValue || !*szValue)
1269 sprintfW(Query, Delete, szName);
1271 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1273 sprintfW(Query, Update, szName);
1275 row = MSI_CreateRecord(1);
1276 MSI_RecordSetStringW(row, 1, szValue);
1280 strcpyW(Query, Insert);
1282 row = MSI_CreateRecord(2);
1283 MSI_RecordSetStringW(row, 1, szName);
1284 MSI_RecordSetStringW(row, 2, szValue);
1287 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1288 if (rc == ERROR_SUCCESS)
1290 rc = MSI_ViewExecute(view, row);
1291 MSI_ViewClose(view);
1292 msiobj_release(&view->hdr);
1295 msiobj_release(&row->hdr);
1300 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1302 MSIPACKAGE *package;
1305 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1310 IWineMsiRemotePackage *remote_package;
1312 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1313 if (!remote_package)
1314 return ERROR_INVALID_HANDLE;
1316 name = SysAllocString( szName );
1317 value = SysAllocString( szValue );
1318 if (!name || !value)
1320 SysFreeString( name );
1321 SysFreeString( value );
1322 IWineMsiRemotePackage_Release( remote_package );
1323 return ERROR_OUTOFMEMORY;
1326 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
1328 SysFreeString( name );
1329 SysFreeString( value );
1330 IWineMsiRemotePackage_Release( remote_package );
1334 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1335 return HRESULT_CODE(hr);
1337 return ERROR_FUNCTION_FAILED;
1340 return ERROR_SUCCESS;
1343 ret = MSI_SetPropertyW( package, szName, szValue);
1344 msiobj_release( &package->hdr );
1348 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
1350 static const WCHAR query[]= {
1351 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1352 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1353 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1354 '=','\'','%','s','\'',0};
1356 if (!name || !*name)
1359 return MSI_QueryGetRecord( package->db, query, name );
1362 /* internal function, not compatible with MsiGetPropertyW */
1363 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
1364 LPWSTR szValueBuf, DWORD* pchValueBuf )
1367 UINT rc = ERROR_FUNCTION_FAILED;
1369 row = MSI_GetPropertyRow( package, szName );
1371 if (*pchValueBuf > 0)
1376 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
1377 msiobj_release(&row->hdr);
1380 if (rc == ERROR_SUCCESS)
1381 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
1382 debugstr_w(szName));
1383 else if (rc == ERROR_MORE_DATA)
1384 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
1385 debugstr_w(szName));
1389 TRACE("property %s not found\n", debugstr_w(szName));
1395 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
1401 r = MSI_GetPropertyW(package, prop, NULL, &sz);
1402 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
1406 str = msi_alloc(sz * sizeof(WCHAR));
1407 r = MSI_GetPropertyW(package, prop, str, &sz);
1408 if (r != ERROR_SUCCESS)
1417 int msi_get_property_int(MSIPACKAGE *package, LPCWSTR prop, int def)
1419 LPWSTR str = msi_dup_property(package, prop);
1420 int val = str ? atoiW(str) : def;
1425 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1426 awstring *szValueBuf, DWORD* pchValueBuf )
1428 static const WCHAR empty[] = {0};
1429 MSIPACKAGE *package;
1430 MSIRECORD *row = NULL;
1431 UINT r = ERROR_FUNCTION_FAILED;
1434 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1435 szValueBuf->str.w, pchValueBuf );
1438 return ERROR_INVALID_PARAMETER;
1440 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1444 IWineMsiRemotePackage *remote_package;
1445 LPWSTR value = NULL;
1449 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
1450 if (!remote_package)
1451 return ERROR_INVALID_HANDLE;
1453 bname = SysAllocString( name );
1456 IWineMsiRemotePackage_Release( remote_package );
1457 return ERROR_OUTOFMEMORY;
1461 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
1466 value = msi_alloc(len * sizeof(WCHAR));
1469 r = ERROR_OUTOFMEMORY;
1473 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
1477 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
1479 /* Bug required by Adobe installers */
1480 if (!szValueBuf->unicode)
1481 *pchValueBuf *= sizeof(WCHAR);
1484 IWineMsiRemotePackage_Release(remote_package);
1485 SysFreeString(bname);
1490 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1491 return HRESULT_CODE(hr);
1493 return ERROR_FUNCTION_FAILED;
1499 row = MSI_GetPropertyRow( package, name );
1501 val = MSI_RecordGetString( row, 1 );
1506 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1509 msiobj_release( &row->hdr );
1510 msiobj_release( &package->hdr );
1515 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1516 LPSTR szValueBuf, DWORD* pchValueBuf )
1522 val.unicode = FALSE;
1523 val.str.a = szValueBuf;
1525 name = strdupAtoW( szName );
1526 if (szName && !name)
1527 return ERROR_OUTOFMEMORY;
1529 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1534 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1535 LPWSTR szValueBuf, DWORD* pchValueBuf )
1540 val.str.w = szValueBuf;
1542 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
1545 typedef struct _msi_remote_package_impl {
1546 const IWineMsiRemotePackageVtbl *lpVtbl;
1549 } msi_remote_package_impl;
1551 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
1553 return (msi_remote_package_impl*) iface;
1556 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
1557 REFIID riid,LPVOID *ppobj)
1559 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1560 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
1562 IUnknown_AddRef( iface );
1567 return E_NOINTERFACE;
1570 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
1572 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1574 return InterlockedIncrement( &This->refs );
1577 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
1579 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1582 r = InterlockedDecrement( &This->refs );
1585 MsiCloseHandle( This->package );
1591 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
1593 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1594 This->package = handle;
1598 HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
1600 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1601 *handle = MsiGetActiveDatabase(This->package);
1605 HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
1607 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1610 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
1611 if (r != ERROR_SUCCESS)
1612 return HRESULT_FROM_WIN32(r);
1617 HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
1619 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1620 UINT r = MsiSetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value);
1621 return HRESULT_FROM_WIN32(r);
1624 HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
1626 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1627 UINT r = MsiProcessMessage(This->package, message, record);
1628 return HRESULT_FROM_WIN32(r);
1631 HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
1633 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1634 UINT r = MsiDoActionW(This->package, (LPWSTR)action);
1635 return HRESULT_FROM_WIN32(r);
1638 HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
1640 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1641 UINT r = MsiSequenceW(This->package, (LPWSTR)table, sequence);
1642 return HRESULT_FROM_WIN32(r);
1645 HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1647 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1648 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1649 return HRESULT_FROM_WIN32(r);
1652 HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
1654 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1655 UINT r = MsiSetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value);
1656 return HRESULT_FROM_WIN32(r);
1659 HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1661 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1662 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1663 return HRESULT_FROM_WIN32(r);
1666 HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
1668 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1669 *ret = MsiGetMode(This->package, mode);
1673 HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
1674 INSTALLSTATE *installed, INSTALLSTATE *action )
1676 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1677 UINT r = MsiGetFeatureStateW(This->package, (LPWSTR)feature, installed, action);
1678 return HRESULT_FROM_WIN32(r);
1681 HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
1683 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1684 UINT r = MsiSetFeatureStateW(This->package, (LPWSTR)feature, state);
1685 return HRESULT_FROM_WIN32(r);
1688 HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
1689 INSTALLSTATE *installed, INSTALLSTATE *action )
1691 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1692 UINT r = MsiGetComponentStateW(This->package, (LPWSTR)component, installed, action);
1693 return HRESULT_FROM_WIN32(r);
1696 HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
1698 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1699 UINT r = MsiSetComponentStateW(This->package, (LPWSTR)component, state);
1700 return HRESULT_FROM_WIN32(r);
1703 HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
1705 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1706 *language = MsiGetLanguage(This->package);
1710 HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
1712 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1713 UINT r = MsiSetInstallLevel(This->package, level);
1714 return HRESULT_FROM_WIN32(r);
1717 HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
1718 BSTR value, DWORD *size )
1720 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1721 UINT r = MsiFormatRecordW(This->package, record, (LPWSTR)value, size);
1722 return HRESULT_FROM_WIN32(r);
1725 HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
1727 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1728 UINT r = MsiEvaluateConditionW(This->package, (LPWSTR)condition);
1729 return HRESULT_FROM_WIN32(r);
1732 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
1738 mrp_GetActiveDatabase,
1748 mrp_GetFeatureState,
1749 mrp_SetFeatureState,
1750 mrp_GetComponentState,
1751 mrp_SetComponentState,
1753 mrp_SetInstallLevel,
1755 mrp_EvaluateCondition,
1758 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
1760 msi_remote_package_impl* This;
1762 This = msi_alloc( sizeof *This );
1764 return E_OUTOFMEMORY;
1766 This->lpVtbl = &msi_remote_package_vtbl;
1775 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
1776 LPCWSTR property, LPWSTR value)
1778 MSISOURCELISTINFO *info;
1780 info = msi_alloc(sizeof(MSISOURCELISTINFO));
1782 return ERROR_OUTOFMEMORY;
1784 info->context = context;
1785 info->options = options;
1786 info->property = property;
1787 info->value = strdupW(value);
1788 list_add_head(&package->sourcelist_info, &info->entry);
1790 return ERROR_SUCCESS;
1793 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
1794 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
1798 disk = msi_alloc(sizeof(MSIMEDIADISK));
1800 return ERROR_OUTOFMEMORY;
1802 disk->context = context;
1803 disk->options = options;
1804 disk->disk_id = disk_id;
1805 disk->volume_label = strdupW(volume_label);
1806 disk->disk_prompt = strdupW(disk_prompt);
1807 list_add_head(&package->sourcelist_media, &disk->entry);
1809 return ERROR_SUCCESS;