2005-01-25 20:17:09 +00: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
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 "msipriv.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "action.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
|
2005-05-27 19:23:29 +00:00
|
|
|
static DWORD deformat_string_internal(MSIPACKAGE *package, LPCWSTR ptr,
|
|
|
|
WCHAR** data, DWORD len, MSIRECORD* record,
|
|
|
|
BOOL* in_group);
|
|
|
|
|
|
|
|
|
2005-06-01 11:02:48 +00:00
|
|
|
static LPWSTR build_default_format(MSIRECORD* record)
|
2005-01-31 20:41:11 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
LPWSTR rc;
|
|
|
|
static const WCHAR fmt[] = {'%','i',':',' ','[','%','i',']',' ',0};
|
|
|
|
WCHAR buf[11];
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(record);
|
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
rc = msi_alloc((11*count)*sizeof(WCHAR));
|
2005-01-31 20:41:11 +00:00
|
|
|
rc[0] = 0;
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
sprintfW(buf,fmt,i,i);
|
|
|
|
strcatW(rc,buf);
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-01-25 20:17:09 +00: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 20:41:11 +00:00
|
|
|
/* break out helper functions for deformating */
|
|
|
|
static LPWSTR deformat_component(MSIPACKAGE* package, LPCWSTR key, DWORD* sz)
|
|
|
|
{
|
|
|
|
LPWSTR value = NULL;
|
2005-08-22 09:15:23 +00:00
|
|
|
MSICOMPONENT *comp;
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
*sz = 0;
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
2005-09-08 11:04:03 +00:00
|
|
|
FIXME("component key %s\n", debugstr_w(key));
|
2005-08-22 09:15:23 +00:00
|
|
|
comp = get_loaded_component(package,key);
|
|
|
|
if (comp)
|
2005-01-31 20:41:11 +00:00
|
|
|
{
|
2005-08-22 09:15:23 +00:00
|
|
|
value = resolve_folder(package, comp->Directory, FALSE, FALSE, NULL);
|
2005-01-31 20:41:11 +00:00
|
|
|
*sz = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-05-25 17:49:49 +00:00
|
|
|
static LPWSTR deformat_file(MSIPACKAGE* package, LPCWSTR key, DWORD* sz,
|
|
|
|
BOOL shortname)
|
2005-01-31 20:41:11 +00:00
|
|
|
{
|
|
|
|
LPWSTR value = NULL;
|
2005-08-23 10:03:17 +00:00
|
|
|
MSIFILE *file;
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
*sz = 0;
|
|
|
|
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
2005-08-23 10:03:17 +00:00
|
|
|
file = get_loaded_file( package, key );
|
|
|
|
if (file)
|
2005-01-31 20:41:11 +00:00
|
|
|
{
|
2005-05-25 17:49:49 +00:00
|
|
|
if (!shortname)
|
|
|
|
{
|
2005-08-23 10:03:17 +00:00
|
|
|
value = strdupW( file->TargetPath );
|
2005-05-25 17:49:49 +00:00
|
|
|
*sz = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD size = 0;
|
2005-08-23 10:03:17 +00:00
|
|
|
size = GetShortPathNameW( file->TargetPath, NULL, 0 );
|
2005-05-25 17:49:49 +00:00
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
*sz = (size-1) * sizeof (WCHAR);
|
|
|
|
size ++;
|
2005-09-20 11:59:14 +00:00
|
|
|
value = msi_alloc(size * sizeof(WCHAR));
|
2005-08-23 10:03:17 +00:00
|
|
|
GetShortPathNameW( file->TargetPath, value, size );
|
2005-05-25 17:49:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-23 10:03:17 +00:00
|
|
|
ERR("Unable to get ShortPath size (%s)\n",
|
|
|
|
debugstr_w( file->TargetPath) );
|
2005-05-25 17:49:49 +00:00
|
|
|
value = NULL;
|
|
|
|
*sz = 0;
|
|
|
|
}
|
|
|
|
}
|
2005-01-31 20:41:11 +00: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 11:59:14 +00:00
|
|
|
value = msi_alloc(sz * sizeof(WCHAR));
|
2005-12-19 17:17:28 +00:00
|
|
|
GetEnvironmentVariableW(key,value,sz);
|
2005-01-31 20:41:11 +00:00
|
|
|
*chunk = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-12 10:15:09 +00:00
|
|
|
ERR("Unknown environment variable %s\n", debugstr_w(key));
|
2005-01-31 20:41:11 +00:00
|
|
|
*chunk = 0;
|
|
|
|
value = NULL;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static LPWSTR deformat_NULL(DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
value = msi_alloc(sizeof(WCHAR)*2);
|
2005-01-31 20:41:11 +00:00
|
|
|
value[0] = 0;
|
|
|
|
*chunk = sizeof(WCHAR);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_escape(LPCWSTR key, DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
value = msi_alloc(sizeof(WCHAR)*2);
|
2005-01-31 20:41:11 +00:00
|
|
|
value[0] = key[0];
|
|
|
|
*chunk = sizeof(WCHAR);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL is_key_number(LPCWSTR key)
|
|
|
|
{
|
|
|
|
INT index = 0;
|
2005-02-02 09:30:22 +00:00
|
|
|
if (key[0] == 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-01-31 20:41:11 +00: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 12:36:12 +00:00
|
|
|
value = msi_dup_record_field(record,index);
|
2005-01-31 20:41:11 +00: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 15:04:08 +00:00
|
|
|
value = msi_dup_property( package, key );
|
2005-01-31 20:41:11 +00:00
|
|
|
|
2005-09-15 15:04:08 +00:00
|
|
|
if (value)
|
2005-01-31 20:41:11 +00:00
|
|
|
*chunk = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2005-05-27 19:23:29 +00: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 11:59:14 +00:00
|
|
|
*group = msi_alloc(i*sizeof(WCHAR));
|
2005-05-27 19:23:29 +00: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 09:30:22 +00: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;
|
|
|
|
|
|
|
|
*mark = scanW(source,'[',len_remaining);
|
|
|
|
if (!*mark)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
count = 1;
|
|
|
|
total_count = 1;
|
|
|
|
*nested = FALSE;
|
|
|
|
for (i = 1; (*mark - source) + i < len_remaining && count > 0; i++)
|
|
|
|
{
|
2005-02-23 12:44:25 +00:00
|
|
|
if ((*mark)[i] == '[' && (*mark)[i-1] != '\\')
|
2005-02-02 09:30:22 +00:00
|
|
|
{
|
|
|
|
count ++;
|
|
|
|
total_count ++;
|
|
|
|
*nested = TRUE;
|
|
|
|
}
|
2005-02-23 12:44:25 +00:00
|
|
|
else if ((*mark)[i] == ']' && (*mark)[i-1] != '\\')
|
2005-02-02 09:30:22 +00:00
|
|
|
{
|
|
|
|
count --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*mark2 = &(*mark)[i-1];
|
|
|
|
|
|
|
|
i = *mark2 - *mark;
|
2005-09-20 11:59:14 +00:00
|
|
|
*key = msi_alloc(i*sizeof(WCHAR));
|
2005-02-02 09:30:22 +00:00
|
|
|
/* do not have the [] in the key */
|
|
|
|
i -= 1;
|
2005-03-28 14:17:51 +00:00
|
|
|
memcpy(*key,&(*mark)[1],i*sizeof(WCHAR));
|
2005-02-02 09:30:22 +00:00
|
|
|
(*key)[i] = 0;
|
|
|
|
|
|
|
|
TRACE("Found Key %s\n",debugstr_w(*key));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-06-01 11:02:48 +00:00
|
|
|
static LPWSTR deformat_group(MSIPACKAGE* package, LPWSTR group, DWORD len,
|
2005-05-27 19:23:29 +00:00
|
|
|
MSIRECORD* record, DWORD* size)
|
|
|
|
{
|
2005-09-20 11:59:14 +00:00
|
|
|
LPWSTR value = NULL;
|
2005-05-27 19:23:29 +00: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 11:59:14 +00:00
|
|
|
value = msi_alloc(*size);
|
2005-05-27 19:23:29 +00: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 11:59:14 +00:00
|
|
|
msi_free(key);
|
2005-05-27 19:23:29 +00: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 11:59:14 +00:00
|
|
|
v2 = msi_alloc((sz+2)*sizeof(WCHAR));
|
2005-05-27 19:23:29 +00:00
|
|
|
v2[0] = '{';
|
|
|
|
memcpy(&v2[1],value,sz*sizeof(WCHAR));
|
|
|
|
v2[sz+1]='}';
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(value);
|
2005-05-27 19:23:29 +00:00
|
|
|
|
|
|
|
*size = (sz+2)*sizeof(WCHAR);
|
|
|
|
return v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-21 09:43:29 +00:00
|
|
|
msi_free(value);
|
2005-05-27 19:23:29 +00:00
|
|
|
*size = 0;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-02 09:30:22 +00:00
|
|
|
|
2005-01-25 20:17:09 +00:00
|
|
|
/*
|
|
|
|
* len is in WCHARs
|
|
|
|
* return is also in WCHARs
|
|
|
|
*/
|
|
|
|
static DWORD deformat_string_internal(MSIPACKAGE *package, LPCWSTR ptr,
|
2005-05-27 19:23:29 +00:00
|
|
|
WCHAR** data, DWORD len, MSIRECORD* record,
|
|
|
|
INT* failcount)
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
2005-02-02 09:30:22 +00:00
|
|
|
LPCWSTR mark = NULL;
|
|
|
|
LPCWSTR mark2 = NULL;
|
2005-01-25 20:17:09 +00:00
|
|
|
DWORD size=0;
|
|
|
|
DWORD chunk=0;
|
2005-02-02 09:30:22 +00:00
|
|
|
LPWSTR key;
|
2005-01-25 20:17:09 +00:00
|
|
|
LPWSTR value = NULL;
|
|
|
|
DWORD sz;
|
2005-01-31 20:41:11 +00:00
|
|
|
LPBYTE newdata = NULL;
|
|
|
|
const WCHAR* progress = NULL;
|
2005-02-02 09:30:22 +00:00
|
|
|
BOOL nested;
|
2005-01-25 20:17:09 +00:00
|
|
|
|
|
|
|
if (ptr==NULL)
|
|
|
|
{
|
|
|
|
TRACE("Deformatting NULL string\n");
|
|
|
|
*data = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-04 09:36:44 +00:00
|
|
|
TRACE("Starting with %s\n",debugstr_wn(ptr,len));
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
/* scan for special characters... fast exit */
|
2005-05-27 19:23:29 +00:00
|
|
|
if ((!scanW(ptr,'[',len) || (scanW(ptr,'[',len) && !scanW(ptr,']',len))) &&
|
|
|
|
(scanW(ptr,'{',len) && !scanW(ptr,'}',len)))
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
|
|
|
/* not formatted */
|
2005-09-20 11:59:14 +00:00
|
|
|
*data = msi_alloc((len*sizeof(WCHAR)));
|
2005-01-25 20:17:09 +00:00
|
|
|
memcpy(*data,ptr,len*sizeof(WCHAR));
|
2005-05-29 20:08:12 +00:00
|
|
|
TRACE("Returning %s\n",debugstr_wn(*data,len));
|
2005-01-25 20:17:09 +00:00
|
|
|
return len;
|
|
|
|
}
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
progress = ptr;
|
|
|
|
|
|
|
|
while (progress - ptr < len)
|
2005-02-02 09:30:22 +00:00
|
|
|
{
|
2005-05-27 19:23:29 +00: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 09:43:29 +00:00
|
|
|
msi_free( key );
|
2005-05-27 19:23:29 +00:00
|
|
|
key = NULL;
|
|
|
|
nested = FALSE;
|
|
|
|
}
|
2005-02-02 09:30:22 +00:00
|
|
|
/* formatted string located */
|
2005-05-27 19:23:29 +00:00
|
|
|
else if (!find_next_outermost_key(progress, len - (progress - ptr),
|
|
|
|
&key, &mark, &mark2, &nested))
|
2005-01-31 20:41:11 +00:00
|
|
|
{
|
|
|
|
LPBYTE nd2;
|
|
|
|
|
2005-11-10 12:14:56 +00:00
|
|
|
TRACE("after value %s\n", debugstr_wn((LPWSTR)newdata,
|
2005-06-04 09:36:44 +00:00
|
|
|
size/sizeof(WCHAR)));
|
2005-01-31 20:41:11 +00:00
|
|
|
chunk = (len - (progress - ptr)) * sizeof(WCHAR);
|
2005-02-02 09:30:22 +00:00
|
|
|
TRACE("after chunk is %li + %li\n",size,chunk);
|
2005-01-31 20:41:11 +00:00
|
|
|
if (size)
|
2005-09-20 11:59:14 +00:00
|
|
|
nd2 = msi_realloc(newdata,(size+chunk));
|
2005-01-25 20:17:09 +00:00
|
|
|
else
|
2005-09-20 11:59:14 +00:00
|
|
|
nd2 = msi_alloc(chunk);
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
newdata = nd2;
|
|
|
|
memcpy(&newdata[size],progress,chunk);
|
|
|
|
size+=chunk;
|
2005-01-25 20:17:09 +00:00
|
|
|
break;
|
2005-01-31 20:41:11 +00: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 11:59:14 +00:00
|
|
|
tgt = msi_alloc(size);
|
2005-01-25 20:17:09 +00:00
|
|
|
else
|
2005-09-20 11:59:14 +00:00
|
|
|
tgt = msi_realloc(newdata,size);
|
2005-01-31 20:41:11 +00:00
|
|
|
newdata = tgt;
|
|
|
|
memcpy(&newdata[old_size],progress,(cnt * sizeof(WCHAR)));
|
|
|
|
}
|
|
|
|
|
|
|
|
progress = mark;
|
|
|
|
|
2005-02-02 09:30:22 +00:00
|
|
|
if (nested)
|
|
|
|
{
|
|
|
|
TRACE("Nested key... %s\n",debugstr_w(key));
|
|
|
|
deformat_string_internal(package, key, &value, strlenW(key)+1,
|
2005-05-27 19:23:29 +00:00
|
|
|
record, failcount);
|
2005-02-02 09:30:22 +00:00
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(key);
|
2005-02-02 09:30:22 +00:00
|
|
|
key = value;
|
|
|
|
}
|
|
|
|
|
2005-06-04 09:36:44 +00:00
|
|
|
TRACE("Current %s .. %s\n",debugstr_wn((LPWSTR)newdata,
|
|
|
|
size/sizeof(WCHAR)),debugstr_w(key));
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
if (!package)
|
|
|
|
{
|
|
|
|
/* only deformat number indexs */
|
2005-05-27 19:23:29 +00:00
|
|
|
if (key && is_key_number(key))
|
|
|
|
{
|
2005-01-31 20:41:11 +00:00
|
|
|
value = deformat_index(record,key,&chunk);
|
2005-05-27 19:23:29 +00:00
|
|
|
if (!chunk && failcount && *failcount >= 0)
|
|
|
|
(*failcount)++;
|
|
|
|
}
|
2005-01-25 20:17:09 +00:00
|
|
|
else
|
|
|
|
{
|
2005-05-27 19:23:29 +00:00
|
|
|
if (failcount)
|
|
|
|
*failcount = -1;
|
|
|
|
if(key)
|
|
|
|
{
|
|
|
|
DWORD keylen = strlenW(key);
|
|
|
|
chunk = (keylen + 2)*sizeof(WCHAR);
|
2005-09-20 11:59:14 +00:00
|
|
|
value = msi_alloc(chunk);
|
2005-05-27 19:23:29 +00:00
|
|
|
value[0] = '[';
|
|
|
|
memcpy(&value[1],key,keylen*sizeof(WCHAR));
|
|
|
|
value[1+keylen] = ']';
|
|
|
|
}
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|
2005-01-31 20:41:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sz = 0;
|
2005-05-27 19:23:29 +00:00
|
|
|
if (key) switch (key[0])
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
2005-01-31 20:41:11 +00:00
|
|
|
case '~':
|
|
|
|
value = deformat_NULL(&chunk);
|
|
|
|
break;
|
|
|
|
case '$':
|
|
|
|
value = deformat_component(package,&key[1],&chunk);
|
|
|
|
break;
|
|
|
|
case '#':
|
2005-05-25 17:49:49 +00:00
|
|
|
value = deformat_file(package,&key[1], &chunk, FALSE);
|
|
|
|
break;
|
2005-01-31 20:41:11 +00:00
|
|
|
case '!': /* should be short path */
|
2005-05-25 17:49:49 +00:00
|
|
|
value = deformat_file(package,&key[1], &chunk, TRUE);
|
2005-01-31 20:41:11 +00:00
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
value = deformat_escape(&key[1],&chunk);
|
|
|
|
break;
|
|
|
|
case '%':
|
|
|
|
value = deformat_environment(package,&key[1],&chunk);
|
|
|
|
break;
|
|
|
|
default:
|
2005-05-27 19:23:29 +00:00
|
|
|
/* index keys cannot be nested */
|
2005-01-31 20:41:11 +00:00
|
|
|
if (is_key_number(key))
|
2005-05-27 19:23:29 +00:00
|
|
|
if (!nested)
|
|
|
|
value = deformat_index(record,key,&chunk);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
static const WCHAR fmt[] = {'[','%','s',']',0};
|
2005-09-20 11:59:14 +00:00
|
|
|
value = msi_alloc(10);
|
2005-05-27 19:23:29 +00:00
|
|
|
sprintfW(value,fmt,key);
|
|
|
|
chunk = strlenW(value)*sizeof(WCHAR);
|
|
|
|
}
|
2005-01-31 20:41:11 +00:00
|
|
|
else
|
|
|
|
value = deformat_property(package,key,&chunk);
|
|
|
|
break;
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|
2005-01-31 20:41:11 +00:00
|
|
|
}
|
2005-02-02 09:30:22 +00:00
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(key);
|
2005-02-02 09:30:22 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
if (value!=NULL)
|
|
|
|
{
|
|
|
|
LPBYTE nd2;
|
|
|
|
TRACE("value %s, chunk %li size %li\n",debugstr_w((LPWSTR)value),
|
|
|
|
chunk, size);
|
|
|
|
if (size)
|
2005-09-20 11:59:14 +00:00
|
|
|
nd2= msi_realloc(newdata,(size + chunk));
|
2005-01-25 20:17:09 +00:00
|
|
|
else
|
2005-09-20 11:59:14 +00:00
|
|
|
nd2= msi_alloc(chunk);
|
2005-01-31 20:41:11 +00:00
|
|
|
newdata = nd2;
|
|
|
|
memcpy(&newdata[size],value,chunk);
|
|
|
|
size+=chunk;
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(value);
|
2005-01-31 20:41:11 +00:00
|
|
|
}
|
2005-05-27 19:23:29 +00:00
|
|
|
else if (failcount && *failcount >=0 )
|
|
|
|
(*failcount)++;
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
progress = mark2+1;
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|
|
|
|
|
2005-06-04 09:36:44 +00:00
|
|
|
TRACE("after everything %s\n",debugstr_wn((LPWSTR)newdata,
|
|
|
|
size/sizeof(WCHAR)));
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
*data = (LPWSTR)newdata;
|
|
|
|
return size / sizeof(WCHAR);
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
UINT MSI_FormatRecordW( MSIPACKAGE* package, MSIRECORD* record, LPWSTR buffer,
|
|
|
|
DWORD *size )
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
|
|
|
LPWSTR deformated;
|
|
|
|
LPWSTR rec;
|
|
|
|
DWORD len;
|
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
TRACE("%p %p %p %li\n",package, record ,buffer, *size);
|
|
|
|
|
2005-10-27 12:36:12 +00:00
|
|
|
rec = msi_dup_record_field(record,0);
|
2005-01-25 20:17:09 +00:00
|
|
|
if (!rec)
|
2005-01-31 20:41:11 +00:00
|
|
|
rec = build_default_format(record);
|
2005-01-25 20:17:09 +00:00
|
|
|
|
|
|
|
TRACE("(%s)\n",debugstr_w(rec));
|
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
len = deformat_string_internal(package,rec,&deformated,strlenW(rec),
|
2005-05-27 19:23:29 +00:00
|
|
|
record, NULL);
|
2005-01-31 20:41:11 +00:00
|
|
|
|
|
|
|
if (buffer)
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
2005-01-31 20:41:11 +00:00
|
|
|
if (*size>len)
|
|
|
|
{
|
|
|
|
memcpy(buffer,deformated,len*sizeof(WCHAR));
|
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
buffer[len] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-02-09 22:22:25 +00:00
|
|
|
if (*size > 0)
|
|
|
|
{
|
|
|
|
memcpy(buffer,deformated,(*size)*sizeof(WCHAR));
|
|
|
|
buffer[(*size)-1] = 0;
|
|
|
|
}
|
2005-01-31 20:41:11 +00:00
|
|
|
rc = ERROR_MORE_DATA;
|
|
|
|
}
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|
|
|
|
else
|
2005-01-31 20:41:11 +00:00
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
*size = len;
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(rec);
|
|
|
|
msi_free(deformated);
|
2005-01-25 20:17:09 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
UINT MSI_FormatRecordA( MSIPACKAGE* package, MSIRECORD* record, LPSTR buffer,
|
|
|
|
DWORD *size )
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
2005-01-31 20:41:11 +00:00
|
|
|
LPWSTR deformated;
|
|
|
|
LPWSTR rec;
|
|
|
|
DWORD len,lenA;
|
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
TRACE("%p %p %p %li\n",package, record ,buffer, *size);
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-10-27 12:36:12 +00:00
|
|
|
rec = msi_dup_record_field(record,0);
|
2005-01-31 20:41:11 +00:00
|
|
|
if (!rec)
|
|
|
|
rec = build_default_format(record);
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
TRACE("(%s)\n",debugstr_w(rec));
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
len = deformat_string_internal(package,rec,&deformated,strlenW(rec),
|
2005-05-27 19:23:29 +00:00
|
|
|
record, NULL);
|
2005-12-21 20:19:47 +00:00
|
|
|
/* If len is zero then WideCharToMultiByte will return 0 indicating
|
|
|
|
* failure, but that will do just as well since we are ignoring
|
|
|
|
* possible errors.
|
|
|
|
*/
|
2005-01-31 20:41:11 +00:00
|
|
|
lenA = WideCharToMultiByte(CP_ACP,0,deformated,len,NULL,0,NULL,NULL);
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
if (buffer)
|
|
|
|
{
|
2005-12-21 20:19:47 +00:00
|
|
|
/* Ditto above */
|
2005-01-31 20:41:11 +00:00
|
|
|
WideCharToMultiByte(CP_ACP,0,deformated,len,buffer,*size,NULL, NULL);
|
|
|
|
if (*size>lenA)
|
|
|
|
{
|
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
buffer[lenA] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rc = ERROR_MORE_DATA;
|
2005-12-21 20:19:47 +00:00
|
|
|
if (*size)
|
|
|
|
buffer[(*size)-1] = 0;
|
2005-01-31 20:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = ERROR_SUCCESS;
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
*size = lenA;
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-09-20 11:59:14 +00:00
|
|
|
msi_free(rec);
|
|
|
|
msi_free(deformated);
|
2005-01-25 20:17:09 +00:00
|
|
|
return rc;
|
2005-01-31 20:41:11 +00:00
|
|
|
}
|
|
|
|
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
UINT WINAPI MsiFormatRecordW( MSIHANDLE hInstall, MSIHANDLE hRecord,
|
|
|
|
LPWSTR szResult, DWORD *sz )
|
|
|
|
{
|
|
|
|
UINT r = ERROR_INVALID_HANDLE;
|
|
|
|
MSIPACKAGE *package;
|
|
|
|
MSIRECORD *record;
|
|
|
|
|
|
|
|
TRACE("%ld %ld %p %p\n", hInstall, hRecord, szResult, sz);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
|
|
|
|
|
2005-03-10 11:15:40 +00:00
|
|
|
r = MSI_FormatRecordW( package, record, szResult, sz );
|
|
|
|
msiobj_release( &record->hdr );
|
2005-01-31 20:41:11 +00:00
|
|
|
if (package)
|
|
|
|
msiobj_release( &package->hdr );
|
|
|
|
return r;
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
UINT WINAPI MsiFormatRecordA( MSIHANDLE hInstall, MSIHANDLE hRecord,
|
|
|
|
LPSTR szResult, DWORD *sz )
|
2005-01-25 20:17:09 +00:00
|
|
|
{
|
2005-01-31 20:41:11 +00:00
|
|
|
UINT r = ERROR_INVALID_HANDLE;
|
|
|
|
MSIPACKAGE *package = NULL;
|
|
|
|
MSIRECORD *record = NULL;
|
2005-01-25 20:17:09 +00:00
|
|
|
|
|
|
|
TRACE("%ld %ld %p %p\n", hInstall, hRecord, szResult, sz);
|
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
if (!record)
|
2005-01-25 20:17:09 +00:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2005-01-31 20:41:11 +00:00
|
|
|
if (!sz)
|
|
|
|
{
|
|
|
|
msiobj_release( &record->hdr );
|
|
|
|
if (szResult)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
else
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-01-31 20:41:11 +00:00
|
|
|
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
|
2005-01-25 20:17:09 +00:00
|
|
|
|
2005-03-10 11:15:40 +00:00
|
|
|
r = MSI_FormatRecordA( package, record, szResult, sz );
|
|
|
|
msiobj_release( &record->hdr );
|
2005-01-31 20:41:11 +00:00
|
|
|
if (package)
|
|
|
|
msiobj_release( &package->hdr );
|
|
|
|
return r;
|
2005-01-25 20:17:09 +00:00
|
|
|
}
|