From a10c87c97c270b9c6c923fbb4e61e2fe779d9107 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 8 Apr 2020 14:19:21 +1000 Subject: Modernize DifxAppCompiler and tuples. --- .../DifxAppExtensionFixture.cs | 10 ++++---- src/wixext/DifxAppCompiler.cs | 27 ++++++++++++---------- src/wixext/DifxAppTableDefinitions.cs | 26 +++++++++++++++++++++ ...ifxAppWindowsInstallerBackendBinderExtension.cs | 18 ++------------- src/wixext/Tuples/MsiDriverPackagesTuple.cs | 10 ++++---- src/wixext/WixToolset.DifxApp.wixext.csproj | 1 - src/wixext/tables.xml | 14 ----------- 7 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 src/wixext/DifxAppTableDefinitions.cs delete mode 100644 src/wixext/tables.xml diff --git a/src/test/WixToolsetTest.DifxApp/DifxAppExtensionFixture.cs b/src/test/WixToolsetTest.DifxApp/DifxAppExtensionFixture.cs index dbe257fa..64acec91 100644 --- a/src/test/WixToolsetTest.DifxApp/DifxAppExtensionFixture.cs +++ b/src/test/WixToolsetTest.DifxApp/DifxAppExtensionFixture.cs @@ -19,11 +19,11 @@ namespace WixToolsetTest.DifxApp var results = build.BuildAndQuery(Build, "CustomAction"); Assert.Equal(new[] { - "CustomAction:MsiCleanupOnSuccess\t1\tDIFxApp.dll\tCleanupOnSuccess\t0", - "CustomAction:MsiInstallDrivers\t3073\tDIFxAppA.dll\tInstallDriverPackages\t0", - "CustomAction:MsiProcessDrivers\t1\tDIFxApp.dll\tProcessDriverPackages\t0", - "CustomAction:MsiRollbackInstall\t3329\tDIFxAppA.dll\tRollbackInstall\t0", - "CustomAction:MsiUninstallDrivers\t3073\tDIFxAppA.dll\tUninstallDriverPackages\t0", + "CustomAction:MsiCleanupOnSuccess\t1\tDIFxApp.dll\tCleanupOnSuccess\t", + "CustomAction:MsiInstallDrivers\t3073\tDIFxAppA.dll\tInstallDriverPackages\t", + "CustomAction:MsiProcessDrivers\t1\tDIFxApp.dll\tProcessDriverPackages\t", + "CustomAction:MsiRollbackInstall\t3329\tDIFxAppA.dll\tRollbackInstall\t", + "CustomAction:MsiUninstallDrivers\t3073\tDIFxAppA.dll\tUninstallDriverPackages\t", }, results.OrderBy(s => s).ToArray()); } diff --git a/src/wixext/DifxAppCompiler.cs b/src/wixext/DifxAppCompiler.cs index 98f36b3f..4d0b8ec9 100644 --- a/src/wixext/DifxAppCompiler.cs +++ b/src/wixext/DifxAppCompiler.cs @@ -37,9 +37,9 @@ namespace WixToolset.DifxApp switch (parentElement.Name.LocalName) { case "Component": - string componentId = context["ComponentId"]; - string directoryId = context["DirectoryId"]; - bool componentWin64 = Boolean.Parse(context["Win64"]); + var componentId = context["ComponentId"]; + var directoryId = context["DirectoryId"]; + var componentWin64 = Boolean.Parse(context["Win64"]); switch (element.Name.LocalName) { @@ -64,9 +64,9 @@ namespace WixToolset.DifxApp /// Identifier for parent component. private void ParseDriverElement(Intermediate intermediate, IntermediateSection section, XElement node, string componentId, bool win64) { - SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); int attributes = 0; - int sequence = CompilerConstants.IntegerNotSet; + var sequence = CompilerConstants.IntegerNotSet; // check the number of times a Driver element has been nested under this Component element if (null != componentId) @@ -81,7 +81,7 @@ namespace WixToolset.DifxApp } } - foreach (XAttribute attrib in node.Attributes()) + foreach (var attrib in node.Attributes()) { if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) { @@ -138,10 +138,10 @@ namespace WixToolset.DifxApp switch (this.Context.Platform) { case Platform.X86: - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "MsiProcessDrivers"); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "MsiProcessDrivers"); break; case Platform.X64: - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "CustomAction", "MsiProcessDrivers_x64"); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.CustomAction, "MsiProcessDrivers_x64"); break; case Platform.IA64: case Platform.ARM: @@ -149,12 +149,15 @@ namespace WixToolset.DifxApp break; } - var row = (MsiDriverPackagesTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "MsiDriverPackages"); - row.Set(0, componentId); - row.Set(1, attributes); + var tuple = section.AddTuple(new MsiDriverPackagesTuple(sourceLineNumbers) + { + ComponentRef = componentId, + Flags = attributes, + }); + if (CompilerConstants.IntegerNotSet != sequence) { - row.Set(2, sequence); + tuple.Sequence = sequence; } } } diff --git a/src/wixext/DifxAppTableDefinitions.cs b/src/wixext/DifxAppTableDefinitions.cs new file mode 100644 index 00000000..1ee33196 --- /dev/null +++ b/src/wixext/DifxAppTableDefinitions.cs @@ -0,0 +1,26 @@ +// 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. + +namespace WixToolset.DifxApp +{ + using WixToolset.Data.WindowsInstaller; + + public static class DifxAppTableDefinitions + { + public static readonly TableDefinition MsiDriverPackages = new TableDefinition( + "MsiDriverPackages", + new[] + { + 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), + new ColumnDefinition("Flags", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 31, description: "Flags for installing and uninstalling driver packages"), + new ColumnDefinition("Sequence", ColumnType.Number, 4, primaryKey: false, nullable: true, ColumnCategory.Unknown, minValue: 0, description: "Order in which the driver packages are processed"), + }, + tupleDefinitionName: DifxAppTupleDefinitions.MsiDriverPackages.Name, + tupleIdIsPrimaryKey: false + ); + + public static readonly TableDefinition[] All = new[] + { + MsiDriverPackages, + }; + } +} diff --git a/src/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs b/src/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs index c87a661b..d3bbc0eb 100644 --- a/src/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs +++ b/src/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs @@ -1,27 +1,13 @@ -// 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. +// 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. namespace WixToolset.DifxApp { using System.Collections.Generic; - using System.Linq; - using System.Xml; using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility; public class DifxAppWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension { - private static readonly TableDefinition[] Tables = LoadTables(); - - public override IEnumerable TableDefinitions => Tables; - - private static TableDefinition[] LoadTables() - { - using (var resourceStream = typeof(DifxAppWindowsInstallerBackendBinderExtension).Assembly.GetManifestResourceStream("WixToolset.DifxApp.tables.xml")) - using (var reader = XmlReader.Create(resourceStream)) - { - var tables = TableDefinitionCollection.Load(reader); - return tables.ToArray(); - } - } + public override IEnumerable TableDefinitions => DifxAppTableDefinitions.All; } } diff --git a/src/wixext/Tuples/MsiDriverPackagesTuple.cs b/src/wixext/Tuples/MsiDriverPackagesTuple.cs index aecc7e77..a1063972 100644 --- a/src/wixext/Tuples/MsiDriverPackagesTuple.cs +++ b/src/wixext/Tuples/MsiDriverPackagesTuple.cs @@ -11,7 +11,7 @@ namespace WixToolset.DifxApp DifxAppTupleDefinitionType.MsiDriverPackages.ToString(), new[] { - new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.Component), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.ComponentRef), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.Flags), IntermediateFieldType.Number), new IntermediateFieldDefinition(nameof(MsiDriverPackagesTupleFields.Sequence), IntermediateFieldType.Number), }, @@ -25,7 +25,7 @@ namespace WixToolset.DifxApp.Tuples public enum MsiDriverPackagesTupleFields { - Component, + ComponentRef, Flags, Sequence, } @@ -42,10 +42,10 @@ namespace WixToolset.DifxApp.Tuples public IntermediateField this[MsiDriverPackagesTupleFields index] => this.Fields[(int)index]; - public string Component + public string ComponentRef { - get => this.Fields[(int)MsiDriverPackagesTupleFields.Component].AsString(); - set => this.Set((int)MsiDriverPackagesTupleFields.Component, value); + get => this.Fields[(int)MsiDriverPackagesTupleFields.ComponentRef].AsString(); + set => this.Set((int)MsiDriverPackagesTupleFields.ComponentRef, value); } public int Flags diff --git a/src/wixext/WixToolset.DifxApp.wixext.csproj b/src/wixext/WixToolset.DifxApp.wixext.csproj index 5717b42a..ca27b04e 100644 --- a/src/wixext/WixToolset.DifxApp.wixext.csproj +++ b/src/wixext/WixToolset.DifxApp.wixext.csproj @@ -13,7 +13,6 @@ - diff --git a/src/wixext/tables.xml b/src/wixext/tables.xml deleted file mode 100644 index c328f875..00000000 --- a/src/wixext/tables.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - -- cgit v1.2.3-55-g6feb