msi: gcc 2.95 compatibility fix.
[wine.git] / dlls / msi / package.c
blobcb022bd5b534f3429096325a9024e5c27a29f06e
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 DWORD log_type = 0;
580 LPWSTR message;
581 DWORD sz;
582 DWORD total_size = 0;
583 INT msg_field=1;
584 INT i;
585 INT rc;
586 char *msg;
587 int len;
589 TRACE("%x\n", eMessageType);
590 rc = 0;
592 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
593 log_type |= INSTALLLOGMODE_ERROR;
594 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
595 log_type |= INSTALLLOGMODE_WARNING;
596 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
597 log_type |= INSTALLLOGMODE_USER;
598 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
599 log_type |= INSTALLLOGMODE_INFO;
600 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
601 log_type |= INSTALLLOGMODE_COMMONDATA;
602 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
603 log_type |= INSTALLLOGMODE_ACTIONSTART;
604 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
605 log_type |= INSTALLLOGMODE_ACTIONDATA;
606 /* just a guess */
607 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
608 log_type |= 0x800;
610 message = msi_alloc(1*sizeof (WCHAR));
611 message[0]=0;
612 msg_field = MSI_RecordGetFieldCount(record);
613 for (i = 1; i <= msg_field; i++)
615 LPWSTR tmp;
616 WCHAR number[3];
617 static const WCHAR format[] = { '%','i',':',' ',0};
618 static const WCHAR space[] = { ' ',0};
619 sz = 0;
620 MSI_RecordGetStringW(record,i,NULL,&sz);
621 sz+=4;
622 total_size+=sz*sizeof(WCHAR);
623 tmp = msi_alloc(sz*sizeof(WCHAR));
624 message = msi_realloc(message,total_size*sizeof (WCHAR));
626 MSI_RecordGetStringW(record,i,tmp,&sz);
628 if (msg_field > 1)
630 sprintfW(number,format,i);
631 strcatW(message,number);
633 strcatW(message,tmp);
634 if (msg_field > 1)
635 strcatW(message,space);
637 msi_free(tmp);
640 TRACE("(%p %lx %lx %s)\n",gUIHandlerA, gUIFilter, log_type,
641 debugstr_w(message));
643 /* convert it to ASCII */
644 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
645 NULL, 0, NULL, NULL );
646 msg = msi_alloc( len );
647 WideCharToMultiByte( CP_ACP, 0, message, -1,
648 msg, len, NULL, NULL );
650 if (gUIHandlerA && (gUIFilter & log_type))
652 rc = gUIHandlerA(gUIContext,eMessageType,msg);
655 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
656 INSTALLMESSAGE_PROGRESS))
658 DWORD write;
659 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
660 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
662 if (log_file != INVALID_HANDLE_VALUE)
664 SetFilePointer(log_file,0, NULL, FILE_END);
665 WriteFile(log_file,msg,strlen(msg),&write,NULL);
666 WriteFile(log_file,"\n",1,&write,NULL);
667 CloseHandle(log_file);
670 msi_free( msg );
672 msi_free( message);
673 return ERROR_SUCCESS;
676 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
677 MSIHANDLE hRecord)
679 UINT ret = ERROR_INVALID_HANDLE;
680 MSIPACKAGE *package = NULL;
681 MSIRECORD *record = NULL;
683 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
684 if( !package )
685 return ERROR_INVALID_HANDLE;
687 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
688 if( !record )
689 goto out;
691 ret = MSI_ProcessMessage( package, eMessageType, record );
693 out:
694 msiobj_release( &package->hdr );
695 if( record )
696 msiobj_release( &record->hdr );
698 return ret;
701 /* property code */
702 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
704 LPWSTR szwName = NULL, szwValue = NULL;
705 UINT r = ERROR_OUTOFMEMORY;
707 szwName = strdupAtoW( szName );
708 if( szName && !szwName )
709 goto end;
711 szwValue = strdupAtoW( szValue );
712 if( szValue && !szwValue )
713 goto end;
715 r = MsiSetPropertyW( hInstall, szwName, szwValue);
717 end:
718 msi_free( szwName );
719 msi_free( szwValue );
721 return r;
724 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
726 MSIQUERY *view;
727 MSIRECORD *row;
728 UINT rc;
729 DWORD sz = 0;
730 static const WCHAR Insert[]=
731 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
732 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
733 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
734 ,' ','(','?',',','?',')',0};
735 static const WCHAR Update[]=
736 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
737 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
738 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
739 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
740 WCHAR Query[1024];
742 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
744 if (!szName)
745 return ERROR_INVALID_PARAMETER;
747 /* this one is weird... */
748 if (!szName[0])
749 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
751 rc = MSI_GetPropertyW(package,szName,0,&sz);
752 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
754 sprintfW(Query,Update,szName);
756 row = MSI_CreateRecord(1);
757 MSI_RecordSetStringW(row,1,szValue);
760 else
762 strcpyW(Query,Insert);
764 row = MSI_CreateRecord(2);
765 MSI_RecordSetStringW(row,1,szName);
766 MSI_RecordSetStringW(row,2,szValue);
769 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
770 if (rc == ERROR_SUCCESS)
772 rc = MSI_ViewExecute(view,row);
774 MSI_ViewClose(view);
775 msiobj_release(&view->hdr);
777 msiobj_release(&row->hdr);
779 return rc;
782 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
784 MSIPACKAGE *package;
785 UINT ret;
787 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
788 if( !package )
789 return ERROR_INVALID_HANDLE;
790 ret = MSI_SetPropertyW( package, szName, szValue);
791 msiobj_release( &package->hdr );
792 return ret;
795 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
797 static const WCHAR query[]=
798 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
799 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
800 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
801 '=','\'','%','s','\'',0};
803 if (!name || !name[0])
804 return NULL;
806 return MSI_QueryGetRecord( package->db, query, name );
809 /* internal function, not compatible with MsiGetPropertyW */
810 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
811 LPWSTR szValueBuf, DWORD* pchValueBuf )
813 MSIRECORD *row;
814 UINT rc = ERROR_FUNCTION_FAILED;
816 row = MSI_GetPropertyRow( package, szName );
818 if (*pchValueBuf > 0)
819 szValueBuf[0] = 0;
821 if (row)
823 rc = MSI_RecordGetStringW(row,1,szValueBuf,pchValueBuf);
824 msiobj_release(&row->hdr);
827 if (rc == ERROR_SUCCESS)
828 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
829 debugstr_w(szName));
830 else if (rc == ERROR_MORE_DATA)
831 TRACE("need %li sized buffer for %s\n", *pchValueBuf,
832 debugstr_w(szName));
833 else
835 *pchValueBuf = 0;
836 TRACE("property %s not found\n", debugstr_w(szName));
839 return rc;
842 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
843 awstring *szValueBuf, DWORD* pchValueBuf )
845 static const WCHAR empty[] = {0};
846 MSIPACKAGE *package;
847 MSIRECORD *row = NULL;
848 UINT r;
849 LPCWSTR val = NULL;
851 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
852 szValueBuf->str.w, pchValueBuf );
854 if (!name)
855 return ERROR_INVALID_PARAMETER;
857 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
858 if (!package)
859 return ERROR_INVALID_HANDLE;
861 row = MSI_GetPropertyRow( package, name );
862 if (row)
863 val = MSI_RecordGetString( row, 1 );
865 if (!val)
866 val = empty;
868 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
870 if (row)
871 msiobj_release( &row->hdr );
872 msiobj_release( &package->hdr );
874 return r;
877 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
878 LPSTR szValueBuf, DWORD* pchValueBuf )
880 awstring val;
881 LPWSTR name;
882 UINT r;
884 val.unicode = FALSE;
885 val.str.a = szValueBuf;
887 name = strdupAtoW( szName );
888 if (szName && !name)
889 return ERROR_OUTOFMEMORY;
891 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
892 msi_free( name );
893 return r;
896 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
897 LPWSTR szValueBuf, DWORD* pchValueBuf )
899 awstring val;
901 val.unicode = TRUE;
902 val.str.w = szValueBuf;
904 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );