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];
145 static const WCHAR cszbs[]={'\\',0};
146 static const WCHAR CFF[] =
147 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
148 static const WCHAR PFF[] =
149 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
150 static const WCHAR CADF[] =
151 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
152 static const WCHAR FaF[] =
153 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
154 static const WCHAR FoF[] =
155 {'F','o','n','t','s','F','o','l','d','e','r',0};
156 static const WCHAR SendTF[] =
157 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
158 static const WCHAR SMF[] =
159 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
160 static const WCHAR StF[] =
161 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
162 static const WCHAR TemplF[] =
163 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
164 static const WCHAR DF[] =
165 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
166 static const WCHAR PMF[] =
167 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
168 static const WCHAR ATF[] =
169 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
170 static const WCHAR ADF[] =
171 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
172 static const WCHAR SF[] =
173 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
174 static const WCHAR SF16[] =
175 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
176 static const WCHAR LADF[] =
177 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
178 static const WCHAR MPF[] =
179 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
180 static const WCHAR PF[] =
181 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
182 static const WCHAR WF[] =
183 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
184 static const WCHAR WV[] =
185 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
186 static const WCHAR TF[]=
187 {'T','e','m','p','F','o','l','d','e','r',0};
188 static const WCHAR szAdminUser[] =
189 {'A','d','m','i','n','U','s','e','r',0};
190 static const WCHAR szPriv[] =
191 {'P','r','i','v','i','l','e','g','e','d',0};
192 static const WCHAR szOne[] =
194 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
195 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
196 static const WCHAR szFormat[] = {'%','l','i',0};
197 static const WCHAR szWinBuild[] =
198 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
199 static const WCHAR szSPL[] =
200 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
201 static const WCHAR szSix[] = {'6',0 };
203 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
204 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
205 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
206 /* Screen properties */
207 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
208 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
209 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
210 static const WCHAR szScreenFormat[] = {'%','d',0};
211 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
212 static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
213 SYSTEM_INFO sys_info;
216 * Other things that probably should be set:
218 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
219 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
220 * ProductState CaptionHeight BorderTop BorderSide TextHeight
221 * RedirectedDllSupport Time Date Privileged
224 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
226 MSI_SetPropertyW(package, CFF, pth);
228 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
230 MSI_SetPropertyW(package, PFF, pth);
232 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
234 MSI_SetPropertyW(package, CADF, pth);
236 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
238 MSI_SetPropertyW(package, FaF, pth);
240 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
242 MSI_SetPropertyW(package, FoF, pth);
244 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
246 MSI_SetPropertyW(package, SendTF, pth);
248 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
250 MSI_SetPropertyW(package, SMF, pth);
252 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
254 MSI_SetPropertyW(package, StF, pth);
256 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
258 MSI_SetPropertyW(package, TemplF, pth);
260 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
262 MSI_SetPropertyW(package, DF, pth);
264 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
266 MSI_SetPropertyW(package, PMF, pth);
268 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
270 MSI_SetPropertyW(package, ATF, pth);
272 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
274 MSI_SetPropertyW(package, ADF, pth);
276 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
278 MSI_SetPropertyW(package, SF, pth);
279 MSI_SetPropertyW(package, SF16, pth);
281 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
283 MSI_SetPropertyW(package, LADF, pth);
285 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
287 MSI_SetPropertyW(package, MPF, pth);
289 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
291 MSI_SetPropertyW(package, PF, pth);
293 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
295 MSI_SetPropertyW(package, WF, pth);
297 /* Physical Memory is specified in MB. Using total amount. */
298 msex.dwLength = sizeof(msex);
299 GlobalMemoryStatusEx( &msex );
300 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
301 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
303 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
304 ptr = strchrW(pth,'\\');
307 MSI_SetPropertyW(package, WV, pth);
309 GetTempPathW(MAX_PATH,pth);
310 MSI_SetPropertyW(package, TF, pth);
313 /* in a wine environment the user is always admin and privileged */
314 MSI_SetPropertyW(package,szAdminUser,szOne);
315 MSI_SetPropertyW(package,szPriv,szOne);
316 MSI_SetPropertyW(package, szAllUsers, szOne);
318 /* set the os things */
319 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
320 GetVersionExA(&OSVersion);
321 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
322 sprintfW(verstr,szFormat,verval);
323 switch (OSVersion.dwPlatformId)
325 case VER_PLATFORM_WIN32_WINDOWS:
326 MSI_SetPropertyW(package,v9x,verstr);
328 case VER_PLATFORM_WIN32_NT:
329 MSI_SetPropertyW(package,vNT,verstr);
332 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
333 MSI_SetPropertyW(package,szWinBuild,verstr);
334 /* just fudge this */
335 MSI_SetPropertyW(package,szSPL,szSix);
337 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
338 MSI_SetPropertyW( package, szVersionMsi, bufstr );
340 GetSystemInfo( &sys_info );
341 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
343 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
344 MSI_SetPropertyW( package, szIntel, bufstr );
347 /* Screen properties. */
349 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
350 MSI_SetPropertyW( package, szScreenX, bufstr );
351 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
352 MSI_SetPropertyW( package, szScreenY, bufstr );
353 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
354 MSI_SetPropertyW( package, szColorBits, bufstr );
358 static UINT msi_get_word_count( MSIPACKAGE *package )
363 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
366 ERR("Unable to allocate handle\n");
369 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
371 if (rc != ERROR_SUCCESS)
373 ERR("Unable to open Summary Information\n");
377 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
378 &word_count, NULL, NULL, NULL );
379 if (rc != ERROR_SUCCESS)
381 ERR("Unable to query word count\n");
382 MsiCloseHandle(suminfo);
386 MsiCloseHandle(suminfo);
390 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
392 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
393 static const WCHAR szpi[] = {'%','i',0};
394 static const WCHAR szProductCode[] = {
395 'P','r','o','d','u','c','t','C','o','d','e',0};
396 MSIPACKAGE *package = NULL;
402 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
406 msiobj_addref( &db->hdr );
409 list_init( &package->components );
410 list_init( &package->features );
411 list_init( &package->files );
412 list_init( &package->tempfiles );
413 list_init( &package->folders );
414 package->ActionFormat = NULL;
415 package->LastAction = NULL;
416 package->dialog = NULL;
417 package->next_dialog = NULL;
418 list_init( &package->subscriptions );
419 list_init( &package->appids );
420 list_init( &package->classes );
421 list_init( &package->mimes );
422 list_init( &package->extensions );
423 list_init( &package->progids );
424 list_init( &package->RunningActions );
426 package->WordCount = msi_get_word_count( package );
427 package->PackagePath = strdupW( db->path );
429 /* OK, here is where we do a slew of things to the database to
430 * prep for all that is to come as a package */
432 for (i=0; i<PROPERTY_HASH_SIZE; i++)
433 list_init( &package->props[i] );
435 clone_properties( package );
436 set_installer_properties(package);
437 sprintfW(uilevel,szpi,gUILevel);
438 MSI_SetPropertyW(package, szLevel, uilevel);
440 package->ProductCode = msi_dup_property( package, szProductCode );
441 set_installed_prop( package );
448 * copy_package_to_temp [internal]
450 * copy the msi file to a temp file to prevent locking a CD
451 * with a multi disc install
453 * FIXME: I think this is wrong, and instead of copying the package,
454 * we should read all the tables to memory, then open the
455 * database to read binary streams on demand.
457 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
459 WCHAR path[MAX_PATH];
460 static const WCHAR szMSI[] = {'M','S','I',0};
462 GetTempPathW( MAX_PATH, path );
463 GetTempFileNameW( path, szMSI, 0, filename );
465 if( !CopyFileW( szPackage, filename, FALSE ) )
467 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
471 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
475 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
477 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
481 /* call will always fail, becase size is 0,
482 * but will return ERROR_FILE_NOT_FOUND first
483 * if the file doesn't exist
485 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
486 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
488 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
489 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
491 HeapFree( GetProcessHeap(), 0, cache_entry );
495 lstrcpyW( filename, cache_entry->lpszLocalFileName );
496 HeapFree( GetProcessHeap(), 0, cache_entry );
500 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
507 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
509 MSIDATABASE *db = NULL;
514 static const WCHAR OriginalDatabase[] =
515 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
516 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
518 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
520 if( szPackage[0] == '#' )
522 handle = atoiW(&szPackage[1]);
523 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
525 return ERROR_INVALID_HANDLE;
529 WCHAR temppath[MAX_PATH];
532 if ( UrlIsW( szPackage, URLIS_URL ) )
533 file = msi_download_file( szPackage, temppath );
535 file = copy_package_to_temp( szPackage, temppath );
537 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
539 if (file != szPackage)
542 if( r != ERROR_SUCCESS )
544 if (GetLastError() == ERROR_FILE_NOT_FOUND)
545 msi_ui_error( 4, MB_OK | MB_ICONWARNING );
551 package = MSI_CreatePackage( db );
552 msiobj_release( &db->hdr );
554 return ERROR_FUNCTION_FAILED;
556 if( szPackage[0] != '#' )
558 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
559 MSI_SetPropertyW( package, Database, szPackage );
563 MSI_SetPropertyW( package, OriginalDatabase, db->path );
564 MSI_SetPropertyW( package, Database, db->path );
569 return ERROR_SUCCESS;
572 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
574 MSIPACKAGE *package = NULL;
577 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
579 if( szPackage == NULL )
580 return ERROR_INVALID_PARAMETER;
583 FIXME("dwOptions %08x not supported\n", dwOptions);
585 ret = MSI_OpenPackageW( szPackage, &package );
586 if( ret == ERROR_SUCCESS )
588 *phPackage = alloc_msihandle( &package->hdr );
590 ret = ERROR_NOT_ENOUGH_MEMORY;
591 msiobj_release( &package->hdr );
597 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
599 return MsiOpenPackageExW( szPackage, 0, phPackage );
602 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
604 LPWSTR szwPack = NULL;
609 szwPack = strdupAtoW( szPackage );
611 return ERROR_OUTOFMEMORY;
614 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
621 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
623 return MsiOpenPackageExA( szPackage, 0, phPackage );
626 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
629 MSIHANDLE handle = 0;
631 TRACE("(%ld)\n",hInstall);
633 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
636 handle = alloc_msihandle( &package->db->hdr );
637 msiobj_release( &package->hdr );
643 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
646 static const WCHAR szActionData[] =
647 {'A','c','t','i','o','n','D','a','t','a',0};
648 static const WCHAR szSetProgress[] =
649 {'S','e','t','P','r','o','g','r','e','s','s',0};
650 static const WCHAR szActionText[] =
651 {'A','c','t','i','o','n','T','e','x','t',0};
655 DWORD total_size = 0;
661 TRACE("%x\n", eMessageType);
664 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
665 log_type |= INSTALLLOGMODE_ERROR;
666 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
667 log_type |= INSTALLLOGMODE_WARNING;
668 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
669 log_type |= INSTALLLOGMODE_USER;
670 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
671 log_type |= INSTALLLOGMODE_INFO;
672 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
673 log_type |= INSTALLLOGMODE_COMMONDATA;
674 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
675 log_type |= INSTALLLOGMODE_ACTIONSTART;
676 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
677 log_type |= INSTALLLOGMODE_ACTIONDATA;
679 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
682 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
684 static const WCHAR template_s[]=
685 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
686 static const WCHAR format[] =
687 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
689 LPCWSTR action_text, action;
690 LPWSTR deformatted = NULL;
692 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
694 action = MSI_RecordGetString(record, 1);
695 action_text = MSI_RecordGetString(record, 2);
697 if (!action || !action_text)
700 deformat_string(package, action_text, &deformatted);
702 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
704 len += strlenW(deformatted);
705 message = msi_alloc(len*sizeof(WCHAR));
706 sprintfW(message, template_s, timet, action);
708 strcatW(message, deformatted);
709 msi_free(deformatted);
714 message = msi_alloc(1*sizeof (WCHAR));
716 msg_field = MSI_RecordGetFieldCount(record);
717 for (i = 1; i <= msg_field; i++)
721 static const WCHAR format[] = { '%','i',':',' ',0};
722 static const WCHAR space[] = { ' ',0};
724 MSI_RecordGetStringW(record,i,NULL,&sz);
726 total_size+=sz*sizeof(WCHAR);
727 tmp = msi_alloc(sz*sizeof(WCHAR));
728 message = msi_realloc(message,total_size*sizeof (WCHAR));
730 MSI_RecordGetStringW(record,i,tmp,&sz);
734 sprintfW(number,format,i);
735 strcatW(message,number);
737 strcatW(message,tmp);
739 strcatW(message,space);
745 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
746 debugstr_w(message));
748 /* convert it to ASCII */
749 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
750 NULL, 0, NULL, NULL );
751 msg = msi_alloc( len );
752 WideCharToMultiByte( CP_ACP, 0, message, -1,
753 msg, len, NULL, NULL );
755 if (gUIHandlerA && (gUIFilter & log_type))
757 rc = gUIHandlerA(gUIContext,eMessageType,msg);
760 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
761 INSTALLMESSAGE_PROGRESS))
764 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
765 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
767 if (log_file != INVALID_HANDLE_VALUE)
769 SetFilePointer(log_file,0, NULL, FILE_END);
770 WriteFile(log_file,msg,strlen(msg),&write,NULL);
771 WriteFile(log_file,"\n",1,&write,NULL);
772 CloseHandle(log_file);
779 switch (eMessageType & 0xff000000)
781 case INSTALLMESSAGE_ACTIONDATA:
782 /* FIXME: format record here instead of in ui_actiondata to get the
783 * correct action data for external scripts */
784 ControlEvent_FireSubscribedEvent(package, szActionData, record);
786 case INSTALLMESSAGE_ACTIONSTART:
790 LPCWSTR action_text = MSI_RecordGetString(record, 2);
792 deformat_string(package, action_text, &deformated);
793 uirow = MSI_CreateRecord(1);
794 MSI_RecordSetStringW(uirow, 1, deformated);
795 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
796 msi_free(deformated);
798 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
800 msiobj_release(&uirow->hdr);
803 case INSTALLMESSAGE_PROGRESS:
804 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
808 return ERROR_SUCCESS;
811 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
814 UINT ret = ERROR_INVALID_HANDLE;
815 MSIPACKAGE *package = NULL;
816 MSIRECORD *record = NULL;
818 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
820 return ERROR_INVALID_HANDLE;
822 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
826 ret = MSI_ProcessMessage( package, eMessageType, record );
829 msiobj_release( &package->hdr );
831 msiobj_release( &record->hdr );
838 typedef struct msi_property {
844 static UINT msi_prop_makehash( const WCHAR *str )
855 hash = (hash<<5) | (hash>>27);
857 return hash % PROPERTY_HASH_SIZE;
860 static msi_property *msi_prop_find( MSIPACKAGE *package, LPCWSTR key )
862 UINT hash = msi_prop_makehash( key );
865 LIST_FOR_EACH_ENTRY( prop, &package->props[hash], msi_property, entry )
866 if (!lstrcmpW( prop->key, key ))
871 static msi_property *msi_prop_add( MSIPACKAGE *package, LPCWSTR key )
873 UINT hash = msi_prop_makehash( key );
876 prop = msi_alloc( sizeof *prop );
879 prop->key = strdupW( key );
881 list_add_head( &package->props[hash], &prop->entry );
886 static void msi_delete_property( msi_property *prop )
888 list_remove( &prop->entry );
889 msi_free( prop->key );
890 msi_free( prop->value );
894 static void msi_free_properties( MSIPACKAGE *package )
898 for ( i=0; i<PROPERTY_HASH_SIZE; i++ )
900 while ( !list_empty(&package->props[i]) )
903 prop = LIST_ENTRY( list_head( &package->props[i] ),
904 msi_property, entry );
905 msi_delete_property( prop );
910 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
912 LPWSTR szwName = NULL, szwValue = NULL;
913 UINT r = ERROR_OUTOFMEMORY;
915 szwName = strdupAtoW( szName );
916 if( szName && !szwName )
919 szwValue = strdupAtoW( szValue );
920 if( szValue && !szwValue )
923 r = MsiSetPropertyW( hInstall, szwName, szwValue);
927 msi_free( szwValue );
932 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
936 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
939 return ERROR_INVALID_PARAMETER;
941 /* this one is weird... */
943 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
945 prop = msi_prop_find( package, szName );
947 prop = msi_prop_add( package, szName );
950 return ERROR_OUTOFMEMORY;
954 msi_free( prop->value );
955 prop->value = strdupW( szValue );
958 msi_delete_property( prop );
960 return ERROR_SUCCESS;
963 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
968 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
970 return ERROR_INVALID_HANDLE;
971 ret = MSI_SetPropertyW( package, szName, szValue);
972 msiobj_release( &package->hdr );
976 /* internal function, not compatible with MsiGetPropertyW */
977 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
978 LPWSTR szValueBuf, DWORD* pchValueBuf )
983 if (*pchValueBuf > 0)
986 prop = msi_prop_find( package, szName );
990 TRACE("property %s not found\n", debugstr_w(szName));
991 return ERROR_FUNCTION_FAILED;
996 len = lstrlenW( prop->value );
997 lstrcpynW(szValueBuf, prop->value, *pchValueBuf);
1002 if( *pchValueBuf > 0 )
1006 TRACE("%s -> %s\n", debugstr_w(szName), debugstr_w(szValueBuf));
1008 if ( *pchValueBuf <= len )
1010 TRACE("have %u, need %u -> ERROR_MORE_DATA\n", *pchValueBuf, len);
1011 r = ERROR_MORE_DATA;
1021 LPWSTR msi_dup_property( MSIPACKAGE *package, LPCWSTR szName )
1024 LPWSTR value = NULL;
1026 prop = msi_prop_find( package, szName );
1028 value = strdupW( prop->value );
1033 int msi_get_property_int( MSIPACKAGE *package, LPCWSTR name, int value )
1037 prop = msi_prop_find( package, name );
1039 value = atoiW( prop->value );
1043 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1044 awstring *szValueBuf, DWORD* pchValueBuf )
1046 static const WCHAR empty[] = {0};
1048 MSIPACKAGE *package;
1052 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1053 szValueBuf->str.w, pchValueBuf );
1056 return ERROR_INVALID_PARAMETER;
1058 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1060 return ERROR_INVALID_HANDLE;
1062 prop = msi_prop_find( package, name );
1069 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1071 msiobj_release( &package->hdr );
1076 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1077 LPSTR szValueBuf, DWORD* pchValueBuf )
1083 val.unicode = FALSE;
1084 val.str.a = szValueBuf;
1086 name = strdupAtoW( szName );
1087 if (szName && !name)
1088 return ERROR_OUTOFMEMORY;
1090 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1095 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1096 LPWSTR szValueBuf, DWORD* pchValueBuf )
1101 val.str.w = szValueBuf;
1103 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );