aboutsummaryrefslogtreecommitdiff
path: root/src/wixext/DifxAppCompiler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/wixext/DifxAppCompiler.cs')
-rw-r--r--src/wixext/DifxAppCompiler.cs148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/wixext/DifxAppCompiler.cs b/src/wixext/DifxAppCompiler.cs
new file mode 100644
index 00000000..63396932
--- /dev/null
+++ b/src/wixext/DifxAppCompiler.cs
@@ -0,0 +1,148 @@
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.Extensions
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Xml.Linq;
8 using WixToolset.Data;
9 using WixToolset.Extensibility;
10
11 /// <summary>
12 /// The compiler for the WiX Toolset Driver Install Frameworks for Applications Extension.
13 /// </summary>
14 public sealed class DifxAppCompiler : CompilerExtension
15 {
16 private HashSet<string> components;
17
18 /// <summary>
19 /// Instantiate a new DifxAppCompiler.
20 /// </summary>
21 public DifxAppCompiler()
22 {
23 this.Namespace = "http://wixtoolset.org/schemas/v4/wxs/difxapp";
24 this.components = new HashSet<string>();
25 }
26
27 /// <summary>
28 /// Processes an element for the Compiler.
29 /// </summary>
30 /// <param name="sourceLineNumbers">Source line number for the parent element.</param>
31 /// <param name="parentElement">Parent element of element to process.</param>
32 /// <param name="element">Element to process.</param>
33 /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
34 public override void ParseElement(XElement parentElement, XElement element, IDictionary<string, string> context)
35 {
36 switch (parentElement.Name.LocalName)
37 {
38 case "Component":
39 string componentId = context["ComponentId"];
40 string directoryId = context["DirectoryId"];
41
42 switch (element.Name.LocalName)
43 {
44 case "Driver":
45 this.ParseDriverElement(element, componentId);
46 break;
47 default:
48 this.Core.UnexpectedElement(parentElement, element);
49 break;
50 }
51 break;
52 default:
53 this.Core.UnexpectedElement(parentElement, element);
54 break;
55 }
56 }
57
58 /// <summary>
59 /// Parses a Driver element.
60 /// </summary>
61 /// <param name="node">Element to parse.</param>
62 /// <param name="componentId">Identifier for parent component.</param>
63 private void ParseDriverElement(XElement node, string componentId)
64 {
65 SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
66 int attributes = 0;
67 int sequence = CompilerConstants.IntegerNotSet;
68
69 // check the number of times a Driver element has been nested under this Component element
70 if (null != componentId)
71 {
72 if (this.components.Contains(componentId))
73 {
74 this.Core.OnMessage(WixErrors.TooManyElements(sourceLineNumbers, "Component", node.Name.LocalName, 1));
75 }
76 else
77 {
78 this.components.Add(componentId);
79 }
80 }
81
82 foreach (XAttribute attrib in node.Attributes())
83 {
84 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
85 {
86 switch (attrib.Name.LocalName)
87 {
88 case "AddRemovePrograms":
89 if (YesNoType.No == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
90 {
91 attributes |= 0x4;
92 }
93 break;
94 case "DeleteFiles":
95 if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
96 {
97 attributes |= 0x10;
98 }
99 break;
100 case "ForceInstall":
101 if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
102 {
103 attributes |= 0x1;
104 }
105 break;
106 case "Legacy":
107 if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
108 {
109 attributes |= 0x8;
110 }
111 break;
112 case "PlugAndPlayPrompt":
113 if (YesNoType.No == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
114 {
115 attributes |= 0x2;
116 }
117 break;
118 case "Sequence":
119 sequence = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, int.MaxValue);
120 break;
121 default:
122 this.Core.UnexpectedAttribute(node, attrib);
123 break;
124 }
125 }
126 else
127 {
128 this.Core.ParseExtensionAttribute(node, attrib);
129 }
130 }
131
132 this.Core.ParseForExtensionElements(node);
133
134 if (!this.Core.EncounteredError)
135 {
136 Row row = this.Core.CreateRow(sourceLineNumbers, "MsiDriverPackages");
137 row[0] = componentId;
138 row[1] = attributes;
139 if (CompilerConstants.IntegerNotSet != sequence)
140 {
141 row[2] = sequence;
142 }
143
144 this.Core.CreateSimpleReference(sourceLineNumbers, "CustomAction", "MsiProcessDrivers");
145 }
146 }
147 }
148}