2007-04-25 12:22:01 +02:00
|
|
|
/*
|
|
|
|
* Implementation of the Microsoft Installer (msi.dll)
|
|
|
|
*
|
|
|
|
* Copyright 2007 James Hawkins
|
2015-02-13 13:39:38 +01:00
|
|
|
* Copyright 2015 Hans Leidekker for CodeWeavers
|
2007-04-25 12:22:01 +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., 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 tagMSISTREAMSVIEW
|
|
|
|
{
|
|
|
|
MSIVIEW view;
|
|
|
|
MSIDATABASE *db;
|
2015-02-13 13:39:38 +01:00
|
|
|
UINT num_cols;
|
2007-04-25 12:22:01 +02:00
|
|
|
} MSISTREAMSVIEW;
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
static BOOL streams_resize_table( MSIDATABASE *db, UINT size )
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
if (!db->num_streams_allocated)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
if (!(db->streams = msi_alloc_zero( size * sizeof(MSISTREAM) ))) return FALSE;
|
|
|
|
db->num_streams_allocated = size;
|
|
|
|
return TRUE;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
2015-02-13 13:39:38 +01:00
|
|
|
while (size >= db->num_streams_allocated)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
MSISTREAM *tmp;
|
|
|
|
UINT new_size = db->num_streams_allocated * 2;
|
|
|
|
if (!(tmp = msi_realloc_zero( db->streams, new_size * sizeof(MSISTREAM) ))) return FALSE;
|
|
|
|
db->streams = tmp;
|
|
|
|
db->num_streams_allocated = new_size;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
2015-02-13 13:39:38 +01:00
|
|
|
return TRUE;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (row >= sv->db->num_streams)
|
2007-04-25 12:22:01 +02:00
|
|
|
return ERROR_NO_MORE_ITEMS;
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
*val = sv->db->streams[row].str_index;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT STREAMS_fetch_stream(struct tagMSIVIEW *view, UINT row, UINT col, IStream **stm)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
2015-02-13 13:39:38 +01:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
HRESULT hr;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %d, %d, %p)\n", view, row, col, stm);
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (row >= sv->db->num_streams)
|
2007-04-25 12:22:01 +02:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
pos.QuadPart = 0;
|
|
|
|
hr = IStream_Seek( sv->db->streams[row].stream, pos, STREAM_SEEK_SET, NULL );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
*stm = sv->db->streams[row].stream;
|
|
|
|
IStream_AddRef( *stm );
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-01-26 23:58:58 +01:00
|
|
|
static UINT STREAMS_set_string( struct tagMSIVIEW *view, UINT row, UINT col, const WCHAR *val, int len )
|
|
|
|
{
|
|
|
|
ERR("Cannot modify primary key.\n");
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
|
2019-01-29 05:11:08 +01:00
|
|
|
static UINT STREAMS_set_stream( MSIVIEW *view, UINT row, UINT col, IStream *stream )
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
IStream *prev;
|
|
|
|
|
|
|
|
TRACE("view %p, row %u, col %u, stream %p.\n", view, row, col, stream);
|
|
|
|
|
|
|
|
prev = sv->db->streams[row].stream;
|
|
|
|
IStream_AddRef(sv->db->streams[row].stream = stream);
|
|
|
|
if (prev) IStream_Release(prev);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (row > sv->db->num_streams || mask >= (1 << sv->num_cols))
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (mask & 1)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
const WCHAR *name = MSI_RecordGetString( rec, 1 );
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (!name) return ERROR_INVALID_PARAMETER;
|
2019-01-24 07:07:32 +01:00
|
|
|
sv->db->streams[row].str_index = msi_add_string( sv->db->strings, name, -1, FALSE );
|
2010-02-04 10:01:09 +01:00
|
|
|
}
|
2015-02-13 13:39:38 +01:00
|
|
|
if (mask & 2)
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
IStream *old, *new;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT r;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
r = MSI_RecordGetIStream( rec, 2, &new );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
old = sv->db->streams[row].stream;
|
|
|
|
hr = IStream_QueryInterface( new, &IID_IStream, (void **)&sv->db->streams[row].stream );
|
2018-10-01 17:01:48 +02:00
|
|
|
IStream_Release( new );
|
2015-02-13 13:39:38 +01:00
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
if (old) IStream_Release( old );
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
static UINT streams_find_row( MSISTREAMSVIEW *sv, MSIRECORD *rec, UINT *row )
|
|
|
|
{
|
|
|
|
const WCHAR *str;
|
|
|
|
UINT r, i, id, val;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
str = MSI_RecordGetString( rec, 1 );
|
|
|
|
r = msi_string2id( sv->db->strings, str, -1, &id );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
for (i = 0; i < sv->db->num_streams; i++)
|
|
|
|
{
|
|
|
|
STREAMS_fetch_int( &sv->view, i, 1, &val );
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (val == id)
|
|
|
|
{
|
|
|
|
if (row) *row = i;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
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;
|
2015-02-13 13:39:38 +01:00
|
|
|
UINT i, r, num_rows = sv->db->num_streams + 1;
|
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);
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
r = streams_find_row( sv, rec, NULL );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
if (!streams_resize_table( sv->db, num_rows ))
|
2008-02-04 18:28:36 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
2009-03-02 06:41:22 +01:00
|
|
|
if (row == -1)
|
2015-02-13 13:39:38 +01:00
|
|
|
row = num_rows - 1;
|
2009-03-02 06:41:22 +01:00
|
|
|
|
2010-02-04 10:02:26 +01:00
|
|
|
/* shift the rows to make room for the new row */
|
2015-02-13 13:39:38 +01:00
|
|
|
for (i = num_rows - 1; i > row; i--)
|
2010-02-04 10:02:26 +01:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
sv->db->streams[i] = sv->db->streams[i - 1];
|
2010-02-04 10:02:26 +01:00
|
|
|
}
|
2009-03-02 06:41:22 +01:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
r = STREAMS_set_row( view, row, rec, (1 << sv->num_cols) - 1 );
|
|
|
|
if (r == ERROR_SUCCESS)
|
|
|
|
sv->db->num_streams = num_rows;
|
|
|
|
|
|
|
|
return r;
|
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);
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (cols) *cols = sv->num_cols;
|
|
|
|
if (rows) *rows = sv->db->num_streams;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
|
|
|
|
|
|
|
TRACE("(%p, %d, %p, %p, %p, %p)\n", view, n, name, type, temporary, table_name);
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (!n || n > sv->num_cols)
|
2007-04-25 12:22:01 +02:00
|
|
|
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_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;
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
return STREAMS_set_row( view, row, rec, (1 << sv->num_cols) - 1 );
|
2008-02-04 18:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static UINT streams_modify_assign(struct tagMSIVIEW *view, MSIRECORD *rec)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv = (MSISTREAMSVIEW *)view;
|
2015-02-13 13:39:38 +01:00
|
|
|
UINT r;
|
2008-02-04 18:28:36 +01:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
r = streams_find_row( sv, rec, NULL );
|
2008-02-04 18:28:36 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", view);
|
|
|
|
|
2009-12-14 04:36:27 +01:00
|
|
|
msi_free(sv);
|
2007-04-25 12:22:01 +02:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MSIVIEWOPS streams_ops =
|
|
|
|
{
|
|
|
|
STREAMS_fetch_int,
|
|
|
|
STREAMS_fetch_stream,
|
2019-01-26 23:58:58 +01:00
|
|
|
NULL,
|
|
|
|
STREAMS_set_string,
|
2019-01-29 05:11:08 +01:00
|
|
|
STREAMS_set_stream,
|
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
|
|
|
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,
|
2007-04-25 12:22:01 +02:00
|
|
|
};
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
static HRESULT open_stream( MSIDATABASE *db, const WCHAR *name, IStream **stream )
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
hr = IStorage_OpenStream( db->storage, name, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, stream );
|
|
|
|
if (FAILED( hr ))
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
MSITRANSFORM *transform;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
LIST_FOR_EACH_ENTRY( transform, &db->transforms, MSITRANSFORM, entry )
|
2010-02-19 12:27:02 +01:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
hr = IStorage_OpenStream( transform->stg, name, NULL, STGM_READ|STGM_SHARE_EXCLUSIVE, 0, stream );
|
|
|
|
if (SUCCEEDED( hr ))
|
|
|
|
break;
|
2010-02-19 12:27:02 +01:00
|
|
|
}
|
2015-02-13 13:39:38 +01:00
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MSISTREAM *find_stream( MSIDATABASE *db, const WCHAR *name )
|
|
|
|
{
|
|
|
|
UINT r, id, i;
|
|
|
|
|
|
|
|
r = msi_string2id( db->strings, name, -1, &id );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < db->num_streams; i++)
|
|
|
|
{
|
|
|
|
if (db->streams[i].str_index == id) return &db->streams[i];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT append_stream( MSIDATABASE *db, const WCHAR *name, IStream *stream )
|
|
|
|
{
|
|
|
|
UINT i = db->num_streams;
|
|
|
|
|
|
|
|
if (!streams_resize_table( db, db->num_streams + 1 ))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
2019-01-24 07:07:32 +01:00
|
|
|
db->streams[i].str_index = msi_add_string( db->strings, name, -1, FALSE );
|
2015-02-13 13:39:38 +01:00
|
|
|
db->streams[i].stream = stream;
|
|
|
|
db->num_streams++;
|
|
|
|
|
2015-03-04 14:29:29 +01:00
|
|
|
TRACE("added %s\n", debugstr_w( name ));
|
2015-02-13 13:39:38 +01:00
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT load_streams( MSIDATABASE *db )
|
|
|
|
{
|
2015-03-04 14:29:29 +01:00
|
|
|
WCHAR decoded[MAX_STREAM_NAME_LEN + 1];
|
2015-02-13 13:39:38 +01:00
|
|
|
IEnumSTATSTG *stgenum;
|
|
|
|
STATSTG stat;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT count, r = ERROR_SUCCESS;
|
|
|
|
IStream *stream;
|
|
|
|
|
|
|
|
hr = IStorage_EnumElements( db->storage, 0, NULL, 0, &stgenum );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
hr = IEnumSTATSTG_Next( stgenum, 1, &stat, &count );
|
|
|
|
if (FAILED( hr ) || !count)
|
|
|
|
break;
|
2008-08-19 05:57:24 +02:00
|
|
|
|
2007-04-25 12:22:01 +02:00
|
|
|
/* table streams are not in the _Streams table */
|
2015-03-04 14:29:29 +01:00
|
|
|
if (stat.type != STGTY_STREAM || *stat.pwcsName == 0x4840)
|
2007-12-26 12:02:55 +01:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
CoTaskMemFree( stat.pwcsName );
|
2007-04-25 12:22:01 +02:00
|
|
|
continue;
|
2007-12-26 12:02:55 +01:00
|
|
|
}
|
2015-03-04 14:29:29 +01:00
|
|
|
decode_streamname( stat.pwcsName, decoded );
|
|
|
|
if (find_stream( db, decoded ))
|
|
|
|
{
|
|
|
|
CoTaskMemFree( stat.pwcsName );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
TRACE("found new stream %s\n", debugstr_w( decoded ));
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
hr = open_stream( db, stat.pwcsName, &stream );
|
2015-03-04 14:29:29 +01:00
|
|
|
CoTaskMemFree( stat.pwcsName );
|
2015-02-13 13:39:38 +01:00
|
|
|
if (FAILED( hr ))
|
2007-04-25 12:22:01 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
ERR("unable to open stream %08x\n", hr);
|
|
|
|
r = ERROR_FUNCTION_FAILED;
|
2007-04-25 12:22:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-04 14:29:29 +01:00
|
|
|
r = append_stream( db, decoded, stream );
|
2010-02-19 12:27:36 +01:00
|
|
|
if (r != ERROR_SUCCESS)
|
2010-02-04 10:01:09 +01:00
|
|
|
break;
|
2015-02-13 13:39:38 +01:00
|
|
|
}
|
2010-02-04 10:01:09 +01:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
TRACE("loaded %u streams\n", db->num_streams);
|
|
|
|
IEnumSTATSTG_Release( stgenum );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT msi_get_stream( MSIDATABASE *db, const WCHAR *name, IStream **ret )
|
|
|
|
{
|
|
|
|
MSISTREAM *stream;
|
|
|
|
WCHAR *encname;
|
|
|
|
HRESULT hr;
|
|
|
|
UINT r;
|
2008-02-04 18:28:36 +01:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if ((stream = find_stream( db, name )))
|
|
|
|
{
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
hr = IStream_Seek( stream->stream, pos, STREAM_SEEK_SET, NULL );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
*ret = stream->stream;
|
|
|
|
IStream_AddRef( *ret );
|
|
|
|
return ERROR_SUCCESS;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
if (!(encname = encode_streamname( FALSE, name )))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
hr = open_stream( db, encname, ret );
|
|
|
|
msi_free( encname );
|
|
|
|
if (FAILED( hr ))
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
|
|
|
|
r = append_stream( db, name, *ret );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
IStream_Release( *ret );
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
IStream_AddRef( *ret );
|
|
|
|
return ERROR_SUCCESS;
|
2007-04-25 12:22:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
UINT STREAMS_CreateView(MSIDATABASE *db, MSIVIEW **view)
|
|
|
|
{
|
|
|
|
MSISTREAMSVIEW *sv;
|
2015-02-13 13:39:38 +01:00
|
|
|
UINT r;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", db, view);
|
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
r = load_streams( db );
|
|
|
|
if (r != ERROR_SUCCESS)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (!(sv = msi_alloc_zero( sizeof(MSISTREAMSVIEW) )))
|
|
|
|
return ERROR_OUTOFMEMORY;
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
sv->view.ops = &streams_ops;
|
2015-02-13 13:39:38 +01:00
|
|
|
sv->num_cols = NUM_STREAMS_COLS;
|
2007-04-25 12:22:01 +02:00
|
|
|
sv->db = db;
|
2015-02-13 13:39:38 +01:00
|
|
|
|
|
|
|
*view = (MSIVIEW *)sv;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT write_stream( IStream *dst, IStream *src )
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
char buf[4096];
|
|
|
|
STATSTG stat;
|
|
|
|
LARGE_INTEGER pos;
|
|
|
|
UINT count, size;
|
|
|
|
|
|
|
|
hr = IStream_Stat( src, &stat, STATFLAG_NONAME );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
hr = IStream_SetSize( dst, stat.cbSize );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
hr = IStream_Seek( dst, pos, STREAM_SEEK_SET, NULL );
|
|
|
|
if (FAILED( hr )) return hr;
|
|
|
|
|
|
|
|
for (;;)
|
2009-05-28 15:04:17 +02:00
|
|
|
{
|
2015-02-13 13:39:38 +01:00
|
|
|
size = min( sizeof(buf), stat.cbSize.QuadPart );
|
|
|
|
hr = IStream_Read( src, buf, size, &count );
|
|
|
|
if (FAILED( hr ) || count != size)
|
|
|
|
{
|
|
|
|
WARN("failed to read stream: %08x\n", hr);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
stat.cbSize.QuadPart -= count;
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
size = count;
|
|
|
|
hr = IStream_Write( dst, buf, size, &count );
|
|
|
|
if (FAILED( hr ) || count != size)
|
|
|
|
{
|
|
|
|
WARN("failed to write stream: %08x\n", hr);
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!stat.cbSize.QuadPart) break;
|
2009-05-28 15:04:17 +02:00
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
2015-02-13 13:39:38 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT msi_commit_streams( MSIDATABASE *db )
|
|
|
|
{
|
|
|
|
UINT i;
|
|
|
|
const WCHAR *name;
|
|
|
|
WCHAR *encname;
|
|
|
|
IStream *stream;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("got %u streams\n", db->num_streams);
|
|
|
|
|
|
|
|
for (i = 0; i < db->num_streams; i++)
|
|
|
|
{
|
|
|
|
name = msi_string_lookup( db->strings, db->streams[i].str_index, NULL );
|
|
|
|
if (!(encname = encode_streamname( FALSE, name ))) return ERROR_OUTOFMEMORY;
|
|
|
|
|
2015-03-16 10:56:35 +01:00
|
|
|
hr = IStorage_CreateStream( db->storage, encname, STGM_WRITE|STGM_SHARE_EXCLUSIVE, 0, 0, &stream );
|
|
|
|
if (SUCCEEDED( hr ))
|
2015-02-13 13:39:38 +01:00
|
|
|
{
|
2015-03-16 10:56:35 +01:00
|
|
|
hr = write_stream( stream, db->streams[i].stream );
|
2015-02-13 13:39:38 +01:00
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
2015-03-16 10:56:35 +01:00
|
|
|
ERR("failed to write stream %s (hr = %08x)\n", debugstr_w(encname), hr);
|
2015-02-13 13:39:38 +01:00
|
|
|
msi_free( encname );
|
2015-03-16 10:56:35 +01:00
|
|
|
IStream_Release( stream );
|
2015-02-13 13:39:38 +01:00
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
2015-03-16 10:56:35 +01:00
|
|
|
hr = IStream_Commit( stream, 0 );
|
|
|
|
IStream_Release( stream );
|
2015-02-13 13:39:38 +01:00
|
|
|
if (FAILED( hr ))
|
|
|
|
{
|
2015-03-16 10:56:35 +01:00
|
|
|
ERR("failed to commit stream %s (hr = %08x)\n", debugstr_w(encname), hr);
|
2015-02-13 13:39:38 +01:00
|
|
|
msi_free( encname );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 10:56:35 +01:00
|
|
|
else if (hr != STG_E_FILEALREADYEXISTS)
|
2015-02-13 13:39:38 +01:00
|
|
|
{
|
2015-03-16 10:56:35 +01:00
|
|
|
ERR("failed to create stream %s (hr = %08x)\n", debugstr_w(encname), hr);
|
2015-02-13 13:39:38 +01:00
|
|
|
msi_free( encname );
|
|
|
|
return ERROR_FUNCTION_FAILED;
|
|
|
|
}
|
|
|
|
msi_free( encname );
|
|
|
|
}
|
2007-04-25 12:22:01 +02:00
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|