Skip to content

Commit f87eab5

Browse files
author
Alex Camilleri
committed
Added Trace Logger, Exception Logger, Settings. Fixed to list population bug.
1 parent 2eff73e commit f87eab5

19 files changed

+916
-156
lines changed

App.config

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
2+
23
<configuration>
3-
<startup>
4-
5-
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
6-
</configuration>
4+
<startup>
5+
6+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
7+
</startup>
8+
</configuration>

BorderlessGaming.csproj

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>BorderlessGaming</RootNamespace>
1111
<AssemblyName>BorderlessGaming</AssemblyName>
12-
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
1515
<PublishUrl>publish\</PublishUrl>
@@ -57,11 +57,12 @@
5757
</PropertyGroup>
5858
<ItemGroup>
5959
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
60-
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll</HintPath>
60+
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
6161
</Reference>
6262
<Reference Include="System" />
6363
<Reference Include="System.Core" />
6464
<Reference Include="System.Management" />
65+
<Reference Include="System.Web" />
6566
<Reference Include="System.Xml.Linq" />
6667
<Reference Include="System.Data.DataSetExtensions" />
6768
<Reference Include="Microsoft.CSharp" />
@@ -72,29 +73,34 @@
7273
<Reference Include="System.Xml" />
7374
</ItemGroup>
7475
<ItemGroup>
75-
<Compile Include="CompactWindow.cs">
76+
<Compile Include="Extensions\StringExtensions.cs" />
77+
<Compile Include="Forms\CompactWindow.cs">
7678
<SubType>Form</SubType>
7779
</Compile>
78-
<Compile Include="CompactWindow.Designer.cs">
80+
<Compile Include="Forms\CompactWindow.Designer.cs">
7981
<DependentUpon>CompactWindow.cs</DependentUpon>
8082
</Compile>
8183
<Compile Include="Favorites.cs" />
82-
<Compile Include="MainWindow.cs">
84+
<Compile Include="Forms\MainWindow.cs">
8385
<SubType>Form</SubType>
8486
</Compile>
85-
<Compile Include="MainWindow.Designer.cs">
87+
<Compile Include="Forms\MainWindow.Designer.cs">
8688
<DependentUpon>MainWindow.cs</DependentUpon>
8789
</Compile>
8890
<Compile Include="Program.cs" />
8991
<Compile Include="Properties\AssemblyInfo.cs" />
90-
<Compile Include="Tools\Tools.cs" />
92+
<Compile Include="Utilities\DynamicMap.cs" />
93+
<Compile Include="Utilities\ExceptionHandler.cs" />
94+
<Compile Include="Utilities\Settings.cs" />
95+
<Compile Include="Utilities\Tools.cs" />
96+
<Compile Include="Utilities\Trace.cs" />
9197
<Compile Include="WindowsApi\Enumerations.cs" />
9298
<Compile Include="WindowsApi\Native.cs" />
9399
<Compile Include="WindowsApi\WindowWrapper.cs" />
94-
<EmbeddedResource Include="CompactWindow.resx">
100+
<EmbeddedResource Include="Forms\CompactWindow.resx">
95101
<DependentUpon>CompactWindow.cs</DependentUpon>
96102
</EmbeddedResource>
97-
<EmbeddedResource Include="MainWindow.resx">
103+
<EmbeddedResource Include="Forms\MainWindow.resx">
98104
<DependentUpon>MainWindow.cs</DependentUpon>
99105
</EmbeddedResource>
100106
<EmbeddedResource Include="Properties\Resources.resx">
@@ -107,9 +113,7 @@
107113
<DependentUpon>Resources.resx</DependentUpon>
108114
<DesignTime>True</DesignTime>
109115
</Compile>
110-
<None Include="app.manifest">
111-
<SubType>Designer</SubType>
112-
</None>
116+
<None Include="app.manifest" />
113117
<None Include="packages.config" />
114118
<None Include="Properties\Settings.settings">
115119
<Generator>SettingsSingleFileGenerator</Generator>

Extensions/StringExtensions.cs

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Text.RegularExpressions;
5+
using System.Web.UI;
6+
7+
namespace BorderlessGaming.Extensions
8+
{
9+
/// <summary>
10+
/// Enum FormatTokenFlags
11+
/// </summary>
12+
public enum FormatTokenFlags
13+
{
14+
/// <summary>
15+
/// Uses the specifier token as the replacement token, matches '%' but not '%%'
16+
/// </summary>
17+
SpecifierToken,
18+
19+
/// <summary>
20+
/// Like String.Format
21+
/// </summary>
22+
IndexToken,
23+
24+
/// <summary>
25+
/// Extracts an Object's Members by name.
26+
/// </summary>
27+
MemberToken
28+
}
29+
30+
/// <summary>
31+
/// Class StringExtensions
32+
/// </summary>
33+
public static class StringExtensions
34+
{
35+
/// <summary>
36+
/// The Reformatting function called to format the string with a list of arguments.
37+
/// </summary>
38+
private static Func<Func<string, object>, string, IList<object>, string> _regexReformatter;
39+
40+
/// <summary>
41+
/// The Regex which matches the specifier token in strings.
42+
/// </summary>
43+
private static Regex _specifierTokenRegex;
44+
45+
/// <summary>
46+
/// The Regex which matches parameter indexes in strings, same as string.Format.
47+
/// </summary>
48+
private static Regex _argumentIndexRegex;
49+
50+
/// <summary>
51+
/// The Regex which matches object member names in strings.
52+
/// </summary>
53+
private static Regex _objectMemberRegex;
54+
55+
/// <summary>
56+
/// Splits a string into an array of strings, the string is split by commas.
57+
/// </summary>
58+
/// <param name="this">The string instance to split by commas.</param>
59+
/// <returns>The <paramref name="this" /> string that has been comma separated into substrings.</returns>
60+
public static string[] CommaSeparate(this string @this)
61+
{
62+
return @this.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
63+
}
64+
65+
/// <summary>
66+
/// Determines whether two String objects contain the same data, ignoring the case of the letters in the String; uses
67+
/// Ordinal comparison.
68+
/// </summary>
69+
/// <param name="this">The current string to be compared to.</param>
70+
/// <param name="other">The other string to compare against the current String for equality.</param>
71+
/// <returns><c>true</c> if the two strings are equal, <c>false</c> otherwise</returns>
72+
public static bool EqualsIgnoreCase(this string @this, string other)
73+
{
74+
return string.Equals(@this, other, StringComparison.OrdinalIgnoreCase);
75+
}
76+
77+
/// <summary>
78+
/// Replaces one or more format items in a specified string with the string representation of a specified object.
79+
/// </summary>
80+
/// <returns>
81+
/// A copy of <paramref name="format" /> in which any format items are replaced by the string representation of
82+
/// <paramref name="values" />.
83+
/// </returns>
84+
/// <param name="format">A composite format string. </param>
85+
/// <param name="values">The arguments to use in formatting <paramref name="format" />.</param>
86+
public static string Form(this string format, params object[] values)
87+
{
88+
var specifierTokenMatches = _specifierTokenRegex.Matches(format);
89+
var indexTokenMatches = _argumentIndexRegex.Matches(format);
90+
var memberNameMatches = _objectMemberRegex.Matches(format);
91+
92+
if (memberNameMatches.Count > 0 && values.Length == 1)
93+
{
94+
format = FormatString(format, FormatTokenFlags.MemberToken, values);
95+
}
96+
else
97+
{
98+
if (indexTokenMatches.Count > 0)
99+
{
100+
format = FormatString(format, FormatTokenFlags.IndexToken, values);
101+
}
102+
103+
if (specifierTokenMatches.Count > 0)
104+
{
105+
format = FormatString(format, FormatTokenFlags.SpecifierToken, values);
106+
}
107+
}
108+
return format;
109+
}
110+
111+
/// <summary>
112+
/// The Function which does all the heavy lifting.
113+
/// </summary>
114+
/// <param name="format">A composite format string</param>
115+
/// <param name="flags">The flags which specify how the <paramref name="format" /> string should be interpreted.</param>
116+
/// <param name="arguments">The arguments to format the <paramref name="format" /> parameter with.</param>
117+
/// <returns>System.String.</returns>
118+
public static string FormatString(string format, FormatTokenFlags flags, params object[] arguments)
119+
{
120+
switch (flags)
121+
{
122+
case FormatTokenFlags.IndexToken:
123+
return string.Format(format, arguments);
124+
125+
case FormatTokenFlags.SpecifierToken:
126+
var stringBuilder = new StringBuilder();
127+
for (int i = 0,
128+
argIndex = 0; i < format.Length; i++)
129+
{
130+
stringBuilder.Append(format[i] == '%' && argIndex < arguments.Length ? "{" + argIndex++ + "}" : format.Substring(i, 1));
131+
}
132+
return string.Format(stringBuilder.ToString(), arguments);
133+
134+
case FormatTokenFlags.MemberToken:
135+
return string.Format(_regexReformatter(name => (name == "0") ? arguments[0] : DataBinder.Eval(arguments[0], name), format, arguments), arguments);
136+
137+
default:
138+
return format;
139+
}
140+
}
141+
142+
public static void Initialize()
143+
{
144+
const RegexOptions regexOptions = RegexOptions.Compiled | RegexOptions.CultureInvariant;
145+
_objectMemberRegex = new Regex(@"(?<start>(\{))+(?<property>[\w\.]+)(?<end>(\}))+", regexOptions);
146+
_specifierTokenRegex = new Regex(@"(?<!\\)%", regexOptions);
147+
_argumentIndexRegex = new Regex(@"\{(\d)\}", regexOptions);
148+
_regexReformatter = (valueFetcher, format, parameters) =>
149+
{
150+
var argumentCollection = new List<object>();
151+
var rewrittenFormat = _objectMemberRegex.Replace(format, match =>
152+
{
153+
Group startGroup = match.Groups["start"],
154+
propertyGroup = match.Groups["property"],
155+
endGroup = match.Groups["end"];
156+
157+
var result = valueFetcher(propertyGroup.Value);
158+
159+
argumentCollection.Add(result);
160+
var index = argumentCollection.Count - 1;
161+
var fmt = new string('{', startGroup.Captures.Count) + index + new string('}', endGroup.Captures.Count);
162+
return string.Format(fmt, argumentCollection.ToArray());
163+
});
164+
165+
return rewrittenFormat;
166+
};
167+
}
168+
}
169+
}

Favorites.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public static void Save(string path)
3535
}
3636
catch (Exception e)
3737
{
38-
MessageBox.Show("Unable to save favorites, do you have permission?" + e.Message, "Uh oh!",
39-
MessageBoxButtons.OK, MessageBoxIcon.Error);
38+
MessageBox.Show("Unable to save favorites, do you have permission?" + e.Message, "Uh oh!", MessageBoxButtons.OK, MessageBoxIcon.Error);
4039
}
4140
}
4241

Forms/CompactWindow.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,6 @@ namespace BorderlessGaming.Forms
1111
{
1212
public partial class CompactWindow : Form
1313
{
14-
private const int SW_SHOW = 0x05;
15-
private const int WS_EX_APPWINDOW = 0x40000;
16-
private const int GWL_EXSTYLE = -0x14; //never want to hunt this down again
17-
private const int WS_EX_DLGMODALFRAME = 0x0001;
18-
private const int WS_EX_TOOLWINDOW = 0x0080;
19-
private const short SWP_NOMOVE = 0X2;
20-
private const short SWP_NOSIZE = 1;
21-
private const short SWP_NOZORDER = 0X4;
22-
private const int SWP_SHOWWINDOW = 0x0040;
23-
24-
public static uint MF_BYPOSITION = 0x400;
25-
public static uint MF_REMOVE = 0x1000;
26-
public static int GWL_STYLE = -16;
2714
private readonly List<string> _borderlessWindows = new List<string>();
2815
private readonly List<string> _processDataList = new List<string>();
2916
private readonly List<string> _tempList = new List<string>();
@@ -149,30 +136,20 @@ private void RemoveBorder(String procName) //actually make it frameless
149136
continue;
150137
}
151138
var pFoundWindow = proc.MainWindowHandle;
152-
var style = Native.GetWindowLong(pFoundWindow, GWL_STYLE);
153-
154-
//get menu
139+
var style = Native.GetWindowLong(pFoundWindow, WindowLongIndex.Style);
155140
var HMENU = Native.GetMenu(proc.MainWindowHandle);
156-
//get item count
157141
var count = Native.GetMenuItemCount(HMENU);
158-
//loop & remove
159142
for (var i = 0; i < count; i++)
160143
{
161-
Native.RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE));
162-
Native.RemoveMenu(HMENU, 0, (MF_BYPOSITION | MF_REMOVE));
144+
Native.RemoveMenu(HMENU, 0, MenuFlags.ByPosition | MenuFlags.Remove);
163145
}
164146

165147
//force a redraw
166148
Native.DrawMenuBar(proc.MainWindowHandle);
167-
Native.SetWindowLong(pFoundWindow, GWL_STYLE, (style & ~(WindowStyleFlags.ExtendedDlgmodalframe | WindowStyleFlags.Caption | WindowStyleFlags.ThickFrame | WindowStyleFlags.Minimize | WindowStyleFlags.Maximize | WindowStyleFlags.SystemMenu | WindowStyleFlags.MaximizeBox | WindowStyleFlags.MinimizeBox | WindowStyleFlags.Border | WindowStyleFlags.ExtendedComposited)));
149+
Native.SetWindowLong(pFoundWindow, WindowLongIndex.Style, (style & ~(WindowStyleFlags.ExtendedDlgmodalframe | WindowStyleFlags.Caption | WindowStyleFlags.ThickFrame | WindowStyleFlags.Minimize | WindowStyleFlags.Maximize | WindowStyleFlags.SystemMenu | WindowStyleFlags.MaximizeBox | WindowStyleFlags.MinimizeBox | WindowStyleFlags.Border | WindowStyleFlags.ExtendedComposited)));
168150

169151
var bounds = Screen.FromHandle(pFoundWindow).Bounds;
170152
Native.SetWindowPos(pFoundWindow, 0, bounds.X, bounds.Y, bounds.Width, bounds.Height, SetWindowPosFlags.NoZOrder | SetWindowPosFlags.ShowWindow);
171-
172-
//no more outside window
173-
// CheckNativeResult(() => Native.MoveWindow(pFoundWindow, 0, 0, bounds.Width, bounds.Height, true));
174-
//resets window to main monito
175-
176153
_gameFound = true;
177154
}
178155

@@ -301,4 +278,4 @@ private void TrayIconExit(object sender, EventArgs e)
301278
Environment.Exit(0);
302279
}
303280
}
304-
}
281+
}

Forms/MainWindow.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,21 @@ private void PopulateList() //Adds active windows to the processDataList
101101
{
102102
_tempList.Add("Refreshing...");
103103
processList.DataSource = _tempList;
104-
Process.GetProcesses().Where(proc => !proc.ProcessName.Equals("explorer")).ToList().ForEach(process =>
104+
var processlist = Process.GetProcesses();
105+
106+
foreach (var process in
107+
processlist.Where(process => process != null && !process.ProcessName.Equals("explorer")))
105108
{
109+
if (String.IsNullOrEmpty(process.MainWindowTitle))
110+
{
111+
Native.SetWindowText(process.MainWindowHandle, process.ProcessName);
112+
}
106113
if (process.MainWindowTitle.Length <= 0)
107114
{
108-
return;
115+
continue;
109116
}
110-
111117
_processDataList.Add(process.ProcessName);
112-
});
118+
}
113119

114120
UpdateList();
115121
}

0 commit comments

Comments
 (0)