32576a0362c3cc34591dcf1572aaa3c2822d7e45
[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 remove_tracked_tempfiles( MSIPACKAGE *package )
53 {
54 struct list *item, *cursor;
55
56 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
57 {
58 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
59
60 list_remove( &temp->entry );
61 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
62 if (!DeleteFileW( temp->Path ))
63 ERR("failed to delete %s\n", debugstr_w( temp->Path ));
64 msi_free( temp->Path );
65 msi_free( temp );
66 }
67 }
68
69 static void free_feature( MSIFEATURE *feature )
70 {
71 struct list *item, *cursor;
72
73 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
74 {
75 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
76 list_remove( &fl->entry );
77 msi_free( fl );
78 }
79
80 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
81 {
82 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
83 list_remove( &cl->entry );
84 msi_free( cl );
85 }
86 msi_free( feature->Feature );
87 msi_free( feature->Feature_Parent );
88 msi_free( feature->Directory );
89 msi_free( feature->Description );
90 msi_free( feature->Title );
91 msi_free( feature );
92 }
93
94 static void free_extension( MSIEXTENSION *ext )
95 {
96 struct list *item, *cursor;
97
98 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
99 {
100 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
101
102 list_remove( &verb->entry );
103 msi_free( verb->Verb );
104 msi_free( verb->Command );
105 msi_free( verb->Argument );
106 msi_free( verb );
107 }
108
109 msi_free( ext->Extension );
110 msi_free( ext->ProgIDText );
111 msi_free( ext );
112 }
113
114 static void free_package_structures( MSIPACKAGE *package )
115 {
116 INT i;
117 struct list *item, *cursor;
118
119 TRACE("Freeing package action data\n");
120
121 remove_tracked_tempfiles(package);
122
123 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
124 {
125 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
126 list_remove( &feature->entry );
127 free_feature( feature );
128 }
129
130 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
131 {
132 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
133
134 list_remove( &folder->entry );
135 msi_free( folder->Parent );
136 msi_free( folder->Directory );
137 msi_free( folder->TargetDefault );
138 msi_free( folder->SourceLongPath );
139 msi_free( folder->SourceShortPath );
140 msi_free( folder->ResolvedTarget );
141 msi_free( folder->ResolvedSource );
142 msi_free( folder->Property );
143 msi_free( folder );
144 }
145
146 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
147 {
148 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
149
150 list_remove( &comp->entry );
151 msi_free( comp->Component );
152 msi_free( comp->ComponentId );
153 msi_free( comp->Directory );
154 msi_free( comp->Condition );
155 msi_free( comp->KeyPath );
156 msi_free( comp->FullKeypath );
157 msi_free( comp );
158 }
159
160 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
161 {
162 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
163
164 list_remove( &file->entry );
165 msi_free( file->File );
166 msi_free( file->FileName );
167 msi_free( file->ShortName );
168 msi_free( file->LongName );
169 msi_free( file->Version );
170 msi_free( file->Language );
171 msi_free( file->TargetPath );
172 msi_free( file );
173 }
174
175 /* clean up extension, progid, class and verb structures */
176 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
177 {
178 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
179
180 list_remove( &cls->entry );
181 msi_free( cls->clsid );
182 msi_free( cls->Context );
183 msi_free( cls->Description );
184 msi_free( cls->FileTypeMask );
185 msi_free( cls->IconPath );
186 msi_free( cls->DefInprocHandler );
187 msi_free( cls->DefInprocHandler32 );
188 msi_free( cls->Argument );
189 msi_free( cls->ProgIDText );
190 msi_free( cls );
191 }
192
193 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
194 {
195 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
196
197 list_remove( &ext->entry );
198 free_extension( ext );
199 }
200
201 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
202 {
203 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
204
205 list_remove( &progid->entry );
206 msi_free( progid->ProgID );
207 msi_free( progid->Description );
208 msi_free( progid->IconPath );
209 msi_free( progid );
210 }
211
212 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
213 {
214 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
215
216 list_remove( &mt->entry );
217 msi_free( mt->suffix );
218 msi_free( mt->clsid );
219 msi_free( mt->ContentType );
220 msi_free( mt );
221 }
222
223 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
224 {
225 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
226
227 list_remove( &appid->entry );
228 msi_free( appid->AppID );
229 msi_free( appid->RemoteServerName );
230 msi_free( appid->LocalServer );
231 msi_free( appid->ServiceParameters );
232 msi_free( appid->DllSurrogate );
233 msi_free( appid );
234 }
235
236 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
237 {
238 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
239
240 list_remove( &info->entry );
241 msi_free( info->value );
242 msi_free( info );
243 }
244
245 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
246 {
247 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
248
249 list_remove( &info->entry );
250 msi_free( info->volume_label );
251 msi_free( info->disk_prompt );
252 msi_free( info );
253 }
254
255 if (package->script)
256 {
257 for (i = 0; i < TOTAL_SCRIPTS; i++)
258 msi_free_action_script( package, i );
259
260 for (i = 0; i < package->script->UniqueActionsCount; i++)
261 msi_free( package->script->UniqueActions[i] );
262
263 msi_free( package->script->UniqueActions );
264 msi_free( package->script );
265 }
266
267 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
268 {
269 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
270
271 list_remove( &patch->entry );
272 msi_free( patch->patchcode );
273 msi_free( patch->transforms );
274 msi_free( patch->localfile );
275 msi_free( patch );
276 }
277
278 msi_free( package->BaseURL );
279 msi_free( package->PackagePath );
280 msi_free( package->ProductCode );
281 msi_free( package->ActionFormat );
282 msi_free( package->LastAction );
283 msi_free( package->langids );
284
285 /* cleanup control event subscriptions */
286 ControlEvent_CleanupSubscriptions( package );
287 }
288
289 static void MSI_FreePackage( MSIOBJECTHDR *arg)
290 {
291 MSIPACKAGE *package= (MSIPACKAGE*) arg;
292
293 if( package->dialog )
294 msi_dialog_destroy( package->dialog );
295
296 msiobj_release( &package->db->hdr );
297 free_package_structures(package);
298 }
299
300 static UINT create_temp_property_table(MSIPACKAGE *package)
301 {
302 MSIQUERY *view = NULL;
303 UINT rc;
304
305 static const WCHAR CreateSql[] = {
306 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
307 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
308 '`','_','P','r','o','p','e','r','t','y','`',' ',
309 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
310 'T','E','M','P','O','R','A','R','Y',',',' ',
311 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
312 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
313 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
314 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
315
316 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
317 if (rc != ERROR_SUCCESS)
318 return rc;
319
320 rc = MSI_ViewExecute(view, 0);
321 MSI_ViewClose(view);
322 msiobj_release(&view->hdr);
323 return rc;
324 }
325
326 UINT msi_clone_properties(MSIPACKAGE *package)
327 {
328 MSIQUERY *view_select = NULL;
329 UINT rc;
330
331 static const WCHAR query_select[] = {
332 'S','E','L','E','C','T',' ','*',' ',
333 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
334 static const WCHAR query_insert[] = {
335 'I','N','S','E','R','T',' ','i','n','t','o',' ',
336 '`','_','P','r','o','p','e','r','t','y','`',' ',
337 '(','`','_','P','r','o','p','e','r','t','y','`',',',
338 '`','V','a','l','u','e','`',')',' ',
339 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
340 static const WCHAR query_update[] = {
341 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
342 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
343 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
344
345 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
346 if (rc != ERROR_SUCCESS)
347 return rc;
348
349 rc = MSI_ViewExecute( view_select, 0 );
350 if (rc != ERROR_SUCCESS)
351 {
352 MSI_ViewClose( view_select );
353 msiobj_release( &view_select->hdr );
354 return rc;
355 }
356
357 while (1)
358 {
359 MSIQUERY *view_insert, *view_update;
360 MSIRECORD *rec_select;
361
362 rc = MSI_ViewFetch( view_select, &rec_select );
363 if (rc != ERROR_SUCCESS)
364 break;
365
366 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
367 if (rc != ERROR_SUCCESS)
368 {
369 msiobj_release( &rec_select->hdr );
370 continue;
371 }
372
373 rc = MSI_ViewExecute( view_insert, rec_select );
374 MSI_ViewClose( view_insert );
375 msiobj_release( &view_insert->hdr );
376 if (rc != ERROR_SUCCESS)
377 {
378 MSIRECORD *rec_update;
379
380 TRACE("insert failed, trying update\n");
381
382 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
383 if (rc != ERROR_SUCCESS)
384 {
385 WARN("open view failed %u\n", rc);
386 msiobj_release( &rec_select->hdr );
387 continue;
388 }
389
390 rec_update = MSI_CreateRecord( 2 );
391 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
392 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
393 rc = MSI_ViewExecute( view_update, rec_update );
394 if (rc != ERROR_SUCCESS)
395 WARN("update failed %u\n", rc);
396
397 MSI_ViewClose( view_update );
398 msiobj_release( &view_update->hdr );
399 msiobj_release( &rec_update->hdr );
400 }
401
402 msiobj_release( &rec_select->hdr );
403 }
404
405 MSI_ViewClose( view_select );
406 msiobj_release( &view_select->hdr );
407 return rc;
408 }
409
410 /*
411 * set_installed_prop
412 *
413 * Sets the "Installed" property to indicate that
414 * the product is installed for the current user.
415 */
416 static UINT set_installed_prop( MSIPACKAGE *package )
417 {
418 HKEY hkey = 0;
419 UINT r;
420
421 r = MSIREG_OpenUninstallKey( package, &hkey, FALSE );
422 if (r == ERROR_SUCCESS)
423 {
424 RegCloseKey( hkey );
425 msi_set_property( package->db, szInstalled, szOne );
426 }
427
428 return r;
429 }
430
431 static UINT set_user_sid_prop( MSIPACKAGE *package )
432 {
433 SID_NAME_USE use;
434 LPWSTR user_name;
435 LPWSTR sid_str = NULL, dom = NULL;
436 DWORD size, dom_size;
437 PSID psid = NULL;
438 UINT r = ERROR_FUNCTION_FAILED;
439
440 size = 0;
441 GetUserNameW( NULL, &size );
442
443 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
444 if (!user_name)
445 return ERROR_OUTOFMEMORY;
446
447 if (!GetUserNameW( user_name, &size ))
448 goto done;
449
450 size = 0;
451 dom_size = 0;
452 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
453
454 psid = msi_alloc( size );
455 dom = msi_alloc( dom_size*sizeof (WCHAR) );
456 if (!psid || !dom)
457 {
458 r = ERROR_OUTOFMEMORY;
459 goto done;
460 }
461
462 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
463 goto done;
464
465 if (!ConvertSidToStringSidW( psid, &sid_str ))
466 goto done;
467
468 r = msi_set_property( package->db, szUserSID, sid_str );
469
470 done:
471 LocalFree( sid_str );
472 msi_free( dom );
473 msi_free( psid );
474 msi_free( user_name );
475
476 return r;
477 }
478
479 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
480 {
481 HKEY netsetup;
482 LONG res;
483 LPWSTR file = NULL;
484 DWORD index = 0, size;
485 WCHAR ver[MAX_PATH];
486 WCHAR name[MAX_PATH];
487 WCHAR windir[MAX_PATH];
488
489 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
490 static const WCHAR sub[] = {
491 'S','o','f','t','w','a','r','e','\\',
492 'M','i','c','r','o','s','o','f','t','\\',
493 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
494 'N','D','P',0
495 };
496 static const WCHAR subdir[] = {
497 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
498 'F','r','a','m','e','w','o','r','k','\\',0
499 };
500
501 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
502 if (res != ERROR_SUCCESS)
503 return NULL;
504
505 GetWindowsDirectoryW(windir, MAX_PATH);
506
507 ver[0] = '\0';
508 size = MAX_PATH;
509 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
510 {
511 index++;
512
513 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
514 if (lstrcmpW(ver, name) < 0)
515 {
516 LPWSTR check;
517 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
518 check = msi_alloc(size * sizeof(WCHAR));
519
520 if (!check)
521 {
522 msi_free(file);
523 return NULL;
524 }
525
526 lstrcpyW(check, windir);
527 lstrcatW(check, szBackSlash);
528 lstrcatW(check, subdir);
529 lstrcatW(check, name);
530 lstrcatW(check, szBackSlash);
531 lstrcatW(check, fusion);
532
533 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
534 {
535 msi_free(file);
536 file = check;
537 lstrcpyW(ver, name);
538 }
539 else
540 msi_free(check);
541 }
542 }
543
544 RegCloseKey(netsetup);
545 return file;
546 }
547
548 typedef struct tagLANGANDCODEPAGE
549 {
550 WORD wLanguage;
551 WORD wCodePage;
552 } LANGANDCODEPAGE;
553
554 static void set_msi_assembly_prop(MSIPACKAGE *package)
555 {
556 UINT val_len;
557 DWORD size, handle;
558 LPVOID version = NULL;
559 WCHAR buf[MAX_PATH];
560 LPWSTR fusion, verstr;
561 LANGANDCODEPAGE *translate;
562
563 static const WCHAR netasm[] = {
564 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
565 };
566 static const WCHAR translation[] = {
567 '\\','V','a','r','F','i','l','e','I','n','f','o',
568 '\\','T','r','a','n','s','l','a','t','i','o','n',0
569 };
570 static const WCHAR verfmt[] = {
571 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
572 '\\','%','0','4','x','%','0','4','x',
573 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
574 };
575
576 fusion = get_fusion_filename(package);
577 if (!fusion)
578 return;
579
580 size = GetFileVersionInfoSizeW(fusion, &handle);
581 if (!size) return;
582
583 version = msi_alloc(size);
584 if (!version) return;
585
586 if (!GetFileVersionInfoW(fusion, handle, size, version))
587 goto done;
588
589 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
590 goto done;
591
592 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
593
594 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
595 goto done;
596
597 if (!val_len || !verstr)
598 goto done;
599
600 msi_set_property(package->db, netasm, verstr);
601
602 done:
603 msi_free(fusion);
604 msi_free(version);
605 }
606
607 static VOID set_installer_properties(MSIPACKAGE *package)
608 {
609 WCHAR pth[MAX_PATH];
610 WCHAR *ptr;
611 OSVERSIONINFOEXW OSVersion;
612 MEMORYSTATUSEX msex;
613 DWORD verval, len;
614 WCHAR verstr[10], bufstr[20];
615 HDC dc;
616 HKEY hkey;
617 LPWSTR username, companyname;
618 SYSTEM_INFO sys_info;
619 SYSTEMTIME systemtime;
620 LANGID langid;
621
622 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
623 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
624 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
625 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
626 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
627 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
628 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
629 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
630 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
631 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
632 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
633 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
634 static const WCHAR szAppDataFolder[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
635 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
636 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
637 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
638 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
639 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
640 static const WCHAR szWindowsFolder[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
641 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
642 static const WCHAR szTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
643 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
644 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
645 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
646 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
647 static const WCHAR szFormat[] = {'%','l','i',0};
648 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
649 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
650 static const WCHAR szSix[] = {'6',0 };
651 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
652 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
653 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
654 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
655 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
656 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
657 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
658 static const WCHAR szIntFormat[] = {'%','d',0};
659 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
660 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
661 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
662 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
663 static const WCHAR szProgramFiles64Folder[] = { 'P','r','o','g','r','a','m','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
664 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
665 static const WCHAR szUserInfo[] = {
666 'S','O','F','T','W','A','R','E','\\',
667 'M','i','c','r','o','s','o','f','t','\\',
668 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
669 'U','s','e','r',' ','I','n','f','o',0
670 };
671 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
672 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
673 static const WCHAR szCurrentVersion[] = {
674 'S','O','F','T','W','A','R','E','\\',
675 'M','i','c','r','o','s','o','f','t','\\',
676 'W','i','n','d','o','w','s',' ','N','T','\\',
677 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
678 };
679 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
680 static const WCHAR szRegisteredOrganization[] = {
681 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
682 };
683 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
684 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
685 static const WCHAR szDate[] = {'D','a','t','e',0};
686 static const WCHAR szTime[] = {'T','i','m','e',0};
687 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
688 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
689 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
690 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
691 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
692 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
693 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
694
695 /*
696 * Other things that probably should be set:
697 *
698 * ComputerName VirtualMemory
699 * ShellAdvSupport DefaultUIFont PackagecodeChanging
700 * CaptionHeight BorderTop BorderSide TextHeight
701 * RedirectedDllSupport
702 */
703
704 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
705 strcatW(pth, szBackSlash);
706 msi_set_property(package->db, szCommonAppDataFolder, pth);
707
708 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
709 strcatW(pth, szBackSlash);
710 msi_set_property(package->db, szFavoritesFolder, pth);
711
712 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
713 strcatW(pth, szBackSlash);
714 msi_set_property(package->db, szFontsFolder, pth);
715
716 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
717 strcatW(pth, szBackSlash);
718 msi_set_property(package->db, szSendToFolder, pth);
719
720 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
721 strcatW(pth, szBackSlash);
722 msi_set_property(package->db, szStartMenuFolder, pth);
723
724 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
725 strcatW(pth, szBackSlash);
726 msi_set_property(package->db, szStartupFolder, pth);
727
728 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
729 strcatW(pth, szBackSlash);
730 msi_set_property(package->db, szTemplateFolder, pth);
731
732 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
733 strcatW(pth, szBackSlash);
734 msi_set_property(package->db, szDesktopFolder, pth);
735
736 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
737 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
738 strcatW(pth, szBackSlash);
739 msi_set_property(package->db, szProgramMenuFolder, pth);
740
741 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
742 strcatW(pth, szBackSlash);
743 msi_set_property(package->db, szAdminToolsFolder, pth);
744
745 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
746 strcatW(pth, szBackSlash);
747 msi_set_property(package->db, szAppDataFolder, pth);
748
749 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
750 strcatW(pth, szBackSlash);
751 msi_set_property(package->db, szSystemFolder, pth);
752 msi_set_property(package->db, szSystem16Folder, pth);
753
754 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
755 strcatW(pth, szBackSlash);
756 msi_set_property(package->db, szLocalAppDataFolder, pth);
757
758 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
759 strcatW(pth, szBackSlash);
760 msi_set_property(package->db, szMyPicturesFolder, pth);
761
762 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
763 strcatW(pth, szBackSlash);
764 msi_set_property(package->db, szPersonalFolder, pth);
765
766 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
767 strcatW(pth, szBackSlash);
768 msi_set_property(package->db, szWindowsFolder, pth);
769
770 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
771 strcatW(pth, szBackSlash);
772 msi_set_property(package->db, szPrintHoodFolder, pth);
773
774 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
775 strcatW(pth, szBackSlash);
776 msi_set_property(package->db, szNetHoodFolder, pth);
777
778 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
779 strcatW(pth, szBackSlash);
780 msi_set_property(package->db, szRecentFolder, pth);
781
782 /* Physical Memory is specified in MB. Using total amount. */
783 msex.dwLength = sizeof(msex);
784 GlobalMemoryStatusEx( &msex );
785 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
786 msi_set_property(package->db, szPhysicalMemory, bufstr);
787
788 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
789 ptr = strchrW(pth,'\\');
790 if (ptr) *(ptr + 1) = 0;
791 msi_set_property(package->db, szWindowsVolume, pth);
792
793 GetTempPathW(MAX_PATH,pth);
794 msi_set_property(package->db, szTempFolder, pth);
795
796 /* in a wine environment the user is always admin and privileged */
797 msi_set_property(package->db, szAdminUser, szOne);
798 msi_set_property(package->db, szPrivileged, szOne);
799
800 /* set the os things */
801 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
802 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
803 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
804 sprintfW(verstr, szFormat, verval);
805 switch (OSVersion.dwPlatformId)
806 {
807 case VER_PLATFORM_WIN32_WINDOWS:
808 msi_set_property(package->db, szVersion9x, verstr);
809 break;
810 case VER_PLATFORM_WIN32_NT:
811 msi_set_property(package->db, szVersionNT, verstr);
812 sprintfW(verstr, szFormat,OSVersion.wProductType);
813 msi_set_property(package->db, szMsiNTProductType, verstr);
814 break;
815 }
816 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
817 msi_set_property(package->db, szWindowsBuild, verstr);
818 /* just fudge this */
819 msi_set_property(package->db, szServicePackLevel, szSix);
820
821 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
822 msi_set_property( package->db, szVersionMsi, bufstr );
823 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
824 msi_set_property( package->db, szVersionDatabase, bufstr );
825
826 GetNativeSystemInfo( &sys_info );
827 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
828 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
829 {
830 msi_set_property( package->db, szIntel, bufstr );
831
832 GetSystemDirectoryW( pth, MAX_PATH );
833 PathAddBackslashW( pth );
834 msi_set_property( package->db, szSystemFolder, pth );
835
836 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
837 PathAddBackslashW( pth );
838 msi_set_property( package->db, szProgramFilesFolder, pth );
839
840 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
841 PathAddBackslashW( pth );
842 msi_set_property( package->db, szCommonFilesFolder, pth );
843 }
844 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
845 {
846 msi_set_property( package->db, szMsiAMD64, bufstr );
847 msi_set_property( package->db, szMsix64, bufstr );
848 msi_set_property( package->db, szVersionNT64, verstr );
849
850 GetSystemDirectoryW( pth, MAX_PATH );
851 PathAddBackslashW( pth );
852 msi_set_property( package->db, szSystem64Folder, pth );
853
854 GetSystemWow64DirectoryW( pth, MAX_PATH );
855 PathAddBackslashW( pth );
856 msi_set_property( package->db, szSystemFolder, pth );
857
858 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
859 PathAddBackslashW( pth );
860 msi_set_property( package->db, szProgramFiles64Folder, pth );
861
862 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
863 PathAddBackslashW( pth );
864 msi_set_property( package->db, szProgramFilesFolder, pth );
865
866 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
867 PathAddBackslashW( pth );
868 msi_set_property( package->db, szCommonFiles64Folder, pth );
869
870 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
871 PathAddBackslashW( pth );
872 msi_set_property( package->db, szCommonFilesFolder, pth );
873 }
874
875 /* Screen properties. */
876 dc = GetDC(0);
877 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
878 msi_set_property( package->db, szScreenX, bufstr );
879 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
880 msi_set_property( package->db, szScreenY, bufstr );
881 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
882 msi_set_property( package->db, szColorBits, bufstr );
883 ReleaseDC(0, dc);
884
885 /* USERNAME and COMPANYNAME */
886 username = msi_dup_property( package->db, szUSERNAME );
887 companyname = msi_dup_property( package->db, szCOMPANYNAME );
888
889 if ((!username || !companyname) &&
890 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
891 {
892 if (!username &&
893 (username = msi_reg_get_val_str( hkey, szDefName )))
894 msi_set_property( package->db, szUSERNAME, username );
895 if (!companyname &&
896 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
897 msi_set_property( package->db, szCOMPANYNAME, companyname );
898 CloseHandle( hkey );
899 }
900 if ((!username || !companyname) &&
901 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
902 {
903 if (!username &&
904 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
905 msi_set_property( package->db, szUSERNAME, username );
906 if (!companyname &&
907 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
908 msi_set_property( package->db, szCOMPANYNAME, companyname );
909 CloseHandle( hkey );
910 }
911 msi_free( username );
912 msi_free( companyname );
913
914 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
915 ERR("Failed to set the UserSID property\n");
916
917 /* Date and time properties */
918 GetSystemTime( &systemtime );
919 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
920 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
921 msi_set_property( package->db, szDate, bufstr );
922 else
923 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
924
925 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
926 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
927 &systemtime, NULL, bufstr,
928 sizeof(bufstr)/sizeof(bufstr[0]) ))
929 msi_set_property( package->db, szTime, bufstr );
930 else
931 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
932
933 set_msi_assembly_prop( package );
934
935 langid = GetUserDefaultLangID();
936 sprintfW(bufstr, szIntFormat, langid);
937 msi_set_property( package->db, szUserLanguageID, bufstr );
938
939 langid = GetSystemDefaultLangID();
940 sprintfW(bufstr, szIntFormat, langid);
941 msi_set_property( package->db, szSystemLangID, bufstr );
942
943 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
944 msi_set_property( package->db, szProductState, bufstr );
945
946 len = 0;
947 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_MORE_DATA)
948 {
949 WCHAR *username;
950 if ((username = msi_alloc( len * sizeof(WCHAR) )))
951 {
952 if (GetUserNameW( username, &len ))
953 msi_set_property( package->db, szLogonUser, username );
954 msi_free( username );
955 }
956 }
957 }
958
959 static UINT msi_load_summary_properties( MSIPACKAGE *package )
960 {
961 UINT rc;
962 MSIHANDLE suminfo;
963 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
964 INT count;
965 DWORD len;
966 LPWSTR package_code;
967 static const WCHAR szPackageCode[] = {
968 'P','a','c','k','a','g','e','C','o','d','e',0};
969
970 if (!hdb) {
971 ERR("Unable to allocate handle\n");
972 return ERROR_OUTOFMEMORY;
973 }
974
975 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
976 MsiCloseHandle(hdb);
977 if (rc != ERROR_SUCCESS)
978 {
979 ERR("Unable to open Summary Information\n");
980 return rc;
981 }
982
983 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
984 &count, NULL, NULL, NULL );
985 if (rc != ERROR_SUCCESS)
986 {
987 WARN("Unable to query page count: %d\n", rc);
988 goto done;
989 }
990
991 /* load package code property */
992 len = 0;
993 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
994 NULL, NULL, NULL, &len );
995 if (rc != ERROR_MORE_DATA)
996 {
997 WARN("Unable to query revision number: %d\n", rc);
998 rc = ERROR_FUNCTION_FAILED;
999 goto done;
1000 }
1001
1002 len++;
1003 package_code = msi_alloc( len * sizeof(WCHAR) );
1004 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1005 NULL, NULL, package_code, &len );
1006 if (rc != ERROR_SUCCESS)
1007 {
1008 WARN("Unable to query rev number: %d\n", rc);
1009 goto done;
1010 }
1011
1012 msi_set_property( package->db, szPackageCode, package_code );
1013 msi_free( package_code );
1014
1015 /* load package attributes */
1016 count = 0;
1017 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1018 &count, NULL, NULL, NULL );
1019 package->WordCount = count;
1020
1021 done:
1022 MsiCloseHandle(suminfo);
1023 return rc;
1024 }
1025
1026 static MSIPACKAGE *msi_alloc_package( void )
1027 {
1028 MSIPACKAGE *package;
1029
1030 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1031 MSI_FreePackage );
1032 if( package )
1033 {
1034 list_init( &package->components );
1035 list_init( &package->features );
1036 list_init( &package->files );
1037 list_init( &package->tempfiles );
1038 list_init( &package->folders );
1039 list_init( &package->subscriptions );
1040 list_init( &package->appids );
1041 list_init( &package->classes );
1042 list_init( &package->mimes );
1043 list_init( &package->extensions );
1044 list_init( &package->progids );
1045 list_init( &package->RunningActions );
1046 list_init( &package->sourcelist_info );
1047 list_init( &package->sourcelist_media );
1048 list_init( &package->patches );
1049 }
1050
1051 return package;
1052 }
1053
1054 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1055 {
1056 BYTE *data;
1057 UINT r, sz;
1058
1059 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1060
1061 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1062 if (r != ERROR_SUCCESS)
1063 return r;
1064
1065 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1066
1067 msi_free(data);
1068 return r;
1069 }
1070
1071 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1072 {
1073 /* FIXME: this should depend on the user's privileges */
1074 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1075 {
1076 TRACE("resetting ALLUSERS property from 2 to 1\n");
1077 msi_set_property( package->db, szAllUsers, szOne );
1078 }
1079 msi_set_property( package->db, szAdminUser, szOne );
1080 }
1081
1082 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1083 {
1084 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
1085 static const WCHAR szpi[] = {'%','i',0};
1086 MSIPACKAGE *package;
1087 WCHAR uilevel[10];
1088 UINT r;
1089
1090 TRACE("%p\n", db);
1091
1092 package = msi_alloc_package();
1093 if (package)
1094 {
1095 msiobj_addref( &db->hdr );
1096 package->db = db;
1097
1098 package->WordCount = 0;
1099 package->PackagePath = strdupW( db->path );
1100 package->BaseURL = strdupW( base_url );
1101
1102 create_temp_property_table( package );
1103 msi_clone_properties( package );
1104 msi_adjust_privilege_properties( package );
1105
1106 package->ProductCode = msi_dup_property( package->db, szProductCode );
1107 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1108
1109 set_installed_prop( package );
1110 set_installer_properties( package );
1111
1112 sprintfW(uilevel,szpi,gUILevel);
1113 msi_set_property(package->db, szLevel, uilevel);
1114
1115 r = msi_load_summary_properties( package );
1116 if (r != ERROR_SUCCESS)
1117 {
1118 msiobj_release( &package->hdr );
1119 return NULL;
1120 }
1121
1122 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1123 msi_load_admin_properties( package );
1124 }
1125
1126 return package;
1127 }
1128
1129 /*
1130 * copy_package_to_temp [internal]
1131 *
1132 * copy the msi file to a temp file to prevent locking a CD
1133 * with a multi disc install
1134 *
1135 * FIXME: I think this is wrong, and instead of copying the package,
1136 * we should read all the tables to memory, then open the
1137 * database to read binary streams on demand.
1138 */
1139 static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
1140 {
1141 WCHAR path[MAX_PATH];
1142
1143 GetTempPathW( MAX_PATH, path );
1144 GetTempFileNameW( path, szMsi, 0, filename );
1145
1146 if( !CopyFileW( szPackage, filename, FALSE ) )
1147 {
1148 UINT error = GetLastError();
1149 if ( error == ERROR_FILE_NOT_FOUND )
1150 ERR("can't find %s\n", debugstr_w(szPackage));
1151 else
1152 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
1153 DeleteFileW( filename );
1154 return error;
1155 }
1156
1157 return ERROR_SUCCESS;
1158 }
1159
1160 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1161 {
1162 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1163 DWORD size = 0;
1164 HRESULT hr;
1165
1166 /* call will always fail, becase size is 0,
1167 * but will return ERROR_FILE_NOT_FOUND first
1168 * if the file doesn't exist
1169 */
1170 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1171 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1172 {
1173 cache_entry = msi_alloc( size );
1174 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1175 {
1176 UINT error = GetLastError();
1177 msi_free( cache_entry );
1178 return error;
1179 }
1180
1181 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1182 msi_free( cache_entry );
1183 return ERROR_SUCCESS;
1184 }
1185
1186 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1187 if ( FAILED(hr) )
1188 {
1189 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1190 return ERROR_FUNCTION_FAILED;
1191 }
1192
1193 return ERROR_SUCCESS;
1194 }
1195
1196 UINT msi_get_local_package_name( LPWSTR path, LPCWSTR suffix )
1197 {
1198 static const WCHAR szInstaller[] = {
1199 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1200 static const WCHAR fmt[] = {'%','x',0};
1201 DWORD time, len, i, offset;
1202 HANDLE handle;
1203
1204 time = GetTickCount();
1205 GetWindowsDirectoryW( path, MAX_PATH );
1206 strcatW( path, szInstaller );
1207 CreateDirectoryW( path, NULL );
1208
1209 len = strlenW(path);
1210 for (i = 0; i < 0x10000; i++)
1211 {
1212 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1213 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1214 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1215 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1216 if (handle != INVALID_HANDLE_VALUE)
1217 {
1218 CloseHandle(handle);
1219 break;
1220 }
1221 if (GetLastError() != ERROR_FILE_EXISTS &&
1222 GetLastError() != ERROR_SHARING_VIOLATION)
1223 return ERROR_FUNCTION_FAILED;
1224 }
1225
1226 return ERROR_SUCCESS;
1227 }
1228
1229 static UINT apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
1230 {
1231 UINT r;
1232 DWORD len;
1233 WCHAR patch_file[MAX_PATH];
1234 MSIDATABASE *patch_db;
1235 MSIPATCHINFO *patch_info;
1236 MSISUMMARYINFO *si;
1237
1238 len = sizeof(patch_file) / sizeof(WCHAR);
1239 r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
1240 INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
1241 if (r != ERROR_SUCCESS)
1242 {
1243 ERR("failed to get patch filename %u\n", r);
1244 return r;
1245 }
1246
1247 r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
1248 if (r != ERROR_SUCCESS)
1249 {
1250 ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
1251 return r;
1252 }
1253
1254 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
1255 if (!si)
1256 {
1257 msiobj_release( &patch_db->hdr );
1258 return ERROR_FUNCTION_FAILED;
1259 }
1260
1261 r = msi_parse_patch_summary( si, &patch_info );
1262 msiobj_release( &si->hdr );
1263 if (r != ERROR_SUCCESS)
1264 {
1265 ERR("failed to parse patch summary %u\n", r);
1266 msiobj_release( &patch_db->hdr );
1267 return r;
1268 }
1269
1270 patch_info->localfile = strdupW( patch_file );
1271 if (!patch_info->localfile)
1272 {
1273 msiobj_release( &patch_db->hdr );
1274 return ERROR_OUTOFMEMORY;
1275 }
1276
1277 r = msi_apply_patch_db( package, patch_db, patch_info );
1278 msiobj_release( &patch_db->hdr );
1279 if (r != ERROR_SUCCESS)
1280 {
1281 ERR("failed to apply patch %u\n", r);
1282 msi_free( patch_info->patchcode );
1283 msi_free( patch_info->transforms );
1284 msi_free( patch_info->localfile );
1285 msi_free( patch_info );
1286 }
1287 return r;
1288 }
1289
1290 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1291 {
1292 WCHAR *template, *p, *q;
1293 DWORD i, count;
1294
1295 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1296 TRACE("version: %d\n", package->version);
1297
1298 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1299 if (!template)
1300 return ERROR_SUCCESS; /* native accepts missing template property */
1301
1302 TRACE("template: %s\n", debugstr_w(template));
1303
1304 p = strchrW( template, ';' );
1305 if (!p)
1306 {
1307 WARN("invalid template string %s\n", debugstr_w(template));
1308 msi_free( template );
1309 return ERROR_PATCH_PACKAGE_INVALID;
1310 }
1311 *p = 0;
1312 if (!template[0] || !strcmpW( template, szIntel ))
1313 package->platform = PLATFORM_INTEL;
1314 else if (!strcmpW( template, szIntel64 ))
1315 package->platform = PLATFORM_INTEL64;
1316 else if (!strcmpW( template, szX64 ))
1317 package->platform = PLATFORM_X64;
1318 else
1319 {
1320 WARN("unknown platform %s\n", debugstr_w(template));
1321 msi_free( template );
1322 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1323 }
1324
1325 count = 1;
1326 for (q = ++p; (q = strchrW( q, ',' )); q++) count++;
1327
1328 package->langids = msi_alloc( count * sizeof(LANGID) );
1329 if (!package->langids)
1330 {
1331 msi_free( template );
1332 return ERROR_OUTOFMEMORY;
1333 }
1334
1335 i = 0;
1336 while (*p)
1337 {
1338 q = strchrW( p, ',' );
1339 if (q) *q = 0;
1340 package->langids[i] = atoiW( p );
1341 if (!q) break;
1342 p = q + 1;
1343 i++;
1344 }
1345 package->num_langids = i + 1;
1346
1347 msi_free( template );
1348 return ERROR_SUCCESS;
1349 }
1350
1351 static UINT validate_package( MSIPACKAGE *package )
1352 {
1353 BOOL is_wow64;
1354 UINT i;
1355
1356 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1357 if (package->platform == PLATFORM_X64)
1358 {
1359 if (!is_64bit && !is_wow64)
1360 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1361 if (package->version < 200)
1362 return ERROR_INSTALL_PACKAGE_INVALID;
1363 }
1364 if (!package->num_langids)
1365 {
1366 return ERROR_SUCCESS;
1367 }
1368 for (i = 0; i < package->num_langids; i++)
1369 {
1370 if (!package->langids[i] || IsValidLocale( package->langids[i], LCID_INSTALLED ))
1371 return ERROR_SUCCESS;
1372 }
1373 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1374 }
1375
1376 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1377 {
1378 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
1379 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1380 MSIDATABASE *db = NULL;
1381 MSIPACKAGE *package;
1382 MSIHANDLE handle;
1383 LPWSTR ptr, base_url = NULL;
1384 UINT r;
1385 WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
1386 LPCWSTR file = szPackage;
1387 DWORD index = 0;
1388 MSISUMMARYINFO *si;
1389
1390 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1391
1392 if( szPackage[0] == '#' )
1393 {
1394 handle = atoiW(&szPackage[1]);
1395 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1396 if( !db )
1397 {
1398 IWineMsiRemoteDatabase *remote_database;
1399
1400 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1401 if ( !remote_database )
1402 return ERROR_INVALID_HANDLE;
1403
1404 IWineMsiRemoteDatabase_Release( remote_database );
1405 WARN("MsiOpenPackage not allowed during a custom action!\n");
1406
1407 return ERROR_FUNCTION_FAILED;
1408 }
1409 }
1410 else
1411 {
1412 if ( UrlIsW( szPackage, URLIS_URL ) )
1413 {
1414 r = msi_download_file( szPackage, cachefile );
1415 if ( r != ERROR_SUCCESS )
1416 return r;
1417
1418 r = copy_package_to_temp( cachefile, temppath );
1419 if ( r != ERROR_SUCCESS )
1420 return r;
1421
1422 file = temppath;
1423
1424 base_url = strdupW( szPackage );
1425 if ( !base_url )
1426 return ERROR_OUTOFMEMORY;
1427
1428 ptr = strrchrW( base_url, '/' );
1429 if (ptr) *(ptr + 1) = '\0';
1430 }
1431 else
1432 {
1433 r = copy_package_to_temp( szPackage, temppath );
1434 if ( r != ERROR_SUCCESS )
1435 return r;
1436
1437 file = temppath;
1438 }
1439
1440 r = msi_get_local_package_name( localfile, dotmsi );
1441 if (r != ERROR_SUCCESS)
1442 return r;
1443
1444 TRACE("Copying to local package %s\n", debugstr_w(localfile));
1445
1446 if (!CopyFileW( file, localfile, FALSE ))
1447 {
1448 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1449 debugstr_w(file), debugstr_w(localfile), GetLastError());
1450 return GetLastError();
1451 }
1452
1453 TRACE("Opening relocated package %s\n", debugstr_w( file ));
1454
1455 /* transforms that add binary streams require that we open the database
1456 * read/write, which is safe because we always create a copy that is thrown
1457 * away when we're done.
1458 */
1459 r = MSI_OpenDatabaseW( file, MSIDBOPEN_TRANSACT, &db );
1460 if( r != ERROR_SUCCESS )
1461 {
1462 if (file != szPackage)
1463 DeleteFileW( file );
1464
1465 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
1466 return ERROR_FILE_NOT_FOUND;
1467
1468 return r;
1469 }
1470
1471 db->localfile = strdupW( localfile );
1472 }
1473
1474 package = MSI_CreatePackage( db, base_url );
1475 msi_free( base_url );
1476 msiobj_release( &db->hdr );
1477 if( !package )
1478 {
1479 if (file != szPackage)
1480 DeleteFileW( file );
1481
1482 return ERROR_INSTALL_PACKAGE_INVALID;
1483 }
1484
1485 if( file != szPackage )
1486 track_tempfile( package, file );
1487
1488 si = MSI_GetSummaryInformationW( db->storage, 0 );
1489 if (!si)
1490 {
1491 WARN("failed to load summary info %u\n", r);
1492 msiobj_release( &package->hdr );
1493 return ERROR_INSTALL_PACKAGE_INVALID;
1494 }
1495
1496 r = msi_parse_summary( si, package );
1497 msiobj_release( &si->hdr );
1498 if (r != ERROR_SUCCESS)
1499 {
1500 WARN("failed to parse summary info %u\n", r);
1501 msiobj_release( &package->hdr );
1502 return r;
1503 }
1504
1505 r = validate_package( package );
1506 if (r != ERROR_SUCCESS)
1507 {
1508 msiobj_release( &package->hdr );
1509 return r;
1510 }
1511 msi_set_property( package->db, Database, db->path );
1512
1513 if( UrlIsW( szPackage, URLIS_URL ) )
1514 msi_set_property( package->db, szOriginalDatabase, szPackage );
1515 else if( szPackage[0] == '#' )
1516 msi_set_property( package->db, szOriginalDatabase, db->path );
1517 else
1518 {
1519 WCHAR fullpath[MAX_PATH];
1520
1521 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1522 msi_set_property( package->db, szOriginalDatabase, fullpath );
1523 }
1524
1525 msi_set_context( package );
1526
1527 while (1)
1528 {
1529 WCHAR patch_code[GUID_SIZE];
1530 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1531 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1532 if (r != ERROR_SUCCESS)
1533 break;
1534
1535 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1536
1537 r = apply_registered_patch( package, patch_code );
1538 if (r != ERROR_SUCCESS)
1539 {
1540 ERR("registered patch failed to apply %u\n", r);
1541 msiobj_release( &package->hdr );
1542 return r;
1543 }
1544
1545 index++;
1546 }
1547
1548 if (index)
1549 {
1550 msi_clone_properties( package );
1551 msi_adjust_privilege_properties( package );
1552 }
1553
1554 *pPackage = package;
1555 return ERROR_SUCCESS;
1556 }
1557
1558 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1559 {
1560 MSIPACKAGE *package = NULL;
1561 UINT ret;
1562
1563 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1564
1565 if( !szPackage || !phPackage )
1566 return ERROR_INVALID_PARAMETER;
1567
1568 if ( !*szPackage )
1569 {
1570 FIXME("Should create an empty database and package\n");
1571 return ERROR_FUNCTION_FAILED;
1572 }
1573
1574 if( dwOptions )
1575 FIXME("dwOptions %08x not supported\n", dwOptions);
1576
1577 ret = MSI_OpenPackageW( szPackage, &package );
1578 if( ret == ERROR_SUCCESS )
1579 {
1580 *phPackage = alloc_msihandle( &package->hdr );
1581 if (! *phPackage)
1582 ret = ERROR_NOT_ENOUGH_MEMORY;
1583 msiobj_release( &package->hdr );
1584 }
1585
1586 return ret;
1587 }
1588
1589 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1590 {
1591 return MsiOpenPackageExW( szPackage, 0, phPackage );
1592 }
1593
1594 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1595 {
1596 LPWSTR szwPack = NULL;
1597 UINT ret;
1598
1599 if( szPackage )
1600 {
1601 szwPack = strdupAtoW( szPackage );
1602 if( !szwPack )
1603 return ERROR_OUTOFMEMORY;
1604 }
1605
1606 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1607
1608 msi_free( szwPack );
1609
1610 return ret;
1611 }
1612
1613 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1614 {
1615 return MsiOpenPackageExA( szPackage, 0, phPackage );
1616 }
1617
1618 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1619 {
1620 MSIPACKAGE *package;
1621 MSIHANDLE handle = 0;
1622 IUnknown *remote_unk;
1623 IWineMsiRemotePackage *remote_package;
1624
1625 TRACE("(%d)\n",hInstall);
1626
1627 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1628 if( package)
1629 {
1630 handle = alloc_msihandle( &package->db->hdr );
1631 msiobj_release( &package->hdr );
1632 }
1633 else if ((remote_unk = msi_get_remote(hInstall)))
1634 {
1635 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1636 (LPVOID *)&remote_package) == S_OK)
1637 {
1638 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1639 IWineMsiRemotePackage_Release(remote_package);
1640 }
1641 else
1642 {
1643 WARN("remote handle %d is not a package\n", hInstall);
1644 }
1645 IUnknown_Release(remote_unk);
1646 }
1647
1648 return handle;
1649 }
1650
1651 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType,
1652 MSIRECORD *record)
1653 {
1654 static const WCHAR szActionData[] =
1655 {'A','c','t','i','o','n','D','a','t','a',0};
1656 static const WCHAR szSetProgress[] =
1657 {'S','e','t','P','r','o','g','r','e','s','s',0};
1658 static const WCHAR szActionText[] =
1659 {'A','c','t','i','o','n','T','e','x','t',0};
1660 DWORD log_type = 0;
1661 LPWSTR message;
1662 DWORD sz;
1663 DWORD total_size = 0;
1664 INT i;
1665 INT rc;
1666 char *msg;
1667 int len;
1668
1669 TRACE("%x\n", eMessageType);
1670 rc = 0;
1671
1672 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1673 log_type |= INSTALLLOGMODE_ERROR;
1674 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1675 log_type |= INSTALLLOGMODE_WARNING;
1676 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1677 log_type |= INSTALLLOGMODE_USER;
1678 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1679 log_type |= INSTALLLOGMODE_INFO;
1680 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1681 log_type |= INSTALLLOGMODE_COMMONDATA;
1682 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1683 log_type |= INSTALLLOGMODE_ACTIONSTART;
1684 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1685 log_type |= INSTALLLOGMODE_ACTIONDATA;
1686 /* just a guess */
1687 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1688 log_type |= 0x800;
1689
1690 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1691 {
1692 static const WCHAR template_s[]=
1693 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1694 static const WCHAR format[] =
1695 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1696 WCHAR timet[0x100];
1697 LPCWSTR action_text, action;
1698 LPWSTR deformatted = NULL;
1699
1700 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1701
1702 action = MSI_RecordGetString(record, 1);
1703 action_text = MSI_RecordGetString(record, 2);
1704
1705 if (!action || !action_text)
1706 return IDOK;
1707
1708 deformat_string(package, action_text, &deformatted);
1709
1710 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1711 if (deformatted)
1712 len += strlenW(deformatted);
1713 message = msi_alloc(len*sizeof(WCHAR));
1714 sprintfW(message, template_s, timet, action);
1715 if (deformatted)
1716 strcatW(message, deformatted);
1717 msi_free(deformatted);
1718 }
1719 else
1720 {
1721 INT msg_field=1;
1722 message = msi_alloc(1*sizeof (WCHAR));
1723 message[0]=0;
1724 msg_field = MSI_RecordGetFieldCount(record);
1725 for (i = 1; i <= msg_field; i++)
1726 {
1727 LPWSTR tmp;
1728 WCHAR number[3];
1729 static const WCHAR format[] = { '%','i',':',' ',0};
1730 sz = 0;
1731 MSI_RecordGetStringW(record,i,NULL,&sz);
1732 sz+=4;
1733 total_size+=sz*sizeof(WCHAR);
1734 tmp = msi_alloc(sz*sizeof(WCHAR));
1735 message = msi_realloc(message,total_size*sizeof (WCHAR));
1736
1737 MSI_RecordGetStringW(record,i,tmp,&sz);
1738
1739 if (msg_field > 1)
1740 {
1741 sprintfW(number,format,i);
1742 strcatW(message,number);
1743 }
1744 strcatW(message,tmp);
1745 if (msg_field > 1)
1746 strcatW(message, szSpace);
1747
1748 msi_free(tmp);
1749 }
1750 }
1751
1752 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1753 gUIFilter, log_type, debugstr_w(message));
1754
1755 /* convert it to ASCII */
1756 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1757 msg = msi_alloc( len );
1758 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1759
1760 if (gUIHandlerW && (gUIFilter & log_type))
1761 {
1762 rc = gUIHandlerW( gUIContext, eMessageType, message );
1763 }
1764 else if (gUIHandlerA && (gUIFilter & log_type))
1765 {
1766 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1767 }
1768 else if (gUIHandlerRecord && (gUIFilter & log_type))
1769 {
1770 MSIHANDLE rec = MsiCreateRecord( 1 );
1771 MsiRecordSetStringW( rec, 0, message );
1772 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1773 MsiCloseHandle( rec );
1774 }
1775
1776 if ((!rc) && (gszLogFile[0]) && !((eMessageType & 0xff000000) ==
1777 INSTALLMESSAGE_PROGRESS))
1778 {
1779 DWORD write;
1780 HANDLE log_file = CreateFileW(gszLogFile,GENERIC_WRITE, 0, NULL,
1781 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1782
1783 if (log_file != INVALID_HANDLE_VALUE)
1784 {
1785 SetFilePointer(log_file,0, NULL, FILE_END);
1786 WriteFile(log_file,msg,strlen(msg),&write,NULL);
1787 WriteFile(log_file,"\n",1,&write,NULL);
1788 CloseHandle(log_file);
1789 }
1790 }
1791 msi_free( msg );
1792 msi_free( message );
1793
1794 switch (eMessageType & 0xff000000)
1795 {
1796 case INSTALLMESSAGE_ACTIONDATA:
1797 /* FIXME: format record here instead of in ui_actiondata to get the
1798 * correct action data for external scripts */
1799 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1800 break;
1801 case INSTALLMESSAGE_ACTIONSTART:
1802 {
1803 MSIRECORD *uirow;
1804 LPWSTR deformated;
1805 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1806
1807 deformat_string(package, action_text, &deformated);
1808 uirow = MSI_CreateRecord(1);
1809 MSI_RecordSetStringW(uirow, 1, deformated);
1810 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1811 msi_free(deformated);
1812
1813 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1814
1815 msiobj_release(&uirow->hdr);
1816 break;
1817 }
1818 case INSTALLMESSAGE_PROGRESS:
1819 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1820 break;
1821 }
1822
1823 return ERROR_SUCCESS;
1824 }
1825
1826 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1827 MSIHANDLE hRecord)
1828 {
1829 UINT ret = ERROR_INVALID_HANDLE;
1830 MSIPACKAGE *package = NULL;
1831 MSIRECORD *record = NULL;
1832
1833 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1834 if( !package )
1835 {
1836 HRESULT hr;
1837 IWineMsiRemotePackage *remote_package;
1838
1839 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1840 if (!remote_package)
1841 return ERROR_INVALID_HANDLE;
1842
1843 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1844
1845 IWineMsiRemotePackage_Release( remote_package );
1846
1847 if (FAILED(hr))
1848 {
1849 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1850 return HRESULT_CODE(hr);
1851
1852 return ERROR_FUNCTION_FAILED;
1853 }
1854
1855 return ERROR_SUCCESS;
1856 }
1857
1858 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1859 if( !record )
1860 goto out;
1861
1862 ret = MSI_ProcessMessage( package, eMessageType, record );
1863
1864 out:
1865 msiobj_release( &package->hdr );
1866 if( record )
1867 msiobj_release( &record->hdr );
1868
1869 return ret;
1870 }
1871
1872 /* property code */
1873
1874 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1875 {
1876 LPWSTR szwName = NULL, szwValue = NULL;
1877 UINT r = ERROR_OUTOFMEMORY;
1878
1879 szwName = strdupAtoW( szName );
1880 if( szName && !szwName )
1881 goto end;
1882
1883 szwValue = strdupAtoW( szValue );
1884 if( szValue && !szwValue )
1885 goto end;
1886
1887 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1888
1889 end:
1890 msi_free( szwName );
1891 msi_free( szwValue );
1892
1893 return r;
1894 }
1895
1896 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1897 {
1898 MSIFOLDER *folder;
1899
1900 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1901 {
1902 if ( source )
1903 {
1904 msi_free( folder->ResolvedSource );
1905 folder->ResolvedSource = NULL;
1906 }
1907 else
1908 {
1909 msi_free( folder->ResolvedTarget );
1910 folder->ResolvedTarget = NULL;
1911 }
1912 }
1913 }
1914
1915 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1916 {
1917 MSIQUERY *view;
1918 MSIRECORD *row = NULL;
1919 UINT rc;
1920 DWORD sz = 0;
1921 WCHAR Query[1024];
1922
1923 static const WCHAR Insert[] = {
1924 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1925 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1926 '`','_','P','r','o','p','e','r','t','y','`',',',
1927 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1928 ,' ','(','?',',','?',')',0};
1929 static const WCHAR Update[] = {
1930 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1931 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1932 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1933 ' ','=',' ','\'','%','s','\'',0};
1934 static const WCHAR Delete[] = {
1935 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1936 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1937 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1938
1939 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
1940
1941 if (!szName)
1942 return ERROR_INVALID_PARAMETER;
1943
1944 /* this one is weird... */
1945 if (!szName[0])
1946 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
1947
1948 rc = msi_get_property(db, szName, 0, &sz);
1949 if (!szValue || !*szValue)
1950 {
1951 sprintfW(Query, Delete, szName);
1952 }
1953 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
1954 {
1955 sprintfW(Query, Update, szName);
1956
1957 row = MSI_CreateRecord(1);
1958 MSI_RecordSetStringW(row, 1, szValue);
1959 }
1960 else
1961 {
1962 strcpyW(Query, Insert);
1963
1964 row = MSI_CreateRecord(2);
1965 MSI_RecordSetStringW(row, 1, szName);
1966 MSI_RecordSetStringW(row, 2, szValue);
1967 }
1968
1969 rc = MSI_DatabaseOpenViewW(db, Query, &view);
1970 if (rc == ERROR_SUCCESS)
1971 {
1972 rc = MSI_ViewExecute(view, row);
1973 MSI_ViewClose(view);
1974 msiobj_release(&view->hdr);
1975 }
1976
1977 if (row)
1978 msiobj_release(&row->hdr);
1979
1980 return rc;
1981 }
1982
1983 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
1984 {
1985 MSIPACKAGE *package;
1986 UINT ret;
1987
1988 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1989 if( !package )
1990 {
1991 HRESULT hr;
1992 BSTR name = NULL, value = NULL;
1993 IWineMsiRemotePackage *remote_package;
1994
1995 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1996 if (!remote_package)
1997 return ERROR_INVALID_HANDLE;
1998
1999 name = SysAllocString( szName );
2000 value = SysAllocString( szValue );
2001 if ((!name && szName) || (!value && szValue))
2002 {
2003 SysFreeString( name );
2004 SysFreeString( value );
2005 IWineMsiRemotePackage_Release( remote_package );
2006 return ERROR_OUTOFMEMORY;
2007 }
2008
2009 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2010
2011 SysFreeString( name );
2012 SysFreeString( value );
2013 IWineMsiRemotePackage_Release( remote_package );
2014
2015 if (FAILED(hr))
2016 {
2017 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2018 return HRESULT_CODE(hr);
2019
2020 return ERROR_FUNCTION_FAILED;
2021 }
2022
2023 return ERROR_SUCCESS;
2024 }
2025
2026 ret = msi_set_property( package->db, szName, szValue );
2027 if (ret == ERROR_SUCCESS && !strcmpW( szName, cszSourceDir ))
2028 msi_reset_folders( package, TRUE );
2029
2030 msiobj_release( &package->hdr );
2031 return ret;
2032 }
2033
2034 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2035 {
2036 MSIQUERY *view;
2037 MSIRECORD *rec, *row = NULL;
2038 UINT r;
2039
2040 static const WCHAR query[]= {
2041 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2042 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2043 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2044 '=','?',0};
2045
2046 if (!name || !*name)
2047 return NULL;
2048
2049 rec = MSI_CreateRecord(1);
2050 if (!rec)
2051 return NULL;
2052
2053 MSI_RecordSetStringW(rec, 1, name);
2054
2055 r = MSI_DatabaseOpenViewW(db, query, &view);
2056 if (r == ERROR_SUCCESS)
2057 {
2058 MSI_ViewExecute(view, rec);
2059 MSI_ViewFetch(view, &row);
2060 MSI_ViewClose(view);
2061 msiobj_release(&view->hdr);
2062 }
2063
2064 msiobj_release(&rec->hdr);
2065 return row;
2066 }
2067
2068 /* internal function, not compatible with MsiGetPropertyW */
2069 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2070 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2071 {
2072 MSIRECORD *row;
2073 UINT rc = ERROR_FUNCTION_FAILED;
2074
2075 row = msi_get_property_row( db, szName );
2076
2077 if (*pchValueBuf > 0)
2078 szValueBuf[0] = 0;
2079
2080 if (row)
2081 {
2082 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2083 msiobj_release(&row->hdr);
2084 }
2085
2086 if (rc == ERROR_SUCCESS)
2087 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2088 debugstr_w(szName));
2089 else if (rc == ERROR_MORE_DATA)
2090 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2091 debugstr_w(szName));
2092 else
2093 {
2094 *pchValueBuf = 0;
2095 TRACE("property %s not found\n", debugstr_w(szName));
2096 }
2097
2098 return rc;
2099 }
2100
2101 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2102 {
2103 DWORD sz = 0;
2104 LPWSTR str;
2105 UINT r;
2106
2107 r = msi_get_property(db, prop, NULL, &sz);
2108 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2109 return NULL;
2110
2111 sz++;
2112 str = msi_alloc(sz * sizeof(WCHAR));
2113 r = msi_get_property(db, prop, str, &sz);
2114 if (r != ERROR_SUCCESS)
2115 {
2116 msi_free(str);
2117 str = NULL;
2118 }
2119
2120 return str;
2121 }
2122
2123 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2124 {
2125 LPWSTR str = msi_dup_property( db, prop );
2126 int val = str ? atoiW(str) : def;
2127 msi_free(str);
2128 return val;
2129 }
2130
2131 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2132 awstring *szValueBuf, LPDWORD pchValueBuf )
2133 {
2134 MSIPACKAGE *package;
2135 MSIRECORD *row = NULL;
2136 UINT r = ERROR_FUNCTION_FAILED;
2137 LPCWSTR val = NULL;
2138
2139 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2140 szValueBuf->str.w, pchValueBuf );
2141
2142 if (!name)
2143 return ERROR_INVALID_PARAMETER;
2144
2145 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2146 if (!package)
2147 {
2148 HRESULT hr;
2149 IWineMsiRemotePackage *remote_package;
2150 LPWSTR value = NULL;
2151 BSTR bname;
2152 DWORD len;
2153
2154 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2155 if (!remote_package)
2156 return ERROR_INVALID_HANDLE;
2157
2158 bname = SysAllocString( name );
2159 if (!bname)
2160 {
2161 IWineMsiRemotePackage_Release( remote_package );
2162 return ERROR_OUTOFMEMORY;
2163 }
2164
2165 len = 0;
2166 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2167 if (FAILED(hr))
2168 goto done;
2169
2170 len++;
2171 value = msi_alloc(len * sizeof(WCHAR));
2172 if (!value)
2173 {
2174 r = ERROR_OUTOFMEMORY;
2175 goto done;
2176 }
2177
2178 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
2179 if (FAILED(hr))
2180 goto done;
2181
2182 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2183
2184 /* Bug required by Adobe installers */
2185 if (!szValueBuf->unicode && !szValueBuf->str.a)
2186 *pchValueBuf *= sizeof(WCHAR);
2187
2188 done:
2189 IWineMsiRemotePackage_Release(remote_package);
2190 SysFreeString(bname);
2191 msi_free(value);
2192
2193 if (FAILED(hr))
2194 {
2195 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2196 return HRESULT_CODE(hr);
2197
2198 return ERROR_FUNCTION_FAILED;
2199 }
2200
2201 return r;
2202 }
2203
2204 row = msi_get_property_row( package->db, name );
2205 if (row)
2206 val = MSI_RecordGetString( row, 1 );
2207
2208 if (!val)
2209 val = szEmpty;
2210
2211 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2212
2213 if (row)
2214 msiobj_release( &row->hdr );
2215 msiobj_release( &package->hdr );
2216
2217 return r;
2218 }
2219
2220 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2221 LPSTR szValueBuf, LPDWORD pchValueBuf )
2222 {
2223 awstring val;
2224 LPWSTR name;
2225 UINT r;
2226
2227 val.unicode = FALSE;
2228 val.str.a = szValueBuf;
2229
2230 name = strdupAtoW( szName );
2231 if (szName && !name)
2232 return ERROR_OUTOFMEMORY;
2233
2234 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2235 msi_free( name );
2236 return r;
2237 }
2238
2239 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2240 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2241 {
2242 awstring val;
2243
2244 val.unicode = TRUE;
2245 val.str.w = szValueBuf;
2246
2247 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2248 }
2249
2250 typedef struct _msi_remote_package_impl {
2251 const IWineMsiRemotePackageVtbl *lpVtbl;
2252 MSIHANDLE package;
2253 LONG refs;
2254 } msi_remote_package_impl;
2255
2256 static inline msi_remote_package_impl* mrp_from_IWineMsiRemotePackage( IWineMsiRemotePackage* iface )
2257 {
2258 return (msi_remote_package_impl*) iface;
2259 }
2260
2261 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2262 REFIID riid,LPVOID *ppobj)
2263 {
2264 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2265 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2266 {
2267 IUnknown_AddRef( iface );
2268 *ppobj = iface;
2269 return S_OK;
2270 }
2271
2272 return E_NOINTERFACE;
2273 }
2274
2275 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2276 {
2277 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2278
2279 return InterlockedIncrement( &This->refs );
2280 }
2281
2282 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2283 {
2284 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2285 ULONG r;
2286
2287 r = InterlockedDecrement( &This->refs );
2288 if (r == 0)
2289 {
2290 MsiCloseHandle( This->package );
2291 msi_free( This );
2292 }
2293 return r;
2294 }
2295
2296 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2297 {
2298 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2299 This->package = handle;
2300 return S_OK;
2301 }
2302
2303 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2304 {
2305 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2306 IWineMsiRemoteDatabase *rdb = NULL;
2307 HRESULT hr;
2308 MSIHANDLE hdb;
2309
2310 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2311 if (FAILED(hr) || !rdb)
2312 {
2313 ERR("Failed to create remote database\n");
2314 return hr;
2315 }
2316
2317 hdb = MsiGetActiveDatabase(This->package);
2318
2319 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2320 if (FAILED(hr))
2321 {
2322 ERR("Failed to set the database handle\n");
2323 return hr;
2324 }
2325
2326 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2327 return S_OK;
2328 }
2329
2330 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
2331 {
2332 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2333 UINT r;
2334
2335 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
2336 if (r != ERROR_SUCCESS)
2337 return HRESULT_FROM_WIN32(r);
2338
2339 return S_OK;
2340 }
2341
2342 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2343 {
2344 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2345 UINT r = MsiSetPropertyW(This->package, property, value);
2346 return HRESULT_FROM_WIN32(r);
2347 }
2348
2349 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2350 {
2351 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2352 UINT r = MsiProcessMessage(This->package, message, record);
2353 return HRESULT_FROM_WIN32(r);
2354 }
2355
2356 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2357 {
2358 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2359 UINT r = MsiDoActionW(This->package, action);
2360 return HRESULT_FROM_WIN32(r);
2361 }
2362
2363 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2364 {
2365 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2366 UINT r = MsiSequenceW(This->package, table, sequence);
2367 return HRESULT_FROM_WIN32(r);
2368 }
2369
2370 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2371 {
2372 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2373 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2374 return HRESULT_FROM_WIN32(r);
2375 }
2376
2377 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2378 {
2379 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2380 UINT r = MsiSetTargetPathW(This->package, folder, value);
2381 return HRESULT_FROM_WIN32(r);
2382 }
2383
2384 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2385 {
2386 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2387 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2388 return HRESULT_FROM_WIN32(r);
2389 }
2390
2391 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2392 {
2393 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2394 *ret = MsiGetMode(This->package, mode);
2395 return S_OK;
2396 }
2397
2398 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2399 {
2400 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2401 UINT r = MsiSetMode(This->package, mode, state);
2402 return HRESULT_FROM_WIN32(r);
2403 }
2404
2405 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2406 INSTALLSTATE *installed, INSTALLSTATE *action )
2407 {
2408 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2409 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2410 return HRESULT_FROM_WIN32(r);
2411 }
2412
2413 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2414 {
2415 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2416 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2417 return HRESULT_FROM_WIN32(r);
2418 }
2419
2420 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2421 INSTALLSTATE *installed, INSTALLSTATE *action )
2422 {
2423 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2424 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2425 return HRESULT_FROM_WIN32(r);
2426 }
2427
2428 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2429 {
2430 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2431 UINT r = MsiSetComponentStateW(This->package, component, state);
2432 return HRESULT_FROM_WIN32(r);
2433 }
2434
2435 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2436 {
2437 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2438 *language = MsiGetLanguage(This->package);
2439 return S_OK;
2440 }
2441
2442 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2443 {
2444 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2445 UINT r = MsiSetInstallLevel(This->package, level);
2446 return HRESULT_FROM_WIN32(r);
2447 }
2448
2449 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2450 BSTR *value)
2451 {
2452 DWORD size = 0;
2453 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2454 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2455 if (r == ERROR_SUCCESS)
2456 {
2457 *value = SysAllocStringLen(NULL, size);
2458 if (!*value)
2459 return E_OUTOFMEMORY;
2460 size++;
2461 r = MsiFormatRecordW(This->package, record, *value, &size);
2462 }
2463 return HRESULT_FROM_WIN32(r);
2464 }
2465
2466 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2467 {
2468 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2469 UINT r = MsiEvaluateConditionW(This->package, condition);
2470 return HRESULT_FROM_WIN32(r);
2471 }
2472
2473 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2474 INT cost_tree, INSTALLSTATE state, INT *cost )
2475 {
2476 msi_remote_package_impl* This = mrp_from_IWineMsiRemotePackage( iface );
2477 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2478 return HRESULT_FROM_WIN32(r);
2479 }
2480
2481 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2482 {
2483 mrp_QueryInterface,
2484 mrp_AddRef,
2485 mrp_Release,
2486 mrp_SetMsiHandle,
2487 mrp_GetActiveDatabase,
2488 mrp_GetProperty,
2489 mrp_SetProperty,
2490 mrp_ProcessMessage,
2491 mrp_DoAction,
2492 mrp_Sequence,
2493 mrp_GetTargetPath,
2494 mrp_SetTargetPath,
2495 mrp_GetSourcePath,
2496 mrp_GetMode,
2497 mrp_SetMode,
2498 mrp_GetFeatureState,
2499 mrp_SetFeatureState,
2500 mrp_GetComponentState,
2501 mrp_SetComponentState,
2502 mrp_GetLanguage,
2503 mrp_SetInstallLevel,
2504 mrp_FormatRecord,
2505 mrp_EvaluateCondition,
2506 mrp_GetFeatureCost,
2507 };
2508
2509 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2510 {
2511 msi_remote_package_impl* This;
2512
2513 This = msi_alloc( sizeof *This );
2514 if (!This)
2515 return E_OUTOFMEMORY;
2516
2517 This->lpVtbl = &msi_remote_package_vtbl;
2518 This->package = 0;
2519 This->refs = 1;
2520
2521 *ppObj = This;
2522
2523 return S_OK;
2524 }
2525
2526 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2527 LPCWSTR property, LPWSTR value)
2528 {
2529 MSISOURCELISTINFO *info;
2530
2531 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2532 if (!info)
2533 return ERROR_OUTOFMEMORY;
2534
2535 info->context = context;
2536 info->options = options;
2537 info->property = property;
2538 info->value = strdupW(value);
2539 list_add_head(&package->sourcelist_info, &info->entry);
2540
2541 return ERROR_SUCCESS;
2542 }
2543
2544 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2545 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2546 {
2547 MSIMEDIADISK *disk;
2548
2549 disk = msi_alloc(sizeof(MSIMEDIADISK));
2550 if (!disk)
2551 return ERROR_OUTOFMEMORY;
2552
2553 disk->context = context;
2554 disk->options = options;
2555 disk->disk_id = disk_id;
2556 disk->volume_label = strdupW(volume_label);
2557 disk->disk_prompt = strdupW(disk_prompt);
2558 list_add_head(&package->sourcelist_media, &disk->entry);
2559
2560 return ERROR_SUCCESS;
2561 }