2003-08-13 03:27:48 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2005-09-22 12:34:07 +02:00
|
|
|
* Copyright 2002-2005 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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
2004-03-19 02:16:36 +01:00
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "msipriv.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
|
|
|
|
#include "query.h"
|
|
|
|
|
2005-11-02 15:24:21 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
typedef struct tagMSICOLUMNINFO
|
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
LPCWSTR tablename;
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT number;
|
2005-09-22 12:34:07 +02:00
|
|
|
LPCWSTR colname;
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT type;
|
|
|
|
UINT offset;
|
|
|
|
} MSICOLUMNINFO;
|
|
|
|
|
|
|
|
struct tagMSITABLE
|
|
|
|
{
|
2004-03-18 05:04:08 +01:00
|
|
|
USHORT **data;
|
|
|
|
UINT row_count;
|
2005-09-14 12:07:26 +02:00
|
|
|
struct list entry;
|
2003-08-13 03:27:48 +02:00
|
|
|
WCHAR name[1];
|
2004-03-18 05:04:08 +01:00
|
|
|
};
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
typedef struct tagMSITRANSFORM {
|
|
|
|
struct list entry;
|
|
|
|
IStorage *stg;
|
|
|
|
} MSITRANSFORM;
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#define MAX_STREAM_NAME 0x1f
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT table_get_column_info( MSIDATABASE *db, LPCWSTR name,
|
|
|
|
MSICOLUMNINFO **pcols, UINT *pcount );
|
|
|
|
static UINT get_tablecolumns( MSIDATABASE *db,
|
|
|
|
LPCWSTR szTableName, MSICOLUMNINFO *colinfo, UINT *sz);
|
2005-09-26 15:25:48 +02:00
|
|
|
static void msi_free_colinfo( MSICOLUMNINFO *colinfo, UINT count );
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static inline UINT bytes_per_column( const MSICOLUMNINFO *col )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
|
|
|
if( col->type & MSITYPE_STRING )
|
|
|
|
return 2;
|
|
|
|
if( (col->type & 0xff) > 4 )
|
|
|
|
ERR("Invalid column size!\n");
|
|
|
|
return col->type & 0xff;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
static int utf2mime(int x)
|
|
|
|
{
|
|
|
|
if( (x>='0') && (x<='9') )
|
|
|
|
return x-'0';
|
|
|
|
if( (x>='A') && (x<='Z') )
|
|
|
|
return x-'A'+10;
|
|
|
|
if( (x>='a') && (x<='z') )
|
|
|
|
return x-'a'+10+26;
|
|
|
|
if( x=='.' )
|
|
|
|
return 10+26+26;
|
|
|
|
if( x=='_' )
|
|
|
|
return 10+26+26+1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-07-06 21:00:46 +02:00
|
|
|
static LPWSTR encode_streamname(BOOL bTable, LPCWSTR in)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
DWORD count = MAX_STREAM_NAME;
|
|
|
|
DWORD ch, next;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR out, p;
|
|
|
|
|
|
|
|
if( !bTable )
|
2005-05-11 14:58:22 +02:00
|
|
|
count = lstrlenW( in )+2;
|
2005-09-20 13:59:14 +02:00
|
|
|
out = msi_alloc( count*sizeof(WCHAR) );
|
2004-07-06 21:00:46 +02:00
|
|
|
p = out;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( bTable )
|
|
|
|
{
|
2004-07-06 21:00:46 +02:00
|
|
|
*p++ = 0x4840;
|
2003-08-13 03:27:48 +02:00
|
|
|
count --;
|
|
|
|
}
|
|
|
|
while( count -- )
|
|
|
|
{
|
|
|
|
ch = *in++;
|
|
|
|
if( !ch )
|
|
|
|
{
|
2004-07-06 21:00:46 +02:00
|
|
|
*p = ch;
|
|
|
|
return out;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
if( ( ch < 0x80 ) && ( utf2mime(ch) >= 0 ) )
|
|
|
|
{
|
|
|
|
ch = utf2mime(ch) + 0x4800;
|
|
|
|
next = *in;
|
|
|
|
if( next && (next<0x80) )
|
|
|
|
{
|
|
|
|
next = utf2mime(next);
|
|
|
|
if( next >= 0 )
|
|
|
|
{
|
|
|
|
next += 0x3ffffc0;
|
|
|
|
ch += (next<<6);
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-07-06 21:00:46 +02:00
|
|
|
*p++ = ch;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2004-07-06 21:00:46 +02:00
|
|
|
ERR("Failed to encode stream name (%s)\n",debugstr_w(in));
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( out );
|
2004-07-06 21:00:46 +02:00
|
|
|
return NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mime2utf(int x)
|
|
|
|
{
|
|
|
|
if( x<10 )
|
|
|
|
return x + '0';
|
|
|
|
if( x<(10+26))
|
|
|
|
return x - 10 + 'A';
|
|
|
|
if( x<(10+26+26))
|
|
|
|
return x - 10 - 26 + 'a';
|
|
|
|
if( x == (10+26+26) )
|
|
|
|
return '.';
|
|
|
|
return '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL decode_streamname(LPWSTR in, LPWSTR out)
|
|
|
|
{
|
|
|
|
WCHAR ch;
|
|
|
|
DWORD count = 0;
|
|
|
|
|
|
|
|
while ( (ch = *in++) )
|
|
|
|
{
|
|
|
|
if( (ch >= 0x3800 ) && (ch < 0x4840 ) )
|
|
|
|
{
|
|
|
|
if( ch >= 0x4800 )
|
|
|
|
ch = mime2utf(ch-0x4800);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ch -= 0x3800;
|
|
|
|
*out++ = mime2utf(ch&0x3f);
|
|
|
|
count++;
|
|
|
|
ch = mime2utf((ch>>6)&0x3f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*out++ = ch;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
*out = 0;
|
|
|
|
return count;
|
|
|
|
}
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
void enum_stream_names( IStorage *stg )
|
|
|
|
{
|
|
|
|
IEnumSTATSTG *stgenum = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
STATSTG stat;
|
|
|
|
ULONG n, count;
|
|
|
|
WCHAR name[0x40];
|
|
|
|
|
|
|
|
r = IStorage_EnumElements( stg, 0, NULL, 0, &stgenum );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
r = IEnumSTATSTG_Next( stgenum, 1, &stat, &count );
|
|
|
|
if( FAILED( r ) || !count )
|
|
|
|
break;
|
|
|
|
decode_streamname( stat.pwcsName, name );
|
2005-01-20 20:57:22 +01:00
|
|
|
TRACE("stream %2ld -> %s %s\n", n,
|
|
|
|
debugstr_w(stat.pwcsName), debugstr_w(name) );
|
2004-06-29 05:41:28 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumSTATSTG_Release( stgenum );
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT read_stream_data( IStorage *stg, LPCWSTR stname,
|
2003-10-28 22:49:06 +01:00
|
|
|
USHORT **pdata, UINT *psz )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
VOID *data;
|
|
|
|
ULONG sz, count;
|
2003-10-28 22:49:06 +01:00
|
|
|
IStream *stm = NULL;
|
|
|
|
STATSTG stat;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR encname;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2004-07-06 21:00:46 +02:00
|
|
|
encname = encode_streamname(TRUE, stname);
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
TRACE("%s -> %s\n",debugstr_w(stname),debugstr_w(encname));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
r = IStorage_OpenStream(stg, encname, NULL,
|
2003-10-28 22:49:06 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stm);
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( encname );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2003-10-28 22:49:06 +01:00
|
|
|
WARN("open stream failed r = %08lx - empty table?\n",r);
|
|
|
|
return ret;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Stat(stm, &stat, STATFLAG_NONAME );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("open stream failed r = %08lx!\n",r);
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( stat.cbSize.QuadPart >> 32 )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Too big!\n");
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = stat.cbSize.QuadPart;
|
2005-09-20 13:59:14 +02:00
|
|
|
data = msi_alloc( sz );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !data )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("couldn't allocate memory r=%08lx!\n",r);
|
2003-10-28 22:49:06 +01:00
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Read(stm, data, sz, &count );
|
2003-10-28 22:49:06 +01:00
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( data );
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("read stream failed r = %08lx!\n",r);
|
2003-08-13 03:27:48 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2003-10-28 22:49:06 +01:00
|
|
|
*pdata = data;
|
|
|
|
*psz = sz;
|
|
|
|
ret = ERROR_SUCCESS;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
end:
|
2003-10-28 22:49:06 +01:00
|
|
|
IStream_Release( stm );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-06-29 05:41:28 +02:00
|
|
|
UINT db_get_raw_stream( MSIDATABASE *db, LPCWSTR stname, IStream **stm )
|
|
|
|
{
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR encname;
|
2004-06-29 05:41:28 +02:00
|
|
|
HRESULT r;
|
|
|
|
|
2004-07-06 21:00:46 +02:00
|
|
|
encname = encode_streamname(FALSE, stname);
|
2004-06-29 05:41:28 +02:00
|
|
|
|
|
|
|
TRACE("%s -> %s\n",debugstr_w(stname),debugstr_w(encname));
|
|
|
|
|
|
|
|
r = IStorage_OpenStream(db->storage, encname, NULL,
|
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm);
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2005-10-27 14:25:04 +02:00
|
|
|
MSITRANSFORM *transform;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( transform, &db->transforms, MSITRANSFORM, entry )
|
|
|
|
{
|
|
|
|
TRACE("looking for %s in transform storage\n", debugstr_w(stname) );
|
|
|
|
r = IStorage_OpenStream( transform->stg, encname, NULL,
|
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm );
|
|
|
|
if (SUCCEEDED(r))
|
|
|
|
break;
|
|
|
|
}
|
2004-06-29 05:41:28 +02:00
|
|
|
}
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
msi_free( encname );
|
|
|
|
|
|
|
|
return SUCCEEDED(r) ? ERROR_SUCCESS : ERROR_FUNCTION_FAILED;
|
2004-06-29 05:41:28 +02:00
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
UINT read_raw_stream_data( MSIDATABASE *db, LPCWSTR stname,
|
2004-06-29 05:41:28 +02:00
|
|
|
USHORT **pdata, UINT *psz )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
VOID *data;
|
|
|
|
ULONG sz, count;
|
|
|
|
IStream *stm = NULL;
|
|
|
|
STATSTG stat;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
r = db_get_raw_stream( db, stname, &stm );
|
2004-06-29 05:41:28 +02:00
|
|
|
if( r != ERROR_SUCCESS)
|
2004-07-10 00:25:34 +02:00
|
|
|
return ret;
|
2004-06-29 05:41:28 +02:00
|
|
|
r = IStream_Stat(stm, &stat, STATFLAG_NONAME );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("open stream failed r = %08lx!\n",r);
|
2004-06-29 05:41:28 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( stat.cbSize.QuadPart >> 32 )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Too big!\n");
|
2004-06-29 05:41:28 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = stat.cbSize.QuadPart;
|
2005-09-20 13:59:14 +02:00
|
|
|
data = msi_alloc( sz );
|
2004-06-29 05:41:28 +02:00
|
|
|
if( !data )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("couldn't allocate memory r=%08lx!\n",r);
|
2004-06-29 05:41:28 +02:00
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Read(stm, data, sz, &count );
|
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( data );
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("read stream failed r = %08lx!\n",r);
|
2004-06-29 05:41:28 +02:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pdata = data;
|
|
|
|
*psz = sz;
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT write_stream_data( IStorage *stg, LPCWSTR stname,
|
|
|
|
LPVOID data, UINT sz )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
ULONG count;
|
|
|
|
IStream *stm = NULL;
|
|
|
|
ULARGE_INTEGER size;
|
|
|
|
LARGE_INTEGER pos;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR encname;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2004-07-06 21:00:46 +02:00
|
|
|
encname = encode_streamname(TRUE, stname );
|
2004-03-19 02:16:36 +01:00
|
|
|
r = IStorage_OpenStream( stg, encname, NULL,
|
2004-03-18 05:04:08 +01:00
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, &stm);
|
2004-03-19 02:16:36 +01:00
|
|
|
if( FAILED(r) )
|
|
|
|
{
|
|
|
|
r = IStorage_CreateStream( stg, encname,
|
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
|
|
|
|
}
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( encname );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("open stream failed r = %08lx\n",r);
|
2004-03-18 05:04:08 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size.QuadPart = sz;
|
|
|
|
r = IStream_SetSize( stm, size );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( FAILED( r ) )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to SetSize\n");
|
2004-03-18 05:04:08 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
r = IStream_Seek( stm, pos, STREAM_SEEK_SET, NULL );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( FAILED( r ) )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to Seek\n");
|
2004-03-18 05:04:08 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Write(stm, data, sz, &count );
|
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to Write\n");
|
2004-03-18 05:04:08 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-09-17 16:29:38 +02:00
|
|
|
static void free_table( MSITABLE *table )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for( i=0; i<table->row_count; i++ )
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( table->data[i] );
|
|
|
|
msi_free( table->data );
|
|
|
|
msi_free( table );
|
2005-09-17 16:29:38 +02:00
|
|
|
}
|
|
|
|
|
2005-09-26 15:25:48 +02:00
|
|
|
static UINT msi_table_get_row_size( const MSICOLUMNINFO *cols, UINT count )
|
|
|
|
{
|
|
|
|
const MSICOLUMNINFO *last_col = &cols[count-1];
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
return last_col->offset + bytes_per_column( last_col );
|
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
/* add this table to the list of cached tables in the database */
|
|
|
|
static MSITABLE *read_table_from_storage( IStorage *stg, LPCWSTR name,
|
|
|
|
const MSICOLUMNINFO *cols, UINT num_cols )
|
2003-10-28 22:49:06 +01:00
|
|
|
{
|
|
|
|
MSITABLE *t;
|
2004-03-18 05:04:08 +01:00
|
|
|
USHORT *rawdata = NULL;
|
2005-09-22 12:34:07 +02:00
|
|
|
UINT rawsize = 0, i, j, row_size = 0;
|
2003-10-28 22:49:06 +01:00
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
TRACE("%s\n",debugstr_w(name));
|
2003-10-28 22:49:06 +01:00
|
|
|
|
2005-02-10 20:19:35 +01:00
|
|
|
/* nonexistent tables should be interpreted as empty tables */
|
2005-09-20 13:59:14 +02:00
|
|
|
t = msi_alloc( sizeof (MSITABLE) + lstrlenW(name)*sizeof (WCHAR) );
|
2003-10-28 22:49:06 +01:00
|
|
|
if( !t )
|
2005-09-21 12:20:20 +02:00
|
|
|
return t;
|
2003-10-28 22:49:06 +01:00
|
|
|
|
2005-09-26 15:25:48 +02:00
|
|
|
row_size = msi_table_get_row_size( cols, num_cols );
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
t->row_count = 0;
|
2003-10-28 22:49:06 +01:00
|
|
|
t->data = NULL;
|
|
|
|
lstrcpyW( t->name, name );
|
|
|
|
|
|
|
|
/* if we can't read the table, just assume that it's empty */
|
2005-09-22 12:34:07 +02:00
|
|
|
read_stream_data( stg, name, &rawdata, &rawsize );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( !rawdata )
|
2005-09-21 12:20:20 +02:00
|
|
|
return t;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
TRACE("Read %d bytes\n", rawsize );
|
|
|
|
|
|
|
|
if( rawsize % row_size )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Table size is invalid %d/%d\n", rawsize, row_size );
|
2005-09-21 12:20:20 +02:00
|
|
|
goto err;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
t->row_count = rawsize / row_size;
|
2005-09-20 13:59:14 +02:00
|
|
|
t->data = msi_alloc_zero( t->row_count * sizeof (USHORT*) );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( !t->data )
|
2005-09-17 16:29:38 +02:00
|
|
|
goto err;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
/* transpose all the data */
|
|
|
|
TRACE("Transposing data from %d columns\n", t->row_count );
|
|
|
|
for( i=0; i<t->row_count; i++ )
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
t->data[i] = msi_alloc( row_size );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( !t->data[i] )
|
2005-09-17 16:29:38 +02:00
|
|
|
goto err;
|
2005-09-21 12:20:20 +02:00
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
for( j=0; j<num_cols; j++ )
|
|
|
|
{
|
|
|
|
UINT ofs = cols[j].offset/2;
|
|
|
|
UINT n = bytes_per_column( &cols[j] );
|
|
|
|
|
|
|
|
switch( n )
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
t->data[i][ofs] = rawdata[ofs*t->row_count + i ];
|
|
|
|
break;
|
|
|
|
case 4:
|
2004-12-06 17:17:45 +01:00
|
|
|
t->data[i][ofs] = rawdata[ofs*t->row_count + i*2 ];
|
|
|
|
t->data[i][ofs+1] = rawdata[ofs*t->row_count + i*2 + 1];
|
2004-03-18 05:04:08 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("oops - unknown column width %d\n", n);
|
2005-09-17 16:29:38 +02:00
|
|
|
goto err;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( rawdata );
|
2005-09-21 12:20:20 +02:00
|
|
|
return t;
|
2005-09-17 16:29:38 +02:00
|
|
|
err:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( rawdata );
|
2005-09-17 16:29:38 +02:00
|
|
|
free_table( t );
|
2005-09-21 12:20:20 +02:00
|
|
|
return NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void free_cached_tables( MSIDATABASE *db )
|
|
|
|
{
|
2005-09-14 12:07:26 +02:00
|
|
|
while( !list_empty( &db->tables ) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-14 12:07:26 +02:00
|
|
|
MSITABLE *t = LIST_ENTRY( list_head( &db->tables ), MSITABLE, entry );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
list_remove( &t->entry );
|
2005-09-21 12:20:20 +02:00
|
|
|
free_table( t );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static MSITABLE *find_cached_table( MSIDATABASE *db, LPCWSTR name )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLE *t;
|
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( t, &db->tables, MSITABLE, entry )
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !lstrcmpW( name, t->name ) )
|
2005-09-21 12:20:20 +02:00
|
|
|
return t;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-21 12:20:20 +02:00
|
|
|
return NULL;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT table_get_column_info( MSIDATABASE *db, LPCWSTR name, MSICOLUMNINFO **pcols, UINT *pcount )
|
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
UINT r, column_count = 0;
|
2004-03-18 05:04:08 +01:00
|
|
|
MSICOLUMNINFO *columns;
|
|
|
|
|
|
|
|
/* get the number of columns in this table */
|
|
|
|
column_count = 0;
|
|
|
|
r = get_tablecolumns( db, name, NULL, &column_count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* if there's no columns, there's no table */
|
|
|
|
if( column_count == 0 )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
TRACE("Table %s found\n", debugstr_w(name) );
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
columns = msi_alloc( column_count*sizeof (MSICOLUMNINFO) );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( !columns )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = get_tablecolumns( db, name, columns, &column_count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( columns );
|
2004-03-18 05:04:08 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcols = columns;
|
|
|
|
*pcount = column_count;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static MSITABLE *get_table( MSIDATABASE *db, LPCWSTR name,
|
|
|
|
const MSICOLUMNINFO *cols, UINT num_cols )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-21 12:20:20 +02:00
|
|
|
MSITABLE *table;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
/* first, see if the table is cached */
|
2005-09-21 12:20:20 +02:00
|
|
|
table = find_cached_table( db, name );
|
|
|
|
if( table )
|
|
|
|
return table;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
table = read_table_from_storage( db->storage, name, cols, num_cols );
|
2005-09-21 12:20:20 +02:00
|
|
|
if( table )
|
|
|
|
list_add_head( &db->tables, &table->entry );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-21 12:20:20 +02:00
|
|
|
return table;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:28 +02:00
|
|
|
static UINT save_table( MSIDATABASE *db, MSITABLE *t )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
USHORT *rawdata = NULL, *p;
|
|
|
|
UINT rawsize, r, i, j, row_size, num_cols = 0;
|
2005-09-26 15:25:48 +02:00
|
|
|
MSICOLUMNINFO *cols = NULL;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
TRACE("Saving %s\n", debugstr_w( t->name ) );
|
|
|
|
|
|
|
|
r = table_get_column_info( db, t->name, &cols, &num_cols );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2005-09-26 15:25:48 +02:00
|
|
|
row_size = msi_table_get_row_size( cols, num_cols );
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
rawsize = t->row_count * row_size;
|
2005-09-20 13:59:14 +02:00
|
|
|
rawdata = msi_alloc_zero( rawsize );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( !rawdata )
|
2005-09-26 15:25:48 +02:00
|
|
|
{
|
|
|
|
r = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
goto err;
|
|
|
|
}
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
p = rawdata;
|
|
|
|
for( i=0; i<num_cols; i++ )
|
|
|
|
{
|
|
|
|
for( j=0; j<t->row_count; j++ )
|
|
|
|
{
|
|
|
|
UINT offset = cols[i].offset;
|
|
|
|
|
|
|
|
*p++ = t->data[j][offset/2];
|
|
|
|
if( 4 == bytes_per_column( &cols[i] ) )
|
|
|
|
*p++ = t->data[j][offset/2+1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("writing %d bytes\n", rawsize);
|
|
|
|
r = write_stream_data( db->storage, t->name, rawdata, rawsize );
|
|
|
|
|
2005-09-26 15:25:48 +02:00
|
|
|
err:
|
|
|
|
msi_free_colinfo( cols, num_cols );
|
|
|
|
msi_free( cols );
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( rawdata );
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT init_string_table( IStorage *stg )
|
|
|
|
{
|
|
|
|
HRESULT r;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szStringData[] = {
|
2004-03-19 02:16:36 +01:00
|
|
|
'_','S','t','r','i','n','g','D','a','t','a',0 };
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szStringPool[] = {
|
2004-03-19 02:16:36 +01:00
|
|
|
'_','S','t','r','i','n','g','P','o','o','l',0 };
|
|
|
|
USHORT zero[2] = { 0, 0 };
|
|
|
|
ULONG count = 0;
|
|
|
|
IStream *stm = NULL;
|
2004-07-06 21:00:46 +02:00
|
|
|
LPWSTR encname;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2004-07-06 21:00:46 +02:00
|
|
|
encname = encode_streamname(TRUE, szStringPool );
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2004-03-19 20:14:12 +01:00
|
|
|
/* create the StringPool stream... add the zero string to it*/
|
2004-03-19 02:16:36 +01:00
|
|
|
r = IStorage_CreateStream( stg, encname,
|
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( encname );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( r )
|
|
|
|
{
|
|
|
|
TRACE("Failed\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Write(stm, zero, sizeof zero, &count );
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
if( FAILED( r ) || ( count != sizeof zero ) )
|
|
|
|
{
|
|
|
|
TRACE("Failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2004-03-19 20:14:12 +01:00
|
|
|
/* create the StringData stream... make it zero length */
|
2004-07-06 21:00:46 +02:00
|
|
|
encname = encode_streamname(TRUE, szStringData );
|
2004-03-19 02:16:36 +01:00
|
|
|
r = IStorage_CreateStream( stg, encname,
|
|
|
|
STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm);
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( encname );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( r )
|
|
|
|
{
|
|
|
|
TRACE("Failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
return r;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-09-16 21:01:40 +02:00
|
|
|
string_table *load_string_table( IStorage *stg )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-16 21:01:40 +02:00
|
|
|
string_table *st = NULL;
|
2004-03-18 05:04:08 +01:00
|
|
|
CHAR *data;
|
|
|
|
USHORT *pool;
|
2005-09-16 21:01:40 +02:00
|
|
|
UINT r, datasize = 0, poolsize = 0, codepage;
|
2004-03-19 02:16:36 +01:00
|
|
|
DWORD i, count, offset, len, n;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szStringData[] = {
|
2003-08-13 03:27:48 +02:00
|
|
|
'_','S','t','r','i','n','g','D','a','t','a',0 };
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szStringPool[] = {
|
2003-08-13 03:27:48 +02:00
|
|
|
'_','S','t','r','i','n','g','P','o','o','l',0 };
|
|
|
|
|
2005-09-16 21:01:40 +02:00
|
|
|
r = read_stream_data( stg, szStringPool, &pool, &poolsize );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS)
|
|
|
|
goto end;
|
2005-09-16 21:01:40 +02:00
|
|
|
r = read_stream_data( stg, szStringData, (USHORT**)&data, &datasize );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS)
|
|
|
|
goto end;
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
count = poolsize/4;
|
2004-06-30 20:24:33 +02:00
|
|
|
if( poolsize > 4 )
|
|
|
|
codepage = pool[0] | ( pool[1] << 16 );
|
|
|
|
else
|
|
|
|
codepage = CP_ACP;
|
2005-09-16 21:01:40 +02:00
|
|
|
st = msi_init_stringtable( count, codepage );
|
2004-03-17 21:49:59 +01:00
|
|
|
|
|
|
|
offset = 0;
|
2005-08-08 13:01:56 +02:00
|
|
|
n = 1;
|
2004-03-19 02:16:36 +01:00
|
|
|
for( i=1; i<count; i++ )
|
2004-03-17 21:49:59 +01:00
|
|
|
{
|
2004-03-18 05:04:08 +01:00
|
|
|
len = pool[i*2];
|
2005-08-08 13:01:56 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a string is over 64k, the previous string entry is made null
|
|
|
|
* and its the high word of the length is inserted in the null string's
|
|
|
|
* reference count field.
|
|
|
|
*/
|
|
|
|
if( pool[i*2-2] == 0 )
|
|
|
|
len += pool[i*2-1] * 0x10000;
|
|
|
|
|
|
|
|
if( (offset + len) > datasize )
|
|
|
|
{
|
|
|
|
ERR("string table corrupt?\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't add the high word of a string's length as a string */
|
|
|
|
if ( len || !pool[i*2+1] )
|
|
|
|
{
|
2005-09-16 21:01:40 +02:00
|
|
|
r = msi_addstring( st, n, data+offset, len, pool[i*2+1] );
|
2005-08-08 13:01:56 +02:00
|
|
|
if( r != n )
|
|
|
|
ERR("Failed to add string %ld\n", n );
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2004-03-17 21:49:59 +01:00
|
|
|
offset += len;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-08-08 13:01:56 +02:00
|
|
|
if ( datasize != offset )
|
|
|
|
ERR("string table load failed! (%08x != %08lx)\n", datasize, offset );
|
|
|
|
|
2004-03-17 21:49:59 +01:00
|
|
|
TRACE("Loaded %ld strings\n", count);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
end:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( pool );
|
|
|
|
msi_free( data );
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2005-09-16 21:01:40 +02:00
|
|
|
return st;
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
2005-05-31 11:30:28 +02:00
|
|
|
static UINT save_string_table( MSIDATABASE *db )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2004-06-30 20:24:33 +02:00
|
|
|
UINT i, count, datasize, poolsize, sz, used, r, codepage;
|
2004-03-18 05:04:08 +01:00
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szStringData[] = {
|
2004-03-18 05:04:08 +01:00
|
|
|
'_','S','t','r','i','n','g','D','a','t','a',0 };
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szStringPool[] = {
|
2004-03-18 05:04:08 +01:00
|
|
|
'_','S','t','r','i','n','g','P','o','o','l',0 };
|
|
|
|
CHAR *data = NULL;
|
|
|
|
USHORT *pool = NULL;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("\n");
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
/* construct the new table in memory first */
|
2004-06-30 20:24:33 +02:00
|
|
|
datasize = msi_string_totalsize( db->strings, &count );
|
2004-03-18 05:04:08 +01:00
|
|
|
poolsize = count*2*sizeof(USHORT);
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
pool = msi_alloc( poolsize );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( ! pool )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to alloc pool %d bytes\n", poolsize );
|
2004-03-18 05:04:08 +01:00
|
|
|
goto err;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2005-09-20 13:59:14 +02:00
|
|
|
data = msi_alloc( datasize );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( ! data )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Failed to alloc data %d bytes\n", poolsize );
|
2004-03-18 05:04:08 +01:00
|
|
|
goto err;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
used = 0;
|
2004-06-30 20:24:33 +02:00
|
|
|
codepage = msi_string_get_codepage( db->strings );
|
|
|
|
pool[0]=codepage&0xffff;
|
|
|
|
pool[1]=(codepage>>16);
|
2004-03-19 20:14:12 +01:00
|
|
|
for( i=1; i<count; i++ )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
sz = datasize - used;
|
|
|
|
r = msi_id2stringA( db->strings, i, data+used, &sz );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( r != ERROR_SUCCESS )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2004-03-19 20:14:12 +01:00
|
|
|
ERR("failed to fetch string\n");
|
2004-03-19 02:16:36 +01:00
|
|
|
sz = 0;
|
|
|
|
}
|
2004-06-30 20:24:33 +02:00
|
|
|
if( sz && (sz < (datasize - used ) ) )
|
2004-03-19 02:16:36 +01:00
|
|
|
sz--;
|
2005-09-16 21:01:40 +02:00
|
|
|
TRACE("adding %u bytes %s\n", sz, debugstr_a(data+used) );
|
2004-03-18 05:04:08 +01:00
|
|
|
pool[ i*2 ] = sz;
|
|
|
|
pool[ i*2 + 1 ] = msi_id_refcount( db->strings, i );
|
2004-03-19 02:16:36 +01:00
|
|
|
used += sz;
|
|
|
|
if( used > datasize )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
ERR("oops overran %d >= %d\n", used, datasize);
|
2004-03-18 05:04:08 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
if( used != datasize )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
ERR("oops used %d != datasize %d\n", used, datasize);
|
2004-03-18 05:04:08 +01:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the streams */
|
|
|
|
r = write_stream_data( db->storage, szStringData, data, datasize );
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("Wrote StringData r=%08x\n", r);
|
2004-03-18 05:04:08 +01:00
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
r = write_stream_data( db->storage, szStringPool, pool, poolsize );
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("Wrote StringPool r=%08x\n", r);
|
2004-03-18 05:04:08 +01:00
|
|
|
if( r )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
err:
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( data );
|
|
|
|
msi_free( pool );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* information for default tables */
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
|
|
|
|
static const WCHAR szTable[] = { 'T','a','b','l','e',0 };
|
|
|
|
static const WCHAR szName[] = { 'N','a','m','e',0 };
|
|
|
|
static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
|
|
|
|
static const WCHAR szColumn[] = { 'C','o','l','u','m','n',0 };
|
|
|
|
static const WCHAR szNumber[] = { 'N','u','m','b','e','r',0 };
|
|
|
|
static const WCHAR szType[] = { 'T','y','p','e',0 };
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static const MSICOLUMNINFO _Columns_cols[4] = {
|
2005-09-28 13:59:40 +02:00
|
|
|
{ szColumns, 1, szTable, MSITYPE_VALID | MSITYPE_STRING | 64, 0 },
|
2005-09-22 12:34:07 +02:00
|
|
|
{ szColumns, 2, szNumber, MSITYPE_VALID | 2, 2 },
|
2005-09-28 13:59:40 +02:00
|
|
|
{ szColumns, 3, szName, MSITYPE_VALID | MSITYPE_STRING | 64, 4 },
|
2005-09-22 12:34:07 +02:00
|
|
|
{ szColumns, 4, szType, MSITYPE_VALID | 2, 6 },
|
|
|
|
};
|
|
|
|
static const MSICOLUMNINFO _Tables_cols[1] = {
|
2005-09-28 13:59:40 +02:00
|
|
|
{ szTables, 1, szName, MSITYPE_VALID | MSITYPE_STRING | 64, 0 },
|
2003-08-13 03:27:48 +02:00
|
|
|
};
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static UINT get_defaulttablecolumns( LPCWSTR name, MSICOLUMNINFO *colinfo, UINT *sz)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
const MSICOLUMNINFO *p;
|
|
|
|
DWORD i, n;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(name));
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
if (!lstrcmpW( name, szTables ))
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
p = _Tables_cols;
|
|
|
|
n = 1;
|
|
|
|
}
|
|
|
|
else if (!lstrcmpW( name, szColumns ))
|
|
|
|
{
|
|
|
|
p = _Columns_cols;
|
|
|
|
n = 4;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
/* duplicate the string data so we can free it in msi_free_colinfo */
|
|
|
|
for (i=0; i<n; i++)
|
|
|
|
{
|
|
|
|
if (colinfo && (i < *sz) )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
memcpy( &colinfo[i], &p[i], sizeof(MSICOLUMNINFO) );
|
|
|
|
colinfo[i].tablename = strdupW( p[i].tablename );
|
|
|
|
colinfo[i].colname = strdupW( p[i].colname );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
2005-09-22 12:34:07 +02:00
|
|
|
if( colinfo && (i >= *sz) )
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
*sz = n;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
static void msi_free_colinfo( MSICOLUMNINFO *colinfo, UINT count )
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for( i=0; i<count; i++ )
|
|
|
|
{
|
|
|
|
msi_free( (LPWSTR) colinfo[i].tablename );
|
|
|
|
msi_free( (LPWSTR) colinfo[i].colname );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
LPWSTR MSI_makestring( MSIDATABASE *db, UINT stringid)
|
|
|
|
{
|
|
|
|
UINT sz=0, r;
|
|
|
|
LPWSTR str;
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
r = msi_id2stringW( db->strings, stringid, NULL, &sz );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return NULL;
|
2005-09-21 12:20:20 +02:00
|
|
|
str = msi_alloc( sz*sizeof (WCHAR) );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !str )
|
|
|
|
return str;
|
2004-03-18 05:04:08 +01:00
|
|
|
r = msi_id2stringW( db->strings, stringid, str, &sz );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
return str;
|
2005-09-21 12:20:20 +02:00
|
|
|
msi_free( str );
|
2003-08-13 03:27:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT get_tablecolumns( MSIDATABASE *db,
|
2003-08-13 03:27:48 +02:00
|
|
|
LPCWSTR szTableName, MSICOLUMNINFO *colinfo, UINT *sz)
|
|
|
|
{
|
|
|
|
UINT r, i, n=0, table_id, count, maxcount = *sz;
|
|
|
|
MSITABLE *table = NULL;
|
|
|
|
|
|
|
|
/* first check if there is a default table with that name */
|
|
|
|
r = get_defaulttablecolumns( szTableName, colinfo, sz );
|
|
|
|
if( ( r == ERROR_SUCCESS ) && *sz )
|
|
|
|
return r;
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
table = get_table( db, szColumns, _Columns_cols, 4 );
|
2005-09-21 12:20:20 +02:00
|
|
|
if( !table )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
ERR("couldn't load _Columns table\n");
|
2005-09-21 12:20:20 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert table and column names to IDs from the string table */
|
2004-06-30 20:18:27 +02:00
|
|
|
r = msi_string2idW( db->strings, szTableName, &table_id );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("Couldn't find id for %s\n", debugstr_w(szTableName));
|
2003-08-13 03:27:48 +02:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Table id is %d\n", table_id);
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
count = table->row_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
for( i=0; i<count; i++ )
|
|
|
|
{
|
2004-03-18 05:04:08 +01:00
|
|
|
if( table->data[ i ][ 0 ] != table_id )
|
2003-08-13 03:27:48 +02:00
|
|
|
continue;
|
|
|
|
if( colinfo )
|
|
|
|
{
|
2004-03-18 05:04:08 +01:00
|
|
|
UINT id = table->data[ i ] [ 2 ];
|
2003-08-13 03:27:48 +02:00
|
|
|
colinfo[n].tablename = MSI_makestring( db, table_id );
|
2004-03-18 05:04:08 +01:00
|
|
|
colinfo[n].number = table->data[ i ][ 1 ] - (1<<15);
|
2003-08-13 03:27:48 +02:00
|
|
|
colinfo[n].colname = MSI_makestring( db, id );
|
2005-09-28 13:59:40 +02:00
|
|
|
colinfo[n].type = table->data[ i ] [ 3 ] ^ 0x8000;
|
2003-08-13 03:27:48 +02:00
|
|
|
/* this assumes that columns are in order in the table */
|
|
|
|
if( n )
|
|
|
|
colinfo[n].offset = colinfo[n-1].offset
|
|
|
|
+ bytes_per_column( &colinfo[n-1] );
|
|
|
|
else
|
|
|
|
colinfo[n].offset = 0;
|
|
|
|
TRACE("table %s column %d is [%s] (%d) with type %08x "
|
|
|
|
"offset %d at row %d\n", debugstr_w(szTableName),
|
|
|
|
colinfo[n].number, debugstr_w(colinfo[n].colname),
|
|
|
|
id, colinfo[n].type, colinfo[n].offset, i);
|
|
|
|
if( n != (colinfo[n].number-1) )
|
|
|
|
{
|
|
|
|
ERR("oops. data in the _Columns table isn't in the right "
|
|
|
|
"order for table %s\n", debugstr_w(szTableName));
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
if( colinfo && ( n >= maxcount ) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*sz = n;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to find the table name in the _Tables table */
|
|
|
|
BOOL TABLE_Exists( MSIDATABASE *db, LPWSTR name )
|
|
|
|
{
|
|
|
|
UINT r, table_id = 0, i, count;
|
|
|
|
MSITABLE *table = NULL;
|
|
|
|
|
|
|
|
if( !lstrcmpW( name, szTables ) )
|
|
|
|
return TRUE;
|
|
|
|
if( !lstrcmpW( name, szColumns ) )
|
|
|
|
return TRUE;
|
|
|
|
|
2004-06-30 20:18:27 +02:00
|
|
|
r = msi_string2idW( db->strings, name, &table_id );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("Couldn't find id for %s\n", debugstr_w(name));
|
2003-08-13 03:27:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
table = get_table( db, szTables, _Tables_cols, 1 );
|
2005-09-21 12:20:20 +02:00
|
|
|
if( !table )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
TRACE("table %s not available\n", debugstr_w(szTables));
|
2003-08-13 03:27:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
/* count = table->size/2; */
|
|
|
|
count = table->row_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
for( i=0; i<count; i++ )
|
2004-03-18 05:04:08 +01:00
|
|
|
if( table->data[ i ][ 0 ] == table_id )
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (i!=count)
|
|
|
|
return TRUE;
|
|
|
|
|
2005-05-20 21:16:50 +02:00
|
|
|
TRACE("Searched %d tables, but %d was not found\n", count, table_id );
|
2004-03-19 02:16:36 +01:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* below is the query interface to a table */
|
|
|
|
|
|
|
|
typedef struct tagMSITABLEVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
MSITABLE *table;
|
|
|
|
MSICOLUMNINFO *columns;
|
|
|
|
UINT num_cols;
|
|
|
|
UINT row_size;
|
|
|
|
WCHAR name[1];
|
|
|
|
} MSITABLEVIEW;
|
|
|
|
|
|
|
|
static UINT TABLE_fetch_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT *val )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
UINT offset, num_rows, n;
|
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( (col==0) || (col>tv->num_cols) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/* how many rows are there ? */
|
2004-03-18 05:04:08 +01:00
|
|
|
num_rows = tv->table->row_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
if( row >= num_rows )
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
|
|
|
if( tv->columns[col-1].offset >= tv->row_size )
|
|
|
|
{
|
|
|
|
ERR("Stuffed up %d >= %d\n", tv->columns[col-1].offset, tv->row_size );
|
|
|
|
ERR("%p %p\n", tv, tv->columns );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset = row + (tv->columns[col-1].offset/2) * num_rows;
|
|
|
|
n = bytes_per_column( &tv->columns[col-1] );
|
|
|
|
switch( n )
|
|
|
|
{
|
|
|
|
case 4:
|
2004-03-18 05:04:08 +01:00
|
|
|
offset = tv->columns[col-1].offset/2;
|
2004-03-19 02:16:36 +01:00
|
|
|
*val = tv->table->data[row][offset] +
|
|
|
|
(tv->table->data[row][offset + 1] << 16);
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
case 2:
|
2004-03-18 05:04:08 +01:00
|
|
|
offset = tv->columns[col-1].offset/2;
|
|
|
|
*val = tv->table->data[row][offset];
|
2003-08-13 03:27:48 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("oops! what is %d bytes per column?\n", n );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2004-12-22 16:22:12 +01:00
|
|
|
/* TRACE("Data [%d][%d] = %d \n", row, col, *val ); */
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-07-06 20:56:12 +02:00
|
|
|
/*
|
|
|
|
* We need a special case for streams, as we need to reference column with
|
|
|
|
* the name of the stream in the same table, and the table name
|
|
|
|
* which may not be available at higher levels of the query
|
|
|
|
*/
|
|
|
|
static UINT TABLE_fetch_stream( struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
UINT ival = 0, refcol = 0, r;
|
|
|
|
LPWSTR sval;
|
2004-07-10 00:25:34 +02:00
|
|
|
LPWSTR full_name;
|
|
|
|
DWORD len;
|
|
|
|
static const WCHAR szDot[] = { '.', 0 };
|
2004-07-06 20:56:12 +02:00
|
|
|
|
|
|
|
if( !view->ops->fetch_int )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The column marked with the type stream data seems to have a single number
|
|
|
|
* which references the column containing the name of the stream data
|
|
|
|
*
|
|
|
|
* Fetch the column to reference first.
|
|
|
|
*/
|
|
|
|
r = view->ops->fetch_int( view, row, col, &ival );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* now get the column with the name of the stream */
|
|
|
|
r = view->ops->fetch_int( view, row, ival, &refcol );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* lookup the string value from the string table */
|
|
|
|
sval = MSI_makestring( tv->db, refcol );
|
|
|
|
if( !sval )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2005-05-11 14:58:22 +02:00
|
|
|
len = lstrlenW( tv->name ) + 2 + lstrlenW( sval );
|
2005-09-20 13:59:14 +02:00
|
|
|
full_name = msi_alloc( len*sizeof(WCHAR) );
|
2005-05-11 14:58:22 +02:00
|
|
|
lstrcpyW( full_name, tv->name );
|
|
|
|
lstrcatW( full_name, szDot );
|
|
|
|
lstrcatW( full_name, sval );
|
2004-07-10 00:25:34 +02:00
|
|
|
|
|
|
|
r = db_get_raw_stream( tv->db, full_name, stm );
|
|
|
|
if( r )
|
|
|
|
ERR("fetching stream %s, error = %d\n",debugstr_w(full_name), r);
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( full_name );
|
|
|
|
msi_free( sval );
|
2004-07-06 20:56:12 +02:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
static UINT TABLE_set_int( struct tagMSIVIEW *view, UINT row, UINT col, UINT val )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
2004-07-12 21:53:05 +02:00
|
|
|
UINT offset, n;
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( (col==0) || (col>tv->num_cols) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( tv->columns[col-1].offset >= tv->row_size )
|
|
|
|
{
|
|
|
|
ERR("Stuffed up %d >= %d\n", tv->columns[col-1].offset, tv->row_size );
|
|
|
|
ERR("%p %p\n", tv, tv->columns );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = bytes_per_column( &tv->columns[col-1] );
|
|
|
|
switch( n )
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
offset = tv->columns[col-1].offset/2;
|
|
|
|
tv->table->data[row][offset] = val & 0xffff;
|
|
|
|
tv->table->data[row][offset + 1] = (val>>16)&0xffff;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
offset = tv->columns[col-1].offset/2;
|
|
|
|
tv->table->data[row][offset] = val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("oops! what is %d bytes per column?\n", n );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-08-24 13:10:23 +02:00
|
|
|
static UINT table_create_new_row( struct tagMSIVIEW *view, UINT *num )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
USHORT **p, *row;
|
|
|
|
UINT sz;
|
|
|
|
|
|
|
|
TRACE("%p\n", view);
|
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
row = msi_alloc_zero( tv->row_size );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( !row )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
sz = (tv->table->row_count + 1) * sizeof (UINT*);
|
|
|
|
if( tv->table->data )
|
2005-09-20 13:59:14 +02:00
|
|
|
p = msi_realloc( tv->table->data, sz );
|
2004-03-19 02:16:36 +01:00
|
|
|
else
|
2005-09-20 13:59:14 +02:00
|
|
|
p = msi_alloc( sz );
|
2004-03-19 02:16:36 +01:00
|
|
|
if( !p )
|
2004-12-10 16:24:52 +01:00
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( row );
|
2004-03-19 02:16:36 +01:00
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
2004-12-10 16:24:52 +01:00
|
|
|
}
|
2004-03-19 02:16:36 +01:00
|
|
|
|
|
|
|
tv->table->data = p;
|
|
|
|
tv->table->data[tv->table->row_count] = row;
|
|
|
|
*num = tv->table->row_count;
|
|
|
|
tv->table->row_count++;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
static UINT TABLE_execute( struct tagMSIVIEW *view, MSIRECORD *record )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %p\n", tv, record);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
TRACE("There are %d columns\n", tv->num_cols );
|
|
|
|
tv->table = get_table( tv->db, tv->name, tv->columns, tv->num_cols );
|
2005-09-21 12:20:20 +02:00
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_close( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", view );
|
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
tv->table = NULL;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_get_dimensions( struct tagMSIVIEW *view, UINT *rows, UINT *cols)
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %p %p\n", view, rows, cols );
|
|
|
|
|
|
|
|
if( cols )
|
|
|
|
*cols = tv->num_cols;
|
|
|
|
if( rows )
|
|
|
|
{
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2004-03-18 05:04:08 +01:00
|
|
|
*rows = tv->table->row_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_get_column_info( struct tagMSIVIEW *view,
|
|
|
|
UINT n, LPWSTR *name, UINT *type )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p %d %p %p\n", tv, n, name, type );
|
|
|
|
|
|
|
|
if( ( n == 0 ) || ( n > tv->num_cols ) )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if( name )
|
|
|
|
{
|
|
|
|
*name = strdupW( tv->columns[n-1].colname );
|
|
|
|
if( !*name )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
if( type )
|
|
|
|
*type = tv->columns[n-1].type;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-29 13:07:29 +02:00
|
|
|
static UINT msi_table_find_row( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *row );
|
2005-08-24 13:10:23 +02:00
|
|
|
|
|
|
|
static UINT table_validate_new( MSITABLEVIEW *tv, MSIRECORD *rec )
|
|
|
|
{
|
2005-10-29 13:07:29 +02:00
|
|
|
UINT r, row;
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2005-10-29 13:07:29 +02:00
|
|
|
r = msi_table_find_row( tv, rec, &row );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
return ERROR_INVALID_DATA;
|
2005-08-24 13:10:23 +02:00
|
|
|
}
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
static UINT msi_table_modify_row( MSITABLEVIEW *tv, MSIRECORD *rec,
|
|
|
|
UINT row, UINT mask )
|
2005-08-24 13:10:23 +02:00
|
|
|
{
|
2005-10-27 14:25:04 +02:00
|
|
|
UINT i, val, r = ERROR_SUCCESS;
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
TRACE("%p %p %u %08x\n", tv, rec, row, mask );
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
for( i = 0; i < tv->num_cols; i++ )
|
2005-08-24 13:10:23 +02:00
|
|
|
{
|
2005-10-27 14:25:04 +02:00
|
|
|
/* set keys or values specified in the mask */
|
|
|
|
if( (~tv->columns[i].type & MSITYPE_KEY) && (~mask & (1<<i)) )
|
|
|
|
continue;
|
2005-08-24 13:10:23 +02:00
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
if( (tv->columns[i].type & MSITYPE_STRING) &&
|
|
|
|
! MSITYPE_IS_BINARY(tv->columns[i].type) )
|
2005-08-24 13:10:23 +02:00
|
|
|
{
|
2005-10-27 14:25:04 +02:00
|
|
|
const WCHAR *str = MSI_RecordGetString( rec, i+1 );
|
2005-08-24 13:10:23 +02:00
|
|
|
val = msi_addstringW( tv->db->strings, 0, str, -1, 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-27 14:25:04 +02:00
|
|
|
val = MSI_RecordGetInteger( rec, i+1 );
|
|
|
|
if ( 2 == bytes_per_column( &tv->columns[i] ) )
|
|
|
|
val ^= 0x8000;
|
2005-08-24 13:10:23 +02:00
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
r = TABLE_set_int( &tv->view, row, i+1, val );
|
2005-08-24 13:10:23 +02:00
|
|
|
if( r )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
static UINT TABLE_insert_row( struct tagMSIVIEW *view, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
UINT r, row = -1;
|
|
|
|
|
|
|
|
TRACE("%p %p\n", tv, rec );
|
|
|
|
|
|
|
|
r = table_create_new_row( view, &row );
|
|
|
|
TRACE("insert_row returned %08x\n", r);
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
return msi_table_modify_row( tv, rec, row, ~0 );
|
|
|
|
}
|
|
|
|
|
2005-02-08 14:44:25 +01:00
|
|
|
static UINT TABLE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode,
|
|
|
|
MSIRECORD *rec)
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2005-08-24 13:10:23 +02:00
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p %d %p\n", view, eModifyMode, rec );
|
|
|
|
|
2005-08-29 12:16:12 +02:00
|
|
|
if (!tv->table)
|
|
|
|
{
|
|
|
|
r = TABLE_execute( view, NULL );
|
|
|
|
if( r )
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2005-08-24 13:10:23 +02:00
|
|
|
switch (eModifyMode)
|
|
|
|
{
|
|
|
|
case MSIMODIFY_VALIDATE_NEW:
|
|
|
|
r = table_validate_new( tv, rec );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIMODIFY_INSERT_TEMPORARY:
|
|
|
|
r = table_validate_new( tv, rec );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
break;
|
|
|
|
r = TABLE_insert_row( view, rec );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MSIMODIFY_REFRESH:
|
|
|
|
case MSIMODIFY_INSERT:
|
|
|
|
case MSIMODIFY_UPDATE:
|
|
|
|
case MSIMODIFY_ASSIGN:
|
|
|
|
case MSIMODIFY_REPLACE:
|
|
|
|
case MSIMODIFY_MERGE:
|
|
|
|
case MSIMODIFY_DELETE:
|
|
|
|
case MSIMODIFY_VALIDATE:
|
|
|
|
case MSIMODIFY_VALIDATE_FIELD:
|
|
|
|
case MSIMODIFY_VALIDATE_DELETE:
|
|
|
|
FIXME("%p %d %p - mode not implemented\n", view, eModifyMode, rec );
|
|
|
|
r = ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
r = ERROR_INVALID_DATA;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", view );
|
|
|
|
|
|
|
|
tv->table = NULL;
|
|
|
|
|
|
|
|
if( tv->columns )
|
|
|
|
{
|
2005-09-22 12:34:07 +02:00
|
|
|
msi_free_colinfo( tv->columns, tv->num_cols );
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( tv->columns );
|
2003-08-13 03:27:48 +02:00
|
|
|
}
|
|
|
|
tv->columns = NULL;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( tv );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MSIVIEWOPS table_ops =
|
|
|
|
{
|
|
|
|
TABLE_fetch_int,
|
2004-07-06 20:56:12 +02:00
|
|
|
TABLE_fetch_stream,
|
2004-03-19 02:16:36 +01:00
|
|
|
TABLE_set_int,
|
|
|
|
TABLE_insert_row,
|
2003-08-13 03:27:48 +02:00
|
|
|
TABLE_execute,
|
|
|
|
TABLE_close,
|
|
|
|
TABLE_get_dimensions,
|
|
|
|
TABLE_get_column_info,
|
|
|
|
TABLE_modify,
|
|
|
|
TABLE_delete
|
|
|
|
};
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
UINT TABLE_CreateView( MSIDATABASE *db, LPCWSTR name, MSIVIEW **view )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv ;
|
2005-09-22 12:34:07 +02:00
|
|
|
UINT r, sz, column_count;
|
2005-09-26 15:25:48 +02:00
|
|
|
MSICOLUMNINFO *columns;
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
TRACE("%p %s %p\n", db, debugstr_w(name), view );
|
|
|
|
|
|
|
|
/* get the number of columns in this table */
|
|
|
|
column_count = 0;
|
|
|
|
r = get_tablecolumns( db, name, NULL, &column_count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* if there's no columns, there's no table */
|
|
|
|
if( column_count == 0 )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
TRACE("Table found\n");
|
|
|
|
|
|
|
|
sz = sizeof *tv + lstrlenW(name)*sizeof name[0] ;
|
2005-09-20 13:59:14 +02:00
|
|
|
tv = msi_alloc_zero( sz );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !tv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2005-09-20 13:59:14 +02:00
|
|
|
columns = msi_alloc( column_count*sizeof (MSICOLUMNINFO));
|
2003-08-13 03:27:48 +02:00
|
|
|
if( !columns )
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( tv );
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = get_tablecolumns( db, name, columns, &column_count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-09-20 13:59:14 +02:00
|
|
|
msi_free( columns );
|
|
|
|
msi_free( tv );
|
2003-08-13 03:27:48 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Table has %d columns\n", column_count);
|
|
|
|
|
|
|
|
/* fill the structure */
|
|
|
|
tv->view.ops = &table_ops;
|
|
|
|
tv->db = db;
|
|
|
|
tv->columns = columns;
|
|
|
|
tv->num_cols = column_count;
|
|
|
|
tv->table = NULL;
|
2005-09-26 15:25:48 +02:00
|
|
|
tv->row_size = msi_table_get_row_size( columns, column_count );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2005-09-22 12:34:07 +02:00
|
|
|
TRACE("%s one row is %d bytes\n", debugstr_w(name), tv->row_size );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
*view = (MSIVIEW*) tv;
|
|
|
|
lstrcpyW( tv->name, name );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
UINT MSI_CommitTables( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
MSITABLE *table = NULL;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
TRACE("%p\n",db);
|
|
|
|
|
|
|
|
r = save_string_table( db );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("failed to save string table r=%08x\n",r);
|
2004-03-19 02:16:36 +01:00
|
|
|
return r;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
2005-09-14 12:07:26 +02:00
|
|
|
LIST_FOR_EACH_ENTRY( table, &db->tables, MSITABLE, entry )
|
2004-03-18 05:04:08 +01:00
|
|
|
{
|
|
|
|
r = save_table( db, table );
|
|
|
|
if( r != ERROR_SUCCESS )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
2005-05-20 21:16:50 +02:00
|
|
|
WARN("failed to save table %s (r=%08x)\n",
|
2004-03-19 02:16:36 +01:00
|
|
|
debugstr_w(table->name), r);
|
2004-03-18 05:04:08 +01:00
|
|
|
return r;
|
2004-03-19 02:16:36 +01:00
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* force everything to reload next time */
|
|
|
|
free_cached_tables( db );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2005-10-26 15:56:33 +02:00
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
static MSIRECORD *msi_get_transform_record( MSITABLEVIEW *tv, string_table *st, USHORT *rawdata )
|
|
|
|
{
|
|
|
|
UINT i, val, ofs = 0;
|
|
|
|
USHORT mask = *rawdata++;
|
|
|
|
MSICOLUMNINFO *columns = tv->columns;
|
|
|
|
MSIRECORD *rec;
|
|
|
|
const int debug_transform = 0;
|
|
|
|
|
|
|
|
rec = MSI_CreateRecord( tv->num_cols );
|
|
|
|
if( !rec )
|
|
|
|
return rec;
|
|
|
|
|
|
|
|
if( debug_transform ) MESSAGE("row -> ");
|
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
UINT n = bytes_per_column( &columns[i] );
|
|
|
|
|
|
|
|
if ( (mask&1) && (i>=(mask>>8)) )
|
|
|
|
break;
|
|
|
|
/* all keys must be present */
|
|
|
|
if ( (~mask&1) && (~columns[i].type & MSITYPE_KEY) && ((1<<i) & ~mask) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch( n )
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
val = rawdata[ofs];
|
|
|
|
if( (columns[i].type & MSITYPE_STRING) &&
|
|
|
|
! MSITYPE_IS_BINARY(tv->columns[i].type) )
|
|
|
|
{
|
|
|
|
LPCWSTR sval = msi_string_lookup_id( st, val );
|
|
|
|
MSI_RecordSetStringW( rec, i+1, sval );
|
|
|
|
if( debug_transform ) MESSAGE("[%s]", debugstr_w(sval));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
val ^= 0x8000;
|
|
|
|
MSI_RecordSetInteger( rec, i+1, val );
|
|
|
|
if( debug_transform) MESSAGE("[0x%04x]", val );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
val = rawdata[ofs] + (rawdata[ofs + 1]<<16);
|
|
|
|
/* val ^= 0x80000000; */
|
|
|
|
MSI_RecordSetInteger( rec, i+1, val );
|
|
|
|
if( debug_transform ) MESSAGE("[0x%08x]", val );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERR("oops - unknown column width %d\n", n);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ofs += n/2;
|
|
|
|
}
|
|
|
|
if( debug_transform) MESSAGE("\n");
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_record( MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
UINT i, n;
|
|
|
|
|
|
|
|
MESSAGE("row -> ");
|
|
|
|
n = MSI_RecordGetFieldCount( rec );
|
|
|
|
for( i=1; i<=n; i++ )
|
|
|
|
{
|
|
|
|
LPCWSTR sval = MSI_RecordGetString( rec, i );
|
|
|
|
|
|
|
|
if( MSI_RecordIsNull( rec, i ) )
|
|
|
|
MESSAGE("[]");
|
|
|
|
else if( (sval = MSI_RecordGetString( rec, i )) )
|
|
|
|
MESSAGE("[%s]", debugstr_w(sval));
|
|
|
|
else
|
|
|
|
MESSAGE("[0x%08x]", MSI_RecordGetInteger( rec, i ) );
|
|
|
|
}
|
|
|
|
MESSAGE("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_table( string_table *st, USHORT *rawdata, UINT rawsize )
|
|
|
|
{
|
|
|
|
LPCWSTR sval;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
for( i=0; i<(rawsize/2); i++ )
|
|
|
|
{
|
|
|
|
sval = msi_string_lookup_id( st, rawdata[i] );
|
|
|
|
if( !sval ) sval = (WCHAR[]) {0};
|
|
|
|
MESSAGE(" %04x %s\n", rawdata[i], debugstr_w(sval) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT* msi_record_to_row( MSITABLEVIEW *tv, MSIRECORD *rec )
|
|
|
|
{
|
|
|
|
LPCWSTR str;
|
|
|
|
UINT i, r, *data;
|
|
|
|
|
|
|
|
data = msi_alloc( tv->num_cols *sizeof (UINT) );
|
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
data[i] = 0;
|
|
|
|
|
|
|
|
if ( ~tv->columns[i].type & MSITYPE_KEY )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* turn the transform column value into a row value */
|
|
|
|
if ( ( tv->columns[i].type & MSITYPE_STRING ) &&
|
|
|
|
! MSITYPE_IS_BINARY(tv->columns[i].type) )
|
|
|
|
{
|
|
|
|
str = MSI_RecordGetString( rec, i+1 );
|
|
|
|
r = msi_string2idW( tv->db->strings, str, &data[i] );
|
|
|
|
|
|
|
|
/* if there's no matching string in the string table,
|
|
|
|
these keys can't match any record, so fail now. */
|
|
|
|
if( ERROR_SUCCESS != r )
|
|
|
|
{
|
|
|
|
msi_free( data );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
data[i] = MSI_RecordGetInteger( rec, i+1 );
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_row_matches( MSITABLEVIEW *tv, UINT row, UINT *data )
|
|
|
|
{
|
|
|
|
UINT i, r, x, ret = ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
if ( ~tv->columns[i].type & MSITYPE_KEY )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* turn the transform column value into a row value */
|
|
|
|
r = TABLE_fetch_int( &tv->view, row, i+1, &x );
|
|
|
|
if ( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("TABLE_fetch_int shouldn't fail here\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if this key matches, move to the next column */
|
|
|
|
if ( x != data[i] )
|
|
|
|
{
|
|
|
|
ret = ERROR_FUNCTION_FAILED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_table_find_row( MSITABLEVIEW *tv, MSIRECORD *rec, UINT *row )
|
|
|
|
{
|
|
|
|
UINT i, r = ERROR_FUNCTION_FAILED, *data;
|
|
|
|
|
|
|
|
data = msi_record_to_row( tv, rec );
|
|
|
|
if( !data )
|
|
|
|
return r;
|
|
|
|
for( i=0; i<tv->table->row_count; i++ )
|
|
|
|
{
|
|
|
|
r = msi_row_matches( tv, i, data );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
*row = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msi_free( data );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT msi_delete_row( MSITABLEVIEW *tv, UINT row )
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for( i=1; i<=tv->num_cols; i++ )
|
|
|
|
tv->view.ops->set_int( &tv->view, row, i, 0 );
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
static UINT msi_table_load_transform( MSIDATABASE *db, IStorage *stg,
|
|
|
|
string_table *st, LPCWSTR name )
|
|
|
|
{
|
2005-10-27 14:25:04 +02:00
|
|
|
UINT rawsize = 0;
|
|
|
|
USHORT *rawdata = NULL;
|
|
|
|
MSITABLEVIEW *tv = NULL;
|
|
|
|
UINT r, n, sz, i, mask;
|
|
|
|
MSIRECORD *rec = NULL;
|
|
|
|
const int debug_transform = 0;
|
|
|
|
|
|
|
|
TRACE("%p %p %p %s\n", db, stg, st, debugstr_w(name) );
|
|
|
|
|
|
|
|
/* create a table view */
|
|
|
|
r = TABLE_CreateView( db, name, (MSIVIEW**) &tv );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
r = tv->view.ops->execute( &tv->view, NULL );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* read the transform data */
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
|
|
|
read_stream_data( stg, name, &rawdata, &rawsize );
|
|
|
|
if( !rawdata || (rawsize < 2) )
|
|
|
|
{
|
|
|
|
ERR("odd sized transform for table %s\n", debugstr_w(name));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("name = %s columns = %u row_size = %u raw size = %u\n",
|
|
|
|
debugstr_w(name), tv->num_cols, tv->row_size, rawsize );
|
|
|
|
|
|
|
|
/* interpret the data */
|
|
|
|
r = ERROR_SUCCESS;
|
|
|
|
for( n=0; n < (rawsize/2); )
|
|
|
|
{
|
|
|
|
mask = rawdata[n];
|
|
|
|
|
|
|
|
if (mask&1)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* if the low bit is set, columns are continuous and
|
|
|
|
* the number of columns is specified in the high byte
|
|
|
|
*/
|
|
|
|
sz = 2 + tv->row_size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If the low bit is not set, rowdata[n] is a bitmask.
|
|
|
|
* Excepting for key fields, which are always present,
|
|
|
|
* each bit indicates that a field is present in the transform record.
|
|
|
|
*
|
|
|
|
* rawdata[n] == 0 is a special case ... only the keys will be present
|
|
|
|
* and it means that this row should be deleted.
|
|
|
|
*/
|
|
|
|
sz = 2;
|
|
|
|
for( i=0; i<tv->num_cols; i++ )
|
|
|
|
{
|
|
|
|
if( (tv->columns[i].type & MSITYPE_KEY) || ((1<<i)&mask))
|
|
|
|
sz += bytes_per_column( &tv->columns[i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check we didn't run of the end of the table */
|
|
|
|
if ( (n+sz) > rawsize )
|
|
|
|
{
|
|
|
|
ERR("borked.\n");
|
|
|
|
dump_table( st, rawdata, rawsize );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec = msi_get_transform_record( tv, st, &rawdata[n] );
|
|
|
|
if (rec)
|
|
|
|
{
|
|
|
|
UINT row = 0;
|
|
|
|
|
|
|
|
r = msi_table_find_row( tv, rec, &row );
|
|
|
|
|
|
|
|
if( rawdata[n] & 1)
|
|
|
|
{
|
|
|
|
if( debug_transform ) MESSAGE("insert [%d]: ", row);
|
|
|
|
TABLE_insert_row( &tv->view, rec );
|
|
|
|
}
|
|
|
|
else if( mask & 0xff )
|
|
|
|
{
|
|
|
|
if( debug_transform ) MESSAGE("modify [%d]: ", row);
|
|
|
|
msi_table_modify_row( tv, rec, row, mask );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( debug_transform ) MESSAGE("delete [%d]: ", row);
|
|
|
|
msi_delete_row( tv, row );
|
|
|
|
}
|
|
|
|
if( debug_transform ) dump_record( rec );
|
|
|
|
msiobj_release( &rec->hdr );
|
|
|
|
}
|
|
|
|
|
|
|
|
n += sz/2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
/* no need to free the table, it's associated with the database */
|
|
|
|
msi_free( rawdata );
|
|
|
|
if( tv )
|
|
|
|
tv->view.ops->delete( &tv->view );
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* msi_table_apply_transform
|
|
|
|
*
|
|
|
|
* Enumerate the table transforms in a transform storage and apply each one.
|
|
|
|
*/
|
|
|
|
UINT msi_table_apply_transform( MSIDATABASE *db, IStorage *stg )
|
|
|
|
{
|
|
|
|
IEnumSTATSTG *stgenum = NULL;
|
|
|
|
HRESULT r;
|
|
|
|
STATSTG stat;
|
|
|
|
ULONG n, count;
|
|
|
|
WCHAR name[0x40];
|
|
|
|
string_table *strings;
|
|
|
|
UINT ret = ERROR_FUNCTION_FAILED;
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
TRACE("%p %p\n", db, stg );
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
strings = load_string_table( stg );
|
|
|
|
if( !strings )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
r = IStorage_EnumElements( stg, 0, NULL, 0, &stgenum );
|
|
|
|
if( FAILED( r ) )
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
while( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
r = IEnumSTATSTG_Next( stgenum, 1, &stat, &count );
|
|
|
|
if( FAILED( r ) || !count )
|
|
|
|
break;
|
|
|
|
decode_streamname( stat.pwcsName, name );
|
|
|
|
if( ( name[0] == 0x4840 ) && ( name[1] != '_' ) )
|
2005-10-27 14:25:04 +02:00
|
|
|
ret = msi_table_load_transform( db, stg, strings, name+1 );
|
2005-10-26 15:56:33 +02:00
|
|
|
else
|
2005-10-27 14:25:04 +02:00
|
|
|
TRACE("transform contains stream %s\n", debugstr_w(name));
|
2005-10-26 15:56:33 +02:00
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
2005-10-27 14:25:04 +02:00
|
|
|
if ( ret == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
MSITRANSFORM *t;
|
|
|
|
|
|
|
|
t = msi_alloc( sizeof *t );
|
|
|
|
t->stg = stg;
|
|
|
|
IStorage_AddRef( stg );
|
|
|
|
list_add_tail( &db->transforms, &t->entry );
|
|
|
|
}
|
|
|
|
|
2005-10-26 15:56:33 +02:00
|
|
|
end:
|
|
|
|
if ( stgenum )
|
|
|
|
IEnumSTATSTG_Release( stgenum );
|
|
|
|
if ( strings )
|
|
|
|
msi_destroy_stringtable( strings );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2005-10-27 14:25:04 +02:00
|
|
|
|
|
|
|
void msi_free_transforms( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
while( !list_empty( &db->transforms ) )
|
|
|
|
{
|
|
|
|
MSITRANSFORM *t = LIST_ENTRY( list_head( &db->transforms ),
|
|
|
|
MSITRANSFORM, entry );
|
|
|
|
list_remove( &t->entry );
|
|
|
|
IStorage_Release( t->stg );
|
|
|
|
msi_free( t );
|
|
|
|
}
|
|
|
|
}
|