@joebigelow / wix / commits / 7e44ed28

Convert obsolete RegistryKey/@Action.

Bob Arnson committed Mar 21, 2021 at 22:03 UTC 7e44ed28026cad6f624a836a5faf9d9b6174d6f3
2 files changed +83
src/WixToolset.Converters/WixConverter.cs
+29
@@ -110,6 +110,7 @@ namespace WixToolset.Converters
110 private static readonly XName RequiresRefElementName = WixNamespace + "RequiresRef";
111 private static readonly XName MultiStringValueElementName = WixNamespace + "MultiStringValue";
112 private static readonly XName RemotePayloadElementName = WixNamespace + "RemotePayload";
113 + private static readonly XName RegistryKeyElementName = WixNamespace + "RegistryKey";
114 private static readonly XName RegistrySearchElementName = WixNamespace + "RegistrySearch";
115 private static readonly XName RequiredPrivilegeElementName = WixNamespace + "RequiredPrivilege";
116 private static readonly XName RowElementName = WixNamespace + "Row";
@@ -225,6 +226,7 @@ namespace WixToolset.Converters
226 { WixConverter.ProgressTextElementName, this.ConvertProgressTextElement },
227 { WixConverter.PublishElementName, this.ConvertPublishElement },
228 { WixConverter.MultiStringValueElementName, this.ConvertMultiStringValueElement },
229 + { WixConverter.RegistryKeyElementName, this.ConvertRegistryKeyElement },
230 { WixConverter.RegistrySearchElementName, this.ConvertRegistrySearchElement },
231 { WixConverter.RemotePayloadElementName, this.ConvertRemotePayloadElement },
232 { WixConverter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement },
@@ -1225,6 +1227,28 @@ namespace WixToolset.Converters
1227
1228 private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value");
1229
1230 + private void ConvertRegistryKeyElement(XElement element)
1231 + {
1232 + var xAction = element.Attribute("Action");
1233 +
1234 + if (xAction != null
1235 + && 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'."))
1236 + {
1237 + switch (xAction?.Value)
1238 + {
1239 + case "create":
1240 + element.SetAttributeValue("ForceCreateOnInstall", "yes");
1241 + break;
1242 + case "createAndRemoveOnUninstall":
1243 + element.SetAttributeValue("ForceCreateOnInstall", "yes");
1244 + element.SetAttributeValue("ForceDeleteOnUninstall", "yes");
1245 + break;
1246 + }
1247 +
1248 + xAction.Remove();
1249 + }
1250 + }
1251 +
1252 private void ConvertRemotePayloadElement(XElement element)
1253 {
1254 var xParent = element.Parent;
@@ -2156,6 +2180,11 @@ namespace WixToolset.Converters
2180 /// CustomTable elements that don't contain the table definition are now CustomTableRef.
2181 /// </summary>
2182 CustomTableRef,
2183 +
2184 + /// <summary>
2185 + /// The RegistryKey element's Action attribute is obsolete.
2186 + /// </summary>
2187 + RegistryKeyActionObsolete,
2188 }
2189 }
2190 }
src/test/WixToolsetTest.Converters/RegistryFixture.cs new
+54
@@ -0,0 +1,54 @@
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 WixToolsetTest.Converters
4 +{
5 + using System;
6 + using System.Xml.Linq;
7 + using WixBuildTools.TestSupport;
8 + using WixToolset.Converters;
9 + using WixToolsetTest.Converters.Mocks;
10 + using Xunit;
11 +
12 + public class RegistryFixture : BaseConverterFixture
13 + {
14 + [Fact]
15 + public void FixRegistryKeyAction()
16 + {
17 + var parse = String.Join(Environment.NewLine,
18 + "<?xml version=\"1.0\" encoding=\"utf-16\"?>",
19 + "<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi'>",
20 + " <Fragment>",
21 + " <Component>",
22 + " <RegistryKey Id='ExampleRegistryKey1' Action='create' Root='HKLM' Key='TestRegistryKey1' />",
23 + " <RegistryKey Id='ExampleRegistryKey2' Action='createAndRemoveOnUninstall' Root='HKLM' Key='TestRegistryKey2' />",
24 + " <RegistryKey Id='ExampleRegistryKey3' Action='none' Root='HKLM' Key='TestRegistryKey3' />",
25 + " </Component>",
26 + " </Fragment>",
27 + "</Wix>");
28 +
29 + var expected = new[]
30 + {
31 + "<Wix xmlns=\"http://wixtoolset.org/schemas/v4/wxs\">",
32 + " <Fragment>",
33 + " <Component>",
34 + " <RegistryKey Id=\"ExampleRegistryKey1\" Root=\"HKLM\" Key=\"TestRegistryKey1\" ForceCreateOnInstall=\"yes\" />",
35 + " <RegistryKey Id=\"ExampleRegistryKey2\" Root=\"HKLM\" Key=\"TestRegistryKey2\" ForceCreateOnInstall=\"yes\" ForceDeleteOnUninstall=\"yes\" />",
36 + " <RegistryKey Id=\"ExampleRegistryKey3\" Root=\"HKLM\" Key=\"TestRegistryKey3\" />",
37 + " </Component>",
38 + " </Fragment>",
39 + "</Wix>"
40 + };
41 +
42 + var document = XDocument.Parse(parse, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo);
43 +
44 + var messaging = new MockMessaging();
45 + var converter = new WixConverter(messaging, 2, null, null);
46 +
47 + var errors = converter.ConvertDocument(document);
48 + Assert.Equal(5, errors);
49 +
50 + var actualLines = UnformattedDocumentLines(document);
51 + WixAssert.CompareLineByLine(expected, actualLines);
52 + }
53 + }
54 +}