diff options
author | Rob Mensching <rob@firegiant.com> | 2021-04-22 05:46:03 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-04-29 16:41:44 -0700 |
commit | c00516901e6b67e398396b14fe7682d0376f8643 (patch) | |
tree | b0d62089a1c5700c7f2c3e3790750bf2d8ea33c0 /src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs | |
parent | 8eb98efd2175d9ece2e4639d43081667af9a4990 (diff) | |
download | wix-c00516901e6b67e398396b14fe7682d0376f8643.tar.gz wix-c00516901e6b67e398396b14fe7682d0376f8643.tar.bz2 wix-c00516901e6b67e398396b14fe7682d0376f8643.zip |
Move balutil into API/burn
Diffstat (limited to 'src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs')
-rw-r--r-- | src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs b/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs new file mode 100644 index 00000000..65dde0f4 --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/BootstrapperCommand.cs | |||
@@ -0,0 +1,145 @@ | |||
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.ComponentModel; | ||
7 | using System.Runtime.InteropServices; | ||
8 | |||
9 | /// <summary> | ||
10 | /// Default implementation of <see cref="IBootstrapperCommand"/>. | ||
11 | /// </summary> | ||
12 | public sealed class BootstrapperCommand : IBootstrapperCommand | ||
13 | { | ||
14 | private readonly string commandLine; | ||
15 | |||
16 | /// <summary> | ||
17 | /// | ||
18 | /// </summary> | ||
19 | /// <param name="action"></param> | ||
20 | /// <param name="display"></param> | ||
21 | /// <param name="restart"></param> | ||
22 | /// <param name="commandLine"></param> | ||
23 | /// <param name="cmdShow"></param> | ||
24 | /// <param name="resume"></param> | ||
25 | /// <param name="splashScreen"></param> | ||
26 | /// <param name="relation"></param> | ||
27 | /// <param name="passthrough"></param> | ||
28 | /// <param name="layoutDirectory"></param> | ||
29 | /// <param name="bootstrapperWorkingFolder"></param> | ||
30 | /// <param name="bootstrapperApplicationDataPath"></param> | ||
31 | public BootstrapperCommand( | ||
32 | LaunchAction action, | ||
33 | Display display, | ||
34 | Restart restart, | ||
35 | string commandLine, | ||
36 | int cmdShow, | ||
37 | ResumeType resume, | ||
38 | IntPtr splashScreen, | ||
39 | RelationType relation, | ||
40 | bool passthrough, | ||
41 | string layoutDirectory, | ||
42 | string bootstrapperWorkingFolder, | ||
43 | string bootstrapperApplicationDataPath) | ||
44 | { | ||
45 | this.Action = action; | ||
46 | this.Display = display; | ||
47 | this.Restart = restart; | ||
48 | this.commandLine = commandLine; | ||
49 | this.CmdShow = cmdShow; | ||
50 | this.Resume = resume; | ||
51 | this.SplashScreen = splashScreen; | ||
52 | this.Relation = relation; | ||
53 | this.Passthrough = passthrough; | ||
54 | this.LayoutDirectory = layoutDirectory; | ||
55 | this.BootstrapperWorkingFolder = bootstrapperWorkingFolder; | ||
56 | this.BootstrapperApplicationDataPath = bootstrapperApplicationDataPath; | ||
57 | } | ||
58 | |||
59 | /// <inheritdoc/> | ||
60 | public LaunchAction Action { get; } | ||
61 | |||
62 | /// <inheritdoc/> | ||
63 | public Display Display { get; } | ||
64 | |||
65 | /// <inheritdoc/> | ||
66 | public Restart Restart { get; } | ||
67 | |||
68 | /// <inheritdoc/> | ||
69 | public string[] CommandLineArgs => GetCommandLineArgs(this.commandLine); | ||
70 | |||
71 | /// <inheritdoc/> | ||
72 | public int CmdShow { get; } | ||
73 | |||
74 | /// <inheritdoc/> | ||
75 | public ResumeType Resume { get; } | ||
76 | |||
77 | /// <inheritdoc/> | ||
78 | public IntPtr SplashScreen { get; } | ||
79 | |||
80 | /// <inheritdoc/> | ||
81 | public RelationType Relation { get; } | ||
82 | |||
83 | /// <inheritdoc/> | ||
84 | public bool Passthrough { get; } | ||
85 | |||
86 | /// <inheritdoc/> | ||
87 | public string LayoutDirectory { get; } | ||
88 | |||
89 | /// <inheritdoc/> | ||
90 | public string BootstrapperWorkingFolder { get; } | ||
91 | |||
92 | /// <inheritdoc/> | ||
93 | public string BootstrapperApplicationDataPath { get; } | ||
94 | |||
95 | /// <summary> | ||
96 | /// Gets the command line arguments as a string array. | ||
97 | /// </summary> | ||
98 | /// <returns> | ||
99 | /// Array of command line arguments. | ||
100 | /// </returns> | ||
101 | /// <exception type="Win32Exception">The command line could not be parsed into an array.</exception> | ||
102 | /// <remarks> | ||
103 | /// This method uses the same parsing as the operating system which handles quotes and spaces correctly. | ||
104 | /// </remarks> | ||
105 | public static string[] GetCommandLineArgs(string commandLine) | ||
106 | { | ||
107 | if (null == commandLine) | ||
108 | { | ||
109 | return new string[0]; | ||
110 | } | ||
111 | |||
112 | // Parse the filtered command line arguments into a native array. | ||
113 | int argc = 0; | ||
114 | |||
115 | // CommandLineToArgvW tries to treat the first argument as the path to the process, | ||
116 | // which fails pretty miserably if your first argument is something like | ||
117 | // FOO="C:\Program Files\My Company". So give it something harmless to play with. | ||
118 | IntPtr argv = NativeMethods.CommandLineToArgvW("ignored " + commandLine, out argc); | ||
119 | |||
120 | if (IntPtr.Zero == argv) | ||
121 | { | ||
122 | // Throw an exception with the last error. | ||
123 | throw new Win32Exception(); | ||
124 | } | ||
125 | |||
126 | // Marshal each native array pointer to a managed string. | ||
127 | try | ||
128 | { | ||
129 | // Skip "ignored" argument/hack. | ||
130 | string[] args = new string[argc - 1]; | ||
131 | for (int i = 1; i < argc; ++i) | ||
132 | { | ||
133 | IntPtr argvi = Marshal.ReadIntPtr(argv, i * IntPtr.Size); | ||
134 | args[i - 1] = Marshal.PtrToStringUni(argvi); | ||
135 | } | ||
136 | |||
137 | return args; | ||
138 | } | ||
139 | finally | ||
140 | { | ||
141 | NativeMethods.LocalFree(argv); | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | } | ||