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