2005-06-17 20:56:55 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-06-17 20:56:55 +00: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 21:00:06 +00:00
|
|
|
#include "msi.h"
|
2005-06-17 20:56:55 +00:00
|
|
|
#include "msidefs.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winuser.h"
|
2006-08-09 22:02:49 +00:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
2005-06-17 20:56:55 +00:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2006-01-23 16:29:50 +00:00
|
|
|
static void msi_file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
|
2005-10-28 10:43:50 +00: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 16:29:50 +00:00
|
|
|
ui_actiondata( package, action, uirow);
|
2005-10-28 10:43:50 +00:00
|
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
msi_free( uipath );
|
|
|
|
ui_progress( package, 2, f->FileSize, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-06-24 04:41:22 +00: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-08-23 10:03:17 +00:00
|
|
|
static UINT get_file_target(MSIPACKAGE *package, LPCWSTR file_key,
|
2006-01-23 16:29:50 +00:00
|
|
|
MSIFILE** file)
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2006-01-23 16:29:50 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( *file, &package->files, MSIFILE, entry )
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2006-01-23 16:29:50 +00:00
|
|
|
if (lstrcmpW( file_key, (*file)->File )==0)
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2006-01-23 16:29:50 +00:00
|
|
|
if ((*file)->state >= msifs_overwrite)
|
2005-06-17 20:56:55 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
else
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2006-11-07 23:11:26 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-07 03:26:20 +00:00
|
|
|
static UINT copy_file(MSIFILE *file, LPWSTR source)
|
2006-11-07 23:12:22 +00:00
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2008-10-07 03:26:20 +00:00
|
|
|
ret = CopyFileW(source, file->TargetPath, FALSE);
|
2008-09-08 10:15:27 +00:00
|
|
|
if (!ret)
|
|
|
|
return GetLastError();
|
|
|
|
|
|
|
|
SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
|
2006-11-07 23:12:22 +00:00
|
|
|
|
2008-09-08 10:15:27 +00:00
|
|
|
file->state = msifs_installed;
|
|
|
|
return ERROR_SUCCESS;
|
2007-02-26 10:28:58 +00:00
|
|
|
}
|
|
|
|
|
2009-10-01 09:53:20 +00:00
|
|
|
static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
|
2007-02-26 10:28:58 +00:00
|
|
|
{
|
|
|
|
UINT gle;
|
|
|
|
|
2008-10-07 03:26:20 +00:00
|
|
|
TRACE("Copying %s to %s\n", debugstr_w(source),
|
2007-02-26 10:28:58 +00:00
|
|
|
debugstr_w(file->TargetPath));
|
|
|
|
|
2008-10-07 03:26:20 +00:00
|
|
|
gle = copy_file(file, source);
|
2007-02-26 10:28:58 +00:00
|
|
|
if (gle == ERROR_SUCCESS)
|
|
|
|
return gle;
|
|
|
|
|
2006-11-07 23:12:22 +00:00
|
|
|
if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
|
|
|
|
{
|
|
|
|
TRACE("overwriting existing file\n");
|
2009-10-01 09:53:20 +00:00
|
|
|
return ERROR_SUCCESS;
|
2006-11-07 23:12:22 +00:00
|
|
|
}
|
2007-02-26 10:28:58 +00:00
|
|
|
else if (gle == ERROR_ACCESS_DENIED)
|
|
|
|
{
|
|
|
|
SetFileAttributesW(file->TargetPath, FILE_ATTRIBUTE_NORMAL);
|
|
|
|
|
2008-10-07 03:26:20 +00:00
|
|
|
gle = copy_file(file, source);
|
2007-02-26 10:28:58 +00:00
|
|
|
TRACE("Overwriting existing file: %d\n", gle);
|
|
|
|
}
|
2009-10-30 13:10:27 +00:00
|
|
|
if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
|
2009-10-01 09:53:20 +00:00
|
|
|
{
|
|
|
|
WCHAR tmpfileW[MAX_PATH], *pathW, *p;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
TRACE("file in use, scheduling rename operation\n");
|
|
|
|
|
2009-10-15 10:46:27 +00:00
|
|
|
GetTempFileNameW(szBackSlash, szMsi, 0, tmpfileW);
|
2009-10-01 09:53:20 +00:00
|
|
|
len = strlenW(file->TargetPath) + strlenW(tmpfileW) + 1;
|
|
|
|
if (!(pathW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
strcpyW(pathW, file->TargetPath);
|
|
|
|
if ((p = strrchrW(pathW, '\\'))) *p = 0;
|
|
|
|
strcatW(pathW, tmpfileW);
|
|
|
|
|
|
|
|
if (CopyFileW(source, pathW, FALSE) &&
|
|
|
|
MoveFileExW(file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT) &&
|
|
|
|
MoveFileExW(pathW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT))
|
|
|
|
{
|
|
|
|
file->state = msifs_installed;
|
|
|
|
package->need_reboot = 1;
|
|
|
|
gle = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gle = GetLastError();
|
|
|
|
WARN("failed to schedule rename operation: %d)\n", gle);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, pathW);
|
|
|
|
}
|
2006-11-07 23:12:22 +00:00
|
|
|
|
|
|
|
return gle;
|
|
|
|
}
|
|
|
|
|
2007-11-26 00:01:19 +00: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));
|
|
|
|
}
|
|
|
|
|
2008-08-19 03:59:44 +00:00
|
|
|
static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
|
|
|
|
LPWSTR *path, DWORD *attrs, PVOID user)
|
|
|
|
{
|
|
|
|
static MSIFILE *f = NULL;
|
|
|
|
|
|
|
|
if (action == MSICABEXTRACT_BEGINEXTRACT)
|
|
|
|
{
|
|
|
|
f = get_loaded_file(package, file);
|
|
|
|
if (!f)
|
|
|
|
{
|
|
|
|
WARN("unknown file in cabinet (%s)\n", debugstr_w(file));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f->state != msifs_missing && f->state != msifs_overwrite)
|
|
|
|
{
|
|
|
|
TRACE("Skipping extraction of %s\n", debugstr_w(file));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
msi_file_update_ui(package, f, szInstallFiles);
|
|
|
|
|
|
|
|
*path = strdupW(f->TargetPath);
|
|
|
|
*attrs = f->Attributes;
|
|
|
|
}
|
|
|
|
else if (action == MSICABEXTRACT_FILEEXTRACTED)
|
|
|
|
{
|
|
|
|
f->state = msifs_installed;
|
|
|
|
f = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-24 12:14:35 +00:00
|
|
|
/*
|
2005-11-02 10:56:42 +00: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 12:14:35 +00:00
|
|
|
*/
|
2005-06-17 20:56:55 +00:00
|
|
|
UINT ACTION_InstallFiles(MSIPACKAGE *package)
|
|
|
|
{
|
2008-04-30 09:22:46 +00:00
|
|
|
MSIMEDIAINFO *mi;
|
2005-06-17 20:56:55 +00:00
|
|
|
UINT rc = ERROR_SUCCESS;
|
2005-08-23 10:03:17 +00:00
|
|
|
MSIFILE *file;
|
2005-06-17 20:56:55 +00:00
|
|
|
|
|
|
|
/* increment progress bar each time action data is sent */
|
|
|
|
ui_progress(package,1,1,0,0);
|
|
|
|
|
2006-11-07 23:11:26 +00:00
|
|
|
schedule_install_files(package);
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-10-29 11:29:17 +00: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 );
|
|
|
|
|
2008-04-30 09:22:46 +00:00
|
|
|
mi = msi_alloc_zero( sizeof(MSIMEDIAINFO) );
|
2005-09-23 10:05:08 +00:00
|
|
|
|
2005-08-23 10:03:17 +00:00
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
2005-06-24 12:14:35 +00:00
|
|
|
{
|
2007-02-08 03:58:14 +00:00
|
|
|
if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
|
2005-10-29 10:31:06 +00:00
|
|
|
continue;
|
|
|
|
|
2007-11-26 00:01:19 +00:00
|
|
|
if (check_dest_hash_matches(file))
|
|
|
|
{
|
|
|
|
TRACE("File hashes match, not overwriting\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2008-06-24 04:41:22 +00:00
|
|
|
if (MsiGetFileVersionW(file->TargetPath, NULL, NULL, NULL, NULL) == ERROR_SUCCESS &&
|
|
|
|
msi_compare_file_version(file) >= 0)
|
|
|
|
{
|
|
|
|
TRACE("Destination file version greater, not overwriting\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-02-04 04:54:42 +00:00
|
|
|
if (file->Sequence > mi->last_sequence || mi->is_continuous ||
|
|
|
|
(file->IsCompressed && !mi->is_extracted))
|
2005-06-24 12:14:35 +00:00
|
|
|
{
|
2008-08-19 03:59:44 +00:00
|
|
|
MSICABDATA data;
|
2008-04-30 09:22:46 +00:00
|
|
|
|
2006-11-08 22:05:47 +00:00
|
|
|
rc = ready_media(package, file, mi);
|
2006-11-08 22:04:54 +00:00
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("Failed to ready media\n");
|
|
|
|
break;
|
|
|
|
}
|
2006-11-08 22:05:47 +00:00
|
|
|
|
2008-04-30 09:22:46 +00:00
|
|
|
data.mi = mi;
|
|
|
|
data.package = package;
|
2008-08-19 03:59:44 +00:00
|
|
|
data.cb = installfiles_cb;
|
|
|
|
data.user = NULL;
|
2008-04-30 09:22:46 +00:00
|
|
|
|
|
|
|
if (file->IsCompressed &&
|
2008-08-19 03:59:44 +00:00
|
|
|
!msi_cabextract(package, mi, &data))
|
2006-11-08 22:05:47 +00:00
|
|
|
{
|
|
|
|
ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
|
|
|
|
rc = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
2005-10-29 10:31:06 +00:00
|
|
|
}
|
2005-06-24 12:14:35 +00:00
|
|
|
|
2006-11-08 22:05:47 +00:00
|
|
|
if (!file->IsCompressed)
|
2005-10-29 10:31:06 +00:00
|
|
|
{
|
2008-10-07 03:26:20 +00:00
|
|
|
LPWSTR source = resolve_file_source(package, file);
|
|
|
|
|
|
|
|
TRACE("file paths %s to %s\n", debugstr_w(source),
|
2008-06-10 22:35:10 +00:00
|
|
|
debugstr_w(file->TargetPath));
|
|
|
|
|
2007-04-13 01:14:48 +00:00
|
|
|
msi_file_update_ui(package, file, szInstallFiles);
|
2009-10-01 09:53:20 +00:00
|
|
|
rc = copy_install_file(package, file, source);
|
2006-11-08 22:05:47 +00:00
|
|
|
if (rc != ERROR_SUCCESS)
|
2006-10-27 07:42:14 +00:00
|
|
|
{
|
2008-10-07 03:26:20 +00:00
|
|
|
ERR("Failed to copy %s to %s (%d)\n", debugstr_w(source),
|
2006-11-08 22:05:47 +00:00
|
|
|
debugstr_w(file->TargetPath), rc);
|
2006-10-27 07:42:14 +00:00
|
|
|
rc = ERROR_INSTALL_FAILURE;
|
2008-10-07 03:26:20 +00:00
|
|
|
msi_free(source);
|
2006-10-27 07:42:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-07 03:26:20 +00:00
|
|
|
|
|
|
|
msi_free(source);
|
2005-10-29 10:31:06 +00:00
|
|
|
}
|
2006-11-08 22:05:47 +00:00
|
|
|
else if (file->state != msifs_installed)
|
2005-10-29 10:31:06 +00:00
|
|
|
{
|
2008-10-07 03:26:20 +00:00
|
|
|
ERR("compressed file wasn't extracted (%s)\n",
|
|
|
|
debugstr_w(file->TargetPath));
|
2006-11-07 23:12:22 +00:00
|
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
|
|
break;
|
2005-10-29 10:31:06 +00:00
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
}
|
|
|
|
|
2008-08-19 03:59:44 +00:00
|
|
|
msi_free_media_info(mi);
|
2005-06-17 20:56:55 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2009-01-15 08:46:57 +00:00
|
|
|
MSIPACKAGE *package = param;
|
2005-06-20 15:33:22 +00:00
|
|
|
WCHAR dest_name[0x100];
|
|
|
|
LPWSTR dest_path, dest;
|
|
|
|
LPCWSTR file_key, component;
|
|
|
|
DWORD sz;
|
|
|
|
DWORD rc;
|
2005-08-22 09:15:23 +00:00
|
|
|
MSICOMPONENT *comp;
|
2006-01-23 16:29:50 +00:00
|
|
|
MSIFILE *file;
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
component = MSI_RecordGetString(row,2);
|
2005-08-22 09:15:23 +00:00
|
|
|
comp = get_loaded_component(package,component);
|
2005-06-20 15:33:22 +00:00
|
|
|
|
2005-10-29 11:36:48 +00:00
|
|
|
if (!ACTION_VerifyComponentForAction( comp, INSTALLSTATE_LOCAL ))
|
2005-06-20 15:33:22 +00: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 09:15:23 +00:00
|
|
|
comp->Action = comp->Installed;
|
2005-06-17 20:56:55 +00:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2005-06-20 15:33:22 +00:00
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-08-22 09:15:23 +00:00
|
|
|
comp->Action = INSTALLSTATE_LOCAL;
|
2005-06-20 15:33:22 +00:00
|
|
|
|
|
|
|
file_key = MSI_RecordGetString(row,3);
|
|
|
|
if (!file_key)
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2005-06-20 15:33:22 +00:00
|
|
|
ERR("Unable to get file key\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2005-06-17 20:56:55 +00:00
|
|
|
}
|
|
|
|
|
2006-01-23 16:29:50 +00:00
|
|
|
rc = get_file_target(package,file_key,&file);
|
2005-06-20 15:33:22 +00:00
|
|
|
|
|
|
|
if (rc != ERROR_SUCCESS)
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2005-06-20 15:33:22 +00:00
|
|
|
ERR("Original file unknown %s\n",debugstr_w(file_key));
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
if (MSI_RecordIsNull(row,4))
|
2006-01-23 16:29:50 +00:00
|
|
|
strcpyW(dest_name,strrchrW(file->TargetPath,'\\')+1);
|
2005-06-20 15:33:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
sz=0x100;
|
|
|
|
MSI_RecordGetStringW(row,4,dest_name,&sz);
|
|
|
|
reduce_to_longfilename(dest_name);
|
2005-06-24 12:14:35 +00:00
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
if (MSI_RecordIsNull(row,5))
|
|
|
|
{
|
|
|
|
LPWSTR p;
|
2006-01-23 16:29:50 +00:00
|
|
|
dest_path = strdupW(file->TargetPath);
|
2005-06-20 15:33:22 +00:00
|
|
|
p = strrchrW(dest_path,'\\');
|
|
|
|
if (p)
|
|
|
|
*p=0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LPCWSTR destkey;
|
|
|
|
destkey = MSI_RecordGetString(row,5);
|
2007-03-29 07:38:57 +00:00
|
|
|
dest_path = resolve_folder(package, destkey, FALSE, FALSE, TRUE, NULL);
|
2005-06-20 15:33:22 +00:00
|
|
|
if (!dest_path)
|
2005-06-17 20:56:55 +00:00
|
|
|
{
|
2005-06-21 20:03:30 +00:00
|
|
|
/* try a Property */
|
2005-09-15 15:04:08 +00:00
|
|
|
dest_path = msi_dup_property( package, destkey );
|
2005-06-21 20:03:30 +00:00
|
|
|
if (!dest_path)
|
|
|
|
{
|
|
|
|
FIXME("Unable to get destination folder, try AppSearch properties\n");
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
}
|
2005-06-20 15:33:22 +00:00
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
dest = build_directory_name(2, dest_path, dest_name);
|
2008-01-16 04:29:56 +00:00
|
|
|
create_full_pathW(dest_path);
|
2005-06-24 12:14:35 +00:00
|
|
|
|
2006-01-23 16:29:50 +00:00
|
|
|
TRACE("Duplicating file %s to %s\n",debugstr_w(file->TargetPath),
|
2005-06-24 12:14:35 +00:00
|
|
|
debugstr_w(dest));
|
|
|
|
|
2006-01-23 16:29:50 +00:00
|
|
|
if (strcmpW(file->TargetPath,dest))
|
|
|
|
rc = !CopyFileW(file->TargetPath,dest,TRUE);
|
2005-06-20 15:33:22 +00:00
|
|
|
else
|
|
|
|
rc = ERROR_SUCCESS;
|
2005-06-24 12:14:35 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
if (rc != ERROR_SUCCESS)
|
2006-10-05 04:41:22 +00:00
|
|
|
ERR("Failed to copy file %s -> %s, last error %d\n",
|
2006-01-23 16:29:50 +00:00
|
|
|
debugstr_w(file->TargetPath), debugstr_w(dest_path), GetLastError());
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
FIXME("We should track these duplicate files as well\n");
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(dest_path);
|
|
|
|
msi_free(dest);
|
2006-01-23 16:29:50 +00:00
|
|
|
|
|
|
|
msi_file_update_ui(package, file, szDuplicateFiles);
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00: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 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
rc = MSI_DatabaseOpenViewW(package->db, ExecSeqQuery, &view);
|
|
|
|
if (rc != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
2005-06-17 20:56:55 +00:00
|
|
|
|
2005-06-20 15:33:22 +00:00
|
|
|
rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
|
2005-06-17 20:56:55 +00:00
|
|
|
msiobj_release(&view->hdr);
|
2005-06-20 15:33:22 +00:00
|
|
|
|
2005-06-17 20:56:55 +00:00
|
|
|
return rc;
|
|
|
|
}
|
2005-11-02 11:42:56 +00:00
|
|
|
|
2008-08-19 04:03:00 +00:00
|
|
|
static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
|
|
|
|
{
|
|
|
|
INSTALLSTATE request = comp->ActionRequest;
|
|
|
|
|
2008-08-21 07:18:40 +00:00
|
|
|
if (request == INSTALLSTATE_UNKNOWN)
|
|
|
|
return FALSE;
|
|
|
|
|
2008-08-19 04:03:00 +00:00
|
|
|
if (install_mode == msidbRemoveFileInstallModeOnInstall &&
|
|
|
|
(request == INSTALLSTATE_LOCAL || request == INSTALLSTATE_SOURCE))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (request == INSTALLSTATE_ABSENT)
|
|
|
|
{
|
|
|
|
if (!comp->ComponentId)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (install_mode == msidbRemoveFileInstallModeOnRemove)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (install_mode == msidbRemoveFileInstallModeOnBoth)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
|
|
|
|
{
|
2009-01-15 08:46:57 +00:00
|
|
|
MSIPACKAGE *package = param;
|
2008-08-19 04:03:00 +00:00
|
|
|
MSICOMPONENT *comp;
|
|
|
|
LPCWSTR component, filename, dirprop;
|
|
|
|
UINT install_mode;
|
|
|
|
LPWSTR dir = NULL, path = NULL;
|
|
|
|
DWORD size;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
component = MSI_RecordGetString(row, 2);
|
|
|
|
filename = MSI_RecordGetString(row, 3);
|
|
|
|
dirprop = MSI_RecordGetString(row, 4);
|
|
|
|
install_mode = MSI_RecordGetInteger(row, 5);
|
|
|
|
|
|
|
|
comp = get_loaded_component(package, component);
|
|
|
|
if (!comp)
|
|
|
|
{
|
|
|
|
ERR("Invalid component: %s\n", debugstr_w(component));
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!verify_comp_for_removal(comp, install_mode))
|
|
|
|
{
|
|
|
|
TRACE("Skipping removal due to missing conditions\n");
|
|
|
|
comp->Action = comp->Installed;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
dir = msi_dup_property(package, dirprop);
|
|
|
|
if (!dir)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2008-08-21 07:14:59 +00:00
|
|
|
size = (filename != NULL) ? lstrlenW(filename) : 0;
|
|
|
|
size += lstrlenW(dir) + 2;
|
2008-08-19 04:03:00 +00:00
|
|
|
path = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
lstrcpyW(path, dir);
|
2008-08-21 07:14:59 +00:00
|
|
|
PathAddBackslashW(path);
|
2008-08-19 04:03:00 +00:00
|
|
|
|
2008-08-21 07:14:59 +00:00
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
lstrcatW(path, filename);
|
|
|
|
|
|
|
|
TRACE("Deleting misc file: %s\n", debugstr_w(path));
|
|
|
|
DeleteFileW(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("Removing misc directory: %s\n", debugstr_w(path));
|
|
|
|
RemoveDirectoryW(path);
|
|
|
|
}
|
2008-08-19 04:03:00 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(path);
|
|
|
|
msi_free(dir);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-11-02 11:42:56 +00:00
|
|
|
UINT ACTION_RemoveFiles( MSIPACKAGE *package )
|
|
|
|
{
|
2008-08-19 04:03:00 +00:00
|
|
|
MSIQUERY *view;
|
2005-11-02 11:42:56 +00:00
|
|
|
MSIFILE *file;
|
2008-08-19 04:03:00 +00:00
|
|
|
UINT r;
|
|
|
|
|
|
|
|
static const WCHAR query[] = {
|
|
|
|
'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ',
|
|
|
|
'`','R','e','m','o','v','e','F','i','l','e','`',0};
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW(package->db, query, &view);
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
MSI_IterateRecords(view, NULL, ITERATE_RemoveFiles, package);
|
|
|
|
msiobj_release(&view->hdr);
|
|
|
|
}
|
2005-11-02 11:42:56 +00:00
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
|
|
|
{
|
2006-01-23 16:29:50 +00:00
|
|
|
MSIRECORD *uirow;
|
|
|
|
LPWSTR uipath, p;
|
|
|
|
|
2005-11-02 11:42:56 +00:00
|
|
|
if ( file->state == msifs_installed )
|
|
|
|
ERR("removing installed file %s\n", debugstr_w(file->TargetPath));
|
|
|
|
|
2008-08-21 07:17:15 +00:00
|
|
|
if ( file->Component->ActionRequest != INSTALLSTATE_ABSENT ||
|
|
|
|
file->Component->Installed == INSTALLSTATE_SOURCE )
|
2005-11-02 11:42:56 +00:00
|
|
|
continue;
|
|
|
|
|
2008-08-19 04:01:36 +00:00
|
|
|
/* don't remove a file if the old file
|
|
|
|
* is strictly newer than the version to be installed
|
2006-08-10 20:53:08 +00:00
|
|
|
*/
|
2008-08-19 04:01:36 +00:00
|
|
|
if ( msi_compare_file_version( file ) < 0 )
|
2006-08-10 20:53:08 +00:00
|
|
|
continue;
|
|
|
|
|
2005-11-02 11:42:56 +00:00
|
|
|
TRACE("removing %s\n", debugstr_w(file->File) );
|
|
|
|
if ( !DeleteFileW( file->TargetPath ) )
|
2008-08-21 07:15:31 +00:00
|
|
|
TRACE("failed to delete %s\n", debugstr_w(file->TargetPath));
|
2005-11-02 11:42:56 +00:00
|
|
|
file->state = msifs_missing;
|
2006-01-23 16:29:50 +00: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 11:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|