private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs args) { switch (args.ExceptionObject) { case Exception ex: Log.Fatal(ex, "Unhandled exception on AppDomain"); Troubleshooting.LogException(ex, "DalamudUnhandled"); var info = "Further information could not be obtained"; if (ex.TargetSite != null && ex.TargetSite.DeclaringType != null) { info = $"{ex.TargetSite.DeclaringType.Assembly.GetName().Name}, {ex.TargetSite.DeclaringType.FullName}::{ex.TargetSite.Name}"; } const MessageBoxType flags = NativeFunctions.MessageBoxType.YesNo | NativeFunctions.MessageBoxType.IconError | NativeFunctions.MessageBoxType.SystemModal; var result = MessageBoxW( Process.GetCurrentProcess().MainWindowHandle, $"An internal error in a Dalamud plugin occurred.\nThe game must close.\n\nType: {ex.GetType().Name}\n{info}\n\nMore information has been recorded separately, please contact us in our Discord or on GitHub.\n\nDo you want to disable all plugins the next time you start the game?", "Dalamud", flags); if (result == (int)User32.MessageBoxResult.IDYES) { Log.Information("User chose to disable plugins on next launch..."); var config = Service <DalamudConfiguration> .Get(); config.PluginSafeMode = true; config.Save(); } Environment.Exit(-1); break; default: Log.Fatal("Unhandled SEH object on AppDomain: {Object}", args.ExceptionObject); break; } }
public void Initialize() { #if DEBUG var fakeStartMenuItem = new MenuItem { Header = "Fake start" }; fakeStartMenuItem.Click += FakeStart_OnClick; LoginContextMenu.Items.Add(fakeStartMenuItem); #endif this.SetDefaults(); var worldStatusBrushOk = WorldStatusPackIcon.Foreground; // grey out world status icon while deferred check is running WorldStatusPackIcon.Foreground = new SolidColorBrush(Color.FromRgb(38, 38, 38)); _launcher.GetGateStatus(App.Settings.Language.GetValueOrDefault(ClientLanguage.English)).ContinueWith((resultTask) => { try { var brushToSet = resultTask.Result.Status ? worldStatusBrushOk : null; Dispatcher.InvokeAsync(() => WorldStatusPackIcon.Foreground = brushToSet ?? new SolidColorBrush(Color.FromRgb(242, 24, 24))); } catch { // ignored } }); _accountManager = new AccountManager(App.Settings); var savedAccount = _accountManager.CurrentAccount; if (savedAccount != null) { SwitchAccount(savedAccount, false); } Model.IsAutoLogin = App.Settings.AutologinEnabled; if (App.Settings.UniqueIdCacheEnabled && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { App.UniqueIdCache.Reset(); Console.Beep(523, 150); // Feedback without popup } if (App.GlobalIsDisableAutologin) { Log.Information("Autologin was disabled globally, saving into settings..."); App.Settings.AutologinEnabled = false; } if (App.Settings.AutologinEnabled && savedAccount != null && !Keyboard.Modifiers.HasFlag(ModifierKeys.Shift)) { Log.Information("Engaging Autologin..."); Model.TryLogin(savedAccount.UserName, savedAccount.Password, savedAccount.UseOtp, savedAccount.UseSteamServiceAccount, true, MainWindowViewModel.AfterLoginAction.Start); return; } else if (Keyboard.Modifiers.HasFlag(ModifierKeys.Shift) || bool.Parse(Environment.GetEnvironmentVariable("XL_NOAUTOLOGIN") ?? "false")) { App.Settings.AutologinEnabled = false; AutoLoginCheckBox.IsChecked = false; } if (App.Settings.GamePath?.Exists != true) { var setup = new FirstTimeSetup(); setup.ShowDialog(); // If the user didn't reach the end of the setup, we should quit if (!setup.WasCompleted) { Environment.Exit(0); return; } SettingsControl.ReloadSettings(); } Task.Run(async() => { await SetupHeadlines(); Troubleshooting.LogTroubleshooting(); }); Log.Information("MainWindow initialized."); Show(); Activate(); }