From 552c9ac5a0b78efacbc53426f9a61fac100e87cf Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sun, 2 Dec 2012 15:43:19 +0100 Subject: separate the input and output storages for LibmsiDatabase --- libmsi/database.c | 22 +++++++++++++--------- libmsi/msipriv.h | 3 ++- libmsi/storages.c | 2 +- libmsi/streams.c | 6 +++--- libmsi/suminfo.c | 4 ++-- libmsi/table.c | 8 ++++---- 6 files changed, 25 insertions(+), 20 deletions(-) (limited to 'libmsi') diff --git a/libmsi/database.c b/libmsi/database.c index c2f283f..d902756 100644 --- a/libmsi/database.c +++ b/libmsi/database.c @@ -145,7 +145,7 @@ unsigned msi_open_storage( LibmsiDatabase *db, const WCHAR *stname ) goto done; } - hr = IStorage_OpenStorage(db->storage, stname, NULL, + hr = IStorage_OpenStorage(db->infile, stname, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, &storage->stg); if (FAILED(hr)) @@ -199,7 +199,7 @@ unsigned msi_create_storage( LibmsiDatabase *db, const WCHAR *stname, IStream *s if (r != LIBMSI_RESULT_SUCCESS) goto done; - hr = IStorage_CreateStorage(db->storage, stname, + hr = IStorage_CreateStorage(db->outfile, stname, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &substg); if (FAILED(hr)) @@ -320,10 +320,10 @@ unsigned msi_get_raw_stream( LibmsiDatabase *db, const WCHAR *stname, IStream ** decode_streamname( stname, decoded ); TRACE("%s -> %s\n", debugstr_w(stname), debugstr_w(decoded)); - if (msi_clone_open_stream( db, db->storage, stname, stm ) == LIBMSI_RESULT_SUCCESS) + if (msi_clone_open_stream( db, db->infile, stname, stm ) == LIBMSI_RESULT_SUCCESS) return LIBMSI_RESULT_SUCCESS; - r = IStorage_OpenStream( db->storage, stname, NULL, + r = IStorage_OpenStream( db->infile, stname, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, stm ); if( FAILED( r ) ) { @@ -340,7 +340,7 @@ unsigned msi_get_raw_stream( LibmsiDatabase *db, const WCHAR *stname, IStream ** } } } - else stg = db->storage; + else stg = db->infile; if( SUCCEEDED(r) ) { @@ -438,7 +438,8 @@ static VOID _libmsi_database_destroy( LibmsiObject *arg ) free_storages( db ); free_transforms( db ); if (db->strings) msi_destroy_stringtable( db->strings ); - IStorage_Release( db->storage ); + IStorage_Release( db->infile ); + IStorage_Release( db->outfile ); if (db->deletefile) { unlink( db->deletefile ); @@ -598,7 +599,11 @@ LibmsiResult libmsi_database_open(const char *szDBPath, const char *szPersist, L if( TRACE_ON( msi ) ) enum_stream_names( stg ); - db->storage = stg; + db->infile = stg; + IStorage_AddRef( db->infile ); + db->outfile = stg; + IStorage_AddRef( db->outfile ); + db->mode = szMode; if (created) db->deletefile = strdup( szDBPath ); @@ -607,14 +612,13 @@ LibmsiResult libmsi_database_open(const char *szDBPath, const char *szPersist, L list_init( &db->streams ); list_init( &db->storages ); - db->strings = msi_load_string_table( stg, &db->bytes_per_strref ); + db->strings = msi_load_string_table( db->infile, &db->bytes_per_strref ); if( !db->strings ) goto end; ret = LIBMSI_RESULT_SUCCESS; msiobj_addref( &db->hdr ); - IStorage_AddRef( stg ); *pdb = db; end: diff --git a/libmsi/msipriv.h b/libmsi/msipriv.h index 689cb22..9ab7854 100644 --- a/libmsi/msipriv.h +++ b/libmsi/msipriv.h @@ -73,7 +73,8 @@ struct LibmsiObject typedef struct LibmsiDatabase { LibmsiObject hdr; - IStorage *storage; + IStorage *infile; + IStorage *outfile; string_table *strings; unsigned bytes_per_strref; char *path; diff --git a/libmsi/storages.c b/libmsi/storages.c index d8f8645..0c4e8e6 100644 --- a/libmsi/storages.c +++ b/libmsi/storages.c @@ -328,7 +328,7 @@ static int add_storages_to_table(LibmsiStorageView *sv) unsigned r; unsigned count = 0, size; - hr = IStorage_EnumElements(sv->db->storage, 0, NULL, 0, &stgenum); + hr = IStorage_EnumElements(sv->db->infile, 0, NULL, 0, &stgenum); if (FAILED(hr)) return -1; diff --git a/libmsi/streams.c b/libmsi/streams.c index f60e5e4..3defa65 100644 --- a/libmsi/streams.c +++ b/libmsi/streams.c @@ -184,7 +184,7 @@ static unsigned streams_view_set_row(LibmsiView *view, unsigned row, LibmsiRecor encname = encode_streamname(false, name); msi_destroy_stream(sv->db, encname); - r = write_stream_data(sv->db->storage, name, data, count, false); + r = write_stream_data(sv->db->outfile, name, data, count, false); if (r != LIBMSI_RESULT_SUCCESS) { WARN("failed to write stream data: %d\n", r); @@ -195,7 +195,7 @@ static unsigned streams_view_set_row(LibmsiView *view, unsigned row, LibmsiRecor if (!stream) goto done; - hr = IStorage_OpenStream(sv->db->storage, encname, 0, + hr = IStorage_OpenStream(sv->db->infile, encname, 0, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream->stream); if (FAILED(hr)) { @@ -400,7 +400,7 @@ static int add_streams_to_table(LibmsiStreamsView *sv) HRESULT hr; unsigned r, count = 0, size; - hr = IStorage_EnumElements(sv->db->storage, 0, NULL, 0, &stgenum); + hr = IStorage_EnumElements(sv->db->infile, 0, NULL, 0, &stgenum); if (FAILED(hr)) return -1; diff --git a/libmsi/suminfo.c b/libmsi/suminfo.c index bbf42ee..c98aef1 100644 --- a/libmsi/suminfo.c +++ b/libmsi/suminfo.c @@ -452,7 +452,7 @@ LibmsiSummaryInfo *_libmsi_get_summary_information( LibmsiDatabase *db, unsigned /* read the stream... if we fail, we'll start with an empty property set */ grfMode = STGM_READ | STGM_SHARE_EXCLUSIVE; - r = IStorage_OpenStream( db->storage, szSumInfo, 0, grfMode, 0, &stm ); + r = IStorage_OpenStream( db->infile, szSumInfo, 0, grfMode, 0, &stm ); if( SUCCEEDED(r) ) { load_summary_info( si, stm ); @@ -703,7 +703,7 @@ static unsigned suminfo_persist( LibmsiSummaryInfo *si ) HRESULT r; grfMode = STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE; - r = IStorage_CreateStream( si->database->storage, szSumInfo, grfMode, 0, 0, &stm ); + r = IStorage_CreateStream( si->database->outfile, szSumInfo, grfMode, 0, 0, &stm ); if( SUCCEEDED(r) ) { ret = save_summary_info( si, stm ); diff --git a/libmsi/table.c b/libmsi/table.c index 8e365b7..37e5493 100644 --- a/libmsi/table.c +++ b/libmsi/table.c @@ -658,7 +658,7 @@ static unsigned get_table( LibmsiDatabase *db, const WCHAR *name, LibmsiTable ** free_table( table ); return r; } - r = read_table_from_storage( db, table, db->storage ); + r = read_table_from_storage( db, table, db->infile ); if (r != LIBMSI_RESULT_SUCCESS) { free_table( table ); @@ -977,7 +977,7 @@ static unsigned save_table( LibmsiDatabase *db, const LibmsiTable *t, unsigned b } TRACE("writing %d bytes\n", rawsize); - r = write_stream_data( db->storage, t->name, rawdata, rawsize, true ); + r = write_stream_data( db->outfile, t->name, rawdata, rawsize, true ); err: msi_free( rawdata ); @@ -2069,7 +2069,7 @@ unsigned _libmsi_database_commit_tables( LibmsiDatabase *db ) TRACE("%p\n",db); - r = msi_save_string_table( db->strings, db->storage, &bytes_per_strref ); + r = msi_save_string_table( db->strings, db->outfile, &bytes_per_strref ); if( r != LIBMSI_RESULT_SUCCESS ) { WARN("failed to save string table r=%08x\n",r); @@ -2087,7 +2087,7 @@ unsigned _libmsi_database_commit_tables( LibmsiDatabase *db ) } } - hr = IStorage_Commit( db->storage, 0 ); + hr = IStorage_Commit( db->outfile, 0 ); if (FAILED( hr )) { WARN("failed to commit changes 0x%08x\n", hr); -- cgit