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 hr
= IStorage_OpenStream( cab
->storage
, encoded
, NULL
, STGM_READ
|STGM_SHARE_EXCLUSIVE
, 0, &stream
);
233 WARN("failed to open stream 0x%08x\n", hr
);
238 return (INT_PTR
)stream
;
241 static UINT CDECL
cabinet_read_stream( INT_PTR hf
, void *pv
, UINT cb
)
243 IStream
*stm
= (IStream
*)hf
;
247 hr
= IStream_Read( stm
, pv
, cb
, &read
);
248 if (hr
== S_OK
|| hr
== S_FALSE
)
254 static int CDECL
cabinet_close_stream( INT_PTR hf
)
256 IStream
*stm
= (IStream
*)hf
;
257 IStream_Release( stm
);
261 static LONG CDECL
cabinet_seek_stream( INT_PTR hf
, LONG dist
, int seektype
)
263 IStream
*stm
= (IStream
*)hf
;
265 ULARGE_INTEGER newpos
;
268 move
.QuadPart
= dist
;
269 hr
= IStream_Seek( stm
, move
, seektype
, &newpos
);
272 if (newpos
.QuadPart
<= MAXLONG
) return newpos
.QuadPart
;
278 static UINT CDECL
msi_media_get_disk_info(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
282 static const WCHAR query
[] = {
283 'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
284 '`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
285 '`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
287 row
= MSI_QueryGetRecord(package
->db
, query
, mi
->disk_id
);
290 TRACE("Unable to query row\n");
291 return ERROR_FUNCTION_FAILED
;
294 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
295 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
296 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
298 msiobj_release(&row
->hdr
);
299 return ERROR_SUCCESS
;
302 static INT_PTR
cabinet_partial_file(FDINOTIFICATIONTYPE fdint
,
303 PFDINOTIFICATION pfdin
)
305 MSICABDATA
*data
= pfdin
->pv
;
306 data
->mi
->is_continuous
= FALSE
;
310 static WCHAR
*get_cabinet_filename(MSIMEDIAINFO
*mi
)
315 len
= strlenW(mi
->sourcedir
) + strlenW(mi
->cabinet
) + 1;
316 if (!(ret
= msi_alloc(len
* sizeof(WCHAR
)))) return NULL
;
317 strcpyW(ret
, mi
->sourcedir
);
318 strcatW(ret
, mi
->cabinet
);
322 static INT_PTR
cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint
,
323 PFDINOTIFICATION pfdin
)
325 MSICABDATA
*data
= pfdin
->pv
;
326 MSIMEDIAINFO
*mi
= data
->mi
;
327 LPWSTR cabinet_file
= NULL
, cab
= strdupAtoW(pfdin
->psz1
);
331 msi_free(mi
->disk_prompt
);
332 msi_free(mi
->cabinet
);
333 msi_free(mi
->volume_label
);
334 mi
->disk_prompt
= NULL
;
336 mi
->volume_label
= NULL
;
339 mi
->is_continuous
= TRUE
;
341 rc
= msi_media_get_disk_info(data
->package
, mi
);
342 if (rc
!= ERROR_SUCCESS
)
344 ERR("Failed to get next cabinet information: %d\n", rc
);
348 if (strcmpiW( mi
->cabinet
, cab
))
353 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
));
355 /* Use cabinet name from the media table */
356 next_cab
= strdupWtoA(mi
->cabinet
);
357 /* Modify path to cabinet file with full filename (psz3 points to a 256 bytes buffer that can be modified contrary to psz1 and psz2) */
358 length
= strlen(pfdin
->psz3
) + 1 + strlen(next_cab
) + 1;
361 WARN("Cannot update next cabinet filename with a string size %u > 256\n", length
);
367 strcat(pfdin
->psz3
, "\\");
368 strcat(pfdin
->psz3
, next_cab
);
370 /* Path psz3 and cabinet psz1 are concatenated by FDI so just reset psz1 */
375 if (!(cabinet_file
= get_cabinet_filename(mi
)))
378 TRACE("Searching for %s\n", debugstr_w(cabinet_file
));
381 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
383 if (msi_change_media(data
->package
, mi
) != ERROR_SUCCESS
)
389 msi_free(cabinet_file
);
393 static INT_PTR
cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint
,
394 PFDINOTIFICATION pfdin
)
396 MSICABDATA
*data
= pfdin
->pv
;
397 MSIMEDIAINFO
*mi
= data
->mi
;
400 msi_free( mi
->disk_prompt
);
401 msi_free( mi
->cabinet
);
402 msi_free( mi
->volume_label
);
403 mi
->disk_prompt
= NULL
;
405 mi
->volume_label
= NULL
;
408 mi
->is_continuous
= TRUE
;
410 rc
= msi_media_get_disk_info( data
->package
, mi
);
411 if (rc
!= ERROR_SUCCESS
)
413 ERR("Failed to get next cabinet information: %u\n", rc
);
416 package_disk
.id
= mi
->disk_id
;
418 TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
422 static INT_PTR
cabinet_copy_file(FDINOTIFICATIONTYPE fdint
,
423 PFDINOTIFICATION pfdin
)
425 MSICABDATA
*data
= pfdin
->pv
;
430 data
->curfile
= strdupAtoW(pfdin
->psz1
);
431 if (!data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_BEGINEXTRACT
, &path
,
434 /* We're not extracting this file, so free the filename. */
435 msi_free(data
->curfile
);
436 data
->curfile
= NULL
;
440 TRACE("extracting %s -> %s\n", debugstr_w(data
->curfile
), debugstr_w(path
));
442 attrs
= attrs
& (FILE_ATTRIBUTE_READONLY
|FILE_ATTRIBUTE_HIDDEN
|FILE_ATTRIBUTE_SYSTEM
);
443 if (!attrs
) attrs
= FILE_ATTRIBUTE_NORMAL
;
445 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0,
446 NULL
, CREATE_ALWAYS
, attrs
, NULL
);
447 if (handle
== INVALID_HANDLE_VALUE
)
449 DWORD err
= GetLastError();
450 DWORD attrs2
= GetFileAttributesW(path
);
452 if (attrs2
== INVALID_FILE_ATTRIBUTES
)
454 ERR("failed to create %s (error %d)\n", debugstr_w(path
), err
);
457 else if (err
== ERROR_ACCESS_DENIED
&& (attrs2
& FILE_ATTRIBUTE_READONLY
))
459 TRACE("removing read-only attribute on %s\n", debugstr_w(path
));
460 SetFileAttributesW( path
, attrs2
& ~FILE_ATTRIBUTE_READONLY
);
461 handle
= CreateFileW(path
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs2
, NULL
);
463 if (handle
!= INVALID_HANDLE_VALUE
) goto done
;
464 err
= GetLastError();
466 if (err
== ERROR_SHARING_VIOLATION
|| err
== ERROR_USER_MAPPED_FILE
)
468 WCHAR
*tmpfileW
, *tmppathW
, *p
;
471 TRACE("file in use, scheduling rename operation\n");
473 if (!(tmppathW
= strdupW( path
))) return ERROR_OUTOFMEMORY
;
474 if ((p
= strrchrW(tmppathW
, '\\'))) *p
= 0;
475 len
= strlenW( tmppathW
) + 16;
476 if (!(tmpfileW
= msi_alloc(len
* sizeof(WCHAR
))))
478 msi_free( tmppathW
);
479 return ERROR_OUTOFMEMORY
;
481 if (!GetTempFileNameW(tmppathW
, szMsi
, 0, tmpfileW
)) tmpfileW
[0] = 0;
482 msi_free( tmppathW
);
484 handle
= CreateFileW(tmpfileW
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, attrs
, NULL
);
486 if (handle
!= INVALID_HANDLE_VALUE
&&
487 MoveFileExW(path
, NULL
, MOVEFILE_DELAY_UNTIL_REBOOT
) &&
488 MoveFileExW(tmpfileW
, path
, MOVEFILE_DELAY_UNTIL_REBOOT
))
490 data
->package
->need_reboot_at_end
= 1;
494 WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path
), GetLastError());
495 DeleteFileW( tmpfileW
);
500 WARN("failed to create %s (error %d)\n", debugstr_w(path
), err
);
506 return (INT_PTR
)handle
;
509 static INT_PTR
cabinet_close_file_info(FDINOTIFICATIONTYPE fdint
,
510 PFDINOTIFICATION pfdin
)
512 MSICABDATA
*data
= pfdin
->pv
;
515 HANDLE handle
= (HANDLE
)pfdin
->hf
;
517 data
->mi
->is_continuous
= FALSE
;
519 if (!DosDateTimeToFileTime(pfdin
->date
, pfdin
->time
, &ft
))
521 if (!LocalFileTimeToFileTime(&ft
, &ftLocal
))
523 if (!SetFileTime(handle
, &ftLocal
, 0, &ftLocal
))
528 data
->cb(data
->package
, data
->curfile
, MSICABEXTRACT_FILEEXTRACTED
, NULL
, NULL
,
531 msi_free(data
->curfile
);
532 data
->curfile
= NULL
;
537 static INT_PTR CDECL
cabinet_notify(FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
541 case fdintPARTIAL_FILE
:
542 return cabinet_partial_file(fdint
, pfdin
);
544 case fdintNEXT_CABINET
:
545 return cabinet_next_cabinet(fdint
, pfdin
);
548 return cabinet_copy_file(fdint
, pfdin
);
550 case fdintCLOSE_FILE_INFO
:
551 return cabinet_close_file_info(fdint
, pfdin
);
558 static INT_PTR CDECL
cabinet_notify_stream( FDINOTIFICATIONTYPE fdint
, PFDINOTIFICATION pfdin
)
562 case fdintPARTIAL_FILE
:
563 return cabinet_partial_file( fdint
, pfdin
);
565 case fdintNEXT_CABINET
:
566 return cabinet_next_cabinet_stream( fdint
, pfdin
);
569 return cabinet_copy_file( fdint
, pfdin
);
571 case fdintCLOSE_FILE_INFO
:
572 return cabinet_close_file_info( fdint
, pfdin
);
574 case fdintCABINET_INFO
:
578 ERR("Unexpected notification %d\n", fdint
);
583 static BOOL
extract_cabinet( MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
585 LPSTR cabinet
, cab_path
= NULL
;
590 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
592 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open
, cabinet_read
,
593 cabinet_write
, cabinet_close
, cabinet_seek
, 0, &erf
);
596 ERR("FDICreate failed\n");
600 cabinet
= strdupWtoA( mi
->cabinet
);
604 cab_path
= strdupWtoA( mi
->sourcedir
);
608 ret
= FDICopy( hfdi
, cabinet
, cab_path
, 0, cabinet_notify
, NULL
, data
);
610 ERR("FDICopy failed\n");
615 msi_free( cab_path
);
618 mi
->is_extracted
= TRUE
;
623 static BOOL
extract_cabinet_stream( MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
, LPVOID data
)
625 static char filename
[] = {'<','S','T','R','E','A','M','>',0};
630 TRACE("extracting %s disk id %u\n", debugstr_w(mi
->cabinet
), mi
->disk_id
);
632 hfdi
= FDICreate( cabinet_alloc
, cabinet_free
, cabinet_open_stream
, cabinet_read_stream
,
633 cabinet_write
, cabinet_close_stream
, cabinet_seek_stream
, 0, &erf
);
636 ERR("FDICreate failed\n");
640 package_disk
.package
= package
;
641 package_disk
.id
= mi
->disk_id
;
643 ret
= FDICopy( hfdi
, filename
, NULL
, 0, cabinet_notify_stream
, NULL
, data
);
644 if (!ret
) ERR("FDICopy failed\n");
647 if (ret
) mi
->is_extracted
= TRUE
;
651 /***********************************************************************
654 * Extract files from a cabinet file or stream.
656 BOOL
msi_cabextract(MSIPACKAGE
* package
, MSIMEDIAINFO
*mi
, LPVOID data
)
658 if (mi
->cabinet
[0] == '#')
660 return extract_cabinet_stream( package
, mi
, data
);
662 return extract_cabinet( package
, mi
, data
);
665 void msi_free_media_info(MSIMEDIAINFO
*mi
)
667 msi_free(mi
->disk_prompt
);
668 msi_free(mi
->cabinet
);
669 msi_free(mi
->volume_label
);
673 static UINT
get_drive_type(const WCHAR
*path
)
675 WCHAR root
[MAX_PATH
+ 1];
678 PathStripToRootW(root
);
679 PathAddBackslashW(root
);
681 return GetDriveTypeW(root
);
684 UINT
msi_load_media_info(MSIPACKAGE
*package
, UINT Sequence
, MSIMEDIAINFO
*mi
)
686 static const WCHAR query
[] = {
687 'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','`','M','e','d','i','a','`',' ',
688 'W','H','E','R','E',' ','`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ',
689 '>','=',' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ','`','D','i','s','k','I','d','`',0};
691 LPWSTR source_dir
, source
;
694 if (Sequence
<= mi
->last_sequence
) /* already loaded */
695 return ERROR_SUCCESS
;
697 row
= MSI_QueryGetRecord(package
->db
, query
, Sequence
);
700 TRACE("Unable to query row\n");
701 return ERROR_FUNCTION_FAILED
;
704 mi
->is_extracted
= FALSE
;
705 mi
->disk_id
= MSI_RecordGetInteger(row
, 1);
706 mi
->last_sequence
= MSI_RecordGetInteger(row
, 2);
707 msi_free(mi
->disk_prompt
);
708 mi
->disk_prompt
= strdupW(MSI_RecordGetString(row
, 3));
709 msi_free(mi
->cabinet
);
710 mi
->cabinet
= strdupW(MSI_RecordGetString(row
, 4));
711 msi_free(mi
->volume_label
);
712 mi
->volume_label
= strdupW(MSI_RecordGetString(row
, 5));
713 msiobj_release(&row
->hdr
);
715 msi_set_sourcedir_props(package
, FALSE
);
716 source_dir
= msi_dup_property(package
->db
, szSourceDir
);
717 lstrcpyW(mi
->sourcedir
, source_dir
);
718 PathAddBackslashW(mi
->sourcedir
);
719 mi
->type
= get_drive_type(source_dir
);
721 options
= MSICODE_PRODUCT
;
722 if (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
)
725 options
|= MSISOURCETYPE_MEDIA
;
727 else if (package
->BaseURL
&& UrlIsW(package
->BaseURL
, URLIS_URL
))
729 source
= package
->BaseURL
;
730 options
|= MSISOURCETYPE_URL
;
734 source
= mi
->sourcedir
;
735 options
|= MSISOURCETYPE_NETWORK
;
738 msi_package_add_media_disk(package
, package
->Context
,
739 MSICODE_PRODUCT
, mi
->disk_id
,
740 mi
->volume_label
, mi
->disk_prompt
);
742 msi_package_add_info(package
, package
->Context
,
743 options
, INSTALLPROPERTY_LASTUSEDSOURCEW
, source
);
745 msi_free(source_dir
);
746 TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence
, debugstr_w(mi
->cabinet
), mi
->disk_id
);
747 return ERROR_SUCCESS
;
750 /* FIXME: search URL sources as well */
751 static UINT
find_published_source(MSIPACKAGE
*package
, MSIMEDIAINFO
*mi
)
753 WCHAR source
[MAX_PATH
];
754 WCHAR volume
[MAX_PATH
];
755 WCHAR prompt
[MAX_PATH
];
756 DWORD volumesz
, promptsz
;
757 DWORD index
, size
, id
;
762 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
763 package
->Context
, MSICODE_PRODUCT
,
764 INSTALLPROPERTY_LASTUSEDTYPEW
, last_type
, &size
);
765 if (r
!= ERROR_SUCCESS
)
769 r
= MsiSourceListGetInfoW(package
->ProductCode
, NULL
,
770 package
->Context
, MSICODE_PRODUCT
,
771 INSTALLPROPERTY_LASTUSEDSOURCEW
, source
, &size
);
772 if (r
!= ERROR_SUCCESS
)
775 if (last_type
[0] == 'n')
777 WCHAR cabinet_file
[MAX_PATH
];
778 BOOL check_all
= FALSE
;
784 while (MsiSourceListEnumSourcesW(package
->ProductCode
, NULL
,
786 MSISOURCETYPE_NETWORK
, index
++,
787 volume
, &volumesz
) == ERROR_SUCCESS
)
789 if (check_all
|| !strncmpiW(source
, volume
, strlenW(source
)))
791 lstrcpyW(cabinet_file
, volume
);
792 PathAddBackslashW(cabinet_file
);
793 lstrcatW(cabinet_file
, mi
->cabinet
);
795 if (GetFileAttributesW(cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
803 lstrcpyW(mi
->sourcedir
, volume
);
804 PathAddBackslashW(mi
->sourcedir
);
805 TRACE("Found network source %s\n", debugstr_w(mi
->sourcedir
));
806 return ERROR_SUCCESS
;
820 while (MsiSourceListEnumMediaDisksW(package
->ProductCode
, NULL
,
822 MSICODE_PRODUCT
, index
++, &id
,
823 volume
, &volumesz
, prompt
, &promptsz
) == ERROR_SUCCESS
)
826 msi_free( mi
->volume_label
);
827 if (!(mi
->volume_label
= msi_alloc( ++volumesz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
828 strcpyW( mi
->volume_label
, volume
);
830 msi_free( mi
->disk_prompt
);
831 if (!(mi
->disk_prompt
= msi_alloc( ++promptsz
* sizeof(WCHAR
) ))) return ERROR_OUTOFMEMORY
;
832 strcpyW( mi
->disk_prompt
, prompt
);
834 if (source_matches_volume(mi
, source
))
836 /* FIXME: what about SourceDir */
837 lstrcpyW(mi
->sourcedir
, source
);
838 PathAddBackslashW(mi
->sourcedir
);
839 TRACE("Found disk source %s\n", debugstr_w(mi
->sourcedir
));
840 return ERROR_SUCCESS
;
844 return ERROR_FUNCTION_FAILED
;
847 UINT
ready_media( MSIPACKAGE
*package
, BOOL compressed
, MSIMEDIAINFO
*mi
)
850 WCHAR
*cabinet_file
= NULL
;
852 /* media info for continuous cabinet is already loaded */
853 if (mi
->is_continuous
) return ERROR_SUCCESS
;
857 /* cabinet is internal, no checks needed */
858 if (mi
->cabinet
[0] == '#') return ERROR_SUCCESS
;
860 if (!(cabinet_file
= get_cabinet_filename( mi
))) return ERROR_OUTOFMEMORY
;
862 /* package should be downloaded */
863 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
&&
864 package
->BaseURL
&& UrlIsW( package
->BaseURL
, URLIS_URL
))
866 WCHAR temppath
[MAX_PATH
], *p
;
868 if ((rc
= msi_download_file( cabinet_file
, temppath
)) != ERROR_SUCCESS
)
870 ERR("failed to download %s (%u)\n", debugstr_w(cabinet_file
), rc
);
871 msi_free( cabinet_file
);
874 if ((p
= strrchrW( temppath
, '\\' ))) *p
= 0;
875 strcpyW( mi
->sourcedir
, temppath
);
876 PathAddBackslashW( mi
->sourcedir
);
877 msi_free( mi
->cabinet
);
878 mi
->cabinet
= strdupW( p
+ 1 );
879 msi_free( cabinet_file
);
880 return ERROR_SUCCESS
;
883 /* check volume matches, change media if not */
884 if (mi
->volume_label
&& mi
->disk_id
> 1)
886 WCHAR
*source
= msi_dup_property( package
->db
, szSourceDir
);
887 BOOL match
= source_matches_volume( mi
, source
);
890 if (!match
&& (mi
->type
== DRIVE_CDROM
|| mi
->type
== DRIVE_REMOVABLE
))
892 if ((rc
= msi_change_media( package
, mi
)) != ERROR_SUCCESS
)
894 msi_free( cabinet_file
);
901 if (compressed
&& GetFileAttributesW( cabinet_file
) == INVALID_FILE_ATTRIBUTES
)
903 if ((rc
= find_published_source( package
, mi
)) != ERROR_SUCCESS
)
905 ERR("cabinet not found: %s\n", debugstr_w(cabinet_file
));
906 msi_free( cabinet_file
);
907 return ERROR_INSTALL_FAILURE
;
911 msi_free( cabinet_file
);
912 return ERROR_SUCCESS
;
915 UINT
msi_add_cabinet_stream( MSIPACKAGE
*package
, UINT disk_id
, IStorage
*storage
, const WCHAR
*name
)
917 MSICABINETSTREAM
*cab
, *item
;
919 TRACE("%p, %u, %p, %s\n", package
, disk_id
, storage
, debugstr_w(name
));
921 LIST_FOR_EACH_ENTRY( item
, &package
->cabinet_streams
, MSICABINETSTREAM
, entry
)
923 if (item
->disk_id
== disk_id
)
925 TRACE("duplicate disk id %u\n", disk_id
);
926 return ERROR_FUNCTION_FAILED
;
929 if (!(cab
= msi_alloc( sizeof(*cab
) ))) return ERROR_OUTOFMEMORY
;
930 if (!(cab
->stream
= msi_alloc( (strlenW( name
) + 1) * sizeof(WCHAR
) )))
933 return ERROR_OUTOFMEMORY
;
935 strcpyW( cab
->stream
, name
);
936 cab
->disk_id
= disk_id
;
937 cab
->storage
= storage
;
938 IStorage_AddRef( storage
);
939 list_add_tail( &package
->cabinet_streams
, &cab
->entry
);
941 return ERROR_SUCCESS
;