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], root
[MAX_PATH
+ 1];
61 strcpyW(root
, source_root
);
62 PathStripToRootW(root
);
63 PathAddBackslashW(root
);
65 if (!GetVolumeInformationW(root
, volume_name
, MAX_PATH
+ 1, NULL
, NULL
, NULL
, NULL
, 0))
67 WARN("failed to get volume information for %s (%u)\n", debugstr_w(root
), GetLastError());
71 len
= strlenW( volume_name
);
72 len2
= strlenW( mi
->volume_label
);
73 if (len2
> len
) return FALSE
;
74 p
= volume_name
+ len
- len2
;
76 return !strcmpiW( mi
->volume_label
, p
);
79 static UINT
msi_change_media(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
81 LPWSTR error
, error_dialog
;
83 UINT r
= ERROR_SUCCESS
;
85 static const WCHAR error_prop
[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
87 if ((package
->ui_level
& INSTALLUILEVEL_MASK
) == INSTALLUILEVEL_NONE
&&
88 !gUIHandlerA
&& !gUIHandlerW
&& !gUIHandlerRecord
) return ERROR_SUCCESS
;
90 error
= msi_build_error_string(package
, 1302, 1, mi
->disk_prompt
);
91 error_dialog
= msi_dup_property(package
->db
, error_prop
);
92 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
94 while (r
== ERROR_SUCCESS
&& !source_matches_volume(mi
, source_dir
))
96 r
= msi_spawn_error_dialog(package
, error_dialog
, error
);
100 gUIHandlerW(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, error
);
102 else if (gUIHandlerA
)
104 char *msg
= strdupWtoA(error
);
105 gUIHandlerA(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, msg
);
108 else if (gUIHandlerRecord
)
110 MSIHANDLE rec
= MsiCreateRecord(1);
111 MsiRecordSetStringW(rec
, 0, error
);
112 gUIHandlerRecord(gUIContext
, MB_RETRYCANCEL
| INSTALLMESSAGE_ERROR
, rec
);
118 msi_free(error_dialog
);
119 msi_free(source_dir
);
124 static MSICABINETSTREAM
*msi_get_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
)
126 MSICABINETSTREAM
*cab
;
128 LIST_FOR_EACH_ENTRY( cab
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
130 if (cab
->disk_id
== disk_id
) return cab
;
135 static void * CDECL
cabinet_alloc(ULONG cb
)
137 return msi_alloc(cb
);
140 static void CDECL
cabinet_free(void *pv
)
145 static INT_PTR CDECL
cabinet_open(char *pszFile
, int oflag
, int pmode
)
148 DWORD dwShareMode
= 0;
149 DWORD dwCreateDisposition
= OPEN_EXISTING
;
151 switch (oflag
& _O_ACCMODE
)
154 dwAccess
= GENERIC_READ
;
155 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
158 dwAccess
= GENERIC_WRITE
;
159 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
162 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
163 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
167 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
168 dwCreateDisposition
= CREATE_NEW
;
169 else if (oflag
& _O_CREAT
)
170 dwCreateDisposition
= CREATE_ALWAYS
;
172 return (INT_PTR
)CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
173 dwCreateDisposition
, 0, NULL
);
176 static UINT CDECL
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
178 HANDLE handle
= (HANDLE
)hf
;
181 if (ReadFile(handle
, pv
, cb
, &read
, NULL
))
187 static UINT CDECL
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
189 HANDLE handle
= (HANDLE
)hf
;
192 if (WriteFile(handle
, pv
, cb
, &written
, NULL
))
198 static int CDECL
cabinet_close(INT_PTR hf
)
200 HANDLE handle
= (HANDLE
)hf
;
201 return CloseHandle(handle
) ? 0 : -1;
204 static LONG CDECL
cabinet_seek(INT_PTR hf
, LONG dist
, int seektype
)
206 HANDLE handle
= (HANDLE
)hf
;
207 /* flags are compatible and so are passed straight through */
208 return SetFilePointer(handle
, dist
, NULL
, seektype
);
217 static struct package_disk package_disk
;
219 static INT_PTR CDECL
cabinet_open_stream( char *pszFile
, int oflag
, int pmode
)
221 MSICABINETSTREAM
*cab
;
226 cab
= msi_get_cabinet_stream( package_disk
.package
, package_disk
.id
);
229 WARN("failed to get cabinet stream\n");
232 if (!cab
->stream
[0] || !(encoded
= encode_streamname( FALSE
, cab
->stream
+ 1 )))
234 WARN("failed to encode stream name\n");
237 hr
= IStorage_OpenStream( cab
->storage
, encoded
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stream
);
240 WARN("failed to open stream 0x%08x\n", hr
);
245 return (INT_PTR
)stream
;
248 static UINT CDECL
cabinet_read_stream( INT_PTR hf
, void *pv
, UINT cb
)
250 IStream
*stm
= (IStream
*)hf
;
254 hr
= IStream_Read( stm
, pv
, cb
, &read
);
255 if (hr
== S_OK
|| hr
== S_FALSE
)
261 static int CDECL
cabinet_close_stream( INT_PTR hf
)
263 IStream
*stm
= (IStream
*)hf
;
264 IStream_Release( stm
);
268 static LONG CDECL
cabinet_seek_stream( INT_PTR hf
, LONG dist
, int seektype
)
270 IStream
*stm
= (IStream
*)hf
;
272 ULARGE_INTEGER newpos
;
275 move
.QuadPart
= dist
;
276 hr
= IStream_Seek( stm
, move
, seektype
, &newpos
);
279 if (newpos
.QuadPart
<= MAXLONG
) return newpos
.QuadPart
;
285 static UINT CDECL
msi_media_get_disk_info(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
289 static const WCHAR query
[] = {
290 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
291 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
292 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
294 row
= MSI_QueryGetRecord(package
->db
, query
, mi
->disk_id
);
297 TRACE("Unable to query row\n");
298 return ERROR_FUNCTION_FAILED
;
301 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
302 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
303 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
305 msiobj_release(&row
->hdr
);
306 return ERROR_SUCCESS
;
309 static INT_PTR
cabinet_partial_file(FDINOTIFICATIONTYPE fdint
,
310 PFDINOTIFICATION pfdin
)
312 MSICABDATA
*data
= pfdin
->pv
;
313 data
->mi
->is_continuous
= FALSE
;
317 static WCHAR
*get_cabinet_filename(MSIMEDIAINFO
*mi
)
322 len
= strlenW(mi
->sourcedir
) + strlenW(mi
->cabinet
) + 1;
323 if (!(ret
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
324 strcpyW(ret
, mi
->sourcedir
);
325 strcatW(ret
, mi
->cabinet
);
329 static INT_PTR
cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint
,
330 PFDINOTIFICATION pfdin
)
332 MSICABDATA
*data
= pfdin
->pv
;
333 MSIMEDIAINFO
*mi
= data
->mi
;
334 LPWSTR cabinet_file
= NULL
, cab
= strdupAtoW(pfdin
->psz1
);
338 msi_free(mi
->disk_prompt
);
339 msi_free(mi
->cabinet
);
340 msi_free(mi
->volume_label
);
341 mi
->disk_prompt
= NULL
;
343 mi
->volume_label
= NULL
;
346 mi
->is_continuous
= TRUE
;
348 rc
= msi_media_get_disk_info(data
->package
, mi
);
349 if (rc
!= ERROR_SUCCESS
)
351 ERR("Failed to get next cabinet information: %d\n", rc
);
355 if (strcmpiW( mi
->cabinet
, cab
))
360 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
));
362 /* Use cabinet name from the media table */
363 next_cab
= strdupWtoA(mi
->cabinet
);
364 /* Modify path to cabinet file with full filename (psz3 points to a 256 bytes buffer that can be modified contrary to psz1 and psz2) */
365 length
= strlen(pfdin
->psz3
) + 1 + strlen(next_cab
) + 1;
368 WARN("Cannot update next cabinet filename with a string size %u > 256\n", length
);
374 strcat(pfdin
->psz3
, "\\");
375 strcat(pfdin
->psz3
, next_cab
);
377 /* Path psz3 and cabinet psz1 are concatenated by FDI so just reset psz1 */
382 if (!(cabinet_file
= get_cabinet_filename(mi
)))
385 TRACE("Searching for %s\n", debugstr_w(cabinet_file
));
388 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
390 if (msi_change_media(data
->package
, mi
) != ERROR_SUCCESS
)
396 msi_free(cabinet_file
);
400 static INT_PTR
cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint
,
401 PFDINOTIFICATION pfdin
)
403 MSICABDATA
*data
= pfdin
->pv
;
404 MSIMEDIAINFO
*mi
= data
->mi
;
407 msi_free( mi
->disk_prompt
);
408 msi_free( mi
->cabinet
);
409 msi_free( mi
->volume_label
);
410 mi
->disk_prompt
= NULL
;
412 mi
->volume_label
= NULL
;
415 mi
->is_continuous
= TRUE
;
417 rc
= msi_media_get_disk_info( data
->package
, mi
);
418 if (rc
!= ERROR_SUCCESS
)
420 ERR("Failed to get next cabinet information: %u\n", rc
);
423 package_disk
.id
= mi
->disk_id
;
425 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
429 static INT_PTR
cabinet_copy_file(FDINOTIFICATIONTYPE fdint
,
430 PFDINOTIFICATION pfdin
)
432 MSICABDATA
*data
= pfdin
->pv
;
437 data
->curfile
= strdupAtoW(pfdin
->psz1
);
438 if (!data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_BEGINEXTRACT
, &path
,
441 /* We're not extracting this file, so free the filename. */
442 msi_free(data
->curfile
);
443 data
->curfile
= NULL
;
447 TRACE("extracting %s -> %s\n", debugstr_w(data
->curfile
), debugstr_w(path
));
449 attrs
= attrs
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
450 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
452 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0,
453 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
454 if (handle
== INVALID_HANDLE_VALUE
)
456 DWORD err
= GetLastError();
457 DWORD attrs2
= GetFileAttributesW(path
);
459 if (attrs2
== INVALID_FILE_ATTRIBUTES
)
461 ERR("failed to create %s (error %d)\n", debugstr_w(path
), err
);
464 else if (err
== ERROR_ACCESS_DENIED
&& (attrs2
& FILE_ATTRIBUTE_READONLY
))
466 TRACE("removing read-only attribute on %s\n", debugstr_w(path
));
467 SetFileAttributesW( path
, attrs2
& ~FILE_ATTRIBUTE_READONLY
);
468 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs2
, NULL
);
470 if (handle
!= INVALID_HANDLE_VALUE
) goto done
;
471 err
= GetLastError();
473 if (err
== ERROR_SHARING_VIOLATION
|| err
== ERROR_USER_MAPPED_FILE
)
475 WCHAR
*tmpfileW
, *tmppathW
, *p
;
478 TRACE("file in use, scheduling rename operation\n");
480 if (!(tmppathW
= strdupW( path
))) return ERROR_OUTOFMEMORY
;
481 if ((p
= strrchrW(tmppathW
, '\\'))) *p
= 0;
482 len
= strlenW( tmppathW
) + 16;
483 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
485 msi_free( tmppathW
);
486 return ERROR_OUTOFMEMORY
;
488 if (!GetTempFileNameW(tmppathW
, szMsi
, 0, tmpfileW
)) tmpfileW
[0] = 0;
489 msi_free( tmppathW
);
491 handle
= CreateFileW(tmpfileW
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs
, NULL
);
493 if (handle
!= INVALID_HANDLE_VALUE
&&
494 MoveFileExW(path
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
495 MoveFileExW(tmpfileW
, path
, MOVEFILE_DELAY_UNTIL_REBOOT
))
497 data
->package
->need_reboot_at_end
= 1;
501 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path
), GetLastError());
502 DeleteFileW( tmpfileW
);
507 WARN("failed to create %s (error %d)\n", debugstr_w(path
), err
);
513 return (INT_PTR
)handle
;
516 static INT_PTR
cabinet_close_file_info(FDINOTIFICATIONTYPE fdint
,
517 PFDINOTIFICATION pfdin
)
519 MSICABDATA
*data
= pfdin
->pv
;
522 HANDLE handle
= (HANDLE
)pfdin
->hf
;
524 data
->mi
->is_continuous
= FALSE
;
526 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
528 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
530 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
535 data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_FILEEXTRACTED
, NULL
, NULL
,
538 msi_free(data
->curfile
);
539 data
->curfile
= NULL
;
544 static INT_PTR CDECL
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
548 case fdintPARTIAL_FILE
:
549 return cabinet_partial_file(fdint
, pfdin
);
551 case fdintNEXT_CABINET
:
552 return cabinet_next_cabinet(fdint
, pfdin
);
555 return cabinet_copy_file(fdint
, pfdin
);
557 case fdintCLOSE_FILE_INFO
:
558 return cabinet_close_file_info(fdint
, pfdin
);
565 static INT_PTR CDECL
cabinet_notify_stream( FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
569 case fdintPARTIAL_FILE
:
570 return cabinet_partial_file( fdint
, pfdin
);
572 case fdintNEXT_CABINET
:
573 return cabinet_next_cabinet_stream( fdint
, pfdin
);
576 return cabinet_copy_file( fdint
, pfdin
);
578 case fdintCLOSE_FILE_INFO
:
579 return cabinet_close_file_info( fdint
, pfdin
);
581 case fdintCABINET_INFO
:
585 ERR("Unexpected notification %d\n", fdint
);
590 static BOOL
extract_cabinet( MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
592 LPSTR cabinet
, cab_path
= NULL
;
597 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
599 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
600 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
603 ERR("FDICreate failed\n");
607 cabinet
= strdupWtoA( mi
->cabinet
);
611 cab_path
= strdupWtoA( mi
->sourcedir
);
615 ret
= FDICopy( hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, data
);
617 ERR("FDICopy failed\n");
622 msi_free( cab_path
);
625 mi
->is_extracted
= TRUE
;
630 static BOOL
extract_cabinet_stream( MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
, LPVOID data
)
632 static char filename
[] = {'<','S','T','R','E','A','M','>',0};
637 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
639 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open_stream
, cabinet_read_stream
,
640 cabinet_write
, cabinet_close_stream
, cabinet_seek_stream
, 0, &erf
);
643 ERR("FDICreate failed\n");
647 package_disk
.package
= package
;
648 package_disk
.id
= mi
->disk_id
;
650 ret
= FDICopy( hfdi
, filename
, NULL
, 0, cabinet_notify_stream
, NULL
, data
);
651 if (!ret
) ERR("FDICopy failed\n");
654 if (ret
) mi
->is_extracted
= TRUE
;
658 /***********************************************************************
661 * Extract files from a cabinet file or stream.
663 BOOL
msi_cabextract(MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
665 if (mi
->cabinet
[0] == '#')
667 return extract_cabinet_stream( package
, mi
, data
);
669 return extract_cabinet( package
, mi
, data
);
672 void msi_free_media_info(MSIMEDIAINFO
*mi
)
674 msi_free(mi
->disk_prompt
);
675 msi_free(mi
->cabinet
);
676 msi_free(mi
->volume_label
);
680 static UINT
get_drive_type(const WCHAR
*path
)
682 WCHAR root
[MAX_PATH
+ 1];
685 PathStripToRootW(root
);
686 PathAddBackslashW(root
);
688 return GetDriveTypeW(root
);
691 UINT
msi_load_media_info(MSIPACKAGE
*package
, UINT Sequence
, MSIMEDIAINFO
*mi
)
693 static const WCHAR query
[] = {
694 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
695 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
696 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
698 LPWSTR source_dir
, source
;
701 if (Sequence
<= mi
->last_sequence
) /* already loaded */
702 return ERROR_SUCCESS
;
704 row
= MSI_QueryGetRecord(package
->db
, query
, Sequence
);
707 TRACE("Unable to query row\n");
708 return ERROR_FUNCTION_FAILED
;
711 mi
->is_extracted
= FALSE
;
712 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
713 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
714 msi_free(mi
->disk_prompt
);
715 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
716 msi_free(mi
->cabinet
);
717 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
718 msi_free(mi
->volume_label
);
719 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
720 msiobj_release(&row
->hdr
);
722 msi_set_sourcedir_props(package
, FALSE
);
723 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
724 lstrcpyW(mi
->sourcedir
, source_dir
);
725 PathAddBackslashW(mi
->sourcedir
);
726 mi
->type
= get_drive_type(source_dir
);
728 options
= MSICODE_PRODUCT
;
729 if (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
)
732 options
|= MSISOURCETYPE_MEDIA
;
734 else if (package
->BaseURL
&& UrlIsW(package
->BaseURL
, URLIS_URL
))
736 source
= package
->BaseURL
;
737 options
|= MSISOURCETYPE_URL
;
741 source
= mi
->sourcedir
;
742 options
|= MSISOURCETYPE_NETWORK
;
745 msi_package_add_media_disk(package
, package
->Context
,
746 MSICODE_PRODUCT
, mi
->disk_id
,
747 mi
->volume_label
, mi
->disk_prompt
);
749 msi_package_add_info(package
, package
->Context
,
750 options
, INSTALLPROPERTY_LASTUSEDSOURCEW
, source
);
752 msi_free(source_dir
);
753 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence
, debugstr_w(mi
->cabinet
), mi
->disk_id
);
754 return ERROR_SUCCESS
;
757 /* FIXME: search URL sources as well */
758 static UINT
find_published_source(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
760 WCHAR source
[MAX_PATH
];
761 WCHAR volume
[MAX_PATH
];
762 WCHAR prompt
[MAX_PATH
];
763 DWORD volumesz
, promptsz
;
764 DWORD index
, size
, id
;
769 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
770 package
->Context
, MSICODE_PRODUCT
,
771 INSTALLPROPERTY_LASTUSEDTYPEW
, last_type
, &size
);
772 if (r
!= ERROR_SUCCESS
)
776 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
777 package
->Context
, MSICODE_PRODUCT
,
778 INSTALLPROPERTY_LASTUSEDSOURCEW
, source
, &size
);
779 if (r
!= ERROR_SUCCESS
)
782 if (last_type
[0] == 'n')
784 WCHAR cabinet_file
[MAX_PATH
];
785 BOOL check_all
= FALSE
;
791 while (MsiSourceListEnumSourcesW(package
->ProductCode
, NULL
,
793 MSISOURCETYPE_NETWORK
, index
++,
794 volume
, &volumesz
) == ERROR_SUCCESS
)
796 if (check_all
|| !strncmpiW(source
, volume
, strlenW(source
)))
798 lstrcpyW(cabinet_file
, volume
);
799 PathAddBackslashW(cabinet_file
);
800 lstrcatW(cabinet_file
, mi
->cabinet
);
802 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
810 lstrcpyW(mi
->sourcedir
, volume
);
811 PathAddBackslashW(mi
->sourcedir
);
812 TRACE("Found network source %s\n", debugstr_w(mi
->sourcedir
));
813 return ERROR_SUCCESS
;
827 while (MsiSourceListEnumMediaDisksW(package
->ProductCode
, NULL
,
829 MSICODE_PRODUCT
, index
++, &id
,
830 volume
, &volumesz
, prompt
, &promptsz
) == ERROR_SUCCESS
)
833 msi_free( mi
->volume_label
);
834 if (!(mi
->volume_label
= msi_alloc( ++volumesz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
835 strcpyW( mi
->volume_label
, volume
);
837 msi_free( mi
->disk_prompt
);
838 if (!(mi
->disk_prompt
= msi_alloc( ++promptsz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
839 strcpyW( mi
->disk_prompt
, prompt
);
841 if (source_matches_volume(mi
, source
))
843 /* FIXME: what about SourceDir */
844 lstrcpyW(mi
->sourcedir
, source
);
845 PathAddBackslashW(mi
->sourcedir
);
846 TRACE("Found disk source %s\n", debugstr_w(mi
->sourcedir
));
847 return ERROR_SUCCESS
;
851 return ERROR_FUNCTION_FAILED
;
854 UINT
ready_media( MSIPACKAGE
*package
, BOOL compressed
, MSIMEDIAINFO
*mi
)
857 WCHAR
*cabinet_file
= NULL
;
859 /* media info for continuous cabinet is already loaded */
860 if (mi
->is_continuous
) return ERROR_SUCCESS
;
864 /* cabinet is internal, no checks needed */
865 if (mi
->cabinet
[0] == '#') return ERROR_SUCCESS
;
867 if (!(cabinet_file
= get_cabinet_filename( mi
))) return ERROR_OUTOFMEMORY
;
869 /* package should be downloaded */
870 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
&&
871 package
->BaseURL
&& UrlIsW( package
->BaseURL
, URLIS_URL
))
873 WCHAR temppath
[MAX_PATH
], *p
;
875 if ((rc
= msi_download_file( cabinet_file
, temppath
)) != ERROR_SUCCESS
)
877 ERR("failed to download %s (%u)\n", debugstr_w(cabinet_file
), rc
);
878 msi_free( cabinet_file
);
881 if ((p
= strrchrW( temppath
, '\\' ))) *p
= 0;
882 strcpyW( mi
->sourcedir
, temppath
);
883 PathAddBackslashW( mi
->sourcedir
);
884 msi_free( mi
->cabinet
);
885 mi
->cabinet
= strdupW( p
+ 1 );
886 msi_free( cabinet_file
);
887 return ERROR_SUCCESS
;
890 /* check volume matches, change media if not */
891 if (mi
->volume_label
&& mi
->disk_id
> 1)
893 WCHAR
*source
= msi_dup_property( package
->db
, szSourceDir
);
894 BOOL match
= source_matches_volume( mi
, source
);
897 if (!match
&& (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
))
899 if ((rc
= msi_change_media( package
, mi
)) != ERROR_SUCCESS
)
901 msi_free( cabinet_file
);
908 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
910 if ((rc
= find_published_source( package
, mi
)) != ERROR_SUCCESS
)
912 ERR("cabinet not found: %s\n", debugstr_w(cabinet_file
));
913 msi_free( cabinet_file
);
914 return ERROR_INSTALL_FAILURE
;
918 msi_free( cabinet_file
);
919 return ERROR_SUCCESS
;
922 UINT
msi_add_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
, IStorage
*storage
, const WCHAR
*name
)
924 MSICABINETSTREAM
*cab
, *item
;
926 TRACE("%p, %u, %p, %s\n", package
, disk_id
, storage
, debugstr_w(name
));
928 LIST_FOR_EACH_ENTRY( item
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
930 if (item
->disk_id
== disk_id
)
932 TRACE("duplicate disk id %u\n", disk_id
);
933 return ERROR_FUNCTION_FAILED
;
936 if (!(cab
= msi_alloc( sizeof(*cab
) ))) return ERROR_OUTOFMEMORY
;
937 if (!(cab
->stream
= msi_alloc( (strlenW( name
) + 1) * sizeof(WCHAR
) )))
940 return ERROR_OUTOFMEMORY
;
942 strcpyW( cab
->stream
, name
);
943 cab
->disk_id
= disk_id
;
944 cab
->storage
= storage
;
945 IStorage_AddRef( storage
);
946 list_add_tail( &package
->cabinet_streams
, &cab
->entry
);
948 return ERROR_SUCCESS
;