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