winecoreaudio.drv: Add mmdevapi driver.
[wine/multimedia.git] / dlls / msi / package.c
blobbad8ab35501d6dad6cd8784a06bd1da98cd81964
1 /*
2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2004 Aric Stewart for CodeWeavers
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.
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.
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
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
23 #define COBJMACROS
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"
47 #include "msipriv.h"
48 #include "msiserver.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msi);
52 static void remove_tracked_tempfiles( MSIPACKAGE *package )
54 struct list *item, *cursor;
56 LIST_FOR_EACH_SAFE( item, cursor, &package->tempfiles )
58 MSITEMPFILE *temp = LIST_ENTRY( item, MSITEMPFILE, entry );
60 list_remove( &temp->entry );
61 TRACE("deleting temp file %s\n", debugstr_w( temp->Path ));
62 DeleteFileW( temp->Path );
63 msi_free( temp->Path );
64 msi_free( temp );
68 static void free_feature( MSIFEATURE *feature )
70 struct list *item, *cursor;
72 LIST_FOR_EACH_SAFE( item, cursor, &feature->Children )
74 FeatureList *fl = LIST_ENTRY( item, FeatureList, entry );
75 list_remove( &fl->entry );
76 msi_free( fl );
79 LIST_FOR_EACH_SAFE( item, cursor, &feature->Components )
81 ComponentList *cl = LIST_ENTRY( item, ComponentList, entry );
82 list_remove( &cl->entry );
83 msi_free( cl );
85 msi_free( feature->Feature );
86 msi_free( feature->Feature_Parent );
87 msi_free( feature->Directory );
88 msi_free( feature->Description );
89 msi_free( feature->Title );
90 msi_free( feature );
93 static void free_extension( MSIEXTENSION *ext )
95 struct list *item, *cursor;
97 LIST_FOR_EACH_SAFE( item, cursor, &ext->verbs )
99 MSIVERB *verb = LIST_ENTRY( item, MSIVERB, entry );
101 list_remove( &verb->entry );
102 msi_free( verb->Verb );
103 msi_free( verb->Command );
104 msi_free( verb->Argument );
105 msi_free( verb );
108 msi_free( ext->Extension );
109 msi_free( ext->ProgIDText );
110 msi_free( ext );
113 static void free_assembly( MSIASSEMBLY *assembly )
115 msi_free( assembly->feature );
116 msi_free( assembly->manifest );
117 msi_free( assembly->application );
118 msi_free( assembly->display_name );
119 if (assembly->tempdir) RemoveDirectoryW( assembly->tempdir );
120 msi_free( assembly->tempdir );
121 msi_free( assembly );
124 static void free_package_structures( MSIPACKAGE *package )
126 INT i;
127 struct list *item, *cursor;
129 TRACE("Freeing package action data\n");
131 remove_tracked_tempfiles(package);
133 LIST_FOR_EACH_SAFE( item, cursor, &package->features )
135 MSIFEATURE *feature = LIST_ENTRY( item, MSIFEATURE, entry );
136 list_remove( &feature->entry );
137 free_feature( feature );
140 LIST_FOR_EACH_SAFE( item, cursor, &package->folders )
142 MSIFOLDER *folder = LIST_ENTRY( item, MSIFOLDER, entry );
144 list_remove( &folder->entry );
145 msi_free( folder->Parent );
146 msi_free( folder->Directory );
147 msi_free( folder->TargetDefault );
148 msi_free( folder->SourceLongPath );
149 msi_free( folder->SourceShortPath );
150 msi_free( folder->ResolvedTarget );
151 msi_free( folder->ResolvedSource );
152 msi_free( folder->Property );
153 msi_free( folder );
156 LIST_FOR_EACH_SAFE( item, cursor, &package->components )
158 MSICOMPONENT *comp = LIST_ENTRY( item, MSICOMPONENT, entry );
160 list_remove( &comp->entry );
161 msi_free( comp->Component );
162 msi_free( comp->ComponentId );
163 msi_free( comp->Directory );
164 msi_free( comp->Condition );
165 msi_free( comp->KeyPath );
166 msi_free( comp->FullKeypath );
167 if (comp->assembly) free_assembly( comp->assembly );
168 msi_free( comp );
171 LIST_FOR_EACH_SAFE( item, cursor, &package->files )
173 MSIFILE *file = LIST_ENTRY( item, MSIFILE, entry );
175 list_remove( &file->entry );
176 msi_free( file->File );
177 msi_free( file->FileName );
178 msi_free( file->ShortName );
179 msi_free( file->LongName );
180 msi_free( file->Version );
181 msi_free( file->Language );
182 msi_free( file->TargetPath );
183 msi_free( file );
186 /* clean up extension, progid, class and verb structures */
187 LIST_FOR_EACH_SAFE( item, cursor, &package->classes )
189 MSICLASS *cls = LIST_ENTRY( item, MSICLASS, entry );
191 list_remove( &cls->entry );
192 msi_free( cls->clsid );
193 msi_free( cls->Context );
194 msi_free( cls->Description );
195 msi_free( cls->FileTypeMask );
196 msi_free( cls->IconPath );
197 msi_free( cls->DefInprocHandler );
198 msi_free( cls->DefInprocHandler32 );
199 msi_free( cls->Argument );
200 msi_free( cls->ProgIDText );
201 msi_free( cls );
204 LIST_FOR_EACH_SAFE( item, cursor, &package->extensions )
206 MSIEXTENSION *ext = LIST_ENTRY( item, MSIEXTENSION, entry );
208 list_remove( &ext->entry );
209 free_extension( ext );
212 LIST_FOR_EACH_SAFE( item, cursor, &package->progids )
214 MSIPROGID *progid = LIST_ENTRY( item, MSIPROGID, entry );
216 list_remove( &progid->entry );
217 msi_free( progid->ProgID );
218 msi_free( progid->Description );
219 msi_free( progid->IconPath );
220 msi_free( progid );
223 LIST_FOR_EACH_SAFE( item, cursor, &package->mimes )
225 MSIMIME *mt = LIST_ENTRY( item, MSIMIME, entry );
227 list_remove( &mt->entry );
228 msi_free( mt->suffix );
229 msi_free( mt->clsid );
230 msi_free( mt->ContentType );
231 msi_free( mt );
234 LIST_FOR_EACH_SAFE( item, cursor, &package->appids )
236 MSIAPPID *appid = LIST_ENTRY( item, MSIAPPID, entry );
238 list_remove( &appid->entry );
239 msi_free( appid->AppID );
240 msi_free( appid->RemoteServerName );
241 msi_free( appid->LocalServer );
242 msi_free( appid->ServiceParameters );
243 msi_free( appid->DllSurrogate );
244 msi_free( appid );
247 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_info )
249 MSISOURCELISTINFO *info = LIST_ENTRY( item, MSISOURCELISTINFO, entry );
251 list_remove( &info->entry );
252 msi_free( info->value );
253 msi_free( info );
256 LIST_FOR_EACH_SAFE( item, cursor, &package->sourcelist_media )
258 MSIMEDIADISK *info = LIST_ENTRY( item, MSIMEDIADISK, entry );
260 list_remove( &info->entry );
261 msi_free( info->volume_label );
262 msi_free( info->disk_prompt );
263 msi_free( info );
266 if (package->script)
268 for (i = 0; i < TOTAL_SCRIPTS; i++)
269 msi_free_action_script( package, i );
271 for (i = 0; i < package->script->UniqueActionsCount; i++)
272 msi_free( package->script->UniqueActions[i] );
274 msi_free( package->script->UniqueActions );
275 msi_free( package->script );
278 LIST_FOR_EACH_SAFE( item, cursor, &package->patches )
280 MSIPATCHINFO *patch = LIST_ENTRY( item, MSIPATCHINFO, entry );
282 list_remove( &patch->entry );
283 msi_free( patch->patchcode );
284 msi_free( patch->transforms );
285 msi_free( patch->localfile );
286 msi_free( patch );
289 LIST_FOR_EACH_SAFE( item, cursor, &package->binaries )
291 MSIBINARY *binary = LIST_ENTRY( item, MSIBINARY, entry );
293 list_remove( &binary->entry );
294 if (binary->module)
295 FreeLibrary( binary->module );
296 if (!DeleteFileW( binary->tmpfile ))
297 ERR("failed to delete %s (%u)\n", debugstr_w(binary->tmpfile), GetLastError());
298 msi_free( binary->source );
299 msi_free( binary->tmpfile );
300 msi_free( binary );
303 LIST_FOR_EACH_SAFE( item, cursor, &package->cabinet_streams )
305 MSICABINETSTREAM *cab = LIST_ENTRY( item, MSICABINETSTREAM, entry );
307 list_remove( &cab->entry );
308 IStorage_Release( cab->storage );
309 msi_free( cab->stream );
310 msi_free( cab );
313 msi_free( package->BaseURL );
314 msi_free( package->PackagePath );
315 msi_free( package->ProductCode );
316 msi_free( package->ActionFormat );
317 msi_free( package->LastAction );
318 msi_free( package->langids );
320 /* cleanup control event subscriptions */
321 ControlEvent_CleanupSubscriptions( package );
324 static void MSI_FreePackage( MSIOBJECTHDR *arg)
326 UINT i;
327 MSIPACKAGE *package = (MSIPACKAGE *)arg;
329 if( package->dialog )
330 msi_dialog_destroy( package->dialog );
332 msiobj_release( &package->db->hdr );
333 free_package_structures(package);
334 CloseHandle( package->log_file );
336 for (i = 0; i < CLR_VERSION_MAX; i++)
337 if (package->cache_net[i]) IAssemblyCache_Release( package->cache_net[i] );
338 if (package->cache_sxs) IAssemblyCache_Release( package->cache_sxs );
341 static UINT create_temp_property_table(MSIPACKAGE *package)
343 MSIQUERY *view = NULL;
344 UINT rc;
346 static const WCHAR CreateSql[] = {
347 'C','R','E','A','T','E',' ','T','A','B','L','E',' ',
348 '`','_','P','r','o','p','e','r','t','y','`',' ','(',' ',
349 '`','_','P','r','o','p','e','r','t','y','`',' ',
350 'C','H','A','R','(','5','6',')',' ','N','O','T',' ','N','U','L','L',' ',
351 'T','E','M','P','O','R','A','R','Y',',',' ',
352 '`','V','a','l','u','e','`',' ','C','H','A','R','(','9','8',')',' ',
353 'N','O','T',' ','N','U','L','L',' ','T','E','M','P','O','R','A','R','Y',
354 ' ','P','R','I','M','A','R','Y',' ','K','E','Y',' ',
355 '`','_','P','r','o','p','e','r','t','y','`',')',' ','H','O','L','D',0};
357 rc = MSI_DatabaseOpenViewW(package->db, CreateSql, &view);
358 if (rc != ERROR_SUCCESS)
359 return rc;
361 rc = MSI_ViewExecute(view, 0);
362 MSI_ViewClose(view);
363 msiobj_release(&view->hdr);
364 return rc;
367 UINT msi_clone_properties(MSIPACKAGE *package)
369 MSIQUERY *view_select = NULL;
370 UINT rc;
372 static const WCHAR query_select[] = {
373 'S','E','L','E','C','T',' ','*',' ',
374 'F','R','O','M',' ','`','P','r','o','p','e','r','t','y','`',0};
375 static const WCHAR query_insert[] = {
376 'I','N','S','E','R','T',' ','i','n','t','o',' ',
377 '`','_','P','r','o','p','e','r','t','y','`',' ',
378 '(','`','_','P','r','o','p','e','r','t','y','`',',',
379 '`','V','a','l','u','e','`',')',' ',
380 'V','A','L','U','E','S',' ','(','?',',','?',')',0};
381 static const WCHAR query_update[] = {
382 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ',
383 'S','E','T',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
384 'W','H','E','R','E',' ','`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','?',0};
386 rc = MSI_DatabaseOpenViewW( package->db, query_select, &view_select );
387 if (rc != ERROR_SUCCESS)
388 return rc;
390 rc = MSI_ViewExecute( view_select, 0 );
391 if (rc != ERROR_SUCCESS)
393 MSI_ViewClose( view_select );
394 msiobj_release( &view_select->hdr );
395 return rc;
398 while (1)
400 MSIQUERY *view_insert, *view_update;
401 MSIRECORD *rec_select;
403 rc = MSI_ViewFetch( view_select, &rec_select );
404 if (rc != ERROR_SUCCESS)
405 break;
407 rc = MSI_DatabaseOpenViewW( package->db, query_insert, &view_insert );
408 if (rc != ERROR_SUCCESS)
410 msiobj_release( &rec_select->hdr );
411 continue;
414 rc = MSI_ViewExecute( view_insert, rec_select );
415 MSI_ViewClose( view_insert );
416 msiobj_release( &view_insert->hdr );
417 if (rc != ERROR_SUCCESS)
419 MSIRECORD *rec_update;
421 TRACE("insert failed, trying update\n");
423 rc = MSI_DatabaseOpenViewW( package->db, query_update, &view_update );
424 if (rc != ERROR_SUCCESS)
426 WARN("open view failed %u\n", rc);
427 msiobj_release( &rec_select->hdr );
428 continue;
431 rec_update = MSI_CreateRecord( 2 );
432 MSI_RecordCopyField( rec_select, 1, rec_update, 2 );
433 MSI_RecordCopyField( rec_select, 2, rec_update, 1 );
434 rc = MSI_ViewExecute( view_update, rec_update );
435 if (rc != ERROR_SUCCESS)
436 WARN("update failed %u\n", rc);
438 MSI_ViewClose( view_update );
439 msiobj_release( &view_update->hdr );
440 msiobj_release( &rec_update->hdr );
443 msiobj_release( &rec_select->hdr );
446 MSI_ViewClose( view_select );
447 msiobj_release( &view_select->hdr );
448 return rc;
452 * set_installed_prop
454 * Sets the "Installed" property to indicate that
455 * the product is installed for the current user.
457 static UINT set_installed_prop( MSIPACKAGE *package )
459 HKEY hkey;
460 UINT r;
462 if (!package->ProductCode) return ERROR_FUNCTION_FAILED;
464 r = MSIREG_OpenUninstallKey( package->ProductCode, package->platform, &hkey, FALSE );
465 if (r == ERROR_SUCCESS)
467 RegCloseKey( hkey );
468 msi_set_property( package->db, szInstalled, szOne );
470 return r;
473 static UINT set_user_sid_prop( MSIPACKAGE *package )
475 SID_NAME_USE use;
476 LPWSTR user_name;
477 LPWSTR sid_str = NULL, dom = NULL;
478 DWORD size, dom_size;
479 PSID psid = NULL;
480 UINT r = ERROR_FUNCTION_FAILED;
482 size = 0;
483 GetUserNameW( NULL, &size );
485 user_name = msi_alloc( (size + 1) * sizeof(WCHAR) );
486 if (!user_name)
487 return ERROR_OUTOFMEMORY;
489 if (!GetUserNameW( user_name, &size ))
490 goto done;
492 size = 0;
493 dom_size = 0;
494 LookupAccountNameW( NULL, user_name, NULL, &size, NULL, &dom_size, &use );
496 psid = msi_alloc( size );
497 dom = msi_alloc( dom_size*sizeof (WCHAR) );
498 if (!psid || !dom)
500 r = ERROR_OUTOFMEMORY;
501 goto done;
504 if (!LookupAccountNameW( NULL, user_name, psid, &size, dom, &dom_size, &use ))
505 goto done;
507 if (!ConvertSidToStringSidW( psid, &sid_str ))
508 goto done;
510 r = msi_set_property( package->db, szUserSID, sid_str );
512 done:
513 LocalFree( sid_str );
514 msi_free( dom );
515 msi_free( psid );
516 msi_free( user_name );
518 return r;
521 static LPWSTR get_fusion_filename(MSIPACKAGE *package)
523 HKEY netsetup;
524 LONG res;
525 LPWSTR file = NULL;
526 DWORD index = 0, size;
527 WCHAR ver[MAX_PATH];
528 WCHAR name[MAX_PATH];
529 WCHAR windir[MAX_PATH];
531 static const WCHAR fusion[] = {'f','u','s','i','o','n','.','d','l','l',0};
532 static const WCHAR sub[] = {
533 'S','o','f','t','w','a','r','e','\\',
534 'M','i','c','r','o','s','o','f','t','\\',
535 'N','E','T',' ','F','r','a','m','e','w','o','r','k',' ','S','e','t','u','p','\\',
536 'N','D','P',0
538 static const WCHAR subdir[] = {
539 'M','i','c','r','o','s','o','f','t','.','N','E','T','\\',
540 'F','r','a','m','e','w','o','r','k','\\',0
543 res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, sub, 0, KEY_ENUMERATE_SUB_KEYS, &netsetup);
544 if (res != ERROR_SUCCESS)
545 return NULL;
547 GetWindowsDirectoryW(windir, MAX_PATH);
549 ver[0] = '\0';
550 size = MAX_PATH;
551 while (RegEnumKeyExW(netsetup, index, name, &size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
553 index++;
555 /* verify existence of fusion.dll .Net 3.0 does not install a new one */
556 if (strcmpW( ver, name ) < 0)
558 LPWSTR check;
559 size = lstrlenW(windir) + lstrlenW(subdir) + lstrlenW(name) +lstrlenW(fusion) + 3;
560 check = msi_alloc(size * sizeof(WCHAR));
562 if (!check)
564 msi_free(file);
565 return NULL;
568 lstrcpyW(check, windir);
569 lstrcatW(check, szBackSlash);
570 lstrcatW(check, subdir);
571 lstrcatW(check, name);
572 lstrcatW(check, szBackSlash);
573 lstrcatW(check, fusion);
575 if(GetFileAttributesW(check) != INVALID_FILE_ATTRIBUTES)
577 msi_free(file);
578 file = check;
579 lstrcpyW(ver, name);
581 else
582 msi_free(check);
586 RegCloseKey(netsetup);
587 return file;
590 typedef struct tagLANGANDCODEPAGE
592 WORD wLanguage;
593 WORD wCodePage;
594 } LANGANDCODEPAGE;
596 static void set_msi_assembly_prop(MSIPACKAGE *package)
598 UINT val_len;
599 DWORD size, handle;
600 LPVOID version = NULL;
601 WCHAR buf[MAX_PATH];
602 LPWSTR fusion, verstr;
603 LANGANDCODEPAGE *translate;
605 static const WCHAR netasm[] = {
606 'M','s','i','N','e','t','A','s','s','e','m','b','l','y','S','u','p','p','o','r','t',0
608 static const WCHAR translation[] = {
609 '\\','V','a','r','F','i','l','e','I','n','f','o',
610 '\\','T','r','a','n','s','l','a','t','i','o','n',0
612 static const WCHAR verfmt[] = {
613 '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
614 '\\','%','0','4','x','%','0','4','x',
615 '\\','P','r','o','d','u','c','t','V','e','r','s','i','o','n',0
618 fusion = get_fusion_filename(package);
619 if (!fusion)
620 return;
622 size = GetFileVersionInfoSizeW(fusion, &handle);
623 if (!size) return;
625 version = msi_alloc(size);
626 if (!version) return;
628 if (!GetFileVersionInfoW(fusion, handle, size, version))
629 goto done;
631 if (!VerQueryValueW(version, translation, (LPVOID *)&translate, &val_len))
632 goto done;
634 sprintfW(buf, verfmt, translate[0].wLanguage, translate[0].wCodePage);
636 if (!VerQueryValueW(version, buf, (LPVOID *)&verstr, &val_len))
637 goto done;
639 if (!val_len || !verstr)
640 goto done;
642 msi_set_property(package->db, netasm, verstr);
644 done:
645 msi_free(fusion);
646 msi_free(version);
649 static VOID set_installer_properties(MSIPACKAGE *package)
651 WCHAR pth[MAX_PATH];
652 WCHAR *ptr;
653 OSVERSIONINFOEXW OSVersion;
654 MEMORYSTATUSEX msex;
655 DWORD verval, len;
656 WCHAR verstr[10], bufstr[20];
657 HDC dc;
658 HKEY hkey;
659 LPWSTR username, companyname;
660 SYSTEM_INFO sys_info;
661 SYSTEMTIME systemtime;
662 LANGID langid;
664 static const WCHAR szCommonFilesFolder[] = {'C','o','m','m','o','n','F','i','l','e','s','F','o','l','d','e','r',0};
665 static const WCHAR szProgramFilesFolder[] = {'P','r','o','g','r','a','m','F','i','l','e','s','F','o','l','d','e','r',0};
666 static const WCHAR szCommonAppDataFolder[] = {'C','o','m','m','o','n','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
667 static const WCHAR szFavoritesFolder[] = {'F','a','v','o','r','i','t','e','s','F','o','l','d','e','r',0};
668 static const WCHAR szFontsFolder[] = {'F','o','n','t','s','F','o','l','d','e','r',0};
669 static const WCHAR szSendToFolder[] = {'S','e','n','d','T','o','F','o','l','d','e','r',0};
670 static const WCHAR szStartMenuFolder[] = {'S','t','a','r','t','M','e','n','u','F','o','l','d','e','r',0};
671 static const WCHAR szStartupFolder[] = {'S','t','a','r','t','u','p','F','o','l','d','e','r',0};
672 static const WCHAR szTemplateFolder[] = {'T','e','m','p','l','a','t','e','F','o','l','d','e','r',0};
673 static const WCHAR szDesktopFolder[] = {'D','e','s','k','t','o','p','F','o','l','d','e','r',0};
674 static const WCHAR szProgramMenuFolder[] = {'P','r','o','g','r','a','m','M','e','n','u','F','o','l','d','e','r',0};
675 static const WCHAR szAdminToolsFolder[] = {'A','d','m','i','n','T','o','o','l','s','F','o','l','d','e','r',0};
676 static const WCHAR szAppDataFolder[] = {'A','p','p','D','a','t','a','F','o','l','d','e','r',0};
677 static const WCHAR szSystemFolder[] = {'S','y','s','t','e','m','F','o','l','d','e','r',0};
678 static const WCHAR szSystem16Folder[] = {'S','y','s','t','e','m','1','6','F','o','l','d','e','r',0};
679 static const WCHAR szLocalAppDataFolder[] = {'L','o','c','a','l','A','p','p','D','a','t','a','F','o','l','d','e','r',0};
680 static const WCHAR szMyPicturesFolder[] = {'M','y','P','i','c','t','u','r','e','s','F','o','l','d','e','r',0};
681 static const WCHAR szPersonalFolder[] = {'P','e','r','s','o','n','a','l','F','o','l','d','e','r',0};
682 static const WCHAR szWindowsFolder[] = {'W','i','n','d','o','w','s','F','o','l','d','e','r',0};
683 static const WCHAR szWindowsVolume[] = {'W','i','n','d','o','w','s','V','o','l','u','m','e',0};
684 static const WCHAR szTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
685 static const WCHAR szPrivileged[] = {'P','r','i','v','i','l','e','g','e','d',0};
686 static const WCHAR szVersion9x[] = {'V','e','r','s','i','o','n','9','X',0};
687 static const WCHAR szVersionNT[] = {'V','e','r','s','i','o','n','N','T',0};
688 static const WCHAR szMsiNTProductType[] = {'M','s','i','N','T','P','r','o','d','u','c','t','T','y','p','e',0};
689 static const WCHAR szFormat[] = {'%','l','i',0};
690 static const WCHAR szWindowsBuild[] = {'W','i','n','d','o','w','s','B','u','i','l','d',0};
691 static const WCHAR szServicePackLevel[] = {'S','e','r','v','i','c','e','P','a','c','k','L','e','v','e','l',0};
692 static const WCHAR szSix[] = {'6',0 };
693 static const WCHAR szVersionMsi[] = { 'V','e','r','s','i','o','n','M','s','i',0 };
694 static const WCHAR szVersionDatabase[] = { 'V','e','r','s','i','o','n','D','a','t','a','b','a','s','e',0 };
695 static const WCHAR szPhysicalMemory[] = { 'P','h','y','s','i','c','a','l','M','e','m','o','r','y',0 };
696 static const WCHAR szFormat2[] = {'%','l','i','.','%','l','i',0};
697 static const WCHAR szScreenX[] = {'S','c','r','e','e','n','X',0};
698 static const WCHAR szScreenY[] = {'S','c','r','e','e','n','Y',0};
699 static const WCHAR szColorBits[] = {'C','o','l','o','r','B','i','t','s',0};
700 static const WCHAR szIntFormat[] = {'%','d',0};
701 static const WCHAR szMsiAMD64[] = { 'M','s','i','A','M','D','6','4',0 };
702 static const WCHAR szMsix64[] = { 'M','s','i','x','6','4',0 };
703 static const WCHAR szSystem64Folder[] = { 'S','y','s','t','e','m','6','4','F','o','l','d','e','r',0 };
704 static const WCHAR szCommonFiles64Folder[] = { 'C','o','m','m','o','n','F','i','l','e','s','6','4','F','o','l','d','e','r',0 };
705 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 };
706 static const WCHAR szVersionNT64[] = { 'V','e','r','s','i','o','n','N','T','6','4',0 };
707 static const WCHAR szUserInfo[] = {
708 'S','O','F','T','W','A','R','E','\\',
709 'M','i','c','r','o','s','o','f','t','\\',
710 'M','S',' ','S','e','t','u','p',' ','(','A','C','M','E',')','\\',
711 'U','s','e','r',' ','I','n','f','o',0
713 static const WCHAR szDefName[] = { 'D','e','f','N','a','m','e',0 };
714 static const WCHAR szDefCompany[] = { 'D','e','f','C','o','m','p','a','n','y',0 };
715 static const WCHAR szCurrentVersion[] = {
716 'S','O','F','T','W','A','R','E','\\',
717 'M','i','c','r','o','s','o','f','t','\\',
718 'W','i','n','d','o','w','s',' ','N','T','\\',
719 'C','u','r','r','e','n','t','V','e','r','s','i','o','n',0
721 static const WCHAR szRegisteredUser[] = {'R','e','g','i','s','t','e','r','e','d','O','w','n','e','r',0};
722 static const WCHAR szRegisteredOrganization[] = {
723 'R','e','g','i','s','t','e','r','e','d','O','r','g','a','n','i','z','a','t','i','o','n',0
725 static const WCHAR szUSERNAME[] = {'U','S','E','R','N','A','M','E',0};
726 static const WCHAR szCOMPANYNAME[] = {'C','O','M','P','A','N','Y','N','A','M','E',0};
727 static const WCHAR szDate[] = {'D','a','t','e',0};
728 static const WCHAR szTime[] = {'T','i','m','e',0};
729 static const WCHAR szUserLanguageID[] = {'U','s','e','r','L','a','n','g','u','a','g','e','I','D',0};
730 static const WCHAR szSystemLangID[] = {'S','y','s','t','e','m','L','a','n','g','u','a','g','e','I','D',0};
731 static const WCHAR szProductState[] = {'P','r','o','d','u','c','t','S','t','a','t','e',0};
732 static const WCHAR szLogonUser[] = {'L','o','g','o','n','U','s','e','r',0};
733 static const WCHAR szNetHoodFolder[] = {'N','e','t','H','o','o','d','F','o','l','d','e','r',0};
734 static const WCHAR szPrintHoodFolder[] = {'P','r','i','n','t','H','o','o','d','F','o','l','d','e','r',0};
735 static const WCHAR szRecentFolder[] = {'R','e','c','e','n','t','F','o','l','d','e','r',0};
738 * Other things that probably should be set:
740 * ComputerName VirtualMemory
741 * ShellAdvSupport DefaultUIFont PackagecodeChanging
742 * CaptionHeight BorderTop BorderSide TextHeight
743 * RedirectedDllSupport
746 SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, 0, pth);
747 strcatW(pth, szBackSlash);
748 msi_set_property(package->db, szCommonAppDataFolder, pth);
750 SHGetFolderPathW(NULL, CSIDL_FAVORITES, NULL, 0, pth);
751 strcatW(pth, szBackSlash);
752 msi_set_property(package->db, szFavoritesFolder, pth);
754 SHGetFolderPathW(NULL, CSIDL_FONTS, NULL, 0, pth);
755 strcatW(pth, szBackSlash);
756 msi_set_property(package->db, szFontsFolder, pth);
758 SHGetFolderPathW(NULL, CSIDL_SENDTO, NULL, 0, pth);
759 strcatW(pth, szBackSlash);
760 msi_set_property(package->db, szSendToFolder, pth);
762 SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, pth);
763 strcatW(pth, szBackSlash);
764 msi_set_property(package->db, szStartMenuFolder, pth);
766 SHGetFolderPathW(NULL, CSIDL_STARTUP, NULL, 0, pth);
767 strcatW(pth, szBackSlash);
768 msi_set_property(package->db, szStartupFolder, pth);
770 SHGetFolderPathW(NULL, CSIDL_TEMPLATES, NULL, 0, pth);
771 strcatW(pth, szBackSlash);
772 msi_set_property(package->db, szTemplateFolder, pth);
774 SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, 0, pth);
775 strcatW(pth, szBackSlash);
776 msi_set_property(package->db, szDesktopFolder, pth);
778 /* FIXME: set to AllUsers profile path if ALLUSERS is set */
779 SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, 0, pth);
780 strcatW(pth, szBackSlash);
781 msi_set_property(package->db, szProgramMenuFolder, pth);
783 SHGetFolderPathW(NULL, CSIDL_ADMINTOOLS, NULL, 0, pth);
784 strcatW(pth, szBackSlash);
785 msi_set_property(package->db, szAdminToolsFolder, pth);
787 SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, pth);
788 strcatW(pth, szBackSlash);
789 msi_set_property(package->db, szAppDataFolder, pth);
791 SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, 0, pth);
792 strcatW(pth, szBackSlash);
793 msi_set_property(package->db, szSystemFolder, pth);
794 msi_set_property(package->db, szSystem16Folder, pth);
796 SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, pth);
797 strcatW(pth, szBackSlash);
798 msi_set_property(package->db, szLocalAppDataFolder, pth);
800 SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, 0, pth);
801 strcatW(pth, szBackSlash);
802 msi_set_property(package->db, szMyPicturesFolder, pth);
804 SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, 0, pth);
805 strcatW(pth, szBackSlash);
806 msi_set_property(package->db, szPersonalFolder, pth);
808 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
809 strcatW(pth, szBackSlash);
810 msi_set_property(package->db, szWindowsFolder, pth);
812 SHGetFolderPathW(NULL, CSIDL_PRINTHOOD, NULL, 0, pth);
813 strcatW(pth, szBackSlash);
814 msi_set_property(package->db, szPrintHoodFolder, pth);
816 SHGetFolderPathW(NULL, CSIDL_NETHOOD, NULL, 0, pth);
817 strcatW(pth, szBackSlash);
818 msi_set_property(package->db, szNetHoodFolder, pth);
820 SHGetFolderPathW(NULL, CSIDL_RECENT, NULL, 0, pth);
821 strcatW(pth, szBackSlash);
822 msi_set_property(package->db, szRecentFolder, pth);
824 /* Physical Memory is specified in MB. Using total amount. */
825 msex.dwLength = sizeof(msex);
826 GlobalMemoryStatusEx( &msex );
827 sprintfW( bufstr, szIntFormat, (int)(msex.ullTotalPhys / 1024 / 1024) );
828 msi_set_property(package->db, szPhysicalMemory, bufstr);
830 SHGetFolderPathW(NULL, CSIDL_WINDOWS, NULL, 0, pth);
831 ptr = strchrW(pth,'\\');
832 if (ptr) *(ptr + 1) = 0;
833 msi_set_property(package->db, szWindowsVolume, pth);
835 GetTempPathW(MAX_PATH,pth);
836 msi_set_property(package->db, szTempFolder, pth);
838 /* in a wine environment the user is always admin and privileged */
839 msi_set_property(package->db, szAdminUser, szOne);
840 msi_set_property(package->db, szPrivileged, szOne);
842 /* set the os things */
843 OSVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
844 GetVersionExW((OSVERSIONINFOW *)&OSVersion);
845 verval = OSVersion.dwMinorVersion + OSVersion.dwMajorVersion * 100;
846 sprintfW(verstr, szFormat, verval);
847 switch (OSVersion.dwPlatformId)
849 case VER_PLATFORM_WIN32_WINDOWS:
850 msi_set_property(package->db, szVersion9x, verstr);
851 break;
852 case VER_PLATFORM_WIN32_NT:
853 msi_set_property(package->db, szVersionNT, verstr);
854 sprintfW(verstr, szFormat,OSVersion.wProductType);
855 msi_set_property(package->db, szMsiNTProductType, verstr);
856 break;
858 sprintfW(verstr, szFormat, OSVersion.dwBuildNumber);
859 msi_set_property(package->db, szWindowsBuild, verstr);
860 /* just fudge this */
861 msi_set_property(package->db, szServicePackLevel, szSix);
863 sprintfW( bufstr, szFormat2, MSI_MAJORVERSION, MSI_MINORVERSION);
864 msi_set_property( package->db, szVersionMsi, bufstr );
865 sprintfW( bufstr, szFormat, MSI_MAJORVERSION * 100);
866 msi_set_property( package->db, szVersionDatabase, bufstr );
868 GetNativeSystemInfo( &sys_info );
869 sprintfW( bufstr, szIntFormat, sys_info.wProcessorLevel );
870 if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
872 msi_set_property( package->db, szIntel, bufstr );
874 GetSystemDirectoryW( pth, MAX_PATH );
875 PathAddBackslashW( pth );
876 msi_set_property( package->db, szSystemFolder, pth );
878 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
879 PathAddBackslashW( pth );
880 msi_set_property( package->db, szProgramFilesFolder, pth );
882 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
883 PathAddBackslashW( pth );
884 msi_set_property( package->db, szCommonFilesFolder, pth );
886 else if (sys_info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
888 msi_set_property( package->db, szMsiAMD64, bufstr );
889 msi_set_property( package->db, szMsix64, bufstr );
890 msi_set_property( package->db, szVersionNT64, verstr );
892 GetSystemDirectoryW( pth, MAX_PATH );
893 PathAddBackslashW( pth );
894 msi_set_property( package->db, szSystem64Folder, pth );
896 GetSystemWow64DirectoryW( pth, MAX_PATH );
897 PathAddBackslashW( pth );
898 msi_set_property( package->db, szSystemFolder, pth );
900 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES, NULL, 0, pth );
901 PathAddBackslashW( pth );
902 msi_set_property( package->db, szProgramFiles64Folder, pth );
904 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILESX86, NULL, 0, pth );
905 PathAddBackslashW( pth );
906 msi_set_property( package->db, szProgramFilesFolder, pth );
908 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMON, NULL, 0, pth );
909 PathAddBackslashW( pth );
910 msi_set_property( package->db, szCommonFiles64Folder, pth );
912 SHGetFolderPathW( NULL, CSIDL_PROGRAM_FILES_COMMONX86, NULL, 0, pth );
913 PathAddBackslashW( pth );
914 msi_set_property( package->db, szCommonFilesFolder, pth );
917 /* Screen properties. */
918 dc = GetDC(0);
919 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, HORZRES ) );
920 msi_set_property( package->db, szScreenX, bufstr );
921 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, VERTRES ));
922 msi_set_property( package->db, szScreenY, bufstr );
923 sprintfW( bufstr, szIntFormat, GetDeviceCaps( dc, BITSPIXEL ));
924 msi_set_property( package->db, szColorBits, bufstr );
925 ReleaseDC(0, dc);
927 /* USERNAME and COMPANYNAME */
928 username = msi_dup_property( package->db, szUSERNAME );
929 companyname = msi_dup_property( package->db, szCOMPANYNAME );
931 if ((!username || !companyname) &&
932 RegOpenKeyW( HKEY_CURRENT_USER, szUserInfo, &hkey ) == ERROR_SUCCESS)
934 if (!username &&
935 (username = msi_reg_get_val_str( hkey, szDefName )))
936 msi_set_property( package->db, szUSERNAME, username );
937 if (!companyname &&
938 (companyname = msi_reg_get_val_str( hkey, szDefCompany )))
939 msi_set_property( package->db, szCOMPANYNAME, companyname );
940 CloseHandle( hkey );
942 if ((!username || !companyname) &&
943 RegOpenKeyW( HKEY_LOCAL_MACHINE, szCurrentVersion, &hkey ) == ERROR_SUCCESS)
945 if (!username &&
946 (username = msi_reg_get_val_str( hkey, szRegisteredUser )))
947 msi_set_property( package->db, szUSERNAME, username );
948 if (!companyname &&
949 (companyname = msi_reg_get_val_str( hkey, szRegisteredOrganization )))
950 msi_set_property( package->db, szCOMPANYNAME, companyname );
951 CloseHandle( hkey );
953 msi_free( username );
954 msi_free( companyname );
956 if ( set_user_sid_prop( package ) != ERROR_SUCCESS)
957 ERR("Failed to set the UserSID property\n");
959 /* Date and time properties */
960 GetSystemTime( &systemtime );
961 if (GetDateFormatW( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systemtime,
962 NULL, bufstr, sizeof(bufstr)/sizeof(bufstr[0]) ))
963 msi_set_property( package->db, szDate, bufstr );
964 else
965 ERR("Couldn't set Date property: GetDateFormat failed with error %d\n", GetLastError());
967 if (GetTimeFormatW( LOCALE_USER_DEFAULT,
968 TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER,
969 &systemtime, NULL, bufstr,
970 sizeof(bufstr)/sizeof(bufstr[0]) ))
971 msi_set_property( package->db, szTime, bufstr );
972 else
973 ERR("Couldn't set Time property: GetTimeFormat failed with error %d\n", GetLastError());
975 set_msi_assembly_prop( package );
977 langid = GetUserDefaultLangID();
978 sprintfW(bufstr, szIntFormat, langid);
979 msi_set_property( package->db, szUserLanguageID, bufstr );
981 langid = GetSystemDefaultLangID();
982 sprintfW(bufstr, szIntFormat, langid);
983 msi_set_property( package->db, szSystemLangID, bufstr );
985 sprintfW(bufstr, szIntFormat, MsiQueryProductStateW(package->ProductCode));
986 msi_set_property( package->db, szProductState, bufstr );
988 len = 0;
989 if (!GetUserNameW( NULL, &len ) && GetLastError() == ERROR_MORE_DATA)
991 WCHAR *username;
992 if ((username = msi_alloc( len * sizeof(WCHAR) )))
994 if (GetUserNameW( username, &len ))
995 msi_set_property( package->db, szLogonUser, username );
996 msi_free( username );
1001 static UINT msi_load_summary_properties( MSIPACKAGE *package )
1003 UINT rc;
1004 MSIHANDLE suminfo;
1005 MSIHANDLE hdb = alloc_msihandle( &package->db->hdr );
1006 INT count;
1007 DWORD len;
1008 LPWSTR package_code;
1009 static const WCHAR szPackageCode[] = {
1010 'P','a','c','k','a','g','e','C','o','d','e',0};
1012 if (!hdb) {
1013 ERR("Unable to allocate handle\n");
1014 return ERROR_OUTOFMEMORY;
1017 rc = MsiGetSummaryInformationW( hdb, NULL, 0, &suminfo );
1018 MsiCloseHandle(hdb);
1019 if (rc != ERROR_SUCCESS)
1021 ERR("Unable to open Summary Information\n");
1022 return rc;
1025 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_PAGECOUNT, NULL,
1026 &count, NULL, NULL, NULL );
1027 if (rc != ERROR_SUCCESS)
1029 WARN("Unable to query page count: %d\n", rc);
1030 goto done;
1033 /* load package code property */
1034 len = 0;
1035 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1036 NULL, NULL, NULL, &len );
1037 if (rc != ERROR_MORE_DATA)
1039 WARN("Unable to query revision number: %d\n", rc);
1040 rc = ERROR_FUNCTION_FAILED;
1041 goto done;
1044 len++;
1045 package_code = msi_alloc( len * sizeof(WCHAR) );
1046 rc = MsiSummaryInfoGetPropertyW( suminfo, PID_REVNUMBER, NULL,
1047 NULL, NULL, package_code, &len );
1048 if (rc != ERROR_SUCCESS)
1050 WARN("Unable to query rev number: %d\n", rc);
1051 goto done;
1054 msi_set_property( package->db, szPackageCode, package_code );
1055 msi_free( package_code );
1057 /* load package attributes */
1058 count = 0;
1059 MsiSummaryInfoGetPropertyW( suminfo, PID_WORDCOUNT, NULL,
1060 &count, NULL, NULL, NULL );
1061 package->WordCount = count;
1063 done:
1064 MsiCloseHandle(suminfo);
1065 return rc;
1068 static MSIPACKAGE *msi_alloc_package( void )
1070 MSIPACKAGE *package;
1072 package = alloc_msiobject( MSIHANDLETYPE_PACKAGE, sizeof (MSIPACKAGE),
1073 MSI_FreePackage );
1074 if( package )
1076 list_init( &package->components );
1077 list_init( &package->features );
1078 list_init( &package->files );
1079 list_init( &package->filepatches );
1080 list_init( &package->tempfiles );
1081 list_init( &package->folders );
1082 list_init( &package->subscriptions );
1083 list_init( &package->appids );
1084 list_init( &package->classes );
1085 list_init( &package->mimes );
1086 list_init( &package->extensions );
1087 list_init( &package->progids );
1088 list_init( &package->RunningActions );
1089 list_init( &package->sourcelist_info );
1090 list_init( &package->sourcelist_media );
1091 list_init( &package->patches );
1092 list_init( &package->binaries );
1093 list_init( &package->cabinet_streams );
1096 return package;
1099 static UINT msi_load_admin_properties(MSIPACKAGE *package)
1101 BYTE *data;
1102 UINT r, sz;
1104 static const WCHAR stmname[] = {'A','d','m','i','n','P','r','o','p','e','r','t','i','e','s',0};
1106 r = read_stream_data(package->db->storage, stmname, FALSE, &data, &sz);
1107 if (r != ERROR_SUCCESS)
1108 return r;
1110 r = msi_parse_command_line(package, (WCHAR *)data, TRUE);
1112 msi_free(data);
1113 return r;
1116 void msi_adjust_privilege_properties( MSIPACKAGE *package )
1118 /* FIXME: this should depend on the user's privileges */
1119 if (msi_get_property_int( package->db, szAllUsers, 0 ) == 2)
1121 TRACE("resetting ALLUSERS property from 2 to 1\n");
1122 msi_set_property( package->db, szAllUsers, szOne );
1124 msi_set_property( package->db, szAdminUser, szOne );
1127 MSIPACKAGE *MSI_CreatePackage( MSIDATABASE *db, LPCWSTR base_url )
1129 static const WCHAR szLevel[] = { 'U','I','L','e','v','e','l',0 };
1130 static const WCHAR szpi[] = {'%','i',0};
1131 MSIPACKAGE *package;
1132 WCHAR uilevel[10];
1133 UINT r;
1135 TRACE("%p\n", db);
1137 package = msi_alloc_package();
1138 if (package)
1140 msiobj_addref( &db->hdr );
1141 package->db = db;
1143 package->WordCount = 0;
1144 package->PackagePath = strdupW( db->path );
1145 package->BaseURL = strdupW( base_url );
1147 create_temp_property_table( package );
1148 msi_clone_properties( package );
1149 msi_adjust_privilege_properties( package );
1151 package->ProductCode = msi_dup_property( package->db, szProductCode );
1152 package->script = msi_alloc_zero( sizeof(MSISCRIPT) );
1154 set_installed_prop( package );
1155 set_installer_properties( package );
1157 sprintfW(uilevel,szpi,gUILevel);
1158 msi_set_property(package->db, szLevel, uilevel);
1160 r = msi_load_summary_properties( package );
1161 if (r != ERROR_SUCCESS)
1163 msiobj_release( &package->hdr );
1164 return NULL;
1167 if (package->WordCount & msidbSumInfoSourceTypeAdminImage)
1168 msi_load_admin_properties( package );
1170 package->log_file = INVALID_HANDLE_VALUE;
1173 return package;
1177 * copy_package_to_temp [internal]
1179 * copy the msi file to a temp file to prevent locking a CD
1180 * with a multi disc install
1182 * FIXME: I think this is wrong, and instead of copying the package,
1183 * we should read all the tables to memory, then open the
1184 * database to read binary streams on demand.
1186 static UINT copy_package_to_temp( LPCWSTR szPackage, LPWSTR filename )
1188 WCHAR path[MAX_PATH];
1190 GetTempPathW( MAX_PATH, path );
1191 GetTempFileNameW( path, szMsi, 0, filename );
1193 if( !CopyFileW( szPackage, filename, FALSE ) )
1195 UINT error = GetLastError();
1196 if ( error == ERROR_FILE_NOT_FOUND )
1197 ERR("can't find %s\n", debugstr_w(szPackage));
1198 else
1199 ERR("failed to copy package %s to %s (%u)\n", debugstr_w(szPackage), debugstr_w(filename), error);
1200 DeleteFileW( filename );
1201 return error;
1204 return ERROR_SUCCESS;
1207 UINT msi_download_file( LPCWSTR szUrl, LPWSTR filename )
1209 LPINTERNET_CACHE_ENTRY_INFOW cache_entry;
1210 DWORD size = 0;
1211 HRESULT hr;
1213 /* call will always fail, becase size is 0,
1214 * but will return ERROR_FILE_NOT_FOUND first
1215 * if the file doesn't exist
1217 GetUrlCacheEntryInfoW( szUrl, NULL, &size );
1218 if ( GetLastError() != ERROR_FILE_NOT_FOUND )
1220 cache_entry = msi_alloc( size );
1221 if ( !GetUrlCacheEntryInfoW( szUrl, cache_entry, &size ) )
1223 UINT error = GetLastError();
1224 msi_free( cache_entry );
1225 return error;
1228 lstrcpyW( filename, cache_entry->lpszLocalFileName );
1229 msi_free( cache_entry );
1230 return ERROR_SUCCESS;
1233 hr = URLDownloadToCacheFileW( NULL, szUrl, filename, MAX_PATH, 0, NULL );
1234 if ( FAILED(hr) )
1236 WARN("failed to download %s to cache file\n", debugstr_w(szUrl));
1237 return ERROR_FUNCTION_FAILED;
1240 return ERROR_SUCCESS;
1243 UINT msi_get_local_package_name( LPWSTR path, LPCWSTR suffix )
1245 static const WCHAR szInstaller[] = {
1246 '\\','I','n','s','t','a','l','l','e','r','\\',0};
1247 static const WCHAR fmt[] = {'%','x',0};
1248 DWORD time, len, i, offset;
1249 HANDLE handle;
1251 time = GetTickCount();
1252 GetWindowsDirectoryW( path, MAX_PATH );
1253 strcatW( path, szInstaller );
1254 CreateDirectoryW( path, NULL );
1256 len = strlenW(path);
1257 for (i = 0; i < 0x10000; i++)
1259 offset = snprintfW( path + len, MAX_PATH - len, fmt, (time + i) & 0xffff );
1260 memcpy( path + len + offset, suffix, (strlenW( suffix ) + 1) * sizeof(WCHAR) );
1261 handle = CreateFileW( path, GENERIC_WRITE, 0, NULL,
1262 CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
1263 if (handle != INVALID_HANDLE_VALUE)
1265 CloseHandle(handle);
1266 break;
1268 if (GetLastError() != ERROR_FILE_EXISTS &&
1269 GetLastError() != ERROR_SHARING_VIOLATION)
1270 return ERROR_FUNCTION_FAILED;
1273 return ERROR_SUCCESS;
1276 static UINT apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
1278 UINT r;
1279 DWORD len;
1280 WCHAR patch_file[MAX_PATH];
1281 MSIDATABASE *patch_db;
1282 MSIPATCHINFO *patch_info;
1283 MSISUMMARYINFO *si;
1285 len = sizeof(patch_file) / sizeof(WCHAR);
1286 r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
1287 INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
1288 if (r != ERROR_SUCCESS)
1290 ERR("failed to get patch filename %u\n", r);
1291 return r;
1294 r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
1295 if (r != ERROR_SUCCESS)
1297 ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
1298 return r;
1301 si = MSI_GetSummaryInformationW( patch_db->storage, 0 );
1302 if (!si)
1304 msiobj_release( &patch_db->hdr );
1305 return ERROR_FUNCTION_FAILED;
1308 r = msi_parse_patch_summary( si, &patch_info );
1309 msiobj_release( &si->hdr );
1310 if (r != ERROR_SUCCESS)
1312 ERR("failed to parse patch summary %u\n", r);
1313 msiobj_release( &patch_db->hdr );
1314 return r;
1317 patch_info->localfile = strdupW( patch_file );
1318 if (!patch_info->localfile)
1320 msiobj_release( &patch_db->hdr );
1321 return ERROR_OUTOFMEMORY;
1324 r = msi_apply_patch_db( package, patch_db, patch_info );
1325 msiobj_release( &patch_db->hdr );
1326 if (r != ERROR_SUCCESS)
1328 ERR("failed to apply patch %u\n", r);
1329 msi_free( patch_info->patchcode );
1330 msi_free( patch_info->transforms );
1331 msi_free( patch_info->localfile );
1332 msi_free( patch_info );
1334 return r;
1337 static UINT msi_parse_summary( MSISUMMARYINFO *si, MSIPACKAGE *package )
1339 WCHAR *template, *p, *q;
1340 DWORD i, count;
1342 package->version = msi_suminfo_get_int32( si, PID_PAGECOUNT );
1343 TRACE("version: %d\n", package->version);
1345 template = msi_suminfo_dup_string( si, PID_TEMPLATE );
1346 if (!template)
1347 return ERROR_SUCCESS; /* native accepts missing template property */
1349 TRACE("template: %s\n", debugstr_w(template));
1351 p = strchrW( template, ';' );
1352 if (!p)
1354 WARN("invalid template string %s\n", debugstr_w(template));
1355 msi_free( template );
1356 return ERROR_PATCH_PACKAGE_INVALID;
1358 *p = 0;
1359 if (!template[0] || !strcmpW( template, szIntel ))
1360 package->platform = PLATFORM_INTEL;
1361 else if (!strcmpW( template, szIntel64 ))
1362 package->platform = PLATFORM_INTEL64;
1363 else if (!strcmpW( template, szX64 ) || !strcmpW( template, szAMD64 ))
1364 package->platform = PLATFORM_X64;
1365 else
1367 WARN("unknown platform %s\n", debugstr_w(template));
1368 msi_free( template );
1369 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1371 p++;
1372 if (!*p)
1374 msi_free( template );
1375 return ERROR_SUCCESS;
1377 count = 1;
1378 for (q = p; (q = strchrW( q, ',' )); q++) count++;
1380 package->langids = msi_alloc( count * sizeof(LANGID) );
1381 if (!package->langids)
1383 msi_free( template );
1384 return ERROR_OUTOFMEMORY;
1387 i = 0;
1388 while (*p)
1390 q = strchrW( p, ',' );
1391 if (q) *q = 0;
1392 package->langids[i] = atoiW( p );
1393 if (!q) break;
1394 p = q + 1;
1395 i++;
1397 package->num_langids = i + 1;
1399 msi_free( template );
1400 return ERROR_SUCCESS;
1403 static UINT validate_package( MSIPACKAGE *package )
1405 BOOL is_wow64;
1406 UINT i;
1408 IsWow64Process( GetCurrentProcess(), &is_wow64 );
1409 if (package->platform == PLATFORM_X64)
1411 if (!is_64bit && !is_wow64)
1412 return ERROR_INSTALL_PLATFORM_UNSUPPORTED;
1413 if (package->version < 200)
1414 return ERROR_INSTALL_PACKAGE_INVALID;
1416 if (!package->num_langids)
1418 return ERROR_SUCCESS;
1420 for (i = 0; i < package->num_langids; i++)
1422 LANGID langid = package->langids[i];
1424 if (PRIMARYLANGID( langid ) == LANG_NEUTRAL)
1426 langid = MAKELANGID( PRIMARYLANGID( GetSystemDefaultLangID() ), SUBLANGID( langid ) );
1428 if (SUBLANGID( langid ) == SUBLANG_NEUTRAL)
1430 langid = MAKELANGID( PRIMARYLANGID( langid ), SUBLANGID( GetSystemDefaultLangID() ) );
1432 if (IsValidLocale( langid, LCID_INSTALLED ))
1433 return ERROR_SUCCESS;
1435 return ERROR_INSTALL_LANGUAGE_UNSUPPORTED;
1438 UINT MSI_OpenPackageW(LPCWSTR szPackage, MSIPACKAGE **pPackage)
1440 static const WCHAR Database[] = {'D','A','T','A','B','A','S','E',0};
1441 static const WCHAR dotmsi[] = {'.','m','s','i',0};
1442 MSIDATABASE *db = NULL;
1443 MSIPACKAGE *package;
1444 MSIHANDLE handle;
1445 LPWSTR ptr, base_url = NULL;
1446 UINT r;
1447 WCHAR temppath[MAX_PATH], localfile[MAX_PATH], cachefile[MAX_PATH];
1448 LPCWSTR file = szPackage;
1449 DWORD index = 0;
1450 MSISUMMARYINFO *si;
1452 TRACE("%s %p\n", debugstr_w(szPackage), pPackage);
1454 if( szPackage[0] == '#' )
1456 handle = atoiW(&szPackage[1]);
1457 db = msihandle2msiinfo( handle, MSIHANDLETYPE_DATABASE );
1458 if( !db )
1460 IWineMsiRemoteDatabase *remote_database;
1462 remote_database = (IWineMsiRemoteDatabase *)msi_get_remote( handle );
1463 if ( !remote_database )
1464 return ERROR_INVALID_HANDLE;
1466 IWineMsiRemoteDatabase_Release( remote_database );
1467 WARN("MsiOpenPackage not allowed during a custom action!\n");
1469 return ERROR_FUNCTION_FAILED;
1472 else
1474 if ( UrlIsW( szPackage, URLIS_URL ) )
1476 r = msi_download_file( szPackage, cachefile );
1477 if ( r != ERROR_SUCCESS )
1478 return r;
1480 r = copy_package_to_temp( cachefile, temppath );
1481 if ( r != ERROR_SUCCESS )
1482 return r;
1484 file = temppath;
1486 base_url = strdupW( szPackage );
1487 if ( !base_url )
1488 return ERROR_OUTOFMEMORY;
1490 ptr = strrchrW( base_url, '/' );
1491 if (ptr) *(ptr + 1) = '\0';
1493 else
1495 r = copy_package_to_temp( szPackage, temppath );
1496 if ( r != ERROR_SUCCESS )
1497 return r;
1499 file = temppath;
1502 r = msi_get_local_package_name( localfile, dotmsi );
1503 if (r != ERROR_SUCCESS)
1504 return r;
1506 TRACE("Copying to local package %s\n", debugstr_w(localfile));
1508 if (!CopyFileW( file, localfile, FALSE ))
1510 ERR("Unable to copy package (%s -> %s) (error %u)\n",
1511 debugstr_w(file), debugstr_w(localfile), GetLastError());
1512 return GetLastError();
1515 TRACE("Opening relocated package %s\n", debugstr_w( file ));
1517 /* transforms that add binary streams require that we open the database
1518 * read/write, which is safe because we always create a copy that is thrown
1519 * away when we're done.
1521 r = MSI_OpenDatabaseW( file, MSIDBOPEN_TRANSACT, &db );
1522 if( r != ERROR_SUCCESS )
1524 if (file != szPackage)
1525 DeleteFileW( file );
1527 if (GetFileAttributesW(szPackage) == INVALID_FILE_ATTRIBUTES)
1528 return ERROR_FILE_NOT_FOUND;
1530 return r;
1533 db->localfile = strdupW( localfile );
1536 package = MSI_CreatePackage( db, base_url );
1537 msi_free( base_url );
1538 msiobj_release( &db->hdr );
1539 if( !package )
1541 if (file != szPackage)
1542 DeleteFileW( file );
1544 return ERROR_INSTALL_PACKAGE_INVALID;
1547 if( file != szPackage )
1548 track_tempfile( package, file );
1550 si = MSI_GetSummaryInformationW( db->storage, 0 );
1551 if (!si)
1553 WARN("failed to load summary info %u\n", r);
1554 msiobj_release( &package->hdr );
1555 return ERROR_INSTALL_PACKAGE_INVALID;
1558 r = msi_parse_summary( si, package );
1559 msiobj_release( &si->hdr );
1560 if (r != ERROR_SUCCESS)
1562 WARN("failed to parse summary info %u\n", r);
1563 msiobj_release( &package->hdr );
1564 return r;
1567 r = validate_package( package );
1568 if (r != ERROR_SUCCESS)
1570 msiobj_release( &package->hdr );
1571 return r;
1573 msi_set_property( package->db, Database, db->path );
1575 if( UrlIsW( szPackage, URLIS_URL ) )
1576 msi_set_property( package->db, szOriginalDatabase, szPackage );
1577 else if( szPackage[0] == '#' )
1578 msi_set_property( package->db, szOriginalDatabase, db->path );
1579 else
1581 WCHAR fullpath[MAX_PATH];
1583 GetFullPathNameW( szPackage, MAX_PATH, fullpath, NULL );
1584 msi_set_property( package->db, szOriginalDatabase, fullpath );
1587 msi_set_context( package );
1589 while (1)
1591 WCHAR patch_code[GUID_SIZE];
1592 r = MsiEnumPatchesExW( package->ProductCode, NULL, package->Context,
1593 MSIPATCHSTATE_APPLIED, index, patch_code, NULL, NULL, NULL, NULL );
1594 if (r != ERROR_SUCCESS)
1595 break;
1597 TRACE("found registered patch %s\n", debugstr_w(patch_code));
1599 r = apply_registered_patch( package, patch_code );
1600 if (r != ERROR_SUCCESS)
1602 ERR("registered patch failed to apply %u\n", r);
1603 msiobj_release( &package->hdr );
1604 return r;
1607 index++;
1610 if (index)
1612 msi_clone_properties( package );
1613 msi_adjust_privilege_properties( package );
1616 if (gszLogFile)
1617 package->log_file = CreateFileW( gszLogFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
1618 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
1620 *pPackage = package;
1621 return ERROR_SUCCESS;
1624 UINT WINAPI MsiOpenPackageExW(LPCWSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1626 MSIPACKAGE *package = NULL;
1627 UINT ret;
1629 TRACE("%s %08x %p\n", debugstr_w(szPackage), dwOptions, phPackage );
1631 if( !szPackage || !phPackage )
1632 return ERROR_INVALID_PARAMETER;
1634 if ( !*szPackage )
1636 FIXME("Should create an empty database and package\n");
1637 return ERROR_FUNCTION_FAILED;
1640 if( dwOptions )
1641 FIXME("dwOptions %08x not supported\n", dwOptions);
1643 ret = MSI_OpenPackageW( szPackage, &package );
1644 if( ret == ERROR_SUCCESS )
1646 *phPackage = alloc_msihandle( &package->hdr );
1647 if (! *phPackage)
1648 ret = ERROR_NOT_ENOUGH_MEMORY;
1649 msiobj_release( &package->hdr );
1652 return ret;
1655 UINT WINAPI MsiOpenPackageW(LPCWSTR szPackage, MSIHANDLE *phPackage)
1657 return MsiOpenPackageExW( szPackage, 0, phPackage );
1660 UINT WINAPI MsiOpenPackageExA(LPCSTR szPackage, DWORD dwOptions, MSIHANDLE *phPackage)
1662 LPWSTR szwPack = NULL;
1663 UINT ret;
1665 if( szPackage )
1667 szwPack = strdupAtoW( szPackage );
1668 if( !szwPack )
1669 return ERROR_OUTOFMEMORY;
1672 ret = MsiOpenPackageExW( szwPack, dwOptions, phPackage );
1674 msi_free( szwPack );
1676 return ret;
1679 UINT WINAPI MsiOpenPackageA(LPCSTR szPackage, MSIHANDLE *phPackage)
1681 return MsiOpenPackageExA( szPackage, 0, phPackage );
1684 MSIHANDLE WINAPI MsiGetActiveDatabase(MSIHANDLE hInstall)
1686 MSIPACKAGE *package;
1687 MSIHANDLE handle = 0;
1688 IUnknown *remote_unk;
1689 IWineMsiRemotePackage *remote_package;
1691 TRACE("(%d)\n",hInstall);
1693 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
1694 if( package)
1696 handle = alloc_msihandle( &package->db->hdr );
1697 msiobj_release( &package->hdr );
1699 else if ((remote_unk = msi_get_remote(hInstall)))
1701 if (IUnknown_QueryInterface(remote_unk, &IID_IWineMsiRemotePackage,
1702 (LPVOID *)&remote_package) == S_OK)
1704 IWineMsiRemotePackage_GetActiveDatabase(remote_package, &handle);
1705 IWineMsiRemotePackage_Release(remote_package);
1707 else
1709 WARN("remote handle %d is not a package\n", hInstall);
1711 IUnknown_Release(remote_unk);
1714 return handle;
1717 INT MSI_ProcessMessage( MSIPACKAGE *package, INSTALLMESSAGE eMessageType, MSIRECORD *record )
1719 static const WCHAR szActionData[] =
1720 {'A','c','t','i','o','n','D','a','t','a',0};
1721 static const WCHAR szSetProgress[] =
1722 {'S','e','t','P','r','o','g','r','e','s','s',0};
1723 static const WCHAR szActionText[] =
1724 {'A','c','t','i','o','n','T','e','x','t',0};
1725 LPWSTR message;
1726 DWORD i, len, total_len, log_type = 0;
1727 INT rc = 0;
1728 char *msg;
1730 TRACE("%x\n", eMessageType);
1732 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ERROR)
1733 log_type |= INSTALLLOGMODE_ERROR;
1734 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_WARNING)
1735 log_type |= INSTALLLOGMODE_WARNING;
1736 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_USER)
1737 log_type |= INSTALLLOGMODE_USER;
1738 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_INFO)
1739 log_type |= INSTALLLOGMODE_INFO;
1740 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_COMMONDATA)
1741 log_type |= INSTALLLOGMODE_COMMONDATA;
1742 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1743 log_type |= INSTALLLOGMODE_ACTIONSTART;
1744 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONDATA)
1745 log_type |= INSTALLLOGMODE_ACTIONDATA;
1746 /* just a guess */
1747 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_PROGRESS)
1748 log_type |= 0x800;
1750 if ((eMessageType & 0xff000000) == INSTALLMESSAGE_ACTIONSTART)
1752 static const WCHAR template_s[]=
1753 {'A','c','t','i','o','n',' ','%','s',':',' ','%','s','.',' ',0};
1754 static const WCHAR format[] =
1755 {'H','H','\'',':','\'','m','m','\'',':','\'','s','s',0};
1756 WCHAR timet[0x100];
1757 LPCWSTR action_text, action;
1758 LPWSTR deformatted = NULL;
1760 GetTimeFormatW(LOCALE_USER_DEFAULT, 0, NULL, format, timet, 0x100);
1762 action = MSI_RecordGetString(record, 1);
1763 action_text = MSI_RecordGetString(record, 2);
1765 if (!action || !action_text)
1766 return IDOK;
1768 deformat_string(package, action_text, &deformatted);
1770 len = strlenW(timet) + strlenW(action) + strlenW(template_s);
1771 if (deformatted)
1772 len += strlenW(deformatted);
1773 message = msi_alloc(len*sizeof(WCHAR));
1774 sprintfW(message, template_s, timet, action);
1775 if (deformatted)
1776 strcatW(message, deformatted);
1777 msi_free(deformatted);
1779 else
1781 static const WCHAR format[] = {'%','u',':',' ',0};
1782 UINT count = MSI_RecordGetFieldCount( record );
1783 WCHAR *p;
1785 total_len = 1;
1786 for (i = 1; i <= count; i++)
1788 len = 0;
1789 MSI_RecordGetStringW( record, i, NULL, &len );
1790 total_len += len + 13;
1792 p = message = msi_alloc( total_len * sizeof(WCHAR) );
1793 if (!p) return ERROR_OUTOFMEMORY;
1795 for (i = 1; i <= count; i++)
1797 if (count > 1)
1799 len = sprintfW( p, format, i );
1800 total_len -= len;
1801 p += len;
1803 len = total_len;
1804 MSI_RecordGetStringW( record, i, p, &len );
1805 total_len -= len;
1806 p += len;
1807 if (count > 1 && total_len)
1809 *p++ = ' ';
1810 total_len--;
1813 p[0] = 0;
1816 TRACE("%p %p %p %x %x %s\n", gUIHandlerA, gUIHandlerW, gUIHandlerRecord,
1817 gUIFilter, log_type, debugstr_w(message));
1819 /* convert it to ASCII */
1820 len = WideCharToMultiByte( CP_ACP, 0, message, -1, NULL, 0, NULL, NULL );
1821 msg = msi_alloc( len );
1822 WideCharToMultiByte( CP_ACP, 0, message, -1, msg, len, NULL, NULL );
1824 if (gUIHandlerW && (gUIFilter & log_type))
1826 rc = gUIHandlerW( gUIContext, eMessageType, message );
1828 else if (gUIHandlerA && (gUIFilter & log_type))
1830 rc = gUIHandlerA( gUIContext, eMessageType, msg );
1832 else if (gUIHandlerRecord && (gUIFilter & log_type))
1834 MSIHANDLE rec = MsiCreateRecord( 1 );
1835 MsiRecordSetStringW( rec, 0, message );
1836 rc = gUIHandlerRecord( gUIContext, eMessageType, rec );
1837 MsiCloseHandle( rec );
1840 if (!rc && package->log_file != INVALID_HANDLE_VALUE &&
1841 (eMessageType & 0xff000000) != INSTALLMESSAGE_PROGRESS)
1843 DWORD written;
1844 WriteFile( package->log_file, msg, len - 1, &written, NULL );
1845 WriteFile( package->log_file, "\n", 1, &written, NULL );
1847 msi_free( msg );
1848 msi_free( message );
1850 switch (eMessageType & 0xff000000)
1852 case INSTALLMESSAGE_ACTIONDATA:
1853 /* FIXME: format record here instead of in ui_actiondata to get the
1854 * correct action data for external scripts */
1855 ControlEvent_FireSubscribedEvent(package, szActionData, record);
1856 break;
1857 case INSTALLMESSAGE_ACTIONSTART:
1859 MSIRECORD *uirow;
1860 LPWSTR deformated;
1861 LPCWSTR action_text = MSI_RecordGetString(record, 2);
1863 deformat_string(package, action_text, &deformated);
1864 uirow = MSI_CreateRecord(1);
1865 MSI_RecordSetStringW(uirow, 1, deformated);
1866 TRACE("INSTALLMESSAGE_ACTIONSTART: %s\n", debugstr_w(deformated));
1867 msi_free(deformated);
1869 ControlEvent_FireSubscribedEvent(package, szActionText, uirow);
1871 msiobj_release(&uirow->hdr);
1872 break;
1874 case INSTALLMESSAGE_PROGRESS:
1875 ControlEvent_FireSubscribedEvent(package, szSetProgress, record);
1876 break;
1879 return ERROR_SUCCESS;
1882 INT WINAPI MsiProcessMessage( MSIHANDLE hInstall, INSTALLMESSAGE eMessageType,
1883 MSIHANDLE hRecord)
1885 UINT ret = ERROR_INVALID_HANDLE;
1886 MSIPACKAGE *package = NULL;
1887 MSIRECORD *record = NULL;
1889 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
1890 if( !package )
1892 HRESULT hr;
1893 IWineMsiRemotePackage *remote_package;
1895 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
1896 if (!remote_package)
1897 return ERROR_INVALID_HANDLE;
1899 hr = IWineMsiRemotePackage_ProcessMessage( remote_package, eMessageType, hRecord );
1901 IWineMsiRemotePackage_Release( remote_package );
1903 if (FAILED(hr))
1905 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
1906 return HRESULT_CODE(hr);
1908 return ERROR_FUNCTION_FAILED;
1911 return ERROR_SUCCESS;
1914 record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
1915 if( !record )
1916 goto out;
1918 ret = MSI_ProcessMessage( package, eMessageType, record );
1920 out:
1921 msiobj_release( &package->hdr );
1922 if( record )
1923 msiobj_release( &record->hdr );
1925 return ret;
1928 /* property code */
1930 UINT WINAPI MsiSetPropertyA( MSIHANDLE hInstall, LPCSTR szName, LPCSTR szValue )
1932 LPWSTR szwName = NULL, szwValue = NULL;
1933 UINT r = ERROR_OUTOFMEMORY;
1935 szwName = strdupAtoW( szName );
1936 if( szName && !szwName )
1937 goto end;
1939 szwValue = strdupAtoW( szValue );
1940 if( szValue && !szwValue )
1941 goto end;
1943 r = MsiSetPropertyW( hInstall, szwName, szwValue);
1945 end:
1946 msi_free( szwName );
1947 msi_free( szwValue );
1949 return r;
1952 void msi_reset_folders( MSIPACKAGE *package, BOOL source )
1954 MSIFOLDER *folder;
1956 LIST_FOR_EACH_ENTRY( folder, &package->folders, MSIFOLDER, entry )
1958 if ( source )
1960 msi_free( folder->ResolvedSource );
1961 folder->ResolvedSource = NULL;
1963 else
1965 msi_free( folder->ResolvedTarget );
1966 folder->ResolvedTarget = NULL;
1971 UINT msi_set_property( MSIDATABASE *db, LPCWSTR szName, LPCWSTR szValue )
1973 MSIQUERY *view;
1974 MSIRECORD *row = NULL;
1975 UINT rc;
1976 DWORD sz = 0;
1977 WCHAR Query[1024];
1979 static const WCHAR Insert[] = {
1980 'I','N','S','E','R','T',' ','i','n','t','o',' ',
1981 '`','_','P','r','o','p','e','r','t','y','`',' ','(',
1982 '`','_','P','r','o','p','e','r','t','y','`',',',
1983 '`','V','a','l','u','e','`',')',' ','V','A','L','U','E','S'
1984 ,' ','(','?',',','?',')',0};
1985 static const WCHAR Update[] = {
1986 'U','P','D','A','T','E',' ','`','_','P','r','o','p','e','r','t','y','`',
1987 ' ','s','e','t',' ','`','V','a','l','u','e','`',' ','=',' ','?',' ',
1988 'w','h','e','r','e',' ','`','_','P','r','o','p','e','r','t','y','`',
1989 ' ','=',' ','\'','%','s','\'',0};
1990 static const WCHAR Delete[] = {
1991 'D','E','L','E','T','E',' ','F','R','O','M',' ',
1992 '`','_','P','r','o','p','e','r','t','y','`',' ','W','H','E','R','E',' ',
1993 '`','_','P','r','o','p','e','r','t','y','`',' ','=',' ','\'','%','s','\'',0};
1995 TRACE("%p %s %s\n", db, debugstr_w(szName), debugstr_w(szValue));
1997 if (!szName)
1998 return ERROR_INVALID_PARAMETER;
2000 /* this one is weird... */
2001 if (!szName[0])
2002 return szValue ? ERROR_FUNCTION_FAILED : ERROR_SUCCESS;
2004 rc = msi_get_property(db, szName, 0, &sz);
2005 if (!szValue || !*szValue)
2007 sprintfW(Query, Delete, szName);
2009 else if (rc == ERROR_MORE_DATA || rc == ERROR_SUCCESS)
2011 sprintfW(Query, Update, szName);
2013 row = MSI_CreateRecord(1);
2014 MSI_RecordSetStringW(row, 1, szValue);
2016 else
2018 strcpyW(Query, Insert);
2020 row = MSI_CreateRecord(2);
2021 MSI_RecordSetStringW(row, 1, szName);
2022 MSI_RecordSetStringW(row, 2, szValue);
2025 rc = MSI_DatabaseOpenViewW(db, Query, &view);
2026 if (rc == ERROR_SUCCESS)
2028 rc = MSI_ViewExecute(view, row);
2029 MSI_ViewClose(view);
2030 msiobj_release(&view->hdr);
2033 if (row)
2034 msiobj_release(&row->hdr);
2036 return rc;
2039 UINT WINAPI MsiSetPropertyW( MSIHANDLE hInstall, LPCWSTR szName, LPCWSTR szValue)
2041 MSIPACKAGE *package;
2042 UINT ret;
2044 package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE);
2045 if( !package )
2047 HRESULT hr;
2048 BSTR name = NULL, value = NULL;
2049 IWineMsiRemotePackage *remote_package;
2051 remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
2052 if (!remote_package)
2053 return ERROR_INVALID_HANDLE;
2055 name = SysAllocString( szName );
2056 value = SysAllocString( szValue );
2057 if ((!name && szName) || (!value && szValue))
2059 SysFreeString( name );
2060 SysFreeString( value );
2061 IWineMsiRemotePackage_Release( remote_package );
2062 return ERROR_OUTOFMEMORY;
2065 hr = IWineMsiRemotePackage_SetProperty( remote_package, name, value );
2067 SysFreeString( name );
2068 SysFreeString( value );
2069 IWineMsiRemotePackage_Release( remote_package );
2071 if (FAILED(hr))
2073 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2074 return HRESULT_CODE(hr);
2076 return ERROR_FUNCTION_FAILED;
2079 return ERROR_SUCCESS;
2082 ret = msi_set_property( package->db, szName, szValue );
2083 if (ret == ERROR_SUCCESS && !strcmpW( szName, cszSourceDir ))
2084 msi_reset_folders( package, TRUE );
2086 msiobj_release( &package->hdr );
2087 return ret;
2090 static MSIRECORD *msi_get_property_row( MSIDATABASE *db, LPCWSTR name )
2092 MSIQUERY *view;
2093 MSIRECORD *rec, *row = NULL;
2094 UINT r;
2096 static const WCHAR query[]= {
2097 'S','E','L','E','C','T',' ','`','V','a','l','u','e','`',' ',
2098 'F','R','O','M',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2099 ' ','W','H','E','R','E',' ' ,'`','_','P','r','o','p','e','r','t','y','`',
2100 '=','?',0};
2102 if (!name || !*name)
2103 return NULL;
2105 rec = MSI_CreateRecord(1);
2106 if (!rec)
2107 return NULL;
2109 MSI_RecordSetStringW(rec, 1, name);
2111 r = MSI_DatabaseOpenViewW(db, query, &view);
2112 if (r == ERROR_SUCCESS)
2114 MSI_ViewExecute(view, rec);
2115 MSI_ViewFetch(view, &row);
2116 MSI_ViewClose(view);
2117 msiobj_release(&view->hdr);
2120 msiobj_release(&rec->hdr);
2121 return row;
2124 /* internal function, not compatible with MsiGetPropertyW */
2125 UINT msi_get_property( MSIDATABASE *db, LPCWSTR szName,
2126 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2128 MSIRECORD *row;
2129 UINT rc = ERROR_FUNCTION_FAILED;
2131 row = msi_get_property_row( db, szName );
2133 if (*pchValueBuf > 0)
2134 szValueBuf[0] = 0;
2136 if (row)
2138 rc = MSI_RecordGetStringW(row, 1, szValueBuf, pchValueBuf);
2139 msiobj_release(&row->hdr);
2142 if (rc == ERROR_SUCCESS)
2143 TRACE("returning %s for property %s\n", debugstr_w(szValueBuf),
2144 debugstr_w(szName));
2145 else if (rc == ERROR_MORE_DATA)
2146 TRACE("need %d sized buffer for %s\n", *pchValueBuf,
2147 debugstr_w(szName));
2148 else
2150 *pchValueBuf = 0;
2151 TRACE("property %s not found\n", debugstr_w(szName));
2154 return rc;
2157 LPWSTR msi_dup_property(MSIDATABASE *db, LPCWSTR prop)
2159 DWORD sz = 0;
2160 LPWSTR str;
2161 UINT r;
2163 r = msi_get_property(db, prop, NULL, &sz);
2164 if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
2165 return NULL;
2167 sz++;
2168 str = msi_alloc(sz * sizeof(WCHAR));
2169 r = msi_get_property(db, prop, str, &sz);
2170 if (r != ERROR_SUCCESS)
2172 msi_free(str);
2173 str = NULL;
2176 return str;
2179 int msi_get_property_int( MSIDATABASE *db, LPCWSTR prop, int def )
2181 LPWSTR str = msi_dup_property( db, prop );
2182 int val = str ? atoiW(str) : def;
2183 msi_free(str);
2184 return val;
2187 static UINT MSI_GetProperty( MSIHANDLE handle, LPCWSTR name,
2188 awstring *szValueBuf, LPDWORD pchValueBuf )
2190 MSIPACKAGE *package;
2191 MSIRECORD *row = NULL;
2192 UINT r = ERROR_FUNCTION_FAILED;
2193 LPCWSTR val = NULL;
2195 TRACE("%u %s %p %p\n", handle, debugstr_w(name),
2196 szValueBuf->str.w, pchValueBuf );
2198 if (!name)
2199 return ERROR_INVALID_PARAMETER;
2201 package = msihandle2msiinfo( handle, MSIHANDLETYPE_PACKAGE );
2202 if (!package)
2204 HRESULT hr;
2205 IWineMsiRemotePackage *remote_package;
2206 LPWSTR value = NULL;
2207 BSTR bname;
2208 DWORD len;
2210 remote_package = (IWineMsiRemotePackage *)msi_get_remote( handle );
2211 if (!remote_package)
2212 return ERROR_INVALID_HANDLE;
2214 bname = SysAllocString( name );
2215 if (!bname)
2217 IWineMsiRemotePackage_Release( remote_package );
2218 return ERROR_OUTOFMEMORY;
2221 len = 0;
2222 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, NULL, &len );
2223 if (FAILED(hr))
2224 goto done;
2226 len++;
2227 value = msi_alloc(len * sizeof(WCHAR));
2228 if (!value)
2230 r = ERROR_OUTOFMEMORY;
2231 goto done;
2234 hr = IWineMsiRemotePackage_GetProperty( remote_package, bname, (BSTR *)value, &len );
2235 if (FAILED(hr))
2236 goto done;
2238 r = msi_strcpy_to_awstring( value, szValueBuf, pchValueBuf );
2240 /* Bug required by Adobe installers */
2241 if (!szValueBuf->unicode && !szValueBuf->str.a)
2242 *pchValueBuf *= sizeof(WCHAR);
2244 done:
2245 IWineMsiRemotePackage_Release(remote_package);
2246 SysFreeString(bname);
2247 msi_free(value);
2249 if (FAILED(hr))
2251 if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
2252 return HRESULT_CODE(hr);
2254 return ERROR_FUNCTION_FAILED;
2257 return r;
2260 row = msi_get_property_row( package->db, name );
2261 if (row)
2262 val = MSI_RecordGetString( row, 1 );
2264 if (!val)
2265 val = szEmpty;
2267 r = msi_strcpy_to_awstring( val, szValueBuf, pchValueBuf );
2269 if (row)
2270 msiobj_release( &row->hdr );
2271 msiobj_release( &package->hdr );
2273 return r;
2276 UINT WINAPI MsiGetPropertyA( MSIHANDLE hInstall, LPCSTR szName,
2277 LPSTR szValueBuf, LPDWORD pchValueBuf )
2279 awstring val;
2280 LPWSTR name;
2281 UINT r;
2283 val.unicode = FALSE;
2284 val.str.a = szValueBuf;
2286 name = strdupAtoW( szName );
2287 if (szName && !name)
2288 return ERROR_OUTOFMEMORY;
2290 r = MSI_GetProperty( hInstall, name, &val, pchValueBuf );
2291 msi_free( name );
2292 return r;
2295 UINT WINAPI MsiGetPropertyW( MSIHANDLE hInstall, LPCWSTR szName,
2296 LPWSTR szValueBuf, LPDWORD pchValueBuf )
2298 awstring val;
2300 val.unicode = TRUE;
2301 val.str.w = szValueBuf;
2303 return MSI_GetProperty( hInstall, szName, &val, pchValueBuf );
2306 typedef struct _msi_remote_package_impl {
2307 IWineMsiRemotePackage IWineMsiRemotePackage_iface;
2308 MSIHANDLE package;
2309 LONG refs;
2310 } msi_remote_package_impl;
2312 static inline msi_remote_package_impl *impl_from_IWineMsiRemotePackage( IWineMsiRemotePackage *iface )
2314 return CONTAINING_RECORD(iface, msi_remote_package_impl, IWineMsiRemotePackage_iface);
2317 static HRESULT WINAPI mrp_QueryInterface( IWineMsiRemotePackage *iface,
2318 REFIID riid,LPVOID *ppobj)
2320 if( IsEqualCLSID( riid, &IID_IUnknown ) ||
2321 IsEqualCLSID( riid, &IID_IWineMsiRemotePackage ) )
2323 IUnknown_AddRef( iface );
2324 *ppobj = iface;
2325 return S_OK;
2328 return E_NOINTERFACE;
2331 static ULONG WINAPI mrp_AddRef( IWineMsiRemotePackage *iface )
2333 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2335 return InterlockedIncrement( &This->refs );
2338 static ULONG WINAPI mrp_Release( IWineMsiRemotePackage *iface )
2340 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2341 ULONG r;
2343 r = InterlockedDecrement( &This->refs );
2344 if (r == 0)
2346 MsiCloseHandle( This->package );
2347 msi_free( This );
2349 return r;
2352 static HRESULT WINAPI mrp_SetMsiHandle( IWineMsiRemotePackage *iface, MSIHANDLE handle )
2354 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2355 This->package = handle;
2356 return S_OK;
2359 static HRESULT WINAPI mrp_GetActiveDatabase( IWineMsiRemotePackage *iface, MSIHANDLE *handle )
2361 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2362 IWineMsiRemoteDatabase *rdb = NULL;
2363 HRESULT hr;
2364 MSIHANDLE hdb;
2366 hr = create_msi_remote_database( NULL, (LPVOID *)&rdb );
2367 if (FAILED(hr) || !rdb)
2369 ERR("Failed to create remote database\n");
2370 return hr;
2373 hdb = MsiGetActiveDatabase(This->package);
2375 hr = IWineMsiRemoteDatabase_SetMsiHandle( rdb, hdb );
2376 if (FAILED(hr))
2378 ERR("Failed to set the database handle\n");
2379 return hr;
2382 *handle = alloc_msi_remote_handle( (IUnknown *)rdb );
2383 return S_OK;
2386 static HRESULT WINAPI mrp_GetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR *value, DWORD *size )
2388 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2389 UINT r;
2391 r = MsiGetPropertyW(This->package, (LPWSTR)property, (LPWSTR)value, size);
2392 if (r != ERROR_SUCCESS)
2393 return HRESULT_FROM_WIN32(r);
2395 return S_OK;
2398 static HRESULT WINAPI mrp_SetProperty( IWineMsiRemotePackage *iface, BSTR property, BSTR value )
2400 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2401 UINT r = MsiSetPropertyW(This->package, property, value);
2402 return HRESULT_FROM_WIN32(r);
2405 static HRESULT WINAPI mrp_ProcessMessage( IWineMsiRemotePackage *iface, INSTALLMESSAGE message, MSIHANDLE record )
2407 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2408 UINT r = MsiProcessMessage(This->package, message, record);
2409 return HRESULT_FROM_WIN32(r);
2412 static HRESULT WINAPI mrp_DoAction( IWineMsiRemotePackage *iface, BSTR action )
2414 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2415 UINT r = MsiDoActionW(This->package, action);
2416 return HRESULT_FROM_WIN32(r);
2419 static HRESULT WINAPI mrp_Sequence( IWineMsiRemotePackage *iface, BSTR table, int sequence )
2421 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2422 UINT r = MsiSequenceW(This->package, table, sequence);
2423 return HRESULT_FROM_WIN32(r);
2426 static HRESULT WINAPI mrp_GetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2428 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2429 UINT r = MsiGetTargetPathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2430 return HRESULT_FROM_WIN32(r);
2433 static HRESULT WINAPI mrp_SetTargetPath( IWineMsiRemotePackage *iface, BSTR folder, BSTR value)
2435 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2436 UINT r = MsiSetTargetPathW(This->package, folder, value);
2437 return HRESULT_FROM_WIN32(r);
2440 static HRESULT WINAPI mrp_GetSourcePath( IWineMsiRemotePackage *iface, BSTR folder, BSTR *value, DWORD *size )
2442 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2443 UINT r = MsiGetSourcePathW(This->package, (LPWSTR)folder, (LPWSTR)value, size);
2444 return HRESULT_FROM_WIN32(r);
2447 static HRESULT WINAPI mrp_GetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL *ret )
2449 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2450 *ret = MsiGetMode(This->package, mode);
2451 return S_OK;
2454 static HRESULT WINAPI mrp_SetMode( IWineMsiRemotePackage *iface, MSIRUNMODE mode, BOOL state )
2456 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2457 UINT r = MsiSetMode(This->package, mode, state);
2458 return HRESULT_FROM_WIN32(r);
2461 static HRESULT WINAPI mrp_GetFeatureState( IWineMsiRemotePackage *iface, BSTR feature,
2462 INSTALLSTATE *installed, INSTALLSTATE *action )
2464 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2465 UINT r = MsiGetFeatureStateW(This->package, feature, installed, action);
2466 return HRESULT_FROM_WIN32(r);
2469 static HRESULT WINAPI mrp_SetFeatureState( IWineMsiRemotePackage *iface, BSTR feature, INSTALLSTATE state )
2471 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2472 UINT r = MsiSetFeatureStateW(This->package, feature, state);
2473 return HRESULT_FROM_WIN32(r);
2476 static HRESULT WINAPI mrp_GetComponentState( IWineMsiRemotePackage *iface, BSTR component,
2477 INSTALLSTATE *installed, INSTALLSTATE *action )
2479 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2480 UINT r = MsiGetComponentStateW(This->package, component, installed, action);
2481 return HRESULT_FROM_WIN32(r);
2484 static HRESULT WINAPI mrp_SetComponentState( IWineMsiRemotePackage *iface, BSTR component, INSTALLSTATE state )
2486 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2487 UINT r = MsiSetComponentStateW(This->package, component, state);
2488 return HRESULT_FROM_WIN32(r);
2491 static HRESULT WINAPI mrp_GetLanguage( IWineMsiRemotePackage *iface, LANGID *language )
2493 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2494 *language = MsiGetLanguage(This->package);
2495 return S_OK;
2498 static HRESULT WINAPI mrp_SetInstallLevel( IWineMsiRemotePackage *iface, int level )
2500 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2501 UINT r = MsiSetInstallLevel(This->package, level);
2502 return HRESULT_FROM_WIN32(r);
2505 static HRESULT WINAPI mrp_FormatRecord( IWineMsiRemotePackage *iface, MSIHANDLE record,
2506 BSTR *value)
2508 DWORD size = 0;
2509 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2510 UINT r = MsiFormatRecordW(This->package, record, NULL, &size);
2511 if (r == ERROR_SUCCESS)
2513 *value = SysAllocStringLen(NULL, size);
2514 if (!*value)
2515 return E_OUTOFMEMORY;
2516 size++;
2517 r = MsiFormatRecordW(This->package, record, *value, &size);
2519 return HRESULT_FROM_WIN32(r);
2522 static HRESULT WINAPI mrp_EvaluateCondition( IWineMsiRemotePackage *iface, BSTR condition )
2524 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2525 UINT r = MsiEvaluateConditionW(This->package, condition);
2526 return HRESULT_FROM_WIN32(r);
2529 static HRESULT WINAPI mrp_GetFeatureCost( IWineMsiRemotePackage *iface, BSTR feature,
2530 INT cost_tree, INSTALLSTATE state, INT *cost )
2532 msi_remote_package_impl* This = impl_from_IWineMsiRemotePackage( iface );
2533 UINT r = MsiGetFeatureCostW(This->package, feature, cost_tree, state, cost);
2534 return HRESULT_FROM_WIN32(r);
2537 static const IWineMsiRemotePackageVtbl msi_remote_package_vtbl =
2539 mrp_QueryInterface,
2540 mrp_AddRef,
2541 mrp_Release,
2542 mrp_SetMsiHandle,
2543 mrp_GetActiveDatabase,
2544 mrp_GetProperty,
2545 mrp_SetProperty,
2546 mrp_ProcessMessage,
2547 mrp_DoAction,
2548 mrp_Sequence,
2549 mrp_GetTargetPath,
2550 mrp_SetTargetPath,
2551 mrp_GetSourcePath,
2552 mrp_GetMode,
2553 mrp_SetMode,
2554 mrp_GetFeatureState,
2555 mrp_SetFeatureState,
2556 mrp_GetComponentState,
2557 mrp_SetComponentState,
2558 mrp_GetLanguage,
2559 mrp_SetInstallLevel,
2560 mrp_FormatRecord,
2561 mrp_EvaluateCondition,
2562 mrp_GetFeatureCost,
2565 HRESULT create_msi_remote_package( IUnknown *pOuter, LPVOID *ppObj )
2567 msi_remote_package_impl* This;
2569 This = msi_alloc( sizeof *This );
2570 if (!This)
2571 return E_OUTOFMEMORY;
2573 This->IWineMsiRemotePackage_iface.lpVtbl = &msi_remote_package_vtbl;
2574 This->package = 0;
2575 This->refs = 1;
2577 *ppObj = This;
2579 return S_OK;
2582 UINT msi_package_add_info(MSIPACKAGE *package, DWORD context, DWORD options,
2583 LPCWSTR property, LPWSTR value)
2585 MSISOURCELISTINFO *info;
2587 LIST_FOR_EACH_ENTRY( info, &package->sourcelist_info, MSISOURCELISTINFO, entry )
2589 if (!strcmpW( info->value, value )) return ERROR_SUCCESS;
2592 info = msi_alloc(sizeof(MSISOURCELISTINFO));
2593 if (!info)
2594 return ERROR_OUTOFMEMORY;
2596 info->context = context;
2597 info->options = options;
2598 info->property = property;
2599 info->value = strdupW(value);
2600 list_add_head(&package->sourcelist_info, &info->entry);
2602 return ERROR_SUCCESS;
2605 UINT msi_package_add_media_disk(MSIPACKAGE *package, DWORD context, DWORD options,
2606 DWORD disk_id, LPWSTR volume_label, LPWSTR disk_prompt)
2608 MSIMEDIADISK *disk;
2610 LIST_FOR_EACH_ENTRY( disk, &package->sourcelist_media, MSIMEDIADISK, entry )
2612 if (disk->disk_id == disk_id) return ERROR_SUCCESS;
2615 disk = msi_alloc(sizeof(MSIMEDIADISK));
2616 if (!disk)
2617 return ERROR_OUTOFMEMORY;
2619 disk->context = context;
2620 disk->options = options;
2621 disk->disk_id = disk_id;
2622 disk->volume_label = strdupW(volume_label);
2623 disk->disk_prompt = strdupW(disk_prompt);
2624 list_add_head(&package->sourcelist_media, &disk->entry);
2626 return ERROR_SUCCESS;