-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSimulatorDatabase.cs
More file actions
2187 lines (2051 loc) · 100 KB
/
SimulatorDatabase.cs
File metadata and controls
2187 lines (2051 loc) · 100 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.Collections.Generic;
using System.Windows.Forms;
using UltimateBlueScreenSimulator;
using System.Drawing;
using System.Management;
using System.Threading;
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Linq;
using System.Drawing.Drawing2D;
using System.Diagnostics;
using System.IO;
using UltimateBlueScreenSimulator.Forms.Simulators;
//
// This namespace contains classes that are shared between forms that specify
// using SimulatorDatabase;
// at the top
//
namespace SimulatorDatabase
{
public enum Icons
{
Flag2D,
Flag3D,
Window3D,
Window2D
}
public class DrawRoutines
{
private bool BlinkState { get; set; }
private bool ForceWatermark { get; set; }
public readonly List<WindowScreen> wss = new List<WindowScreen>();
private readonly List<Bitmap> freezescreens = new List<Bitmap>();
public DrawRoutines()
{
this.BlinkState = false;
this.ForceWatermark = false;
}
/// <summary>
/// Called when upscaling crash screens to fullscreen or when mirroring them to secondary displays
/// </summary>
/// <param name="ws">WindowScreen form</param>
/// <param name="watermark">Adds a watermark overlay on top of the processed image</param>
public void Draw(WindowScreen ws, bool watermark)
{
ForceWatermark = watermark;
Draw(ws);
}
/// <summary>
/// Called when upscaling crash screens to fullscreen or when mirroring them to secondary displays
/// </summary>
/// <param name="ws">WindowScreen form</param>
/// <param name="blinkcolor">If passed, a blinking caret will be displayed at the top left</param>
public void Draw(WindowScreen ws, Color? blinkcolor = null)
{
// for upscaling and multidisplay support
if (ws.primary || Program.gs.DisplayMode == "mirror")
{
Form frm = Program.verificate ? Form.ActiveForm : null;
if (frm is null)
{
return;
}
using (Bitmap bmp = new Bitmap(frm.Width, frm.Height))
{
frm.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
if (blinkcolor != null)
{
if (this.BlinkState)
{
using (Graphics b = Graphics.FromImage(bmp))
{
b.FillRectangle(new SolidBrush(blinkcolor ?? Color.White), new Rectangle(0, 6, 8, 2));
}
}
this.BlinkState = !this.BlinkState;
}
if (ForceWatermark)
{
using (Graphics b = Graphics.FromImage(bmp))
{
b.DrawString("blue screen simulator plus", new Font("Segoe UI", ws.Width / 100, FontStyle.Regular), new SolidBrush(Color.FromArgb(128, Color.Blue)), new Point(2, 0));
}
}
Bitmap newImage = new Bitmap(ws.Width, ws.Height);
using (Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode = Program.gs.GetInterpolationMode();
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.DrawImage(bmp, new Rectangle(0, 0, ws.Width, ws.Height));
}
// dispose old images from memory to avoid memory leaks and potentially
// actual crashes
ws.screenDisplay.Image?.Dispose();
ws.screenDisplay.Image = newImage;
bmp.Dispose();
}
}
}
/// <summary>
/// Called when displaying a preview of a bugcheck
/// </summary>
/// <param name="ws">WindowScreen form</param>
public void DrawSpecial(WindowScreen ws, Form special)
{
// for upscaling and multidisplay support
Form frm = special;
using (Bitmap bmp = new Bitmap(frm.Width, frm.Height))
{
frm.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
if (ForceWatermark)
{
using (Graphics b = Graphics.FromImage(bmp))
{
b.DrawString("blue screen simulator plus", new Font("Segoe UI", ws.Width / 100, FontStyle.Regular), new SolidBrush(Color.FromArgb(128, Color.Blue)), new Point(2, 0));
}
}
Bitmap newImage = new Bitmap(ws.Width, ws.Height);
using (Graphics g = Graphics.FromImage(newImage))
{
g.InterpolationMode = Program.gs.GetInterpolationMode();
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.DrawImage(bmp, new Rectangle(0, 0, ws.Width, ws.Height));
}
// dispose old images from memory to avoid memory leaks and potentially
// actual crashes
ws.screenDisplay.Image?.Dispose();
ws.screenDisplay.Image = newImage;
bmp.Dispose();
}
}
/// <summary>
/// Takes a screenshot of a form
/// </summary>
/// <param name="meself">The form you want to screenshot</param>
/// <returns>Filename of the saved screenshot</returns>
public string Screenshot(Form meself)
{
meself.FormBorderStyle = FormBorderStyle.None;
WindowScreen wsw = new WindowScreen
{
Width = meself.Width,
Height = meself.Height
};
Draw(wsw);
wsw.Text = "Scaled window";
wsw.FormBorderStyle = FormBorderStyle.Sizable;
wsw.WindowState = FormWindowState.Normal;
wsw.Show();
meself.FormBorderStyle = FormBorderStyle.FixedSingle;
Image img = wsw.screenDisplay.Image;
string filename = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\bssp_" + string.Join("_", meself.Text.Split(Path.GetInvalidFileNameChars())) + ".png";
using (Bitmap tempImage = new Bitmap(img))
{
tempImage.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
tempImage.Dispose();
}
img.Dispose();
wsw.Close();
return filename;
}
/// <summary>
/// Closes upscaled displays and disposes them
/// </summary>
public void Dispose()
{
if ((UIActions.specialwindow != null) && (UIActions.specialwindow.Opacity == 0.0))
{
return;
}
if (Program.halt)
{
return;
}
foreach (WindowScreen ws in wss)
{
ws.Close();
ws.Dispose();
}
foreach (Bitmap bmp in freezescreens)
{
bmp.Dispose();
}
wss.Clear();
freezescreens.Clear();
ForceWatermark = false;
}
/// <summary>
/// Draws the image for all displays
/// </summary>
public void DrawAll()
{
foreach (WindowScreen ws in wss)
{
try
{
Program.dr.Draw(ws);
}
catch when (!Debugger.IsAttached)
{
ws.Close();
}
}
}
/// <summary>
/// Sets a rainbow gradient as the background image
/// </summary>
/// <param name="form">Form to set the background image to</param>
public void DrawRainbow(Form form)
{
LinearGradientBrush br = new LinearGradientBrush(form.ClientRectangle, Color.Black, Color.Black, 0, false);
ColorBlend cb = new ColorBlend
{
Positions = new[] { 0, 1 / 7f, 2 / 7f, 3 / 7f, 4 / 7f, 5 / 7f, 6 / 7f, 1 },
Colors = new[] { Color.Violet, Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet }
};
br.InterpolationColors = cb;
// rotate
br.RotateTransform(45);
// paint
Bitmap bmp = new Bitmap(form.Width, form.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.FillRectangle(new SolidBrush(Color.Black), form.ClientRectangle);
g.FillRectangle(br, form.ClientRectangle);
}
form.BackgroundImage = bmp;
}
public void InitSpecial(Form frm)
{
if (frm is null)
{
throw new ArgumentNullException(nameof(frm));
}
WindowScreen ws = new WindowScreen();
if (Program.gs.DisplayMode != "none")
{
ws.StartPosition = FormStartPosition.CenterScreen;
ws.Width = 640;
ws.Height = 480;
ws.primary = false;
}
wss.Add(ws);
}
/// <summary>
/// Initialize scaled display for fullscreen mode
/// </summary>
/// <param name="frm">Form to upscale</param>
/// <param name="native">Specifies whether or not the primary display should be upscaled, if true then it's not upscaled</param>
public void Init(Form frm, bool native = false)
{
if ((Program.gs.DisplayMode == "none") && native)
{
return;
}
if (Screen.AllScreens.Length > 1)
{
foreach (Screen s in Screen.AllScreens)
{
WindowScreen ws = new WindowScreen();
if (!s.Primary)
{
if (Program.gs.DisplayMode != "none")
{
ws.StartPosition = FormStartPosition.Manual;
ws.Location = s.WorkingArea.Location;
ws.Size = new Size(s.WorkingArea.Width, s.WorkingArea.Height);
ws.primary = false;
if (Program.gs.DisplayMode == "freeze")
{
Bitmap screenshot = new Bitmap(s.Bounds.Width,
s.Bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(screenshot);
gfxScreenshot.CopyFromScreen(
s.Bounds.X,
s.Bounds.Y,
0,
0,
s.Bounds.Size,
CopyPixelOperation.SourceCopy
);
freezescreens.Add(screenshot);
}
}
}
wss.Add(ws);
}
}
else
{
if (!native)
{
wss.Add(new WindowScreen());
}
}
for (int i = 0; i < wss.Count; i++)
{
WindowScreen ws = wss[i];
ws.Show();
if (!ws.primary)
{
if (Program.gs.DisplayMode == "freeze")
{
ws.screenDisplay.Image = freezescreens[i - 1];
}
}
}
// do not draw the main display if native resolution is used
if (!native)
{
foreach (WindowScreen ws in wss)
{
Program.dr.Draw(ws);
}
frm.TopMost = false;
for (int i = 0; i < wss.Count; i++)
{
WindowScreen ws = wss[i];
ws.Show();
if (!ws.primary)
{
if (Program.gs.DisplayMode == "freeze")
{
ws.screenDisplay.Image = freezescreens[i - 1];
}
}
}
frm.Hide();
}
}
}
internal struct USBDeviceInfo
{
public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
{
this.DeviceID = deviceID;
this.PnpDeviceID = pnpDeviceID;
this.Description = description;
}
public string DeviceID { get; private set; }
public string PnpDeviceID { get; private set; }
public string Description { get; private set; }
public static List<USBDeviceInfo> GetUSBDevices()
{
List<USBDeviceInfo> devices = new List<USBDeviceInfo>();
ManagementObjectCollection collection;
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
{
collection = searcher.Get();
}
foreach (ManagementBaseObject device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
(string)device.GetPropertyValue("Description")
));
}
collection.Dispose();
return devices;
}
}
//
// Blue screen template class
//
[JsonUnmappedMemberHandling(JsonUnmappedMemberHandling.Disallow)]
public class BlueScreen
{
/* this stuff is required to serialize various parts of the class correctly */
public IDictionary<string, int> Background {
get { return I_color_builder(background); }
set { background = I_decode_color(value); }
}
public IDictionary<string, int> Foreground {
get { return I_color_builder(foreground); }
set { foreground = I_decode_color(value); }
}
public IDictionary<string, int> Highlight_BG {
get { return I_color_builder(highlight_bg); }
set { highlight_bg = I_decode_color(value); }
}
public IDictionary<string, int> Highlight_FG {
get { return I_color_builder(highlight_fg); }
set { highlight_fg = I_decode_color(value); }
}
public IDictionary<string, dynamic> Font {
get {
return new Dictionary<string, dynamic>() {
{ "FontFamily", font.FontFamily.Name },
{ "Bold", font.Bold },
{ "Italic", font.Italic },
{ "Strikeout", font.Strikeout },
{ "Underline", font.Underline },
{ "Size", font.Size },
};
}
set {
font = new Font(new FontFamily(((JsonElement)value["FontFamily"]).ToString()), ((JsonElement)value["Size"]).Deserialize<float>(), FontStyle.Regular);
if (((JsonElement)value["Bold"]).Deserialize<bool>())
{
font = new Font(font, font.Style ^ FontStyle.Bold);
}
if (((JsonElement)value["Italic"]).Deserialize<bool>())
{
font = new Font(font, font.Style ^ FontStyle.Italic);
}
if (((JsonElement)value["Underline"]).Deserialize<bool>())
{
font = new Font(font, font.Style ^ FontStyle.Underline);
}
if (((JsonElement)value["Strikeout"]).Deserialize<bool>())
{
font = new Font(font, font.Style ^ FontStyle.Strikeout);
}
}
}
private IDictionary<string, int> I_color_builder(Color color)
{
return new Dictionary<string, int>()
{
{"R", color.R },
{"G", color.G },
{"B", color.B },
};
}
private Color I_decode_color(IDictionary<string, int> data)
{
return Color.FromArgb(
data["R"],
data["G"],
data["B"]
);
}
private Color background { get; set; }
private Color foreground { get; set; }
private Color highlight_bg { get; set; }
private Color highlight_fg { get; set; }
private Font font { get; set; }
public string[] ecodes { get; set; }
public string os { get; set; }
// possible values:
// 2D flag
// 3D flag
// 2D window
// 3D window
public string icon { get; set; }
public IDictionary<string, string> titles { get; set; }
public IDictionary<string, string> texts { get; set; }
public List<KeyValuePair<string, string[]>> codefiles { get; set; }
public IDictionary<string, bool> bools { get; set; }
public IDictionary<string, int> ints { get; set; }
public IDictionary<string, string> strings { get; set; }
public IDictionary<int, int> progression { get; set; }
[JsonIgnore]
private bool special = false;
[JsonIgnore]
public static Random r = new Random();
// constructor
///<summary>
///Blue screen template class. Requires base_os to be set to one of the preset OS templates. If desired, autosetup can be disabled, which makes it so that the template will not set default settings.
///</summary>
public BlueScreen(string base_os, bool autosetup = true, Random r = null)
{
if (r == null)
{
r = new Random();
}
BlueScreen.r = r;
this.background = Color.FromArgb(0, 0, 0);
this.foreground = Color.FromArgb(255, 255, 255);
this.os = base_os;
string[] codes_temp = { "RRRRRRRRRRRRRRRR", "RRRRRRRRRRRRRRRR", "RRRRRRRRRRRRRRRR", "RRRRRRRRRRRRRRRR" };
this.ecodes = codes_temp;
this.highlight_bg = Color.FromArgb(255, 255, 255);
this.highlight_fg = Color.FromArgb(0, 0, 0);
this.icon = "2D flag";
this.titles = new Dictionary<string, string>();
this.texts = new Dictionary<string, string>();
this.codefiles = new List<KeyValuePair<string, string[]>>();
this.bools = new Dictionary<string, bool>();
this.ints = new Dictionary<string, int>();
this.strings = new Dictionary<string, string>();
this.progression = new Dictionary<int, int>();
this.font = new Font("Lucida Console", 10.4f, FontStyle.Regular);
if (autosetup && Program.verificate) { SetOSSpecificDefaults(); }
}
[JsonConstructor]
public BlueScreen()
{
r = new Random();
this.background = new Color();
this.foreground = new Color();
this.highlight_bg = new Color();
this.highlight_fg = new Color();
this.titles = new Dictionary<string, string>();
this.texts = new Dictionary<string, string>();
this.codefiles = new List<KeyValuePair<string, string[]>>();
this.bools = new Dictionary<string, bool>();
this.ints = new Dictionary<string, int>();
this.strings = new Dictionary<string, string>();
this.progression = new Dictionary<int, int>();
}
///<summary>
///Returns boolean dictionary
///</summary>
public IDictionary<string, bool> AllBools() { return this.bools; }
///<summary>
///Returns integers dictionary
///</summary>
public IDictionary<string, int> AllInts() { return this.ints; }
///<summary>
///Returns dictionary of strings
///</summary>
public IDictionary<string, string> AllStrings() { return this.strings; }
///<summary>
///Returns dictionary of progress tuner preferences
///</summary>
public IDictionary<int, int> AllProgress() { return this.progression; }
///<summary>
///Logs an event
///</summary>
///<param name="e">Desired event type</param>
///<param name="message">Description of the event</param>
public void Log(string e, string message)
{
Program.gs.Log(e, message, this.strings.Keys.Contains("friendlyname") ? this.strings["friendlyname"] : "");
}
// blue screen properties
///<summary>
///Gets a single boolean value. If no matching value is found, a default value of false will be returned.
///</summary>
///<param name="name">Key in the dictionary</param>
public bool GetBool(string name)
{
Log("Info", $"Reading bool {name}");
if (this.bools.ContainsKey(name))
{
return this.bools[name];
}
else
{
Log("Warning", "No data, returning false");
return false;
}
}
///<summary>
///Sets a single boolean value. If no existing value with the name specified is found, a new entry in the dictionary will be created.
///</summary>
///<param name="name">Dictionary key or variable name</param>
///<param name="value">The value which you set the boolean to</param>
public void SetBool(string name, bool value)
{
Log("Info", $"Setting bool {name} to {value}");
if (this.bools.ContainsKey(name))
{
this.bools[name] = value;
}
else
{
this.bools.Add(name, value);
}
}
///<summary>
///Gets a single string value. If no matching value is found, a default value of "" will be returned.
///</summary>
///<returns>A string from the specified dictionary key with certain exceptions (os and icon return the corresponding variables, ecode1, ecode2, ecode3, ecode4 return value from ecodes array of specified index.</returns>
///<param name="name">Key in the dictionary (except for special cases)</param>
public string GetString(string name)
{
Log("Info", $"Getting string {name}");
switch (name)
{
case "os": return this.os;
case "icon": return this.icon;
case "ecode1": return this.ecodes[0];
case "ecode2": return this.ecodes[1];
case "ecode3": return this.ecodes[2];
case "ecode4": return this.ecodes[3];
default:
if (this.strings.ContainsKey(name))
{
return strings[name];
}
else if (this.titles.ContainsKey(name))
{
return titles[name];
}
else if (this.texts.ContainsKey(name))
{
return texts[name];
}
else
{
Log("Warning", "No data, returning empty string");
return "";
}
}
}
///<summary>
///Sets a single string value. If no existing value with the name specified is found, a new entry in the dictionary will be created.
///<para><strong>Special case for "os" and "icon"</strong></para><para>These strings modify the corresponding variables directly instead of modifying dictionary entries</para>
///</summary>
///<param name="name">Dictionary key or variable name (see special case for "os" and "icon")</param>
///<param name="value">The value which you set the string to</param>
public void SetString(string name, string value)
{
Log("Info", $"Setting string {name} to {value}");
switch (name)
{
case "icon": this.icon = value; break;
case "os": this.os = value; break;
default:
if (this.strings.ContainsKey(name))
{
this.strings[name] = value;
}
else
{
this.strings.Add(name, value);
}
break;
}
}
///<summary>
///Erases all texts and titles, which the user can access in additional options
///</summary>
public void ClearAllTitleTexts()
{
Log("Info", $"Clearing all titles and texts");
this.titles.Clear();
this.texts.Clear();
}
///<summary>
///Erases all timing data for progress tuner
///</summary>
public void ClearProgress()
{
Log("Info", $"Clearing progress tuning data");
this.progression.Clear();
}
///<summary>
///Modifies a value in the titles dictionary, which is like strings, but which can be accessed by the user under additional options (difference between titles and texts is semantic)
///</summary>
///<param name="name">Dictionary key or variable name</param>
///<param name="value">The value which you set the string to</param>
public void SetTitle(string name, string value)
{
Log("Info", $"Setting title {name} to {value}");
this.titles[name] = value;
}
///<summary>
///Adds a value to the titles dictionary, which is like strings, but which can be accessed by the user under additional options (difference between titles and texts is semantic)
///</summary>
///<param name="name">Dictionary key or variable name</param>
///<param name="value">The value which you set the string to</param>
public void PushTitle(string name, string value)
{
Log("Info", $"Pushing title {name} with value {value}");
this.titles.Add(name, value);
}
///<summary>
///Modifies a value in the texts dictionary, which is like strings, but which can be accessed by the user under additional options (difference between titles and texts is semantic)
///</summary>
///<param name="name">Dictionary key or variable name</param>
///<param name="value">The value which you set the string to</param>
public void SetText(string name, string value)
{
Log("Info", $"Setting text {name} to {value}");
this.texts[name] = value;
}
///<summary>
///Adds a value to the texts dictionary, which is like strings, but which can be accessed by the user under additional options (difference between titles and texts is semantic)
///</summary>
///<param name="name">Dictionary key or variable name</param>
///<param name="value">The value which you set the string to</param>
public void PushText(string name, string value)
{
Log("Info", $"Pushing text {name} with value {value}");
this.texts.Add(name, value);
}
// theming
///<summary>
///Allows you to access a specific color used by the configuration
///</summary>
///<param name="bg">Determines whether to get a background color or not</param>
///<param name="highlight">Determines whether or not to get a highlight color</param>
public Color GetTheme(bool bg, bool highlight = false)
{
Log("Info", $"Getting " + (highlight ? "highlight " : "") + (bg ? "background" : "foreground") + " color" );
if (highlight && Program.verificate)
{
if (bg) { return this.highlight_bg; } else { return this.highlight_fg; }
}
if (bg) { return this.background; } else { return this.foreground; }
}
///<summary>
///Allows you to set colors used by the configuration
///</summary>
///<param name="bg">Background color</param>
///<param name="fg">Foreground color</param>
///<param name="highlight">Determines if these colors are applied to highlights or normal text</param>
public void SetTheme(Color bg, Color fg, bool highlight = false)
{
Log("Info", $"Setting " + (highlight ? "highlight" : "base") + $" colors to ({bg.R}, {bg.G}, {bg.B}), ({fg.R}, {fg.G}, {fg.B})");
if (highlight && Program.verificate)
{
this.highlight_bg = bg;
this.highlight_fg = fg;
return;
}
this.background = bg;
this.foreground = fg;
}
// error codes
///<summary>
///Gets an array of error codes used by the configuration
///</summary>
public string[] GetCodes()
{
Log("Info", $"Getting error codes");
return this.ecodes;
}
///<summary>
///Allows you to set error codes used by the configuration
///</summary>
///<param name="code1">First block</param>
///<param name="code2">Second block</param>
///<param name="code3">Third block</param>
///<param name="code4">Fourth block</param>
public void SetCodes(string code1, string code2, string code3, string code4)
{
Log("Info", $"Setting error codes to {code1}, {code2}, {code3}, {code4}");
string[] code_temp = { code1, code2, code3, code4 };
this.ecodes = code_temp;
}
///<summary>
///Allows for converting r,g,b intensities to System.Drawing.Color
///</summary>
///<param name="r">Red intensity</param>
///<param name="g">Green intensity</param>
///<param name="b">Blue intensity</param>
private Color RGB(int r, int g, int b)
{
Log("Info", $"Getting color from values {r}, {g}, {b}");
return Color.FromArgb(r, g, b);
}
// integers
///<summary>
///Gets an integer value from the ints dictionary, which may be used to store settings like timeouts, blink speed, etc.
///</summary>
///<param name="name">Key of the dictionary</param>
public int GetInt(string name)
{
Log("Info", $"Getting integer value of {name}");
if (this.ints.ContainsKey(name) && Program.verificate)
{
return this.ints[name];
}
else
{
Log("Warning", "No data, returning 1");
return 1;
}
}
///<summary>
///Sets an integer value for the ints dictionary, which may be used to store settings like timeouts, blink speed, etc. If the key does not exist, a new key value pair will be pushed to the ints dictionary.
///</summary>
///<param name="name">Key of the dictionary</param>
///<param name="value">Integer value</param>
public void SetInt(string name, int value)
{
Log("Info", $"Getting integer value of {name} to {value}");
if (this.ints.ContainsKey(name))
{
this.ints[name] = value;
}
else
{
this.ints.Add(name, value);
}
}
///<summary>
///Sets the font, which is used by the selected configuration when displaying text.
///</summary>
///<param name="font_family">Family of the font, e.g. Arial, Segoe UI, Consolas, etc.</param>
///<param name="emsize">Size of the font in points (e.g. value of 12f is 12pt)</param>
///<param name="style">Special font style attributes, such as bold, italic, underline, strikethrough, etc.</param>
public void SetFont(string font_family, float emsize, FontStyle style)
{
Log("Info", $"Setting font as {font_family}, {emsize}pt");
this.font = new Font(font_family, emsize, style);
}
///<summary>
///Gets the font, which is used by the selected configuration when displaying text.
///</summary>
public Font GetFont()
{
Log("Info", $"Getting current font");
return this.font;
}
///<summary>
///Gets the icon, which is used by the selected configuration on the taskbar and window title bar.
///</summary>
public Icon GetIcon()
{
Log("Info", $"Getting icon");
switch (GetString("icon"))
{
case "3D flag":
return UltimateBlueScreenSimulator.Properties.Resources.Tatice_Operating_Systems_Windows;
case "3D window":
return UltimateBlueScreenSimulator.Properties.Resources.Dakirby309_Windows_8_Metro_Folders_OS_Windows_8_Metro;
case "2D window":
return UltimateBlueScreenSimulator.Properties.Resources.new_windows_logo__2_;
case "2D flag":
default:
return UltimateBlueScreenSimulator.Properties.Resources.artage_io_48148_1564916990;
}
}
///<summary>
///Returns all entries from the titles dictionary
///</summary>
public IDictionary<string, string> GetTitles()
{
Log("Info", $"Getting all titles");
return this.titles;
}
///<summary>
///Returns all entries from the texts dictionary
///</summary>
public IDictionary<string, string> GetTexts()
{
Log("Info", $"Getting all texts");
return this.texts;
}
// progress keyframes
///<summary>
///Gets progress tuner value at a specified time index
///</summary>
///<param name="name">Time index (roughly 5ms)</param>
public int GetProgression(int name)
{
Log("Info", $"Getting progress tuner data at {name}");
if (this.progression.ContainsKey(name))
{
return this.progression[name];
}
else
{
Log("Warning", "No data, returning 0");
return 0;
}
}
///<summary>
///Sets progress tuner value at a specified time index
///</summary>
///<param name="name">Time index (roughly 5ms)</param>
///<param name="value">Value increment (e.g. if increment is 5, then a value of 25 would change to 30 at this keyframe)</param>
public void SetProgression(int name, int value)
{
Log("Info", $"Setting progress tuner data at {name} to {value}");
if (this.progression.ContainsKey(name))
{
this.progression[name] = value;
}
else
{
this.progression.Add(name, value);
}
}
///<summary>
///Bulk applies progression based on two integer arrays (keys and values)
///</summary>
///<param name="keys">List of keyframe indicies</param>
///<param name="values">List of value increments at specified keyframe indicies</param>
public void SetAllProgression(int[] keys, int[] values)
{
Log("Info", $"Setting progress tuner data to predefined array");
this.progression.Clear();
for (int i = 0; i < keys.Length; i++)
{
this.progression[keys[i]] = values[i];
}
}
///<summary>
///Uses the GenHex function to generate multiple error address codes.
///</summary>
///<param name="count">Number of address codes to generate</param>
///<param name="places">Number of places for each code (e.g. 6 places with a template RRRRRRRR might generate 259AD1 for one block)</param>
///<param name="lower">Determines if the generated addresses should be in lowercase (such is the case with date codes, such as on NT4)</param>
///<returns>List of generated codes as a formatted string with comma separation and with 0x in front of each generated hex code</returns>
public string GenAddress(int count, int places, bool lower)
{
Log("Info", $"Generating error {count} address code(s) with {places} place(s)" + (lower ? " in lowercase" : ""));
string ot = "";
string inspir = GetString("ecode1");
for (int i = 0; i < count; i++)
{
if (i == 1) { inspir = GetString("ecode2"); }
if (i == 2) { inspir = GetString("ecode3"); }
if (i == 3) { inspir = GetString("ecode4"); }
if (ot != "") { ot += ", "; }
ot += "0x" + GenHex(places, inspir);
}
if (lower) { return ot.ToLower(); }
return ot;
}
///<summary>
///Generates hexadecimal codes
///</summary>
///<param name="lettercount">Sets the length of the actual hex code</param>
///<param name="inspir">A string where each character represents if the value is fixed or random (e.g. 63RR25E0, which might return as 631725E0)</param>
public string GenHex(int lettercount, string inspir)