Commit 33045101 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

msi: Store the IStorage list as an array of STORAGE structures.

parent 7728acd1
...@@ -50,7 +50,7 @@ typedef struct tagMSISTORAGESVIEW ...@@ -50,7 +50,7 @@ typedef struct tagMSISTORAGESVIEW
{ {
MSIVIEW view; MSIVIEW view;
MSIDATABASE *db; MSIDATABASE *db;
STORAGE **storages; STORAGE *storages;
UINT max_storages; UINT max_storages;
UINT num_rows; UINT num_rows;
UINT row_size; UINT row_size;
...@@ -61,7 +61,7 @@ static BOOL storages_set_table_size(MSISTORAGESVIEW *sv, UINT size) ...@@ -61,7 +61,7 @@ static BOOL storages_set_table_size(MSISTORAGESVIEW *sv, UINT size)
if (size >= sv->max_storages) if (size >= sv->max_storages)
{ {
sv->max_storages *= 2; sv->max_storages *= 2;
sv->storages = msi_realloc(sv->storages, sv->max_storages * sizeof(STORAGE *)); sv->storages = msi_realloc(sv->storages, sv->max_storages * sizeof(*sv->storages));
if (!sv->storages) if (!sv->storages)
return FALSE; return FALSE;
} }
...@@ -69,23 +69,6 @@ static BOOL storages_set_table_size(MSISTORAGESVIEW *sv, UINT size) ...@@ -69,23 +69,6 @@ static BOOL storages_set_table_size(MSISTORAGESVIEW *sv, UINT size)
return TRUE; return TRUE;
} }
static STORAGE *create_storage(MSISTORAGESVIEW *sv, LPCWSTR name, IStorage *stg)
{
STORAGE *storage;
storage = msi_alloc(sizeof(STORAGE));
if (!storage)
return NULL;
storage->str_index = msi_add_string(sv->db->strings, name, -1, FALSE);
storage->storage = stg;
if (storage->storage)
IStorage_AddRef(storage->storage);
return storage;
}
static UINT STORAGES_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val) static UINT STORAGES_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT *val)
{ {
MSISTORAGESVIEW *sv = (MSISTORAGESVIEW *)view; MSISTORAGESVIEW *sv = (MSISTORAGESVIEW *)view;
...@@ -98,7 +81,7 @@ static UINT STORAGES_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT ...@@ -98,7 +81,7 @@ static UINT STORAGES_fetch_int(struct tagMSIVIEW *view, UINT row, UINT col, UINT
if (row >= sv->num_rows) if (row >= sv->num_rows)
return ERROR_NO_MORE_ITEMS; return ERROR_NO_MORE_ITEMS;
*val = sv->storages[row]->str_index; *val = sv->storages[row].str_index;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
...@@ -173,7 +156,7 @@ done: ...@@ -173,7 +156,7 @@ done:
static UINT STORAGES_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask) static UINT STORAGES_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, UINT mask)
{ {
MSISTORAGESVIEW *sv = (MSISTORAGESVIEW *)view; MSISTORAGESVIEW *sv = (MSISTORAGESVIEW *)view;
IStorage *stg, *substg = NULL; IStorage *stg, *substg = NULL, *prev;
IStream *stm; IStream *stm;
LPWSTR name = NULL; LPWSTR name = NULL;
HRESULT hr; HRESULT hr;
...@@ -181,7 +164,7 @@ static UINT STORAGES_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, ...@@ -181,7 +164,7 @@ static UINT STORAGES_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec,
TRACE("(%p, %p)\n", view, rec); TRACE("(%p, %p)\n", view, rec);
if (row > sv->num_rows) if (row >= sv->num_rows)
return ERROR_FUNCTION_FAILED; return ERROR_FUNCTION_FAILED;
r = MSI_RecordGetIStream(rec, 2, &stm); r = MSI_RecordGetIStream(rec, 2, &stm);
...@@ -218,9 +201,11 @@ static UINT STORAGES_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec, ...@@ -218,9 +201,11 @@ static UINT STORAGES_set_row(struct tagMSIVIEW *view, UINT row, MSIRECORD *rec,
goto done; goto done;
} }
sv->storages[row] = create_storage(sv, name, stg); prev = sv->storages[row].storage;
if (!sv->storages[row]) sv->storages[row].str_index = msi_add_string(sv->db->strings, name, -1, FALSE);
r = ERROR_FUNCTION_FAILED; IStorage_AddRef(stg);
sv->storages[row].storage = stg;
if (prev) IStorage_Release(prev);
done: done:
msi_free(name); msi_free(name);
...@@ -242,6 +227,8 @@ static UINT STORAGES_insert_row(struct tagMSIVIEW *view, MSIRECORD *rec, UINT ro ...@@ -242,6 +227,8 @@ static UINT STORAGES_insert_row(struct tagMSIVIEW *view, MSIRECORD *rec, UINT ro
if (row == -1) if (row == -1)
row = sv->num_rows - 1; row = sv->num_rows - 1;
memset(&sv->storages[row], 0, sizeof(sv->storages[row]));
/* FIXME have to readjust rows */ /* FIXME have to readjust rows */
return STORAGES_set_row(view, row, rec, 0); return STORAGES_set_row(view, row, rec, 0);
...@@ -400,9 +387,8 @@ static UINT STORAGES_delete(struct tagMSIVIEW *view) ...@@ -400,9 +387,8 @@ static UINT STORAGES_delete(struct tagMSIVIEW *view)
for (i = 0; i < sv->num_rows; i++) for (i = 0; i < sv->num_rows; i++)
{ {
if (sv->storages[i]->storage) if (sv->storages[i].storage)
IStorage_Release(sv->storages[i]->storage); IStorage_Release(sv->storages[i].storage);
msi_free(sv->storages[i]);
} }
msi_free(sv->storages); msi_free(sv->storages);
...@@ -436,7 +422,6 @@ static const MSIVIEWOPS storages_ops = ...@@ -436,7 +422,6 @@ static const MSIVIEWOPS storages_ops =
static INT add_storages_to_table(MSISTORAGESVIEW *sv) static INT add_storages_to_table(MSISTORAGESVIEW *sv)
{ {
STORAGE *storage = NULL;
IEnumSTATSTG *stgenum = NULL; IEnumSTATSTG *stgenum = NULL;
STATSTG stat; STATSTG stat;
HRESULT hr; HRESULT hr;
...@@ -447,7 +432,7 @@ static INT add_storages_to_table(MSISTORAGESVIEW *sv) ...@@ -447,7 +432,7 @@ static INT add_storages_to_table(MSISTORAGESVIEW *sv)
return -1; return -1;
sv->max_storages = 1; sv->max_storages = 1;
sv->storages = msi_alloc(sizeof(STORAGE *)); sv->storages = msi_alloc(sizeof(*sv->storages));
if (!sv->storages) if (!sv->storages)
return -1; return -1;
...@@ -466,26 +451,19 @@ static INT add_storages_to_table(MSISTORAGESVIEW *sv) ...@@ -466,26 +451,19 @@ static INT add_storages_to_table(MSISTORAGESVIEW *sv)
TRACE("enumerated storage %s\n", debugstr_w(stat.pwcsName)); TRACE("enumerated storage %s\n", debugstr_w(stat.pwcsName));
storage = create_storage(sv, stat.pwcsName, NULL); if (!storages_set_table_size(sv, ++count))
if (!storage)
{ {
count = -1; count = -1;
CoTaskMemFree(stat.pwcsName);
break; break;
} }
sv->storages[count - 1].str_index = msi_add_string(sv->db->strings, stat.pwcsName, -1, FALSE);
sv->storages[count - 1].storage = NULL;
IStorage_OpenStorage(sv->db->storage, stat.pwcsName, NULL, IStorage_OpenStorage(sv->db->storage, stat.pwcsName, NULL,
STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0, STGM_READ | STGM_SHARE_EXCLUSIVE, NULL, 0,
&storage->storage); &sv->storages[count - 1].storage);
CoTaskMemFree(stat.pwcsName); CoTaskMemFree(stat.pwcsName);
if (!storages_set_table_size(sv, ++count))
{
count = -1;
break;
}
sv->storages[count - 1] = storage;
} }
IEnumSTATSTG_Release(stgenum); IEnumSTATSTG_Release(stgenum);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment