From 0731fa5ca035f0ca9d5cb28f5e3ef07d98f9a7ae Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 29 Dec 2017 21:47:48 -0800 Subject: Implement IParseHelper.GetAttributeMsidbRegistryRootValue() --- src/WixToolset.Core/CompilerCore.cs | 64 +--------------------- .../ExtensibilityServices/ParseHelper.cs | 60 ++++++++++++++++++++ 2 files changed, 61 insertions(+), 63 deletions(-) diff --git a/src/WixToolset.Core/CompilerCore.cs b/src/WixToolset.Core/CompilerCore.cs index 7cb7b703..651c80a3 100644 --- a/src/WixToolset.Core/CompilerCore.cs +++ b/src/WixToolset.Core/CompilerCore.cs @@ -830,42 +830,6 @@ namespace WixToolset.Core return this.parseHelper.GetAttributeVersionValue(sourceLineNumbers, attribute); } - /// - /// Gets a RegistryRoot value and displays an error for an illegal value. - /// - /// Source line information about the owner element. - /// The attribute containing the value to get. - /// Whether HKMU is considered a valid value. - /// The attribute's RegisitryRootType value. - [SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes")] - public Wix.RegistryRootType GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) - { - Wix.RegistryRootType registryRoot = Wix.RegistryRootType.NotSet; - string value = this.GetAttributeValue(sourceLineNumbers, attribute); - - if (0 < value.Length) - { - registryRoot = Wix.Enums.ParseRegistryRootType(value); - - if (Wix.RegistryRootType.IllegalValue == registryRoot || (!allowHkmu && Wix.RegistryRootType.HKMU == registryRoot)) - { - // TODO: Find a way to expose the valid values programatically! - if (allowHkmu) - { - this.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, - "HKMU", "HKCR", "HKCU", "HKLM", "HKU")); - } - else - { - this.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, - "HKCR", "HKCU", "HKLM", "HKU")); - } - } - } - - return registryRoot; - } - /// /// Gets a RegistryRoot as a MsiInterop.MsidbRegistryRoot value and displays an error for an illegal value. /// @@ -876,33 +840,7 @@ namespace WixToolset.Core [SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes")] public int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) { - Wix.RegistryRootType registryRoot = this.GetAttributeRegistryRootValue(sourceLineNumbers, attribute, allowHkmu); - - switch (registryRoot) - { - case Wix.RegistryRootType.NotSet: - return CompilerConstants.IntegerNotSet; - case Wix.RegistryRootType.HKCR: - return Core.Native.MsiInterop.MsidbRegistryRootClassesRoot; - case Wix.RegistryRootType.HKCU: - return Core.Native.MsiInterop.MsidbRegistryRootCurrentUser; - case Wix.RegistryRootType.HKLM: - return Core.Native.MsiInterop.MsidbRegistryRootLocalMachine; - case Wix.RegistryRootType.HKU: - return Core.Native.MsiInterop.MsidbRegistryRootUsers; - case Wix.RegistryRootType.HKMU: - // This is gross, but there was *one* registry root parsing instance - // (in Compiler.ParseRegistrySearchElement()) that did not explicitly - // handle HKMU and it fell through to the default error case. The - // others treated it as -1, which is what we do here. - if (allowHkmu) - { - return -1; - } - break; - } - - return CompilerConstants.IntegerNotSet; + return this.parseHelper.GetAttributeMsidbRegistryRootValue(sourceLineNumbers, attribute, allowHkmu); } /// diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs index d2486890..b65abdfb 100644 --- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs @@ -12,6 +12,7 @@ namespace WixToolset.Core.ExtensibilityServices using System.Text.RegularExpressions; using System.Xml.Linq; using WixToolset.Data; + using Wix = WixToolset.Data.Serialize; using WixToolset.Data.Tuples; using WixToolset.Extensibility; using WixToolset.Extensibility.Services; @@ -571,6 +572,37 @@ namespace WixToolset.Core.ExtensibilityServices return Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, emptyRule); } + public int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) + { + Wix.RegistryRootType registryRoot = this.GetAttributeRegistryRootValue(sourceLineNumbers, attribute, allowHkmu); + + switch (registryRoot) + { + case Wix.RegistryRootType.NotSet: + return CompilerConstants.IntegerNotSet; + case Wix.RegistryRootType.HKCR: + return Core.Native.MsiInterop.MsidbRegistryRootClassesRoot; + case Wix.RegistryRootType.HKCU: + return Core.Native.MsiInterop.MsidbRegistryRootCurrentUser; + case Wix.RegistryRootType.HKLM: + return Core.Native.MsiInterop.MsidbRegistryRootLocalMachine; + case Wix.RegistryRootType.HKU: + return Core.Native.MsiInterop.MsidbRegistryRootUsers; + case Wix.RegistryRootType.HKMU: + // This is gross, but there was *one* registry root parsing instance + // (in Compiler.ParseRegistrySearchElement()) that did not explicitly + // handle HKMU and it fell through to the default error case. The + // others treated it as -1, which is what we do here. + if (allowHkmu) + { + return -1; + } + break; + } + + return CompilerConstants.IntegerNotSet; + } + public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) { var value = this.GetAttributeValue(sourceLineNumbers, attribute); @@ -814,6 +846,34 @@ namespace WixToolset.Core.ExtensibilityServices return row; } + private Wix.RegistryRootType GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) + { + Wix.RegistryRootType registryRoot = Wix.RegistryRootType.NotSet; + string value = this.GetAttributeValue(sourceLineNumbers, attribute); + + if (0 < value.Length) + { + registryRoot = Wix.Enums.ParseRegistryRootType(value); + + if (Wix.RegistryRootType.IllegalValue == registryRoot || (!allowHkmu && Wix.RegistryRootType.HKMU == registryRoot)) + { + // TODO: Find a way to expose the valid values programatically! + if (allowHkmu) + { + this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, + "HKMU", "HKCR", "HKCU", "HKLM", "HKU")); + } + else + { + this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, + "HKCR", "HKCU", "HKLM", "HKU")); + } + } + } + + return registryRoot; + } + private static bool TryFindExtension(IEnumerable extensions, XNamespace ns, out ICompilerExtension extension) { extension = null; -- cgit v1.2.3-55-g6feb