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"
37 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
39 /* from msvcrt/fcntl.h */
43 #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
44 #define _O_APPEND 0x0008
45 #define _O_RANDOM 0x0010
46 #define _O_SEQUENTIAL 0x0020
47 #define _O_TEMPORARY 0x0040
48 #define _O_NOINHERIT 0x0080
49 #define _O_CREAT 0x0100
50 #define _O_TRUNC 0x0200
51 #define _O_EXCL 0x0400
52 #define _O_SHORT_LIVED 0x1000
53 #define _O_TEXT 0x4000
54 #define _O_BINARY 0x8000
56 static BOOL
source_matches_volume(MSIMEDIAINFO
*mi
, LPCWSTR source_root
)
58 WCHAR volume_name
[MAX_PATH
+ 1], root
[MAX_PATH
+ 1];
62 strcpyW(root
, source_root
);
63 PathStripToRootW(root
);
64 PathAddBackslashW(root
);
66 if (!GetVolumeInformationW(root
, volume_name
, MAX_PATH
+ 1, NULL
, NULL
, NULL
, NULL
, 0))
68 WARN("failed to get volume information for %s (%u)\n", debugstr_w(root
), GetLastError());
72 len
= strlenW( volume_name
);
73 len2
= strlenW( mi
->volume_label
);
74 if (len2
> len
) return FALSE
;
75 p
= volume_name
+ len
- len2
;
77 return !strcmpiW( mi
->volume_label
, p
);
80 static UINT
msi_change_media(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
86 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
87 record
= MSI_CreateRecord(2);
89 while (r
== IDRETRY
&& !source_matches_volume(mi
, source_dir
))
91 MSI_RecordSetStringW(record
, 0, NULL
);
92 MSI_RecordSetInteger(record
, 1, MSIERR_CABNOTFOUND
);
93 MSI_RecordSetStringW(record
, 2, mi
->disk_prompt
);
94 r
= MSI_ProcessMessage(package
, INSTALLMESSAGE_ERROR
| MB_RETRYCANCEL
, record
);
97 msiobj_release(&record
->hdr
);
103 static MSICABINETSTREAM
*msi_get_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
)
105 MSICABINETSTREAM
*cab
;
107 LIST_FOR_EACH_ENTRY( cab
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
109 if (cab
->disk_id
== disk_id
) return cab
;
114 static void * CDECL
cabinet_alloc(ULONG cb
)
116 return msi_alloc(cb
);
119 static void CDECL
cabinet_free(void *pv
)
124 static INT_PTR CDECL
cabinet_open(char *pszFile
, int oflag
, int pmode
)
127 DWORD dwShareMode
= 0;
128 DWORD dwCreateDisposition
= OPEN_EXISTING
;
130 switch (oflag
& _O_ACCMODE
)
133 dwAccess
= GENERIC_READ
;
134 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
137 dwAccess
= GENERIC_WRITE
;
138 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
141 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
142 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
146 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
147 dwCreateDisposition
= CREATE_NEW
;
148 else if (oflag
& _O_CREAT
)
149 dwCreateDisposition
= CREATE_ALWAYS
;
151 return (INT_PTR
)CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
152 dwCreateDisposition
, 0, NULL
);
155 static UINT CDECL
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
157 HANDLE handle
= (HANDLE
)hf
;
160 if (ReadFile(handle
, pv
, cb
, &read
, NULL
))
166 static UINT CDECL
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
168 HANDLE handle
= (HANDLE
)hf
;
171 if (WriteFile(handle
, pv
, cb
, &written
, NULL
))
177 static int CDECL
cabinet_close(INT_PTR hf
)
179 HANDLE handle
= (HANDLE
)hf
;
180 return CloseHandle(handle
) ? 0 : -1;
183 static LONG CDECL
cabinet_seek(INT_PTR hf
, LONG dist
, int seektype
)
185 HANDLE handle
= (HANDLE
)hf
;
186 /* flags are compatible and so are passed straight through */
187 return SetFilePointer(handle
, dist
, NULL
, seektype
);
196 static struct package_disk package_disk
;
198 static INT_PTR CDECL
cabinet_open_stream( char *pszFile
, int oflag
, int pmode
)
200 MSICABINETSTREAM
*cab
;
203 if (!(cab
= msi_get_cabinet_stream( package_disk
.package
, package_disk
.id
)))
205 WARN("failed to get cabinet stream\n");
208 if (cab
->storage
== package_disk
.package
->db
->storage
)
210 UINT r
= msi_get_stream( package_disk
.package
->db
, cab
->stream
+ 1, &stream
);
211 if (r
!= ERROR_SUCCESS
)
213 WARN("failed to get stream %u\n", r
);
217 else /* patch storage */
222 if (!(encoded
= encode_streamname( FALSE
, cab
->stream
+ 1 )))
224 WARN("failed to encode stream name\n");
227 hr
= IStorage_OpenStream( cab
->storage
, encoded
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stream
);
231 WARN("failed to open stream 0x%08x\n", hr
);
235 return (INT_PTR
)stream
;
238 static UINT CDECL
cabinet_read_stream( INT_PTR hf
, void *pv
, UINT cb
)
240 IStream
*stm
= (IStream
*)hf
;
244 hr
= IStream_Read( stm
, pv
, cb
, &read
);
245 if (hr
== S_OK
|| hr
== S_FALSE
)
251 static int CDECL
cabinet_close_stream( INT_PTR hf
)
253 IStream
*stm
= (IStream
*)hf
;
254 IStream_Release( stm
);
258 static LONG CDECL
cabinet_seek_stream( INT_PTR hf
, LONG dist
, int seektype
)
260 IStream
*stm
= (IStream
*)hf
;
262 ULARGE_INTEGER newpos
;
265 move
.QuadPart
= dist
;
266 hr
= IStream_Seek( stm
, move
, seektype
, &newpos
);
269 if (newpos
.QuadPart
<= MAXLONG
) return newpos
.QuadPart
;
275 static UINT CDECL
msi_media_get_disk_info(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
279 static const WCHAR query
[] = {
280 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
281 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
282 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
284 row
= MSI_QueryGetRecord(package
->db
, query
, mi
->disk_id
);
287 TRACE("Unable to query row\n");
288 return ERROR_FUNCTION_FAILED
;
291 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
292 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
293 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
295 msiobj_release(&row
->hdr
);
296 return ERROR_SUCCESS
;
299 static INT_PTR
cabinet_partial_file(FDINOTIFICATIONTYPE fdint
,
300 PFDINOTIFICATION pfdin
)
302 MSICABDATA
*data
= pfdin
->pv
;
303 data
->mi
->is_continuous
= FALSE
;
307 static WCHAR
*get_cabinet_filename(MSIMEDIAINFO
*mi
)
312 len
= strlenW(mi
->sourcedir
) + strlenW(mi
->cabinet
) + 1;
313 if (!(ret
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
314 strcpyW(ret
, mi
->sourcedir
);
315 strcatW(ret
, mi
->cabinet
);
319 static INT_PTR
cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint
,
320 PFDINOTIFICATION pfdin
)
322 MSICABDATA
*data
= pfdin
->pv
;
323 MSIMEDIAINFO
*mi
= data
->mi
;
324 LPWSTR cabinet_file
= NULL
, cab
= strdupAtoW(pfdin
->psz1
);
328 msi_free(mi
->disk_prompt
);
329 msi_free(mi
->cabinet
);
330 msi_free(mi
->volume_label
);
331 mi
->disk_prompt
= NULL
;
333 mi
->volume_label
= NULL
;
336 mi
->is_continuous
= TRUE
;
338 rc
= msi_media_get_disk_info(data
->package
, mi
);
339 if (rc
!= ERROR_SUCCESS
)
341 ERR("Failed to get next cabinet information: %d\n", rc
);
345 if (strcmpiW( mi
->cabinet
, cab
))
350 WARN("Continuous cabinet %s does not match the next cabinet %s in the media table => use latter one\n", debugstr_w(cab
), debugstr_w(mi
->cabinet
));
352 /* Use cabinet name from the media table */
353 next_cab
= strdupWtoA(mi
->cabinet
);
354 /* Modify path to cabinet file with full filename (psz3 points to a 256 bytes buffer that can be modified contrary to psz1 and psz2) */
355 length
= strlen(pfdin
->psz3
) + 1 + strlen(next_cab
) + 1;
358 WARN("Cannot update next cabinet filename with a string size %u > 256\n", length
);
364 strcat(pfdin
->psz3
, "\\");
365 strcat(pfdin
->psz3
, next_cab
);
367 /* Path psz3 and cabinet psz1 are concatenated by FDI so just reset psz1 */
372 if (!(cabinet_file
= get_cabinet_filename(mi
)))
375 TRACE("Searching for %s\n", debugstr_w(cabinet_file
));
378 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
380 if (msi_change_media(data
->package
, mi
) != ERROR_SUCCESS
)
386 msi_free(cabinet_file
);
390 static INT_PTR
cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint
,
391 PFDINOTIFICATION pfdin
)
393 MSICABDATA
*data
= pfdin
->pv
;
394 MSIMEDIAINFO
*mi
= data
->mi
;
397 msi_free( mi
->disk_prompt
);
398 msi_free( mi
->cabinet
);
399 msi_free( mi
->volume_label
);
400 mi
->disk_prompt
= NULL
;
402 mi
->volume_label
= NULL
;
405 mi
->is_continuous
= TRUE
;
407 rc
= msi_media_get_disk_info( data
->package
, mi
);
408 if (rc
!= ERROR_SUCCESS
)
410 ERR("Failed to get next cabinet information: %u\n", rc
);
413 package_disk
.id
= mi
->disk_id
;
415 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
419 static INT_PTR
cabinet_copy_file(FDINOTIFICATIONTYPE fdint
,
420 PFDINOTIFICATION pfdin
)
422 MSICABDATA
*data
= pfdin
->pv
;
427 data
->curfile
= strdupAtoW(pfdin
->psz1
);
428 if (!data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_BEGINEXTRACT
, &path
,
431 /* We're not extracting this file, so free the filename. */
432 msi_free(data
->curfile
);
433 data
->curfile
= NULL
;
437 TRACE("extracting %s -> %s\n", debugstr_w(data
->curfile
), debugstr_w(path
));
439 attrs
= attrs
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
440 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
442 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0,
443 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
444 if (handle
== INVALID_HANDLE_VALUE
)
446 DWORD err
= GetLastError();
447 DWORD attrs2
= GetFileAttributesW(path
);
449 if (attrs2
== INVALID_FILE_ATTRIBUTES
)
451 ERR("failed to create %s (error %d)\n", debugstr_w(path
), err
);
454 else if (err
== ERROR_ACCESS_DENIED
&& (attrs2
& FILE_ATTRIBUTE_READONLY
))
456 TRACE("removing read-only attribute on %s\n", debugstr_w(path
));
457 SetFileAttributesW( path
, attrs2
& ~FILE_ATTRIBUTE_READONLY
);
458 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs
, NULL
);
460 if (handle
!= INVALID_HANDLE_VALUE
) goto done
;
461 err
= GetLastError();
463 if (err
== ERROR_SHARING_VIOLATION
|| err
== ERROR_USER_MAPPED_FILE
)
465 WCHAR
*tmpfileW
, *tmppathW
, *p
;
468 TRACE("file in use, scheduling rename operation\n");
470 if (!(tmppathW
= strdupW( path
))) return ERROR_OUTOFMEMORY
;
471 if ((p
= strrchrW(tmppathW
, '\\'))) *p
= 0;
472 len
= strlenW( tmppathW
) + 16;
473 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
475 msi_free( tmppathW
);
476 return ERROR_OUTOFMEMORY
;
478 if (!GetTempFileNameW(tmppathW
, szMsi
, 0, tmpfileW
)) tmpfileW
[0] = 0;
479 msi_free( tmppathW
);
481 handle
= CreateFileW(tmpfileW
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs
, NULL
);
483 if (handle
!= INVALID_HANDLE_VALUE
&&
484 MoveFileExW(path
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
485 MoveFileExW(tmpfileW
, path
, MOVEFILE_DELAY_UNTIL_REBOOT
))
487 data
->package
->need_reboot_at_end
= 1;
491 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path
), GetLastError());
492 DeleteFileW( tmpfileW
);
497 WARN("failed to create %s (error %d)\n", debugstr_w(path
), err
);
503 return (INT_PTR
)handle
;
506 static INT_PTR
cabinet_close_file_info(FDINOTIFICATIONTYPE fdint
,
507 PFDINOTIFICATION pfdin
)
509 MSICABDATA
*data
= pfdin
->pv
;
512 HANDLE handle
= (HANDLE
)pfdin
->hf
;
514 data
->mi
->is_continuous
= FALSE
;
516 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
518 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
520 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
525 data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_FILEEXTRACTED
, NULL
, NULL
,
528 msi_free(data
->curfile
);
529 data
->curfile
= NULL
;
534 static INT_PTR CDECL
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
538 case fdintPARTIAL_FILE
:
539 return cabinet_partial_file(fdint
, pfdin
);
541 case fdintNEXT_CABINET
:
542 return cabinet_next_cabinet(fdint
, pfdin
);
545 return cabinet_copy_file(fdint
, pfdin
);
547 case fdintCLOSE_FILE_INFO
:
548 return cabinet_close_file_info(fdint
, pfdin
);
555 static INT_PTR CDECL
cabinet_notify_stream( FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
559 case fdintPARTIAL_FILE
:
560 return cabinet_partial_file( fdint
, pfdin
);
562 case fdintNEXT_CABINET
:
563 return cabinet_next_cabinet_stream( fdint
, pfdin
);
566 return cabinet_copy_file( fdint
, pfdin
);
568 case fdintCLOSE_FILE_INFO
:
569 return cabinet_close_file_info( fdint
, pfdin
);
571 case fdintCABINET_INFO
:
575 ERR("Unexpected notification %d\n", fdint
);
580 static BOOL
extract_cabinet( MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
582 LPSTR cabinet
, cab_path
= NULL
;
587 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
589 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
590 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
593 ERR("FDICreate failed\n");
597 cabinet
= strdupWtoA( mi
->cabinet
);
601 cab_path
= strdupWtoA( mi
->sourcedir
);
605 ret
= FDICopy( hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, data
);
607 ERR("FDICopy failed\n");
612 msi_free( cab_path
);
615 mi
->is_extracted
= TRUE
;
620 static BOOL
extract_cabinet_stream( MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
, LPVOID data
)
622 static char filename
[] = {'<','S','T','R','E','A','M','>',0};
627 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
629 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open_stream
, cabinet_read_stream
,
630 cabinet_write
, cabinet_close_stream
, cabinet_seek_stream
, 0, &erf
);
633 ERR("FDICreate failed\n");
637 package_disk
.package
= package
;
638 package_disk
.id
= mi
->disk_id
;
640 ret
= FDICopy( hfdi
, filename
, NULL
, 0, cabinet_notify_stream
, NULL
, data
);
641 if (!ret
) ERR("FDICopy failed\n");
644 if (ret
) mi
->is_extracted
= TRUE
;
648 /***********************************************************************
651 * Extract files from a cabinet file or stream.
653 BOOL
msi_cabextract(MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
655 if (mi
->cabinet
[0] == '#')
657 return extract_cabinet_stream( package
, mi
, data
);
659 return extract_cabinet( package
, mi
, data
);
662 void msi_free_media_info(MSIMEDIAINFO
*mi
)
664 msi_free(mi
->disk_prompt
);
665 msi_free(mi
->cabinet
);
666 msi_free(mi
->volume_label
);
670 static UINT
get_drive_type(const WCHAR
*path
)
672 WCHAR root
[MAX_PATH
+ 1];
675 PathStripToRootW(root
);
676 PathAddBackslashW(root
);
678 return GetDriveTypeW(root
);
681 UINT
msi_load_media_info(MSIPACKAGE
*package
, UINT Sequence
, MSIMEDIAINFO
*mi
)
683 static const WCHAR query
[] = {
684 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
685 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
686 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
688 LPWSTR source_dir
, source
;
691 if (Sequence
<= mi
->last_sequence
) /* already loaded */
692 return ERROR_SUCCESS
;
694 row
= MSI_QueryGetRecord(package
->db
, query
, Sequence
);
697 TRACE("Unable to query row\n");
698 return ERROR_FUNCTION_FAILED
;
701 mi
->is_extracted
= FALSE
;
702 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
703 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
704 msi_free(mi
->disk_prompt
);
705 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
706 msi_free(mi
->cabinet
);
707 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
708 msi_free(mi
->volume_label
);
709 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
710 msiobj_release(&row
->hdr
);
712 msi_set_sourcedir_props(package
, FALSE
);
713 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
714 lstrcpyW(mi
->sourcedir
, source_dir
);
715 PathAddBackslashW(mi
->sourcedir
);
716 mi
->type
= get_drive_type(source_dir
);
718 options
= MSICODE_PRODUCT
;
719 if (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
)
722 options
|= MSISOURCETYPE_MEDIA
;
724 else if (package
->BaseURL
&& UrlIsW(package
->BaseURL
, URLIS_URL
))
726 source
= package
->BaseURL
;
727 options
|= MSISOURCETYPE_URL
;
731 source
= mi
->sourcedir
;
732 options
|= MSISOURCETYPE_NETWORK
;
735 msi_package_add_media_disk(package
, package
->Context
,
736 MSICODE_PRODUCT
, mi
->disk_id
,
737 mi
->volume_label
, mi
->disk_prompt
);
739 msi_package_add_info(package
, package
->Context
,
740 options
, INSTALLPROPERTY_LASTUSEDSOURCEW
, source
);
742 msi_free(source_dir
);
743 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence
, debugstr_w(mi
->cabinet
), mi
->disk_id
);
744 return ERROR_SUCCESS
;
747 /* FIXME: search URL sources as well */
748 static UINT
find_published_source(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
750 WCHAR source
[MAX_PATH
];
751 WCHAR volume
[MAX_PATH
];
752 WCHAR prompt
[MAX_PATH
];
753 DWORD volumesz
, promptsz
;
754 DWORD index
, size
, id
;
759 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
760 package
->Context
, MSICODE_PRODUCT
,
761 INSTALLPROPERTY_LASTUSEDTYPEW
, last_type
, &size
);
762 if (r
!= ERROR_SUCCESS
)
766 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
767 package
->Context
, MSICODE_PRODUCT
,
768 INSTALLPROPERTY_LASTUSEDSOURCEW
, source
, &size
);
769 if (r
!= ERROR_SUCCESS
)
772 if (last_type
[0] == 'n')
774 WCHAR cabinet_file
[MAX_PATH
];
775 BOOL check_all
= FALSE
;
781 while (MsiSourceListEnumSourcesW(package
->ProductCode
, NULL
,
783 MSISOURCETYPE_NETWORK
, index
++,
784 volume
, &volumesz
) == ERROR_SUCCESS
)
786 if (check_all
|| !strncmpiW(source
, volume
, strlenW(source
)))
788 lstrcpyW(cabinet_file
, volume
);
789 PathAddBackslashW(cabinet_file
);
790 lstrcatW(cabinet_file
, mi
->cabinet
);
792 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
800 lstrcpyW(mi
->sourcedir
, volume
);
801 PathAddBackslashW(mi
->sourcedir
);
802 TRACE("Found network source %s\n", debugstr_w(mi
->sourcedir
));
803 return ERROR_SUCCESS
;
817 while (MsiSourceListEnumMediaDisksW(package
->ProductCode
, NULL
,
819 MSICODE_PRODUCT
, index
++, &id
,
820 volume
, &volumesz
, prompt
, &promptsz
) == ERROR_SUCCESS
)
823 msi_free( mi
->volume_label
);
824 if (!(mi
->volume_label
= msi_alloc( ++volumesz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
825 strcpyW( mi
->volume_label
, volume
);
827 msi_free( mi
->disk_prompt
);
828 if (!(mi
->disk_prompt
= msi_alloc( ++promptsz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
829 strcpyW( mi
->disk_prompt
, prompt
);
831 if (source_matches_volume(mi
, source
))
833 /* FIXME: what about SourceDir */
834 lstrcpyW(mi
->sourcedir
, source
);
835 PathAddBackslashW(mi
->sourcedir
);
836 TRACE("Found disk source %s\n", debugstr_w(mi
->sourcedir
));
837 return ERROR_SUCCESS
;
841 return ERROR_FUNCTION_FAILED
;
844 UINT
ready_media( MSIPACKAGE
*package
, BOOL compressed
, MSIMEDIAINFO
*mi
)
847 WCHAR
*cabinet_file
= NULL
;
849 /* media info for continuous cabinet is already loaded */
850 if (mi
->is_continuous
) return ERROR_SUCCESS
;
854 /* cabinet is internal, no checks needed */
855 if (mi
->cabinet
[0] == '#') return ERROR_SUCCESS
;
857 if (!(cabinet_file
= get_cabinet_filename( mi
))) return ERROR_OUTOFMEMORY
;
859 /* package should be downloaded */
860 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
&&
861 package
->BaseURL
&& UrlIsW( package
->BaseURL
, URLIS_URL
))
863 WCHAR temppath
[MAX_PATH
], *p
;
865 if ((rc
= msi_download_file( cabinet_file
, temppath
)) != ERROR_SUCCESS
)
867 ERR("failed to download %s (%u)\n", debugstr_w(cabinet_file
), rc
);
868 msi_free( cabinet_file
);
871 if ((p
= strrchrW( temppath
, '\\' ))) *p
= 0;
872 strcpyW( mi
->sourcedir
, temppath
);
873 PathAddBackslashW( mi
->sourcedir
);
874 msi_free( mi
->cabinet
);
875 mi
->cabinet
= strdupW( p
+ 1 );
876 msi_free( cabinet_file
);
877 return ERROR_SUCCESS
;
880 /* check volume matches, change media if not */
881 if (mi
->volume_label
&& mi
->disk_id
> 1)
883 WCHAR
*source
= msi_dup_property( package
->db
, szSourceDir
);
884 BOOL match
= source_matches_volume( mi
, source
);
887 if (!match
&& (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
))
889 if ((rc
= msi_change_media( package
, mi
)) != ERROR_SUCCESS
)
891 msi_free( cabinet_file
);
898 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
900 if ((rc
= find_published_source( package
, mi
)) != ERROR_SUCCESS
)
902 ERR("cabinet not found: %s\n", debugstr_w(cabinet_file
));
903 msi_free( cabinet_file
);
904 return ERROR_INSTALL_FAILURE
;
908 msi_free( cabinet_file
);
909 return ERROR_SUCCESS
;
912 UINT
msi_add_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
, IStorage
*storage
, const WCHAR
*name
)
914 MSICABINETSTREAM
*cab
, *item
;
916 TRACE("%p, %u, %p, %s\n", package
, disk_id
, storage
, debugstr_w(name
));
918 LIST_FOR_EACH_ENTRY( item
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
920 if (item
->disk_id
== disk_id
)
922 TRACE("duplicate disk id %u\n", disk_id
);
923 return ERROR_FUNCTION_FAILED
;
926 if (!(cab
= msi_alloc( sizeof(*cab
) ))) return ERROR_OUTOFMEMORY
;
927 if (!(cab
->stream
= msi_alloc( (strlenW( name
) + 1) * sizeof(WCHAR
) )))
930 return ERROR_OUTOFMEMORY
;
932 strcpyW( cab
->stream
, name
);
933 cab
->disk_id
= disk_id
;
934 cab
->storage
= storage
;
935 IStorage_AddRef( storage
);
936 list_add_tail( &package
->cabinet_streams
, &cab
->entry
);
938 return ERROR_SUCCESS
;