From 6e70991e86c50fa8fd7ee011401a4e08a2c58321 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 15 Jun 2022 23:31:08 -0700 Subject: [PATCH] Fix build, add export all (nw) --- .../External/libmsi/LibmsiDatabase.cs | 75 +++++++++++++++++++ BurnOutSharp/External/libmsi/LibmsiQuery.cs | 3 +- .../External/libmsi/Views/LibmsiInsertView.cs | 5 +- .../External/libmsi/Views/LibmsiSelectView.cs | 5 +- .../libmsi/Views/LibmsiStorageView.cs | 5 +- .../libmsi/Views/LibmsiStreamsView.cs | 5 +- .../External/libmsi/Views/LibmsiTableView.cs | 19 +++-- .../External/libmsi/Views/LibmsiUpdateView.cs | 3 +- .../External/libmsi/Views/LibmsiWhereView.cs | 5 +- 9 files changed, 96 insertions(+), 29 deletions(-) diff --git a/BurnOutSharp/External/libmsi/LibmsiDatabase.cs b/BurnOutSharp/External/libmsi/LibmsiDatabase.cs index 36b5ec9e..2dbaf17e 100644 --- a/BurnOutSharp/External/libmsi/LibmsiDatabase.cs +++ b/BurnOutSharp/External/libmsi/LibmsiDatabase.cs @@ -290,6 +290,81 @@ namespace LibMSI return r == LibmsiResult.LIBMSI_RESULT_SUCCESS; } + /// Adapted from WixToolset + 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; + } + /// /// Import a table to the database from file . /// diff --git a/BurnOutSharp/External/libmsi/LibmsiQuery.cs b/BurnOutSharp/External/libmsi/LibmsiQuery.cs index ba371207..879d0746 100644 --- a/BurnOutSharp/External/libmsi/LibmsiQuery.cs +++ b/BurnOutSharp/External/libmsi/LibmsiQuery.cs @@ -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"); diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiInsertView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiInsertView.cs index 05fbfcbd..063ab758 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiInsertView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiInsertView.cs @@ -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; } } diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiSelectView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiSelectView.cs index d7a55882..a026a288 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiSelectView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiSelectView.cs @@ -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; } diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiStorageView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiStorageView.cs index 5f31767a..45d52f91 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiStorageView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiStorageView.cs @@ -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) diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiStreamsView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiStreamsView.cs index 13e41297..3e977f4d 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiStreamsView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiStreamsView.cs @@ -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"); diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiTableView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiTableView.cs index 4442a33e..3552a6b5 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiTableView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiTableView.cs @@ -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; diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiUpdateView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiUpdateView.cs index cabf06f5..f09d95bb 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiUpdateView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiUpdateView.cs @@ -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); } } } diff --git a/BurnOutSharp/External/libmsi/Views/LibmsiWhereView.cs b/BurnOutSharp/External/libmsi/Views/LibmsiWhereView.cs index ff1b23b2..2b7afe3d 100644 --- a/BurnOutSharp/External/libmsi/Views/LibmsiWhereView.cs +++ b/BurnOutSharp/External/libmsi/Views/LibmsiWhereView.cs @@ -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: