From 007e4dfe58293212180a617da25025e52677eee8 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 11 Feb 2021 14:40:06 -0800 Subject: Preserve unconvertable Win64 attribute content --- src/WixToolset.Converters/WixConverter.cs | 36 +++++++++++++++++----- .../WixToolsetTest.Converters/BitnessFixture.cs | 8 ++++- 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index 18cd7115..4d5564b4 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -636,8 +636,8 @@ namespace WixToolset.Converters var win64 = element.Attribute("Win64"); if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead.")) { - var value = win64.Value; - element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32")); + var value = this.UpdateWin64ValueToBitnessValue(win64); + element.Add(new XAttribute("Bitness", value)); win64.Remove(); } } @@ -755,8 +755,8 @@ namespace WixToolset.Converters var win64 = element.Attribute("Win64"); if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead.")) { - var value = win64.Value; - element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32")); + var value = this.UpdateWin64ValueToBitnessValue(win64); + element.Add(new XAttribute("Bitness", value)); win64.Remove(); } } @@ -1104,8 +1104,8 @@ namespace WixToolset.Converters var win64 = element.Attribute("Win64"); if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead.")) { - var value = win64.Value; - element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32")); + var value = this.UpdateWin64ValueToBitnessValue(win64); + element.Add(new XAttribute("Bitness", value)); win64.Remove(); } } @@ -1296,8 +1296,8 @@ namespace WixToolset.Converters var win64 = element.Attribute("Win64"); if (win64 != null && this.OnError(ConverterTestType.Win64AttributeRenamed, element, "The Win64 attribute has been renamed. Use the Bitness attribute instead.")) { - var value = win64.Value; - element.Add(new XAttribute("Bitness", value == "yes" ? "always64" : "always32")); + var value = this.UpdateWin64ValueToBitnessValue(win64); + element.Add(new XAttribute("Bitness", value)); win64.Remove(); } @@ -1341,6 +1341,21 @@ namespace WixToolset.Converters } } + private string UpdateWin64ValueToBitnessValue(XAttribute xWin64Attribute) + { + var value = xWin64Attribute.Value ?? String.Empty; + switch (value) + { + case "yes": + return "always64"; + case "no": + return "always32"; + default: + this.OnError(ConverterTestType.Win64AttributeRenameCannotBeAutomatic, xWin64Attribute, "Breaking change: The Win64 attribute's value '{0}' cannot be converted automatically to the new Bitness attribute.", value); + return value; + } + } + private IEnumerable YieldConverterTypes(IEnumerable types) { if (null != types) @@ -1795,6 +1810,11 @@ namespace WixToolset.Converters /// The Win64 attribute has been renamed. Use the Bitness attribute instead. /// Win64AttributeRenamed, + + /// + /// Breaking change: The Win64 attribute's value '{0}' cannot be converted automatically to the new Bitness attribute. + /// + Win64AttributeRenameCannotBeAutomatic, } } } diff --git a/src/test/WixToolsetTest.Converters/BitnessFixture.cs b/src/test/WixToolsetTest.Converters/BitnessFixture.cs index 9996806d..e45a9388 100644 --- a/src/test/WixToolsetTest.Converters/BitnessFixture.cs +++ b/src/test/WixToolsetTest.Converters/BitnessFixture.cs @@ -27,6 +27,9 @@ namespace WixToolsetTest.Converters " ", " ", " ", + " ", + " ", + " ", " ", ""); @@ -43,6 +46,9 @@ namespace WixToolsetTest.Converters " ", " ", " ", + " ", + " ", + " ", " ", "" }; @@ -53,7 +59,7 @@ namespace WixToolsetTest.Converters var converter = new WixConverter(messaging, 2, null, null); var errors = converter.ConvertDocument(document); - Assert.Equal(7, errors); + Assert.Equal(10, errors); var actualLines = UnformattedDocumentLines(document); WixAssert.CompareLineByLine(expected, actualLines); -- cgit v1.2.3-55-g6feb