private void Application_Startup(object sender, EventArgs e) { void SetTheme() => DarkThemeDictionary.IsEnabled = Settings.Default.IsDarkTheme; Settings.Default.Upgrade(); Settings.Default.PropertyChanged += (_, __) => SetTheme(); SetTheme(); DispatcherUnhandledException += (o, eventArgs) => { var m = ShowErrorMessage(eventArgs.Exception); eventArgs.Handled = m != MessageBoxResult.Cancel || m != MessageBoxResult.No; }; AppDomain.CurrentDomain.UnhandledException += delegate(object o, UnhandledExceptionEventArgs eventArgs) { ShowErrorMessage(eventArgs.ExceptionObject as Exception); }; var args = Environment.GetCommandLineArgs(); if (args.Length > 1) // #0 is file path { bool showHelp = false; void AddHelp(OptionSet set) { set.Add("h|help", "Show this message and exit", h => showHelp = h != null); } IBluescreenViewModel data = null; Type type = null; var currentSet = CmdParameterAttribute.GetBaseOptionSet(t => type = t, out var bluescreenOptions); AddHelp(currentSet); try { foreach (var option in bluescreenOptions) { if (args.Contains(option.Value)) { type = option.Key; break; } } if (type is null) { showHelp = true; goto showHelp; } data = (IBluescreenViewModel)Activator.CreateInstance(type); currentSet = CmdParameterAttribute.GetOptionSetFor(type, data); if (showHelp) { goto showHelp; } AddHelp(currentSet); currentSet.Parse(args); } catch (OptionException ex) { if (AttachConsole(AttachParentProcess)) { Console.WriteLine("\n"); Console.Write("BluescreenSimulator: "); Console.WriteLine(ex.Message); Console.WriteLine("Try `--help' for more information."); Console.WriteLine(); FreeConsole(); } Shutdown(1); return; } showHelp: if (showHelp) { ShowHelp(currentSet); return; } if (data.EnableUnsafe) { MessageBox.Show("You are entering Unsafe Mode. Be careful!", "Careful", MessageBoxButton.OK, MessageBoxImage.Warning); RunGui(true); } else { data.ShowView(); } } else { RunGui(false); } }