Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Codeusa committed Jan 8, 2018
1 parent 7c338c2 commit a3e668c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
23 changes: 17 additions & 6 deletions BorderlessGaming.Logic/Core/ProcessWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
13 changes: 11 additions & 2 deletions BorderlessGaming.Logic/Windows/Security.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config>(memoryStream);
using (var memoryStream = new MemoryStream(File.ReadAllBytes(AppEnvironment.ConfigPath)))
{
return Serializer.Deserialize<Config>(memoryStream);
}
}
catch (global::System.Exception)
{
File.Delete(AppEnvironment.ConfigPath);
SaveConfig(new Config());
return LoadConfigFile();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions BorderlessGaming/Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit a3e668c

Please sign in to comment.