msi: Handle remote calls to MsiGetLanguage.
[wine/multimedia.git] / dlls / msi / package.c
blob8038dd14f85e67c1e647782048801fafb033f8a2
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 clone_properties(MSIPACKAGE *package)
65 MSIQUERY * view = NULL;
66 UINT rc;
67 static const WCHAR CreateSql[] = {
68 'C','R','E','A','T','E',' ','T','A','B','L','E',' ','`','_','P','r','o',
69 'p','e','r','t','y','`',' ','(',' ','`','_','P','r','o','p','e','r','t',
70 'y','`',' ','C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U',
71 'L','L',' ','T','E','M','P','O','R','A','R','Y',',',' ','`','V','a','l',
72 'u','e','`',' ','C','H','A','R','(','9','8',')',' ','N','O','T',' ','N',
73 'U','L','L',' ','T','E','M','P','O','R','A','R','Y',' ','P','R','I','M',
74 'A','R','Y',' ','K','E','Y',' ','`','_','P','r','o','p','e','r','t','y',
75 '`',')',0};
76 static const WCHAR Query[] = {
77 'S','E','L','E','C','T',' ','*',' ',
78 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
79 static const WCHAR Insert[] = {
80 'I','N','S','E','R','T',' ','i','n','t','o',' ',
81 '`','_','P','r','o','p','e','r','t','y','`',' ',
82 '(','`','_','P','r','o','p','e','r','t','y','`',',',
83 '`','V','a','l','u','e','`',')',' ',
84 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
86 /* create the temporary properties table */
87 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
88 if (rc != ERROR_SUCCESS)
89 return rc;
91 rc = MSI_ViewExecute(view, 0);
92 MSI_ViewClose(view);
93 msiobj_release(&view->hdr);
94 if (rc != ERROR_SUCCESS)
95 return rc;
97 /* clone the existing properties */
98 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
99 if (rc != ERROR_SUCCESS)
100 return rc;
102 rc = MSI_ViewExecute(view, 0);
103 if (rc != ERROR_SUCCESS)
105 MSI_ViewClose(view);
106 msiobj_release(&view->hdr);
107 return rc;
110 while (1)
112 MSIRECORD *row;
113 MSIQUERY *view2;
115 rc = MSI_ViewFetch(view, &row);
116 if (rc != ERROR_SUCCESS)
117 break;
119 rc = MSI_DatabaseOpenViewW(package->db, Insert, &view2);
120 if (rc!= ERROR_SUCCESS)
121 continue;
123 rc = MSI_ViewExecute(view2, row);
124 MSI_ViewClose(view2);
125 msiobj_release(&view2->hdr);
127 if (rc == ERROR_SUCCESS)
128 msiobj_release(&row->hdr);
131 MSI_ViewClose(view);
132 msiobj_release(&view->hdr);
134 return rc;
138 * set_installed_prop
140 * Sets the "Installed" property to indicate that
141 * the product is installed for the current user.
143 static UINT set_installed_prop( MSIPACKAGE *package )
145 static const WCHAR szInstalled[] = {
146 'I','n','s','t','a','l','l','e','d',0 };
147 WCHAR val[2] = { '1', 0 };
148 HKEY hkey = 0;
149 UINT r;
151 r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
152 if (r == ERROR_SUCCESS)
154 RegCloseKey( hkey );
155 MSI_SetPropertyW( package, szInstalled, val );
158 return r;
161 static UINT set_user_sid_prop( MSIPACKAGE *package )
163 SID_NAME_USE use;
164 LPWSTR user_name;
165 LPWSTR sid_str = NULL, dom = NULL;
166 DWORD size, dom_size;
167 PSID psid = NULL;
168 UINT r = ERROR_FUNCTION_FAILED;
170 static const WCHAR user_sid[] = {'U','s','e','r','S','I','D',0};
172 size = 0;
173 GetUserNameW( NULL, &size );
175 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
176 if (!user_name)
177 return ERROR_OUTOFMEMORY;
179 if (!GetUserNameW( user_name, &size ))
180 goto done;
182 size = 0;
183 dom_size = 0;
184 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
186 psid = msi_alloc( size );
187 dom = msi_alloc( dom_size*sizeof (WCHAR) );
188 if (!psid || !dom)
190 r = ERROR_OUTOFMEMORY;
191 goto done;
194 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
195 goto done;
197 if (!ConvertSidToStringSidW( psid, &sid_str ))
198 goto done;
200 r = MSI_SetPropertyW( package, user_sid, sid_str );
202 done:
203 LocalFree( sid_str );
204 msi_free( dom );
205 msi_free( psid );
206 msi_free( user_name );
208 return r;
211 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
213 HKEY netsetup;
214 LONG res;
215 LPWSTR file;
216 DWORD index = 0, size;
217 WCHAR ver[MAX_PATH];
218 WCHAR name[MAX_PATH];
219 WCHAR windir[MAX_PATH];
221 static const WCHAR backslash[] = {'\\',0};
222 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
223 static const WCHAR sub[] = {
224 'S','o','f','t','w','a','r','e','\\',
225 'M','i','c','r','o','s','o','f','t','\\',
226 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
227 'N','D','P',0
229 static const WCHAR subdir[] = {
230 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
231 'F','r','a','m','e','w','o','r','k','\\',0
234 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
235 if (res != ERROR_SUCCESS)
236 return NULL;
238 ver[0] = '\0';
239 size = MAX_PATH;
240 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
242 index++;
243 if (lstrcmpW(ver, name) < 0)
244 lstrcpyW(ver, name);
247 RegCloseKey(netsetup);
249 if (!index)
250 return NULL;
252 GetWindowsDirectoryW(windir, MAX_PATH);
254 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(ver) +lstrlenW(fusion) + 3;
255 file = msi_alloc(size * sizeof(WCHAR));
256 if (!file)
257 return NULL;
259 lstrcpyW(file, windir);
260 lstrcatW(file, backslash);
261 lstrcatW(file, subdir);
262 lstrcatW(file, ver);
263 lstrcatW(file, backslash);
264 lstrcatW(file, fusion);
266 return file;
269 typedef struct tagLANGANDCODEPAGE
271 WORD wLanguage;
272 WORD wCodePage;
273 } LANGANDCODEPAGE;
275 static void set_msi_assembly_prop(MSIPACKAGE *package)
277 UINT val_len;
278 DWORD size, handle;
279 LPVOID version = NULL;
280 WCHAR buf[MAX_PATH];
281 LPWSTR fusion, verstr;
282 LANGANDCODEPAGE *translate;
284 static const WCHAR netasm[] = {
285 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
287 static const WCHAR translation[] = {
288 '\\','V','a','r','F','i','l','e','I','n','f','o',
289 '\\','T','r','a','n','s','l','a','t','i','o','n',0
291 static const WCHAR verfmt[] = {
292 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
293 '\\','%','0','4','x','%','0','4','x',
294 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
297 fusion = get_fusion_filename(package);
298 if (!fusion)
299 return;
301 size = GetFileVersionInfoSizeW(fusion, &handle);
302 if (!size) return;
304 version = msi_alloc(size);
305 if (!version) return;
307 if (!GetFileVersionInfoW(fusion, handle, size, version))
308 goto done;
310 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
311 goto done;
313 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
315 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
316 goto done;
318 if (!val_len || !verstr)
319 goto done;
321 MSI_SetPropertyW(package, netasm, verstr);
323 done:
324 msi_free(fusion);
325 msi_free(version);
329 * There are a whole slew of these we need to set
332 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
334 static VOID set_installer_properties(MSIPACKAGE *package)
336 WCHAR pth[MAX_PATH];
337 WCHAR *ptr;
338 OSVERSIONINFOEXW OSVersion;
339 MEMORYSTATUSEX msex;
340 DWORD verval;
341 WCHAR verstr[10], bufstr[20];
342 HDC dc;
343 LPWSTR check;
344 HKEY hkey;
345 LONG res;
346 SYSTEM_INFO sys_info;
347 SYSTEMTIME systemtime;
349 static const WCHAR cszbs[]={'\\',0};
350 static const WCHAR CFF[] =
351 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
352 static const WCHAR PFF[] =
353 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
354 static const WCHAR CADF[] =
355 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
356 static const WCHAR FaF[] =
357 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
358 static const WCHAR FoF[] =
359 {'F','o','n','t','s','F','o','l','d','e','r',0};
360 static const WCHAR SendTF[] =
361 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
362 static const WCHAR SMF[] =
363 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
364 static const WCHAR StF[] =
365 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
366 static const WCHAR TemplF[] =
367 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
368 static const WCHAR DF[] =
369 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
370 static const WCHAR PMF[] =
371 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
372 static const WCHAR ATF[] =
373 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
374 static const WCHAR ADF[] =
375 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
376 static const WCHAR SF[] =
377 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
378 static const WCHAR SF16[] =
379 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
380 static const WCHAR LADF[] =
381 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
382 static const WCHAR MPF[] =
383 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
384 static const WCHAR PF[] =
385 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
386 static const WCHAR WF[] =
387 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
388 static const WCHAR WV[] =
389 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
390 static const WCHAR TF[]=
391 {'T','e','m','p','F','o','l','d','e','r',0};
392 static const WCHAR szAdminUser[] =
393 {'A','d','m','i','n','U','s','e','r',0};
394 static const WCHAR szPriv[] =
395 {'P','r','i','v','i','l','e','g','e','d',0};
396 static const WCHAR szOne[] =
397 {'1',0};
398 static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
399 static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
400 static const WCHAR szMsiNTProductType[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
401 static const WCHAR szFormat[] = {'%','l','i',0};
402 static const WCHAR szWinBuild[] =
403 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
404 static const WCHAR szSPL[] =
405 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
406 static const WCHAR szSix[] = {'6',0 };
408 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
409 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
410 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
411 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
412 /* Screen properties */
413 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
414 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
415 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
416 static const WCHAR szScreenFormat[] = {'%','d',0};
417 static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
418 static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
419 static const WCHAR szCurrentVersion[] = {
420 'S','O','F','T','W','A','R','E','\\',
421 'M','i','c','r','o','s','o','f','t','\\',
422 'W','i','n','d','o','w','s',' ','N','T','\\',
423 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
425 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
426 static const WCHAR szRegisteredOrg[] = {
427 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
429 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
430 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
431 static const WCHAR szDate[] = {'D','a','t','e',0};
432 static const WCHAR szTime[] = {'T','i','m','e',0};
435 * Other things that probably should be set:
437 * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
438 * ShellAdvSupport DefaultUIFont PackagecodeChanging
439 * ProductState CaptionHeight BorderTop BorderSide TextHeight
440 * RedirectedDllSupport
443 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
444 strcatW(pth,cszbs);
445 MSI_SetPropertyW(package, CFF, pth);
447 SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
448 strcatW(pth,cszbs);
449 MSI_SetPropertyW(package, PFF, pth);
451 SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
452 strcatW(pth,cszbs);
453 MSI_SetPropertyW(package, CADF, pth);
455 SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
456 strcatW(pth,cszbs);
457 MSI_SetPropertyW(package, FaF, pth);
459 SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
460 strcatW(pth,cszbs);
461 MSI_SetPropertyW(package, FoF, pth);
463 SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
464 strcatW(pth,cszbs);
465 MSI_SetPropertyW(package, SendTF, pth);
467 SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
468 strcatW(pth,cszbs);
469 MSI_SetPropertyW(package, SMF, pth);
471 SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
472 strcatW(pth,cszbs);
473 MSI_SetPropertyW(package, StF, pth);
475 SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
476 strcatW(pth,cszbs);
477 MSI_SetPropertyW(package, TemplF, pth);
479 SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
480 strcatW(pth,cszbs);
481 MSI_SetPropertyW(package, DF, pth);
483 SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
484 strcatW(pth,cszbs);
485 MSI_SetPropertyW(package, PMF, pth);
487 SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
488 strcatW(pth,cszbs);
489 MSI_SetPropertyW(package, ATF, pth);
491 SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
492 strcatW(pth,cszbs);
493 MSI_SetPropertyW(package, ADF, pth);
495 SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
496 strcatW(pth,cszbs);
497 MSI_SetPropertyW(package, SF, pth);
498 MSI_SetPropertyW(package, SF16, pth);
500 SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
501 strcatW(pth,cszbs);
502 MSI_SetPropertyW(package, LADF, pth);
504 SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
505 strcatW(pth,cszbs);
506 MSI_SetPropertyW(package, MPF, pth);
508 SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
509 strcatW(pth,cszbs);
510 MSI_SetPropertyW(package, PF, pth);
512 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
513 strcatW(pth,cszbs);
514 MSI_SetPropertyW(package, WF, pth);
516 /* Physical Memory is specified in MB. Using total amount. */
517 msex.dwLength = sizeof(msex);
518 GlobalMemoryStatusEx( &msex );
519 sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
520 MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
522 SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
523 ptr = strchrW(pth,'\\');
524 if (ptr)
525 *(ptr+1) = 0;
526 MSI_SetPropertyW(package, WV, pth);
528 GetTempPathW(MAX_PATH,pth);
529 MSI_SetPropertyW(package, TF, pth);
532 /* in a wine environment the user is always admin and privileged */
533 MSI_SetPropertyW(package,szAdminUser,szOne);
534 MSI_SetPropertyW(package,szPriv,szOne);
535 MSI_SetPropertyW(package, szAllUsers, szOne);
537 /* set the os things */
538 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
539 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
540 verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
541 sprintfW(verstr,szFormat,verval);
542 switch (OSVersion.dwPlatformId)
544 case VER_PLATFORM_WIN32_WINDOWS:
545 MSI_SetPropertyW(package,v9x,verstr);
546 break;
547 case VER_PLATFORM_WIN32_NT:
548 MSI_SetPropertyW(package,vNT,verstr);
549 sprintfW(verstr,szFormat,OSVersion.wProductType);
550 MSI_SetPropertyW(package,szMsiNTProductType,verstr);
551 break;
553 sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
554 MSI_SetPropertyW(package,szWinBuild,verstr);
555 /* just fudge this */
556 MSI_SetPropertyW(package,szSPL,szSix);
558 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
559 MSI_SetPropertyW( package, szVersionMsi, bufstr );
560 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
561 MSI_SetPropertyW( package, szVersionDatabase, bufstr );
563 GetSystemInfo( &sys_info );
564 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
566 sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
567 MSI_SetPropertyW( package, szIntel, bufstr );
570 /* Screen properties. */
571 dc = GetDC(0);
572 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
573 MSI_SetPropertyW( package, szScreenX, bufstr );
574 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
575 MSI_SetPropertyW( package, szScreenY, bufstr );
576 sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
577 MSI_SetPropertyW( package, szColorBits, bufstr );
578 ReleaseDC(0, dc);
580 /* USERNAME and COMPANYNAME */
581 res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
582 if (res != ERROR_SUCCESS)
583 return;
585 check = msi_dup_property( package, szUSERNAME );
586 if (!check)
588 LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
589 MSI_SetPropertyW( package, szUSERNAME, user );
590 msi_free( user );
593 msi_free( check );
595 check = msi_dup_property( package, szCOMPANYNAME );
596 if (!check)
598 LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
599 MSI_SetPropertyW( package, szCOMPANYNAME, company );
600 msi_free( company );
603 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
604 ERR("Failed to set the UserSID property\n");
606 /* Date and time properties */
607 GetSystemTime( &systemtime );
608 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
609 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
610 MSI_SetPropertyW( package, szDate, bufstr );
611 else
612 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
614 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
615 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
616 &systemtime, NULL, bufstr,
617 sizeof(bufstr)/sizeof(bufstr[0]) ))
618 MSI_SetPropertyW( package, szTime, bufstr );
619 else
620 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
622 set_msi_assembly_prop( package );
624 msi_free( check );
625 CloseHandle( hkey );
628 static UINT msi_load_summary_properties( MSIPACKAGE *package )
630 UINT rc;
631 MSIHANDLE suminfo;
632 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
633 INT word_count;
634 DWORD len;
635 LPWSTR package_code;
636 static const WCHAR szPackageCode[] = {
637 'P','a','c','k','a','g','e','C','o','d','e',0};
639 if (!hdb) {
640 ERR("Unable to allocate handle\n");
641 return 0;
643 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
644 MsiCloseHandle(hdb);
645 if (rc != ERROR_SUCCESS)
647 ERR("Unable to open Summary Information\n");
648 return rc;
651 /* load package attributes */
652 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
653 &word_count, NULL, NULL, NULL );
654 if (rc == ERROR_SUCCESS)
655 package->WordCount = word_count;
656 else
657 WARN("Unable to query word count\n");
659 /* load package code property */
660 len = 0;
661 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
662 NULL, NULL, NULL, &len );
663 if (rc == ERROR_MORE_DATA)
665 len++;
666 package_code = msi_alloc( len * sizeof(WCHAR) );
667 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
668 NULL, NULL, package_code, &len );
669 if (rc == ERROR_SUCCESS)
670 MSI_SetPropertyW( package, szPackageCode, package_code );
671 else
672 WARN("Unable to query rev number, %d\n", rc);
673 msi_free( package_code );
675 else
676 WARN("Unable to query rev number, %d\n", rc);
678 MsiCloseHandle(suminfo);
679 return ERROR_SUCCESS;
682 static MSIPACKAGE *msi_alloc_package( void )
684 MSIPACKAGE *package;
686 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
687 MSI_FreePackage );
688 if( package )
690 list_init( &package->components );
691 list_init( &package->features );
692 list_init( &package->files );
693 list_init( &package->tempfiles );
694 list_init( &package->folders );
695 list_init( &package->subscriptions );
696 list_init( &package->appids );
697 list_init( &package->classes );
698 list_init( &package->mimes );
699 list_init( &package->extensions );
700 list_init( &package->progids );
701 list_init( &package->RunningActions );
702 list_init( &package->sourcelist_info );
703 list_init( &package->sourcelist_media );
705 package->ActionFormat = NULL;
706 package->LastAction = NULL;
707 package->dialog = NULL;
708 package->next_dialog = NULL;
709 package->scheduled_action_running = FALSE;
710 package->commit_action_running = FALSE;
711 package->rollback_action_running = FALSE;
714 return package;
717 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
719 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
720 static const WCHAR szpi[] = {'%','i',0};
721 static const WCHAR szProductCode[] = {
722 'P','r','o','d','u','c','t','C','o','d','e',0};
723 MSIPACKAGE *package;
724 WCHAR uilevel[10];
726 TRACE("%p\n", db);
728 package = msi_alloc_package();
729 if (package)
731 msiobj_addref( &db->hdr );
732 package->db = db;
734 package->WordCount = 0;
735 package->PackagePath = strdupW( db->path );
736 package->BaseURL = strdupW( base_url );
738 clone_properties( package );
739 set_installer_properties(package);
740 sprintfW(uilevel,szpi,gUILevel);
741 MSI_SetPropertyW(package, szLevel, uilevel);
743 package->ProductCode = msi_dup_property( package, szProductCode );
744 set_installed_prop( package );
745 msi_load_summary_properties( package );
748 return package;
752 * copy_package_to_temp [internal]
754 * copy the msi file to a temp file to prevent locking a CD
755 * with a multi disc install
757 * FIXME: I think this is wrong, and instead of copying the package,
758 * we should read all the tables to memory, then open the
759 * database to read binary streams on demand.
761 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
763 WCHAR path[MAX_PATH];
764 static const WCHAR szMSI[] = {'m','s','i',0};
766 GetTempPathW( MAX_PATH, path );
767 GetTempFileNameW( path, szMSI, 0, filename );
769 if( !CopyFileW( szPackage, filename, FALSE ) )
771 DeleteFileW( filename );
772 ERR("failed to copy package %s\n", debugstr_w(szPackage) );
773 return szPackage;
776 TRACE("Opening relocated package %s\n", debugstr_w( filename ));
777 return filename;
780 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
782 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
783 DWORD size = 0;
784 HRESULT hr;
786 /* call will always fail, becase size is 0,
787 * but will return ERROR_FILE_NOT_FOUND first
788 * if the file doesn't exist
790 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
791 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
793 cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
794 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
796 HeapFree( GetProcessHeap(), 0, cache_entry );
797 return szUrl;
800 lstrcpyW( filename, cache_entry->lpszLocalFileName );
801 HeapFree( GetProcessHeap(), 0, cache_entry );
802 return filename;
805 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
806 if ( FAILED(hr) )
807 return szUrl;
809 return filename;
812 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
814 static const WCHAR OriginalDatabase[] =
815 {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
816 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
817 MSIDATABASE *db = NULL;
818 MSIPACKAGE *package;
819 MSIHANDLE handle;
820 LPWSTR ptr, base_url = NULL;
821 UINT r;
822 WCHAR temppath[MAX_PATH];
823 LPCWSTR file = szPackage;
825 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
827 if( szPackage[0] == '#' )
829 handle = atoiW(&szPackage[1]);
830 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
831 if( !db )
832 return ERROR_INVALID_HANDLE;
834 else
836 if ( UrlIsW( szPackage, URLIS_URL ) )
838 file = msi_download_file( szPackage, temppath );
840 base_url = strdupW( szPackage );
841 if ( !base_url )
842 return ERROR_OUTOFMEMORY;
844 ptr = strrchrW( base_url, '/' );
845 if (ptr) *(ptr + 1) = '\0';
847 else
848 file = copy_package_to_temp( szPackage, temppath );
850 r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
851 if( r != ERROR_SUCCESS )
853 if (GetLastError() == ERROR_FILE_NOT_FOUND)
854 msi_ui_error( 4, MB_OK | MB_ICONWARNING );
855 if (file != szPackage)
856 DeleteFileW( file );
858 return r;
862 package = MSI_CreatePackage( db, base_url );
863 msi_free( base_url );
864 msiobj_release( &db->hdr );
865 if( !package )
867 if (file != szPackage)
868 DeleteFileW( file );
869 return ERROR_FUNCTION_FAILED;
872 if( file != szPackage )
873 track_tempfile( package, file );
875 if( szPackage[0] != '#' )
877 MSI_SetPropertyW( package, OriginalDatabase, szPackage );
878 MSI_SetPropertyW( package, Database, szPackage );
880 else
882 MSI_SetPropertyW( package, OriginalDatabase, db->path );
883 MSI_SetPropertyW( package, Database, db->path );
886 *pPackage = package;
888 return ERROR_SUCCESS;
891 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
893 MSIPACKAGE *package = NULL;
894 UINT ret;
896 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
898 if( szPackage == NULL )
899 return ERROR_INVALID_PARAMETER;
901 if( dwOptions )
902 FIXME("dwOptions %08x not supported\n", dwOptions);
904 ret = MSI_OpenPackageW( szPackage, &package );
905 if( ret == ERROR_SUCCESS )
907 *phPackage = alloc_msihandle( &package->hdr );
908 if (! *phPackage)
909 ret = ERROR_NOT_ENOUGH_MEMORY;
910 msiobj_release( &package->hdr );
913 return ret;
916 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
918 return MsiOpenPackageExW( szPackage, 0, phPackage );
921 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
923 LPWSTR szwPack = NULL;
924 UINT ret;
926 if( szPackage )
928 szwPack = strdupAtoW( szPackage );
929 if( !szwPack )
930 return ERROR_OUTOFMEMORY;
933 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
935 msi_free( szwPack );
937 return ret;
940 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
942 return MsiOpenPackageExA( szPackage, 0, phPackage );
945 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
947 MSIPACKAGE *package;
948 MSIHANDLE handle = 0;
949 IWineMsiRemotePackage *remote_package;
951 TRACE("(%ld)\n",hInstall);
953 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
954 if( package)
956 handle = alloc_msihandle( &package->db->hdr );
957 msiobj_release( &package->hdr );
959 else if ((remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall )))
961 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
962 IWineMsiRemotePackage_Release(remote_package);
965 return handle;
968 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
969 MSIRECORD *record)
971 static const WCHAR szActionData[] =
972 {'A','c','t','i','o','n','D','a','t','a',0};
973 static const WCHAR szSetProgress[] =
974 {'S','e','t','P','r','o','g','r','e','s','s',0};
975 static const WCHAR szActionText[] =
976 {'A','c','t','i','o','n','T','e','x','t',0};
977 DWORD log_type = 0;
978 LPWSTR message;
979 DWORD sz;
980 DWORD total_size = 0;
981 INT i;
982 INT rc;
983 char *msg;
984 int len;
986 TRACE("%x\n", eMessageType);
987 rc = 0;
989 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
990 log_type |= INSTALLLOGMODE_ERROR;
991 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
992 log_type |= INSTALLLOGMODE_WARNING;
993 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
994 log_type |= INSTALLLOGMODE_USER;
995 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
996 log_type |= INSTALLLOGMODE_INFO;
997 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
998 log_type |= INSTALLLOGMODE_COMMONDATA;
999 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1000 log_type |= INSTALLLOGMODE_ACTIONSTART;
1001 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1002 log_type |= INSTALLLOGMODE_ACTIONDATA;
1003 /* just a guess */
1004 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1005 log_type |= 0x800;
1007 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1009 static const WCHAR template_s[]=
1010 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1011 static const WCHAR format[] =
1012 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1013 WCHAR timet[0x100];
1014 LPCWSTR action_text, action;
1015 LPWSTR deformatted = NULL;
1017 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1019 action = MSI_RecordGetString(record, 1);
1020 action_text = MSI_RecordGetString(record, 2);
1022 if (!action || !action_text)
1023 return IDOK;
1025 deformat_string(package, action_text, &deformatted);
1027 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1028 if (deformatted)
1029 len += strlenW(deformatted);
1030 message = msi_alloc(len*sizeof(WCHAR));
1031 sprintfW(message, template_s, timet, action);
1032 if (deformatted)
1033 strcatW(message, deformatted);
1034 msi_free(deformatted);
1036 else
1038 INT msg_field=1;
1039 message = msi_alloc(1*sizeof (WCHAR));
1040 message[0]=0;
1041 msg_field = MSI_RecordGetFieldCount(record);
1042 for (i = 1; i <= msg_field; i++)
1044 LPWSTR tmp;
1045 WCHAR number[3];
1046 static const WCHAR format[] = { '%','i',':',' ',0};
1047 static const WCHAR space[] = { ' ',0};
1048 sz = 0;
1049 MSI_RecordGetStringW(record,i,NULL,&sz);
1050 sz+=4;
1051 total_size+=sz*sizeof(WCHAR);
1052 tmp = msi_alloc(sz*sizeof(WCHAR));
1053 message = msi_realloc(message,total_size*sizeof (WCHAR));
1055 MSI_RecordGetStringW(record,i,tmp,&sz);
1057 if (msg_field > 1)
1059 sprintfW(number,format,i);
1060 strcatW(message,number);
1062 strcatW(message,tmp);
1063 if (msg_field > 1)
1064 strcatW(message,space);
1066 msi_free(tmp);
1070 TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
1071 debugstr_w(message));
1073 /* convert it to ASCII */
1074 len = WideCharToMultiByte( CP_ACP, 0, message, -1,
1075 NULL, 0, NULL, NULL );
1076 msg = msi_alloc( len );
1077 WideCharToMultiByte( CP_ACP, 0, message, -1,
1078 msg, len, NULL, NULL );
1080 if (gUIHandlerA && (gUIFilter & log_type))
1082 rc = gUIHandlerA(gUIContext,eMessageType,msg);
1085 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
1086 INSTALLMESSAGE_PROGRESS))
1088 DWORD write;
1089 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
1090 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1092 if (log_file != INVALID_HANDLE_VALUE)
1094 SetFilePointer(log_file,0, NULL, FILE_END);
1095 WriteFile(log_file,msg,strlen(msg),&write,NULL);
1096 WriteFile(log_file,"\n",1,&write,NULL);
1097 CloseHandle(log_file);
1100 msi_free( msg );
1102 msi_free( message);
1104 switch (eMessageType & 0xff000000)
1106 case INSTALLMESSAGE_ACTIONDATA:
1107 /* FIXME: format record here instead of in ui_actiondata to get the
1108 * correct action data for external scripts */
1109 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1110 break;
1111 case INSTALLMESSAGE_ACTIONSTART:
1113 MSIRECORD *uirow;
1114 LPWSTR deformated;
1115 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1117 deformat_string(package, action_text, &deformated);
1118 uirow = MSI_CreateRecord(1);
1119 MSI_RecordSetStringW(uirow, 1, deformated);
1120 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1121 msi_free(deformated);
1123 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1125 msiobj_release(&uirow->hdr);
1126 break;
1128 case INSTALLMESSAGE_PROGRESS:
1129 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1130 break;
1133 return ERROR_SUCCESS;
1136 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1137 MSIHANDLE hRecord)
1139 UINT ret = ERROR_INVALID_HANDLE;
1140 MSIPACKAGE *package = NULL;
1141 MSIRECORD *record = NULL;
1143 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1144 if( !package )
1146 HRESULT hr;
1147 IWineMsiRemotePackage *remote_package;
1149 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1150 if (!remote_package)
1151 return ERROR_INVALID_HANDLE;
1153 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1155 IWineMsiRemotePackage_Release( remote_package );
1157 if (FAILED(hr))
1159 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1160 return HRESULT_CODE(hr);
1162 return ERROR_FUNCTION_FAILED;
1165 return ERROR_SUCCESS;
1168 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1169 if( !record )
1170 goto out;
1172 ret = MSI_ProcessMessage( package, eMessageType, record );
1174 out:
1175 msiobj_release( &package->hdr );
1176 if( record )
1177 msiobj_release( &record->hdr );
1179 return ret;
1182 /* property code */
1184 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1186 LPWSTR szwName = NULL, szwValue = NULL;
1187 UINT r = ERROR_OUTOFMEMORY;
1189 szwName = strdupAtoW( szName );
1190 if( szName && !szwName )
1191 goto end;
1193 szwValue = strdupAtoW( szValue );
1194 if( szValue && !szwValue )
1195 goto end;
1197 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1199 end:
1200 msi_free( szwName );
1201 msi_free( szwValue );
1203 return r;
1206 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
1208 MSIQUERY *view;
1209 MSIRECORD *row = NULL;
1210 UINT rc;
1211 DWORD sz = 0;
1212 WCHAR Query[1024];
1214 static const WCHAR Insert[] = {
1215 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1216 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1217 '`','_','P','r','o','p','e','r','t','y','`',',',
1218 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1219 ,' ','(','?',',','?',')',0};
1220 static const WCHAR Update[] = {
1221 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1222 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1223 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1224 ' ','=',' ','\'','%','s','\'',0};
1225 static const WCHAR Delete[] = {
1226 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1227 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1228 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1230 TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
1232 if (!szName)
1233 return ERROR_INVALID_PARAMETER;
1235 /* this one is weird... */
1236 if (!szName[0])
1237 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1239 rc = MSI_GetPropertyW(package, szName, 0, &sz);
1240 if (!szValue || !*szValue)
1242 sprintfW(Query, Delete, szName);
1244 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1246 sprintfW(Query, Update, szName);
1248 row = MSI_CreateRecord(1);
1249 MSI_RecordSetStringW(row, 1, szValue);
1251 else
1253 strcpyW(Query, Insert);
1255 row = MSI_CreateRecord(2);
1256 MSI_RecordSetStringW(row, 1, szName);
1257 MSI_RecordSetStringW(row, 2, szValue);
1260 rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1261 if (rc == ERROR_SUCCESS)
1263 rc = MSI_ViewExecute(view, row);
1264 MSI_ViewClose(view);
1265 msiobj_release(&view->hdr);
1268 msiobj_release(&row->hdr);
1270 return rc;
1273 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1275 MSIPACKAGE *package;
1276 UINT ret;
1278 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1279 if( !package )
1281 HRESULT hr;
1282 IWineMsiRemotePackage *remote_package;
1284 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1285 if (!remote_package)
1286 return ERROR_INVALID_HANDLE;
1288 hr = IWineMsiRemotePackage_SetProperty( remote_package, (BSTR *)szName, (BSTR *)szValue );
1290 IWineMsiRemotePackage_Release(remote_package);
1292 if (FAILED(hr))
1294 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1295 return HRESULT_CODE(hr);
1297 return ERROR_FUNCTION_FAILED;
1300 return ERROR_SUCCESS;
1303 ret = MSI_SetPropertyW( package, szName, szValue);
1304 msiobj_release( &package->hdr );
1305 return ret;
1308 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
1310 static const WCHAR query[]= {
1311 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1312 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1313 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1314 '=','\'','%','s','\'',0};
1316 if (!name || !*name)
1317 return NULL;
1319 return MSI_QueryGetRecord( package->db, query, name );
1322 /* internal function, not compatible with MsiGetPropertyW */
1323 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName,
1324 LPWSTR szValueBuf, DWORD* pchValueBuf )
1326 MSIRECORD *row;
1327 UINT rc = ERROR_FUNCTION_FAILED;
1329 row = MSI_GetPropertyRow( package, szName );
1331 if (*pchValueBuf > 0)
1332 szValueBuf[0] = 0;
1334 if (row)
1336 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
1337 msiobj_release(&row->hdr);
1340 if (rc == ERROR_SUCCESS)
1341 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
1342 debugstr_w(szName));
1343 else if (rc == ERROR_MORE_DATA)
1344 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
1345 debugstr_w(szName));
1346 else
1348 *pchValueBuf = 0;
1349 TRACE("property %s not found\n", debugstr_w(szName));
1352 return rc;
1355 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
1357 DWORD sz = 0;
1358 LPWSTR str;
1359 UINT r;
1361 r = MSI_GetPropertyW(package, prop, NULL, &sz);
1362 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
1363 return NULL;
1365 sz++;
1366 str = msi_alloc(sz * sizeof(WCHAR));
1367 r = MSI_GetPropertyW(package, prop, str, &sz);
1368 if (r != ERROR_SUCCESS)
1370 msi_free(str);
1371 str = NULL;
1374 return str;
1377 int msi_get_property_int(MSIPACKAGE *package, LPCWSTR prop, int def)
1379 LPWSTR str = msi_dup_property(package, prop);
1380 int val = str ? atoiW(str) : def;
1381 msi_free(str);
1382 return val;
1385 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1386 awstring *szValueBuf, DWORD* pchValueBuf )
1388 static const WCHAR empty[] = {0};
1389 MSIPACKAGE *package;
1390 MSIRECORD *row = NULL;
1391 UINT r = ERROR_FUNCTION_FAILED;
1392 LPCWSTR val = NULL;
1394 TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1395 szValueBuf->str.w, pchValueBuf );
1397 if (!name)
1398 return ERROR_INVALID_PARAMETER;
1400 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1401 if (!package)
1403 HRESULT hr;
1404 IWineMsiRemotePackage *remote_package;
1405 LPWSTR value = NULL;
1406 DWORD len;
1408 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
1409 if (!remote_package)
1410 return ERROR_INVALID_HANDLE;
1412 len = 0;
1413 hr = IWineMsiRemotePackage_GetProperty( remote_package, (BSTR *)name, NULL, &len );
1414 if (FAILED(hr))
1415 goto done;
1417 len++;
1418 value = msi_alloc(len * sizeof(WCHAR));
1419 if (!value)
1421 r = ERROR_OUTOFMEMORY;
1422 goto done;
1425 hr = IWineMsiRemotePackage_GetProperty( remote_package, (BSTR *)name, (BSTR *)value, &len );
1426 if (FAILED(hr))
1427 goto done;
1429 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
1430 *pchValueBuf *= sizeof(WCHAR); /* Bug required by Adobe installers */
1432 done:
1433 IWineMsiRemotePackage_Release(remote_package);
1434 msi_free(value);
1436 if (FAILED(hr))
1438 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1439 return HRESULT_CODE(hr);
1441 return ERROR_FUNCTION_FAILED;
1444 return r;
1447 row = MSI_GetPropertyRow( package, name );
1448 if (row)
1449 val = MSI_RecordGetString( row, 1 );
1451 if (!val)
1452 val = empty;
1454 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1456 if (row)
1457 msiobj_release( &row->hdr );
1458 msiobj_release( &package->hdr );
1460 return r;
1463 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1464 LPSTR szValueBuf, DWORD* pchValueBuf )
1466 awstring val;
1467 LPWSTR name;
1468 UINT r;
1470 val.unicode = FALSE;
1471 val.str.a = szValueBuf;
1473 name = strdupAtoW( szName );
1474 if (szName && !name)
1475 return ERROR_OUTOFMEMORY;
1477 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1478 msi_free( name );
1479 return r;
1482 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1483 LPWSTR szValueBuf, DWORD* pchValueBuf )
1485 awstring val;
1487 val.unicode = TRUE;
1488 val.str.w = szValueBuf;
1490 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
1493 typedef struct _msi_remote_package_impl {
1494 const IWineMsiRemotePackageVtbl *lpVtbl;
1495 MSIHANDLE package;
1496 LONG refs;
1497 } msi_remote_package_impl;
1499 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
1501 return (msi_remote_package_impl*) iface;
1504 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
1505 REFIID riid,LPVOID *ppobj)
1507 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1508 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
1510 IUnknown_AddRef( iface );
1511 *ppobj = iface;
1512 return S_OK;
1515 return E_NOINTERFACE;
1518 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
1520 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1522 return InterlockedIncrement( &This->refs );
1525 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
1527 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1528 ULONG r;
1530 r = InterlockedDecrement( &This->refs );
1531 if (r == 0)
1533 MsiCloseHandle( This->package );
1534 msi_free( This );
1536 return r;
1539 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
1541 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1542 This->package = handle;
1543 return S_OK;
1546 HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
1548 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1549 *handle = MsiGetActiveDatabase(This->package);
1550 return S_OK;
1553 HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR *property, BSTR *value, DWORD *size )
1555 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1556 UINT r;
1558 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
1559 if (r != ERROR_SUCCESS)
1560 return HRESULT_FROM_WIN32(r);
1562 return S_OK;
1565 HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR *property, BSTR *value )
1567 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1568 UINT r = MsiSetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value);
1569 return HRESULT_FROM_WIN32(r);
1572 HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
1574 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1575 UINT r = MsiProcessMessage(This->package, message, record);
1576 return HRESULT_FROM_WIN32(r);
1579 HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR *action )
1581 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1582 UINT r = MsiDoActionW(This->package, (LPWSTR)action);
1583 return HRESULT_FROM_WIN32(r);
1586 HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR *table, int sequence )
1588 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1589 UINT r = MsiSequenceW(This->package, (LPWSTR)table, sequence);
1590 return HRESULT_FROM_WIN32(r);
1593 HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR *folder, BSTR *value, DWORD *size )
1595 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1596 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1597 return HRESULT_FROM_WIN32(r);
1600 HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR *folder, BSTR *value)
1602 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1603 UINT r = MsiSetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value);
1604 return HRESULT_FROM_WIN32(r);
1607 HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR *folder, BSTR *value, DWORD *size )
1609 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1610 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1611 return HRESULT_FROM_WIN32(r);
1614 HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
1616 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1617 *ret = MsiGetMode(This->package, mode);
1618 return S_OK;
1621 HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR *feature,
1622 INSTALLSTATE *installed, INSTALLSTATE *action )
1624 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1625 UINT r = MsiGetFeatureStateW(This->package, (LPWSTR)feature, installed, action);
1626 return HRESULT_FROM_WIN32(r);
1629 HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR *feature, INSTALLSTATE state )
1631 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1632 UINT r = MsiSetFeatureStateW(This->package, (LPWSTR)feature, state);
1633 return HRESULT_FROM_WIN32(r);
1636 HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR *component,
1637 INSTALLSTATE *installed, INSTALLSTATE *action )
1639 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1640 UINT r = MsiGetComponentStateW(This->package, (LPWSTR)component, installed, action);
1641 return HRESULT_FROM_WIN32(r);
1644 HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR *component, INSTALLSTATE state )
1646 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1647 UINT r = MsiSetFeatureStateW(This->package, (LPWSTR)component, state);
1648 return HRESULT_FROM_WIN32(r);
1651 HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
1653 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1654 *language = MsiGetLanguage(This->package);
1655 return S_OK;
1658 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
1660 mrp_QueryInterface,
1661 mrp_AddRef,
1662 mrp_Release,
1663 mrp_SetMsiHandle,
1664 mrp_GetActiveDatabase,
1665 mrp_GetProperty,
1666 mrp_SetProperty,
1667 mrp_ProcessMessage,
1668 mrp_DoAction,
1669 mrp_Sequence,
1670 mrp_GetTargetPath,
1671 mrp_SetTargetPath,
1672 mrp_GetSourcePath,
1673 mrp_GetMode,
1674 mrp_GetFeatureState,
1675 mrp_SetFeatureState,
1676 mrp_GetComponentState,
1677 mrp_SetComponentState,
1678 mrp_GetLanguage,
1681 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
1683 msi_remote_package_impl* This;
1685 This = msi_alloc( sizeof *This );
1686 if (!This)
1687 return E_OUTOFMEMORY;
1689 This->lpVtbl = &msi_remote_package_vtbl;
1690 This->package = 0;
1691 This->refs = 1;
1693 *ppObj = This;
1695 return S_OK;
1698 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
1699 LPCWSTR property, LPWSTR value)
1701 MSISOURCELISTINFO *info;
1703 info = msi_alloc(sizeof(MSISOURCELISTINFO));
1704 if (!info)
1705 return ERROR_OUTOFMEMORY;
1707 info->context = context;
1708 info->options = options;
1709 info->property = property;
1710 info->value = strdupW(value);
1711 list_add_head(&package->sourcelist_info, &info->entry);
1713 return ERROR_SUCCESS;
1716 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
1717 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
1719 MSIMEDIADISK *disk;
1721 disk = msi_alloc(sizeof(MSIMEDIADISK));
1722 if (!disk)
1723 return ERROR_OUTOFMEMORY;
1725 disk->context = context;
1726 disk->options = options;
1727 disk->disk_id = disk_id;
1728 disk->volume_label = strdupW(volume_label);
1729 disk->disk_prompt = strdupW(disk_prompt);
1730 list_add_head(&package->sourcelist_media, &disk->entry);
1732 return ERROR_SUCCESS;