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, NULL
, NULL
, NULL
, NULL
, 0))
66 WARN("failed to get volume information for %s (%u)\n", debugstr_w(root
), GetLastError());
69 return !strcmpiW( mi
->volume_label
, volume_name
);
72 static UINT
msi_change_media(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
74 LPWSTR error
, error_dialog
;
76 UINT r
= ERROR_SUCCESS
;
78 static const WCHAR error_prop
[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
80 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
&&
81 !gUIHandlerA
&& !gUIHandlerW
&& !gUIHandlerRecord
) return ERROR_SUCCESS
;
83 error
= msi_build_error_string(package
, 1302, 1, mi
->disk_prompt
);
84 error_dialog
= msi_dup_property(package
->db
, error_prop
);
85 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
87 while (r
== ERROR_SUCCESS
&& !source_matches_volume(mi
, source_dir
))
89 r
= msi_spawn_error_dialog(package
, error_dialog
, error
);
93 gUIHandlerW(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, error
);
97 char *msg
= strdupWtoA(error
);
98 gUIHandlerA(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, msg
);
101 else if (gUIHandlerRecord
)
103 MSIHANDLE rec
= MsiCreateRecord(1);
104 MsiRecordSetStringW(rec
, 0, error
);
105 gUIHandlerRecord(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, rec
);
111 msi_free(error_dialog
);
112 msi_free(source_dir
);
117 static MSICABINETSTREAM
*msi_get_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
)
119 MSICABINETSTREAM
*cab
;
121 LIST_FOR_EACH_ENTRY( cab
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
123 if (cab
->disk_id
== disk_id
) return cab
;
128 static void * CDECL
cabinet_alloc(ULONG cb
)
130 return msi_alloc(cb
);
133 static void CDECL
cabinet_free(void *pv
)
138 static INT_PTR CDECL
cabinet_open(char *pszFile
, int oflag
, int pmode
)
141 DWORD dwShareMode
= 0;
142 DWORD dwCreateDisposition
= OPEN_EXISTING
;
144 switch (oflag
& _O_ACCMODE
)
147 dwAccess
= GENERIC_READ
;
148 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
151 dwAccess
= GENERIC_WRITE
;
152 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
155 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
156 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
160 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
161 dwCreateDisposition
= CREATE_NEW
;
162 else if (oflag
& _O_CREAT
)
163 dwCreateDisposition
= CREATE_ALWAYS
;
165 return (INT_PTR
)CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
166 dwCreateDisposition
, 0, NULL
);
169 static UINT CDECL
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
171 HANDLE handle
= (HANDLE
)hf
;
174 if (ReadFile(handle
, pv
, cb
, &read
, NULL
))
180 static UINT CDECL
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
182 HANDLE handle
= (HANDLE
)hf
;
185 if (WriteFile(handle
, pv
, cb
, &written
, NULL
))
191 static int CDECL
cabinet_close(INT_PTR hf
)
193 HANDLE handle
= (HANDLE
)hf
;
194 return CloseHandle(handle
) ? 0 : -1;
197 static LONG CDECL
cabinet_seek(INT_PTR hf
, LONG dist
, int seektype
)
199 HANDLE handle
= (HANDLE
)hf
;
200 /* flags are compatible and so are passed straight through */
201 return SetFilePointer(handle
, dist
, NULL
, seektype
);
210 static struct package_disk package_disk
;
212 static INT_PTR CDECL
cabinet_open_stream( char *pszFile
, int oflag
, int pmode
)
214 MSICABINETSTREAM
*cab
;
219 cab
= msi_get_cabinet_stream( package_disk
.package
, package_disk
.id
);
222 WARN("failed to get cabinet stream\n");
225 if (!cab
->stream
[0] || !(encoded
= encode_streamname( FALSE
, cab
->stream
+ 1 )))
227 WARN("failed to encode stream name\n");
230 if (msi_clone_open_stream( package_disk
.package
->db
, cab
->storage
, encoded
, &stream
) != ERROR_SUCCESS
)
232 hr
= IStorage_OpenStream( cab
->storage
, encoded
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stream
);
235 WARN("failed to open stream 0x%08x\n", hr
);
241 return (INT_PTR
)stream
;
244 static UINT CDECL
cabinet_read_stream( INT_PTR hf
, void *pv
, UINT cb
)
246 IStream
*stm
= (IStream
*)hf
;
250 hr
= IStream_Read( stm
, pv
, cb
, &read
);
251 if (hr
== S_OK
|| hr
== S_FALSE
)
257 static int CDECL
cabinet_close_stream( INT_PTR hf
)
259 IStream
*stm
= (IStream
*)hf
;
260 IStream_Release( stm
);
264 static LONG CDECL
cabinet_seek_stream( INT_PTR hf
, LONG dist
, int seektype
)
266 IStream
*stm
= (IStream
*)hf
;
268 ULARGE_INTEGER newpos
;
271 move
.QuadPart
= dist
;
272 hr
= IStream_Seek( stm
, move
, seektype
, &newpos
);
275 if (newpos
.QuadPart
<= MAXLONG
) return newpos
.QuadPart
;
281 static UINT CDECL
msi_media_get_disk_info(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
285 static const WCHAR query
[] = {
286 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
287 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
288 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
290 row
= MSI_QueryGetRecord(package
->db
, query
, mi
->disk_id
);
293 TRACE("Unable to query row\n");
294 return ERROR_FUNCTION_FAILED
;
297 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
298 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
299 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
301 msiobj_release(&row
->hdr
);
302 return ERROR_SUCCESS
;
305 static INT_PTR
cabinet_partial_file(FDINOTIFICATIONTYPE fdint
,
306 PFDINOTIFICATION pfdin
)
308 MSICABDATA
*data
= pfdin
->pv
;
309 data
->mi
->is_continuous
= FALSE
;
313 static WCHAR
*get_cabinet_filename(MSIMEDIAINFO
*mi
)
318 len
= strlenW(mi
->sourcedir
) + strlenW(mi
->cabinet
) + 1;
319 if (!(ret
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
320 strcpyW(ret
, mi
->sourcedir
);
321 strcatW(ret
, mi
->cabinet
);
325 static INT_PTR
cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint
,
326 PFDINOTIFICATION pfdin
)
328 MSICABDATA
*data
= pfdin
->pv
;
329 MSIMEDIAINFO
*mi
= data
->mi
;
330 LPWSTR cabinet_file
= NULL
, cab
= strdupAtoW(pfdin
->psz1
);
334 msi_free(mi
->disk_prompt
);
335 msi_free(mi
->cabinet
);
336 msi_free(mi
->volume_label
);
337 mi
->disk_prompt
= NULL
;
339 mi
->volume_label
= NULL
;
342 mi
->is_continuous
= TRUE
;
344 rc
= msi_media_get_disk_info(data
->package
, mi
);
345 if (rc
!= ERROR_SUCCESS
)
347 ERR("Failed to get next cabinet information: %d\n", rc
);
351 if (strcmpiW( mi
->cabinet
, cab
))
356 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
));
358 /* Use cabinet name from the media table */
359 next_cab
= strdupWtoA(mi
->cabinet
);
360 /* Modify path to cabinet file with full filename (psz3 points to a 256 bytes buffer that can be modified contrary to psz1 and psz2) */
361 length
= strlen(pfdin
->psz3
) + 1 + strlen(next_cab
) + 1;
364 WARN("Cannot update next cabinet filename with a string size %u > 256\n", length
);
370 strcat(pfdin
->psz3
, "\\");
371 strcat(pfdin
->psz3
, next_cab
);
373 /* Path psz3 and cabinet psz1 are concatenated by FDI so just reset psz1 */
378 if (!(cabinet_file
= get_cabinet_filename(mi
)))
381 TRACE("Searching for %s\n", debugstr_w(cabinet_file
));
384 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
386 if (msi_change_media(data
->package
, mi
) != ERROR_SUCCESS
)
392 msi_free(cabinet_file
);
396 static INT_PTR
cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint
,
397 PFDINOTIFICATION pfdin
)
399 MSICABDATA
*data
= pfdin
->pv
;
400 MSIMEDIAINFO
*mi
= data
->mi
;
403 msi_free( mi
->disk_prompt
);
404 msi_free( mi
->cabinet
);
405 msi_free( mi
->volume_label
);
406 mi
->disk_prompt
= NULL
;
408 mi
->volume_label
= NULL
;
411 mi
->is_continuous
= TRUE
;
413 rc
= msi_media_get_disk_info( data
->package
, mi
);
414 if (rc
!= ERROR_SUCCESS
)
416 ERR("Failed to get next cabinet information: %u\n", rc
);
419 package_disk
.id
= mi
->disk_id
;
421 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
425 static INT_PTR
cabinet_copy_file(FDINOTIFICATIONTYPE fdint
,
426 PFDINOTIFICATION pfdin
)
428 MSICABDATA
*data
= pfdin
->pv
;
433 data
->curfile
= strdupAtoW(pfdin
->psz1
);
434 if (!data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_BEGINEXTRACT
, &path
,
437 /* We're not extracting this file, so free the filename. */
438 msi_free(data
->curfile
);
439 data
->curfile
= NULL
;
443 TRACE("extracting %s -> %s\n", debugstr_w(data
->curfile
), debugstr_w(path
));
445 attrs
= attrs
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
446 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
448 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0,
449 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
450 if (handle
== INVALID_HANDLE_VALUE
)
452 DWORD err
= GetLastError();
453 DWORD attrs2
= GetFileAttributesW(path
);
455 if (attrs2
== INVALID_FILE_ATTRIBUTES
)
457 ERR("failed to create %s (error %d)\n", debugstr_w(path
), err
);
460 else if (err
== ERROR_ACCESS_DENIED
&& (attrs2
& FILE_ATTRIBUTE_READONLY
))
462 TRACE("removing read-only attribute on %s\n", debugstr_w(path
));
463 SetFileAttributesW( path
, attrs2
& ~FILE_ATTRIBUTE_READONLY
);
464 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs2
, NULL
);
466 if (handle
!= INVALID_HANDLE_VALUE
) goto done
;
467 err
= GetLastError();
469 if (err
== ERROR_SHARING_VIOLATION
|| err
== ERROR_USER_MAPPED_FILE
)
471 WCHAR
*tmpfileW
, *tmppathW
, *p
;
474 TRACE("file in use, scheduling rename operation\n");
476 if (!(tmppathW
= strdupW( path
))) return ERROR_OUTOFMEMORY
;
477 if ((p
= strrchrW(tmppathW
, '\\'))) *p
= 0;
478 len
= strlenW( tmppathW
) + 16;
479 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
481 msi_free( tmppathW
);
482 return ERROR_OUTOFMEMORY
;
484 if (!GetTempFileNameW(tmppathW
, szMsi
, 0, tmpfileW
)) tmpfileW
[0] = 0;
485 msi_free( tmppathW
);
487 handle
= CreateFileW(tmpfileW
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs
, NULL
);
489 if (handle
!= INVALID_HANDLE_VALUE
&&
490 MoveFileExW(path
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
491 MoveFileExW(tmpfileW
, path
, MOVEFILE_DELAY_UNTIL_REBOOT
))
493 data
->package
->need_reboot_at_end
= 1;
497 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path
), GetLastError());
498 DeleteFileW( tmpfileW
);
503 WARN("failed to create %s (error %d)\n", debugstr_w(path
), err
);
509 return (INT_PTR
)handle
;
512 static INT_PTR
cabinet_close_file_info(FDINOTIFICATIONTYPE fdint
,
513 PFDINOTIFICATION pfdin
)
515 MSICABDATA
*data
= pfdin
->pv
;
518 HANDLE handle
= (HANDLE
)pfdin
->hf
;
520 data
->mi
->is_continuous
= FALSE
;
522 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
524 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
526 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
531 data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_FILEEXTRACTED
, NULL
, NULL
,
534 msi_free(data
->curfile
);
535 data
->curfile
= NULL
;
540 static INT_PTR CDECL
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
544 case fdintPARTIAL_FILE
:
545 return cabinet_partial_file(fdint
, pfdin
);
547 case fdintNEXT_CABINET
:
548 return cabinet_next_cabinet(fdint
, pfdin
);
551 return cabinet_copy_file(fdint
, pfdin
);
553 case fdintCLOSE_FILE_INFO
:
554 return cabinet_close_file_info(fdint
, pfdin
);
561 static INT_PTR CDECL
cabinet_notify_stream( FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
565 case fdintPARTIAL_FILE
:
566 return cabinet_partial_file( fdint
, pfdin
);
568 case fdintNEXT_CABINET
:
569 return cabinet_next_cabinet_stream( fdint
, pfdin
);
572 return cabinet_copy_file( fdint
, pfdin
);
574 case fdintCLOSE_FILE_INFO
:
575 return cabinet_close_file_info( fdint
, pfdin
);
577 case fdintCABINET_INFO
:
581 ERR("Unexpected notification %d\n", fdint
);
586 static BOOL
extract_cabinet( MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
588 LPSTR cabinet
, cab_path
= NULL
;
593 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
595 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
596 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
599 ERR("FDICreate failed\n");
603 cabinet
= strdupWtoA( mi
->cabinet
);
607 cab_path
= strdupWtoA( mi
->sourcedir
);
611 ret
= FDICopy( hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, data
);
613 ERR("FDICopy failed\n");
618 msi_free( cab_path
);
621 mi
->is_extracted
= TRUE
;
626 static BOOL
extract_cabinet_stream( MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
, LPVOID data
)
628 static char filename
[] = {'<','S','T','R','E','A','M','>',0};
633 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
635 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open_stream
, cabinet_read_stream
,
636 cabinet_write
, cabinet_close_stream
, cabinet_seek_stream
, 0, &erf
);
639 ERR("FDICreate failed\n");
643 package_disk
.package
= package
;
644 package_disk
.id
= mi
->disk_id
;
646 ret
= FDICopy( hfdi
, filename
, NULL
, 0, cabinet_notify_stream
, NULL
, data
);
647 if (!ret
) ERR("FDICopy failed\n");
650 if (ret
) mi
->is_extracted
= TRUE
;
654 /***********************************************************************
657 * Extract files from a cabinet file or stream.
659 BOOL
msi_cabextract(MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
661 if (mi
->cabinet
[0] == '#')
663 return extract_cabinet_stream( package
, mi
, data
);
665 return extract_cabinet( package
, mi
, data
);
668 void msi_free_media_info(MSIMEDIAINFO
*mi
)
670 msi_free(mi
->disk_prompt
);
671 msi_free(mi
->cabinet
);
672 msi_free(mi
->volume_label
);
676 static UINT
get_drive_type(const WCHAR
*path
)
678 WCHAR root
[MAX_PATH
+ 1];
681 PathStripToRootW(root
);
682 PathAddBackslashW(root
);
684 return GetDriveTypeW(root
);
687 UINT
msi_load_media_info(MSIPACKAGE
*package
, UINT Sequence
, MSIMEDIAINFO
*mi
)
689 static const WCHAR query
[] = {
690 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
691 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
692 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
694 LPWSTR source_dir
, source
;
697 if (Sequence
<= mi
->last_sequence
) /* already loaded */
698 return ERROR_SUCCESS
;
700 row
= MSI_QueryGetRecord(package
->db
, query
, Sequence
);
703 TRACE("Unable to query row\n");
704 return ERROR_FUNCTION_FAILED
;
707 mi
->is_extracted
= FALSE
;
708 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
709 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
710 msi_free(mi
->disk_prompt
);
711 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
712 msi_free(mi
->cabinet
);
713 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
714 msi_free(mi
->volume_label
);
715 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
716 msiobj_release(&row
->hdr
);
718 msi_set_sourcedir_props(package
, FALSE
);
719 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
720 lstrcpyW(mi
->sourcedir
, source_dir
);
721 PathAddBackslashW(mi
->sourcedir
);
722 mi
->type
= get_drive_type(source_dir
);
724 options
= MSICODE_PRODUCT
;
725 if (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
)
728 options
|= MSISOURCETYPE_MEDIA
;
730 else if (package
->BaseURL
&& UrlIsW(package
->BaseURL
, URLIS_URL
))
732 source
= package
->BaseURL
;
733 options
|= MSISOURCETYPE_URL
;
737 source
= mi
->sourcedir
;
738 options
|= MSISOURCETYPE_NETWORK
;
741 msi_package_add_media_disk(package
, package
->Context
,
742 MSICODE_PRODUCT
, mi
->disk_id
,
743 mi
->volume_label
, mi
->disk_prompt
);
745 msi_package_add_info(package
, package
->Context
,
746 options
, INSTALLPROPERTY_LASTUSEDSOURCEW
, source
);
748 msi_free(source_dir
);
749 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence
, debugstr_w(mi
->cabinet
), mi
->disk_id
);
750 return ERROR_SUCCESS
;
753 /* FIXME: search URL sources as well */
754 static UINT
find_published_source(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
756 WCHAR source
[MAX_PATH
];
757 WCHAR volume
[MAX_PATH
];
758 WCHAR prompt
[MAX_PATH
];
759 DWORD volumesz
, promptsz
;
760 DWORD index
, size
, id
;
765 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
766 package
->Context
, MSICODE_PRODUCT
,
767 INSTALLPROPERTY_LASTUSEDTYPEW
, last_type
, &size
);
768 if (r
!= ERROR_SUCCESS
)
772 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
773 package
->Context
, MSICODE_PRODUCT
,
774 INSTALLPROPERTY_LASTUSEDSOURCEW
, source
, &size
);
775 if (r
!= ERROR_SUCCESS
)
778 if (last_type
[0] == 'n')
780 WCHAR cabinet_file
[MAX_PATH
];
781 BOOL check_all
= FALSE
;
787 while (MsiSourceListEnumSourcesW(package
->ProductCode
, NULL
,
789 MSISOURCETYPE_NETWORK
, index
++,
790 volume
, &volumesz
) == ERROR_SUCCESS
)
792 if (check_all
|| !strncmpiW(source
, volume
, strlenW(source
)))
794 lstrcpyW(cabinet_file
, volume
);
795 PathAddBackslashW(cabinet_file
);
796 lstrcatW(cabinet_file
, mi
->cabinet
);
798 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
806 lstrcpyW(mi
->sourcedir
, volume
);
807 PathAddBackslashW(mi
->sourcedir
);
808 TRACE("Found network source %s\n", debugstr_w(mi
->sourcedir
));
809 return ERROR_SUCCESS
;
823 while (MsiSourceListEnumMediaDisksW(package
->ProductCode
, NULL
,
825 MSICODE_PRODUCT
, index
++, &id
,
826 volume
, &volumesz
, prompt
, &promptsz
) == ERROR_SUCCESS
)
829 msi_free( mi
->volume_label
);
830 if (!(mi
->volume_label
= msi_alloc( ++volumesz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
831 strcpyW( mi
->volume_label
, volume
);
833 msi_free( mi
->disk_prompt
);
834 if (!(mi
->disk_prompt
= msi_alloc( ++promptsz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
835 strcpyW( mi
->disk_prompt
, prompt
);
837 if (source_matches_volume(mi
, source
))
839 /* FIXME: what about SourceDir */
840 lstrcpyW(mi
->sourcedir
, source
);
841 PathAddBackslashW(mi
->sourcedir
);
842 TRACE("Found disk source %s\n", debugstr_w(mi
->sourcedir
));
843 return ERROR_SUCCESS
;
847 return ERROR_FUNCTION_FAILED
;
850 UINT
ready_media( MSIPACKAGE
*package
, BOOL compressed
, MSIMEDIAINFO
*mi
)
853 WCHAR
*cabinet_file
= NULL
;
855 /* media info for continuous cabinet is already loaded */
856 if (mi
->is_continuous
) return ERROR_SUCCESS
;
860 /* cabinet is internal, no checks needed */
861 if (mi
->cabinet
[0] == '#') return ERROR_SUCCESS
;
863 if (!(cabinet_file
= get_cabinet_filename( mi
))) return ERROR_OUTOFMEMORY
;
865 /* package should be downloaded */
866 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
&&
867 package
->BaseURL
&& UrlIsW( package
->BaseURL
, URLIS_URL
))
869 WCHAR temppath
[MAX_PATH
], *p
;
871 if ((rc
= msi_download_file( cabinet_file
, temppath
)) != ERROR_SUCCESS
)
873 ERR("failed to download %s (%u)\n", debugstr_w(cabinet_file
), rc
);
874 msi_free( cabinet_file
);
877 if ((p
= strrchrW( temppath
, '\\' ))) *p
= 0;
878 strcpyW( mi
->sourcedir
, temppath
);
879 PathAddBackslashW( mi
->sourcedir
);
880 msi_free( mi
->cabinet
);
881 mi
->cabinet
= strdupW( p
+ 1 );
882 msi_free( cabinet_file
);
883 return ERROR_SUCCESS
;
886 /* check volume matches, change media if not */
887 if (mi
->volume_label
&& mi
->disk_id
> 1)
889 WCHAR
*source
= msi_dup_property( package
->db
, szSourceDir
);
890 BOOL match
= source_matches_volume( mi
, source
);
893 if (!match
&& (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
))
895 if ((rc
= msi_change_media( package
, mi
)) != ERROR_SUCCESS
)
897 msi_free( cabinet_file
);
904 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
906 if ((rc
= find_published_source( package
, mi
)) != ERROR_SUCCESS
)
908 ERR("cabinet not found: %s\n", debugstr_w(cabinet_file
));
909 msi_free( cabinet_file
);
910 return ERROR_INSTALL_FAILURE
;
914 msi_free( cabinet_file
);
915 return ERROR_SUCCESS
;
918 UINT
msi_add_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
, IStorage
*storage
, const WCHAR
*name
)
920 MSICABINETSTREAM
*cab
, *item
;
922 TRACE("%p, %u, %p, %s\n", package
, disk_id
, storage
, debugstr_w(name
));
924 LIST_FOR_EACH_ENTRY( item
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
926 if (item
->disk_id
== disk_id
)
928 TRACE("duplicate disk id %u\n", disk_id
);
929 return ERROR_FUNCTION_FAILED
;
932 if (!(cab
= msi_alloc( sizeof(*cab
) ))) return ERROR_OUTOFMEMORY
;
933 if (!(cab
->stream
= msi_alloc( (strlenW( name
) + 1) * sizeof(WCHAR
) )))
936 return ERROR_OUTOFMEMORY
;
938 strcpyW( cab
->stream
, name
);
939 cab
->disk_id
= disk_id
;
940 cab
->storage
= storage
;
941 IStorage_AddRef( storage
);
942 list_add_tail( &package
->cabinet_streams
, &cab
->entry
);
944 return ERROR_SUCCESS
;