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};
233 * Other things that probably should be set:
235 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
236 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
237 * ProductState CaptionHeight BorderTop BorderSide TextHeight
238 * RedirectedDllSupport Time Date Privileged
241 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
243 MSI_SetPropertyW(package
, CFF
, pth
);
245 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
247 MSI_SetPropertyW(package
, PFF
, pth
);
249 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
251 MSI_SetPropertyW(package
, CADF
, pth
);
253 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
255 MSI_SetPropertyW(package
, FaF
, pth
);
257 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
259 MSI_SetPropertyW(package
, FoF
, pth
);
261 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
263 MSI_SetPropertyW(package
, SendTF
, pth
);
265 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
267 MSI_SetPropertyW(package
, SMF
, pth
);
269 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
271 MSI_SetPropertyW(package
, StF
, pth
);
273 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
275 MSI_SetPropertyW(package
, TemplF
, pth
);
277 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
279 MSI_SetPropertyW(package
, DF
, pth
);
281 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
283 MSI_SetPropertyW(package
, PMF
, pth
);
285 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
287 MSI_SetPropertyW(package
, ATF
, pth
);
289 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
291 MSI_SetPropertyW(package
, ADF
, pth
);
293 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
295 MSI_SetPropertyW(package
, SF
, pth
);
296 MSI_SetPropertyW(package
, SF16
, pth
);
298 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
300 MSI_SetPropertyW(package
, LADF
, pth
);
302 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
304 MSI_SetPropertyW(package
, MPF
, pth
);
306 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
308 MSI_SetPropertyW(package
, PF
, pth
);
310 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
312 MSI_SetPropertyW(package
, WF
, pth
);
314 /* Physical Memory is specified in MB. Using total amount. */
315 msex
.dwLength
= sizeof(msex
);
316 GlobalMemoryStatusEx( &msex
);
317 sprintfW( bufstr
, szScreenFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
318 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
320 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
321 ptr
= strchrW(pth
,'\\');
324 MSI_SetPropertyW(package
, WV
, pth
);
326 GetTempPathW(MAX_PATH
,pth
);
327 MSI_SetPropertyW(package
, TF
, pth
);
330 /* in a wine environment the user is always admin and privileged */
331 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
332 MSI_SetPropertyW(package
,szPriv
,szOne
);
334 /* set the os things */
335 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
336 GetVersionExA(&OSVersion
);
337 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
338 sprintfW(verstr
,szFormat
,verval
);
339 switch (OSVersion
.dwPlatformId
)
341 case VER_PLATFORM_WIN32_WINDOWS
:
342 MSI_SetPropertyW(package
,v9x
,verstr
);
344 case VER_PLATFORM_WIN32_NT
:
345 MSI_SetPropertyW(package
,vNT
,verstr
);
348 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
349 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
350 /* just fudge this */
351 MSI_SetPropertyW(package
,szSPL
,szSix
);
353 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
354 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
356 /* Screen properties. */
358 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, HORZRES
) );
359 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
360 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, VERTRES
));
361 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
362 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
363 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
367 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
)
369 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
370 static const WCHAR szpi
[] = {'%','i',0};
371 static const WCHAR szProductCode
[] = {
372 'P','r','o','d','u','c','t','C','o','d','e',0};
373 MSIPACKAGE
*package
= NULL
;
378 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
382 msiobj_addref( &db
->hdr
);
385 list_init( &package
->components
);
386 list_init( &package
->features
);
387 list_init( &package
->files
);
388 list_init( &package
->tempfiles
);
389 list_init( &package
->folders
);
390 package
->ActionFormat
= NULL
;
391 package
->LastAction
= NULL
;
392 package
->dialog
= NULL
;
393 package
->next_dialog
= NULL
;
394 list_init( &package
->subscriptions
);
395 list_init( &package
->appids
);
396 list_init( &package
->classes
);
397 list_init( &package
->mimes
);
398 list_init( &package
->extensions
);
399 list_init( &package
->progids
);
400 list_init( &package
->RunningActions
);
402 /* OK, here is where we do a slew of things to the database to
403 * prep for all that is to come as a package */
405 clone_properties(db
);
406 set_installer_properties(package
);
407 sprintfW(uilevel
,szpi
,gUILevel
);
408 MSI_SetPropertyW(package
, szLevel
, uilevel
);
410 package
->ProductCode
= msi_dup_property( package
, szProductCode
);
411 set_installed_prop( package
);
418 * copy_package_to_temp [internal]
420 * copy the msi file to a temp file to prevent locking a CD
421 * with a multi disc install
423 * FIXME: I think this is wrong, and instead of copying the package,
424 * we should read all the tables to memory, then open the
425 * database to read binary streams on demand.
427 static LPCWSTR
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
429 WCHAR path
[MAX_PATH
];
430 static const WCHAR szMSI
[] = {'M','S','I',0};
432 GetTempPathW( MAX_PATH
, path
);
433 GetTempFileNameW( path
, szMSI
, 0, filename
);
435 if( !CopyFileW( szPackage
, filename
, FALSE
) )
437 ERR("failed to copy package to temp path %s\n", debugstr_w(filename
) );
441 TRACE("Opening relocated package %s\n", debugstr_w( filename
));
445 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
447 MSIDATABASE
*db
= NULL
;
452 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
454 if( szPackage
[0] == '#' )
456 handle
= atoiW(&szPackage
[1]);
457 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
459 return ERROR_INVALID_HANDLE
;
463 WCHAR temppath
[MAX_PATH
];
464 LPCWSTR file
= copy_package_to_temp( szPackage
, temppath
);
466 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
468 if (file
!= szPackage
)
471 if( r
!= ERROR_SUCCESS
)
475 package
= MSI_CreatePackage( db
);
476 msiobj_release( &db
->hdr
);
478 return ERROR_FUNCTION_FAILED
;
481 * FIXME: I don't think this is right. Maybe we should be storing the
482 * name of the database in the MSIDATABASE structure and fetching this
483 * info from there, or maybe this is only relevant to cached databases.
485 if( szPackage
[0] != '#' )
487 static const WCHAR OriginalDatabase
[] =
488 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
489 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
491 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
492 MSI_SetPropertyW( package
, Database
, szPackage
);
497 return ERROR_SUCCESS
;
500 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
502 MSIPACKAGE
*package
= NULL
;
505 TRACE("%s %08lx %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
508 FIXME("dwOptions %08lx not supported\n", dwOptions
);
510 ret
= MSI_OpenPackageW( szPackage
, &package
);
511 if( ret
== ERROR_SUCCESS
)
513 *phPackage
= alloc_msihandle( &package
->hdr
);
514 msiobj_release( &package
->hdr
);
520 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
522 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
525 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
527 LPWSTR szwPack
= NULL
;
532 szwPack
= strdupAtoW( szPackage
);
534 return ERROR_OUTOFMEMORY
;
537 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
544 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
546 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
549 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
552 MSIHANDLE handle
= 0;
554 TRACE("(%ld)\n",hInstall
);
556 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
559 handle
= alloc_msihandle( &package
->db
->hdr
);
560 msiobj_release( &package
->hdr
);
566 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
572 DWORD total_size
= 0;
579 TRACE("%x\n", eMessageType
);
582 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
583 log_type
|= INSTALLLOGMODE_ERROR
;
584 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
585 log_type
|= INSTALLLOGMODE_WARNING
;
586 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
587 log_type
|= INSTALLLOGMODE_USER
;
588 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
589 log_type
|= INSTALLLOGMODE_INFO
;
590 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
591 log_type
|= INSTALLLOGMODE_COMMONDATA
;
592 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
593 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
594 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
595 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
597 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
600 message
= msi_alloc(1*sizeof (WCHAR
));
602 msg_field
= MSI_RecordGetFieldCount(record
);
603 for (i
= 1; i
<= msg_field
; i
++)
607 static const WCHAR format
[] = { '%','i',':',' ',0};
608 static const WCHAR space
[] = { ' ',0};
610 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
612 total_size
+=sz
*sizeof(WCHAR
);
613 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
614 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
616 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
620 sprintfW(number
,format
,i
);
621 strcatW(message
,number
);
623 strcatW(message
,tmp
);
625 strcatW(message
,space
);
630 TRACE("(%p %lx %lx %s)\n",gUIHandlerA
, gUIFilter
, log_type
,
631 debugstr_w(message
));
633 /* convert it to ASCII */
634 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1,
635 NULL
, 0, NULL
, NULL
);
636 msg
= msi_alloc( len
);
637 WideCharToMultiByte( CP_ACP
, 0, message
, -1,
638 msg
, len
, NULL
, NULL
);
640 if (gUIHandlerA
&& (gUIFilter
& log_type
))
642 rc
= gUIHandlerA(gUIContext
,eMessageType
,msg
);
645 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
646 INSTALLMESSAGE_PROGRESS
))
649 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
650 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
652 if (log_file
!= INVALID_HANDLE_VALUE
)
654 SetFilePointer(log_file
,0, NULL
, FILE_END
);
655 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
656 WriteFile(log_file
,"\n",1,&write
,NULL
);
657 CloseHandle(log_file
);
663 return ERROR_SUCCESS
;
666 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
669 UINT ret
= ERROR_INVALID_HANDLE
;
670 MSIPACKAGE
*package
= NULL
;
671 MSIRECORD
*record
= NULL
;
673 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
675 return ERROR_INVALID_HANDLE
;
677 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
681 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
684 msiobj_release( &package
->hdr
);
686 msiobj_release( &record
->hdr
);
692 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
694 LPWSTR szwName
= NULL
, szwValue
= NULL
;
695 UINT r
= ERROR_OUTOFMEMORY
;
697 szwName
= strdupAtoW( szName
);
698 if( szName
&& !szwName
)
701 szwValue
= strdupAtoW( szValue
);
702 if( szValue
&& !szwValue
)
705 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
709 msi_free( szwValue
);
714 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
720 static const WCHAR Insert
[]=
721 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
722 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
723 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
724 ,' ','(','?',',','?',')',0};
725 static const WCHAR Update
[]=
726 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
727 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
728 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
729 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
732 TRACE("%p %s %s\n", package
, debugstr_w(szName
), debugstr_w(szValue
));
735 return ERROR_INVALID_PARAMETER
;
737 /* this one is weird... */
739 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
741 rc
= MSI_GetPropertyW(package
,szName
,0,&sz
);
742 if (rc
==ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
744 sprintfW(Query
,Update
,szName
);
746 row
= MSI_CreateRecord(1);
747 MSI_RecordSetStringW(row
,1,szValue
);
752 strcpyW(Query
,Insert
);
754 row
= MSI_CreateRecord(2);
755 MSI_RecordSetStringW(row
,1,szName
);
756 MSI_RecordSetStringW(row
,2,szValue
);
759 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view
);
760 if (rc
== ERROR_SUCCESS
)
762 rc
= MSI_ViewExecute(view
,row
);
765 msiobj_release(&view
->hdr
);
767 msiobj_release(&row
->hdr
);
772 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
777 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
779 return ERROR_INVALID_HANDLE
;
780 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
781 msiobj_release( &package
->hdr
);
785 static MSIRECORD
*MSI_GetPropertyRow( MSIPACKAGE
*package
, LPCWSTR name
)
787 static const WCHAR query
[]=
788 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
789 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
790 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
791 '=','\'','%','s','\'',0};
793 if (!name
|| !name
[0])
796 return MSI_QueryGetRecord( package
->db
, query
, name
);
799 /* internal function, not compatible with MsiGetPropertyW */
800 UINT
MSI_GetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
,
801 LPWSTR szValueBuf
, DWORD
* pchValueBuf
)
804 UINT rc
= ERROR_FUNCTION_FAILED
;
806 row
= MSI_GetPropertyRow( package
, szName
);
808 if (*pchValueBuf
> 0)
813 rc
= MSI_RecordGetStringW(row
,1,szValueBuf
,pchValueBuf
);
814 msiobj_release(&row
->hdr
);
817 if (rc
== ERROR_SUCCESS
)
818 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
820 else if (rc
== ERROR_MORE_DATA
)
821 TRACE("need %li sized buffer for %s\n", *pchValueBuf
,
826 TRACE("property %s not found\n", debugstr_w(szName
));
832 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
833 awstring
*szValueBuf
, DWORD
* pchValueBuf
)
835 static const WCHAR empty
[] = {0};
837 MSIRECORD
*row
= NULL
;
841 TRACE("%lu %s %p %p\n", handle
, debugstr_w(name
),
842 szValueBuf
->str
.w
, pchValueBuf
);
845 return ERROR_INVALID_PARAMETER
;
847 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
849 return ERROR_INVALID_HANDLE
;
851 row
= MSI_GetPropertyRow( package
, name
);
853 val
= MSI_RecordGetString( row
, 1 );
858 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
861 msiobj_release( &row
->hdr
);
862 msiobj_release( &package
->hdr
);
867 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
868 LPSTR szValueBuf
, DWORD
* pchValueBuf
)
875 val
.str
.a
= szValueBuf
;
877 name
= strdupAtoW( szName
);
879 return ERROR_OUTOFMEMORY
;
881 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
886 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
887 LPWSTR szValueBuf
, DWORD
* pchValueBuf
)
892 val
.str
.w
= szValueBuf
;
894 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);