aboutsummaryrefslogtreecommitdiff
path: root/src/ext/DifxApp/wixext
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-05-04 13:22:13 -0700
committerRob Mensching <rob@firegiant.com>2021-05-04 13:24:02 -0700
commit03db7922de5b7e04300e0ed09e24f7b8890ec2e8 (patch)
tree1f39ab6257f479dbd54f93a0c0bdb2fc5a6c3e74 /src/ext/DifxApp/wixext
parent543c9851d7cacbf85f575b1f6f52e41da7a1d66b (diff)
downloadwix-03db7922de5b7e04300e0ed09e24f7b8890ec2e8.tar.gz
wix-03db7922de5b7e04300e0ed09e24f7b8890ec2e8.tar.bz2
wix-03db7922de5b7e04300e0ed09e24f7b8890ec2e8.zip
Move DifxApp.wixext into ext
Diffstat (limited to 'src/ext/DifxApp/wixext')
-rw-r--r--src/ext/DifxApp/wixext/DifxAppCompiler.cs161
-rw-r--r--src/ext/DifxApp/wixext/DifxAppDecompiler.cs98
-rw-r--r--src/ext/DifxApp/wixext/DifxAppExtensionData.cs23
-rw-r--r--src/ext/DifxApp/wixext/DifxAppExtensionFactory.cs18
-rw-r--r--src/ext/DifxApp/wixext/DifxAppTableDefinitions.cs26
-rw-r--r--src/ext/DifxApp/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs13
-rw-r--r--src/ext/DifxApp/wixext/Symbols/DifxAppSymbolDefinitions.cs39
-rw-r--r--src/ext/DifxApp/wixext/Symbols/MsiDriverPackagesSymbol.cs63
-rw-r--r--src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.csproj28
-rw-r--r--src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.targets11
10 files changed, 480 insertions, 0 deletions
diff --git a/src/ext/DifxApp/wixext/DifxAppCompiler.cs b/src/ext/DifxApp/wixext/DifxAppCompiler.cs
new file mode 100644
index 00000000..e056988f
--- /dev/null
+++ b/src/ext/DifxApp/wixext/DifxAppCompiler.cs
@@ -0,0 +1,161 @@
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.DifxApp
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Xml.Linq;
8 using WixToolset.Data;
9 using WixToolset.DifxApp.Symbols;
10 using WixToolset.Extensibility;
11
12 /// <summary>
13 /// The compiler for the WiX Toolset Driver Install Frameworks for Applications Extension.
14 /// </summary>
15 public sealed class DifxAppCompiler : BaseCompilerExtension
16 {
17 private HashSet<string> components;
18
19 public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/difxapp";
20 /// <summary>
21 /// Instantiate a new DifxAppCompiler.
22 /// </summary>
23 public DifxAppCompiler()
24 {
25 this.components = new HashSet<string>();
26 }
27
28 /// <summary>
29 /// Processes an element for the Compiler.
30 /// </summary>
31 /// <param name="sourceLineNumbers">Source line number for the parent element.</param>
32 /// <param name="parentElement">Parent element of element to process.</param>
33 /// <param name="element">Element to process.</param>
34 /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
35 public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context)
36 {
37 switch (parentElement.Name.LocalName)
38 {
39 case "Component":
40 var componentId = context["ComponentId"];
41 var directoryId = context["DirectoryId"];
42 var componentWin64 = Boolean.Parse(context["Win64"]);
43
44 switch (element.Name.LocalName)
45 {
46 case "Driver":
47 this.ParseDriverElement(intermediate, section, element, componentId, componentWin64);
48 break;
49 default:
50 this.ParseHelper.UnexpectedElement(parentElement, element);
51 break;
52 }
53 break;
54 default:
55 this.ParseHelper.UnexpectedElement(parentElement, element);
56 break;
57 }
58 }
59
60 /// <summary>
61 /// Parses a Driver element.
62 /// </summary>
63 /// <param name="node">Element to parse.</param>
64 /// <param name="componentId">Identifier for parent component.</param>
65 private void ParseDriverElement(Intermediate intermediate, IntermediateSection section, XElement node, string componentId, bool win64)
66 {
67 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
68 int attributes = 0;
69 var sequence = CompilerConstants.IntegerNotSet;
70
71 // check the number of times a Driver element has been nested under this Component element
72 if (null != componentId)
73 {
74 if (this.components.Contains(componentId))
75 {
76 this.Messaging.Write(ErrorMessages.TooManyElements(sourceLineNumbers, "Component", node.Name.LocalName, 1));
77 }
78 else
79 {
80 this.components.Add(componentId);
81 }
82 }
83
84 foreach (var attrib in node.Attributes())
85 {
86 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
87 {
88 switch (attrib.Name.LocalName)
89 {
90 case "AddRemovePrograms":
91 if (YesNoType.No == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
92 {
93 attributes |= 0x4;
94 }
95 break;
96 case "DeleteFiles":
97 if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
98 {
99 attributes |= 0x10;
100 }
101 break;
102 case "ForceInstall":
103 if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
104 {
105 attributes |= 0x1;
106 }
107 break;
108 case "Legacy":
109 if (YesNoType.Yes == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
110 {
111 attributes |= 0x8;
112 }
113 break;
114 case "PlugAndPlayPrompt":
115 if (YesNoType.No == this.ParseHelper.GetAttributeYesNoValue(sourceLineNumbers, attrib))
116 {
117 attributes |= 0x2;
118 }
119 break;
120 case "Sequence":
121 sequence = this.ParseHelper.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, int.MaxValue);
122 break;
123 default:
124 this.ParseHelper.UnexpectedAttribute(node, attrib);
125 break;
126 }
127 }
128 else
129 {
130 this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib);
131 }
132 }
133
134 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, node);
135
136 if (!this.Messaging.EncounteredError)
137 {
138 switch (this.Context.Platform)
139 {
140 case Platform.X86:
141 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.CustomAction, "MsiProcessDrivers");
142 break;
143 case Platform.X64:
144 this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, SymbolDefinitions.CustomAction, "MsiProcessDrivers_x64");
145 break;
146 }
147
148 var symbol = section.AddSymbol(new MsiDriverPackagesSymbol(sourceLineNumbers)
149 {
150 ComponentRef = componentId,
151 Flags = attributes,
152 });
153
154 if (CompilerConstants.IntegerNotSet != sequence)
155 {
156 symbol.Sequence = sequence;
157 }
158 }
159 }
160 }
161}
diff --git a/src/ext/DifxApp/wixext/DifxAppDecompiler.cs b/src/ext/DifxApp/wixext/DifxAppDecompiler.cs
new file mode 100644
index 00000000..e41d8b98
--- /dev/null
+++ b/src/ext/DifxApp/wixext/DifxAppDecompiler.cs
@@ -0,0 +1,98 @@
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.DifxApp
4{
5#if TODO_CONSIDER_DECOMPILER
6 using System;
7 using System.Collections;
8 using System.Globalization;
9 using WixToolset.Data;
10 using WixToolset.Extensibility;
11 using DifxApp = WixToolset.Extensions.Serialize.DifxApp;
12 using Wix = WixToolset.Data.Serialize;
13
14 /// <summary>
15 /// The decompiler for the WiX Toolset Driver Install Frameworks for Applications Extension.
16 /// </summary>
17 public sealed class DifxAppDecompiler : DecompilerExtension
18 {
19 /// <summary>
20 /// Creates a decompiler for Gaming Extension.
21 /// </summary>
22 public DifxAppDecompiler()
23 {
24 this.TableDefinitions = DifxAppExtensionData.GetExtensionTableDefinitions();
25 }
26
27 /// <summary>
28 /// Decompiles an extension table.
29 /// </summary>
30 /// <param name="table">The table to decompile.</param>
31 public override void DecompileTable(Table table)
32 {
33 switch (table.Name)
34 {
35 case "MsiDriverPackages":
36 this.DecompileMsiDriverPackagesTable(table);
37 break;
38 default:
39 base.DecompileTable(table);
40 break;
41 }
42 }
43
44 /// <summary>
45 /// Decompile the MsiDriverPackages table.
46 /// </summary>
47 /// <param name="table">The table to decompile.</param>
48 private void DecompileMsiDriverPackagesTable(Table table)
49 {
50 foreach (Row row in table.Rows)
51 {
52 DifxApp.Driver driver = new DifxApp.Driver();
53
54 int attributes = (int)row[1];
55 if (0x1 == (attributes & 0x1))
56 {
57 driver.ForceInstall = DifxApp.YesNoType.yes;
58 }
59
60 if (0x2 == (attributes & 0x2))
61 {
62 driver.PlugAndPlayPrompt = DifxApp.YesNoType.no;
63 }
64
65 if (0x4 == (attributes & 0x4))
66 {
67 driver.AddRemovePrograms = DifxApp.YesNoType.no;
68 }
69
70 if (0x8 == (attributes & 0x8))
71 {
72 driver.Legacy = DifxApp.YesNoType.yes;
73 }
74
75 if (0x10 == (attributes & 0x10))
76 {
77 driver.DeleteFiles = DifxApp.YesNoType.yes;
78 }
79
80 if (null != row[2])
81 {
82 driver.Sequence = (int)row[2];
83 }
84
85 Wix.Component component = (Wix.Component)this.Core.GetIndexedElement("Component", (string)row[0]);
86 if (null != component)
87 {
88 component.AddChild(driver);
89 }
90 else
91 {
92 this.Core.OnMessage(WixWarnings.ExpectedForeignRow(row.SourceLineNumbers, table.Name, row.GetPrimaryKey(DecompilerConstants.PrimaryKeyDelimiter), "Component", (string)row[0], "Component"));
93 }
94 }
95 }
96 }
97#endif
98}
diff --git a/src/ext/DifxApp/wixext/DifxAppExtensionData.cs b/src/ext/DifxApp/wixext/DifxAppExtensionData.cs
new file mode 100644
index 00000000..31a95b8e
--- /dev/null
+++ b/src/ext/DifxApp/wixext/DifxAppExtensionData.cs
@@ -0,0 +1,23 @@
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.DifxApp
4{
5 using WixToolset.Data;
6 using WixToolset.Extensibility;
7
8 public sealed class DifxAppExtensionData : BaseExtensionData
9 {
10 public override string DefaultCulture => "en-US";
11
12 public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
13 {
14 symbolDefinition = DifxAppSymbolDefinitions.ByName(name);
15 return symbolDefinition != null;
16 }
17
18 public override Intermediate GetLibrary(ISymbolDefinitionCreator symbolDefinitions)
19 {
20 return Intermediate.Load(typeof(DifxAppExtensionData).Assembly, "WixToolset.DifxApp.difxapp.wixlib", symbolDefinitions);
21 }
22 }
23}
diff --git a/src/ext/DifxApp/wixext/DifxAppExtensionFactory.cs b/src/ext/DifxApp/wixext/DifxAppExtensionFactory.cs
new file mode 100644
index 00000000..3932685d
--- /dev/null
+++ b/src/ext/DifxApp/wixext/DifxAppExtensionFactory.cs
@@ -0,0 +1,18 @@
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.DifxApp
4{
5 using System;
6 using System.Collections.Generic;
7 using WixToolset.Extensibility;
8
9 public class DifxAppExtensionFactory : BaseExtensionFactory
10 {
11 protected override IReadOnlyCollection<Type> ExtensionTypes => new[]
12 {
13 typeof(DifxAppCompiler),
14 typeof(DifxAppExtensionData),
15 typeof(DifxAppWindowsInstallerBackendBinderExtension),
16 };
17 }
18}
diff --git a/src/ext/DifxApp/wixext/DifxAppTableDefinitions.cs b/src/ext/DifxApp/wixext/DifxAppTableDefinitions.cs
new file mode 100644
index 00000000..a6c26444
--- /dev/null
+++ b/src/ext/DifxApp/wixext/DifxAppTableDefinitions.cs
@@ -0,0 +1,26 @@
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.DifxApp
4{
5 using WixToolset.Data.WindowsInstaller;
6
7 public static class DifxAppTableDefinitions
8 {
9 public static readonly TableDefinition MsiDriverPackages = new TableDefinition(
10 "MsiDriverPackages",
11 DifxAppSymbolDefinitions.MsiDriverPackages,
12 new[]
13 {
14 new ColumnDefinition("Component", ColumnType.String, 72, primaryKey: true, nullable: false, ColumnCategory.Identifier, keyTable: "Component", keyColumn: 1, description: "Name of the component that represents the driver package", modularizeType: ColumnModularizeType.Column),
15 new ColumnDefinition("Flags", ColumnType.Number, 4, primaryKey: false, nullable: false, ColumnCategory.Unknown, minValue: 0, maxValue: 31, description: "Flags for installing and uninstalling driver packages"),
16 new ColumnDefinition("Sequence", ColumnType.Number, 4, primaryKey: false, nullable: true, ColumnCategory.Unknown, minValue: 0, description: "Order in which the driver packages are processed"),
17 },
18 symbolIdIsPrimaryKey: false
19 );
20
21 public static readonly TableDefinition[] All = new[]
22 {
23 MsiDriverPackages,
24 };
25 }
26}
diff --git a/src/ext/DifxApp/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs b/src/ext/DifxApp/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs
new file mode 100644
index 00000000..41f01175
--- /dev/null
+++ b/src/ext/DifxApp/wixext/DifxAppWindowsInstallerBackendBinderExtension.cs
@@ -0,0 +1,13 @@
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.DifxApp
4{
5 using System.Collections.Generic;
6 using WixToolset.Data.WindowsInstaller;
7 using WixToolset.Extensibility;
8
9 public class DifxAppWindowsInstallerBackendBinderExtension : BaseWindowsInstallerBackendBinderExtension
10 {
11 public override IReadOnlyCollection<TableDefinition> TableDefinitions => DifxAppTableDefinitions.All;
12 }
13}
diff --git a/src/ext/DifxApp/wixext/Symbols/DifxAppSymbolDefinitions.cs b/src/ext/DifxApp/wixext/Symbols/DifxAppSymbolDefinitions.cs
new file mode 100644
index 00000000..76f4d88f
--- /dev/null
+++ b/src/ext/DifxApp/wixext/Symbols/DifxAppSymbolDefinitions.cs
@@ -0,0 +1,39 @@
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.DifxApp
4{
5 using System;
6 using WixToolset.Data;
7
8 public enum DifxAppSymbolDefinitionType
9 {
10 MsiDriverPackages,
11 }
12
13 public static partial class DifxAppSymbolDefinitions
14 {
15 public static readonly Version Version = new Version("4.0.0");
16
17 public static IntermediateSymbolDefinition ByName(string name)
18 {
19 if (!Enum.TryParse(name, out DifxAppSymbolDefinitionType type))
20 {
21 return null;
22 }
23
24 return ByType(type);
25 }
26
27 public static IntermediateSymbolDefinition ByType(DifxAppSymbolDefinitionType type)
28 {
29 switch (type)
30 {
31 case DifxAppSymbolDefinitionType.MsiDriverPackages:
32 return DifxAppSymbolDefinitions.MsiDriverPackages;
33
34 default:
35 throw new ArgumentOutOfRangeException(nameof(type));
36 }
37 }
38 }
39}
diff --git a/src/ext/DifxApp/wixext/Symbols/MsiDriverPackagesSymbol.cs b/src/ext/DifxApp/wixext/Symbols/MsiDriverPackagesSymbol.cs
new file mode 100644
index 00000000..2fd91bc8
--- /dev/null
+++ b/src/ext/DifxApp/wixext/Symbols/MsiDriverPackagesSymbol.cs
@@ -0,0 +1,63 @@
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.DifxApp
4{
5 using WixToolset.Data;
6 using WixToolset.DifxApp.Symbols;
7
8 public static partial class DifxAppSymbolDefinitions
9 {
10 public static readonly IntermediateSymbolDefinition MsiDriverPackages = new IntermediateSymbolDefinition(
11 DifxAppSymbolDefinitionType.MsiDriverPackages.ToString(),
12 new[]
13 {
14 new IntermediateFieldDefinition(nameof(MsiDriverPackagesSymbolFields.ComponentRef), IntermediateFieldType.String),
15 new IntermediateFieldDefinition(nameof(MsiDriverPackagesSymbolFields.Flags), IntermediateFieldType.Number),
16 new IntermediateFieldDefinition(nameof(MsiDriverPackagesSymbolFields.Sequence), IntermediateFieldType.Number),
17 },
18 typeof(MsiDriverPackagesSymbol));
19 }
20}
21
22namespace WixToolset.DifxApp.Symbols
23{
24 using WixToolset.Data;
25
26 public enum MsiDriverPackagesSymbolFields
27 {
28 ComponentRef,
29 Flags,
30 Sequence,
31 }
32
33 public class MsiDriverPackagesSymbol : IntermediateSymbol
34 {
35 public MsiDriverPackagesSymbol() : base(DifxAppSymbolDefinitions.MsiDriverPackages, null, null)
36 {
37 }
38
39 public MsiDriverPackagesSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(DifxAppSymbolDefinitions.MsiDriverPackages, sourceLineNumber, id)
40 {
41 }
42
43 public IntermediateField this[MsiDriverPackagesSymbolFields index] => this.Fields[(int)index];
44
45 public string ComponentRef
46 {
47 get => this.Fields[(int)MsiDriverPackagesSymbolFields.ComponentRef].AsString();
48 set => this.Set((int)MsiDriverPackagesSymbolFields.ComponentRef, value);
49 }
50
51 public int Flags
52 {
53 get => this.Fields[(int)MsiDriverPackagesSymbolFields.Flags].AsNumber();
54 set => this.Set((int)MsiDriverPackagesSymbolFields.Flags, value);
55 }
56
57 public int? Sequence
58 {
59 get => this.Fields[(int)MsiDriverPackagesSymbolFields.Sequence].AsNullableNumber();
60 set => this.Set((int)MsiDriverPackagesSymbolFields.Sequence, value);
61 }
62 }
63} \ No newline at end of file
diff --git a/src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.csproj b/src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.csproj
new file mode 100644
index 00000000..50d3debf
--- /dev/null
+++ b/src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.csproj
@@ -0,0 +1,28 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- 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. -->
3
4<Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netstandard2.0</TargetFramework>
7 <RootNamespace>WixToolset.DifxApp</RootNamespace>
8 <Description>WiX Toolset DIFxApp Extension</Description>
9 <Title>WiX Toolset DIFxApp Extension</Title>
10 <IsTool>true</IsTool>
11 <ContentTargetFolders>build</ContentTargetFolders>
12 </PropertyGroup>
13 <ItemGroup>
14 <Content Include="$(MSBuildThisFileName).targets" />
15 <EmbeddedResource Include="$(OutputPath)..\difxapp.wixlib" />
16 </ItemGroup>
17 <ItemGroup>
18 <PackageReference Include="WixToolset.Extensibility" Version="4.0.*" PrivateAssets="all" />
19 </ItemGroup>
20
21 <ItemGroup>
22 <ProjectReference Include="..\wixlib\difxapp.wixproj" ReferenceOutputAssembly="false" Condition=" '$(NCrunch)'=='' " />
23 </ItemGroup>
24
25 <ItemGroup>
26 <PackageReference Include="Nerdbank.GitVersioning" Version="3.3.37" PrivateAssets="all" />
27 </ItemGroup>
28</Project>
diff --git a/src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.targets b/src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.targets
new file mode 100644
index 00000000..b01d4116
--- /dev/null
+++ b/src/ext/DifxApp/wixext/WixToolset.DifxApp.wixext.targets
@@ -0,0 +1,11 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- 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. -->
3
4<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
5 <PropertyGroup>
6 <WixToolsetDifxAppWixextPath Condition=" '$(WixToolsetDifxAppWixextPath)' == '' ">$(MSBuildThisFileDirectory)..\tools\WixToolset.DifxApp.wixext.dll</WixToolsetDifxAppWixextPath>
7 </PropertyGroup>
8 <ItemGroup>
9 <WixExtension Include="$(WixToolsetDifxAppWixextPath)" />
10 </ItemGroup>
11</Project>