| 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.DirectX |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using System.Xml.Linq; |
| 8 | using WixToolset.Data; |
| 9 | using WixToolset.Extensibility; |
| 10 | using WixToolset.Extensibility.Data; |
| 11 | |
| 12 | /// <summary> |
| 13 | /// The compiler for the WiX Toolset DirectX Extension. |
| 14 | /// </summary> |
| 15 | public sealed class DirectXCompiler : BaseCompilerExtension |
| 16 | { |
| 17 | public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/directx"; |
| 18 | |
| 19 | /// <summary> |
| 20 | /// Processes an element for the Compiler. |
| 21 | /// </summary> |
| 22 | /// <param name="parentElement">Parent element of element to process.</param> |
| 23 | /// <param name="element">Element to process.</param> |
| 24 | /// <param name="context">Extra information about the context in which this element is being parsed.</param> |
| 25 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) |
| 26 | { |
| 27 | switch (parentElement.Name.LocalName) |
| 28 | { |
| 29 | case "Fragment": |
| 30 | case "Module": |
| 31 | case "Package": |
| 32 | case "UI": |
| 33 | this.AddCustomActionReference(intermediate, section, element, parentElement); |
| 34 | break; |
| 35 | default: |
| 36 | this.ParseHelper.UnexpectedElement(parentElement, element); |
| 37 | break; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private void AddCustomActionReference(Intermediate intermediate, IntermediateSection section, XElement element, XElement parentElement) |
| 42 | { |
| 43 | var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); |
| 44 | |
| 45 | switch (element.Name.LocalName) |
| 46 | { |
| 47 | case "GetCapabilities": |
| 48 | this.ParseHelper.CreateCustomActionReference(sourceLineNumbers, section, "Wix4QueryDirectXCaps", this.Context.Platform, CustomActionPlatforms.X86 | CustomActionPlatforms.X64 | CustomActionPlatforms.ARM64); |
| 49 | break; |
| 50 | default: |
| 51 | this.ParseHelper.UnexpectedElement(parentElement, element); |
| 52 | break; |
| 53 | } |
| 54 | |
| 55 | foreach (var attrib in element.Attributes()) |
| 56 | { |
| 57 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) |
| 58 | { |
| 59 | // no attributes today |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element); |
| 68 | } |
| 69 | } |
| 70 | } |