Add the decompiled package's platform to the DecompileResult.
Bob Arnson committed
Oct 8, 2020 at 15:12 UTC
ac70afc7ec180ed192c54502035721446e831f49
3 files changed
+47
-25
src/WixToolset.Core.WindowsInstaller/Decompile/DecompileMsiOrMsmCommand.cs
+13
-1
@@ -6,8 +6,10 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
6
using System.Collections.Generic;
7
using System.ComponentModel;
8
using System.IO;
9
+ using System.Linq;
10
using WixToolset.Core.WindowsInstaller.Msi;
11
using WixToolset.Data;
12
+ using WixToolset.Data.WindowsInstaller;
13
using WixToolset.Extensibility;
14
using WixToolset.Extensibility.Data;
15
using WixToolset.Extensibility.Services;
@@ -41,13 +43,15 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
43
Directory.Delete(this.Context.ExtractFolder, true);
44
}
45
44
- var unbindCommand = new UnbindDatabaseCommand(this.Messaging, database, this.Context.DecompilePath, this.Context.DecompileType, this.Context.ExtractFolder, this.Context.IntermediateFolder, this.Context.IsAdminImage, false, skipSummaryInfo: false);
46
+ var unbindCommand = new UnbindDatabaseCommand(this.Messaging, database, this.Context.DecompilePath, this.Context.DecompileType, this.Context.ExtractFolder, this.Context.IntermediateFolder, this.Context.IsAdminImage, suppressDemodularization: false, skipSummaryInfo: false);
47
var output = unbindCommand.Execute();
48
var extractedFilePaths = new List<string>(unbindCommand.ExportedFiles);
49
50
var decompiler = new Decompiler(this.Messaging, this.Extensions, this.Context.BaseSourcePath, this.Context.SuppressCustomTables, this.Context.SuppressDroppingEmptyTables, this.Context.SuppressUI, this.Context.TreatProductAsModule);
51
result.Document = decompiler.Decompile(output);
52
53
+ result.Platform = GetPlatformFromOutput(output);
54
+
55
// extract the files from the cabinets
56
if (!String.IsNullOrEmpty(this.Context.ExtractFolder) && !this.Context.SuppressExtractCabinets)
57
{
@@ -77,5 +81,13 @@ namespace WixToolset.Core.WindowsInstaller.Unbind
81
82
return result;
83
}
84
+
85
+ private static Platform? GetPlatformFromOutput(WindowsInstallerData output)
86
+ {
87
+ var template = output.Tables["_SummaryInformation"]?.Rows.SingleOrDefault(row => row.FieldAsInteger(0) == 7)?.FieldAsString(1);
88
+
89
+ return Decompiler.GetPlatformFromTemplateSummaryInformation(template?.Split(';'));
90
+
91
+ }
92
}
93
}
src/WixToolset.Core.WindowsInstaller/Decompile/Decompiler.cs
+31
-24
@@ -93,7 +93,7 @@ namespace WixToolset.Core.WindowsInstaller
93
94
private string ModularizationGuid { get; set; }
95
96
- public XElement UIElement
96
+ private XElement UIElement
97
{
98
get
99
{
@@ -107,12 +107,11 @@ namespace WixToolset.Core.WindowsInstaller
107
}
108
}
109
110
- public Dictionary<string, XElement> Singletons { get; } = new Dictionary<string, XElement>();
110
+ private Dictionary<string, XElement> Singletons { get; } = new Dictionary<string, XElement>();
111
112
- public Dictionary<string, XElement> IndexedElements { get; } = new Dictionary<string, XElement>();
113
-
114
- public Dictionary<string, XElement> PatchTargetFiles { get; } = new Dictionary<string, XElement>();
112
+ private Dictionary<string, XElement> IndexedElements { get; } = new Dictionary<string, XElement>();
113
114
+ private Dictionary<string, XElement> PatchTargetFiles { get; } = new Dictionary<string, XElement>();
115
116
/// <summary>
117
/// Decompile the database file.
@@ -215,12 +214,30 @@ namespace WixToolset.Core.WindowsInstaller
214
}
215
#endif
216
217
+ internal static Platform? GetPlatformFromTemplateSummaryInformation(string[] template)
218
+ {
219
+ if (null != template && 1 < template.Length && null != template[0] && 0 < template[0].Length)
220
+ {
221
+ switch (template[0])
222
+ {
223
+ case "Intel":
224
+ return Platform.X86;
225
+ case "x64":
226
+ return Platform.X64;
227
+ case "Arm64":
228
+ return Platform.ARM64;
229
+ }
230
+ }
231
+
232
+ return null;
233
+ }
234
+
235
/// <summary>
236
/// Gets the element corresponding to the row it came from.
237
/// </summary>
238
/// <param name="row">The row corresponding to the element.</param>
239
/// <returns>The indexed element.</returns>
223
- public XElement GetIndexedElement(WixToolset.Data.WindowsInstaller.Row row) => this.GetIndexedElement(row.TableDefinition.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter));
240
+ private XElement GetIndexedElement(WixToolset.Data.WindowsInstaller.Row row) => this.GetIndexedElement(row.TableDefinition.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter));
241
242
/// <summary>
243
/// Gets the element corresponding to the primary key of the given table.
@@ -228,7 +245,7 @@ namespace WixToolset.Core.WindowsInstaller
245
/// <param name="table">The table corresponding to the element.</param>
246
/// <param name="primaryKey">The primary key corresponding to the element.</param>
247
/// <returns>The indexed element.</returns>
231
- public XElement GetIndexedElement(string table, params string[] primaryKey) => this.IndexedElements[String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey))];
248
+ private XElement GetIndexedElement(string table, params string[] primaryKey) => this.IndexedElements[String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey))];
249
250
/// <summary>
251
/// Gets the element corresponding to the primary key of the given table.
@@ -236,7 +253,7 @@ namespace WixToolset.Core.WindowsInstaller
253
/// <param name="table">The table corresponding to the element.</param>
254
/// <param name="primaryKey">The primary key corresponding to the element.</param>
255
/// <returns>The indexed element.</returns>
239
- public bool TryGetIndexedElement(WixToolset.Data.WindowsInstaller.Row row, out XElement xElement) => this.TryGetIndexedElement(row.TableDefinition.Name, out xElement, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter));
256
+ private bool TryGetIndexedElement(WixToolset.Data.WindowsInstaller.Row row, out XElement xElement) => this.TryGetIndexedElement(row.TableDefinition.Name, out xElement, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter));
257
258
/// <summary>
259
/// Gets the element corresponding to the primary key of the given table.
@@ -244,14 +261,14 @@ namespace WixToolset.Core.WindowsInstaller
261
/// <param name="table">The table corresponding to the element.</param>
262
/// <param name="primaryKey">The primary key corresponding to the element.</param>
263
/// <returns>The indexed element.</returns>
247
- public bool TryGetIndexedElement(string table, out XElement xElement, params string[] primaryKey) => this.IndexedElements.TryGetValue(String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey)), out xElement);
264
+ private bool TryGetIndexedElement(string table, out XElement xElement, params string[] primaryKey) => this.IndexedElements.TryGetValue(String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey)), out xElement);
265
266
/// <summary>
267
/// Index an element by its corresponding row.
268
/// </summary>
269
/// <param name="row">The row corresponding to the element.</param>
270
/// <param name="element">The element to index.</param>
254
- public void IndexElement(WixToolset.Data.WindowsInstaller.Row row, XElement element)
271
+ private void IndexElement(WixToolset.Data.WindowsInstaller.Row row, XElement element)
272
{
273
this.IndexedElements.Add(String.Concat(row.TableDefinition.Name, ':', row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter)), element);
274
}
@@ -261,7 +278,7 @@ namespace WixToolset.Core.WindowsInstaller
278
/// </summary>
279
/// <param name="row">The row corresponding to the element.</param>
280
/// <param name="element">The element to index.</param>
264
- public void IndexElement(XElement element, string table, params string[] primaryKey)
281
+ private void IndexElement(XElement element, string table, params string[] primaryKey)
282
{
283
this.IndexedElements.Add(String.Concat(table, ':', String.Join(DecompilerConstants.PrimaryKeyDelimiterString, primaryKey)), element);
284
}
@@ -3004,20 +3021,10 @@ namespace WixToolset.Core.WindowsInstaller
3021
xPackage.SetAttributeValue("Languages", template[template.Length - 1]);
3022
}
3023
3007
- if (1 < template.Length && null != template[0] && 0 < template[0].Length)
3024
+ var platform = GetPlatformFromTemplateSummaryInformation(template).ToString().ToLowerInvariant();
3025
+ if (!String.IsNullOrEmpty(platform))
3026
{
3009
- switch (template[0])
3010
- {
3011
- case "Intel":
3012
- xPackage.SetAttributeValue("Platform", "x86");
3013
- break;
3014
- case "x64":
3015
- xPackage.SetAttributeValue("Platform", "x64");
3016
- break;
3017
- case "Arm64":
3018
- xPackage.SetAttributeValue("Platform", "arm64");
3019
- break;
3020
- }
3027
+ xPackage.SetAttributeValue("Platform", platform);
3028
}
3029
break;
3030
case 9:
src/WixToolset.Core/DecompileResult.cs
+3
@@ -4,6 +4,7 @@ namespace WixToolset.Core
4
{
5
using System.Collections.Generic;
6
using System.Xml.Linq;
7
+ using WixToolset.Data;
8
using WixToolset.Extensibility.Data;
9
10
internal class DecompileResult : IDecompileResult
@@ -11,5 +12,7 @@ namespace WixToolset.Core
12
public XDocument Document { get; set; }
13
14
public IEnumerable<string> ExtractedFilePaths { get; set; }
15
+
16
+ public Platform? Platform { get; set; }
17
}
18
}