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
28 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msi
);
39 static BOOL
source_matches_volume(MSIMEDIAINFO
*mi
, LPCWSTR source_root
)
41 WCHAR volume_name
[MAX_PATH
+ 1], root
[MAX_PATH
+ 1];
45 lstrcpyW(root
, source_root
);
46 PathStripToRootW(root
);
47 PathAddBackslashW(root
);
49 if (!GetVolumeInformationW(root
, volume_name
, MAX_PATH
+ 1, NULL
, NULL
, NULL
, NULL
, 0))
51 WARN( "failed to get volume information for %s (%lu)\n", debugstr_w(root
), GetLastError() );
55 len
= lstrlenW( volume_name
);
56 len2
= lstrlenW( mi
->volume_label
);
57 if (len2
> len
) return FALSE
;
58 p
= volume_name
+ len
- len2
;
60 return !wcsicmp( mi
->volume_label
, p
);
63 static UINT
change_media(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
69 source_dir
= msi_dup_property(package
->db
, L
"SourceDir");
70 record
= MSI_CreateRecord(2);
72 while (r
== IDRETRY
&& !source_matches_volume(mi
, source_dir
))
74 MSI_RecordSetStringW(record
, 0, NULL
);
75 MSI_RecordSetInteger(record
, 1, MSIERR_CABNOTFOUND
);
76 MSI_RecordSetStringW(record
, 2, mi
->disk_prompt
);
77 r
= MSI_ProcessMessage(package
, INSTALLMESSAGE_ERROR
| MB_RETRYCANCEL
, record
);
80 msiobj_release(&record
->hdr
);
83 return r
== IDRETRY
? ERROR_SUCCESS
: ERROR_INSTALL_SOURCE_ABSENT
;
86 static MSICABINETSTREAM
*get_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
)
88 MSICABINETSTREAM
*cab
;
90 LIST_FOR_EACH_ENTRY( cab
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
92 if (cab
->disk_id
== disk_id
) return cab
;
97 static void * CDECL
cabinet_alloc(ULONG cb
)
102 static void CDECL
cabinet_free(void *pv
)
107 static INT_PTR CDECL
cabinet_open(char *pszFile
, int oflag
, int pmode
)
110 DWORD dwShareMode
= 0;
111 DWORD dwCreateDisposition
= OPEN_EXISTING
;
115 switch (oflag
& _O_ACCMODE
)
118 dwAccess
= GENERIC_READ
;
119 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_DELETE
;
122 dwAccess
= GENERIC_WRITE
;
123 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
126 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
127 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
;
131 if ((oflag
& (_O_CREAT
| _O_EXCL
)) == (_O_CREAT
| _O_EXCL
))
132 dwCreateDisposition
= CREATE_NEW
;
133 else if (oflag
& _O_CREAT
)
134 dwCreateDisposition
= CREATE_ALWAYS
;
136 path
= strdupUtoW(pszFile
);
137 handle
= CreateFileW(path
, dwAccess
, dwShareMode
, NULL
, dwCreateDisposition
, 0, NULL
);
139 return (INT_PTR
)handle
;
142 static UINT CDECL
cabinet_read(INT_PTR hf
, void *pv
, UINT cb
)
144 HANDLE handle
= (HANDLE
)hf
;
147 if (ReadFile(handle
, pv
, cb
, &read
, NULL
))
153 static UINT CDECL
cabinet_write(INT_PTR hf
, void *pv
, UINT cb
)
155 HANDLE handle
= (HANDLE
)hf
;
158 if (WriteFile(handle
, pv
, cb
, &written
, NULL
))
164 static int CDECL
cabinet_close(INT_PTR hf
)
166 HANDLE handle
= (HANDLE
)hf
;
167 return CloseHandle(handle
) ? 0 : -1;
170 static LONG CDECL
cabinet_seek(INT_PTR hf
, LONG dist
, int seektype
)
172 HANDLE handle
= (HANDLE
)hf
;
173 /* flags are compatible and so are passed straight through */
174 return SetFilePointer(handle
, dist
, NULL
, seektype
);
183 static struct package_disk package_disk
;
185 static INT_PTR CDECL
cabinet_open_stream( char *pszFile
, int oflag
, int pmode
)
187 MSICABINETSTREAM
*cab
;
190 if (!(cab
= get_cabinet_stream( package_disk
.package
, package_disk
.id
)))
192 WARN("failed to get cabinet stream\n");
195 if (cab
->storage
== package_disk
.package
->db
->storage
)
197 UINT r
= msi_get_stream( package_disk
.package
->db
, cab
->stream
+ 1, &stream
);
198 if (r
!= ERROR_SUCCESS
)
200 WARN("failed to get stream %u\n", r
);
204 else /* patch storage */
209 if (!(encoded
= encode_streamname( FALSE
, cab
->stream
+ 1 )))
211 WARN("failed to encode stream name\n");
214 hr
= IStorage_OpenStream( cab
->storage
, encoded
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stream
);
218 WARN( "failed to open stream %#lx\n", hr
);
222 return (INT_PTR
)stream
;
225 static UINT CDECL
cabinet_read_stream( INT_PTR hf
, void *pv
, UINT cb
)
227 IStream
*stm
= (IStream
*)hf
;
231 hr
= IStream_Read( stm
, pv
, cb
, &read
);
232 if (hr
== S_OK
|| hr
== S_FALSE
)
238 static int CDECL
cabinet_close_stream( INT_PTR hf
)
240 IStream
*stm
= (IStream
*)hf
;
241 IStream_Release( stm
);
245 static LONG CDECL
cabinet_seek_stream( INT_PTR hf
, LONG dist
, int seektype
)
247 IStream
*stm
= (IStream
*)hf
;
249 ULARGE_INTEGER newpos
;
252 move
.QuadPart
= dist
;
253 hr
= IStream_Seek( stm
, move
, seektype
, &newpos
);
256 if (newpos
.QuadPart
<= MAXLONG
) return newpos
.QuadPart
;
262 static UINT
media_get_disk_info(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
266 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Media` WHERE `DiskId` = %d", mi
->disk_id
);
269 TRACE("Unable to query row\n");
270 return ERROR_FUNCTION_FAILED
;
273 mi
->disk_prompt
= wcsdup(MSI_RecordGetString(row
, 3));
274 mi
->cabinet
= wcsdup(MSI_RecordGetString(row
, 4));
275 mi
->volume_label
= wcsdup(MSI_RecordGetString(row
, 5));
277 msiobj_release(&row
->hdr
);
278 return ERROR_SUCCESS
;
281 static INT_PTR
cabinet_partial_file(FDINOTIFICATIONTYPE fdint
,
282 PFDINOTIFICATION pfdin
)
284 MSICABDATA
*data
= pfdin
->pv
;
285 data
->mi
->is_continuous
= FALSE
;
289 static WCHAR
*get_cabinet_filename(MSIMEDIAINFO
*mi
)
294 len
= lstrlenW(mi
->sourcedir
) + lstrlenW(mi
->cabinet
) + 1;
295 if (!(ret
= malloc(len
* sizeof(WCHAR
)))) return NULL
;
296 lstrcpyW(ret
, mi
->sourcedir
);
297 lstrcatW(ret
, mi
->cabinet
);
301 static INT_PTR
cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint
,
302 PFDINOTIFICATION pfdin
)
304 MSICABDATA
*data
= pfdin
->pv
;
305 MSIMEDIAINFO
*mi
= data
->mi
;
306 LPWSTR cabinet_file
= NULL
, cab
= strdupAtoW(pfdin
->psz1
);
310 free(mi
->disk_prompt
);
312 free(mi
->volume_label
);
313 mi
->disk_prompt
= NULL
;
315 mi
->volume_label
= NULL
;
318 mi
->is_continuous
= TRUE
;
320 rc
= media_get_disk_info(data
->package
, mi
);
321 if (rc
!= ERROR_SUCCESS
)
323 ERR("Failed to get next cabinet information: %d\n", rc
);
327 if (wcsicmp( mi
->cabinet
, cab
))
332 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
));
334 /* Use cabinet name from the media table */
335 next_cab
= strdupWtoA(mi
->cabinet
);
336 /* Modify path to cabinet file with full filename (psz3 points to a 256 bytes buffer that can be modified contrary to psz1 and psz2) */
337 length
= strlen(pfdin
->psz3
) + 1 + strlen(next_cab
) + 1;
340 WARN( "cannot update next cabinet filename with a string size %lu > 256\n", length
);
346 strcat(pfdin
->psz3
, "\\");
347 strcat(pfdin
->psz3
, next_cab
);
349 /* Path psz3 and cabinet psz1 are concatenated by FDI so just reset psz1 */
354 if (!(cabinet_file
= get_cabinet_filename(mi
)))
357 TRACE("Searching for %s\n", debugstr_w(cabinet_file
));
360 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
362 if (change_media(data
->package
, mi
) != ERROR_SUCCESS
)
372 static INT_PTR
cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint
,
373 PFDINOTIFICATION pfdin
)
375 MSICABDATA
*data
= pfdin
->pv
;
376 MSIMEDIAINFO
*mi
= data
->mi
;
379 free( mi
->disk_prompt
);
381 free( mi
->volume_label
);
382 mi
->disk_prompt
= NULL
;
384 mi
->volume_label
= NULL
;
387 mi
->is_continuous
= TRUE
;
389 rc
= media_get_disk_info( data
->package
, mi
);
390 if (rc
!= ERROR_SUCCESS
)
392 ERR("Failed to get next cabinet information: %u\n", rc
);
395 package_disk
.id
= mi
->disk_id
;
397 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
401 static INT_PTR
cabinet_copy_file(FDINOTIFICATIONTYPE fdint
,
402 PFDINOTIFICATION pfdin
)
404 MSICABDATA
*data
= pfdin
->pv
;
409 data
->curfile
= strdupAtoW(pfdin
->psz1
);
410 if (!data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_BEGINEXTRACT
, &path
,
413 /* We're not extracting this file, so free the filename. */
415 data
->curfile
= NULL
;
419 TRACE("extracting %s -> %s\n", debugstr_w(data
->curfile
), debugstr_w(path
));
421 attrs
= attrs
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
422 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
424 handle
= msi_create_file( data
->package
, path
, GENERIC_READ
| GENERIC_WRITE
, 0, CREATE_ALWAYS
, attrs
);
425 if (handle
== INVALID_HANDLE_VALUE
)
427 DWORD err
= GetLastError();
428 DWORD attrs2
= msi_get_file_attributes( data
->package
, path
);
430 if (attrs2
== INVALID_FILE_ATTRIBUTES
)
432 ERR( "failed to create %s (error %lu)\n", debugstr_w(path
), err
);
435 else if (err
== ERROR_ACCESS_DENIED
&& (attrs2
& FILE_ATTRIBUTE_READONLY
))
437 TRACE("removing read-only attribute on %s\n", debugstr_w(path
));
438 msi_set_file_attributes( data
->package
, path
, attrs2
& ~FILE_ATTRIBUTE_READONLY
);
439 handle
= msi_create_file( data
->package
, path
, GENERIC_READ
| GENERIC_WRITE
, 0, CREATE_ALWAYS
, attrs
);
441 if (handle
!= INVALID_HANDLE_VALUE
) goto done
;
442 err
= GetLastError();
444 if (err
== ERROR_SHARING_VIOLATION
|| err
== ERROR_USER_MAPPED_FILE
)
446 WCHAR
*tmpfileW
, *tmppathW
, *p
;
449 TRACE("file in use, scheduling rename operation\n");
451 if (!(tmppathW
= wcsdup(path
))) return ERROR_OUTOFMEMORY
;
452 if ((p
= wcsrchr(tmppathW
, '\\'))) *p
= 0;
453 len
= lstrlenW( tmppathW
) + 16;
454 if (!(tmpfileW
= malloc(len
* sizeof(WCHAR
))))
457 return ERROR_OUTOFMEMORY
;
459 if (!msi_get_temp_file_name( data
->package
, tmppathW
, L
"msi", tmpfileW
)) tmpfileW
[0] = 0;
462 handle
= msi_create_file( data
->package
, tmpfileW
, GENERIC_READ
| GENERIC_WRITE
, 0, CREATE_ALWAYS
, attrs
);
464 if (handle
!= INVALID_HANDLE_VALUE
&&
465 msi_move_file( data
->package
, path
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
466 msi_move_file( data
->package
, tmpfileW
, path
, MOVEFILE_DELAY_UNTIL_REBOOT
))
468 data
->package
->need_reboot_at_end
= 1;
472 WARN( "failed to schedule rename operation %s (error %lu)\n", debugstr_w(path
), GetLastError() );
473 msi_delete_file( data
->package
, tmpfileW
);
477 else WARN( "failed to create %s (error %lu)\n", debugstr_w(path
), err
);
483 return (INT_PTR
)handle
;
486 static INT_PTR
cabinet_close_file_info(FDINOTIFICATIONTYPE fdint
,
487 PFDINOTIFICATION pfdin
)
489 MSICABDATA
*data
= pfdin
->pv
;
492 HANDLE handle
= (HANDLE
)pfdin
->hf
;
494 data
->mi
->is_continuous
= FALSE
;
496 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
501 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
506 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
513 data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_FILEEXTRACTED
, NULL
, NULL
, data
->user
);
516 data
->curfile
= NULL
;
521 static INT_PTR CDECL
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
525 case fdintPARTIAL_FILE
:
526 return cabinet_partial_file(fdint
, pfdin
);
528 case fdintNEXT_CABINET
:
529 return cabinet_next_cabinet(fdint
, pfdin
);
532 return cabinet_copy_file(fdint
, pfdin
);
534 case fdintCLOSE_FILE_INFO
:
535 return cabinet_close_file_info(fdint
, pfdin
);
542 static INT_PTR CDECL
cabinet_notify_stream( FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
546 case fdintPARTIAL_FILE
:
547 return cabinet_partial_file( fdint
, pfdin
);
549 case fdintNEXT_CABINET
:
550 return cabinet_next_cabinet_stream( fdint
, pfdin
);
553 return cabinet_copy_file( fdint
, pfdin
);
555 case fdintCLOSE_FILE_INFO
:
556 return cabinet_close_file_info( fdint
, pfdin
);
558 case fdintCABINET_INFO
:
562 ERR("Unexpected notification %d\n", fdint
);
567 static BOOL
extract_cabinet( MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
569 LPSTR cabinet
, cab_path
= NULL
;
574 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
576 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
577 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
580 ERR("FDICreate failed\n");
584 cabinet
= strdupWtoU( mi
->cabinet
);
588 cab_path
= strdupWtoU( mi
->sourcedir
);
592 ret
= FDICopy( hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, data
);
594 ERR("FDICopy failed\n");
602 mi
->is_extracted
= TRUE
;
607 static BOOL
extract_cabinet_stream( MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
, LPVOID data
)
609 static char filename
[] = {'<','S','T','R','E','A','M','>',0};
614 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
616 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open_stream
, cabinet_read_stream
,
617 cabinet_write
, cabinet_close_stream
, cabinet_seek_stream
, 0, &erf
);
620 ERR("FDICreate failed\n");
624 package_disk
.package
= package
;
625 package_disk
.id
= mi
->disk_id
;
627 ret
= FDICopy( hfdi
, filename
, NULL
, 0, cabinet_notify_stream
, NULL
, data
);
628 if (!ret
) ERR("FDICopy failed\n");
631 if (ret
) mi
->is_extracted
= TRUE
;
635 /***********************************************************************
638 * Extract files from a cabinet file or stream.
640 BOOL
msi_cabextract(MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
642 if (mi
->cabinet
[0] == '#')
644 return extract_cabinet_stream( package
, mi
, data
);
646 return extract_cabinet( package
, mi
, data
);
649 void msi_free_media_info(MSIMEDIAINFO
*mi
)
651 free(mi
->disk_prompt
);
653 free(mi
->volume_label
);
654 free(mi
->last_volume
);
658 static UINT
get_drive_type(const WCHAR
*path
)
660 WCHAR root
[MAX_PATH
+ 1];
662 lstrcpyW(root
, path
);
663 PathStripToRootW(root
);
664 PathAddBackslashW(root
);
666 return GetDriveTypeW(root
);
669 static WCHAR
*get_base_url( MSIDATABASE
*db
)
671 WCHAR
*p
, *ret
= NULL
, *orig_db
= msi_dup_property( db
, L
"OriginalDatabase" );
672 if (UrlIsW( orig_db
, URLIS_URL
) && (ret
= wcsdup( orig_db
)) && (p
= wcsrchr( ret
, '/' ))) p
[1] = 0;
677 UINT
msi_load_media_info(MSIPACKAGE
*package
, UINT Sequence
, MSIMEDIAINFO
*mi
)
680 WCHAR
*source_dir
, *source
, *base_url
= NULL
;
683 if (Sequence
<= mi
->last_sequence
) /* already loaded */
684 return ERROR_SUCCESS
;
686 row
= MSI_QueryGetRecord(package
->db
, L
"SELECT * FROM `Media` WHERE `LastSequence` >= %d ORDER BY `DiskId`", Sequence
);
689 TRACE("Unable to query row\n");
690 return ERROR_FUNCTION_FAILED
;
693 mi
->is_extracted
= FALSE
;
694 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
695 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
696 free(mi
->disk_prompt
);
697 mi
->disk_prompt
= wcsdup(MSI_RecordGetString(row
, 3));
699 mi
->cabinet
= wcsdup(MSI_RecordGetString(row
, 4));
700 free(mi
->volume_label
);
701 mi
->volume_label
= wcsdup(MSI_RecordGetString(row
, 5));
702 msiobj_release(&row
->hdr
);
704 msi_set_sourcedir_props(package
, FALSE
);
705 source_dir
= msi_dup_property(package
->db
, L
"SourceDir");
706 lstrcpyW(mi
->sourcedir
, source_dir
);
707 PathAddBackslashW(mi
->sourcedir
);
708 mi
->type
= get_drive_type(source_dir
);
710 options
= MSICODE_PRODUCT
;
711 if (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
)
714 options
|= MSISOURCETYPE_MEDIA
;
716 else if ((base_url
= get_base_url(package
->db
)))
719 options
|= MSISOURCETYPE_URL
;
723 source
= mi
->sourcedir
;
724 options
|= MSISOURCETYPE_NETWORK
;
727 msi_package_add_media_disk(package
, package
->Context
,
728 MSICODE_PRODUCT
, mi
->disk_id
,
729 mi
->volume_label
, mi
->disk_prompt
);
731 msi_package_add_info(package
, package
->Context
,
732 options
, INSTALLPROPERTY_LASTUSEDSOURCEW
, source
);
734 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence
, debugstr_w(mi
->cabinet
), mi
->disk_id
);
738 return ERROR_SUCCESS
;
741 /* FIXME: search URL sources as well */
742 static UINT
find_published_source(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
744 WCHAR source
[MAX_PATH
];
745 WCHAR volume
[MAX_PATH
];
746 WCHAR prompt
[MAX_PATH
];
747 DWORD volumesz
, promptsz
;
748 DWORD index
, size
, id
;
753 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
754 package
->Context
, MSICODE_PRODUCT
,
755 INSTALLPROPERTY_LASTUSEDTYPEW
, last_type
, &size
);
756 if (r
!= ERROR_SUCCESS
)
760 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
761 package
->Context
, MSICODE_PRODUCT
,
762 INSTALLPROPERTY_LASTUSEDSOURCEW
, source
, &size
);
763 if (r
!= ERROR_SUCCESS
)
766 if (last_type
[0] == 'n')
768 WCHAR cabinet_file
[MAX_PATH
];
769 BOOL check_all
= FALSE
;
775 while (MsiSourceListEnumSourcesW(package
->ProductCode
, NULL
,
777 MSISOURCETYPE_NETWORK
, index
++,
778 volume
, &volumesz
) == ERROR_SUCCESS
)
780 if (check_all
|| !wcsnicmp(source
, volume
, lstrlenW(source
)))
782 lstrcpyW(cabinet_file
, volume
);
783 PathAddBackslashW(cabinet_file
);
784 lstrcatW(cabinet_file
, mi
->cabinet
);
786 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
794 lstrcpyW(mi
->sourcedir
, volume
);
795 PathAddBackslashW(mi
->sourcedir
);
796 TRACE("Found network source %s\n", debugstr_w(mi
->sourcedir
));
797 return ERROR_SUCCESS
;
811 while (MsiSourceListEnumMediaDisksW(package
->ProductCode
, NULL
,
813 MSICODE_PRODUCT
, index
++, &id
,
814 volume
, &volumesz
, prompt
, &promptsz
) == ERROR_SUCCESS
)
817 free( mi
->volume_label
);
818 if (!(mi
->volume_label
= malloc( ++volumesz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
819 lstrcpyW( mi
->volume_label
, volume
);
821 free( mi
->disk_prompt
);
822 if (!(mi
->disk_prompt
= malloc( ++promptsz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
823 lstrcpyW( mi
->disk_prompt
, prompt
);
825 if (source_matches_volume(mi
, source
))
827 /* FIXME: what about SourceDir */
828 lstrcpyW(mi
->sourcedir
, source
);
829 PathAddBackslashW(mi
->sourcedir
);
830 TRACE("Found disk source %s\n", debugstr_w(mi
->sourcedir
));
831 return ERROR_SUCCESS
;
835 return ERROR_FUNCTION_FAILED
;
838 UINT
ready_media( MSIPACKAGE
*package
, BOOL compressed
, MSIMEDIAINFO
*mi
)
841 WCHAR
*cabinet_file
= NULL
;
843 /* media info for continuous cabinet is already loaded */
844 if (mi
->is_continuous
) return ERROR_SUCCESS
;
850 /* cabinet is internal, no checks needed */
851 if (mi
->cabinet
[0] == '#') return ERROR_SUCCESS
;
853 if (!(cabinet_file
= get_cabinet_filename( mi
))) return ERROR_OUTOFMEMORY
;
855 /* package should be downloaded */
856 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
&&
857 (base_url
= get_base_url( package
->db
)))
859 WCHAR temppath
[MAX_PATH
], *p
, *url
;
861 free( cabinet_file
);
862 if (!(url
= realloc( base_url
, (wcslen( base_url
) + wcslen( mi
->cabinet
) + 1) * sizeof(WCHAR
) )))
865 return ERROR_OUTOFMEMORY
;
867 lstrcatW( url
, mi
->cabinet
);
868 if ((rc
= msi_download_file( url
, temppath
)) != ERROR_SUCCESS
)
870 ERR("failed to download %s (%u)\n", debugstr_w(url
), rc
);
874 if ((p
= wcsrchr( temppath
, '\\' ))) *p
= 0;
875 lstrcpyW( mi
->sourcedir
, temppath
);
876 PathAddBackslashW( mi
->sourcedir
);
878 mi
->cabinet
= wcsdup( p
+ 1 );
881 return ERROR_SUCCESS
;
884 /* check volume matches, change media if not */
885 if (mi
->volume_label
)
887 /* assume first volume is in the drive */
888 if (mi
->last_volume
&& wcsicmp( mi
->last_volume
, mi
->volume_label
))
890 WCHAR
*source
= msi_dup_property( package
->db
, L
"SourceDir" );
891 BOOL match
= source_matches_volume( mi
, source
);
894 if (!match
&& (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
))
896 if ((rc
= change_media( package
, mi
)) != ERROR_SUCCESS
)
898 free( cabinet_file
);
904 free(mi
->last_volume
);
905 mi
->last_volume
= wcsdup(mi
->volume_label
);
909 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
911 if ((rc
= find_published_source( package
, mi
)) != ERROR_SUCCESS
)
913 ERR("cabinet not found: %s\n", debugstr_w(cabinet_file
));
914 free( cabinet_file
);
915 return ERROR_INSTALL_FAILURE
;
919 free( cabinet_file
);
920 return ERROR_SUCCESS
;
923 UINT
msi_add_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
, IStorage
*storage
, const WCHAR
*name
)
925 MSICABINETSTREAM
*cab
, *item
;
927 TRACE("%p, %u, %p, %s\n", package
, disk_id
, storage
, debugstr_w(name
));
929 LIST_FOR_EACH_ENTRY( item
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
931 if (item
->disk_id
== disk_id
)
933 TRACE("duplicate disk id %u\n", disk_id
);
934 return ERROR_FUNCTION_FAILED
;
937 if (!(cab
= malloc( sizeof(*cab
) ))) return ERROR_OUTOFMEMORY
;
938 if (!(cab
->stream
= malloc( (wcslen( name
) + 1) * sizeof(WCHAR
) )))
941 return ERROR_OUTOFMEMORY
;
943 lstrcpyW( cab
->stream
, name
);
944 cab
->disk_id
= disk_id
;
945 cab
->storage
= storage
;
946 IStorage_AddRef( storage
);
947 list_add_tail( &package
->cabinet_streams
, &cab
->entry
);
949 return ERROR_SUCCESS
;