-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathCLIProcessor.cs
More file actions
277 lines (267 loc) · 9.76 KB
/
CLIProcessor.cs
File metadata and controls
277 lines (267 loc) · 9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using SimulatorDatabase;
namespace UltimateBlueScreenSimulator
{
///<summary>
///Command line interface processor
///</summary>
internal class CLIProcessor
{
internal readonly string[] args;
private bool checkvalue;
public CLIProcessor(string[] args)
{
this.args = args;
checkvalue = false;
}
///<summary>
///Processes all provided arguments
///</summary>
public void ProcessArgs()
{
string lastArg = "";
foreach (string arg in args)
{
if (arg.StartsWith("/"))
{
ProcessFlag(arg);
}
if (checkvalue)
{
ProcessValue(lastArg, arg);
}
lastArg = arg;
}
PostProcess();
}
///<summary>
///Forces a boolean on all configurations to a specific value
///</summary>
///<param name="name">Name of the boolean</param>
///<param name="value">Value of the boolean</param>
private void ForceBool(string name, bool value)
{
Program.gs.Log("Info", $"Forcing {name} to {(value?"enabled":"disabled")} state");
foreach (BlueScreen bs in Program.templates.GetAll())
{
bs.SetBool(name, value);
}
}
///<summary>
///Processes a value after a specific flag
///</summary>
///<param name="flag">The specific flag</param>
///<param name="value">The value</param>
private void ProcessValue(string flag, string value)
{
string ecode;
if (flag.Length < 2)
{
return;
}
switch (flag.Substring(1))
{
case "wv":
//select Windows version using /wv argument
ecode = value;
if (ecode == "")
{
Program.gs.ErrorCode = 15;
}
int i = 0;
bool done = false;
foreach (BlueScreen bs in Program.templates.GetAll())
{
if (bs.GetString("friendlyname").ToLower().Contains(ecode.ToLower()) || bs.GetString("os").ToLower().Contains(ecode.ToLower()))
{
UIActions.me = bs;
Program.gs.DisplayOne = true;
//Program.f1.comboBox1.SelectedIndex = i;
done = true;
break;
}
i++;
}
if (!done)
{
Program.gs.ErrorCode = 12;
}
break;
case "config":
//this code loads hack file if specified in arguments
string filename = value;
Program.gs.Log("Info", $"Loading configuration file: {filename}");
if (File.Exists(filename))
{
if (filename != "")
{
AboutSettingsDialog abb = new AboutSettingsDialog();
Program.templates = Program.templates.LoadConfig(filename);
abb.Close();
abb.Dispose();
}
}
else
{
Program.gs.ErrorCode = 24;
}
break;
case "file":
//displays errror cuplrit file if specified in arguments
Program.gs.Log("Info", "Setting culprit file");
Program.F1.checkBox2.Checked = true;
ecode = value;
foreach (BlueScreen bs in Program.templates.GetAll())
{
bs.SetString("culprit", ecode);
}
if (ecode == "")
{
Program.gs.ErrorCode = 16;
}
Program.F1.textBox2.Text = ecode;
break;
}
}
///<summary>
///Closes the splash screen
///</summary>
internal void ExitSplash()
{
if (!CheckNoSplash())
{
Program.gs.Log("Info", "Safely closing splash screen");
}
}
///<summary>
///Processes a command line parameter which has a slash in front of it
///</summary>
///<param name="arg">The argument with the / character</param>
private void ProcessFlag(string arg)
{
// key is the flag, value determines which boolean to force
Dictionary<string, string> forceFlags = new Dictionary<string, string>()
{
{"wm", "watermark"}, {"desc", "show_description"}, {"ac", "autoclose"},
{"ap", "acpi"}, {"amd", "amd"}, {"blink", "blink"}, {"gs", "insider"},
{"qr", "qr"}, {"srv", "server"}, {"stack", "stack_trace"},
{"win", "windowed"}, {"file", "show_file"}, {"ctd", "countdown"},
};
foreach (KeyValuePair<string, string> kv in forceFlags)
{
if (arg.Substring(1).Equals(kv.Key))
{
ForceBool(kv.Value, true);
} else if (arg.Substring(1).Equals($"d{kv.Key}"))
{
ForceBool(kv.Value, false);
}
}
switch (arg.Substring(1))
{
case "?":
ExitSplash();
MessageBox.Show(string.Join("\n", Program.cmds), "Command line argument usage", MessageBoxButtons.OK, MessageBoxIcon.Information);
Program.gs.ErrorCode = 999;
Program.halt = true;
break;
case "finalize_update":
case "hidesplash":
Program.hide_splash = true;
break;
case "clr":
//Clears Verifile verification certificate
ExitSplash();
File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\Verifile\bssp3.key");
MessageBox.Show("Signature verification file deleted. The program will now close.", "Ultimate blue screen simulator plus", MessageBoxButtons.OK, MessageBoxIcon.Information);
Program.halt = true;
Application.Exit();
break;
case "c":
ExitSplash();
UIActions.GetOS(Program.F1);
break;
case "doneupdate":
File.Delete("BSSP.exe");
break;
case "random":
UIActions.RandFunction(Program.F1, false);
break;
case "hwm":
ForceBool("watermark", false);
break;
case "legacy":
Program.force_legacy = true;
break;
case "config":
case "file":
case "wv":
checkvalue = true;
break;
}
}
///<summary>
///Processes arguments which should be dealt with last
///</summary>
private void PostProcess()
{
//hide main interface if /h flag is set
if (args.Contains("/h"))
{
Program.halt = true;
Program.gs.Log("Info", "Hiding main interface");
Form mf = Program.F1;
if (Program.gs.LegacyUI)
{
mf = Program.F2;
}
mf.WindowState = FormWindowState.Minimized;
mf.ShowInTaskbar = false;
mf.ShowIcon = false;
mf.Hide();
Program.gs.PM_CloseMainUI = true;
if (!args.Contains("/c") && !args.Contains("/random"))
{
ExitSplash();
MessageBox.Show("/h cannot be used without /c or /random", "Syntax error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
}
//Simulate crash if /c flag is set
if (args.Contains("/c"))
{
Program.gs.Log("Info", "Starting simulation from command line");
UIActions.Crash(Program.F1);
}
//Post update scripts
if (args.Contains("/finalize_update"))
{
Program.gs.Log("Info", $"Performing update (Stage 2)");
UpdateInterface ui = new UpdateInterface
{
finalize = true
};
Application.Run(ui);
Program.halt = true;
}
}
///<summary>
///Returns true if splash screen cannot be displayed
///</summary>
public bool CheckNoSplash()
{
return args.Contains("/finalize_update") || args.Contains("/hidesplash");
}
///<summary>
///Returns true if splash screen preview is enabled
///</summary>
public bool CheckPreviewSplash()
{
return args.Contains("/preview_splash");
}
}
}