mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 10:35:28 +00:00
f4be6dc36f
* [MSIEXEC] Sync msiexec to wine-9.8 * [WINESYNC] msi: Disable FS redirection for temporary file in cabinet_copy_file(). wine commit id a58c6251870dfb7d214464e709bbbc9ca649b900 by Paul Gofman <pgofman@codeweavers.com> * [WINESYNC] msi/tests: Correct a couple of failure messages in test_msirecord. wine commit id 2fde0a3f5c233b0ea1637f409998ce4ee85d28a7 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Use the wcsdup function instead of reimplementing it. wine commit id 7cc7a6defc08d4de7574b7a75d574c3ab1f32db8 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Use _O_* constants from fcntl.h instead of redefining them. wine commit id b07c95e79cdf6ae26c5170daa481ad160e0ce76a by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Remove wrappers around CRT memory allocation functions. wine commit id d920aa81ad0c4618c27ebd7e9863618e988328e0 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Initialize all members of WINTRUST_DATA. The pSignatureSettings field was not unitilized so it got a random value from the stack causing a later crash when it was dereferenced in Wintrust (SoftPubloadSignature). wine commit id 904bedb3e96bc68101652e151db102532399abe8 by Philip K. Gisslow <ripxorip@gmail.com> * [WINESYNC] msi: Fix memory leak on realloc failure in create_diff_row_query (cppcheck). wine commit id 3e231d0f36a56ce991c7edbb6ae7845094e8417e by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak on realloc failure in msi_get_window_text (cppcheck). wine commit id 6c1dd0f2c5669e084eb1f84571c38761a97c0970 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak on realloc failure in search_directory (cppcheck). wine commit id d394df4a30feb685927908fce2887bf5496b5d66 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] ntdll: Default to Windows 10. wine commit id 69154f0329aec4fb64886a0689da198b5323dcde by Hans Leidekker <hans@codeweavers.com> * [MSI] Fix build * [WINESYNC] Update winesync file * [WINESYNC] msi/tests: Avoid test failures when running with insufficient rights. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51040 wine commit id 79ec3d9fb8551e84e9ff71dcf18861430246278a by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Install and patch global assemblies in InstallFinalize. Installing global assemblies requires assembly caches to be initialized and this is no longer the case after the PE conversion (builtin fusion no longer loads if the dll is not present on disk). The next patch changes msi to perform late initialization of the assembly caches so that native fusion can be loaded once it's installed by .NET installers. However, there's no guarantee that all necessary files and registry keys are installed before the InstallFiles and PatchFiles actions are executed. Therefore this patch moves the parts of these actions handling global assemblies to InstallFinalize. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51345 wine commit id 2c450fd6215c0da4685143f97ece8b6db0f54a0b by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Perform late initialization of the assembly caches. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51345 wine commit id d9d700f3328f00ec419571df0e02cef208fa1e7b by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Remove msi_ prefix from static functions. wine commit id 3611398b7575177b91e8162a84ebca977c50c2f5 by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Get rid of unnecessary typedefs. wine commit id 258012742512a4072265fcc47826c52319bd37ab by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Handle memory allocation failure in get_link_file (cppcheck). wine commit id 687c4f5c8dc65def6fc066d5d802d7448db70d7f by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Annotate memory allocation functions with __WINE_(DEALLOC|MALLOC). wine commit id 9df04bfdb03a3017f532e70a047ee83290dbc257 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi/tests: Fix the ok() formats so they match the size of their arguments. wine commit id b6fb1b8983af7644b78bb0ba5fb9d18a1f0822f1 by Francois Gouget <fgouget@codeweavers.com> * [WINESYNC] msi/tests: Ok_() takes printf-style arguments. This lets the compiler check that the format and argument sizes match. wine commit id a80b183af74194a06af3281ee272590a7134b7f1 by Francois Gouget <fgouget@codeweavers.com> * [WINESYNC] msi: Return ERROR_OUTOFMEMORY if calloc fails in TransformView_Create (scan-build). Instead of ERROR_SUCCESS. wine commit id daa20d9d636057d7009ff3652a8577b423d23fcf by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Make TransformView_Create static. wine commit id 1da5618cbac1214082bfb897dc81804d14fc6e9e by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak in ready_media (scan-build). base_url was never freed, and can simply be enlarged instead of copying it to a new buffer. wine commit id c39f785b34692ee994b2449cc17a96815517e9bf by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leak on error path in MSI_ProcessMessage (scan-build). wine commit id d06b3fd5274b056c720e2fb42eb189052d99404d by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Release record instead of free. ../dlls/msi/dialog.c:4476:11: warning: attempt to call free on non-heap object 'hdr' [-Wfree-nonheap-object] free( &rec->hdr ); ^ wine commit id 7b3690dd7399cd64123554c8a6fc7e35dcbebbe1 by Daniel Lehman <dlehman25@gmail.com> * [WINESYNC] include: Remove redundant __WINE_USE_MSVCRT checks. wine commit id 93630ce14ebf16333fda8481b5ede6f587eb32ca by Alexandre Julliard <julliard@winehq.org> * [WINESYNC] msi: Fix memory leak on error path in MSI_OpenPackageW (scan-build). wine commit id 4db2ffa60e16e06b4f6ef89fcc4c73229f4446b1 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix double free on error paths in TransformView_Create (scan-build). If TransformView_Create returns an error, it should not return a pointer that table_load_transform will try to free. wine commit id 0653409e0631582d89edaab0ac516994710dae1a by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Fix memory leaks in HANDLE_CustomType23 (scan-build). wine commit id 993f4d48d23477e70e92256890c77687a1c4ba08 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Reject shorter/longer lines in MsiDatabaseImportA. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54532 Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id e1ddc58a259d80f16bf1e62f23428775e1b070a0 by David Kahurani <k.kahurani@gmail.com> * [WINESYNC] msi: Convert newlines to alternate representation when exporting. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=54532 Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id 60e4f8a261ae9044aafa9c4eec2a3f2aec6481b5 by David Kahurani <k.kahurani@gmail.com> * [WINESYNC] msi: Remove DECLSPEC_HIDDEN usage. wine commit id 51049c95a242f1553562a442142e813e37cee233 by Alistair Leslie-Hughes <leslie_alistair@hotmail.com> * [MSI] remove DECLSPEC_HIDDEN * [WINESYNC] msi: Fully initialize the control structure in dialog_line_control(). Fixes: 76606eaea034c51a73190aac92e75d8b20e82164 Fixes: 174b7b51ac9e57c6cfa8f48e62bbf468ae3b1f24 wine commit id 735584076efafc29673e0c9418a64343634f9aa5 by Jinoh Kang <jinoh.kang.kr@gmail.com> * [WINESYNC] msi: Make insertion order of line controls consistent with other controls. Fixes: 2c5bd49297f79d9941a256d8ec61e0eb2bf9bf9c wine commit id 3eceda2f2a77754f0bf93ea33018e8ef49e82669 by Jinoh Kang <jinoh.kang.kr@gmail.com> * [WINESYNC] msi: Don't open code dialog_add_control() in dialog_line_control(). Commit b1cc87cb656 ("msi: The line control has a height of exactly 2 device units.", 2007-12-16) open-coded the body of (msi_)dialog_add_control() inside dialog_line_control() modulo the height override. Except the fixed height, line controls have nothing special compared to other controls. Thus, there is little merit in open-coding it. Also, dialog_line_control() has bit-rotted over time; it already missed a few changes that were done to any other controls. Fix this by just using dialog_add_control(). Also, add a special case logic just for line controls. wine commit id 1fca47b724b3835ac0267f58c5b3486fc222fc71 by Jinoh Kang <jinoh.kang.kr@gmail.com> * [WINESYNC] msi: Use nameless unions/structs. wine commit id 8de0a9dc740d3ed1e3cf9460852db7e609122f3b by Alexandre Julliard <julliard@winehq.org> * [MSI] disable nameless structs * [WINESYNC] msi/tests: Use nameless unions/structs. wine commit id 490aee03e45222aa9d7e3e7fd6ff80064dc3778d by Alexandre Julliard <julliard@winehq.org> * [WINESYNC] makedep: Use #pragma makedep testdll for TESTDLL resources. wine commit id 81da9ff0f8dea4932a3afdc4c447c1c9242bb596 by Rémi Bernon <rbernon@codeweavers.com> * [WINESYNC] msi: Use CreateFileW() for handling path from cabinet_open() instead. wine commit id 085e95cd5eceb36c3e21cb7d42adab5a6af38a38 by Jactry Zeng <jzeng@codeweavers.com> * [WINESYNC] msiexec: Use CRT allocation functions. wine commit id 0f44b3bdcb3d91701a9a8ef1ad07f3e88c08a666 by Alex Henrie <alexhenrie24@gmail.com> * [WINESYNC] msi: Remove DECLSPEC_HIDDEN usage. wine commit id 91e81083458374706bbace11114f4ad5e473ac07 by Alistair Leslie-Hughes <leslie_alistair@hotmail.com> * [WINESYNC] msi: Store Context as MSIINSTALLCONTEXT in MSIPACKAGE. Avoids casting to enum pointer in msi_locate_product call. wine commit id 2daa8c9f95b35983c885f5f7efe9e1b48e91f679 by Jacek Caban <jacek@codeweavers.com> * [WINESYNC] msi/tests: Initialize pathkey in test_installprops. It could be used uninitialized on early no access return. wine commit id 93668319dd63add97036fbb79b5745c699117313 by Jacek Caban <jacek@codeweavers.com> * [WINESYNC] regsvr32: Use message boxes by default for output. regsvr32 is in GUI subsystem and shouldn't interact with console. Keeping unix I/O output in silent mode. Removing -c option as not existing in native. Signed-off-by: Eric Pouech <epouech@codeweavers.com> wine commit id ac8da35b87005e45947b8164a4132f3bbb4ec2cc by Eric Pouech <epouech@codeweavers.com> * [MSI]: Reduce diff * [WINESYNC] msiexec: No longer use console/file output APIs. Regular GUI apps don't. Signed-off-by: Eric Pouech <epouech@codeweavers.com> wine commit id e048f71ecbb103ae7c1876092cb8244b24a73cb7 by Eric Pouech <epouech@codeweavers.com> * [WINESYNC] msi: Fix a memory leak (Coverity). wine commit id 4afca1787febb012d0cdd2c007dd32beba35178d by Zhiyi Zhang <zzhang@codeweavers.com> * [WINESYNC] msi: Don't write past end of string when selecting parent directory. wine commit id bbce5d014db7f023b133d6d09e6846e027586f7d by Fabian Maurer <dark.shadow4@web.de> * [WINESYNC] msi: Avoid leaking stream on DB update. MSI_RecordGetIStream adds a reference to the stream. This reference should be negated as we are done setting the stream. Signed-off-by: David Kahurani <k.kahurani@gmail.com> wine commit id 386dbe1059ba08485696760c267ef06dbed95bad by David Kahurani <k.kahurani@gmail.com> * [WINESYNC] msi/tests: Expand costing tests. wine commit id 674efeb1f7445935cf4f49dd1285727055664ab9 by Zebediah Figura <zfigura@codeweavers.com> * [WINESYNC] msi: Round costs up to 4096 bytes instead of clamping. wine commit id 9725a2286acdb791de316295d9bcb11411a3fd56 by Zebediah Figura <zfigura@codeweavers.com> * [WINESYNC] msi: Store component cost in 512-byte units. This avoids overflow when component costs exceed 4 GB. wine commit id d7bbe884ef29215f4db2027f450fb959314f5383 by Zebediah Figura <zfigura@codeweavers.com> * [MSI] store component cost in 512-byte units * [WINESYNC] msi: Multiply by 512 in dialog_vcl_add_drives(). The main motivation here is to avoid overflow, and multiplying in one place seems simpler. wine commit id 4a227c62a59a55aff9bacf1473c7f478f5c83294 by Zebediah Figura <zfigura@codeweavers.com> * [MSI] reduce diff * [WINESYNC] msi: Create the custom action server as an elevated process. Dragon Naturally Speaking 12.5 manually validates that the custom action server is elevated. One might imagine that the right approach here is to add a manifest to msiexec; however, msiexec does not always trigger a UAC prompt on Windows. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51143 wine commit id 366398cc53c76028c8dfe8d8a16c78a6a10ce962 by Zebediah Figura <z.figura12@gmail.com> * [WINESYNC] msi/tests: Delete the temp .msi file in all failure cases. wine commit id 43fb0ecd0717ad1a6aa0702ed68368ee35d3ecda by Alexandre Julliard <julliard@winehq.org> * [WINESYNC] msi/tests: Use the helpers from utils.h in more modules. wine commit id b3f11ceb7a0ddcf5fe742377f99c947b0b56a051 by Hans Leidekker <hans@codeweavers.com> * [MSITEST] include util header * [WINESYNC] msi/tests: Try restarting tests elevated. Wine starts processes non-elevated since e92ba2de43d7afbe0704b11b29f7c30f44dfaeca which means that many tests are skipped now. wine commit id a6eb51f0e595b2e5ddc521fb61b10d72849dd0f2 by Hans Leidekker <hans@codeweavers.com> * [MSITEST] try restarting for tests elevated * [WINESYNC] msi/tests: Get rid of workarounds for old Windows versions. wine commit id 738ec8285583248a84349939734ed600a47ba73d by Hans Leidekker <hans@codeweavers.com> * [MSI] fix patch failed * [WINESYNC] msi: Install global assemblies before running deferred custom actions. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56493 wine commit id 7f0ca9c284d15d03f14a8fefefac834990d622cd by Hans Leidekker <hans@codeweavers.com> * [WINESYNC] msi: Install global assemblies after install custom actions and before commit custom actions. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56609 wine commit id 27f5470ff4c20121b9eacd702c888400191c7d9e by Hans Leidekker <hans@codeweavers.com> * [WINESYNC]: msi is now in sync with wine-staging wine-9.8 * [MSI] Fix build * [WINESYNC] Update WINESYNC doc * [MSI] Remove nonameless* defines * [MSIEXEC] Fix build * [MSIEXEC] Fix build * [MSI] Fix vcl_get_cost
1618 lines
46 KiB
C
1618 lines
46 KiB
C
/*
|
|
* 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
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
*/
|
|
|
|
/*
|
|
* Actions dealing with files:
|
|
*
|
|
* InstallFiles
|
|
* DuplicateFiles
|
|
* MoveFiles
|
|
* PatchFiles
|
|
* RemoveDuplicateFiles
|
|
* RemoveFiles
|
|
*/
|
|
|
|
#include <stdarg.h>
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "windef.h"
|
|
#include "winbase.h"
|
|
#include "winerror.h"
|
|
#include "fdi.h"
|
|
#include "msi.h"
|
|
#include "msidefs.h"
|
|
#include "msipriv.h"
|
|
#include "winuser.h"
|
|
#include "winreg.h"
|
|
#include "shlwapi.h"
|
|
#include "patchapi.h"
|
|
#include "wine/debug.h"
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
BOOL msi_get_temp_file_name( MSIPACKAGE *package, const WCHAR *tmp_path, const WCHAR *prefix, WCHAR *tmp_filename )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = GetTempFileNameW( tmp_path, prefix, 0, tmp_filename );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
HANDLE msi_create_file( MSIPACKAGE *package, const WCHAR *filename, DWORD access, DWORD sharing, DWORD creation,
|
|
DWORD flags )
|
|
{
|
|
HANDLE handle;
|
|
msi_disable_fs_redirection( package );
|
|
handle = CreateFileW( filename, access, sharing, NULL, creation, flags, NULL );
|
|
msi_revert_fs_redirection( package );
|
|
return handle;
|
|
}
|
|
|
|
static BOOL copy_file( MSIPACKAGE *package, const WCHAR *src, const WCHAR *dst, BOOL fail_if_exists )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = CopyFileW( src, dst, fail_if_exists );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
BOOL msi_delete_file( MSIPACKAGE *package, const WCHAR *filename )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = DeleteFileW( filename );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
static BOOL create_directory( MSIPACKAGE *package, const WCHAR *path )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = CreateDirectoryW( path, NULL );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
BOOL msi_remove_directory( MSIPACKAGE *package, const WCHAR *path )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = RemoveDirectoryW( path );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
BOOL msi_set_file_attributes( MSIPACKAGE *package, const WCHAR *filename, DWORD attrs )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = SetFileAttributesW( filename, attrs );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
DWORD msi_get_file_attributes( MSIPACKAGE *package, const WCHAR *path )
|
|
{
|
|
DWORD attrs;
|
|
msi_disable_fs_redirection( package );
|
|
attrs = GetFileAttributesW( path );
|
|
msi_revert_fs_redirection( package );
|
|
return attrs;
|
|
}
|
|
|
|
HANDLE msi_find_first_file( MSIPACKAGE *package, const WCHAR *filename, WIN32_FIND_DATAW *data )
|
|
{
|
|
HANDLE handle;
|
|
msi_disable_fs_redirection( package );
|
|
handle = FindFirstFileW( filename, data );
|
|
msi_revert_fs_redirection( package );
|
|
return handle;
|
|
}
|
|
|
|
BOOL msi_find_next_file( MSIPACKAGE *package, HANDLE handle, WIN32_FIND_DATAW *data )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = FindNextFileW( handle, data );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
BOOL msi_move_file( MSIPACKAGE *package, const WCHAR *from, const WCHAR *to, DWORD flags )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = MoveFileExW( from, to, flags );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
static BOOL apply_filepatch( MSIPACKAGE *package, const WCHAR *patch, const WCHAR *old, const WCHAR *new )
|
|
{
|
|
BOOL ret;
|
|
msi_disable_fs_redirection( package );
|
|
ret = ApplyPatchToFileW( patch, old, new, 0 );
|
|
msi_revert_fs_redirection( package );
|
|
return ret;
|
|
}
|
|
|
|
DWORD msi_get_file_version_info( MSIPACKAGE *package, const WCHAR *path, DWORD buflen, BYTE *buffer )
|
|
{
|
|
DWORD size, handle;
|
|
msi_disable_fs_redirection( package );
|
|
if (buffer) size = GetFileVersionInfoW( path, 0, buflen, buffer );
|
|
else size = GetFileVersionInfoSizeW( path, &handle );
|
|
msi_revert_fs_redirection( package );
|
|
return size;
|
|
}
|
|
|
|
VS_FIXEDFILEINFO *msi_get_disk_file_version( MSIPACKAGE *package, const WCHAR *filename )
|
|
{
|
|
VS_FIXEDFILEINFO *ptr, *ret;
|
|
DWORD version_size;
|
|
UINT size;
|
|
void *version;
|
|
|
|
if (!(version_size = msi_get_file_version_info( package, filename, 0, NULL ))) return NULL;
|
|
if (!(version = malloc( version_size ))) return NULL;
|
|
|
|
msi_get_file_version_info( package, filename, version_size, version );
|
|
|
|
if (!VerQueryValueW( version, L"\\", (void **)&ptr, &size ))
|
|
{
|
|
free( version );
|
|
return NULL;
|
|
}
|
|
|
|
if (!(ret = malloc( size )))
|
|
{
|
|
free( version );
|
|
return NULL;
|
|
}
|
|
|
|
memcpy( ret, ptr, size );
|
|
free( version );
|
|
return ret;
|
|
}
|
|
|
|
DWORD msi_get_disk_file_size( MSIPACKAGE *package, const WCHAR *filename )
|
|
{
|
|
DWORD size;
|
|
HANDLE file;
|
|
file = msi_create_file( package, filename, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, 0 );
|
|
if (file == INVALID_HANDLE_VALUE) return INVALID_FILE_SIZE;
|
|
size = GetFileSize( file, NULL );
|
|
CloseHandle( file );
|
|
return size;
|
|
}
|
|
|
|
/* Recursively create all directories in the path. */
|
|
BOOL msi_create_full_path( MSIPACKAGE *package, const WCHAR *path )
|
|
{
|
|
BOOL ret = TRUE;
|
|
WCHAR *new_path;
|
|
int len;
|
|
|
|
if (!(new_path = malloc( (wcslen( path ) + 1) * sizeof(WCHAR) ))) return FALSE;
|
|
lstrcpyW( new_path, path );
|
|
|
|
while ((len = lstrlenW( new_path )) && new_path[len - 1] == '\\')
|
|
new_path[len - 1] = 0;
|
|
|
|
while (!create_directory( package, new_path ))
|
|
{
|
|
WCHAR *slash;
|
|
DWORD last_error = GetLastError();
|
|
if (last_error == ERROR_ALREADY_EXISTS) break;
|
|
if (last_error != ERROR_PATH_NOT_FOUND)
|
|
{
|
|
ret = FALSE;
|
|
break;
|
|
}
|
|
if (!(slash = wcsrchr( new_path, '\\' )))
|
|
{
|
|
ret = FALSE;
|
|
break;
|
|
}
|
|
len = slash - new_path;
|
|
new_path[len] = 0;
|
|
if (!msi_create_full_path( package, new_path ))
|
|
{
|
|
ret = FALSE;
|
|
break;
|
|
}
|
|
new_path[len] = '\\';
|
|
}
|
|
free( new_path );
|
|
return ret;
|
|
}
|
|
|
|
static void file_update_ui( MSIPACKAGE *package, MSIFILE *f, const WCHAR *action )
|
|
{
|
|
MSIRECORD *uirow;
|
|
|
|
uirow = MSI_CreateRecord( 9 );
|
|
MSI_RecordSetStringW( uirow, 1, f->FileName );
|
|
MSI_RecordSetStringW( uirow, 9, f->Component->Directory );
|
|
MSI_RecordSetInteger( uirow, 6, f->FileSize );
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
|
msiobj_release( &uirow->hdr );
|
|
msi_ui_progress( package, 2, f->FileSize, 0, 0 );
|
|
}
|
|
|
|
static BOOL is_registered_patch_media( MSIPACKAGE *package, UINT disk_id )
|
|
{
|
|
MSIPATCHINFO *patch;
|
|
|
|
LIST_FOR_EACH_ENTRY( patch, &package->patches, MSIPATCHINFO, entry )
|
|
{
|
|
if (patch->disk_id == disk_id && patch->registered) return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
static BOOL is_obsoleted_by_patch( MSIPACKAGE *package, MSIFILE *file )
|
|
{
|
|
if (!list_empty( &package->patches ) && file->disk_id < MSI_INITIAL_MEDIA_TRANSFORM_DISKID)
|
|
{
|
|
if (!msi_get_property_int( package->db, L"Installed", 0 )) return FALSE;
|
|
return TRUE;
|
|
}
|
|
if (is_registered_patch_media( package, file->disk_id )) return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
static BOOL file_hash_matches( MSIPACKAGE *package, MSIFILE *file )
|
|
{
|
|
UINT r;
|
|
MSIFILEHASHINFO hash;
|
|
|
|
hash.dwFileHashInfoSize = sizeof(hash);
|
|
r = msi_get_filehash( package, file->TargetPath, &hash );
|
|
if (r != ERROR_SUCCESS)
|
|
return FALSE;
|
|
|
|
return !memcmp( &hash, &file->hash, sizeof(hash) );
|
|
}
|
|
|
|
static msi_file_state calculate_install_state( MSIPACKAGE *package, MSIFILE *file )
|
|
{
|
|
MSICOMPONENT *comp = file->Component;
|
|
VS_FIXEDFILEINFO *file_version;
|
|
WCHAR *font_version;
|
|
msi_file_state state;
|
|
DWORD size;
|
|
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (!comp->Enabled || comp->Action != INSTALLSTATE_LOCAL)
|
|
{
|
|
TRACE("skipping %s (not scheduled for install)\n", debugstr_w(file->File));
|
|
return msifs_skipped;
|
|
}
|
|
if (is_obsoleted_by_patch( package, file ))
|
|
{
|
|
TRACE("skipping %s (obsoleted by patch)\n", debugstr_w(file->File));
|
|
return msifs_skipped;
|
|
}
|
|
if (msi_get_file_attributes( package, file->TargetPath ) == INVALID_FILE_ATTRIBUTES)
|
|
{
|
|
TRACE("installing %s (missing)\n", debugstr_w(file->File));
|
|
return msifs_missing;
|
|
}
|
|
if (file->Version)
|
|
{
|
|
if ((file_version = msi_get_disk_file_version( package, file->TargetPath )))
|
|
{
|
|
if (msi_compare_file_versions( file_version, file->Version ) < 0)
|
|
{
|
|
TRACE("overwriting %s (new version %s old version %u.%u.%u.%u)\n",
|
|
debugstr_w(file->File), debugstr_w(file->Version),
|
|
HIWORD(file_version->dwFileVersionMS), LOWORD(file_version->dwFileVersionMS),
|
|
HIWORD(file_version->dwFileVersionLS), LOWORD(file_version->dwFileVersionLS));
|
|
state = msifs_overwrite;
|
|
}
|
|
else
|
|
{
|
|
TRACE("keeping %s (new version %s old version %u.%u.%u.%u)\n",
|
|
debugstr_w(file->File), debugstr_w(file->Version),
|
|
HIWORD(file_version->dwFileVersionMS), LOWORD(file_version->dwFileVersionMS),
|
|
HIWORD(file_version->dwFileVersionLS), LOWORD(file_version->dwFileVersionLS));
|
|
state = msifs_present;
|
|
}
|
|
free( file_version );
|
|
return state;
|
|
}
|
|
else if ((font_version = msi_get_font_file_version( package, file->TargetPath )))
|
|
{
|
|
if (msi_compare_font_versions( font_version, file->Version ) < 0)
|
|
{
|
|
TRACE("overwriting %s (new version %s old version %s)\n",
|
|
debugstr_w(file->File), debugstr_w(file->Version), debugstr_w(font_version));
|
|
state = msifs_overwrite;
|
|
}
|
|
else
|
|
{
|
|
TRACE("keeping %s (new version %s old version %s)\n",
|
|
debugstr_w(file->File), debugstr_w(file->Version), debugstr_w(font_version));
|
|
state = msifs_present;
|
|
}
|
|
free( font_version );
|
|
return state;
|
|
}
|
|
}
|
|
if ((size = msi_get_disk_file_size( package, file->TargetPath )) != file->FileSize)
|
|
{
|
|
TRACE("overwriting %s (old size %lu new size %d)\n", debugstr_w(file->File), size, file->FileSize);
|
|
return msifs_overwrite;
|
|
}
|
|
if (file->hash.dwFileHashInfoSize)
|
|
{
|
|
if (file_hash_matches( package, file ))
|
|
{
|
|
TRACE("keeping %s (hash match)\n", debugstr_w(file->File));
|
|
return msifs_hashmatch;
|
|
}
|
|
else
|
|
{
|
|
TRACE("overwriting %s (hash mismatch)\n", debugstr_w(file->File));
|
|
return msifs_overwrite;
|
|
}
|
|
}
|
|
/* assume present */
|
|
TRACE("keeping %s\n", debugstr_w(file->File));
|
|
return msifs_present;
|
|
}
|
|
|
|
static void schedule_install_files(MSIPACKAGE *package)
|
|
{
|
|
MSIFILE *file;
|
|
|
|
LIST_FOR_EACH_ENTRY(file, &package->files, MSIFILE, entry)
|
|
{
|
|
MSICOMPONENT *comp = file->Component;
|
|
|
|
file->state = calculate_install_state( package, file );
|
|
if (file->state == msifs_overwrite && (comp->Attributes & msidbComponentAttributesNeverOverwrite))
|
|
{
|
|
TRACE("not overwriting %s\n", debugstr_w(file->TargetPath));
|
|
file->state = msifs_skipped;
|
|
}
|
|
}
|
|
}
|
|
|
|
static UINT copy_file_attributes( MSIPACKAGE *package, MSIFILE *file, WCHAR *source )
|
|
{
|
|
BOOL ret;
|
|
|
|
ret = copy_file( package, source, file->TargetPath, FALSE );
|
|
if (!ret)
|
|
return GetLastError();
|
|
|
|
msi_set_file_attributes( package, file->TargetPath, FILE_ATTRIBUTE_NORMAL );
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static UINT copy_install_file(MSIPACKAGE *package, MSIFILE *file, LPWSTR source)
|
|
{
|
|
UINT gle;
|
|
|
|
TRACE("Copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
|
|
|
|
gle = copy_file_attributes( package, file, source );
|
|
if (gle == ERROR_SUCCESS)
|
|
return gle;
|
|
|
|
if (gle == ERROR_ALREADY_EXISTS && file->state == msifs_overwrite)
|
|
{
|
|
TRACE("overwriting existing file\n");
|
|
return ERROR_SUCCESS;
|
|
}
|
|
else if (gle == ERROR_ACCESS_DENIED)
|
|
{
|
|
msi_set_file_attributes( package, file->TargetPath, FILE_ATTRIBUTE_NORMAL );
|
|
|
|
gle = copy_file_attributes( package, file, source );
|
|
TRACE("Overwriting existing file: %d\n", gle);
|
|
}
|
|
if (gle == ERROR_SHARING_VIOLATION || gle == ERROR_USER_MAPPED_FILE)
|
|
{
|
|
WCHAR *tmpfileW, *pathW, *p;
|
|
DWORD len;
|
|
|
|
TRACE("file in use, scheduling rename operation\n");
|
|
|
|
if (!(pathW = wcsdup( file->TargetPath ))) return ERROR_OUTOFMEMORY;
|
|
if ((p = wcsrchr(pathW, '\\'))) *p = 0;
|
|
len = lstrlenW( pathW ) + 16;
|
|
if (!(tmpfileW = malloc(len * sizeof(WCHAR))))
|
|
{
|
|
free( pathW );
|
|
return ERROR_OUTOFMEMORY;
|
|
}
|
|
if (!GetTempFileNameW( pathW, L"msi", 0, tmpfileW )) tmpfileW[0] = 0;
|
|
free( pathW );
|
|
|
|
if (copy_file( package, source, tmpfileW, FALSE ) &&
|
|
msi_move_file( package, file->TargetPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT ) &&
|
|
msi_move_file( package, tmpfileW, file->TargetPath, MOVEFILE_DELAY_UNTIL_REBOOT ))
|
|
{
|
|
package->need_reboot_at_end = 1;
|
|
gle = ERROR_SUCCESS;
|
|
}
|
|
else
|
|
{
|
|
gle = GetLastError();
|
|
WARN("failed to schedule rename operation: %d)\n", gle);
|
|
DeleteFileW( tmpfileW );
|
|
}
|
|
free(tmpfileW);
|
|
}
|
|
|
|
return gle;
|
|
}
|
|
|
|
static UINT create_folder( MSIPACKAGE *package, const WCHAR *dir )
|
|
{
|
|
MSIFOLDER *folder;
|
|
const WCHAR *install_path;
|
|
|
|
install_path = msi_get_target_folder( package, dir );
|
|
if (!install_path) return ERROR_FUNCTION_FAILED;
|
|
|
|
folder = msi_get_loaded_folder( package, dir );
|
|
if (folder->State == FOLDER_STATE_UNINITIALIZED)
|
|
{
|
|
msi_create_full_path( package, install_path );
|
|
folder->State = FOLDER_STATE_CREATED;
|
|
}
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
static MSIFILE *find_file( MSIPACKAGE *package, UINT disk_id, const WCHAR *filename )
|
|
{
|
|
MSIFILE *file;
|
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
|
{
|
|
if (file->disk_id == disk_id &&
|
|
file->state != msifs_installed &&
|
|
!wcsicmp( filename, file->File )) return file;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static BOOL installfiles_cb(MSIPACKAGE *package, LPCWSTR filename, DWORD action,
|
|
LPWSTR *path, DWORD *attrs, PVOID user)
|
|
{
|
|
MSIFILE *file = *(MSIFILE **)user;
|
|
|
|
if (action == MSICABEXTRACT_BEGINEXTRACT)
|
|
{
|
|
if (!(file = find_file( package, file->disk_id, filename )))
|
|
{
|
|
TRACE("unknown file in cabinet (%s)\n", debugstr_w(filename));
|
|
return FALSE;
|
|
}
|
|
if (file->state != msifs_missing && file->state != msifs_overwrite)
|
|
return FALSE;
|
|
|
|
if (!msi_is_global_assembly( file->Component ))
|
|
{
|
|
create_folder( package, file->Component->Directory );
|
|
}
|
|
*path = wcsdup( file->TargetPath );
|
|
*attrs = file->Attributes;
|
|
*(MSIFILE **)user = file;
|
|
}
|
|
else if (action == MSICABEXTRACT_FILEEXTRACTED)
|
|
{
|
|
if (!msi_is_global_assembly( file->Component )) file->state = msifs_installed;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
WCHAR *msi_resolve_file_source( MSIPACKAGE *package, MSIFILE *file )
|
|
{
|
|
WCHAR *p, *path;
|
|
|
|
TRACE("Working to resolve source of file %s\n", debugstr_w(file->File));
|
|
|
|
if (file->IsCompressed) return NULL;
|
|
|
|
p = msi_resolve_source_folder( package, file->Component->Directory, NULL );
|
|
path = msi_build_directory_name( 2, p, file->ShortName );
|
|
|
|
if (file->LongName && msi_get_file_attributes( package, path ) == INVALID_FILE_ATTRIBUTES)
|
|
{
|
|
free( path );
|
|
path = msi_build_directory_name( 2, p, file->LongName );
|
|
}
|
|
free( p );
|
|
TRACE("file %s source resolves to %s\n", debugstr_w(file->File), debugstr_w(path));
|
|
return path;
|
|
}
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
UINT ACTION_InstallFiles(MSIPACKAGE *package)
|
|
{
|
|
MSIMEDIAINFO *mi;
|
|
UINT rc = ERROR_SUCCESS;
|
|
MSIFILE *file;
|
|
|
|
msi_set_sourcedir_props(package, FALSE);
|
|
|
|
if (package->script == SCRIPT_NONE)
|
|
return msi_schedule_action(package, SCRIPT_INSTALL, L"InstallFiles");
|
|
|
|
schedule_install_files(package);
|
|
mi = calloc(1, sizeof(MSIMEDIAINFO));
|
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
|
{
|
|
BOOL is_global_assembly = msi_is_global_assembly( file->Component );
|
|
|
|
file_update_ui( package, file, L"InstallFiles" );
|
|
|
|
rc = msi_load_media_info( package, file->Sequence, mi );
|
|
if (rc != ERROR_SUCCESS)
|
|
{
|
|
ERR("Unable to load media info for %s (%u)\n", debugstr_w(file->File), rc);
|
|
rc = ERROR_FUNCTION_FAILED;
|
|
goto done;
|
|
}
|
|
|
|
if (file->state != msifs_hashmatch &&
|
|
file->state != msifs_skipped &&
|
|
(file->state != msifs_present || !msi_get_property_int( package->db, L"Installed", 0 )) &&
|
|
(rc = ready_media( package, file->IsCompressed, mi )))
|
|
{
|
|
ERR("Failed to ready media for %s\n", debugstr_w(file->File));
|
|
goto done;
|
|
}
|
|
|
|
if (file->state != msifs_missing && !mi->is_continuous && file->state != msifs_overwrite)
|
|
continue;
|
|
|
|
if (file->Sequence > mi->last_sequence || mi->is_continuous ||
|
|
(file->IsCompressed && !mi->is_extracted))
|
|
{
|
|
MSICABDATA data;
|
|
MSIFILE *cursor = file;
|
|
|
|
data.mi = mi;
|
|
data.package = package;
|
|
data.cb = installfiles_cb;
|
|
data.user = &cursor;
|
|
|
|
if (file->IsCompressed && !msi_cabextract(package, mi, &data))
|
|
{
|
|
ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
if (!file->IsCompressed)
|
|
{
|
|
WCHAR *source = msi_resolve_file_source(package, file);
|
|
|
|
TRACE("copying %s to %s\n", debugstr_w(source), debugstr_w(file->TargetPath));
|
|
|
|
if (!is_global_assembly)
|
|
{
|
|
create_folder(package, file->Component->Directory);
|
|
}
|
|
rc = copy_install_file(package, file, source);
|
|
if (rc != ERROR_SUCCESS)
|
|
{
|
|
ERR("Failed to copy %s to %s (%u)\n", debugstr_w(source), debugstr_w(file->TargetPath), rc);
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
free(source);
|
|
goto done;
|
|
}
|
|
if (!is_global_assembly) file->state = msifs_installed;
|
|
free(source);
|
|
}
|
|
else if (!is_global_assembly && file->state != msifs_installed &&
|
|
!(file->Attributes & msidbFileAttributesPatchAdded))
|
|
{
|
|
ERR("compressed file wasn't installed (%s)\n", debugstr_w(file->File));
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
done:
|
|
msi_free_media_info(mi);
|
|
return rc;
|
|
}
|
|
|
|
static MSIFILEPATCH *find_filepatch( MSIPACKAGE *package, UINT disk_id, const WCHAR *key )
|
|
{
|
|
MSIFILEPATCH *patch;
|
|
|
|
LIST_FOR_EACH_ENTRY( patch, &package->filepatches, MSIFILEPATCH, entry )
|
|
{
|
|
if (!patch->extracted && patch->disk_id == disk_id && !wcscmp( key, patch->File->File ))
|
|
return patch;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
static BOOL patchfiles_cb(MSIPACKAGE *package, LPCWSTR file, DWORD action,
|
|
LPWSTR *path, DWORD *attrs, PVOID user)
|
|
{
|
|
MSIFILEPATCH *patch = *(MSIFILEPATCH **)user;
|
|
|
|
if (action == MSICABEXTRACT_BEGINEXTRACT)
|
|
{
|
|
MSICOMPONENT *comp;
|
|
|
|
if (is_registered_patch_media( package, patch->disk_id ) ||
|
|
!(patch = find_filepatch( package, patch->disk_id, file ))) return FALSE;
|
|
|
|
comp = patch->File->Component;
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (!comp->Enabled || comp->Action != INSTALLSTATE_LOCAL)
|
|
{
|
|
TRACE("file %s component %s not installed or disabled\n",
|
|
debugstr_w(patch->File->File), debugstr_w(comp->Component));
|
|
return FALSE;
|
|
}
|
|
|
|
patch->path = msi_create_temp_file( package->db );
|
|
*path = wcsdup( patch->path );
|
|
*attrs = patch->File->Attributes;
|
|
*(MSIFILEPATCH **)user = patch;
|
|
}
|
|
else if (action == MSICABEXTRACT_FILEEXTRACTED)
|
|
{
|
|
patch->extracted = TRUE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static UINT patch_file( MSIPACKAGE *package, MSIFILEPATCH *patch )
|
|
{
|
|
UINT r = ERROR_SUCCESS;
|
|
WCHAR *tmpfile = msi_create_temp_file( package->db );
|
|
|
|
if (!tmpfile) return ERROR_INSTALL_FAILURE;
|
|
if (apply_filepatch( package, patch->path, patch->File->TargetPath, tmpfile ))
|
|
{
|
|
msi_delete_file( package, patch->File->TargetPath );
|
|
msi_move_file( package, tmpfile, patch->File->TargetPath, 0 );
|
|
}
|
|
else
|
|
{
|
|
WARN( "failed to patch %s: %#lx\n", debugstr_w(patch->File->TargetPath), GetLastError() );
|
|
r = ERROR_INSTALL_FAILURE;
|
|
}
|
|
DeleteFileW( patch->path );
|
|
DeleteFileW( tmpfile );
|
|
free( tmpfile );
|
|
return r;
|
|
}
|
|
|
|
UINT msi_patch_assembly( MSIPACKAGE *package, MSIASSEMBLY *assembly, MSIFILEPATCH *patch )
|
|
{
|
|
UINT r = ERROR_FUNCTION_FAILED;
|
|
IAssemblyName *name;
|
|
IAssemblyEnum *iter;
|
|
|
|
if (!(iter = msi_create_assembly_enum( package, assembly->display_name )))
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
while ((IAssemblyEnum_GetNextAssembly( iter, NULL, &name, 0 ) == S_OK))
|
|
{
|
|
WCHAR *displayname, *path;
|
|
DWORD len = 0;
|
|
HRESULT hr;
|
|
|
|
hr = IAssemblyName_GetDisplayName( name, NULL, &len, 0 );
|
|
if (hr != E_NOT_SUFFICIENT_BUFFER || !(displayname = malloc( len * sizeof(WCHAR) )))
|
|
break;
|
|
|
|
hr = IAssemblyName_GetDisplayName( name, displayname, &len, 0 );
|
|
if (FAILED( hr ))
|
|
{
|
|
free( displayname );
|
|
break;
|
|
}
|
|
|
|
if ((path = msi_get_assembly_path( package, displayname )))
|
|
{
|
|
if (!copy_file( package, path, patch->File->TargetPath, FALSE ))
|
|
{
|
|
ERR( "failed to copy file %s -> %s (%lu)\n", debugstr_w(path),
|
|
debugstr_w(patch->File->TargetPath), GetLastError() );
|
|
free( path );
|
|
free( displayname );
|
|
IAssemblyName_Release( name );
|
|
break;
|
|
}
|
|
r = patch_file( package, patch );
|
|
free( path );
|
|
}
|
|
|
|
free( displayname );
|
|
IAssemblyName_Release( name );
|
|
if (r == ERROR_SUCCESS) break;
|
|
}
|
|
|
|
IAssemblyEnum_Release( iter );
|
|
return r;
|
|
}
|
|
|
|
UINT ACTION_PatchFiles( MSIPACKAGE *package )
|
|
{
|
|
MSIFILEPATCH *patch;
|
|
MSIMEDIAINFO *mi;
|
|
UINT rc = ERROR_SUCCESS;
|
|
|
|
TRACE("%p\n", package);
|
|
|
|
if (package->script == SCRIPT_NONE)
|
|
return msi_schedule_action(package, SCRIPT_INSTALL, L"PatchFiles");
|
|
|
|
mi = calloc( 1, sizeof(MSIMEDIAINFO) );
|
|
|
|
TRACE("extracting files\n");
|
|
|
|
LIST_FOR_EACH_ENTRY( patch, &package->filepatches, MSIFILEPATCH, entry )
|
|
{
|
|
MSIFILE *file = patch->File;
|
|
MSICOMPONENT *comp = file->Component;
|
|
|
|
rc = msi_load_media_info( package, patch->Sequence, mi );
|
|
if (rc != ERROR_SUCCESS)
|
|
{
|
|
ERR("Unable to load media info for %s (%u)\n", debugstr_w(file->File), rc);
|
|
rc = ERROR_FUNCTION_FAILED;
|
|
goto done;
|
|
}
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (!comp->Enabled || comp->Action != INSTALLSTATE_LOCAL) continue;
|
|
|
|
if (!patch->extracted)
|
|
{
|
|
MSICABDATA data;
|
|
MSIFILEPATCH *cursor = patch;
|
|
|
|
rc = ready_media( package, TRUE, mi );
|
|
if (rc != ERROR_SUCCESS)
|
|
{
|
|
ERR("Failed to ready media for %s\n", debugstr_w(file->File));
|
|
goto done;
|
|
}
|
|
data.mi = mi;
|
|
data.package = package;
|
|
data.cb = patchfiles_cb;
|
|
data.user = &cursor;
|
|
|
|
if (!msi_cabextract( package, mi, &data ))
|
|
{
|
|
ERR("Failed to extract cabinet: %s\n", debugstr_w(mi->cabinet));
|
|
rc = ERROR_INSTALL_FAILURE;
|
|
goto done;
|
|
}
|
|
}
|
|
}
|
|
|
|
TRACE("applying patches\n");
|
|
|
|
LIST_FOR_EACH_ENTRY( patch, &package->filepatches, MSIFILEPATCH, entry )
|
|
{
|
|
MSICOMPONENT *comp = patch->File->Component;
|
|
|
|
if (msi_is_global_assembly( comp ) || !patch->path) continue;
|
|
|
|
rc = patch_file( package, patch );
|
|
if (rc && !(patch->Attributes & msidbPatchAttributesNonVital))
|
|
{
|
|
ERR("Failed to apply patch to file: %s\n", debugstr_w(patch->File->File));
|
|
break;
|
|
}
|
|
}
|
|
|
|
done:
|
|
msi_free_media_info(mi);
|
|
return rc;
|
|
}
|
|
|
|
#define is_dot_dir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
|
|
|
|
struct file_list
|
|
{
|
|
struct list entry;
|
|
LPWSTR sourcename;
|
|
LPWSTR destname;
|
|
LPWSTR source;
|
|
LPWSTR dest;
|
|
};
|
|
|
|
static BOOL move_file( MSIPACKAGE *package, const WCHAR *source, const WCHAR *dest, int options )
|
|
{
|
|
BOOL ret;
|
|
|
|
if (msi_get_file_attributes( package, source ) == FILE_ATTRIBUTE_DIRECTORY ||
|
|
msi_get_file_attributes( package, dest ) == FILE_ATTRIBUTE_DIRECTORY)
|
|
{
|
|
WARN("Source or dest is directory, not moving\n");
|
|
return FALSE;
|
|
}
|
|
|
|
if (options == msidbMoveFileOptionsMove)
|
|
{
|
|
TRACE("moving %s -> %s\n", debugstr_w(source), debugstr_w(dest));
|
|
ret = msi_move_file( package, source, dest, MOVEFILE_REPLACE_EXISTING );
|
|
if (!ret)
|
|
{
|
|
WARN( "msi_move_file failed: %lu\n", GetLastError() );
|
|
return FALSE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
TRACE("copying %s -> %s\n", debugstr_w(source), debugstr_w(dest));
|
|
ret = copy_file( package, source, dest, FALSE );
|
|
if (!ret)
|
|
{
|
|
WARN( "copy_file failed: %lu\n", GetLastError() );
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static WCHAR *wildcard_to_file( const WCHAR *wildcard, const WCHAR *filename )
|
|
{
|
|
const WCHAR *ptr;
|
|
WCHAR *path;
|
|
DWORD dirlen, pathlen;
|
|
|
|
ptr = wcsrchr(wildcard, '\\');
|
|
dirlen = ptr - wildcard + 1;
|
|
|
|
pathlen = dirlen + lstrlenW(filename) + 1;
|
|
if (!(path = malloc(pathlen * sizeof(WCHAR)))) return NULL;
|
|
|
|
lstrcpynW(path, wildcard, dirlen + 1);
|
|
lstrcatW(path, filename);
|
|
|
|
return path;
|
|
}
|
|
|
|
static void free_file_entry(struct file_list *file)
|
|
{
|
|
free(file->source);
|
|
free(file->dest);
|
|
free(file);
|
|
}
|
|
|
|
static void free_list(struct file_list *list)
|
|
{
|
|
while (!list_empty(&list->entry))
|
|
{
|
|
struct file_list *file = LIST_ENTRY(list_head(&list->entry), struct file_list, entry);
|
|
|
|
list_remove(&file->entry);
|
|
free_file_entry(file);
|
|
}
|
|
}
|
|
|
|
static BOOL add_wildcard( struct file_list *files, const WCHAR *source, WCHAR *dest )
|
|
{
|
|
struct file_list *new, *file;
|
|
WCHAR *ptr, *filename;
|
|
DWORD size;
|
|
|
|
new = calloc(1, sizeof(*new));
|
|
if (!new)
|
|
return FALSE;
|
|
|
|
new->source = wcsdup(source);
|
|
ptr = wcsrchr(dest, '\\') + 1;
|
|
filename = wcsrchr(new->source, '\\') + 1;
|
|
|
|
new->sourcename = filename;
|
|
|
|
if (*ptr)
|
|
new->destname = ptr;
|
|
else
|
|
new->destname = new->sourcename;
|
|
|
|
size = (ptr - dest) + lstrlenW(filename) + 1;
|
|
new->dest = malloc(size * sizeof(WCHAR));
|
|
if (!new->dest)
|
|
{
|
|
free_file_entry(new);
|
|
return FALSE;
|
|
}
|
|
|
|
lstrcpynW(new->dest, dest, ptr - dest + 1);
|
|
lstrcatW(new->dest, filename);
|
|
|
|
if (list_empty(&files->entry))
|
|
{
|
|
list_add_head(&files->entry, &new->entry);
|
|
return TRUE;
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY(file, &files->entry, struct file_list, entry)
|
|
{
|
|
if (wcscmp( source, file->source ) < 0)
|
|
{
|
|
list_add_before(&file->entry, &new->entry);
|
|
return TRUE;
|
|
}
|
|
}
|
|
|
|
list_add_after(&file->entry, &new->entry);
|
|
return TRUE;
|
|
}
|
|
|
|
static BOOL move_files_wildcard( MSIPACKAGE *package, const WCHAR *source, WCHAR *dest, int options )
|
|
{
|
|
WIN32_FIND_DATAW wfd;
|
|
HANDLE hfile;
|
|
LPWSTR path;
|
|
BOOL res;
|
|
struct file_list files, *file;
|
|
DWORD size;
|
|
|
|
hfile = msi_find_first_file( package, source, &wfd );
|
|
if (hfile == INVALID_HANDLE_VALUE) return FALSE;
|
|
|
|
list_init(&files.entry);
|
|
|
|
for (res = TRUE; res; res = msi_find_next_file( package, hfile, &wfd ))
|
|
{
|
|
if (is_dot_dir(wfd.cFileName)) continue;
|
|
|
|
path = wildcard_to_file( source, wfd.cFileName );
|
|
if (!path)
|
|
{
|
|
res = FALSE;
|
|
goto done;
|
|
}
|
|
|
|
add_wildcard(&files, path, dest);
|
|
free(path);
|
|
}
|
|
|
|
/* no files match the wildcard */
|
|
if (list_empty(&files.entry))
|
|
goto done;
|
|
|
|
/* only the first wildcard match gets renamed to dest */
|
|
file = LIST_ENTRY(list_head(&files.entry), struct file_list, entry);
|
|
size = (wcsrchr(file->dest, '\\') - file->dest) + lstrlenW(file->destname) + 2;
|
|
file->dest = realloc(file->dest, size * sizeof(WCHAR));
|
|
if (!file->dest)
|
|
{
|
|
res = FALSE;
|
|
goto done;
|
|
}
|
|
|
|
/* file->dest may be shorter after the reallocation, so add a NULL
|
|
* terminator. This is needed for the call to wcsrchr, as there will no
|
|
* longer be a NULL terminator within the bounds of the allocation in this case.
|
|
*/
|
|
file->dest[size - 1] = '\0';
|
|
lstrcpyW(wcsrchr(file->dest, '\\') + 1, file->destname);
|
|
|
|
while (!list_empty(&files.entry))
|
|
{
|
|
file = LIST_ENTRY(list_head(&files.entry), struct file_list, entry);
|
|
|
|
move_file( package, file->source, file->dest, options );
|
|
|
|
list_remove(&file->entry);
|
|
free_file_entry(file);
|
|
}
|
|
|
|
res = TRUE;
|
|
|
|
done:
|
|
free_list(&files);
|
|
FindClose(hfile);
|
|
return res;
|
|
}
|
|
|
|
void msi_reduce_to_long_filename( WCHAR *filename )
|
|
{
|
|
WCHAR *p = wcschr( filename, '|' );
|
|
if (p) memmove( filename, p + 1, (lstrlenW( p + 1 ) + 1) * sizeof(WCHAR) );
|
|
}
|
|
|
|
static UINT ITERATE_MoveFiles( MSIRECORD *rec, LPVOID param )
|
|
{
|
|
MSIPACKAGE *package = param;
|
|
MSIRECORD *uirow;
|
|
MSICOMPONENT *comp;
|
|
LPCWSTR sourcename, component;
|
|
LPWSTR sourcedir, destname = NULL, destdir = NULL, source = NULL, dest = NULL;
|
|
int options;
|
|
DWORD size;
|
|
BOOL wildcards;
|
|
|
|
component = MSI_RecordGetString(rec, 2);
|
|
comp = msi_get_loaded_component(package, component);
|
|
if (!comp)
|
|
return ERROR_SUCCESS;
|
|
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (comp->Action != INSTALLSTATE_LOCAL)
|
|
{
|
|
TRACE("component not scheduled for installation %s\n", debugstr_w(component));
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
sourcename = MSI_RecordGetString(rec, 3);
|
|
options = MSI_RecordGetInteger(rec, 7);
|
|
|
|
sourcedir = msi_dup_property(package->db, MSI_RecordGetString(rec, 5));
|
|
if (!sourcedir)
|
|
goto done;
|
|
|
|
destdir = msi_dup_property(package->db, MSI_RecordGetString(rec, 6));
|
|
if (!destdir)
|
|
goto done;
|
|
|
|
if (!sourcename)
|
|
{
|
|
if (msi_get_file_attributes( package, sourcedir ) == INVALID_FILE_ATTRIBUTES)
|
|
goto done;
|
|
|
|
source = wcsdup(sourcedir);
|
|
if (!source)
|
|
goto done;
|
|
}
|
|
else
|
|
{
|
|
size = lstrlenW(sourcedir) + lstrlenW(sourcename) + 2;
|
|
source = malloc(size * sizeof(WCHAR));
|
|
if (!source)
|
|
goto done;
|
|
|
|
lstrcpyW(source, sourcedir);
|
|
if (source[lstrlenW(source) - 1] != '\\')
|
|
lstrcatW(source, L"\\");
|
|
lstrcatW(source, sourcename);
|
|
}
|
|
|
|
wildcards = wcschr(source, '*') || wcschr(source, '?');
|
|
|
|
if (MSI_RecordIsNull(rec, 4))
|
|
{
|
|
if (!wildcards)
|
|
{
|
|
WCHAR *p;
|
|
if (sourcename)
|
|
destname = wcsdup(sourcename);
|
|
else if ((p = wcsrchr(sourcedir, '\\')))
|
|
destname = wcsdup(p + 1);
|
|
else
|
|
destname = wcsdup(sourcedir);
|
|
if (!destname)
|
|
goto done;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
destname = wcsdup(MSI_RecordGetString(rec, 4));
|
|
if (destname) msi_reduce_to_long_filename(destname);
|
|
}
|
|
|
|
size = 0;
|
|
if (destname)
|
|
size = lstrlenW(destname);
|
|
|
|
size += lstrlenW(destdir) + 2;
|
|
dest = malloc(size * sizeof(WCHAR));
|
|
if (!dest)
|
|
goto done;
|
|
|
|
lstrcpyW(dest, destdir);
|
|
if (dest[lstrlenW(dest) - 1] != '\\')
|
|
lstrcatW(dest, L"\\");
|
|
|
|
if (destname)
|
|
lstrcatW(dest, destname);
|
|
|
|
if (msi_get_file_attributes( package, destdir ) == INVALID_FILE_ATTRIBUTES)
|
|
{
|
|
if (!msi_create_full_path( package, destdir ))
|
|
{
|
|
WARN( "failed to create directory %lu\n", GetLastError() );
|
|
goto done;
|
|
}
|
|
}
|
|
|
|
if (!wildcards)
|
|
move_file( package, source, dest, options );
|
|
else
|
|
move_files_wildcard( package, source, dest, options );
|
|
|
|
done:
|
|
uirow = MSI_CreateRecord( 9 );
|
|
MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(rec, 1) );
|
|
MSI_RecordSetInteger( uirow, 6, 1 ); /* FIXME */
|
|
MSI_RecordSetStringW( uirow, 9, destdir );
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
free(sourcedir);
|
|
free(destdir);
|
|
free(destname);
|
|
free(source);
|
|
free(dest);
|
|
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
UINT ACTION_MoveFiles( MSIPACKAGE *package )
|
|
{
|
|
MSIQUERY *view;
|
|
UINT rc;
|
|
|
|
if (package->script == SCRIPT_NONE)
|
|
return msi_schedule_action(package, SCRIPT_INSTALL, L"MoveFiles");
|
|
|
|
rc = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `MoveFile`", &view);
|
|
if (rc != ERROR_SUCCESS)
|
|
return ERROR_SUCCESS;
|
|
|
|
rc = MSI_IterateRecords(view, NULL, ITERATE_MoveFiles, package);
|
|
msiobj_release(&view->hdr);
|
|
return rc;
|
|
}
|
|
|
|
static WCHAR *get_duplicate_filename( MSIPACKAGE *package, MSIRECORD *row, const WCHAR *file_key, const WCHAR *src )
|
|
{
|
|
DWORD len;
|
|
WCHAR *dst_name, *dst_path, *dst;
|
|
|
|
if (MSI_RecordIsNull( row, 4 ))
|
|
{
|
|
len = lstrlenW( src ) + 1;
|
|
if (!(dst_name = malloc( len * sizeof(WCHAR)))) return NULL;
|
|
lstrcpyW( dst_name, wcsrchr( src, '\\' ) + 1 );
|
|
}
|
|
else
|
|
{
|
|
MSI_RecordGetStringW( row, 4, NULL, &len );
|
|
if (!(dst_name = malloc( ++len * sizeof(WCHAR) ))) return NULL;
|
|
MSI_RecordGetStringW( row, 4, dst_name, &len );
|
|
msi_reduce_to_long_filename( dst_name );
|
|
}
|
|
|
|
if (MSI_RecordIsNull( row, 5 ))
|
|
{
|
|
WCHAR *p;
|
|
dst_path = wcsdup( src );
|
|
p = wcsrchr( dst_path, '\\' );
|
|
if (p) *p = 0;
|
|
}
|
|
else
|
|
{
|
|
const WCHAR *dst_key = MSI_RecordGetString( row, 5 );
|
|
|
|
dst_path = wcsdup( msi_get_target_folder( package, dst_key ) );
|
|
if (!dst_path)
|
|
{
|
|
/* try a property */
|
|
dst_path = msi_dup_property( package->db, dst_key );
|
|
if (!dst_path)
|
|
{
|
|
FIXME("Unable to get destination folder, try AppSearch properties\n");
|
|
free( dst_name );
|
|
return NULL;
|
|
}
|
|
}
|
|
}
|
|
|
|
dst = msi_build_directory_name( 2, dst_path, dst_name );
|
|
msi_create_full_path( package, dst_path );
|
|
|
|
free( dst_name );
|
|
free( dst_path );
|
|
return dst;
|
|
}
|
|
|
|
static UINT ITERATE_DuplicateFiles(MSIRECORD *row, LPVOID param)
|
|
{
|
|
MSIPACKAGE *package = param;
|
|
LPWSTR dest;
|
|
LPCWSTR file_key, component;
|
|
MSICOMPONENT *comp;
|
|
MSIRECORD *uirow;
|
|
MSIFILE *file;
|
|
|
|
component = MSI_RecordGetString(row,2);
|
|
comp = msi_get_loaded_component(package, component);
|
|
if (!comp)
|
|
return ERROR_SUCCESS;
|
|
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (comp->Action != INSTALLSTATE_LOCAL)
|
|
{
|
|
TRACE("component not scheduled for installation %s\n", debugstr_w(component));
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
file_key = MSI_RecordGetString(row,3);
|
|
if (!file_key)
|
|
{
|
|
ERR("Unable to get file key\n");
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
|
|
file = msi_get_loaded_file( package, file_key );
|
|
if (!file)
|
|
{
|
|
ERR("Original file unknown %s\n", debugstr_w(file_key));
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
|
|
if (!dest)
|
|
{
|
|
WARN("Unable to get duplicate filename\n");
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
TRACE("Duplicating file %s to %s\n", debugstr_w(file->TargetPath), debugstr_w(dest));
|
|
if (!copy_file( package, file->TargetPath, dest, TRUE ))
|
|
{
|
|
WARN( "failed to copy file %s -> %s (%lu)\n",
|
|
debugstr_w(file->TargetPath), debugstr_w(dest), GetLastError() );
|
|
}
|
|
FIXME("We should track these duplicate files as well\n");
|
|
|
|
uirow = MSI_CreateRecord( 9 );
|
|
MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
|
|
MSI_RecordSetInteger( uirow, 6, file->FileSize );
|
|
MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
free(dest);
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
UINT ACTION_DuplicateFiles(MSIPACKAGE *package)
|
|
{
|
|
MSIQUERY *view;
|
|
UINT rc;
|
|
|
|
if (package->script == SCRIPT_NONE)
|
|
return msi_schedule_action(package, SCRIPT_INSTALL, L"DuplicateFiles");
|
|
|
|
rc = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `DuplicateFile`", &view);
|
|
if (rc != ERROR_SUCCESS)
|
|
return ERROR_SUCCESS;
|
|
|
|
rc = MSI_IterateRecords(view, NULL, ITERATE_DuplicateFiles, package);
|
|
msiobj_release(&view->hdr);
|
|
return rc;
|
|
}
|
|
|
|
static UINT ITERATE_RemoveDuplicateFiles( MSIRECORD *row, LPVOID param )
|
|
{
|
|
MSIPACKAGE *package = param;
|
|
LPWSTR dest;
|
|
LPCWSTR file_key, component;
|
|
MSICOMPONENT *comp;
|
|
MSIRECORD *uirow;
|
|
MSIFILE *file;
|
|
|
|
component = MSI_RecordGetString( row, 2 );
|
|
comp = msi_get_loaded_component( package, component );
|
|
if (!comp)
|
|
return ERROR_SUCCESS;
|
|
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (comp->Action != INSTALLSTATE_ABSENT)
|
|
{
|
|
TRACE("component not scheduled for removal %s\n", debugstr_w(component));
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
file_key = MSI_RecordGetString( row, 3 );
|
|
if (!file_key)
|
|
{
|
|
ERR("Unable to get file key\n");
|
|
return ERROR_FUNCTION_FAILED;
|
|
}
|
|
|
|
file = msi_get_loaded_file( package, file_key );
|
|
if (!file)
|
|
{
|
|
ERR("Original file unknown %s\n", debugstr_w(file_key));
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
dest = get_duplicate_filename( package, row, file_key, file->TargetPath );
|
|
if (!dest)
|
|
{
|
|
WARN("Unable to get duplicate filename\n");
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
TRACE("Removing duplicate %s of %s\n", debugstr_w(dest), debugstr_w(file->TargetPath));
|
|
if (!msi_delete_file( package, dest ))
|
|
{
|
|
WARN( "failed to delete duplicate file %s (%lu)\n", debugstr_w(dest), GetLastError() );
|
|
}
|
|
|
|
uirow = MSI_CreateRecord( 9 );
|
|
MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString( row, 1 ) );
|
|
MSI_RecordSetStringW( uirow, 9, MSI_RecordGetString( row, 5 ) );
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
free(dest);
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
UINT ACTION_RemoveDuplicateFiles( MSIPACKAGE *package )
|
|
{
|
|
MSIQUERY *view;
|
|
UINT rc;
|
|
|
|
if (package->script == SCRIPT_NONE)
|
|
return msi_schedule_action(package, SCRIPT_INSTALL, L"RemoveDuplicateFiles");
|
|
|
|
rc = MSI_DatabaseOpenViewW( package->db, L"SELECT * FROM `DuplicateFile`", &view );
|
|
if (rc != ERROR_SUCCESS)
|
|
return ERROR_SUCCESS;
|
|
|
|
rc = MSI_IterateRecords( view, NULL, ITERATE_RemoveDuplicateFiles, package );
|
|
msiobj_release( &view->hdr );
|
|
return rc;
|
|
}
|
|
|
|
static BOOL verify_comp_for_removal(MSICOMPONENT *comp, UINT install_mode)
|
|
{
|
|
/* special case */
|
|
if (comp->Action != INSTALLSTATE_SOURCE &&
|
|
comp->Attributes & msidbComponentAttributesSourceOnly &&
|
|
(install_mode == msidbRemoveFileInstallModeOnRemove ||
|
|
install_mode == msidbRemoveFileInstallModeOnBoth)) return TRUE;
|
|
|
|
switch (comp->Action)
|
|
{
|
|
case INSTALLSTATE_LOCAL:
|
|
case INSTALLSTATE_SOURCE:
|
|
if (install_mode == msidbRemoveFileInstallModeOnInstall ||
|
|
install_mode == msidbRemoveFileInstallModeOnBoth) return TRUE;
|
|
break;
|
|
case INSTALLSTATE_ABSENT:
|
|
if (install_mode == msidbRemoveFileInstallModeOnRemove ||
|
|
install_mode == msidbRemoveFileInstallModeOnBoth) return TRUE;
|
|
break;
|
|
default: break;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
static UINT ITERATE_RemoveFiles(MSIRECORD *row, LPVOID param)
|
|
{
|
|
MSIPACKAGE *package = param;
|
|
MSICOMPONENT *comp;
|
|
MSIRECORD *uirow;
|
|
LPCWSTR component, dirprop;
|
|
UINT install_mode;
|
|
LPWSTR dir = NULL, path = NULL, filename = NULL;
|
|
DWORD size;
|
|
UINT ret = ERROR_SUCCESS;
|
|
|
|
component = MSI_RecordGetString(row, 2);
|
|
dirprop = MSI_RecordGetString(row, 4);
|
|
install_mode = MSI_RecordGetInteger(row, 5);
|
|
|
|
comp = msi_get_loaded_component(package, component);
|
|
if (!comp)
|
|
return ERROR_SUCCESS;
|
|
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (!verify_comp_for_removal(comp, install_mode))
|
|
{
|
|
TRACE("Skipping removal due to install mode\n");
|
|
return ERROR_SUCCESS;
|
|
}
|
|
if (comp->assembly && !comp->assembly->application)
|
|
{
|
|
return ERROR_SUCCESS;
|
|
}
|
|
if (comp->Attributes & msidbComponentAttributesPermanent)
|
|
{
|
|
TRACE("permanent component, not removing file\n");
|
|
return ERROR_SUCCESS;
|
|
}
|
|
|
|
dir = msi_dup_property(package->db, dirprop);
|
|
if (!dir)
|
|
{
|
|
WARN("directory property has no value\n");
|
|
return ERROR_SUCCESS;
|
|
}
|
|
size = 0;
|
|
if ((filename = wcsdup( MSI_RecordGetString(row, 3) )))
|
|
{
|
|
msi_reduce_to_long_filename( filename );
|
|
size = lstrlenW( filename );
|
|
}
|
|
size += lstrlenW(dir) + 2;
|
|
path = malloc(size * sizeof(WCHAR));
|
|
if (!path)
|
|
{
|
|
ret = ERROR_OUTOFMEMORY;
|
|
goto done;
|
|
}
|
|
|
|
if (filename)
|
|
{
|
|
lstrcpyW(path, dir);
|
|
PathAddBackslashW(path);
|
|
lstrcatW(path, filename);
|
|
|
|
TRACE("Deleting misc file: %s\n", debugstr_w(path));
|
|
msi_delete_file( package, path );
|
|
}
|
|
else
|
|
{
|
|
TRACE("Removing misc directory: %s\n", debugstr_w(dir));
|
|
msi_remove_directory( package, dir );
|
|
}
|
|
|
|
done:
|
|
uirow = MSI_CreateRecord( 9 );
|
|
MSI_RecordSetStringW( uirow, 1, MSI_RecordGetString(row, 1) );
|
|
MSI_RecordSetStringW( uirow, 9, dir );
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
|
msiobj_release( &uirow->hdr );
|
|
|
|
free(filename);
|
|
free(path);
|
|
free(dir);
|
|
return ret;
|
|
}
|
|
|
|
static void remove_folder( MSIFOLDER *folder )
|
|
{
|
|
FolderList *fl;
|
|
|
|
LIST_FOR_EACH_ENTRY( fl, &folder->children, FolderList, entry )
|
|
{
|
|
remove_folder( fl->folder );
|
|
}
|
|
if (!folder->persistent && folder->State != FOLDER_STATE_REMOVED)
|
|
{
|
|
if (RemoveDirectoryW( folder->ResolvedTarget )) folder->State = FOLDER_STATE_REMOVED;
|
|
}
|
|
}
|
|
|
|
UINT ACTION_RemoveFiles( MSIPACKAGE *package )
|
|
{
|
|
MSIQUERY *view;
|
|
MSICOMPONENT *comp;
|
|
MSIFILE *file;
|
|
UINT r;
|
|
|
|
if (package->script == SCRIPT_NONE)
|
|
return msi_schedule_action(package, SCRIPT_INSTALL, L"RemoveFiles");
|
|
|
|
r = MSI_DatabaseOpenViewW(package->db, L"SELECT * FROM `RemoveFile`", &view);
|
|
if (r == ERROR_SUCCESS)
|
|
{
|
|
r = MSI_IterateRecords(view, NULL, ITERATE_RemoveFiles, package);
|
|
msiobj_release(&view->hdr);
|
|
if (r != ERROR_SUCCESS)
|
|
return r;
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY( file, &package->files, MSIFILE, entry )
|
|
{
|
|
MSIRECORD *uirow;
|
|
VS_FIXEDFILEINFO *ver;
|
|
|
|
comp = file->Component;
|
|
file_update_ui( package, file, L"RemoveFiles" );
|
|
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (comp->Action != INSTALLSTATE_ABSENT || comp->Installed == INSTALLSTATE_SOURCE)
|
|
continue;
|
|
|
|
if (comp->assembly && !comp->assembly->application)
|
|
continue;
|
|
|
|
if (comp->Attributes & msidbComponentAttributesPermanent)
|
|
{
|
|
TRACE("permanent component, not removing file\n");
|
|
continue;
|
|
}
|
|
|
|
if (file->Version)
|
|
{
|
|
ver = msi_get_disk_file_version( package, file->TargetPath );
|
|
if (ver && msi_compare_file_versions( ver, file->Version ) > 0)
|
|
{
|
|
TRACE("newer version detected, not removing file\n");
|
|
free( ver );
|
|
continue;
|
|
}
|
|
free( ver );
|
|
}
|
|
|
|
if (file->state == msifs_installed)
|
|
WARN("removing installed file %s\n", debugstr_w(file->TargetPath));
|
|
|
|
TRACE("removing %s\n", debugstr_w(file->File) );
|
|
|
|
msi_set_file_attributes( package, file->TargetPath, FILE_ATTRIBUTE_NORMAL );
|
|
if (!msi_delete_file( package, file->TargetPath ))
|
|
{
|
|
WARN( "failed to delete %s (%lu)\n", debugstr_w(file->TargetPath), GetLastError() );
|
|
}
|
|
file->state = msifs_missing;
|
|
|
|
uirow = MSI_CreateRecord( 9 );
|
|
MSI_RecordSetStringW( uirow, 1, file->FileName );
|
|
MSI_RecordSetStringW( uirow, 9, comp->Directory );
|
|
MSI_ProcessMessage(package, INSTALLMESSAGE_ACTIONDATA, uirow);
|
|
msiobj_release( &uirow->hdr );
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY( comp, &package->components, MSICOMPONENT, entry )
|
|
{
|
|
comp->Action = msi_get_component_action( package, comp );
|
|
if (comp->Action != INSTALLSTATE_ABSENT) continue;
|
|
|
|
if (comp->Attributes & msidbComponentAttributesPermanent)
|
|
{
|
|
TRACE("permanent component, not removing directory\n");
|
|
continue;
|
|
}
|
|
if (comp->assembly && !comp->assembly->application)
|
|
msi_uninstall_assembly( package, comp );
|
|
else
|
|
{
|
|
MSIFOLDER *folder = msi_get_loaded_folder( package, comp->Directory );
|
|
if (folder) remove_folder( folder );
|
|
}
|
|
}
|
|
return ERROR_SUCCESS;
|
|
}
|