From 7a934bcfb8d460b0cf91a51caa956a8bbff14edf Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Mon, 28 Oct 2019 21:17:09 -0400 Subject: Modernize tuple creation and update dependencies. --- src/wixext/FirewallCompiler.cs | 33 ++++++++++------------ .../FirewallWindowsInstallerBackendExtension.cs | 5 +++- src/wixext/Tuples/FirewallTupleDefinitions.cs | 3 +- src/wixext/Tuples/WixFirewallExceptionTuple.cs | 19 ++++--------- src/wixext/tables.xml | 2 +- 5 files changed, 27 insertions(+), 35 deletions(-) (limited to 'src/wixext') diff --git a/src/wixext/FirewallCompiler.cs b/src/wixext/FirewallCompiler.cs index 0696b4b1..353afff3 100644 --- a/src/wixext/FirewallCompiler.cs +++ b/src/wixext/FirewallCompiler.cs @@ -4,10 +4,10 @@ namespace WixToolset.Firewall { using System; using System.Collections.Generic; - using System.Globalization; using System.Xml.Linq; using WixToolset.Data; using WixToolset.Extensibility; + using WixToolset.Firewall.Tuples; /// /// The compiler for the WiX Toolset Firewall Extension. @@ -255,13 +255,18 @@ namespace WixToolset.Firewall fileId = file; } - var row = this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixFirewallException", id); - row.Set(1, name); - row.Set(2, remoteAddresses); + var tuple = new WixFirewallExceptionTuple(sourceLineNumbers, id) + { + Name = name, + RemoteAddresses = remoteAddresses, + Profile = profile ?? FirewallConstants.NET_FW_PROFILE2_ALL, + ComponentRef = componentId, + Description = description, + }; if (!String.IsNullOrEmpty(port)) { - row.Set(3, port); + tuple.Port = port; if (!protocol.HasValue) { @@ -270,32 +275,24 @@ namespace WixToolset.Firewall } } - if (protocol.HasValue) - { - row.Set(4, protocol); - } + tuple.Protocol = protocol.Value; if (!String.IsNullOrEmpty(fileId)) { - row.Set(5, $"[#{fileId}]"); + tuple.Program = $"[#{fileId}]"; this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "File", fileId); } else if (!String.IsNullOrEmpty(program)) { - row.Set(5, program); + tuple.Program = program; } if (CompilerConstants.IntegerNotSet != attributes) { - row.Set(6, attributes); + tuple.Attributes = attributes; } - // Default is "all" - row.Set(7, profile ?? FirewallConstants.NET_FW_PROFILE2_ALL); - - row.Set(8, componentId); - - row.Set(9, description); + section.Tuples.Add(tuple); if (this.Context.Platform == Platform.ARM) { diff --git a/src/wixext/FirewallWindowsInstallerBackendExtension.cs b/src/wixext/FirewallWindowsInstallerBackendExtension.cs index a3949e69..47a01ac0 100644 --- a/src/wixext/FirewallWindowsInstallerBackendExtension.cs +++ b/src/wixext/FirewallWindowsInstallerBackendExtension.cs @@ -1,9 +1,10 @@ -// 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.Firewall { using System.Linq; using System.Xml; + using WixToolset.Data; using WixToolset.Data.WindowsInstaller; using WixToolset.Extensibility; @@ -13,6 +14,8 @@ namespace WixToolset.Firewall protected override TableDefinition[] TableDefinitionsForTuples => Tables; + public override bool TryAddTupleToOutput(IntermediateTuple tuple, WindowsInstallerData output) => this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, this.TableDefinitionsForTuples, true); + private static TableDefinition[] LoadTables() { using (var resourceStream = typeof(FirewallWindowsInstallerBackendBinderExtension).Assembly.GetManifestResourceStream("WixToolset.Firewall.tables.xml")) diff --git a/src/wixext/Tuples/FirewallTupleDefinitions.cs b/src/wixext/Tuples/FirewallTupleDefinitions.cs index 79fc28cf..df595c18 100644 --- a/src/wixext/Tuples/FirewallTupleDefinitions.cs +++ b/src/wixext/Tuples/FirewallTupleDefinitions.cs @@ -15,7 +15,6 @@ namespace WixToolset.Firewall.Tuples FirewallTupleDefinitionNames.WixFirewallException, new[] { - new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.WixFirewallException), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Name), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.RemoteAddresses), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Port), IntermediateFieldType.String), @@ -23,7 +22,7 @@ namespace WixToolset.Firewall.Tuples new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Program), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Attributes), IntermediateFieldType.Number), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Profile), IntermediateFieldType.Number), - new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Component_), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.ComponentRef), IntermediateFieldType.String), new IntermediateFieldDefinition(nameof(WixFirewallExceptionTupleFields.Description), IntermediateFieldType.String), }, typeof(WixFirewallExceptionTuple)); diff --git a/src/wixext/Tuples/WixFirewallExceptionTuple.cs b/src/wixext/Tuples/WixFirewallExceptionTuple.cs index 715a4b9b..3c7cda3a 100644 --- a/src/wixext/Tuples/WixFirewallExceptionTuple.cs +++ b/src/wixext/Tuples/WixFirewallExceptionTuple.cs @@ -6,7 +6,6 @@ namespace WixToolset.Firewall.Tuples public enum WixFirewallExceptionTupleFields { - WixFirewallException, Name, RemoteAddresses, Port, @@ -14,7 +13,7 @@ namespace WixToolset.Firewall.Tuples Program, Attributes, Profile, - Component_, + ComponentRef, Description, } @@ -30,12 +29,6 @@ namespace WixToolset.Firewall.Tuples public IntermediateField this[WixFirewallExceptionTupleFields index] => this.Fields[(int)index]; - public string WixFirewallException - { - get => this.Fields[(int)WixFirewallExceptionTupleFields.WixFirewallException].AsString(); - set => this.Set((int)WixFirewallExceptionTupleFields.WixFirewallException, value); - } - public string Name { get => this.Fields[(int)WixFirewallExceptionTupleFields.Name].AsString(); @@ -54,9 +47,9 @@ namespace WixToolset.Firewall.Tuples set => this.Set((int)WixFirewallExceptionTupleFields.Port, value); } - public int Protocol + public int? Protocol { - get => this.Fields[(int)WixFirewallExceptionTupleFields.Protocol].AsNumber(); + get => this.Fields[(int)WixFirewallExceptionTupleFields.Protocol].AsNullableNumber(); set => this.Set((int)WixFirewallExceptionTupleFields.Protocol, value); } @@ -78,10 +71,10 @@ namespace WixToolset.Firewall.Tuples set => this.Set((int)WixFirewallExceptionTupleFields.Profile, value); } - public string Component_ + public string ComponentRef { - get => this.Fields[(int)WixFirewallExceptionTupleFields.Component_].AsString(); - set => this.Set((int)WixFirewallExceptionTupleFields.Component_, value); + get => this.Fields[(int)WixFirewallExceptionTupleFields.ComponentRef].AsString(); + set => this.Set((int)WixFirewallExceptionTupleFields.ComponentRef, value); } public string Description diff --git a/src/wixext/tables.xml b/src/wixext/tables.xml index 5b408b96..b0c32305 100644 --- a/src/wixext/tables.xml +++ b/src/wixext/tables.xml @@ -17,7 +17,7 @@ + description="Vital=1" />