private void StartBluescreenWithDelay(BluescreenData data) { Bluescreen bluescreen = new Bluescreen(data); ConfirmButton.IsEnabled = false; CancelButton.IsEnabled = true; delayThread = new Thread((() => { try { Thread.Sleep(data.Delay * 1000); Application.Current.Dispatcher.Invoke((Action)(() => { bluescreen.Show(); ConfirmButton.IsEnabled = true; CancelButton.IsEnabled = false; })); } catch (ThreadInterruptedException) { Application.Current.Dispatcher.Invoke((Action)(() => bluescreen.Close())); } bluescreen = null; delayThread = null; })); delayThread.Start(); }
private void ShowBSOD(object sender, RoutedEventArgs e) { BluescreenData data = new BluescreenData(); bool success = PopulateData(data); if (success) { StartBluescreenWithDelay(data); } }
public Bluescreen(BluescreenData bluescreenData) { InitializeComponent(); this.Cursor = Cursors.None; this.bluescreenData = bluescreenData; InitializeScreen(); Loaded += new RoutedEventHandler(Bluescreen_Loaded); Closing += Close; }
private void Application_Startup(object sender, EventArgs e) { string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1) // #0 is file path { BluescreenData bluescreenData = new BluescreenData(); bool show_help = false; bool enable_unsafe = false; var p = new OptionSet() { { "e|emoticon=", "{Text} for Emoticon", t => bluescreenData.Emoticon = t }, { "m1|main1=", "{Text} for Main Text (Line 1)", t => bluescreenData.MainText1 = t }, { "m2|main2=", "{Text} for Main Text (Line 2)", t => bluescreenData.MainText2 = t }, { "p|progress=", "{Text} for Progress (\"complete\")", t => bluescreenData.Complete = t }, { "mi|moreinfo=", "{Text} for More Info", t => bluescreenData.MoreInfo = t }, { "s|supportperson=", "{Text} for Support Person", t => bluescreenData.SupportPerson = t }, { "sc|stopcode=", "{Text} for Stop code", t => bluescreenData.StopCode = t }, { "br|bgred=", "Background color {value} for red (0-255)", (byte r) => bluescreenData.BgRed = r }, { "bg|bggreen=", "Background color {value} for green (0-255)", (byte g) => bluescreenData.BgGreen = g }, { "bb|bgblue=", "Background color {value} for blue (0-255)", (byte b) => bluescreenData.BgBlue = b }, { "fr|fgred=", "Foreground (text) color {value} for red (0-255)", (byte r) => bluescreenData.FgRed = r }, { "fg|fggreen=", "Foreground (text) color {value} for green (0-255)", (byte g) => bluescreenData.FgGreen = g }, { "fb|fgblue=", "Foreground (text) color {value} for blue (0-255)", (byte b) => bluescreenData.FgBlue = b }, { "oq|origqr", "Use original QR code", o => bluescreenData.UseOriginalQR = o != null }, { "hq|hideqr", "Hides the QR code", h => bluescreenData.HideQR = h != null }, { "d|delay=", "Bluescreen Delay {duration} in seconds (0-86400)", (int d) => { if (d > 86400) { throw new OptionException("Delay maximum is 86400 seconds (24 hours)", "d|delay="); } bluescreenData.Delay = d; } }, { "c|cmd=", "The {command} to run after complete (Careful!)", c => { bluescreenData.CmdCommand = c; bluescreenData.EnableUnsafe = true; } }, { "u|enable-unsafe", "Enable unsafe mode (forces GUI mode and discards all other settings)", eu => enable_unsafe = eu != null }, { "h|help", "Show this message and exit", h => show_help = h != null } }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException ex) { if (AttachConsole(ATTACH_PARENT_PROCESS)) { Console.WriteLine("\n"); Console.Write("BluescreenSimulator: "); Console.WriteLine(ex.Message); Console.WriteLine("Try `--help' for more information."); Console.WriteLine(); FreeConsole(); } Shutdown(1); return; } if (show_help) { ShowHelp(p); return; } if (enable_unsafe) { MessageBox.Show("You are entering Unsafe Mode. Be careful!", "Careful", MessageBoxButton.OK, MessageBoxImage.Warning); RunGui(true); } else { Bluescreen bluescreen = new Bluescreen(bluescreenData); Thread delayThread = new Thread((() => { try { Thread.Sleep(bluescreenData.Delay * 1000); Application.Current.Dispatcher.Invoke((Action)(() => bluescreen.Show())); } catch (ThreadInterruptedException) { Application.Current.Dispatcher.Invoke((Action)(() => bluescreen.Close())); } bluescreen = null; delayThread = null; })); delayThread.Start(); } } else { RunGui(false); } }
private bool PopulateData(BluescreenData data) { if (!string.IsNullOrEmpty(Emoticon.Text)) { data.Emoticon = Emoticon.Text; } if (!string.IsNullOrEmpty(MainText1.Text)) { data.MainText1 = MainText1.Text; } if (!string.IsNullOrEmpty(MainText2.Text)) { data.MainText2 = MainText2.Text; } if (!string.IsNullOrEmpty(Complete.Text)) { data.Complete = Complete.Text; } if (!string.IsNullOrEmpty(MoreInfo.Text)) { data.MoreInfo = MoreInfo.Text; } if (!string.IsNullOrEmpty(SupportPerson.Text)) { data.SupportPerson = SupportPerson.Text; } if (!string.IsNullOrEmpty(StopCode.Text)) { data.StopCode = StopCode.Text; } if (!string.IsNullOrEmpty(BgRed.Text)) { try { byte red = byte.Parse(BgRed.Text); data.BgRed = red; } catch (OverflowException) { MessageBox.Show("Background color value for red is invalid! Must be a number between 0 and 255.", "Invalid color value", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }; } if (!string.IsNullOrEmpty(BgGreen.Text)) { try { byte green = byte.Parse(BgGreen.Text); data.BgGreen = green; } catch (OverflowException) { MessageBox.Show("Background color value for green is invalid! Must be a number between 0 and 255.", "Invalid color value", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }; } if (!string.IsNullOrEmpty(BgBlue.Text)) { try { byte blue = byte.Parse(BgBlue.Text); data.BgBlue = blue; } catch (OverflowException) { MessageBox.Show("Background color value for blue is invalid! Must be a number between 0 and 255.", "Invalid color value", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }; } if (!string.IsNullOrEmpty(FgRed.Text)) { try { byte red = byte.Parse(FgRed.Text); data.FgRed = red; } catch (OverflowException) { MessageBox.Show("Foreground color value for red is invalid! Must be a number between 0 and 255.", "Invalid color value", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }; } if (!string.IsNullOrEmpty(FgGreen.Text)) { try { byte green = byte.Parse(FgGreen.Text); data.FgGreen = green; } catch (OverflowException) { MessageBox.Show("Foreground color value for green is invalid! Must be a number between 0 and 255.", "Invalid color value", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }; } if (!string.IsNullOrEmpty(FgBlue.Text)) { try { byte blue = byte.Parse(FgBlue.Text); data.FgBlue = blue; } catch (OverflowException) { MessageBox.Show("Foreground color value for blue is invalid! Must be a number between 0 and 255.", "Invalid color value", MessageBoxButton.OK, MessageBoxImage.Error); return(false); }; } if (!string.IsNullOrEmpty(Delay.Text)) { try { int delay = int.Parse(Delay.Text); if (delay > 86400) { MessageBox.Show("Please enter a number between 0 and 86,400 (= 24 hours)", "Invalid delay", MessageBoxButton.OK, MessageBoxImage.Error); return(false); } data.Delay = delay; } catch (OverflowException) { }; } if (enableUnsafe && !string.IsNullOrEmpty(CmdCommand.Text.Trim())) { MessageBoxResult messageBoxResult = MessageBox.Show("Using a CMD command can be dangerous. " + "I will not be responsible for any data loss or other damage arising from irresponsible or careless use of the CMD command option. " + "Please re-check your command to make sure that you execute what you intended:\r\n\r\n" + CmdCommand.Text.Trim() + "\r\n\r\n" + "Do you want to proceed?", "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (messageBoxResult == MessageBoxResult.No) { return(false); } data.CmdCommand = CmdCommand.Text.Trim(); } data.EnableUnsafe = enableUnsafe; data.HideQR = HideQR.IsChecked == true; // is a bool? -> need explicit check data.UseOriginalQR = UseOriginalQR.IsChecked == true; // is a bool? -> need explicit check return(true); }