@joebigelow / wix-1 / commits / dfa44dcb

Add query mechanisms for useful for patching and cabinets

Rob Mensching committed Feb 5, 2020 at 13:58 UTC dfa44dcb277235051654fe4e951d957b5e3f9dc6
2 files changed +70 -2
src/WixBuildTools.TestSupport/Query.cs
+67 -1
@@ -4,7 +4,10 @@ namespace WixBuildTools.TestSupport
4 {
5 using System;
6 using System.Collections.Generic;
7 + using System.IO;
8 + using System.Linq;
9 using System.Text;
10 + using WixToolset.Dtf.Compression.Cab;
11 using WixToolset.Dtf.WindowsInstaller;
12
13 public class Query
@@ -25,7 +28,7 @@ namespace WixBuildTools.TestSupport
28 continue;
29 }
30
28 - using (var view = db.OpenView($"SELECT * FROM `{table}`"))
31 + using (var view = db.OpenView("SELECT * FROM `{0}`", table))
32 {
33 view.Execute();
34
@@ -58,5 +61,68 @@ namespace WixBuildTools.TestSupport
61 results.Sort();
62 return results.ToArray();
63 }
64 +
65 + public static CabFileInfo[] GetCabinetFiles(string path)
66 + {
67 + var cab = new CabInfo(path);
68 +
69 + var result = cab.GetFiles();
70 +
71 + return result.Select(c => c).ToArray();
72 + }
73 +
74 + public static void ExtractStream(string path, string streamName, string outputPath)
75 + {
76 + Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
77 +
78 + using (var db = new Database(path))
79 + using (var view = db.OpenView("SELECT `Data` FROM `_Streams` WHERE `Name` = '{0}'", streamName))
80 + {
81 + view.Execute();
82 +
83 + using (var record = view.Fetch())
84 + {
85 + record.GetStream(1, outputPath);
86 + }
87 + }
88 + }
89 +
90 + public static void ExtractSubStorage(string path, string subStorageName, string outputPath)
91 + {
92 + Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
93 +
94 + using (var db = new Database(path))
95 + using (var view = db.OpenView("SELECT `Name`, `Data` FROM `_Storages` WHERE `Name` = '{0}'", subStorageName))
96 + {
97 + view.Execute();
98 +
99 + using (var record = view.Fetch())
100 + {
101 + var name = record.GetString(1);
102 + record.GetStream(2, outputPath);
103 + }
104 + }
105 + }
106 +
107 + public static string[] GetSubStorageNames(string path)
108 + {
109 + var result = new List<string>();
110 +
111 + using (var db = new Database(path))
112 + using (var view = db.OpenView("SELECT `Name` FROM `_Storages`"))
113 + {
114 + view.Execute();
115 +
116 + Record record;
117 + while ((record = view.Fetch()) != null)
118 + {
119 + var name = record.GetString(1);
120 + result.Add(name);
121 + }
122 + }
123 +
124 + result.Sort();
125 + return result.ToArray();
126 + }
127 }
128 }
src/WixBuildTools.TestSupport/WixBuildTools.TestSupport.csproj
+3 -1
@@ -4,7 +4,7 @@
4 <Project Sdk="Microsoft.NET.Sdk">
5
6 <PropertyGroup>
7 - <TargetFramework>netstandard2.0</TargetFramework>
7 + <TargetFrameworks>netstandard2.0;net461;net472</TargetFrameworks>
8 <IsPackable>true</IsPackable>
9 <DebugType>embedded</DebugType>
10 <PublishRepositoryUrl>true</PublishRepositoryUrl>
@@ -13,6 +13,8 @@
13 <ItemGroup>
14 <PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3" />
15 <PackageReference Include="WixToolset.Dtf.WindowsInstaller" Version="4.0.*" NoWarn="NU1701" />
16 + <PackageReference Include="WixToolset.Dtf.Compression" Version="4.0.*" NoWarn="NU1701" />
17 + <PackageReference Include="WixToolset.Dtf.Compression.Cab" Version="4.0.*" NoWarn="NU1701" />
18 </ItemGroup>
19
20 <ItemGroup>