Added support for doing SetBitmapBits on a DIB section.
[wine/dcerpc.git] / dlls / msi / package.c
blob96bf46fc089773608c99c18fd29996c034bcdce6
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "winnls.h"
29 #include "shlwapi.h"
30 #include "wingdi.h"
31 #include "wine/debug.h"
32 #include "msi.h"
33 #include "msiquery.h"
34 #include "objidl.h"
35 #include "wincrypt.h"
36 #include "winuser.h"
37 #include "shlobj.h"
38 #include "wine/unicode.h"
39 #include "objbase.h"
41 #include "msipriv.h"
42 #include "action.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msi);
46 static void MSI_FreePackage( MSIOBJECTHDR *arg)
48 MSIPACKAGE *package= (MSIPACKAGE*) arg;
50 if( package->dialog )
51 msi_dialog_destroy( package->dialog );
52 ACTION_free_package_structures(package);
54 msiobj_release( &package->db->hdr );
57 static UINT clone_properties(MSIDATABASE *db)
59 MSIQUERY * view = NULL;
60 UINT rc;
61 static const WCHAR CreateSql[] = {
62 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
63 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
64 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
65 'L','L',',',' ','`','V','a','l','u','e','`',' ','C','H','A','R','(','9',
66 '8',')',' ','N','O','T',' ','N','U','L','L',' ','P','R','I','M','A','R',
67 'Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y','`',')',0};
68 static const WCHAR Query[] = {
69 'S','E','L','E','C','T',' ','*',' ',
70 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
71 static const WCHAR Insert[] = {
72 'I','N','S','E','R','T',' ','i','n','t','o',' ',
73 '`','_','P','r','o','p','e','r','t','y','`',' ',
74 '(','`','_','P','r','o','p','e','r','t','y','`',',',
75 '`','V','a','l','u','e','`',')',' ',
76 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
78 /* create the temporary properties table */
79 rc = MSI_DatabaseOpenViewW(db, CreateSql, &view);
80 if (rc != ERROR_SUCCESS)
81 return rc;
82 rc = MSI_ViewExecute(view,0);
83 MSI_ViewClose(view);
84 msiobj_release(&view->hdr);
85 if (rc != ERROR_SUCCESS)
86 return rc;
88 /* clone the existing properties */
89 rc = MSI_DatabaseOpenViewW(db, Query, &view);
90 if (rc != ERROR_SUCCESS)
91 return rc;
93 rc = MSI_ViewExecute(view, 0);
94 if (rc != ERROR_SUCCESS)
96 MSI_ViewClose(view);
97 msiobj_release(&view->hdr);
98 return rc;
100 while (1)
102 MSIRECORD * row;
103 MSIQUERY * view2;
105 rc = MSI_ViewFetch(view,&row);
106 if (rc != ERROR_SUCCESS)
107 break;
109 rc = MSI_DatabaseOpenViewW(db,Insert,&view2);
110 if (rc!= ERROR_SUCCESS)
111 continue;
112 rc = MSI_ViewExecute(view2,row);
113 MSI_ViewClose(view2);
114 msiobj_release(&view2->hdr);
116 if (rc == ERROR_SUCCESS)
117 msiobj_release(&row->hdr);
119 MSI_ViewClose(view);
120 msiobj_release(&view->hdr);
122 return rc;
126 * set_installed_prop
128 * Sets the "Installed" property to indicate that
129 * the product is installed for the current user.
131 static UINT set_installed_prop( MSIPACKAGE *package )
133 static const WCHAR szInstalled[] = {
134 'I','n','s','t','a','l','l','e','d',0 };
135 WCHAR val[2] = { '1', 0 };
136 HKEY hkey = 0;
137 UINT r;
139 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
140 if (r == ERROR_SUCCESS)
142 RegCloseKey( hkey );
143 MSI_SetPropertyW( package, szInstalled, val );
146 return r;
150 * There are a whole slew of these we need to set
153 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
155 static VOID set_installer_properties(MSIPACKAGE *package)
157 WCHAR pth[MAX_PATH];
158 WCHAR *ptr;
159 OSVERSIONINFOA OSVersion;
160 MEMORYSTATUSEX msex;
161 DWORD verval;
162 WCHAR verstr[10], bufstr[20];
163 HDC dc;
165 static const WCHAR cszbs[]={'\\',0};
166 static const WCHAR CFF[] =
167 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
168 static const WCHAR PFF[] =
169 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
170 static const WCHAR CADF[] =
171 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
172 static const WCHAR FaF[] =
173 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
174 static const WCHAR FoF[] =
175 {'F','o','n','t','s','F','o','l','d','e','r',0};
176 static const WCHAR SendTF[] =
177 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
178 static const WCHAR SMF[] =
179 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
180 static const WCHAR StF[] =
181 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
182 static const WCHAR TemplF[] =
183 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
184 static const WCHAR DF[] =
185 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
186 static const WCHAR PMF[] =
187 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
188 static const WCHAR ATF[] =
189 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
190 static const WCHAR ADF[] =
191 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
192 static const WCHAR SF[] =
193 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
194 static const WCHAR SF16[] =
195 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
196 static const WCHAR LADF[] =
197 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
198 static const WCHAR MPF[] =
199 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
200 static const WCHAR PF[] =
201 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
202 static const WCHAR WF[] =
203 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
204 static const WCHAR WV[] =
205 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
206 static const WCHAR TF[]=
207 {'T','e','m','p','F','o','l','d','e','r',0};
208 static const WCHAR szAdminUser[] =
209 {'A','d','m','i','n','U','s','e','r',0};
210 static const WCHAR szPriv[] =
211 {'P','r','i','v','i','l','e','g','e','d',0};
212 static const WCHAR szOne[] =
213 {'1',0};
214 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
215 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
216 static const WCHAR szFormat[] = {'%','l','i',0};
217 static const WCHAR szWinBuild[] =
218 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
219 static const WCHAR szSPL[] =
220 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
221 static const WCHAR szSix[] = {'6',0 };
223 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
224 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
225 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
226 /* Screen properties */
227 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
228 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
229 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
230 static const WCHAR szScreenFormat[] = {'%','d',0};
233 * Other things that probably should be set:
235 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
236 * Intel ShellAdvSupport DefaultUIFont VersionDatabase PackagecodeChanging
237 * ProductState CaptionHeight BorderTop BorderSide TextHeight
238 * RedirectedDllSupport Time Date Privileged
241 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
242 strcatW(pth,cszbs);
243 MSI_SetPropertyW(package, CFF, pth);
245 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
246 strcatW(pth,cszbs);
247 MSI_SetPropertyW(package, PFF, pth);
249 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
250 strcatW(pth,cszbs);
251 MSI_SetPropertyW(package, CADF, pth);
253 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
254 strcatW(pth,cszbs);
255 MSI_SetPropertyW(package, FaF, pth);
257 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
258 strcatW(pth,cszbs);
259 MSI_SetPropertyW(package, FoF, pth);
261 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
262 strcatW(pth,cszbs);
263 MSI_SetPropertyW(package, SendTF, pth);
265 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
266 strcatW(pth,cszbs);
267 MSI_SetPropertyW(package, SMF, pth);
269 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
270 strcatW(pth,cszbs);
271 MSI_SetPropertyW(package, StF, pth);
273 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
274 strcatW(pth,cszbs);
275 MSI_SetPropertyW(package, TemplF, pth);
277 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
278 strcatW(pth,cszbs);
279 MSI_SetPropertyW(package, DF, pth);
281 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
282 strcatW(pth,cszbs);
283 MSI_SetPropertyW(package, PMF, pth);
285 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
286 strcatW(pth,cszbs);
287 MSI_SetPropertyW(package, ATF, pth);
289 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
290 strcatW(pth,cszbs);
291 MSI_SetPropertyW(package, ADF, pth);
293 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
294 strcatW(pth,cszbs);
295 MSI_SetPropertyW(package, SF, pth);
296 MSI_SetPropertyW(package, SF16, pth);
298 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
299 strcatW(pth,cszbs);
300 MSI_SetPropertyW(package, LADF, pth);
302 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
303 strcatW(pth,cszbs);
304 MSI_SetPropertyW(package, MPF, pth);
306 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
307 strcatW(pth,cszbs);
308 MSI_SetPropertyW(package, PF, pth);
310 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
311 strcatW(pth,cszbs);
312 MSI_SetPropertyW(package, WF, pth);
314 /* Physical Memory is specified in MB. Using total amount. */
315 msex.dwLength = sizeof(msex);
316 GlobalMemoryStatusEx( &msex );
317 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
318 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
320 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
321 ptr = strchrW(pth,'\\');
322 if (ptr)
323 *(ptr+1) = 0;
324 MSI_SetPropertyW(package, WV, pth);
326 GetTempPathW(MAX_PATH,pth);
327 MSI_SetPropertyW(package, TF, pth);
330 /* in a wine environment the user is always admin and privileged */
331 MSI_SetPropertyW(package,szAdminUser,szOne);
332 MSI_SetPropertyW(package,szPriv,szOne);
334 /* set the os things */
335 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
336 GetVersionExA(&OSVersion);
337 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
338 sprintfW(verstr,szFormat,verval);
339 switch (OSVersion.dwPlatformId)
341 case VER_PLATFORM_WIN32_WINDOWS:
342 MSI_SetPropertyW(package,v9x,verstr);
343 break;
344 case VER_PLATFORM_WIN32_NT:
345 MSI_SetPropertyW(package,vNT,verstr);
346 break;
348 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
349 MSI_SetPropertyW(package,szWinBuild,verstr);
350 /* just fudge this */
351 MSI_SetPropertyW(package,szSPL,szSix);
353 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
354 MSI_SetPropertyW( package, szVersionMsi, bufstr );
356 /* Screen properties. */
357 dc = GetDC(0);
358 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
359 MSI_SetPropertyW( package, szScreenX, bufstr );
360 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
361 MSI_SetPropertyW( package, szScreenY, bufstr );
362 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
363 MSI_SetPropertyW( package, szColorBits, bufstr );
364 ReleaseDC(0, dc);
367 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db )
369 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
370 static const WCHAR szpi[] = {'%','i',0};
371 static const WCHAR szProductCode[] = {
372 'P','r','o','d','u','c','t','C','o','d','e',0};
373 MSIPACKAGE *package = NULL;
374 WCHAR uilevel[10];
376 TRACE("%p\n", db);
378 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
379 MSI_FreePackage );
380 if( package )
382 msiobj_addref( &db->hdr );
384 package->db = db;
385 list_init( &package->components );
386 list_init( &package->features );
387 list_init( &package->files );
388 list_init( &package->tempfiles );
389 list_init( &package->folders );
390 package->ActionFormat = NULL;
391 package->LastAction = NULL;
392 package->dialog = NULL;
393 package->next_dialog = NULL;
394 list_init( &package->subscriptions );
395 list_init( &package->appids );
396 list_init( &package->classes );
397 list_init( &package->mimes );
398 list_init( &package->extensions );
399 list_init( &package->progids );
400 list_init( &package->RunningActions );
402 /* OK, here is where we do a slew of things to the database to
403 * prep for all that is to come as a package */
405 clone_properties(db);
406 set_installer_properties(package);
407 sprintfW(uilevel,szpi,gUILevel);
408 MSI_SetPropertyW(package, szLevel, uilevel);
410 package->ProductCode = msi_dup_property( package, szProductCode );
411 set_installed_prop( package );
414 return package;
418 * copy_package_to_temp [internal]
420 * copy the msi file to a temp file to prevent locking a CD
421 * with a multi disc install
423 * FIXME: I think this is wrong, and instead of copying the package,
424 * we should read all the tables to memory, then open the
425 * database to read binary streams on demand.
427 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
429 WCHAR path[MAX_PATH];
430 static const WCHAR szMSI[] = {'M','S','I',0};
432 GetTempPathW( MAX_PATH, path );
433 GetTempFileNameW( path, szMSI, 0, filename );
435 if( !CopyFileW( szPackage, filename, FALSE ) )
437 ERR("failed to copy package to temp path %s\n", debugstr_w(filename) );
438 return szPackage;
441 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
442 return filename;
445 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
447 MSIDATABASE *db = NULL;
448 MSIPACKAGE *package;
449 MSIHANDLE handle;
450 UINT r;
452 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
454 if( szPackage[0] == '#' )
456 handle = atoiW(&szPackage[1]);
457 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
458 if( !db )
459 return ERROR_INVALID_HANDLE;
461 else
463 WCHAR temppath[MAX_PATH];
464 LPCWSTR file = copy_package_to_temp( szPackage, temppath );
466 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
468 if (file != szPackage)
469 DeleteFileW( file );
471 if( r != ERROR_SUCCESS )
472 return r;
475 package = MSI_CreatePackage( db );
476 msiobj_release( &db->hdr );
477 if( !package )
478 return ERROR_FUNCTION_FAILED;
481 * FIXME: I don't think this is right. Maybe we should be storing the
482 * name of the database in the MSIDATABASE structure and fetching this
483 * info from there, or maybe this is only relevant to cached databases.
485 if( szPackage[0] != '#' )
487 static const WCHAR OriginalDatabase[] =
488 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
489 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
491 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
492 MSI_SetPropertyW( package, Database, szPackage );
495 *pPackage = package;
497 return ERROR_SUCCESS;
500 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
502 MSIPACKAGE *package = NULL;
503 UINT ret;
505 TRACE("%s %08lx %p\n", debugstr_w(szPackage), dwOptions, phPackage );
507 if( dwOptions )
508 FIXME("dwOptions %08lx not supported\n", dwOptions);
510 ret = MSI_OpenPackageW( szPackage, &package );
511 if( ret == ERROR_SUCCESS )
513 *phPackage = alloc_msihandle( &package->hdr );
514 msiobj_release( &package->hdr );
517 return ret;
520 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
522 return MsiOpenPackageExW( szPackage, 0, phPackage );
525 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
527 LPWSTR szwPack = NULL;
528 UINT ret;
530 if( szPackage )
532 szwPack = strdupAtoW( szPackage );
533 if( !szwPack )
534 return ERROR_OUTOFMEMORY;
537 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
539 msi_free( szwPack );
541 return ret;
544 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
546 return MsiOpenPackageExA( szPackage, 0, phPackage );
549 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
551 MSIPACKAGE *package;
552 MSIHANDLE handle = 0;
554 TRACE("(%ld)\n",hInstall);
556 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
557 if( package)
559 handle = alloc_msihandle( &package->db->hdr );
560 msiobj_release( &package->hdr );
563 return handle;
566 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
567 MSIRECORD *record)
569 DWORD log_type = 0;
570 LPWSTR message;
571 DWORD sz;
572 DWORD total_size = 0;
573 INT msg_field=1;
574 INT i;
575 INT rc;
576 char *msg;
577 int len;
579 TRACE("%x\n", eMessageType);
580 rc = 0;
582 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
583 log_type |= INSTALLLOGMODE_ERROR;
584 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
585 log_type |= INSTALLLOGMODE_WARNING;
586 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
587 log_type |= INSTALLLOGMODE_USER;
588 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
589 log_type |= INSTALLLOGMODE_INFO;
590 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
591 log_type |= INSTALLLOGMODE_COMMONDATA;
592 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
593 log_type |= INSTALLLOGMODE_ACTIONSTART;
594 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
595 log_type |= INSTALLLOGMODE_ACTIONDATA;
596 /* just a guess */
597 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
598 log_type |= 0x800;
600 message = msi_alloc(1*sizeof (WCHAR));
601 message[0]=0;
602 msg_field = MSI_RecordGetFieldCount(record);
603 for (i = 1; i <= msg_field; i++)
605 LPWSTR tmp;
606 WCHAR number[3];
607 static const WCHAR format[] = { '%','i',':',' ',0};
608 static const WCHAR space[] = { ' ',0};
609 sz = 0;
610 MSI_RecordGetStringW(record,i,NULL,&sz);
611 sz+=4;
612 total_size+=sz*sizeof(WCHAR);
613 tmp = msi_alloc(sz*sizeof(WCHAR));
614 message = msi_realloc(message,total_size*sizeof (WCHAR));
616 MSI_RecordGetStringW(record,i,tmp,&sz);
618 if (msg_field > 1)
620 sprintfW(number,format,i);
621 strcatW(message,number);
623 strcatW(message,tmp);
624 if (msg_field > 1)
625 strcatW(message,space);
627 msi_free(tmp);
630 TRACE("(%p %lx %lx %s)\n",gUIHandlerA, gUIFilter, log_type,
631 debugstr_w(message));
633 /* convert it to ASCII */
634 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
635 NULL, 0, NULL, NULL );
636 msg = msi_alloc( len );
637 WideCharToMultiByte( CP_ACP, 0, message, -1,
638 msg, len, NULL, NULL );
640 if (gUIHandlerA && (gUIFilter & log_type))
642 rc = gUIHandlerA(gUIContext,eMessageType,msg);
645 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
646 INSTALLMESSAGE_PROGRESS))
648 DWORD write;
649 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
650 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
652 if (log_file != INVALID_HANDLE_VALUE)
654 SetFilePointer(log_file,0, NULL, FILE_END);
655 WriteFile(log_file,msg,strlen(msg),&write,NULL);
656 WriteFile(log_file,"\n",1,&write,NULL);
657 CloseHandle(log_file);
660 msi_free( msg );
662 msi_free( message);
663 return ERROR_SUCCESS;
666 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
667 MSIHANDLE hRecord)
669 UINT ret = ERROR_INVALID_HANDLE;
670 MSIPACKAGE *package = NULL;
671 MSIRECORD *record = NULL;
673 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
674 if( !package )
675 return ERROR_INVALID_HANDLE;
677 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
678 if( !record )
679 goto out;
681 ret = MSI_ProcessMessage( package, eMessageType, record );
683 out:
684 msiobj_release( &package->hdr );
685 if( record )
686 msiobj_release( &record->hdr );
688 return ret;
691 /* property code */
692 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
694 LPWSTR szwName = NULL, szwValue = NULL;
695 UINT r = ERROR_OUTOFMEMORY;
697 szwName = strdupAtoW( szName );
698 if( szName && !szwName )
699 goto end;
701 szwValue = strdupAtoW( szValue );
702 if( szValue && !szwValue )
703 goto end;
705 r = MsiSetPropertyW( hInstall, szwName, szwValue);
707 end:
708 msi_free( szwName );
709 msi_free( szwValue );
711 return r;
714 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
716 MSIQUERY *view;
717 MSIRECORD *row;
718 UINT rc;
719 DWORD sz = 0;
720 static const WCHAR Insert[]=
721 {'I','N','S','E','R','T',' ','i','n','t','o',' ','`','_','P','r','o','p'
722 ,'e','r','t','y','`',' ','(','`','_','P','r','o','p','e','r','t','y','`'
723 ,',','`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
724 ,' ','(','?',',','?',')',0};
725 static const WCHAR Update[]=
726 {'U','P','D','A','T','E',' ','_','P','r','o','p','e'
727 ,'r','t','y',' ','s','e','t',' ','`','V','a','l','u','e','`',' ','='
728 ,' ','?',' ','w','h','e','r','e',' ','`','_','P','r','o','p'
729 ,'e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
730 WCHAR Query[1024];
732 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
734 if (!szName)
735 return ERROR_INVALID_PARAMETER;
737 /* this one is weird... */
738 if (!szName[0])
739 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
741 rc = MSI_GetPropertyW(package,szName,0,&sz);
742 if (rc==ERROR_MORE_DATA || rc == ERROR_SUCCESS)
744 sprintfW(Query,Update,szName);
746 row = MSI_CreateRecord(1);
747 MSI_RecordSetStringW(row,1,szValue);
750 else
752 strcpyW(Query,Insert);
754 row = MSI_CreateRecord(2);
755 MSI_RecordSetStringW(row,1,szName);
756 MSI_RecordSetStringW(row,2,szValue);
759 rc = MSI_DatabaseOpenViewW(package->db,Query,&view);
760 if (rc == ERROR_SUCCESS)
762 rc = MSI_ViewExecute(view,row);
764 MSI_ViewClose(view);
765 msiobj_release(&view->hdr);
767 msiobj_release(&row->hdr);
769 return rc;
772 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
774 MSIPACKAGE *package;
775 UINT ret;
777 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
778 if( !package )
779 return ERROR_INVALID_HANDLE;
780 ret = MSI_SetPropertyW( package, szName, szValue);
781 msiobj_release( &package->hdr );
782 return ret;
785 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
787 static const WCHAR query[]=
788 {'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
789 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
790 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
791 '=','\'','%','s','\'',0};
793 if (!name || !name[0])
794 return NULL;
796 return MSI_QueryGetRecord( package->db, query, name );
799 /* internal function, not compatible with MsiGetPropertyW */
800 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
801 LPWSTR szValueBuf, DWORD* pchValueBuf )
803 MSIRECORD *row;
804 UINT rc = ERROR_FUNCTION_FAILED;
806 row = MSI_GetPropertyRow( package, szName );
808 if (*pchValueBuf > 0)
809 szValueBuf[0] = 0;
811 if (row)
813 rc = MSI_RecordGetStringW(row,1,szValueBuf,pchValueBuf);
814 msiobj_release(&row->hdr);
817 if (rc == ERROR_SUCCESS)
818 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
819 debugstr_w(szName));
820 else if (rc == ERROR_MORE_DATA)
821 TRACE("need %li sized buffer for %s\n", *pchValueBuf,
822 debugstr_w(szName));
823 else
825 *pchValueBuf = 0;
826 TRACE("property %s not found\n", debugstr_w(szName));
829 return rc;
832 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
833 awstring *szValueBuf, DWORD* pchValueBuf )
835 static const WCHAR empty[] = {0};
836 MSIPACKAGE *package;
837 MSIRECORD *row = NULL;
838 UINT r;
839 LPCWSTR val = NULL;
841 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
842 szValueBuf->str.w, pchValueBuf );
844 if (!name)
845 return ERROR_INVALID_PARAMETER;
847 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
848 if (!package)
849 return ERROR_INVALID_HANDLE;
851 row = MSI_GetPropertyRow( package, name );
852 if (row)
853 val = MSI_RecordGetString( row, 1 );
855 if (!val)
856 val = empty;
858 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
860 if (row)
861 msiobj_release( &row->hdr );
862 msiobj_release( &package->hdr );
864 return r;
867 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
868 LPSTR szValueBuf, DWORD* pchValueBuf )
870 awstring val;
871 LPWSTR name;
872 UINT r;
874 val.unicode = FALSE;
875 val.str.a = szValueBuf;
877 name = strdupAtoW( szName );
878 if (szName && !name)
879 return ERROR_OUTOFMEMORY;
881 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
882 msi_free( name );
883 return r;
886 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
887 LPWSTR szValueBuf, DWORD* pchValueBuf )
889 awstring val;
891 val.unicode = TRUE;
892 val.str.w = szValueBuf;
894 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );