From dfa44dcb277235051654fe4e951d957b5e3f9dc6 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 5 Feb 2020 13:58:02 -0800 Subject: Add query mechanisms for useful for patching and cabinets --- src/WixBuildTools.TestSupport/Query.cs | 68 +++++++++++++++++++++- .../WixBuildTools.TestSupport.csproj | 4 +- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/src/WixBuildTools.TestSupport/Query.cs b/src/WixBuildTools.TestSupport/Query.cs index a5883067..bbd9f89a 100644 --- a/src/WixBuildTools.TestSupport/Query.cs +++ b/src/WixBuildTools.TestSupport/Query.cs @@ -4,7 +4,10 @@ namespace WixBuildTools.TestSupport { using System; using System.Collections.Generic; + using System.IO; + using System.Linq; using System.Text; + using WixToolset.Dtf.Compression.Cab; using WixToolset.Dtf.WindowsInstaller; public class Query @@ -25,7 +28,7 @@ namespace WixBuildTools.TestSupport continue; } - using (var view = db.OpenView($"SELECT * FROM `{table}`")) + using (var view = db.OpenView("SELECT * FROM `{0}`", table)) { view.Execute(); @@ -58,5 +61,68 @@ namespace WixBuildTools.TestSupport results.Sort(); return results.ToArray(); } + + public static CabFileInfo[] GetCabinetFiles(string path) + { + var cab = new CabInfo(path); + + var result = cab.GetFiles(); + + return result.Select(c => c).ToArray(); + } + + public static void ExtractStream(string path, string streamName, string outputPath) + { + Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); + + using (var db = new Database(path)) + using (var view = db.OpenView("SELECT `Data` FROM `_Streams` WHERE `Name` = '{0}'", streamName)) + { + view.Execute(); + + using (var record = view.Fetch()) + { + record.GetStream(1, outputPath); + } + } + } + + public static void ExtractSubStorage(string path, string subStorageName, string outputPath) + { + Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); + + using (var db = new Database(path)) + using (var view = db.OpenView("SELECT `Name`, `Data` FROM `_Storages` WHERE `Name` = '{0}'", subStorageName)) + { + view.Execute(); + + using (var record = view.Fetch()) + { + var name = record.GetString(1); + record.GetStream(2, outputPath); + } + } + } + + public static string[] GetSubStorageNames(string path) + { + var result = new List(); + + using (var db = new Database(path)) + using (var view = db.OpenView("SELECT `Name` FROM `_Storages`")) + { + view.Execute(); + + Record record; + while ((record = view.Fetch()) != null) + { + var name = record.GetString(1); + result.Add(name); + } + } + + result.Sort(); + return result.ToArray(); + } } } diff --git a/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj b/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj index 782a0217..31bdf033 100644 --- a/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj +++ b/src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj @@ -4,7 +4,7 @@ - netstandard2.0 + netstandard2.0;net461;net472 true embedded true @@ -13,6 +13,8 @@ + + -- cgit v1.2.3-55-g6feb