2008-08-19 05:59:44 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2008 James Hawkins
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2010-03-23 11:46:54 +01:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2008-08-19 05:59:44 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "fdi.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
2010-03-23 11:46:54 +01:00
|
|
|
#include "objidl.h"
|
2017-07-23 22:50:53 +02:00
|
|
|
#include "resource.h"
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2008-12-11 22:27:54 +01:00
|
|
|
/* from msvcrt/fcntl.h */
|
|
|
|
#define _O_RDONLY 0
|
|
|
|
#define _O_WRONLY 1
|
|
|
|
#define _O_RDWR 2
|
|
|
|
#define _O_ACCMODE (_O_RDONLY|_O_WRONLY|_O_RDWR)
|
|
|
|
#define _O_APPEND 0x0008
|
|
|
|
#define _O_RANDOM 0x0010
|
|
|
|
#define _O_SEQUENTIAL 0x0020
|
|
|
|
#define _O_TEMPORARY 0x0040
|
|
|
|
#define _O_NOINHERIT 0x0080
|
|
|
|
#define _O_CREAT 0x0100
|
|
|
|
#define _O_TRUNC 0x0200
|
|
|
|
#define _O_EXCL 0x0400
|
|
|
|
#define _O_SHORT_LIVED 0x1000
|
|
|
|
#define _O_TEXT 0x4000
|
|
|
|
#define _O_BINARY 0x8000
|
|
|
|
|
2009-09-15 09:28:41 +02:00
|
|
|
static BOOL source_matches_volume(MSIMEDIAINFO *mi, LPCWSTR source_root)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2015-04-16 17:01:55 +02:00
|
|
|
WCHAR volume_name[MAX_PATH + 1], root[MAX_PATH + 1];
|
|
|
|
const WCHAR *p;
|
|
|
|
int len, len2;
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW(root, source_root);
|
2009-09-15 09:28:41 +02:00
|
|
|
PathStripToRootW(root);
|
|
|
|
PathAddBackslashW(root);
|
|
|
|
|
2012-01-10 16:55:23 +01:00
|
|
|
if (!GetVolumeInformationW(root, volume_name, MAX_PATH + 1, NULL, NULL, NULL, NULL, 0))
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2012-01-10 16:55:23 +01:00
|
|
|
WARN("failed to get volume information for %s (%u)\n", debugstr_w(root), GetLastError());
|
2008-08-19 05:59:44 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-04-16 17:01:55 +02:00
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
len = lstrlenW( volume_name );
|
|
|
|
len2 = lstrlenW( mi->volume_label );
|
2015-04-16 17:01:55 +02:00
|
|
|
if (len2 > len) return FALSE;
|
|
|
|
p = volume_name + len - len2;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
return !wcsicmp( mi->volume_label, p );
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_change_media(MSIPACKAGE *package, MSIMEDIAINFO *mi)
|
|
|
|
{
|
2017-07-23 22:50:53 +02:00
|
|
|
MSIRECORD *record;
|
2008-08-19 05:59:44 +02:00
|
|
|
LPWSTR source_dir;
|
2017-07-23 22:50:53 +02:00
|
|
|
UINT r = IDRETRY;
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
source_dir = msi_dup_property(package->db, L"SourceDir");
|
2017-07-23 22:50:53 +02:00
|
|
|
record = MSI_CreateRecord(2);
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2017-07-23 22:50:53 +02:00
|
|
|
while (r == IDRETRY && !source_matches_volume(mi, source_dir))
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2017-07-23 22:50:53 +02:00
|
|
|
MSI_RecordSetStringW(record, 0, NULL);
|
|
|
|
MSI_RecordSetInteger(record, 1, MSIERR_CABNOTFOUND);
|
|
|
|
MSI_RecordSetStringW(record, 2, mi->disk_prompt);
|
|
|
|
r = MSI_ProcessMessage(package, INSTALLMESSAGE_ERROR | MB_RETRYCANCEL, record);
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
|
2017-07-23 22:50:53 +02:00
|
|
|
msiobj_release(&record->hdr);
|
2008-08-19 05:59:44 +02:00
|
|
|
msi_free(source_dir);
|
|
|
|
|
2019-01-02 19:39:13 +01:00
|
|
|
return r == IDRETRY ? ERROR_SUCCESS : ERROR_INSTALL_SOURCE_ABSENT;
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
|
2011-04-18 11:19:31 +02:00
|
|
|
static MSICABINETSTREAM *msi_get_cabinet_stream( MSIPACKAGE *package, UINT disk_id )
|
|
|
|
{
|
|
|
|
MSICABINETSTREAM *cab;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( cab, &package->cabinet_streams, MSICABINETSTREAM, entry )
|
|
|
|
{
|
|
|
|
if (cab->disk_id == disk_id) return cab;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-06 13:56:09 +01:00
|
|
|
static void * CDECL cabinet_alloc(ULONG cb)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
return msi_alloc(cb);
|
|
|
|
}
|
|
|
|
|
2008-12-21 12:48:20 +01:00
|
|
|
static void CDECL cabinet_free(void *pv)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
msi_free(pv);
|
|
|
|
}
|
|
|
|
|
2008-12-21 12:48:20 +01:00
|
|
|
static INT_PTR CDECL cabinet_open(char *pszFile, int oflag, int pmode)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
DWORD dwAccess = 0;
|
|
|
|
DWORD dwShareMode = 0;
|
|
|
|
DWORD dwCreateDisposition = OPEN_EXISTING;
|
|
|
|
|
|
|
|
switch (oflag & _O_ACCMODE)
|
|
|
|
{
|
|
|
|
case _O_RDONLY:
|
|
|
|
dwAccess = GENERIC_READ;
|
|
|
|
dwShareMode = FILE_SHARE_READ | FILE_SHARE_DELETE;
|
|
|
|
break;
|
|
|
|
case _O_WRONLY:
|
|
|
|
dwAccess = GENERIC_WRITE;
|
|
|
|
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
|
|
|
break;
|
|
|
|
case _O_RDWR:
|
|
|
|
dwAccess = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((oflag & (_O_CREAT | _O_EXCL)) == (_O_CREAT | _O_EXCL))
|
|
|
|
dwCreateDisposition = CREATE_NEW;
|
|
|
|
else if (oflag & _O_CREAT)
|
|
|
|
dwCreateDisposition = CREATE_ALWAYS;
|
|
|
|
|
2013-10-15 18:08:38 +02:00
|
|
|
return (INT_PTR)CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
|
|
|
|
dwCreateDisposition, 0, NULL);
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
|
2008-12-21 12:48:20 +01:00
|
|
|
static UINT CDECL cabinet_read(INT_PTR hf, void *pv, UINT cb)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE)hf;
|
|
|
|
DWORD read;
|
|
|
|
|
|
|
|
if (ReadFile(handle, pv, cb, &read, NULL))
|
|
|
|
return read;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-21 12:48:20 +01:00
|
|
|
static UINT CDECL cabinet_write(INT_PTR hf, void *pv, UINT cb)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE)hf;
|
|
|
|
DWORD written;
|
|
|
|
|
|
|
|
if (WriteFile(handle, pv, cb, &written, NULL))
|
|
|
|
return written;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-21 12:48:20 +01:00
|
|
|
static int CDECL cabinet_close(INT_PTR hf)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE)hf;
|
|
|
|
return CloseHandle(handle) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2009-01-13 23:31:50 +01:00
|
|
|
static LONG CDECL cabinet_seek(INT_PTR hf, LONG dist, int seektype)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
HANDLE handle = (HANDLE)hf;
|
|
|
|
/* flags are compatible and so are passed straight through */
|
|
|
|
return SetFilePointer(handle, dist, NULL, seektype);
|
|
|
|
}
|
|
|
|
|
2011-04-14 14:42:48 +02:00
|
|
|
struct package_disk
|
2010-03-23 11:46:54 +01:00
|
|
|
{
|
2011-04-14 14:42:48 +02:00
|
|
|
MSIPACKAGE *package;
|
|
|
|
UINT id;
|
2010-03-23 11:46:54 +01:00
|
|
|
};
|
|
|
|
|
2011-04-14 14:42:48 +02:00
|
|
|
static struct package_disk package_disk;
|
2010-03-23 11:46:54 +01:00
|
|
|
|
|
|
|
static INT_PTR CDECL cabinet_open_stream( char *pszFile, int oflag, int pmode )
|
|
|
|
{
|
2011-04-14 14:42:48 +02:00
|
|
|
MSICABINETSTREAM *cab;
|
|
|
|
IStream *stream;
|
2010-03-23 11:46:54 +01:00
|
|
|
|
2015-06-22 12:12:48 +02:00
|
|
|
if (!(cab = msi_get_cabinet_stream( package_disk.package, package_disk.id )))
|
2010-03-23 11:46:54 +01:00
|
|
|
{
|
2011-04-14 14:42:48 +02:00
|
|
|
WARN("failed to get cabinet stream\n");
|
2013-10-15 18:08:38 +02:00
|
|
|
return -1;
|
2010-03-23 11:46:54 +01:00
|
|
|
}
|
2015-06-22 12:12:48 +02:00
|
|
|
if (cab->storage == package_disk.package->db->storage)
|
2011-04-14 14:42:48 +02:00
|
|
|
{
|
2015-06-22 12:12:48 +02:00
|
|
|
UINT r = msi_get_stream( package_disk.package->db, cab->stream + 1, &stream );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WARN("failed to get stream %u\n", r);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-04-14 14:42:48 +02:00
|
|
|
}
|
2015-06-22 12:12:48 +02:00
|
|
|
else /* patch storage */
|
2011-04-14 14:42:48 +02:00
|
|
|
{
|
2015-06-22 12:12:48 +02:00
|
|
|
HRESULT hr;
|
|
|
|
WCHAR *encoded;
|
|
|
|
|
|
|
|
if (!(encoded = encode_streamname( FALSE, cab->stream + 1 )))
|
|
|
|
{
|
|
|
|
WARN("failed to encode stream name\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
hr = IStorage_OpenStream( cab->storage, encoded, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, &stream );
|
2015-02-13 13:37:49 +01:00
|
|
|
msi_free( encoded );
|
2015-06-22 12:12:48 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("failed to open stream 0x%08x\n", hr);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-04-14 14:42:48 +02:00
|
|
|
}
|
|
|
|
return (INT_PTR)stream;
|
2010-03-23 11:46:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT CDECL cabinet_read_stream( INT_PTR hf, void *pv, UINT cb )
|
|
|
|
{
|
|
|
|
IStream *stm = (IStream *)hf;
|
|
|
|
DWORD read;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IStream_Read( stm, pv, cb, &read );
|
|
|
|
if (hr == S_OK || hr == S_FALSE)
|
|
|
|
return read;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL cabinet_close_stream( INT_PTR hf )
|
|
|
|
{
|
|
|
|
IStream *stm = (IStream *)hf;
|
|
|
|
IStream_Release( stm );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG CDECL cabinet_seek_stream( INT_PTR hf, LONG dist, int seektype )
|
|
|
|
{
|
|
|
|
IStream *stm = (IStream *)hf;
|
|
|
|
LARGE_INTEGER move;
|
|
|
|
ULARGE_INTEGER newpos;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
move.QuadPart = dist;
|
|
|
|
hr = IStream_Seek( stm, move, seektype, &newpos );
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
if (newpos.QuadPart <= MAXLONG) return newpos.QuadPart;
|
|
|
|
ERR("Too big!\n");
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-08-31 15:14:09 +02:00
|
|
|
static UINT msi_media_get_disk_info(MSIPACKAGE *package, MSIMEDIAINFO *mi)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *row;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
row = MSI_QueryGetRecord(package->db, L"SELECT * FROM `Media` WHERE `DiskId` = %d", mi->disk_id);
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!row)
|
|
|
|
{
|
|
|
|
TRACE("Unable to query row\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
|
|
|
|
mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
|
|
|
|
mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
|
|
|
|
|
|
|
|
msiobj_release(&row->hdr);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR cabinet_partial_file(FDINOTIFICATIONTYPE fdint,
|
|
|
|
PFDINOTIFICATION pfdin)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MSICABDATA *data = pfdin->pv;
|
2008-08-19 05:59:44 +02:00
|
|
|
data->mi->is_continuous = FALSE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-26 12:12:15 +01:00
|
|
|
static WCHAR *get_cabinet_filename(MSIMEDIAINFO *mi)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
WCHAR *ret;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
len = lstrlenW(mi->sourcedir) + lstrlenW(mi->cabinet) + 1;
|
2010-03-26 12:12:15 +01:00
|
|
|
if (!(ret = msi_alloc(len * sizeof(WCHAR)))) return NULL;
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW(ret, mi->sourcedir);
|
|
|
|
lstrcatW(ret, mi->cabinet);
|
2010-03-26 12:12:15 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-08-19 05:59:44 +02:00
|
|
|
static INT_PTR cabinet_next_cabinet(FDINOTIFICATIONTYPE fdint,
|
|
|
|
PFDINOTIFICATION pfdin)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MSICABDATA *data = pfdin->pv;
|
2008-08-19 05:59:44 +02:00
|
|
|
MSIMEDIAINFO *mi = data->mi;
|
2010-03-26 12:12:15 +01:00
|
|
|
LPWSTR cabinet_file = NULL, cab = strdupAtoW(pfdin->psz1);
|
2008-08-19 05:59:44 +02:00
|
|
|
INT_PTR res = -1;
|
|
|
|
UINT rc;
|
|
|
|
|
|
|
|
msi_free(mi->disk_prompt);
|
|
|
|
msi_free(mi->cabinet);
|
|
|
|
msi_free(mi->volume_label);
|
|
|
|
mi->disk_prompt = NULL;
|
|
|
|
mi->cabinet = NULL;
|
|
|
|
mi->volume_label = NULL;
|
|
|
|
|
|
|
|
mi->disk_id++;
|
|
|
|
mi->is_continuous = TRUE;
|
|
|
|
|
|
|
|
rc = msi_media_get_disk_info(data->package, mi);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Failed to get next cabinet information: %d\n", rc);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
if (wcsicmp( mi->cabinet, cab ))
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2013-05-01 15:27:31 +02:00
|
|
|
char *next_cab;
|
|
|
|
ULONG length;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
/* Use cabinet name from the media table */
|
|
|
|
next_cab = strdupWtoA(mi->cabinet);
|
|
|
|
/* Modify path to cabinet file with full filename (psz3 points to a 256 bytes buffer that can be modified contrary to psz1 and psz2) */
|
|
|
|
length = strlen(pfdin->psz3) + 1 + strlen(next_cab) + 1;
|
|
|
|
if (length > 256)
|
|
|
|
{
|
|
|
|
WARN("Cannot update next cabinet filename with a string size %u > 256\n", length);
|
|
|
|
msi_free(next_cab);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcat(pfdin->psz3, "\\");
|
|
|
|
strcat(pfdin->psz3, next_cab);
|
|
|
|
}
|
|
|
|
/* Path psz3 and cabinet psz1 are concatenated by FDI so just reset psz1 */
|
|
|
|
*pfdin->psz1 = 0;
|
|
|
|
msi_free(next_cab);
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
|
2010-03-26 12:12:15 +01:00
|
|
|
if (!(cabinet_file = get_cabinet_filename(mi)))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
TRACE("Searching for %s\n", debugstr_w(cabinet_file));
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
res = 0;
|
2010-03-26 12:12:15 +01:00
|
|
|
if (GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
if (msi_change_media(data->package, mi) != ERROR_SUCCESS)
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(cab);
|
2010-03-26 12:12:15 +01:00
|
|
|
msi_free(cabinet_file);
|
2008-08-19 05:59:44 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-09-20 11:20:19 +02:00
|
|
|
static INT_PTR cabinet_next_cabinet_stream( FDINOTIFICATIONTYPE fdint,
|
|
|
|
PFDINOTIFICATION pfdin )
|
|
|
|
{
|
|
|
|
MSICABDATA *data = pfdin->pv;
|
|
|
|
MSIMEDIAINFO *mi = data->mi;
|
|
|
|
UINT rc;
|
|
|
|
|
|
|
|
msi_free( mi->disk_prompt );
|
|
|
|
msi_free( mi->cabinet );
|
|
|
|
msi_free( mi->volume_label );
|
|
|
|
mi->disk_prompt = NULL;
|
|
|
|
mi->cabinet = NULL;
|
|
|
|
mi->volume_label = NULL;
|
|
|
|
|
|
|
|
mi->disk_id++;
|
|
|
|
mi->is_continuous = TRUE;
|
|
|
|
|
|
|
|
rc = msi_media_get_disk_info( data->package, mi );
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Failed to get next cabinet information: %u\n", rc);
|
|
|
|
return -1;
|
|
|
|
}
|
2011-04-14 14:42:48 +02:00
|
|
|
package_disk.id = mi->disk_id;
|
2010-09-20 11:20:19 +02:00
|
|
|
|
2011-04-14 14:42:48 +02:00
|
|
|
TRACE("next cabinet is %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
|
2010-09-20 11:20:19 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-19 05:59:44 +02:00
|
|
|
static INT_PTR cabinet_copy_file(FDINOTIFICATIONTYPE fdint,
|
|
|
|
PFDINOTIFICATION pfdin)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MSICABDATA *data = pfdin->pv;
|
2008-08-19 05:59:44 +02:00
|
|
|
HANDLE handle = 0;
|
|
|
|
LPWSTR path = NULL;
|
|
|
|
DWORD attrs;
|
|
|
|
|
|
|
|
data->curfile = strdupAtoW(pfdin->psz1);
|
|
|
|
if (!data->cb(data->package, data->curfile, MSICABEXTRACT_BEGINEXTRACT, &path,
|
|
|
|
&attrs, data->user))
|
2009-12-18 05:00:45 +01:00
|
|
|
{
|
|
|
|
/* We're not extracting this file, so free the filename. */
|
|
|
|
msi_free(data->curfile);
|
|
|
|
data->curfile = NULL;
|
2008-08-19 05:59:44 +02:00
|
|
|
goto done;
|
2009-12-18 05:00:45 +01:00
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2012-03-16 16:13:30 +01:00
|
|
|
TRACE("extracting %s -> %s\n", debugstr_w(data->curfile), debugstr_w(path));
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
attrs = attrs & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
|
|
|
|
if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
|
|
|
|
|
2019-03-20 09:43:44 +01:00
|
|
|
handle = msi_create_file( data->package, path, GENERIC_READ | GENERIC_WRITE, 0, CREATE_ALWAYS, attrs );
|
2008-08-19 05:59:44 +02:00
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2009-09-09 12:19:28 +02:00
|
|
|
DWORD err = GetLastError();
|
2019-03-20 09:43:44 +01:00
|
|
|
DWORD attrs2 = msi_get_file_attributes( data->package, path );
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2009-10-01 11:53:20 +02:00
|
|
|
if (attrs2 == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
2009-09-09 12:19:28 +02:00
|
|
|
ERR("failed to create %s (error %d)\n", debugstr_w(path), err);
|
2009-10-01 11:53:20 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
else if (err == ERROR_ACCESS_DENIED && (attrs2 & FILE_ATTRIBUTE_READONLY))
|
2009-09-09 12:19:28 +02:00
|
|
|
{
|
|
|
|
TRACE("removing read-only attribute on %s\n", debugstr_w(path));
|
2019-03-20 09:43:44 +01:00
|
|
|
msi_set_file_attributes( data->package, path, attrs2 & ~FILE_ATTRIBUTE_READONLY );
|
|
|
|
handle = msi_create_file( data->package, path, GENERIC_READ | GENERIC_WRITE, 0, CREATE_ALWAYS, attrs );
|
2009-10-01 11:53:20 +02:00
|
|
|
|
|
|
|
if (handle != INVALID_HANDLE_VALUE) goto done;
|
|
|
|
err = GetLastError();
|
|
|
|
}
|
2009-10-30 14:10:27 +01:00
|
|
|
if (err == ERROR_SHARING_VIOLATION || err == ERROR_USER_MAPPED_FILE)
|
2009-10-01 11:53:20 +02:00
|
|
|
{
|
2011-06-09 15:56:57 +02:00
|
|
|
WCHAR *tmpfileW, *tmppathW, *p;
|
2009-10-01 11:53:20 +02:00
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
TRACE("file in use, scheduling rename operation\n");
|
|
|
|
|
2011-06-09 15:56:57 +02:00
|
|
|
if (!(tmppathW = strdupW( path ))) return ERROR_OUTOFMEMORY;
|
2019-06-13 08:42:35 +02:00
|
|
|
if ((p = wcsrchr(tmppathW, '\\'))) *p = 0;
|
|
|
|
len = lstrlenW( tmppathW ) + 16;
|
2011-06-09 15:56:57 +02:00
|
|
|
if (!(tmpfileW = msi_alloc(len * sizeof(WCHAR))))
|
|
|
|
{
|
|
|
|
msi_free( tmppathW );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!GetTempFileNameW(tmppathW, L"msi", 0, tmpfileW)) tmpfileW[0] = 0;
|
2011-06-09 15:56:57 +02:00
|
|
|
msi_free( tmppathW );
|
2009-10-01 11:53:20 +02:00
|
|
|
|
2011-06-09 15:56:57 +02:00
|
|
|
handle = CreateFileW(tmpfileW, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, attrs, NULL);
|
2009-10-01 11:53:20 +02:00
|
|
|
|
|
|
|
if (handle != INVALID_HANDLE_VALUE &&
|
2019-03-20 09:43:44 +01:00
|
|
|
msi_move_file( data->package, path, NULL, MOVEFILE_DELAY_UNTIL_REBOOT ) &&
|
|
|
|
msi_move_file( data->package, tmpfileW, path, MOVEFILE_DELAY_UNTIL_REBOOT ))
|
2009-10-01 11:53:20 +02:00
|
|
|
{
|
2012-04-02 13:15:16 +02:00
|
|
|
data->package->need_reboot_at_end = 1;
|
2009-10-01 11:53:20 +02:00
|
|
|
}
|
|
|
|
else
|
2011-06-09 15:56:57 +02:00
|
|
|
{
|
2009-10-01 11:53:20 +02:00
|
|
|
WARN("failed to schedule rename operation %s (error %d)\n", debugstr_w(path), GetLastError());
|
2011-06-09 15:56:57 +02:00
|
|
|
DeleteFileW( tmpfileW );
|
|
|
|
}
|
|
|
|
msi_free(tmpfileW);
|
2009-09-09 12:19:28 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
WARN("failed to create %s (error %d)\n", debugstr_w(path), err);
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(path);
|
|
|
|
|
|
|
|
return (INT_PTR)handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR cabinet_close_file_info(FDINOTIFICATIONTYPE fdint,
|
|
|
|
PFDINOTIFICATION pfdin)
|
|
|
|
{
|
2009-01-15 09:46:57 +01:00
|
|
|
MSICABDATA *data = pfdin->pv;
|
2008-08-19 05:59:44 +02:00
|
|
|
FILETIME ft;
|
|
|
|
FILETIME ftLocal;
|
|
|
|
HANDLE handle = (HANDLE)pfdin->hf;
|
|
|
|
|
|
|
|
data->mi->is_continuous = FALSE;
|
|
|
|
|
|
|
|
if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
|
2021-09-13 12:05:00 +02:00
|
|
|
{
|
|
|
|
CloseHandle(handle);
|
2008-08-19 05:59:44 +02:00
|
|
|
return -1;
|
2021-09-13 12:05:00 +02:00
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!LocalFileTimeToFileTime(&ft, &ftLocal))
|
2021-09-13 12:05:00 +02:00
|
|
|
{
|
|
|
|
CloseHandle(handle);
|
2008-08-19 05:59:44 +02:00
|
|
|
return -1;
|
2021-09-13 12:05:00 +02:00
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
|
2021-09-13 12:05:00 +02:00
|
|
|
{
|
|
|
|
CloseHandle(handle);
|
2008-08-19 05:59:44 +02:00
|
|
|
return -1;
|
2021-09-13 12:05:00 +02:00
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
CloseHandle(handle);
|
2021-09-13 12:05:00 +02:00
|
|
|
data->cb(data->package, data->curfile, MSICABEXTRACT_FILEEXTRACTED, NULL, NULL, data->user);
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
msi_free(data->curfile);
|
|
|
|
data->curfile = NULL;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-12-21 12:48:20 +01:00
|
|
|
static INT_PTR CDECL cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
switch (fdint)
|
|
|
|
{
|
|
|
|
case fdintPARTIAL_FILE:
|
|
|
|
return cabinet_partial_file(fdint, pfdin);
|
|
|
|
|
|
|
|
case fdintNEXT_CABINET:
|
|
|
|
return cabinet_next_cabinet(fdint, pfdin);
|
|
|
|
|
|
|
|
case fdintCOPY_FILE:
|
|
|
|
return cabinet_copy_file(fdint, pfdin);
|
|
|
|
|
|
|
|
case fdintCLOSE_FILE_INFO:
|
|
|
|
return cabinet_close_file_info(fdint, pfdin);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:46:54 +01:00
|
|
|
static INT_PTR CDECL cabinet_notify_stream( FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin )
|
|
|
|
{
|
|
|
|
switch (fdint)
|
|
|
|
{
|
2010-09-20 11:20:19 +02:00
|
|
|
case fdintPARTIAL_FILE:
|
|
|
|
return cabinet_partial_file( fdint, pfdin );
|
|
|
|
|
|
|
|
case fdintNEXT_CABINET:
|
|
|
|
return cabinet_next_cabinet_stream( fdint, pfdin );
|
|
|
|
|
2010-03-23 11:46:54 +01:00
|
|
|
case fdintCOPY_FILE:
|
|
|
|
return cabinet_copy_file( fdint, pfdin );
|
|
|
|
|
|
|
|
case fdintCLOSE_FILE_INFO:
|
|
|
|
return cabinet_close_file_info( fdint, pfdin );
|
|
|
|
|
|
|
|
case fdintCABINET_INFO:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ERR("Unexpected notification %d\n", fdint);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL extract_cabinet( MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data )
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
LPSTR cabinet, cab_path = NULL;
|
|
|
|
HFDI hfdi;
|
|
|
|
ERF erf;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2011-04-14 14:42:48 +02:00
|
|
|
TRACE("extracting %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2010-03-23 11:46:54 +01:00
|
|
|
hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
|
|
|
|
cabinet_write, cabinet_close, cabinet_seek, 0, &erf );
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!hfdi)
|
|
|
|
{
|
|
|
|
ERR("FDICreate failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-26 12:12:15 +01:00
|
|
|
cabinet = strdupWtoA( mi->cabinet );
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!cabinet)
|
|
|
|
goto done;
|
|
|
|
|
2010-03-26 12:12:15 +01:00
|
|
|
cab_path = strdupWtoA( mi->sourcedir );
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!cab_path)
|
|
|
|
goto done;
|
|
|
|
|
2010-03-23 11:46:54 +01:00
|
|
|
ret = FDICopy( hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, data );
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!ret)
|
|
|
|
ERR("FDICopy failed\n");
|
|
|
|
|
|
|
|
done:
|
2010-03-23 11:46:54 +01:00
|
|
|
FDIDestroy( hfdi );
|
|
|
|
msi_free(cabinet );
|
|
|
|
msi_free( cab_path );
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
mi->is_extracted = TRUE;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:46:54 +01:00
|
|
|
static BOOL extract_cabinet_stream( MSIPACKAGE *package, MSIMEDIAINFO *mi, LPVOID data )
|
|
|
|
{
|
|
|
|
static char filename[] = {'<','S','T','R','E','A','M','>',0};
|
|
|
|
HFDI hfdi;
|
|
|
|
ERF erf;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
2011-04-14 14:42:48 +02:00
|
|
|
TRACE("extracting %s disk id %u\n", debugstr_w(mi->cabinet), mi->disk_id);
|
2010-03-23 11:46:54 +01:00
|
|
|
|
|
|
|
hfdi = FDICreate( cabinet_alloc, cabinet_free, cabinet_open_stream, cabinet_read_stream,
|
|
|
|
cabinet_write, cabinet_close_stream, cabinet_seek_stream, 0, &erf );
|
|
|
|
if (!hfdi)
|
|
|
|
{
|
|
|
|
ERR("FDICreate failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-04-14 14:42:48 +02:00
|
|
|
package_disk.package = package;
|
|
|
|
package_disk.id = mi->disk_id;
|
2010-03-23 11:46:54 +01:00
|
|
|
|
|
|
|
ret = FDICopy( hfdi, filename, NULL, 0, cabinet_notify_stream, NULL, data );
|
2011-04-14 14:42:48 +02:00
|
|
|
if (!ret) ERR("FDICopy failed\n");
|
2010-03-23 11:46:54 +01:00
|
|
|
|
|
|
|
FDIDestroy( hfdi );
|
2011-04-14 14:42:48 +02:00
|
|
|
if (ret) mi->is_extracted = TRUE;
|
2010-03-23 11:46:54 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* msi_cabextract
|
|
|
|
*
|
|
|
|
* Extract files from a cabinet file or stream.
|
|
|
|
*/
|
|
|
|
BOOL msi_cabextract(MSIPACKAGE* package, MSIMEDIAINFO *mi, LPVOID data)
|
|
|
|
{
|
|
|
|
if (mi->cabinet[0] == '#')
|
|
|
|
{
|
|
|
|
return extract_cabinet_stream( package, mi, data );
|
|
|
|
}
|
|
|
|
return extract_cabinet( package, mi, data );
|
|
|
|
}
|
|
|
|
|
2008-08-19 05:59:44 +02:00
|
|
|
void msi_free_media_info(MSIMEDIAINFO *mi)
|
|
|
|
{
|
|
|
|
msi_free(mi->disk_prompt);
|
|
|
|
msi_free(mi->cabinet);
|
|
|
|
msi_free(mi->volume_label);
|
2019-01-07 08:55:15 +01:00
|
|
|
msi_free(mi->last_volume);
|
2008-08-19 05:59:44 +02:00
|
|
|
msi_free(mi);
|
|
|
|
}
|
|
|
|
|
2009-09-15 09:28:41 +02:00
|
|
|
static UINT get_drive_type(const WCHAR *path)
|
|
|
|
{
|
|
|
|
WCHAR root[MAX_PATH + 1];
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW(root, path);
|
2009-09-15 09:28:41 +02:00
|
|
|
PathStripToRootW(root);
|
|
|
|
PathAddBackslashW(root);
|
|
|
|
|
|
|
|
return GetDriveTypeW(root);
|
|
|
|
}
|
|
|
|
|
2018-04-18 10:05:46 +02:00
|
|
|
static WCHAR *get_base_url( MSIDATABASE *db )
|
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
WCHAR *p, *ret = NULL, *orig_db = msi_dup_property( db, L"OriginalDatabase" );
|
2019-06-13 08:42:35 +02:00
|
|
|
if (UrlIsW( orig_db, URLIS_URL ) && (ret = strdupW( orig_db )) && (p = wcsrchr( ret, '/'))) p[1] = 0;
|
2018-04-18 10:05:46 +02:00
|
|
|
msi_free( orig_db );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-03-22 20:45:10 +01:00
|
|
|
UINT msi_load_media_info(MSIPACKAGE *package, UINT Sequence, MSIMEDIAINFO *mi)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *row;
|
2018-04-18 10:05:46 +02:00
|
|
|
WCHAR *source_dir, *source, *base_url = NULL;
|
2008-08-19 05:59:44 +02:00
|
|
|
DWORD options;
|
|
|
|
|
2011-04-14 14:40:45 +02:00
|
|
|
if (Sequence <= mi->last_sequence) /* already loaded */
|
|
|
|
return ERROR_SUCCESS;
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
row = MSI_QueryGetRecord(package->db, L"SELECT * FROM `Media` WHERE `LastSequence` >= %d ORDER BY `DiskId`", Sequence);
|
2008-08-19 05:59:44 +02:00
|
|
|
if (!row)
|
|
|
|
{
|
|
|
|
TRACE("Unable to query row\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
mi->is_extracted = FALSE;
|
|
|
|
mi->disk_id = MSI_RecordGetInteger(row, 1);
|
|
|
|
mi->last_sequence = MSI_RecordGetInteger(row, 2);
|
|
|
|
msi_free(mi->disk_prompt);
|
|
|
|
mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
|
|
|
|
msi_free(mi->cabinet);
|
|
|
|
mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
|
|
|
|
msi_free(mi->volume_label);
|
|
|
|
mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
|
|
|
|
msiobj_release(&row->hdr);
|
|
|
|
|
2010-07-23 09:42:37 +02:00
|
|
|
msi_set_sourcedir_props(package, FALSE);
|
2020-10-29 11:47:14 +01:00
|
|
|
source_dir = msi_dup_property(package->db, L"SourceDir");
|
2010-03-26 12:12:15 +01:00
|
|
|
lstrcpyW(mi->sourcedir, source_dir);
|
2011-08-04 13:34:07 +02:00
|
|
|
PathAddBackslashW(mi->sourcedir);
|
2009-09-15 09:28:41 +02:00
|
|
|
mi->type = get_drive_type(source_dir);
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
options = MSICODE_PRODUCT;
|
|
|
|
if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
|
|
|
|
{
|
|
|
|
source = source_dir;
|
|
|
|
options |= MSISOURCETYPE_MEDIA;
|
|
|
|
}
|
2018-04-18 10:05:46 +02:00
|
|
|
else if ((base_url = get_base_url(package->db)))
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2018-04-18 10:05:46 +02:00
|
|
|
source = base_url;
|
2008-08-19 05:59:44 +02:00
|
|
|
options |= MSISOURCETYPE_URL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-03-26 12:12:15 +01:00
|
|
|
source = mi->sourcedir;
|
2008-08-19 05:59:44 +02:00
|
|
|
options |= MSISOURCETYPE_NETWORK;
|
|
|
|
}
|
|
|
|
|
|
|
|
msi_package_add_media_disk(package, package->Context,
|
|
|
|
MSICODE_PRODUCT, mi->disk_id,
|
|
|
|
mi->volume_label, mi->disk_prompt);
|
|
|
|
|
|
|
|
msi_package_add_info(package, package->Context,
|
|
|
|
options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
|
|
|
|
|
2011-04-14 14:40:45 +02:00
|
|
|
TRACE("sequence %u -> cabinet %s disk id %u\n", Sequence, debugstr_w(mi->cabinet), mi->disk_id);
|
2018-04-18 10:05:46 +02:00
|
|
|
|
|
|
|
msi_free(base_url);
|
|
|
|
msi_free(source_dir);
|
2008-08-19 05:59:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-03-23 11:48:46 +01:00
|
|
|
/* FIXME: search URL sources as well */
|
2009-01-10 15:20:03 +01:00
|
|
|
static UINT find_published_source(MSIPACKAGE *package, MSIMEDIAINFO *mi)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
|
|
|
WCHAR source[MAX_PATH];
|
|
|
|
WCHAR volume[MAX_PATH];
|
|
|
|
WCHAR prompt[MAX_PATH];
|
|
|
|
DWORD volumesz, promptsz;
|
|
|
|
DWORD index, size, id;
|
2010-03-23 11:48:46 +01:00
|
|
|
WCHAR last_type[2];
|
2008-08-19 05:59:44 +02:00
|
|
|
UINT r;
|
|
|
|
|
2010-03-23 11:48:46 +01:00
|
|
|
size = 2;
|
|
|
|
r = MsiSourceListGetInfoW(package->ProductCode, NULL,
|
|
|
|
package->Context, MSICODE_PRODUCT,
|
|
|
|
INSTALLPROPERTY_LASTUSEDTYPEW, last_type, &size);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
2008-08-19 05:59:44 +02:00
|
|
|
size = MAX_PATH;
|
|
|
|
r = MsiSourceListGetInfoW(package->ProductCode, NULL,
|
|
|
|
package->Context, MSICODE_PRODUCT,
|
|
|
|
INSTALLPROPERTY_LASTUSEDSOURCEW, source, &size);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
2010-03-23 11:48:46 +01:00
|
|
|
if (last_type[0] == 'n')
|
|
|
|
{
|
2011-03-10 02:20:57 +01:00
|
|
|
WCHAR cabinet_file[MAX_PATH];
|
|
|
|
BOOL check_all = FALSE;
|
|
|
|
|
|
|
|
while(TRUE)
|
2010-03-23 11:48:46 +01:00
|
|
|
{
|
2011-03-10 02:20:57 +01:00
|
|
|
index = 0;
|
|
|
|
volumesz = MAX_PATH;
|
|
|
|
while (MsiSourceListEnumSourcesW(package->ProductCode, NULL,
|
|
|
|
package->Context,
|
|
|
|
MSISOURCETYPE_NETWORK, index++,
|
|
|
|
volume, &volumesz) == ERROR_SUCCESS)
|
2010-03-23 11:48:46 +01:00
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
if (check_all || !wcsnicmp(source, volume, lstrlenW(source)))
|
2011-03-10 02:20:57 +01:00
|
|
|
{
|
|
|
|
lstrcpyW(cabinet_file, volume);
|
|
|
|
PathAddBackslashW(cabinet_file);
|
|
|
|
lstrcatW(cabinet_file, mi->cabinet);
|
|
|
|
|
|
|
|
if (GetFileAttributesW(cabinet_file) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
{
|
|
|
|
volumesz = MAX_PATH;
|
|
|
|
if(!check_all)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW(mi->sourcedir, volume);
|
2011-08-04 13:34:07 +02:00
|
|
|
PathAddBackslashW(mi->sourcedir);
|
2011-03-10 02:20:57 +01:00
|
|
|
TRACE("Found network source %s\n", debugstr_w(mi->sourcedir));
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2010-03-23 11:48:46 +01:00
|
|
|
}
|
2011-03-10 02:20:57 +01:00
|
|
|
|
|
|
|
if (!check_all)
|
|
|
|
check_all = TRUE;
|
|
|
|
else
|
|
|
|
break;
|
2010-03-23 11:48:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-19 05:59:44 +02:00
|
|
|
index = 0;
|
|
|
|
volumesz = MAX_PATH;
|
|
|
|
promptsz = MAX_PATH;
|
|
|
|
while (MsiSourceListEnumMediaDisksW(package->ProductCode, NULL,
|
|
|
|
package->Context,
|
|
|
|
MSICODE_PRODUCT, index++, &id,
|
|
|
|
volume, &volumesz, prompt, &promptsz) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
mi->disk_id = id;
|
2012-01-03 13:53:50 +01:00
|
|
|
msi_free( mi->volume_label );
|
|
|
|
if (!(mi->volume_label = msi_alloc( ++volumesz * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW( mi->volume_label, volume );
|
2012-01-03 13:53:50 +01:00
|
|
|
|
|
|
|
msi_free( mi->disk_prompt );
|
|
|
|
if (!(mi->disk_prompt = msi_alloc( ++promptsz * sizeof(WCHAR) ))) return ERROR_OUTOFMEMORY;
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW( mi->disk_prompt, prompt );
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
if (source_matches_volume(mi, source))
|
|
|
|
{
|
|
|
|
/* FIXME: what about SourceDir */
|
2010-03-26 12:12:15 +01:00
|
|
|
lstrcpyW(mi->sourcedir, source);
|
2011-08-04 13:34:07 +02:00
|
|
|
PathAddBackslashW(mi->sourcedir);
|
2010-03-26 12:12:15 +01:00
|
|
|
TRACE("Found disk source %s\n", debugstr_w(mi->sourcedir));
|
2008-08-19 05:59:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2011-12-23 13:53:34 +01:00
|
|
|
UINT ready_media( MSIPACKAGE *package, BOOL compressed, MSIMEDIAINFO *mi )
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2011-12-23 13:53:34 +01:00
|
|
|
UINT rc;
|
|
|
|
WCHAR *cabinet_file = NULL;
|
2008-08-19 05:59:44 +02:00
|
|
|
|
|
|
|
/* media info for continuous cabinet is already loaded */
|
2011-12-23 13:53:34 +01:00
|
|
|
if (mi->is_continuous) return ERROR_SUCCESS;
|
2010-03-26 12:12:15 +01:00
|
|
|
|
2011-12-23 13:53:34 +01:00
|
|
|
if (mi->cabinet)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2018-04-18 10:05:46 +02:00
|
|
|
WCHAR *base_url;
|
|
|
|
|
2011-12-23 13:53:34 +01:00
|
|
|
/* cabinet is internal, no checks needed */
|
|
|
|
if (mi->cabinet[0] == '#') return ERROR_SUCCESS;
|
2008-08-19 05:59:44 +02:00
|
|
|
|
2011-12-23 13:53:34 +01:00
|
|
|
if (!(cabinet_file = get_cabinet_filename( mi ))) return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
/* package should be downloaded */
|
|
|
|
if (compressed && GetFileAttributesW( cabinet_file ) == INVALID_FILE_ATTRIBUTES &&
|
2018-04-18 10:05:46 +02:00
|
|
|
(base_url = get_base_url( package->db )))
|
2010-06-23 10:44:26 +02:00
|
|
|
{
|
2018-04-18 10:05:46 +02:00
|
|
|
WCHAR temppath[MAX_PATH], *p, *url;
|
2010-03-26 12:12:15 +01:00
|
|
|
|
2018-04-18 10:05:46 +02:00
|
|
|
msi_free( cabinet_file );
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!(url = msi_alloc( (lstrlenW( base_url ) + lstrlenW( mi->cabinet ) + 1) * sizeof(WCHAR) )))
|
2011-12-23 13:53:34 +01:00
|
|
|
{
|
2018-04-18 10:05:46 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW( url, base_url );
|
|
|
|
lstrcatW( url, mi->cabinet );
|
2018-04-18 10:05:46 +02:00
|
|
|
if ((rc = msi_download_file( url, temppath )) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to download %s (%u)\n", debugstr_w(url), rc);
|
|
|
|
msi_free( url );
|
2011-12-23 13:53:34 +01:00
|
|
|
return rc;
|
|
|
|
}
|
2019-06-13 08:42:35 +02:00
|
|
|
if ((p = wcsrchr( temppath, '\\' ))) *p = 0;
|
|
|
|
lstrcpyW( mi->sourcedir, temppath );
|
2011-12-23 13:53:34 +01:00
|
|
|
PathAddBackslashW( mi->sourcedir );
|
|
|
|
msi_free( mi->cabinet );
|
|
|
|
mi->cabinet = strdupW( p + 1 );
|
2018-04-18 10:05:46 +02:00
|
|
|
|
|
|
|
msi_free( url );
|
2011-12-23 13:53:34 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
/* check volume matches, change media if not */
|
2019-01-07 08:55:15 +01:00
|
|
|
if (mi->volume_label)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2019-01-07 08:55:15 +01:00
|
|
|
/* assume first volume is in the drive */
|
2019-06-13 08:42:35 +02:00
|
|
|
if (mi->last_volume && wcsicmp( mi->last_volume, mi->volume_label ))
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
WCHAR *source = msi_dup_property( package->db, L"SourceDir" );
|
2019-01-07 08:55:15 +01:00
|
|
|
BOOL match = source_matches_volume( mi, source );
|
|
|
|
msi_free( source );
|
|
|
|
|
|
|
|
if (!match && (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE))
|
2010-03-26 12:12:15 +01:00
|
|
|
{
|
2019-01-07 08:55:15 +01:00
|
|
|
if ((rc = msi_change_media( package, mi )) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msi_free( cabinet_file );
|
|
|
|
return rc;
|
|
|
|
}
|
2010-03-26 12:12:15 +01:00
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
2019-01-07 08:55:15 +01:00
|
|
|
|
|
|
|
msi_free(mi->last_volume);
|
|
|
|
mi->last_volume = strdupW(mi->volume_label);
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
2011-12-23 13:53:34 +01:00
|
|
|
if (mi->cabinet)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2011-12-23 13:53:34 +01:00
|
|
|
if (compressed && GetFileAttributesW( cabinet_file ) == INVALID_FILE_ATTRIBUTES)
|
2008-08-19 05:59:44 +02:00
|
|
|
{
|
2011-12-23 13:53:34 +01:00
|
|
|
if ((rc = find_published_source( package, mi )) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("cabinet not found: %s\n", debugstr_w(cabinet_file));
|
|
|
|
msi_free( cabinet_file );
|
|
|
|
return ERROR_INSTALL_FAILURE;
|
|
|
|
}
|
2008-08-19 05:59:44 +02:00
|
|
|
}
|
|
|
|
}
|
2011-12-23 13:53:34 +01:00
|
|
|
msi_free( cabinet_file );
|
2008-08-19 05:59:44 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2011-04-14 14:41:19 +02:00
|
|
|
|
|
|
|
UINT msi_add_cabinet_stream( MSIPACKAGE *package, UINT disk_id, IStorage *storage, const WCHAR *name )
|
|
|
|
{
|
|
|
|
MSICABINETSTREAM *cab, *item;
|
|
|
|
|
|
|
|
TRACE("%p, %u, %p, %s\n", package, disk_id, storage, debugstr_w(name));
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( item, &package->cabinet_streams, MSICABINETSTREAM, entry )
|
|
|
|
{
|
|
|
|
if (item->disk_id == disk_id)
|
|
|
|
{
|
|
|
|
TRACE("duplicate disk id %u\n", disk_id);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(cab = msi_alloc( sizeof(*cab) ))) return ERROR_OUTOFMEMORY;
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!(cab->stream = msi_alloc( (lstrlenW( name ) + 1) * sizeof(WCHAR ) )))
|
2011-04-14 14:41:19 +02:00
|
|
|
{
|
|
|
|
msi_free( cab );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2019-06-13 08:42:35 +02:00
|
|
|
lstrcpyW( cab->stream, name );
|
2011-04-14 14:41:19 +02:00
|
|
|
cab->disk_id = disk_id;
|
|
|
|
cab->storage = storage;
|
|
|
|
IStorage_AddRef( storage );
|
|
|
|
list_add_tail( &package->cabinet_streams, &cab->entry );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|