2003-08-13 03:27:48 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
2004-03-19 02:16:36 +01: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
|
|
|
|
* 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"
|
|
|
|
|
2004-07-06 20:56:12 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
#include "query.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msi);
|
|
|
|
|
|
|
|
typedef struct tagMSICOLUMNINFO
|
|
|
|
{
|
|
|
|
LPWSTR tablename;
|
|
|
|
UINT number;
|
|
|
|
LPWSTR colname;
|
|
|
|
UINT type;
|
|
|
|
UINT offset;
|
|
|
|
} MSICOLUMNINFO;
|
|
|
|
|
|
|
|
struct tagMSITABLE
|
|
|
|
{
|
2004-03-18 05:04:08 +01:00
|
|
|
USHORT **data;
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT ref_count;
|
2004-03-18 05:04:08 +01:00
|
|
|
UINT row_count;
|
2003-08-13 03:27:48 +02:00
|
|
|
struct tagMSITABLE *next;
|
|
|
|
struct tagMSITABLE *prev;
|
|
|
|
WCHAR name[1];
|
2004-03-18 05:04:08 +01:00
|
|
|
};
|
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);
|
|
|
|
|
|
|
|
static inline UINT bytes_per_column( MSICOLUMNINFO *col )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
count = strlenW( in )+2;
|
|
|
|
out = HeapAlloc( GetProcessHeap(), 0, count*sizeof(WCHAR) );
|
|
|
|
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));
|
|
|
|
HeapFree( GetProcessHeap(), 0, out );
|
|
|
|
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);
|
2004-07-06 21:00:46 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, 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 ) )
|
|
|
|
{
|
|
|
|
ERR("open stream failed r = %08lx!\n",r);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( stat.cbSize.QuadPart >> 32 )
|
|
|
|
{
|
|
|
|
ERR("Too big!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = stat.cbSize.QuadPart;
|
|
|
|
data = HeapAlloc( GetProcessHeap(), 0, sz );
|
|
|
|
if( !data )
|
|
|
|
{
|
|
|
|
ERR("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
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
ERR("read stream failed r = %08lx!\n",r);
|
|
|
|
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);
|
2004-07-06 21:00:46 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, encname );
|
2004-06-29 05:41:28 +02:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
|
|
|
WARN("open stream failed r = %08lx - empty table?\n",r);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
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 ) )
|
|
|
|
{
|
|
|
|
ERR("open stream failed r = %08lx!\n",r);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( stat.cbSize.QuadPart >> 32 )
|
|
|
|
{
|
|
|
|
ERR("Too big!\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = stat.cbSize.QuadPart;
|
|
|
|
data = HeapAlloc( GetProcessHeap(), 0, sz );
|
|
|
|
if( !data )
|
|
|
|
{
|
|
|
|
ERR("couldn't allocate memory r=%08lx!\n",r);
|
|
|
|
ret = ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Read(stm, data, sz, &count );
|
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
ERR("read stream failed r = %08lx!\n",r);
|
|
|
|
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-01-20 20:57:22 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, encname );
|
2004-03-18 05:04:08 +01:00
|
|
|
if( FAILED( r ) )
|
|
|
|
{
|
2004-03-19 02:16:36 +01:00
|
|
|
ERR("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
|
|
|
{
|
|
|
|
ERR("Failed to SetSize\n");
|
|
|
|
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
|
|
|
{
|
|
|
|
ERR("Failed to Seek\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = IStream_Write(stm, data, sz, &count );
|
|
|
|
if( FAILED( r ) || ( count != sz ) )
|
|
|
|
{
|
|
|
|
ERR("Failed to Write\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
end:
|
|
|
|
IStream_Release( stm );
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT read_table_from_storage( MSIDATABASE *db, LPCWSTR name, MSITABLE **ptable)
|
2003-10-28 22:49:06 +01:00
|
|
|
{
|
|
|
|
MSITABLE *t;
|
2004-03-18 05:04:08 +01:00
|
|
|
USHORT *rawdata = NULL;
|
|
|
|
UINT rawsize = 0, r, i, j, row_size = 0, num_cols = 0;
|
|
|
|
MSICOLUMNINFO *cols, *last_col;
|
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-01-26 22:09:04 +01:00
|
|
|
/* non-existing tables should be interpreted as empty tables */
|
2003-10-28 22:49:06 +01:00
|
|
|
t = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
sizeof (MSITABLE) + lstrlenW(name)*sizeof (WCHAR) );
|
|
|
|
if( !t )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
r = table_get_column_info( db, name, &cols, &num_cols );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, t );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
last_col = &cols[num_cols-1];
|
|
|
|
row_size = last_col->offset + bytes_per_column( last_col );
|
|
|
|
|
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 );
|
|
|
|
t->ref_count = 1;
|
|
|
|
*ptable = t;
|
|
|
|
|
|
|
|
/* if we can't read the table, just assume that it's empty */
|
2004-03-18 05:04:08 +01:00
|
|
|
read_stream_data( db->storage, name, &rawdata, &rawsize );
|
|
|
|
if( !rawdata )
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
|
|
|
|
TRACE("Read %d bytes\n", rawsize );
|
|
|
|
|
|
|
|
if( rawsize % row_size )
|
|
|
|
{
|
|
|
|
ERR("Table size is invalid %d/%d\n", rawsize, row_size );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
t->row_count = rawsize / row_size;
|
|
|
|
t->data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
t->row_count * sizeof (USHORT*) );
|
|
|
|
if( !t->data )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY; /* FIXME: memory leak */
|
|
|
|
|
|
|
|
/* transpose all the data */
|
|
|
|
TRACE("Transposing data from %d columns\n", t->row_count );
|
|
|
|
for( i=0; i<t->row_count; i++ )
|
|
|
|
{
|
|
|
|
t->data[i] = HeapAlloc( GetProcessHeap(), 0, row_size );
|
|
|
|
if( !t->data[i] )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY; /* FIXME: memory leak */
|
|
|
|
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);
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, cols );
|
|
|
|
HeapFree( GetProcessHeap(), 0, rawdata );
|
2003-10-28 22:49:06 +01:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
/* add this table to the list of cached tables in the database */
|
|
|
|
void add_table(MSIDATABASE *db, MSITABLE *table)
|
|
|
|
{
|
|
|
|
table->next = db->first_table;
|
|
|
|
table->prev = NULL;
|
|
|
|
if( db->first_table )
|
|
|
|
db->first_table->prev = table;
|
|
|
|
else
|
|
|
|
db->last_table = table;
|
|
|
|
db->first_table = table;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove from the list of cached tables */
|
|
|
|
void remove_table( MSIDATABASE *db, MSITABLE *table )
|
|
|
|
{
|
|
|
|
if( table->next )
|
|
|
|
table->next->prev = table->prev;
|
|
|
|
else
|
|
|
|
db->last_table = table->prev;
|
|
|
|
if( table->prev )
|
|
|
|
table->prev->next = table->next;
|
|
|
|
else
|
|
|
|
db->first_table = table->next;
|
|
|
|
table->next = NULL;
|
|
|
|
table->prev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_table( MSIDATABASE *db, MSITABLE *table )
|
|
|
|
{
|
|
|
|
if( !table->ref_count )
|
|
|
|
ERR("Trying to destroy table with refcount 0\n");
|
|
|
|
table->ref_count --;
|
|
|
|
if( !table->ref_count )
|
|
|
|
{
|
|
|
|
remove_table( db, table );
|
|
|
|
HeapFree( GetProcessHeap(), 0, table->data );
|
|
|
|
HeapFree( GetProcessHeap(), 0, table );
|
|
|
|
TRACE("Destroyed table %s\n", debugstr_w(table->name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_cached_tables( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
while( db->first_table )
|
|
|
|
{
|
|
|
|
MSITABLE *t = db->first_table;
|
|
|
|
|
|
|
|
if ( --t->ref_count )
|
|
|
|
ERR("table ref count not zero for %s\n", debugstr_w(t->name));
|
|
|
|
remove_table( db, t );
|
|
|
|
HeapFree( GetProcessHeap(), 0, t->data );
|
|
|
|
HeapFree( GetProcessHeap(), 0, t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT find_cached_table(MSIDATABASE *db, LPCWSTR name, MSITABLE **ptable)
|
|
|
|
{
|
|
|
|
MSITABLE *t;
|
|
|
|
|
|
|
|
for( t = db->first_table; t; t=t->next )
|
|
|
|
{
|
|
|
|
if( !lstrcmpW( name, t->name ) )
|
|
|
|
{
|
|
|
|
*ptable = t;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
static UINT table_get_column_info( MSIDATABASE *db, LPCWSTR name, MSICOLUMNINFO **pcols, UINT *pcount )
|
|
|
|
{
|
|
|
|
UINT r, column_count;
|
|
|
|
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) );
|
|
|
|
|
|
|
|
columns = HeapAlloc( GetProcessHeap(), 0, column_count*sizeof (MSICOLUMNINFO));
|
|
|
|
if( !columns )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = get_tablecolumns( db, name, columns, &column_count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, columns );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pcols = columns;
|
|
|
|
*pcount = column_count;
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2003-08-13 03:27:48 +02:00
|
|
|
UINT get_table(MSIDATABASE *db, LPCWSTR name, MSITABLE **ptable)
|
|
|
|
{
|
|
|
|
UINT r;
|
|
|
|
|
|
|
|
*ptable = NULL;
|
|
|
|
|
|
|
|
/* first, see if the table is cached */
|
|
|
|
r = find_cached_table( db, name, ptable );
|
|
|
|
if( r == ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
(*ptable)->ref_count++;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
r = read_table_from_storage( db, name, ptable );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
/* add the table to the list */
|
|
|
|
add_table( db, *ptable );
|
|
|
|
(*ptable)->ref_count++;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
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;
|
|
|
|
MSICOLUMNINFO *cols, *last_col;
|
|
|
|
|
|
|
|
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
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
last_col = &cols[num_cols-1];
|
|
|
|
row_size = last_col->offset + bytes_per_column( last_col );
|
|
|
|
|
|
|
|
rawsize = t->row_count * row_size;
|
|
|
|
rawdata = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, rawsize );
|
|
|
|
if( !rawdata )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, rawdata );
|
|
|
|
|
|
|
|
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);
|
2004-07-06 21:00:46 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, 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);
|
2004-07-06 21:00:46 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, 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
|
|
|
}
|
|
|
|
|
2004-03-17 21:49:59 +01:00
|
|
|
UINT load_string_table( MSIDATABASE *db )
|
2003-08-13 03:27:48 +02:00
|
|
|
{
|
2004-03-18 05:04:08 +01:00
|
|
|
CHAR *data;
|
|
|
|
USHORT *pool;
|
2004-06-30 20:24:33 +02:00
|
|
|
UINT r, ret = ERROR_FUNCTION_FAILED, 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 };
|
|
|
|
|
2004-03-17 21:49:59 +01:00
|
|
|
if( db->strings )
|
|
|
|
{
|
|
|
|
msi_destroy_stringtable( db->strings );
|
|
|
|
db->strings = NULL;
|
|
|
|
}
|
|
|
|
|
2004-03-18 05:04:08 +01:00
|
|
|
r = read_stream_data( db->storage, szStringPool, &pool, &poolsize );
|
2003-08-13 03:27:48 +02:00
|
|
|
if( r != ERROR_SUCCESS)
|
|
|
|
goto end;
|
2004-03-18 05:04:08 +01:00
|
|
|
r = read_stream_data( db->storage, 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;
|
|
|
|
db->strings = msi_init_stringtable( count, codepage );
|
2004-03-17 21:49:59 +01:00
|
|
|
|
|
|
|
offset = 0;
|
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];
|
2004-03-19 02:16:36 +01:00
|
|
|
n = msi_addstring( db->strings, i, data+offset, len, pool[i*2+1] );
|
|
|
|
if( n != i )
|
|
|
|
ERR("Failed to add string %ld\n", i );
|
2004-03-17 21:49:59 +01:00
|
|
|
offset += len;
|
|
|
|
}
|
2003-08-13 03:27:48 +02:00
|
|
|
|
2004-03-17 21:49:59 +01:00
|
|
|
TRACE("Loaded %ld strings\n", count);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
end:
|
2005-01-20 11:36:35 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, pool );
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT save_string_table( MSIDATABASE *db )
|
|
|
|
{
|
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);
|
|
|
|
|
|
|
|
pool = HeapAlloc( GetProcessHeap(), 0, poolsize );
|
|
|
|
if( ! pool )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
|
|
|
ERR("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
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
data = HeapAlloc( GetProcessHeap(), 0, datasize );
|
|
|
|
if( ! data )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
|
|
|
ERR("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--;
|
2004-06-30 20:24:33 +02:00
|
|
|
TRACE("adding %u bytes %s\n", sz, 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-01-20 11:36:35 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
HeapFree( GetProcessHeap(), 0, pool );
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LPWSTR strdupW( LPCWSTR str )
|
|
|
|
{
|
2003-10-28 22:43:14 +01:00
|
|
|
UINT len = lstrlenW( str ) + 1;
|
2003-08-13 03:27:48 +02:00
|
|
|
LPWSTR ret = HeapAlloc( GetProcessHeap(), 0, len*sizeof (WCHAR) );
|
|
|
|
if( ret )
|
|
|
|
lstrcpyW( ret, str );
|
|
|
|
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
|
|
|
|
|
|
|
struct standard_table {
|
|
|
|
LPCWSTR tablename;
|
|
|
|
LPCWSTR columnname;
|
|
|
|
UINT number;
|
|
|
|
UINT type;
|
|
|
|
} MSI_standard_tables[] =
|
|
|
|
{
|
|
|
|
{ szTables, szName, 1, MSITYPE_VALID | MSITYPE_STRING | 32},
|
|
|
|
{ szColumns, szTable, 1, MSITYPE_VALID | MSITYPE_STRING | 32},
|
|
|
|
{ szColumns, szNumber, 2, MSITYPE_VALID | 2},
|
|
|
|
{ szColumns, szName, 3, MSITYPE_VALID | MSITYPE_STRING | 32},
|
|
|
|
{ szColumns, szType, 4, MSITYPE_VALID | 2},
|
|
|
|
};
|
|
|
|
|
|
|
|
#define STANDARD_TABLE_COUNT \
|
|
|
|
(sizeof(MSI_standard_tables)/sizeof(struct standard_table))
|
|
|
|
|
|
|
|
UINT get_defaulttablecolumns( LPCWSTR szTable, MSICOLUMNINFO *colinfo, UINT *sz)
|
|
|
|
{
|
|
|
|
DWORD i, n=0;
|
|
|
|
|
|
|
|
for(i=0; i<STANDARD_TABLE_COUNT; i++)
|
|
|
|
{
|
|
|
|
if( lstrcmpW( szTable, MSI_standard_tables[i].tablename ) )
|
|
|
|
continue;
|
|
|
|
if(colinfo && (n < *sz) )
|
|
|
|
{
|
|
|
|
colinfo[n].tablename = strdupW(MSI_standard_tables[i].tablename);
|
|
|
|
colinfo[n].colname = strdupW(MSI_standard_tables[i].columnname);
|
|
|
|
colinfo[n].number = MSI_standard_tables[i].number;
|
|
|
|
colinfo[n].type = MSI_standard_tables[i].type;
|
|
|
|
/* ERR("Table %s has column %s\n",debugstr_w(colinfo[n].tablename),
|
|
|
|
debugstr_w(colinfo[n].colname)); */
|
|
|
|
if( n )
|
|
|
|
colinfo[n].offset = colinfo[n-1].offset
|
|
|
|
+ bytes_per_column( &colinfo[n-1] );
|
|
|
|
else
|
|
|
|
colinfo[n].offset = 0;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
if( colinfo && (n >= *sz) )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*sz = n;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
str = HeapAlloc( GetProcessHeap(), 0, sz*sizeof (WCHAR));
|
|
|
|
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;
|
|
|
|
HeapFree( GetProcessHeap(), 0, str );
|
|
|
|
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;
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
/* first check if there is a default table with that name */
|
|
|
|
r = get_defaulttablecolumns( szTableName, colinfo, sz );
|
|
|
|
if( ( r == ERROR_SUCCESS ) && *sz )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = get_table( db, szColumns, &table);
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("table %s not available\n", debugstr_w(szColumns));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 )
|
|
|
|
{
|
|
|
|
release_table( db, table );
|
|
|
|
ERR("Couldn't find id for %s\n", debugstr_w(szTableName));
|
|
|
|
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 );
|
2004-03-18 05:04:08 +01:00
|
|
|
colinfo[n].type = table->data[ i ] [ 3 ];
|
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;
|
|
|
|
|
|
|
|
release_table( db, table );
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to find the table name in the _Tables table */
|
|
|
|
BOOL TABLE_Exists( MSIDATABASE *db, LPWSTR name )
|
|
|
|
{
|
2004-04-19 22:12:14 +02:00
|
|
|
static const WCHAR szTables[] = { '_','T','a','b','l','e','s',0 };
|
|
|
|
static const WCHAR szColumns[] = { '_','C','o','l','u','m','n','s',0 };
|
2003-08-13 03:27:48 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = get_table( db, szTables, &table);
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
ERR("table %s not available\n", debugstr_w(szTables));
|
|
|
|
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;
|
|
|
|
|
|
|
|
release_table( db, table );
|
|
|
|
|
|
|
|
if (i!=count)
|
|
|
|
return TRUE;
|
|
|
|
|
2004-03-19 02:16:36 +01:00
|
|
|
ERR("Searched %d tables, but %d was not found\n", count, table_id );
|
|
|
|
|
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;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
len = strlenW( tv->name ) + 2 + strlenW( sval );
|
|
|
|
full_name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
|
|
|
|
strcpyW( full_name, tv->name );
|
|
|
|
strcatW( full_name, szDot );
|
|
|
|
strcatW( full_name, sval );
|
|
|
|
|
|
|
|
r = db_get_raw_stream( tv->db, full_name, stm );
|
|
|
|
if( r )
|
|
|
|
ERR("fetching stream %s, error = %d\n",debugstr_w(full_name), r);
|
|
|
|
HeapFree( GetProcessHeap(), 0, full_name );
|
2004-07-06 20:56:12 +02:00
|
|
|
HeapFree( GetProcessHeap(), 0, sval );
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT TABLE_insert_row( struct tagMSIVIEW *view, UINT *num )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
USHORT **p, *row;
|
|
|
|
UINT sz;
|
|
|
|
|
|
|
|
TRACE("%p\n", view);
|
|
|
|
|
|
|
|
if( !tv->table )
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
row = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, tv->row_size );
|
|
|
|
if( !row )
|
|
|
|
return ERROR_NOT_ENOUGH_MEMORY;
|
|
|
|
|
|
|
|
sz = (tv->table->row_count + 1) * sizeof (UINT*);
|
|
|
|
if( tv->table->data )
|
|
|
|
p = HeapReAlloc( GetProcessHeap(), 0, tv->table->data, sz );
|
|
|
|
else
|
|
|
|
p = HeapAlloc( GetProcessHeap(), 0, sz );
|
|
|
|
if( !p )
|
2004-12-10 16:24:52 +01:00
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, 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;
|
|
|
|
UINT r;
|
|
|
|
|
2004-07-10 00:25:34 +02:00
|
|
|
TRACE("%p %p\n", tv, record);
|
2003-08-13 03:27:48 +02:00
|
|
|
|
|
|
|
if( tv->table )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = get_table( tv->db, tv->name, &tv->table );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
return r;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
release_table( tv->db, tv->table );
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_modify( struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIHANDLE hrec)
|
|
|
|
{
|
|
|
|
FIXME("%p %d %ld\n", view, eModifyMode, hrec );
|
|
|
|
return ERROR_CALL_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT TABLE_delete( struct tagMSIVIEW *view )
|
|
|
|
{
|
|
|
|
MSITABLEVIEW *tv = (MSITABLEVIEW*)view;
|
|
|
|
|
|
|
|
TRACE("%p\n", view );
|
|
|
|
|
|
|
|
if( tv->table )
|
|
|
|
release_table( tv->db, tv->table );
|
|
|
|
tv->table = NULL;
|
|
|
|
|
|
|
|
if( tv->columns )
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
for( i=0; i<tv->num_cols; i++)
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, tv->columns[i].colname );
|
|
|
|
HeapFree( GetProcessHeap(), 0, tv->columns[i].tablename );
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, tv->columns );
|
|
|
|
}
|
|
|
|
tv->columns = NULL;
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, tv );
|
|
|
|
|
|
|
|
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 ;
|
|
|
|
UINT r, sz, column_count;
|
|
|
|
MSICOLUMNINFO *columns, *last_col;
|
|
|
|
|
|
|
|
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] ;
|
|
|
|
tv = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sz );
|
|
|
|
if( !tv )
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
columns = HeapAlloc( GetProcessHeap(), 0, column_count*sizeof (MSICOLUMNINFO));
|
|
|
|
if( !columns )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, tv );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = get_tablecolumns( db, name, columns, &column_count );
|
|
|
|
if( r != ERROR_SUCCESS )
|
|
|
|
{
|
|
|
|
HeapFree( GetProcessHeap(), 0, columns );
|
|
|
|
HeapFree( GetProcessHeap(), 0, tv );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Table has %d columns\n", column_count);
|
|
|
|
|
|
|
|
last_col = &columns[column_count-1];
|
|
|
|
|
|
|
|
/* fill the structure */
|
|
|
|
tv->view.ops = &table_ops;
|
|
|
|
tv->db = db;
|
|
|
|
tv->columns = columns;
|
|
|
|
tv->num_cols = column_count;
|
|
|
|
tv->table = NULL;
|
|
|
|
tv->row_size = last_col->offset + bytes_per_column( last_col );
|
|
|
|
|
|
|
|
TRACE("one row is %d bytes\n", tv->row_size );
|
|
|
|
|
|
|
|
*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 )
|
|
|
|
{
|
|
|
|
ERR("failed to save string table r=%08x\n",r);
|
|
|
|
return r;
|
|
|
|
}
|
2004-03-18 05:04:08 +01:00
|
|
|
|
|
|
|
for( table = db->first_table; table; table = table->next )
|
|
|
|
{
|
|
|
|
r = save_table( db, table );
|
|
|
|
if( r != ERROR_SUCCESS )
|
2004-03-19 02:16:36 +01:00
|
|
|
{
|
|
|
|
ERR("failed to save table %s (r=%08x)\n",
|
|
|
|
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;
|
|
|
|
}
|