comctl32/tooltips: Remove redundant code, let handlers deal with A<->W conversions.
[wine] / dlls / msi / media.c
1 /*
2  * Implementation of the Microsoft Installer (msi.dll)
3  *
4  * Copyright 2008 James Hawkins
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winerror.h"
25 #include "wine/debug.h"
26 #include "fdi.h"
27 #include "msipriv.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "shlwapi.h"
31 #include "wine/unicode.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(msi);
34
35 /* from msvcrt/fcntl.h */
36 #define _O_RDONLY      0
37 #define _O_WRONLY      1
38 #define _O_RDWR        2
39 #define _O_ACCMODE     (_O_RDONLY|_O_WRONLY|_O_RDWR)
40 #define _O_APPEND      0x0008
41 #define _O_RANDOM      0x0010
42 #define _O_SEQUENTIAL  0x0020
43 #define _O_TEMPORARY   0x0040
44 #define _O_NOINHERIT   0x0080
45 #define _O_CREAT       0x0100
46 #define _O_TRUNC       0x0200
47 #define _O_EXCL        0x0400
48 #define _O_SHORT_LIVED 0x1000
49 #define _O_TEXT        0x4000
50 #define _O_BINARY      0x8000
51
52 static BOOL source_matches_volume(MSIMEDIAINFO *mi, LPCWSTR source_root)
53 {
54     WCHAR volume_name[MAX_PATH + 1];
55     WCHAR root[MAX_PATH + 1];
56
57     strcpyW(root, source_root);
58     PathStripToRootW(root);
59     PathAddBackslashW(root);
60
61     if (!GetVolumeInformationW(root, volume_name, MAX_PATH + 1,
62                                NULL, NULL, NULL, NULL, 0))
63     {
64         ERR("Failed to get volume information\n");
65         return FALSE;
66     }
67
68     return !lstrcmpW(mi->volume_label, volume_name);
69 }
70
71 static UINT msi_change_media(MSIPACKAGE *package, MSIMEDIAINFO *mi)
72 {
73     LPSTR msg;
74     LPWSTR error, error_dialog;
75     LPWSTR source_dir;
76     UINT r = ERROR_SUCCESS;
77
78     static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
79     static const WCHAR error_prop[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
80
81     if ((msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) ==
82          INSTALLUILEVEL_NONE && !gUIHandlerA)
83         return ERROR_SUCCESS;
84
85     error = generate_error_string(package, 1302, 1, mi->disk_prompt);
86     error_dialog = msi_dup_property(package, error_prop);
87     source_dir = msi_dup_property(package, cszSourceDir);
88
89     while (r == ERROR_SUCCESS &&
90            !source_matches_volume(mi, source_dir))
91     {
92         r = msi_spawn_error_dialog(package, error_dialog, error);
93
94         if (gUIHandlerA)
95         {
96             msg = strdupWtoA(error);
97             gUIHandlerA(gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, msg);
98             msi_free(msg);
99         }
100     }
101
102     msi_free(error);
103     msi_free(error_dialog);
104     msi_free(source_dir);
105
106     return r;
107 }
108
109 static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream,
110                                     WCHAR* source)
111 {
112     UINT rc;
113     USHORT* data;
114     UINT size;
115     DWORD write;
116     HANDLE hfile;
117     WCHAR tmp[MAX_PATH];
118
119     static const WCHAR cszTempFolder[]= {
120         'T','e','m','p','F','o','l','d','e','r',0};
121
122     rc = read_raw_stream_data(package->db, stream, &data, &size);
123     if (rc != ERROR_SUCCESS)
124         return rc;
125
126     write = MAX_PATH;
127     if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
128         GetTempPathW(MAX_PATH, tmp);
129
130     GetTempFileNameW(tmp, stream, 0, source);
131
132     track_tempfile(package, source);
133     hfile = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
134                         FILE_ATTRIBUTE_NORMAL, NULL);
135
136     if (hfile == INVALID_HANDLE_VALUE)
137     {
138         ERR("Unable to create file %s\n", debugstr_w(source));
139         rc = ERROR_FUNCTION_FAILED;
140         goto end;
141     }
142
143     WriteFile(hfile, data, size, &write, NULL);
144     CloseHandle(hfile);
145     TRACE("wrote %i bytes to %s\n", write, debugstr_w(source));
146
147 end:
148     msi_free(data);
149     return rc;
150 }
151
152 static void * CDECL cabinet_alloc(ULONG cb)
153 {
154     return msi_alloc(cb);
155 }
156
157 static void CDECL cabinet_free(void *pv)
158 {
159     msi_free(pv);
160 }
161
162 static INT_PTR CDECL cabinet_open(char *pszFile, int oflag, int pmode)
163 {
164     HANDLE handle;
165     DWORD dwAccess = 0;
166     DWORD dwShareMode = 0;
167     DWORD dwCreateDisposition = OPEN_EXISTING;
168
169     switch (oflag & _O_ACCMODE)
170     {
171     case _O_RDONLY:
172         dwAccess = GENERIC_READ;
173         dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
174         break;
175     case _O_WRONLY:
176         dwAccess = GENERIC_WRITE;
177         dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
178         break;
179     case _O_RDWR:
180         dwAccess = GENERIC_READ | GENERIC_WRITE;
181         dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
182         break;
183     }
184
185     if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
186         dwCreateDisposition = CREATE_NEW;
187     else if (oflag & _O_CREAT)
188         dwCreateDisposition = CREATE_ALWAYS;
189
190     handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
191                          dwCreateDisposition, 0, NULL);
192     if (handle == INVALID_HANDLE_VALUE)
193         return 0;
194
195     return (INT_PTR)handle;
196 }
197
198 static UINT CDECL cabinet_read(INT_PTR hf, void *pv, UINT cb)
199 {
200     HANDLE handle = (HANDLE)hf;
201     DWORD read;
202
203     if (ReadFile(handle, pv, cb, &read, NULL))
204         return read;
205
206     return 0;
207 }
208
209 static UINT CDECL cabinet_write(INT_PTR hf, void *pv, UINT cb)
210 {
211     HANDLE handle = (HANDLE)hf;
212     DWORD written;
213
214     if (WriteFile(handle, pv, cb, &written, NULL))
215         return written;
216
217     return 0;
218 }
219
220 static int CDECL cabinet_close(INT_PTR hf)
221 {
222     HANDLE handle = (HANDLE)hf;
223     return CloseHandle(handle) ? 0 : -1;
224 }
225
226 static LONG CDECL cabinet_seek(INT_PTR hf, LONG dist, int seektype)
227 {
228     HANDLE handle = (HANDLE)hf;
229     /* flags are compatible and so are passed straight through */
230     return SetFilePointer(handle, dist, NULL, seektype);
231 }
232
233 static UINT CDECL msi_media_get_disk_info(MSIPACKAGE *package, MSIMEDIAINFO *mi)
234 {
235     MSIRECORD *row;
236     LPWSTR ptr;
237
238     static const WCHAR query[] = {
239         'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
240         '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
241         '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
242
243     row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
244     if (!row)
245     {
246         TRACE("Unable to query row\n");
247         return ERROR_FUNCTION_FAILED;
248     }
249
250     mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
251     mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
252     mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
253
254     if (!mi->first_volume)
255         mi->first_volume = strdupW(mi->volume_label);
256
257     ptr = strrchrW(mi->source, '\\') + 1;
258     lstrcpyW(ptr, mi->cabinet);
259     msiobj_release(&row->hdr);
260
261     return ERROR_SUCCESS;
262 }
263
264 static INT_PTR cabinet_partial_file(FDINOTIFICATIONTYPE fdint,
265                                     PFDINOTIFICATION pfdin)
266 {
267     MSICABDATA *data = pfdin->pv;
268     data->mi->is_continuous = FALSE;
269     return 0;
270 }
271
272 static INT_PTR cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint,
273                                     PFDINOTIFICATION pfdin)
274 {
275     MSICABDATA *data = pfdin->pv;
276     MSIMEDIAINFO *mi = data->mi;
277     LPWSTR cab = strdupAtoW(pfdin->psz1);
278     INT_PTR res = -1;
279     UINT rc;
280
281     msi_free(mi->disk_prompt);
282     msi_free(mi->cabinet);
283     msi_free(mi->volume_label);
284     mi->disk_prompt = NULL;
285     mi->cabinet = NULL;
286     mi->volume_label = NULL;
287
288     mi->disk_id++;
289     mi->is_continuous = TRUE;
290
291     rc = msi_media_get_disk_info(data->package, mi);
292     if (rc != ERROR_SUCCESS)
293     {
294         ERR("Failed to get next cabinet information: %d\n", rc);
295         goto done;
296     }
297
298     if (lstrcmpiW(mi->cabinet, cab))
299     {
300         ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
301         goto done;
302     }
303
304     TRACE("Searching for %s\n", debugstr_w(mi->source));
305
306     res = 0;
307     if (GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
308     {
309         if (msi_change_media(data->package, mi) != ERROR_SUCCESS)
310             res = -1;
311     }
312
313 done:
314     msi_free(cab);
315     return res;
316 }
317
318 static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint,
319                                  PFDINOTIFICATION pfdin)
320 {
321     MSICABDATA *data = pfdin->pv;
322     HANDLE handle = 0;
323     LPWSTR path = NULL;
324     DWORD attrs;
325
326     data->curfile = strdupAtoW(pfdin->psz1);
327     if (!data->cb(data->package, data->curfile, MSICABEXTRACT_BEGINEXTRACT, &path,
328                   &attrs, data->user))
329         goto done;
330
331     TRACE("extracting %s\n", debugstr_w(path));
332
333     attrs = attrs & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
334     if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
335
336     handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0,
337                          NULL, CREATE_ALWAYS, attrs, NULL);
338     if (handle == INVALID_HANDLE_VALUE)
339     {
340         DWORD err = GetLastError();
341         DWORD attrs2 = GetFileAttributesW(path);
342
343         if (attrs2 == INVALID_FILE_ATTRIBUTES)
344         {
345             ERR("failed to create %s (error %d)\n", debugstr_w(path), err);
346             goto done;
347         }
348         else if (err == ERROR_ACCESS_DENIED && (attrs2 & FILE_ATTRIBUTE_READONLY))
349         {
350             TRACE("removing read-only attribute on %s\n", debugstr_w(path));
351             SetFileAttributesW( path, attrs2 & ~FILE_ATTRIBUTE_READONLY );
352             handle = CreateFileW(path, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs2, NULL);
353
354             if (handle != INVALID_HANDLE_VALUE) goto done;
355             err = GetLastError();
356         }
357         if (err == ERROR_SHARING_VIOLATION)
358         {
359             static const WCHAR msiW[] = {'m','s','i',0};
360             static const WCHAR slashW[] = {'\\',0};
361             WCHAR tmpfileW[MAX_PATH], *tmppathW, *p;
362             DWORD len;
363
364             TRACE("file in use, scheduling rename operation\n");
365
366             GetTempFileNameW(slashW, msiW, 0, tmpfileW);
367             len = strlenW(path) + strlenW(tmpfileW) + 1;
368             if (!(tmppathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
369                 return ERROR_OUTOFMEMORY;
370
371             strcpyW(tmppathW, path);
372             if ((p = strrchrW(tmppathW, '\\'))) *p = 0;
373             strcatW(tmppathW, tmpfileW);
374
375             handle = CreateFileW(tmppathW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
376
377             if (handle != INVALID_HANDLE_VALUE &&
378                 MoveFileExW(path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
379                 MoveFileExW(tmppathW, path, MOVEFILE_DELAY_UNTIL_REBOOT))
380             {
381                 data->package->need_reboot = 1;
382             }
383             else
384                 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path), GetLastError());
385
386             HeapFree(GetProcessHeap(), 0, tmppathW);
387         }
388         else
389             WARN("failed to create %s (error %d)\n", debugstr_w(path), err);
390     }
391
392 done:
393     msi_free(path);
394
395     return (INT_PTR)handle;
396 }
397
398 static INT_PTR cabinet_close_file_info(FDINOTIFICATIONTYPE fdint,
399                                        PFDINOTIFICATION pfdin)
400 {
401     MSICABDATA *data = pfdin->pv;
402     FILETIME ft;
403     FILETIME ftLocal;
404     HANDLE handle = (HANDLE)pfdin->hf;
405
406     data->mi->is_continuous = FALSE;
407
408     if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
409         return -1;
410     if (!LocalFileTimeToFileTime(&ft, &ftLocal))
411         return -1;
412     if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
413         return -1;
414
415     CloseHandle(handle);
416
417     data->cb(data->package, data->curfile, MSICABEXTRACT_FILEEXTRACTED, NULL, NULL,
418              data->user);
419
420     msi_free(data->curfile);
421     data->curfile = NULL;
422
423     return 1;
424 }
425
426 static INT_PTR CDECL cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
427 {
428     TRACE("(%d)\n", fdint);
429
430     switch (fdint)
431     {
432     case fdintPARTIAL_FILE:
433         return cabinet_partial_file(fdint, pfdin);
434
435     case fdintNEXT_CABINET:
436         return cabinet_next_cabinet(fdint, pfdin);
437
438     case fdintCOPY_FILE:
439         return cabinet_copy_file(fdint, pfdin);
440
441     case fdintCLOSE_FILE_INFO:
442         return cabinet_close_file_info(fdint, pfdin);
443
444     default:
445         return 0;
446     }
447 }
448
449 /***********************************************************************
450  *            msi_cabextract
451  *
452  * Extract files from a cab file.
453  */
454 BOOL msi_cabextract(MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data)
455 {
456     LPSTR cabinet, cab_path = NULL;
457     LPWSTR ptr;
458     HFDI hfdi;
459     ERF erf;
460     BOOL ret = FALSE;
461
462     TRACE("Extracting %s\n", debugstr_w(mi->source));
463
464     hfdi = FDICreate(cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
465                      cabinet_write, cabinet_close, cabinet_seek, 0, &erf);
466     if (!hfdi)
467     {
468         ERR("FDICreate failed\n");
469         return FALSE;
470     }
471
472     ptr = strrchrW(mi->source, '\\') + 1;
473     cabinet = strdupWtoA(ptr);
474     if (!cabinet)
475         goto done;
476
477     cab_path = strdupWtoA(mi->source);
478     if (!cab_path)
479         goto done;
480
481     cab_path[ptr - mi->source] = '\0';
482
483     ret = FDICopy(hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, data);
484     if (!ret)
485         ERR("FDICopy failed\n");
486
487 done:
488     FDIDestroy(hfdi);
489     msi_free(cabinet);
490     msi_free(cab_path);
491
492     if (ret)
493         mi->is_extracted = TRUE;
494
495     return ret;
496 }
497
498 void msi_free_media_info(MSIMEDIAINFO *mi)
499 {
500     msi_free(mi->disk_prompt);
501     msi_free(mi->cabinet);
502     msi_free(mi->volume_label);
503     msi_free(mi->first_volume);
504     msi_free(mi);
505 }
506
507 static UINT get_drive_type(const WCHAR *path)
508 {
509     WCHAR root[MAX_PATH + 1];
510
511     strcpyW(root, path);
512     PathStripToRootW(root);
513     PathAddBackslashW(root);
514
515     return GetDriveTypeW(root);
516 }
517
518 static UINT msi_load_media_info(MSIPACKAGE *package, MSIFILE *file, MSIMEDIAINFO *mi)
519 {
520     MSIRECORD *row;
521     LPWSTR source_dir;
522     LPWSTR source;
523     DWORD options;
524     UINT r;
525
526     static const WCHAR query[] = {
527         'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
528         '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
529         '`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
530         ' ','%','i',' ','A','N','D',' ','`','D','i','s','k','I','d','`',' ','>','=',
531         ' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
532         '`','D','i','s','k','I','d','`',0};
533
534     row = MSI_QueryGetRecord(package->db, query, file->Sequence, mi->disk_id);
535     if (!row)
536     {
537         TRACE("Unable to query row\n");
538         return ERROR_FUNCTION_FAILED;
539     }
540
541     mi->is_extracted = FALSE;
542     mi->disk_id = MSI_RecordGetInteger(row, 1);
543     mi->last_sequence = MSI_RecordGetInteger(row, 2);
544     msi_free(mi->disk_prompt);
545     mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
546     msi_free(mi->cabinet);
547     mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
548     msi_free(mi->volume_label);
549     mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
550     msiobj_release(&row->hdr);
551
552     if (!mi->first_volume)
553         mi->first_volume = strdupW(mi->volume_label);
554
555     source_dir = msi_dup_property(package, cszSourceDir);
556     lstrcpyW(mi->source, source_dir);
557     mi->type = get_drive_type(source_dir);
558
559     if (file->IsCompressed && mi->cabinet)
560     {
561         if (mi->cabinet[0] == '#')
562         {
563             r = writeout_cabinet_stream(package, &mi->cabinet[1], mi->source);
564             if (r != ERROR_SUCCESS)
565             {
566                 ERR("Failed to extract cabinet stream\n");
567                 return ERROR_FUNCTION_FAILED;
568             }
569         }
570         else
571             lstrcatW(mi->source, mi->cabinet);
572     }
573
574     options = MSICODE_PRODUCT;
575     if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
576     {
577         source = source_dir;
578         options |= MSISOURCETYPE_MEDIA;
579     }
580     else if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
581     {
582         source = package->BaseURL;
583         options |= MSISOURCETYPE_URL;
584     }
585     else
586     {
587         source = mi->source;
588         options |= MSISOURCETYPE_NETWORK;
589     }
590
591     msi_package_add_media_disk(package, package->Context,
592                                MSICODE_PRODUCT, mi->disk_id,
593                                mi->volume_label, mi->disk_prompt);
594
595     msi_package_add_info(package, package->Context,
596                          options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
597
598     msi_free(source_dir);
599     return ERROR_SUCCESS;
600 }
601
602 /* FIXME: search NETWORK and URL sources as well */
603 static UINT find_published_source(MSIPACKAGE *package, MSIMEDIAINFO *mi)
604 {
605     WCHAR source[MAX_PATH];
606     WCHAR volume[MAX_PATH];
607     WCHAR prompt[MAX_PATH];
608     DWORD volumesz, promptsz;
609     DWORD index, size, id;
610     UINT r;
611
612     size = MAX_PATH;
613     r = MsiSourceListGetInfoW(package->ProductCode, NULL,
614                               package->Context, MSICODE_PRODUCT,
615                               INSTALLPROPERTY_LASTUSEDSOURCEW, source, &size);
616     if (r != ERROR_SUCCESS)
617         return r;
618
619     index = 0;
620     volumesz = MAX_PATH;
621     promptsz = MAX_PATH;
622     while (MsiSourceListEnumMediaDisksW(package->ProductCode, NULL,
623                                         package->Context,
624                                         MSICODE_PRODUCT, index++, &id,
625                                         volume, &volumesz, prompt, &promptsz) == ERROR_SUCCESS)
626     {
627         mi->disk_id = id;
628         mi->volume_label = msi_realloc(mi->volume_label, ++volumesz * sizeof(WCHAR));
629         lstrcpyW(mi->volume_label, volume);
630         mi->disk_prompt = msi_realloc(mi->disk_prompt, ++promptsz * sizeof(WCHAR));
631         lstrcpyW(mi->disk_prompt, prompt);
632
633         if (source_matches_volume(mi, source))
634         {
635             /* FIXME: what about SourceDir */
636             lstrcpyW(mi->source, source);
637             return ERROR_SUCCESS;
638         }
639     }
640
641     return ERROR_FUNCTION_FAILED;
642 }
643
644 UINT ready_media(MSIPACKAGE *package, MSIFILE *file, MSIMEDIAINFO *mi)
645 {
646     UINT rc = ERROR_SUCCESS;
647
648     /* media info for continuous cabinet is already loaded */
649     if (mi->is_continuous)
650         return ERROR_SUCCESS;
651
652     rc = msi_load_media_info(package, file, mi);
653     if (rc != ERROR_SUCCESS)
654     {
655         ERR("Unable to load media info\n");
656         return ERROR_FUNCTION_FAILED;
657     }
658
659     /* cabinet is internal, no checks needed */
660     if (!mi->cabinet || mi->cabinet[0] == '#')
661         return ERROR_SUCCESS;
662
663     /* package should be downloaded */
664     if (file->IsCompressed &&
665         GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES &&
666         package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
667     {
668         WCHAR temppath[MAX_PATH];
669
670         msi_download_file(mi->source, temppath);
671         lstrcpyW(mi->source, temppath);
672         return ERROR_SUCCESS;
673     }
674
675     /* check volume matches, change media if not */
676     if (mi->volume_label && mi->disk_id > 1 &&
677         lstrcmpW(mi->first_volume, mi->volume_label))
678     {
679         LPWSTR source = msi_dup_property(package, cszSourceDir);
680         BOOL matches;
681
682         matches = source_matches_volume(mi, source);
683         msi_free(source);
684
685         if ((mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE) && !matches)
686         {
687             rc = msi_change_media(package, mi);
688             if (rc != ERROR_SUCCESS)
689                 return rc;
690         }
691     }
692
693     if (file->IsCompressed &&
694         GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
695     {
696         rc = find_published_source(package, mi);
697         if (rc != ERROR_SUCCESS)
698         {
699             ERR("Cabinet not found: %s\n", debugstr_w(mi->source));
700             return ERROR_INSTALL_FAILURE;
701         }
702     }
703
704     return ERROR_SUCCESS;
705 }