2011-05-24 10:49:37 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2004,2005 Aric Stewart for CodeWeavers
|
|
|
|
* Copyright 2011 Hans Leidekker 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#define COBJMACROS
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2011-07-07 09:22:48 +02:00
|
|
|
static BOOL match_language( MSIPACKAGE *package, LANGID langid )
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (!package->num_langids || !langid) return TRUE;
|
|
|
|
for (i = 0; i < package->num_langids; i++)
|
|
|
|
{
|
|
|
|
if (package->langids[i] == langid) return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-21 11:29:08 +02:00
|
|
|
struct transform_desc
|
|
|
|
{
|
|
|
|
WCHAR *product_code_from;
|
|
|
|
WCHAR *product_code_to;
|
|
|
|
WCHAR *version_from;
|
|
|
|
WCHAR *version_to;
|
|
|
|
WCHAR *upgrade_code;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void free_transform_desc( struct transform_desc *desc )
|
|
|
|
{
|
|
|
|
msi_free( desc->product_code_from );
|
|
|
|
msi_free( desc->product_code_to );
|
|
|
|
msi_free( desc->version_from );
|
|
|
|
msi_free( desc->version_to );
|
|
|
|
msi_free( desc->upgrade_code );
|
|
|
|
msi_free( desc );
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct transform_desc *parse_transform_desc( const WCHAR *str )
|
|
|
|
{
|
|
|
|
struct transform_desc *ret;
|
|
|
|
const WCHAR *p = str, *q;
|
|
|
|
UINT len;
|
|
|
|
|
|
|
|
if (!(ret = msi_alloc_zero( sizeof(*ret) ))) return NULL;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
q = wcschr( p, '}' );
|
2014-10-21 11:29:08 +02:00
|
|
|
if (*p != '{' || !q) goto error;
|
|
|
|
|
|
|
|
len = q - p + 1;
|
|
|
|
if (!(ret->product_code_from = msi_alloc( (len + 1) * sizeof(WCHAR) ))) goto error;
|
|
|
|
memcpy( ret->product_code_from, p, len * sizeof(WCHAR) );
|
|
|
|
ret->product_code_from[len] = 0;
|
|
|
|
|
|
|
|
p = q + 1;
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!(q = wcschr( p, ';' ))) goto error;
|
2014-10-21 11:29:08 +02:00
|
|
|
len = q - p;
|
|
|
|
if (!(ret->version_from = msi_alloc( (len + 1) * sizeof(WCHAR) ))) goto error;
|
|
|
|
memcpy( ret->version_from, p, len * sizeof(WCHAR) );
|
|
|
|
ret->version_from[len] = 0;
|
|
|
|
|
|
|
|
p = q + 1;
|
2019-06-13 08:42:35 +02:00
|
|
|
q = wcschr( p, '}' );
|
2014-10-21 11:29:08 +02:00
|
|
|
if (*p != '{' || !q) goto error;
|
|
|
|
|
|
|
|
len = q - p + 1;
|
|
|
|
if (!(ret->product_code_to = msi_alloc( (len + 1) * sizeof(WCHAR) ))) goto error;
|
|
|
|
memcpy( ret->product_code_to, p, len * sizeof(WCHAR) );
|
|
|
|
ret->product_code_to[len] = 0;
|
|
|
|
|
|
|
|
p = q + 1;
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!(q = wcschr( p, ';' ))) goto error;
|
2014-10-21 11:29:08 +02:00
|
|
|
len = q - p;
|
|
|
|
if (!(ret->version_to = msi_alloc( (len + 1) * sizeof(WCHAR) ))) goto error;
|
|
|
|
memcpy( ret->version_to, p, len * sizeof(WCHAR) );
|
|
|
|
ret->version_to[len] = 0;
|
|
|
|
|
|
|
|
p = q + 1;
|
2019-06-13 08:42:35 +02:00
|
|
|
q = wcschr( p, '}' );
|
2014-10-21 11:29:08 +02:00
|
|
|
if (*p != '{' || !q) goto error;
|
|
|
|
|
|
|
|
len = q - p + 1;
|
|
|
|
if (!(ret->upgrade_code = msi_alloc( (len + 1) * sizeof(WCHAR) ))) goto error;
|
|
|
|
memcpy( ret->upgrade_code, p, len * sizeof(WCHAR) );
|
|
|
|
ret->upgrade_code[len] = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
free_transform_desc( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-03 14:46:32 +02:00
|
|
|
static UINT check_transform_applicable( MSIPACKAGE *package, IStorage *transform )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
2014-10-21 11:29:08 +02:00
|
|
|
static const UINT supported_flags =
|
|
|
|
MSITRANSFORM_VALIDATE_PRODUCT | MSITRANSFORM_VALIDATE_LANGUAGE |
|
|
|
|
MSITRANSFORM_VALIDATE_PLATFORM | MSITRANSFORM_VALIDATE_MAJORVERSION |
|
|
|
|
MSITRANSFORM_VALIDATE_MINORVERSION | MSITRANSFORM_VALIDATE_UPGRADECODE;
|
2015-03-16 10:55:58 +01:00
|
|
|
MSISUMMARYINFO *si;
|
|
|
|
UINT r, valid_flags = 0, wanted_flags = 0;
|
2014-10-21 11:29:08 +02:00
|
|
|
WCHAR *template, *product, *p;
|
|
|
|
struct transform_desc *desc;
|
2014-09-03 15:41:09 +02:00
|
|
|
|
2015-03-16 10:55:58 +01:00
|
|
|
r = msi_get_suminfo( transform, 0, &si );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2014-10-21 11:29:08 +02:00
|
|
|
{
|
|
|
|
WARN("no summary information!\n");
|
2015-03-16 10:55:58 +01:00
|
|
|
return r;
|
2014-10-21 11:29:08 +02:00
|
|
|
}
|
|
|
|
wanted_flags = msi_suminfo_get_int32( si, PID_CHARCOUNT );
|
|
|
|
wanted_flags &= 0xffff; /* mask off error condition flags */
|
|
|
|
TRACE("validation flags 0x%04x\n", wanted_flags);
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2016-07-14 13:47:34 +02:00
|
|
|
/* native is not validating platform */
|
|
|
|
wanted_flags &= ~MSITRANSFORM_VALIDATE_PLATFORM;
|
|
|
|
|
2014-10-21 11:29:08 +02:00
|
|
|
if (wanted_flags & ~supported_flags)
|
|
|
|
{
|
|
|
|
FIXME("unsupported validation flags 0x%04x\n", wanted_flags);
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
if (!(template = msi_suminfo_dup_string( si, PID_TEMPLATE )))
|
|
|
|
{
|
|
|
|
WARN("no template property!\n");
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
TRACE("template property: %s\n", debugstr_w(template));
|
|
|
|
if (!(product = msi_get_suminfo_product( transform )))
|
|
|
|
{
|
|
|
|
WARN("no product property!\n");
|
|
|
|
msi_free( template );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
TRACE("product property: %s\n", debugstr_w(product));
|
|
|
|
if (!(desc = parse_transform_desc( product )))
|
|
|
|
{
|
|
|
|
msi_free( template );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
msi_free( product );
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2014-10-21 11:29:08 +02:00
|
|
|
if (wanted_flags & MSITRANSFORM_VALIDATE_LANGUAGE)
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!template[0] || ((p = wcschr( template, ';' )) && match_language( package, wcstol( p + 1, NULL, 10 ) )))
|
2014-10-21 11:29:08 +02:00
|
|
|
{
|
|
|
|
valid_flags |= MSITRANSFORM_VALIDATE_LANGUAGE;
|
|
|
|
}
|
|
|
|
}
|
2014-09-03 15:41:09 +02:00
|
|
|
if (wanted_flags & MSITRANSFORM_VALIDATE_PRODUCT)
|
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
WCHAR *product_code_installed = msi_dup_property( package->db, L"ProductCode" );
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2014-10-21 11:29:08 +02:00
|
|
|
if (!product_code_installed)
|
|
|
|
{
|
|
|
|
msi_free( template );
|
|
|
|
free_transform_desc( desc );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_INSTALL_PACKAGE_INVALID;
|
|
|
|
}
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!wcscmp( desc->product_code_from, product_code_installed ))
|
2014-09-03 15:41:09 +02:00
|
|
|
{
|
|
|
|
valid_flags |= MSITRANSFORM_VALIDATE_PRODUCT;
|
|
|
|
}
|
2014-10-21 11:29:08 +02:00
|
|
|
msi_free( product_code_installed );
|
2014-09-03 15:41:09 +02:00
|
|
|
}
|
2014-10-21 11:29:08 +02:00
|
|
|
msi_free( template );
|
|
|
|
if (wanted_flags & MSITRANSFORM_VALIDATE_MAJORVERSION)
|
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
WCHAR *product_version_installed = msi_dup_property( package->db, L"ProductVersion" );
|
2014-10-21 11:29:08 +02:00
|
|
|
DWORD major_installed, minor_installed, major, minor;
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2014-10-21 11:29:08 +02:00
|
|
|
if (!product_version_installed)
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
2014-10-21 11:29:08 +02:00
|
|
|
free_transform_desc( desc );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_INSTALL_PACKAGE_INVALID;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
2014-10-21 11:29:08 +02:00
|
|
|
msi_parse_version_string( product_version_installed, &major_installed, &minor_installed );
|
|
|
|
msi_parse_version_string( desc->version_from, &major, &minor );
|
|
|
|
|
|
|
|
if (major_installed == major)
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
2014-10-21 11:29:08 +02:00
|
|
|
valid_flags |= MSITRANSFORM_VALIDATE_MAJORVERSION;
|
|
|
|
wanted_flags &= ~MSITRANSFORM_VALIDATE_MINORVERSION;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
2014-10-21 11:29:08 +02:00
|
|
|
msi_free( product_version_installed );
|
|
|
|
}
|
|
|
|
else if (wanted_flags & MSITRANSFORM_VALIDATE_MINORVERSION)
|
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
WCHAR *product_version_installed = msi_dup_property( package->db, L"ProductVersion" );
|
2014-10-21 11:29:08 +02:00
|
|
|
DWORD major_installed, minor_installed, major, minor;
|
|
|
|
|
|
|
|
if (!product_version_installed)
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
2014-10-21 11:29:08 +02:00
|
|
|
free_transform_desc( desc );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_INSTALL_PACKAGE_INVALID;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
2014-10-21 11:29:08 +02:00
|
|
|
msi_parse_version_string( product_version_installed, &major_installed, &minor_installed );
|
|
|
|
msi_parse_version_string( desc->version_from, &major, &minor );
|
|
|
|
|
|
|
|
if (major_installed == major && minor_installed == minor)
|
|
|
|
valid_flags |= MSITRANSFORM_VALIDATE_MINORVERSION;
|
|
|
|
msi_free( product_version_installed );
|
|
|
|
}
|
|
|
|
if (wanted_flags & MSITRANSFORM_VALIDATE_UPGRADECODE)
|
|
|
|
{
|
2020-10-29 11:47:14 +01:00
|
|
|
WCHAR *upgrade_code_installed = msi_dup_property( package->db, L"UpgradeCode" );
|
2014-10-21 11:29:08 +02:00
|
|
|
|
|
|
|
if (!upgrade_code_installed)
|
|
|
|
{
|
|
|
|
free_transform_desc( desc );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
return ERROR_INSTALL_PACKAGE_INVALID;
|
|
|
|
}
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!wcscmp( desc->upgrade_code, upgrade_code_installed ))
|
2014-10-21 11:29:08 +02:00
|
|
|
valid_flags |= MSITRANSFORM_VALIDATE_UPGRADECODE;
|
|
|
|
msi_free( upgrade_code_installed );
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
|
2014-10-21 11:29:08 +02:00
|
|
|
free_transform_desc( desc );
|
2014-09-03 15:41:09 +02:00
|
|
|
msiobj_release( &si->hdr );
|
2014-10-21 11:29:08 +02:00
|
|
|
if ((valid_flags & wanted_flags) != wanted_flags) return ERROR_FUNCTION_FAILED;
|
2014-09-03 15:41:09 +02:00
|
|
|
TRACE("applicable transform\n");
|
|
|
|
return ERROR_SUCCESS;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT apply_substorage_transform( MSIPACKAGE *package, MSIDATABASE *patch_db, LPCWSTR name )
|
|
|
|
{
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
IStorage *stg = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
TRACE("%p %s\n", package, debugstr_w(name));
|
|
|
|
|
|
|
|
if (*name++ != ':')
|
|
|
|
{
|
|
|
|
ERR("expected a colon in %s\n", debugstr_w(name));
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
r = IStorage_OpenStorage( patch_db->storage, name, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &stg );
|
|
|
|
if (SUCCEEDED(r))
|
|
|
|
{
|
|
|
|
ret = check_transform_applicable( package, stg );
|
|
|
|
if (ret == ERROR_SUCCESS)
|
2020-07-01 10:44:00 +02:00
|
|
|
{
|
|
|
|
msi_table_apply_transform( package->db, stg, MSITRANSFORM_ERROR_VIEWTRANSFORM );
|
2020-06-25 20:08:43 +02:00
|
|
|
msi_table_apply_transform( package->db, stg, 0 );
|
2020-07-01 10:44:00 +02:00
|
|
|
}
|
2011-05-24 10:49:37 +02:00
|
|
|
else
|
2020-07-01 10:44:00 +02:00
|
|
|
{
|
2011-05-24 10:49:37 +02:00
|
|
|
TRACE("substorage transform %s wasn't applicable\n", debugstr_w(name));
|
2020-07-01 10:44:00 +02:00
|
|
|
}
|
2011-05-24 10:49:37 +02:00
|
|
|
IStorage_Release( stg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("failed to open substorage %s\n", debugstr_w(name));
|
|
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT msi_check_patch_applicable( MSIPACKAGE *package, MSISUMMARYINFO *si )
|
|
|
|
{
|
|
|
|
LPWSTR guid_list, *guids, product_code;
|
|
|
|
UINT i, ret = ERROR_FUNCTION_FAILED;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
product_code = msi_dup_property( package->db, L"ProductCode" );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (!product_code)
|
|
|
|
{
|
|
|
|
/* FIXME: the property ProductCode should be written into the DB somewhere */
|
|
|
|
ERR("no product code to check\n");
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
guid_list = msi_suminfo_dup_string( si, PID_TEMPLATE );
|
|
|
|
guids = msi_split_string( guid_list, ';' );
|
|
|
|
for (i = 0; guids[i] && ret != ERROR_SUCCESS; i++)
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!wcscmp( guids[i], product_code )) ret = ERROR_SUCCESS;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
msi_free( guids );
|
|
|
|
msi_free( guid_list );
|
|
|
|
msi_free( product_code );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-07 09:14:55 +02:00
|
|
|
static UINT msi_parse_patch_summary( MSISUMMARYINFO *si, MSIPATCHINFO **patch )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
MSIPATCHINFO *pi;
|
|
|
|
UINT r = ERROR_SUCCESS;
|
|
|
|
WCHAR *p;
|
|
|
|
|
|
|
|
if (!(pi = msi_alloc_zero( sizeof(MSIPATCHINFO) )))
|
|
|
|
{
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
if (!(pi->patchcode = msi_suminfo_dup_string( si, PID_REVNUMBER )))
|
|
|
|
{
|
|
|
|
msi_free( pi );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
p = pi->patchcode;
|
|
|
|
if (*p != '{')
|
|
|
|
{
|
|
|
|
msi_free( pi->patchcode );
|
|
|
|
msi_free( pi );
|
|
|
|
return ERROR_PATCH_PACKAGE_INVALID;
|
|
|
|
}
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!(p = wcschr( p + 1, '}' )))
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
msi_free( pi->patchcode );
|
|
|
|
msi_free( pi );
|
|
|
|
return ERROR_PATCH_PACKAGE_INVALID;
|
|
|
|
}
|
|
|
|
if (p[1])
|
|
|
|
{
|
|
|
|
FIXME("patch obsoletes %s\n", debugstr_w(p + 1));
|
|
|
|
p[1] = 0;
|
|
|
|
}
|
|
|
|
TRACE("patch code %s\n", debugstr_w(pi->patchcode));
|
2011-08-23 14:42:03 +02:00
|
|
|
if (!(pi->products = msi_suminfo_dup_string( si, PID_TEMPLATE )))
|
|
|
|
{
|
|
|
|
msi_free( pi->patchcode );
|
|
|
|
msi_free( pi );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
2011-05-24 10:49:37 +02:00
|
|
|
if (!(pi->transforms = msi_suminfo_dup_string( si, PID_LASTAUTHOR )))
|
|
|
|
{
|
|
|
|
msi_free( pi->patchcode );
|
2011-08-23 14:42:03 +02:00
|
|
|
msi_free( pi->products );
|
2011-05-24 10:49:37 +02:00
|
|
|
msi_free( pi );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
*patch = pi;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT patch_set_media_source_prop( MSIPACKAGE *package )
|
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
const WCHAR *property;
|
|
|
|
WCHAR *patch;
|
|
|
|
UINT r;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( package->db, L"SELECT `Source` FROM `Media` WHERE `Source` IS NOT NULL", &view );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, 0 );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
property = MSI_RecordGetString( rec, 1 );
|
2020-10-29 11:47:14 +01:00
|
|
|
patch = msi_dup_property( package->db, L"PATCH" );
|
2012-10-29 12:15:21 +01:00
|
|
|
msi_set_property( package->db, property, patch, -1 );
|
2011-05-24 10:49:37 +02:00
|
|
|
msi_free( patch );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct patch_offset
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
WCHAR *name;
|
|
|
|
UINT sequence;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct patch_offset_list
|
|
|
|
{
|
|
|
|
struct list files;
|
2015-03-04 14:30:42 +01:00
|
|
|
struct list patches;
|
2011-05-24 10:49:37 +02:00
|
|
|
UINT count, min, max;
|
|
|
|
UINT offset_to_apply;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct patch_offset_list *patch_offset_list_create( void )
|
|
|
|
{
|
|
|
|
struct patch_offset_list *pos = msi_alloc( sizeof(struct patch_offset_list) );
|
|
|
|
list_init( &pos->files );
|
2015-03-04 14:30:42 +01:00
|
|
|
list_init( &pos->patches );
|
2011-05-24 10:49:37 +02:00
|
|
|
pos->count = pos->max = 0;
|
|
|
|
pos->min = 999999;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void patch_offset_list_free( struct patch_offset_list *pos )
|
|
|
|
{
|
|
|
|
struct patch_offset *po, *po2;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( po, po2, &pos->files, struct patch_offset, entry )
|
|
|
|
{
|
|
|
|
msi_free( po->name );
|
|
|
|
msi_free( po );
|
|
|
|
}
|
2015-03-04 14:30:42 +01:00
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( po, po2, &pos->patches, struct patch_offset, entry )
|
|
|
|
{
|
|
|
|
msi_free( po->name );
|
|
|
|
msi_free( po );
|
|
|
|
}
|
2011-05-24 10:49:37 +02:00
|
|
|
msi_free( pos );
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
static void patch_offset_get_filepatches( MSIDATABASE *db, UINT last_sequence, struct patch_offset_list *pos )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT r;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db, L"SELECT * FROM `Patch` WHERE `Sequence` <= ? ORDER BY `Sequence`", &view );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 1 );
|
|
|
|
MSI_RecordSetInteger( rec, 1, last_sequence );
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
2015-03-04 14:30:42 +01:00
|
|
|
struct patch_offset *po = msi_alloc( sizeof(struct patch_offset) );
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
po->name = msi_dup_record_field( rec, 1 );
|
|
|
|
po->sequence = MSI_RecordGetInteger( rec, 2 );
|
|
|
|
pos->min = min( pos->min, po->sequence );
|
|
|
|
pos->max = max( pos->max, po->sequence );
|
|
|
|
list_add_tail( &pos->patches, &po->entry );
|
2011-05-24 10:49:37 +02:00
|
|
|
pos->count++;
|
2015-03-04 14:30:42 +01:00
|
|
|
|
2011-05-24 10:49:37 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void patch_offset_get_files( MSIDATABASE *db, UINT last_sequence, struct patch_offset_list *pos )
|
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT r;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db, L"SELECT * FROM `File` WHERE `Sequence` <= ? ORDER BY `Sequence`", &view );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 1 );
|
|
|
|
MSI_RecordSetInteger( rec, 1, last_sequence );
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
UINT attributes = MSI_RecordGetInteger( rec, 7 );
|
|
|
|
if (attributes & msidbFileAttributesPatchAdded)
|
|
|
|
{
|
|
|
|
struct patch_offset *po = msi_alloc( sizeof(struct patch_offset) );
|
|
|
|
|
|
|
|
po->name = msi_dup_record_field( rec, 1 );
|
|
|
|
po->sequence = MSI_RecordGetInteger( rec, 8 );
|
|
|
|
pos->min = min( pos->min, po->sequence );
|
|
|
|
pos->max = max( pos->max, po->sequence );
|
|
|
|
list_add_tail( &pos->files, &po->entry );
|
|
|
|
pos->count++;
|
|
|
|
}
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
static UINT patch_update_file_sequence( MSIDATABASE *db, const struct patch_offset_list *pos,
|
|
|
|
MSIQUERY *view, MSIRECORD *rec )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
struct patch_offset *po;
|
2015-03-04 14:30:42 +01:00
|
|
|
const WCHAR *file = MSI_RecordGetString( rec, 1 );
|
|
|
|
UINT r = ERROR_SUCCESS, seq = MSI_RecordGetInteger( rec, 8 );
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( po, &pos->files, struct patch_offset, entry )
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!wcsicmp( file, po->name ))
|
2015-03-04 14:30:42 +01:00
|
|
|
{
|
|
|
|
MSI_RecordSetInteger( rec, 8, seq + pos->offset_to_apply );
|
|
|
|
r = MSI_ViewModify( view, MSIMODIFY_UPDATE, rec );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
ERR("Failed to update offset for file %s (%u)\n", debugstr_w(file), r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT patch_update_filepatch_sequence( MSIDATABASE *db, const struct patch_offset_list *pos,
|
|
|
|
MSIQUERY *view, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
struct patch_offset *po;
|
|
|
|
const WCHAR *file = MSI_RecordGetString( rec, 1 );
|
|
|
|
UINT r = ERROR_SUCCESS, seq = MSI_RecordGetInteger( rec, 2 );
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( po, &pos->patches, struct patch_offset, entry )
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
if (seq == po->sequence && !wcsicmp( file, po->name ))
|
2015-03-04 14:30:42 +01:00
|
|
|
{
|
|
|
|
MSIQUERY *delete_view, *insert_view;
|
|
|
|
MSIRECORD *rec2;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db, L"DELETE FROM `Patch` WHERE `File_` = ? AND `Sequence` = ?", &delete_view );
|
2015-03-04 14:30:42 +01:00
|
|
|
if (r != ERROR_SUCCESS) return r;
|
|
|
|
|
|
|
|
rec2 = MSI_CreateRecord( 2 );
|
|
|
|
MSI_RecordSetStringW( rec2, 1, po->name );
|
|
|
|
MSI_RecordSetInteger( rec2, 2, po->sequence );
|
|
|
|
r = MSI_ViewExecute( delete_view, rec2 );
|
|
|
|
msiobj_release( &delete_view->hdr );
|
|
|
|
msiobj_release( &rec2->hdr );
|
|
|
|
if (r != ERROR_SUCCESS) return r;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db, L"INSERT INTO `Patch` (`File_`,`Sequence`,`PatchSize`,`Attributes`,"
|
|
|
|
L"`Header`,`StreamRef_`) VALUES (?,?,?,?,?,?)", &insert_view );
|
2015-03-04 14:30:42 +01:00
|
|
|
if (r != ERROR_SUCCESS) return r;
|
|
|
|
|
|
|
|
MSI_RecordSetInteger( rec, 2, po->sequence + pos->offset_to_apply );
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( insert_view, rec );
|
|
|
|
msiobj_release( &insert_view->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
ERR("Failed to update offset for filepatch %s (%u)\n", debugstr_w(file), r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT patch_offset_modify_db( MSIDATABASE *db, struct patch_offset_list *pos )
|
|
|
|
{
|
2011-05-24 10:49:37 +02:00
|
|
|
MSIRECORD *rec;
|
|
|
|
MSIQUERY *view;
|
2015-03-04 14:30:42 +01:00
|
|
|
UINT r, min = pos->min, max = pos->max, r_fetch;
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db,
|
|
|
|
L"SELECT * FROM `File` WHERE `Sequence` >= ? AND `Sequence` <= ? ORDER BY `Sequence`",
|
|
|
|
&view );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 2 );
|
2015-03-04 14:30:42 +01:00
|
|
|
MSI_RecordSetInteger( rec, 1, min );
|
|
|
|
MSI_RecordSetInteger( rec, 2, max );
|
2011-05-24 10:49:37 +02:00
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
while ((r_fetch = MSI_ViewFetch( view, &rec )) == ERROR_SUCCESS)
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
2015-03-04 14:30:42 +01:00
|
|
|
r = patch_update_file_sequence( db, pos, view, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS) goto done;
|
|
|
|
}
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( db,
|
|
|
|
L"SELECT *FROM `Patch` WHERE `Sequence` >= ? AND `Sequence` <= ? ORDER BY `Sequence`",
|
|
|
|
&view );
|
2015-03-04 14:30:42 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 2 );
|
|
|
|
MSI_RecordSetInteger( rec, 1, min );
|
|
|
|
MSI_RecordSetInteger( rec, 2, max );
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while ((r_fetch = MSI_ViewFetch( view, &rec )) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
r = patch_update_filepatch_sequence( db, pos, view, rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS) goto done;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release( &view->hdr );
|
2015-03-04 14:30:42 +01:00
|
|
|
return r;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
static const WCHAR patch_media_query[] =
|
|
|
|
L"SELECT * FROM `Media` WHERE `Source` IS NOT NULL AND `Cabinet` IS NOT NULL ORDER BY `DiskId`";
|
2011-05-24 10:49:37 +02:00
|
|
|
|
|
|
|
struct patch_media
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
UINT disk_id;
|
|
|
|
UINT last_sequence;
|
|
|
|
WCHAR *prompt;
|
|
|
|
WCHAR *cabinet;
|
|
|
|
WCHAR *volume;
|
|
|
|
WCHAR *source;
|
|
|
|
};
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
static UINT patch_add_media( MSIPACKAGE *package, IStorage *storage, MSIPATCHINFO *patch )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT r, disk_id;
|
|
|
|
struct list media_list;
|
|
|
|
struct patch_media *media, *next;
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( package->db, patch_media_query, &view );
|
|
|
|
if (r != ERROR_SUCCESS) return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, 0 );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
TRACE("query failed %u\n", r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
list_init( &media_list );
|
|
|
|
while (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
disk_id = MSI_RecordGetInteger( rec, 1 );
|
|
|
|
TRACE("disk_id %u\n", disk_id);
|
|
|
|
if (disk_id >= MSI_INITIAL_MEDIA_TRANSFORM_DISKID)
|
|
|
|
{
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
continue;
|
|
|
|
}
|
2020-10-29 11:47:14 +01:00
|
|
|
if (!(media = msi_alloc( sizeof( *media ))))
|
|
|
|
{
|
2015-06-11 16:57:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
goto done;
|
2020-10-29 11:47:14 +01:00
|
|
|
}
|
2011-05-24 10:49:37 +02:00
|
|
|
media->disk_id = disk_id;
|
|
|
|
media->last_sequence = MSI_RecordGetInteger( rec, 2 );
|
|
|
|
media->prompt = msi_dup_record_field( rec, 3 );
|
|
|
|
media->cabinet = msi_dup_record_field( rec, 4 );
|
|
|
|
media->volume = msi_dup_record_field( rec, 5 );
|
|
|
|
media->source = msi_dup_record_field( rec, 6 );
|
|
|
|
|
|
|
|
list_add_tail( &media_list, &media->entry );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
LIST_FOR_EACH_ENTRY( media, &media_list, struct patch_media, entry )
|
|
|
|
{
|
|
|
|
MSIQUERY *delete_view, *insert_view;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( package->db, L"DELETE FROM `Media` WHERE `DiskId`=?", &delete_view );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS) goto done;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 1 );
|
|
|
|
MSI_RecordSetInteger( rec, 1, media->disk_id );
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( delete_view, rec );
|
|
|
|
msiobj_release( &delete_view->hdr );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS) goto done;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = MSI_DatabaseOpenViewW( package->db, L"INSERT INTO `Media` (`DiskId`,`LastSequence`,`DiskPrompt`,"
|
|
|
|
L"`Cabinet`,`VolumeLabel`,`Source`) VALUES (?,?,?,?,?,?)",
|
|
|
|
&insert_view );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS) goto done;
|
|
|
|
|
|
|
|
disk_id = package->db->media_transform_disk_id;
|
|
|
|
TRACE("disk id %u\n", disk_id);
|
2015-03-25 14:32:44 +01:00
|
|
|
TRACE("last sequence %u\n", media->last_sequence);
|
2011-05-24 10:49:37 +02:00
|
|
|
TRACE("prompt %s\n", debugstr_w(media->prompt));
|
|
|
|
TRACE("cabinet %s\n", debugstr_w(media->cabinet));
|
|
|
|
TRACE("volume %s\n", debugstr_w(media->volume));
|
|
|
|
TRACE("source %s\n", debugstr_w(media->source));
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( 6 );
|
|
|
|
MSI_RecordSetInteger( rec, 1, disk_id );
|
2015-03-25 14:32:44 +01:00
|
|
|
MSI_RecordSetInteger( rec, 2, media->last_sequence );
|
2011-05-24 10:49:37 +02:00
|
|
|
MSI_RecordSetStringW( rec, 3, media->prompt );
|
|
|
|
MSI_RecordSetStringW( rec, 4, media->cabinet );
|
|
|
|
MSI_RecordSetStringW( rec, 5, media->volume );
|
|
|
|
MSI_RecordSetStringW( rec, 6, media->source );
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( insert_view, rec );
|
|
|
|
msiobj_release( &insert_view->hdr );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
if (r != ERROR_SUCCESS) goto done;
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
r = msi_add_cabinet_stream( package, disk_id, storage, media->cabinet );
|
|
|
|
if (r != ERROR_SUCCESS) ERR("failed to add cabinet stream %u\n", r);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
patch->disk_id = disk_id;
|
|
|
|
package->db->media_transform_disk_id++;
|
|
|
|
}
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( media, next, &media_list, struct patch_media, entry )
|
|
|
|
{
|
|
|
|
list_remove( &media->entry );
|
|
|
|
msi_free( media->prompt );
|
|
|
|
msi_free( media->cabinet );
|
|
|
|
msi_free( media->volume );
|
|
|
|
msi_free( media->source );
|
|
|
|
msi_free( media );
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
static UINT patch_set_offsets( MSIDATABASE *db, MSIPATCHINFO *patch )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
r = MSI_DatabaseOpenViewW( db, patch_media_query, &view );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = MSI_ViewExecute( view, 0 );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
while (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
2015-03-04 14:30:42 +01:00
|
|
|
UINT offset, last_sequence = MSI_RecordGetInteger( rec, 2 );
|
2011-05-24 10:49:37 +02:00
|
|
|
struct patch_offset_list *pos;
|
|
|
|
|
|
|
|
/* FIXME: set/check Source field instead? */
|
|
|
|
if (last_sequence >= MSI_INITIAL_MEDIA_TRANSFORM_OFFSET)
|
|
|
|
{
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pos = patch_offset_list_create();
|
|
|
|
patch_offset_get_files( db, last_sequence, pos );
|
2015-03-04 14:30:42 +01:00
|
|
|
patch_offset_get_filepatches( db, last_sequence, pos );
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
offset = db->media_transform_offset - pos->min;
|
|
|
|
last_sequence = offset + pos->max;
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
last_sequence += pos->min;
|
|
|
|
pos->offset_to_apply = offset;
|
|
|
|
if (pos->count)
|
|
|
|
{
|
|
|
|
r = patch_offset_modify_db( db, pos );
|
2011-05-24 10:49:37 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
2015-03-04 14:30:42 +01:00
|
|
|
ERR("Failed to set offsets, expect breakage (%u)\n", r);
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
2015-03-04 14:30:42 +01:00
|
|
|
MSI_RecordSetInteger( rec, 2, last_sequence );
|
|
|
|
r = MSI_ViewModify( view, MSIMODIFY_UPDATE, rec );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
ERR("Failed to update Media table entry, expect breakage (%u)\n", r);
|
|
|
|
|
|
|
|
db->media_transform_offset = last_sequence + 1;
|
|
|
|
|
2011-05-24 10:49:37 +02:00
|
|
|
patch_offset_list_free( pos );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-04-19 11:26:49 +02:00
|
|
|
static DWORD is_uninstallable( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
MSIQUERY *view;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
if (MSI_DatabaseOpenViewW( db, L"SELECT `Value` FROM `MsiPatchMetadata` WHERE `Company` IS NULL "
|
|
|
|
L"AND `Property`='AllowRemoval'", &view ) != ERROR_SUCCESS) return 0;
|
2017-04-19 11:26:49 +02:00
|
|
|
if (MSI_ViewExecute( view, 0 ) != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MSI_ViewFetch( view, &rec ) == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
const WCHAR *value = MSI_RecordGetString( rec, 1 );
|
2019-06-13 08:42:35 +02:00
|
|
|
ret = wcstol( value, NULL, 10 );
|
2017-04-19 11:26:49 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
FIXME( "check other criteria\n" );
|
|
|
|
|
|
|
|
msiobj_release( &view->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-07 09:14:55 +02:00
|
|
|
static UINT msi_apply_patch_db( MSIPACKAGE *package, MSIDATABASE *patch_db, MSIPATCHINFO *patch )
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
UINT i, r = ERROR_SUCCESS;
|
|
|
|
WCHAR **substorage;
|
|
|
|
|
|
|
|
/* apply substorage transforms */
|
|
|
|
substorage = msi_split_string( patch->transforms, ';' );
|
|
|
|
for (i = 0; substorage && substorage[i] && r == ERROR_SUCCESS; i++)
|
|
|
|
{
|
|
|
|
r = apply_substorage_transform( package, patch_db, substorage[i] );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
{
|
2015-03-04 14:30:42 +01:00
|
|
|
r = patch_set_offsets( package->db, patch );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
r = patch_add_media( package, patch_db->storage, patch );
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
msi_free( substorage );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
2015-03-04 14:30:42 +01:00
|
|
|
r = patch_set_media_source_prop( package );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2017-04-19 11:26:49 +02:00
|
|
|
patch->uninstallable = is_uninstallable( patch_db );
|
|
|
|
patch->state = MSIPATCHSTATE_APPLIED;
|
2011-05-24 10:49:37 +02:00
|
|
|
list_add_tail( &package->patches, &patch->entry );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-08-23 14:42:03 +02:00
|
|
|
void msi_free_patchinfo( MSIPATCHINFO *patch )
|
|
|
|
{
|
|
|
|
msi_free( patch->patchcode );
|
|
|
|
msi_free( patch->products );
|
|
|
|
msi_free( patch->transforms );
|
|
|
|
msi_free( patch->filename );
|
|
|
|
msi_free( patch->localfile );
|
|
|
|
msi_free( patch );
|
|
|
|
}
|
|
|
|
|
2011-05-24 10:49:37 +02:00
|
|
|
static UINT msi_apply_patch_package( MSIPACKAGE *package, const WCHAR *file )
|
|
|
|
{
|
|
|
|
MSIDATABASE *patch_db = NULL;
|
|
|
|
WCHAR localfile[MAX_PATH];
|
|
|
|
MSISUMMARYINFO *si;
|
|
|
|
MSIPATCHINFO *patch = NULL;
|
2015-03-16 10:55:58 +01:00
|
|
|
UINT r;
|
2011-05-24 10:49:37 +02:00
|
|
|
|
2015-03-16 10:55:21 +01:00
|
|
|
TRACE("%p, %s\n", package, debugstr_w(file));
|
2011-05-24 10:49:37 +02:00
|
|
|
|
|
|
|
r = MSI_OpenDatabaseW( file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to open patch collection %s\n", debugstr_w( file ) );
|
|
|
|
return r;
|
|
|
|
}
|
2015-03-16 10:55:58 +01:00
|
|
|
r = msi_get_suminfo( patch_db->storage, 0, &si );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
msiobj_release( &patch_db->hdr );
|
2015-03-16 10:55:58 +01:00
|
|
|
return r;
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
r = msi_check_patch_applicable( package, si );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
TRACE("patch not applicable\n");
|
|
|
|
r = ERROR_SUCCESS;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
r = msi_parse_patch_summary( si, &patch );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
goto done;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
r = msi_create_empty_local_file( localfile, L".msp" );
|
2011-05-24 10:49:37 +02:00
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
goto done;
|
|
|
|
|
2011-06-30 12:15:37 +02:00
|
|
|
r = ERROR_OUTOFMEMORY;
|
2015-04-10 12:58:26 +02:00
|
|
|
patch->registered = FALSE;
|
2011-06-30 12:15:37 +02:00
|
|
|
if (!(patch->filename = strdupW( file ))) goto done;
|
|
|
|
if (!(patch->localfile = strdupW( localfile ))) goto done;
|
2011-05-24 10:49:37 +02:00
|
|
|
|
|
|
|
r = msi_apply_patch_db( package, patch_db, patch );
|
|
|
|
if (r != ERROR_SUCCESS) WARN("patch failed to apply %u\n", r);
|
|
|
|
|
|
|
|
done:
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
msiobj_release( &patch_db->hdr );
|
|
|
|
if (patch && r != ERROR_SUCCESS)
|
|
|
|
{
|
2011-08-23 14:42:03 +02:00
|
|
|
DeleteFileW( patch->localfile );
|
|
|
|
msi_free_patchinfo( patch );
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the PATCH property, and apply all the patches it specifies */
|
|
|
|
UINT msi_apply_patches( MSIPACKAGE *package )
|
|
|
|
{
|
|
|
|
LPWSTR patch_list, *patches;
|
|
|
|
UINT i, r = ERROR_SUCCESS;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
patch_list = msi_dup_property( package->db, L"PATCH" );
|
2011-05-24 10:49:37 +02:00
|
|
|
|
|
|
|
TRACE("patches to be applied: %s\n", debugstr_w(patch_list));
|
|
|
|
|
|
|
|
patches = msi_split_string( patch_list, ';' );
|
|
|
|
for (i = 0; patches && patches[i] && r == ERROR_SUCCESS; i++)
|
|
|
|
r = msi_apply_patch_package( package, patches[i] );
|
|
|
|
|
|
|
|
msi_free( patches );
|
|
|
|
msi_free( patch_list );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT msi_apply_transforms( MSIPACKAGE *package )
|
|
|
|
{
|
|
|
|
LPWSTR xform_list, *xforms;
|
|
|
|
UINT i, r = ERROR_SUCCESS;
|
|
|
|
|
2020-10-29 11:47:14 +01:00
|
|
|
xform_list = msi_dup_property( package->db, L"TRANSFORMS" );
|
2011-05-24 10:49:37 +02:00
|
|
|
xforms = msi_split_string( xform_list, ';' );
|
|
|
|
|
|
|
|
for (i = 0; xforms && xforms[i] && r == ERROR_SUCCESS; i++)
|
|
|
|
{
|
|
|
|
if (xforms[i][0] == ':')
|
|
|
|
r = apply_substorage_transform( package, package->db, xforms[i] );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WCHAR *transform;
|
|
|
|
|
|
|
|
if (!PathIsRelativeW( xforms[i] )) transform = xforms[i];
|
|
|
|
else
|
|
|
|
{
|
2019-06-13 08:42:35 +02:00
|
|
|
WCHAR *p = wcsrchr( package->PackagePath, '\\' );
|
2011-05-24 10:49:37 +02:00
|
|
|
DWORD len = p - package->PackagePath + 1;
|
|
|
|
|
2019-06-13 08:42:35 +02:00
|
|
|
if (!(transform = msi_alloc( (len + lstrlenW( xforms[i] ) + 1) * sizeof(WCHAR)) ))
|
2011-05-24 10:49:37 +02:00
|
|
|
{
|
|
|
|
msi_free( xforms );
|
|
|
|
msi_free( xform_list );
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
memcpy( transform, package->PackagePath, len * sizeof(WCHAR) );
|
2019-06-13 08:42:35 +02:00
|
|
|
memcpy( transform + len, xforms[i], (lstrlenW( xforms[i] ) + 1) * sizeof(WCHAR) );
|
2011-05-24 10:49:37 +02:00
|
|
|
}
|
|
|
|
r = MSI_DatabaseApplyTransformW( package->db, transform, 0 );
|
|
|
|
if (transform != xforms[i]) msi_free( transform );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msi_free( xforms );
|
|
|
|
msi_free( xform_list );
|
|
|
|
return r;
|
|
|
|
}
|
2011-06-30 12:15:37 +02:00
|
|
|
|
|
|
|
UINT msi_apply_registered_patch( MSIPACKAGE *package, LPCWSTR patch_code )
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
DWORD len;
|
|
|
|
WCHAR patch_file[MAX_PATH];
|
|
|
|
MSIDATABASE *patch_db;
|
|
|
|
MSIPATCHINFO *patch_info;
|
|
|
|
MSISUMMARYINFO *si;
|
|
|
|
|
2015-03-16 10:55:21 +01:00
|
|
|
TRACE("%p, %s\n", package, debugstr_w(patch_code));
|
|
|
|
|
2018-08-20 21:15:43 +02:00
|
|
|
len = ARRAY_SIZE( patch_file );
|
2011-06-30 12:15:37 +02:00
|
|
|
r = MsiGetPatchInfoExW( patch_code, package->ProductCode, NULL, package->Context,
|
|
|
|
INSTALLPROPERTY_LOCALPACKAGEW, patch_file, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to get patch filename %u\n", r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
r = MSI_OpenDatabaseW( patch_file, MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE, &patch_db );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to open patch database %s\n", debugstr_w( patch_file ));
|
|
|
|
return r;
|
|
|
|
}
|
2015-03-16 10:55:58 +01:00
|
|
|
r = msi_get_suminfo( patch_db->storage, 0, &si );
|
|
|
|
if (r != ERROR_SUCCESS)
|
2011-06-30 12:15:37 +02:00
|
|
|
{
|
|
|
|
msiobj_release( &patch_db->hdr );
|
2015-03-16 10:55:58 +01:00
|
|
|
return r;
|
2011-06-30 12:15:37 +02:00
|
|
|
}
|
|
|
|
r = msi_parse_patch_summary( si, &patch_info );
|
|
|
|
msiobj_release( &si->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to parse patch summary %u\n", r);
|
|
|
|
msiobj_release( &patch_db->hdr );
|
|
|
|
return r;
|
|
|
|
}
|
2015-04-10 12:58:26 +02:00
|
|
|
patch_info->registered = TRUE;
|
2011-06-30 12:15:37 +02:00
|
|
|
patch_info->localfile = strdupW( patch_file );
|
|
|
|
if (!patch_info->localfile)
|
|
|
|
{
|
|
|
|
msiobj_release( &patch_db->hdr );
|
2011-08-23 14:42:03 +02:00
|
|
|
msi_free_patchinfo( patch_info );
|
2011-06-30 12:15:37 +02:00
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
r = msi_apply_patch_db( package, patch_db, patch_info );
|
|
|
|
msiobj_release( &patch_db->hdr );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to apply patch %u\n", r);
|
2011-08-23 14:42:03 +02:00
|
|
|
msi_free_patchinfo( patch_info );
|
2011-06-30 12:15:37 +02:00
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|