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
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/msiformatrecord.asp
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
#include "msiserver.h"
|
2005-01-25 21:17:09 +01:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2005-05-27 21:23:29 +02:00
|
|
|
static DWORD deformat_string_internal(MSIPACKAGE *package, LPCWSTR ptr,
|
|
|
|
WCHAR** data, DWORD len, MSIRECORD* record,
|
|
|
|
BOOL* in_group);
|
|
|
|
|
|
|
|
|
2007-06-12 00:04:49 +02:00
|
|
|
static LPWSTR build_default_format(const MSIRECORD* record)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
2006-09-06 05:26:56 +02:00
|
|
|
LPWSTR rc, buf;
|
|
|
|
static const WCHAR fmt[] = {'%','i',':',' ','%','s',' ',0};
|
|
|
|
static const WCHAR fmt_null[] = {'%','i',':',' ',' ',0};
|
|
|
|
static const WCHAR fmt_index[] = {'%','i',0};
|
|
|
|
LPCWSTR str;
|
|
|
|
WCHAR index[10];
|
|
|
|
DWORD size, max_len, len;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(record);
|
|
|
|
|
2006-09-06 05:26:56 +02:00
|
|
|
max_len = MAX_PATH;
|
|
|
|
buf = msi_alloc((max_len + 1) * sizeof(WCHAR));
|
|
|
|
|
|
|
|
rc = NULL;
|
|
|
|
size = 1;
|
2005-01-31 21:41:11 +01:00
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
2006-09-06 05:26:56 +02:00
|
|
|
sprintfW(index,fmt_index,i);
|
|
|
|
str = MSI_RecordGetString(record, i);
|
|
|
|
len = (str) ? lstrlenW(str) : 0;
|
|
|
|
len += (sizeof(fmt_null) - 3) + lstrlenW(index);
|
|
|
|
size += len;
|
|
|
|
|
|
|
|
if (len > max_len)
|
|
|
|
{
|
|
|
|
max_len = len;
|
|
|
|
buf = msi_realloc(buf, (max_len + 1) * sizeof(WCHAR));
|
|
|
|
if (!buf) return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
sprintfW(buf,fmt,i,str);
|
|
|
|
else
|
|
|
|
sprintfW(buf,fmt_null,i);
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
rc = msi_alloc(size * sizeof(WCHAR));
|
|
|
|
lstrcpyW(rc, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rc = msi_realloc(rc, size * sizeof(WCHAR));
|
|
|
|
lstrcatW(rc, buf);
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2006-09-06 05:26:56 +02:00
|
|
|
msi_free(buf);
|
2005-01-31 21:41:11 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-01-25 21:17:09 +01:00
|
|
|
static const WCHAR* scanW(LPCWSTR buf, WCHAR token, DWORD len)
|
|
|
|
{
|
|
|
|
DWORD i;
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
if (buf[i] == token)
|
|
|
|
return &buf[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
/* break out helper functions for deformating */
|
|
|
|
static LPWSTR deformat_component(MSIPACKAGE* package, LPCWSTR key, DWORD* sz)
|
|
|
|
{
|
|
|
|
LPWSTR value = NULL;
|
2005-08-22 11:15:23 +02:00
|
|
|
MSICOMPONENT *comp;
|
2007-05-24 20:11:20 +02:00
|
|
|
BOOL source;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
*sz = 0;
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
2005-08-22 11:15:23 +02:00
|
|
|
comp = get_loaded_component(package,key);
|
|
|
|
if (comp)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2007-05-24 20:11:20 +02:00
|
|
|
source = (comp->Action == INSTALLSTATE_SOURCE) ? TRUE : FALSE;
|
|
|
|
value = resolve_folder(package, comp->Directory, source, FALSE, TRUE, NULL);
|
2005-01-31 21:41:11 +01:00
|
|
|
*sz = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-05-25 19:49:49 +02:00
|
|
|
static LPWSTR deformat_file(MSIPACKAGE* package, LPCWSTR key, DWORD* sz,
|
|
|
|
BOOL shortname)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
|
|
|
LPWSTR value = NULL;
|
2005-08-23 12:03:17 +02:00
|
|
|
MSIFILE *file;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
*sz = 0;
|
|
|
|
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
2005-08-23 12:03:17 +02:00
|
|
|
file = get_loaded_file( package, key );
|
|
|
|
if (file)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
2005-05-25 19:49:49 +02:00
|
|
|
if (!shortname)
|
|
|
|
{
|
2005-08-23 12:03:17 +02:00
|
|
|
value = strdupW( file->TargetPath );
|
2005-05-25 19:49:49 +02:00
|
|
|
*sz = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD size = 0;
|
2005-08-23 12:03:17 +02:00
|
|
|
size = GetShortPathNameW( file->TargetPath, NULL, 0 );
|
2005-05-25 19:49:49 +02:00
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
*sz = (size-1) * sizeof (WCHAR);
|
|
|
|
size ++;
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(size * sizeof(WCHAR));
|
2005-08-23 12:03:17 +02:00
|
|
|
GetShortPathNameW( file->TargetPath, value, size );
|
2005-05-25 19:49:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-06 05:28:15 +02:00
|
|
|
value = strdupW( file->TargetPath );
|
|
|
|
*sz = (lstrlenW(value)) * sizeof(WCHAR);
|
2005-05-25 19:49:49 +02:00
|
|
|
}
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_environment(MSIPACKAGE* package, LPCWSTR key,
|
|
|
|
DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value = NULL;
|
|
|
|
DWORD sz;
|
|
|
|
|
|
|
|
sz = GetEnvironmentVariableW(key,NULL,0);
|
|
|
|
if (sz > 0)
|
|
|
|
{
|
|
|
|
sz++;
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(sz * sizeof(WCHAR));
|
2005-12-19 18:17:28 +01:00
|
|
|
GetEnvironmentVariableW(key,value,sz);
|
2005-01-31 21:41:11 +01:00
|
|
|
*chunk = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-12 12:15:09 +02:00
|
|
|
ERR("Unknown environment variable %s\n", debugstr_w(key));
|
2005-01-31 21:41:11 +01:00
|
|
|
*chunk = 0;
|
|
|
|
value = NULL;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static LPWSTR deformat_NULL(DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(sizeof(WCHAR)*2);
|
2005-01-31 21:41:11 +01:00
|
|
|
value[0] = 0;
|
|
|
|
*chunk = sizeof(WCHAR);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_escape(LPCWSTR key, DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(sizeof(WCHAR)*2);
|
2005-01-31 21:41:11 +01:00
|
|
|
value[0] = key[0];
|
|
|
|
*chunk = sizeof(WCHAR);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL is_key_number(LPCWSTR key)
|
|
|
|
{
|
|
|
|
INT index = 0;
|
2005-02-02 10:30:22 +01:00
|
|
|
if (key[0] == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
while (isdigitW(key[index])) index++;
|
|
|
|
if (key[index] == 0)
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_index(MSIRECORD* record, LPCWSTR key, DWORD* chunk )
|
|
|
|
{
|
|
|
|
INT index;
|
|
|
|
LPWSTR value;
|
|
|
|
|
|
|
|
index = atoiW(key);
|
|
|
|
TRACE("record index %i\n",index);
|
2005-10-27 14:36:12 +02:00
|
|
|
value = msi_dup_record_field(record,index);
|
2005-01-31 21:41:11 +01:00
|
|
|
if (value)
|
|
|
|
*chunk = strlenW(value) * sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = NULL;
|
|
|
|
*chunk = 0;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_property(MSIPACKAGE* package, LPCWSTR key, DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-15 17:04:08 +02:00
|
|
|
value = msi_dup_property( package, key );
|
2005-01-31 21:41:11 +01:00
|
|
|
|
2005-09-15 17:04:08 +02:00
|
|
|
if (value)
|
2005-01-31 21:41:11 +01:00
|
|
|
*chunk = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-05-27 21:23:29 +02:00
|
|
|
/*
|
|
|
|
* Groups cannot be nested. They are just treated as from { to next }
|
|
|
|
*/
|
|
|
|
static BOOL find_next_group(LPCWSTR source, DWORD len_remaining,
|
|
|
|
LPWSTR *group, LPCWSTR *mark,
|
|
|
|
LPCWSTR* mark2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
|
|
|
|
*mark = scanW(source,'{',len_remaining);
|
|
|
|
if (!*mark)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 1; (*mark - source) + i < len_remaining; i++)
|
|
|
|
{
|
|
|
|
if ((*mark)[i] == '}')
|
|
|
|
{
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! found)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*mark2 = &(*mark)[i];
|
|
|
|
|
|
|
|
i = *mark2 - *mark;
|
2005-09-20 13:59:14 +02:00
|
|
|
*group = msi_alloc(i*sizeof(WCHAR));
|
2005-05-27 21:23:29 +02:00
|
|
|
|
|
|
|
i -= 1;
|
|
|
|
memcpy(*group,&(*mark)[1],i*sizeof(WCHAR));
|
|
|
|
(*group)[i] = 0;
|
|
|
|
|
|
|
|
TRACE("Found group %s\n",debugstr_w(*group));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-02 10:30:22 +01:00
|
|
|
static BOOL find_next_outermost_key(LPCWSTR source, DWORD len_remaining,
|
|
|
|
LPWSTR *key, LPCWSTR *mark, LPCWSTR* mark2,
|
|
|
|
BOOL *nested)
|
|
|
|
{
|
|
|
|
INT count = 0;
|
|
|
|
INT total_count = 0;
|
|
|
|
int i;
|
|
|
|
|
2007-09-17 17:03:08 +02:00
|
|
|
*nested = FALSE;
|
2005-02-02 10:30:22 +01:00
|
|
|
*mark = scanW(source,'[',len_remaining);
|
|
|
|
if (!*mark)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
total_count = 1;
|
|
|
|
for (i = 1; (*mark - source) + i < len_remaining && count > 0; i++)
|
|
|
|
{
|
2005-02-23 13:44:25 +01:00
|
|
|
if ((*mark)[i] == '[' && (*mark)[i-1] != '\\')
|
2005-02-02 10:30:22 +01:00
|
|
|
{
|
|
|
|
count ++;
|
|
|
|
total_count ++;
|
|
|
|
*nested = TRUE;
|
|
|
|
}
|
2005-02-23 13:44:25 +01:00
|
|
|
else if ((*mark)[i] == ']' && (*mark)[i-1] != '\\')
|
2005-02-02 10:30:22 +01:00
|
|
|
{
|
|
|
|
count --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*mark2 = &(*mark)[i-1];
|
|
|
|
|
|
|
|
i = *mark2 - *mark;
|
2005-09-20 13:59:14 +02:00
|
|
|
*key = msi_alloc(i*sizeof(WCHAR));
|
2005-02-02 10:30:22 +01:00
|
|
|
/* do not have the [] in the key */
|
|
|
|
i -= 1;
|
2005-03-28 16:17:51 +02:00
|
|
|
memcpy(*key,&(*mark)[1],i*sizeof(WCHAR));
|
2005-02-02 10:30:22 +01:00
|
|
|
(*key)[i] = 0;
|
|
|
|
|
|
|
|
TRACE("Found Key %s\n",debugstr_w(*key));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-01 13:02:48 +02:00
|
|
|
static LPWSTR deformat_group(MSIPACKAGE* package, LPWSTR group, DWORD len,
|
2005-05-27 21:23:29 +02:00
|
|
|
MSIRECORD* record, DWORD* size)
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
LPWSTR value = NULL;
|
2005-05-27 21:23:29 +02:00
|
|
|
LPCWSTR mark, mark2;
|
|
|
|
LPWSTR key;
|
|
|
|
BOOL nested;
|
|
|
|
INT failcount;
|
|
|
|
static const WCHAR fmt[] = {'{','%','s','}',0};
|
|
|
|
UINT sz;
|
|
|
|
|
|
|
|
if (!group || group[0] == 0)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* if no [] then group is returned as is */
|
|
|
|
|
|
|
|
if (!find_next_outermost_key(group, len, &key, &mark, &mark2, &nested))
|
|
|
|
{
|
|
|
|
*size = (len+2)*sizeof(WCHAR);
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(*size);
|
2005-05-27 21:23:29 +02:00
|
|
|
sprintfW(value,fmt,group);
|
|
|
|
/* do not return size of the null at the end */
|
|
|
|
*size = (len+1)*sizeof(WCHAR);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(key);
|
2005-05-27 21:23:29 +02:00
|
|
|
failcount = 0;
|
|
|
|
sz = deformat_string_internal(package, group, &value, strlenW(group),
|
|
|
|
record, &failcount);
|
|
|
|
if (failcount==0)
|
|
|
|
{
|
|
|
|
*size = sz * sizeof(WCHAR);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
else if (failcount < 0)
|
|
|
|
{
|
|
|
|
LPWSTR v2;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
v2 = msi_alloc((sz+2)*sizeof(WCHAR));
|
2005-05-27 21:23:29 +02:00
|
|
|
v2[0] = '{';
|
|
|
|
memcpy(&v2[1],value,sz*sizeof(WCHAR));
|
|
|
|
v2[sz+1]='}';
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(value);
|
2005-05-27 21:23:29 +02:00
|
|
|
|
|
|
|
*size = (sz+2)*sizeof(WCHAR);
|
|
|
|
return v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-21 11:43:29 +02:00
|
|
|
msi_free(value);
|
2005-05-27 21:23:29 +02:00
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2005-01-25 21:17:09 +01:00
|
|
|
/*
|
|
|
|
* len is in WCHARs
|
|
|
|
* return is also in WCHARs
|
|
|
|
*/
|
|
|
|
static DWORD deformat_string_internal(MSIPACKAGE *package, LPCWSTR ptr,
|
2005-05-27 21:23:29 +02:00
|
|
|
WCHAR** data, DWORD len, MSIRECORD* record,
|
|
|
|
INT* failcount)
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2005-02-02 10:30:22 +01:00
|
|
|
LPCWSTR mark = NULL;
|
|
|
|
LPCWSTR mark2 = NULL;
|
2005-01-25 21:17:09 +01:00
|
|
|
DWORD size=0;
|
|
|
|
DWORD chunk=0;
|
2005-02-02 10:30:22 +01:00
|
|
|
LPWSTR key;
|
2005-01-25 21:17:09 +01:00
|
|
|
LPWSTR value = NULL;
|
|
|
|
DWORD sz;
|
2005-01-31 21:41:11 +01:00
|
|
|
LPBYTE newdata = NULL;
|
|
|
|
const WCHAR* progress = NULL;
|
2007-09-17 17:03:40 +02:00
|
|
|
BOOL nested = FALSE;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
|
|
|
if (ptr==NULL)
|
|
|
|
{
|
|
|
|
TRACE("Deformatting NULL string\n");
|
|
|
|
*data = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-04 11:36:44 +02:00
|
|
|
TRACE("Starting with %s\n",debugstr_wn(ptr,len));
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
/* scan for special characters... fast exit */
|
2005-05-27 21:23:29 +02:00
|
|
|
if ((!scanW(ptr,'[',len) || (scanW(ptr,'[',len) && !scanW(ptr,']',len))) &&
|
|
|
|
(scanW(ptr,'{',len) && !scanW(ptr,'}',len)))
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
|
|
|
/* not formatted */
|
2005-09-20 13:59:14 +02:00
|
|
|
*data = msi_alloc((len*sizeof(WCHAR)));
|
2005-01-25 21:17:09 +01:00
|
|
|
memcpy(*data,ptr,len*sizeof(WCHAR));
|
2005-05-29 22:08:12 +02:00
|
|
|
TRACE("Returning %s\n",debugstr_wn(*data,len));
|
2005-01-25 21:17:09 +01:00
|
|
|
return len;
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
progress = ptr;
|
|
|
|
|
|
|
|
while (progress - ptr < len)
|
2005-02-02 10:30:22 +01:00
|
|
|
{
|
2005-05-27 21:23:29 +02:00
|
|
|
/* seek out first group if existing */
|
|
|
|
if (find_next_group(progress, len - (progress - ptr), &key,
|
|
|
|
&mark, &mark2))
|
|
|
|
{
|
|
|
|
value = deformat_group(package, key, strlenW(key)+1, record,
|
|
|
|
&chunk);
|
2005-09-21 11:43:29 +02:00
|
|
|
msi_free( key );
|
2005-05-27 21:23:29 +02:00
|
|
|
key = NULL;
|
|
|
|
nested = FALSE;
|
|
|
|
}
|
2005-02-02 10:30:22 +01:00
|
|
|
/* formatted string located */
|
2005-05-27 21:23:29 +02:00
|
|
|
else if (!find_next_outermost_key(progress, len - (progress - ptr),
|
|
|
|
&key, &mark, &mark2, &nested))
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
|
|
|
LPBYTE nd2;
|
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("after value %s\n", debugstr_wn((LPWSTR)newdata,
|
2005-06-04 11:36:44 +02:00
|
|
|
size/sizeof(WCHAR)));
|
2005-01-31 21:41:11 +01:00
|
|
|
chunk = (len - (progress - ptr)) * sizeof(WCHAR);
|
2006-10-05 06:41:22 +02:00
|
|
|
TRACE("after chunk is %i + %i\n",size,chunk);
|
2005-01-31 21:41:11 +01:00
|
|
|
if (size)
|
2005-09-20 13:59:14 +02:00
|
|
|
nd2 = msi_realloc(newdata,(size+chunk));
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
2005-09-20 13:59:14 +02:00
|
|
|
nd2 = msi_alloc(chunk);
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
newdata = nd2;
|
|
|
|
memcpy(&newdata[size],progress,chunk);
|
|
|
|
size+=chunk;
|
2005-01-25 21:17:09 +01:00
|
|
|
break;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mark != progress)
|
|
|
|
{
|
|
|
|
LPBYTE tgt;
|
|
|
|
DWORD old_size = size;
|
|
|
|
INT cnt = (mark - progress);
|
|
|
|
TRACE("%i (%i) characters before marker\n",cnt,(mark-progress));
|
|
|
|
size += cnt * sizeof(WCHAR);
|
|
|
|
if (!old_size)
|
2005-09-20 13:59:14 +02:00
|
|
|
tgt = msi_alloc(size);
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
2005-09-20 13:59:14 +02:00
|
|
|
tgt = msi_realloc(newdata,size);
|
2005-01-31 21:41:11 +01:00
|
|
|
newdata = tgt;
|
|
|
|
memcpy(&newdata[old_size],progress,(cnt * sizeof(WCHAR)));
|
|
|
|
}
|
|
|
|
|
|
|
|
progress = mark;
|
|
|
|
|
2005-02-02 10:30:22 +01:00
|
|
|
if (nested)
|
|
|
|
{
|
|
|
|
TRACE("Nested key... %s\n",debugstr_w(key));
|
|
|
|
deformat_string_internal(package, key, &value, strlenW(key)+1,
|
2005-05-27 21:23:29 +02:00
|
|
|
record, failcount);
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(key);
|
2005-02-02 10:30:22 +01:00
|
|
|
key = value;
|
|
|
|
}
|
|
|
|
|
2005-06-04 11:36:44 +02:00
|
|
|
TRACE("Current %s .. %s\n",debugstr_wn((LPWSTR)newdata,
|
|
|
|
size/sizeof(WCHAR)),debugstr_w(key));
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
if (!package)
|
|
|
|
{
|
|
|
|
/* only deformat number indexs */
|
2005-05-27 21:23:29 +02:00
|
|
|
if (key && is_key_number(key))
|
|
|
|
{
|
2005-01-31 21:41:11 +01:00
|
|
|
value = deformat_index(record,key,&chunk);
|
2005-05-27 21:23:29 +02:00
|
|
|
if (!chunk && failcount && *failcount >= 0)
|
|
|
|
(*failcount)++;
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
|
|
|
{
|
2005-05-27 21:23:29 +02:00
|
|
|
if (failcount)
|
|
|
|
*failcount = -1;
|
|
|
|
if(key)
|
|
|
|
{
|
|
|
|
DWORD keylen = strlenW(key);
|
|
|
|
chunk = (keylen + 2)*sizeof(WCHAR);
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(chunk);
|
2005-05-27 21:23:29 +02:00
|
|
|
value[0] = '[';
|
|
|
|
memcpy(&value[1],key,keylen*sizeof(WCHAR));
|
|
|
|
value[1+keylen] = ']';
|
|
|
|
}
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sz = 0;
|
2005-05-27 21:23:29 +02:00
|
|
|
if (key) switch (key[0])
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2005-01-31 21:41:11 +01:00
|
|
|
case '~':
|
|
|
|
value = deformat_NULL(&chunk);
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
value = deformat_component(package,&key[1],&chunk);
|
|
|
|
break;
|
|
|
|
case '#':
|
2005-05-25 19:49:49 +02:00
|
|
|
value = deformat_file(package,&key[1], &chunk, FALSE);
|
|
|
|
break;
|
2005-01-31 21:41:11 +01:00
|
|
|
case '!': /* should be short path */
|
2005-05-25 19:49:49 +02:00
|
|
|
value = deformat_file(package,&key[1], &chunk, TRUE);
|
2005-01-31 21:41:11 +01:00
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
value = deformat_escape(&key[1],&chunk);
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
value = deformat_environment(package,&key[1],&chunk);
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-27 21:23:29 +02:00
|
|
|
/* index keys cannot be nested */
|
2005-01-31 21:41:11 +01:00
|
|
|
if (is_key_number(key))
|
2005-05-27 21:23:29 +02:00
|
|
|
if (!nested)
|
|
|
|
value = deformat_index(record,key,&chunk);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const WCHAR fmt[] = {'[','%','s',']',0};
|
2005-09-20 13:59:14 +02:00
|
|
|
value = msi_alloc(10);
|
2005-05-27 21:23:29 +02:00
|
|
|
sprintfW(value,fmt,key);
|
|
|
|
chunk = strlenW(value)*sizeof(WCHAR);
|
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
else
|
|
|
|
value = deformat_property(package,key,&chunk);
|
|
|
|
break;
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(key);
|
2005-02-02 10:30:22 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
if (value!=NULL)
|
|
|
|
{
|
|
|
|
LPBYTE nd2;
|
2006-10-05 06:41:22 +02:00
|
|
|
TRACE("value %s, chunk %i size %i\n",debugstr_w((LPWSTR)value),
|
2005-01-31 21:41:11 +01:00
|
|
|
chunk, size);
|
|
|
|
if (size)
|
2005-09-20 13:59:14 +02:00
|
|
|
nd2= msi_realloc(newdata,(size + chunk));
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
2005-09-20 13:59:14 +02:00
|
|
|
nd2= msi_alloc(chunk);
|
2005-01-31 21:41:11 +01:00
|
|
|
newdata = nd2;
|
|
|
|
memcpy(&newdata[size],value,chunk);
|
|
|
|
size+=chunk;
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(value);
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
2005-05-27 21:23:29 +02:00
|
|
|
else if (failcount && *failcount >=0 )
|
|
|
|
(*failcount)++;
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
progress = mark2+1;
|
2005-01-25 21:17:09 +01:00
|
|
|
}
|
|
|
|
|
2005-06-04 11:36:44 +02:00
|
|
|
TRACE("after everything %s\n",debugstr_wn((LPWSTR)newdata,
|
|
|
|
size/sizeof(WCHAR)));
|
2005-01-31 21:41:11 +01:00
|
|
|
|
|
|
|
*data = (LPWSTR)newdata;
|
|
|
|
return size / sizeof(WCHAR);
|
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
|
|
|
{
|
|
|
|
LPWSTR deformated;
|
|
|
|
LPWSTR rec;
|
|
|
|
DWORD len;
|
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
|
|
|
|
2006-10-05 06:41:22 +02:00
|
|
|
TRACE("%p %p %p %i\n", package, record ,buffer, *size);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-10-27 14:36:12 +02:00
|
|
|
rec = msi_dup_record_field(record,0);
|
2005-01-25 21:17:09 +01:00
|
|
|
if (!rec)
|
2005-01-31 21:41:11 +01:00
|
|
|
rec = build_default_format(record);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(rec));
|
|
|
|
|
2007-09-17 17:02:18 +02:00
|
|
|
len = deformat_string_internal(package,rec,&deformated,
|
|
|
|
rec ? strlenW(rec) : 0, record, NULL);
|
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
|
|
|
}
|
|
|
|
else
|
2005-01-31 21:41:11 +01:00
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
*size = len;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free(rec);
|
|
|
|
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;
|
|
|
|
|
|
|
|
TRACE("%ld %ld %p %p\n", hInstall, hRecord, szResult, sz);
|
|
|
|
|
2007-07-06 02:48:43 +02:00
|
|
|
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
|
|
|
|
if (!package)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IWineMsiRemotePackage *remote_package;
|
|
|
|
BSTR value = NULL;
|
|
|
|
DWORD len;
|
|
|
|
awstring wstr;
|
|
|
|
|
|
|
|
remote_package = (IWineMsiRemotePackage *)msi_get_remote( hInstall );
|
|
|
|
if (remote_package)
|
|
|
|
{
|
|
|
|
len = 0;
|
|
|
|
hr = IWineMsiRemotePackage_FormatRecord( remote_package, hRecord,
|
|
|
|
NULL, &len );
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
value = SysAllocStringLen( NULL, len );
|
|
|
|
if (!value)
|
|
|
|
{
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IWineMsiRemotePackage_FormatRecord( remote_package, hRecord,
|
|
|
|
value, &len );
|
|
|
|
if (FAILED(hr))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
wstr.unicode = TRUE;
|
|
|
|
wstr.str.w = szResult;
|
|
|
|
r = msi_strcpy_to_awstring( value, &wstr, sz );
|
|
|
|
|
|
|
|
done:
|
|
|
|
IWineMsiRemotePackage_Release( remote_package );
|
|
|
|
SysFreeString( value );
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
if (HRESULT_FACILITY(hr) == FACILITY_WIN32)
|
|
|
|
return HRESULT_CODE(hr);
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
|
|
|
|
|
|
|
|
if (!record)
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
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
|
|
|
|
|
|
|
TRACE("%ld %ld %p %p\n", hInstall, hRecord, szResult, sz);
|
|
|
|
|
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;
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, value, -1, NULL, 0, NULL, NULL);
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, value, -1, szResult, *sz, NULL, NULL);
|
|
|
|
|
|
|
|
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
|
|
|
}
|