urlmon: Don't create stgmed_obj for binding to object.
[wine] / dlls / msi / package.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2004 Aric Stewart for CodeWeavers
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
24
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"
46
47 #include "msipriv.h"
48 #include "msiserver.h"
49
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
51
52 static void MSI_FreePackage( MSIOBJECTHDR *arg)
53 {
54     MSIPACKAGE *package= (MSIPACKAGE*) arg;
55
56     if( package->dialog )
57         msi_dialog_destroy( package->dialog );
58
59     msiobj_release( &package->db->hdr );
60     ACTION_free_package_structures(package);
61 }
62
63 static UINT create_temp_property_table(MSIPACKAGE *package)
64 {
65     MSIQUERY *view = NULL;
66     UINT rc;
67
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};
77
78     rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
79     if (rc != ERROR_SUCCESS)
80         return rc;
81
82     rc = MSI_ViewExecute(view, 0);
83     MSI_ViewClose(view);
84     msiobj_release(&view->hdr);
85     return rc;
86 }
87
88 UINT msi_clone_properties(MSIPACKAGE *package)
89 {
90     MSIQUERY *view = NULL;
91     UINT rc;
92
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};
102
103     /* clone the existing properties */
104     rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
105     if (rc != ERROR_SUCCESS)
106         return rc;
107
108     rc = MSI_ViewExecute(view, 0);
109     if (rc != ERROR_SUCCESS)
110     {
111         MSI_ViewClose(view);
112         msiobj_release(&view->hdr);
113         return rc;
114     }
115
116     while (1)
117     {
118         MSIRECORD *row;
119         MSIQUERY *view2;
120
121         rc = MSI_ViewFetch(view, &row);
122         if (rc != ERROR_SUCCESS)
123             break;
124
125         rc = MSI_DatabaseOpenViewW(package->db, Insert, &view2);
126         if (rc != ERROR_SUCCESS)
127         {
128             msiobj_release(&row->hdr);
129             continue;
130         }
131
132         MSI_ViewExecute(view2, row);
133         MSI_ViewClose(view2);
134         msiobj_release(&view2->hdr);
135         msiobj_release(&row->hdr);
136     }
137
138     MSI_ViewClose(view);
139     msiobj_release(&view->hdr);
140
141     return rc;
142 }
143
144 /*
145  * set_installed_prop
146  *
147  * Sets the "Installed" property to indicate that
148  *  the product is installed for the current user.
149  */
150 static UINT set_installed_prop( MSIPACKAGE *package )
151 {
152     static const WCHAR szInstalled[] = {
153         'I','n','s','t','a','l','l','e','d',0 };
154     WCHAR val[2] = { '1', 0 };
155     HKEY hkey = 0;
156     UINT r;
157
158     r = MSIREG_OpenUninstallKey( package->ProductCode, &hkey, FALSE );
159     if (r == ERROR_SUCCESS)
160     {
161         RegCloseKey( hkey );
162         MSI_SetPropertyW( package, szInstalled, val );
163     }
164
165     return r;
166 }
167
168 static UINT set_user_sid_prop( MSIPACKAGE *package )
169 {
170     SID_NAME_USE use;
171     LPWSTR user_name;
172     LPWSTR sid_str = NULL, dom = NULL;
173     DWORD size, dom_size;
174     PSID psid = NULL;
175     UINT r = ERROR_FUNCTION_FAILED;
176
177     static const WCHAR user_sid[] = {'U','s','e','r','S','I','D',0};
178
179     size = 0;
180     GetUserNameW( NULL, &size );
181
182     user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
183     if (!user_name)
184         return ERROR_OUTOFMEMORY;
185
186     if (!GetUserNameW( user_name, &size ))
187         goto done;
188
189     size = 0;
190     dom_size = 0;
191     LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
192
193     psid = msi_alloc( size );
194     dom = msi_alloc( dom_size*sizeof (WCHAR) );
195     if (!psid || !dom)
196     {
197         r = ERROR_OUTOFMEMORY;
198         goto done;
199     }
200
201     if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
202         goto done;
203
204     if (!ConvertSidToStringSidW( psid, &sid_str ))
205         goto done;
206
207     r = MSI_SetPropertyW( package, user_sid, sid_str );
208
209 done:
210     LocalFree( sid_str );
211     msi_free( dom );
212     msi_free( psid );
213     msi_free( user_name );
214
215     return r;
216 }
217
218 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
219 {
220     HKEY netsetup;
221     LONG res;
222     LPWSTR file;
223     DWORD index = 0, size;
224     WCHAR ver[MAX_PATH];
225     WCHAR name[MAX_PATH];
226     WCHAR windir[MAX_PATH];
227
228     static const WCHAR backslash[] = {'\\',0};
229     static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
230     static const WCHAR sub[] = {
231         'S','o','f','t','w','a','r','e','\\',
232         'M','i','c','r','o','s','o','f','t','\\',
233         'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
234         'N','D','P',0
235     };
236     static const WCHAR subdir[] = {
237         'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
238         'F','r','a','m','e','w','o','r','k','\\',0
239     };
240
241     res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
242     if (res != ERROR_SUCCESS)
243         return NULL;
244
245     ver[0] = '\0';
246     size = MAX_PATH;
247     while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
248     {
249         index++;
250         if (lstrcmpW(ver, name) < 0)
251             lstrcpyW(ver, name);
252     }
253
254     RegCloseKey(netsetup);
255
256     if (!index)
257         return NULL;
258
259     GetWindowsDirectoryW(windir, MAX_PATH);
260
261     size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(ver) +lstrlenW(fusion) + 3;
262     file = msi_alloc(size * sizeof(WCHAR));
263     if (!file)
264         return NULL;
265
266     lstrcpyW(file, windir);
267     lstrcatW(file, backslash);
268     lstrcatW(file, subdir);
269     lstrcatW(file, ver);
270     lstrcatW(file, backslash);
271     lstrcatW(file, fusion);
272
273     return file;
274 }
275
276 typedef struct tagLANGANDCODEPAGE
277 {
278   WORD wLanguage;
279   WORD wCodePage;
280 } LANGANDCODEPAGE;
281
282 static void set_msi_assembly_prop(MSIPACKAGE *package)
283 {
284     UINT val_len;
285     DWORD size, handle;
286     LPVOID version = NULL;
287     WCHAR buf[MAX_PATH];
288     LPWSTR fusion, verstr;
289     LANGANDCODEPAGE *translate;
290
291     static const WCHAR netasm[] = {
292         'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
293     };
294     static const WCHAR translation[] = {
295         '\\','V','a','r','F','i','l','e','I','n','f','o',
296         '\\','T','r','a','n','s','l','a','t','i','o','n',0
297     };
298     static const WCHAR verfmt[] = {
299         '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
300         '\\','%','0','4','x','%','0','4','x',
301         '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
302     };
303
304     fusion = get_fusion_filename(package);
305     if (!fusion)
306         return;
307
308     size = GetFileVersionInfoSizeW(fusion, &handle);
309     if (!size) return;
310
311     version = msi_alloc(size);
312     if (!version) return;
313
314     if (!GetFileVersionInfoW(fusion, handle, size, version))
315         goto done;
316
317     if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
318         goto done;
319
320     sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
321
322     if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
323         goto done;
324
325     if (!val_len || !verstr)
326         goto done;
327
328     MSI_SetPropertyW(package, netasm, verstr);
329
330 done:
331     msi_free(fusion);
332     msi_free(version);
333 }
334
335 /*
336  * There are a whole slew of these we need to set
337  *
338  *
339 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/properties.asp
340  */
341 static VOID set_installer_properties(MSIPACKAGE *package)
342 {
343     WCHAR pth[MAX_PATH];
344     WCHAR *ptr;
345     OSVERSIONINFOEXW OSVersion;
346     MEMORYSTATUSEX msex;
347     DWORD verval;
348     WCHAR verstr[10], bufstr[20];
349     HDC dc;
350     LPWSTR check;
351     HKEY hkey;
352     LONG res;
353     SYSTEM_INFO sys_info;
354     SYSTEMTIME systemtime;
355
356     static const WCHAR cszbs[]={'\\',0};
357     static const WCHAR CFF[] = 
358 {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
359     static const WCHAR PFF[] = 
360 {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
361     static const WCHAR CADF[] = 
362 {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
363     static const WCHAR FaF[] = 
364 {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
365     static const WCHAR FoF[] = 
366 {'F','o','n','t','s','F','o','l','d','e','r',0};
367     static const WCHAR SendTF[] = 
368 {'S','e','n','d','T','o','F','o','l','d','e','r',0};
369     static const WCHAR SMF[] = 
370 {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
371     static const WCHAR StF[] = 
372 {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
373     static const WCHAR TemplF[] = 
374 {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
375     static const WCHAR DF[] = 
376 {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
377     static const WCHAR PMF[] = 
378 {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
379     static const WCHAR ATF[] = 
380 {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
381     static const WCHAR ADF[] = 
382 {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
383     static const WCHAR SF[] = 
384 {'S','y','s','t','e','m','F','o','l','d','e','r',0};
385     static const WCHAR SF16[] = 
386 {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
387     static const WCHAR LADF[] = 
388 {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
389     static const WCHAR MPF[] = 
390 {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
391     static const WCHAR PF[] = 
392 {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
393     static const WCHAR WF[] = 
394 {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
395     static const WCHAR WV[] = 
396 {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
397     static const WCHAR TF[]=
398 {'T','e','m','p','F','o','l','d','e','r',0};
399     static const WCHAR szAdminUser[] =
400 {'A','d','m','i','n','U','s','e','r',0};
401     static const WCHAR szPriv[] =
402 {'P','r','i','v','i','l','e','g','e','d',0};
403     static const WCHAR szOne[] =
404 {'1',0};
405     static const WCHAR v9x[] = { 'V','e','r','s','i','o','n','9','X',0 };
406     static const WCHAR vNT[] = { 'V','e','r','s','i','o','n','N','T',0 };
407     static const WCHAR szMsiNTProductType[] = { 'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0 };
408     static const WCHAR szFormat[] = {'%','l','i',0};
409     static const WCHAR szWinBuild[] =
410 {'W','i','n','d','o','w','s','B','u','i','l','d', 0 };
411     static const WCHAR szSPL[] = 
412 {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0 };
413     static const WCHAR szSix[] = {'6',0 };
414
415     static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
416     static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
417     static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
418     static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
419 /* Screen properties */
420     static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
421     static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
422     static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
423     static const WCHAR szScreenFormat[] = {'%','d',0};
424     static const WCHAR szIntel[] = { 'I','n','t','e','l',0 };
425     static const WCHAR szAllUsers[] = { 'A','L','L','U','S','E','R','S',0 };
426     static const WCHAR szCurrentVersion[] = {
427         'S','O','F','T','W','A','R','E','\\',
428         'M','i','c','r','o','s','o','f','t','\\',
429         'W','i','n','d','o','w','s',' ','N','T','\\',
430         'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
431     };
432     static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
433     static const WCHAR szRegisteredOrg[] = {
434         'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
435     };
436     static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
437     static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
438     static const WCHAR szDate[] = {'D','a','t','e',0};
439     static const WCHAR szTime[] = {'T','i','m','e',0};
440
441     /*
442      * Other things that probably should be set:
443      *
444      * SystemLanguageID ComputerName UserLanguageID LogonUser VirtualMemory
445      * ShellAdvSupport DefaultUIFont PackagecodeChanging
446      * ProductState CaptionHeight BorderTop BorderSide TextHeight
447      * RedirectedDllSupport
448      */
449
450     SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES_COMMON,NULL,0,pth);
451     strcatW(pth,cszbs);
452     MSI_SetPropertyW(package, CFF, pth);
453
454     SHGetFolderPathW(NULL,CSIDL_PROGRAM_FILES,NULL,0,pth);
455     strcatW(pth,cszbs);
456     MSI_SetPropertyW(package, PFF, pth);
457
458     SHGetFolderPathW(NULL,CSIDL_COMMON_APPDATA,NULL,0,pth);
459     strcatW(pth,cszbs);
460     MSI_SetPropertyW(package, CADF, pth);
461
462     SHGetFolderPathW(NULL,CSIDL_FAVORITES,NULL,0,pth);
463     strcatW(pth,cszbs);
464     MSI_SetPropertyW(package, FaF, pth);
465
466     SHGetFolderPathW(NULL,CSIDL_FONTS,NULL,0,pth);
467     strcatW(pth,cszbs);
468     MSI_SetPropertyW(package, FoF, pth);
469
470     SHGetFolderPathW(NULL,CSIDL_SENDTO,NULL,0,pth);
471     strcatW(pth,cszbs);
472     MSI_SetPropertyW(package, SendTF, pth);
473
474     SHGetFolderPathW(NULL,CSIDL_STARTMENU,NULL,0,pth);
475     strcatW(pth,cszbs);
476     MSI_SetPropertyW(package, SMF, pth);
477
478     SHGetFolderPathW(NULL,CSIDL_STARTUP,NULL,0,pth);
479     strcatW(pth,cszbs);
480     MSI_SetPropertyW(package, StF, pth);
481
482     SHGetFolderPathW(NULL,CSIDL_TEMPLATES,NULL,0,pth);
483     strcatW(pth,cszbs);
484     MSI_SetPropertyW(package, TemplF, pth);
485
486     SHGetFolderPathW(NULL,CSIDL_DESKTOP,NULL,0,pth);
487     strcatW(pth,cszbs);
488     MSI_SetPropertyW(package, DF, pth);
489
490     SHGetFolderPathW(NULL,CSIDL_PROGRAMS,NULL,0,pth);
491     strcatW(pth,cszbs);
492     MSI_SetPropertyW(package, PMF, pth);
493
494     SHGetFolderPathW(NULL,CSIDL_ADMINTOOLS,NULL,0,pth);
495     strcatW(pth,cszbs);
496     MSI_SetPropertyW(package, ATF, pth);
497
498     SHGetFolderPathW(NULL,CSIDL_APPDATA,NULL,0,pth);
499     strcatW(pth,cszbs);
500     MSI_SetPropertyW(package, ADF, pth);
501
502     SHGetFolderPathW(NULL,CSIDL_SYSTEM,NULL,0,pth);
503     strcatW(pth,cszbs);
504     MSI_SetPropertyW(package, SF, pth);
505     MSI_SetPropertyW(package, SF16, pth);
506
507     SHGetFolderPathW(NULL,CSIDL_LOCAL_APPDATA,NULL,0,pth);
508     strcatW(pth,cszbs);
509     MSI_SetPropertyW(package, LADF, pth);
510
511     SHGetFolderPathW(NULL,CSIDL_MYPICTURES,NULL,0,pth);
512     strcatW(pth,cszbs);
513     MSI_SetPropertyW(package, MPF, pth);
514
515     SHGetFolderPathW(NULL,CSIDL_PERSONAL,NULL,0,pth);
516     strcatW(pth,cszbs);
517     MSI_SetPropertyW(package, PF, pth);
518
519     SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
520     strcatW(pth,cszbs);
521     MSI_SetPropertyW(package, WF, pth);
522     
523     /* Physical Memory is specified in MB. Using total amount. */
524     msex.dwLength = sizeof(msex);
525     GlobalMemoryStatusEx( &msex );
526     sprintfW( bufstr, szScreenFormat, (int)(msex.ullTotalPhys/1024/1024));
527     MSI_SetPropertyW(package, szPhysicalMemory, bufstr);
528
529     SHGetFolderPathW(NULL,CSIDL_WINDOWS,NULL,0,pth);
530     ptr = strchrW(pth,'\\');
531     if (ptr)
532         *(ptr+1) = 0;
533     MSI_SetPropertyW(package, WV, pth);
534     
535     GetTempPathW(MAX_PATH,pth);
536     MSI_SetPropertyW(package, TF, pth);
537
538
539     /* in a wine environment the user is always admin and privileged */
540     MSI_SetPropertyW(package,szAdminUser,szOne);
541     MSI_SetPropertyW(package,szPriv,szOne);
542     MSI_SetPropertyW(package, szAllUsers, szOne);
543
544     /* set the os things */
545     OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
546     GetVersionExW((OSVERSIONINFOW *)&OSVersion);
547     verval = OSVersion.dwMinorVersion+OSVersion.dwMajorVersion*100;
548     sprintfW(verstr,szFormat,verval);
549     switch (OSVersion.dwPlatformId)
550     {
551         case VER_PLATFORM_WIN32_WINDOWS:    
552             MSI_SetPropertyW(package,v9x,verstr);
553             break;
554         case VER_PLATFORM_WIN32_NT:
555             MSI_SetPropertyW(package,vNT,verstr);
556             sprintfW(verstr,szFormat,OSVersion.wProductType);
557             MSI_SetPropertyW(package,szMsiNTProductType,verstr);
558             break;
559     }
560     sprintfW(verstr,szFormat,OSVersion.dwBuildNumber);
561     MSI_SetPropertyW(package,szWinBuild,verstr);
562     /* just fudge this */
563     MSI_SetPropertyW(package,szSPL,szSix);
564
565     sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
566     MSI_SetPropertyW( package, szVersionMsi, bufstr );
567     sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
568     MSI_SetPropertyW( package, szVersionDatabase, bufstr );
569
570     GetSystemInfo( &sys_info );
571     if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
572     {
573         sprintfW( bufstr, szScreenFormat, sys_info.wProcessorLevel );
574         MSI_SetPropertyW( package, szIntel, bufstr );
575     }
576
577     /* Screen properties. */
578     dc = GetDC(0);
579     sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, HORZRES ) );
580     MSI_SetPropertyW( package, szScreenX, bufstr );
581     sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, VERTRES ));
582     MSI_SetPropertyW( package, szScreenY, bufstr );
583     sprintfW( bufstr, szScreenFormat, GetDeviceCaps( dc, BITSPIXEL ));
584     MSI_SetPropertyW( package, szColorBits, bufstr );
585     ReleaseDC(0, dc);
586
587     /* USERNAME and COMPANYNAME */
588     res = RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey );
589     if (res != ERROR_SUCCESS)
590         return;
591
592     check = msi_dup_property( package, szUSERNAME );
593     if (!check)
594     {
595         LPWSTR user = msi_reg_get_val_str( hkey, szRegisteredUser );
596         MSI_SetPropertyW( package, szUSERNAME, user );
597         msi_free( user );
598     }
599
600     msi_free( check );
601
602     check = msi_dup_property( package, szCOMPANYNAME );
603     if (!check)
604     {
605         LPWSTR company = msi_reg_get_val_str( hkey, szRegisteredOrg );
606         MSI_SetPropertyW( package, szCOMPANYNAME, company );
607         msi_free( company );
608     }
609
610     if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
611         ERR("Failed to set the UserSID property\n");
612
613     /* Date and time properties */
614     GetSystemTime( &systemtime );
615     if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
616                         NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
617         MSI_SetPropertyW( package, szDate, bufstr );
618     else
619         ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
620
621     if (GetTimeFormatW( LOCALE_USER_DEFAULT,
622                         TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
623                         &systemtime, NULL, bufstr,
624                         sizeof(bufstr)/sizeof(bufstr[0]) ))
625         MSI_SetPropertyW( package, szTime, bufstr );
626     else
627         ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
628
629     set_msi_assembly_prop( package );
630
631     msi_free( check );
632     CloseHandle( hkey );
633 }
634
635 static UINT msi_load_summary_properties( MSIPACKAGE *package )
636 {
637     UINT rc;
638     MSIHANDLE suminfo;
639     MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
640     INT count;
641     DWORD len;
642     LPWSTR package_code;
643     static const WCHAR szPackageCode[] = {
644         'P','a','c','k','a','g','e','C','o','d','e',0};
645
646     if (!hdb) {
647         ERR("Unable to allocate handle\n");
648         return ERROR_OUTOFMEMORY;
649     }
650
651     rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
652     MsiCloseHandle(hdb);
653     if (rc != ERROR_SUCCESS)
654     {
655         ERR("Unable to open Summary Information\n");
656         return rc;
657     }
658
659     rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
660                                      &count, NULL, NULL, NULL );
661     if (rc != ERROR_SUCCESS)
662     {
663         WARN("Unable to query page count: %d\n", rc);
664         goto done;
665     }
666
667     /* load package code property */
668     len = 0;
669     rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
670                                      NULL, NULL, NULL, &len );
671     if (rc != ERROR_MORE_DATA)
672     {
673         WARN("Unable to query revision number: %d\n", rc);
674         rc = ERROR_FUNCTION_FAILED;
675         goto done;
676     }
677
678     len++;
679     package_code = msi_alloc( len * sizeof(WCHAR) );
680     rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
681                                      NULL, NULL, package_code, &len );
682     if (rc != ERROR_SUCCESS)
683     {
684         WARN("Unable to query rev number: %d\n", rc);
685         goto done;
686     }
687
688     MSI_SetPropertyW( package, szPackageCode, package_code );
689     msi_free( package_code );
690
691     /* load package attributes */
692     count = 0;
693     MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
694                                 &count, NULL, NULL, NULL );
695     package->WordCount = count;
696
697 done:
698     MsiCloseHandle(suminfo);
699     return rc;
700 }
701
702 static MSIPACKAGE *msi_alloc_package( void )
703 {
704     MSIPACKAGE *package;
705
706     package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
707                                MSI_FreePackage );
708     if( package )
709     {
710         list_init( &package->components );
711         list_init( &package->features );
712         list_init( &package->files );
713         list_init( &package->tempfiles );
714         list_init( &package->folders );
715         list_init( &package->subscriptions );
716         list_init( &package->appids );
717         list_init( &package->classes );
718         list_init( &package->mimes );
719         list_init( &package->extensions );
720         list_init( &package->progids );
721         list_init( &package->RunningActions );
722         list_init( &package->sourcelist_info );
723         list_init( &package->sourcelist_media );
724
725         package->ActionFormat = NULL;
726         package->LastAction = NULL;
727         package->dialog = NULL;
728         package->next_dialog = NULL;
729         package->scheduled_action_running = FALSE;
730         package->commit_action_running = FALSE;
731         package->rollback_action_running = FALSE;
732     }
733
734     return package;
735 }
736
737 static UINT msi_load_admin_properties(MSIPACKAGE *package)
738 {
739     BYTE *data;
740     UINT r, sz;
741
742     static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
743
744     r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
745     if (r != ERROR_SUCCESS)
746         return r;
747
748     r = msi_parse_command_line(package, (WCHAR *)data);
749
750     msi_free(data);
751     return r;
752 }
753
754 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
755 {
756     static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
757     static const WCHAR szpi[] = {'%','i',0};
758     static const WCHAR szProductCode[] = {
759         'P','r','o','d','u','c','t','C','o','d','e',0};
760     MSIPACKAGE *package;
761     WCHAR uilevel[10];
762     UINT r;
763
764     TRACE("%p\n", db);
765
766     package = msi_alloc_package();
767     if (package)
768     {
769         msiobj_addref( &db->hdr );
770         package->db = db;
771
772         package->WordCount = 0;
773         package->PackagePath = strdupW( db->path );
774         package->BaseURL = strdupW( base_url );
775
776         create_temp_property_table( package );
777         msi_clone_properties( package );
778         set_installer_properties(package);
779         sprintfW(uilevel,szpi,gUILevel);
780         MSI_SetPropertyW(package, szLevel, uilevel);
781
782         package->ProductCode = msi_dup_property( package, szProductCode );
783         set_installed_prop( package );
784         r = msi_load_summary_properties( package );
785         if (r != ERROR_SUCCESS)
786         {
787             msiobj_release( &package->hdr );
788             return NULL;
789         }
790
791         if (package->WordCount & MSIWORDCOUNT_ADMINISTRATIVE)
792             msi_load_admin_properties( package );
793     }
794
795     return package;
796 }
797
798 /*
799  * copy_package_to_temp   [internal]
800  *
801  * copy the msi file to a temp file to prevent locking a CD
802  * with a multi disc install 
803  *
804  * FIXME: I think this is wrong, and instead of copying the package,
805  *        we should read all the tables to memory, then open the
806  *        database to read binary streams on demand.
807  */ 
808 static LPCWSTR copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
809 {
810     WCHAR path[MAX_PATH];
811     static const WCHAR szMSI[] = {'m','s','i',0};
812
813     GetTempPathW( MAX_PATH, path );
814     GetTempFileNameW( path, szMSI, 0, filename );
815
816     if( !CopyFileW( szPackage, filename, FALSE ) )
817     {
818         DeleteFileW( filename );
819         ERR("failed to copy package %s\n", debugstr_w(szPackage) );
820         return szPackage;
821     }
822
823     TRACE("Opening relocated package %s\n", debugstr_w( filename ));
824     return filename;
825 }
826
827 LPCWSTR msi_download_file( LPCWSTR szUrl, LPWSTR filename )
828 {
829     LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
830     DWORD size = 0;
831     HRESULT hr;
832
833     /* call will always fail, becase size is 0,
834      * but will return ERROR_FILE_NOT_FOUND first
835      * if the file doesn't exist
836      */
837     GetUrlCacheEntryInfoW( szUrl, NULL, &size );
838     if ( GetLastError() != ERROR_FILE_NOT_FOUND )
839     {
840         cache_entry = HeapAlloc( GetProcessHeap(), 0, size );
841         if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
842         {
843             HeapFree( GetProcessHeap(), 0, cache_entry );
844             return szUrl;
845         }
846
847         lstrcpyW( filename, cache_entry->lpszLocalFileName );
848         HeapFree( GetProcessHeap(), 0, cache_entry );
849         return filename;
850     }
851
852     hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
853     if ( FAILED(hr) )
854         return szUrl;
855
856     return filename;
857 }
858
859 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
860 {
861     static const WCHAR OriginalDatabase[] =
862         {'O','r','i','g','i','n','a','l','D','a','t','a','b','a','s','e',0};
863     static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
864     MSIDATABASE *db = NULL;
865     MSIPACKAGE *package;
866     MSIHANDLE handle;
867     LPWSTR ptr, base_url = NULL;
868     UINT r;
869     WCHAR temppath[MAX_PATH];
870     LPCWSTR file = szPackage;
871
872     TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
873
874     if( szPackage[0] == '#' )
875     {
876         handle = atoiW(&szPackage[1]);
877         db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
878         if( !db )
879         {
880             IWineMsiRemoteDatabase *remote_database;
881
882             remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
883             if ( !remote_database )
884                 return ERROR_INVALID_HANDLE;
885
886             IWineMsiRemoteDatabase_Release( remote_database );
887             WARN("MsiOpenPackage not allowed during a custom action!\n");
888
889             return ERROR_FUNCTION_FAILED;
890         }
891     }
892     else
893     {
894         if ( UrlIsW( szPackage, URLIS_URL ) )
895         {
896             file = msi_download_file( szPackage, temppath );
897
898             base_url = strdupW( szPackage );
899             if ( !base_url )
900                 return ERROR_OUTOFMEMORY;
901
902             ptr = strrchrW( base_url, '/' );
903             if (ptr) *(ptr + 1) = '\0';
904         }
905         else
906             file = copy_package_to_temp( szPackage, temppath );
907
908         r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY, &db );
909         if( r != ERROR_SUCCESS )
910         {
911             if (file != szPackage)
912                 DeleteFileW( file );
913
914             if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
915                 return ERROR_FILE_NOT_FOUND;
916
917             return r;
918         }
919     }
920
921     package = MSI_CreatePackage( db, base_url );
922     msi_free( base_url );
923     msiobj_release( &db->hdr );
924     if( !package )
925     {
926         if (file != szPackage)
927             DeleteFileW( file );
928
929         return ERROR_INSTALL_PACKAGE_INVALID;
930     }
931
932     if( file != szPackage )
933         track_tempfile( package, file );
934
935     MSI_SetPropertyW( package, Database, db->path );
936
937     if( UrlIsW( szPackage, URLIS_URL ) )
938         MSI_SetPropertyW( package, OriginalDatabase, szPackage );
939     else if( szPackage[0] == '#' )
940         MSI_SetPropertyW( package, OriginalDatabase, db->path );
941     else
942     {
943         WCHAR fullpath[MAX_PATH];
944
945         GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
946         MSI_SetPropertyW( package, OriginalDatabase, fullpath );
947     }
948
949     *pPackage = package;
950
951     return ERROR_SUCCESS;
952 }
953
954 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
955 {
956     MSIPACKAGE *package = NULL;
957     UINT ret;
958
959     TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
960
961     if( !szPackage || !phPackage )
962         return ERROR_INVALID_PARAMETER;
963
964     if ( !*szPackage )
965     {
966         FIXME("Should create an empty database and package\n");
967         return ERROR_FUNCTION_FAILED;
968     }
969
970     if( dwOptions )
971         FIXME("dwOptions %08x not supported\n", dwOptions);
972
973     ret = MSI_OpenPackageW( szPackage, &package );
974     if( ret == ERROR_SUCCESS )
975     {
976         *phPackage = alloc_msihandle( &package->hdr );
977         if (! *phPackage)
978             ret = ERROR_NOT_ENOUGH_MEMORY;
979         msiobj_release( &package->hdr );
980     }
981
982     return ret;
983 }
984
985 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
986 {
987     return MsiOpenPackageExW( szPackage, 0, phPackage );
988 }
989
990 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
991 {
992     LPWSTR szwPack = NULL;
993     UINT ret;
994
995     if( szPackage )
996     {
997         szwPack = strdupAtoW( szPackage );
998         if( !szwPack )
999             return ERROR_OUTOFMEMORY;
1000     }
1001
1002     ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1003
1004     msi_free( szwPack );
1005
1006     return ret;
1007 }
1008
1009 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1010 {
1011     return MsiOpenPackageExA( szPackage, 0, phPackage );
1012 }
1013
1014 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1015 {
1016     MSIPACKAGE *package;
1017     MSIHANDLE handle = 0;
1018     IWineMsiRemotePackage *remote_package;
1019
1020     TRACE("(%ld)\n",hInstall);
1021
1022     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1023     if( package)
1024     {
1025         handle = alloc_msihandle( &package->db->hdr );
1026         msiobj_release( &package->hdr );
1027     }
1028     else if ((remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall )))
1029     {
1030         IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1031         IWineMsiRemotePackage_Release(remote_package);
1032     }
1033
1034     return handle;
1035 }
1036
1037 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1038                                MSIRECORD *record)
1039 {
1040     static const WCHAR szActionData[] =
1041         {'A','c','t','i','o','n','D','a','t','a',0};
1042     static const WCHAR szSetProgress[] =
1043         {'S','e','t','P','r','o','g','r','e','s','s',0};
1044     static const WCHAR szActionText[] =
1045         {'A','c','t','i','o','n','T','e','x','t',0};
1046     DWORD log_type = 0;
1047     LPWSTR message;
1048     DWORD sz;
1049     DWORD total_size = 0;
1050     INT i;
1051     INT rc;
1052     char *msg;
1053     int len;
1054
1055     TRACE("%x\n", eMessageType);
1056     rc = 0;
1057
1058     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1059         log_type |= INSTALLLOGMODE_ERROR;
1060     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1061         log_type |= INSTALLLOGMODE_WARNING;
1062     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1063         log_type |= INSTALLLOGMODE_USER;
1064     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1065         log_type |= INSTALLLOGMODE_INFO;
1066     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1067         log_type |= INSTALLLOGMODE_COMMONDATA;
1068     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1069         log_type |= INSTALLLOGMODE_ACTIONSTART;
1070     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1071         log_type |= INSTALLLOGMODE_ACTIONDATA;
1072     /* just a guess */
1073     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1074         log_type |= 0x800;
1075
1076     if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1077     {
1078         static const WCHAR template_s[]=
1079             {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1080         static const WCHAR format[] = 
1081             {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1082         WCHAR timet[0x100];
1083         LPCWSTR action_text, action;
1084         LPWSTR deformatted = NULL;
1085
1086         GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1087
1088         action = MSI_RecordGetString(record, 1);
1089         action_text = MSI_RecordGetString(record, 2);
1090
1091         if (!action || !action_text)
1092             return IDOK;
1093
1094         deformat_string(package, action_text, &deformatted);
1095
1096         len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1097         if (deformatted)
1098             len += strlenW(deformatted);
1099         message = msi_alloc(len*sizeof(WCHAR));
1100         sprintfW(message, template_s, timet, action);
1101         if (deformatted)
1102             strcatW(message, deformatted);
1103         msi_free(deformatted);
1104     }
1105     else
1106     {
1107         INT msg_field=1;
1108         message = msi_alloc(1*sizeof (WCHAR));
1109         message[0]=0;
1110         msg_field = MSI_RecordGetFieldCount(record);
1111         for (i = 1; i <= msg_field; i++)
1112         {
1113             LPWSTR tmp;
1114             WCHAR number[3];
1115             static const WCHAR format[] = { '%','i',':',' ',0};
1116             static const WCHAR space[] = { ' ',0};
1117             sz = 0;
1118             MSI_RecordGetStringW(record,i,NULL,&sz);
1119             sz+=4;
1120             total_size+=sz*sizeof(WCHAR);
1121             tmp = msi_alloc(sz*sizeof(WCHAR));
1122             message = msi_realloc(message,total_size*sizeof (WCHAR));
1123
1124             MSI_RecordGetStringW(record,i,tmp,&sz);
1125
1126             if (msg_field > 1)
1127             {
1128                 sprintfW(number,format,i);
1129                 strcatW(message,number);
1130             }
1131             strcatW(message,tmp);
1132             if (msg_field > 1)
1133                 strcatW(message,space);
1134
1135             msi_free(tmp);
1136         }
1137     }
1138
1139     TRACE("(%p %x %x %s)\n", gUIHandlerA, gUIFilter, log_type,
1140                              debugstr_w(message));
1141
1142     /* convert it to ASCII */
1143     len = WideCharToMultiByte( CP_ACP, 0, message, -1,
1144                                NULL, 0, NULL, NULL );
1145     msg = msi_alloc( len );
1146     WideCharToMultiByte( CP_ACP, 0, message, -1,
1147                          msg, len, NULL, NULL );
1148
1149     if (gUIHandlerA && (gUIFilter & log_type))
1150     {
1151         rc = gUIHandlerA(gUIContext,eMessageType,msg);
1152     }
1153
1154     if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
1155                                       INSTALLMESSAGE_PROGRESS))
1156     {
1157         DWORD write;
1158         HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
1159                                   OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1160
1161         if (log_file != INVALID_HANDLE_VALUE)
1162         {
1163             SetFilePointer(log_file,0, NULL, FILE_END);
1164             WriteFile(log_file,msg,strlen(msg),&write,NULL);
1165             WriteFile(log_file,"\n",1,&write,NULL);
1166             CloseHandle(log_file);
1167         }
1168     }
1169     msi_free( msg );
1170
1171     msi_free( message);
1172
1173     switch (eMessageType & 0xff000000)
1174     {
1175     case INSTALLMESSAGE_ACTIONDATA:
1176         /* FIXME: format record here instead of in ui_actiondata to get the
1177          * correct action data for external scripts */
1178         ControlEvent_FireSubscribedEvent(package, szActionData, record);
1179         break;
1180     case INSTALLMESSAGE_ACTIONSTART:
1181     {
1182         MSIRECORD *uirow;
1183         LPWSTR deformated;
1184         LPCWSTR action_text = MSI_RecordGetString(record, 2);
1185
1186         deformat_string(package, action_text, &deformated);
1187         uirow = MSI_CreateRecord(1);
1188         MSI_RecordSetStringW(uirow, 1, deformated);
1189         TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1190         msi_free(deformated);
1191
1192         ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1193
1194         msiobj_release(&uirow->hdr);
1195         break;
1196     }
1197     case INSTALLMESSAGE_PROGRESS:
1198         ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1199         break;
1200     }
1201
1202     return ERROR_SUCCESS;
1203 }
1204
1205 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1206                               MSIHANDLE hRecord)
1207 {
1208     UINT ret = ERROR_INVALID_HANDLE;
1209     MSIPACKAGE *package = NULL;
1210     MSIRECORD *record = NULL;
1211
1212     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1213     if( !package )
1214     {
1215         HRESULT hr;
1216         IWineMsiRemotePackage *remote_package;
1217
1218         remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1219         if (!remote_package)
1220             return ERROR_INVALID_HANDLE;
1221
1222         hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1223
1224         IWineMsiRemotePackage_Release( remote_package );
1225
1226         if (FAILED(hr))
1227         {
1228             if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1229                 return HRESULT_CODE(hr);
1230
1231             return ERROR_FUNCTION_FAILED;
1232         }
1233
1234         return ERROR_SUCCESS;
1235     }
1236
1237     record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1238     if( !record )
1239         goto out;
1240
1241     ret = MSI_ProcessMessage( package, eMessageType, record );
1242
1243 out:
1244     msiobj_release( &package->hdr );
1245     if( record )
1246         msiobj_release( &record->hdr );
1247
1248     return ret;
1249 }
1250
1251 /* property code */
1252
1253 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1254 {
1255     LPWSTR szwName = NULL, szwValue = NULL;
1256     UINT r = ERROR_OUTOFMEMORY;
1257
1258     szwName = strdupAtoW( szName );
1259     if( szName && !szwName )
1260         goto end;
1261
1262     szwValue = strdupAtoW( szValue );
1263     if( szValue && !szwValue )
1264         goto end;
1265
1266     r = MsiSetPropertyW( hInstall, szwName, szwValue);
1267
1268 end:
1269     msi_free( szwName );
1270     msi_free( szwValue );
1271
1272     return r;
1273 }
1274
1275 UINT MSI_SetPropertyW( MSIPACKAGE *package, LPCWSTR szName, LPCWSTR szValue)
1276 {
1277     MSIQUERY *view;
1278     MSIRECORD *row = NULL;
1279     UINT rc;
1280     DWORD sz = 0;
1281     WCHAR Query[1024];
1282
1283     static const WCHAR Insert[] = {
1284         'I','N','S','E','R','T',' ','i','n','t','o',' ',
1285         '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1286         '`','_','P','r','o','p','e','r','t','y','`',',',
1287         '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1288         ,' ','(','?',',','?',')',0};
1289     static const WCHAR Update[] = {
1290         'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1291         ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1292         'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1293         ' ','=',' ','\'','%','s','\'',0};
1294     static const WCHAR Delete[] = {
1295         'D','E','L','E','T','E',' ','F','R','O','M',' ',
1296         '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1297         '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1298
1299     TRACE("%p %s %s\n", package, debugstr_w(szName), debugstr_w(szValue));
1300
1301     if (!szName)
1302         return ERROR_INVALID_PARAMETER;
1303
1304     /* this one is weird... */
1305     if (!szName[0])
1306         return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1307
1308     rc = MSI_GetPropertyW(package, szName, 0, &sz);
1309     if (!szValue || !*szValue)
1310     {
1311         sprintfW(Query, Delete, szName);
1312     }
1313     else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1314     {
1315         sprintfW(Query, Update, szName);
1316
1317         row = MSI_CreateRecord(1);
1318         MSI_RecordSetStringW(row, 1, szValue);
1319     }
1320     else
1321     {
1322         strcpyW(Query, Insert);
1323
1324         row = MSI_CreateRecord(2);
1325         MSI_RecordSetStringW(row, 1, szName);
1326         MSI_RecordSetStringW(row, 2, szValue);
1327     }
1328
1329     rc = MSI_DatabaseOpenViewW(package->db, Query, &view);
1330     if (rc == ERROR_SUCCESS)
1331     {
1332         rc = MSI_ViewExecute(view, row);
1333         MSI_ViewClose(view);
1334         msiobj_release(&view->hdr);
1335     }
1336
1337     msiobj_release(&row->hdr);
1338
1339     return rc;
1340 }
1341
1342 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1343 {
1344     MSIPACKAGE *package;
1345     UINT ret;
1346
1347     package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1348     if( !package )
1349     {
1350         HRESULT hr;
1351         BSTR name = NULL, value = NULL;
1352         IWineMsiRemotePackage *remote_package;
1353
1354         remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1355         if (!remote_package)
1356             return ERROR_INVALID_HANDLE;
1357
1358         name = SysAllocString( szName );
1359         value = SysAllocString( szValue );
1360         if ((!name && szName) || (!value && szValue))
1361         {
1362             SysFreeString( name );
1363             SysFreeString( value );
1364             IWineMsiRemotePackage_Release( remote_package );
1365             return ERROR_OUTOFMEMORY;
1366         }
1367
1368         hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
1369
1370         SysFreeString( name );
1371         SysFreeString( value );
1372         IWineMsiRemotePackage_Release( remote_package );
1373
1374         if (FAILED(hr))
1375         {
1376             if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1377                 return HRESULT_CODE(hr);
1378
1379             return ERROR_FUNCTION_FAILED;
1380         }
1381
1382         return ERROR_SUCCESS;
1383     }
1384
1385     ret = MSI_SetPropertyW( package, szName, szValue);
1386     msiobj_release( &package->hdr );
1387     return ret;
1388 }
1389
1390 static MSIRECORD *MSI_GetPropertyRow( MSIPACKAGE *package, LPCWSTR name )
1391 {
1392     static const WCHAR query[]= {
1393         'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
1394         'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1395         ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
1396         '=','\'','%','s','\'',0};
1397
1398     if (!name || !*name)
1399         return NULL;
1400
1401     return MSI_QueryGetRecord( package->db, query, name );
1402 }
1403
1404 /* internal function, not compatible with MsiGetPropertyW */
1405 UINT MSI_GetPropertyW( MSIPACKAGE *package, LPCWSTR szName, 
1406                        LPWSTR szValueBuf, LPDWORD pchValueBuf )
1407 {
1408     MSIRECORD *row;
1409     UINT rc = ERROR_FUNCTION_FAILED;
1410
1411     row = MSI_GetPropertyRow( package, szName );
1412
1413     if (*pchValueBuf > 0)
1414         szValueBuf[0] = 0;
1415
1416     if (row)
1417     {
1418         rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
1419         msiobj_release(&row->hdr);
1420     }
1421
1422     if (rc == ERROR_SUCCESS)
1423         TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
1424             debugstr_w(szName));
1425     else if (rc == ERROR_MORE_DATA)
1426         TRACE("need %d sized buffer for %s\n", *pchValueBuf,
1427             debugstr_w(szName));
1428     else
1429     {
1430         *pchValueBuf = 0;
1431         TRACE("property %s not found\n", debugstr_w(szName));
1432     }
1433
1434     return rc;
1435 }
1436
1437 LPWSTR msi_dup_property(MSIPACKAGE *package, LPCWSTR prop)
1438 {
1439     DWORD sz = 0;
1440     LPWSTR str;
1441     UINT r;
1442
1443     r = MSI_GetPropertyW(package, prop, NULL, &sz);
1444     if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
1445         return NULL;
1446
1447     sz++;
1448     str = msi_alloc(sz * sizeof(WCHAR));
1449     r = MSI_GetPropertyW(package, prop, str, &sz);
1450     if (r != ERROR_SUCCESS)
1451     {
1452         msi_free(str);
1453         str = NULL;
1454     }
1455
1456     return str;
1457 }
1458
1459 int msi_get_property_int(MSIPACKAGE *package, LPCWSTR prop, int def)
1460 {
1461     LPWSTR str = msi_dup_property(package, prop);
1462     int val = str ? atoiW(str) : def;
1463     msi_free(str);
1464     return val;
1465 }
1466
1467 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
1468                              awstring *szValueBuf, LPDWORD pchValueBuf )
1469 {
1470     static const WCHAR empty[] = {0};
1471     MSIPACKAGE *package;
1472     MSIRECORD *row = NULL;
1473     UINT r = ERROR_FUNCTION_FAILED;
1474     LPCWSTR val = NULL;
1475
1476     TRACE("%lu %s %p %p\n", handle, debugstr_w(name),
1477           szValueBuf->str.w, pchValueBuf );
1478
1479     if (!name)
1480         return ERROR_INVALID_PARAMETER;
1481
1482     package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
1483     if (!package)
1484     {
1485         HRESULT hr;
1486         IWineMsiRemotePackage *remote_package;
1487         LPWSTR value = NULL;
1488         BSTR bname;
1489         DWORD len;
1490
1491         remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
1492         if (!remote_package)
1493             return ERROR_INVALID_HANDLE;
1494
1495         bname = SysAllocString( name );
1496         if (!bname)
1497         {
1498             IWineMsiRemotePackage_Release( remote_package );
1499             return ERROR_OUTOFMEMORY;
1500         }
1501
1502         len = 0;
1503         hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
1504         if (FAILED(hr))
1505             goto done;
1506
1507         len++;
1508         value = msi_alloc(len * sizeof(WCHAR));
1509         if (!value)
1510         {
1511             r = ERROR_OUTOFMEMORY;
1512             goto done;
1513         }
1514
1515         hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
1516         if (FAILED(hr))
1517             goto done;
1518
1519         r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
1520
1521         /* Bug required by Adobe installers */
1522         if (!szValueBuf->unicode && !szValueBuf->str.a)
1523             *pchValueBuf *= sizeof(WCHAR);
1524
1525 done:
1526         IWineMsiRemotePackage_Release(remote_package);
1527         SysFreeString(bname);
1528         msi_free(value);
1529
1530         if (FAILED(hr))
1531         {
1532             if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1533                 return HRESULT_CODE(hr);
1534
1535             return ERROR_FUNCTION_FAILED;
1536         }
1537
1538         return r;
1539     }
1540
1541     row = MSI_GetPropertyRow( package, name );
1542     if (row)
1543         val = MSI_RecordGetString( row, 1 );
1544
1545     if (!val)
1546         val = empty;
1547
1548     r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
1549
1550     if (row)
1551         msiobj_release( &row->hdr );
1552     msiobj_release( &package->hdr );
1553
1554     return r;
1555 }
1556
1557 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
1558                              LPSTR szValueBuf, LPDWORD pchValueBuf )
1559 {
1560     awstring val;
1561     LPWSTR name;
1562     UINT r;
1563
1564     val.unicode = FALSE;
1565     val.str.a = szValueBuf;
1566
1567     name = strdupAtoW( szName );
1568     if (szName && !name)
1569         return ERROR_OUTOFMEMORY;
1570
1571     r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
1572     msi_free( name );
1573     return r;
1574 }
1575
1576 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
1577                              LPWSTR szValueBuf, LPDWORD pchValueBuf )
1578 {
1579     awstring val;
1580
1581     val.unicode = TRUE;
1582     val.str.w = szValueBuf;
1583
1584     return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
1585 }
1586
1587 typedef struct _msi_remote_package_impl {
1588     const IWineMsiRemotePackageVtbl *lpVtbl;
1589     MSIHANDLE package;
1590     LONG refs;
1591 } msi_remote_package_impl;
1592
1593 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
1594 {
1595     return (msi_remote_package_impl*) iface;
1596 }
1597
1598 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
1599                 REFIID riid,LPVOID *ppobj)
1600 {
1601     if( IsEqualCLSID( riid, &IID_IUnknown ) ||
1602         IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
1603     {
1604         IUnknown_AddRef( iface );
1605         *ppobj = iface;
1606         return S_OK;
1607     }
1608
1609     return E_NOINTERFACE;
1610 }
1611
1612 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
1613 {
1614     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1615
1616     return InterlockedIncrement( &This->refs );
1617 }
1618
1619 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
1620 {
1621     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1622     ULONG r;
1623
1624     r = InterlockedDecrement( &This->refs );
1625     if (r == 0)
1626     {
1627         MsiCloseHandle( This->package );
1628         msi_free( This );
1629     }
1630     return r;
1631 }
1632
1633 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
1634 {
1635     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1636     This->package = handle;
1637     return S_OK;
1638 }
1639
1640 HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
1641 {
1642     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1643     IWineMsiRemoteDatabase *rdb = NULL;
1644     HRESULT hr;
1645     MSIHANDLE hdb;
1646
1647     hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
1648     if (FAILED(hr) || !rdb)
1649     {
1650         ERR("Failed to create remote database\n");
1651         return hr;
1652     }
1653
1654     hdb = MsiGetActiveDatabase(This->package);
1655
1656     hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
1657     if (FAILED(hr))
1658     {
1659         ERR("Failed to set the database handle\n");
1660         return hr;
1661     }
1662
1663     *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
1664     return S_OK;
1665 }
1666
1667 HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
1668 {
1669     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1670     UINT r;
1671
1672     r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
1673     if (r != ERROR_SUCCESS)
1674         return HRESULT_FROM_WIN32(r);
1675
1676     return S_OK;
1677 }
1678
1679 HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
1680 {
1681     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1682     UINT r = MsiSetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value);
1683     return HRESULT_FROM_WIN32(r);
1684 }
1685
1686 HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
1687 {
1688     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1689     UINT r = MsiProcessMessage(This->package, message, record);
1690     return HRESULT_FROM_WIN32(r);
1691 }
1692
1693 HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
1694 {
1695     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1696     UINT r = MsiDoActionW(This->package, (LPWSTR)action);
1697     return HRESULT_FROM_WIN32(r);
1698 }
1699
1700 HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
1701 {
1702     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1703     UINT r = MsiSequenceW(This->package, (LPWSTR)table, sequence);
1704     return HRESULT_FROM_WIN32(r);
1705 }
1706
1707 HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1708 {
1709     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1710     UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1711     return HRESULT_FROM_WIN32(r);
1712 }
1713
1714 HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
1715 {
1716     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1717     UINT r = MsiSetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value);
1718     return HRESULT_FROM_WIN32(r);
1719 }
1720
1721 HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
1722 {
1723     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1724     UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
1725     return HRESULT_FROM_WIN32(r);
1726 }
1727
1728 HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
1729 {
1730     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1731     *ret = MsiGetMode(This->package, mode);
1732     return S_OK;
1733 }
1734
1735 HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
1736                                     INSTALLSTATE *installed, INSTALLSTATE *action )
1737 {
1738     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1739     UINT r = MsiGetFeatureStateW(This->package, (LPWSTR)feature, installed, action);
1740     return HRESULT_FROM_WIN32(r);
1741 }
1742
1743 HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
1744 {
1745     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1746     UINT r = MsiSetFeatureStateW(This->package, (LPWSTR)feature, state);
1747     return HRESULT_FROM_WIN32(r);
1748 }
1749
1750 HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
1751                                       INSTALLSTATE *installed, INSTALLSTATE *action )
1752 {
1753     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1754     UINT r = MsiGetComponentStateW(This->package, (LPWSTR)component, installed, action);
1755     return HRESULT_FROM_WIN32(r);
1756 }
1757
1758 HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
1759 {
1760     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1761     UINT r = MsiSetComponentStateW(This->package, (LPWSTR)component, state);
1762     return HRESULT_FROM_WIN32(r);
1763 }
1764
1765 HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
1766 {
1767     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1768     *language = MsiGetLanguage(This->package);
1769     return S_OK;
1770 }
1771
1772 HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
1773 {
1774     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1775     UINT r = MsiSetInstallLevel(This->package, level);
1776     return HRESULT_FROM_WIN32(r);
1777 }
1778
1779 HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
1780                                  BSTR value, DWORD *size )
1781 {
1782     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1783     UINT r = MsiFormatRecordW(This->package, record, (LPWSTR)value, size);
1784     return HRESULT_FROM_WIN32(r);
1785 }
1786
1787 HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
1788 {
1789     msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
1790     UINT r = MsiEvaluateConditionW(This->package, (LPWSTR)condition);
1791     return HRESULT_FROM_WIN32(r);
1792 }
1793
1794 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
1795 {
1796     mrp_QueryInterface,
1797     mrp_AddRef,
1798     mrp_Release,
1799     mrp_SetMsiHandle,
1800     mrp_GetActiveDatabase,
1801     mrp_GetProperty,
1802     mrp_SetProperty,
1803     mrp_ProcessMessage,
1804     mrp_DoAction,
1805     mrp_Sequence,
1806     mrp_GetTargetPath,
1807     mrp_SetTargetPath,
1808     mrp_GetSourcePath,
1809     mrp_GetMode,
1810     mrp_GetFeatureState,
1811     mrp_SetFeatureState,
1812     mrp_GetComponentState,
1813     mrp_SetComponentState,
1814     mrp_GetLanguage,
1815     mrp_SetInstallLevel,
1816     mrp_FormatRecord,
1817     mrp_EvaluateCondition,
1818 };
1819
1820 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
1821 {
1822     msi_remote_package_impl* This;
1823
1824     This = msi_alloc( sizeof *This );
1825     if (!This)
1826         return E_OUTOFMEMORY;
1827
1828     This->lpVtbl = &msi_remote_package_vtbl;
1829     This->package = 0;
1830     This->refs = 1;
1831
1832     *ppObj = This;
1833
1834     return S_OK;
1835 }
1836
1837 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
1838                           LPCWSTR property, LPWSTR value)
1839 {
1840     MSISOURCELISTINFO *info;
1841
1842     info = msi_alloc(sizeof(MSISOURCELISTINFO));
1843     if (!info)
1844         return ERROR_OUTOFMEMORY;
1845
1846     info->context = context;
1847     info->options = options;
1848     info->property = property;
1849     info->value = strdupW(value);
1850     list_add_head(&package->sourcelist_info, &info->entry);
1851
1852     return ERROR_SUCCESS;
1853 }
1854
1855 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
1856                                 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
1857 {
1858     MSIMEDIADISK *disk;
1859
1860     disk = msi_alloc(sizeof(MSIMEDIADISK));
1861     if (!disk)
1862         return ERROR_OUTOFMEMORY;
1863
1864     disk->context = context;
1865     disk->options = options;
1866     disk->disk_id = disk_id;
1867     disk->volume_label = strdupW(volume_label);
1868     disk->disk_prompt = strdupW(disk_prompt);
1869     list_add_head(&package->sourcelist_media, &disk->entry);
1870
1871     return ERROR_SUCCESS;
1872 }