push 1fb51685cfc6ddbce546c9614143e4d38b5f030b
[wine/hacks.git] / dlls / msi / package.c
blobe9b630994e8e79e26fe674ac40856ce93b0e441b
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
25 #include <stdarg.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 "wininet.h"
39 #include "winver.h"
40 #include "urlmon.h"
41 #include "shlobj.h"
42 #include "wine/unicode.h"
43 #include "objbase.h"
44 #include "msidefs.h"
45 #include "sddl.h"
47 #include "msipriv.h"
48 #include "msiserver.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 static void MSI_FreePackage( MSIOBJECTHDR *arg)
54 MSIPACKAGE *package= (MSIPACKAGE*) arg;
56 if( package->dialog )
57 msi_dialog_destroy( package->dialog );
59 msiobj_release( &package->db->hdr );
60 ACTION_free_package_structures(package);
63 static UINT create_temp_property_table(MSIPACKAGE *package)
65 MSIQUERY *view = NULL;
66 UINT rc;
68 static const WCHAR CreateSql[] = {
69 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
70 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
71 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
72 'L','L',' ','T','E','M','P','O','R','A','R','Y',',',' ','`','V','a','l',
73 'u','e','`',' ','C','H','A','R','(','9','8',')',' ','N','O','T',' ','N',
74 'U','L','L',' ','T','E','M','P','O','R','A','R','Y',' ','P','R','I','M',
75 'A','R','Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y',
76 '`',')',0};
78 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
79 if (rc != ERROR_SUCCESS)
80 return rc;
82 rc = MSI_ViewExecute(view, 0);
83 MSI_ViewClose(view);
84 msiobj_release(&view->hdr);
85 return rc;
88 UINT msi_clone_properties(MSIPACKAGE *package)
90 MSIQUERY *view = NULL;
91 UINT rc;
93 static const WCHAR Query[] = {
94 'S','E','L','E','C','T',' ','*',' ',
95 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
96 static const WCHAR Insert[] = {
97 'I','N','S','E','R','T',' ','i','n','t','o',' ',
98 '`','_','P','r','o','p','e','r','t','y','`',' ',
99 '(','`','_','P','r','o','p','e','r','t','y','`',',',
100 '`','V','a','l','u','e','`',')',' ',
101 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
103 /* clone the existing properties */
104 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
105 if (rc != ERROR_SUCCESS)
106 return rc;
108 rc = MSI_ViewExecute(view, 0);
109 if (rc != ERROR_SUCCESS)
111 MSI_ViewClose(view);
112 msiobj_release(&view->hdr);
113 return rc;
116 while (1)
118 MSIRECORD *row;
119 MSIQUERY *view2;
121 rc = MSI_ViewFetch(view, &row);
122 if (rc != ERROR_SUCCESS)
123 break;
125 rc = MSI_DatabaseOpenViewW(package->db, Insert, &view2);
126 if (rc!= ERROR_SUCCESS)
127 continue;
129 rc = MSI_ViewExecute(view2, row);
130 MSI_ViewClose(view2);
131 msiobj_release(&view2->hdr);
133 if (rc == ERROR_SUCCESS)
134 msiobj_release(&row->hdr);
137 MSI_ViewClose(view);
138 msiobj_release(&view->hdr);
140 return rc;
144 * set_installed_prop
146 * Sets the "Installed" property to indicate that
147 * the product is installed for the current user.
149 static UINT set_installed_prop( MSIPACKAGE *package )
151 static const WCHAR szInstalled[] = {
152 'I','n','s','t','a','l','l','e','d',0 };
153 WCHAR val[2] = { '1', 0 };
154 HKEY hkey = 0;
155 UINT r;
157 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
158 if (r == ERROR_SUCCESS)
160 RegCloseKey( hkey );
161 MSI_SetPropertyW( package, szInstalled, val );
164 return r;
167 static UINT set_user_sid_prop( MSIPACKAGE *package )
169 SID_NAME_USE use;
170 LPWSTR user_name;
171 LPWSTR sid_str = NULL, dom = NULL;
172 DWORD size, dom_size;
173 PSID psid = NULL;
174 UINT r = ERROR_FUNCTION_FAILED;
176 static const WCHAR user_sid[] = {'U','s','e','r','S','I','D',0};
178 size = 0;
179 GetUserNameW( NULL, &size );
181 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
182 if (!user_name)
183 return ERROR_OUTOFMEMORY;
185 if (!GetUserNameW( user_name, &size ))
186 goto done;
188 size = 0;
189 dom_size = 0;
190 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
192 psid = msi_alloc( size );
193 dom = msi_alloc( dom_size*sizeof (WCHAR) );
194 if (!psid || !dom)
196 r = ERROR_OUTOFMEMORY;
197 goto done;
200 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
201 goto done;
203 if (!ConvertSidToStringSidW( psid, &sid_str ))
204 goto done;
206 r = MSI_SetPropertyW( package, user_sid, sid_str );
208 done:
209 LocalFree( sid_str );
210 msi_free( dom );
211 msi_free( psid );
212 msi_free( user_name );
214 return r;
217 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
219 HKEY netsetup;
220 LONG res;
221 LPWSTR file;
222 DWORD index = 0, size;
223 WCHAR ver[MAX_PATH];
224 WCHAR name[MAX_PATH];
225 WCHAR windir[MAX_PATH];
227 static const WCHAR backslash[] = {'\\',0};
228 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
229 static const WCHAR sub[] = {
230 'S','o','f','t','w','a','r','e','\\',
231 'M','i','c','r','o','s','o','f','t','\\',
232 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
233 'N','D','P',0
235 static const WCHAR subdir[] = {
236 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
237 'F','r','a','m','e','w','o','r','k','\\',0
240 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
241 if (res != ERROR_SUCCESS)
242 return NULL;
244 ver[0] = '\0';
245 size = MAX_PATH;
246 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
248 index++;
249 if (lstrcmpW(ver, name) < 0)
250 lstrcpyW(ver, name);
253 RegCloseKey(netsetup);
255 if (!index)
256 return NULL;
258 GetWindowsDirectoryW(windir, MAX_PATH);
260 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(ver) +lstrlenW(fusion) + 3;
261 file = msi_alloc(size * sizeof(WCHAR));
262 if (!file)
263 return NULL;
265 lstrcpyW(file, windir);
266 lstrcatW(file, backslash);
267 lstrcatW(file, subdir);
268 lstrcatW(file, ver);
269 lstrcatW(file, backslash);
270 lstrcatW(file, fusion);
272 return file;
275 typedef struct tagLANGANDCODEPAGE
277 WORD wLanguage;
278 WORD wCodePage;
279 } LANGANDCODEPAGE;
281 static void set_msi_assembly_prop(MSIPACKAGE *package)
283 UINT val_len;
284 DWORD size, handle;
285 LPVOID version = NULL;
286 WCHAR buf[MAX_PATH];
287 LPWSTR fusion, verstr;
288 LANGANDCODEPAGE *translate;
290 static const WCHAR netasm[] = {
291 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
293 static const WCHAR translation[] = {
294 '\\','V','a','r','F','i','l','e','I','n','f','o',
295 '\\','T','r','a','n','s','l','a','t','i','o','n',0
297 static const WCHAR verfmt[] = {
298 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
299 '\\','%','0','4','x','%','0','4','x',
300 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
303 fusion = get_fusion_filename(package);
304 if (!fusion)
305 return;
307 size = GetFileVersionInfoSizeW(fusion, &handle);
308 if (!size) return;
310 version = msi_alloc(size);
311 if (!version) return;
313 if (!GetFileVersionInfoW(fusion, handle, size, version))
314 goto done;
316 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
317 goto done;
319 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
321 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
322 goto done;
324 if (!val_len || !verstr)
325 goto done;
327 MSI_SetPropertyW(package, netasm, verstr);
329 done:
330 msi_free(fusion);
331 msi_free(version);
335 * There are a whole slew of these we need to set
338 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
340 static VOID set_installer_properties(MSIPACKAGE *package)
342 WCHAR pth[MAX_PATH];
343 WCHAR *ptr;
344 OSVERSIONINFOEXW OSVersion;
345 MEMORYSTATUSEX msex;
346 DWORD verval;
347 WCHAR verstr[10], bufstr[20];
348 HDC dc;
349 LPWSTR check;
350 HKEY hkey;
351 LONG res;
352 SYSTEM_INFO sys_info;
353 SYSTEMTIME systemtime;
355 static const WCHAR cszbs[]={'\\',0};
356 static const WCHAR CFF[] =
357 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
358 static const WCHAR PFF[] =
359 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
360 static const WCHAR CADF[] =
361 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
362 static const WCHAR FaF[] =
363 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
364 static const WCHAR FoF[] =
365 {'F','o','n','t','s','F','o','l','d','e','r',0};
366 static const WCHAR SendTF[] =
367 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
368 static const WCHAR SMF[] =
369 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
370 static const WCHAR StF[] =
371 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
372 static const WCHAR TemplF[] =
373 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
374 static const WCHAR DF[] =
375 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
376 static const WCHAR PMF[] =
377 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
378 static const WCHAR ATF[] =
379 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
380 static const WCHAR ADF[] =
381 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
382 static const WCHAR SF[] =
383 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
384 static const WCHAR SF16[] =
385 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
386 static const WCHAR LADF[] =
387 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
388 static const WCHAR MPF[] =
389 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
390 static const WCHAR PF[] =
391 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
392 static const WCHAR WF[] =
393 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
394 static const WCHAR WV[] =
395 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
396 static const WCHAR TF[]=
397 {'T','e','m','p','F','o','l','d','e','r',0};
398 static const WCHAR szAdminUser[] =
399 {'A','d','m','i','n','U','s','e','r',0};
400 static const WCHAR szPriv[] =
401 {'P','r','i','v','i','l','e','g','e','d',0};
402 static const WCHAR szOne[] =
403 {'1',0};
404 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
405 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
406 static const WCHAR szMsiNTProductType[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
407 static const WCHAR szFormat[] = {'%','l','i',0};
408 static const WCHAR szWinBuild[] =
409 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
410 static const WCHAR szSPL[] =
411 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
412 static const WCHAR szSix[] = {'6',0 };
414 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
415 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
416 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
417 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
418 /* Screen properties */
419 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
420 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
421 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
422 static const WCHAR szScreenFormat[] = {'%','d',0};
423 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
424 static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
425 static const WCHAR szCurrentVersion[] = {
426 'S','O','F','T','W','A','R','E','\\',
427 'M','i','c','r','o','s','o','f','t','\\',
428 'W','i','n','d','o','w','s',' ','N','T','\\',
429 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
431 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
432 static const WCHAR szRegisteredOrg[] = {
433 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
435 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
436 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
437 static const WCHAR szDate[] = {'D','a','t','e',0};
438 static const WCHAR szTime[] = {'T','i','m','e',0};
441 * Other things that probably should be set:
443 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
444 * ShellAdvSupport DefaultUIFont PackagecodeChanging
445 * ProductState CaptionHeight BorderTop BorderSide TextHeight
446 * RedirectedDllSupport
449 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
450 strcatW(pth,cszbs);
451 MSI_SetPropertyW(package, CFF, pth);
453 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
454 strcatW(pth,cszbs);
455 MSI_SetPropertyW(package, PFF, pth);
457 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
458 strcatW(pth,cszbs);
459 MSI_SetPropertyW(package, CADF, pth);
461 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
462 strcatW(pth,cszbs);
463 MSI_SetPropertyW(package, FaF, pth);
465 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
466 strcatW(pth,cszbs);
467 MSI_SetPropertyW(package, FoF, pth);
469 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
470 strcatW(pth,cszbs);
471 MSI_SetPropertyW(package, SendTF, pth);
473 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
474 strcatW(pth,cszbs);
475 MSI_SetPropertyW(package, SMF, pth);
477 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
478 strcatW(pth,cszbs);
479 MSI_SetPropertyW(package, StF, pth);
481 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
482 strcatW(pth,cszbs);
483 MSI_SetPropertyW(package, TemplF, pth);
485 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
486 strcatW(pth,cszbs);
487 MSI_SetPropertyW(package, DF, pth);
489 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
490 strcatW(pth,cszbs);
491 MSI_SetPropertyW(package, PMF, pth);
493 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
494 strcatW(pth,cszbs);
495 MSI_SetPropertyW(package, ATF, pth);
497 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
498 strcatW(pth,cszbs);
499 MSI_SetPropertyW(package, ADF, pth);
501 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
502 strcatW(pth,cszbs);
503 MSI_SetPropertyW(package, SF, pth);
504 MSI_SetPropertyW(package, SF16, pth);
506 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
507 strcatW(pth,cszbs);
508 MSI_SetPropertyW(package, LADF, pth);
510 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
511 strcatW(pth,cszbs);
512 MSI_SetPropertyW(package, MPF, pth);
514 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
515 strcatW(pth,cszbs);
516 MSI_SetPropertyW(package, PF, pth);
518 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
519 strcatW(pth,cszbs);
520 MSI_SetPropertyW(package, WF, pth);
522 /* Physical Memory is specified in MB. Using total amount. */
523 msex.dwLength = sizeof(msex);
524 GlobalMemoryStatusEx( &msex );
525 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
526 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
528 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
529 ptr = strchrW(pth,'\\');
530 if (ptr)
531 *(ptr+1) = 0;
532 MSI_SetPropertyW(package, WV, pth);
534 GetTempPathW(MAX_PATH,pth);
535 MSI_SetPropertyW(package, TF, pth);
538 /* in a wine environment the user is always admin and privileged */
539 MSI_SetPropertyW(package,szAdminUser,szOne);
540 MSI_SetPropertyW(package,szPriv,szOne);
541 MSI_SetPropertyW(package, szAllUsers, szOne);
543 /* set the os things */
544 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
545 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
546 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
547 sprintfW(verstr,szFormat,verval);
548 switch (OSVersion.dwPlatformId)
550 case VER_PLATFORM_WIN32_WINDOWS:
551 MSI_SetPropertyW(package,v9x,verstr);
552 break;
553 case VER_PLATFORM_WIN32_NT:
554 MSI_SetPropertyW(package,vNT,verstr);
555 sprintfW(verstr,szFormat,OSVersion.wProductType);
556 MSI_SetPropertyW(package,szMsiNTProductType,verstr);
557 break;
559 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
560 MSI_SetPropertyW(package,szWinBuild,verstr);
561 /* just fudge this */
562 MSI_SetPropertyW(package,szSPL,szSix);
564 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
565 MSI_SetPropertyW( package, szVersionMsi, bufstr );
566 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
567 MSI_SetPropertyW( package, szVersionDatabase, bufstr );
569 GetSystemInfo( &sys_info );
570 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
572 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
573 MSI_SetPropertyW( package, szIntel, bufstr );
576 /* Screen properties. */
577 dc = GetDC(0);
578 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
579 MSI_SetPropertyW( package, szScreenX, bufstr );
580 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
581 MSI_SetPropertyW( package, szScreenY, bufstr );
582 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
583 MSI_SetPropertyW( package, szColorBits, bufstr );
584 ReleaseDC(0, dc);
586 /* USERNAME and COMPANYNAME */
587 res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
588 if (res != ERROR_SUCCESS)
589 return;
591 check = msi_dup_property( package, szUSERNAME );
592 if (!check)
594 LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
595 MSI_SetPropertyW( package, szUSERNAME, user );
596 msi_free( user );
599 msi_free( check );
601 check = msi_dup_property( package, szCOMPANYNAME );
602 if (!check)
604 LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
605 MSI_SetPropertyW( package, szCOMPANYNAME, company );
606 msi_free( company );
609 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
610 ERR("Failed to set the UserSID property\n");
612 /* Date and time properties */
613 GetSystemTime( &systemtime );
614 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
615 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
616 MSI_SetPropertyW( package, szDate, bufstr );
617 else
618 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
620 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
621 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
622 &systemtime, NULL, bufstr,
623 sizeof(bufstr)/sizeof(bufstr[0]) ))
624 MSI_SetPropertyW( package, szTime, bufstr );
625 else
626 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
628 set_msi_assembly_prop( package );
630 msi_free( check );
631 CloseHandle( hkey );
634 static UINT msi_load_summary_properties( MSIPACKAGE *package )
636 UINT rc;
637 MSIHANDLE suminfo;
638 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
639 INT word_count;
640 DWORD len;
641 LPWSTR package_code;
642 static const WCHAR szPackageCode[] = {
643 'P','a','c','k','a','g','e','C','o','d','e',0};
645 if (!hdb) {
646 ERR("Unable to allocate handle\n");
647 return 0;
649 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
650 MsiCloseHandle(hdb);
651 if (rc != ERROR_SUCCESS)
653 ERR("Unable to open Summary Information\n");
654 return rc;
657 /* load package attributes */
658 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
659 &word_count, NULL, NULL, NULL );
660 if (rc == ERROR_SUCCESS)
661 package->WordCount = word_count;
662 else
663 WARN("Unable to query word count\n");
665 /* load package code property */
666 len = 0;
667 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
668 NULL, NULL, NULL, &len );
669 if (rc == ERROR_MORE_DATA)
671 len++;
672 package_code = msi_alloc( len * sizeof(WCHAR) );
673 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
674 NULL, NULL, package_code, &len );
675 if (rc == ERROR_SUCCESS)
676 MSI_SetPropertyW( package, szPackageCode, package_code );
677 else
678 WARN("Unable to query rev number, %d\n", rc);
679 msi_free( package_code );
681 else
682 WARN("Unable to query rev number, %d\n", rc);
684 MsiCloseHandle(suminfo);
685 return ERROR_SUCCESS;
688 static MSIPACKAGE *msi_alloc_package( void )
690 MSIPACKAGE *package;
692 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
693 MSI_FreePackage );
694 if( package )
696 list_init( &package->components );
697 list_init( &package->features );
698 list_init( &package->files );
699 list_init( &package->tempfiles );
700 list_init( &package->folders );
701 list_init( &package->subscriptions );
702 list_init( &package->appids );
703 list_init( &package->classes );
704 list_init( &package->mimes );
705 list_init( &package->extensions );
706 list_init( &package->progids );
707 list_init( &package->RunningActions );
708 list_init( &package->sourcelist_info );
709 list_init( &package->sourcelist_media );
711 package->ActionFormat = NULL;
712 package->LastAction = NULL;
713 package->dialog = NULL;
714 package->next_dialog = NULL;
715 package->scheduled_action_running = FALSE;
716 package->commit_action_running = FALSE;
717 package->rollback_action_running = FALSE;
720 return package;
723 static UINT msi_load_admin_properties(MSIPACKAGE *package)
725 BYTE *data;
726 UINT r, sz;
728 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
730 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
731 if (r != ERROR_SUCCESS)
732 return r;
734 r = msi_parse_command_line(package, (WCHAR *)data);
736 msi_free(data);
737 return r;
740 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
742 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
743 static const WCHAR szpi[] = {'%','i',0};
744 static const WCHAR szProductCode[] = {
745 'P','r','o','d','u','c','t','C','o','d','e',0};
746 MSIPACKAGE *package;
747 WCHAR uilevel[10];
749 TRACE("%p\n", db);
751 package = msi_alloc_package();
752 if (package)
754 msiobj_addref( &db->hdr );
755 package->db = db;
757 package->WordCount = 0;
758 package->PackagePath = strdupW( db->path );
759 package->BaseURL = strdupW( base_url );
761 create_temp_property_table( package );
762 msi_clone_properties( package );
763 set_installer_properties(package);
764 sprintfW(uilevel,szpi,gUILevel);
765 MSI_SetPropertyW(package, szLevel, uilevel);
767 package->ProductCode = msi_dup_property( package, szProductCode );
768 set_installed_prop( package );
769 msi_load_summary_properties( package );
771 if (package->WordCount & MSIWORDCOUNT_ADMINISTRATIVE)
772 msi_load_admin_properties( package );
775 return package;
779 * copy_package_to_temp [internal]
781 * copy the msi file to a temp file to prevent locking a CD
782 * with a multi disc install
784 * FIXME: I think this is wrong, and instead of copying the package,
785 * we should read all the tables to memory, then open the
786 * database to read binary streams on demand.
788 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
790 WCHAR path[MAX_PATH];
791 static const WCHAR szMSI[] = {'m','s','i',0};
793 GetTempPathW( MAX_PATH, path );
794 GetTempFileNameW( path, szMSI, 0, filename );
796 if( !CopyFileW( szPackage, filename, FALSE ) )
798 DeleteFileW( filename );
799 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
800 return szPackage;
803 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
804 return filename;
807 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
809 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
810 DWORD size = 0;
811 HRESULT hr;
813 /* call will always fail, becase size is 0,
814 * but will return ERROR_FILE_NOT_FOUND first
815 * if the file doesn't exist
817 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
818 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
820 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
821 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
823 HeapFree( GetProcessHeap(), 0, cache_entry );
824 return szUrl;
827 lstrcpyW( filename, cache_entry->lpszLocalFileName );
828 HeapFree( GetProcessHeap(), 0, cache_entry );
829 return filename;
832 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
833 if ( FAILED(hr) )
834 return szUrl;
836 return filename;
839 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
841 static const WCHAR OriginalDatabase[] =
842 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
843 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
844 MSIDATABASE *db = NULL;
845 MSIPACKAGE *package;
846 MSIHANDLE handle;
847 LPWSTR ptr, base_url = NULL;
848 UINT r;
849 WCHAR temppath[MAX_PATH];
850 LPCWSTR file = szPackage;
852 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
854 if( szPackage[0] == '#' )
856 handle = atoiW(&szPackage[1]);
857 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
858 if( !db )
859 return ERROR_INVALID_HANDLE;
861 else
863 if ( UrlIsW( szPackage, URLIS_URL ) )
865 file = msi_download_file( szPackage, temppath );
867 base_url = strdupW( szPackage );
868 if ( !base_url )
869 return ERROR_OUTOFMEMORY;
871 ptr = strrchrW( base_url, '/' );
872 if (ptr) *(ptr + 1) = '\0';
874 else
875 file = copy_package_to_temp( szPackage, temppath );
877 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
878 if( r != ERROR_SUCCESS )
880 if (GetLastError() == ERROR_FILE_NOT_FOUND)
881 msi_ui_error( 4, MB_OK | MB_ICONWARNING );
882 if (file != szPackage)
883 DeleteFileW( file );
885 return r;
889 package = MSI_CreatePackage( db, base_url );
890 msi_free( base_url );
891 msiobj_release( &db->hdr );
892 if( !package )
894 if (file != szPackage)
895 DeleteFileW( file );
896 return ERROR_FUNCTION_FAILED;
899 if( file != szPackage )
900 track_tempfile( package, file );
902 if( szPackage[0] != '#' )
904 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
905 MSI_SetPropertyW( package, Database, szPackage );
907 else
909 MSI_SetPropertyW( package, OriginalDatabase, db->path );
910 MSI_SetPropertyW( package, Database, db->path );
913 *pPackage = package;
915 return ERROR_SUCCESS;
918 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
920 MSIPACKAGE *package = NULL;
921 UINT ret;
923 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
925 if( szPackage == NULL )
926 return ERROR_INVALID_PARAMETER;
928 if( dwOptions )
929 FIXME("dwOptions %08x not supported\n", dwOptions);
931 ret = MSI_OpenPackageW( szPackage, &package );
932 if( ret == ERROR_SUCCESS )
934 *phPackage = alloc_msihandle( &package->hdr );
935 if (! *phPackage)
936 ret = ERROR_NOT_ENOUGH_MEMORY;
937 msiobj_release( &package->hdr );
940 return ret;
943 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
945 return MsiOpenPackageExW( szPackage, 0, phPackage );
948 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
950 LPWSTR szwPack = NULL;
951 UINT ret;
953 if( szPackage )
955 szwPack = strdupAtoW( szPackage );
956 if( !szwPack )
957 return ERROR_OUTOFMEMORY;
960 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
962 msi_free( szwPack );
964 return ret;
967 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
969 return MsiOpenPackageExA( szPackage, 0, phPackage );
972 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
974 MSIPACKAGE *package;
975 MSIHANDLE handle = 0;
976 IWineMsiRemotePackage *remote_package;
978 TRACE("(%ld)\n",hInstall);
980 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
981 if( package)
983 handle = alloc_msihandle( &package->db->hdr );
984 msiobj_release( &package->hdr );
986 else if ((remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall )))
988 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
989 IWineMsiRemotePackage_Release(remote_package);
992 return handle;
995 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
996 MSIRECORD *record)
998 static const WCHAR szActionData[] =
999 {'A','c','t','i','o','n','D','a','t','a',0};
1000 static const WCHAR szSetProgress[] =
1001 {'S','e','t','P','r','o','g','r','e','s','s',0};
1002 static const WCHAR szActionText[] =
1003 {'A','c','t','i','o','n','T','e','x','t',0};
1004 DWORD log_type = 0;
1005 LPWSTR message;
1006 DWORD sz;
1007 DWORD total_size = 0;
1008 INT i;
1009 INT rc;
1010 char *msg;
1011 int len;
1013 TRACE("%x\n", eMessageType);
1014 rc = 0;
1016 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1017 log_type |= INSTALLLOGMODE_ERROR;
1018 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1019 log_type |= INSTALLLOGMODE_WARNING;
1020 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1021 log_type |= INSTALLLOGMODE_USER;
1022 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1023 log_type |= INSTALLLOGMODE_INFO;
1024 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1025 log_type |= INSTALLLOGMODE_COMMONDATA;
1026 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1027 log_type |= INSTALLLOGMODE_ACTIONSTART;
1028 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1029 log_type |= INSTALLLOGMODE_ACTIONDATA;
1030 /* just a guess */
1031 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1032 log_type |= 0x800;
1034 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1036 static const WCHAR template_s[]=
1037 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1038 static const WCHAR format[] =
1039 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1040 WCHAR timet[0x100];
1041 LPCWSTR action_text, action;
1042 LPWSTR deformatted = NULL;
1044 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1046 action = MSI_RecordGetString(record, 1);
1047 action_text = MSI_RecordGetString(record, 2);
1049 if (!action || !action_text)
1050 return IDOK;
1052 deformat_string(package, action_text, &deformatted);
1054 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1055 if (deformatted)
1056 len += strlenW(deformatted);
1057 message = msi_alloc(len*sizeof(WCHAR));
1058 sprintfW(message, template_s, timet, action);
1059 if (deformatted)
1060 strcatW(message, deformatted);
1061 msi_free(deformatted);
1063 else
1065 INT msg_field=1;
1066 message = msi_alloc(1*sizeof (WCHAR));
1067 message[0]=0;
1068 msg_field = MSI_RecordGetFieldCount(record);
1069 for (i = 1; i <= msg_field; i++)
1071 LPWSTR tmp;
1072 WCHAR number[3];
1073 static const WCHAR format[] = { '%','i',':',' ',0};
1074 static const WCHAR space[] = { ' ',0};
1075 sz = 0;
1076 MSI_RecordGetStringW(record,i,NULL,&sz);
1077 sz+=4;
1078 total_size+=sz*sizeof(WCHAR);
1079 tmp = msi_alloc(sz*sizeof(WCHAR));
1080 message = msi_realloc(message,total_size*sizeof (WCHAR));
1082 MSI_RecordGetStringW(record,i,tmp,&sz);
1084 if (msg_field > 1)
1086 sprintfW(number,format,i);
1087 strcatW(message,number);
1089 strcatW(message,tmp);
1090 if (msg_field > 1)
1091 strcatW(message,space);
1093 msi_free(tmp);
1097 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
1098 debugstr_w(message));
1100 /* convert it to ASCII */
1101 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
1102 NULL, 0, NULL, NULL );
1103 msg = msi_alloc( len );
1104 WideCharToMultiByte( CP_ACP, 0, message, -1,
1105 msg, len, NULL, NULL );
1107 if (gUIHandlerA && (gUIFilter & log_type))
1109 rc = gUIHandlerA(gUIContext,eMessageType,msg);
1112 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
1113 INSTALLMESSAGE_PROGRESS))
1115 DWORD write;
1116 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
1117 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1119 if (log_file != INVALID_HANDLE_VALUE)
1121 SetFilePointer(log_file,0, NULL, FILE_END);
1122 WriteFile(log_file,msg,strlen(msg),&write,NULL);
1123 WriteFile(log_file,"\n",1,&write,NULL);
1124 CloseHandle(log_file);
1127 msi_free( msg );
1129 msi_free( message);
1131 switch (eMessageType & 0xff000000)
1133 case INSTALLMESSAGE_ACTIONDATA:
1134 /* FIXME: format record here instead of in ui_actiondata to get the
1135 * correct action data for external scripts */
1136 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1137 break;
1138 case INSTALLMESSAGE_ACTIONSTART:
1140 MSIRECORD *uirow;
1141 LPWSTR deformated;
1142 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1144 deformat_string(package, action_text, &deformated);
1145 uirow = MSI_CreateRecord(1);
1146 MSI_RecordSetStringW(uirow, 1, deformated);
1147 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1148 msi_free(deformated);
1150 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1152 msiobj_release(&uirow->hdr);
1153 break;
1155 case INSTALLMESSAGE_PROGRESS:
1156 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1157 break;
1160 return ERROR_SUCCESS;
1163 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1164 MSIHANDLE hRecord)
1166 UINT ret = ERROR_INVALID_HANDLE;
1167 MSIPACKAGE *package = NULL;
1168 MSIRECORD *record = NULL;
1170 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1171 if( !package )
1173 HRESULT hr;
1174 IWineMsiRemotePackage *remote_package;
1176 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1177 if (!remote_package)
1178 return ERROR_INVALID_HANDLE;
1180 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1182 IWineMsiRemotePackage_Release( remote_package );
1184 if (FAILED(hr))
1186 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1187 return HRESULT_CODE(hr);
1189 return ERROR_FUNCTION_FAILED;
1192 return ERROR_SUCCESS;
1195 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1196 if( !record )
1197 goto out;
1199 ret = MSI_ProcessMessage( package, eMessageType, record );
1201 out:
1202 msiobj_release( &package->hdr );
1203 if( record )
1204 msiobj_release( &record->hdr );
1206 return ret;
1209 /* property code */
1211 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1213 LPWSTR szwName = NULL, szwValue = NULL;
1214 UINT r = ERROR_OUTOFMEMORY;
1216 szwName = strdupAtoW( szName );
1217 if( szName && !szwName )
1218 goto end;
1220 szwValue = strdupAtoW( szValue );
1221 if( szValue && !szwValue )
1222 goto end;
1224 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1226 end:
1227 msi_free( szwName );
1228 msi_free( szwValue );
1230 return r;
1233 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
1235 MSIQUERY *view;
1236 MSIRECORD *row = NULL;
1237 UINT rc;
1238 DWORD sz = 0;
1239 WCHAR Query[1024];
1241 static const WCHAR Insert[] = {
1242 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1243 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1244 '`','_','P','r','o','p','e','r','t','y','`',',',
1245 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1246 ,' ','(','?',',','?',')',0};
1247 static const WCHAR Update[] = {
1248 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1249 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1250 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1251 ' ','=',' ','\'','%','s','\'',0};
1252 static const WCHAR Delete[] = {
1253 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1254 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1255 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1257 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
1259 if (!szName)
1260 return ERROR_INVALID_PARAMETER;
1262 /* this one is weird... */
1263 if (!szName[0])
1264 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1266 rc = MSI_GetPropertyW(package, szName, 0, &sz);
1267 if (!szValue || !*szValue)
1269 sprintfW(Query, Delete, szName);
1271 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1273 sprintfW(Query, Update, szName);
1275 row = MSI_CreateRecord(1);
1276 MSI_RecordSetStringW(row, 1, szValue);
1278 else
1280 strcpyW(Query, Insert);
1282 row = MSI_CreateRecord(2);
1283 MSI_RecordSetStringW(row, 1, szName);
1284 MSI_RecordSetStringW(row, 2, szValue);
1287 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1288 if (rc == ERROR_SUCCESS)
1290 rc = MSI_ViewExecute(view, row);
1291 MSI_ViewClose(view);
1292 msiobj_release(&view->hdr);
1295 msiobj_release(&row->hdr);
1297 return rc;
1300 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1302 MSIPACKAGE *package;
1303 UINT ret;
1305 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1306 if( !package )
1308 HRESULT hr;
1309 BSTR name, value;
1310 IWineMsiRemotePackage *remote_package;
1312 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1313 if (!remote_package)
1314 return ERROR_INVALID_HANDLE;
1316 name = SysAllocString( szName );
1317 value = SysAllocString( szValue );
1318 if (!name || !value)
1320 SysFreeString( name );
1321 SysFreeString( value );
1322 IWineMsiRemotePackage_Release( remote_package );
1323 return ERROR_OUTOFMEMORY;
1326 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
1328 SysFreeString( name );
1329 SysFreeString( value );
1330 IWineMsiRemotePackage_Release( remote_package );
1332 if (FAILED(hr))
1334 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1335 return HRESULT_CODE(hr);
1337 return ERROR_FUNCTION_FAILED;
1340 return ERROR_SUCCESS;
1343 ret = MSI_SetPropertyW( package, szName, szValue);
1344 msiobj_release( &package->hdr );
1345 return ret;
1348 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
1350 static const WCHAR query[]= {
1351 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1352 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1353 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1354 '=','\'','%','s','\'',0};
1356 if (!name || !*name)
1357 return NULL;
1359 return MSI_QueryGetRecord( package->db, query, name );
1362 /* internal function, not compatible with MsiGetPropertyW */
1363 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
1364 LPWSTR szValueBuf, LPDWORD pchValueBuf )
1366 MSIRECORD *row;
1367 UINT rc = ERROR_FUNCTION_FAILED;
1369 row = MSI_GetPropertyRow( package, szName );
1371 if (*pchValueBuf > 0)
1372 szValueBuf[0] = 0;
1374 if (row)
1376 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
1377 msiobj_release(&row->hdr);
1380 if (rc == ERROR_SUCCESS)
1381 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
1382 debugstr_w(szName));
1383 else if (rc == ERROR_MORE_DATA)
1384 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
1385 debugstr_w(szName));
1386 else
1388 *pchValueBuf = 0;
1389 TRACE("property %s not found\n", debugstr_w(szName));
1392 return rc;
1395 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
1397 DWORD sz = 0;
1398 LPWSTR str;
1399 UINT r;
1401 r = MSI_GetPropertyW(package, prop, NULL, &sz);
1402 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
1403 return NULL;
1405 sz++;
1406 str = msi_alloc(sz * sizeof(WCHAR));
1407 r = MSI_GetPropertyW(package, prop, str, &sz);
1408 if (r != ERROR_SUCCESS)
1410 msi_free(str);
1411 str = NULL;
1414 return str;
1417 int msi_get_property_int(MSIPACKAGE *package, LPCWSTR prop, int def)
1419 LPWSTR str = msi_dup_property(package, prop);
1420 int val = str ? atoiW(str) : def;
1421 msi_free(str);
1422 return val;
1425 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1426 awstring *szValueBuf, LPDWORD pchValueBuf )
1428 static const WCHAR empty[] = {0};
1429 MSIPACKAGE *package;
1430 MSIRECORD *row = NULL;
1431 UINT r = ERROR_FUNCTION_FAILED;
1432 LPCWSTR val = NULL;
1434 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1435 szValueBuf->str.w, pchValueBuf );
1437 if (!name)
1438 return ERROR_INVALID_PARAMETER;
1440 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1441 if (!package)
1443 HRESULT hr;
1444 IWineMsiRemotePackage *remote_package;
1445 LPWSTR value = NULL;
1446 BSTR bname;
1447 DWORD len;
1449 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
1450 if (!remote_package)
1451 return ERROR_INVALID_HANDLE;
1453 bname = SysAllocString( name );
1454 if (!bname)
1456 IWineMsiRemotePackage_Release( remote_package );
1457 return ERROR_OUTOFMEMORY;
1460 len = 0;
1461 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
1462 if (FAILED(hr))
1463 goto done;
1465 len++;
1466 value = msi_alloc(len * sizeof(WCHAR));
1467 if (!value)
1469 r = ERROR_OUTOFMEMORY;
1470 goto done;
1473 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
1474 if (FAILED(hr))
1475 goto done;
1477 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
1479 /* Bug required by Adobe installers */
1480 if (!szValueBuf->unicode && !szValueBuf->str.a)
1481 *pchValueBuf *= sizeof(WCHAR);
1483 done:
1484 IWineMsiRemotePackage_Release(remote_package);
1485 SysFreeString(bname);
1486 msi_free(value);
1488 if (FAILED(hr))
1490 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1491 return HRESULT_CODE(hr);
1493 return ERROR_FUNCTION_FAILED;
1496 return r;
1499 row = MSI_GetPropertyRow( package, name );
1500 if (row)
1501 val = MSI_RecordGetString( row, 1 );
1503 if (!val)
1504 val = empty;
1506 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1508 if (row)
1509 msiobj_release( &row->hdr );
1510 msiobj_release( &package->hdr );
1512 return r;
1515 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1516 LPSTR szValueBuf, LPDWORD pchValueBuf )
1518 awstring val;
1519 LPWSTR name;
1520 UINT r;
1522 val.unicode = FALSE;
1523 val.str.a = szValueBuf;
1525 name = strdupAtoW( szName );
1526 if (szName && !name)
1527 return ERROR_OUTOFMEMORY;
1529 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1530 msi_free( name );
1531 return r;
1534 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1535 LPWSTR szValueBuf, LPDWORD pchValueBuf )
1537 awstring val;
1539 val.unicode = TRUE;
1540 val.str.w = szValueBuf;
1542 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
1545 typedef struct _msi_remote_package_impl {
1546 const IWineMsiRemotePackageVtbl *lpVtbl;
1547 MSIHANDLE package;
1548 LONG refs;
1549 } msi_remote_package_impl;
1551 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
1553 return (msi_remote_package_impl*) iface;
1556 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
1557 REFIID riid,LPVOID *ppobj)
1559 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1560 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
1562 IUnknown_AddRef( iface );
1563 *ppobj = iface;
1564 return S_OK;
1567 return E_NOINTERFACE;
1570 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
1572 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1574 return InterlockedIncrement( &This->refs );
1577 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
1579 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1580 ULONG r;
1582 r = InterlockedDecrement( &This->refs );
1583 if (r == 0)
1585 MsiCloseHandle( This->package );
1586 msi_free( This );
1588 return r;
1591 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
1593 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1594 This->package = handle;
1595 return S_OK;
1598 HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
1600 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1601 *handle = MsiGetActiveDatabase(This->package);
1602 return S_OK;
1605 HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
1607 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1608 UINT r;
1610 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
1611 if (r != ERROR_SUCCESS)
1612 return HRESULT_FROM_WIN32(r);
1614 return S_OK;
1617 HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
1619 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1620 UINT r = MsiSetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value);
1621 return HRESULT_FROM_WIN32(r);
1624 HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
1626 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1627 UINT r = MsiProcessMessage(This->package, message, record);
1628 return HRESULT_FROM_WIN32(r);
1631 HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
1633 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1634 UINT r = MsiDoActionW(This->package, (LPWSTR)action);
1635 return HRESULT_FROM_WIN32(r);
1638 HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
1640 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1641 UINT r = MsiSequenceW(This->package, (LPWSTR)table, sequence);
1642 return HRESULT_FROM_WIN32(r);
1645 HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1647 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1648 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1649 return HRESULT_FROM_WIN32(r);
1652 HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
1654 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1655 UINT r = MsiSetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value);
1656 return HRESULT_FROM_WIN32(r);
1659 HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1661 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1662 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1663 return HRESULT_FROM_WIN32(r);
1666 HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
1668 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1669 *ret = MsiGetMode(This->package, mode);
1670 return S_OK;
1673 HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
1674 INSTALLSTATE *installed, INSTALLSTATE *action )
1676 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1677 UINT r = MsiGetFeatureStateW(This->package, (LPWSTR)feature, installed, action);
1678 return HRESULT_FROM_WIN32(r);
1681 HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
1683 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1684 UINT r = MsiSetFeatureStateW(This->package, (LPWSTR)feature, state);
1685 return HRESULT_FROM_WIN32(r);
1688 HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
1689 INSTALLSTATE *installed, INSTALLSTATE *action )
1691 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1692 UINT r = MsiGetComponentStateW(This->package, (LPWSTR)component, installed, action);
1693 return HRESULT_FROM_WIN32(r);
1696 HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
1698 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1699 UINT r = MsiSetComponentStateW(This->package, (LPWSTR)component, state);
1700 return HRESULT_FROM_WIN32(r);
1703 HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
1705 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1706 *language = MsiGetLanguage(This->package);
1707 return S_OK;
1710 HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
1712 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1713 UINT r = MsiSetInstallLevel(This->package, level);
1714 return HRESULT_FROM_WIN32(r);
1717 HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
1718 BSTR value, DWORD *size )
1720 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1721 UINT r = MsiFormatRecordW(This->package, record, (LPWSTR)value, size);
1722 return HRESULT_FROM_WIN32(r);
1725 HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
1727 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1728 UINT r = MsiEvaluateConditionW(This->package, (LPWSTR)condition);
1729 return HRESULT_FROM_WIN32(r);
1732 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
1734 mrp_QueryInterface,
1735 mrp_AddRef,
1736 mrp_Release,
1737 mrp_SetMsiHandle,
1738 mrp_GetActiveDatabase,
1739 mrp_GetProperty,
1740 mrp_SetProperty,
1741 mrp_ProcessMessage,
1742 mrp_DoAction,
1743 mrp_Sequence,
1744 mrp_GetTargetPath,
1745 mrp_SetTargetPath,
1746 mrp_GetSourcePath,
1747 mrp_GetMode,
1748 mrp_GetFeatureState,
1749 mrp_SetFeatureState,
1750 mrp_GetComponentState,
1751 mrp_SetComponentState,
1752 mrp_GetLanguage,
1753 mrp_SetInstallLevel,
1754 mrp_FormatRecord,
1755 mrp_EvaluateCondition,
1758 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
1760 msi_remote_package_impl* This;
1762 This = msi_alloc( sizeof *This );
1763 if (!This)
1764 return E_OUTOFMEMORY;
1766 This->lpVtbl = &msi_remote_package_vtbl;
1767 This->package = 0;
1768 This->refs = 1;
1770 *ppObj = This;
1772 return S_OK;
1775 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
1776 LPCWSTR property, LPWSTR value)
1778 MSISOURCELISTINFO *info;
1780 info = msi_alloc(sizeof(MSISOURCELISTINFO));
1781 if (!info)
1782 return ERROR_OUTOFMEMORY;
1784 info->context = context;
1785 info->options = options;
1786 info->property = property;
1787 info->value = strdupW(value);
1788 list_add_head(&package->sourcelist_info, &info->entry);
1790 return ERROR_SUCCESS;
1793 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
1794 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
1796 MSIMEDIADISK *disk;
1798 disk = msi_alloc(sizeof(MSIMEDIADISK));
1799 if (!disk)
1800 return ERROR_OUTOFMEMORY;
1802 disk->context = context;
1803 disk->options = options;
1804 disk->disk_id = disk_id;
1805 disk->volume_label = strdupW(volume_label);
1806 disk->disk_prompt = strdupW(disk_prompt);
1807 list_add_head(&package->sourcelist_media, &disk->entry);
1809 return ERROR_SUCCESS;