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 #define WIN32_NO_STATUS
23 #define COM_NO_WINDOWS_H
30 //#include "winerror.h"
31 #include <wine/debug.h>
38 #include <wine/unicode.h>
40 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
42 /* from msvcrt/fcntl.h */
46 #define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
47 #define _O_APPEND 0x0008
48 #define _O_RANDOM 0x0010
49 #define _O_SEQUENTIAL 0x0020
50 #define _O_TEMPORARY 0x0040
51 #define _O_NOINHERIT 0x0080
52 #define _O_CREAT 0x0100
53 #define _O_TRUNC 0x0200
54 #define _O_EXCL 0x0400
55 #define _O_SHORT_LIVED 0x1000
56 #define _O_TEXT 0x4000
57 #define _O_BINARY 0x8000
59 static BOOL
source_matches_volume(MSIMEDIAINFO
*mi
, LPCWSTR source_root
)
61 WCHAR volume_name
[MAX_PATH
+ 1];
62 WCHAR root
[MAX_PATH
+ 1];
64 strcpyW(root
, source_root
);
65 PathStripToRootW(root
);
66 PathAddBackslashW(root
);
68 if (!GetVolumeInformationW(root
, volume_name
, MAX_PATH
+ 1, NULL
, NULL
, NULL
, NULL
, 0))
70 WARN("failed to get volume information for %s (%u)\n", debugstr_w(root
), GetLastError());
73 return !strcmpiW( mi
->volume_label
, volume_name
);
76 static UINT
msi_change_media(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
78 LPWSTR error
, error_dialog
;
80 UINT r
= ERROR_SUCCESS
;
82 static const WCHAR error_prop
[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
84 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
&&
85 !gUIHandlerA
&& !gUIHandlerW
&& !gUIHandlerRecord
) return ERROR_SUCCESS
;
87 error
= msi_build_error_string(package
, 1302, 1, mi
->disk_prompt
);
88 error_dialog
= msi_dup_property(package
->db
, error_prop
);
89 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
91 while (r
== ERROR_SUCCESS
&& !source_matches_volume(mi
, source_dir
))
93 r
= msi_spawn_error_dialog(package
, error_dialog
, error
);
97 gUIHandlerW(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, error
);
101 char *msg
= strdupWtoA(error
);
102 gUIHandlerA(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, msg
);
105 else if (gUIHandlerRecord
)
107 MSIHANDLE rec
= MsiCreateRecord(1);
108 MsiRecordSetStringW(rec
, 0, error
);
109 gUIHandlerRecord(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, rec
);
115 msi_free(error_dialog
);
116 msi_free(source_dir
);
121 static MSICABINETSTREAM
*msi_get_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
)
123 MSICABINETSTREAM
*cab
;
125 LIST_FOR_EACH_ENTRY( cab
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
127 if (cab
->disk_id
== disk_id
) return cab
;
132 static void * CDECL
cabinet_alloc(ULONG cb
)
134 return msi_alloc(cb
);
137 static void CDECL
cabinet_free(void *pv
)
142 static INT_PTR CDECL
cabinet_open(char *pszFile
, int oflag
, int pmode
)
146 DWORD dwShareMode
= 0;
147 DWORD dwCreateDisposition
= OPEN_EXISTING
;
149 switch (oflag
& _O_ACCMODE
)
152 dwAccess
= GENERIC_READ
;
153 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
156 dwAccess
= GENERIC_WRITE
;
157 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
160 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
161 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
165 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
166 dwCreateDisposition
= CREATE_NEW
;
167 else if (oflag
& _O_CREAT
)
168 dwCreateDisposition
= CREATE_ALWAYS
;
170 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
171 dwCreateDisposition
, 0, NULL
);
172 if (handle
== INVALID_HANDLE_VALUE
)
175 return (INT_PTR
)handle
;
178 static UINT CDECL
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
180 HANDLE handle
= (HANDLE
)hf
;
183 if (ReadFile(handle
, pv
, cb
, &read
, NULL
))
189 static UINT CDECL
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
191 HANDLE handle
= (HANDLE
)hf
;
194 if (WriteFile(handle
, pv
, cb
, &written
, NULL
))
200 static int CDECL
cabinet_close(INT_PTR hf
)
202 HANDLE handle
= (HANDLE
)hf
;
203 return CloseHandle(handle
) ? 0 : -1;
206 static LONG CDECL
cabinet_seek(INT_PTR hf
, LONG dist
, int seektype
)
208 HANDLE handle
= (HANDLE
)hf
;
209 /* flags are compatible and so are passed straight through */
210 return SetFilePointer(handle
, dist
, NULL
, seektype
);
219 static struct package_disk package_disk
;
221 static INT_PTR CDECL
cabinet_open_stream( char *pszFile
, int oflag
, int pmode
)
223 MSICABINETSTREAM
*cab
;
228 cab
= msi_get_cabinet_stream( package_disk
.package
, package_disk
.id
);
231 WARN("failed to get cabinet stream\n");
234 if (!cab
->stream
[0] || !(encoded
= encode_streamname( FALSE
, cab
->stream
+ 1 )))
236 WARN("failed to encode stream name\n");
239 if (msi_clone_open_stream( package_disk
.package
->db
, cab
->storage
, encoded
, &stream
) != ERROR_SUCCESS
)
241 hr
= IStorage_OpenStream( cab
->storage
, encoded
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stream
);
244 WARN("failed to open stream 0x%08x\n", hr
);
250 return (INT_PTR
)stream
;
253 static UINT CDECL
cabinet_read_stream( INT_PTR hf
, void *pv
, UINT cb
)
255 IStream
*stm
= (IStream
*)hf
;
259 hr
= IStream_Read( stm
, pv
, cb
, &read
);
260 if (hr
== S_OK
|| hr
== S_FALSE
)
266 static int CDECL
cabinet_close_stream( INT_PTR hf
)
268 IStream
*stm
= (IStream
*)hf
;
269 IStream_Release( stm
);
273 static LONG CDECL
cabinet_seek_stream( INT_PTR hf
, LONG dist
, int seektype
)
275 IStream
*stm
= (IStream
*)hf
;
277 ULARGE_INTEGER newpos
;
280 move
.QuadPart
= dist
;
281 hr
= IStream_Seek( stm
, move
, seektype
, &newpos
);
284 if (newpos
.QuadPart
<= MAXLONG
) return newpos
.QuadPart
;
290 static UINT CDECL
msi_media_get_disk_info(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
294 static const WCHAR query
[] = {
295 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
296 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
297 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
299 row
= MSI_QueryGetRecord(package
->db
, query
, mi
->disk_id
);
302 TRACE("Unable to query row\n");
303 return ERROR_FUNCTION_FAILED
;
306 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
307 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
308 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
310 if (!mi
->first_volume
)
311 mi
->first_volume
= strdupW(mi
->volume_label
);
313 msiobj_release(&row
->hdr
);
314 return ERROR_SUCCESS
;
317 static INT_PTR
cabinet_partial_file(FDINOTIFICATIONTYPE fdint
,
318 PFDINOTIFICATION pfdin
)
320 MSICABDATA
*data
= pfdin
->pv
;
321 data
->mi
->is_continuous
= FALSE
;
325 static WCHAR
*get_cabinet_filename(MSIMEDIAINFO
*mi
)
330 len
= strlenW(mi
->sourcedir
) + strlenW(mi
->cabinet
) + 1;
331 if (!(ret
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
332 strcpyW(ret
, mi
->sourcedir
);
333 strcatW(ret
, mi
->cabinet
);
337 static INT_PTR
cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint
,
338 PFDINOTIFICATION pfdin
)
340 MSICABDATA
*data
= pfdin
->pv
;
341 MSIMEDIAINFO
*mi
= data
->mi
;
342 LPWSTR cabinet_file
= NULL
, cab
= strdupAtoW(pfdin
->psz1
);
346 msi_free(mi
->disk_prompt
);
347 msi_free(mi
->cabinet
);
348 msi_free(mi
->volume_label
);
349 mi
->disk_prompt
= NULL
;
351 mi
->volume_label
= NULL
;
354 mi
->is_continuous
= TRUE
;
356 rc
= msi_media_get_disk_info(data
->package
, mi
);
357 if (rc
!= ERROR_SUCCESS
)
359 ERR("Failed to get next cabinet information: %d\n", rc
);
363 if (strcmpiW( mi
->cabinet
, cab
))
365 ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
369 if (!(cabinet_file
= get_cabinet_filename(mi
)))
372 TRACE("Searching for %s\n", debugstr_w(cabinet_file
));
375 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
377 if (msi_change_media(data
->package
, mi
) != ERROR_SUCCESS
)
383 msi_free(cabinet_file
);
387 static INT_PTR
cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint
,
388 PFDINOTIFICATION pfdin
)
390 MSICABDATA
*data
= pfdin
->pv
;
391 MSIMEDIAINFO
*mi
= data
->mi
;
394 msi_free( mi
->disk_prompt
);
395 msi_free( mi
->cabinet
);
396 msi_free( mi
->volume_label
);
397 mi
->disk_prompt
= NULL
;
399 mi
->volume_label
= NULL
;
402 mi
->is_continuous
= TRUE
;
404 rc
= msi_media_get_disk_info( data
->package
, mi
);
405 if (rc
!= ERROR_SUCCESS
)
407 ERR("Failed to get next cabinet information: %u\n", rc
);
410 package_disk
.id
= mi
->disk_id
;
412 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
416 static INT_PTR
cabinet_copy_file(FDINOTIFICATIONTYPE fdint
,
417 PFDINOTIFICATION pfdin
)
419 MSICABDATA
*data
= pfdin
->pv
;
424 data
->curfile
= strdupAtoW(pfdin
->psz1
);
425 if (!data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_BEGINEXTRACT
, &path
,
428 /* We're not extracting this file, so free the filename. */
429 msi_free(data
->curfile
);
430 data
->curfile
= NULL
;
434 TRACE("extracting %s -> %s\n", debugstr_w(data
->curfile
), debugstr_w(path
));
436 attrs
= attrs
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
437 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
439 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0,
440 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
441 if (handle
== INVALID_HANDLE_VALUE
)
443 DWORD err
= GetLastError();
444 DWORD attrs2
= GetFileAttributesW(path
);
446 if (attrs2
== INVALID_FILE_ATTRIBUTES
)
448 ERR("failed to create %s (error %d)\n", debugstr_w(path
), err
);
451 else if (err
== ERROR_ACCESS_DENIED
&& (attrs2
& FILE_ATTRIBUTE_READONLY
))
453 TRACE("removing read-only attribute on %s\n", debugstr_w(path
));
454 SetFileAttributesW( path
, attrs2
& ~FILE_ATTRIBUTE_READONLY
);
455 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs2
, NULL
);
457 if (handle
!= INVALID_HANDLE_VALUE
) goto done
;
458 err
= GetLastError();
460 if (err
== ERROR_SHARING_VIOLATION
|| err
== ERROR_USER_MAPPED_FILE
)
462 WCHAR
*tmpfileW
, *tmppathW
, *p
;
465 TRACE("file in use, scheduling rename operation\n");
467 if (!(tmppathW
= strdupW( path
))) return ERROR_OUTOFMEMORY
;
468 if ((p
= strrchrW(tmppathW
, '\\'))) *p
= 0;
469 len
= strlenW( tmppathW
) + 16;
470 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
472 msi_free( tmppathW
);
473 return ERROR_OUTOFMEMORY
;
475 if (!GetTempFileNameW(tmppathW
, szMsi
, 0, tmpfileW
)) tmpfileW
[0] = 0;
476 msi_free( tmppathW
);
478 handle
= CreateFileW(tmpfileW
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs
, NULL
);
480 if (handle
!= INVALID_HANDLE_VALUE
&&
481 MoveFileExW(path
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
482 MoveFileExW(tmpfileW
, path
, MOVEFILE_DELAY_UNTIL_REBOOT
))
484 data
->package
->need_reboot_at_end
= 1;
488 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path
), GetLastError());
489 DeleteFileW( tmpfileW
);
494 WARN("failed to create %s (error %d)\n", debugstr_w(path
), err
);
500 return (INT_PTR
)handle
;
503 static INT_PTR
cabinet_close_file_info(FDINOTIFICATIONTYPE fdint
,
504 PFDINOTIFICATION pfdin
)
506 MSICABDATA
*data
= pfdin
->pv
;
509 HANDLE handle
= (HANDLE
)pfdin
->hf
;
511 data
->mi
->is_continuous
= FALSE
;
513 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
515 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
517 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
522 data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_FILEEXTRACTED
, NULL
, NULL
,
525 msi_free(data
->curfile
);
526 data
->curfile
= NULL
;
531 static INT_PTR CDECL
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
535 case fdintPARTIAL_FILE
:
536 return cabinet_partial_file(fdint
, pfdin
);
538 case fdintNEXT_CABINET
:
539 return cabinet_next_cabinet(fdint
, pfdin
);
542 return cabinet_copy_file(fdint
, pfdin
);
544 case fdintCLOSE_FILE_INFO
:
545 return cabinet_close_file_info(fdint
, pfdin
);
552 static INT_PTR CDECL
cabinet_notify_stream( FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
556 case fdintPARTIAL_FILE
:
557 return cabinet_partial_file( fdint
, pfdin
);
559 case fdintNEXT_CABINET
:
560 return cabinet_next_cabinet_stream( fdint
, pfdin
);
563 return cabinet_copy_file( fdint
, pfdin
);
565 case fdintCLOSE_FILE_INFO
:
566 return cabinet_close_file_info( fdint
, pfdin
);
568 case fdintCABINET_INFO
:
572 ERR("Unexpected notification %d\n", fdint
);
577 static BOOL
extract_cabinet( MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
579 LPSTR cabinet
, cab_path
= NULL
;
584 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
586 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
587 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
590 ERR("FDICreate failed\n");
594 cabinet
= strdupWtoA( mi
->cabinet
);
598 cab_path
= strdupWtoA( mi
->sourcedir
);
602 ret
= FDICopy( hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, data
);
604 ERR("FDICopy failed\n");
609 msi_free( cab_path
);
612 mi
->is_extracted
= TRUE
;
617 static BOOL
extract_cabinet_stream( MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
, LPVOID data
)
619 static char filename
[] = {'<','S','T','R','E','A','M','>',0};
624 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
626 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open_stream
, cabinet_read_stream
,
627 cabinet_write
, cabinet_close_stream
, cabinet_seek_stream
, 0, &erf
);
630 ERR("FDICreate failed\n");
634 package_disk
.package
= package
;
635 package_disk
.id
= mi
->disk_id
;
637 ret
= FDICopy( hfdi
, filename
, NULL
, 0, cabinet_notify_stream
, NULL
, data
);
638 if (!ret
) ERR("FDICopy failed\n");
641 if (ret
) mi
->is_extracted
= TRUE
;
645 /***********************************************************************
648 * Extract files from a cabinet file or stream.
650 BOOL
msi_cabextract(MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
652 if (mi
->cabinet
[0] == '#')
654 return extract_cabinet_stream( package
, mi
, data
);
656 return extract_cabinet( package
, mi
, data
);
659 void msi_free_media_info(MSIMEDIAINFO
*mi
)
661 msi_free(mi
->disk_prompt
);
662 msi_free(mi
->cabinet
);
663 msi_free(mi
->volume_label
);
664 msi_free(mi
->first_volume
);
668 static UINT
get_drive_type(const WCHAR
*path
)
670 WCHAR root
[MAX_PATH
+ 1];
673 PathStripToRootW(root
);
674 PathAddBackslashW(root
);
676 return GetDriveTypeW(root
);
679 UINT
msi_load_media_info(MSIPACKAGE
*package
, UINT Sequence
, MSIMEDIAINFO
*mi
)
681 static const WCHAR query
[] = {
682 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
683 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
684 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
686 LPWSTR source_dir
, source
;
689 if (Sequence
<= mi
->last_sequence
) /* already loaded */
690 return ERROR_SUCCESS
;
692 row
= MSI_QueryGetRecord(package
->db
, query
, Sequence
);
695 TRACE("Unable to query row\n");
696 return ERROR_FUNCTION_FAILED
;
699 mi
->is_extracted
= FALSE
;
700 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
701 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
702 msi_free(mi
->disk_prompt
);
703 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
704 msi_free(mi
->cabinet
);
705 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
706 msi_free(mi
->volume_label
);
707 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
708 msiobj_release(&row
->hdr
);
710 if (!mi
->first_volume
)
711 mi
->first_volume
= strdupW(mi
->volume_label
);
713 msi_set_sourcedir_props(package
, FALSE
);
714 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
715 lstrcpyW(mi
->sourcedir
, source_dir
);
716 PathAddBackslashW(mi
->sourcedir
);
717 mi
->type
= get_drive_type(source_dir
);
719 options
= MSICODE_PRODUCT
;
720 if (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
)
723 options
|= MSISOURCETYPE_MEDIA
;
725 else if (package
->BaseURL
&& UrlIsW(package
->BaseURL
, URLIS_URL
))
727 source
= package
->BaseURL
;
728 options
|= MSISOURCETYPE_URL
;
732 source
= mi
->sourcedir
;
733 options
|= MSISOURCETYPE_NETWORK
;
736 msi_package_add_media_disk(package
, package
->Context
,
737 MSICODE_PRODUCT
, mi
->disk_id
,
738 mi
->volume_label
, mi
->disk_prompt
);
740 msi_package_add_info(package
, package
->Context
,
741 options
, INSTALLPROPERTY_LASTUSEDSOURCEW
, source
);
743 msi_free(source_dir
);
744 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence
, debugstr_w(mi
->cabinet
), mi
->disk_id
);
745 return ERROR_SUCCESS
;
748 /* FIXME: search URL sources as well */
749 static UINT
find_published_source(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
751 WCHAR source
[MAX_PATH
];
752 WCHAR volume
[MAX_PATH
];
753 WCHAR prompt
[MAX_PATH
];
754 DWORD volumesz
, promptsz
;
755 DWORD index
, size
, id
;
760 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
761 package
->Context
, MSICODE_PRODUCT
,
762 INSTALLPROPERTY_LASTUSEDTYPEW
, last_type
, &size
);
763 if (r
!= ERROR_SUCCESS
)
767 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
768 package
->Context
, MSICODE_PRODUCT
,
769 INSTALLPROPERTY_LASTUSEDSOURCEW
, source
, &size
);
770 if (r
!= ERROR_SUCCESS
)
773 if (last_type
[0] == 'n')
775 WCHAR cabinet_file
[MAX_PATH
];
776 BOOL check_all
= FALSE
;
782 while (MsiSourceListEnumSourcesW(package
->ProductCode
, NULL
,
784 MSISOURCETYPE_NETWORK
, index
++,
785 volume
, &volumesz
) == ERROR_SUCCESS
)
787 if (check_all
|| !strncmpiW(source
, volume
, strlenW(source
)))
789 lstrcpyW(cabinet_file
, volume
);
790 PathAddBackslashW(cabinet_file
);
791 lstrcatW(cabinet_file
, mi
->cabinet
);
793 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
801 lstrcpyW(mi
->sourcedir
, volume
);
802 PathAddBackslashW(mi
->sourcedir
);
803 TRACE("Found network source %s\n", debugstr_w(mi
->sourcedir
));
804 return ERROR_SUCCESS
;
818 while (MsiSourceListEnumMediaDisksW(package
->ProductCode
, NULL
,
820 MSICODE_PRODUCT
, index
++, &id
,
821 volume
, &volumesz
, prompt
, &promptsz
) == ERROR_SUCCESS
)
824 msi_free( mi
->volume_label
);
825 if (!(mi
->volume_label
= msi_alloc( ++volumesz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
826 strcpyW( mi
->volume_label
, volume
);
828 msi_free( mi
->disk_prompt
);
829 if (!(mi
->disk_prompt
= msi_alloc( ++promptsz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
830 strcpyW( mi
->disk_prompt
, prompt
);
832 if (source_matches_volume(mi
, source
))
834 /* FIXME: what about SourceDir */
835 lstrcpyW(mi
->sourcedir
, source
);
836 PathAddBackslashW(mi
->sourcedir
);
837 TRACE("Found disk source %s\n", debugstr_w(mi
->sourcedir
));
838 return ERROR_SUCCESS
;
842 return ERROR_FUNCTION_FAILED
;
845 UINT
ready_media( MSIPACKAGE
*package
, BOOL compressed
, MSIMEDIAINFO
*mi
)
848 WCHAR
*cabinet_file
= NULL
;
850 /* media info for continuous cabinet is already loaded */
851 if (mi
->is_continuous
) return ERROR_SUCCESS
;
855 /* cabinet is internal, no checks needed */
856 if (mi
->cabinet
[0] == '#') return ERROR_SUCCESS
;
858 if (!(cabinet_file
= get_cabinet_filename( mi
))) return ERROR_OUTOFMEMORY
;
860 /* package should be downloaded */
861 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
&&
862 package
->BaseURL
&& UrlIsW( package
->BaseURL
, URLIS_URL
))
864 WCHAR temppath
[MAX_PATH
], *p
;
866 if ((rc
= msi_download_file( cabinet_file
, temppath
)) != ERROR_SUCCESS
)
868 ERR("failed to download %s (%u)\n", debugstr_w(cabinet_file
), rc
);
869 msi_free( cabinet_file
);
872 if ((p
= strrchrW( temppath
, '\\' ))) *p
= 0;
873 strcpyW( mi
->sourcedir
, temppath
);
874 PathAddBackslashW( mi
->sourcedir
);
875 msi_free( mi
->cabinet
);
876 mi
->cabinet
= strdupW( p
+ 1 );
877 msi_free( cabinet_file
);
878 return ERROR_SUCCESS
;
881 /* check volume matches, change media if not */
882 if (mi
->volume_label
&& mi
->disk_id
> 1 && strcmpW( mi
->first_volume
, mi
->volume_label
))
884 WCHAR
*source
= msi_dup_property( package
->db
, szSourceDir
);
885 BOOL match
= source_matches_volume( mi
, source
);
888 if (!match
&& (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
))
890 if ((rc
= msi_change_media( package
, mi
)) != ERROR_SUCCESS
)
892 msi_free( cabinet_file
);
899 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
901 if ((rc
= find_published_source( package
, mi
)) != ERROR_SUCCESS
)
903 ERR("cabinet not found: %s\n", debugstr_w(cabinet_file
));
904 msi_free( cabinet_file
);
905 return ERROR_INSTALL_FAILURE
;
909 msi_free( cabinet_file
);
910 return ERROR_SUCCESS
;
913 UINT
msi_add_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
, IStorage
*storage
, const WCHAR
*name
)
915 MSICABINETSTREAM
*cab
, *item
;
917 TRACE("%p, %u, %p, %s\n", package
, disk_id
, storage
, debugstr_w(name
));
919 LIST_FOR_EACH_ENTRY( item
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
921 if (item
->disk_id
== disk_id
)
923 TRACE("duplicate disk id %u\n", disk_id
);
924 return ERROR_FUNCTION_FAILED
;
927 if (!(cab
= msi_alloc( sizeof(*cab
) ))) return ERROR_OUTOFMEMORY
;
928 if (!(cab
->stream
= msi_alloc( (strlenW( name
) + 1) * sizeof(WCHAR
) )))
931 return ERROR_OUTOFMEMORY
;
933 strcpyW( cab
->stream
, name
);
934 cab
->disk_id
= disk_id
;
935 cab
->storage
= storage
;
936 IStorage_AddRef( storage
);
937 list_add_tail( &package
->cabinet_streams
, &cab
->entry
);
939 return ERROR_SUCCESS
;