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_FreePackage( MSIOBJECTHDR *arg)
51 MSIPACKAGE *package= (MSIPACKAGE*) arg;
54 msi_dialog_destroy( package->dialog );
55 ACTION_free_package_structures(package);
57 msiobj_release( &package->db->hdr );
60 static UINT clone_properties(MSIDATABASE *db)
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',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
69 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
70 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
71 static const WCHAR Query[] = {
72 'S','E','L','E','C','T',' ','*',' ',
73 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
74 static const WCHAR Insert[] = {
75 'I','N','S','E','R','T',' ','i','n','t','o',' ',
76 '`','_','P','r','o','p','e','r','t','y','`',' ',
77 '(','`','_','P','r','o','p','e','r','t','y','`',',',
78 '`','V','a','l','u','e','`',')',' ',
79 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
81 /* create the temporary properties table */
82 rc = MSI_DatabaseOpenViewW(db, CreateSql, &view);
83 if (rc != ERROR_SUCCESS)
85 rc = MSI_ViewExecute(view,0);
87 msiobj_release(&view->hdr);
88 if (rc != ERROR_SUCCESS)
91 /* clone the existing properties */
92 rc = MSI_DatabaseOpenViewW(db, Query, &view);
93 if (rc != ERROR_SUCCESS)
96 rc = MSI_ViewExecute(view, 0);
97 if (rc != ERROR_SUCCESS)
100 msiobj_release(&view->hdr);
108 rc = MSI_ViewFetch(view,&row);
109 if (rc != ERROR_SUCCESS)
112 rc = MSI_DatabaseOpenViewW(db,Insert,&view2);
113 if (rc!= ERROR_SUCCESS)
115 rc = MSI_ViewExecute(view2,row);
116 MSI_ViewClose(view2);
117 msiobj_release(&view2->hdr);
119 if (rc == ERROR_SUCCESS)
120 msiobj_release(&row->hdr);
123 msiobj_release(&view->hdr);
131 * Sets the "Installed" property to indicate that
132 * the product is installed for the current user.
134 static UINT set_installed_prop( MSIPACKAGE *package )
136 static const WCHAR szInstalled[] = {
137 'I','n','s','t','a','l','l','e','d',0 };
138 WCHAR val[2] = { '1', 0 };
142 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
143 if (r == ERROR_SUCCESS)
146 MSI_SetPropertyW( package, szInstalled, val );
153 * There are a whole slew of these we need to set
156 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
158 static VOID set_installer_properties(MSIPACKAGE *package)
162 OSVERSIONINFOA OSVersion;
165 WCHAR verstr[10], bufstr[20];
168 static const WCHAR cszbs[]={'\\',0};
169 static const WCHAR CFF[] =
170 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
171 static const WCHAR PFF[] =
172 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
173 static const WCHAR CADF[] =
174 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
175 static const WCHAR FaF[] =
176 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
177 static const WCHAR FoF[] =
178 {'F','o','n','t','s','F','o','l','d','e','r',0};
179 static const WCHAR SendTF[] =
180 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
181 static const WCHAR SMF[] =
182 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
183 static const WCHAR StF[] =
184 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
185 static const WCHAR TemplF[] =
186 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
187 static const WCHAR DF[] =
188 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
189 static const WCHAR PMF[] =
190 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
191 static const WCHAR ATF[] =
192 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
193 static const WCHAR ADF[] =
194 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
195 static const WCHAR SF[] =
196 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
197 static const WCHAR SF16[] =
198 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
199 static const WCHAR LADF[] =
200 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
201 static const WCHAR MPF[] =
202 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
203 static const WCHAR PF[] =
204 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
205 static const WCHAR WF[] =
206 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
207 static const WCHAR WV[] =
208 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
209 static const WCHAR TF[]=
210 {'T','e','m','p','F','o','l','d','e','r',0};
211 static const WCHAR szAdminUser[] =
212 {'A','d','m','i','n','U','s','e','r',0};
213 static const WCHAR szPriv[] =
214 {'P','r','i','v','i','l','e','g','e','d',0};
215 static const WCHAR szOne[] =
217 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
218 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
219 static const WCHAR szFormat[] = {'%','l','i',0};
220 static const WCHAR szWinBuild[] =
221 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
222 static const WCHAR szSPL[] =
223 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
224 static const WCHAR szSix[] = {'6',0 };
226 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
227 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
228 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
229 /* Screen properties */
230 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
231 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
232 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
233 static const WCHAR szScreenFormat[] = {'%','d',0};
234 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
235 SYSTEM_INFO sys_info;
238 * Other things that probably should be set:
240 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
241 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
242 * ProductState CaptionHeight BorderTop BorderSide TextHeight
243 * RedirectedDllSupport Time Date Privileged
246 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
248 MSI_SetPropertyW(package, CFF, pth);
250 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
252 MSI_SetPropertyW(package, PFF, pth);
254 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
256 MSI_SetPropertyW(package, CADF, pth);
258 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
260 MSI_SetPropertyW(package, FaF, pth);
262 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
264 MSI_SetPropertyW(package, FoF, pth);
266 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
268 MSI_SetPropertyW(package, SendTF, pth);
270 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
272 MSI_SetPropertyW(package, SMF, pth);
274 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
276 MSI_SetPropertyW(package, StF, pth);
278 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
280 MSI_SetPropertyW(package, TemplF, pth);
282 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
284 MSI_SetPropertyW(package, DF, pth);
286 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
288 MSI_SetPropertyW(package, PMF, pth);
290 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
292 MSI_SetPropertyW(package, ATF, pth);
294 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
296 MSI_SetPropertyW(package, ADF, pth);
298 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
300 MSI_SetPropertyW(package, SF, pth);
301 MSI_SetPropertyW(package, SF16, pth);
303 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
305 MSI_SetPropertyW(package, LADF, pth);
307 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
309 MSI_SetPropertyW(package, MPF, pth);
311 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
313 MSI_SetPropertyW(package, PF, pth);
315 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
317 MSI_SetPropertyW(package, WF, pth);
319 /* Physical Memory is specified in MB. Using total amount. */
320 msex.dwLength = sizeof(msex);
321 GlobalMemoryStatusEx( &msex );
322 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
323 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
325 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
326 ptr = strchrW(pth,'\\');
329 MSI_SetPropertyW(package, WV, pth);
331 GetTempPathW(MAX_PATH,pth);
332 MSI_SetPropertyW(package, TF, pth);
335 /* in a wine environment the user is always admin and privileged */
336 MSI_SetPropertyW(package,szAdminUser,szOne);
337 MSI_SetPropertyW(package,szPriv,szOne);
339 /* set the os things */
340 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
341 GetVersionExA(&OSVersion);
342 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
343 sprintfW(verstr,szFormat,verval);
344 switch (OSVersion.dwPlatformId)
346 case VER_PLATFORM_WIN32_WINDOWS:
347 MSI_SetPropertyW(package,v9x,verstr);
349 case VER_PLATFORM_WIN32_NT:
350 MSI_SetPropertyW(package,vNT,verstr);
353 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
354 MSI_SetPropertyW(package,szWinBuild,verstr);
355 /* just fudge this */
356 MSI_SetPropertyW(package,szSPL,szSix);
358 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
359 MSI_SetPropertyW( package, szVersionMsi, bufstr );
361 GetSystemInfo( &sys_info );
362 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
364 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
365 MSI_SetPropertyW( package, szIntel, bufstr );
368 /* Screen properties. */
370 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
371 MSI_SetPropertyW( package, szScreenX, bufstr );
372 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
373 MSI_SetPropertyW( package, szScreenY, bufstr );
374 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
375 MSI_SetPropertyW( package, szColorBits, bufstr );
379 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
381 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
382 static const WCHAR szpi[] = {'%','i',0};
383 static const WCHAR szProductCode[] = {
384 'P','r','o','d','u','c','t','C','o','d','e',0};
385 MSIPACKAGE *package = NULL;
390 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
394 msiobj_addref( &db->hdr );
397 list_init( &package->components );
398 list_init( &package->features );
399 list_init( &package->files );
400 list_init( &package->tempfiles );
401 list_init( &package->folders );
402 package->ActionFormat = NULL;
403 package->LastAction = NULL;
404 package->dialog = NULL;
405 package->next_dialog = NULL;
406 list_init( &package->subscriptions );
407 list_init( &package->appids );
408 list_init( &package->classes );
409 list_init( &package->mimes );
410 list_init( &package->extensions );
411 list_init( &package->progids );
412 list_init( &package->RunningActions );
414 /* OK, here is where we do a slew of things to the database to
415 * prep for all that is to come as a package */
417 clone_properties(db);
418 set_installer_properties(package);
419 sprintfW(uilevel,szpi,gUILevel);
420 MSI_SetPropertyW(package, szLevel, uilevel);
422 package->ProductCode = msi_dup_property( package, szProductCode );
423 set_installed_prop( package );
430 * copy_package_to_temp [internal]
432 * copy the msi file to a temp file to prevent locking a CD
433 * with a multi disc install
435 * FIXME: I think this is wrong, and instead of copying the package,
436 * we should read all the tables to memory, then open the
437 * database to read binary streams on demand.
439 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
441 WCHAR path[MAX_PATH];
442 static const WCHAR szMSI[] = {'M','S','I',0};
444 GetTempPathW( MAX_PATH, path );
445 GetTempFileNameW( path, szMSI, 0, filename );
447 if( !CopyFileW( szPackage, filename, FALSE ) )
449 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
453 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
457 static LPCWSTR msi_download_package( LPCWSTR szUrl, LPWSTR filename )
459 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
463 /* call will always fail, becase size is 0,
464 * but will return ERROR_FILE_NOT_FOUND first
465 * if the file doesn't exist
467 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
468 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
470 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
471 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
473 HeapFree( GetProcessHeap(), 0, cache_entry );
477 lstrcpyW( filename, cache_entry->lpszLocalFileName );
478 HeapFree( GetProcessHeap(), 0, cache_entry );
482 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
489 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
491 MSIDATABASE *db = NULL;
496 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
498 if( szPackage[0] == '#' )
500 handle = atoiW(&szPackage[1]);
501 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
503 return ERROR_INVALID_HANDLE;
507 WCHAR temppath[MAX_PATH];
510 if ( UrlIsW( szPackage, URLIS_URL ) )
511 file = msi_download_package( szPackage, temppath );
513 file = copy_package_to_temp( szPackage, temppath );
515 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
517 if (file != szPackage)
520 if( r != ERROR_SUCCESS )
524 package = MSI_CreatePackage( db );
525 msiobj_release( &db->hdr );
527 return ERROR_FUNCTION_FAILED;
530 * FIXME: I don't think this is right. Maybe we should be storing the
531 * name of the database in the MSIDATABASE structure and fetching this
532 * info from there, or maybe this is only relevant to cached databases.
534 if( szPackage[0] != '#' )
536 static const WCHAR OriginalDatabase[] =
537 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
538 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
540 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
541 MSI_SetPropertyW( package, Database, szPackage );
546 return ERROR_SUCCESS;
549 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
551 MSIPACKAGE *package = NULL;
554 TRACE("%s %08lx %p\n", debugstr_w(szPackage), dwOptions, phPackage );
556 if( szPackage == NULL )
557 return ERROR_INVALID_PARAMETER;
560 FIXME("dwOptions %08lx not supported\n", dwOptions);
562 ret = MSI_OpenPackageW( szPackage, &package );
563 if( ret == ERROR_SUCCESS )
565 *phPackage = alloc_msihandle( &package->hdr );
566 msiobj_release( &package->hdr );
572 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
574 return MsiOpenPackageExW( szPackage, 0, phPackage );
577 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
579 LPWSTR szwPack = NULL;
584 szwPack = strdupAtoW( szPackage );
586 return ERROR_OUTOFMEMORY;
589 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
596 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
598 return MsiOpenPackageExA( szPackage, 0, phPackage );
601 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
604 MSIHANDLE handle = 0;
606 TRACE("(%ld)\n",hInstall);
608 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
611 handle = alloc_msihandle( &package->db->hdr );
612 msiobj_release( &package->hdr );
618 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
621 static const WCHAR szActionData[] =
622 {'A','c','t','i','o','n','D','a','t','a',0};
623 static const WCHAR szSetProgress[] =
624 {'S','e','t','P','r','o','g','r','e','s','s',0};
625 static const WCHAR szActionText[] =
626 {'A','c','t','i','o','n','T','e','x','t',0};
630 DWORD total_size = 0;
636 TRACE("%x\n", eMessageType);
639 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
640 log_type |= INSTALLLOGMODE_ERROR;
641 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
642 log_type |= INSTALLLOGMODE_WARNING;
643 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
644 log_type |= INSTALLLOGMODE_USER;
645 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
646 log_type |= INSTALLLOGMODE_INFO;
647 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
648 log_type |= INSTALLLOGMODE_COMMONDATA;
649 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
650 log_type |= INSTALLLOGMODE_ACTIONSTART;
651 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
652 log_type |= INSTALLLOGMODE_ACTIONDATA;
654 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
657 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
659 static const WCHAR template_s[]=
660 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
661 static const WCHAR format[] =
662 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
664 LPCWSTR action_text, action;
665 LPWSTR deformatted = NULL;
667 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
669 action = MSI_RecordGetString(record, 1);
670 action_text = MSI_RecordGetString(record, 2);
672 if (!action || !action_text)
675 deformat_string(package, action_text, &deformatted);
677 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
679 len += strlenW(deformatted);
680 message = msi_alloc(len*sizeof(WCHAR));
681 sprintfW(message, template_s, timet, action);
683 strcatW(message, deformatted);
684 msi_free(deformatted);
689 message = msi_alloc(1*sizeof (WCHAR));
691 msg_field = MSI_RecordGetFieldCount(record);
692 for (i = 1; i <= msg_field; i++)
696 static const WCHAR format[] = { '%','i',':',' ',0};
697 static const WCHAR space[] = { ' ',0};
699 MSI_RecordGetStringW(record,i,NULL,&sz);
701 total_size+=sz*sizeof(WCHAR);
702 tmp = msi_alloc(sz*sizeof(WCHAR));
703 message = msi_realloc(message,total_size*sizeof (WCHAR));
705 MSI_RecordGetStringW(record,i,tmp,&sz);
709 sprintfW(number,format,i);
710 strcatW(message,number);
712 strcatW(message,tmp);
714 strcatW(message,space);
720 TRACE("(%p %lx %lx %s)\n",gUIHandlerA, gUIFilter, log_type,
721 debugstr_w(message));
723 /* convert it to ASCII */
724 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
725 NULL, 0, NULL, NULL );
726 msg = msi_alloc( len );
727 WideCharToMultiByte( CP_ACP, 0, message, -1,
728 msg, len, NULL, NULL );
730 if (gUIHandlerA && (gUIFilter & log_type))
732 rc = gUIHandlerA(gUIContext,eMessageType,msg);
735 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
736 INSTALLMESSAGE_PROGRESS))
739 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
740 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
742 if (log_file != INVALID_HANDLE_VALUE)
744 SetFilePointer(log_file,0, NULL, FILE_END);
745 WriteFile(log_file,msg,strlen(msg),&write,NULL);
746 WriteFile(log_file,"\n",1,&write,NULL);
747 CloseHandle(log_file);
754 switch (eMessageType & 0xff000000)
756 case INSTALLMESSAGE_ACTIONDATA:
757 /* FIXME: format record here instead of in ui_actiondata to get the
758 * correct action data for external scripts */
759 ControlEvent_FireSubscribedEvent(package, szActionData, record);
761 case INSTALLMESSAGE_ACTIONSTART:
765 LPCWSTR action_text = MSI_RecordGetString(record, 2);
767 deformat_string(package, action_text, &deformated);
768 uirow = MSI_CreateRecord(1);
769 MSI_RecordSetStringW(uirow, 1, deformated);
770 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
771 msi_free(deformated);
773 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
775 msiobj_release(&uirow->hdr);
778 case INSTALLMESSAGE_PROGRESS:
779 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
783 return ERROR_SUCCESS;
786 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
789 UINT ret = ERROR_INVALID_HANDLE;
790 MSIPACKAGE *package = NULL;
791 MSIRECORD *record = NULL;
793 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
795 return ERROR_INVALID_HANDLE;
797 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
801 ret = MSI_ProcessMessage( package, eMessageType, record );
804 msiobj_release( &package->hdr );
806 msiobj_release( &record->hdr );
812 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
814 LPWSTR szwName = NULL, szwValue = NULL;
815 UINT r = ERROR_OUTOFMEMORY;
817 szwName = strdupAtoW( szName );
818 if( szName && !szwName )
821 szwValue = strdupAtoW( szValue );
822 if( szValue && !szwValue )
825 r = MsiSetPropertyW( hInstall, szwName, szwValue);
829 msi_free( szwValue );
834 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
840 static const WCHAR Insert[]=
841 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
842 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
843 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
844 ,' ','(','?',',','?',')',0};
845 static const WCHAR Update[]=
846 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
847 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
848 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
849 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
852 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
855 return ERROR_INVALID_PARAMETER;
857 /* this one is weird... */
859 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
861 rc = MSI_GetPropertyW(package,szName,0,&sz);
862 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
864 sprintfW(Query,Update,szName);
866 row = MSI_CreateRecord(1);
867 MSI_RecordSetStringW(row,1,szValue);
872 strcpyW(Query,Insert);
874 row = MSI_CreateRecord(2);
875 MSI_RecordSetStringW(row,1,szName);
876 MSI_RecordSetStringW(row,2,szValue);
879 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
880 if (rc == ERROR_SUCCESS)
882 rc = MSI_ViewExecute(view,row);
885 msiobj_release(&view->hdr);
887 msiobj_release(&row->hdr);
892 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
897 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
899 return ERROR_INVALID_HANDLE;
900 ret = MSI_SetPropertyW( package, szName, szValue);
901 msiobj_release( &package->hdr );
905 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
907 static const WCHAR query[]=
908 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
909 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
910 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
911 '=','\'','%','s','\'',0};
913 if (!name || !name[0])
916 return MSI_QueryGetRecord( package->db, query, name );
919 /* internal function, not compatible with MsiGetPropertyW */
920 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
921 LPWSTR szValueBuf, DWORD* pchValueBuf )
924 UINT rc = ERROR_FUNCTION_FAILED;
926 row = MSI_GetPropertyRow( package, szName );
928 if (*pchValueBuf > 0)
933 rc = MSI_RecordGetStringW(row,1,szValueBuf,pchValueBuf);
934 msiobj_release(&row->hdr);
937 if (rc == ERROR_SUCCESS)
938 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
940 else if (rc == ERROR_MORE_DATA)
941 TRACE("need %li sized buffer for %s\n", *pchValueBuf,
946 TRACE("property %s not found\n", debugstr_w(szName));
952 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
953 awstring *szValueBuf, DWORD* pchValueBuf )
955 static const WCHAR empty[] = {0};
957 MSIRECORD *row = NULL;
961 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
962 szValueBuf->str.w, pchValueBuf );
965 return ERROR_INVALID_PARAMETER;
967 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
969 return ERROR_INVALID_HANDLE;
971 row = MSI_GetPropertyRow( package, name );
973 val = MSI_RecordGetString( row, 1 );
978 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
981 msiobj_release( &row->hdr );
982 msiobj_release( &package->hdr );
987 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
988 LPSTR szValueBuf, DWORD* pchValueBuf )
995 val.str.a = szValueBuf;
997 name = strdupAtoW( szName );
999 return ERROR_OUTOFMEMORY;
1001 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1006 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1007 LPWSTR szValueBuf, DWORD* pchValueBuf )
1012 val.str.w = szValueBuf;
1014 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );