aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Arnson <bob@firegiant.com>2021-03-21 22:03:32 -0400
committerBob Arnson <bob@firegiant.com>2021-03-21 22:07:28 -0400
commit7e44ed28026cad6f624a836a5faf9d9b6174d6f3 (patch)
treebd8f469462a374284fb138cf152e58d23eb5a240
parent6ffe147d054e6515b5276f6412994fe88392366b (diff)
downloadwix-7e44ed28026cad6f624a836a5faf9d9b6174d6f3.tar.gz
wix-7e44ed28026cad6f624a836a5faf9d9b6174d6f3.tar.bz2
wix-7e44ed28026cad6f624a836a5faf9d9b6174d6f3.zip
Convert obsolete RegistryKey/@Action.
-rw-r--r--src/WixToolset.Converters/WixConverter.cs29
-rw-r--r--src/test/WixToolsetTest.Converters/RegistryFixture.cs54
2 files changed, 83 insertions, 0 deletions
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
110 private static readonly XName RequiresRefElementName = WixNamespace + "RequiresRef"; 110 private static readonly XName RequiresRefElementName = WixNamespace + "RequiresRef";
111 private static readonly XName MultiStringValueElementName = WixNamespace + "MultiStringValue"; 111 private static readonly XName MultiStringValueElementName = WixNamespace + "MultiStringValue";
112 private static readonly XName RemotePayloadElementName = WixNamespace + "RemotePayload"; 112 private static readonly XName RemotePayloadElementName = WixNamespace + "RemotePayload";
113 private static readonly XName RegistryKeyElementName = WixNamespace + "RegistryKey";
113 private static readonly XName RegistrySearchElementName = WixNamespace + "RegistrySearch"; 114 private static readonly XName RegistrySearchElementName = WixNamespace + "RegistrySearch";
114 private static readonly XName RequiredPrivilegeElementName = WixNamespace + "RequiredPrivilege"; 115 private static readonly XName RequiredPrivilegeElementName = WixNamespace + "RequiredPrivilege";
115 private static readonly XName RowElementName = WixNamespace + "Row"; 116 private static readonly XName RowElementName = WixNamespace + "Row";
@@ -225,6 +226,7 @@ namespace WixToolset.Converters
225 { WixConverter.ProgressTextElementName, this.ConvertProgressTextElement }, 226 { WixConverter.ProgressTextElementName, this.ConvertProgressTextElement },
226 { WixConverter.PublishElementName, this.ConvertPublishElement }, 227 { WixConverter.PublishElementName, this.ConvertPublishElement },
227 { WixConverter.MultiStringValueElementName, this.ConvertMultiStringValueElement }, 228 { WixConverter.MultiStringValueElementName, this.ConvertMultiStringValueElement },
229 { WixConverter.RegistryKeyElementName, this.ConvertRegistryKeyElement },
228 { WixConverter.RegistrySearchElementName, this.ConvertRegistrySearchElement }, 230 { WixConverter.RegistrySearchElementName, this.ConvertRegistrySearchElement },
229 { WixConverter.RemotePayloadElementName, this.ConvertRemotePayloadElement }, 231 { WixConverter.RemotePayloadElementName, this.ConvertRemotePayloadElement },
230 { WixConverter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement }, 232 { WixConverter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement },
@@ -1225,6 +1227,28 @@ namespace WixToolset.Converters
1225 1227
1226 private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value"); 1228 private void ConvertMultiStringValueElement(XElement element) => this.ConvertInnerTextToAttribute(element, "Value");
1227 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
1228 private void ConvertRemotePayloadElement(XElement element) 1252 private void ConvertRemotePayloadElement(XElement element)
1229 { 1253 {
1230 var xParent = element.Parent; 1254 var xParent = element.Parent;
@@ -2156,6 +2180,11 @@ namespace WixToolset.Converters
2156 /// CustomTable elements that don't contain the table definition are now CustomTableRef. 2180 /// CustomTable elements that don't contain the table definition are now CustomTableRef.
2157 /// </summary> 2181 /// </summary>
2158 CustomTableRef, 2182 CustomTableRef,
2183
2184 /// <summary>
2185 /// The RegistryKey element's Action attribute is obsolete.
2186 /// </summary>
2187 RegistryKeyActionObsolete,
2159 } 2188 }
2160 } 2189 }
2161} 2190}
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 @@
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
3namespace 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}