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() --- .../ExtensibilityServices/ParseHelper.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs') 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