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