From 7e44ed28026cad6f624a836a5faf9d9b6174d6f3 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Sun, 21 Mar 2021 22:03:32 -0400 Subject: Convert obsolete RegistryKey/@Action. --- src/WixToolset.Converters/WixConverter.cs | 29 ++++++++++++ .../WixToolsetTest.Converters/RegistryFixture.cs | 54 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/WixToolsetTest.Converters/RegistryFixture.cs (limited to 'src') diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index 9ada4745..09a4168a 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -110,6 +110,7 @@ namespace WixToolset.Converters private static readonly XName RequiresRefElementName = WixNamespace + "RequiresRef"; private static readonly XName MultiStringValueElementName = WixNamespace + "MultiStringValue"; private static readonly XName RemotePayloadElementName = WixNamespace + "RemotePayload"; + private static readonly XName RegistryKeyElementName = WixNamespace + "RegistryKey"; private static readonly XName RegistrySearchElementName = WixNamespace + "RegistrySearch"; private static readonly XName RequiredPrivilegeElementName = WixNamespace + "RequiredPrivilege"; private static readonly XName RowElementName = WixNamespace + "Row"; @@ -225,6 +226,7 @@ namespace WixToolset.Converters { WixConverter.ProgressTextElementName, this.ConvertProgressTextElement }, { WixConverter.PublishElementName, this.ConvertPublishElement }, { WixConverter.MultiStringValueElementName, this.ConvertMultiStringValueElement }, + { WixConverter.RegistryKeyElementName, this.ConvertRegistryKeyElement }, { WixConverter.RegistrySearchElementName, this.ConvertRegistrySearchElement }, { WixConverter.RemotePayloadElementName, this.ConvertRemotePayloadElement }, { WixConverter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement }, @@ -1225,6 +1227,28 @@ namespace WixToolset.Converters private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); + private void ConvertRegistryKeyElement(XElement element) + { + var xAction = element.Attribute("Action"); + + if (xAction != null + && this.OnError(ConverterTestType.RegistryKeyActionObsolete, element, "The RegistryKey element's Action attribute is obsolete. Action='create' will be converted to ForceCreateOnInstall='yes'. Action='createAndRemoveOnUninstall' will be converted to ForceCreateOnInstall='yes' and ForceDeleteOnUninstall='yes'.")) + { + switch (xAction?.Value) + { + case "create": + element.SetAttributeValue("ForceCreateOnInstall", "yes"); + break; + case "createAndRemoveOnUninstall": + element.SetAttributeValue("ForceCreateOnInstall", "yes"); + element.SetAttributeValue("ForceDeleteOnUninstall", "yes"); + break; + } + + xAction.Remove(); + } + } + private void ConvertRemotePayloadElement(XElement element) { var xParent = element.Parent; @@ -2156,6 +2180,11 @@ namespace WixToolset.Converters /// CustomTable elements that don't contain the table definition are now CustomTableRef. /// CustomTableRef, + + /// + /// The RegistryKey element's Action attribute is obsolete. + /// + RegistryKeyActionObsolete, } } } diff --git a/src/test/WixToolsetTest.Converters/RegistryFixture.cs b/src/test/WixToolsetTest.Converters/RegistryFixture.cs new file mode 100644 index 00000000..405f5416 --- /dev/null +++ b/src/test/WixToolsetTest.Converters/RegistryFixture.cs @@ -0,0 +1,54 @@ +// 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 WixToolsetTest.Converters +{ + using System; + using System.Xml.Linq; + using WixBuildTools.TestSupport; + using WixToolset.Converters; + using WixToolsetTest.Converters.Mocks; + using Xunit; + + public class RegistryFixture : BaseConverterFixture + { + [Fact] + public void FixRegistryKeyAction() + { + var parse = String.Join(Environment.NewLine, + "", + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + ""); + + var expected = new[] + { + "", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + "" + }; + + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); + + var messaging = new MockMessaging(); + var converter = new WixConverter(messaging, 2, null, null); + + var errors = converter.ConvertDocument(document); + Assert.Equal(5, errors); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + } + } +} -- cgit v1.2.3-55-g6feb