diff options
Diffstat (limited to 'src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs')
-rw-r--r-- | src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs | 135 |
1 files changed, 62 insertions, 73 deletions
diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs index dce77781..9d4a7cbd 100644 --- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs | |||
@@ -16,7 +16,6 @@ namespace WixToolset.Core.ExtensibilityServices | |||
16 | using WixToolset.Extensibility; | 16 | using WixToolset.Extensibility; |
17 | using WixToolset.Extensibility.Data; | 17 | using WixToolset.Extensibility.Data; |
18 | using WixToolset.Extensibility.Services; | 18 | using WixToolset.Extensibility.Services; |
19 | using Wix = WixToolset.Data.Serialize; | ||
20 | 19 | ||
21 | internal class ParseHelper : IParseHelper | 20 | internal class ParseHelper : IParseHelper |
22 | { | 21 | { |
@@ -179,23 +178,21 @@ namespace WixToolset.Core.ExtensibilityServices | |||
179 | return new Identifier(id, AccessModifier.Private); | 178 | return new Identifier(id, AccessModifier.Private); |
180 | } | 179 | } |
181 | 180 | ||
182 | public Identifier CreateRegistryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, int root, string key, string name, string value, string componentId, bool escapeLeadingHash) | 181 | public Identifier CreateRegistryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, RegistryRootType root, string key, string name, string value, string componentId, bool escapeLeadingHash) |
183 | { | 182 | { |
184 | Identifier id = null; | 183 | if (RegistryRootType.Unknown == root) |
185 | |||
186 | if (-1 > root || 3 < root) | ||
187 | { | 184 | { |
188 | throw new ArgumentOutOfRangeException("root"); | 185 | throw new ArgumentOutOfRangeException(nameof(root)); |
189 | } | 186 | } |
190 | 187 | ||
191 | if (null == key) | 188 | if (null == key) |
192 | { | 189 | { |
193 | throw new ArgumentNullException("key"); | 190 | throw new ArgumentNullException(nameof(key)); |
194 | } | 191 | } |
195 | 192 | ||
196 | if (null == componentId) | 193 | if (null == componentId) |
197 | { | 194 | { |
198 | throw new ArgumentNullException("componentId"); | 195 | throw new ArgumentNullException(nameof(componentId)); |
199 | } | 196 | } |
200 | 197 | ||
201 | // Escape the leading '#' character for string registry values. | 198 | // Escape the leading '#' character for string registry values. |
@@ -204,26 +201,31 @@ namespace WixToolset.Core.ExtensibilityServices | |||
204 | value = String.Concat("#", value); | 201 | value = String.Concat("#", value); |
205 | } | 202 | } |
206 | 203 | ||
207 | id = this.CreateIdentifier("reg", componentId, root.ToString(CultureInfo.InvariantCulture.NumberFormat), key.ToLowerInvariant(), (null != name ? name.ToLowerInvariant() : name)); | 204 | var id = this.CreateIdentifier("reg", componentId, ((int)root).ToString(CultureInfo.InvariantCulture.NumberFormat), key.ToLowerInvariant(), (null != name ? name.ToLowerInvariant() : name)); |
205 | |||
206 | var tuple = new RegistryTuple(sourceLineNumbers, id) | ||
207 | { | ||
208 | Root = root, | ||
209 | Key = key, | ||
210 | Name = name, | ||
211 | Value = value, | ||
212 | Component_ = componentId, | ||
213 | }; | ||
208 | 214 | ||
209 | var row = this.CreateRow(section, sourceLineNumbers, TupleDefinitionType.Registry, id); | 215 | section.Tuples.Add(tuple); |
210 | row.Set(1, root); | ||
211 | row.Set(2, key); | ||
212 | row.Set(3, name); | ||
213 | row.Set(4, value); | ||
214 | row.Set(5, componentId); | ||
215 | 216 | ||
216 | return id; | 217 | return id; |
217 | } | 218 | } |
218 | 219 | ||
219 | public void CreateSimpleReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys) | 220 | public void CreateSimpleReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys) |
220 | { | 221 | { |
221 | var joinedKeys = String.Join("/", primaryKeys); | 222 | var tuple = new WixSimpleReferenceTuple(sourceLineNumbers) |
222 | var id = String.Concat(tableName, ":", joinedKeys); | 223 | { |
224 | Table = tableName, | ||
225 | PrimaryKeys = String.Join("/", primaryKeys) | ||
226 | }; | ||
223 | 227 | ||
224 | var wixSimpleReferenceRow = (WixSimpleReferenceTuple)this.CreateRow(section, sourceLineNumbers, TupleDefinitionType.WixSimpleReference); | 228 | section.Tuples.Add(tuple); |
225 | wixSimpleReferenceRow.Table = tableName; | ||
226 | wixSimpleReferenceRow.PrimaryKeys = joinedKeys; | ||
227 | } | 229 | } |
228 | 230 | ||
229 | public void CreateWixGroupRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, ComplexReferenceChildType childType, string childId) | 231 | public void CreateWixGroupRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, ComplexReferenceChildType childType, string childId) |
@@ -238,11 +240,15 @@ namespace WixToolset.Core.ExtensibilityServices | |||
238 | throw new ArgumentNullException("childId"); | 240 | throw new ArgumentNullException("childId"); |
239 | } | 241 | } |
240 | 242 | ||
241 | var row = (WixGroupTuple)this.CreateRow(section, sourceLineNumbers, TupleDefinitionType.WixGroup); | 243 | var tuple = new WixGroupTuple(sourceLineNumbers) |
242 | row.ParentId = parentId; | 244 | { |
243 | row.ParentType = parentType; | 245 | ParentId = parentId, |
244 | row.ChildId = childId; | 246 | ParentType = parentType, |
245 | row.ChildType = childType; | 247 | ChildId = childId, |
248 | ChildType = childType, | ||
249 | }; | ||
250 | |||
251 | section.Tuples.Add(tuple); | ||
246 | } | 252 | } |
247 | 253 | ||
248 | public IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null) | 254 | public IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null) |
@@ -573,35 +579,46 @@ namespace WixToolset.Core.ExtensibilityServices | |||
573 | return Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, emptyRule); | 579 | return Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, emptyRule); |
574 | } | 580 | } |
575 | 581 | ||
576 | public int GetAttributeMsidbRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) | 582 | public RegistryRootType? GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) |
577 | { | 583 | { |
578 | Wix.RegistryRootType registryRoot = this.GetAttributeRegistryRootValue(sourceLineNumbers, attribute, allowHkmu); | 584 | string value = this.GetAttributeValue(sourceLineNumbers, attribute); |
585 | if (String.IsNullOrEmpty(value)) | ||
586 | { | ||
587 | return null; | ||
588 | } | ||
579 | 589 | ||
580 | switch (registryRoot) | 590 | switch (value) |
581 | { | 591 | { |
582 | case Wix.RegistryRootType.NotSet: | 592 | case "HKCR": |
583 | return CompilerConstants.IntegerNotSet; | 593 | return RegistryRootType.ClassesRoot; |
584 | case Wix.RegistryRootType.HKCR: | 594 | |
585 | return Core.Native.MsiInterop.MsidbRegistryRootClassesRoot; | 595 | case "HKCU": |
586 | case Wix.RegistryRootType.HKCU: | 596 | return RegistryRootType.CurrentUser; |
587 | return Core.Native.MsiInterop.MsidbRegistryRootCurrentUser; | 597 | |
588 | case Wix.RegistryRootType.HKLM: | 598 | case "HKLM": |
589 | return Core.Native.MsiInterop.MsidbRegistryRootLocalMachine; | 599 | return RegistryRootType.LocalMachine; |
590 | case Wix.RegistryRootType.HKU: | 600 | |
591 | return Core.Native.MsiInterop.MsidbRegistryRootUsers; | 601 | case "HKU": |
592 | case Wix.RegistryRootType.HKMU: | 602 | return RegistryRootType.Users; |
593 | // This is gross, but there was *one* registry root parsing instance | 603 | |
594 | // (in Compiler.ParseRegistrySearchElement()) that did not explicitly | 604 | case "HKMU": |
595 | // handle HKMU and it fell through to the default error case. The | ||
596 | // others treated it as -1, which is what we do here. | ||
597 | if (allowHkmu) | 605 | if (allowHkmu) |
598 | { | 606 | { |
599 | return -1; | 607 | return RegistryRootType.MachineUser; |
600 | } | 608 | } |
601 | break; | 609 | break; |
602 | } | 610 | } |
603 | 611 | ||
604 | return CompilerConstants.IntegerNotSet; | 612 | if (allowHkmu) |
613 | { | ||
614 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, "HKMU", "HKCR", "HKCU", "HKLM", "HKU")); | ||
615 | } | ||
616 | else | ||
617 | { | ||
618 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, "HKCR", "HKCU", "HKLM", "HKU")); | ||
619 | } | ||
620 | |||
621 | return RegistryRootType.Unknown; | ||
605 | } | 622 | } |
606 | 623 | ||
607 | public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) | 624 | public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) |
@@ -847,34 +864,6 @@ namespace WixToolset.Core.ExtensibilityServices | |||
847 | return row; | 864 | return row; |
848 | } | 865 | } |
849 | 866 | ||
850 | private Wix.RegistryRootType GetAttributeRegistryRootValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowHkmu) | ||
851 | { | ||
852 | Wix.RegistryRootType registryRoot = Wix.RegistryRootType.NotSet; | ||
853 | string value = this.GetAttributeValue(sourceLineNumbers, attribute); | ||
854 | |||
855 | if (0 < value.Length) | ||
856 | { | ||
857 | registryRoot = Wix.Enums.ParseRegistryRootType(value); | ||
858 | |||
859 | if (Wix.RegistryRootType.IllegalValue == registryRoot || (!allowHkmu && Wix.RegistryRootType.HKMU == registryRoot)) | ||
860 | { | ||
861 | // TODO: Find a way to expose the valid values programatically! | ||
862 | if (allowHkmu) | ||
863 | { | ||
864 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, | ||
865 | "HKMU", "HKCR", "HKCU", "HKLM", "HKU")); | ||
866 | } | ||
867 | else | ||
868 | { | ||
869 | this.Messaging.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, | ||
870 | "HKCR", "HKCU", "HKLM", "HKU")); | ||
871 | } | ||
872 | } | ||
873 | } | ||
874 | |||
875 | return registryRoot; | ||
876 | } | ||
877 | |||
878 | private static bool TryFindExtension(IEnumerable<ICompilerExtension> extensions, XNamespace ns, out ICompilerExtension extension) | 867 | private static bool TryFindExtension(IEnumerable<ICompilerExtension> extensions, XNamespace ns, out ICompilerExtension extension) |
879 | { | 868 | { |
880 | extension = null; | 869 | extension = null; |