2 * Implementation of the Microsoft Installer (msi.dll)
4 * Copyright 2008 James Hawkins
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
27 #include "wine/debug.h"
34 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
38 /* from msvcrt/fcntl.h */
42 #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
43 #define _O_APPEND 0x0008
44 #define _O_RANDOM 0x0010
45 #define _O_SEQUENTIAL 0x0020
46 #define _O_TEMPORARY 0x0040
47 #define _O_NOINHERIT 0x0080
48 #define _O_CREAT 0x0100
49 #define _O_TRUNC 0x0200
50 #define _O_EXCL 0x0400
51 #define _O_SHORT_LIVED 0x1000
52 #define _O_TEXT 0x4000
53 #define _O_BINARY 0x8000
55 static BOOL source_matches_volume(MSIMEDIAINFO *mi, LPCWSTR source_root)
57 WCHAR volume_name[MAX_PATH + 1];
58 WCHAR root[MAX_PATH + 1];
60 strcpyW(root, source_root);
61 PathStripToRootW(root);
62 PathAddBackslashW(root);
64 if (!GetVolumeInformationW(root, volume_name, MAX_PATH + 1,
65 NULL, NULL, NULL, NULL, 0))
67 ERR("Failed to get volume information\n");
71 return !strcmpW( mi->volume_label, volume_name );
74 static UINT msi_change_media(MSIPACKAGE *package, MSIMEDIAINFO *mi)
76 LPWSTR error, error_dialog;
78 UINT r = ERROR_SUCCESS;
80 static const WCHAR error_prop[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
82 if ((msi_get_property_int(package->db, szUILevel, 0) & INSTALLUILEVEL_MASK) ==
83 INSTALLUILEVEL_NONE && !gUIHandlerA && !gUIHandlerW && !gUIHandlerRecord)
86 error = msi_build_error_string(package, 1302, 1, mi->disk_prompt);
87 error_dialog = msi_dup_property(package->db, error_prop);
88 source_dir = msi_dup_property(package->db, szSourceDir);
90 while (r == ERROR_SUCCESS && !source_matches_volume(mi, source_dir))
92 r = msi_spawn_error_dialog(package, error_dialog, error);
96 gUIHandlerW(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, error);
100 char *msg = strdupWtoA(error);
101 gUIHandlerA(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, msg);
104 else if (gUIHandlerRecord)
106 MSIHANDLE rec = MsiCreateRecord(1);
107 MsiRecordSetStringW(rec, 0, error);
108 gUIHandlerRecord(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, rec);
114 msi_free(error_dialog);
115 msi_free(source_dir);
120 static MSICABINETSTREAM *msi_get_cabinet_stream( MSIPACKAGE *package, UINT disk_id )
122 MSICABINETSTREAM *cab;
124 LIST_FOR_EACH_ENTRY( cab, &package->cabinet_streams, MSICABINETSTREAM, entry )
126 if (cab->disk_id == disk_id) return cab;
131 static void * CDECL cabinet_alloc(ULONG cb)
133 return msi_alloc(cb);
136 static void CDECL cabinet_free(void *pv)
141 static INT_PTR CDECL cabinet_open(char *pszFile, int oflag, int pmode)
145 DWORD dwShareMode = 0;
146 DWORD dwCreateDisposition = OPEN_EXISTING;
148 switch (oflag & _O_ACCMODE)
151 dwAccess = GENERIC_READ;
152 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
155 dwAccess = GENERIC_WRITE;
156 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
159 dwAccess = GENERIC_READ | GENERIC_WRITE;
160 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
164 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
165 dwCreateDisposition = CREATE_NEW;
166 else if (oflag & _O_CREAT)
167 dwCreateDisposition = CREATE_ALWAYS;
169 handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
170 dwCreateDisposition, 0, NULL);
171 if (handle == INVALID_HANDLE_VALUE)
174 return (INT_PTR)handle;
177 static UINT CDECL cabinet_read(INT_PTR hf, void *pv, UINT cb)
179 HANDLE handle = (HANDLE)hf;
182 if (ReadFile(handle, pv, cb, &read, NULL))
188 static UINT CDECL cabinet_write(INT_PTR hf, void *pv, UINT cb)
190 HANDLE handle = (HANDLE)hf;
193 if (WriteFile(handle, pv, cb, &written, NULL))
199 static int CDECL cabinet_close(INT_PTR hf)
201 HANDLE handle = (HANDLE)hf;
202 return CloseHandle(handle) ? 0 : -1;
205 static LONG CDECL cabinet_seek(INT_PTR hf, LONG dist, int seektype)
207 HANDLE handle = (HANDLE)hf;
208 /* flags are compatible and so are passed straight through */
209 return SetFilePointer(handle, dist, NULL, seektype);
218 static struct package_disk package_disk;
220 static INT_PTR CDECL cabinet_open_stream( char *pszFile, int oflag, int pmode )
222 MSICABINETSTREAM *cab;
227 cab = msi_get_cabinet_stream( package_disk.package, package_disk.id );
230 WARN("failed to get cabinet stream\n");
233 if (!cab->stream[0] || !(encoded = encode_streamname( FALSE, cab->stream + 1 )))
235 WARN("failed to encode stream name\n");
238 if (msi_clone_open_stream( package_disk.package->db, cab->storage, encoded, &stream ) != ERROR_SUCCESS)
240 hr = IStorage_OpenStream( cab->storage, encoded, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &stream );
243 WARN("failed to open stream 0x%08x\n", hr);
249 return (INT_PTR)stream;
252 static UINT CDECL cabinet_read_stream( INT_PTR hf, void *pv, UINT cb )
254 IStream *stm = (IStream *)hf;
258 hr = IStream_Read( stm, pv, cb, &read );
259 if (hr == S_OK || hr == S_FALSE)
265 static int CDECL cabinet_close_stream( INT_PTR hf )
267 IStream *stm = (IStream *)hf;
268 IStream_Release( stm );
272 static LONG CDECL cabinet_seek_stream( INT_PTR hf, LONG dist, int seektype )
274 IStream *stm = (IStream *)hf;
276 ULARGE_INTEGER newpos;
279 move.QuadPart = dist;
280 hr = IStream_Seek( stm, move, seektype, &newpos );
283 if (newpos.QuadPart <= MAXLONG) return newpos.QuadPart;
289 static UINT CDECL msi_media_get_disk_info(MSIPACKAGE *package, MSIMEDIAINFO *mi)
293 static const WCHAR query[] = {
294 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
295 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
296 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
298 row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
301 TRACE("Unable to query row\n");
302 return ERROR_FUNCTION_FAILED;
305 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
306 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
307 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
309 if (!mi->first_volume)
310 mi->first_volume = strdupW(mi->volume_label);
312 msiobj_release(&row->hdr);
313 return ERROR_SUCCESS;
316 static INT_PTR cabinet_partial_file(FDINOTIFICATIONTYPE fdint,
317 PFDINOTIFICATION pfdin)
319 MSICABDATA *data = pfdin->pv;
320 data->mi->is_continuous = FALSE;
324 static WCHAR *get_cabinet_filename(MSIMEDIAINFO *mi)
329 len = strlenW(mi->sourcedir) + strlenW(mi->cabinet) + 1;
330 if (!(ret = msi_alloc(len * sizeof(WCHAR)))) return NULL;
331 strcpyW(ret, mi->sourcedir);
332 strcatW(ret, mi->cabinet);
336 static INT_PTR cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint,
337 PFDINOTIFICATION pfdin)
339 MSICABDATA *data = pfdin->pv;
340 MSIMEDIAINFO *mi = data->mi;
341 LPWSTR cabinet_file = NULL, cab = strdupAtoW(pfdin->psz1);
345 msi_free(mi->disk_prompt);
346 msi_free(mi->cabinet);
347 msi_free(mi->volume_label);
348 mi->disk_prompt = NULL;
350 mi->volume_label = NULL;
353 mi->is_continuous = TRUE;
355 rc = msi_media_get_disk_info(data->package, mi);
356 if (rc != ERROR_SUCCESS)
358 ERR("Failed to get next cabinet information: %d\n", rc);
362 if (strcmpiW( mi->cabinet, cab ))
364 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
368 if (!(cabinet_file = get_cabinet_filename(mi)))
371 TRACE("Searching for %s\n", debugstr_w(cabinet_file));
374 if (GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
376 if (msi_change_media(data->package, mi) != ERROR_SUCCESS)
382 msi_free(cabinet_file);
386 static INT_PTR cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint,
387 PFDINOTIFICATION pfdin )
389 MSICABDATA *data = pfdin->pv;
390 MSIMEDIAINFO *mi = data->mi;
393 msi_free( mi->disk_prompt );
394 msi_free( mi->cabinet );
395 msi_free( mi->volume_label );
396 mi->disk_prompt = NULL;
398 mi->volume_label = NULL;
401 mi->is_continuous = TRUE;
403 rc = msi_media_get_disk_info( data->package, mi );
404 if (rc != ERROR_SUCCESS)
406 ERR("Failed to get next cabinet information: %u\n", rc);
409 package_disk.id = mi->disk_id;
411 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
415 static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint,
416 PFDINOTIFICATION pfdin)
418 MSICABDATA *data = pfdin->pv;
423 data->curfile = strdupAtoW(pfdin->psz1);
424 if (!data->cb(data->package, data->curfile, MSICABEXTRACT_BEGINEXTRACT, &path,
427 /* We're not extracting this file, so free the filename. */
428 msi_free(data->curfile);
429 data->curfile = NULL;
433 TRACE("extracting %s\n", debugstr_w(path));
435 attrs = attrs & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
436 if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
438 handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0,
439 NULL, CREATE_ALWAYS, attrs, NULL);
440 if (handle == INVALID_HANDLE_VALUE)
442 DWORD err = GetLastError();
443 DWORD attrs2 = GetFileAttributesW(path);
445 if (attrs2 == INVALID_FILE_ATTRIBUTES)
447 ERR("failed to create %s (error %d)\n", debugstr_w(path), err);
450 else if (err == ERROR_ACCESS_DENIED && (attrs2 & FILE_ATTRIBUTE_READONLY))
452 TRACE("removing read-only attribute on %s\n", debugstr_w(path));
453 SetFileAttributesW( path, attrs2 & ~FILE_ATTRIBUTE_READONLY );
454 handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs2, NULL);
456 if (handle != INVALID_HANDLE_VALUE) goto done;
457 err = GetLastError();
459 if (err == ERROR_SHARING_VIOLATION || err == ERROR_USER_MAPPED_FILE)
461 WCHAR tmpfileW[MAX_PATH], *tmppathW, *p;
464 TRACE("file in use, scheduling rename operation\n");
466 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
467 len = strlenW(path) + strlenW(tmpfileW) + 1;
468 if (!(tmppathW = msi_alloc(len * sizeof(WCHAR))))
469 return ERROR_OUTOFMEMORY;
471 strcpyW(tmppathW, path);
472 if ((p = strrchrW(tmppathW, '\\'))) *p = 0;
473 strcatW(tmppathW, tmpfileW);
475 handle = CreateFileW(tmppathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
477 if (handle != INVALID_HANDLE_VALUE &&
478 MoveFileExW(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
479 MoveFileExW(tmppathW, path, MOVEFILE_DELAY_UNTIL_REBOOT))
481 data->package->need_reboot = 1;
484 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path), GetLastError());
489 WARN("failed to create %s (error %d)\n", debugstr_w(path), err);
495 return (INT_PTR)handle;
498 static INT_PTR cabinet_close_file_info(FDINOTIFICATIONTYPE fdint,
499 PFDINOTIFICATION pfdin)
501 MSICABDATA *data = pfdin->pv;
504 HANDLE handle = (HANDLE)pfdin->hf;
506 data->mi->is_continuous = FALSE;
508 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
510 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
512 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
517 data->cb(data->package, data->curfile, MSICABEXTRACT_FILEEXTRACTED, NULL, NULL,
520 msi_free(data->curfile);
521 data->curfile = NULL;
526 static INT_PTR CDECL cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
530 case fdintPARTIAL_FILE:
531 return cabinet_partial_file(fdint, pfdin);
533 case fdintNEXT_CABINET:
534 return cabinet_next_cabinet(fdint, pfdin);
537 return cabinet_copy_file(fdint, pfdin);
539 case fdintCLOSE_FILE_INFO:
540 return cabinet_close_file_info(fdint, pfdin);
547 static INT_PTR CDECL cabinet_notify_stream( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin )
551 case fdintPARTIAL_FILE:
552 return cabinet_partial_file( fdint, pfdin );
554 case fdintNEXT_CABINET:
555 return cabinet_next_cabinet_stream( fdint, pfdin );
558 return cabinet_copy_file( fdint, pfdin );
560 case fdintCLOSE_FILE_INFO:
561 return cabinet_close_file_info( fdint, pfdin );
563 case fdintCABINET_INFO:
567 ERR("Unexpected notification %d\n", fdint);
572 static BOOL extract_cabinet( MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data )
574 LPSTR cabinet, cab_path = NULL;
579 TRACE("extracting %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
581 hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
582 cabinet_write, cabinet_close, cabinet_seek, 0, &erf );
585 ERR("FDICreate failed\n");
589 cabinet = strdupWtoA( mi->cabinet );
593 cab_path = strdupWtoA( mi->sourcedir );
597 ret = FDICopy( hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, data );
599 ERR("FDICopy failed\n");
604 msi_free( cab_path );
607 mi->is_extracted = TRUE;
612 static BOOL extract_cabinet_stream( MSIPACKAGE *package, MSIMEDIAINFO *mi, LPVOID data )
614 static char filename[] = {'<','S','T','R','E','A','M','>',0};
619 TRACE("extracting %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
621 hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open_stream, cabinet_read_stream,
622 cabinet_write, cabinet_close_stream, cabinet_seek_stream, 0, &erf );
625 ERR("FDICreate failed\n");
629 package_disk.package = package;
630 package_disk.id = mi->disk_id;
632 ret = FDICopy( hfdi, filename, NULL, 0, cabinet_notify_stream, NULL, data );
633 if (!ret) ERR("FDICopy failed\n");
636 if (ret) mi->is_extracted = TRUE;
640 /***********************************************************************
643 * Extract files from a cabinet file or stream.
645 BOOL msi_cabextract(MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data)
647 if (mi->cabinet[0] == '#')
649 return extract_cabinet_stream( package, mi, data );
651 return extract_cabinet( package, mi, data );
654 void msi_free_media_info(MSIMEDIAINFO *mi)
656 msi_free(mi->disk_prompt);
657 msi_free(mi->cabinet);
658 msi_free(mi->volume_label);
659 msi_free(mi->first_volume);
663 static UINT get_drive_type(const WCHAR *path)
665 WCHAR root[MAX_PATH + 1];
668 PathStripToRootW(root);
669 PathAddBackslashW(root);
671 return GetDriveTypeW(root);
674 UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
676 static const WCHAR query[] = {
677 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
678 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
679 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
681 LPWSTR source_dir, source;
684 if (Sequence <= mi->last_sequence) /* already loaded */
685 return ERROR_SUCCESS;
687 row = MSI_QueryGetRecord(package->db, query, Sequence);
690 TRACE("Unable to query row\n");
691 return ERROR_FUNCTION_FAILED;
694 mi->is_extracted = FALSE;
695 mi->disk_id = MSI_RecordGetInteger(row, 1);
696 mi->last_sequence = MSI_RecordGetInteger(row, 2);
697 msi_free(mi->disk_prompt);
698 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
699 msi_free(mi->cabinet);
700 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
701 msi_free(mi->volume_label);
702 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
703 msiobj_release(&row->hdr);
705 if (!mi->first_volume)
706 mi->first_volume = strdupW(mi->volume_label);
708 msi_set_sourcedir_props(package, FALSE);
709 source_dir = msi_dup_property(package->db, szSourceDir);
710 lstrcpyW(mi->sourcedir, source_dir);
711 mi->type = get_drive_type(source_dir);
713 options = MSICODE_PRODUCT;
714 if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
717 options |= MSISOURCETYPE_MEDIA;
719 else if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
721 source = package->BaseURL;
722 options |= MSISOURCETYPE_URL;
726 source = mi->sourcedir;
727 options |= MSISOURCETYPE_NETWORK;
730 msi_package_add_media_disk(package, package->Context,
731 MSICODE_PRODUCT, mi->disk_id,
732 mi->volume_label, mi->disk_prompt);
734 msi_package_add_info(package, package->Context,
735 options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
737 msi_free(source_dir);
738 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence, debugstr_w(mi->cabinet), mi->disk_id);
739 return ERROR_SUCCESS;
742 /* FIXME: search URL sources as well */
743 static UINT find_published_source(MSIPACKAGE *package, MSIMEDIAINFO *mi)
745 WCHAR source[MAX_PATH];
746 WCHAR volume[MAX_PATH];
747 WCHAR prompt[MAX_PATH];
748 DWORD volumesz, promptsz;
749 DWORD index, size, id;
754 r = MsiSourceListGetInfoW(package->ProductCode, NULL,
755 package->Context, MSICODE_PRODUCT,
756 INSTALLPROPERTY_LASTUSEDTYPEW, last_type, &size);
757 if (r != ERROR_SUCCESS)
761 r = MsiSourceListGetInfoW(package->ProductCode, NULL,
762 package->Context, MSICODE_PRODUCT,
763 INSTALLPROPERTY_LASTUSEDSOURCEW, source, &size);
764 if (r != ERROR_SUCCESS)
767 if (last_type[0] == 'n')
769 WCHAR cabinet_file[MAX_PATH];
770 BOOL check_all = FALSE;
776 while (MsiSourceListEnumSourcesW(package->ProductCode, NULL,
778 MSISOURCETYPE_NETWORK, index++,
779 volume, &volumesz) == ERROR_SUCCESS)
781 if (check_all || !strncmpiW(source, volume, strlenW(source)))
783 lstrcpyW(cabinet_file, volume);
784 PathAddBackslashW(cabinet_file);
785 lstrcatW(cabinet_file, mi->cabinet);
787 if (GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
795 lstrcpyW(mi->sourcedir, volume);
796 TRACE("Found network source %s\n", debugstr_w(mi->sourcedir));
797 return ERROR_SUCCESS;
811 while (MsiSourceListEnumMediaDisksW(package->ProductCode, NULL,
813 MSICODE_PRODUCT, index++, &id,
814 volume, &volumesz, prompt, &promptsz) == ERROR_SUCCESS)
817 mi->volume_label = msi_realloc(mi->volume_label, ++volumesz * sizeof(WCHAR));
818 lstrcpyW(mi->volume_label, volume);
819 mi->disk_prompt = msi_realloc(mi->disk_prompt, ++promptsz * sizeof(WCHAR));
820 lstrcpyW(mi->disk_prompt, prompt);
822 if (source_matches_volume(mi, source))
824 /* FIXME: what about SourceDir */
825 lstrcpyW(mi->sourcedir, source);
826 TRACE("Found disk source %s\n", debugstr_w(mi->sourcedir));
827 return ERROR_SUCCESS;
831 return ERROR_FUNCTION_FAILED;
834 UINT ready_media(MSIPACKAGE *package, UINT Sequence, BOOL IsCompressed, MSIMEDIAINFO *mi)
836 UINT rc = ERROR_SUCCESS;
839 /* media info for continuous cabinet is already loaded */
840 if (mi->is_continuous)
841 return ERROR_SUCCESS;
843 /* cabinet is internal, no checks needed */
844 if (!mi->cabinet || mi->cabinet[0] == '#')
845 return ERROR_SUCCESS;
847 cabinet_file = get_cabinet_filename(mi);
849 /* package should be downloaded */
851 GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES &&
852 package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
854 WCHAR temppath[MAX_PATH], *p;
856 rc = msi_download_file(cabinet_file, temppath);
857 if (rc != ERROR_SUCCESS)
859 ERR("Failed to download %s (%u)\n", debugstr_w(cabinet_file), rc);
860 msi_free(cabinet_file);
863 if ((p = strrchrW(temppath, '\\'))) *p = 0;
864 strcpyW(mi->sourcedir, temppath);
865 msi_free(mi->cabinet);
866 mi->cabinet = strdupW(p + 1);
868 msi_free(cabinet_file);
869 return ERROR_SUCCESS;
872 /* check volume matches, change media if not */
873 if (mi->volume_label && mi->disk_id > 1 &&
874 strcmpW( mi->first_volume, mi->volume_label ))
876 LPWSTR source = msi_dup_property(package->db, szSourceDir);
879 matches = source_matches_volume(mi, source);
882 if ((mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE) && !matches)
884 rc = msi_change_media(package, mi);
885 if (rc != ERROR_SUCCESS)
887 msi_free(cabinet_file);
894 GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
896 rc = find_published_source(package, mi);
897 if (rc != ERROR_SUCCESS)
899 ERR("Cabinet not found: %s\n", debugstr_w(cabinet_file));
900 msi_free(cabinet_file);
901 return ERROR_INSTALL_FAILURE;
905 msi_free(cabinet_file);
906 return ERROR_SUCCESS;
909 UINT msi_add_cabinet_stream( MSIPACKAGE *package, UINT disk_id, IStorage *storage, const WCHAR *name )
911 MSICABINETSTREAM *cab, *item;
913 TRACE("%p, %u, %p, %s\n", package, disk_id, storage, debugstr_w(name));
915 LIST_FOR_EACH_ENTRY( item, &package->cabinet_streams, MSICABINETSTREAM, entry )
917 if (item->disk_id == disk_id)
919 TRACE("duplicate disk id %u\n", disk_id);
920 return ERROR_FUNCTION_FAILED;
923 if (!(cab = msi_alloc( sizeof(*cab) ))) return ERROR_OUTOFMEMORY;
924 if (!(cab->stream = msi_alloc( (strlenW( name ) + 1) * sizeof(WCHAR ) )))
927 return ERROR_OUTOFMEMORY;
929 strcpyW( cab->stream, name );
930 cab->disk_id = disk_id;
931 cab->storage = storage;
932 IStorage_AddRef( storage );
933 list_add_tail( &package->cabinet_streams, &cab->entry );
935 return ERROR_SUCCESS;