aboutsummaryrefslogtreecommitdiff
path: root/src/ext/UI/wixext
diff options
context:
space:
mode:
authorBob Arnson <bob@firegiant.com>2022-01-29 23:44:11 -0500
committerBob Arnson <github@bobs.org>2022-01-30 13:02:05 -0500
commit7ce477c6863c74ef0a50d117d8c28b2f19971b42 (patch)
treeb953aae25a04d9ffbf0bd4609055087d96e760dc /src/ext/UI/wixext
parent3c1b81ff55975adffdc76f1a184b0f264bd97cd6 (diff)
downloadwix-7ce477c6863c74ef0a50d117d8c28b2f19971b42.tar.gz
wix-7ce477c6863c74ef0a50d117d8c28b2f19971b42.tar.bz2
wix-7ce477c6863c74ef0a50d117d8c28b2f19971b42.zip
Add compiler extension to handle platforms.
Custom actions to print EULA and validate install directories are defined in WixUIExtension compiler extension, to handle platform-specific custom actions referred to from `DoAction` control events. This is the least-worst solution, given the `DoAction` approach used in the WixUI authoring and anyone customizing a WixUI set.
Diffstat (limited to 'src/ext/UI/wixext')
-rw-r--r--src/ext/UI/wixext/UICompiler.cs118
-rw-r--r--src/ext/UI/wixext/UIExtensionFactory.cs1
2 files changed, 119 insertions, 0 deletions
diff --git a/src/ext/UI/wixext/UICompiler.cs b/src/ext/UI/wixext/UICompiler.cs
new file mode 100644
index 00000000..46b856c0
--- /dev/null
+++ b/src/ext/UI/wixext/UICompiler.cs
@@ -0,0 +1,118 @@
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
3namespace 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
59 foreach (var attrib in element.Attributes())
60 {
61 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
62 {
63 switch (attrib.Name.LocalName)
64 {
65 case "Id":
66 id = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
67 break;
68 default:
69 this.ParseHelper.UnexpectedAttribute(element, attrib);
70 break;
71 }
72 }
73 else
74 {
75 this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib);
76 }
77 }
78
79 if (null == id)
80 {
81 this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
82 }
83 else
84 {
85 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.WixUI, id);
86
87 // Because these custom actions are "scheduled" via `DoAction` control events, we have to create the
88 // custom action definitions here, so the `DoAction` references are static and the targets are
89 // dynamically created to properly reflect the platform-specific DLL and avoid having duplicate ids
90 // in the UI .wixlib.
91 var platform = this.Context.Platform == Platform.ARM64 ? "A64" : this.Context.Platform.ToString();
92 var source = $"WixUiCa_{platform}";
93
94 section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIPrintEula"))
95 {
96 TargetType = CustomActionTargetType.Dll,
97 Target = "PrintEula",
98 SourceType = CustomActionSourceType.Binary,
99 Source = source,
100 IgnoreResult = true,
101 ExecutionType = CustomActionExecutionType.Immediate,
102 });
103
104 section.AddSymbol(new CustomActionSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "WixUIValidatePath"))
105 {
106 TargetType = CustomActionTargetType.Dll,
107 Target = "ValidatePath",
108 SourceType = CustomActionSourceType.Binary,
109 Source = source,
110 IgnoreResult = true,
111 ExecutionType = CustomActionExecutionType.Immediate,
112 });
113 }
114
115 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);
116 }
117 }
118}
diff --git a/src/ext/UI/wixext/UIExtensionFactory.cs b/src/ext/UI/wixext/UIExtensionFactory.cs
index 141aa39f..a16a9899 100644
--- a/src/ext/UI/wixext/UIExtensionFactory.cs
+++ b/src/ext/UI/wixext/UIExtensionFactory.cs
@@ -11,6 +11,7 @@ namespace WixToolset.UI
11 protected override IReadOnlyCollection<Type> ExtensionTypes => new[] 11 protected override IReadOnlyCollection<Type> ExtensionTypes => new[]
12 { 12 {
13 typeof(UIExtensionData), 13 typeof(UIExtensionData),
14 typeof(UICompiler),
14 }; 15 };
15 } 16 }
16} 17}