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 hr = IStorage_OpenStream( cab->storage, encoded, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &stream );
242 WARN("failed to open stream 0x%08x\n", hr);
245 return (INT_PTR)stream;
248 static UINT CDECL cabinet_read_stream( INT_PTR hf, void *pv, UINT cb )
250 IStream *stm = (IStream *)hf;
254 hr = IStream_Read( stm, pv, cb, &read );
255 if (hr == S_OK || hr == S_FALSE)
261 static int CDECL cabinet_close_stream( INT_PTR hf )
263 IStream *stm = (IStream *)hf;
264 IStream_Release( stm );
268 static LONG CDECL cabinet_seek_stream( INT_PTR hf, LONG dist, int seektype )
270 IStream *stm = (IStream *)hf;
272 ULARGE_INTEGER newpos;
275 move.QuadPart = dist;
276 hr = IStream_Seek( stm, move, seektype, &newpos );
279 if (newpos.QuadPart <= MAXLONG) return newpos.QuadPart;
285 static UINT CDECL msi_media_get_disk_info(MSIPACKAGE *package, MSIMEDIAINFO *mi)
289 static const WCHAR query[] = {
290 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
291 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
292 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
294 row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
297 TRACE("Unable to query row\n");
298 return ERROR_FUNCTION_FAILED;
301 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
302 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
303 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
305 if (!mi->first_volume)
306 mi->first_volume = strdupW(mi->volume_label);
308 msiobj_release(&row->hdr);
309 return ERROR_SUCCESS;
312 static INT_PTR cabinet_partial_file(FDINOTIFICATIONTYPE fdint,
313 PFDINOTIFICATION pfdin)
315 MSICABDATA *data = pfdin->pv;
316 data->mi->is_continuous = FALSE;
320 static WCHAR *get_cabinet_filename(MSIMEDIAINFO *mi)
325 len = strlenW(mi->sourcedir) + strlenW(mi->cabinet) + 1;
326 if (!(ret = msi_alloc(len * sizeof(WCHAR)))) return NULL;
327 strcpyW(ret, mi->sourcedir);
328 strcatW(ret, mi->cabinet);
332 static INT_PTR cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint,
333 PFDINOTIFICATION pfdin)
335 MSICABDATA *data = pfdin->pv;
336 MSIMEDIAINFO *mi = data->mi;
337 LPWSTR cabinet_file = NULL, cab = strdupAtoW(pfdin->psz1);
341 msi_free(mi->disk_prompt);
342 msi_free(mi->cabinet);
343 msi_free(mi->volume_label);
344 mi->disk_prompt = NULL;
346 mi->volume_label = NULL;
349 mi->is_continuous = TRUE;
351 rc = msi_media_get_disk_info(data->package, mi);
352 if (rc != ERROR_SUCCESS)
354 ERR("Failed to get next cabinet information: %d\n", rc);
358 if (strcmpiW( mi->cabinet, cab ))
360 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
364 if (!(cabinet_file = get_cabinet_filename(mi)))
367 TRACE("Searching for %s\n", debugstr_w(cabinet_file));
370 if (GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
372 if (msi_change_media(data->package, mi) != ERROR_SUCCESS)
378 msi_free(cabinet_file);
382 static INT_PTR cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint,
383 PFDINOTIFICATION pfdin )
385 MSICABDATA *data = pfdin->pv;
386 MSIMEDIAINFO *mi = data->mi;
389 msi_free( mi->disk_prompt );
390 msi_free( mi->cabinet );
391 msi_free( mi->volume_label );
392 mi->disk_prompt = NULL;
394 mi->volume_label = NULL;
397 mi->is_continuous = TRUE;
399 rc = msi_media_get_disk_info( data->package, mi );
400 if (rc != ERROR_SUCCESS)
402 ERR("Failed to get next cabinet information: %u\n", rc);
405 package_disk.id = mi->disk_id;
407 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
411 static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint,
412 PFDINOTIFICATION pfdin)
414 MSICABDATA *data = pfdin->pv;
419 data->curfile = strdupAtoW(pfdin->psz1);
420 if (!data->cb(data->package, data->curfile, MSICABEXTRACT_BEGINEXTRACT, &path,
423 /* We're not extracting this file, so free the filename. */
424 msi_free(data->curfile);
425 data->curfile = NULL;
429 TRACE("extracting %s\n", debugstr_w(path));
431 attrs = attrs & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
432 if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
434 handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0,
435 NULL, CREATE_ALWAYS, attrs, NULL);
436 if (handle == INVALID_HANDLE_VALUE)
438 DWORD err = GetLastError();
439 DWORD attrs2 = GetFileAttributesW(path);
441 if (attrs2 == INVALID_FILE_ATTRIBUTES)
443 ERR("failed to create %s (error %d)\n", debugstr_w(path), err);
446 else if (err == ERROR_ACCESS_DENIED && (attrs2 & FILE_ATTRIBUTE_READONLY))
448 TRACE("removing read-only attribute on %s\n", debugstr_w(path));
449 SetFileAttributesW( path, attrs2 & ~FILE_ATTRIBUTE_READONLY );
450 handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs2, NULL);
452 if (handle != INVALID_HANDLE_VALUE) goto done;
453 err = GetLastError();
455 if (err == ERROR_SHARING_VIOLATION || err == ERROR_USER_MAPPED_FILE)
457 WCHAR tmpfileW[MAX_PATH], *tmppathW, *p;
460 TRACE("file in use, scheduling rename operation\n");
462 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
463 len = strlenW(path) + strlenW(tmpfileW) + 1;
464 if (!(tmppathW = msi_alloc(len * sizeof(WCHAR))))
465 return ERROR_OUTOFMEMORY;
467 strcpyW(tmppathW, path);
468 if ((p = strrchrW(tmppathW, '\\'))) *p = 0;
469 strcatW(tmppathW, tmpfileW);
471 handle = CreateFileW(tmppathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
473 if (handle != INVALID_HANDLE_VALUE &&
474 MoveFileExW(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
475 MoveFileExW(tmppathW, path, MOVEFILE_DELAY_UNTIL_REBOOT))
477 data->package->need_reboot = 1;
480 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path), GetLastError());
485 WARN("failed to create %s (error %d)\n", debugstr_w(path), err);
491 return (INT_PTR)handle;
494 static INT_PTR cabinet_close_file_info(FDINOTIFICATIONTYPE fdint,
495 PFDINOTIFICATION pfdin)
497 MSICABDATA *data = pfdin->pv;
500 HANDLE handle = (HANDLE)pfdin->hf;
502 data->mi->is_continuous = FALSE;
504 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
506 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
508 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
513 data->cb(data->package, data->curfile, MSICABEXTRACT_FILEEXTRACTED, NULL, NULL,
516 msi_free(data->curfile);
517 data->curfile = NULL;
522 static INT_PTR CDECL cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
526 case fdintPARTIAL_FILE:
527 return cabinet_partial_file(fdint, pfdin);
529 case fdintNEXT_CABINET:
530 return cabinet_next_cabinet(fdint, pfdin);
533 return cabinet_copy_file(fdint, pfdin);
535 case fdintCLOSE_FILE_INFO:
536 return cabinet_close_file_info(fdint, pfdin);
543 static INT_PTR CDECL cabinet_notify_stream( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin )
547 case fdintPARTIAL_FILE:
548 return cabinet_partial_file( fdint, pfdin );
550 case fdintNEXT_CABINET:
551 return cabinet_next_cabinet_stream( fdint, pfdin );
554 return cabinet_copy_file( fdint, pfdin );
556 case fdintCLOSE_FILE_INFO:
557 return cabinet_close_file_info( fdint, pfdin );
559 case fdintCABINET_INFO:
563 ERR("Unexpected notification %d\n", fdint);
568 static BOOL extract_cabinet( MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data )
570 LPSTR cabinet, cab_path = NULL;
575 TRACE("extracting %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
577 hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
578 cabinet_write, cabinet_close, cabinet_seek, 0, &erf );
581 ERR("FDICreate failed\n");
585 cabinet = strdupWtoA( mi->cabinet );
589 cab_path = strdupWtoA( mi->sourcedir );
593 ret = FDICopy( hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, data );
595 ERR("FDICopy failed\n");
600 msi_free( cab_path );
603 mi->is_extracted = TRUE;
608 static BOOL extract_cabinet_stream( MSIPACKAGE *package, MSIMEDIAINFO *mi, LPVOID data )
610 static char filename[] = {'<','S','T','R','E','A','M','>',0};
615 TRACE("extracting %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
617 hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open_stream, cabinet_read_stream,
618 cabinet_write, cabinet_close_stream, cabinet_seek_stream, 0, &erf );
621 ERR("FDICreate failed\n");
625 package_disk.package = package;
626 package_disk.id = mi->disk_id;
628 ret = FDICopy( hfdi, filename, NULL, 0, cabinet_notify_stream, NULL, data );
629 if (!ret) ERR("FDICopy failed\n");
632 if (ret) mi->is_extracted = TRUE;
636 /***********************************************************************
639 * Extract files from a cabinet file or stream.
641 BOOL msi_cabextract(MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data)
643 if (mi->cabinet[0] == '#')
645 return extract_cabinet_stream( package, mi, data );
647 return extract_cabinet( package, mi, data );
650 void msi_free_media_info(MSIMEDIAINFO *mi)
652 msi_free(mi->disk_prompt);
653 msi_free(mi->cabinet);
654 msi_free(mi->volume_label);
655 msi_free(mi->first_volume);
659 static UINT get_drive_type(const WCHAR *path)
661 WCHAR root[MAX_PATH + 1];
664 PathStripToRootW(root);
665 PathAddBackslashW(root);
667 return GetDriveTypeW(root);
670 UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
672 static const WCHAR query[] = {
673 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
674 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
675 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
677 LPWSTR source_dir, source;
680 if (Sequence <= mi->last_sequence) /* already loaded */
681 return ERROR_SUCCESS;
683 row = MSI_QueryGetRecord(package->db, query, Sequence);
686 TRACE("Unable to query row\n");
687 return ERROR_FUNCTION_FAILED;
690 mi->is_extracted = FALSE;
691 mi->disk_id = MSI_RecordGetInteger(row, 1);
692 mi->last_sequence = MSI_RecordGetInteger(row, 2);
693 msi_free(mi->disk_prompt);
694 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
695 msi_free(mi->cabinet);
696 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
697 msi_free(mi->volume_label);
698 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
699 msiobj_release(&row->hdr);
701 if (!mi->first_volume)
702 mi->first_volume = strdupW(mi->volume_label);
704 msi_set_sourcedir_props(package, FALSE);
705 source_dir = msi_dup_property(package->db, szSourceDir);
706 lstrcpyW(mi->sourcedir, source_dir);
707 mi->type = get_drive_type(source_dir);
709 options = MSICODE_PRODUCT;
710 if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
713 options |= MSISOURCETYPE_MEDIA;
715 else if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
717 source = package->BaseURL;
718 options |= MSISOURCETYPE_URL;
722 source = mi->sourcedir;
723 options |= MSISOURCETYPE_NETWORK;
726 msi_package_add_media_disk(package, package->Context,
727 MSICODE_PRODUCT, mi->disk_id,
728 mi->volume_label, mi->disk_prompt);
730 msi_package_add_info(package, package->Context,
731 options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
733 msi_free(source_dir);
734 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence, debugstr_w(mi->cabinet), mi->disk_id);
735 return ERROR_SUCCESS;
738 /* FIXME: search URL sources as well */
739 static UINT find_published_source(MSIPACKAGE *package, MSIMEDIAINFO *mi)
741 WCHAR source[MAX_PATH];
742 WCHAR volume[MAX_PATH];
743 WCHAR prompt[MAX_PATH];
744 DWORD volumesz, promptsz;
745 DWORD index, size, id;
750 r = MsiSourceListGetInfoW(package->ProductCode, NULL,
751 package->Context, MSICODE_PRODUCT,
752 INSTALLPROPERTY_LASTUSEDTYPEW, last_type, &size);
753 if (r != ERROR_SUCCESS)
757 r = MsiSourceListGetInfoW(package->ProductCode, NULL,
758 package->Context, MSICODE_PRODUCT,
759 INSTALLPROPERTY_LASTUSEDSOURCEW, source, &size);
760 if (r != ERROR_SUCCESS)
763 if (last_type[0] == 'n')
765 WCHAR cabinet_file[MAX_PATH];
766 BOOL check_all = FALSE;
772 while (MsiSourceListEnumSourcesW(package->ProductCode, NULL,
774 MSISOURCETYPE_NETWORK, index++,
775 volume, &volumesz) == ERROR_SUCCESS)
777 if (check_all || !strncmpiW(source, volume, strlenW(source)))
779 lstrcpyW(cabinet_file, volume);
780 PathAddBackslashW(cabinet_file);
781 lstrcatW(cabinet_file, mi->cabinet);
783 if (GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
791 lstrcpyW(mi->sourcedir, volume);
792 TRACE("Found network source %s\n", debugstr_w(mi->sourcedir));
793 return ERROR_SUCCESS;
807 while (MsiSourceListEnumMediaDisksW(package->ProductCode, NULL,
809 MSICODE_PRODUCT, index++, &id,
810 volume, &volumesz, prompt, &promptsz) == ERROR_SUCCESS)
813 mi->volume_label = msi_realloc(mi->volume_label, ++volumesz * sizeof(WCHAR));
814 lstrcpyW(mi->volume_label, volume);
815 mi->disk_prompt = msi_realloc(mi->disk_prompt, ++promptsz * sizeof(WCHAR));
816 lstrcpyW(mi->disk_prompt, prompt);
818 if (source_matches_volume(mi, source))
820 /* FIXME: what about SourceDir */
821 lstrcpyW(mi->sourcedir, source);
822 TRACE("Found disk source %s\n", debugstr_w(mi->sourcedir));
823 return ERROR_SUCCESS;
827 return ERROR_FUNCTION_FAILED;
830 UINT ready_media(MSIPACKAGE *package, UINT Sequence, BOOL IsCompressed, MSIMEDIAINFO *mi)
832 UINT rc = ERROR_SUCCESS;
835 /* media info for continuous cabinet is already loaded */
836 if (mi->is_continuous)
837 return ERROR_SUCCESS;
839 /* cabinet is internal, no checks needed */
840 if (!mi->cabinet || mi->cabinet[0] == '#')
841 return ERROR_SUCCESS;
843 cabinet_file = get_cabinet_filename(mi);
845 /* package should be downloaded */
847 GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES &&
848 package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
850 WCHAR temppath[MAX_PATH], *p;
852 rc = msi_download_file(cabinet_file, temppath);
853 if (rc != ERROR_SUCCESS)
855 ERR("Failed to download %s (%u)\n", debugstr_w(cabinet_file), rc);
856 msi_free(cabinet_file);
859 if ((p = strrchrW(temppath, '\\'))) *p = 0;
860 strcpyW(mi->sourcedir, temppath);
861 msi_free(mi->cabinet);
862 mi->cabinet = strdupW(p + 1);
864 msi_free(cabinet_file);
865 return ERROR_SUCCESS;
868 /* check volume matches, change media if not */
869 if (mi->volume_label && mi->disk_id > 1 &&
870 strcmpW( mi->first_volume, mi->volume_label ))
872 LPWSTR source = msi_dup_property(package->db, szSourceDir);
875 matches = source_matches_volume(mi, source);
878 if ((mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE) && !matches)
880 rc = msi_change_media(package, mi);
881 if (rc != ERROR_SUCCESS)
883 msi_free(cabinet_file);
890 GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
892 rc = find_published_source(package, mi);
893 if (rc != ERROR_SUCCESS)
895 ERR("Cabinet not found: %s\n", debugstr_w(cabinet_file));
896 msi_free(cabinet_file);
897 return ERROR_INSTALL_FAILURE;
901 msi_free(cabinet_file);
902 return ERROR_SUCCESS;
905 UINT msi_add_cabinet_stream( MSIPACKAGE *package, UINT disk_id, IStorage *storage, const WCHAR *name )
907 MSICABINETSTREAM *cab, *item;
909 TRACE("%p, %u, %p, %s\n", package, disk_id, storage, debugstr_w(name));
911 LIST_FOR_EACH_ENTRY( item, &package->cabinet_streams, MSICABINETSTREAM, entry )
913 if (item->disk_id == disk_id)
915 TRACE("duplicate disk id %u\n", disk_id);
916 return ERROR_FUNCTION_FAILED;
919 if (!(cab = msi_alloc( sizeof(*cab) ))) return ERROR_OUTOFMEMORY;
920 if (!(cab->stream = msi_alloc( (strlenW( name ) + 1) * sizeof(WCHAR ) )))
923 return ERROR_OUTOFMEMORY;
925 strcpyW( cab->stream, name );
926 cab->disk_id = disk_id;
927 cab->storage = storage;
928 IStorage_AddRef( storage );
929 list_add_tail( &package->cabinet_streams, &cab->entry );
931 return ERROR_SUCCESS;