diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-06-29 19:14:02 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-07-02 12:50:09 -0500 |
commit | 8cbfc326cccf8d9b3b63cb6f752fc770f7dee0fc (patch) | |
tree | 639f70e7327cdfade62271da04aaaaae2e85cc05 /src/api/burn/WixToolset.Mba.Core | |
parent | e844f12f7d7247a1e9ba4eef2a388e614001bb24 (diff) | |
download | wix-8cbfc326cccf8d9b3b63cb6f752fc770f7dee0fc.tar.gz wix-8cbfc326cccf8d9b3b63cb6f752fc770f7dee0fc.tar.bz2 wix-8cbfc326cccf8d9b3b63cb6f752fc770f7dee0fc.zip |
Expose overridable variable APIs in balutil and Mba.Core.
Fixes #4777
Diffstat (limited to 'src/api/burn/WixToolset.Mba.Core')
10 files changed, 230 insertions, 9 deletions
diff --git a/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs b/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs index 65dde0f4..345e0448 100644 --- a/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs +++ b/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs | |||
@@ -3,6 +3,7 @@ | |||
3 | namespace WixToolset.Mba.Core | 3 | namespace WixToolset.Mba.Core |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | ||
6 | using System.ComponentModel; | 7 | using System.ComponentModel; |
7 | using System.Runtime.InteropServices; | 8 | using System.Runtime.InteropServices; |
8 | 9 | ||
@@ -11,8 +12,6 @@ namespace WixToolset.Mba.Core | |||
11 | /// </summary> | 12 | /// </summary> |
12 | public sealed class BootstrapperCommand : IBootstrapperCommand | 13 | public sealed class BootstrapperCommand : IBootstrapperCommand |
13 | { | 14 | { |
14 | private readonly string commandLine; | ||
15 | |||
16 | /// <summary> | 15 | /// <summary> |
17 | /// | 16 | /// |
18 | /// </summary> | 17 | /// </summary> |
@@ -45,7 +44,7 @@ namespace WixToolset.Mba.Core | |||
45 | this.Action = action; | 44 | this.Action = action; |
46 | this.Display = display; | 45 | this.Display = display; |
47 | this.Restart = restart; | 46 | this.Restart = restart; |
48 | this.commandLine = commandLine; | 47 | this.CommandLine = commandLine; |
49 | this.CmdShow = cmdShow; | 48 | this.CmdShow = cmdShow; |
50 | this.Resume = resume; | 49 | this.Resume = resume; |
51 | this.SplashScreen = splashScreen; | 50 | this.SplashScreen = splashScreen; |
@@ -66,7 +65,7 @@ namespace WixToolset.Mba.Core | |||
66 | public Restart Restart { get; } | 65 | public Restart Restart { get; } |
67 | 66 | ||
68 | /// <inheritdoc/> | 67 | /// <inheritdoc/> |
69 | public string[] CommandLineArgs => GetCommandLineArgs(this.commandLine); | 68 | public string CommandLine { get; } |
70 | 69 | ||
71 | /// <inheritdoc/> | 70 | /// <inheritdoc/> |
72 | public int CmdShow { get; } | 71 | public int CmdShow { get; } |
@@ -92,6 +91,49 @@ namespace WixToolset.Mba.Core | |||
92 | /// <inheritdoc/> | 91 | /// <inheritdoc/> |
93 | public string BootstrapperApplicationDataPath { get; } | 92 | public string BootstrapperApplicationDataPath { get; } |
94 | 93 | ||
94 | /// <inheritdoc/> | ||
95 | public IMbaCommand ParseCommandLine() | ||
96 | { | ||
97 | var args = ParseCommandLineToArgs(this.CommandLine); | ||
98 | var unknownArgs = new List<string>(); | ||
99 | var variables = new List<KeyValuePair<string, string>>(); | ||
100 | |||
101 | foreach (var arg in args) | ||
102 | { | ||
103 | var unknownArg = false; | ||
104 | |||
105 | if (arg[0] == '-' || arg[0] == '/') | ||
106 | { | ||
107 | unknownArg = true; | ||
108 | } | ||
109 | else | ||
110 | { | ||
111 | var index = arg.IndexOf('='); | ||
112 | if (index == -1) | ||
113 | { | ||
114 | unknownArg = true; | ||
115 | } | ||
116 | else | ||
117 | { | ||
118 | var name = arg.Substring(0, index); | ||
119 | var value = arg.Substring(index + 1); | ||
120 | variables.Add(new KeyValuePair<string, string>(name, value)); | ||
121 | } | ||
122 | } | ||
123 | |||
124 | if (unknownArg) | ||
125 | { | ||
126 | unknownArgs.Add(arg); | ||
127 | } | ||
128 | } | ||
129 | |||
130 | return new MbaCommand | ||
131 | { | ||
132 | UnknownCommandLineArgs = unknownArgs.ToArray(), | ||
133 | Variables = variables.ToArray(), | ||
134 | }; | ||
135 | } | ||
136 | |||
95 | /// <summary> | 137 | /// <summary> |
96 | /// Gets the command line arguments as a string array. | 138 | /// Gets the command line arguments as a string array. |
97 | /// </summary> | 139 | /// </summary> |
@@ -102,7 +144,7 @@ namespace WixToolset.Mba.Core | |||
102 | /// <remarks> | 144 | /// <remarks> |
103 | /// This method uses the same parsing as the operating system which handles quotes and spaces correctly. | 145 | /// This method uses the same parsing as the operating system which handles quotes and spaces correctly. |
104 | /// </remarks> | 146 | /// </remarks> |
105 | public static string[] GetCommandLineArgs(string commandLine) | 147 | public static string[] ParseCommandLineToArgs(string commandLine) |
106 | { | 148 | { |
107 | if (null == commandLine) | 149 | if (null == commandLine) |
108 | { | 150 | { |
diff --git a/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs b/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs index 3d5d535d..4a533bf9 100644 --- a/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs +++ b/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs | |||
@@ -23,6 +23,9 @@ namespace WixToolset.Mba.Core | |||
23 | public string LogVariable { get; internal set; } | 23 | public string LogVariable { get; internal set; } |
24 | 24 | ||
25 | /// <inheritdoc/> | 25 | /// <inheritdoc/> |
26 | public IOverridableVariables OverridableVariables { get; internal set; } | ||
27 | |||
28 | /// <inheritdoc/> | ||
26 | public IDictionary<string, IPackageInfo> Packages { get; internal set; } | 29 | public IDictionary<string, IPackageInfo> Packages { get; internal set; } |
27 | 30 | ||
28 | internal BundleInfo() | 31 | internal BundleInfo() |
@@ -78,6 +81,8 @@ namespace WixToolset.Mba.Core | |||
78 | 81 | ||
79 | bundle.LogVariable = BootstrapperApplicationData.GetAttribute(bundleNode, "LogPathVariable"); | 82 | bundle.LogVariable = BootstrapperApplicationData.GetAttribute(bundleNode, "LogPathVariable"); |
80 | 83 | ||
84 | bundle.OverridableVariables = OverridableVariablesInfo.ParseFromXml(root); | ||
85 | |||
81 | bundle.Packages = PackageInfo.ParsePackagesFromXml(root); | 86 | bundle.Packages = PackageInfo.ParsePackagesFromXml(root); |
82 | 87 | ||
83 | return bundle; | 88 | return bundle; |
diff --git a/src/api/burn/WixToolset.Mba.Core/IBootstrapperCommand.cs b/src/api/burn/WixToolset.Mba.Core/IBootstrapperCommand.cs index e861813f..b7baa55c 100644 --- a/src/api/burn/WixToolset.Mba.Core/IBootstrapperCommand.cs +++ b/src/api/burn/WixToolset.Mba.Core/IBootstrapperCommand.cs | |||
@@ -25,13 +25,12 @@ namespace WixToolset.Mba.Core | |||
25 | Restart Restart { get; } | 25 | Restart Restart { get; } |
26 | 26 | ||
27 | /// <summary> | 27 | /// <summary> |
28 | /// Gets the command line arguments as a string array. | 28 | /// Gets the command line arguments. |
29 | /// </summary> | 29 | /// </summary> |
30 | /// <returns> | 30 | /// <returns> |
31 | /// Array of command line arguments not handled by the engine. | 31 | /// Command line arguments not handled by the engine. |
32 | /// </returns> | 32 | /// </returns> |
33 | /// <exception type="Win32Exception">The command line could not be parsed into an array.</exception> | 33 | string CommandLine { get; } |
34 | string[] CommandLineArgs { get; } | ||
35 | 34 | ||
36 | /// <summary> | 35 | /// <summary> |
37 | /// Hint for the initial visibility of the window. | 36 | /// Hint for the initial visibility of the window. |
@@ -72,5 +71,14 @@ namespace WixToolset.Mba.Core | |||
72 | /// Gets path to BootstrapperApplicationData.xml. | 71 | /// Gets path to BootstrapperApplicationData.xml. |
73 | /// </summary> | 72 | /// </summary> |
74 | string BootstrapperApplicationDataPath { get; } | 73 | string BootstrapperApplicationDataPath { get; } |
74 | |||
75 | /// <summary> | ||
76 | /// Parses the command line arguments into an <see cref="IMbaCommand"/>. | ||
77 | /// </summary> | ||
78 | /// <returns> | ||
79 | /// The parsed information. | ||
80 | /// </returns> | ||
81 | /// <exception type="Win32Exception">The command line could not be parsed.</exception> | ||
82 | IMbaCommand ParseCommandLine(); | ||
75 | } | 83 | } |
76 | } | 84 | } |
diff --git a/src/api/burn/WixToolset.Mba.Core/IBundleInfo.cs b/src/api/burn/WixToolset.Mba.Core/IBundleInfo.cs index f4a82f36..35decc88 100644 --- a/src/api/burn/WixToolset.Mba.Core/IBundleInfo.cs +++ b/src/api/burn/WixToolset.Mba.Core/IBundleInfo.cs | |||
@@ -22,6 +22,11 @@ namespace WixToolset.Mba.Core | |||
22 | /// <summary> | 22 | /// <summary> |
23 | /// | 23 | /// |
24 | /// </summary> | 24 | /// </summary> |
25 | IOverridableVariables OverridableVariables { get; } | ||
26 | |||
27 | /// <summary> | ||
28 | /// | ||
29 | /// </summary> | ||
25 | IDictionary<string, IPackageInfo> Packages { get; } | 30 | IDictionary<string, IPackageInfo> Packages { get; } |
26 | 31 | ||
27 | /// <summary> | 32 | /// <summary> |
diff --git a/src/api/burn/WixToolset.Mba.Core/IMbaCommand.cs b/src/api/burn/WixToolset.Mba.Core/IMbaCommand.cs new file mode 100644 index 00000000..a3ad68d8 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/IMbaCommand.cs | |||
@@ -0,0 +1,30 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | using System.Collections.Generic; | ||
6 | |||
7 | /// <summary> | ||
8 | /// Command information parsed from the command line. | ||
9 | /// </summary> | ||
10 | public interface IMbaCommand | ||
11 | { | ||
12 | /// <summary> | ||
13 | /// The command line arguments not parsed into <see cref="IBootstrapperCommand"/> or <see cref="IMbaCommand"/>. | ||
14 | /// </summary> | ||
15 | string[] UnknownCommandLineArgs { get; } | ||
16 | |||
17 | /// <summary> | ||
18 | /// The variables that were parsed from the command line. | ||
19 | /// Key = variable name, Value = variable value. | ||
20 | /// </summary> | ||
21 | KeyValuePair<string, string>[] Variables { get; } | ||
22 | |||
23 | /// <summary> | ||
24 | /// Sets overridable variables from the command line. | ||
25 | /// </summary> | ||
26 | /// <param name="overridableVariables">The overridable variable information from <see cref="IBootstrapperApplicationData"/>.</param> | ||
27 | /// <param name="engine">The engine.</param> | ||
28 | void SetOverridableVariables(IOverridableVariables overridableVariables, IEngine engine); | ||
29 | } | ||
30 | } | ||
diff --git a/src/api/burn/WixToolset.Mba.Core/IOverridableVariableInfo.cs b/src/api/burn/WixToolset.Mba.Core/IOverridableVariableInfo.cs new file mode 100644 index 00000000..d01dead3 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/IOverridableVariableInfo.cs | |||
@@ -0,0 +1,15 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | /// <summary> | ||
6 | /// Overridable variable from the BA manifest. | ||
7 | /// </summary> | ||
8 | public interface IOverridableVariableInfo | ||
9 | { | ||
10 | /// <summary> | ||
11 | /// The Variable name. | ||
12 | /// </summary> | ||
13 | string Name { get; } | ||
14 | } | ||
15 | } \ No newline at end of file | ||
diff --git a/src/api/burn/WixToolset.Mba.Core/IOverridableVariables.cs b/src/api/burn/WixToolset.Mba.Core/IOverridableVariables.cs new file mode 100644 index 00000000..3944913b --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/IOverridableVariables.cs | |||
@@ -0,0 +1,17 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | using System.Collections.Generic; | ||
6 | |||
7 | /// <summary> | ||
8 | /// Overridable variable information from the BA manifest. | ||
9 | /// </summary> | ||
10 | public interface IOverridableVariables | ||
11 | { | ||
12 | /// <summary> | ||
13 | /// Variable Dictionary of variable name to <see cref="IOverridableVariableInfo"/>. | ||
14 | /// </summary> | ||
15 | IDictionary<string, IOverridableVariableInfo> Variables { get; } | ||
16 | } | ||
17 | } \ No newline at end of file | ||
diff --git a/src/api/burn/WixToolset.Mba.Core/MbaCommand.cs b/src/api/burn/WixToolset.Mba.Core/MbaCommand.cs new file mode 100644 index 00000000..e7e49607 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/MbaCommand.cs | |||
@@ -0,0 +1,33 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | using System.Collections.Generic; | ||
6 | |||
7 | /// <summary> | ||
8 | /// Default implementation of <see cref="IMbaCommand"/>. | ||
9 | /// </summary> | ||
10 | internal sealed class MbaCommand : IMbaCommand | ||
11 | { | ||
12 | public string[] UnknownCommandLineArgs { get; internal set; } | ||
13 | |||
14 | public KeyValuePair<string, string>[] Variables { get; internal set; } | ||
15 | |||
16 | internal MbaCommand() { } | ||
17 | |||
18 | public void SetOverridableVariables(IOverridableVariables overridableVariables, IEngine engine) | ||
19 | { | ||
20 | foreach (var kvp in this.Variables) | ||
21 | { | ||
22 | if (!overridableVariables.Variables.TryGetValue(kvp.Key, out var overridableVariable)) | ||
23 | { | ||
24 | engine.Log(LogLevel.Error, string.Format("Ignoring attempt to set non-overridable variable: '{0}'.", kvp.Key)); | ||
25 | } | ||
26 | else | ||
27 | { | ||
28 | engine.SetVariableString(overridableVariable.Name, kvp.Value, false); | ||
29 | } | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | } | ||
diff --git a/src/api/burn/WixToolset.Mba.Core/OverridableVariableInfo.cs b/src/api/burn/WixToolset.Mba.Core/OverridableVariableInfo.cs new file mode 100644 index 00000000..b8e85c34 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/OverridableVariableInfo.cs | |||
@@ -0,0 +1,15 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | /// <summary> | ||
6 | /// Default implementation of <see cref="IOverridableVariableInfo"/>. | ||
7 | /// </summary> | ||
8 | internal class OverridableVariableInfo : IOverridableVariableInfo | ||
9 | { | ||
10 | /// <inheritdoc /> | ||
11 | public string Name { get; internal set; } | ||
12 | |||
13 | internal OverridableVariableInfo() { } | ||
14 | } | ||
15 | } | ||
diff --git a/src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs b/src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs new file mode 100644 index 00000000..855ce9a9 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/OverridableVariables.cs | |||
@@ -0,0 +1,51 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Xml; | ||
8 | using System.Xml.XPath; | ||
9 | |||
10 | /// <summary> | ||
11 | /// Default implementation of <see cref="IOverridableVariables"/>. | ||
12 | /// </summary> | ||
13 | public class OverridableVariablesInfo : IOverridableVariables | ||
14 | { | ||
15 | /// <inheritdoc /> | ||
16 | public IDictionary<string, IOverridableVariableInfo> Variables { get; internal set; } | ||
17 | |||
18 | internal OverridableVariablesInfo() { } | ||
19 | |||
20 | /// <summary> | ||
21 | /// Parses the overridable variable info from the BA manifest. | ||
22 | /// </summary> | ||
23 | /// <param name="root">XML root</param> | ||
24 | /// <returns>The parsed information.</returns> | ||
25 | public static IOverridableVariables ParseFromXml(XPathNavigator root) | ||
26 | { | ||
27 | XmlNamespaceManager namespaceManager = new XmlNamespaceManager(root.NameTable); | ||
28 | namespaceManager.AddNamespace("p", BootstrapperApplicationData.XMLNamespace); | ||
29 | XPathNodeIterator nodes = root.Select("/p:BootstrapperApplicationData/p:WixStdbaOverridableVariable", namespaceManager); | ||
30 | |||
31 | var overridableVariables = new OverridableVariablesInfo(); | ||
32 | overridableVariables.Variables = new Dictionary<string, IOverridableVariableInfo>(); | ||
33 | |||
34 | foreach (XPathNavigator node in nodes) | ||
35 | { | ||
36 | var variable = new OverridableVariableInfo(); | ||
37 | |||
38 | string name = BootstrapperApplicationData.GetAttribute(node, "Name"); | ||
39 | if (name == null) | ||
40 | { | ||
41 | throw new Exception("Failed to get name for overridable variable."); | ||
42 | } | ||
43 | variable.Name = name; | ||
44 | |||
45 | overridableVariables.Variables.Add(variable.Name, variable); | ||
46 | } | ||
47 | |||
48 | return overridableVariables; | ||
49 | } | ||
50 | } | ||
51 | } | ||