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
31 #include "wine/debug.h"
38 #include "wine/unicode.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static void MSI_FreePackage( MSIOBJECTHDR *arg)
48 MSIPACKAGE *package= (MSIPACKAGE*) arg;
51 msi_dialog_destroy( package->dialog );
52 ACTION_free_package_structures(package);
54 msiobj_release( &package->db->hdr );
57 static UINT clone_properties(MSIDATABASE *db)
59 MSIQUERY * view = NULL;
61 static const WCHAR CreateSql[] = {
62 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
63 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
64 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
65 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
66 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
67 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
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};
71 static const WCHAR Insert[] = {
72 'I','N','S','E','R','T',' ','i','n','t','o',' ',
73 '`','_','P','r','o','p','e','r','t','y','`',' ',
74 '(','`','_','P','r','o','p','e','r','t','y','`',',',
75 '`','V','a','l','u','e','`',')',' ',
76 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
78 /* create the temporary properties table */
79 rc = MSI_DatabaseOpenViewW(db, CreateSql, &view);
80 if (rc != ERROR_SUCCESS)
82 rc = MSI_ViewExecute(view,0);
84 msiobj_release(&view->hdr);
85 if (rc != ERROR_SUCCESS)
88 /* clone the existing properties */
89 rc = MSI_DatabaseOpenViewW(db, Query, &view);
90 if (rc != ERROR_SUCCESS)
93 rc = MSI_ViewExecute(view, 0);
94 if (rc != ERROR_SUCCESS)
97 msiobj_release(&view->hdr);
105 rc = MSI_ViewFetch(view,&row);
106 if (rc != ERROR_SUCCESS)
109 rc = MSI_DatabaseOpenViewW(db,Insert,&view2);
110 if (rc!= ERROR_SUCCESS)
112 rc = MSI_ViewExecute(view2,row);
113 MSI_ViewClose(view2);
114 msiobj_release(&view2->hdr);
116 if (rc == ERROR_SUCCESS)
117 msiobj_release(&row->hdr);
120 msiobj_release(&view->hdr);
128 * Sets the "Installed" property to indicate that
129 * the product is installed for the current user.
131 static UINT set_installed_prop( MSIPACKAGE *package )
133 static const WCHAR szInstalled[] = {
134 'I','n','s','t','a','l','l','e','d',0 };
135 WCHAR val[2] = { '1', 0 };
139 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
140 if (r == ERROR_SUCCESS)
143 MSI_SetPropertyW( package, szInstalled, val );
150 * There are a whole slew of these we need to set
153 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
155 static VOID set_installer_properties(MSIPACKAGE *package)
159 OSVERSIONINFOA OSVersion;
162 WCHAR verstr[10], bufstr[20];
165 static const WCHAR cszbs[]={'\\',0};
166 static const WCHAR CFF[] =
167 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
168 static const WCHAR PFF[] =
169 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
170 static const WCHAR CADF[] =
171 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
172 static const WCHAR FaF[] =
173 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
174 static const WCHAR FoF[] =
175 {'F','o','n','t','s','F','o','l','d','e','r',0};
176 static const WCHAR SendTF[] =
177 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
178 static const WCHAR SMF[] =
179 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
180 static const WCHAR StF[] =
181 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
182 static const WCHAR TemplF[] =
183 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
184 static const WCHAR DF[] =
185 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
186 static const WCHAR PMF[] =
187 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
188 static const WCHAR ATF[] =
189 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
190 static const WCHAR ADF[] =
191 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
192 static const WCHAR SF[] =
193 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
194 static const WCHAR SF16[] =
195 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
196 static const WCHAR LADF[] =
197 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
198 static const WCHAR MPF[] =
199 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
200 static const WCHAR PF[] =
201 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
202 static const WCHAR WF[] =
203 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
204 static const WCHAR WV[] =
205 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
206 static const WCHAR TF[]=
207 {'T','e','m','p','F','o','l','d','e','r',0};
208 static const WCHAR szAdminUser[] =
209 {'A','d','m','i','n','U','s','e','r',0};
210 static const WCHAR szPriv[] =
211 {'P','r','i','v','i','l','e','g','e','d',0};
212 static const WCHAR szOne[] =
214 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
215 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
216 static const WCHAR szFormat[] = {'%','l','i',0};
217 static const WCHAR szWinBuild[] =
218 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
219 static const WCHAR szSPL[] =
220 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
221 static const WCHAR szSix[] = {'6',0 };
223 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
224 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
225 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
226 /* Screen properties */
227 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
228 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
229 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
230 static const WCHAR szScreenFormat[] = {'%','d',0};
231 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
232 SYSTEM_INFO sys_info;
235 * Other things that probably should be set:
237 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
238 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
239 * ProductState CaptionHeight BorderTop BorderSide TextHeight
240 * RedirectedDllSupport Time Date Privileged
243 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
245 MSI_SetPropertyW(package, CFF, pth);
247 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
249 MSI_SetPropertyW(package, PFF, pth);
251 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
253 MSI_SetPropertyW(package, CADF, pth);
255 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
257 MSI_SetPropertyW(package, FaF, pth);
259 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
261 MSI_SetPropertyW(package, FoF, pth);
263 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
265 MSI_SetPropertyW(package, SendTF, pth);
267 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
269 MSI_SetPropertyW(package, SMF, pth);
271 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
273 MSI_SetPropertyW(package, StF, pth);
275 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
277 MSI_SetPropertyW(package, TemplF, pth);
279 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
281 MSI_SetPropertyW(package, DF, pth);
283 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
285 MSI_SetPropertyW(package, PMF, pth);
287 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
289 MSI_SetPropertyW(package, ATF, pth);
291 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
293 MSI_SetPropertyW(package, ADF, pth);
295 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
297 MSI_SetPropertyW(package, SF, pth);
298 MSI_SetPropertyW(package, SF16, pth);
300 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
302 MSI_SetPropertyW(package, LADF, pth);
304 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
306 MSI_SetPropertyW(package, MPF, pth);
308 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
310 MSI_SetPropertyW(package, PF, pth);
312 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
314 MSI_SetPropertyW(package, WF, pth);
316 /* Physical Memory is specified in MB. Using total amount. */
317 msex.dwLength = sizeof(msex);
318 GlobalMemoryStatusEx( &msex );
319 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
320 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
322 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
323 ptr = strchrW(pth,'\\');
326 MSI_SetPropertyW(package, WV, pth);
328 GetTempPathW(MAX_PATH,pth);
329 MSI_SetPropertyW(package, TF, pth);
332 /* in a wine environment the user is always admin and privileged */
333 MSI_SetPropertyW(package,szAdminUser,szOne);
334 MSI_SetPropertyW(package,szPriv,szOne);
336 /* set the os things */
337 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
338 GetVersionExA(&OSVersion);
339 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
340 sprintfW(verstr,szFormat,verval);
341 switch (OSVersion.dwPlatformId)
343 case VER_PLATFORM_WIN32_WINDOWS:
344 MSI_SetPropertyW(package,v9x,verstr);
346 case VER_PLATFORM_WIN32_NT:
347 MSI_SetPropertyW(package,vNT,verstr);
350 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
351 MSI_SetPropertyW(package,szWinBuild,verstr);
352 /* just fudge this */
353 MSI_SetPropertyW(package,szSPL,szSix);
355 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
356 MSI_SetPropertyW( package, szVersionMsi, bufstr );
358 GetSystemInfo( &sys_info );
359 if (sys_info.u.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
361 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
362 MSI_SetPropertyW( package, szIntel, bufstr );
365 /* Screen properties. */
367 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
368 MSI_SetPropertyW( package, szScreenX, bufstr );
369 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
370 MSI_SetPropertyW( package, szScreenY, bufstr );
371 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
372 MSI_SetPropertyW( package, szColorBits, bufstr );
376 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
378 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
379 static const WCHAR szpi[] = {'%','i',0};
380 static const WCHAR szProductCode[] = {
381 'P','r','o','d','u','c','t','C','o','d','e',0};
382 MSIPACKAGE *package = NULL;
387 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
391 msiobj_addref( &db->hdr );
394 list_init( &package->components );
395 list_init( &package->features );
396 list_init( &package->files );
397 list_init( &package->tempfiles );
398 list_init( &package->folders );
399 package->ActionFormat = NULL;
400 package->LastAction = NULL;
401 package->dialog = NULL;
402 package->next_dialog = NULL;
403 list_init( &package->subscriptions );
404 list_init( &package->appids );
405 list_init( &package->classes );
406 list_init( &package->mimes );
407 list_init( &package->extensions );
408 list_init( &package->progids );
409 list_init( &package->RunningActions );
411 /* OK, here is where we do a slew of things to the database to
412 * prep for all that is to come as a package */
414 clone_properties(db);
415 set_installer_properties(package);
416 sprintfW(uilevel,szpi,gUILevel);
417 MSI_SetPropertyW(package, szLevel, uilevel);
419 package->ProductCode = msi_dup_property( package, szProductCode );
420 set_installed_prop( package );
427 * copy_package_to_temp [internal]
429 * copy the msi file to a temp file to prevent locking a CD
430 * with a multi disc install
432 * FIXME: I think this is wrong, and instead of copying the package,
433 * we should read all the tables to memory, then open the
434 * database to read binary streams on demand.
436 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
438 WCHAR path[MAX_PATH];
439 static const WCHAR szMSI[] = {'M','S','I',0};
441 GetTempPathW( MAX_PATH, path );
442 GetTempFileNameW( path, szMSI, 0, filename );
444 if( !CopyFileW( szPackage, filename, FALSE ) )
446 ERR("failed to copy package to temp path %s\n", debugstr_w(filename) );
450 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
454 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
456 MSIDATABASE *db = NULL;
461 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
463 if( szPackage[0] == '#' )
465 handle = atoiW(&szPackage[1]);
466 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
468 return ERROR_INVALID_HANDLE;
472 WCHAR temppath[MAX_PATH];
473 LPCWSTR file = copy_package_to_temp( szPackage, temppath );
475 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
477 if (file != szPackage)
480 if( r != ERROR_SUCCESS )
484 package = MSI_CreatePackage( db );
485 msiobj_release( &db->hdr );
487 return ERROR_FUNCTION_FAILED;
490 * FIXME: I don't think this is right. Maybe we should be storing the
491 * name of the database in the MSIDATABASE structure and fetching this
492 * info from there, or maybe this is only relevant to cached databases.
494 if( szPackage[0] != '#' )
496 static const WCHAR OriginalDatabase[] =
497 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
498 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
500 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
501 MSI_SetPropertyW( package, Database, szPackage );
506 return ERROR_SUCCESS;
509 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
511 MSIPACKAGE *package = NULL;
514 TRACE("%s %08lx %p\n", debugstr_w(szPackage), dwOptions, phPackage );
517 FIXME("dwOptions %08lx not supported\n", dwOptions);
519 ret = MSI_OpenPackageW( szPackage, &package );
520 if( ret == ERROR_SUCCESS )
522 *phPackage = alloc_msihandle( &package->hdr );
523 msiobj_release( &package->hdr );
529 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
531 return MsiOpenPackageExW( szPackage, 0, phPackage );
534 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
536 LPWSTR szwPack = NULL;
541 szwPack = strdupAtoW( szPackage );
543 return ERROR_OUTOFMEMORY;
546 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
553 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
555 return MsiOpenPackageExA( szPackage, 0, phPackage );
558 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
561 MSIHANDLE handle = 0;
563 TRACE("(%ld)\n",hInstall);
565 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
568 handle = alloc_msihandle( &package->db->hdr );
569 msiobj_release( &package->hdr );
575 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
581 DWORD total_size = 0;
588 TRACE("%x\n", eMessageType);
591 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
592 log_type |= INSTALLLOGMODE_ERROR;
593 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
594 log_type |= INSTALLLOGMODE_WARNING;
595 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
596 log_type |= INSTALLLOGMODE_USER;
597 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
598 log_type |= INSTALLLOGMODE_INFO;
599 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
600 log_type |= INSTALLLOGMODE_COMMONDATA;
601 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
602 log_type |= INSTALLLOGMODE_ACTIONSTART;
603 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
604 log_type |= INSTALLLOGMODE_ACTIONDATA;
606 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
609 message = msi_alloc(1*sizeof (WCHAR));
611 msg_field = MSI_RecordGetFieldCount(record);
612 for (i = 1; i <= msg_field; i++)
616 static const WCHAR format[] = { '%','i',':',' ',0};
617 static const WCHAR space[] = { ' ',0};
619 MSI_RecordGetStringW(record,i,NULL,&sz);
621 total_size+=sz*sizeof(WCHAR);
622 tmp = msi_alloc(sz*sizeof(WCHAR));
623 message = msi_realloc(message,total_size*sizeof (WCHAR));
625 MSI_RecordGetStringW(record,i,tmp,&sz);
629 sprintfW(number,format,i);
630 strcatW(message,number);
632 strcatW(message,tmp);
634 strcatW(message,space);
639 TRACE("(%p %lx %lx %s)\n",gUIHandlerA, gUIFilter, log_type,
640 debugstr_w(message));
642 /* convert it to ASCII */
643 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
644 NULL, 0, NULL, NULL );
645 msg = msi_alloc( len );
646 WideCharToMultiByte( CP_ACP, 0, message, -1,
647 msg, len, NULL, NULL );
649 if (gUIHandlerA && (gUIFilter & log_type))
651 rc = gUIHandlerA(gUIContext,eMessageType,msg);
654 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
655 INSTALLMESSAGE_PROGRESS))
658 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
659 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
661 if (log_file != INVALID_HANDLE_VALUE)
663 SetFilePointer(log_file,0, NULL, FILE_END);
664 WriteFile(log_file,msg,strlen(msg),&write,NULL);
665 WriteFile(log_file,"\n",1,&write,NULL);
666 CloseHandle(log_file);
672 return ERROR_SUCCESS;
675 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
678 UINT ret = ERROR_INVALID_HANDLE;
679 MSIPACKAGE *package = NULL;
680 MSIRECORD *record = NULL;
682 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
684 return ERROR_INVALID_HANDLE;
686 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
690 ret = MSI_ProcessMessage( package, eMessageType, record );
693 msiobj_release( &package->hdr );
695 msiobj_release( &record->hdr );
701 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
703 LPWSTR szwName = NULL, szwValue = NULL;
704 UINT r = ERROR_OUTOFMEMORY;
706 szwName = strdupAtoW( szName );
707 if( szName && !szwName )
710 szwValue = strdupAtoW( szValue );
711 if( szValue && !szwValue )
714 r = MsiSetPropertyW( hInstall, szwName, szwValue);
718 msi_free( szwValue );
723 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
729 static const WCHAR Insert[]=
730 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
731 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
732 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
733 ,' ','(','?',',','?',')',0};
734 static const WCHAR Update[]=
735 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
736 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
737 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
738 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
741 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
744 return ERROR_INVALID_PARAMETER;
746 /* this one is weird... */
748 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
750 rc = MSI_GetPropertyW(package,szName,0,&sz);
751 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
753 sprintfW(Query,Update,szName);
755 row = MSI_CreateRecord(1);
756 MSI_RecordSetStringW(row,1,szValue);
761 strcpyW(Query,Insert);
763 row = MSI_CreateRecord(2);
764 MSI_RecordSetStringW(row,1,szName);
765 MSI_RecordSetStringW(row,2,szValue);
768 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
769 if (rc == ERROR_SUCCESS)
771 rc = MSI_ViewExecute(view,row);
774 msiobj_release(&view->hdr);
776 msiobj_release(&row->hdr);
781 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
786 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
788 return ERROR_INVALID_HANDLE;
789 ret = MSI_SetPropertyW( package, szName, szValue);
790 msiobj_release( &package->hdr );
794 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
796 static const WCHAR query[]=
797 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
798 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
799 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
800 '=','\'','%','s','\'',0};
802 if (!name || !name[0])
805 return MSI_QueryGetRecord( package->db, query, name );
808 /* internal function, not compatible with MsiGetPropertyW */
809 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
810 LPWSTR szValueBuf, DWORD* pchValueBuf )
813 UINT rc = ERROR_FUNCTION_FAILED;
815 row = MSI_GetPropertyRow( package, szName );
817 if (*pchValueBuf > 0)
822 rc = MSI_RecordGetStringW(row,1,szValueBuf,pchValueBuf);
823 msiobj_release(&row->hdr);
826 if (rc == ERROR_SUCCESS)
827 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
829 else if (rc == ERROR_MORE_DATA)
830 TRACE("need %li sized buffer for %s\n", *pchValueBuf,
835 TRACE("property %s not found\n", debugstr_w(szName));
841 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
842 awstring *szValueBuf, DWORD* pchValueBuf )
844 static const WCHAR empty[] = {0};
846 MSIRECORD *row = NULL;
850 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
851 szValueBuf->str.w, pchValueBuf );
854 return ERROR_INVALID_PARAMETER;
856 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
858 return ERROR_INVALID_HANDLE;
860 row = MSI_GetPropertyRow( package, name );
862 val = MSI_RecordGetString( row, 1 );
867 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
870 msiobj_release( &row->hdr );
871 msiobj_release( &package->hdr );
876 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
877 LPSTR szValueBuf, DWORD* pchValueBuf )
884 val.str.a = szValueBuf;
886 name = strdupAtoW( szName );
888 return ERROR_OUTOFMEMORY;
890 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
895 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
896 LPWSTR szValueBuf, DWORD* pchValueBuf )
901 val.str.w = szValueBuf;
903 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );