Skip to content

Commit

Permalink
Version 8.3
Browse files Browse the repository at this point in the history
Changes:
Added exception handling when reading Favorites settings so that in the
case of corrupt or unreadable favorites, the application may continue to
load without them.  This resolves issue Codeusa#191.
Added more exception handling when enumerating processes to prevent
issues where Windows is resuming from sleep or hibernation and a process
is not responding or unavailable in an unusual way.  This resolves issue
Codeusa#208.
Merged changes from SecretOnline, including adding a process to
favorites by regex string and togglable application update availability
check.
Updated the program icon with a new font that's more visible at more
resolutions.
  • Loading branch information
psouza4 committed Nov 25, 2015
1 parent 283be25 commit 34c07a4
Show file tree
Hide file tree
Showing 20 changed files with 3,543 additions and 1,083 deletions.
102 changes: 63 additions & 39 deletions BorderlessGaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public void Start()
/// </summary>
private void DoMainWork()
{
while (!workerTaskToken.IsCancellationRequested)
while (!this.workerTaskToken.IsCancellationRequested)
{
// update the processlist
UpdateProcesses();
this.UpdateProcesses();

if (AutoHandleFavorites)
if (this.AutoHandleFavorites)
{
// check favorites against the cache
foreach (var pd in _processDetails)
Expand All @@ -95,63 +95,87 @@ private void DoMainWork()

private void UpdateProcesses()
{
if (!this.AutoHandleFavorites)
{
MainWindow frm = MainWindow.ext();
// Note: additional try/catch blocks were added here to prevent stalls when Windows is put into
// suspend or hibernation.

if (frm != null)
if ((frm.WindowState == FormWindowState.Minimized) || (!frm.Visible))
return;
try
{
if (!this.AutoHandleFavorites)
{
MainWindow frm = MainWindow.ext();

if (frm != null)
if ((frm.WindowState == FormWindowState.Minimized) || (!frm.Visible))
return;
}
}
catch { } // swallow any exceptions in attempting to check window minimize/visibility state

lock (updateLock)
lock (this.updateLock)
{
for (int i = 0; i < _processDetails.Count;)
// check existing processes for changes (auto-prune)
for (int i = 0; i < this._processDetails.Count;)
{
var pd = _processDetails[i];
try
{
ProcessDetails pd = this._processDetails[i];

bool should_be_pruned = pd.ProcessHasExited;
bool should_be_pruned = pd.ProcessHasExited;

if (!should_be_pruned)
{
string current_title = "";
if (!should_be_pruned)
{
string current_title = "";

if (!pd.NoAccess)
{
// 2 or 10 seconds until window title timeout, depending on slow-window detection mode
Tools.StartMethodMultithreadedAndWait(() => { current_title = Native.GetWindowTitle(pd.WindowHandle); }, (Utilities.AppEnvironment.SettingValue("SlowWindowDetection", false)) ? 10 : 2);
should_be_pruned = should_be_pruned || (pd.WindowTitle != current_title);
}
}

if (!pd.NoAccess)
if (should_be_pruned)
{
Tools.StartMethodMultithreadedAndWait(() => { current_title = Native.GetWindowTitle(pd.WindowHandle); }, (Utilities.AppEnvironment.SettingValue("SlowWindowDetection", false)) ? 10 : 2);
should_be_pruned = should_be_pruned || (pd.WindowTitle != current_title);
if (pd.MadeBorderless)
HandlePrunedProcess(pd);
_processDetails.RemoveAt(i);
}
else
i++;
}
catch
{
// swallow any exceptions and move to the next item in the array
i++;
}

if (should_be_pruned)
{
if (pd.MadeBorderless)
HandlePrunedProcess(pd);
_processDetails.RemoveAt(i);
}
else
i++;
}

windows.QueryProcessesWithWindows((pd) =>
{
if (_hiddenProcesses.IsHidden(pd.Proc.ProcessName))
return;
if (!_processDetails.Select(p => p.Proc.Id).Contains(pd.Proc.Id))
_processDetails.Add(pd);
}, _processDetails.WindowPtrSet);

// add new process windows
try
{
windows.QueryProcessesWithWindows((pd) =>
{
if (_hiddenProcesses.IsHidden(pd.Proc.ProcessName))
return;
if (!_processDetails.Select(p => p.Proc.Id).Contains(pd.Proc.Id))
_processDetails.Add(pd);
}, _processDetails.WindowPtrSet);
}
catch { } // swallow any exceptions in attempting to add new windows

// update window
window.lblUpdateStatus.Text = "Last updated " + DateTime.Now.ToString();
}
}

public Task RefreshProcesses()
{
lock (updateLock)
lock (this.updateLock)
{
_processDetails.ClearProcesses();
this._processDetails.ClearProcesses();
}
return Task.Factory.StartNew(UpdateProcesses);

return Task.Factory.StartNew(this.UpdateProcesses);
}

/// <summary>
Expand Down
8 changes: 6 additions & 2 deletions BorderlessGaming.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>BorderlessGaming.ico</ApplicationIcon>
<ApplicationIcon>BorderlessGaming_new.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.Launch as User.manifest</ApplicationManifest>
Expand Down Expand Up @@ -151,6 +151,7 @@
<Compile Include="WindowsAPI\Windows.cs" />
<EmbeddedResource Include="Forms\AboutForm.de.resx">
<DependentUpon>AboutForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="Forms\AboutForm.en.resx">
<DependentUpon>AboutForm.cs</DependentUpon>
Expand Down Expand Up @@ -179,7 +180,9 @@
<SubType>Designer</SubType>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.de.resx" />
<EmbeddedResource Include="Properties\Resources.de.resx">
<SubType>Designer</SubType>
</EmbeddedResource>
<None Include="app.config" />
<None Include="app.Launch as User.manifest" />
<None Include="app.Launch as Elevated.manifest" />
Expand Down Expand Up @@ -234,6 +237,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="BorderlessGaming.ico" />
<Content Include="BorderlessGaming_new.ico" />
<None Include="data\bordered.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Binary file added BorderlessGaming_new.ico
Binary file not shown.
33 changes: 23 additions & 10 deletions Common/Favorites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BorderlessGaming.Utilities;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;

namespace BorderlessGaming.Common
{
Expand Down Expand Up @@ -56,15 +57,23 @@ public void Load()
}
catch
{
var favsStringList = new List<string>(JsonConvert.DeserializeObject<List<string>>(jsonDoc));

foreach (string oldFav in favsStringList)
{
Favorite fav = new Favorite();
fav.Kind = Favorite.FavoriteKinds.ByBinaryName;
fav.SearchText = oldFav;
Add(fav);
}
try
{
var favsStringList = new List<string>(JsonConvert.DeserializeObject<List<string>>(jsonDoc));

foreach (string oldFav in favsStringList)
{
try
{
Favorite fav = new Favorite();
fav.Kind = Favorite.FavoriteKinds.ByBinaryName;
fav.SearchText = oldFav;
Add(fav);
}
catch { } // blindly read favorites -- if one is corrupt, read the rest: resolves issue #191
}
}
catch { } // blindly read favorites -- if one is corrupt, read the rest: resolves issue #191
}
}
else
Expand Down Expand Up @@ -105,6 +114,7 @@ public enum FavoriteKinds : int
{
ByBinaryName = 0,
ByTitleText = 1,
ByRegexString = 2,
}

public SizeModes SizeMode = SizeModes.FullScreen;
Expand Down Expand Up @@ -143,6 +153,8 @@ public override string ToString() // so that the ListView control knows how to d

if (this.Kind == FavoriteKinds.ByBinaryName)
extra_details += " [Process]";
else if (this.Kind == FavoriteKinds.ByRegexString)
extra_details += " [Regex]";
else if (this.Kind != FavoriteKinds.ByTitleText)
extra_details += " [?]";

Expand Down Expand Up @@ -171,7 +183,8 @@ public override string ToString() // so that the ListView control knows how to d
public bool Matches(ProcessDetails pd)
{
return (((Kind == FavoriteKinds.ByBinaryName) && (pd.BinaryName == SearchText)) ||
((Kind == FavoriteKinds.ByTitleText) && (pd.WindowTitle == SearchText)));
((Kind == FavoriteKinds.ByTitleText) && (pd.WindowTitle == SearchText)) ||
((Kind == FavoriteKinds.ByRegexString) && (Regex.IsMatch(pd.WindowTitle, SearchText))));
}
}
}
Expand Down
41 changes: 26 additions & 15 deletions Common/HiddenProcesses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ public class HiddenProcesses : ObservableCollection<string>
private static readonly string[] AlwaysHiddenProcesses =
{
// Skip self
"BorderlessGaming",
"borderlessgaming",

// Skip Windows core system processes
"csrss", "smss", "lsass", "wininit", "svchost", "services", "winlogon", "dwm",
"explorer", "taskmgr", "mmc", "rundll32", "vcredist_x86", "vcredist_x64", "msiexec",

// Skip common video streaming software
"XSplit",
"xsplit",

// Skip common web browsers
"iexplore", "firefox", "chrome", "safari",

// Skip launchers/misc.
"IW4 Console", "Steam", "Origin", "Uplay"
"iw4 console", "steam", "origin", "uplay"

// Let them hide the rest manually
};
Expand Down Expand Up @@ -99,21 +99,32 @@ public void Load()
{
foreach (var p in AlwaysHiddenProcesses)
alwaysHideSet.Add(p);
try

if (File.Exists(path))
{
if (File.Exists(path))
{
var processes = JsonConvert.DeserializeObject<List<string>>(File.ReadAllText(path));
foreach (var p in processes)
userHideSet.Add(p.Trim().ToLower());
} else
{
Save();
}
string jsonDoc = File.ReadAllText(path);

try
{
var processes = JsonConvert.DeserializeObject<List<string>>(jsonDoc);
foreach (var p in processes)
userHideSet.Add(p.Trim().ToLower());
}
catch
{
try
{
var hiddenStringList = new List<string>(JsonConvert.DeserializeObject<List<string>>(jsonDoc));

foreach (string oldHidden in hiddenStringList)
userHideSet.Add(oldHidden);
}
catch { }
}
}
catch
else
{
//log
Save();
}
}

Expand Down
21 changes: 21 additions & 0 deletions Forms/AboutForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Forms/AboutForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private void OpenPsouza4Steam(object sender, EventArgs e)
Tools.GotoSite("http://steamcommunity.com/id/psouza4/");
}

private void OpenSecretOnlineGithub(object sender, EventArgs e)
{
Tools.GotoSite("https://github.com/SecretOnline/");
}

#endregion
}
}
Loading

0 comments on commit 34c07a4

Please sign in to comment.