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