| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.UI |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Xml.Linq; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Data.Symbols; |
| 10 | using WixToolset.Extensibility; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// The decompiler for the WiX Toolset UI Extension. |
| 14 | /// </summary> |
| 15 | public sealed class UICompiler : BaseCompilerExtension |
| 16 | { |
| 17 | public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/ui"; |
| 18 | |
| 19 | /// <summary> |
| 20 | /// Processes an element for the Compiler. |
| 21 | /// </summary> |
| 22 | /// <param name="sourceLineNumbers">Source line number for the parent element.</param> |
| 23 | /// <param name="parentElement">Parent element of element to process.</param> |
| 24 | /// <param name="element">Element to process.</param> |
| 25 | /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param> |
| 26 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) |
| 27 | { |
| 28 | switch (parentElement.Name.LocalName) |
| 29 | { |
| 30 | case "Fragment": |
| 31 | case "Module": |
| 32 | case "PatchFamily": |
| 33 | case "Package": |
| 34 | case "UI": |
| 35 | switch (element.Name.LocalName) |
| 36 | { |
| 37 | case "WixUI": |
| 38 | this.ParseWixUIElement(intermediate, section, element); |
| 39 | break; |
| 40 | default: |
| 41 | this.ParseHelper.UnexpectedElement(parentElement, element); |
| 42 | break; |
| 43 | } |
| 44 | break; |
| 45 | default: |
| 46 | this.ParseHelper.UnexpectedElement(parentElement, element); |
| 47 | break; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /// <summary> |
| 52 | /// Parses a WixUI element. |
| 53 | /// </summary> |
| 54 | private void ParseWixUIElement(Intermediate intermediate, IntermediateSection section, XElement element) |
| 55 | { |
| 56 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); |
| 57 | string id = null; |
| 58 | string installDirectory = null; |
| 59 | YesNoType extendedPathValidation = YesNoType.No; |
| 60 | |
| 61 | foreach (var attrib in element.Attributes()) |
| 62 | { |
| 63 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) |
| 64 | { |
| 65 | switch (attrib.Name.LocalName) |
| 66 | { |
| 67 | case "Id": |
| 68 | id = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); |
| 69 | break; |
| 70 | case "InstallDirectory": |
| 71 | installDirectory = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); |
| 72 | break; |
| 73 | case "ExtendedPathValidation": |
| 74 | extendedPathValidation = this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib); |
| 75 | break; |
| 76 | default: |
| 77 | this.ParseHelper.UnexpectedAttribute(element, attrib); |
| 78 | break; |
| 79 | } |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (null == id) |
| 88 | { |
| 89 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString(); |
| 94 | |
| 95 | if (extendedPathValidation == YesNoType.No) |
| 96 | { |
| 97 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, $"{id}_{platform}"); |
| 98 | } |
| 99 | else |
| 100 | { |
| 101 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, $"{id}_ExtendedPathValidation_{platform}"); |
| 102 | } |
| 103 | |
| 104 | if (installDirectory != null) |
| 105 | { |
| 106 | section.AddSymbol(new PropertySymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WIXUI_INSTALLDIR")) |
| 107 | { |
| 108 | Value = installDirectory |
| 109 | }); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); |
| 114 | } |
| 115 | } |
| 116 | } |