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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
39 #include "wine/unicode.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
47 static void MSI_FreePackage( MSIOBJECTHDR *arg)
49 MSIPACKAGE *package= (MSIPACKAGE*) arg;
52 msi_dialog_destroy( package->dialog );
53 ACTION_free_package_structures(package);
55 msiobj_release( &package->db->hdr );
58 static UINT clone_properties(MSIDATABASE *db)
60 MSIQUERY * view = NULL;
62 static const WCHAR CreateSql[] = {
63 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
64 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
65 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
66 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
67 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
68 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
69 static const WCHAR Query[] = {
70 'S','E','L','E','C','T',' ','*',' ',
71 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
72 static const WCHAR Insert[] = {
73 'I','N','S','E','R','T',' ','i','n','t','o',' ',
74 '`','_','P','r','o','p','e','r','t','y','`',' ',
75 '(','`','_','P','r','o','p','e','r','t','y','`',',',
76 '`','V','a','l','u','e','`',')',' ',
77 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
79 /* create the temporary properties table */
80 rc = MSI_DatabaseOpenViewW(db, CreateSql, &view);
81 if (rc != ERROR_SUCCESS)
83 rc = MSI_ViewExecute(view,0);
85 msiobj_release(&view->hdr);
86 if (rc != ERROR_SUCCESS)
89 /* clone the existing properties */
90 rc = MSI_DatabaseOpenViewW(db, Query, &view);
91 if (rc != ERROR_SUCCESS)
94 rc = MSI_ViewExecute(view, 0);
95 if (rc != ERROR_SUCCESS)
98 msiobj_release(&view->hdr);
106 rc = MSI_ViewFetch(view,&row);
107 if (rc != ERROR_SUCCESS)
110 rc = MSI_DatabaseOpenViewW(db,Insert,&view2);
111 if (rc!= ERROR_SUCCESS)
113 rc = MSI_ViewExecute(view2,row);
114 MSI_ViewClose(view2);
115 msiobj_release(&view2->hdr);
117 if (rc == ERROR_SUCCESS)
118 msiobj_release(&row->hdr);
121 msiobj_release(&view->hdr);
129 * Sets the "Installed" property to indicate that
130 * the product is installed for the current user.
132 static UINT set_installed_prop( MSIPACKAGE *package )
134 static const WCHAR szInstalled[] = {
135 'I','n','s','t','a','l','l','e','d',0 };
136 WCHAR val[2] = { '1', 0 };
140 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
141 if (r == ERROR_SUCCESS)
144 MSI_SetPropertyW( package, szInstalled, val );
151 * There are a whole slew of these we need to set
154 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
156 static VOID set_installer_properties(MSIPACKAGE *package)
160 OSVERSIONINFOA OSVersion;
163 WCHAR verstr[10], bufstr[20];
166 static const WCHAR cszbs[]={'\\',0};
167 static const WCHAR CFF[] =
168 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
169 static const WCHAR PFF[] =
170 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
171 static const WCHAR CADF[] =
172 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
173 static const WCHAR FaF[] =
174 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
175 static const WCHAR FoF[] =
176 {'F','o','n','t','s','F','o','l','d','e','r',0};
177 static const WCHAR SendTF[] =
178 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
179 static const WCHAR SMF[] =
180 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
181 static const WCHAR StF[] =
182 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
183 static const WCHAR TemplF[] =
184 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
185 static const WCHAR DF[] =
186 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
187 static const WCHAR PMF[] =
188 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
189 static const WCHAR ATF[] =
190 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
191 static const WCHAR ADF[] =
192 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
193 static const WCHAR SF[] =
194 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
195 static const WCHAR SF16[] =
196 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
197 static const WCHAR LADF[] =
198 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
199 static const WCHAR MPF[] =
200 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
201 static const WCHAR PF[] =
202 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
203 static const WCHAR WF[] =
204 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
205 static const WCHAR WV[] =
206 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
207 static const WCHAR TF[]=
208 {'T','e','m','p','F','o','l','d','e','r',0};
209 static const WCHAR szAdminUser[] =
210 {'A','d','m','i','n','U','s','e','r',0};
211 static const WCHAR szPriv[] =
212 {'P','r','i','v','i','l','e','g','e','d',0};
213 static const WCHAR szOne[] =
215 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
216 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
217 static const WCHAR szFormat[] = {'%','l','i',0};
218 static const WCHAR szWinBuild[] =
219 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
220 static const WCHAR szSPL[] =
221 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
222 static const WCHAR szSix[] = {'6',0 };
224 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
225 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
226 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
227 /* Screen properties */
228 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
229 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
230 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
231 static const WCHAR szScreenFormat[] = {'%','d',0};
232 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
233 SYSTEM_INFO sys_info;
236 * Other things that probably should be set:
238 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
239 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
240 * ProductState CaptionHeight BorderTop BorderSide TextHeight
241 * RedirectedDllSupport Time Date Privileged
244 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
246 MSI_SetPropertyW(package, CFF, pth);
248 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
250 MSI_SetPropertyW(package, PFF, pth);
252 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
254 MSI_SetPropertyW(package, CADF, pth);
256 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
258 MSI_SetPropertyW(package, FaF, pth);
260 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
262 MSI_SetPropertyW(package, FoF, pth);
264 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
266 MSI_SetPropertyW(package, SendTF, pth);
268 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
270 MSI_SetPropertyW(package, SMF, pth);
272 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
274 MSI_SetPropertyW(package, StF, pth);
276 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
278 MSI_SetPropertyW(package, TemplF, pth);
280 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
282 MSI_SetPropertyW(package, DF, pth);
284 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
286 MSI_SetPropertyW(package, PMF, pth);
288 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
290 MSI_SetPropertyW(package, ATF, pth);
292 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
294 MSI_SetPropertyW(package, ADF, pth);
296 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
298 MSI_SetPropertyW(package, SF, pth);
299 MSI_SetPropertyW(package, SF16, pth);
301 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
303 MSI_SetPropertyW(package, LADF, pth);
305 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
307 MSI_SetPropertyW(package, MPF, pth);
309 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
311 MSI_SetPropertyW(package, PF, pth);
313 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
315 MSI_SetPropertyW(package, WF, pth);
317 /* Physical Memory is specified in MB. Using total amount. */
318 msex.dwLength = sizeof(msex);
319 GlobalMemoryStatusEx( &msex );
320 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
321 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
323 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
324 ptr = strchrW(pth,'\\');
327 MSI_SetPropertyW(package, WV, pth);
329 GetTempPathW(MAX_PATH,pth);
330 MSI_SetPropertyW(package, TF, pth);
333 /* in a wine environment the user is always admin and privileged */
334 MSI_SetPropertyW(package,szAdminUser,szOne);
335 MSI_SetPropertyW(package,szPriv,szOne);
337 /* set the os things */
338 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
339 GetVersionExA(&OSVersion);
340 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
341 sprintfW(verstr,szFormat,verval);
342 switch (OSVersion.dwPlatformId)
344 case VER_PLATFORM_WIN32_WINDOWS:
345 MSI_SetPropertyW(package,v9x,verstr);
347 case VER_PLATFORM_WIN32_NT:
348 MSI_SetPropertyW(package,vNT,verstr);
351 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
352 MSI_SetPropertyW(package,szWinBuild,verstr);
353 /* just fudge this */
354 MSI_SetPropertyW(package,szSPL,szSix);
356 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
357 MSI_SetPropertyW( package, szVersionMsi, bufstr );
359 GetSystemInfo( &sys_info );
360 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
362 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
363 MSI_SetPropertyW( package, szIntel, bufstr );
366 /* Screen properties. */
368 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
369 MSI_SetPropertyW( package, szScreenX, bufstr );
370 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
371 MSI_SetPropertyW( package, szScreenY, bufstr );
372 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
373 MSI_SetPropertyW( package, szColorBits, bufstr );
377 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
379 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
380 static const WCHAR szpi[] = {'%','i',0};
381 static const WCHAR szProductCode[] = {
382 'P','r','o','d','u','c','t','C','o','d','e',0};
383 MSIPACKAGE *package = NULL;
388 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
392 msiobj_addref( &db->hdr );
395 list_init( &package->components );
396 list_init( &package->features );
397 list_init( &package->files );
398 list_init( &package->tempfiles );
399 list_init( &package->folders );
400 package->ActionFormat = NULL;
401 package->LastAction = NULL;
402 package->dialog = NULL;
403 package->next_dialog = NULL;
404 list_init( &package->subscriptions );
405 list_init( &package->appids );
406 list_init( &package->classes );
407 list_init( &package->mimes );
408 list_init( &package->extensions );
409 list_init( &package->progids );
410 list_init( &package->RunningActions );
412 /* OK, here is where we do a slew of things to the database to
413 * prep for all that is to come as a package */
415 clone_properties(db);
416 set_installer_properties(package);
417 sprintfW(uilevel,szpi,gUILevel);
418 MSI_SetPropertyW(package, szLevel, uilevel);
420 package->ProductCode = msi_dup_property( package, szProductCode );
421 set_installed_prop( package );
428 * copy_package_to_temp [internal]
430 * copy the msi file to a temp file to prevent locking a CD
431 * with a multi disc install
433 * FIXME: I think this is wrong, and instead of copying the package,
434 * we should read all the tables to memory, then open the
435 * database to read binary streams on demand.
437 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
439 WCHAR path[MAX_PATH];
440 static const WCHAR szMSI[] = {'M','S','I',0};
442 GetTempPathW( MAX_PATH, path );
443 GetTempFileNameW( path, szMSI, 0, filename );
445 if( !CopyFileW( szPackage, filename, FALSE ) )
447 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
451 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
455 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
457 MSIDATABASE *db = NULL;
462 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
464 if( szPackage[0] == '#' )
466 handle = atoiW(&szPackage[1]);
467 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
469 return ERROR_INVALID_HANDLE;
473 WCHAR temppath[MAX_PATH];
474 LPCWSTR file = copy_package_to_temp( szPackage, temppath );
476 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
478 if (file != szPackage)
481 if( r != ERROR_SUCCESS )
485 package = MSI_CreatePackage( db );
486 msiobj_release( &db->hdr );
488 return ERROR_FUNCTION_FAILED;
491 * FIXME: I don't think this is right. Maybe we should be storing the
492 * name of the database in the MSIDATABASE structure and fetching this
493 * info from there, or maybe this is only relevant to cached databases.
495 if( szPackage[0] != '#' )
497 static const WCHAR OriginalDatabase[] =
498 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
499 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
501 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
502 MSI_SetPropertyW( package, Database, szPackage );
507 return ERROR_SUCCESS;
510 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
512 MSIPACKAGE *package = NULL;
515 TRACE("%s %08lx %p\n", debugstr_w(szPackage), dwOptions, phPackage );
517 if( szPackage == NULL )
518 return ERROR_INVALID_PARAMETER;
521 FIXME("dwOptions %08lx not supported\n", dwOptions);
523 ret = MSI_OpenPackageW( szPackage, &package );
524 if( ret == ERROR_SUCCESS )
526 *phPackage = alloc_msihandle( &package->hdr );
527 msiobj_release( &package->hdr );
533 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
535 return MsiOpenPackageExW( szPackage, 0, phPackage );
538 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
540 LPWSTR szwPack = NULL;
545 szwPack = strdupAtoW( szPackage );
547 return ERROR_OUTOFMEMORY;
550 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
557 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
559 return MsiOpenPackageExA( szPackage, 0, phPackage );
562 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
565 MSIHANDLE handle = 0;
567 TRACE("(%ld)\n",hInstall);
569 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
572 handle = alloc_msihandle( &package->db->hdr );
573 msiobj_release( &package->hdr );
579 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
582 static const WCHAR szActionData[] =
583 {'A','c','t','i','o','n','D','a','t','a',0};
584 static const WCHAR szSetProgress[] =
585 {'S','e','t','P','r','o','g','r','e','s','s',0};
586 static const WCHAR szActionText[] =
587 {'A','c','t','i','o','n','T','e','x','t',0};
591 DWORD total_size = 0;
597 TRACE("%x\n", eMessageType);
600 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
601 log_type |= INSTALLLOGMODE_ERROR;
602 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
603 log_type |= INSTALLLOGMODE_WARNING;
604 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
605 log_type |= INSTALLLOGMODE_USER;
606 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
607 log_type |= INSTALLLOGMODE_INFO;
608 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
609 log_type |= INSTALLLOGMODE_COMMONDATA;
610 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
611 log_type |= INSTALLLOGMODE_ACTIONSTART;
612 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
613 log_type |= INSTALLLOGMODE_ACTIONDATA;
615 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
618 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
620 static const WCHAR template_s[]=
621 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
622 static const WCHAR format[] =
623 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
625 LPCWSTR action_text, action;
626 LPWSTR deformatted = NULL;
628 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
630 action = MSI_RecordGetString(record, 1);
631 action_text = MSI_RecordGetString(record, 2);
632 deformat_string(package, action_text, &deformatted);
634 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
636 len += strlenW(deformatted);
637 message = msi_alloc(len*sizeof(WCHAR));
638 sprintfW(message, template_s, timet, action);
640 strcatW(message, deformatted);
641 msi_free(deformatted);
646 message = msi_alloc(1*sizeof (WCHAR));
648 msg_field = MSI_RecordGetFieldCount(record);
649 for (i = 1; i <= msg_field; i++)
653 static const WCHAR format[] = { '%','i',':',' ',0};
654 static const WCHAR space[] = { ' ',0};
656 MSI_RecordGetStringW(record,i,NULL,&sz);
658 total_size+=sz*sizeof(WCHAR);
659 tmp = msi_alloc(sz*sizeof(WCHAR));
660 message = msi_realloc(message,total_size*sizeof (WCHAR));
662 MSI_RecordGetStringW(record,i,tmp,&sz);
666 sprintfW(number,format,i);
667 strcatW(message,number);
669 strcatW(message,tmp);
671 strcatW(message,space);
677 TRACE("(%p %lx %lx %s)\n",gUIHandlerA, gUIFilter, log_type,
678 debugstr_w(message));
680 /* convert it to ASCII */
681 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
682 NULL, 0, NULL, NULL );
683 msg = msi_alloc( len );
684 WideCharToMultiByte( CP_ACP, 0, message, -1,
685 msg, len, NULL, NULL );
687 if (gUIHandlerA && (gUIFilter & log_type))
689 rc = gUIHandlerA(gUIContext,eMessageType,msg);
692 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
693 INSTALLMESSAGE_PROGRESS))
696 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
697 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
699 if (log_file != INVALID_HANDLE_VALUE)
701 SetFilePointer(log_file,0, NULL, FILE_END);
702 WriteFile(log_file,msg,strlen(msg),&write,NULL);
703 WriteFile(log_file,"\n",1,&write,NULL);
704 CloseHandle(log_file);
711 switch (eMessageType & 0xff000000)
713 case INSTALLMESSAGE_ACTIONDATA:
714 /* FIXME: format record here instead of in ui_actiondata to get the
715 * correct action data for external scripts */
716 ControlEvent_FireSubscribedEvent(package, szActionData, record);
718 case INSTALLMESSAGE_ACTIONSTART:
722 LPCWSTR action_text = MSI_RecordGetString(record, 2);
724 deformat_string(package, action_text, &deformated);
725 uirow = MSI_CreateRecord(1);
726 MSI_RecordSetStringW(uirow, 1, deformated);
727 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
728 msi_free(deformated);
730 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
732 msiobj_release(&uirow->hdr);
735 case INSTALLMESSAGE_PROGRESS:
736 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
740 return ERROR_SUCCESS;
743 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
746 UINT ret = ERROR_INVALID_HANDLE;
747 MSIPACKAGE *package = NULL;
748 MSIRECORD *record = NULL;
750 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
752 return ERROR_INVALID_HANDLE;
754 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
758 ret = MSI_ProcessMessage( package, eMessageType, record );
761 msiobj_release( &package->hdr );
763 msiobj_release( &record->hdr );
769 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
771 LPWSTR szwName = NULL, szwValue = NULL;
772 UINT r = ERROR_OUTOFMEMORY;
774 szwName = strdupAtoW( szName );
775 if( szName && !szwName )
778 szwValue = strdupAtoW( szValue );
779 if( szValue && !szwValue )
782 r = MsiSetPropertyW( hInstall, szwName, szwValue);
786 msi_free( szwValue );
791 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
797 static const WCHAR Insert[]=
798 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
799 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
800 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
801 ,' ','(','?',',','?',')',0};
802 static const WCHAR Update[]=
803 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
804 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
805 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
806 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
809 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
812 return ERROR_INVALID_PARAMETER;
814 /* this one is weird... */
816 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
818 rc = MSI_GetPropertyW(package,szName,0,&sz);
819 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
821 sprintfW(Query,Update,szName);
823 row = MSI_CreateRecord(1);
824 MSI_RecordSetStringW(row,1,szValue);
829 strcpyW(Query,Insert);
831 row = MSI_CreateRecord(2);
832 MSI_RecordSetStringW(row,1,szName);
833 MSI_RecordSetStringW(row,2,szValue);
836 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
837 if (rc == ERROR_SUCCESS)
839 rc = MSI_ViewExecute(view,row);
842 msiobj_release(&view->hdr);
844 msiobj_release(&row->hdr);
849 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
854 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
856 return ERROR_INVALID_HANDLE;
857 ret = MSI_SetPropertyW( package, szName, szValue);
858 msiobj_release( &package->hdr );
862 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
864 static const WCHAR query[]=
865 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
866 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
867 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
868 '=','\'','%','s','\'',0};
870 if (!name || !name[0])
873 return MSI_QueryGetRecord( package->db, query, name );
876 /* internal function, not compatible with MsiGetPropertyW */
877 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
878 LPWSTR szValueBuf, DWORD* pchValueBuf )
881 UINT rc = ERROR_FUNCTION_FAILED;
883 row = MSI_GetPropertyRow( package, szName );
885 if (*pchValueBuf > 0)
890 rc = MSI_RecordGetStringW(row,1,szValueBuf,pchValueBuf);
891 msiobj_release(&row->hdr);
894 if (rc == ERROR_SUCCESS)
895 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
897 else if (rc == ERROR_MORE_DATA)
898 TRACE("need %li sized buffer for %s\n", *pchValueBuf,
903 TRACE("property %s not found\n", debugstr_w(szName));
909 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
910 awstring *szValueBuf, DWORD* pchValueBuf )
912 static const WCHAR empty[] = {0};
914 MSIRECORD *row = NULL;
918 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
919 szValueBuf->str.w, pchValueBuf );
922 return ERROR_INVALID_PARAMETER;
924 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
926 return ERROR_INVALID_HANDLE;
928 row = MSI_GetPropertyRow( package, name );
930 val = MSI_RecordGetString( row, 1 );
935 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
938 msiobj_release( &row->hdr );
939 msiobj_release( &package->hdr );
944 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
945 LPSTR szValueBuf, DWORD* pchValueBuf )
952 val.str.a = szValueBuf;
954 name = strdupAtoW( szName );
956 return ERROR_OUTOFMEMORY;
958 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
963 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
964 LPWSTR szValueBuf, DWORD* pchValueBuf )
969 val.str.w = szValueBuf;
971 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );