2003-08-13 03:27:48 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2004-07-10 00:25:34 +02:00
|
|
|
* Copyright 2002-2004 Mike McCormack for CodeWeavers
|
2003-08-13 03:27:48 +02:00
|
|
|
*
|
|
|
|
* 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
|
2003-08-13 03:27:48 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2004-08-11 21:43:45 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
2010-10-19 11:27:44 +02:00
|
|
|
#include "wine/unicode.h"
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "winnls.h"
|
2005-01-09 19:24:15 +01:00
|
|
|
#include "ole2.h"
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-06-23 18:43:38 +02:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "query.h"
|
|
|
|
|
2005-11-02 15:24:21 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
#define MSIFIELD_NULL 0
|
|
|
|
#define MSIFIELD_INT 1
|
|
|
|
#define MSIFIELD_WSTR 3
|
|
|
|
#define MSIFIELD_STREAM 4
|
2010-09-10 17:30:05 +02:00
|
|
|
#define MSIFIELD_INTPTR 5
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-05-31 11:30:28 +02:00
|
|
|
static void MSI_FreeField( MSIFIELD *field )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
switch( field->type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_NULL:
|
|
|
|
case MSIFIELD_INT:
|
2010-09-10 17:30:05 +02:00
|
|
|
case MSIFIELD_INTPTR:
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
case MSIFIELD_WSTR:
|
2005-09-20 13:57:19 +02:00
|
|
|
msi_free( field->u.szwVal);
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
case MSIFIELD_STREAM:
|
|
|
|
IStream_Release( field->u.stream );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("Invalid field type %d\n", field->type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 02:01:12 +01:00
|
|
|
void MSI_CloseRecord( MSIOBJECTHDR *arg )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec = (MSIRECORD *) arg;
|
|
|
|
UINT i;
|
|
|
|
|
2004-06-29 05:49:54 +02:00
|
|
|
for( i=0; i<=rec->count; i++ )
|
2003-08-13 03:27:48 +02:00
|
|
|
MSI_FreeField( &rec->fields[i] );
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
MSIRECORD *MSI_CreateRecord( UINT cParams )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT len;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("%d\n", cParams);
|
|
|
|
|
2005-01-06 21:42:25 +01:00
|
|
|
if( cParams>65535 )
|
|
|
|
return NULL;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
len = sizeof (MSIRECORD) + sizeof (MSIFIELD)*cParams;
|
|
|
|
rec = alloc_msiobject( MSIHANDLETYPE_RECORD, len, MSI_CloseRecord );
|
|
|
|
if( rec )
|
2005-01-06 21:42:25 +01:00
|
|
|
rec->count = cParams;
|
2004-07-10 00:25:34 +02:00
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
MSIHANDLE WINAPI MsiCreateRecord( UINT cParams )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
|
|
|
MSIHANDLE ret = 0;
|
|
|
|
|
|
|
|
TRACE("%d\n", cParams);
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( cParams );
|
|
|
|
if( rec )
|
2006-04-07 06:33:16 +02:00
|
|
|
{
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = alloc_msihandle( &rec->hdr );
|
2006-04-07 06:33:16 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
2004-07-10 00:25:34 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordGetFieldCount( const MSIRECORD *rec )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
return rec->count;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordGetFieldCount( MSIHANDLE handle )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d\n", handle );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
2005-01-06 21:42:25 +01:00
|
|
|
return -1;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordGetFieldCount( rec );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
|
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL string2intW( LPCWSTR str, int *out )
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
LPCWSTR p = str;
|
|
|
|
|
|
|
|
if( *p == '-' ) /* skip the minus sign */
|
|
|
|
p++;
|
|
|
|
while ( *p )
|
|
|
|
{
|
|
|
|
if( (*p < '0') || (*p > '9') )
|
|
|
|
return FALSE;
|
|
|
|
x *= 10;
|
|
|
|
x += (*p - '0');
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( str[0] == '-' ) /* check if it's negative */
|
|
|
|
x = -x;
|
|
|
|
*out = x;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordCopyField( MSIRECORD *in_rec, UINT in_n,
|
|
|
|
MSIRECORD *out_rec, UINT out_n )
|
2006-08-31 10:05:45 +02:00
|
|
|
{
|
|
|
|
UINT r = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
msiobj_lock( &in_rec->hdr );
|
|
|
|
|
|
|
|
if ( in_n > in_rec->count || out_n > out_rec->count )
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
else if ( in_rec != out_rec || in_n != out_n )
|
|
|
|
{
|
|
|
|
LPWSTR str;
|
|
|
|
MSIFIELD *in, *out;
|
|
|
|
|
|
|
|
in = &in_rec->fields[in_n];
|
|
|
|
out = &out_rec->fields[out_n];
|
|
|
|
|
|
|
|
switch ( in->type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_NULL:
|
|
|
|
break;
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
out->u.iVal = in->u.iVal;
|
|
|
|
break;
|
2010-09-10 17:30:05 +02:00
|
|
|
case MSIFIELD_INTPTR:
|
|
|
|
out->u.pVal = in->u.pVal;
|
|
|
|
break;
|
2006-08-31 10:05:45 +02:00
|
|
|
case MSIFIELD_WSTR:
|
|
|
|
str = strdupW( in->u.szwVal );
|
|
|
|
if ( !str )
|
|
|
|
r = ERROR_OUTOFMEMORY;
|
|
|
|
else
|
|
|
|
out->u.szwVal = str;
|
|
|
|
break;
|
|
|
|
case MSIFIELD_STREAM:
|
|
|
|
IStream_AddRef( in->u.stream );
|
|
|
|
out->u.stream = in->u.stream;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("invalid field type %d\n", in->type);
|
|
|
|
}
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
out->type = in->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
msiobj_unlock( &in_rec->hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2010-09-10 17:30:05 +02:00
|
|
|
INT_PTR MSI_RecordGetIntPtr( MSIRECORD *rec, UINT iField )
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
TRACE( "%p %d\n", rec, iField );
|
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return MININT_PTR;
|
|
|
|
|
|
|
|
switch( rec->fields[iField].type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
return rec->fields[iField].u.iVal;
|
|
|
|
case MSIFIELD_INTPTR:
|
|
|
|
return rec->fields[iField].u.pVal;
|
|
|
|
case MSIFIELD_WSTR:
|
|
|
|
if( string2intW( rec->fields[iField].u.szwVal, &ret ) )
|
|
|
|
return ret;
|
|
|
|
return MININT_PTR;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MININT_PTR;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
int MSI_RecordGetInteger( MSIRECORD *rec, UINT iField)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %d\n", rec, iField );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return MSI_NULL_INTEGER;
|
|
|
|
|
|
|
|
switch( rec->fields[iField].type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
return rec->fields[iField].u.iVal;
|
2010-09-10 17:30:05 +02:00
|
|
|
case MSIFIELD_INTPTR:
|
|
|
|
return rec->fields[iField].u.pVal;
|
2003-08-13 03:27:48 +02:00
|
|
|
case MSIFIELD_WSTR:
|
|
|
|
if( string2intW( rec->fields[iField].u.szwVal, &ret ) )
|
|
|
|
return ret;
|
|
|
|
return MSI_NULL_INTEGER;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MSI_NULL_INTEGER;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
int WINAPI MsiRecordGetInteger( MSIHANDLE handle, UINT iField)
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT ret;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d\n", handle, iField );
|
2004-07-10 00:25:34 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return MSI_NULL_INTEGER;
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordGetInteger( rec, iField );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT WINAPI MsiRecordClearData( MSIHANDLE handle )
|
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT i;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d\n", handle );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2003-08-13 03:27:48 +02:00
|
|
|
for( i=0; i<=rec->count; i++)
|
|
|
|
{
|
|
|
|
MSI_FreeField( &rec->fields[i] );
|
|
|
|
rec->fields[i].type = MSIFIELD_NULL;
|
|
|
|
rec->fields[i].u.iVal = 0;
|
|
|
|
}
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2005-03-10 12:15:40 +01:00
|
|
|
msiobj_release( &rec->hdr );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-09-10 17:30:05 +02:00
|
|
|
UINT MSI_RecordSetIntPtr( MSIRECORD *rec, UINT iField, INT_PTR pVal )
|
|
|
|
{
|
|
|
|
TRACE("%p %u %ld\n", rec, iField, pVal);
|
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
MSI_FreeField( &rec->fields[iField] );
|
|
|
|
rec->fields[iField].type = MSIFIELD_INTPTR;
|
|
|
|
rec->fields[iField].u.pVal = pVal;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordSetInteger( MSIRECORD *rec, UINT iField, int iVal )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %u %d\n", rec, iField, iVal);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-01-06 21:42:25 +01:00
|
|
|
if( iField > rec->count )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2006-11-21 07:21:27 +01:00
|
|
|
|
2005-01-06 21:42:25 +01:00
|
|
|
MSI_FreeField( &rec->fields[iField] );
|
|
|
|
rec->fields[iField].type = MSIFIELD_INT;
|
|
|
|
rec->fields[iField].u.iVal = iVal;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordSetInteger( MSIHANDLE handle, UINT iField, int iVal )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %u %d\n", handle, iField, iVal);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordSetInteger( rec, iField, iVal );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
BOOL MSI_RecordIsNull( MSIRECORD *rec, UINT iField )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
BOOL r = TRUE;
|
|
|
|
|
|
|
|
TRACE("%p %d\n", rec, iField );
|
|
|
|
|
2004-03-19 20:14:12 +01:00
|
|
|
r = ( iField > rec->count ) ||
|
|
|
|
( rec->fields[iField].type == MSIFIELD_NULL );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-03-19 20:14:12 +01:00
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
BOOL WINAPI MsiRecordIsNull( MSIHANDLE handle, UINT iField )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d\n", handle, iField );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
2005-01-06 21:42:25 +01:00
|
|
|
return 0;
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordIsNull( rec, iField );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordGetStringA(MSIRECORD *rec, UINT iField,
|
|
|
|
LPSTR szValue, LPDWORD pcchValue)
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
UINT len=0, ret;
|
|
|
|
CHAR buffer[16];
|
|
|
|
|
|
|
|
TRACE("%p %d %p %p\n", rec, iField, szValue, pcchValue);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( iField > rec->count )
|
2008-02-11 08:15:13 +01:00
|
|
|
{
|
|
|
|
if ( szValue && *pcchValue > 0 )
|
|
|
|
szValue[0] = 0;
|
|
|
|
|
|
|
|
*pcchValue = 0;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
switch( rec->fields[iField].type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
wsprintfA(buffer, "%d", rec->fields[iField].u.iVal);
|
|
|
|
len = lstrlenA( buffer );
|
2006-11-21 07:21:27 +01:00
|
|
|
if (szValue)
|
|
|
|
lstrcpynA(szValue, buffer, *pcchValue);
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
case MSIFIELD_WSTR:
|
|
|
|
len = WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1,
|
|
|
|
NULL, 0 , NULL, NULL);
|
2008-12-17 17:14:50 +01:00
|
|
|
if (szValue)
|
|
|
|
WideCharToMultiByte( CP_ACP, 0, rec->fields[iField].u.szwVal, -1,
|
|
|
|
szValue, *pcchValue, NULL, NULL);
|
2006-08-28 09:51:11 +02:00
|
|
|
if( szValue && *pcchValue && len>*pcchValue )
|
2005-01-06 21:42:25 +01:00
|
|
|
szValue[*pcchValue-1] = 0;
|
|
|
|
if( len )
|
|
|
|
len--;
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
2004-06-30 21:46:25 +02:00
|
|
|
case MSIFIELD_NULL:
|
2008-12-17 17:14:50 +01:00
|
|
|
if( szValue && *pcchValue > 0 )
|
2004-06-30 21:46:25 +02:00
|
|
|
szValue[0] = 0;
|
2004-08-24 22:56:08 +02:00
|
|
|
break;
|
2003-08-13 03:27:48 +02:00
|
|
|
default:
|
|
|
|
ret = ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-08-28 09:51:11 +02:00
|
|
|
if( szValue && *pcchValue <= len )
|
2003-08-13 03:27:48 +02:00
|
|
|
ret = ERROR_MORE_DATA;
|
|
|
|
*pcchValue = len;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordGetStringA(MSIHANDLE handle, UINT iField,
|
|
|
|
LPSTR szValue, LPDWORD pcchValue)
|
2004-06-30 20:18:27 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %p %p\n", handle, iField, szValue, pcchValue);
|
2004-06-30 20:18:27 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
2004-07-10 00:25:34 +02:00
|
|
|
return ERROR_INVALID_HANDLE;
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordGetStringA( rec, iField, szValue, pcchValue);
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
2004-06-30 20:18:27 +02:00
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
const WCHAR *MSI_RecordGetString( const MSIRECORD *rec, UINT iField )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
2004-06-30 20:18:27 +02:00
|
|
|
if( iField > rec->count )
|
|
|
|
return NULL;
|
|
|
|
|
2004-06-30 20:42:02 +02:00
|
|
|
if( rec->fields[iField].type != MSIFIELD_WSTR )
|
|
|
|
return NULL;
|
|
|
|
|
2004-06-30 20:18:27 +02:00
|
|
|
return rec->fields[iField].u.szwVal;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordGetStringW(MSIRECORD *rec, UINT iField,
|
|
|
|
LPWSTR szValue, LPDWORD pcchValue)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
UINT len=0, ret;
|
|
|
|
WCHAR buffer[16];
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szFormat[] = { '%','d',0 };
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %d %p %p\n", rec, iField, szValue, pcchValue);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( iField > rec->count )
|
2008-02-11 08:15:13 +01:00
|
|
|
{
|
|
|
|
if ( szValue && *pcchValue > 0 )
|
|
|
|
szValue[0] = 0;
|
|
|
|
|
|
|
|
*pcchValue = 0;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
switch( rec->fields[iField].type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
wsprintfW(buffer, szFormat, rec->fields[iField].u.iVal);
|
|
|
|
len = lstrlenW( buffer );
|
2006-11-21 07:21:27 +01:00
|
|
|
if (szValue)
|
|
|
|
lstrcpynW(szValue, buffer, *pcchValue);
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
case MSIFIELD_WSTR:
|
|
|
|
len = lstrlenW( rec->fields[iField].u.szwVal );
|
2006-11-21 07:21:27 +01:00
|
|
|
if (szValue)
|
|
|
|
lstrcpynW(szValue, rec->fields[iField].u.szwVal, *pcchValue);
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
2004-06-30 21:46:25 +02:00
|
|
|
case MSIFIELD_NULL:
|
2006-08-28 09:51:11 +02:00
|
|
|
if( szValue && *pcchValue > 0 )
|
2004-06-30 21:46:25 +02:00
|
|
|
szValue[0] = 0;
|
2003-08-13 03:27:48 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-08-28 09:51:11 +02:00
|
|
|
if( szValue && *pcchValue <= len )
|
2003-08-13 03:27:48 +02:00
|
|
|
ret = ERROR_MORE_DATA;
|
|
|
|
*pcchValue = len;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordGetStringW(MSIHANDLE handle, UINT iField,
|
|
|
|
LPWSTR szValue, LPDWORD pcchValue)
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT ret;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %p %p\n", handle, iField, szValue, pcchValue);
|
2004-07-10 00:25:34 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordGetStringW( rec, iField, szValue, pcchValue );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-05-27 11:26:13 +02:00
|
|
|
static UINT msi_get_stream_size( IStream *stm )
|
|
|
|
{
|
|
|
|
STATSTG stat;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
r = IStream_Stat( stm, &stat, STATFLAG_NONAME );
|
|
|
|
if( FAILED(r) )
|
|
|
|
return 0;
|
|
|
|
return stat.cbSize.QuadPart;
|
|
|
|
}
|
|
|
|
|
2009-01-10 15:20:03 +01:00
|
|
|
static UINT MSI_RecordDataSize(MSIRECORD *rec, UINT iField)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-01-06 21:42:25 +01:00
|
|
|
TRACE("%p %d\n", rec, iField);
|
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch( rec->fields[iField].type )
|
|
|
|
{
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
return sizeof (INT);
|
|
|
|
case MSIFIELD_WSTR:
|
|
|
|
return lstrlenW( rec->fields[iField].u.szwVal );
|
|
|
|
case MSIFIELD_NULL:
|
|
|
|
break;
|
2005-05-27 11:26:13 +02:00
|
|
|
case MSIFIELD_STREAM:
|
|
|
|
return msi_get_stream_size( rec->fields[iField].u.stream );
|
2005-01-06 21:42:25 +01:00
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordDataSize(MSIHANDLE handle, UINT iField)
|
2005-01-06 21:42:25 +01:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT ret;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d\n", handle, iField);
|
2005-01-06 21:42:25 +01:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return 0;
|
|
|
|
msiobj_lock( &rec->hdr );
|
|
|
|
ret = MSI_RecordDataSize( rec, iField);
|
|
|
|
msiobj_unlock( &rec->hdr );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-10 15:20:03 +01:00
|
|
|
static UINT MSI_RecordSetStringA( MSIRECORD *rec, UINT iField, LPCSTR szValue )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-06-30 20:18:27 +02:00
|
|
|
LPWSTR str;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %d %s\n", rec, iField, debugstr_a(szValue));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
MSI_FreeField( &rec->fields[iField] );
|
2005-01-31 12:30:59 +01:00
|
|
|
if( szValue && szValue[0] )
|
2005-01-26 21:39:54 +01:00
|
|
|
{
|
2005-03-25 17:38:26 +01:00
|
|
|
str = strdupAtoW( szValue );
|
2005-01-26 21:39:54 +01:00
|
|
|
rec->fields[iField].type = MSIFIELD_WSTR;
|
|
|
|
rec->fields[iField].u.szwVal = str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rec->fields[iField].type = MSIFIELD_NULL;
|
|
|
|
rec->fields[iField].u.szwVal = NULL;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordSetStringA( MSIHANDLE handle, UINT iField, LPCSTR szValue )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %s\n", handle, iField, debugstr_a(szValue));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordSetStringA( rec, iField, szValue );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordSetStringW( MSIRECORD *rec, UINT iField, LPCWSTR szValue )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
LPWSTR str;
|
|
|
|
|
|
|
|
TRACE("%p %d %s\n", rec, iField, debugstr_w(szValue));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
MSI_FreeField( &rec->fields[iField] );
|
2005-01-26 21:39:54 +01:00
|
|
|
|
2005-01-31 12:30:59 +01:00
|
|
|
if( szValue && szValue[0] )
|
2005-01-26 21:39:54 +01:00
|
|
|
{
|
2005-03-25 17:38:26 +01:00
|
|
|
str = strdupW( szValue );
|
2005-01-26 21:39:54 +01:00
|
|
|
rec->fields[iField].type = MSIFIELD_WSTR;
|
|
|
|
rec->fields[iField].u.szwVal = str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rec->fields[iField].type = MSIFIELD_NULL;
|
|
|
|
rec->fields[iField].u.szwVal = NULL;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordSetStringW( MSIHANDLE handle, UINT iField, LPCWSTR szValue )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT ret;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %s\n", handle, iField, debugstr_w(szValue));
|
2004-07-10 00:25:34 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordSetStringW( rec, iField, szValue );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-01-09 19:24:15 +01:00
|
|
|
/* read the data in a file into an IStream */
|
2005-05-31 11:30:28 +02:00
|
|
|
static UINT RECORD_StreamFromFile(LPCWSTR szFile, IStream **pstm)
|
2005-01-09 19:24:15 +01:00
|
|
|
{
|
|
|
|
DWORD sz, szHighWord = 0, read;
|
|
|
|
HANDLE handle;
|
|
|
|
HGLOBAL hGlob = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
ULARGE_INTEGER ulSize;
|
|
|
|
|
|
|
|
TRACE("reading %s\n", debugstr_w(szFile));
|
|
|
|
|
|
|
|
/* read the file into memory */
|
|
|
|
handle = CreateFileW(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if( handle == INVALID_HANDLE_VALUE )
|
|
|
|
return GetLastError();
|
|
|
|
sz = GetFileSize(handle, &szHighWord);
|
|
|
|
if( sz != INVALID_FILE_SIZE && szHighWord == 0 )
|
|
|
|
{
|
|
|
|
hGlob = GlobalAlloc(GMEM_FIXED, sz);
|
|
|
|
if( hGlob )
|
|
|
|
{
|
|
|
|
BOOL r = ReadFile(handle, hGlob, sz, &read, NULL);
|
|
|
|
if( !r )
|
|
|
|
{
|
|
|
|
GlobalFree(hGlob);
|
|
|
|
hGlob = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CloseHandle(handle);
|
|
|
|
if( !hGlob )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
/* make a stream out of it, and set the correct file size */
|
|
|
|
hr = CreateStreamOnHGlobal(hGlob, TRUE, pstm);
|
|
|
|
if( FAILED( hr ) )
|
|
|
|
{
|
|
|
|
GlobalFree(hGlob);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the correct size - CreateStreamOnHGlobal screws it up */
|
|
|
|
ulSize.QuadPart = sz;
|
|
|
|
IStream_SetSize(*pstm, ulSize);
|
|
|
|
|
2006-10-05 06:41:22 +02:00
|
|
|
TRACE("read %s, %d bytes into IStream %p\n", debugstr_w(szFile), sz, *pstm);
|
2005-01-09 19:24:15 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-24 18:51:58 +02:00
|
|
|
UINT MSI_RecordSetStream(MSIRECORD *rec, UINT iField, IStream *stream)
|
2007-04-21 13:56:20 +02:00
|
|
|
{
|
|
|
|
if ( (iField == 0) || (iField > rec->count) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
MSI_FreeField( &rec->fields[iField] );
|
|
|
|
rec->fields[iField].type = MSIFIELD_STREAM;
|
|
|
|
rec->fields[iField].u.stream = stream;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-05-26 22:31:45 +02:00
|
|
|
UINT MSI_RecordSetStreamFromFileW(MSIRECORD *rec, UINT iField, LPCWSTR szFilename)
|
2005-01-09 19:24:15 +01:00
|
|
|
{
|
|
|
|
IStream *stm = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
if( (iField == 0) || (iField > rec->count) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* no filename means we should seek back to the start of the stream */
|
|
|
|
if( !szFilename )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER ofs;
|
|
|
|
ULARGE_INTEGER cur;
|
|
|
|
|
|
|
|
if( rec->fields[iField].type != MSIFIELD_STREAM )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
stm = rec->fields[iField].u.stream;
|
|
|
|
if( !stm )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
ofs.QuadPart = 0;
|
|
|
|
r = IStream_Seek( stm, ofs, STREAM_SEEK_SET, &cur );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* read the file into a stream and save the stream in the record */
|
|
|
|
r = RECORD_StreamFromFile(szFilename, &stm);
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* if all's good, store it in the record */
|
2007-04-21 13:56:20 +02:00
|
|
|
MSI_RecordSetStream(rec, iField, stm);
|
2005-01-09 19:24:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordSetStreamA(MSIHANDLE hRecord, UINT iField, LPCSTR szFilename)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-01-09 19:24:15 +01:00
|
|
|
LPWSTR wstr = NULL;
|
2005-03-25 17:38:26 +01:00
|
|
|
UINT ret;
|
2005-01-09 19:24:15 +01:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %s\n", hRecord, iField, debugstr_a(szFilename));
|
2005-01-09 19:24:15 +01:00
|
|
|
|
|
|
|
if( szFilename )
|
|
|
|
{
|
2005-03-25 17:38:26 +01:00
|
|
|
wstr = strdupAtoW( szFilename );
|
|
|
|
if( !wstr )
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2005-01-09 19:24:15 +01:00
|
|
|
}
|
|
|
|
ret = MsiRecordSetStreamW(hRecord, iField, wstr);
|
2005-09-20 13:57:19 +02:00
|
|
|
msi_free(wstr);
|
2005-01-09 19:24:15 +01:00
|
|
|
|
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordSetStreamW(MSIHANDLE handle, UINT iField, LPCWSTR szFilename)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-01-09 19:24:15 +01:00
|
|
|
MSIRECORD *rec;
|
|
|
|
UINT ret;
|
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %s\n", handle, iField, debugstr_w(szFilename));
|
2005-01-09 19:24:15 +01:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
|
|
|
|
|
|
|
msiobj_lock( &rec->hdr );
|
2007-04-21 13:56:20 +02:00
|
|
|
ret = MSI_RecordSetStreamFromFileW( rec, iField, szFilename );
|
2005-01-09 19:24:15 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordReadStream(MSIRECORD *rec, UINT iField, char *buf, LPDWORD sz)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-06-29 05:41:28 +02:00
|
|
|
ULONG count;
|
|
|
|
HRESULT r;
|
|
|
|
IStream *stm;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %d %p %p\n", rec, iField, buf, sz);
|
2004-06-29 05:41:28 +02:00
|
|
|
|
2005-01-09 19:24:15 +01:00
|
|
|
if( !sz )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( iField > rec->count)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2004-06-29 05:41:28 +02:00
|
|
|
|
2009-03-02 11:34:32 +01:00
|
|
|
if ( rec->fields[iField].type == MSIFIELD_NULL )
|
|
|
|
{
|
|
|
|
*sz = 0;
|
|
|
|
return ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
2004-06-29 05:41:28 +02:00
|
|
|
if( rec->fields[iField].type != MSIFIELD_STREAM )
|
2005-01-09 19:24:15 +01:00
|
|
|
return ERROR_INVALID_DATATYPE;
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
stm = rec->fields[iField].u.stream;
|
|
|
|
if( !stm )
|
2005-01-09 19:24:15 +01:00
|
|
|
return ERROR_INVALID_PARAMETER;
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
/* if there's no buffer pointer, calculate the length to the end */
|
|
|
|
if( !buf )
|
|
|
|
{
|
|
|
|
LARGE_INTEGER ofs;
|
|
|
|
ULARGE_INTEGER end, cur;
|
|
|
|
|
|
|
|
ofs.QuadPart = cur.QuadPart = 0;
|
|
|
|
end.QuadPart = 0;
|
2011-07-07 09:22:20 +02:00
|
|
|
IStream_Seek( stm, ofs, STREAM_SEEK_SET, &cur );
|
2004-06-29 05:41:28 +02:00
|
|
|
IStream_Seek( stm, ofs, STREAM_SEEK_END, &end );
|
|
|
|
ofs.QuadPart = cur.QuadPart;
|
|
|
|
IStream_Seek( stm, ofs, STREAM_SEEK_SET, &cur );
|
|
|
|
*sz = end.QuadPart - cur.QuadPart;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the data */
|
|
|
|
count = 0;
|
|
|
|
r = IStream_Read( stm, buf, *sz, &count );
|
|
|
|
if( FAILED( r ) )
|
2004-12-06 17:18:22 +01:00
|
|
|
{
|
|
|
|
*sz = 0;
|
2004-06-29 05:41:28 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2004-12-06 17:18:22 +01:00
|
|
|
}
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
*sz = count;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT WINAPI MsiRecordReadStream(MSIHANDLE handle, UINT iField, char *buf, LPDWORD sz)
|
2004-06-29 05:41:28 +02:00
|
|
|
{
|
|
|
|
MSIRECORD *rec;
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT ret;
|
2004-06-29 05:41:28 +02:00
|
|
|
|
2009-01-04 14:14:15 +01:00
|
|
|
TRACE("%d %d %p %p\n", handle, iField, buf, sz);
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
rec = msihandle2msiinfo( handle, MSIHANDLETYPE_RECORD );
|
|
|
|
if( !rec )
|
|
|
|
return ERROR_INVALID_HANDLE;
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_lock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
ret = MSI_RecordReadStream( rec, iField, buf, sz );
|
2004-12-27 20:29:33 +01:00
|
|
|
msiobj_unlock( &rec->hdr );
|
2004-07-10 00:25:34 +02:00
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordSetIStream( MSIRECORD *rec, UINT iField, IStream *stm )
|
2004-07-10 00:25:34 +02:00
|
|
|
{
|
|
|
|
TRACE("%p %d %p\n", rec, iField, stm);
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
MSI_FreeField( &rec->fields[iField] );
|
|
|
|
|
|
|
|
rec->fields[iField].type = MSIFIELD_STREAM;
|
|
|
|
rec->fields[iField].u.stream = stm;
|
|
|
|
IStream_AddRef( stm );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2005-04-11 14:47:20 +02:00
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordGetIStream( MSIRECORD *rec, UINT iField, IStream **pstm)
|
2005-04-11 14:47:20 +02:00
|
|
|
{
|
|
|
|
TRACE("%p %d %p\n", rec, iField, pstm);
|
|
|
|
|
|
|
|
if( iField > rec->count )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
if( rec->fields[iField].type != MSIFIELD_STREAM )
|
|
|
|
return ERROR_INVALID_FIELD;
|
|
|
|
|
|
|
|
*pstm = rec->fields[iField].u.stream;
|
|
|
|
IStream_AddRef( *pstm );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-06-23 18:43:38 +02:00
|
|
|
|
|
|
|
static UINT msi_dump_stream_to_file( IStream *stm, LPCWSTR name )
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER size;
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
IStream *out;
|
|
|
|
DWORD stgm;
|
|
|
|
HRESULT r;
|
|
|
|
|
|
|
|
stgm = STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_FAILIFTHERE;
|
|
|
|
r = SHCreateStreamOnFileW( name, stgm, &out );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
r = IStream_Seek( stm, pos, STREAM_SEEK_END, &size );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
r = IStream_Seek( stm, pos, STREAM_SEEK_SET, NULL );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = IStream_CopyTo( stm, out, size, NULL, NULL );
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release( out );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-08-09 10:41:41 +02:00
|
|
|
UINT MSI_RecordStreamToFile( MSIRECORD *rec, UINT iField, LPCWSTR name )
|
2005-06-23 18:43:38 +02:00
|
|
|
{
|
|
|
|
IStream *stm = NULL;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p %u %s\n", rec, iField, debugstr_w(name));
|
|
|
|
|
|
|
|
msiobj_lock( &rec->hdr );
|
|
|
|
|
|
|
|
r = MSI_RecordGetIStream( rec, iField, &stm );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
r = msi_dump_stream_to_file( stm, name );
|
|
|
|
IStream_Release( stm );
|
|
|
|
}
|
|
|
|
|
|
|
|
msiobj_unlock( &rec->hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2008-10-09 05:42:33 +02:00
|
|
|
|
|
|
|
MSIRECORD *MSI_CloneRecord(MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
MSIRECORD *clone;
|
|
|
|
UINT r, i, count;
|
|
|
|
|
|
|
|
count = MSI_RecordGetFieldCount(rec);
|
|
|
|
clone = MSI_CreateRecord(count);
|
|
|
|
if (!clone)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i <= count; i++)
|
|
|
|
{
|
|
|
|
if (rec->fields[i].type == MSIFIELD_STREAM)
|
|
|
|
{
|
|
|
|
if (FAILED(IStream_Clone(rec->fields[i].u.stream,
|
|
|
|
&clone->fields[i].u.stream)))
|
|
|
|
{
|
|
|
|
msiobj_release(&clone->hdr);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-05-24 18:51:53 +02:00
|
|
|
clone->fields[i].type = MSIFIELD_STREAM;
|
2008-10-09 05:42:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = MSI_RecordCopyField(rec, i, clone, i);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
msiobj_release(&clone->hdr);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL MSI_RecordsAreEqual(MSIRECORD *a, MSIRECORD *b)
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
if (a->count != b->count)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i <= a->count; i++)
|
|
|
|
{
|
|
|
|
if (a->fields[i].type != b->fields[i].type)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch (a->fields[i].type)
|
|
|
|
{
|
|
|
|
case MSIFIELD_NULL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIFIELD_INT:
|
|
|
|
if (a->fields[i].u.iVal != b->fields[i].u.iVal)
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIFIELD_WSTR:
|
2010-10-19 11:27:44 +02:00
|
|
|
if (strcmpW(a->fields[i].u.szwVal, b->fields[i].u.szwVal))
|
2008-10-09 05:42:33 +02:00
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIFIELD_STREAM:
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2011-05-06 14:39:17 +02:00
|
|
|
|
|
|
|
WCHAR *msi_dup_record_field( MSIRECORD *rec, INT field )
|
|
|
|
{
|
|
|
|
DWORD sz = 0;
|
|
|
|
WCHAR *str;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
if (MSI_RecordIsNull( rec, field )) return NULL;
|
|
|
|
|
|
|
|
r = MSI_RecordGetStringW( rec, field, NULL, &sz );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sz++;
|
|
|
|
str = msi_alloc( sz * sizeof(WCHAR) );
|
|
|
|
if (!str) return NULL;
|
|
|
|
str[0] = 0;
|
|
|
|
r = MSI_RecordGetStringW( rec, field, str, &sz );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
ERR("failed to get string!\n");
|
|
|
|
msi_free( str );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return str;
|
|
|
|
}
|