Modernize DifxAppCompiler and tuples.
Sean Hall committed
Apr 8, 2020 at 14:19 UTC
a10c87c97c270b9c6c923fbb4e61e2fe779d9107
7 files changed
+53
-53
src/test/WixToolsetTest.DifxApp/DifxAppExtensionFixture.cs
+5
-5
@@ -19,11 +19,11 @@ namespace WixToolsetTest.DifxApp
19
var results = build.BuildAndQuery(Build, "CustomAction");
20
Assert.Equal(new[]
21
{
22
- "CustomAction:MsiCleanupOnSuccess\t1\tDIFxApp.dll\tCleanupOnSuccess\t0",
23
- "CustomAction:MsiInstallDrivers\t3073\tDIFxAppA.dll\tInstallDriverPackages\t0",
24
- "CustomAction:MsiProcessDrivers\t1\tDIFxApp.dll\tProcessDriverPackages\t0",
25
- "CustomAction:MsiRollbackInstall\t3329\tDIFxAppA.dll\tRollbackInstall\t0",
26
- "CustomAction:MsiUninstallDrivers\t3073\tDIFxAppA.dll\tUninstallDriverPackages\t0",
22
+ "CustomAction:MsiCleanupOnSuccess\t1\tDIFxApp.dll\tCleanupOnSuccess\t",
23
+ "CustomAction:MsiInstallDrivers\t3073\tDIFxAppA.dll\tInstallDriverPackages\t",
24
+ "CustomAction:MsiProcessDrivers\t1\tDIFxApp.dll\tProcessDriverPackages\t",
25
+ "CustomAction:MsiRollbackInstall\t3329\tDIFxAppA.dll\tRollbackInstall\t",
26
+ "CustomAction:MsiUninstallDrivers\t3073\tDIFxAppA.dll\tUninstallDriverPackages\t",
27
}, results.OrderBy(s => s).ToArray());
28
}
29
src/wixext/DifxAppCompiler.cs
+15
-12
@@ -37,9 +37,9 @@ namespace WixToolset.DifxApp
37
switch (parentElement.Name.LocalName)
38
{
39
case "Component":
40
- string componentId = context["ComponentId"];
41
- string directoryId = context["DirectoryId"];
42
- bool componentWin64 = Boolean.Parse(context["Win64"]);
40
+ var componentId = context["ComponentId"];
41
+ var directoryId = context["DirectoryId"];
42
+ var componentWin64 = Boolean.Parse(context["Win64"]);
43
44
switch (element.Name.LocalName)
45
{
@@ -64,9 +64,9 @@ namespace WixToolset.DifxApp
64
/// <param name="componentId">Identifier for parent component.</param>
65
private void ParseDriverElement(Intermediate intermediate, IntermediateSection section, XElement node, string componentId, bool win64)
66
{
67
- SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
67
+ var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
68
int attributes = 0;
69
- int sequence = CompilerConstants.IntegerNotSet;
69
+ var sequence = CompilerConstants.IntegerNotSet;
70
71
// check the number of times a Driver element has been nested under this Component element
72
if (null != componentId)
@@ -81,7 +81,7 @@ namespace WixToolset.DifxApp
81
}
82
}
83
84
- foreach (XAttribute attrib in node.Attributes())
84
+ foreach (var attrib in node.Attributes())
85
{
86
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
87
{
@@ -138,10 +138,10 @@ namespace WixToolset.DifxApp
138
switch (this.Context.Platform)
139
{
140
case Platform.X86:
141
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "MsiProcessDrivers");
141
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "MsiProcessDrivers");
142
break;
143
case Platform.X64:
144
- this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "MsiProcessDrivers_x64");
144
+ this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "MsiProcessDrivers_x64");
145
break;
146
case Platform.IA64:
147
case Platform.ARM:
@@ -149,12 +149,15 @@ namespace WixToolset.DifxApp
149
break;
150
}
151
152
- var row = (MsiDriverPackagesTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "MsiDriverPackages");
153
- row.Set(0, componentId);
154
- row.Set(1, attributes);
152
+ var tuple = section.AddTuple(new MsiDriverPackagesTuple(sourceLineNumbers)
153
+ {
154
+ ComponentRef = componentId,
155
+ Flags = attributes,
156
+ });
157
+
158
if (CompilerConstants.IntegerNotSet != sequence)
159
{
157
- row.Set(2, sequence);
160
+ tuple.Sequence = sequence;
161
}
162
}
163
}
src/wixext/DifxAppTableDefinitions.cs
new
+26
@@ -0,0 +1,26 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolset.DifxApp
4
+{
5
+ using WixToolset.Data.WindowsInstaller;
6
+
7
+ public static class DifxAppTableDefinitions
8
+ {
9
+ public static readonly TableDefinition MsiDriverPackages = new TableDefinition(
10
+ "MsiDriverPackages",
11
+ new[]
12
+ {
13
+ new ColumnDefinition("Component", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Name of the component that represents the driver package", modularizeType: ColumnModularizeType.Column),
14
+ new ColumnDefinition("Flags", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 31, description: "Flags for installing and uninstalling driver packages"),
15
+ new ColumnDefinition("Sequence", ColumnType.Number, 4, primaryKey: false, nullable: true, ColumnCategory.Unknown, minValue: 0, description: "Order in which the driver packages are processed"),
16
+ },
17
+ tupleDefinitionName: DifxAppTupleDefinitions.MsiDriverPackages.Name,
18
+ tupleIdIsPrimaryKey: false
19
+ );
20
+
21
+ public static readonly TableDefinition[] All = new[]
22
+ {
23
+ MsiDriverPackages,
24
+ };
25
+ }
26
+}
src/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs
+2
-16
@@ -1,27 +1,13 @@
1
-// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
3
namespace WixToolset.DifxApp
4
{
5
using System.Collections.Generic;
6
- using System.Linq;
7
- using System.Xml;
6
using WixToolset.Data.WindowsInstaller;
7
using WixToolset.Extensibility;
8
9
public class DifxAppWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension
10
{
13
- private static readonly TableDefinition[] Tables = LoadTables();
14
-
15
- public override IEnumerable<TableDefinition> TableDefinitions => Tables;
16
-
17
- private static TableDefinition[] LoadTables()
18
- {
19
- using (var resourceStream = typeof(DifxAppWindowsInstallerBackendBinderExtension).Assembly.GetManifestResourceStream("WixToolset.DifxApp.tables.xml"))
20
- using (var reader = XmlReader.Create(resourceStream))
21
- {
22
- var tables = TableDefinitionCollection.Load(reader);
23
- return tables.ToArray();
24
- }
25
- }
11
+ public override IEnumerable<TableDefinition> TableDefinitions => DifxAppTableDefinitions.All;
12
}
13
}
src/wixext/Tuples/MsiDriverPackagesTuple.cs
+5
-5
@@ -11,7 +11,7 @@ namespace WixToolset.DifxApp
11
DifxAppTupleDefinitionType.MsiDriverPackages.ToString(),
12
new[]
13
{
14
- new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.Component), IntermediateFieldType.String),
14
+ new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.ComponentRef), IntermediateFieldType.String),
15
new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.Flags), IntermediateFieldType.Number),
16
new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.Sequence), IntermediateFieldType.Number),
17
},
@@ -25,7 +25,7 @@ namespace WixToolset.DifxApp.Tuples
25
26
public enum MsiDriverPackagesTupleFields
27
{
28
- Component,
28
+ ComponentRef,
29
Flags,
30
Sequence,
31
}
@@ -42,10 +42,10 @@ namespace WixToolset.DifxApp.Tuples
42
43
public IntermediateField this[MsiDriverPackagesTupleFields index] => this.Fields[(int)index];
44
45
- public string Component
45
+ public string ComponentRef
46
{
47
- get => this.Fields[(int)MsiDriverPackagesTupleFields.Component].AsString();
48
- set => this.Set((int)MsiDriverPackagesTupleFields.Component, value);
47
+ get => this.Fields[(int)MsiDriverPackagesTupleFields.ComponentRef].AsString();
48
+ set => this.Set((int)MsiDriverPackagesTupleFields.ComponentRef, value);
49
}
50
51
public int Flags
src/wixext/WixToolset.DifxApp.wixext.csproj
-1
@@ -13,7 +13,6 @@
13
<ItemGroup>
14
<Content Include="$(MSBuildThisFileName).targets" />
15
<Content Include="difxapp.xsd" PackagePath="tools" />
16
- <EmbeddedResource Include="tables.xml" />
16
<EmbeddedResource Include="$(OutputPath)..\difxapp.wixlib" />
17
</ItemGroup>
18
<ItemGroup>
src/wixext/tables.xml
deleted
-14
@@ -1,14 +0,0 @@
1
-<?xml version="1.0" encoding="utf-8"?>
2
-<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
-
4
-
5
-<tableDefinitions xmlns="http://wixtoolset.org/schemas/v4/wi/tables">
6
- <tableDefinition name="MsiDriverPackages">
7
- <columnDefinition name="Component" type="string" length="72" primaryKey="yes" modularize="column"
8
- keyTable="Component" keyColumn="1" category="identifier" description="Name of the component that represents the driver package"/>
9
- <columnDefinition name="Flags" type="number" length="4"
10
- minValue="0" maxValue="31" description="Flags for installing and uninstalling driver packages"/>
11
- <columnDefinition name="Sequence" type="number" length="4" nullable="yes"
12
- minValue="0" description="Order in which the driver packages are processed"/>
13
- </tableDefinition>
14
-</tableDefinitions>