From 0177cb5b9b08351266816097ea9e8561b9ec0973 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Fri, 23 Apr 2021 17:50:54 -0400 Subject: Fix for added elements to reference platform-specific extension custom actions. --- src/WixToolset.Converters/WixConverter.cs | 113 +++++++++++++++++++++ .../ConverterIntegrationFixture.cs | 3 +- .../UtilExtensionFixture.cs | 75 ++++++++++++++ 3 files changed, 189 insertions(+), 2 deletions(-) diff --git a/src/WixToolset.Converters/WixConverter.cs b/src/WixToolset.Converters/WixConverter.cs index 6080eeb9..e42d0605 100644 --- a/src/WixToolset.Converters/WixConverter.cs +++ b/src/WixToolset.Converters/WixConverter.cs @@ -105,6 +105,7 @@ namespace WixToolset.Converters private static readonly XName PermissionExElementName = WixNamespace + "PermissionEx"; private static readonly XName ProductElementName = WixNamespace + "Product"; private static readonly XName ProgressTextElementName = WixNamespace + "ProgressText"; + private static readonly XName PropertyRefElementName = WixNamespace + "PropertyRef"; private static readonly XName PublishElementName = WixNamespace + "Publish"; private static readonly XName ProvidesElementName = WixNamespace + "Provides"; private static readonly XName RequiresElementName = WixNamespace + "Requires"; @@ -138,6 +139,7 @@ namespace WixToolset.Converters private static readonly XName UtilRegistrySearchName = WixUtilNamespace + "RegistrySearch"; private static readonly XName UtilXmlConfigElementName = WixUtilNamespace + "XmlConfig"; private static readonly XName CustomActionElementName = WixNamespace + "CustomAction"; + private static readonly XName CustomActionRefElementName = WixNamespace + "CustomActionRef"; private static readonly XName PropertyElementName = WixNamespace + "Property"; private static readonly XName Wix4ElementName = WixNamespace + "Wix"; private static readonly XName Wix3ElementName = Wix3Namespace + "Wix"; @@ -230,12 +232,14 @@ namespace WixToolset.Converters { WixConverter.PermissionExElementName, this.ConvertPermissionExElement }, { WixConverter.ProductElementName, this.ConvertProductElement }, { WixConverter.ProgressTextElementName, this.ConvertProgressTextElement }, + { WixConverter.PropertyRefElementName, this.ConvertPropertyRefElement }, { WixConverter.PublishElementName, this.ConvertPublishElement }, { WixConverter.MultiStringValueElementName, this.ConvertMultiStringValueElement }, { WixConverter.RegistryKeyElementName, this.ConvertRegistryKeyElement }, { WixConverter.RegistrySearchElementName, this.ConvertRegistrySearchElement }, { WixConverter.RemotePayloadElementName, this.ConvertRemotePayloadElement }, { WixConverter.RequiredPrivilegeElementName, this.ConvertRequiredPrivilegeElement }, + { WixConverter.CustomActionRefElementName, this.ConvertCustomActionRefElement }, { WixConverter.ServiceArgumentElementName, this.ConvertServiceArgumentElement }, { WixConverter.SetDirectoryElementName, this.ConvertSetDirectoryElement }, { WixConverter.SetPropertyElementName, this.ConvertSetPropertyElement }, @@ -1293,6 +1297,110 @@ namespace WixToolset.Converters xAttribute?.Remove(); } + private void ConvertPropertyRefElement(XElement element) + { + var newElementName = String.Empty; + + var id = element.Attribute("Id"); + switch (id?.Value) + { + case "WIX_SUITE_BACKOFFICE": + case "WIX_SUITE_BLADE": + case "WIX_SUITE_COMMUNICATIONS": + case "WIX_SUITE_COMPUTE_SERVER": + case "WIX_SUITE_DATACENTER": + case "WIX_SUITE_EMBEDDED_RESTRICTED": + case "WIX_SUITE_EMBEDDEDNT": + case "WIX_SUITE_ENTERPRISE": + case "WIX_SUITE_MEDIACENTER": + case "WIX_SUITE_PERSONAL": + case "WIX_SUITE_SECURITY_APPLIANCE": + case "WIX_SUITE_SERVERR2": + case "WIX_SUITE_SINGLEUSERTS": + case "WIX_SUITE_SMALLBUSINESS": + case "WIX_SUITE_SMALLBUSINESS_RESTRICTED": + case "WIX_SUITE_STARTER": + case "WIX_SUITE_STORAGE_SERVER": + case "WIX_SUITE_TABLETPC": + case "WIX_SUITE_TERMINAL": + case "WIX_SUITE_WH_SERVER": + newElementName = "QueryWindowsSuiteInfo"; + break; + case "WIX_DIR_ADMINTOOLS": + case "WIX_DIR_ALTSTARTUP": + case "WIX_DIR_CDBURN_AREA": + case "WIX_DIR_COMMON_ADMINTOOLS": + case "WIX_DIR_COMMON_ALTSTARTUP": + case "WIX_DIR_COMMON_DOCUMENTS": + case "WIX_DIR_COMMON_FAVORITES": + case "WIX_DIR_COMMON_MUSIC": + case "WIX_DIR_COMMON_PICTURES": + case "WIX_DIR_COMMON_VIDEO": + case "WIX_DIR_COOKIES": + case "WIX_DIR_DESKTOP": + case "WIX_DIR_HISTORY": + case "WIX_DIR_INTERNET_CACHE": + case "WIX_DIR_MYMUSIC": + case "WIX_DIR_MYPICTURES": + case "WIX_DIR_MYVIDEO": + case "WIX_DIR_NETHOOD": + case "WIX_DIR_PERSONAL": + case "WIX_DIR_PRINTHOOD": + case "WIX_DIR_PROFILE": + case "WIX_DIR_RECENT": + case "WIX_DIR_RESOURCES": + newElementName = "QueryWindowsDirectories"; + break; + case "WIX_DWM_COMPOSITION_ENABLED": + case "WIX_WDDM_DRIVER_PRESENT": + newElementName = "QueryWindowsDriverInfo"; + break; + case "WIX_ACCOUNT_LOCALSYSTEM": + case "WIX_ACCOUNT_LOCALSERVICE": + case "WIX_ACCOUNT_NETWORKSERVICE": + case "WIX_ACCOUNT_ADMINISTRATORS": + case "WIX_ACCOUNT_USERS": + case "WIX_ACCOUNT_GUESTS": + case "WIX_ACCOUNT_PERFLOGUSERS": + case "WIX_ACCOUNT_PERFLOGUSERS_NODOMAIN": + newElementName = "QueryWindowsWellKnownSIDs"; + break; + } + + if (!String.IsNullOrEmpty(newElementName) + && this.OnError(ConverterTestType.UtilReferencesReplaced, element, "Custom action and property reference {0} to WixUtilExtension have been replaced with strongly-typed elements.", id)) + { + element.AddAfterSelf(new XElement(WixUtilNamespace + newElementName)); + element.Remove(); + } + } + + private void ConvertCustomActionRefElement(XElement element) + { + var newElementName = String.Empty; + + var id = element.Attribute("Id"); + switch (id?.Value) + { + case "WixBroadcastSettingChange": + case "WixBroadcastEnvironmentChange": + case "WixCheckRebootRequired": + case "WixExitEarlyWithSuccess": + case "WixFailWhenDeferred": + case "WixWaitForEvent": + case "WixWaitForEventDeferred": + newElementName = id?.Value.Substring(3); // strip leading Wix + break; + } + + if (!String.IsNullOrEmpty(newElementName) + && this.OnError(ConverterTestType.UtilReferencesReplaced, element, "Custom action and property reference {0} to WixUtilExtension have been replaced with strongly-typed elements.", id)) + { + element.AddAfterSelf(new XElement(WixUtilNamespace + newElementName)); + element.Remove(); + } + } + private void ConvertPublishElement(XElement element) { this.ConvertInnerTextToAttribute(element, "Condition"); @@ -2317,6 +2425,11 @@ namespace WixToolset.Converters /// Standard directories should no longer be defined using the Directory element. /// DefiningStandardDirectoryDeprecated, + + /// + /// Naked custom action and property references replaced with WixUtilExtension elements. + /// + UtilReferencesReplaced, } } } diff --git a/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs b/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs index acd7991e..a39f6243 100644 --- a/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs +++ b/src/test/WixToolsetTest.Converters/ConverterIntegrationFixture.cs @@ -8,7 +8,6 @@ namespace WixToolsetTest.Converters using WixBuildTools.TestSupport; using WixToolset.Converters; using WixToolset.Core; - using WixToolset.Core.ExtensibilityServices; using WixToolset.Core.TestPackage; using WixToolsetTest.Converters.Mocks; using Xunit; @@ -88,7 +87,7 @@ namespace WixToolsetTest.Converters var converter = new WixConverter(messaging, 4); var errors = converter.ConvertFile(targetFile, true); - Assert.Equal(10, errors); + Assert.Single(messaging.Messages.Where(m => m.Id == 5/*WixConverter.ConverterTestType.UnauthorizedAccessException*/)); } } diff --git a/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs b/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs index 9964e3b0..10450c68 100644 --- a/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs +++ b/src/test/WixToolsetTest.Converters/UtilExtensionFixture.cs @@ -111,5 +111,80 @@ namespace WixToolsetTest.Converters var actualLines = UnformattedDocumentLines(document); WixAssert.CompareLineByLine(expected, actualLines); } + + + [Fact] + public void FixXmlConfigValueCData() + { + var parse = String.Join(Environment.NewLine, + "", + " ", + " ", + " b]]>", + " ", + " ", + ""); + + 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(3, errors); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + } + + [Fact] + public void FixQueryOsPropertyRefs() + { + 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(6, errors); + + var actualLines = UnformattedDocumentLines(document); + WixAssert.CompareLineByLine(expected, actualLines); + } } } -- cgit v1.2.3-55-g6feb