Fix build, add export all (nw)

This commit is contained in:
Matt Nadareski
2022-06-15 23:31:08 -07:00
parent f1803b9f3a
commit 6e70991e86
9 changed files with 96 additions and 29 deletions

View File

@@ -290,6 +290,81 @@ namespace LibMSI
return r == LibmsiResult.LIBMSI_RESULT_SUCCESS;
}
/// <remarks>Adapted from WixToolset</remarks>
public bool ExportAll(string path)
{
if (string.IsNullOrEmpty(path))
return false;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
// SummaryInfo
Exception err = null;
string summaryInfoPath = System.IO.Path.Combine(path, "_SummaryInformation.idt");
using (Stream summaryInfoStream = File.OpenWrite(summaryInfoPath))
{
Export("_SummaryInformation", summaryInfoStream, ref err);
}
// Tables
err = null;
LibmsiQuery tableQuery = LibmsiQuery.Create(this, $"SELECT `Name` FROM `_Tables`", ref err);
tableQuery.Execute(null, ref err);
LibmsiRecord tableRecord = tableQuery.Fetch(ref err);
while (tableRecord != null)
{
err = null;
string table = tableRecord.GetString(1);
string tablePath = System.IO.Path.Combine(path, $"{table}.idt");
using (Stream tableStream = File.OpenWrite(tablePath))
{
Export(table, tableStream, ref err);
}
tableRecord = tableQuery.Fetch(ref err);
}
// Streams
if (!Directory.Exists(System.IO.Path.Combine(path, "_Streams")))
Directory.CreateDirectory(System.IO.Path.Combine(path, "_Streams"));
err = null;
LibmsiQuery streamsQuery = LibmsiQuery.Create(this, $"SELECT `Name`, `Data` FROM `_Streams`", ref err);
streamsQuery.Execute(null, ref err);
LibmsiRecord streamRecord = streamsQuery.Fetch(ref err);
while (streamRecord != null)
{
err = null;
string stream = streamRecord.GetString(1);
if (stream.EndsWith("SummaryInformation", StringComparison.Ordinal))
continue;
int i = stream.IndexOf('.');
if (i >= 0)
{
if (File.Exists(System.IO.Path.Combine(path, stream.Substring(0, i), stream.Substring(i + 1) + ".ibd")))
continue;
}
using (Stream streamRecordStream = streamRecord.GetStream(2))
using (Stream streamRecordOutput = File.OpenWrite(System.IO.Path.Combine(path, "_Streams", stream)))
{
streamRecordStream.CopyTo(streamRecordOutput);
}
streamRecord = tableQuery.Fetch(ref err);
}
return true;
}
/// <summary>
/// Import a table to the database from file <paramref name="path"/>.
/// </summary>

View File

@@ -23,7 +23,6 @@ using System.Collections.Generic;
using LibGSF.Input;
using LibMSI.Internal;
using LibMSI.Views;
using static LibMSI.LibmsiRecord;
using static LibMSI.Internal.MsiPriv;
namespace LibMSI
@@ -349,7 +348,7 @@ namespace LibMSI
{
ret = view.FetchStream(row, i, out GsfInput stm);
if ((ret == LibmsiResult.LIBMSI_RESULT_SUCCESS) && stm != null)
RecordSetGsfInput(rec, i, stm);
rec.SetGsfInput(i, stm);
else
Console.Error.WriteLine("Failed to get stream");

View File

@@ -19,7 +19,6 @@
*/
using System;
using static LibMSI.LibmsiRecord;
using static LibMSI.Internal.LibmsiSQLInput;
using static LibMSI.Internal.MsiPriv;
@@ -201,7 +200,7 @@ namespace LibMSI.Views
if (rec == null)
return null;
RecordCopyField(rec, wildcard_count, merged, i);
rec.CopyField(wildcard_count, merged, i);
wildcard_count++;
break;
default:
@@ -271,7 +270,7 @@ namespace LibMSI.Views
if (a == b)
{
RecordCopyField(values, colidx, padded, i);
values.CopyField(colidx, padded, i);
break;
}
}

View File

@@ -20,7 +20,6 @@
using LibGSF.Input;
using static LibMSI.LibmsiQuery;
using static LibMSI.LibmsiRecord;
using static LibMSI.Internal.MsiPriv;
namespace LibMSI.Views
@@ -158,7 +157,7 @@ namespace LibMSI.Views
int expanded_mask = 0;
for (int i = 0; i < NumCols; i++ )
{
r = RecordCopyField(rec, i + 1, expanded, Cols[i]);
r = rec.CopyField(i + 1, expanded, Cols[i]);
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
break;
@@ -187,7 +186,7 @@ namespace LibMSI.Views
for (int i = 0; i < NumCols; i++)
{
r = RecordCopyField(record, i + 1, outrec, Cols[i] );
r = record.CopyField(i + 1, outrec, Cols[i] );
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
return r;
}

View File

@@ -21,7 +21,6 @@
using System;
using LibGSF.Input;
using LibMSI.Internal;
using static LibMSI.LibmsiRecord;
using static LibMSI.Internal.MsiPriv;
namespace LibMSI.Views
@@ -144,7 +143,7 @@ namespace LibMSI.Views
if (row > NumRows)
return LibmsiResult.LIBMSI_RESULT_FUNCTION_FAILED;
LibmsiResult r = GetGsfInput(rec, 2, out GsfInput stm);
LibmsiResult r = rec.GetGsfInput(2, out GsfInput stm);
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
return r;
@@ -161,7 +160,7 @@ namespace LibMSI.Views
}
else
{
name = RecordGetStringRaw(rec, 1);
name = rec.GetStringRaw(1);
}
if (name == null)

View File

@@ -22,7 +22,6 @@ using System;
using LibGSF.Input;
using LibMSI.Internal;
using static LibMSI.LibmsiQuery;
using static LibMSI.LibmsiRecord;
using static LibMSI.Internal.LibmsiTable;
using static LibMSI.Internal.MsiPriv;
@@ -119,7 +118,7 @@ namespace LibMSI.Views
if (row > NumRows)
return LibmsiResult.LIBMSI_RESULT_FUNCTION_FAILED;
LibmsiResult r = GetGsfInput(rec, 2, out GsfInput stm);
LibmsiResult r = rec.GetGsfInput(2, out GsfInput stm);
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
return r;
@@ -138,7 +137,7 @@ namespace LibMSI.Views
}
else
{
name = RecordGetStringRaw(rec, 1);
name = rec.GetStringRaw(1);
if (name == null)
{
Console.Error.WriteLine("Failed to retrieve stream name");

View File

@@ -23,7 +23,6 @@ using System.Linq;
using LibGSF.Input;
using LibMSI.Internal;
using static LibMSI.LibmsiQuery;
using static LibMSI.LibmsiRecord;
using static LibMSI.LibmsiTypes;
using static LibMSI.Internal.LibmsiTable;
using static LibMSI.Internal.MsiPriv;
@@ -85,7 +84,7 @@ namespace LibMSI.Views
tv.Database = db;
tv.Columns = tv.Table.ColInfo;
tv.NumCols = tv.Table.ColCount;
tv.RowSize = GetRowSize(db, tv.Table.ColInfo, tv.Table.ColCount, LONG_STR_BYTES);
tv.RowSize = GetRowSize(tv.Table.ColInfo, tv.Table.ColCount, LONG_STR_BYTES);
tv.Name = name;
view = tv;
@@ -117,7 +116,7 @@ namespace LibMSI.Views
return LibmsiResult.LIBMSI_RESULT_FUNCTION_FAILED;
}
int n = BytesPerColumn(Database, Columns[col - 1], LONG_STR_BYTES);
int n = BytesPerColumn(Columns[col - 1], LONG_STR_BYTES);
if (n != 2 && n != 3 && n != 4)
{
Console.Error.WriteLine("oops! what is %d bytes per column?\n", n );
@@ -192,7 +191,7 @@ namespace LibMSI.Views
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
return LibmsiResult.LIBMSI_RESULT_FUNCTION_FAILED;
r = GetGsfInput(rec, i + 1, out GsfInput stm);
r = rec.GetGsfInput(i + 1, out GsfInput stm);
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
return r;
@@ -208,7 +207,7 @@ namespace LibMSI.Views
{
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
{
string sval = RecordGetStringRaw(rec, i + 1);
string sval = rec.GetStringRaw(i + 1);
val = Database.Strings.AddString(sval, -1, 1, persistent ? StringPersistence.StringPersistent : StringPersistence.StringNonPersistent );
}
else
@@ -596,7 +595,7 @@ namespace LibMSI.Views
}
else
{
int n = BytesPerColumn(Database, Columns[i], LONG_STR_BYTES);
int n = BytesPerColumn(Columns[i], LONG_STR_BYTES);
switch (n)
{
case 2:
@@ -645,7 +644,7 @@ namespace LibMSI.Views
Columns[col - 1].HashTable = null;
int n = BytesPerColumn(Database, Columns[col - 1], LONG_STR_BYTES);
int n = BytesPerColumn(Columns[col - 1], LONG_STR_BYTES);
if (n != 2 && n != 3 && n != 4)
{
Console.Error.WriteLine($"Oops! what is {n} bytes per column?");
@@ -676,7 +675,7 @@ namespace LibMSI.Views
}
else if ((columninfo.Type & MSITYPE_STRING) != 0)
{
string sval = RecordGetStringRaw(rec, iField);
string sval = rec.GetStringRaw(iField);
if (sval != null)
{
r = Database.Strings.IdFromStringUTF8(sval, out pvalue);
@@ -688,7 +687,7 @@ namespace LibMSI.Views
pvalue = 0;
}
}
else if (BytesPerColumn(Database, columninfo, LONG_STR_BYTES) == 2)
else if (BytesPerColumn(columninfo, LONG_STR_BYTES) == 2)
{
pvalue = 0x8000 + rec.GetInt(iField);
if ((pvalue & 0xffff0000) != 0)
@@ -763,7 +762,7 @@ namespace LibMSI.Views
}
else if ((Columns[i].Type & MSITYPE_STRING) != 0)
{
string str = RecordGetStringRaw(rec, i + 1);
string str = rec.GetStringRaw(i + 1);
if (str == null || str[0] == 0)
{
column = i;

View File

@@ -19,7 +19,6 @@
*/
using LibMSI.Internal;
using static LibMSI.LibmsiRecord;
namespace LibMSI.Views
{
@@ -116,7 +115,7 @@ namespace LibMSI.Views
{
for (i = 1; i <= where_count; i++)
{
RecordCopyField(record, cols_count + i, where, i);
record.CopyField(cols_count + i, where, i);
}
}
}

View File

@@ -24,7 +24,6 @@ using System.Linq;
using LibGSF.Input;
using LibMSI.Internal;
using static LibMSI.LibmsiQuery;
using static LibMSI.LibmsiRecord;
using static LibMSI.Internal.LibmsiSQLInput;
using static LibMSI.Internal.MsiPriv;
@@ -294,7 +293,7 @@ namespace LibMSI.Views
for (int i = 1; i <= col_count; i++)
{
r = RecordCopyField(rec, i + offset, reduced, i);
r = rec.CopyField(i + offset, reduced, i);
if (r != LibmsiResult.LIBMSI_RESULT_SUCCESS)
break;
}
@@ -775,7 +774,7 @@ namespace LibMSI.Views
break;
case EXPR_WILDCARD:
str = RecordGetStringRaw(record, ++RecIndex);
str = record.GetStringRaw(++RecIndex);
break;
default: