msi: Don't crash when logging a record with only one field.
[wine.git] / dlls / msi / package.c
blob24a23d6ac932cff56ce9cee3003ea39884de9ea6
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
24 #include <stdarg.h>
25 #include <stdio.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "shlwapi.h"
31 #include "wingdi.h"
32 #include "wine/debug.h"
33 #include "msi.h"
34 #include "msiquery.h"
35 #include "objidl.h"
36 #include "wincrypt.h"
37 #include "winuser.h"
38 #include "shlobj.h"
39 #include "wine/unicode.h"
40 #include "objbase.h"
42 #include "msipriv.h"
43 #include "action.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msi);
47 static void MSI_FreePackage( MSIOBJECTHDR *arg)
49 MSIPACKAGE *package= (MSIPACKAGE*) arg;
51 if( package->dialog )
52 msi_dialog_destroy( package->dialog );
53 ACTION_free_package_structures(package);
55 msiobj_release( &package->db->hdr );
58 static UINT clone_properties(MSIDATABASE *db)
60 MSIQUERY * view = NULL;
61 UINT rc;
62 static const WCHAR CreateSql[] = {
63 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
64 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
65 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
66 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
67 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
68 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
69 static const WCHAR Query[] = {
70 'S','E','L','E','C','T',' ','*',' ',
71 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
72 static const WCHAR Insert[] = {
73 'I','N','S','E','R','T',' ','i','n','t','o',' ',
74 '`','_','P','r','o','p','e','r','t','y','`',' ',
75 '(','`','_','P','r','o','p','e','r','t','y','`',',',
76 '`','V','a','l','u','e','`',')',' ',
77 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
79 /* create the temporary properties table */
80 rc = MSI_DatabaseOpenViewW(db, CreateSql, &view);
81 if (rc != ERROR_SUCCESS)
82 return rc;
83 rc = MSI_ViewExecute(view,0);
84 MSI_ViewClose(view);
85 msiobj_release(&view->hdr);
86 if (rc != ERROR_SUCCESS)
87 return rc;
89 /* clone the existing properties */
90 rc = MSI_DatabaseOpenViewW(db, Query, &view);
91 if (rc != ERROR_SUCCESS)
92 return rc;
94 rc = MSI_ViewExecute(view, 0);
95 if (rc != ERROR_SUCCESS)
97 MSI_ViewClose(view);
98 msiobj_release(&view->hdr);
99 return rc;
101 while (1)
103 MSIRECORD * row;
104 MSIQUERY * view2;
106 rc = MSI_ViewFetch(view,&row);
107 if (rc != ERROR_SUCCESS)
108 break;
110 rc = MSI_DatabaseOpenViewW(db,Insert,&view2);
111 if (rc!= ERROR_SUCCESS)
112 continue;
113 rc = MSI_ViewExecute(view2,row);
114 MSI_ViewClose(view2);
115 msiobj_release(&view2->hdr);
117 if (rc == ERROR_SUCCESS)
118 msiobj_release(&row->hdr);
120 MSI_ViewClose(view);
121 msiobj_release(&view->hdr);
123 return rc;
127 * set_installed_prop
129 * Sets the "Installed" property to indicate that
130 * the product is installed for the current user.
132 static UINT set_installed_prop( MSIPACKAGE *package )
134 static const WCHAR szInstalled[] = {
135 'I','n','s','t','a','l','l','e','d',0 };
136 WCHAR val[2] = { '1', 0 };
137 HKEY hkey = 0;
138 UINT r;
140 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
141 if (r == ERROR_SUCCESS)
143 RegCloseKey( hkey );
144 MSI_SetPropertyW( package, szInstalled, val );
147 return r;
151 * There are a whole slew of these we need to set
154 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
156 static VOID set_installer_properties(MSIPACKAGE *package)
158 WCHAR pth[MAX_PATH];
159 WCHAR *ptr;
160 OSVERSIONINFOA OSVersion;
161 MEMORYSTATUSEX msex;
162 DWORD verval;
163 WCHAR verstr[10], bufstr[20];
164 HDC dc;
166 static const WCHAR cszbs[]={'\\',0};
167 static const WCHAR CFF[] =
168 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
169 static const WCHAR PFF[] =
170 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
171 static const WCHAR CADF[] =
172 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
173 static const WCHAR FaF[] =
174 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
175 static const WCHAR FoF[] =
176 {'F','o','n','t','s','F','o','l','d','e','r',0};
177 static const WCHAR SendTF[] =
178 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
179 static const WCHAR SMF[] =
180 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
181 static const WCHAR StF[] =
182 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
183 static const WCHAR TemplF[] =
184 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
185 static const WCHAR DF[] =
186 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
187 static const WCHAR PMF[] =
188 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
189 static const WCHAR ATF[] =
190 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
191 static const WCHAR ADF[] =
192 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
193 static const WCHAR SF[] =
194 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
195 static const WCHAR SF16[] =
196 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
197 static const WCHAR LADF[] =
198 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
199 static const WCHAR MPF[] =
200 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
201 static const WCHAR PF[] =
202 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
203 static const WCHAR WF[] =
204 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
205 static const WCHAR WV[] =
206 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
207 static const WCHAR TF[]=
208 {'T','e','m','p','F','o','l','d','e','r',0};
209 static const WCHAR szAdminUser[] =
210 {'A','d','m','i','n','U','s','e','r',0};
211 static const WCHAR szPriv[] =
212 {'P','r','i','v','i','l','e','g','e','d',0};
213 static const WCHAR szOne[] =
214 {'1',0};
215 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
216 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
217 static const WCHAR szFormat[] = {'%','l','i',0};
218 static const WCHAR szWinBuild[] =
219 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
220 static const WCHAR szSPL[] =
221 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
222 static const WCHAR szSix[] = {'6',0 };
224 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
225 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
226 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
227 /* Screen properties */
228 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
229 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
230 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
231 static const WCHAR szScreenFormat[] = {'%','d',0};
232 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
233 SYSTEM_INFO sys_info;
236 * Other things that probably should be set:
238 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
239 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
240 * ProductState CaptionHeight BorderTop BorderSide TextHeight
241 * RedirectedDllSupport Time Date Privileged
244 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
245 strcatW(pth,cszbs);
246 MSI_SetPropertyW(package, CFF, pth);
248 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
249 strcatW(pth,cszbs);
250 MSI_SetPropertyW(package, PFF, pth);
252 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
253 strcatW(pth,cszbs);
254 MSI_SetPropertyW(package, CADF, pth);
256 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
257 strcatW(pth,cszbs);
258 MSI_SetPropertyW(package, FaF, pth);
260 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
261 strcatW(pth,cszbs);
262 MSI_SetPropertyW(package, FoF, pth);
264 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
265 strcatW(pth,cszbs);
266 MSI_SetPropertyW(package, SendTF, pth);
268 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
269 strcatW(pth,cszbs);
270 MSI_SetPropertyW(package, SMF, pth);
272 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
273 strcatW(pth,cszbs);
274 MSI_SetPropertyW(package, StF, pth);
276 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
277 strcatW(pth,cszbs);
278 MSI_SetPropertyW(package, TemplF, pth);
280 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
281 strcatW(pth,cszbs);
282 MSI_SetPropertyW(package, DF, pth);
284 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
285 strcatW(pth,cszbs);
286 MSI_SetPropertyW(package, PMF, pth);
288 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
289 strcatW(pth,cszbs);
290 MSI_SetPropertyW(package, ATF, pth);
292 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
293 strcatW(pth,cszbs);
294 MSI_SetPropertyW(package, ADF, pth);
296 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
297 strcatW(pth,cszbs);
298 MSI_SetPropertyW(package, SF, pth);
299 MSI_SetPropertyW(package, SF16, pth);
301 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
302 strcatW(pth,cszbs);
303 MSI_SetPropertyW(package, LADF, pth);
305 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
306 strcatW(pth,cszbs);
307 MSI_SetPropertyW(package, MPF, pth);
309 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
310 strcatW(pth,cszbs);
311 MSI_SetPropertyW(package, PF, pth);
313 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
314 strcatW(pth,cszbs);
315 MSI_SetPropertyW(package, WF, pth);
317 /* Physical Memory is specified in MB. Using total amount. */
318 msex.dwLength = sizeof(msex);
319 GlobalMemoryStatusEx( &msex );
320 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
321 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
323 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
324 ptr = strchrW(pth,'\\');
325 if (ptr)
326 *(ptr+1) = 0;
327 MSI_SetPropertyW(package, WV, pth);
329 GetTempPathW(MAX_PATH,pth);
330 MSI_SetPropertyW(package, TF, pth);
333 /* in a wine environment the user is always admin and privileged */
334 MSI_SetPropertyW(package,szAdminUser,szOne);
335 MSI_SetPropertyW(package,szPriv,szOne);
337 /* set the os things */
338 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
339 GetVersionExA(&OSVersion);
340 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
341 sprintfW(verstr,szFormat,verval);
342 switch (OSVersion.dwPlatformId)
344 case VER_PLATFORM_WIN32_WINDOWS:
345 MSI_SetPropertyW(package,v9x,verstr);
346 break;
347 case VER_PLATFORM_WIN32_NT:
348 MSI_SetPropertyW(package,vNT,verstr);
349 break;
351 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
352 MSI_SetPropertyW(package,szWinBuild,verstr);
353 /* just fudge this */
354 MSI_SetPropertyW(package,szSPL,szSix);
356 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
357 MSI_SetPropertyW( package, szVersionMsi, bufstr );
359 GetSystemInfo( &sys_info );
360 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
362 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
363 MSI_SetPropertyW( package, szIntel, bufstr );
366 /* Screen properties. */
367 dc = GetDC(0);
368 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
369 MSI_SetPropertyW( package, szScreenX, bufstr );
370 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
371 MSI_SetPropertyW( package, szScreenY, bufstr );
372 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
373 MSI_SetPropertyW( package, szColorBits, bufstr );
374 ReleaseDC(0, dc);
377 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
379 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
380 static const WCHAR szpi[] = {'%','i',0};
381 static const WCHAR szProductCode[] = {
382 'P','r','o','d','u','c','t','C','o','d','e',0};
383 MSIPACKAGE *package = NULL;
384 WCHAR uilevel[10];
386 TRACE("%p\n", db);
388 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
389 MSI_FreePackage );
390 if( package )
392 msiobj_addref( &db->hdr );
394 package->db = db;
395 list_init( &package->components );
396 list_init( &package->features );
397 list_init( &package->files );
398 list_init( &package->tempfiles );
399 list_init( &package->folders );
400 package->ActionFormat = NULL;
401 package->LastAction = NULL;
402 package->dialog = NULL;
403 package->next_dialog = NULL;
404 list_init( &package->subscriptions );
405 list_init( &package->appids );
406 list_init( &package->classes );
407 list_init( &package->mimes );
408 list_init( &package->extensions );
409 list_init( &package->progids );
410 list_init( &package->RunningActions );
412 /* OK, here is where we do a slew of things to the database to
413 * prep for all that is to come as a package */
415 clone_properties(db);
416 set_installer_properties(package);
417 sprintfW(uilevel,szpi,gUILevel);
418 MSI_SetPropertyW(package, szLevel, uilevel);
420 package->ProductCode = msi_dup_property( package, szProductCode );
421 set_installed_prop( package );
424 return package;
428 * copy_package_to_temp [internal]
430 * copy the msi file to a temp file to prevent locking a CD
431 * with a multi disc install
433 * FIXME: I think this is wrong, and instead of copying the package,
434 * we should read all the tables to memory, then open the
435 * database to read binary streams on demand.
437 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
439 WCHAR path[MAX_PATH];
440 static const WCHAR szMSI[] = {'M','S','I',0};
442 GetTempPathW( MAX_PATH, path );
443 GetTempFileNameW( path, szMSI, 0, filename );
445 if( !CopyFileW( szPackage, filename, FALSE ) )
447 ERR("failed to copy package to temp path %s\n", debugstr_w(filename) );
448 return szPackage;
451 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
452 return filename;
455 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
457 MSIDATABASE *db = NULL;
458 MSIPACKAGE *package;
459 MSIHANDLE handle;
460 UINT r;
462 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
464 if( szPackage[0] == '#' )
466 handle = atoiW(&szPackage[1]);
467 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
468 if( !db )
469 return ERROR_INVALID_HANDLE;
471 else
473 WCHAR temppath[MAX_PATH];
474 LPCWSTR file = copy_package_to_temp( szPackage, temppath );
476 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
478 if (file != szPackage)
479 DeleteFileW( file );
481 if( r != ERROR_SUCCESS )
482 return r;
485 package = MSI_CreatePackage( db );
486 msiobj_release( &db->hdr );
487 if( !package )
488 return ERROR_FUNCTION_FAILED;
491 * FIXME: I don't think this is right. Maybe we should be storing the
492 * name of the database in the MSIDATABASE structure and fetching this
493 * info from there, or maybe this is only relevant to cached databases.
495 if( szPackage[0] != '#' )
497 static const WCHAR OriginalDatabase[] =
498 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
499 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
501 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
502 MSI_SetPropertyW( package, Database, szPackage );
505 *pPackage = package;
507 return ERROR_SUCCESS;
510 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
512 MSIPACKAGE *package = NULL;
513 UINT ret;
515 TRACE("%s %08lx %p\n", debugstr_w(szPackage), dwOptions, phPackage );
517 if( dwOptions )
518 FIXME("dwOptions %08lx not supported\n", dwOptions);
520 ret = MSI_OpenPackageW( szPackage, &package );
521 if( ret == ERROR_SUCCESS )
523 *phPackage = alloc_msihandle( &package->hdr );
524 msiobj_release( &package->hdr );
527 return ret;
530 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
532 return MsiOpenPackageExW( szPackage, 0, phPackage );
535 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
537 LPWSTR szwPack = NULL;
538 UINT ret;
540 if( szPackage )
542 szwPack = strdupAtoW( szPackage );
543 if( !szwPack )
544 return ERROR_OUTOFMEMORY;
547 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
549 msi_free( szwPack );
551 return ret;
554 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
556 return MsiOpenPackageExA( szPackage, 0, phPackage );
559 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
561 MSIPACKAGE *package;
562 MSIHANDLE handle = 0;
564 TRACE("(%ld)\n",hInstall);
566 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
567 if( package)
569 handle = alloc_msihandle( &package->db->hdr );
570 msiobj_release( &package->hdr );
573 return handle;
576 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
577 MSIRECORD *record)
579 static const WCHAR szActionData[] =
580 {'A','c','t','i','o','n','D','a','t','a',0};
581 static const WCHAR szSetProgress[] =
582 {'S','e','t','P','r','o','g','r','e','s','s',0};
583 static const WCHAR szActionText[] =
584 {'A','c','t','i','o','n','T','e','x','t',0};
585 DWORD log_type = 0;
586 LPWSTR message;
587 DWORD sz;
588 DWORD total_size = 0;
589 INT i;
590 INT rc;
591 char *msg;
592 int len;
594 TRACE("%x\n", eMessageType);
595 rc = 0;
597 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
598 log_type |= INSTALLLOGMODE_ERROR;
599 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
600 log_type |= INSTALLLOGMODE_WARNING;
601 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
602 log_type |= INSTALLLOGMODE_USER;
603 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
604 log_type |= INSTALLLOGMODE_INFO;
605 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
606 log_type |= INSTALLLOGMODE_COMMONDATA;
607 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
608 log_type |= INSTALLLOGMODE_ACTIONSTART;
609 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
610 log_type |= INSTALLLOGMODE_ACTIONDATA;
611 /* just a guess */
612 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
613 log_type |= 0x800;
615 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
617 static const WCHAR template_s[]=
618 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
619 static const WCHAR format[] =
620 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
621 WCHAR timet[0x100];
622 LPCWSTR action_text, action;
623 LPWSTR deformatted = NULL;
625 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
627 action = MSI_RecordGetString(record, 1);
628 action_text = MSI_RecordGetString(record, 2);
629 deformat_string(package, action_text, &deformatted);
631 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
632 if (deformatted)
633 len += strlenW(deformatted);
634 message = msi_alloc(len*sizeof(WCHAR));
635 sprintfW(message, template_s, timet, action);
636 if (deformatted)
637 strcatW(message, deformatted);
638 msi_free(deformatted);
640 else
642 INT msg_field=1;
643 message = msi_alloc(1*sizeof (WCHAR));
644 message[0]=0;
645 msg_field = MSI_RecordGetFieldCount(record);
646 for (i = 1; i <= msg_field; i++)
648 LPWSTR tmp;
649 WCHAR number[3];
650 static const WCHAR format[] = { '%','i',':',' ',0};
651 static const WCHAR space[] = { ' ',0};
652 sz = 0;
653 MSI_RecordGetStringW(record,i,NULL,&sz);
654 sz+=4;
655 total_size+=sz*sizeof(WCHAR);
656 tmp = msi_alloc(sz*sizeof(WCHAR));
657 message = msi_realloc(message,total_size*sizeof (WCHAR));
659 MSI_RecordGetStringW(record,i,tmp,&sz);
661 if (msg_field > 1)
663 sprintfW(number,format,i);
664 strcatW(message,number);
666 strcatW(message,tmp);
667 if (msg_field > 1)
668 strcatW(message,space);
670 msi_free(tmp);
674 TRACE("(%p %lx %lx %s)\n",gUIHandlerA, gUIFilter, log_type,
675 debugstr_w(message));
677 /* convert it to ASCII */
678 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
679 NULL, 0, NULL, NULL );
680 msg = msi_alloc( len );
681 WideCharToMultiByte( CP_ACP, 0, message, -1,
682 msg, len, NULL, NULL );
684 if (gUIHandlerA && (gUIFilter & log_type))
686 rc = gUIHandlerA(gUIContext,eMessageType,msg);
689 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
690 INSTALLMESSAGE_PROGRESS))
692 DWORD write;
693 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
694 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
696 if (log_file != INVALID_HANDLE_VALUE)
698 SetFilePointer(log_file,0, NULL, FILE_END);
699 WriteFile(log_file,msg,strlen(msg),&write,NULL);
700 WriteFile(log_file,"\n",1,&write,NULL);
701 CloseHandle(log_file);
704 msi_free( msg );
706 msi_free( message);
708 switch (eMessageType & 0xff000000)
710 case INSTALLMESSAGE_ACTIONDATA:
711 /* FIXME: format record here instead of in ui_actiondata to get the
712 * correct action data for external scripts */
713 ControlEvent_FireSubscribedEvent(package, szActionData, record);
714 break;
715 case INSTALLMESSAGE_ACTIONSTART:
717 MSIRECORD *uirow;
718 LPWSTR deformated;
719 LPCWSTR action_text = MSI_RecordGetString(record, 2);
721 deformat_string(package, action_text, &deformated);
722 uirow = MSI_CreateRecord(1);
723 MSI_RecordSetStringW(uirow, 1, deformated);
724 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
725 msi_free(deformated);
727 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
729 msiobj_release(&uirow->hdr);
730 break;
732 case INSTALLMESSAGE_PROGRESS:
733 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
734 break;
737 return ERROR_SUCCESS;
740 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
741 MSIHANDLE hRecord)
743 UINT ret = ERROR_INVALID_HANDLE;
744 MSIPACKAGE *package = NULL;
745 MSIRECORD *record = NULL;
747 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
748 if( !package )
749 return ERROR_INVALID_HANDLE;
751 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
752 if( !record )
753 goto out;
755 ret = MSI_ProcessMessage( package, eMessageType, record );
757 out:
758 msiobj_release( &package->hdr );
759 if( record )
760 msiobj_release( &record->hdr );
762 return ret;
765 /* property code */
766 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
768 LPWSTR szwName = NULL, szwValue = NULL;
769 UINT r = ERROR_OUTOFMEMORY;
771 szwName = strdupAtoW( szName );
772 if( szName && !szwName )
773 goto end;
775 szwValue = strdupAtoW( szValue );
776 if( szValue && !szwValue )
777 goto end;
779 r = MsiSetPropertyW( hInstall, szwName, szwValue);
781 end:
782 msi_free( szwName );
783 msi_free( szwValue );
785 return r;
788 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
790 MSIQUERY *view;
791 MSIRECORD *row;
792 UINT rc;
793 DWORD sz = 0;
794 static const WCHAR Insert[]=
795 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
796 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
797 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
798 ,' ','(','?',',','?',')',0};
799 static const WCHAR Update[]=
800 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
801 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
802 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
803 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
804 WCHAR Query[1024];
806 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
808 if (!szName)
809 return ERROR_INVALID_PARAMETER;
811 /* this one is weird... */
812 if (!szName[0])
813 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
815 rc = MSI_GetPropertyW(package,szName,0,&sz);
816 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
818 sprintfW(Query,Update,szName);
820 row = MSI_CreateRecord(1);
821 MSI_RecordSetStringW(row,1,szValue);
824 else
826 strcpyW(Query,Insert);
828 row = MSI_CreateRecord(2);
829 MSI_RecordSetStringW(row,1,szName);
830 MSI_RecordSetStringW(row,2,szValue);
833 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
834 if (rc == ERROR_SUCCESS)
836 rc = MSI_ViewExecute(view,row);
838 MSI_ViewClose(view);
839 msiobj_release(&view->hdr);
841 msiobj_release(&row->hdr);
843 return rc;
846 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
848 MSIPACKAGE *package;
849 UINT ret;
851 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
852 if( !package )
853 return ERROR_INVALID_HANDLE;
854 ret = MSI_SetPropertyW( package, szName, szValue);
855 msiobj_release( &package->hdr );
856 return ret;
859 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
861 static const WCHAR query[]=
862 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
863 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
864 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
865 '=','\'','%','s','\'',0};
867 if (!name || !name[0])
868 return NULL;
870 return MSI_QueryGetRecord( package->db, query, name );
873 /* internal function, not compatible with MsiGetPropertyW */
874 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
875 LPWSTR szValueBuf, DWORD* pchValueBuf )
877 MSIRECORD *row;
878 UINT rc = ERROR_FUNCTION_FAILED;
880 row = MSI_GetPropertyRow( package, szName );
882 if (*pchValueBuf > 0)
883 szValueBuf[0] = 0;
885 if (row)
887 rc = MSI_RecordGetStringW(row,1,szValueBuf,pchValueBuf);
888 msiobj_release(&row->hdr);
891 if (rc == ERROR_SUCCESS)
892 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
893 debugstr_w(szName));
894 else if (rc == ERROR_MORE_DATA)
895 TRACE("need %li sized buffer for %s\n", *pchValueBuf,
896 debugstr_w(szName));
897 else
899 *pchValueBuf = 0;
900 TRACE("property %s not found\n", debugstr_w(szName));
903 return rc;
906 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
907 awstring *szValueBuf, DWORD* pchValueBuf )
909 static const WCHAR empty[] = {0};
910 MSIPACKAGE *package;
911 MSIRECORD *row = NULL;
912 UINT r;
913 LPCWSTR val = NULL;
915 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
916 szValueBuf->str.w, pchValueBuf );
918 if (!name)
919 return ERROR_INVALID_PARAMETER;
921 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
922 if (!package)
923 return ERROR_INVALID_HANDLE;
925 row = MSI_GetPropertyRow( package, name );
926 if (row)
927 val = MSI_RecordGetString( row, 1 );
929 if (!val)
930 val = empty;
932 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
934 if (row)
935 msiobj_release( &row->hdr );
936 msiobj_release( &package->hdr );
938 return r;
941 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
942 LPSTR szValueBuf, DWORD* pchValueBuf )
944 awstring val;
945 LPWSTR name;
946 UINT r;
948 val.unicode = FALSE;
949 val.str.a = szValueBuf;
951 name = strdupAtoW( szName );
952 if (szName && !name)
953 return ERROR_OUTOFMEMORY;
955 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
956 msi_free( name );
957 return r;
960 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
961 LPWSTR szValueBuf, DWORD* pchValueBuf )
963 awstring val;
965 val.unicode = TRUE;
966 val.str.w = szValueBuf;
968 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );