From a3e668c7791a557a403017a1efc296cb97af16ce Mon Sep 17 00:00:00 2001 From: Codeusa Date: Mon, 8 Jan 2018 18:21:32 -0500 Subject: [PATCH] Fix crash --- BorderlessGaming.Logic/Core/ProcessWatcher.cs | 23 ++++++++++++++----- BorderlessGaming.Logic/Windows/Security.cs | 13 +++++++++-- BorderlessGaming/Forms/MainWindow.cs | 4 ++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/BorderlessGaming.Logic/Core/ProcessWatcher.cs b/BorderlessGaming.Logic/Core/ProcessWatcher.cs index e1a086b..ff24970 100644 --- a/BorderlessGaming.Logic/Core/ProcessWatcher.cs +++ b/BorderlessGaming.Logic/Core/ProcessWatcher.cs @@ -205,15 +205,26 @@ private void UpdateProcesses() } Native.QueryProcessesWithWindows(pd => { - if (Config.Instance.IsHidden(pd.Proc.ProcessName)) + try { - return; + if (!string.IsNullOrWhiteSpace(pd?.Proc?.ProcessName)) + { + if (Config.Instance.IsHidden(pd?.Proc?.ProcessName)) + { + return; + } + if (Processes.Select(p => p.Proc.Id).Contains(pd.Proc.Id) && + Processes.Select(p => p.WindowTitle).Contains(pd.WindowTitle)) + { + return; + } + Processes.Add(pd); + _callback(pd, false); + } } - if (!Processes.Select(p => p.Proc.Id).Contains(pd.Proc.Id) || - !Processes.Select(p => p.WindowTitle).Contains(pd.WindowTitle)) + catch (Exception) { - Processes.Add(pd); - _callback(pd, false); + _callback(null, false); } }, Processes.Where(p => p.WindowHandle != IntPtr.Zero).Select(p => p.WindowHandle).ToList()); } diff --git a/BorderlessGaming.Logic/Windows/Security.cs b/BorderlessGaming.Logic/Windows/Security.cs index 888a7e3..5e01b89 100644 --- a/BorderlessGaming.Logic/Windows/Security.cs +++ b/BorderlessGaming.Logic/Windows/Security.cs @@ -36,9 +36,18 @@ public static void SaveConfig(Config instance) public static Config LoadConfigFile() { - using (var memoryStream = new MemoryStream(File.ReadAllBytes(AppEnvironment.ConfigPath))) + try { - return Serializer.Deserialize(memoryStream); + using (var memoryStream = new MemoryStream(File.ReadAllBytes(AppEnvironment.ConfigPath))) + { + return Serializer.Deserialize(memoryStream); + } + } + catch (global::System.Exception) + { + File.Delete(AppEnvironment.ConfigPath); + SaveConfig(new Config()); + return LoadConfigFile(); } } } diff --git a/BorderlessGaming/Forms/MainWindow.cs b/BorderlessGaming/Forms/MainWindow.cs index 55f6ea4..8f9a0e5 100644 --- a/BorderlessGaming/Forms/MainWindow.cs +++ b/BorderlessGaming/Forms/MainWindow.cs @@ -208,6 +208,10 @@ private async void fullApplicationRefreshToolStripMenuItem_Click(object sender, private void HandleProcessChange(ProcessDetails process, bool remove) { + if (process == null) + { + return; + } if (remove) { this.PerformSafely(() => lstProcesses.Items.Remove(process));