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"
41 #include "wine/unicode.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msi);
49 static void msi_free_properties( MSIPACKAGE *package );
51 static void MSI_FreePackage( MSIOBJECTHDR *arg)
53 MSIPACKAGE *package= (MSIPACKAGE*) arg;
56 msi_dialog_destroy( package->dialog );
57 ACTION_free_package_structures(package);
59 msi_free_properties( package );
61 msiobj_release( &package->db->hdr );
64 static UINT clone_properties( MSIPACKAGE *package )
66 MSIQUERY * view = NULL;
68 static const WCHAR Query[] = {
69 'S','E','L','E','C','T',' ','*',' ',
70 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
72 /* clone the existing properties */
73 rc = MSI_DatabaseOpenViewW( package->db, Query, &view );
74 if (rc != ERROR_SUCCESS)
77 rc = MSI_ViewExecute(view, 0);
78 if (rc != ERROR_SUCCESS)
81 msiobj_release(&view->hdr);
89 rc = MSI_ViewFetch(view,&row);
90 if (rc != ERROR_SUCCESS)
93 name = MSI_RecordGetString( row, 1 );
94 value = MSI_RecordGetString( row, 2 );
95 MSI_SetPropertyW( package, name, value );
97 msiobj_release( &row->hdr );
100 msiobj_release(&view->hdr);
108 * Sets the "Installed" property to indicate that
109 * the product is installed for the current user.
111 static UINT set_installed_prop( MSIPACKAGE *package )
113 static const WCHAR szInstalled[] = {
114 'I','n','s','t','a','l','l','e','d',0 };
115 WCHAR val[2] = { '1', 0 };
119 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
120 if (r == ERROR_SUCCESS)
123 MSI_SetPropertyW( package, szInstalled, val );
130 * There are a whole slew of these we need to set
133 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
135 static VOID set_installer_properties(MSIPACKAGE *package)
139 OSVERSIONINFOA OSVersion;
142 WCHAR verstr[10], bufstr[20];
148 static const WCHAR cszbs[]={'\\',0};
149 static const WCHAR CFF[] =
150 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
151 static const WCHAR PFF[] =
152 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
153 static const WCHAR CADF[] =
154 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
155 static const WCHAR FaF[] =
156 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
157 static const WCHAR FoF[] =
158 {'F','o','n','t','s','F','o','l','d','e','r',0};
159 static const WCHAR SendTF[] =
160 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
161 static const WCHAR SMF[] =
162 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
163 static const WCHAR StF[] =
164 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
165 static const WCHAR TemplF[] =
166 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
167 static const WCHAR DF[] =
168 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
169 static const WCHAR PMF[] =
170 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
171 static const WCHAR ATF[] =
172 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
173 static const WCHAR ADF[] =
174 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
175 static const WCHAR SF[] =
176 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
177 static const WCHAR SF16[] =
178 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
179 static const WCHAR LADF[] =
180 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
181 static const WCHAR MPF[] =
182 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
183 static const WCHAR PF[] =
184 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
185 static const WCHAR WF[] =
186 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
187 static const WCHAR WV[] =
188 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
189 static const WCHAR TF[]=
190 {'T','e','m','p','F','o','l','d','e','r',0};
191 static const WCHAR szAdminUser[] =
192 {'A','d','m','i','n','U','s','e','r',0};
193 static const WCHAR szPriv[] =
194 {'P','r','i','v','i','l','e','g','e','d',0};
195 static const WCHAR szOne[] =
197 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
198 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
199 static const WCHAR szFormat[] = {'%','l','i',0};
200 static const WCHAR szWinBuild[] =
201 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
202 static const WCHAR szSPL[] =
203 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
204 static const WCHAR szSix[] = {'6',0 };
206 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
207 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
208 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
209 /* Screen properties */
210 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
211 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
212 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
213 static const WCHAR szScreenFormat[] = {'%','d',0};
214 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
215 static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
216 static const WCHAR szCurrentVersion[] = {
217 'S','O','F','T','W','A','R','E','\\',
218 'M','i','c','r','o','s','o','f','t','\\',
219 'W','i','n','d','o','w','s',' ','N','T','\\',
220 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
222 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
223 static const WCHAR szRegisteredOrg[] = {
224 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
226 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
227 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
228 SYSTEM_INFO sys_info;
231 * Other things that probably should be set:
233 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
234 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
235 * ProductState CaptionHeight BorderTop BorderSide TextHeight
236 * RedirectedDllSupport Time Date Privileged
239 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
241 MSI_SetPropertyW(package, CFF, pth);
243 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
245 MSI_SetPropertyW(package, PFF, pth);
247 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
249 MSI_SetPropertyW(package, CADF, pth);
251 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
253 MSI_SetPropertyW(package, FaF, pth);
255 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
257 MSI_SetPropertyW(package, FoF, pth);
259 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
261 MSI_SetPropertyW(package, SendTF, pth);
263 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
265 MSI_SetPropertyW(package, SMF, pth);
267 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
269 MSI_SetPropertyW(package, StF, pth);
271 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
273 MSI_SetPropertyW(package, TemplF, pth);
275 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
277 MSI_SetPropertyW(package, DF, pth);
279 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
281 MSI_SetPropertyW(package, PMF, pth);
283 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
285 MSI_SetPropertyW(package, ATF, pth);
287 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
289 MSI_SetPropertyW(package, ADF, pth);
291 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
293 MSI_SetPropertyW(package, SF, pth);
294 MSI_SetPropertyW(package, SF16, pth);
296 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
298 MSI_SetPropertyW(package, LADF, pth);
300 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
302 MSI_SetPropertyW(package, MPF, pth);
304 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
306 MSI_SetPropertyW(package, PF, pth);
308 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
310 MSI_SetPropertyW(package, WF, pth);
312 /* Physical Memory is specified in MB. Using total amount. */
313 msex.dwLength = sizeof(msex);
314 GlobalMemoryStatusEx( &msex );
315 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
316 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
318 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
319 ptr = strchrW(pth,'\\');
322 MSI_SetPropertyW(package, WV, pth);
324 GetTempPathW(MAX_PATH,pth);
325 MSI_SetPropertyW(package, TF, pth);
328 /* in a wine environment the user is always admin and privileged */
329 MSI_SetPropertyW(package,szAdminUser,szOne);
330 MSI_SetPropertyW(package,szPriv,szOne);
331 MSI_SetPropertyW(package, szAllUsers, szOne);
333 /* set the os things */
334 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
335 GetVersionExA(&OSVersion);
336 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
337 sprintfW(verstr,szFormat,verval);
338 switch (OSVersion.dwPlatformId)
340 case VER_PLATFORM_WIN32_WINDOWS:
341 MSI_SetPropertyW(package,v9x,verstr);
343 case VER_PLATFORM_WIN32_NT:
344 MSI_SetPropertyW(package,vNT,verstr);
347 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
348 MSI_SetPropertyW(package,szWinBuild,verstr);
349 /* just fudge this */
350 MSI_SetPropertyW(package,szSPL,szSix);
352 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
353 MSI_SetPropertyW( package, szVersionMsi, bufstr );
355 GetSystemInfo( &sys_info );
356 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
358 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
359 MSI_SetPropertyW( package, szIntel, bufstr );
362 /* Screen properties. */
364 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
365 MSI_SetPropertyW( package, szScreenX, bufstr );
366 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
367 MSI_SetPropertyW( package, szScreenY, bufstr );
368 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
369 MSI_SetPropertyW( package, szColorBits, bufstr );
372 /* USERNAME and COMPANYNAME */
373 res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
374 if (res != ERROR_SUCCESS)
377 check = msi_dup_property( package, szUSERNAME );
380 LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
381 MSI_SetPropertyW( package, szUSERNAME, user );
387 check = msi_dup_property( package, szCOMPANYNAME );
390 LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
391 MSI_SetPropertyW( package, szCOMPANYNAME, company );
399 static UINT msi_get_word_count( MSIPACKAGE *package )
404 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
407 ERR("Unable to allocate handle\n");
410 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
412 if (rc != ERROR_SUCCESS)
414 ERR("Unable to open Summary Information\n");
418 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
419 &word_count, NULL, NULL, NULL );
420 if (rc != ERROR_SUCCESS)
422 ERR("Unable to query word count\n");
423 MsiCloseHandle(suminfo);
427 MsiCloseHandle(suminfo);
431 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPWSTR base_url )
433 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
434 static const WCHAR szpi[] = {'%','i',0};
435 static const WCHAR szProductCode[] = {
436 'P','r','o','d','u','c','t','C','o','d','e',0};
437 MSIPACKAGE *package = NULL;
443 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
447 msiobj_addref( &db->hdr );
450 list_init( &package->components );
451 list_init( &package->features );
452 list_init( &package->files );
453 list_init( &package->tempfiles );
454 list_init( &package->folders );
455 package->ActionFormat = NULL;
456 package->LastAction = NULL;
457 package->dialog = NULL;
458 package->next_dialog = NULL;
459 list_init( &package->subscriptions );
460 list_init( &package->appids );
461 list_init( &package->classes );
462 list_init( &package->mimes );
463 list_init( &package->extensions );
464 list_init( &package->progids );
465 list_init( &package->RunningActions );
467 package->WordCount = msi_get_word_count( package );
468 package->PackagePath = strdupW( db->path );
469 package->BaseURL = strdupW( base_url );
471 /* OK, here is where we do a slew of things to the database to
472 * prep for all that is to come as a package */
474 for (i=0; i<PROPERTY_HASH_SIZE; i++)
475 list_init( &package->props[i] );
477 clone_properties( package );
478 set_installer_properties(package);
479 sprintfW(uilevel,szpi,gUILevel);
480 MSI_SetPropertyW(package, szLevel, uilevel);
482 package->ProductCode = msi_dup_property( package, szProductCode );
483 set_installed_prop( package );
490 * copy_package_to_temp [internal]
492 * copy the msi file to a temp file to prevent locking a CD
493 * with a multi disc install
495 * FIXME: I think this is wrong, and instead of copying the package,
496 * we should read all the tables to memory, then open the
497 * database to read binary streams on demand.
499 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
501 WCHAR path[MAX_PATH];
502 static const WCHAR szMSI[] = {'M','S','I',0};
504 GetTempPathW( MAX_PATH, path );
505 GetTempFileNameW( path, szMSI, 0, filename );
507 if( !CopyFileW( szPackage, filename, FALSE ) )
509 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
513 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
517 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
519 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
523 /* call will always fail, becase size is 0,
524 * but will return ERROR_FILE_NOT_FOUND first
525 * if the file doesn't exist
527 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
528 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
530 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
531 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
533 HeapFree( GetProcessHeap(), 0, cache_entry );
537 lstrcpyW( filename, cache_entry->lpszLocalFileName );
538 HeapFree( GetProcessHeap(), 0, cache_entry );
542 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
549 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
551 MSIDATABASE *db = NULL;
554 LPWSTR ptr, base_url = NULL;
557 static const WCHAR OriginalDatabase[] =
558 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
559 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
561 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
563 if( szPackage[0] == '#' )
565 handle = atoiW(&szPackage[1]);
566 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
568 return ERROR_INVALID_HANDLE;
572 WCHAR temppath[MAX_PATH];
575 if ( UrlIsW( szPackage, URLIS_URL ) )
577 file = msi_download_file( szPackage, temppath );
579 base_url = strdupW( szPackage );
581 return ERROR_OUTOFMEMORY;
583 ptr = strrchrW( base_url, '/' );
584 if (ptr) *(ptr + 1) = '\0';
587 file = copy_package_to_temp( szPackage, temppath );
589 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
591 if (file != szPackage)
594 if( r != ERROR_SUCCESS )
596 if (GetLastError() == ERROR_FILE_NOT_FOUND)
597 msi_ui_error( 4, MB_OK | MB_ICONWARNING );
603 package = MSI_CreatePackage( db, base_url );
604 msi_free( base_url );
605 msiobj_release( &db->hdr );
607 return ERROR_FUNCTION_FAILED;
609 if( szPackage[0] != '#' )
611 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
612 MSI_SetPropertyW( package, Database, szPackage );
616 MSI_SetPropertyW( package, OriginalDatabase, db->path );
617 MSI_SetPropertyW( package, Database, db->path );
622 return ERROR_SUCCESS;
625 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
627 MSIPACKAGE *package = NULL;
630 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
632 if( szPackage == NULL )
633 return ERROR_INVALID_PARAMETER;
636 FIXME("dwOptions %08x not supported\n", dwOptions);
638 ret = MSI_OpenPackageW( szPackage, &package );
639 if( ret == ERROR_SUCCESS )
641 *phPackage = alloc_msihandle( &package->hdr );
643 ret = ERROR_NOT_ENOUGH_MEMORY;
644 msiobj_release( &package->hdr );
650 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
652 return MsiOpenPackageExW( szPackage, 0, phPackage );
655 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
657 LPWSTR szwPack = NULL;
662 szwPack = strdupAtoW( szPackage );
664 return ERROR_OUTOFMEMORY;
667 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
674 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
676 return MsiOpenPackageExA( szPackage, 0, phPackage );
679 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
682 MSIHANDLE handle = 0;
684 TRACE("(%ld)\n",hInstall);
686 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
689 handle = alloc_msihandle( &package->db->hdr );
690 msiobj_release( &package->hdr );
696 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
699 static const WCHAR szActionData[] =
700 {'A','c','t','i','o','n','D','a','t','a',0};
701 static const WCHAR szSetProgress[] =
702 {'S','e','t','P','r','o','g','r','e','s','s',0};
703 static const WCHAR szActionText[] =
704 {'A','c','t','i','o','n','T','e','x','t',0};
708 DWORD total_size = 0;
714 TRACE("%x\n", eMessageType);
717 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
718 log_type |= INSTALLLOGMODE_ERROR;
719 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
720 log_type |= INSTALLLOGMODE_WARNING;
721 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
722 log_type |= INSTALLLOGMODE_USER;
723 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
724 log_type |= INSTALLLOGMODE_INFO;
725 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
726 log_type |= INSTALLLOGMODE_COMMONDATA;
727 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
728 log_type |= INSTALLLOGMODE_ACTIONSTART;
729 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
730 log_type |= INSTALLLOGMODE_ACTIONDATA;
732 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
735 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
737 static const WCHAR template_s[]=
738 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
739 static const WCHAR format[] =
740 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
742 LPCWSTR action_text, action;
743 LPWSTR deformatted = NULL;
745 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
747 action = MSI_RecordGetString(record, 1);
748 action_text = MSI_RecordGetString(record, 2);
750 if (!action || !action_text)
753 deformat_string(package, action_text, &deformatted);
755 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
757 len += strlenW(deformatted);
758 message = msi_alloc(len*sizeof(WCHAR));
759 sprintfW(message, template_s, timet, action);
761 strcatW(message, deformatted);
762 msi_free(deformatted);
767 message = msi_alloc(1*sizeof (WCHAR));
769 msg_field = MSI_RecordGetFieldCount(record);
770 for (i = 1; i <= msg_field; i++)
774 static const WCHAR format[] = { '%','i',':',' ',0};
775 static const WCHAR space[] = { ' ',0};
777 MSI_RecordGetStringW(record,i,NULL,&sz);
779 total_size+=sz*sizeof(WCHAR);
780 tmp = msi_alloc(sz*sizeof(WCHAR));
781 message = msi_realloc(message,total_size*sizeof (WCHAR));
783 MSI_RecordGetStringW(record,i,tmp,&sz);
787 sprintfW(number,format,i);
788 strcatW(message,number);
790 strcatW(message,tmp);
792 strcatW(message,space);
798 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
799 debugstr_w(message));
801 /* convert it to ASCII */
802 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
803 NULL, 0, NULL, NULL );
804 msg = msi_alloc( len );
805 WideCharToMultiByte( CP_ACP, 0, message, -1,
806 msg, len, NULL, NULL );
808 if (gUIHandlerA && (gUIFilter & log_type))
810 rc = gUIHandlerA(gUIContext,eMessageType,msg);
813 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
814 INSTALLMESSAGE_PROGRESS))
817 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
818 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
820 if (log_file != INVALID_HANDLE_VALUE)
822 SetFilePointer(log_file,0, NULL, FILE_END);
823 WriteFile(log_file,msg,strlen(msg),&write,NULL);
824 WriteFile(log_file,"\n",1,&write,NULL);
825 CloseHandle(log_file);
832 switch (eMessageType & 0xff000000)
834 case INSTALLMESSAGE_ACTIONDATA:
835 /* FIXME: format record here instead of in ui_actiondata to get the
836 * correct action data for external scripts */
837 ControlEvent_FireSubscribedEvent(package, szActionData, record);
839 case INSTALLMESSAGE_ACTIONSTART:
843 LPCWSTR action_text = MSI_RecordGetString(record, 2);
845 deformat_string(package, action_text, &deformated);
846 uirow = MSI_CreateRecord(1);
847 MSI_RecordSetStringW(uirow, 1, deformated);
848 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
849 msi_free(deformated);
851 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
853 msiobj_release(&uirow->hdr);
856 case INSTALLMESSAGE_PROGRESS:
857 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
861 return ERROR_SUCCESS;
864 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
867 UINT ret = ERROR_INVALID_HANDLE;
868 MSIPACKAGE *package = NULL;
869 MSIRECORD *record = NULL;
871 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
873 return ERROR_INVALID_HANDLE;
875 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
879 ret = MSI_ProcessMessage( package, eMessageType, record );
882 msiobj_release( &package->hdr );
884 msiobj_release( &record->hdr );
891 typedef struct msi_property {
897 static UINT msi_prop_makehash( const WCHAR *str )
908 hash = (hash<<5) | (hash>>27);
910 return hash % PROPERTY_HASH_SIZE;
913 static msi_property *msi_prop_find( MSIPACKAGE *package, LPCWSTR key )
915 UINT hash = msi_prop_makehash( key );
918 LIST_FOR_EACH_ENTRY( prop, &package->props[hash], msi_property, entry )
919 if (!lstrcmpW( prop->key, key ))
924 static msi_property *msi_prop_add( MSIPACKAGE *package, LPCWSTR key )
926 UINT hash = msi_prop_makehash( key );
929 prop = msi_alloc( sizeof *prop );
932 prop->key = strdupW( key );
934 list_add_head( &package->props[hash], &prop->entry );
939 static void msi_delete_property( msi_property *prop )
941 list_remove( &prop->entry );
942 msi_free( prop->key );
943 msi_free( prop->value );
947 static void msi_free_properties( MSIPACKAGE *package )
951 for ( i=0; i<PROPERTY_HASH_SIZE; i++ )
953 while ( !list_empty(&package->props[i]) )
956 prop = LIST_ENTRY( list_head( &package->props[i] ),
957 msi_property, entry );
958 msi_delete_property( prop );
963 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
965 LPWSTR szwName = NULL, szwValue = NULL;
966 UINT r = ERROR_OUTOFMEMORY;
968 szwName = strdupAtoW( szName );
969 if( szName && !szwName )
972 szwValue = strdupAtoW( szValue );
973 if( szValue && !szwValue )
976 r = MsiSetPropertyW( hInstall, szwName, szwValue);
980 msi_free( szwValue );
985 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
989 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
992 return ERROR_INVALID_PARAMETER;
994 /* this one is weird... */
996 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
998 prop = msi_prop_find( package, szName );
1000 prop = msi_prop_add( package, szName );
1003 return ERROR_OUTOFMEMORY;
1007 msi_free( prop->value );
1008 prop->value = strdupW( szValue );
1011 msi_delete_property( prop );
1013 return ERROR_SUCCESS;
1016 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1018 MSIPACKAGE *package;
1021 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1023 return ERROR_INVALID_HANDLE;
1024 ret = MSI_SetPropertyW( package, szName, szValue);
1025 msiobj_release( &package->hdr );
1029 /* internal function, not compatible with MsiGetPropertyW */
1030 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
1031 LPWSTR szValueBuf, DWORD* pchValueBuf )
1036 if (*pchValueBuf > 0)
1039 prop = msi_prop_find( package, szName );
1043 TRACE("property %s not found\n", debugstr_w(szName));
1044 return ERROR_FUNCTION_FAILED;
1049 len = lstrlenW( prop->value );
1050 lstrcpynW(szValueBuf, prop->value, *pchValueBuf);
1055 if( *pchValueBuf > 0 )
1059 TRACE("%s -> %s\n", debugstr_w(szName), debugstr_w(szValueBuf));
1061 if ( *pchValueBuf <= len )
1063 TRACE("have %u, need %u -> ERROR_MORE_DATA\n", *pchValueBuf, len);
1064 r = ERROR_MORE_DATA;
1074 LPWSTR msi_dup_property( MSIPACKAGE *package, LPCWSTR szName )
1077 LPWSTR value = NULL;
1079 prop = msi_prop_find( package, szName );
1081 value = strdupW( prop->value );
1086 int msi_get_property_int( MSIPACKAGE *package, LPCWSTR name, int value )
1090 prop = msi_prop_find( package, name );
1092 value = atoiW( prop->value );
1096 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1097 awstring *szValueBuf, DWORD* pchValueBuf )
1099 static const WCHAR empty[] = {0};
1101 MSIPACKAGE *package;
1105 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1106 szValueBuf->str.w, pchValueBuf );
1109 return ERROR_INVALID_PARAMETER;
1111 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1113 return ERROR_INVALID_HANDLE;
1115 prop = msi_prop_find( package, name );
1122 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1124 msiobj_release( &package->hdr );
1129 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1130 LPSTR szValueBuf, DWORD* pchValueBuf )
1136 val.unicode = FALSE;
1137 val.str.a = szValueBuf;
1139 name = strdupAtoW( szName );
1140 if (szName && !name)
1141 return ERROR_OUTOFMEMORY;
1143 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1148 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1149 LPWSTR szValueBuf, DWORD* pchValueBuf )
1154 val.str.w = szValueBuf;
1156 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );