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"
39 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
45 * The MSVC headers define the MSIDBOPEN_* macros cast to LPCTSTR,
46 * which is a problem because LPCTSTR isn't defined when compiling wine.
47 * To work around this problem, we need to define LPCTSTR as LPCWSTR here,
48 * and make sure to only use it in W functions.
50 #define LPCTSTR LPCWSTR
52 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
54 MSIPACKAGE
*package
= (MSIPACKAGE
*) arg
;
57 msi_dialog_destroy( package
->dialog
);
58 ACTION_free_package_structures(package
);
60 msiobj_release( &package
->db
->hdr
);
63 static UINT
clone_properties(MSIDATABASE
*db
)
65 MSIQUERY
* view
= NULL
;
67 static const WCHAR CreateSql
[] = {
68 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
69 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
70 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
71 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
72 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
73 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
74 static const WCHAR Query
[] = {
75 'S','E','L','E','C','T',' ','*',' ',
76 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
77 static const WCHAR Insert
[] = {
78 'I','N','S','E','R','T',' ','i','n','t','o',' ',
79 '`','_','P','r','o','p','e','r','t','y','`',' ',
80 '(','`','_','P','r','o','p','e','r','t','y','`',',',
81 '`','V','a','l','u','e','`',')',' ',
82 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
84 /* create the temporary properties table */
85 rc
= MSI_DatabaseOpenViewW(db
, CreateSql
, &view
);
86 if (rc
!= ERROR_SUCCESS
)
88 rc
= MSI_ViewExecute(view
,0);
90 msiobj_release(&view
->hdr
);
91 if (rc
!= ERROR_SUCCESS
)
94 /* clone the existing properties */
95 rc
= MSI_DatabaseOpenViewW(db
, Query
, &view
);
96 if (rc
!= ERROR_SUCCESS
)
99 rc
= MSI_ViewExecute(view
, 0);
100 if (rc
!= ERROR_SUCCESS
)
103 msiobj_release(&view
->hdr
);
111 rc
= MSI_ViewFetch(view
,&row
);
112 if (rc
!= ERROR_SUCCESS
)
115 rc
= MSI_DatabaseOpenViewW(db
,Insert
,&view2
);
116 if (rc
!= ERROR_SUCCESS
)
118 rc
= MSI_ViewExecute(view2
,row
);
119 MSI_ViewClose(view2
);
120 msiobj_release(&view2
->hdr
);
122 if (rc
== ERROR_SUCCESS
)
123 msiobj_release(&row
->hdr
);
126 msiobj_release(&view
->hdr
);
132 * There are a whole slew of these we need to set
135 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
137 static VOID
set_installer_properties(MSIPACKAGE
*package
)
141 OSVERSIONINFOA OSVersion
;
144 WCHAR verstr
[10], bufstr
[20];
147 static const WCHAR cszbs
[]={'\\',0};
148 static const WCHAR CFF
[] =
149 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
150 static const WCHAR PFF
[] =
151 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
152 static const WCHAR CADF
[] =
153 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
154 static const WCHAR FaF
[] =
155 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
156 static const WCHAR FoF
[] =
157 {'F','o','n','t','s','F','o','l','d','e','r',0};
158 static const WCHAR SendTF
[] =
159 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
160 static const WCHAR SMF
[] =
161 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
162 static const WCHAR StF
[] =
163 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
164 static const WCHAR TemplF
[] =
165 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
166 static const WCHAR DF
[] =
167 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
168 static const WCHAR PMF
[] =
169 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
170 static const WCHAR ATF
[] =
171 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
172 static const WCHAR ADF
[] =
173 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
174 static const WCHAR SF
[] =
175 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
176 static const WCHAR SF16
[] =
177 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
178 static const WCHAR LADF
[] =
179 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
180 static const WCHAR MPF
[] =
181 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
182 static const WCHAR PF
[] =
183 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
184 static const WCHAR WF
[] =
185 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
186 static const WCHAR WV
[] =
187 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
188 static const WCHAR TF
[]=
189 {'T','e','m','p','F','o','l','d','e','r',0};
190 static const WCHAR szAdminUser
[] =
191 {'A','d','m','i','n','U','s','e','r',0};
192 static const WCHAR szPriv
[] =
193 {'P','r','i','v','i','l','e','g','e','d',0};
194 static const WCHAR szOne
[] =
196 static const WCHAR v9x
[] = { 'V','e','r','s','i','o','n','9','X',0 };
197 static const WCHAR vNT
[] = { 'V','e','r','s','i','o','n','N','T',0 };
198 static const WCHAR szFormat
[] = {'%','l','i',0};
199 static const WCHAR szWinBuild
[] =
200 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
201 static const WCHAR szSPL
[] =
202 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
203 static const WCHAR szSix
[] = {'6',0 };
205 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
206 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
207 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
208 /* Screen properties */
209 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
210 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
211 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
212 static const WCHAR szScreenFormat
[] = {'%','d',0};
215 * Other things I notice set
238 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
240 MSI_SetPropertyW(package
, CFF
, pth
);
242 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
244 MSI_SetPropertyW(package
, PFF
, pth
);
246 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
248 MSI_SetPropertyW(package
, CADF
, pth
);
250 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
252 MSI_SetPropertyW(package
, FaF
, pth
);
254 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
256 MSI_SetPropertyW(package
, FoF
, pth
);
258 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
260 MSI_SetPropertyW(package
, SendTF
, pth
);
262 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
264 MSI_SetPropertyW(package
, SMF
, pth
);
266 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
268 MSI_SetPropertyW(package
, StF
, pth
);
270 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
272 MSI_SetPropertyW(package
, TemplF
, pth
);
274 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
276 MSI_SetPropertyW(package
, DF
, pth
);
278 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
280 MSI_SetPropertyW(package
, PMF
, pth
);
282 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
284 MSI_SetPropertyW(package
, ATF
, pth
);
286 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
288 MSI_SetPropertyW(package
, ADF
, pth
);
290 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
292 MSI_SetPropertyW(package
, SF
, pth
);
293 MSI_SetPropertyW(package
, SF16
, pth
);
295 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
297 MSI_SetPropertyW(package
, LADF
, pth
);
299 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
301 MSI_SetPropertyW(package
, MPF
, pth
);
303 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
305 MSI_SetPropertyW(package
, PF
, pth
);
307 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
309 MSI_SetPropertyW(package
, WF
, pth
);
311 /* Physical Memory is specified in MB. Using total amount. */
312 msex
.dwLength
= sizeof(msex
);
313 GlobalMemoryStatusEx( &msex
);
314 sprintfW( bufstr
, szScreenFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
315 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
317 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
318 ptr
= strchrW(pth
,'\\');
321 MSI_SetPropertyW(package
, WV
, pth
);
323 GetTempPathW(MAX_PATH
,pth
);
324 MSI_SetPropertyW(package
, TF
, pth
);
327 /* in a wine environment the user is always admin and privileged */
328 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
329 MSI_SetPropertyW(package
,szPriv
,szOne
);
331 /* set the os things */
332 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
333 GetVersionExA(&OSVersion
);
334 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
335 sprintfW(verstr
,szFormat
,verval
);
336 switch (OSVersion
.dwPlatformId
)
338 case VER_PLATFORM_WIN32_WINDOWS
:
339 MSI_SetPropertyW(package
,v9x
,verstr
);
341 case VER_PLATFORM_WIN32_NT
:
342 MSI_SetPropertyW(package
,vNT
,verstr
);
345 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
346 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
347 /* just fudge this */
348 MSI_SetPropertyW(package
,szSPL
,szSix
);
350 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
351 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
353 /* Screen properties. */
355 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, HORZRES
) );
356 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
357 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, VERTRES
));
358 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
359 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
360 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
364 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
)
366 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
367 static const WCHAR szpi
[] = {'%','i',0};
368 MSIPACKAGE
*package
= NULL
;
373 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
377 msiobj_addref( &db
->hdr
);
380 list_init( &package
->components
);
381 list_init( &package
->features
);
382 list_init( &package
->files
);
383 list_init( &package
->tempfiles
);
384 list_init( &package
->folders
);
385 package
->ActionFormat
= NULL
;
386 package
->LastAction
= NULL
;
387 package
->dialog
= NULL
;
388 package
->next_dialog
= NULL
;
389 list_init( &package
->subscriptions
);
390 list_init( &package
->appids
);
391 list_init( &package
->classes
);
392 list_init( &package
->mimes
);
393 list_init( &package
->extensions
);
394 list_init( &package
->progids
);
395 list_init( &package
->RunningActions
);
397 /* OK, here is where we do a slew of things to the database to
398 * prep for all that is to come as a package */
400 clone_properties(db
);
401 set_installer_properties(package
);
402 sprintfW(uilevel
,szpi
,gUILevel
);
403 MSI_SetPropertyW(package
, szLevel
, uilevel
);
410 * copy_package_to_temp [internal]
412 * copy the msi file to a temp file to prevent locking a CD
413 * with a multi disc install
415 * FIXME: I think this is wrong, and instead of copying the package,
416 * we should read all the tables to memory, then open the
417 * database to read binary streams on demand.
419 static LPCWSTR
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
421 WCHAR path
[MAX_PATH
];
422 static const WCHAR szMSI
[] = {'M','S','I',0};
424 GetTempPathW( MAX_PATH
, path
);
425 GetTempFileNameW( path
, szMSI
, 0, filename
);
427 if( !CopyFileW( szPackage
, filename
, FALSE
) )
429 ERR("failed to copy package to temp path %s\n", debugstr_w(filename
) );
433 TRACE("Opening relocated package %s\n", debugstr_w( filename
));
437 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
439 MSIDATABASE
*db
= NULL
;
443 static const WCHAR szProductCode
[]= {'P','r','o','d','u','c','t','C','o','d','e',0};
446 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
448 if( szPackage
[0] == '#' )
450 handle
= atoiW(&szPackage
[1]);
451 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
453 return ERROR_INVALID_HANDLE
;
457 WCHAR temppath
[MAX_PATH
];
458 LPCWSTR file
= copy_package_to_temp( szPackage
, temppath
);
460 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
462 if (file
!= szPackage
)
465 if( r
!= ERROR_SUCCESS
)
469 package
= MSI_CreatePackage( db
);
470 msiobj_release( &db
->hdr
);
472 return ERROR_FUNCTION_FAILED
;
475 * FIXME: I don't think this is right. Maybe we should be storing the
476 * name of the database in the MSIDATABASE structure and fetching this
477 * info from there, or maybe this is only relevant to cached databases.
479 if( szPackage
[0] != '#' )
481 static const WCHAR OriginalDatabase
[] =
482 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
483 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
485 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
486 MSI_SetPropertyW( package
, Database
, szPackage
);
489 /* this property must exist */
491 MSI_GetPropertyW(package
,szProductCode
,NULL
,&size
);
493 package
->ProductCode
= msi_alloc(size
* sizeof(WCHAR
));
494 MSI_GetPropertyW(package
,szProductCode
,package
->ProductCode
, &size
);
498 return ERROR_SUCCESS
;
501 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
503 MSIPACKAGE
*package
= NULL
;
506 TRACE("%s %08lx %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
509 FIXME("dwOptions %08lx not supported\n", dwOptions
);
511 ret
= MSI_OpenPackageW( szPackage
, &package
);
512 if( ret
== ERROR_SUCCESS
)
514 *phPackage
= alloc_msihandle( &package
->hdr
);
515 msiobj_release( &package
->hdr
);
521 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
523 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
526 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
528 LPWSTR szwPack
= NULL
;
533 szwPack
= strdupAtoW( szPackage
);
535 return ERROR_OUTOFMEMORY
;
538 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
545 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
547 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
550 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
553 MSIHANDLE handle
= 0;
555 TRACE("(%ld)\n",hInstall
);
557 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
560 handle
= alloc_msihandle( &package
->db
->hdr
);
561 msiobj_release( &package
->hdr
);
567 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
573 DWORD total_size
= 0;
580 TRACE("%x \n",eMessageType
);
583 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
584 log_type
|= INSTALLLOGMODE_ERROR
;
585 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
586 log_type
|= INSTALLLOGMODE_WARNING
;
587 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
588 log_type
|= INSTALLLOGMODE_USER
;
589 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
590 log_type
|= INSTALLLOGMODE_INFO
;
591 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
592 log_type
|= INSTALLLOGMODE_COMMONDATA
;
593 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
594 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
595 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
596 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
598 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
601 message
= msi_alloc(1*sizeof (WCHAR
));
603 msg_field
= MSI_RecordGetFieldCount(record
);
604 for (i
= 1; i
<= msg_field
; i
++)
608 const static WCHAR format
[] = { '%','i',':',' ',0};
609 const static WCHAR space
[] = { ' ',0};
611 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
613 total_size
+=sz
*sizeof(WCHAR
);
614 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
615 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
617 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
621 sprintfW(number
,format
,i
);
622 strcatW(message
,number
);
624 strcatW(message
,tmp
);
626 strcatW(message
,space
);
631 TRACE("(%p %lx %lx %s)\n",gUIHandlerA
, gUIFilter
, log_type
,
632 debugstr_w(message
));
634 /* convert it to ASCII */
635 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1,
636 NULL
, 0, NULL
, NULL
);
637 msg
= msi_alloc( len
);
638 WideCharToMultiByte( CP_ACP
, 0, message
, -1,
639 msg
, len
, NULL
, NULL
);
641 if (gUIHandlerA
&& (gUIFilter
& log_type
))
643 rc
= gUIHandlerA(gUIContext
,eMessageType
,msg
);
646 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
647 INSTALLMESSAGE_PROGRESS
))
650 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
651 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
653 if (log_file
!= INVALID_HANDLE_VALUE
)
655 SetFilePointer(log_file
,0, NULL
, FILE_END
);
656 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
657 WriteFile(log_file
,"\n",1,&write
,NULL
);
658 CloseHandle(log_file
);
664 return ERROR_SUCCESS
;
667 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
670 UINT ret
= ERROR_INVALID_HANDLE
;
671 MSIPACKAGE
*package
= NULL
;
672 MSIRECORD
*record
= NULL
;
674 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
676 return ERROR_INVALID_HANDLE
;
678 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
682 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
685 msiobj_release( &package
->hdr
);
687 msiobj_release( &record
->hdr
);
693 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
695 LPWSTR szwName
= NULL
, szwValue
= NULL
;
696 UINT hr
= ERROR_INSTALL_FAILURE
;
700 szwName
= strdupAtoW( szName
);
707 szwValue
= strdupAtoW( szValue
);
712 hr
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
716 msi_free( szwValue
);
721 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
727 static const WCHAR Insert
[]=
728 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
729 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
730 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
731 ,' ','(','?',',','?',')',0};
732 static const WCHAR Update
[]=
733 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
734 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
735 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
736 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
739 TRACE("Setting property (%s %s)\n",debugstr_w(szName
),
740 debugstr_w(szValue
));
742 rc
= MSI_GetPropertyW(package
,szName
,0,&sz
);
743 if (rc
==ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
745 sprintfW(Query
,Update
,szName
);
747 row
= MSI_CreateRecord(1);
748 MSI_RecordSetStringW(row
,1,szValue
);
753 strcpyW(Query
,Insert
);
755 row
= MSI_CreateRecord(2);
756 MSI_RecordSetStringW(row
,1,szName
);
757 MSI_RecordSetStringW(row
,2,szValue
);
760 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view
);
761 if (rc
== ERROR_SUCCESS
)
763 rc
= MSI_ViewExecute(view
,row
);
766 msiobj_release(&view
->hdr
);
768 msiobj_release(&row
->hdr
);
773 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
779 return ERROR_INVALID_PARAMETER
;
781 return ERROR_INVALID_PARAMETER
;
783 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
785 return ERROR_INVALID_HANDLE
;
786 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
787 msiobj_release( &package
->hdr
);
791 static UINT
MSI_GetPropertyRow(MSIPACKAGE
*package
, LPCWSTR szName
, MSIRECORD
**row
)
795 static const WCHAR select
[]=
796 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
797 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
798 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
799 '=','\'','%','s','\'',0};
803 return ERROR_INVALID_PARAMETER
;
805 sz
= sizeof select
+ strlenW(szName
)*sizeof(WCHAR
);
806 query
= msi_alloc( sz
);
807 sprintfW(query
,select
,szName
);
809 rc
= MSI_DatabaseOpenViewW(package
->db
, query
, &view
);
811 if (rc
== ERROR_SUCCESS
)
813 rc
= MSI_ViewExecute(view
, 0);
814 if (rc
== ERROR_SUCCESS
)
815 rc
= MSI_ViewFetch(view
,row
);
818 msiobj_release(&view
->hdr
);
824 UINT
MSI_GetPropertyW(MSIPACKAGE
*package
, LPCWSTR szName
,
825 LPWSTR szValueBuf
, DWORD
* pchValueBuf
)
830 rc
= MSI_GetPropertyRow(package
, szName
, &row
);
832 if (*pchValueBuf
> 0)
835 if (rc
== ERROR_SUCCESS
)
837 rc
= MSI_RecordGetStringW(row
,1,szValueBuf
,pchValueBuf
);
838 msiobj_release(&row
->hdr
);
841 if (rc
== ERROR_SUCCESS
)
842 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
844 else if (rc
== ERROR_MORE_DATA
)
845 TRACE("need %li sized buffer for %s\n", *pchValueBuf
,
850 TRACE("property %s not found\n", debugstr_w(szName
));
856 UINT
MSI_GetPropertyA(MSIPACKAGE
*package
, LPCSTR szName
,
857 LPSTR szValueBuf
, DWORD
* pchValueBuf
)
861 LPWSTR szwName
= NULL
;
863 if (*pchValueBuf
> 0)
868 szwName
= strdupAtoW( szName
);
870 return ERROR_NOT_ENOUGH_MEMORY
;
873 rc
= MSI_GetPropertyRow(package
, szwName
, &row
);
874 if (rc
== ERROR_SUCCESS
)
876 rc
= MSI_RecordGetStringA(row
,1,szValueBuf
,pchValueBuf
);
877 msiobj_release(&row
->hdr
);
880 if (rc
== ERROR_SUCCESS
)
881 TRACE("returning %s for property %s\n", debugstr_a(szValueBuf
),
883 else if (rc
== ERROR_MORE_DATA
)
884 TRACE("need %ld sized buffer for %s\n", *pchValueBuf
,
889 TRACE("property not found\n");
896 UINT WINAPI
MsiGetPropertyA(MSIHANDLE hInstall
, LPCSTR szName
, LPSTR szValueBuf
, DWORD
* pchValueBuf
)
901 TRACE("%lu %s %p\n", hInstall
, debugstr_a(szName
), pchValueBuf
);
904 return ERROR_INVALID_HANDLE
;
906 return ERROR_INVALID_PARAMETER
;
907 if (NULL
!= szValueBuf
&& NULL
== pchValueBuf
)
908 return ERROR_INVALID_PARAMETER
;
910 /* This was tested against native msi */
911 if (NULL
== szValueBuf
&& NULL
!= pchValueBuf
)
914 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
916 return ERROR_INVALID_HANDLE
;
917 ret
= MSI_GetPropertyA(package
, szName
, szValueBuf
, pchValueBuf
);
918 msiobj_release( &package
->hdr
);
920 /* MsiGetProperty does not return error codes on missing properties */
921 if (ret
!= ERROR_MORE_DATA
)
928 UINT WINAPI
MsiGetPropertyW(MSIHANDLE hInstall
, LPCWSTR szName
,
929 LPWSTR szValueBuf
, DWORD
* pchValueBuf
)
934 TRACE("%lu %s %p\n", hInstall
, debugstr_w(szName
), pchValueBuf
);
937 return ERROR_INVALID_HANDLE
;
939 return ERROR_INVALID_PARAMETER
;
940 if (NULL
!= szValueBuf
&& NULL
== pchValueBuf
)
941 return ERROR_INVALID_PARAMETER
;
943 /* This was tested against native msi */
944 if (NULL
== szValueBuf
&& NULL
!= pchValueBuf
)
947 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
949 return ERROR_INVALID_HANDLE
;
950 ret
= MSI_GetPropertyW(package
, szName
, szValueBuf
, pchValueBuf
);
951 msiobj_release( &package
->hdr
);
953 /* MsiGetProperty does not return error codes on missing properties */
954 if (ret
!= ERROR_MORE_DATA
)