2005-01-25 21:17:09 +01:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2005 Mike McCormack for CodeWeavers
|
|
|
|
* Copyright 2005 Aric Stewart for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-01-25 21:17:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "winnls.h"
|
2007-07-06 02:48:43 +02:00
|
|
|
#include "objbase.h"
|
|
|
|
#include "oleauto.h"
|
|
|
|
|
|
|
|
#include "msipriv.h"
|
2018-04-16 03:52:10 +02:00
|
|
|
#include "winemsi.h"
|
2005-01-25 21:17:09 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
/* types arranged by precedence */
|
|
|
|
#define FORMAT_NULL 0x0001
|
|
|
|
#define FORMAT_LITERAL 0x0002
|
|
|
|
#define FORMAT_NUMBER 0x0004
|
|
|
|
#define FORMAT_LBRACK 0x0010
|
|
|
|
#define FORMAT_LBRACE 0x0020
|
|
|
|
#define FORMAT_RBRACK 0x0011
|
|
|
|
#define FORMAT_RBRACE 0x0021
|
|
|
|
#define FORMAT_ESCAPE 0x0040
|
|
|
|
#define FORMAT_PROPNULL 0x0080
|
|
|
|
#define FORMAT_ERROR 0x1000
|
|
|
|
#define FORMAT_FAIL 0x2000
|
|
|
|
|
|
|
|
#define left_type(x) (x & 0xF0)
|
|
|
|
|
|
|
|
typedef struct _tagFORMAT
|
|
|
|
{
|
|
|
|
MSIPACKAGE *package;
|
|
|
|
MSIRECORD *record;
|
|
|
|
LPWSTR deformatted;
|
|
|
|
int len;
|
|
|
|
int n;
|
|
|
|
BOOL propfailed;
|
|
|
|
BOOL groupfailed;
|
|
|
|
int groups;
|
|
|
|
} FORMAT;
|
|
|
|
|
|
|
|
typedef struct _tagFORMSTR
|
|
|
|
{
|
|
|
|
struct list entry;
|
|
|
|
int n;
|
|
|
|
int len;
|
|
|
|
int type;
|
|
|
|
BOOL propfound;
|
|
|
|
BOOL nonprop;
|
|
|
|
} FORMSTR;
|
|
|
|
|
|
|
|
typedef struct _tagSTACK
|
|
|
|
{
|
|
|
|
struct list items;
|
|
|
|
} STACK;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
static STACK *create_stack(void)
|
|
|
|
{
|
|
|
|
STACK *stack = msi_alloc(sizeof(STACK));
|
|
|
|
list_init(&stack->items);
|
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_stack(STACK *stack)
|
|
|
|
{
|
|
|
|
while (!list_empty(&stack->items))
|
|
|
|
{
|
|
|
|
FORMSTR *str = LIST_ENTRY(list_head(&stack->items), FORMSTR, entry);
|
|
|
|
list_remove(&str->entry);
|
|
|
|
msi_free(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
msi_free(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stack_push(STACK *stack, FORMSTR *str)
|
|
|
|
{
|
|
|
|
list_add_head(&stack->items, &str->entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static FORMSTR *stack_pop(STACK *stack)
|
|
|
|
{
|
|
|
|
FORMSTR *ret;
|
|
|
|
|
|
|
|
if (list_empty(&stack->items))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ret = LIST_ENTRY(list_head(&stack->items), FORMSTR, entry);
|
|
|
|
list_remove(&ret->entry);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FORMSTR *stack_find(STACK *stack, int type)
|
|
|
|
{
|
|
|
|
FORMSTR *str;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(str, &stack->items, FORMSTR, entry)
|
|
|
|
{
|
|
|
|
if (str->type == type)
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static FORMSTR *stack_peek(STACK *stack)
|
|
|
|
{
|
|
|
|
return LIST_ENTRY(list_head(&stack->items), FORMSTR, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPCWSTR get_formstr_data(FORMAT *format, FORMSTR *str)
|
|
|
|
{
|
|
|
|
return &format->deformatted[str->n];
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *dup_formstr( FORMAT *format, FORMSTR *str, int *ret_len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *val;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!str->len) return NULL;
|
|
|
|
if ((val = msi_alloc( (str->len + 1) * sizeof(WCHAR) )))
|
|
|
|
{
|
|
|
|
memcpy( val, get_formstr_data(format, str), str->len * sizeof(WCHAR) );
|
|
|
|
val[str->len] = 0;
|
|
|
|
*ret_len = str->len;
|
|
|
|
}
|
2008-02-04 22:59:21 +01:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *deformat_index( FORMAT *format, FORMSTR *str, int *ret_len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *val, *ret;
|
|
|
|
DWORD len;
|
|
|
|
int field;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(val = msi_alloc( (str->len + 1) * sizeof(WCHAR) ))) return NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
lstrcpynW(val, get_formstr_data(format, str), str->len + 1);
|
2012-11-05 16:29:50 +01:00
|
|
|
field = atoiW( val );
|
|
|
|
msi_free( val );
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (MSI_RecordIsNull( format->record, field ) ||
|
|
|
|
MSI_RecordGetStringW( format->record, field, NULL, &len )) return NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
len++;
|
|
|
|
if (!(ret = msi_alloc( len * sizeof(WCHAR) ))) return NULL;
|
|
|
|
ret[0] = 0;
|
|
|
|
if (MSI_RecordGetStringW( format->record, field, ret, &len ))
|
|
|
|
{
|
|
|
|
msi_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
*ret_len = len;
|
2008-02-04 22:59:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *deformat_property( FORMAT *format, FORMSTR *str, int *ret_len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *prop, *ret;
|
|
|
|
DWORD len = 0;
|
|
|
|
UINT r;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(prop = msi_alloc( (str->len + 1) * sizeof(WCHAR) ))) return NULL;
|
|
|
|
lstrcpynW( prop, get_formstr_data(format, str), str->len + 1 );
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
r = msi_get_property( format->package->db, prop, NULL, &len );
|
|
|
|
if (r != ERROR_SUCCESS && r != ERROR_MORE_DATA)
|
|
|
|
{
|
|
|
|
msi_free( prop );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
len++;
|
|
|
|
if ((ret = msi_alloc( len * sizeof(WCHAR) )))
|
|
|
|
msi_get_property( format->package->db, prop, ret, &len );
|
|
|
|
msi_free( prop );
|
|
|
|
*ret_len = len;
|
2008-02-04 22:59:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *deformat_component( FORMAT *format, FORMSTR *str, int *ret_len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *key, *ret;
|
2008-02-04 22:59:21 +01:00
|
|
|
MSICOMPONENT *comp;
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(key = msi_alloc( (str->len + 1) * sizeof(WCHAR) ))) return NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
lstrcpynW(key, get_formstr_data(format, str), str->len + 1);
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(comp = msi_get_loaded_component( format->package, key )))
|
|
|
|
{
|
|
|
|
msi_free( key );
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-02-07 09:40:13 +01:00
|
|
|
if (comp->Action == INSTALLSTATE_SOURCE)
|
2011-05-06 14:39:17 +02:00
|
|
|
ret = msi_resolve_source_folder( format->package, comp->Directory, NULL );
|
2011-02-07 09:40:13 +01:00
|
|
|
else
|
2011-05-02 16:03:32 +02:00
|
|
|
ret = strdupW( msi_get_target_folder( format->package, comp->Directory ) );
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-06 15:20:02 +01:00
|
|
|
if (ret) *ret_len = strlenW( ret );
|
|
|
|
else *ret_len = 0;
|
2012-11-05 16:29:50 +01:00
|
|
|
msi_free( key );
|
2008-02-04 22:59:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *deformat_file( FORMAT *format, FORMSTR *str, BOOL shortname, int *ret_len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *key, *ret = NULL;
|
|
|
|
const MSIFILE *file;
|
|
|
|
DWORD len = 0;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(key = msi_alloc( (str->len + 1) * sizeof(WCHAR) ))) return NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
lstrcpynW(key, get_formstr_data(format, str), str->len + 1);
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(file = msi_get_loaded_file( format->package, key ))) goto done;
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!shortname)
|
|
|
|
{
|
2012-11-06 15:20:02 +01:00
|
|
|
if ((ret = strdupW( file->TargetPath ))) len = strlenW( ret );
|
2008-02-04 22:59:21 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2012-11-05 16:29:50 +01:00
|
|
|
if ((len = GetShortPathNameW(file->TargetPath, NULL, 0)) <= 0)
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-06 15:20:02 +01:00
|
|
|
if ((ret = strdupW( file->TargetPath ))) len = strlenW( ret );
|
2008-02-04 22:59:21 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2012-11-05 16:29:50 +01:00
|
|
|
len++;
|
|
|
|
if ((ret = msi_alloc( len * sizeof(WCHAR) )))
|
|
|
|
len = GetShortPathNameW( file->TargetPath, ret, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
|
|
|
|
done:
|
2012-11-05 16:29:50 +01:00
|
|
|
msi_free( key );
|
|
|
|
*ret_len = len;
|
2008-02-04 22:59:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *deformat_environment( FORMAT *format, FORMSTR *str, int *ret_len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *key, *ret = NULL;
|
|
|
|
DWORD len;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(key = msi_alloc((str->len + 1) * sizeof(WCHAR)))) return NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
lstrcpynW(key, get_formstr_data(format, str), str->len + 1);
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if ((len = GetEnvironmentVariableW( key, NULL, 0 )))
|
|
|
|
{
|
|
|
|
len++;
|
|
|
|
if ((ret = msi_alloc( len * sizeof(WCHAR) )))
|
|
|
|
*ret_len = GetEnvironmentVariableW( key, ret, len );
|
|
|
|
}
|
|
|
|
msi_free( key );
|
2008-02-04 22:59:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *deformat_literal( FORMAT *format, FORMSTR *str, BOOL *propfound,
|
2017-07-11 07:18:34 +02:00
|
|
|
int *type, int *len )
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
|
|
|
LPCWSTR data = get_formstr_data(format, str);
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *replaced = NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
char ch = data[0];
|
|
|
|
|
|
|
|
if (ch == '\\')
|
|
|
|
{
|
|
|
|
str->n++;
|
|
|
|
if (str->len == 1)
|
|
|
|
{
|
|
|
|
str->len = 0;
|
|
|
|
replaced = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
str->len = 1;
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = dup_formstr( format, str, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ch == '~')
|
|
|
|
{
|
|
|
|
if (str->len != 1)
|
|
|
|
replaced = NULL;
|
2012-11-05 16:29:50 +01:00
|
|
|
else if ((replaced = msi_alloc( sizeof(WCHAR) )))
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
*replaced = 0;
|
|
|
|
*len = 0;
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (ch == '%' || ch == '#' || ch == '!' || ch == '$')
|
|
|
|
{
|
|
|
|
str->n++;
|
|
|
|
str->len--;
|
|
|
|
|
|
|
|
switch (ch)
|
|
|
|
{
|
|
|
|
case '%':
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = deformat_environment( format, str, len ); break;
|
2008-02-04 22:59:21 +01:00
|
|
|
case '#':
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = deformat_file( format, str, FALSE, len ); break;
|
2008-02-04 22:59:21 +01:00
|
|
|
case '!':
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = deformat_file( format, str, TRUE, len ); break;
|
2008-02-04 22:59:21 +01:00
|
|
|
case '$':
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = deformat_component( format, str, len ); break;
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
*type = FORMAT_LITERAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = deformat_property( format, str, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
*type = FORMAT_LITERAL;
|
|
|
|
|
|
|
|
if (replaced)
|
|
|
|
*propfound = TRUE;
|
|
|
|
else
|
|
|
|
format->propfailed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return replaced;
|
|
|
|
}
|
2005-05-27 21:23:29 +02:00
|
|
|
|
2017-10-04 16:49:41 +02:00
|
|
|
static WCHAR *build_default_format( const MSIRECORD *record )
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2017-07-11 07:18:34 +02:00
|
|
|
static const WCHAR fmt[] = {'%','i',':',' ','[','%','i',']',' ',0};
|
2017-10-04 16:49:41 +02:00
|
|
|
int i, count = MSI_RecordGetFieldCount( record );
|
|
|
|
WCHAR *ret, *tmp, buf[26];
|
|
|
|
DWORD size = 1;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2017-10-04 16:49:41 +02:00
|
|
|
if (!(ret = msi_alloc( sizeof(*ret) ))) return NULL;
|
|
|
|
ret[0] = 0;
|
2017-07-11 07:18:34 +02:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
2017-10-04 16:49:41 +02:00
|
|
|
size += sprintfW( buf, fmt, i, i );
|
|
|
|
if (!(tmp = msi_realloc( ret, size * sizeof(*ret) )))
|
|
|
|
{
|
|
|
|
msi_free( ret );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ret = tmp;
|
|
|
|
strcatW( ret, buf );
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2017-10-04 16:49:41 +02:00
|
|
|
return ret;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
static BOOL format_is_number(WCHAR x)
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
return ((x >= '0') && (x <= '9'));
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
static BOOL format_str_is_number(LPWSTR str)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
LPWSTR ptr;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
for (ptr = str; *ptr; ptr++)
|
|
|
|
if (!format_is_number(*ptr))
|
|
|
|
return FALSE;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-05 14:17:21 +01:00
|
|
|
static BOOL format_is_alpha(WCHAR x)
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
|
|
|
return (!format_is_number(x) && x != '\0' &&
|
|
|
|
x != '[' && x != ']' && x != '{' && x != '}');
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-05 14:17:21 +01:00
|
|
|
static BOOL format_is_literal(WCHAR x)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
return (format_is_alpha(x) || format_is_number(x));
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
static int format_lex(FORMAT *format, FORMSTR **out)
|
|
|
|
{
|
|
|
|
int type, len = 1;
|
|
|
|
FORMSTR *str;
|
|
|
|
LPCWSTR data;
|
|
|
|
WCHAR ch;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
*out = NULL;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!format->deformatted)
|
|
|
|
return FORMAT_NULL;
|
|
|
|
|
|
|
|
*out = msi_alloc_zero(sizeof(FORMSTR));
|
|
|
|
if (!*out)
|
|
|
|
return FORMAT_FAIL;
|
|
|
|
|
|
|
|
str = *out;
|
|
|
|
str->n = format->n;
|
|
|
|
str->len = 1;
|
|
|
|
data = get_formstr_data(format, str);
|
|
|
|
|
|
|
|
ch = data[0];
|
|
|
|
switch (ch)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
case '{': type = FORMAT_LBRACE; break;
|
|
|
|
case '}': type = FORMAT_RBRACE; break;
|
|
|
|
case '[': type = FORMAT_LBRACK; break;
|
|
|
|
case ']': type = FORMAT_RBRACK; break;
|
|
|
|
case '~': type = FORMAT_PROPNULL; break;
|
|
|
|
case '\0': type = FORMAT_NULL; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
type = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type)
|
|
|
|
{
|
|
|
|
str->type = type;
|
|
|
|
format->n++;
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch == '\\')
|
|
|
|
{
|
|
|
|
while (data[len] && data[len] != ']')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
type = FORMAT_ESCAPE;
|
|
|
|
}
|
|
|
|
else if (format_is_alpha(ch))
|
|
|
|
{
|
|
|
|
while (format_is_literal(data[len]))
|
|
|
|
len++;
|
|
|
|
|
|
|
|
type = FORMAT_LITERAL;
|
|
|
|
}
|
|
|
|
else if (format_is_number(ch))
|
|
|
|
{
|
|
|
|
while (format_is_number(data[len]))
|
|
|
|
len++;
|
|
|
|
|
|
|
|
type = FORMAT_NUMBER;
|
|
|
|
|
|
|
|
if (data[len] != ']')
|
2005-05-25 19:49:49 +02:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
while (format_is_literal(data[len]))
|
|
|
|
len++;
|
2005-05-25 19:49:49 +02:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
type = FORMAT_LITERAL;
|
2005-05-25 19:49:49 +02:00
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2008-02-04 22:59:21 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Got unknown character %c(%x)\n", ch, ch);
|
|
|
|
return FORMAT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
format->n += len;
|
|
|
|
str->len = len;
|
|
|
|
str->type = type;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
return type;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static FORMSTR *format_replace( FORMAT *format, BOOL propfound, BOOL nonprop,
|
|
|
|
int oldsize, int type, WCHAR *replace, int len )
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
FORMSTR *ret;
|
|
|
|
LPWSTR str, ptr;
|
|
|
|
DWORD size = 0;
|
|
|
|
int n;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (replace)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!len)
|
2008-02-04 22:59:21 +01:00
|
|
|
size = 1;
|
|
|
|
else
|
2012-11-05 16:29:50 +01:00
|
|
|
size = len;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2008-02-04 22:59:21 +01:00
|
|
|
|
|
|
|
size -= oldsize;
|
|
|
|
size = format->len + size + 1;
|
|
|
|
|
|
|
|
if (size <= 1)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
msi_free(format->deformatted);
|
|
|
|
format->deformatted = NULL;
|
|
|
|
format->len = 0;
|
|
|
|
return NULL;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
str = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
str[0] = '\0';
|
|
|
|
memcpy(str, format->deformatted, format->n * sizeof(WCHAR));
|
|
|
|
n = format->n;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (replace)
|
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!len) str[n++] = 0;
|
2008-02-04 22:59:21 +01:00
|
|
|
else
|
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
memcpy( str + n, replace, len * sizeof(WCHAR) );
|
|
|
|
n += len;
|
|
|
|
str[n] = 0;
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
ptr = &format->deformatted[format->n + oldsize];
|
|
|
|
memcpy(&str[n], ptr, (lstrlenW(ptr) + 1) * sizeof(WCHAR));
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
msi_free(format->deformatted);
|
|
|
|
format->deformatted = str;
|
|
|
|
format->len = size - 1;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-25 21:57:23 +01:00
|
|
|
/* don't reformat the NULL */
|
2012-11-05 16:29:50 +01:00
|
|
|
if (replace && !len)
|
2008-02-25 21:57:23 +01:00
|
|
|
format->n++;
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!replace)
|
|
|
|
return NULL;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
ret = msi_alloc_zero(sizeof(FORMSTR));
|
|
|
|
if (!ret)
|
|
|
|
return NULL;
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
ret->len = len;
|
2008-02-04 22:59:21 +01:00
|
|
|
ret->type = type;
|
|
|
|
ret->n = format->n;
|
|
|
|
ret->propfound = propfound;
|
|
|
|
ret->nonprop = nonprop;
|
|
|
|
|
|
|
|
return ret;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *replace_stack_group( FORMAT *format, STACK *values,
|
|
|
|
BOOL *propfound, BOOL *nonprop,
|
|
|
|
int *oldsize, int *type, int *len )
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *replaced;
|
|
|
|
FORMSTR *content, *node;
|
2008-02-04 22:59:21 +01:00
|
|
|
int n;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
*nonprop = FALSE;
|
|
|
|
*propfound = FALSE;
|
|
|
|
|
|
|
|
node = stack_pop(values);
|
|
|
|
n = node->n;
|
|
|
|
*oldsize = node->len;
|
|
|
|
msi_free(node);
|
|
|
|
|
|
|
|
while ((node = stack_pop(values)))
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
*oldsize += node->len;
|
|
|
|
|
|
|
|
if (node->nonprop)
|
|
|
|
*nonprop = TRUE;
|
|
|
|
|
|
|
|
if (node->propfound)
|
|
|
|
*propfound = TRUE;
|
|
|
|
|
|
|
|
msi_free(node);
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
content = msi_alloc_zero(sizeof(FORMSTR));
|
|
|
|
content->n = n;
|
|
|
|
content->len = *oldsize;
|
|
|
|
content->type = FORMAT_LITERAL;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!format->groupfailed && (*oldsize == 2 ||
|
|
|
|
(format->propfailed && !*nonprop)))
|
|
|
|
{
|
|
|
|
msi_free(content);
|
2005-01-31 21:41:11 +01:00
|
|
|
return NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
else if (format->deformatted[content->n + 1] == '{' &&
|
|
|
|
format->deformatted[content->n + content->len - 2] == '}')
|
|
|
|
{
|
|
|
|
format->groupfailed = FALSE;
|
|
|
|
content->len = 0;
|
|
|
|
}
|
|
|
|
else if (*propfound && !*nonprop &&
|
|
|
|
!format->groupfailed && format->groups == 0)
|
|
|
|
{
|
|
|
|
content->n++;
|
|
|
|
content->len -= 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (format->groups != 0)
|
|
|
|
format->groupfailed = TRUE;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
*nonprop = TRUE;
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = dup_formstr( format, content, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
*type = content->type;
|
|
|
|
msi_free(content);
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (format->groups == 0)
|
|
|
|
format->propfailed = FALSE;
|
|
|
|
|
|
|
|
return replaced;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
static WCHAR *replace_stack_prop( FORMAT *format, STACK *values,
|
|
|
|
BOOL *propfound, BOOL *nonprop,
|
|
|
|
int *oldsize, int *type, int *len )
|
2005-05-27 21:23:29 +02:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *replaced;
|
|
|
|
FORMSTR *content, *node;
|
2008-02-04 22:59:21 +01:00
|
|
|
int n;
|
2005-05-27 21:23:29 +02:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
*propfound = FALSE;
|
|
|
|
*nonprop = FALSE;
|
2005-05-27 21:23:29 +02:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
node = stack_pop(values);
|
|
|
|
n = node->n;
|
|
|
|
*oldsize = node->len;
|
|
|
|
*type = stack_peek(values)->type;
|
|
|
|
msi_free(node);
|
|
|
|
|
|
|
|
while ((node = stack_pop(values)))
|
2005-05-27 21:23:29 +02:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
*oldsize += node->len;
|
|
|
|
|
|
|
|
if (*type != FORMAT_ESCAPE &&
|
|
|
|
stack_peek(values) && node->type != *type)
|
|
|
|
*type = FORMAT_LITERAL;
|
|
|
|
|
|
|
|
msi_free(node);
|
2005-05-27 21:23:29 +02:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
content = msi_alloc_zero(sizeof(FORMSTR));
|
|
|
|
content->n = n + 1;
|
|
|
|
content->len = *oldsize - 2;
|
|
|
|
content->type = *type;
|
2005-05-27 21:23:29 +02:00
|
|
|
|
2017-07-11 07:18:34 +02:00
|
|
|
if (*type == FORMAT_NUMBER && format->record)
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = deformat_index( format, content, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
if (replaced)
|
|
|
|
*propfound = TRUE;
|
|
|
|
else
|
|
|
|
format->propfailed = TRUE;
|
2005-05-27 21:23:29 +02:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (replaced)
|
|
|
|
*type = format_str_is_number(replaced) ?
|
|
|
|
FORMAT_NUMBER : FORMAT_LITERAL;
|
|
|
|
}
|
|
|
|
else if (format->package)
|
|
|
|
{
|
2017-07-11 07:18:34 +02:00
|
|
|
replaced = deformat_literal( format, content, propfound, type, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*nonprop = TRUE;
|
|
|
|
content->n--;
|
|
|
|
content->len += 2;
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = dup_formstr( format, content, len );
|
2008-02-04 22:59:21 +01:00
|
|
|
}
|
|
|
|
msi_free(content);
|
|
|
|
return replaced;
|
2005-05-27 21:23:29 +02:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
static UINT replace_stack(FORMAT *format, STACK *stack, STACK *values)
|
2005-02-02 10:30:22 +01:00
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
WCHAR *replaced = NULL;
|
|
|
|
FORMSTR *beg, *top, *node;
|
|
|
|
BOOL propfound = FALSE, nonprop = FALSE, group = FALSE;
|
|
|
|
int type, n, len = 0, oldsize = 0;
|
2008-02-04 22:59:21 +01:00
|
|
|
|
|
|
|
node = stack_peek(values);
|
|
|
|
type = node->type;
|
|
|
|
n = node->n;
|
|
|
|
|
|
|
|
if (type == FORMAT_LBRACK)
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = replace_stack_prop( format, values, &propfound,
|
|
|
|
&nonprop, &oldsize, &type, &len );
|
2008-02-04 22:59:21 +01:00
|
|
|
else if (type == FORMAT_LBRACE)
|
|
|
|
{
|
2012-11-05 16:29:50 +01:00
|
|
|
replaced = replace_stack_group( format, values, &propfound,
|
|
|
|
&nonprop, &oldsize, &type, &len );
|
2008-02-04 22:59:21 +01:00
|
|
|
group = TRUE;
|
|
|
|
}
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
format->n = n;
|
2012-11-05 16:29:50 +01:00
|
|
|
beg = format_replace( format, propfound, nonprop, oldsize, type, replaced, len );
|
2014-04-10 07:19:11 +02:00
|
|
|
msi_free(replaced);
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!beg)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
format->n = beg->n + beg->len;
|
|
|
|
|
|
|
|
top = stack_peek(stack);
|
|
|
|
if (top)
|
2005-02-02 10:30:22 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
type = top->type;
|
|
|
|
|
|
|
|
if ((type == FORMAT_LITERAL || type == FORMAT_NUMBER) &&
|
|
|
|
type == beg->type)
|
2005-02-02 10:30:22 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
top->len += beg->len;
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (group)
|
|
|
|
top->nonprop = FALSE;
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (type == FORMAT_LITERAL)
|
|
|
|
top->nonprop = beg->nonprop;
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (beg->propfound)
|
|
|
|
top->propfound = TRUE;
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
msi_free(beg);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stack_push(stack, beg);
|
|
|
|
return ERROR_SUCCESS;
|
2005-02-02 10:30:22 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
static BOOL verify_format(LPWSTR data)
|
2005-05-27 21:23:29 +02:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
int count = 0;
|
2005-05-27 21:23:29 +02:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
while (*data)
|
2005-05-27 21:23:29 +02:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
if (*data == '[' && *(data - 1) != '\\')
|
|
|
|
count++;
|
|
|
|
else if (*data == ']')
|
|
|
|
count--;
|
|
|
|
|
|
|
|
data++;
|
2005-05-27 21:23:29 +02:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (count > 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2005-01-25 21:17:09 +01:00
|
|
|
static DWORD deformat_string_internal(MSIPACKAGE *package, LPCWSTR ptr,
|
2008-02-04 22:59:21 +01:00
|
|
|
WCHAR** data, DWORD *len,
|
2017-07-11 07:18:34 +02:00
|
|
|
MSIRECORD* record)
|
2008-02-04 22:59:21 +01:00
|
|
|
{
|
|
|
|
FORMAT format;
|
|
|
|
FORMSTR *str = NULL;
|
|
|
|
STACK *stack, *temp;
|
|
|
|
FORMSTR *node;
|
|
|
|
int type;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!ptr)
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
|
|
|
*data = NULL;
|
2008-02-04 22:59:21 +01:00
|
|
|
*len = 0;
|
|
|
|
return ERROR_SUCCESS;
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
*data = strdupW(ptr);
|
|
|
|
*len = lstrlenW(ptr);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
ZeroMemory(&format, sizeof(FORMAT));
|
|
|
|
format.package = package;
|
|
|
|
format.record = record;
|
|
|
|
format.deformatted = *data;
|
|
|
|
format.len = *len;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (!verify_format(*data))
|
|
|
|
return ERROR_SUCCESS;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2010-05-20 12:00:53 +02:00
|
|
|
stack = create_stack();
|
|
|
|
temp = create_stack();
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
while ((type = format_lex(&format, &str)) != FORMAT_NULL)
|
|
|
|
{
|
|
|
|
if (type == FORMAT_LBRACK || type == FORMAT_LBRACE ||
|
|
|
|
type == FORMAT_LITERAL || type == FORMAT_NUMBER ||
|
|
|
|
type == FORMAT_ESCAPE || type == FORMAT_PROPNULL)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
if (type == FORMAT_LBRACE)
|
2005-05-27 21:23:29 +02:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
format.propfailed = FALSE;
|
|
|
|
format.groups++;
|
2005-05-27 21:23:29 +02:00
|
|
|
}
|
2008-02-04 22:59:21 +01:00
|
|
|
else if (type == FORMAT_ESCAPE &&
|
|
|
|
!stack_find(stack, FORMAT_LBRACK))
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
format.n -= str->len - 1;
|
|
|
|
str->len = 1;
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
2008-02-04 22:59:21 +01:00
|
|
|
|
|
|
|
stack_push(stack, str);
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2008-02-04 22:59:21 +01:00
|
|
|
else if (type == FORMAT_RBRACK || type == FORMAT_RBRACE)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2008-02-04 22:59:21 +01:00
|
|
|
if (type == FORMAT_RBRACE)
|
|
|
|
format.groups--;
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
stack_push(stack, str);
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
if (stack_find(stack, left_type(type)))
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
node = stack_pop(stack);
|
|
|
|
stack_push(temp, node);
|
|
|
|
} while (node->type != left_type(type));
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
replace_stack(&format, stack, temp);
|
|
|
|
}
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
*data = format.deformatted;
|
|
|
|
*len = format.len;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
msi_free(str);
|
|
|
|
free_stack(stack);
|
|
|
|
free_stack(temp);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2008-02-04 22:59:21 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
UINT MSI_FormatRecordW( MSIPACKAGE* package, MSIRECORD* record, LPWSTR buffer,
|
2007-08-09 10:41:41 +02:00
|
|
|
LPDWORD size )
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2017-07-24 16:35:22 +02:00
|
|
|
WCHAR *format, *deformated = NULL;
|
2005-01-25 21:17:09 +01:00
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
2012-11-05 16:29:50 +01:00
|
|
|
DWORD len;
|
2017-07-11 07:18:34 +02:00
|
|
|
MSIRECORD *record_deformated;
|
|
|
|
int field_count, i;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2009-06-04 10:12:31 +02:00
|
|
|
TRACE("%p %p %p %p\n", package, record, buffer, size);
|
2017-07-11 07:18:34 +02:00
|
|
|
dump_record(record);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2012-11-05 16:29:50 +01:00
|
|
|
if (!(format = msi_dup_record_field( record, 0 )))
|
|
|
|
format = build_default_format( record );
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2017-07-11 07:18:34 +02:00
|
|
|
field_count = MSI_RecordGetFieldCount(record);
|
|
|
|
record_deformated = MSI_CloneRecord(record);
|
|
|
|
if (!record_deformated)
|
|
|
|
{
|
|
|
|
rc = ERROR_OUTOFMEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
MSI_RecordSetStringW(record_deformated, 0, format);
|
|
|
|
for (i = 1; i <= field_count; i++)
|
|
|
|
{
|
|
|
|
if (MSI_RecordGetString(record, i))
|
|
|
|
{
|
|
|
|
deformat_string_internal(package, MSI_RecordGetString(record, i), &deformated, &len, NULL);
|
|
|
|
MSI_RecordSetStringW(record_deformated, i, deformated);
|
|
|
|
msi_free(deformated);
|
|
|
|
}
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2017-07-11 07:18:34 +02:00
|
|
|
deformat_string_internal(package, format, &deformated, &len, record_deformated);
|
2005-01-31 21:41:11 +01:00
|
|
|
if (buffer)
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2005-01-31 21:41:11 +01:00
|
|
|
if (*size>len)
|
|
|
|
{
|
|
|
|
memcpy(buffer,deformated,len*sizeof(WCHAR));
|
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
buffer[len] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-09 23:22:25 +01:00
|
|
|
if (*size > 0)
|
|
|
|
{
|
|
|
|
memcpy(buffer,deformated,(*size)*sizeof(WCHAR));
|
|
|
|
buffer[(*size)-1] = 0;
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
rc = ERROR_MORE_DATA;
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
2012-11-05 16:29:50 +01:00
|
|
|
else rc = ERROR_SUCCESS;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
*size = len;
|
2017-07-11 07:18:34 +02:00
|
|
|
msiobj_release(&record_deformated->hdr);
|
|
|
|
end:
|
2012-11-05 16:29:50 +01:00
|
|
|
msi_free( format );
|
|
|
|
msi_free( deformated );
|
2005-01-25 21:17:09 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
UINT WINAPI MsiFormatRecordW( MSIHANDLE hInstall, MSIHANDLE hRecord,
|
2007-08-09 10:41:41 +02:00
|
|
|
LPWSTR szResult, LPDWORD sz )
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
|
|
|
UINT r = ERROR_INVALID_HANDLE;
|
|
|
|
MSIPACKAGE *package;
|
|
|
|
MSIRECORD *record;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %p %p\n", hInstall, hRecord, szResult, sz);
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2018-04-25 05:27:39 +02:00
|
|
|
record = msihandle2msiinfo(hRecord, MSIHANDLETYPE_RECORD);
|
|
|
|
if (!record)
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
2007-07-06 02:48:43 +02:00
|
|
|
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
|
|
|
|
if (!package)
|
|
|
|
{
|
2018-04-25 05:27:39 +02:00
|
|
|
LPWSTR value = NULL;
|
2018-04-16 03:52:10 +02:00
|
|
|
MSIHANDLE remote;
|
2007-07-06 02:48:43 +02:00
|
|
|
awstring wstr;
|
|
|
|
|
2018-04-16 03:52:10 +02:00
|
|
|
if ((remote = msi_get_remote(hInstall)))
|
2007-07-06 02:48:43 +02:00
|
|
|
{
|
2018-04-25 05:27:39 +02:00
|
|
|
r = remote_FormatRecord(remote, (struct wire_record *)&record->count, &value);
|
|
|
|
if (r)
|
|
|
|
{
|
|
|
|
midl_user_free(value);
|
|
|
|
return r;
|
|
|
|
}
|
2007-07-06 02:48:43 +02:00
|
|
|
|
|
|
|
wstr.unicode = TRUE;
|
|
|
|
wstr.str.w = szResult;
|
2018-04-25 05:27:39 +02:00
|
|
|
r = msi_strcpy_to_awstring(value, -1, &wstr, sz);
|
2007-07-06 02:48:43 +02:00
|
|
|
|
2018-04-25 05:27:39 +02:00
|
|
|
midl_user_free(value);
|
2007-07-06 02:48:43 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
if (!sz)
|
|
|
|
{
|
|
|
|
msiobj_release( &record->hdr );
|
|
|
|
if (szResult)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-03-10 12:15:40 +01:00
|
|
|
r = MSI_FormatRecordW( package, record, szResult, sz );
|
|
|
|
msiobj_release( &record->hdr );
|
2005-01-31 21:41:11 +01:00
|
|
|
if (package)
|
|
|
|
msiobj_release( &package->hdr );
|
|
|
|
return r;
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
UINT WINAPI MsiFormatRecordA( MSIHANDLE hInstall, MSIHANDLE hRecord,
|
2007-08-09 10:41:41 +02:00
|
|
|
LPSTR szResult, LPDWORD sz )
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2007-07-06 02:52:07 +02:00
|
|
|
UINT r;
|
|
|
|
DWORD len, save;
|
|
|
|
LPWSTR value;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %p %p\n", hInstall, hRecord, szResult, sz);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2007-07-06 02:52:07 +02:00
|
|
|
if (!hRecord)
|
2005-01-25 21:17:09 +01:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2007-07-06 02:52:07 +02:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
if (!sz)
|
|
|
|
{
|
|
|
|
if (szResult)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2007-07-06 02:52:07 +02:00
|
|
|
r = MsiFormatRecordW( hInstall, hRecord, NULL, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2007-07-06 02:52:07 +02:00
|
|
|
value = msi_alloc(++len * sizeof(WCHAR));
|
|
|
|
if (!value)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
r = MsiFormatRecordW( hInstall, hRecord, value, &len );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
save = len + 1;
|
2008-02-04 22:59:21 +01:00
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, value, len + 1, NULL, 0, NULL, NULL);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, value, len, szResult, *sz, NULL, NULL);
|
2007-07-06 02:52:07 +02:00
|
|
|
|
|
|
|
if (szResult && len > *sz)
|
|
|
|
{
|
|
|
|
if (*sz) szResult[*sz - 1] = '\0';
|
|
|
|
r = ERROR_MORE_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sz = save - 1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(value);
|
2005-01-31 21:41:11 +01:00
|
|
|
return r;
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
2011-05-06 14:39:17 +02:00
|
|
|
|
|
|
|
/* wrapper to resist a need for a full rewrite right now */
|
2012-11-07 15:55:26 +01:00
|
|
|
DWORD deformat_string( MSIPACKAGE *package, const WCHAR *fmt, WCHAR **data )
|
2011-05-06 14:39:17 +02:00
|
|
|
{
|
2012-11-07 15:55:26 +01:00
|
|
|
DWORD len;
|
|
|
|
MSIRECORD *rec;
|
2011-05-06 14:39:17 +02:00
|
|
|
|
2012-11-07 15:55:26 +01:00
|
|
|
*data = NULL;
|
|
|
|
if (!fmt) return 0;
|
|
|
|
if (!(rec = MSI_CreateRecord( 1 ))) return 0;
|
2011-05-06 14:39:17 +02:00
|
|
|
|
2012-11-07 15:55:26 +01:00
|
|
|
MSI_RecordSetStringW( rec, 0, fmt );
|
|
|
|
MSI_FormatRecordW( package, rec, NULL, &len );
|
|
|
|
if (!(*data = msi_alloc( ++len * sizeof(WCHAR) )))
|
|
|
|
{
|
2011-05-06 14:39:17 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
2012-11-07 15:55:26 +01:00
|
|
|
return 0;
|
2011-05-06 14:39:17 +02:00
|
|
|
}
|
2012-11-07 15:55:26 +01:00
|
|
|
MSI_FormatRecordW( package, rec, *data, &len );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return len;
|
2011-05-06 14:39:17 +02:00
|
|
|
}
|