From 284b9e369ddfb44b865ed0f3dccd2fc3eb6cd9b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E5=BD=A6=E8=B5=A4=E5=B1=8B=E5=85=88?= Date: Sun, 7 Jan 2024 18:55:22 +0900 Subject: [PATCH] Crashing fixes? --- Amethyst/App.xaml.cs | 19 ++++++++++++++----- Amethyst/Classes/AppPlugins.cs | 4 +++- Amethyst/Classes/Interfacing.cs | 13 ++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Amethyst/App.xaml.cs b/Amethyst/App.xaml.cs index 4da33eff..aace285f 100644 --- a/Amethyst/App.xaml.cs +++ b/Amethyst/App.xaml.cs @@ -125,9 +125,17 @@ public App() // Create an empty file for checking for crashes try { - Interfacing.CrashFile = new FileInfo(Path.Join(Interfacing.TemporaryFolder.Path, ".crash")); - if (Environment.GetCommandLineArgs().ElementAtOrDefault(1)?.StartsWith("amethyst-app:crash") ?? false) - Interfacing.CrashFile.Create(); // Create the file if not running as crash handler + if (!Interfacing.SuppressAllDomainExceptions && + (string.IsNullOrEmpty(Environment.GetCommandLineArgs().ElementAtOrDefault(1)) || + Environment.GetCommandLineArgs().ElementAtOrDefault(1) is "amethyst-app:")) + { + Interfacing.CrashFile = + new FileInfo(Path.Join(Interfacing.TemporaryFolder.Path, "Crash", + Guid.NewGuid().ToString().ToUpper())); + + Interfacing.CrashFile.Directory?.Create(); // Create the directory too... + Interfacing.CrashFile.Create(); // Create the file if not running as slave + } } catch (Exception e) { @@ -515,7 +523,8 @@ protected override async void OnLaunched(LaunchActivatedEventArgs eventArgs) new DirectoryInfo(Path.Join(pluginFolder, "Assets", "Strings")) .CopyToFolder(outputFolder.Path); - pluginStringsFolders.Add(Path.Join(pluginFolder, "Assets", "Strings"), outputFolder.Path); + pluginStringsFolders.Add(Path.Join(pluginFolder, "Assets", "Strings"), + outputFolder.Path); } // Create a new localization config @@ -566,7 +575,7 @@ await File.WriteAllTextAsync(Interfacing.GetAppDataFilePath("Localization.json") Logger.Info("Starting the crash handler passing the app PID..."); await ($"amethyst-app:crash-watchdog?pid={Environment.ProcessId}&log={Logger.LogFilePath}" + - $"&crash={Path.Join(Interfacing.TemporaryFolder.Path, ".crash")}").ToUri().LaunchAsync(); + $"&crash={Interfacing.CrashFile.FullName}").ToUri().LaunchAsync(); // Disable internal sounds ElementSoundPlayer.State = ElementSoundPlayerState.Off; diff --git a/Amethyst/Classes/AppPlugins.cs b/Amethyst/Classes/AppPlugins.cs index 5189a004..edac95b7 100644 --- a/Amethyst/Classes/AppPlugins.cs +++ b/Amethyst/Classes/AppPlugins.cs @@ -86,7 +86,9 @@ public static void UpdateTrackingDevicesInterface() var failingOverrideGuid = ""; foreach (var device in AppData.Settings.OverrideDevicesGuidMap - .Where(device => TrackingDevicesList[device].DeviceStatus != 0)) + .Where(device => + TrackingDevicesList.TryGetValue(device, out var deviceInternal) && + deviceInternal.DeviceStatus != 0)) { overrideStatusOk = false; failingOverrideGuid = device; diff --git a/Amethyst/Classes/Interfacing.cs b/Amethyst/Classes/Interfacing.cs index f125376d..0c0cd802 100644 --- a/Amethyst/Classes/Interfacing.cs +++ b/Amethyst/Classes/Interfacing.cs @@ -776,9 +776,16 @@ public static async Task ExecuteAppRestart(bool handleExit = true, string parame info.FileName = "explorer.exe"; } - // Exit without re-handling everything - Process.Start(info); - Environment.Exit(0); + try + { + // Exit without re-handling everything + Process.Start(info); + Environment.Exit(0); + } + catch (Exception e) + { + Logger.Fatal(e); + } } // Still here?