-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathUIActions.cs
More file actions
1196 lines (1163 loc) · 51.1 KB
/
Copy pathUIActions.cs
File metadata and controls
1196 lines (1163 loc) · 51.1 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using MaterialSkin2Framework.Controls;
using Microsoft.Win32;
using SimulatorDatabase;
namespace UltimateBlueScreenSimulator
{
public static class UIActions
{
public static ThreadStart ts;
public static Thread bsod_starter;
public static BlueScreen me;
public static WindowScreen specialwindow;
public static string Version {
get {
string verStr = string.Join(".", Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.').Take(3).ToArray());
while (verStr.EndsWith(".0"))
{
verStr = verStr.Substring(0, verStr.Length - 2);
}
if (!verStr.Contains("."))
{
verStr += ".0";
}
return verStr;
}
}
/// <summary>
/// Hides controls related to settings from current form
/// </summary>
/// <param name="f">Current form (can be Main or NewUI)</param>
public static void HideSelection(Control f)
{
//hide all controls
FlowLayoutPanel container = ((FlowLayoutPanel)FindControl(f, "flowLayoutPanel1"));
if (f is FlowLayoutPanel panel) { container = panel; }
if (container is null)
{
return;
}
foreach (Control c in container.Controls)
{
if (c is FlowLayoutPanel)
{
HideSelection(c);
}
switch (c.Name)
{
case "WXOptions":
case "errorCode":
case "crashDumpBox":
case "nineXmessage":
case "serverBox":
case "greenBox":
case "qrBox":
case "checkBox1":
case "winMode":
case "acpiBox":
case "amdBox":
case "stackBox":
case "ntPanel":
case "memoryBox":
case "dumpBox":
case "winPanel":
case "advNTButton":
case "eCodeEditButton":
case "devPCBox":
case "playSndBox":
case "countdownBox":
case "progressTuneButton":
case "halfBox":
case "troubleshootBox":
case "blackScreenBox":
case "panel2":
c.Visible = false;
Program.gs.Log("Info", $"Hiding {c}");
break;
case "checkBox2":
c.Visible = true;
break;
case "embedExeButton":
c.Visible = !Program.templates.qaddeTrip;
break;
}
switch (c.Name)
{
case "addInfFile":
c.Enabled = false;
break;
case "dumpBox":
case "checkBox2":
c.Enabled = true;
break;
}
}
}
/// <summary>
/// Find a control from a container (recursive search)
/// </summary>
/// <param name="container">The container where to search the control from</param>
/// <param name="Name">Name of the control you want to find</param>
/// <returns>Control with the specified name</returns>
private static Control FindControl(Control container, string Name)
{
Program.gs.Log("Info", $"Searching for {Name} from {container.Name}");
foreach (Control c in container.Controls)
{
Control FoundControl = null;
if (c is FlowLayoutPanel flp)
{
FoundControl = FindControl(flp, Name);
}
else if (c is Panel p)
{
FoundControl = FindControl(p, Name);
}
else if (c is MaterialTabControl tc)
{
FoundControl = FindControl(tc, Name);
}
else if (c is TabPage tp)
{
FoundControl = FindControl(tp, Name);
}
if (FoundControl != null)
{
return FoundControl;
}
if (c.Name == Name)
{
return c;
}
}
return null;
}
/// <summary>
/// Allows you to remove or restore [?] on various UI elements
/// </summary>
/// <param name="container">Container where the UI elements are located</param>
/// <param name="show">Visibility</param>
public static void RemoveQuestionMark(Control container, bool show)
{
Program.gs.Log("Info", $"Hiding question marks in {container.Name}");
foreach (Control c in container.Controls)
{
if (c is FlowLayoutPanel flp)
{
RemoveQuestionMark(flp, show);
}
else if (c is Panel p)
{
RemoveQuestionMark(p, show);
}
else if (c is MaterialTabControl tc)
{
RemoveQuestionMark(tc, show);
}
else if (c is TabPage tp)
{
RemoveQuestionMark(tp, show);
}
if (show && c.Text.Contains(""))
{
c.Text = c.Text.Replace("", " [?]");
}
else if (c.Text.Contains("[?]"))
{
c.Text = c.Text.Replace(" [?]", "");
}
}
}
/// <summary>
/// Allows you to check or uncheck either a CheckBox or MaterialCheckbox from a container
/// </summary>
/// <param name="container">The container to search the control from</param>
/// <param name="Name">Name of the control</param>
/// <param name="Checked">Check value you want to apply to the control</param>
/// <exception cref="FormatException">The type of the control is invalid</exception>
private static void SetControlChecked(Control container, string Name, bool Checked)
{
Program.gs.Log("Info", $"Setting checked to {Checked} for {Name}");
Control c = FindControl(container, Name);
if (c is CheckBox ch)
{
ch.Checked = Checked;
return;
}
else if (c is MaterialCheckbox mch)
{
mch.Checked = Checked;
return;
}
else if (c is RadioButton rb)
{
rb.Checked = Checked;
return;
}
else if (c is MaterialRadioButton mrb)
{
mrb.Checked = Checked;
return;
}
throw new FormatException();
}
/// <summary>
/// Allows you to show or hide a control from a specific container
/// </summary>
/// <param name="container">The container to search the control from</param>
/// <param name="Name">Name of the control</param>
/// <param name="Visible">Visible value you want to apply to the control</param>
private static void SetControlVisible(Control container, string Name, bool Visible)
{
Program.gs.Log("Info", $"Setting visible to {Visible} for {Name}");
FindControl(container, Name).Visible = Visible;
}
/// <summary>
/// Allows you to enable or disable a control from a specific container
/// </summary>
/// <param name="container">The container to search the control from</param>
/// <param name="Name">Name of the control</param>
/// <param name="Visible">Enabled value you want to apply to the control</param>
private static void SetControlEnabled(Control container, string Name, bool Enabled)
{
Program.gs.Log("Info", $"Setting enabled to {Enabled} for {Name}");
FindControl(container, Name).Enabled = Enabled;
}
public static void UpdateBool(Form f, CheckBox c)
{
if (me == null)
{
return;
}
Dictionary<string, string> kvp = new Dictionary<string, string>()
{
{ "autoBox", "autoclose" },
{ "serverBox", "server" },
{ "greenBox", "insider" },
{ "qrBox", "qr" },
{ "memoryBox", "extracodes" },
{ "devPCBox", "device" },
{ "blackScreenBox", "blackscreen" },
{ "addInfFile", "extrafile" },
{ "amdBox", "amd" },
{ "stackBox", "stack_trace" },
{ "blinkBox", "blink" },
{ "acpiBox", "acpi" },
{ "waterBox", "watermark" },
{ "checkBox1", "show_description" },
{ "dumpBox", "autoclose" },
{ "playSndBox", "playsound" },
{ "countdownBox", "countdown" },
{ "displayOsBox", "bootscreen" },
{ "halfBox", "halfres" },
{ "rainbowBox", "rainbow" },
{ "troubleshootBox", "troubleshoot" },
{ "winMode", "windowed" },
{ "checkBox2", "show_file" },
{ "crashDumpBox", "crashdump" }
};
switch (c.Name)
{
case "acpiBox":
SetControlEnabled(f, "dumpBox", !c.Checked);
SetControlChecked(f, "dumpBox", !c.Checked);
break;
case "halfBox":
SetControlEnabled(f, "winPanel", !c.Checked);
if (me.GetBool("halfres"))
{
SetControlChecked(f, "nostartup", true);
}
break;
case "checkBox2":
SetControlEnabled(f, "textBox2", c.Checked);
SetControlEnabled(f, "button2", c.Checked);
break;
case "winMode":
SetControlVisible(f, "label7", !c.Checked);
break;
}
if (kvp.Keys.Contains(c.Name))
{
me.SetBool(kvp[c.Name], c.Checked);
} else
{
throw new NullReferenceException();
}
}
/// <summary>
/// Sets the visibility and values of setting controls on the current form
/// </summary>
/// <param name="f">Main or NewUI form object</param>
/// <param name="me">Selected template</param>
public static void ResetSelection(Form f, BlueScreen me)
{
//progressTunerToolStripMenuItem.Enabled = fal
FlowLayoutPanel fp = (FlowLayoutPanel)FindControl(f, "flowLayoutPanel1");
SetControlVisible(fp, "rainbowBox", me.GetBool("font_support") || me.GetString("os") == "BOOTMGR");
SetControlEnabled(fp, "addInfFile", false);
// set control visibility for specific OS-es
List<string> ExplicitShow = new List<string>();
switch (me.GetString("os"))
{
case "Windows 11 Beta":
ExplicitShow.AddRange(new string[] { "WXOptions","errorCode", "winMode", "checkBox1", "memoryBox", "eCodeEditButton", "progressTuneButton", "greenBox", "crashDumpBox" });
SetControlVisible(fp, "serverBox", false);
SetControlVisible(fp, "blackScreenBox", false);
SetControlVisible(fp, "devPCBox", false);
SetControlVisible(fp, "qrBox", false);
break;
case "Windows 11":
ExplicitShow.AddRange(new string[]
{
"WXOptions",
"serverBox",
"qrBox",
"errorCode",
"checkBox1",
"winMode",
"memoryBox",
"eCodeEditButton",
"blackScreenBox",
"progressTuneButton"
});
SetControlVisible(fp, "devPCBox", false);
SetControlChecked(fp, "autoBox", true);
SetControlChecked(fp, "blackScreenBox", me.GetBool("blackscreen"));
SetControlVisible(fp, "crashDumpBox", true);
break;
case "Windows 10":
ExplicitShow.AddRange(new string[]
{
"WXOptions",
"serverBox",
"greenBox",
"qrBox",
"errorCode",
"checkBox1",
"winMode",
"memoryBox",
"eCodeEditButton",
"devPCBox",
"progressTuneButton"
});
SetControlVisible(fp, "blackScreenBox", false);
SetControlVisible(fp, "crashDumpBox", true);
SetControlChecked(fp, "autoBox", true);
break;
case "Windows 8/8.1":
ExplicitShow.AddRange(new string[]
{
"WXOptions",
"errorCode",
"checkBox1",
"winMode",
"memoryBox",
"eCodeEditButton",
"progressTuneButton",
"blackScreenBox"
});
SetControlVisible(fp, "crashDumpBox", false);
SetControlVisible(fp, "greenBox", false);
SetControlVisible(fp, "serverBox", false);
SetControlVisible(fp, "crashDumpBox", false);
SetControlChecked(fp, "blackScreenBox", me.GetBool("blackscreen"));
break;
case "Windows 8 Beta":
ExplicitShow.AddRange(new string[]
{
"errorCode",
"winMode",
"memoryBox",
"eCodeEditButton",
"countdownBox"
});
SetControlEnabled(fp, "checkBox2", false);
break;
case "Windows Vista":
case "Windows 7":
ExplicitShow.AddRange(new string[]
{
"errorCode",
"winMode",
"acpiBox",
"checkBox1",
"autoBox",
"dumpBox",
"advNTButton",
"eCodeEditButton"
});
SetControlEnabled(fp, "addInfFile", true);
//progressTunerToolStripMenuItem.Enabled = true;
break;
case "Windows XP":
ExplicitShow.AddRange(new string[]
{
"errorCode",
"winMode",
"checkBox1",
"autoBox",
"dumpBox",
"advNTButton",
"eCodeEditButton"
});
SetControlEnabled(fp, "addInfFile", true);
break;
case "Windows 2000":
ExplicitShow.AddRange(new string[]
{
"errorCode",
"winMode",
"eCodeEditButton",
"advNTButton"
});
SetControlChecked(fp, "checkBox1", true);
break;
case "Windows 9x/Me":
ExplicitShow.AddRange(new string[]
{
"nineXmessage",
"winMode",
"eCodeEditButton",
"panel2"
});
break;
case "Windows CE":
ExplicitShow.AddRange(new string[]
{
"winMode",
"errorCode"
});
SetControlChecked(fp, "checkBox2", false);
SetControlEnabled(fp, "checkBox2", false);
SetControlEnabled(fp, "textBox2", false);
break;
case "Windows NT 3.x/4.0":
ExplicitShow.AddRange(new string[]
{
"errorCode",
"stackBox",
"ntPanel",
"winMode",
"advNTButton",
"eCodeEditButton",
"troubleshootBox"
});
SetControlVisible(fp, "amdBox", !me.GetBool("threepointone"));
SetControlVisible(fp, "displayOsBox", me.GetBool("threepointone"));
break;
case "Windows 3.1x":
SetControlVisible(fp, "winMode", true);
break;
case "Windows 1.x/2.x":
ExplicitShow.AddRange(new string[]
{
"winMode",
"winPanel",
"playSndBox",
"halfBox",
});
SetControlEnabled(fp, "winPanel", !me.GetBool("halfres"));
break;
case "BOOTMGR":
SetControlVisible(fp, "winMode", true);
break;
}
foreach (string s in ExplicitShow)
{
SetControlVisible(fp, s, true);
}
/*bool inlist = false;
foreach (string item in ((ComboBox)FindControl(fp.Controls["errorCode"], "comboBox1")).Items)
{
if (item == me.GetString("code"))
{
inlist = true;
}
}*/
if (fp.Controls["nineXmessage"].Visible)
{
((ComboBox)FindControl(fp, "comboBox2")).Items.Clear();
foreach (string text in me.GetTexts().Keys)
{
if (text != "Prompt")
{
((ComboBox)FindControl(fp, "comboBox2")).Items.Add(text);
}
}
}
//codeCustomizationToolStripMenuItem.Enabled = eCodeEditButton.Visible;
//advancedNTOptionsToolStripMenuItem.Enabled = advNTButton.Visible;
// load options for current bluescreen
string nx_code;
try
{
nx_code = me.GetCodes()[0].Substring(0, 2);
}
catch
{
nx_code = "00";
}
((ComboBox)FindControl(fp, "nineXErrorCode")).SelectedIndex = -1;
for (int i = 0; i < Program.templates.NxErrors.Length; i++)
{
string selc = Program.templates.NxErrors[i].Split('\t')[0];
if (nx_code == selc)
{
((ComboBox)FindControl(fp, "nineXErrorCode")).SelectedIndex = i;
}
}
Program.gs.Log("Info", "Loading settings for configuration template", me.GetString("friendlyname"));
SetControlChecked(fp, "autoBox", me.GetBool("autoclose"));
SetControlChecked(fp, "serverBox", me.GetBool("server"));
SetControlChecked(fp, "greenBox", me.GetBool("insider"));
SetControlChecked(fp, "qrBox", me.GetBool("qr"));
SetControlChecked(fp, "checkBox1", me.GetBool("show_description"));
SetControlChecked(fp, "checkBox2", me.GetBool("show_file"));
SetControlChecked(fp, "amdBox", me.GetBool("amd"));
SetControlChecked(fp, "stackBox", me.GetBool("stack_trace"));
SetControlChecked(fp, "blinkBox", me.GetBool("blink"));
SetControlChecked(fp, "acpiBox", me.GetBool("acpi"));
SetControlChecked(fp, "playSndBox", me.GetBool("playsound"));
SetControlChecked(fp, "waterBox", me.GetBool("watermark"));
SetControlChecked(fp, "winMode", me.GetBool("windowed"));
SetControlChecked(fp, "countdownBox", me.GetBool("countdown"));
SetControlChecked(fp, "displayOsBox", me.GetBool("bootscreen"));
SetControlChecked(fp, "halfBox", me.GetBool("halfres"));
SetControlChecked(fp, "rainbowBox", me.GetBool("rainbow"));
SetControlChecked(fp, "memoryBox", me.GetBool("extracodes"));
SetControlChecked(fp, "troubleshootBox", me.GetBool("troubleshoot"));
SetControlChecked(fp, "crashDumpBox", me.GetBool("crashdump"));
SetControlVisible(fp, "advNTButton", me.GetFiles().Count > 0);
FindControl(fp, "textBox2").Text = me.GetString("culprit");
((ComboBox)FindControl(fp, "comboBox1")).SelectedItem = me.GetString("code");
((ComboBox)FindControl(fp, "comboBox2")).SelectedItem = me.GetString("screen_mode");
if (((CheckBox)FindControl(fp, "acpiBox")).Checked)
{
SetControlEnabled(fp, "dumpBox", false);
}
SetControlChecked(fp, "win1startup", false);
SetControlChecked(fp, "win2startup", false);
SetControlChecked(fp, "nostartup", false);
switch (me.GetString("qr_file"))
{
case "local:0":
SetControlChecked(fp, "win1startup", true);
break;
case "local:1":
SetControlChecked(fp, "win2startup", true);
break;
case "local:null":
SetControlChecked(fp, "nostartup", true);
break;
}
}
/// <summary>
/// Get the current OS and automatically select a template based on it
/// </summary>
/// <param name="f">Name of the form to set the selection for</param>
public static void GetOS(Form f)
{
Control fp = f;
ComboBox wv = ((ComboBox)FindControl(fp, "windowVersion"));
wv.Items.Clear();
for (int i = Program.templates.Count - 1; i >= 0; i--)
{
wv.Items.Add(Program.templates.GetAt(i).GetString("friendlyname"));
}
SetControlVisible(fp, "WXOptions", false);
SetControlVisible(fp, "errorCode", false);
SetControlVisible(fp, "nineXmessage", false);
SetControlVisible(fp, "serverBox", false);
SetControlVisible(fp, "greenBox", false);
SetControlVisible(fp, "qrBox", false);
SetControlVisible(fp, "checkBox1", false);
SetControlVisible(fp, "winMode", false);
SetControlVisible(fp, "acpiBox", false);
SetControlVisible(fp, "amdBox", false);
SetControlVisible(fp, "stackBox", false);
SetControlVisible(fp, "ntPanel", false);
SetControlEnabled(fp, "checkBox2", true);
if (wv.Items.Count > 0) { wv.SelectedIndex = 0; }
string winver = "";
int os_build = 0;
/*if (specificos != "")
{
winver = specificos;
specificos = "";
}*/
try
{
winver = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
os_build = Convert.ToInt32(Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild", "0").ToString());
}
catch
{
if (os_build == 0)
{
Program.gs.Log("Error", "CurrentBuild missing, Windows registry may be corrupted...");
}
if (winver == "")
{
Program.gs.Log("Error", "ProductName missing, Windows registry may be corrupted...");
}
}
//this code identifies Windows 11
if (os_build >= 26200)
{
SetOS("Windows 11", f);
} else if (os_build >= 22000)
{
SetOS("Legacy Windows 11", f);
}
//this code identifies Windows 10
else if (winver.Contains("Windows 10"))
{
SetOS("Windows 10", f);
}
//this code identifies Windows 8 or Windows 8.1
else if (winver.Contains("Windows 8"))
{
SetOS("Windows 8", f);
}
//this code identifies Windows 7
else if (winver.Contains("Windows 7"))
{
SetOS("Windows 7", f);
}
//this code identifies Windows Vista
else if (winver.Contains("Windows Vista"))
{
SetOS("Windows Vista", f);
}
//this code identifies Windows XP
else if (winver.Contains("Windows XP"))
{
SetOS("Windows XP", f);
}
//this code identifies Windows 2000
else if ((winver.Contains("Windows 2000")) || (winver.Contains("Windows NT 5")))
{
SetOS("Windows 2000", f);
}
//this code identifies Windows 95 or Windows 98
else if ((winver.Contains("Windows 95")) || (winver.Contains("Windows 98")))
{
SetOS("Windows 9x", f);
}
//this code identifies old Windows NT versions
else if ((winver.Contains("Windows NT 4")) || (winver.Contains("Windows NT 3")))
{
SetOS("Windows NT", f);
}
}
/// <summary>
/// Sets OS selection based on the host version
/// </summary>
/// <param name="winver">Your Windows version (e.g. Windows Vista)</param>
/// <param name="f">Name of the form to set the selection for</param>
private static void SetOS(string winver, Form f)
{
Control fp = f;
ComboBox wv = ((ComboBox)FindControl(fp, "windowVersion"));
for (int i = 0; i < wv.Items.Count; i++)
{
if (wv.Items[i].ToString().Contains(winver))
{
wv.SelectedIndex = i;
break;
}
}
}
/// <summary>
/// Perform neccessary steps for initializing a form
/// </summary>
/// <param name="f">Name of the form to initialize</param>
public static void InitializeForm(Form f)
{
if (Program.gs.ErrorCode != 0)
{
ProcessErrors(f);
}
f.Text = $"Blue Screen Simulator Plus {Version}";
if (Program.gs.DevBuild)
{
f.Text += " // UNDER CONSTRUCTION //";
}
((ComboBox)FindControl(f, "windowVersion")).Items.Clear();
for (int i = Program.templates.Count - 1; i >= 0; i--)
{
((ComboBox)FindControl(f, "windowVersion")).Items.Add(Program.templates.GetAt(i).GetString("friendlyname"));
}
//SetControlVisible(fp, "WXOptions", false);
SetControlVisible(f, "errorCode", false);
SetControlVisible(f, "nineXmessage", false);
SetControlVisible(f, "serverBox", false);
SetControlVisible(f, "greenBox", false);
SetControlVisible(f, "qrBox", false);
SetControlVisible(f, "checkBox1", false);
SetControlVisible(f, "winMode", false);
SetControlVisible(f, "acpiBox", false);
SetControlVisible(f, "amdBox", false);
SetControlVisible(f, "stackBox", false);
SetControlVisible(f, "ntPanel", false);
SetControlEnabled(f, "checkBox2", true);
if (((ComboBox)FindControl(f, "windowVersion")).Items.Count > 0) { ((ComboBox)FindControl(f, "windowVersion")).SelectedIndex = 0; }
string winver;
int os_build;
try
{
winver = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductName", "").ToString();
os_build = Convert.ToInt32(Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "CurrentBuild", "0").ToString());
}
catch
{
}
if (Program.gs.DisplayOne)
{
((ComboBox)FindControl(f, "windowVersion")).Items.Clear();
for (int i = Program.templates.Count - 1; i >= 0; i--)
{
((ComboBox)FindControl(f, "windowVersion")).Items.Add(Program.templates.GetAt(i).GetString("friendlyname"));
}
((ComboBox)FindControl(f, "windowVersion")).SelectedItem = me.GetString("friendlyname");
if (f is Main)
{
SetControlVisible(f, "windowVersion", false);
FindControl(f, "label1").Text = "Selected preset: " + ((ComboBox)FindControl(f, "windowVersion")).SelectedItem.ToString();
FindControl(f, "linkLabel1").Location = new Point(FindControl(f, "label1").Location.X + FindControl(f, "label1").Width, FindControl(f, "linkLabel1").Location.Y);
FindControl(f, "linkLabel1").Visible = true;
}
}
else
{
GetOS(f);
}
if (Program.gs.PM_CloseMainUI)
{
f.WindowState = FormWindowState.Minimized;
f.Hide();
return;
}
}
/// <summary>
/// Display an error message to the user if something goes wrong
/// </summary>
/// <param name="f">Name of the form, which to display the message for</param>
private static void ProcessErrors(Form f)
{
Program.clip.ExitSplash();
switch (Program.gs.ErrorCode)
{
case 0:
break;
case 1:
MessageBox.Show("No command specified in hidden mode\nAre you missing the /c argument?\n\n0x001: COMMAND_DEADLOCK", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Program.halt = true;
Application.Exit();
break;
case 2:
MessageBox.Show("Specified file is either corrupted or not a valid blue screen simulator plus hack file.\n\n0x002: HEADER_MISSING", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 3:
MessageBox.Show("Specified file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x003: INCOMPATIBLE_HACK", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 4:
MessageBox.Show("Specified file is either corrupt or does not exist.\n\n0x004: FILE_MISSING", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 5:
MessageBox.Show("Specified file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x005: MISSING_ATTRIBUTES", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 6:
MessageBox.Show("Specified file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x006: FACE_TOO_LONG", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 7:
MessageBox.Show("Specified file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x007: FACE_TOO_SHORT", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 8:
MessageBox.Show("Specified file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x008: RGB_OUT_OF_RANGE", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 9:
MessageBox.Show("Specified file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x009: RGB_VALUE_NEGATIVE", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 10:
MessageBox.Show("A supported Windows version could not be identified.\n\n0x00A: PRODUCT_NAME_NOT_LISTED", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 11:
MessageBox.Show("Windows version could not be identified.\nAre you using a compatibility layer?\n\n0x00B: PRODUCT_NAME_MISSING", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 12:
MessageBox.Show("Cannot find the Windows version specified\n\n0x00C: WINVER_NOT_FOUND", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 13:
MessageBox.Show("Cannot find the error code specified\n\n0x00D: NTCODE_NOT_FOUND", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 14:
MessageBox.Show("Cannot find the error code specified\n\n0x00D: 9XCODE_NOT_FOUND", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 15:
MessageBox.Show("The syntax of the command is incorrect\n\n0x00E: BAD_SYNTAX", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 16:
MessageBox.Show("The syntax of the command is incorrect\n\n0x00F: BAD_SYNTAX", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 17:
MessageBox.Show("The syntax of the command is incorrect\n\n0x010: BAD_SYNTAX", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 18:
MessageBox.Show("The syntax of the command is incorrect\n\n0x011: BAD_SYNTAX", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 19:
MessageBox.Show("Internal database could not be loaded\n\n0x012: NT_DATABASE_MISSING", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 20:
MessageBox.Show("Internal database seems to be corrupted\n\n0x013: NT_DATABASE_CORRUPTED", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 23:
MessageBox.Show("The syntax of the command is incorrect\n\n0x016: COMMAND_ARGUMENT_INVALID", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 24:
MessageBox.Show("Specified hack file does not exist\n\n0x014: HACK_FILE_NON_EXISTENT", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
case 25:
MessageBox.Show("Specified hack file is either corrupted or incompatible with this version of blue screen simulator plus.\n\n0x015: HACK_FILE_INCOMPATIBLE", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
default:
Application.Exit();
f.Close();
break;
}
}
/// <summary>
/// Start simulation
/// </summary>
/// <param name="f">Name of the form which triggered the crash</param>
public static void ShowBlueScreen(Form f)
{
if (((ComboBox)FindControl(f, "windowVersion")).Items.Count < 1)
{
Program.loadfinished = true;
if (Program.gs.EnableEggs && (Program.gs.ErrorCode != 500))
{
MessageBox.Show("Please select a Windows version! Also, how in the world did you deselect a dropdown list?", "Error displaying crash screen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (Program.gs.ErrorCode == 500)
{
Thread.CurrentThread.Abort();
return;
}
else
{
MessageBox.Show("No configuration selected", "Error displaying crash screen", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return;
}
me.Show();
Thread.CurrentThread.Abort();
}
/// <summary>
/// Start simulation without checks
/// </summary>
/// <param name="f">Name of the form that triggered the crash</param>
public static void Crash(Form f)
{
ts = new ThreadStart(() => { ShowBlueScreen(f); });
bsod_starter = new Thread(ts);
bsod_starter.Start();
}
/// <summary>
/// Generate a random bugcheck based on a seed
/// </summary>
/// <param name="f">Name of the form, where the seed is entered</param>
/// <param name="shiftDown">Is the user holding down the SHIFT key? If they are, force the generator to use the selected OS</param>
/// <returns>Generated bugcheck</returns>
public static BlueScreen RandFunction(Form f, bool shiftDown)
{
Control tb1;
if (f is MaterialForm)
{
tb1 = FindControl(f, "textBox1") as MaterialTextBox2;
} else
{
tb1 = FindControl(f, "textBox1") as TextBox;
}
CheckBox winMode = (CheckBox)FindControl(f, "winMode");
CheckBox waterBox = (CheckBox)FindControl(f, "waterBox");
ComboBox comboBox1 = (ComboBox)FindControl(f, "comboBox1");
ComboBox comboBox2 = (ComboBox)FindControl(f, "comboBox2");
if (me == null) { me = new BlueScreen(); }
ulong seed = (ulong)DateTime.Now.Ticks;
bool isNumeric = ulong.TryParse(tb1.Text, out _);
if (tb1.Text != "")
{
if (!isNumeric)
{
seed = BinaryPrimitives.ReadUInt64BigEndian(GetHash(tb1.Text));
}
else
{
seed = ulong.Parse(tb1.Text);
}
}
Random r = new Random((int)seed);
string base_os = Program.templates.GetAt(r.Next(Program.templates.Count - 1)).GetString("os");
if (shiftDown)
{
base_os = me.GetString("os");
}
BlueScreen bs = new BlueScreen(base_os, true, r);
foreach (string kvp in bs.AllBools().Keys.ToArray<string>())
{
bool value = r.Next(0, 100) > 50;
bs.SetBool(kvp, value);
}
foreach (string kvp in bs.AllInts().Keys.ToArray<string>())
{
if (!kvp.Contains("margin"))
{
int value = r.Next(0, 1000);
bs.SetInt(kvp, value);
}
}
if (r.Next(0, 100) > 75)
{
Color[] c1 = RandInvColor(r);
Color[] c2 = RandInvColor(r);
bs.SetTheme(c1[0], c1[1], false);
bs.SetTheme(c2[0], c2[1], true);
}
if (r.Next(0, 100) > 95)
{
bs.SetString("emoticon", ":)");
}
if (comboBox1.Items.Count == 0) { Program.ReloadNTErrors(); }
bs.SetString("code", comboBox1.Items[r.Next(0, comboBox1.Items.Count - 1)].ToString());
if (bs.GetString("os") != "Windows 3.1x")
{
bs.SetString("screen_mode", comboBox2.Items[r.Next(0, comboBox2.Items.Count - 1)].ToString());
}
bs.SetBool("troubleshoot", r.Next(0, 100) > 50);
bs.SetBool("rainbow", r.Next(0, 100) > 50);
bs.SetBool("windowed", winMode.Checked);
bs.SetBool("amd", winMode.Checked);
bs.SetBool("blink", winMode.Checked);
bs.SetBool("watermark", waterBox.Checked);
bs.SetString("culprit", me.GenFile());
if (isNumeric && (tb1.Text != ""))
{
bs.SetString("friendlyname", "Random template #" + seed.ToString());
}
else if (tb1.Text == "")
{
bs.SetString("friendlyname", "Random template #" + seed.ToString() + " (from clock time)");
}
else
{
bs.SetString("friendlyname", "Random template #" + seed.ToString() + " (seed: " + tb1.Text + ")");
}
Thread th = new Thread(new ThreadStart(() => {
bs.Show();
}));
th.Start();
th.Join();
return bs;