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
31 #include "wine/debug.h"
40 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
49 static void MSI_FreePackage( MSIOBJECTHDR *arg)
51 MSIPACKAGE *package= (MSIPACKAGE*) arg;
54 msi_dialog_destroy( package->dialog );
56 msiobj_release( &package->db->hdr );
57 ACTION_free_package_structures(package);
60 static UINT clone_properties(MSIPACKAGE *package)
62 MSIQUERY * view = NULL;
64 static const WCHAR CreateSql[] = {
65 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
66 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
67 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
68 'L','L',' ','T','E','M','P','O','R','A','R','Y',',',' ','`','V','a','l',
69 'u','e','`',' ','C','H','A','R','(','9','8',')',' ','N','O','T',' ','N',
70 'U','L','L',' ','T','E','M','P','O','R','A','R','Y',' ','P','R','I','M',
71 'A','R','Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y',
73 static const WCHAR Query[] = {
74 'S','E','L','E','C','T',' ','*',' ',
75 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
76 static const WCHAR Insert[] = {
77 'I','N','S','E','R','T',' ','i','n','t','o',' ',
78 '`','_','P','r','o','p','e','r','t','y','`',' ',
79 '(','`','_','P','r','o','p','e','r','t','y','`',',',
80 '`','V','a','l','u','e','`',')',' ',
81 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
83 /* create the temporary properties table */
84 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
85 if (rc != ERROR_SUCCESS)
88 rc = MSI_ViewExecute(view, 0);
90 msiobj_release(&view->hdr);
91 if (rc != ERROR_SUCCESS)
94 /* clone the existing properties */
95 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
96 if (rc != ERROR_SUCCESS)
99 rc = MSI_ViewExecute(view, 0);
100 if (rc != ERROR_SUCCESS)
103 msiobj_release(&view->hdr);
112 rc = MSI_ViewFetch(view, &row);
113 if (rc != ERROR_SUCCESS)
116 rc = MSI_DatabaseOpenViewW(package->db, Insert, &view2);
117 if (rc!= ERROR_SUCCESS)
120 rc = MSI_ViewExecute(view2, row);
121 MSI_ViewClose(view2);
122 msiobj_release(&view2->hdr);
124 if (rc == ERROR_SUCCESS)
125 msiobj_release(&row->hdr);
129 msiobj_release(&view->hdr);
137 * Sets the "Installed" property to indicate that
138 * the product is installed for the current user.
140 static UINT set_installed_prop( MSIPACKAGE *package )
142 static const WCHAR szInstalled[] = {
143 'I','n','s','t','a','l','l','e','d',0 };
144 WCHAR val[2] = { '1', 0 };
148 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
149 if (r == ERROR_SUCCESS)
152 MSI_SetPropertyW( package, szInstalled, val );
158 static UINT set_user_sid_prop( MSIPACKAGE *package )
162 LPWSTR sid_str = NULL, dom = NULL;
163 DWORD size, dom_size;
165 UINT r = ERROR_FUNCTION_FAILED;
167 static const WCHAR user_sid[] = {'U','s','e','r','S','I','D',0};
170 GetUserNameW( NULL, &size );
172 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
174 return ERROR_OUTOFMEMORY;
176 if (!GetUserNameW( user_name, &size ))
181 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
183 psid = msi_alloc( size );
184 dom = msi_alloc( dom_size*sizeof (WCHAR) );
187 r = ERROR_OUTOFMEMORY;
191 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
194 if (!ConvertSidToStringSidW( psid, &sid_str ))
197 r = MSI_SetPropertyW( package, user_sid, sid_str );
200 LocalFree( sid_str );
203 msi_free( user_name );
209 * There are a whole slew of these we need to set
212 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
214 static VOID set_installer_properties(MSIPACKAGE *package)
218 OSVERSIONINFOA OSVersion;
221 WCHAR verstr[10], bufstr[20];
226 SYSTEM_INFO sys_info;
227 SYSTEMTIME systemtime;
229 static const WCHAR cszbs[]={'\\',0};
230 static const WCHAR CFF[] =
231 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
232 static const WCHAR PFF[] =
233 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
234 static const WCHAR CADF[] =
235 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
236 static const WCHAR FaF[] =
237 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
238 static const WCHAR FoF[] =
239 {'F','o','n','t','s','F','o','l','d','e','r',0};
240 static const WCHAR SendTF[] =
241 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
242 static const WCHAR SMF[] =
243 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
244 static const WCHAR StF[] =
245 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
246 static const WCHAR TemplF[] =
247 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
248 static const WCHAR DF[] =
249 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
250 static const WCHAR PMF[] =
251 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
252 static const WCHAR ATF[] =
253 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
254 static const WCHAR ADF[] =
255 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
256 static const WCHAR SF[] =
257 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
258 static const WCHAR SF16[] =
259 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
260 static const WCHAR LADF[] =
261 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
262 static const WCHAR MPF[] =
263 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
264 static const WCHAR PF[] =
265 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
266 static const WCHAR WF[] =
267 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
268 static const WCHAR WV[] =
269 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
270 static const WCHAR TF[]=
271 {'T','e','m','p','F','o','l','d','e','r',0};
272 static const WCHAR szAdminUser[] =
273 {'A','d','m','i','n','U','s','e','r',0};
274 static const WCHAR szPriv[] =
275 {'P','r','i','v','i','l','e','g','e','d',0};
276 static const WCHAR szOne[] =
278 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
279 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
280 static const WCHAR szFormat[] = {'%','l','i',0};
281 static const WCHAR szWinBuild[] =
282 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
283 static const WCHAR szSPL[] =
284 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
285 static const WCHAR szSix[] = {'6',0 };
287 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
288 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
289 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
290 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
291 /* Screen properties */
292 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
293 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
294 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
295 static const WCHAR szScreenFormat[] = {'%','d',0};
296 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
297 static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
298 static const WCHAR szCurrentVersion[] = {
299 'S','O','F','T','W','A','R','E','\\',
300 'M','i','c','r','o','s','o','f','t','\\',
301 'W','i','n','d','o','w','s',' ','N','T','\\',
302 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
304 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
305 static const WCHAR szRegisteredOrg[] = {
306 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
308 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
309 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
310 static const WCHAR szDate[] = {'D','a','t','e',0};
311 static const WCHAR szTime[] = {'T','i','m','e',0};
314 * Other things that probably should be set:
316 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
317 * ShellAdvSupport DefaultUIFont PackagecodeChanging
318 * ProductState CaptionHeight BorderTop BorderSide TextHeight
319 * RedirectedDllSupport
322 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
324 MSI_SetPropertyW(package, CFF, pth);
326 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
328 MSI_SetPropertyW(package, PFF, pth);
330 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
332 MSI_SetPropertyW(package, CADF, pth);
334 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
336 MSI_SetPropertyW(package, FaF, pth);
338 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
340 MSI_SetPropertyW(package, FoF, pth);
342 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
344 MSI_SetPropertyW(package, SendTF, pth);
346 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
348 MSI_SetPropertyW(package, SMF, pth);
350 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
352 MSI_SetPropertyW(package, StF, pth);
354 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
356 MSI_SetPropertyW(package, TemplF, pth);
358 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
360 MSI_SetPropertyW(package, DF, pth);
362 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
364 MSI_SetPropertyW(package, PMF, pth);
366 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
368 MSI_SetPropertyW(package, ATF, pth);
370 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
372 MSI_SetPropertyW(package, ADF, pth);
374 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
376 MSI_SetPropertyW(package, SF, pth);
377 MSI_SetPropertyW(package, SF16, pth);
379 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
381 MSI_SetPropertyW(package, LADF, pth);
383 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
385 MSI_SetPropertyW(package, MPF, pth);
387 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
389 MSI_SetPropertyW(package, PF, pth);
391 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
393 MSI_SetPropertyW(package, WF, pth);
395 /* Physical Memory is specified in MB. Using total amount. */
396 msex.dwLength = sizeof(msex);
397 GlobalMemoryStatusEx( &msex );
398 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
399 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
401 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
402 ptr = strchrW(pth,'\\');
405 MSI_SetPropertyW(package, WV, pth);
407 GetTempPathW(MAX_PATH,pth);
408 MSI_SetPropertyW(package, TF, pth);
411 /* in a wine environment the user is always admin and privileged */
412 MSI_SetPropertyW(package,szAdminUser,szOne);
413 MSI_SetPropertyW(package,szPriv,szOne);
414 MSI_SetPropertyW(package, szAllUsers, szOne);
416 /* set the os things */
417 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
418 GetVersionExA(&OSVersion);
419 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
420 sprintfW(verstr,szFormat,verval);
421 switch (OSVersion.dwPlatformId)
423 case VER_PLATFORM_WIN32_WINDOWS:
424 MSI_SetPropertyW(package,v9x,verstr);
426 case VER_PLATFORM_WIN32_NT:
427 MSI_SetPropertyW(package,vNT,verstr);
430 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
431 MSI_SetPropertyW(package,szWinBuild,verstr);
432 /* just fudge this */
433 MSI_SetPropertyW(package,szSPL,szSix);
435 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
436 MSI_SetPropertyW( package, szVersionMsi, bufstr );
437 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
438 MSI_SetPropertyW( package, szVersionDatabase, bufstr );
440 GetSystemInfo( &sys_info );
441 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
443 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
444 MSI_SetPropertyW( package, szIntel, bufstr );
447 /* Screen properties. */
449 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
450 MSI_SetPropertyW( package, szScreenX, bufstr );
451 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
452 MSI_SetPropertyW( package, szScreenY, bufstr );
453 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
454 MSI_SetPropertyW( package, szColorBits, bufstr );
457 /* USERNAME and COMPANYNAME */
458 res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
459 if (res != ERROR_SUCCESS)
462 check = msi_dup_property( package, szUSERNAME );
465 LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
466 MSI_SetPropertyW( package, szUSERNAME, user );
472 check = msi_dup_property( package, szCOMPANYNAME );
475 LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
476 MSI_SetPropertyW( package, szCOMPANYNAME, company );
480 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
481 ERR("Failed to set the UserSID property\n");
483 /* Date and time properties */
484 GetSystemTime( &systemtime );
485 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
486 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
487 MSI_SetPropertyW( package, szDate, bufstr );
489 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
491 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
492 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
493 &systemtime, NULL, bufstr,
494 sizeof(bufstr)/sizeof(bufstr[0]) ))
495 MSI_SetPropertyW( package, szTime, bufstr );
497 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
503 static UINT msi_load_summary_properties( MSIPACKAGE *package )
507 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
511 static const WCHAR szPackageCode[] = {
512 'P','a','c','k','a','g','e','C','o','d','e',0};
515 ERR("Unable to allocate handle\n");
518 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
520 if (rc != ERROR_SUCCESS)
522 ERR("Unable to open Summary Information\n");
526 /* load package attributes */
527 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
528 &word_count, NULL, NULL, NULL );
529 if (rc == ERROR_SUCCESS)
530 package->WordCount = word_count;
532 WARN("Unable to query word count\n");
534 /* load package code property */
536 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
537 NULL, NULL, NULL, &len );
538 if (rc == ERROR_MORE_DATA)
541 package_code = msi_alloc( len * sizeof(WCHAR) );
542 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
543 NULL, NULL, package_code, &len );
544 if (rc == ERROR_SUCCESS)
545 MSI_SetPropertyW( package, szPackageCode, package_code );
547 WARN("Unable to query rev number, %d\n", rc);
548 msi_free( package_code );
551 WARN("Unable to query rev number, %d\n", rc);
553 MsiCloseHandle(suminfo);
554 return ERROR_SUCCESS;
557 static MSIPACKAGE *msi_alloc_package( void )
561 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
565 list_init( &package->components );
566 list_init( &package->features );
567 list_init( &package->files );
568 list_init( &package->tempfiles );
569 list_init( &package->folders );
570 list_init( &package->subscriptions );
571 list_init( &package->appids );
572 list_init( &package->classes );
573 list_init( &package->mimes );
574 list_init( &package->extensions );
575 list_init( &package->progids );
576 list_init( &package->RunningActions );
578 package->ActionFormat = NULL;
579 package->LastAction = NULL;
580 package->dialog = NULL;
581 package->next_dialog = NULL;
587 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPWSTR base_url )
589 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
590 static const WCHAR szpi[] = {'%','i',0};
591 static const WCHAR szProductCode[] = {
592 'P','r','o','d','u','c','t','C','o','d','e',0};
598 package = msi_alloc_package();
601 msiobj_addref( &db->hdr );
604 package->WordCount = 0;
605 package->PackagePath = strdupW( db->path );
606 package->BaseURL = strdupW( base_url );
608 clone_properties( package );
609 set_installer_properties(package);
610 sprintfW(uilevel,szpi,gUILevel);
611 MSI_SetPropertyW(package, szLevel, uilevel);
613 package->ProductCode = msi_dup_property( package, szProductCode );
614 set_installed_prop( package );
615 msi_load_summary_properties( package );
622 * copy_package_to_temp [internal]
624 * copy the msi file to a temp file to prevent locking a CD
625 * with a multi disc install
627 * FIXME: I think this is wrong, and instead of copying the package,
628 * we should read all the tables to memory, then open the
629 * database to read binary streams on demand.
631 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
633 WCHAR path[MAX_PATH];
634 static const WCHAR szMSI[] = {'m','s','i',0};
636 GetTempPathW( MAX_PATH, path );
637 GetTempFileNameW( path, szMSI, 0, filename );
639 if( !CopyFileW( szPackage, filename, FALSE ) )
641 DeleteFileW( filename );
642 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
646 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
650 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
652 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
656 /* call will always fail, becase size is 0,
657 * but will return ERROR_FILE_NOT_FOUND first
658 * if the file doesn't exist
660 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
661 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
663 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
664 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
666 HeapFree( GetProcessHeap(), 0, cache_entry );
670 lstrcpyW( filename, cache_entry->lpszLocalFileName );
671 HeapFree( GetProcessHeap(), 0, cache_entry );
675 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
682 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
684 static const WCHAR OriginalDatabase[] =
685 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
686 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
687 MSIDATABASE *db = NULL;
690 LPWSTR ptr, base_url = NULL;
692 WCHAR temppath[MAX_PATH];
693 LPCWSTR file = szPackage;
695 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
697 if( szPackage[0] == '#' )
699 handle = atoiW(&szPackage[1]);
700 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
702 return ERROR_INVALID_HANDLE;
706 if ( UrlIsW( szPackage, URLIS_URL ) )
708 file = msi_download_file( szPackage, temppath );
710 base_url = strdupW( szPackage );
712 return ERROR_OUTOFMEMORY;
714 ptr = strrchrW( base_url, '/' );
715 if (ptr) *(ptr + 1) = '\0';
718 file = copy_package_to_temp( szPackage, temppath );
720 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
721 if( r != ERROR_SUCCESS )
723 if (GetLastError() == ERROR_FILE_NOT_FOUND)
724 msi_ui_error( 4, MB_OK | MB_ICONWARNING );
725 if (file != szPackage)
732 package = MSI_CreatePackage( db, base_url );
733 msi_free( base_url );
734 msiobj_release( &db->hdr );
737 if (file != szPackage)
739 return ERROR_FUNCTION_FAILED;
742 if( file != szPackage )
743 track_tempfile( package, file );
745 if( szPackage[0] != '#' )
747 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
748 MSI_SetPropertyW( package, Database, szPackage );
752 MSI_SetPropertyW( package, OriginalDatabase, db->path );
753 MSI_SetPropertyW( package, Database, db->path );
758 return ERROR_SUCCESS;
761 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
763 MSIPACKAGE *package = NULL;
766 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
768 if( szPackage == NULL )
769 return ERROR_INVALID_PARAMETER;
772 FIXME("dwOptions %08x not supported\n", dwOptions);
774 ret = MSI_OpenPackageW( szPackage, &package );
775 if( ret == ERROR_SUCCESS )
777 *phPackage = alloc_msihandle( &package->hdr );
779 ret = ERROR_NOT_ENOUGH_MEMORY;
780 msiobj_release( &package->hdr );
786 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
788 return MsiOpenPackageExW( szPackage, 0, phPackage );
791 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
793 LPWSTR szwPack = NULL;
798 szwPack = strdupAtoW( szPackage );
800 return ERROR_OUTOFMEMORY;
803 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
810 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
812 return MsiOpenPackageExA( szPackage, 0, phPackage );
815 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
818 MSIHANDLE handle = 0;
820 TRACE("(%ld)\n",hInstall);
822 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
825 handle = alloc_msihandle( &package->db->hdr );
826 msiobj_release( &package->hdr );
832 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
835 static const WCHAR szActionData[] =
836 {'A','c','t','i','o','n','D','a','t','a',0};
837 static const WCHAR szSetProgress[] =
838 {'S','e','t','P','r','o','g','r','e','s','s',0};
839 static const WCHAR szActionText[] =
840 {'A','c','t','i','o','n','T','e','x','t',0};
844 DWORD total_size = 0;
850 TRACE("%x\n", eMessageType);
853 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
854 log_type |= INSTALLLOGMODE_ERROR;
855 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
856 log_type |= INSTALLLOGMODE_WARNING;
857 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
858 log_type |= INSTALLLOGMODE_USER;
859 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
860 log_type |= INSTALLLOGMODE_INFO;
861 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
862 log_type |= INSTALLLOGMODE_COMMONDATA;
863 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
864 log_type |= INSTALLLOGMODE_ACTIONSTART;
865 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
866 log_type |= INSTALLLOGMODE_ACTIONDATA;
868 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
871 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
873 static const WCHAR template_s[]=
874 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
875 static const WCHAR format[] =
876 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
878 LPCWSTR action_text, action;
879 LPWSTR deformatted = NULL;
881 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
883 action = MSI_RecordGetString(record, 1);
884 action_text = MSI_RecordGetString(record, 2);
886 if (!action || !action_text)
889 deformat_string(package, action_text, &deformatted);
891 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
893 len += strlenW(deformatted);
894 message = msi_alloc(len*sizeof(WCHAR));
895 sprintfW(message, template_s, timet, action);
897 strcatW(message, deformatted);
898 msi_free(deformatted);
903 message = msi_alloc(1*sizeof (WCHAR));
905 msg_field = MSI_RecordGetFieldCount(record);
906 for (i = 1; i <= msg_field; i++)
910 static const WCHAR format[] = { '%','i',':',' ',0};
911 static const WCHAR space[] = { ' ',0};
913 MSI_RecordGetStringW(record,i,NULL,&sz);
915 total_size+=sz*sizeof(WCHAR);
916 tmp = msi_alloc(sz*sizeof(WCHAR));
917 message = msi_realloc(message,total_size*sizeof (WCHAR));
919 MSI_RecordGetStringW(record,i,tmp,&sz);
923 sprintfW(number,format,i);
924 strcatW(message,number);
926 strcatW(message,tmp);
928 strcatW(message,space);
934 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
935 debugstr_w(message));
937 /* convert it to ASCII */
938 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
939 NULL, 0, NULL, NULL );
940 msg = msi_alloc( len );
941 WideCharToMultiByte( CP_ACP, 0, message, -1,
942 msg, len, NULL, NULL );
944 if (gUIHandlerA && (gUIFilter & log_type))
946 rc = gUIHandlerA(gUIContext,eMessageType,msg);
949 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
950 INSTALLMESSAGE_PROGRESS))
953 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
954 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
956 if (log_file != INVALID_HANDLE_VALUE)
958 SetFilePointer(log_file,0, NULL, FILE_END);
959 WriteFile(log_file,msg,strlen(msg),&write,NULL);
960 WriteFile(log_file,"\n",1,&write,NULL);
961 CloseHandle(log_file);
968 switch (eMessageType & 0xff000000)
970 case INSTALLMESSAGE_ACTIONDATA:
971 /* FIXME: format record here instead of in ui_actiondata to get the
972 * correct action data for external scripts */
973 ControlEvent_FireSubscribedEvent(package, szActionData, record);
975 case INSTALLMESSAGE_ACTIONSTART:
979 LPCWSTR action_text = MSI_RecordGetString(record, 2);
981 deformat_string(package, action_text, &deformated);
982 uirow = MSI_CreateRecord(1);
983 MSI_RecordSetStringW(uirow, 1, deformated);
984 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
985 msi_free(deformated);
987 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
989 msiobj_release(&uirow->hdr);
992 case INSTALLMESSAGE_PROGRESS:
993 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
997 return ERROR_SUCCESS;
1000 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1003 UINT ret = ERROR_INVALID_HANDLE;
1004 MSIPACKAGE *package = NULL;
1005 MSIRECORD *record = NULL;
1007 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1009 return ERROR_INVALID_HANDLE;
1011 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1015 ret = MSI_ProcessMessage( package, eMessageType, record );
1018 msiobj_release( &package->hdr );
1020 msiobj_release( &record->hdr );
1027 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1029 LPWSTR szwName = NULL, szwValue = NULL;
1030 UINT r = ERROR_OUTOFMEMORY;
1032 szwName = strdupAtoW( szName );
1033 if( szName && !szwName )
1036 szwValue = strdupAtoW( szValue );
1037 if( szValue && !szwValue )
1040 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1043 msi_free( szwName );
1044 msi_free( szwValue );
1049 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
1052 MSIRECORD *row = NULL;
1057 static const WCHAR Insert[] = {
1058 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1059 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1060 '`','_','P','r','o','p','e','r','t','y','`',',',
1061 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1062 ,' ','(','?',',','?',')',0};
1063 static const WCHAR Update[] = {
1064 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1065 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1066 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1067 ' ','=',' ','\'','%','s','\'',0};
1068 static const WCHAR Delete[] = {
1069 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1070 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1071 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1073 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
1076 return ERROR_INVALID_PARAMETER;
1078 /* this one is weird... */
1080 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1082 rc = MSI_GetPropertyW(package, szName, 0, &sz);
1083 if (!szValue || !*szValue)
1085 sprintfW(Query, Delete, szName);
1087 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1089 sprintfW(Query, Update, szName);
1091 row = MSI_CreateRecord(1);
1092 MSI_RecordSetStringW(row, 1, szValue);
1096 strcpyW(Query, Insert);
1098 row = MSI_CreateRecord(2);
1099 MSI_RecordSetStringW(row, 1, szName);
1100 MSI_RecordSetStringW(row, 2, szValue);
1103 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1104 if (rc == ERROR_SUCCESS)
1106 rc = MSI_ViewExecute(view, row);
1107 MSI_ViewClose(view);
1108 msiobj_release(&view->hdr);
1111 msiobj_release(&row->hdr);
1116 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1118 MSIPACKAGE *package;
1121 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1123 return ERROR_INVALID_HANDLE;
1124 ret = MSI_SetPropertyW( package, szName, szValue);
1125 msiobj_release( &package->hdr );
1129 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
1131 static const WCHAR query[]= {
1132 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1133 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1134 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1135 '=','\'','%','s','\'',0};
1137 if (!name || !*name)
1140 return MSI_QueryGetRecord( package->db, query, name );
1143 /* internal function, not compatible with MsiGetPropertyW */
1144 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
1145 LPWSTR szValueBuf, DWORD* pchValueBuf )
1148 UINT rc = ERROR_FUNCTION_FAILED;
1150 row = MSI_GetPropertyRow( package, szName );
1152 if (*pchValueBuf > 0)
1157 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
1158 msiobj_release(&row->hdr);
1161 if (rc == ERROR_SUCCESS)
1162 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
1163 debugstr_w(szName));
1164 else if (rc == ERROR_MORE_DATA)
1165 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
1166 debugstr_w(szName));
1170 TRACE("property %s not found\n", debugstr_w(szName));
1176 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
1182 r = MSI_GetPropertyW(package, prop, NULL, &sz);
1183 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
1187 str = msi_alloc(sz * sizeof(WCHAR));
1188 r = MSI_GetPropertyW(package, prop, str, &sz);
1189 if (r != ERROR_SUCCESS)
1198 int msi_get_property_int(MSIPACKAGE *package, LPCWSTR prop, int def)
1200 LPWSTR str = msi_dup_property(package, prop);
1201 int val = str ? atoiW(str) : def;
1206 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1207 awstring *szValueBuf, DWORD* pchValueBuf )
1209 static const WCHAR empty[] = {0};
1210 MSIPACKAGE *package;
1211 MSIRECORD *row = NULL;
1215 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1216 szValueBuf->str.w, pchValueBuf );
1219 return ERROR_INVALID_PARAMETER;
1221 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1223 return ERROR_INVALID_HANDLE;
1225 row = MSI_GetPropertyRow( package, name );
1227 val = MSI_RecordGetString( row, 1 );
1232 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1235 msiobj_release( &row->hdr );
1236 msiobj_release( &package->hdr );
1241 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1242 LPSTR szValueBuf, DWORD* pchValueBuf )
1248 val.unicode = FALSE;
1249 val.str.a = szValueBuf;
1251 name = strdupAtoW( szName );
1252 if (szName && !name)
1253 return ERROR_OUTOFMEMORY;
1255 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1260 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1261 LPWSTR szValueBuf, DWORD* pchValueBuf )
1266 val.str.w = szValueBuf;
1268 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );