2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
32 #include "wine/debug.h"
41 #include "wine/unicode.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
50 static void MSI_FreePackage( MSIOBJECTHDR
*arg
)
52 MSIPACKAGE
*package
= (MSIPACKAGE
*) arg
;
55 msi_dialog_destroy( package
->dialog
);
56 ACTION_free_package_structures(package
);
58 msiobj_release( &package
->db
->hdr
);
61 static UINT
clone_properties(MSIDATABASE
*db
)
63 MSIQUERY
* view
= NULL
;
65 static const WCHAR CreateSql
[] = {
66 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
67 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
68 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
69 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
70 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
71 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
72 static const WCHAR Query
[] = {
73 'S','E','L','E','C','T',' ','*',' ',
74 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
75 static const WCHAR Insert
[] = {
76 'I','N','S','E','R','T',' ','i','n','t','o',' ',
77 '`','_','P','r','o','p','e','r','t','y','`',' ',
78 '(','`','_','P','r','o','p','e','r','t','y','`',',',
79 '`','V','a','l','u','e','`',')',' ',
80 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
82 /* create the temporary properties table */
83 rc
= MSI_DatabaseOpenViewW(db
, CreateSql
, &view
);
84 if (rc
!= ERROR_SUCCESS
)
86 rc
= MSI_ViewExecute(view
,0);
88 msiobj_release(&view
->hdr
);
89 if (rc
!= ERROR_SUCCESS
)
92 /* clone the existing properties */
93 rc
= MSI_DatabaseOpenViewW(db
, Query
, &view
);
94 if (rc
!= ERROR_SUCCESS
)
97 rc
= MSI_ViewExecute(view
, 0);
98 if (rc
!= ERROR_SUCCESS
)
101 msiobj_release(&view
->hdr
);
109 rc
= MSI_ViewFetch(view
,&row
);
110 if (rc
!= ERROR_SUCCESS
)
113 rc
= MSI_DatabaseOpenViewW(db
,Insert
,&view2
);
114 if (rc
!= ERROR_SUCCESS
)
116 rc
= MSI_ViewExecute(view2
,row
);
117 MSI_ViewClose(view2
);
118 msiobj_release(&view2
->hdr
);
120 if (rc
== ERROR_SUCCESS
)
121 msiobj_release(&row
->hdr
);
124 msiobj_release(&view
->hdr
);
132 * Sets the "Installed" property to indicate that
133 * the product is installed for the current user.
135 static UINT
set_installed_prop( MSIPACKAGE
*package
)
137 static const WCHAR szInstalled
[] = {
138 'I','n','s','t','a','l','l','e','d',0 };
139 WCHAR val
[2] = { '1', 0 };
143 r
= MSIREG_OpenUninstallKey( package
->ProductCode
, &hkey
, FALSE
);
144 if (r
== ERROR_SUCCESS
)
147 MSI_SetPropertyW( package
, szInstalled
, val
);
154 * There are a whole slew of these we need to set
157 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
159 static VOID
set_installer_properties(MSIPACKAGE
*package
)
163 OSVERSIONINFOA OSVersion
;
166 WCHAR verstr
[10], bufstr
[20];
169 static const WCHAR cszbs
[]={'\\',0};
170 static const WCHAR CFF
[] =
171 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
172 static const WCHAR PFF
[] =
173 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
174 static const WCHAR CADF
[] =
175 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
176 static const WCHAR FaF
[] =
177 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
178 static const WCHAR FoF
[] =
179 {'F','o','n','t','s','F','o','l','d','e','r',0};
180 static const WCHAR SendTF
[] =
181 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
182 static const WCHAR SMF
[] =
183 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
184 static const WCHAR StF
[] =
185 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
186 static const WCHAR TemplF
[] =
187 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
188 static const WCHAR DF
[] =
189 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
190 static const WCHAR PMF
[] =
191 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
192 static const WCHAR ATF
[] =
193 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
194 static const WCHAR ADF
[] =
195 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
196 static const WCHAR SF
[] =
197 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
198 static const WCHAR SF16
[] =
199 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
200 static const WCHAR LADF
[] =
201 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
202 static const WCHAR MPF
[] =
203 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
204 static const WCHAR PF
[] =
205 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
206 static const WCHAR WF
[] =
207 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
208 static const WCHAR WV
[] =
209 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
210 static const WCHAR TF
[]=
211 {'T','e','m','p','F','o','l','d','e','r',0};
212 static const WCHAR szAdminUser
[] =
213 {'A','d','m','i','n','U','s','e','r',0};
214 static const WCHAR szPriv
[] =
215 {'P','r','i','v','i','l','e','g','e','d',0};
216 static const WCHAR szOne
[] =
218 static const WCHAR v9x
[] = { 'V','e','r','s','i','o','n','9','X',0 };
219 static const WCHAR vNT
[] = { 'V','e','r','s','i','o','n','N','T',0 };
220 static const WCHAR szFormat
[] = {'%','l','i',0};
221 static const WCHAR szWinBuild
[] =
222 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
223 static const WCHAR szSPL
[] =
224 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
225 static const WCHAR szSix
[] = {'6',0 };
227 static const WCHAR szVersionMsi
[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
228 static const WCHAR szPhysicalMemory
[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
229 static const WCHAR szFormat2
[] = {'%','l','i','.','%','l','i',0};
230 /* Screen properties */
231 static const WCHAR szScreenX
[] = {'S','c','r','e','e','n','X',0};
232 static const WCHAR szScreenY
[] = {'S','c','r','e','e','n','Y',0};
233 static const WCHAR szColorBits
[] = {'C','o','l','o','r','B','i','t','s',0};
234 static const WCHAR szScreenFormat
[] = {'%','d',0};
235 static const WCHAR szIntel
[] = { 'I','n','t','e','l',0 };
236 SYSTEM_INFO sys_info
;
239 * Other things that probably should be set:
241 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
242 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
243 * ProductState CaptionHeight BorderTop BorderSide TextHeight
244 * RedirectedDllSupport Time Date Privileged
247 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES_COMMON
,NULL
,0,pth
);
249 MSI_SetPropertyW(package
, CFF
, pth
);
251 SHGetFolderPathW(NULL
,CSIDL_PROGRAM_FILES
,NULL
,0,pth
);
253 MSI_SetPropertyW(package
, PFF
, pth
);
255 SHGetFolderPathW(NULL
,CSIDL_COMMON_APPDATA
,NULL
,0,pth
);
257 MSI_SetPropertyW(package
, CADF
, pth
);
259 SHGetFolderPathW(NULL
,CSIDL_FAVORITES
,NULL
,0,pth
);
261 MSI_SetPropertyW(package
, FaF
, pth
);
263 SHGetFolderPathW(NULL
,CSIDL_FONTS
,NULL
,0,pth
);
265 MSI_SetPropertyW(package
, FoF
, pth
);
267 SHGetFolderPathW(NULL
,CSIDL_SENDTO
,NULL
,0,pth
);
269 MSI_SetPropertyW(package
, SendTF
, pth
);
271 SHGetFolderPathW(NULL
,CSIDL_STARTMENU
,NULL
,0,pth
);
273 MSI_SetPropertyW(package
, SMF
, pth
);
275 SHGetFolderPathW(NULL
,CSIDL_STARTUP
,NULL
,0,pth
);
277 MSI_SetPropertyW(package
, StF
, pth
);
279 SHGetFolderPathW(NULL
,CSIDL_TEMPLATES
,NULL
,0,pth
);
281 MSI_SetPropertyW(package
, TemplF
, pth
);
283 SHGetFolderPathW(NULL
,CSIDL_DESKTOP
,NULL
,0,pth
);
285 MSI_SetPropertyW(package
, DF
, pth
);
287 SHGetFolderPathW(NULL
,CSIDL_PROGRAMS
,NULL
,0,pth
);
289 MSI_SetPropertyW(package
, PMF
, pth
);
291 SHGetFolderPathW(NULL
,CSIDL_ADMINTOOLS
,NULL
,0,pth
);
293 MSI_SetPropertyW(package
, ATF
, pth
);
295 SHGetFolderPathW(NULL
,CSIDL_APPDATA
,NULL
,0,pth
);
297 MSI_SetPropertyW(package
, ADF
, pth
);
299 SHGetFolderPathW(NULL
,CSIDL_SYSTEM
,NULL
,0,pth
);
301 MSI_SetPropertyW(package
, SF
, pth
);
302 MSI_SetPropertyW(package
, SF16
, pth
);
304 SHGetFolderPathW(NULL
,CSIDL_LOCAL_APPDATA
,NULL
,0,pth
);
306 MSI_SetPropertyW(package
, LADF
, pth
);
308 SHGetFolderPathW(NULL
,CSIDL_MYPICTURES
,NULL
,0,pth
);
310 MSI_SetPropertyW(package
, MPF
, pth
);
312 SHGetFolderPathW(NULL
,CSIDL_PERSONAL
,NULL
,0,pth
);
314 MSI_SetPropertyW(package
, PF
, pth
);
316 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
318 MSI_SetPropertyW(package
, WF
, pth
);
320 /* Physical Memory is specified in MB. Using total amount. */
321 msex
.dwLength
= sizeof(msex
);
322 GlobalMemoryStatusEx( &msex
);
323 sprintfW( bufstr
, szScreenFormat
, (int)(msex
.ullTotalPhys
/1024/1024));
324 MSI_SetPropertyW(package
, szPhysicalMemory
, bufstr
);
326 SHGetFolderPathW(NULL
,CSIDL_WINDOWS
,NULL
,0,pth
);
327 ptr
= strchrW(pth
,'\\');
330 MSI_SetPropertyW(package
, WV
, pth
);
332 GetTempPathW(MAX_PATH
,pth
);
333 MSI_SetPropertyW(package
, TF
, pth
);
336 /* in a wine environment the user is always admin and privileged */
337 MSI_SetPropertyW(package
,szAdminUser
,szOne
);
338 MSI_SetPropertyW(package
,szPriv
,szOne
);
340 /* set the os things */
341 OSVersion
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFOA
);
342 GetVersionExA(&OSVersion
);
343 verval
= OSVersion
.dwMinorVersion
+OSVersion
.dwMajorVersion
*100;
344 sprintfW(verstr
,szFormat
,verval
);
345 switch (OSVersion
.dwPlatformId
)
347 case VER_PLATFORM_WIN32_WINDOWS
:
348 MSI_SetPropertyW(package
,v9x
,verstr
);
350 case VER_PLATFORM_WIN32_NT
:
351 MSI_SetPropertyW(package
,vNT
,verstr
);
354 sprintfW(verstr
,szFormat
,OSVersion
.dwBuildNumber
);
355 MSI_SetPropertyW(package
,szWinBuild
,verstr
);
356 /* just fudge this */
357 MSI_SetPropertyW(package
,szSPL
,szSix
);
359 sprintfW( bufstr
, szFormat2
, MSI_MAJORVERSION
, MSI_MINORVERSION
);
360 MSI_SetPropertyW( package
, szVersionMsi
, bufstr
);
362 GetSystemInfo( &sys_info
);
363 if (sys_info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_INTEL
)
365 sprintfW( bufstr
, szScreenFormat
, sys_info
.wProcessorLevel
);
366 MSI_SetPropertyW( package
, szIntel
, bufstr
);
369 /* Screen properties. */
371 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, HORZRES
) );
372 MSI_SetPropertyW( package
, szScreenX
, bufstr
);
373 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, VERTRES
));
374 MSI_SetPropertyW( package
, szScreenY
, bufstr
);
375 sprintfW( bufstr
, szScreenFormat
, GetDeviceCaps( dc
, BITSPIXEL
));
376 MSI_SetPropertyW( package
, szColorBits
, bufstr
);
380 static UINT
msi_get_word_count( MSIPACKAGE
*package
)
385 MSIHANDLE hdb
= alloc_msihandle( &package
->db
->hdr
);
387 rc
= MsiGetSummaryInformationW( hdb
, NULL
, 0, &suminfo
);
389 if (rc
!= ERROR_SUCCESS
)
391 ERR("Unable to open Summary Information\n");
395 rc
= MsiSummaryInfoGetPropertyW( suminfo
, PID_WORDCOUNT
, NULL
,
396 &word_count
, NULL
, NULL
, NULL
);
397 if (rc
!= ERROR_SUCCESS
)
399 ERR("Unable to query word count\n");
400 MsiCloseHandle(suminfo
);
404 MsiCloseHandle(suminfo
);
408 MSIPACKAGE
*MSI_CreatePackage( MSIDATABASE
*db
)
410 static const WCHAR szLevel
[] = { 'U','I','L','e','v','e','l',0 };
411 static const WCHAR szpi
[] = {'%','i',0};
412 static const WCHAR szProductCode
[] = {
413 'P','r','o','d','u','c','t','C','o','d','e',0};
414 MSIPACKAGE
*package
= NULL
;
419 package
= alloc_msiobject( MSIHANDLETYPE_PACKAGE
, sizeof (MSIPACKAGE
),
423 msiobj_addref( &db
->hdr
);
426 list_init( &package
->components
);
427 list_init( &package
->features
);
428 list_init( &package
->files
);
429 list_init( &package
->tempfiles
);
430 list_init( &package
->folders
);
431 package
->ActionFormat
= NULL
;
432 package
->LastAction
= NULL
;
433 package
->dialog
= NULL
;
434 package
->next_dialog
= NULL
;
435 list_init( &package
->subscriptions
);
436 list_init( &package
->appids
);
437 list_init( &package
->classes
);
438 list_init( &package
->mimes
);
439 list_init( &package
->extensions
);
440 list_init( &package
->progids
);
441 list_init( &package
->RunningActions
);
443 package
->WordCount
= msi_get_word_count( package
);
445 /* OK, here is where we do a slew of things to the database to
446 * prep for all that is to come as a package */
448 clone_properties(db
);
449 set_installer_properties(package
);
450 sprintfW(uilevel
,szpi
,gUILevel
);
451 MSI_SetPropertyW(package
, szLevel
, uilevel
);
453 package
->ProductCode
= msi_dup_property( package
, szProductCode
);
454 set_installed_prop( package
);
461 * copy_package_to_temp [internal]
463 * copy the msi file to a temp file to prevent locking a CD
464 * with a multi disc install
466 * FIXME: I think this is wrong, and instead of copying the package,
467 * we should read all the tables to memory, then open the
468 * database to read binary streams on demand.
470 static LPCWSTR
copy_package_to_temp( LPCWSTR szPackage
, LPWSTR filename
)
472 WCHAR path
[MAX_PATH
];
473 static const WCHAR szMSI
[] = {'M','S','I',0};
475 GetTempPathW( MAX_PATH
, path
);
476 GetTempFileNameW( path
, szMSI
, 0, filename
);
478 if( !CopyFileW( szPackage
, filename
, FALSE
) )
480 ERR("failed to copy package %s\n", debugstr_w(szPackage
) );
484 TRACE("Opening relocated package %s\n", debugstr_w( filename
));
488 static LPCWSTR
msi_download_package( LPCWSTR szUrl
, LPWSTR filename
)
490 LPINTERNET_CACHE_ENTRY_INFOW cache_entry
;
494 /* call will always fail, becase size is 0,
495 * but will return ERROR_FILE_NOT_FOUND first
496 * if the file doesn't exist
498 GetUrlCacheEntryInfoW( szUrl
, NULL
, &size
);
499 if ( GetLastError() != ERROR_FILE_NOT_FOUND
)
501 cache_entry
= HeapAlloc( GetProcessHeap(), 0, size
);
502 if ( !GetUrlCacheEntryInfoW( szUrl
, cache_entry
, &size
) )
504 HeapFree( GetProcessHeap(), 0, cache_entry
);
508 lstrcpyW( filename
, cache_entry
->lpszLocalFileName
);
509 HeapFree( GetProcessHeap(), 0, cache_entry
);
513 hr
= URLDownloadToCacheFileW( NULL
, szUrl
, filename
, MAX_PATH
, 0, NULL
);
520 UINT
MSI_OpenPackageW(LPCWSTR szPackage
, MSIPACKAGE
**pPackage
)
522 MSIDATABASE
*db
= NULL
;
527 TRACE("%s %p\n", debugstr_w(szPackage
), pPackage
);
529 if( szPackage
[0] == '#' )
531 handle
= atoiW(&szPackage
[1]);
532 db
= msihandle2msiinfo( handle
, MSIHANDLETYPE_DATABASE
);
534 return ERROR_INVALID_HANDLE
;
538 WCHAR temppath
[MAX_PATH
];
541 if ( UrlIsW( szPackage
, URLIS_URL
) )
542 file
= msi_download_package( szPackage
, temppath
);
544 file
= copy_package_to_temp( szPackage
, temppath
);
546 r
= MSI_OpenDatabaseW( file
, MSIDBOPEN_READONLY
, &db
);
548 if (file
!= szPackage
)
551 if( r
!= ERROR_SUCCESS
)
555 package
= MSI_CreatePackage( db
);
556 msiobj_release( &db
->hdr
);
558 return ERROR_FUNCTION_FAILED
;
561 * FIXME: I don't think this is right. Maybe we should be storing the
562 * name of the database in the MSIDATABASE structure and fetching this
563 * info from there, or maybe this is only relevant to cached databases.
565 if( szPackage
[0] != '#' )
567 static const WCHAR OriginalDatabase
[] =
568 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
569 static const WCHAR Database
[] = {'D','A','T','A','B','A','S','E',0};
571 MSI_SetPropertyW( package
, OriginalDatabase
, szPackage
);
572 MSI_SetPropertyW( package
, Database
, szPackage
);
577 return ERROR_SUCCESS
;
580 UINT WINAPI
MsiOpenPackageExW(LPCWSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
582 MSIPACKAGE
*package
= NULL
;
585 TRACE("%s %08lx %p\n", debugstr_w(szPackage
), dwOptions
, phPackage
);
587 if( szPackage
== NULL
)
588 return ERROR_INVALID_PARAMETER
;
591 FIXME("dwOptions %08lx not supported\n", dwOptions
);
593 ret
= MSI_OpenPackageW( szPackage
, &package
);
594 if( ret
== ERROR_SUCCESS
)
596 *phPackage
= alloc_msihandle( &package
->hdr
);
597 msiobj_release( &package
->hdr
);
603 UINT WINAPI
MsiOpenPackageW(LPCWSTR szPackage
, MSIHANDLE
*phPackage
)
605 return MsiOpenPackageExW( szPackage
, 0, phPackage
);
608 UINT WINAPI
MsiOpenPackageExA(LPCSTR szPackage
, DWORD dwOptions
, MSIHANDLE
*phPackage
)
610 LPWSTR szwPack
= NULL
;
615 szwPack
= strdupAtoW( szPackage
);
617 return ERROR_OUTOFMEMORY
;
620 ret
= MsiOpenPackageExW( szwPack
, dwOptions
, phPackage
);
627 UINT WINAPI
MsiOpenPackageA(LPCSTR szPackage
, MSIHANDLE
*phPackage
)
629 return MsiOpenPackageExA( szPackage
, 0, phPackage
);
632 MSIHANDLE WINAPI
MsiGetActiveDatabase(MSIHANDLE hInstall
)
635 MSIHANDLE handle
= 0;
637 TRACE("(%ld)\n",hInstall
);
639 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
642 handle
= alloc_msihandle( &package
->db
->hdr
);
643 msiobj_release( &package
->hdr
);
649 INT
MSI_ProcessMessage( MSIPACKAGE
*package
, INSTALLMESSAGE eMessageType
,
652 static const WCHAR szActionData
[] =
653 {'A','c','t','i','o','n','D','a','t','a',0};
654 static const WCHAR szSetProgress
[] =
655 {'S','e','t','P','r','o','g','r','e','s','s',0};
656 static const WCHAR szActionText
[] =
657 {'A','c','t','i','o','n','T','e','x','t',0};
661 DWORD total_size
= 0;
667 TRACE("%x\n", eMessageType
);
670 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ERROR
)
671 log_type
|= INSTALLLOGMODE_ERROR
;
672 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_WARNING
)
673 log_type
|= INSTALLLOGMODE_WARNING
;
674 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_USER
)
675 log_type
|= INSTALLLOGMODE_USER
;
676 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_INFO
)
677 log_type
|= INSTALLLOGMODE_INFO
;
678 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_COMMONDATA
)
679 log_type
|= INSTALLLOGMODE_COMMONDATA
;
680 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
681 log_type
|= INSTALLLOGMODE_ACTIONSTART
;
682 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONDATA
)
683 log_type
|= INSTALLLOGMODE_ACTIONDATA
;
685 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_PROGRESS
)
688 if ((eMessageType
& 0xff000000) == INSTALLMESSAGE_ACTIONSTART
)
690 static const WCHAR template_s
[]=
691 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
692 static const WCHAR format
[] =
693 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
695 LPCWSTR action_text
, action
;
696 LPWSTR deformatted
= NULL
;
698 GetTimeFormatW(LOCALE_USER_DEFAULT
, 0, NULL
, format
, timet
, 0x100);
700 action
= MSI_RecordGetString(record
, 1);
701 action_text
= MSI_RecordGetString(record
, 2);
703 if (!action
|| !action_text
)
706 deformat_string(package
, action_text
, &deformatted
);
708 len
= strlenW(timet
) + strlenW(action
) + strlenW(template_s
);
710 len
+= strlenW(deformatted
);
711 message
= msi_alloc(len
*sizeof(WCHAR
));
712 sprintfW(message
, template_s
, timet
, action
);
714 strcatW(message
, deformatted
);
715 msi_free(deformatted
);
720 message
= msi_alloc(1*sizeof (WCHAR
));
722 msg_field
= MSI_RecordGetFieldCount(record
);
723 for (i
= 1; i
<= msg_field
; i
++)
727 static const WCHAR format
[] = { '%','i',':',' ',0};
728 static const WCHAR space
[] = { ' ',0};
730 MSI_RecordGetStringW(record
,i
,NULL
,&sz
);
732 total_size
+=sz
*sizeof(WCHAR
);
733 tmp
= msi_alloc(sz
*sizeof(WCHAR
));
734 message
= msi_realloc(message
,total_size
*sizeof (WCHAR
));
736 MSI_RecordGetStringW(record
,i
,tmp
,&sz
);
740 sprintfW(number
,format
,i
);
741 strcatW(message
,number
);
743 strcatW(message
,tmp
);
745 strcatW(message
,space
);
751 TRACE("(%p %lx %lx %s)\n",gUIHandlerA
, gUIFilter
, log_type
,
752 debugstr_w(message
));
754 /* convert it to ASCII */
755 len
= WideCharToMultiByte( CP_ACP
, 0, message
, -1,
756 NULL
, 0, NULL
, NULL
);
757 msg
= msi_alloc( len
);
758 WideCharToMultiByte( CP_ACP
, 0, message
, -1,
759 msg
, len
, NULL
, NULL
);
761 if (gUIHandlerA
&& (gUIFilter
& log_type
))
763 rc
= gUIHandlerA(gUIContext
,eMessageType
,msg
);
766 if ((!rc
) && (gszLogFile
[0]) && !((eMessageType
& 0xff000000) ==
767 INSTALLMESSAGE_PROGRESS
))
770 HANDLE log_file
= CreateFileW(gszLogFile
,GENERIC_WRITE
, 0, NULL
,
771 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
773 if (log_file
!= INVALID_HANDLE_VALUE
)
775 SetFilePointer(log_file
,0, NULL
, FILE_END
);
776 WriteFile(log_file
,msg
,strlen(msg
),&write
,NULL
);
777 WriteFile(log_file
,"\n",1,&write
,NULL
);
778 CloseHandle(log_file
);
785 switch (eMessageType
& 0xff000000)
787 case INSTALLMESSAGE_ACTIONDATA
:
788 /* FIXME: format record here instead of in ui_actiondata to get the
789 * correct action data for external scripts */
790 ControlEvent_FireSubscribedEvent(package
, szActionData
, record
);
792 case INSTALLMESSAGE_ACTIONSTART
:
796 LPCWSTR action_text
= MSI_RecordGetString(record
, 2);
798 deformat_string(package
, action_text
, &deformated
);
799 uirow
= MSI_CreateRecord(1);
800 MSI_RecordSetStringW(uirow
, 1, deformated
);
801 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated
));
802 msi_free(deformated
);
804 ControlEvent_FireSubscribedEvent(package
, szActionText
, uirow
);
806 msiobj_release(&uirow
->hdr
);
809 case INSTALLMESSAGE_PROGRESS
:
810 ControlEvent_FireSubscribedEvent(package
, szSetProgress
, record
);
814 return ERROR_SUCCESS
;
817 INT WINAPI
MsiProcessMessage( MSIHANDLE hInstall
, INSTALLMESSAGE eMessageType
,
820 UINT ret
= ERROR_INVALID_HANDLE
;
821 MSIPACKAGE
*package
= NULL
;
822 MSIRECORD
*record
= NULL
;
824 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
826 return ERROR_INVALID_HANDLE
;
828 record
= msihandle2msiinfo( hRecord
, MSIHANDLETYPE_RECORD
);
832 ret
= MSI_ProcessMessage( package
, eMessageType
, record
);
835 msiobj_release( &package
->hdr
);
837 msiobj_release( &record
->hdr
);
843 UINT WINAPI
MsiSetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
, LPCSTR szValue
)
845 LPWSTR szwName
= NULL
, szwValue
= NULL
;
846 UINT r
= ERROR_OUTOFMEMORY
;
848 szwName
= strdupAtoW( szName
);
849 if( szName
&& !szwName
)
852 szwValue
= strdupAtoW( szValue
);
853 if( szValue
&& !szwValue
)
856 r
= MsiSetPropertyW( hInstall
, szwName
, szwValue
);
860 msi_free( szwValue
);
865 UINT
MSI_SetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
, LPCWSTR szValue
)
871 static const WCHAR Insert
[]=
872 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
873 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
874 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
875 ,' ','(','?',',','?',')',0};
876 static const WCHAR Update
[]=
877 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
878 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
879 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
880 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
883 TRACE("%p %s %s\n", package
, debugstr_w(szName
), debugstr_w(szValue
));
886 return ERROR_INVALID_PARAMETER
;
888 /* this one is weird... */
890 return szValue
? ERROR_FUNCTION_FAILED
: ERROR_SUCCESS
;
892 rc
= MSI_GetPropertyW(package
,szName
,0,&sz
);
893 if (rc
==ERROR_MORE_DATA
|| rc
== ERROR_SUCCESS
)
895 sprintfW(Query
,Update
,szName
);
897 row
= MSI_CreateRecord(1);
898 MSI_RecordSetStringW(row
,1,szValue
);
903 strcpyW(Query
,Insert
);
905 row
= MSI_CreateRecord(2);
906 MSI_RecordSetStringW(row
,1,szName
);
907 MSI_RecordSetStringW(row
,2,szValue
);
910 rc
= MSI_DatabaseOpenViewW(package
->db
,Query
,&view
);
911 if (rc
== ERROR_SUCCESS
)
913 rc
= MSI_ViewExecute(view
,row
);
916 msiobj_release(&view
->hdr
);
918 msiobj_release(&row
->hdr
);
923 UINT WINAPI
MsiSetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
, LPCWSTR szValue
)
928 package
= msihandle2msiinfo( hInstall
, MSIHANDLETYPE_PACKAGE
);
930 return ERROR_INVALID_HANDLE
;
931 ret
= MSI_SetPropertyW( package
, szName
, szValue
);
932 msiobj_release( &package
->hdr
);
936 static MSIRECORD
*MSI_GetPropertyRow( MSIPACKAGE
*package
, LPCWSTR name
)
938 static const WCHAR query
[]=
939 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
940 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
941 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
942 '=','\'','%','s','\'',0};
944 if (!name
|| !name
[0])
947 return MSI_QueryGetRecord( package
->db
, query
, name
);
950 /* internal function, not compatible with MsiGetPropertyW */
951 UINT
MSI_GetPropertyW( MSIPACKAGE
*package
, LPCWSTR szName
,
952 LPWSTR szValueBuf
, DWORD
* pchValueBuf
)
955 UINT rc
= ERROR_FUNCTION_FAILED
;
957 row
= MSI_GetPropertyRow( package
, szName
);
959 if (*pchValueBuf
> 0)
964 rc
= MSI_RecordGetStringW(row
,1,szValueBuf
,pchValueBuf
);
965 msiobj_release(&row
->hdr
);
968 if (rc
== ERROR_SUCCESS
)
969 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf
),
971 else if (rc
== ERROR_MORE_DATA
)
972 TRACE("need %li sized buffer for %s\n", *pchValueBuf
,
977 TRACE("property %s not found\n", debugstr_w(szName
));
983 static UINT
MSI_GetProperty( MSIHANDLE handle
, LPCWSTR name
,
984 awstring
*szValueBuf
, DWORD
* pchValueBuf
)
986 static const WCHAR empty
[] = {0};
988 MSIRECORD
*row
= NULL
;
992 TRACE("%lu %s %p %p\n", handle
, debugstr_w(name
),
993 szValueBuf
->str
.w
, pchValueBuf
);
996 return ERROR_INVALID_PARAMETER
;
998 package
= msihandle2msiinfo( handle
, MSIHANDLETYPE_PACKAGE
);
1000 return ERROR_INVALID_HANDLE
;
1002 row
= MSI_GetPropertyRow( package
, name
);
1004 val
= MSI_RecordGetString( row
, 1 );
1009 r
= msi_strcpy_to_awstring( val
, szValueBuf
, pchValueBuf
);
1012 msiobj_release( &row
->hdr
);
1013 msiobj_release( &package
->hdr
);
1018 UINT WINAPI
MsiGetPropertyA( MSIHANDLE hInstall
, LPCSTR szName
,
1019 LPSTR szValueBuf
, DWORD
* pchValueBuf
)
1025 val
.unicode
= FALSE
;
1026 val
.str
.a
= szValueBuf
;
1028 name
= strdupAtoW( szName
);
1029 if (szName
&& !name
)
1030 return ERROR_OUTOFMEMORY
;
1032 r
= MSI_GetProperty( hInstall
, name
, &val
, pchValueBuf
);
1037 UINT WINAPI
MsiGetPropertyW( MSIHANDLE hInstall
, LPCWSTR szName
,
1038 LPWSTR szValueBuf
, DWORD
* pchValueBuf
)
1043 val
.str
.w
= szValueBuf
;
1045 return MSI_GetProperty( hInstall
, szName
, &val
, pchValueBuf
);