msi: Search network sources in addition to disk sources.
[wine.git] / dlls / msi / media.c
blob5c53027e900fff8ac4c22add0ab2877741dd75c9
1 /*
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
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winerror.h"
27 #include "wine/debug.h"
28 #include "fdi.h"
29 #include "msipriv.h"
30 #include "winuser.h"
31 #include "winreg.h"
32 #include "shlwapi.h"
33 #include "objidl.h"
34 #include "wine/unicode.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msi);
38 /* from msvcrt/fcntl.h */
39 #define _O_RDONLY 0
40 #define _O_WRONLY 1
41 #define _O_RDWR 2
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");
68 return FALSE;
71 return !lstrcmpW(mi->volume_label, volume_name);
74 static UINT msi_change_media(MSIPACKAGE *package, MSIMEDIAINFO *mi)
76 LPWSTR error, error_dialog;
77 LPWSTR source_dir;
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, szUILevel, 0) & INSTALLUILEVEL_MASK) ==
83 INSTALLUILEVEL_NONE && !gUIHandlerA && !gUIHandlerW && !gUIHandlerRecord)
84 return ERROR_SUCCESS;
86 error = generate_error_string(package, 1302, 1, mi->disk_prompt);
87 error_dialog = msi_dup_property(package, error_prop);
88 source_dir = msi_dup_property(package, cszSourceDir);
90 while (r == ERROR_SUCCESS && !source_matches_volume(mi, source_dir))
92 r = msi_spawn_error_dialog(package, error_dialog, error);
94 if (gUIHandlerW)
96 gUIHandlerW(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, error);
98 else if (gUIHandlerA)
100 char *msg = strdupWtoA(error);
101 gUIHandlerA(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, msg);
102 msi_free(msg);
104 else if (gUIHandlerRecord)
106 MSIHANDLE rec = MsiCreateRecord(1);
107 MsiRecordSetStringW(rec, 0, error);
108 gUIHandlerRecord(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, rec);
109 MsiCloseHandle(rec);
113 msi_free(error);
114 msi_free(error_dialog);
115 msi_free(source_dir);
117 return r;
120 static void * CDECL cabinet_alloc(ULONG cb)
122 return msi_alloc(cb);
125 static void CDECL cabinet_free(void *pv)
127 msi_free(pv);
130 static INT_PTR CDECL cabinet_open(char *pszFile, int oflag, int pmode)
132 HANDLE handle;
133 DWORD dwAccess = 0;
134 DWORD dwShareMode = 0;
135 DWORD dwCreateDisposition = OPEN_EXISTING;
137 switch (oflag & _O_ACCMODE)
139 case _O_RDONLY:
140 dwAccess = GENERIC_READ;
141 dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
142 break;
143 case _O_WRONLY:
144 dwAccess = GENERIC_WRITE;
145 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
146 break;
147 case _O_RDWR:
148 dwAccess = GENERIC_READ | GENERIC_WRITE;
149 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
150 break;
153 if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
154 dwCreateDisposition = CREATE_NEW;
155 else if (oflag & _O_CREAT)
156 dwCreateDisposition = CREATE_ALWAYS;
158 handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
159 dwCreateDisposition, 0, NULL);
160 if (handle == INVALID_HANDLE_VALUE)
161 return 0;
163 return (INT_PTR)handle;
166 static UINT CDECL cabinet_read(INT_PTR hf, void *pv, UINT cb)
168 HANDLE handle = (HANDLE)hf;
169 DWORD read;
171 if (ReadFile(handle, pv, cb, &read, NULL))
172 return read;
174 return 0;
177 static UINT CDECL cabinet_write(INT_PTR hf, void *pv, UINT cb)
179 HANDLE handle = (HANDLE)hf;
180 DWORD written;
182 if (WriteFile(handle, pv, cb, &written, NULL))
183 return written;
185 return 0;
188 static int CDECL cabinet_close(INT_PTR hf)
190 HANDLE handle = (HANDLE)hf;
191 return CloseHandle(handle) ? 0 : -1;
194 static LONG CDECL cabinet_seek(INT_PTR hf, LONG dist, int seektype)
196 HANDLE handle = (HANDLE)hf;
197 /* flags are compatible and so are passed straight through */
198 return SetFilePointer(handle, dist, NULL, seektype);
201 struct cab_stream
203 MSIDATABASE *db;
204 WCHAR *name;
207 static struct cab_stream cab_stream;
209 static INT_PTR CDECL cabinet_open_stream( char *pszFile, int oflag, int pmode )
211 UINT r;
212 IStream *stm;
214 if (oflag)
215 WARN("ignoring open flags 0x%08x\n", oflag);
217 r = db_get_raw_stream( cab_stream.db, cab_stream.name, &stm );
218 if (r != ERROR_SUCCESS)
220 WARN("Failed to get cabinet stream %u\n", r);
221 return 0;
224 return (INT_PTR)stm;
227 static UINT CDECL cabinet_read_stream( INT_PTR hf, void *pv, UINT cb )
229 IStream *stm = (IStream *)hf;
230 DWORD read;
231 HRESULT hr;
233 hr = IStream_Read( stm, pv, cb, &read );
234 if (hr == S_OK || hr == S_FALSE)
235 return read;
237 return 0;
240 static int CDECL cabinet_close_stream( INT_PTR hf )
242 IStream *stm = (IStream *)hf;
243 IStream_Release( stm );
244 return 0;
247 static LONG CDECL cabinet_seek_stream( INT_PTR hf, LONG dist, int seektype )
249 IStream *stm = (IStream *)hf;
250 LARGE_INTEGER move;
251 ULARGE_INTEGER newpos;
252 HRESULT hr;
254 move.QuadPart = dist;
255 hr = IStream_Seek( stm, move, seektype, &newpos );
256 if (SUCCEEDED(hr))
258 if (newpos.QuadPart <= MAXLONG) return newpos.QuadPart;
259 ERR("Too big!\n");
261 return -1;
264 static UINT CDECL msi_media_get_disk_info(MSIPACKAGE *package, MSIMEDIAINFO *mi)
266 MSIRECORD *row;
267 LPWSTR ptr;
269 static const WCHAR query[] = {
270 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
271 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
272 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
274 row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
275 if (!row)
277 TRACE("Unable to query row\n");
278 return ERROR_FUNCTION_FAILED;
281 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
282 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
283 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
285 if (!mi->first_volume)
286 mi->first_volume = strdupW(mi->volume_label);
288 ptr = strrchrW(mi->source, '\\') + 1;
289 lstrcpyW(ptr, mi->cabinet);
290 msiobj_release(&row->hdr);
292 return ERROR_SUCCESS;
295 static INT_PTR cabinet_partial_file(FDINOTIFICATIONTYPE fdint,
296 PFDINOTIFICATION pfdin)
298 MSICABDATA *data = pfdin->pv;
299 data->mi->is_continuous = FALSE;
300 return 0;
303 static INT_PTR cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint,
304 PFDINOTIFICATION pfdin)
306 MSICABDATA *data = pfdin->pv;
307 MSIMEDIAINFO *mi = data->mi;
308 LPWSTR cab = strdupAtoW(pfdin->psz1);
309 INT_PTR res = -1;
310 UINT rc;
312 msi_free(mi->disk_prompt);
313 msi_free(mi->cabinet);
314 msi_free(mi->volume_label);
315 mi->disk_prompt = NULL;
316 mi->cabinet = NULL;
317 mi->volume_label = NULL;
319 mi->disk_id++;
320 mi->is_continuous = TRUE;
322 rc = msi_media_get_disk_info(data->package, mi);
323 if (rc != ERROR_SUCCESS)
325 ERR("Failed to get next cabinet information: %d\n", rc);
326 goto done;
329 if (lstrcmpiW(mi->cabinet, cab))
331 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
332 goto done;
335 TRACE("Searching for %s\n", debugstr_w(mi->source));
337 res = 0;
338 if (GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
340 if (msi_change_media(data->package, mi) != ERROR_SUCCESS)
341 res = -1;
344 done:
345 msi_free(cab);
346 return res;
349 static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint,
350 PFDINOTIFICATION pfdin)
352 MSICABDATA *data = pfdin->pv;
353 HANDLE handle = 0;
354 LPWSTR path = NULL;
355 DWORD attrs;
357 data->curfile = strdupAtoW(pfdin->psz1);
358 if (!data->cb(data->package, data->curfile, MSICABEXTRACT_BEGINEXTRACT, &path,
359 &attrs, data->user))
361 /* We're not extracting this file, so free the filename. */
362 msi_free(data->curfile);
363 data->curfile = NULL;
364 goto done;
367 TRACE("extracting %s\n", debugstr_w(path));
369 attrs = attrs & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
370 if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
372 handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0,
373 NULL, CREATE_ALWAYS, attrs, NULL);
374 if (handle == INVALID_HANDLE_VALUE)
376 DWORD err = GetLastError();
377 DWORD attrs2 = GetFileAttributesW(path);
379 if (attrs2 == INVALID_FILE_ATTRIBUTES)
381 ERR("failed to create %s (error %d)\n", debugstr_w(path), err);
382 goto done;
384 else if (err == ERROR_ACCESS_DENIED && (attrs2 & FILE_ATTRIBUTE_READONLY))
386 TRACE("removing read-only attribute on %s\n", debugstr_w(path));
387 SetFileAttributesW( path, attrs2 & ~FILE_ATTRIBUTE_READONLY );
388 handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs2, NULL);
390 if (handle != INVALID_HANDLE_VALUE) goto done;
391 err = GetLastError();
393 if (err == ERROR_SHARING_VIOLATION || err == ERROR_USER_MAPPED_FILE)
395 WCHAR tmpfileW[MAX_PATH], *tmppathW, *p;
396 DWORD len;
398 TRACE("file in use, scheduling rename operation\n");
400 GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
401 len = strlenW(path) + strlenW(tmpfileW) + 1;
402 if (!(tmppathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
403 return ERROR_OUTOFMEMORY;
405 strcpyW(tmppathW, path);
406 if ((p = strrchrW(tmppathW, '\\'))) *p = 0;
407 strcatW(tmppathW, tmpfileW);
409 handle = CreateFileW(tmppathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
411 if (handle != INVALID_HANDLE_VALUE &&
412 MoveFileExW(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
413 MoveFileExW(tmppathW, path, MOVEFILE_DELAY_UNTIL_REBOOT))
415 data->package->need_reboot = 1;
417 else
418 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path), GetLastError());
420 HeapFree(GetProcessHeap(), 0, tmppathW);
422 else
423 WARN("failed to create %s (error %d)\n", debugstr_w(path), err);
426 done:
427 msi_free(path);
429 return (INT_PTR)handle;
432 static INT_PTR cabinet_close_file_info(FDINOTIFICATIONTYPE fdint,
433 PFDINOTIFICATION pfdin)
435 MSICABDATA *data = pfdin->pv;
436 FILETIME ft;
437 FILETIME ftLocal;
438 HANDLE handle = (HANDLE)pfdin->hf;
440 data->mi->is_continuous = FALSE;
442 if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
443 return -1;
444 if (!LocalFileTimeToFileTime(&ft, &ftLocal))
445 return -1;
446 if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
447 return -1;
449 CloseHandle(handle);
451 data->cb(data->package, data->curfile, MSICABEXTRACT_FILEEXTRACTED, NULL, NULL,
452 data->user);
454 msi_free(data->curfile);
455 data->curfile = NULL;
457 return 1;
460 static INT_PTR CDECL cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
462 TRACE("(%d)\n", fdint);
464 switch (fdint)
466 case fdintPARTIAL_FILE:
467 return cabinet_partial_file(fdint, pfdin);
469 case fdintNEXT_CABINET:
470 return cabinet_next_cabinet(fdint, pfdin);
472 case fdintCOPY_FILE:
473 return cabinet_copy_file(fdint, pfdin);
475 case fdintCLOSE_FILE_INFO:
476 return cabinet_close_file_info(fdint, pfdin);
478 default:
479 return 0;
483 static INT_PTR CDECL cabinet_notify_stream( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin )
485 TRACE("(%d)\n", fdint);
487 switch (fdint)
489 case fdintCOPY_FILE:
490 return cabinet_copy_file( fdint, pfdin );
492 case fdintCLOSE_FILE_INFO:
493 return cabinet_close_file_info( fdint, pfdin );
495 case fdintCABINET_INFO:
496 return 0;
498 default:
499 ERR("Unexpected notification %d\n", fdint);
500 return 0;
504 static BOOL extract_cabinet( MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data )
506 LPSTR cabinet, cab_path = NULL;
507 LPWSTR ptr;
508 HFDI hfdi;
509 ERF erf;
510 BOOL ret = FALSE;
512 TRACE("Extracting %s\n", debugstr_w(mi->source));
514 hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
515 cabinet_write, cabinet_close, cabinet_seek, 0, &erf );
516 if (!hfdi)
518 ERR("FDICreate failed\n");
519 return FALSE;
522 ptr = strrchrW( mi->source, '\\' ) + 1;
523 cabinet = strdupWtoA( ptr );
524 if (!cabinet)
525 goto done;
527 cab_path = strdupWtoA( mi->source );
528 if (!cab_path)
529 goto done;
531 cab_path[ptr - mi->source] = '\0';
533 ret = FDICopy( hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, data );
534 if (!ret)
535 ERR("FDICopy failed\n");
537 done:
538 FDIDestroy( hfdi );
539 msi_free(cabinet );
540 msi_free( cab_path );
542 if (ret)
543 mi->is_extracted = TRUE;
545 return ret;
548 static BOOL extract_cabinet_stream( MSIPACKAGE *package, MSIMEDIAINFO *mi, LPVOID data )
550 static char filename[] = {'<','S','T','R','E','A','M','>',0};
551 HFDI hfdi;
552 ERF erf;
553 BOOL ret = FALSE;
555 TRACE("Extracting %s\n", debugstr_w(mi->cabinet));
557 hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open_stream, cabinet_read_stream,
558 cabinet_write, cabinet_close_stream, cabinet_seek_stream, 0, &erf );
559 if (!hfdi)
561 ERR("FDICreate failed\n");
562 return FALSE;
565 cab_stream.db = package->db;
566 cab_stream.name = encode_streamname( FALSE, mi->cabinet + 1 );
567 if (!cab_stream.name)
568 goto done;
570 ret = FDICopy( hfdi, filename, NULL, 0, cabinet_notify_stream, NULL, data );
571 if (!ret)
572 ERR("FDICopy failed\n");
574 done:
575 FDIDestroy( hfdi );
576 msi_free( cab_stream.name );
578 if (ret)
579 mi->is_extracted = TRUE;
581 return ret;
584 /***********************************************************************
585 * msi_cabextract
587 * Extract files from a cabinet file or stream.
589 BOOL msi_cabextract(MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data)
591 if (mi->cabinet[0] == '#')
593 return extract_cabinet_stream( package, mi, data );
595 return extract_cabinet( package, mi, data );
598 void msi_free_media_info(MSIMEDIAINFO *mi)
600 msi_free(mi->disk_prompt);
601 msi_free(mi->cabinet);
602 msi_free(mi->volume_label);
603 msi_free(mi->first_volume);
604 msi_free(mi);
607 static UINT get_drive_type(const WCHAR *path)
609 WCHAR root[MAX_PATH + 1];
611 strcpyW(root, path);
612 PathStripToRootW(root);
613 PathAddBackslashW(root);
615 return GetDriveTypeW(root);
618 static UINT msi_load_media_info(MSIPACKAGE *package, MSIFILE *file, MSIMEDIAINFO *mi)
620 MSIRECORD *row;
621 LPWSTR source_dir;
622 LPWSTR source;
623 DWORD options;
625 static const WCHAR query[] = {
626 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
627 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
628 '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
629 ' ','%','i',' ','A','N','D',' ','`','D','i','s','k','I','d','`',' ','>','=',
630 ' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
631 '`','D','i','s','k','I','d','`',0};
633 row = MSI_QueryGetRecord(package->db, query, file->Sequence, mi->disk_id);
634 if (!row)
636 TRACE("Unable to query row\n");
637 return ERROR_FUNCTION_FAILED;
640 mi->is_extracted = FALSE;
641 mi->disk_id = MSI_RecordGetInteger(row, 1);
642 mi->last_sequence = MSI_RecordGetInteger(row, 2);
643 msi_free(mi->disk_prompt);
644 mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
645 msi_free(mi->cabinet);
646 mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
647 msi_free(mi->volume_label);
648 mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
649 msiobj_release(&row->hdr);
651 if (!mi->first_volume)
652 mi->first_volume = strdupW(mi->volume_label);
654 source_dir = msi_dup_property(package, cszSourceDir);
655 lstrcpyW(mi->source, source_dir);
656 mi->type = get_drive_type(source_dir);
658 if (file->IsCompressed && mi->cabinet && mi->cabinet[0] != '#')
659 lstrcatW(mi->source, mi->cabinet);
661 options = MSICODE_PRODUCT;
662 if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
664 source = source_dir;
665 options |= MSISOURCETYPE_MEDIA;
667 else if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
669 source = package->BaseURL;
670 options |= MSISOURCETYPE_URL;
672 else
674 source = mi->source;
675 options |= MSISOURCETYPE_NETWORK;
678 msi_package_add_media_disk(package, package->Context,
679 MSICODE_PRODUCT, mi->disk_id,
680 mi->volume_label, mi->disk_prompt);
682 msi_package_add_info(package, package->Context,
683 options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
685 msi_free(source_dir);
686 return ERROR_SUCCESS;
689 /* FIXME: search URL sources as well */
690 static UINT find_published_source(MSIPACKAGE *package, MSIMEDIAINFO *mi)
692 WCHAR source[MAX_PATH];
693 WCHAR volume[MAX_PATH];
694 WCHAR prompt[MAX_PATH];
695 DWORD volumesz, promptsz;
696 DWORD index, size, id;
697 WCHAR last_type[2];
698 UINT r;
700 size = 2;
701 r = MsiSourceListGetInfoW(package->ProductCode, NULL,
702 package->Context, MSICODE_PRODUCT,
703 INSTALLPROPERTY_LASTUSEDTYPEW, last_type, &size);
704 if (r != ERROR_SUCCESS)
705 return r;
707 size = MAX_PATH;
708 r = MsiSourceListGetInfoW(package->ProductCode, NULL,
709 package->Context, MSICODE_PRODUCT,
710 INSTALLPROPERTY_LASTUSEDSOURCEW, source, &size);
711 if (r != ERROR_SUCCESS)
712 return r;
714 index = 0;
715 volumesz = MAX_PATH;
716 promptsz = MAX_PATH;
718 if (last_type[0] == 'n')
720 while (MsiSourceListEnumSourcesW(package->ProductCode, NULL,
721 package->Context,
722 MSISOURCETYPE_NETWORK, index++,
723 volume, &volumesz) == ERROR_SUCCESS)
725 if (!strncmpiW(source, volume, strlenW(source)))
727 lstrcpyW(mi->source, source);
728 lstrcatW(mi->source, mi->cabinet);
729 TRACE("Found network source %s\n", debugstr_w(mi->source));
730 return ERROR_SUCCESS;
735 index = 0;
736 volumesz = MAX_PATH;
737 promptsz = MAX_PATH;
738 while (MsiSourceListEnumMediaDisksW(package->ProductCode, NULL,
739 package->Context,
740 MSICODE_PRODUCT, index++, &id,
741 volume, &volumesz, prompt, &promptsz) == ERROR_SUCCESS)
743 mi->disk_id = id;
744 mi->volume_label = msi_realloc(mi->volume_label, ++volumesz * sizeof(WCHAR));
745 lstrcpyW(mi->volume_label, volume);
746 mi->disk_prompt = msi_realloc(mi->disk_prompt, ++promptsz * sizeof(WCHAR));
747 lstrcpyW(mi->disk_prompt, prompt);
749 if (source_matches_volume(mi, source))
751 /* FIXME: what about SourceDir */
752 lstrcpyW(mi->source, source);
753 TRACE("Found disk source %s\n", debugstr_w(mi->source));
754 return ERROR_SUCCESS;
758 return ERROR_FUNCTION_FAILED;
761 UINT ready_media(MSIPACKAGE *package, MSIFILE *file, MSIMEDIAINFO *mi)
763 UINT rc = ERROR_SUCCESS;
765 /* media info for continuous cabinet is already loaded */
766 if (mi->is_continuous)
767 return ERROR_SUCCESS;
769 rc = msi_load_media_info(package, file, mi);
770 if (rc != ERROR_SUCCESS)
772 ERR("Unable to load media info\n");
773 return ERROR_FUNCTION_FAILED;
776 /* cabinet is internal, no checks needed */
777 if (!mi->cabinet || mi->cabinet[0] == '#')
778 return ERROR_SUCCESS;
780 /* package should be downloaded */
781 if (file->IsCompressed &&
782 GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES &&
783 package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
785 WCHAR temppath[MAX_PATH];
787 msi_download_file(mi->source, temppath);
788 lstrcpyW(mi->source, temppath);
789 return ERROR_SUCCESS;
792 /* check volume matches, change media if not */
793 if (mi->volume_label && mi->disk_id > 1 &&
794 lstrcmpW(mi->first_volume, mi->volume_label))
796 LPWSTR source = msi_dup_property(package, cszSourceDir);
797 BOOL matches;
799 matches = source_matches_volume(mi, source);
800 msi_free(source);
802 if ((mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE) && !matches)
804 rc = msi_change_media(package, mi);
805 if (rc != ERROR_SUCCESS)
806 return rc;
810 if (file->IsCompressed &&
811 GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
813 rc = find_published_source(package, mi);
814 if (rc != ERROR_SUCCESS)
816 ERR("Cabinet not found: %s\n", debugstr_w(mi->source));
817 return ERROR_INSTALL_FAILURE;
821 return ERROR_SUCCESS;