2005-06-17 22:56:55 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2005 Aric Stewart for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-17 22:56:55 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actions dealing with files These are
|
|
|
|
*
|
|
|
|
* InstallFiles
|
|
|
|
* DuplicateFiles
|
|
|
|
* MoveFiles (TODO)
|
|
|
|
* PatchFiles (TODO)
|
|
|
|
* RemoveDuplicateFiles(TODO)
|
|
|
|
* RemoveFiles(TODO)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "fdi.h"
|
2005-07-05 23:00:06 +02:00
|
|
|
#include "msi.h"
|
2005-06-17 22:56:55 +02:00
|
|
|
#include "msidefs.h"
|
|
|
|
#include "msvcrt/fcntl.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winuser.h"
|
2006-08-10 00:02:49 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
2005-06-17 22:56:55 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
|
|
|
extern const WCHAR szInstallFiles[];
|
|
|
|
extern const WCHAR szDuplicateFiles[];
|
|
|
|
extern const WCHAR szMoveFiles[];
|
|
|
|
extern const WCHAR szPatchFiles[];
|
|
|
|
extern const WCHAR szRemoveDuplicateFiles[];
|
|
|
|
extern const WCHAR szRemoveFiles[];
|
|
|
|
|
|
|
|
static const WCHAR cszTempFolder[]= {'T','e','m','p','F','o','l','d','e','r',0};
|
|
|
|
|
2006-11-08 00:09:29 +01:00
|
|
|
struct media_info {
|
2006-11-08 00:10:52 +01:00
|
|
|
UINT disk_id;
|
2008-02-26 08:54:14 +01:00
|
|
|
UINT type;
|
2006-11-08 00:09:29 +01:00
|
|
|
UINT last_sequence;
|
2006-11-08 00:10:52 +01:00
|
|
|
LPWSTR disk_prompt;
|
|
|
|
LPWSTR cabinet;
|
2007-11-26 01:02:55 +01:00
|
|
|
LPWSTR first_volume;
|
2006-11-08 00:10:52 +01:00
|
|
|
LPWSTR volume_label;
|
|
|
|
BOOL is_continuous;
|
2007-02-04 05:54:42 +01:00
|
|
|
BOOL is_extracted;
|
2006-11-08 00:09:29 +01:00
|
|
|
WCHAR source[MAX_PATH];
|
|
|
|
};
|
|
|
|
|
2007-05-09 09:04:10 +02:00
|
|
|
static BOOL source_matches_volume(struct media_info *mi, LPWSTR source_root)
|
|
|
|
{
|
|
|
|
WCHAR volume_name[MAX_PATH + 1];
|
|
|
|
|
|
|
|
if (!GetVolumeInformationW(source_root, volume_name, MAX_PATH + 1,
|
|
|
|
NULL, NULL, NULL, NULL, 0))
|
|
|
|
{
|
|
|
|
ERR("Failed to get volume information\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return !lstrcmpW(mi->volume_label, volume_name);
|
|
|
|
}
|
|
|
|
|
2006-11-08 23:07:53 +01:00
|
|
|
static UINT msi_change_media( MSIPACKAGE *package, struct media_info *mi )
|
|
|
|
{
|
2006-11-13 23:18:54 +01:00
|
|
|
LPSTR msg;
|
2006-11-08 23:07:53 +01:00
|
|
|
LPWSTR error, error_dialog;
|
2007-05-09 09:04:10 +02:00
|
|
|
LPWSTR source_dir;
|
2006-11-08 23:07:53 +01:00
|
|
|
UINT r = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
static const WCHAR szUILevel[] = {'U','I','L','e','v','e','l',0};
|
|
|
|
static const WCHAR error_prop[] = {'E','r','r','o','r','D','i','a','l','o','g',0};
|
|
|
|
|
2007-02-07 06:53:24 +01:00
|
|
|
if ( (msi_get_property_int(package, szUILevel, 0) & INSTALLUILEVEL_MASK) == INSTALLUILEVEL_NONE && !gUIHandlerA )
|
2006-11-08 23:07:53 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
error = generate_error_string( package, 1302, 1, mi->disk_prompt );
|
|
|
|
error_dialog = msi_dup_property( package, error_prop );
|
2007-05-09 09:04:10 +02:00
|
|
|
source_dir = msi_dup_property( package, cszSourceDir );
|
|
|
|
PathStripToRootW(source_dir);
|
2006-11-08 23:07:53 +01:00
|
|
|
|
2007-05-09 09:04:10 +02:00
|
|
|
while ( r == ERROR_SUCCESS &&
|
|
|
|
!source_matches_volume(mi, source_dir) )
|
2006-11-13 23:18:54 +01:00
|
|
|
{
|
2006-11-08 23:07:53 +01:00
|
|
|
r = msi_spawn_error_dialog( package, error_dialog, error );
|
|
|
|
|
2006-11-13 23:18:54 +01:00
|
|
|
if (gUIHandlerA)
|
|
|
|
{
|
|
|
|
msg = strdupWtoA( error );
|
|
|
|
gUIHandlerA( gUIContext, MB_RETRYCANCEL | INSTALLMESSAGE_ERROR, msg );
|
|
|
|
msi_free(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-08 23:07:53 +01:00
|
|
|
msi_free( error );
|
|
|
|
msi_free( error_dialog );
|
2007-05-09 09:04:10 +02:00
|
|
|
msi_free( source_dir );
|
2006-11-08 23:07:53 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-06-17 22:56:55 +02:00
|
|
|
/*
|
|
|
|
* This is a helper function for handling embedded cabinet media
|
|
|
|
*/
|
|
|
|
static UINT writeout_cabinet_stream(MSIPACKAGE *package, LPCWSTR stream_name,
|
|
|
|
WCHAR* source)
|
|
|
|
{
|
|
|
|
UINT rc;
|
|
|
|
USHORT* data;
|
|
|
|
UINT size;
|
|
|
|
DWORD write;
|
|
|
|
HANDLE the_file;
|
|
|
|
WCHAR tmp[MAX_PATH];
|
|
|
|
|
|
|
|
rc = read_raw_stream_data(package->db,stream_name,&data,&size);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
write = MAX_PATH;
|
|
|
|
if (MSI_GetPropertyW(package, cszTempFolder, tmp, &write))
|
|
|
|
GetTempPathW(MAX_PATH,tmp);
|
|
|
|
|
|
|
|
GetTempFileNameW(tmp,stream_name,0,source);
|
|
|
|
|
2006-11-14 04:42:27 +01:00
|
|
|
track_tempfile(package, source);
|
2005-06-17 22:56:55 +02:00
|
|
|
the_file = CreateFileW(source, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
|
|
|
|
if (the_file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
ERR("Unable to create file %s\n",debugstr_w(source));
|
|
|
|
rc = ERROR_FUNCTION_FAILED;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteFile(the_file,data,size,&write,NULL);
|
|
|
|
CloseHandle(the_file);
|
2006-10-05 06:41:22 +02:00
|
|
|
TRACE("wrote %i bytes to %s\n",write,debugstr_w(source));
|
2005-06-17 22:56:55 +02:00
|
|
|
end:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(data);
|
2005-06-17 22:56:55 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Support functions for FDI functions */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
MSIPACKAGE* package;
|
2006-11-08 00:10:52 +01:00
|
|
|
struct media_info *mi;
|
2005-06-17 22:56:55 +02:00
|
|
|
} CabData;
|
|
|
|
|
|
|
|
static void * cabinet_alloc(ULONG cb)
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
return msi_alloc(cb);
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cabinet_free(void *pv)
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(pv);
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR cabinet_open(char *pszFile, int oflag, int pmode)
|
|
|
|
{
|
2005-10-28 12:40:54 +02:00
|
|
|
HANDLE handle;
|
2005-06-17 22:56:55 +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;
|
2005-10-28 12:40:54 +02:00
|
|
|
handle = CreateFileA( pszFile, dwAccess, dwShareMode, NULL,
|
|
|
|
dwCreateDisposition, 0, NULL );
|
|
|
|
if (handle == INVALID_HANDLE_VALUE)
|
|
|
|
return 0;
|
|
|
|
return (INT_PTR) handle;
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT cabinet_read(INT_PTR hf, void *pv, UINT cb)
|
|
|
|
{
|
2005-10-28 12:40:54 +02:00
|
|
|
HANDLE handle = (HANDLE) hf;
|
2005-06-17 22:56:55 +02:00
|
|
|
DWORD dwRead;
|
2005-10-28 12:40:54 +02:00
|
|
|
if (ReadFile(handle, pv, cb, &dwRead, NULL))
|
2005-06-17 22:56:55 +02:00
|
|
|
return dwRead;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT cabinet_write(INT_PTR hf, void *pv, UINT cb)
|
|
|
|
{
|
2005-10-28 12:40:54 +02:00
|
|
|
HANDLE handle = (HANDLE) hf;
|
2005-06-17 22:56:55 +02:00
|
|
|
DWORD dwWritten;
|
2005-10-28 12:40:54 +02:00
|
|
|
if (WriteFile(handle, pv, cb, &dwWritten, NULL))
|
2005-06-17 22:56:55 +02:00
|
|
|
return dwWritten;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cabinet_close(INT_PTR hf)
|
|
|
|
{
|
2005-10-28 12:40:54 +02:00
|
|
|
HANDLE handle = (HANDLE) hf;
|
|
|
|
return CloseHandle(handle) ? 0 : -1;
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static long cabinet_seek(INT_PTR hf, long dist, int seektype)
|
|
|
|
{
|
2005-10-28 12:40:54 +02:00
|
|
|
HANDLE handle = (HANDLE) hf;
|
2005-06-17 22:56:55 +02:00
|
|
|
/* flags are compatible and so are passed straight through */
|
2005-10-28 12:40:54 +02:00
|
|
|
return SetFilePointer(handle, dist, NULL, seektype);
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
2006-01-23 17:29:50 +01:00
|
|
|
static void msi_file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
|
2005-10-28 12:43:50 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *uirow;
|
|
|
|
LPWSTR uipath, p;
|
|
|
|
|
|
|
|
/* the UI chunk */
|
|
|
|
uirow = MSI_CreateRecord( 9 );
|
|
|
|
MSI_RecordSetStringW( uirow, 1, f->FileName );
|
|
|
|
uipath = strdupW( f->TargetPath );
|
|
|
|
p = strrchrW(uipath,'\\');
|
|
|
|
if (p)
|
|
|
|
p[1]=0;
|
|
|
|
MSI_RecordSetStringW( uirow, 9, uipath);
|
|
|
|
MSI_RecordSetInteger( uirow, 6, f->FileSize );
|
2006-01-23 17:29:50 +01:00
|
|
|
ui_actiondata( package, action, uirow);
|
2005-10-28 12:43:50 +02:00
|
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
msi_free( uipath );
|
|
|
|
ui_progress( package, 2, f->FileSize, 0, 0);
|
|
|
|
}
|
|
|
|
|
2006-11-20 08:15:40 +01:00
|
|
|
static UINT msi_media_get_disk_info( MSIPACKAGE *package, struct media_info *mi )
|
2006-11-08 23:07:53 +01:00
|
|
|
{
|
|
|
|
MSIRECORD *row;
|
|
|
|
LPWSTR ptr;
|
|
|
|
|
|
|
|
static const WCHAR query[] =
|
|
|
|
{'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
|
|
|
|
'`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
|
|
|
|
'`','D','i','s','k','I','d','`',' ','=',' ','%','i',0};
|
|
|
|
|
2006-11-20 08:15:40 +01:00
|
|
|
row = MSI_QueryGetRecord(package->db, query, mi->disk_id);
|
2006-11-08 23:07:53 +01:00
|
|
|
if (!row)
|
|
|
|
{
|
|
|
|
TRACE("Unable to query row\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2006-11-20 08:15:40 +01:00
|
|
|
mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
|
|
|
|
mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
|
2007-06-25 22:05:03 +02:00
|
|
|
mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
|
2006-11-08 23:07:53 +01:00
|
|
|
|
2007-11-26 01:02:55 +01:00
|
|
|
if (!mi->first_volume)
|
|
|
|
mi->first_volume = strdupW(mi->volume_label);
|
|
|
|
|
2006-11-20 08:15:40 +01:00
|
|
|
ptr = strrchrW(mi->source, '\\') + 1;
|
|
|
|
lstrcpyW(ptr, mi->cabinet);
|
2006-11-20 08:15:07 +01:00
|
|
|
msiobj_release(&row->hdr);
|
2006-11-08 23:07:53 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-06-17 22:56:55 +02:00
|
|
|
static INT_PTR cabinet_notify(FDINOTIFICATIONTYPE fdint, PFDINOTIFICATION pfdin)
|
|
|
|
{
|
2006-11-08 23:07:53 +01:00
|
|
|
TRACE("(%d)\n", fdint);
|
|
|
|
|
2005-06-17 22:56:55 +02:00
|
|
|
switch (fdint)
|
|
|
|
{
|
2006-11-08 23:07:53 +01:00
|
|
|
case fdintPARTIAL_FILE:
|
|
|
|
{
|
|
|
|
CabData *data = (CabData *)pfdin->pv;
|
|
|
|
data->mi->is_continuous = FALSE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case fdintNEXT_CABINET:
|
|
|
|
{
|
|
|
|
CabData *data = (CabData *)pfdin->pv;
|
|
|
|
struct media_info *mi = data->mi;
|
|
|
|
LPWSTR cab = strdupAtoW(pfdin->psz1);
|
|
|
|
UINT rc;
|
|
|
|
|
|
|
|
msi_free(mi->disk_prompt);
|
2007-06-25 22:05:03 +02:00
|
|
|
msi_free(mi->cabinet);
|
|
|
|
msi_free(mi->volume_label);
|
2007-10-23 10:10:11 +02:00
|
|
|
mi->disk_prompt = NULL;
|
|
|
|
mi->cabinet = NULL;
|
|
|
|
mi->volume_label = NULL;
|
2006-11-08 23:07:53 +01:00
|
|
|
|
|
|
|
mi->disk_id++;
|
|
|
|
mi->is_continuous = TRUE;
|
|
|
|
|
2006-11-20 08:15:40 +01:00
|
|
|
rc = msi_media_get_disk_info(data->package, mi);
|
2006-11-08 23:07:53 +01:00
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
2007-12-12 04:47:08 +01:00
|
|
|
msi_free(cab);
|
2006-11-08 23:07:53 +01:00
|
|
|
ERR("Failed to get next cabinet information: %d\n", rc);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lstrcmpiW(mi->cabinet, cab))
|
|
|
|
{
|
|
|
|
msi_free(cab);
|
|
|
|
ERR("Continuous cabinet does not match the next cabinet in the Media table\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
msi_free(cab);
|
|
|
|
|
|
|
|
TRACE("Searching for %s\n", debugstr_w(mi->source));
|
|
|
|
|
|
|
|
if (GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
|
|
|
|
rc = msi_change_media(data->package, mi);
|
|
|
|
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
case fdintCOPY_FILE:
|
|
|
|
{
|
|
|
|
CabData *data = (CabData*) pfdin->pv;
|
2005-10-29 12:31:06 +02:00
|
|
|
HANDLE handle;
|
|
|
|
LPWSTR file;
|
2005-08-23 12:03:17 +02:00
|
|
|
MSIFILE *f;
|
2006-07-18 13:51:31 +02:00
|
|
|
DWORD attrs;
|
2005-06-24 14:14:35 +02:00
|
|
|
|
2005-10-29 12:31:06 +02:00
|
|
|
file = strdupAtoW(pfdin->psz1);
|
|
|
|
f = get_loaded_file(data->package, file);
|
|
|
|
msi_free(file);
|
2005-06-24 14:14:35 +02:00
|
|
|
|
2005-08-23 12:03:17 +02:00
|
|
|
if (!f)
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
2006-07-29 10:12:58 +02:00
|
|
|
WARN("unknown file in cabinet (%s)\n",debugstr_a(pfdin->psz1));
|
2005-06-24 14:14:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-02 11:56:42 +01:00
|
|
|
if (f->state != msifs_missing && f->state != msifs_overwrite)
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
2005-09-22 12:56:26 +02:00
|
|
|
TRACE("Skipping extraction of %s\n",debugstr_a(pfdin->psz1));
|
2005-06-24 14:14:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-01-23 17:29:50 +01:00
|
|
|
msi_file_update_ui( data->package, f, szInstallFiles );
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-10-29 12:31:06 +02:00
|
|
|
TRACE("extracting %s\n", debugstr_w(f->TargetPath) );
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2006-07-18 13:51:31 +02:00
|
|
|
attrs = f->Attributes & (FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM);
|
|
|
|
if (!attrs) attrs = FILE_ATTRIBUTE_NORMAL;
|
|
|
|
|
2005-10-29 12:31:06 +02:00
|
|
|
handle = CreateFileW( f->TargetPath, GENERIC_READ | GENERIC_WRITE, 0,
|
2006-07-18 13:51:31 +02:00
|
|
|
NULL, CREATE_ALWAYS, attrs, NULL );
|
2005-10-29 12:31:06 +02:00
|
|
|
if ( handle == INVALID_HANDLE_VALUE )
|
|
|
|
{
|
2006-11-28 03:18:51 +01:00
|
|
|
if ( GetFileAttributesW( f->TargetPath ) != INVALID_FILE_ATTRIBUTES )
|
|
|
|
f->state = msifs_installed;
|
|
|
|
else
|
|
|
|
ERR("failed to create %s (error %d)\n",
|
|
|
|
debugstr_w( f->TargetPath ), GetLastError() );
|
|
|
|
|
2005-10-29 12:31:06 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-11-02 11:56:42 +01:00
|
|
|
f->state = msifs_installed;
|
2005-10-29 12:31:06 +02:00
|
|
|
return (INT_PTR) handle;
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
case fdintCLOSE_FILE_INFO:
|
|
|
|
{
|
2008-03-04 18:16:27 +01:00
|
|
|
CabData *data = (CabData*) pfdin->pv;
|
2005-06-17 22:56:55 +02:00
|
|
|
FILETIME ft;
|
2005-10-28 12:40:54 +02:00
|
|
|
FILETIME ftLocal;
|
|
|
|
HANDLE handle = (HANDLE) pfdin->hf;
|
|
|
|
|
2008-03-04 18:16:27 +01:00
|
|
|
data->mi->is_continuous = FALSE;
|
|
|
|
|
2005-06-17 22:56:55 +02:00
|
|
|
if (!DosDateTimeToFileTime(pfdin->date, pfdin->time, &ft))
|
|
|
|
return -1;
|
|
|
|
if (!LocalFileTimeToFileTime(&ft, &ftLocal))
|
|
|
|
return -1;
|
2005-10-28 12:40:54 +02:00
|
|
|
if (!SetFileTime(handle, &ftLocal, 0, &ftLocal))
|
2005-06-17 22:56:55 +02:00
|
|
|
return -1;
|
2005-10-28 12:40:54 +02:00
|
|
|
CloseHandle(handle);
|
2005-06-17 22:56:55 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* extract_cabinet_file
|
|
|
|
*
|
|
|
|
* Extract files from a cab file.
|
|
|
|
*/
|
2006-11-08 00:09:29 +01:00
|
|
|
static BOOL extract_cabinet_file(MSIPACKAGE* package, struct media_info *mi)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2006-11-08 00:10:52 +01:00
|
|
|
LPSTR cabinet, cab_path = NULL;
|
|
|
|
LPWSTR ptr;
|
2005-06-17 22:56:55 +02:00
|
|
|
HFDI hfdi;
|
|
|
|
ERF erf;
|
2006-11-08 00:10:52 +01:00
|
|
|
BOOL ret = FALSE;
|
2005-06-17 22:56:55 +02:00
|
|
|
CabData data;
|
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
TRACE("Extracting %s\n", debugstr_w(mi->source));
|
|
|
|
|
|
|
|
hfdi = FDICreate(cabinet_alloc, cabinet_free, cabinet_open, cabinet_read,
|
|
|
|
cabinet_write, cabinet_close, cabinet_seek, 0, &erf);
|
2005-06-17 22:56:55 +02:00
|
|
|
if (!hfdi)
|
|
|
|
{
|
|
|
|
ERR("FDICreate failed\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
ptr = strrchrW(mi->source, '\\') + 1;
|
|
|
|
cabinet = strdupWtoA(ptr);
|
|
|
|
if (!cabinet)
|
|
|
|
goto done;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
cab_path = strdupWtoA(mi->source);
|
|
|
|
if (!cab_path)
|
|
|
|
goto done;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
cab_path[ptr - mi->source] = '\0';
|
|
|
|
|
|
|
|
data.package = package;
|
|
|
|
data.mi = mi;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
ret = FDICopy(hfdi, cabinet, cab_path, 0, cabinet_notify, NULL, &data);
|
2005-06-17 22:56:55 +02:00
|
|
|
if (!ret)
|
|
|
|
ERR("FDICopy failed\n");
|
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
done:
|
2005-06-17 22:56:55 +02:00
|
|
|
FDIDestroy(hfdi);
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(cabinet);
|
|
|
|
msi_free(cab_path);
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2007-02-04 05:54:42 +01:00
|
|
|
if (ret)
|
|
|
|
mi->is_extracted = TRUE;
|
|
|
|
|
2005-06-17 22:56:55 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-11-08 00:09:58 +01:00
|
|
|
static VOID set_file_source(MSIPACKAGE* package, MSIFILE* file, LPCWSTR path)
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
2006-08-07 20:37:49 +02:00
|
|
|
if (!file->IsCompressed)
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
2006-03-21 11:40:36 +01:00
|
|
|
LPWSTR p, path;
|
2007-03-29 09:38:57 +02:00
|
|
|
p = resolve_folder(package, file->Component->Directory, TRUE, FALSE, TRUE, NULL);
|
2006-03-21 11:40:36 +01:00
|
|
|
path = build_directory_name(2, p, file->ShortName);
|
2007-06-21 18:19:57 +02:00
|
|
|
if (file->LongName &&
|
|
|
|
INVALID_FILE_ATTRIBUTES == GetFileAttributesW( path ))
|
2006-03-21 11:40:36 +01:00
|
|
|
{
|
|
|
|
msi_free(path);
|
|
|
|
path = build_directory_name(2, p, file->LongName);
|
|
|
|
}
|
|
|
|
file->SourcePath = path;
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(p);
|
2005-06-24 14:14:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
file->SourcePath = build_directory_name(2, path, file->File);
|
|
|
|
}
|
|
|
|
|
2005-09-23 12:05:08 +02:00
|
|
|
static void free_media_info( struct media_info *mi )
|
|
|
|
{
|
2006-11-08 00:10:52 +01:00
|
|
|
msi_free( mi->disk_prompt );
|
|
|
|
msi_free( mi->cabinet );
|
|
|
|
msi_free( mi->volume_label );
|
2007-11-26 01:02:55 +01:00
|
|
|
msi_free( mi->first_volume );
|
2005-09-23 12:05:08 +02:00
|
|
|
msi_free( mi );
|
|
|
|
}
|
|
|
|
|
2006-11-08 23:03:36 +01:00
|
|
|
static UINT load_media_info(MSIPACKAGE *package, MSIFILE *file, struct media_info *mi)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2006-11-08 23:03:36 +01:00
|
|
|
MSIRECORD *row;
|
2006-11-08 00:10:52 +01:00
|
|
|
LPWSTR source_dir;
|
2008-02-26 08:54:14 +01:00
|
|
|
LPWSTR source;
|
|
|
|
DWORD options;
|
2006-11-08 23:03:36 +01:00
|
|
|
UINT r;
|
|
|
|
|
|
|
|
static const WCHAR query[] = {
|
|
|
|
'S','E','L','E','C','T',' ','*',' ', 'F','R','O','M',' ',
|
|
|
|
'`','M','e','d','i','a','`',' ','W','H','E','R','E',' ',
|
|
|
|
'`','L','a','s','t','S','e','q','u','e','n','c','e','`',' ','>','=',
|
|
|
|
' ','%','i',' ','A','N','D',' ','`','D','i','s','k','I','d','`',' ','>','=',
|
|
|
|
' ','%','i',' ','O','R','D','E','R',' ','B','Y',' ',
|
|
|
|
'`','D','i','s','k','I','d','`',0
|
|
|
|
};
|
|
|
|
|
|
|
|
row = MSI_QueryGetRecord(package->db, query, file->Sequence, mi->disk_id);
|
2005-06-17 22:56:55 +02:00
|
|
|
if (!row)
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
|
|
|
TRACE("Unable to query row\n");
|
2005-06-17 22:56:55 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2005-06-24 14:14:35 +02:00
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2007-04-12 01:52:00 +02:00
|
|
|
mi->is_extracted = FALSE;
|
2006-11-08 23:03:36 +01:00
|
|
|
mi->disk_id = MSI_RecordGetInteger(row, 1);
|
|
|
|
mi->last_sequence = MSI_RecordGetInteger(row, 2);
|
2006-11-20 08:15:18 +01:00
|
|
|
msi_free(mi->disk_prompt);
|
2006-11-08 23:03:01 +01:00
|
|
|
mi->disk_prompt = strdupW(MSI_RecordGetString(row, 3));
|
2006-11-20 08:15:18 +01:00
|
|
|
msi_free(mi->cabinet);
|
2006-11-08 23:03:36 +01:00
|
|
|
mi->cabinet = strdupW(MSI_RecordGetString(row, 4));
|
2006-11-20 08:15:18 +01:00
|
|
|
msi_free(mi->volume_label);
|
2006-11-08 23:03:36 +01:00
|
|
|
mi->volume_label = strdupW(MSI_RecordGetString(row, 5));
|
|
|
|
msiobj_release(&row->hdr);
|
2005-06-29 21:19:09 +02:00
|
|
|
|
2007-11-26 01:02:55 +01:00
|
|
|
if (!mi->first_volume)
|
|
|
|
mi->first_volume = strdupW(mi->volume_label);
|
|
|
|
|
2006-11-08 00:10:52 +01:00
|
|
|
source_dir = msi_dup_property(package, cszSourceDir);
|
2008-01-05 07:07:34 +01:00
|
|
|
lstrcpyW(mi->source, source_dir);
|
2005-06-24 14:14:35 +02:00
|
|
|
|
2008-02-26 08:54:14 +01:00
|
|
|
PathStripToRootW(source_dir);
|
|
|
|
mi->type = GetDriveTypeW(source_dir);
|
|
|
|
|
2008-01-05 07:07:34 +01:00
|
|
|
if (file->IsCompressed && mi->cabinet)
|
2006-11-08 23:03:36 +01:00
|
|
|
{
|
2008-01-05 07:07:34 +01:00
|
|
|
if (mi->cabinet[0] == '#')
|
2006-11-08 23:03:36 +01:00
|
|
|
{
|
2008-01-05 07:07:34 +01:00
|
|
|
r = writeout_cabinet_stream(package, &mi->cabinet[1], mi->source);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Failed to extract cabinet stream\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
2006-11-08 23:03:36 +01:00
|
|
|
}
|
2008-01-05 07:07:34 +01:00
|
|
|
else
|
2006-11-08 23:03:36 +01:00
|
|
|
lstrcatW(mi->source, mi->cabinet);
|
2005-06-24 14:14:35 +02:00
|
|
|
}
|
|
|
|
|
2008-02-26 08:54:14 +01:00
|
|
|
options = MSICODE_PRODUCT;
|
|
|
|
if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
|
|
|
|
{
|
|
|
|
source = source_dir;
|
|
|
|
options |= MSISOURCETYPE_MEDIA;
|
|
|
|
}
|
|
|
|
else if (package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
|
|
|
|
{
|
|
|
|
source = package->BaseURL;
|
|
|
|
options |= MSISOURCETYPE_URL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
source = mi->source;
|
|
|
|
options |= MSISOURCETYPE_NETWORK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE)
|
2008-04-05 07:10:02 +02:00
|
|
|
msi_package_add_media_disk(package, package->Context,
|
2008-02-26 08:54:14 +01:00
|
|
|
MSICODE_PRODUCT, mi->disk_id,
|
|
|
|
mi->volume_label, mi->disk_prompt);
|
2005-07-05 23:00:06 +02:00
|
|
|
|
2008-04-05 07:10:02 +02:00
|
|
|
msi_package_add_info(package, package->Context,
|
2008-02-26 08:54:14 +01:00
|
|
|
options, INSTALLPROPERTY_LASTUSEDSOURCEW, source);
|
2005-07-05 23:00:06 +02:00
|
|
|
|
2006-11-08 23:03:36 +01:00
|
|
|
msi_free(source_dir);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-07-05 23:00:06 +02:00
|
|
|
|
2008-02-26 08:55:56 +01:00
|
|
|
/* FIXME: search NETWORK and URL sources as well */
|
|
|
|
static UINT find_published_source(MSIPACKAGE *package, struct media_info *mi)
|
|
|
|
{
|
|
|
|
WCHAR source[MAX_PATH];
|
|
|
|
WCHAR volume[MAX_PATH];
|
|
|
|
WCHAR prompt[MAX_PATH];
|
|
|
|
DWORD volumesz, promptsz;
|
2008-03-20 08:04:49 +01:00
|
|
|
DWORD index, size, id;
|
2008-02-26 08:55:56 +01:00
|
|
|
UINT r;
|
|
|
|
|
|
|
|
r = MsiSourceListGetInfoW(package->ProductCode, NULL,
|
2008-04-05 07:10:02 +02:00
|
|
|
package->Context, MSICODE_PRODUCT,
|
2008-02-26 08:55:56 +01:00
|
|
|
INSTALLPROPERTY_LASTUSEDSOURCEW, source, &size);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
volumesz = MAX_PATH;
|
|
|
|
promptsz = MAX_PATH;
|
|
|
|
while (MsiSourceListEnumMediaDisksW(package->ProductCode, NULL,
|
2008-04-05 07:10:02 +02:00
|
|
|
package->Context,
|
2008-02-26 08:55:56 +01:00
|
|
|
MSICODE_PRODUCT, index++, &id,
|
|
|
|
volume, &volumesz, prompt, &promptsz) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
mi->disk_id = id;
|
|
|
|
mi->volume_label = msi_realloc(mi->volume_label, ++volumesz * sizeof(WCHAR));
|
|
|
|
lstrcpyW(mi->volume_label, volume);
|
|
|
|
mi->disk_prompt = msi_realloc(mi->disk_prompt, ++promptsz * sizeof(WCHAR));
|
|
|
|
lstrcpyW(mi->disk_prompt, prompt);
|
|
|
|
|
|
|
|
if (source_matches_volume(mi, source))
|
|
|
|
{
|
|
|
|
/* FIXME: what about SourceDir */
|
|
|
|
lstrcpyW(mi->source, source);
|
|
|
|
lstrcatW(mi->source, mi->cabinet);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2006-11-08 23:05:47 +01:00
|
|
|
static UINT ready_media(MSIPACKAGE *package, MSIFILE *file, struct media_info *mi)
|
2006-11-08 23:03:36 +01:00
|
|
|
{
|
2007-11-15 09:58:21 +01:00
|
|
|
UINT rc = ERROR_SUCCESS;
|
2005-07-05 23:00:06 +02:00
|
|
|
|
2006-11-08 23:07:53 +01:00
|
|
|
/* media info for continuous cabinet is already loaded */
|
|
|
|
if (mi->is_continuous)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2006-11-08 23:03:36 +01:00
|
|
|
rc = load_media_info(package, file, mi);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Unable to load media info\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
2006-10-27 02:13:52 +02:00
|
|
|
|
2007-11-28 21:56:53 +01:00
|
|
|
/* cabinet is internal, no checks needed */
|
|
|
|
if (!mi->cabinet || mi->cabinet[0] == '#')
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
2007-11-15 09:58:21 +01:00
|
|
|
/* package should be downloaded */
|
|
|
|
if (file->IsCompressed &&
|
|
|
|
GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES &&
|
|
|
|
package->BaseURL && UrlIsW(package->BaseURL, URLIS_URL))
|
2007-05-09 09:04:10 +02:00
|
|
|
{
|
2008-01-05 21:47:48 +01:00
|
|
|
WCHAR temppath[MAX_PATH];
|
|
|
|
|
|
|
|
msi_download_file(mi->source, temppath);
|
|
|
|
lstrcpyW(mi->source, temppath);
|
|
|
|
return ERROR_SUCCESS;
|
2007-05-09 09:04:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-15 09:58:21 +01:00
|
|
|
/* check volume matches, change media if not */
|
2007-11-26 01:02:55 +01:00
|
|
|
if (mi->volume_label && mi->disk_id > 1 &&
|
|
|
|
lstrcmpW(mi->first_volume, mi->volume_label))
|
2006-11-08 23:03:36 +01:00
|
|
|
{
|
2007-11-15 09:58:21 +01:00
|
|
|
LPWSTR source = msi_dup_property(package, cszSourceDir);
|
|
|
|
BOOL matches;
|
|
|
|
|
|
|
|
matches = source_matches_volume(mi, source);
|
|
|
|
msi_free(source);
|
2007-05-09 09:04:10 +02:00
|
|
|
|
2008-02-26 08:54:14 +01:00
|
|
|
if ((mi->type == DRIVE_CDROM || mi->type == DRIVE_REMOVABLE) && !matches)
|
2006-08-10 00:02:49 +02:00
|
|
|
{
|
2007-11-15 09:58:21 +01:00
|
|
|
rc = msi_change_media(package, mi);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return rc;
|
2006-11-08 23:03:36 +01:00
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
2005-07-05 23:00:06 +02:00
|
|
|
|
2007-11-17 00:29:18 +01:00
|
|
|
if (file->IsCompressed &&
|
2007-11-19 19:51:34 +01:00
|
|
|
GetFileAttributesW(mi->source) == INVALID_FILE_ATTRIBUTES)
|
2007-11-15 09:58:21 +01:00
|
|
|
{
|
2008-02-26 08:55:56 +01:00
|
|
|
/* FIXME: this might be done earlier in the install process */
|
|
|
|
rc = find_published_source(package, mi);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Cabinet not found: %s\n", debugstr_w(mi->source));
|
|
|
|
return ERROR_INSTALL_FAILURE;
|
|
|
|
}
|
2007-11-15 09:58:21 +01:00
|
|
|
}
|
2007-05-09 09:04:10 +02:00
|
|
|
|
2007-11-15 09:58:21 +01:00
|
|
|
return ERROR_SUCCESS;
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
2005-08-23 12:03:17 +02:00
|
|
|
static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
|
2006-01-23 17:29:50 +01:00
|
|
|
MSIFILE** file)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2006-01-23 17:29:50 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( *file, &package->files, MSIFILE, entry )
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2006-01-23 17:29:50 +01:00
|
|
|
if (lstrcmpW( file_key, (*file)->File )==0)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2006-01-23 17:29:50 +01:00
|
|
|
if ((*file)->state >= msifs_overwrite)
|
2005-06-17 22:56:55 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
else
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2006-11-08 00:11:26 +01:00
|
|
|
static void schedule_install_files(MSIPACKAGE *package)
|
|
|
|
{
|
|
|
|
MSIFILE *file;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
|
|
|
|
{
|
|
|
|
if (!ACTION_VerifyComponentForAction(file->Component, INSTALLSTATE_LOCAL))
|
|
|
|
{
|
|
|
|
TRACE("File %s is not scheduled for install\n", debugstr_w(file->File));
|
|
|
|
|
|
|
|
ui_progress(package,2,file->FileSize,0,0);
|
|
|
|
file->state = msifs_skipped;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-26 11:28:58 +01:00
|
|
|
static UINT copy_file(MSIFILE *file)
|
2006-11-08 00:12:22 +01:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
ret = CopyFileW(file->SourcePath, file->TargetPath, FALSE);
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
file->state = msifs_installed;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-02-26 11:28:58 +01:00
|
|
|
return GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT copy_install_file(MSIFILE *file)
|
|
|
|
{
|
|
|
|
UINT gle;
|
|
|
|
|
|
|
|
TRACE("Copying %s to %s\n", debugstr_w(file->SourcePath),
|
|
|
|
debugstr_w(file->TargetPath));
|
|
|
|
|
|
|
|
gle = copy_file(file);
|
|
|
|
if (gle == ERROR_SUCCESS)
|
|
|
|
return gle;
|
|
|
|
|
2006-11-08 00:12:22 +01:00
|
|
|
if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
|
|
|
|
{
|
|
|
|
TRACE("overwriting existing file\n");
|
|
|
|
gle = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if (gle == ERROR_FILE_NOT_FOUND)
|
|
|
|
{
|
|
|
|
/* FIXME: this needs to be tested, I'm pretty sure it fails */
|
|
|
|
TRACE("Source file not found\n");
|
|
|
|
gle = ERROR_SUCCESS;
|
|
|
|
}
|
2007-02-26 11:28:58 +01:00
|
|
|
else if (gle == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
|
|
|
|
|
|
|
|
gle = copy_file(file);
|
|
|
|
TRACE("Overwriting existing file: %d\n", gle);
|
|
|
|
}
|
2006-11-08 00:12:22 +01:00
|
|
|
else if (!(file->Attributes & msidbFileAttributesVital))
|
|
|
|
{
|
|
|
|
TRACE("Ignoring error for nonvital\n");
|
|
|
|
gle = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gle;
|
|
|
|
}
|
|
|
|
|
2007-11-26 01:01:19 +01:00
|
|
|
static BOOL check_dest_hash_matches(MSIFILE *file)
|
|
|
|
{
|
|
|
|
MSIFILEHASHINFO hash;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
if (!file->hash.dwFileHashInfoSize)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hash.dwFileHashInfoSize = sizeof(MSIFILEHASHINFO);
|
|
|
|
r = MsiGetFileHashW(file->TargetPath, 0, &hash);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return !memcmp(&hash, &file->hash, sizeof(MSIFILEHASHINFO));
|
|
|
|
}
|
|
|
|
|
2005-06-24 14:14:35 +02:00
|
|
|
/*
|
2005-11-02 11:56:42 +01:00
|
|
|
* ACTION_InstallFiles()
|
|
|
|
*
|
|
|
|
* For efficiency, this is done in two passes:
|
|
|
|
* 1) Correct all the TargetPaths and determine what files are to be installed.
|
|
|
|
* 2) Extract Cabinets and copy files.
|
2005-06-24 14:14:35 +02:00
|
|
|
*/
|
2005-06-17 22:56:55 +02:00
|
|
|
UINT ACTION_InstallFiles(MSIPACKAGE *package)
|
|
|
|
{
|
2005-09-23 12:05:08 +02:00
|
|
|
struct media_info *mi;
|
2005-06-17 22:56:55 +02:00
|
|
|
UINT rc = ERROR_SUCCESS;
|
2005-08-23 12:03:17 +02:00
|
|
|
MSIFILE *file;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
|
|
|
/* increment progress bar each time action data is sent */
|
|
|
|
ui_progress(package,1,1,0,0);
|
|
|
|
|
2006-11-08 00:11:26 +01:00
|
|
|
schedule_install_files(package);
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-10-29 13:29:17 +02:00
|
|
|
/*
|
|
|
|
* Despite MSDN specifying that the CreateFolders action
|
|
|
|
* should be called before InstallFiles, some installers don't
|
|
|
|
* do that, and they seem to work correctly. We need to create
|
|
|
|
* directories here to make sure that the files can be copied.
|
|
|
|
*/
|
|
|
|
msi_create_component_directories( package );
|
|
|
|
|
2006-11-08 00:10:22 +01:00
|
|
|
mi = msi_alloc_zero( sizeof(struct media_info) );
|
2005-09-23 12:05:08 +02:00
|
|
|
|
2005-08-23 12:03:17 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
2007-02-08 04:58:14 +01:00
|
|
|
if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
|
2005-10-29 12:31:06 +02:00
|
|
|
continue;
|
|
|
|
|
2007-11-26 01:01:19 +01:00
|
|
|
if (check_dest_hash_matches(file))
|
|
|
|
{
|
|
|
|
TRACE("File hashes match, not overwriting\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-02-04 05:54:42 +01:00
|
|
|
if (file->Sequence > mi->last_sequence || mi->is_continuous ||
|
|
|
|
(file->IsCompressed && !mi->is_extracted))
|
2005-06-24 14:14:35 +02:00
|
|
|
{
|
2006-11-08 23:05:47 +01:00
|
|
|
rc = ready_media(package, file, mi);
|
2006-11-08 23:04:54 +01:00
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Failed to ready media\n");
|
|
|
|
break;
|
|
|
|
}
|
2006-11-08 23:05:47 +01:00
|
|
|
|
|
|
|
if (file->IsCompressed && !extract_cabinet_file(package, mi))
|
|
|
|
{
|
|
|
|
ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
|
|
|
|
rc = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
2005-10-29 12:31:06 +02:00
|
|
|
}
|
2005-06-24 14:14:35 +02:00
|
|
|
|
2006-11-08 23:04:54 +01:00
|
|
|
set_file_source(package, file, mi->source);
|
|
|
|
|
2005-10-29 12:31:06 +02:00
|
|
|
TRACE("file paths %s to %s\n",debugstr_w(file->SourcePath),
|
|
|
|
debugstr_w(file->TargetPath));
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2006-11-08 23:05:47 +01:00
|
|
|
if (!file->IsCompressed)
|
2005-10-29 12:31:06 +02:00
|
|
|
{
|
2007-04-13 03:14:48 +02:00
|
|
|
msi_file_update_ui(package, file, szInstallFiles);
|
2006-11-08 23:05:47 +01:00
|
|
|
rc = copy_install_file(file);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
2006-10-27 09:42:14 +02:00
|
|
|
{
|
2006-11-08 23:05:47 +01:00
|
|
|
ERR("Failed to copy %s to %s (%d)\n", debugstr_w(file->SourcePath),
|
|
|
|
debugstr_w(file->TargetPath), rc);
|
2006-10-27 09:42:14 +02:00
|
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
2005-10-29 12:31:06 +02:00
|
|
|
}
|
2006-11-08 23:05:47 +01:00
|
|
|
else if (file->state != msifs_installed)
|
2005-10-29 12:31:06 +02:00
|
|
|
{
|
2006-11-08 23:05:47 +01:00
|
|
|
ERR("compressed file wasn't extracted (%s)\n", debugstr_w(file->TargetPath));
|
2006-11-08 00:12:22 +01:00
|
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
|
|
break;
|
2005-10-29 12:31:06 +02:00
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:05:08 +02:00
|
|
|
free_media_info( mi );
|
2005-06-17 22:56:55 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2005-06-20 17:33:22 +02:00
|
|
|
MSIPACKAGE *package = (MSIPACKAGE*)param;
|
|
|
|
WCHAR dest_name[0x100];
|
|
|
|
LPWSTR dest_path, dest;
|
|
|
|
LPCWSTR file_key, component;
|
|
|
|
DWORD sz;
|
|
|
|
DWORD rc;
|
2005-08-22 11:15:23 +02:00
|
|
|
MSICOMPONENT *comp;
|
2006-01-23 17:29:50 +01:00
|
|
|
MSIFILE *file;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
component = MSI_RecordGetString(row,2);
|
2005-08-22 11:15:23 +02:00
|
|
|
comp = get_loaded_component(package,component);
|
2005-06-20 17:33:22 +02:00
|
|
|
|
2005-10-29 13:36:48 +02:00
|
|
|
if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ))
|
2005-06-20 17:33:22 +02:00
|
|
|
{
|
|
|
|
TRACE("Skipping copy due to disabled component %s\n",
|
|
|
|
debugstr_w(component));
|
|
|
|
|
|
|
|
/* the action taken was the same as the current install state */
|
2005-08-22 11:15:23 +02:00
|
|
|
comp->Action = comp->Installed;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2005-06-20 17:33:22 +02:00
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-08-22 11:15:23 +02:00
|
|
|
comp->Action = INSTALLSTATE_LOCAL;
|
2005-06-20 17:33:22 +02:00
|
|
|
|
|
|
|
file_key = MSI_RecordGetString(row,3);
|
|
|
|
if (!file_key)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2005-06-20 17:33:22 +02:00
|
|
|
ERR("Unable to get file key\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
|
|
|
|
2006-01-23 17:29:50 +01:00
|
|
|
rc = get_file_target(package,file_key,&file);
|
2005-06-20 17:33:22 +02:00
|
|
|
|
|
|
|
if (rc != ERROR_SUCCESS)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2005-06-20 17:33:22 +02:00
|
|
|
ERR("Original file unknown %s\n",debugstr_w(file_key));
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
if (MSI_RecordIsNull(row,4))
|
2006-01-23 17:29:50 +01:00
|
|
|
strcpyW(dest_name,strrchrW(file->TargetPath,'\\')+1);
|
2005-06-20 17:33:22 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sz=0x100;
|
|
|
|
MSI_RecordGetStringW(row,4,dest_name,&sz);
|
|
|
|
reduce_to_longfilename(dest_name);
|
2005-06-24 14:14:35 +02:00
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
if (MSI_RecordIsNull(row,5))
|
|
|
|
{
|
|
|
|
LPWSTR p;
|
2006-01-23 17:29:50 +01:00
|
|
|
dest_path = strdupW(file->TargetPath);
|
2005-06-20 17:33:22 +02:00
|
|
|
p = strrchrW(dest_path,'\\');
|
|
|
|
if (p)
|
|
|
|
*p=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPCWSTR destkey;
|
|
|
|
destkey = MSI_RecordGetString(row,5);
|
2007-03-29 09:38:57 +02:00
|
|
|
dest_path = resolve_folder(package, destkey, FALSE, FALSE, TRUE, NULL);
|
2005-06-20 17:33:22 +02:00
|
|
|
if (!dest_path)
|
2005-06-17 22:56:55 +02:00
|
|
|
{
|
2005-06-21 22:03:30 +02:00
|
|
|
/* try a Property */
|
2005-09-15 17:04:08 +02:00
|
|
|
dest_path = msi_dup_property( package, destkey );
|
2005-06-21 22:03:30 +02:00
|
|
|
if (!dest_path)
|
|
|
|
{
|
|
|
|
FIXME("Unable to get destination folder, try AppSearch properties\n");
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
}
|
2005-06-20 17:33:22 +02:00
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
dest = build_directory_name(2, dest_path, dest_name);
|
2008-01-16 05:29:56 +01:00
|
|
|
create_full_pathW(dest_path);
|
2005-06-24 14:14:35 +02:00
|
|
|
|
2006-01-23 17:29:50 +01:00
|
|
|
TRACE("Duplicating file %s to %s\n",debugstr_w(file->TargetPath),
|
2005-06-24 14:14:35 +02:00
|
|
|
debugstr_w(dest));
|
|
|
|
|
2006-01-23 17:29:50 +01:00
|
|
|
if (strcmpW(file->TargetPath,dest))
|
|
|
|
rc = !CopyFileW(file->TargetPath,dest,TRUE);
|
2005-06-20 17:33:22 +02:00
|
|
|
else
|
|
|
|
rc = ERROR_SUCCESS;
|
2005-06-24 14:14:35 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
if (rc != ERROR_SUCCESS)
|
2006-10-05 06:41:22 +02:00
|
|
|
ERR("Failed to copy file %s -> %s, last error %d\n",
|
2006-01-23 17:29:50 +01:00
|
|
|
debugstr_w(file->TargetPath), debugstr_w(dest_path), GetLastError());
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
FIXME("We should track these duplicate files as well\n");
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(dest_path);
|
|
|
|
msi_free(dest);
|
2006-01-23 17:29:50 +01:00
|
|
|
|
|
|
|
msi_file_update_ui(package, file, szDuplicateFiles);
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
|
|
|
|
{
|
|
|
|
UINT rc;
|
|
|
|
MSIQUERY * view;
|
|
|
|
static const WCHAR ExecSeqQuery[] =
|
|
|
|
{'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
|
|
|
|
'`','D','u','p','l','i','c','a','t','e','F','i','l','e','`',0};
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
2005-06-17 22:56:55 +02:00
|
|
|
|
2005-06-20 17:33:22 +02:00
|
|
|
rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
|
2005-06-17 22:56:55 +02:00
|
|
|
msiobj_release(&view->hdr);
|
2005-06-20 17:33:22 +02:00
|
|
|
|
2005-06-17 22:56:55 +02:00
|
|
|
return rc;
|
|
|
|
}
|
2005-11-02 12:42:56 +01:00
|
|
|
|
2006-08-10 22:53:08 +02:00
|
|
|
/* compares the version of a file read from the filesystem and
|
|
|
|
* the version specified in the File table
|
|
|
|
*/
|
|
|
|
static int msi_compare_file_version( MSIFILE *file )
|
|
|
|
{
|
|
|
|
WCHAR version[MAX_PATH];
|
|
|
|
DWORD size;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
size = MAX_PATH;
|
|
|
|
version[0] = '\0';
|
|
|
|
r = MsiGetFileVersionW( file->TargetPath, version, &size, NULL, NULL );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return lstrcmpW( version, file->Version );
|
|
|
|
}
|
|
|
|
|
2005-11-02 12:42:56 +01:00
|
|
|
UINT ACTION_RemoveFiles( MSIPACKAGE *package )
|
|
|
|
{
|
|
|
|
MSIFILE *file;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
|
|
|
{
|
2006-01-23 17:29:50 +01:00
|
|
|
MSIRECORD *uirow;
|
|
|
|
LPWSTR uipath, p;
|
|
|
|
|
2005-11-02 12:42:56 +01:00
|
|
|
if ( !file->Component )
|
|
|
|
continue;
|
|
|
|
if ( file->Component->Installed == INSTALLSTATE_LOCAL )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( file->state == msifs_installed )
|
|
|
|
ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
|
|
|
|
|
|
|
|
if ( file->state != msifs_present )
|
|
|
|
continue;
|
|
|
|
|
2006-08-10 22:53:08 +02:00
|
|
|
/* only remove a file if the version to be installed
|
|
|
|
* is strictly newer than the old file
|
|
|
|
*/
|
|
|
|
if ( msi_compare_file_version( file ) >= 0 )
|
|
|
|
continue;
|
|
|
|
|
2005-11-02 12:42:56 +01:00
|
|
|
TRACE("removing %s\n", debugstr_w(file->File) );
|
|
|
|
if ( !DeleteFileW( file->TargetPath ) )
|
|
|
|
ERR("failed to delete %s\n", debugstr_w(file->TargetPath) );
|
|
|
|
file->state = msifs_missing;
|
2006-01-23 17:29:50 +01:00
|
|
|
|
|
|
|
/* the UI chunk */
|
|
|
|
uirow = MSI_CreateRecord( 9 );
|
|
|
|
MSI_RecordSetStringW( uirow, 1, file->FileName );
|
|
|
|
uipath = strdupW( file->TargetPath );
|
|
|
|
p = strrchrW(uipath,'\\');
|
|
|
|
if (p)
|
|
|
|
p[1]=0;
|
|
|
|
MSI_RecordSetStringW( uirow, 9, uipath);
|
|
|
|
ui_actiondata( package, szRemoveFiles, uirow);
|
|
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
msi_free( uipath );
|
|
|
|
/* FIXME: call ui_progress here? */
|
2005-11-02 12:42:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|