2007-04-25 12:22:01 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2007 James Hawkins
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "msi.h"
|
|
|
|
#include "msiquery.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "msipriv.h"
|
2008-03-01 09:08:48 +01:00
|
|
|
#include "query.h"
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2010-02-19 12:27:36 +01:00
|
|
|
#include "wine/unicode.h"
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
|
|
|
|
|
|
|
#define NUM_STREAMS_COLS 2
|
|
|
|
|
|
|
|
typedef struct tabSTREAM
|
|
|
|
{
|
2008-02-17 13:23:38 +01:00
|
|
|
UINT str_index;
|
2007-04-25 12:22:01 +02:00
|
|
|
IStream *stream;
|
|
|
|
} STREAM;
|
|
|
|
|
|
|
|
typedef struct tagMSISTREAMSVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
|
|
|
STREAM **streams;
|
|
|
|
UINT max_streams;
|
|
|
|
UINT num_rows;
|
|
|
|
UINT row_size;
|
|
|
|
} MSISTREAMSVIEW;
|
|
|
|
|
2008-02-17 13:23:38 +01:00
|
|
|
static BOOL streams_set_table_size(MSISTREAMSVIEW *sv, UINT size)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2008-02-04 18:28:36 +01:00
|
|
|
if (size >= sv->max_streams)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
|
|
|
sv->max_streams *= 2;
|
2009-06-10 17:13:59 +02:00
|
|
|
sv->streams = msi_realloc_zero(sv->streams, sv->max_streams * sizeof(STREAM *));
|
2007-04-25 12:22:01 +02:00
|
|
|
if (!sv->streams)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-04-19 12:37:20 +02:00
|
|
|
static STREAM *create_stream(MSISTREAMSVIEW *sv, LPCWSTR name, BOOL encoded, IStream *stm)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
|
|
|
STREAM *stream;
|
2014-10-02 12:17:34 +02:00
|
|
|
WCHAR decoded[MAX_STREAM_NAME_LEN + 1];
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
stream = msi_alloc(sizeof(STREAM));
|
|
|
|
if (!stream)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (encoded)
|
|
|
|
{
|
|
|
|
decode_streamname(name, decoded);
|
|
|
|
TRACE("stream -> %s %s\n", debugstr_w(name), debugstr_w(decoded));
|
2010-02-04 10:00:24 +01:00
|
|
|
name = decoded;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
2015-02-13 13:38:14 +01:00
|
|
|
stream->str_index = msi_add_string(sv->db->strings, name, -1, StringNonPersistent);
|
2007-04-25 12:22:01 +02:00
|
|
|
stream->stream = stm;
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %d, %p)\n", view, row, col, val);
|
|
|
|
|
|
|
|
if (col != 1)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
if (row >= sv->num_rows)
|
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
|
|
|
*val = sv->streams[row]->str_index;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_fetch_stream(struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %d, %p)\n", view, row, col, stm);
|
|
|
|
|
|
|
|
if (row >= sv->num_rows)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
IStream_AddRef(sv->streams[row]->stream);
|
|
|
|
*stm = sv->streams[row]->stream;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
static UINT STREAMS_get_row( struct tagMSIVIEW *view, UINT row, MSIRECORD **rec )
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
|
2010-02-04 10:00:46 +01:00
|
|
|
TRACE("%p %d %p\n", sv, row, rec);
|
2007-07-27 02:40:38 +02:00
|
|
|
|
2010-02-04 10:00:46 +01:00
|
|
|
return msi_view_get_row( sv->db, view, row, rec );
|
2007-07-27 02:40:38 +02:00
|
|
|
}
|
|
|
|
|
2007-04-25 12:22:01 +02:00
|
|
|
static UINT STREAMS_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
STREAM *stream;
|
|
|
|
IStream *stm;
|
|
|
|
STATSTG stat;
|
2010-02-04 10:01:32 +01:00
|
|
|
LPWSTR encname = NULL, name = NULL;
|
2007-04-25 12:22:01 +02:00
|
|
|
USHORT *data = NULL;
|
|
|
|
HRESULT hr;
|
|
|
|
ULONG count;
|
|
|
|
UINT r = ERROR_FUNCTION_FAILED;
|
|
|
|
|
2010-02-04 10:01:09 +01:00
|
|
|
TRACE("(%p, %d, %p, %08x)\n", view, row, rec, mask);
|
2008-02-04 18:28:36 +01:00
|
|
|
|
|
|
|
if (row > sv->num_rows)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
r = MSI_RecordGetIStream(rec, 2, &stm);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
hr = IStream_Stat(stm, &stat, STATFLAG_NONAME);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("failed to stat stream: %08x\n", hr);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stat.cbSize.QuadPart >> 32)
|
2010-02-04 10:01:09 +01:00
|
|
|
{
|
|
|
|
WARN("stream too large\n");
|
2007-04-25 12:22:01 +02:00
|
|
|
goto done;
|
2010-02-04 10:01:09 +01:00
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
data = msi_alloc(stat.cbSize.QuadPart);
|
|
|
|
if (!data)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
hr = IStream_Read(stm, data, stat.cbSize.QuadPart, &count);
|
|
|
|
if (FAILED(hr) || count != stat.cbSize.QuadPart)
|
|
|
|
{
|
|
|
|
WARN("failed to read stream: %08x\n", hr);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = strdupW(MSI_RecordGetString(rec, 1));
|
|
|
|
if (!name)
|
2010-02-04 10:01:09 +01:00
|
|
|
{
|
|
|
|
WARN("failed to retrieve stream name\n");
|
2007-04-25 12:22:01 +02:00
|
|
|
goto done;
|
2010-02-04 10:01:09 +01:00
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
r = write_stream_data(sv->db->storage, name, data, count, FALSE);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
WARN("failed to write stream data: %d\n", r);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = create_stream(sv, name, FALSE, NULL);
|
|
|
|
if (!stream)
|
|
|
|
goto done;
|
|
|
|
|
2015-02-13 13:37:49 +01:00
|
|
|
encname = encode_streamname(FALSE, name);
|
2010-02-04 10:01:32 +01:00
|
|
|
hr = IStorage_OpenStream(sv->db->storage, encname, 0,
|
2010-02-04 10:01:09 +01:00
|
|
|
STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream->stream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("failed to open stream: %08x\n", hr);
|
2012-12-08 13:08:57 +01:00
|
|
|
msi_free(stream);
|
2010-02-04 10:01:09 +01:00
|
|
|
goto done;
|
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2008-02-04 18:28:36 +01:00
|
|
|
sv->streams[row] = stream;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
done:
|
|
|
|
msi_free(name);
|
|
|
|
msi_free(data);
|
2010-02-04 10:01:32 +01:00
|
|
|
msi_free(encname);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
IStream_Release(stm);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
static UINT STREAMS_insert_row(struct tagMSIVIEW *view, MSIRECORD *rec, UINT row, BOOL temporary)
|
2008-02-04 18:28:36 +01:00
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
2010-02-04 10:02:26 +01:00
|
|
|
UINT i;
|
2008-02-04 18:28:36 +01:00
|
|
|
|
2010-02-04 10:01:09 +01:00
|
|
|
TRACE("(%p, %p, %d, %d)\n", view, rec, row, temporary);
|
|
|
|
|
2008-02-04 18:28:36 +01:00
|
|
|
if (!streams_set_table_size(sv, ++sv->num_rows))
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
if (row == -1)
|
|
|
|
row = sv->num_rows - 1;
|
|
|
|
|
2010-02-04 10:02:26 +01:00
|
|
|
/* shift the rows to make room for the new row */
|
|
|
|
for (i = sv->num_rows - 1; i > row; i--)
|
|
|
|
{
|
|
|
|
sv->streams[i] = sv->streams[i - 1];
|
|
|
|
}
|
2009-03-02 06:41:22 +01:00
|
|
|
|
|
|
|
return STREAMS_set_row(view, row, rec, 0);
|
2008-02-04 18:28:36 +01:00
|
|
|
}
|
|
|
|
|
2007-06-18 22:49:31 +02:00
|
|
|
static UINT STREAMS_delete_row(struct tagMSIVIEW *view, UINT row)
|
|
|
|
{
|
|
|
|
FIXME("(%p %d): stub!\n", view, row);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-04-25 12:22:01 +02:00
|
|
|
static UINT STREAMS_execute(struct tagMSIVIEW *view, MSIRECORD *record)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %p)\n", view, record);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_close(struct tagMSIVIEW *view)
|
|
|
|
{
|
|
|
|
TRACE("(%p)\n", view);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_get_dimensions(struct tagMSIVIEW *view, UINT *rows, UINT *cols)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
|
|
|
|
TRACE("(%p, %p, %p)\n", view, rows, cols);
|
|
|
|
|
|
|
|
if (cols) *cols = NUM_STREAMS_COLS;
|
|
|
|
if (rows) *rows = sv->num_rows;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-07-27 10:53:10 +02:00
|
|
|
static UINT STREAMS_get_column_info( struct tagMSIVIEW *view, UINT n, LPCWSTR *name,
|
|
|
|
UINT *type, BOOL *temporary, LPCWSTR *table_name )
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2009-10-18 18:41:41 +02:00
|
|
|
TRACE("(%p, %d, %p, %p, %p, %p)\n", view, n, name, type, temporary,
|
|
|
|
table_name);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
if (n == 0 || n > NUM_STREAMS_COLS)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
switch (n)
|
|
|
|
{
|
|
|
|
case 1:
|
2011-07-27 10:53:10 +02:00
|
|
|
if (name) *name = szName;
|
2010-02-04 10:02:59 +01:00
|
|
|
if (type) *type = MSITYPE_STRING | MSITYPE_VALID | MAX_STREAM_NAME_LEN;
|
2007-04-25 12:22:01 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2011-07-27 10:53:10 +02:00
|
|
|
if (name) *name = szData;
|
2007-04-25 12:22:01 +02:00
|
|
|
if (type) *type = MSITYPE_STRING | MSITYPE_VALID | MSITYPE_NULLABLE;
|
|
|
|
break;
|
|
|
|
}
|
2011-07-27 10:53:10 +02:00
|
|
|
if (table_name) *table_name = szStreams;
|
|
|
|
if (temporary) *temporary = FALSE;
|
2007-04-25 12:22:01 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-02-04 18:28:36 +01:00
|
|
|
static UINT streams_find_row(MSISTREAMSVIEW *sv, MSIRECORD *rec, UINT *row)
|
|
|
|
{
|
|
|
|
LPCWSTR str;
|
2011-08-30 18:17:21 +02:00
|
|
|
UINT r, i, id, data;
|
2008-02-04 18:28:36 +01:00
|
|
|
|
|
|
|
str = MSI_RecordGetString(rec, 1);
|
2012-10-29 12:12:50 +01:00
|
|
|
r = msi_string2id(sv->db->strings, str, -1, &id);
|
2011-08-30 18:17:21 +02:00
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2008-02-04 18:28:36 +01:00
|
|
|
|
|
|
|
for (i = 0; i < sv->num_rows; i++)
|
|
|
|
{
|
|
|
|
STREAMS_fetch_int(&sv->view, i, 1, &data);
|
|
|
|
|
|
|
|
if (data == id)
|
|
|
|
{
|
|
|
|
*row = i;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT streams_modify_update(struct tagMSIVIEW *view, MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
UINT r, row;
|
|
|
|
|
|
|
|
r = streams_find_row(sv, rec, &row);
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
return STREAMS_set_row(view, row, rec, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT streams_modify_assign(struct tagMSIVIEW *view, MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
UINT r, row;
|
|
|
|
|
|
|
|
r = streams_find_row(sv, rec, &row);
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
return streams_modify_update(view, rec);
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
return STREAMS_insert_row(view, rec, -1, FALSE);
|
2008-02-04 18:28:36 +01:00
|
|
|
}
|
|
|
|
|
2007-07-27 02:40:38 +02:00
|
|
|
static UINT STREAMS_modify(struct tagMSIVIEW *view, MSIMODIFY eModifyMode, MSIRECORD *rec, UINT row)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2007-10-18 05:58:31 +02:00
|
|
|
UINT r;
|
|
|
|
|
|
|
|
TRACE("%p %d %p\n", view, eModifyMode, rec);
|
|
|
|
|
|
|
|
switch (eModifyMode)
|
|
|
|
{
|
2008-02-04 18:28:36 +01:00
|
|
|
case MSIMODIFY_ASSIGN:
|
|
|
|
r = streams_modify_assign(view, rec);
|
|
|
|
break;
|
|
|
|
|
2007-10-18 05:58:31 +02:00
|
|
|
case MSIMODIFY_INSERT:
|
2009-03-02 06:41:22 +01:00
|
|
|
r = STREAMS_insert_row(view, rec, -1, FALSE);
|
2007-10-18 05:58:31 +02:00
|
|
|
break;
|
|
|
|
|
2008-02-04 18:28:36 +01:00
|
|
|
case MSIMODIFY_UPDATE:
|
|
|
|
r = streams_modify_update(view, rec);
|
|
|
|
break;
|
|
|
|
|
2007-10-18 05:58:31 +02:00
|
|
|
case MSIMODIFY_VALIDATE_NEW:
|
|
|
|
case MSIMODIFY_INSERT_TEMPORARY:
|
|
|
|
case MSIMODIFY_REFRESH:
|
|
|
|
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;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_delete(struct tagMSIVIEW *view)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
2008-02-17 13:23:38 +01:00
|
|
|
UINT i;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", view);
|
|
|
|
|
|
|
|
for (i = 0; i < sv->num_rows; i++)
|
|
|
|
{
|
2009-12-18 11:02:30 +01:00
|
|
|
if (sv->streams[i])
|
|
|
|
{
|
|
|
|
if (sv->streams[i]->stream)
|
|
|
|
IStream_Release(sv->streams[i]->stream);
|
|
|
|
msi_free(sv->streams[i]);
|
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
msi_free(sv->streams);
|
2009-12-14 04:36:27 +01:00
|
|
|
msi_free(sv);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_find_matching_rows(struct tagMSIVIEW *view, UINT col,
|
|
|
|
UINT val, UINT *row, MSIITERHANDLE *handle)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
2009-12-30 21:24:27 +01:00
|
|
|
UINT index = PtrToUlong(*handle);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2010-02-04 10:01:09 +01:00
|
|
|
TRACE("(%p, %d, %d, %p, %p)\n", view, col, val, row, handle);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
if (col == 0 || col > NUM_STREAMS_COLS)
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
|
|
|
|
while (index < sv->num_rows)
|
|
|
|
{
|
|
|
|
if (sv->streams[index]->str_index == val)
|
|
|
|
{
|
|
|
|
*row = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
2009-12-30 21:24:27 +01:00
|
|
|
*handle = UlongToPtr(++index);
|
2010-02-04 10:03:21 +01:00
|
|
|
|
|
|
|
if (index > sv->num_rows)
|
2007-04-25 12:22:01 +02:00
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MSIVIEWOPS streams_ops =
|
|
|
|
{
|
|
|
|
STREAMS_fetch_int,
|
|
|
|
STREAMS_fetch_stream,
|
2007-07-27 02:40:38 +02:00
|
|
|
STREAMS_get_row,
|
2007-04-25 12:22:01 +02:00
|
|
|
STREAMS_set_row,
|
|
|
|
STREAMS_insert_row,
|
2007-06-18 22:49:31 +02:00
|
|
|
STREAMS_delete_row,
|
2007-04-25 12:22:01 +02:00
|
|
|
STREAMS_execute,
|
|
|
|
STREAMS_close,
|
|
|
|
STREAMS_get_dimensions,
|
|
|
|
STREAMS_get_column_info,
|
|
|
|
STREAMS_modify,
|
|
|
|
STREAMS_delete,
|
2007-07-19 03:21:00 +02:00
|
|
|
STREAMS_find_matching_rows,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2007-07-20 23:01:13 +02:00
|
|
|
NULL,
|
2007-07-21 03:41:16 +02:00
|
|
|
NULL,
|
2007-12-18 02:35:31 +01:00
|
|
|
NULL,
|
2008-10-02 22:56:54 +02:00
|
|
|
NULL,
|
2007-04-25 12:22:01 +02:00
|
|
|
};
|
|
|
|
|
2008-02-15 21:14:22 +01:00
|
|
|
static INT add_streams_to_table(MSISTREAMSVIEW *sv)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
|
|
|
IEnumSTATSTG *stgenum = NULL;
|
|
|
|
STATSTG stat;
|
|
|
|
STREAM *stream = NULL;
|
|
|
|
HRESULT hr;
|
2010-02-19 12:27:36 +01:00
|
|
|
UINT r, count = 0, size;
|
|
|
|
LPWSTR encname;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
hr = IStorage_EnumElements(sv->db->storage, 0, NULL, 0, &stgenum);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
sv->max_streams = 1;
|
2009-06-10 17:13:59 +02:00
|
|
|
sv->streams = msi_alloc_zero(sizeof(STREAM *));
|
2007-04-25 12:22:01 +02:00
|
|
|
if (!sv->streams)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
size = 0;
|
|
|
|
hr = IEnumSTATSTG_Next(stgenum, 1, &stat, &size);
|
|
|
|
if (FAILED(hr) || !size)
|
|
|
|
break;
|
|
|
|
|
2008-08-19 05:57:24 +02:00
|
|
|
if (stat.type != STGTY_STREAM)
|
2010-02-19 12:27:02 +01:00
|
|
|
{
|
|
|
|
CoTaskMemFree(stat.pwcsName);
|
2008-08-19 05:57:24 +02:00
|
|
|
continue;
|
2010-02-19 12:27:02 +01:00
|
|
|
}
|
2008-08-19 05:57:24 +02:00
|
|
|
|
2007-04-25 12:22:01 +02:00
|
|
|
/* table streams are not in the _Streams table */
|
|
|
|
if (*stat.pwcsName == 0x4840)
|
2007-12-26 12:02:55 +01:00
|
|
|
{
|
|
|
|
CoTaskMemFree(stat.pwcsName);
|
2007-04-25 12:22:01 +02:00
|
|
|
continue;
|
2007-12-26 12:02:55 +01:00
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
stream = create_stream(sv, stat.pwcsName, TRUE, NULL);
|
|
|
|
if (!stream)
|
|
|
|
{
|
|
|
|
count = -1;
|
2007-12-26 12:02:55 +01:00
|
|
|
CoTaskMemFree(stat.pwcsName);
|
2007-04-25 12:22:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-02-22 12:25:21 +01:00
|
|
|
/* these streams appear to be unencoded */
|
|
|
|
if (*stat.pwcsName == 0x0005)
|
2010-02-19 12:27:36 +01:00
|
|
|
{
|
2011-05-06 14:40:48 +02:00
|
|
|
r = msi_get_raw_stream(sv->db, stat.pwcsName, &stream->stream);
|
2010-02-19 12:27:36 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
encname = encode_streamname(FALSE, stat.pwcsName);
|
2011-05-06 14:40:48 +02:00
|
|
|
r = msi_get_raw_stream(sv->db, encname, &stream->stream);
|
2010-02-19 12:27:36 +01:00
|
|
|
msi_free(encname);
|
|
|
|
}
|
2007-12-26 12:02:55 +01:00
|
|
|
CoTaskMemFree(stat.pwcsName);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2010-02-19 12:27:36 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
2010-02-04 10:01:09 +01:00
|
|
|
{
|
2010-02-19 12:27:36 +01:00
|
|
|
WARN("unable to get stream %u\n", r);
|
2010-02-04 10:01:09 +01:00
|
|
|
count = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-02-04 18:28:36 +01:00
|
|
|
if (!streams_set_table_size(sv, ++count))
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
|
|
|
count = -1;
|
|
|
|
break;
|
|
|
|
}
|
2008-02-04 18:28:36 +01:00
|
|
|
|
|
|
|
sv->streams[count - 1] = stream;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
IEnumSTATSTG_Release(stgenum);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT STREAMS_CreateView(MSIDATABASE *db, MSIVIEW **view)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv;
|
2008-02-15 21:14:22 +01:00
|
|
|
INT rows;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", db, view);
|
|
|
|
|
2011-06-07 10:34:22 +02:00
|
|
|
sv = msi_alloc_zero( sizeof(MSISTREAMSVIEW) );
|
2007-04-25 12:22:01 +02:00
|
|
|
if (!sv)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
sv->view.ops = &streams_ops;
|
|
|
|
sv->db = db;
|
2008-02-15 21:14:22 +01:00
|
|
|
rows = add_streams_to_table(sv);
|
|
|
|
if (rows < 0)
|
2009-05-28 15:04:17 +02:00
|
|
|
{
|
|
|
|
msi_free( sv );
|
2007-04-25 12:22:01 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2009-05-28 15:04:17 +02:00
|
|
|
}
|
2008-02-15 21:14:22 +01:00
|
|
|
sv->num_rows = rows;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
*view = (MSIVIEW *)sv;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|