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
|
|
|
|
* 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 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);
|
|
|
|
|
|
|
|
|
2005-06-01 13:02:48 +02:00
|
|
|
static LPWSTR build_default_format(MSIRECORD* record)
|
2005-01-31 21:41:11 +01:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
LPWSTR rc;
|
|
|
|
static const WCHAR fmt[] = {'%','i',':',' ','[','%','i',']',' ',0};
|
|
|
|
WCHAR buf[11];
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(record);
|
|
|
|
|
|
|
|
rc = HeapAlloc(GetProcessHeap(),0,(11*count)*sizeof(WCHAR));
|
|
|
|
rc[0] = 0;
|
|
|
|
for (i = 1; i <= count; i++)
|
|
|
|
{
|
|
|
|
sprintfW(buf,fmt,i,i);
|
|
|
|
strcatW(rc,buf);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
INT index;
|
|
|
|
|
|
|
|
*sz = 0;
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ERR("POORLY HANDLED DEFORMAT.. [$componentkey] \n");
|
|
|
|
index = get_loaded_component(package,key);
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
value = resolve_folder(package, package->components[index].Directory,
|
|
|
|
FALSE, FALSE, NULL);
|
|
|
|
*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;
|
|
|
|
INT index;
|
|
|
|
|
|
|
|
*sz = 0;
|
|
|
|
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
index = get_loaded_file(package,key);
|
|
|
|
if (index >=0)
|
|
|
|
{
|
2005-05-25 19:49:49 +02:00
|
|
|
if (!shortname)
|
|
|
|
{
|
|
|
|
value = strdupW(package->files[index].TargetPath);
|
|
|
|
*sz = (strlenW(value)) * sizeof(WCHAR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD size = 0;
|
|
|
|
size = GetShortPathNameW(package->files[index].TargetPath, NULL, 0);
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
*sz = (size-1) * sizeof (WCHAR);
|
|
|
|
size ++;
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,size * sizeof(WCHAR));
|
|
|
|
GetShortPathNameW(package->files[index].TargetPath, value,
|
|
|
|
size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("Unable to get ShortPath size (%s)\n",
|
|
|
|
debugstr_w(package->files[index].TargetPath));
|
|
|
|
value = NULL;
|
|
|
|
*sz = 0;
|
|
|
|
}
|
|
|
|
}
|
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++;
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,sz * sizeof(WCHAR));
|
|
|
|
GetEnvironmentVariableW(&key[1],value,sz);
|
|
|
|
*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;
|
|
|
|
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*2);
|
|
|
|
value[0] = 0;
|
|
|
|
*chunk = sizeof(WCHAR);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_escape(LPCWSTR key, DWORD* chunk)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*2);
|
|
|
|
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);
|
|
|
|
value = load_dynamic_stringW(record,index);
|
|
|
|
if (value)
|
|
|
|
*chunk = strlenW(value) * sizeof(WCHAR);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = NULL;
|
|
|
|
*chunk = 0;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR deformat_property(MSIPACKAGE* package, LPCWSTR key, DWORD* chunk)
|
|
|
|
{
|
|
|
|
UINT rc;
|
|
|
|
LPWSTR value;
|
|
|
|
|
|
|
|
if (!package)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
value = load_dynamic_property(package,key, &rc);
|
|
|
|
|
|
|
|
if (rc == ERROR_SUCCESS)
|
|
|
|
*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;
|
|
|
|
*group = HeapAlloc(GetProcessHeap(),0,i*sizeof(WCHAR));
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
*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 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;
|
|
|
|
*key = HeapAlloc(GetProcessHeap(),0,i*sizeof(WCHAR));
|
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
LPWSTR value;
|
|
|
|
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);
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,*size);
|
|
|
|
sprintfW(value,fmt,group);
|
|
|
|
/* do not return size of the null at the end */
|
|
|
|
*size = (len+1)*sizeof(WCHAR);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,key);
|
|
|
|
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;
|
|
|
|
|
|
|
|
v2 = HeapAlloc(GetProcessHeap(),0,(sz+2)*sizeof(WCHAR));
|
|
|
|
v2[0] = '{';
|
|
|
|
memcpy(&v2[1],value,sz*sizeof(WCHAR));
|
|
|
|
v2[sz+1]='}';
|
|
|
|
HeapFree(GetProcessHeap(),0,value);
|
|
|
|
|
|
|
|
*size = (sz+2)*sizeof(WCHAR);
|
|
|
|
return v2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*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;
|
2005-02-02 10:30:22 +01:00
|
|
|
BOOL nested;
|
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 */
|
|
|
|
*data = HeapAlloc(GetProcessHeap(),0,(len*sizeof(WCHAR)));
|
|
|
|
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);
|
|
|
|
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-06-04 11:36:44 +02:00
|
|
|
TRACE("after value %s \n",debugstr_wn((LPWSTR)newdata,
|
|
|
|
size/sizeof(WCHAR)));
|
2005-01-31 21:41:11 +01:00
|
|
|
chunk = (len - (progress - ptr)) * sizeof(WCHAR);
|
2005-02-02 10:30:22 +01:00
|
|
|
TRACE("after chunk is %li + %li\n",size,chunk);
|
2005-01-31 21:41:11 +01:00
|
|
|
if (size)
|
|
|
|
nd2 = HeapReAlloc(GetProcessHeap(),0,newdata,(size+chunk));
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
2005-02-02 10:30:22 +01:00
|
|
|
nd2 = HeapAlloc(GetProcessHeap(),0,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)
|
|
|
|
tgt = HeapAlloc(GetProcessHeap(),0,size);
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
2005-01-31 21:41:11 +01:00
|
|
|
tgt = HeapReAlloc(GetProcessHeap(),0,newdata,size);
|
|
|
|
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
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,key);
|
|
|
|
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);
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,chunk);
|
|
|
|
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};
|
|
|
|
value = HeapAlloc(GetProcessHeap(),0,10);
|
|
|
|
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
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,key);
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
if (value!=NULL)
|
|
|
|
{
|
|
|
|
LPBYTE nd2;
|
|
|
|
TRACE("value %s, chunk %li size %li\n",debugstr_w((LPWSTR)value),
|
|
|
|
chunk, size);
|
|
|
|
if (size)
|
|
|
|
nd2= HeapReAlloc(GetProcessHeap(),0,newdata,(size + chunk));
|
2005-01-25 21:17:09 +01:00
|
|
|
else
|
2005-01-31 21:41:11 +01:00
|
|
|
nd2= HeapAlloc(GetProcessHeap(),0,chunk);
|
|
|
|
newdata = nd2;
|
|
|
|
memcpy(&newdata[size],value,chunk);
|
|
|
|
size+=chunk;
|
|
|
|
HeapFree(GetProcessHeap(),0,value);
|
|
|
|
}
|
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,
|
|
|
|
DWORD *size )
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
|
|
|
LPWSTR deformated;
|
|
|
|
LPWSTR rec;
|
|
|
|
DWORD len;
|
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
TRACE("%p %p %p %li\n",package, record ,buffer, *size);
|
|
|
|
|
|
|
|
rec = load_dynamic_stringW(record,0);
|
|
|
|
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));
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
len = deformat_string_internal(package,rec,&deformated,strlenW(rec),
|
2005-05-27 21:23:29 +02:00
|
|
|
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
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(),0,rec);
|
|
|
|
HeapFree(GetProcessHeap(),0,deformated);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
UINT MSI_FormatRecordA( MSIPACKAGE* package, MSIRECORD* record, LPSTR buffer,
|
|
|
|
DWORD *size )
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2005-01-31 21:41:11 +01:00
|
|
|
LPWSTR deformated;
|
|
|
|
LPWSTR rec;
|
|
|
|
DWORD len,lenA;
|
|
|
|
UINT rc = ERROR_INVALID_PARAMETER;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
TRACE("%p %p %p %li\n",package, record ,buffer, *size);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
rec = load_dynamic_stringW(record,0);
|
|
|
|
if (!rec)
|
|
|
|
rec = build_default_format(record);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
TRACE("(%s)\n",debugstr_w(rec));
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
len = deformat_string_internal(package,rec,&deformated,strlenW(rec),
|
2005-05-27 21:23:29 +02:00
|
|
|
record, NULL);
|
2005-01-31 21:41:11 +01:00
|
|
|
lenA = WideCharToMultiByte(CP_ACP,0,deformated,len,NULL,0,NULL,NULL);
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte(CP_ACP,0,deformated,len,buffer,*size,NULL, NULL);
|
|
|
|
if (*size>lenA)
|
|
|
|
{
|
|
|
|
rc = ERROR_SUCCESS;
|
|
|
|
buffer[lenA] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rc = ERROR_MORE_DATA;
|
|
|
|
buffer[(*size)-1] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
rc = ERROR_SUCCESS;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
*size = lenA;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
HeapFree(GetProcessHeap(),0,rec);
|
|
|
|
HeapFree(GetProcessHeap(),0,deformated);
|
2005-01-25 21:17:09 +01:00
|
|
|
return rc;
|
2005-01-31 21:41:11 +01:00
|
|
|
}
|
|
|
|
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01: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 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,
|
|
|
|
LPSTR szResult, DWORD *sz )
|
2005-01-25 21:17:09 +01:00
|
|
|
{
|
2005-01-31 21:41:11 +01:00
|
|
|
UINT r = ERROR_INVALID_HANDLE;
|
|
|
|
MSIPACKAGE *package = NULL;
|
|
|
|
MSIRECORD *record = NULL;
|
2005-01-25 21:17:09 +01:00
|
|
|
|
|
|
|
TRACE("%ld %ld %p %p\n", hInstall, hRecord, szResult, sz);
|
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
record = msihandle2msiinfo( hRecord, MSIHANDLETYPE_RECORD );
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
if (!record)
|
2005-01-25 21:17:09 +01:00
|
|
|
return ERROR_INVALID_HANDLE;
|
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-01-25 21:17:09 +01:00
|
|
|
|
2005-01-31 21:41:11 +01:00
|
|
|
package = msihandle2msiinfo( hInstall, MSIHANDLETYPE_PACKAGE );
|
2005-01-25 21:17:09 +01:00
|
|
|
|
2005-03-10 12:15:40 +01:00
|
|
|
r = MSI_FormatRecordA( 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
|
|
|
}
|