Implement IParseHelper.GetAttributeMsidbRegistryRootValue()
Rob Mensching committed
Dec 29, 2017 at 21:47 UTC
0731fa5ca035f0ca9d5cb28f5e3ef07d98f9a7ae
2 files changed
+61
-63
src/WixToolset.Core/CompilerCore.cs
+1
-63
@@ -830,42 +830,6 @@ namespace WixToolset.Core
830
return this.parseHelper.GetAttributeVersionValue(sourceLineNumbers, attribute);
831
}
832
833
- /// <summary>
834
- /// Gets a RegistryRoot value and displays an error for an illegal value.
835
- /// </summary>
836
- /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
837
- /// <param name="attribute">The attribute containing the value to get.</param>
838
- /// <param name="allowHkmu">Whether HKMU is considered a valid value.</param>
839
- /// <returns>The attribute's RegisitryRootType value.</returns>
840
- [SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes")]
841
- public Wix.RegistryRootType GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu)
842
- {
843
- Wix.RegistryRootType registryRoot = Wix.RegistryRootType.NotSet;
844
- string value = this.GetAttributeValue(sourceLineNumbers, attribute);
845
-
846
- if (0 < value.Length)
847
- {
848
- registryRoot = Wix.Enums.ParseRegistryRootType(value);
849
-
850
- if (Wix.RegistryRootType.IllegalValue == registryRoot || (!allowHkmu && Wix.RegistryRootType.HKMU == registryRoot))
851
- {
852
- // TODO: Find a way to expose the valid values programatically!
853
- if (allowHkmu)
854
- {
855
- this.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value,
856
- "HKMU", "HKCR", "HKCU", "HKLM", "HKU"));
857
- }
858
- else
859
- {
860
- this.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value,
861
- "HKCR", "HKCU", "HKLM", "HKU"));
862
- }
863
- }
864
- }
865
-
866
- return registryRoot;
867
- }
868
-
833
/// <summary>
834
/// Gets a RegistryRoot as a MsiInterop.MsidbRegistryRoot value and displays an error for an illegal value.
835
/// </summary>
@@ -876,33 +840,7 @@ namespace WixToolset.Core
840
[SuppressMessage("Microsoft.Design", "CA1059:MembersShouldNotExposeCertainConcreteTypes")]
841
public int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu)
842
{
879
- Wix.RegistryRootType registryRoot = this.GetAttributeRegistryRootValue(sourceLineNumbers, attribute, allowHkmu);
880
-
881
- switch (registryRoot)
882
- {
883
- case Wix.RegistryRootType.NotSet:
884
- return CompilerConstants.IntegerNotSet;
885
- case Wix.RegistryRootType.HKCR:
886
- return Core.Native.MsiInterop.MsidbRegistryRootClassesRoot;
887
- case Wix.RegistryRootType.HKCU:
888
- return Core.Native.MsiInterop.MsidbRegistryRootCurrentUser;
889
- case Wix.RegistryRootType.HKLM:
890
- return Core.Native.MsiInterop.MsidbRegistryRootLocalMachine;
891
- case Wix.RegistryRootType.HKU:
892
- return Core.Native.MsiInterop.MsidbRegistryRootUsers;
893
- case Wix.RegistryRootType.HKMU:
894
- // This is gross, but there was *one* registry root parsing instance
895
- // (in Compiler.ParseRegistrySearchElement()) that did not explicitly
896
- // handle HKMU and it fell through to the default error case. The
897
- // others treated it as -1, which is what we do here.
898
- if (allowHkmu)
899
- {
900
- return -1;
901
- }
902
- break;
903
- }
904
-
905
- return CompilerConstants.IntegerNotSet;
843
+ return this.parseHelper.GetAttributeMsidbRegistryRootValue(sourceLineNumbers, attribute, allowHkmu);
844
}
845
846
/// <summary>
src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs
+60
@@ -12,6 +12,7 @@ namespace WixToolset.Core.ExtensibilityServices
12
using System.Text.RegularExpressions;
13
using System.Xml.Linq;
14
using WixToolset.Data;
15
+ using Wix = WixToolset.Data.Serialize;
16
using WixToolset.Data.Tuples;
17
using WixToolset.Extensibility;
18
using WixToolset.Extensibility.Services;
@@ -571,6 +572,37 @@ namespace WixToolset.Core.ExtensibilityServices
572
return Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, emptyRule);
573
}
574
575
+ public int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu)
576
+ {
577
+ Wix.RegistryRootType registryRoot = this.GetAttributeRegistryRootValue(sourceLineNumbers, attribute, allowHkmu);
578
+
579
+ switch (registryRoot)
580
+ {
581
+ case Wix.RegistryRootType.NotSet:
582
+ return CompilerConstants.IntegerNotSet;
583
+ case Wix.RegistryRootType.HKCR:
584
+ return Core.Native.MsiInterop.MsidbRegistryRootClassesRoot;
585
+ case Wix.RegistryRootType.HKCU:
586
+ return Core.Native.MsiInterop.MsidbRegistryRootCurrentUser;
587
+ case Wix.RegistryRootType.HKLM:
588
+ return Core.Native.MsiInterop.MsidbRegistryRootLocalMachine;
589
+ case Wix.RegistryRootType.HKU:
590
+ return Core.Native.MsiInterop.MsidbRegistryRootUsers;
591
+ case Wix.RegistryRootType.HKMU:
592
+ // This is gross, but there was *one* registry root parsing instance
593
+ // (in Compiler.ParseRegistrySearchElement()) that did not explicitly
594
+ // handle HKMU and it fell through to the default error case. The
595
+ // others treated it as -1, which is what we do here.
596
+ if (allowHkmu)
597
+ {
598
+ return -1;
599
+ }
600
+ break;
601
+ }
602
+
603
+ return CompilerConstants.IntegerNotSet;
604
+ }
605
+
606
public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute)
607
{
608
var value = this.GetAttributeValue(sourceLineNumbers, attribute);
@@ -814,6 +846,34 @@ namespace WixToolset.Core.ExtensibilityServices
846
return row;
847
}
848
849
+ private Wix.RegistryRootType GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu)
850
+ {
851
+ Wix.RegistryRootType registryRoot = Wix.RegistryRootType.NotSet;
852
+ string value = this.GetAttributeValue(sourceLineNumbers, attribute);
853
+
854
+ if (0 < value.Length)
855
+ {
856
+ registryRoot = Wix.Enums.ParseRegistryRootType(value);
857
+
858
+ if (Wix.RegistryRootType.IllegalValue == registryRoot || (!allowHkmu && Wix.RegistryRootType.HKMU == registryRoot))
859
+ {
860
+ // TODO: Find a way to expose the valid values programatically!
861
+ if (allowHkmu)
862
+ {
863
+ this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value,
864
+ "HKMU", "HKCR", "HKCU", "HKLM", "HKU"));
865
+ }
866
+ else
867
+ {
868
+ this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value,
869
+ "HKCR", "HKCU", "HKLM", "HKU"));
870
+ }
871
+ }
872
+ }
873
+
874
+ return registryRoot;
875
+ }
876
+
877
private static bool TryFindExtension(IEnumerable<ICompilerExtension> extensions, XNamespace ns, out ICompilerExtension extension)
878
{
879
extension = null;