-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathProgram.cs
62 lines (57 loc) · 1.69 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Borderless1942;
using System.Diagnostics;
// Start Process
var processStartInfo = new ProcessStartInfo
{
FileName = @"BF1942.exe"
};
foreach (var arg in args)
{
processStartInfo.ArgumentList.Add(arg);
}
var process = Process.Start(processStartInfo)!;
var keepAlive = true;
Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [BF1942 Process Has Started] [{process.Id}]");
// Wait for initial window handle
var window = await process.WaitForMainWindowAsync();
window.RemoveBorders();
// Keep itself alive until detected otherwise
while (keepAlive)
{
MainLoop:
UpdateWindowPosition(window);
await Task.Delay(100);
if (process.HasExited)
{
var oldProcessId = process.Id;
var retryCount = 0;
while (retryCount < 3)
{
var matchingProcesses = Process.GetProcessesByName("BF1942");
if (matchingProcesses.Length == 1)
{
process = matchingProcesses[0];
if (process.HasExited)
{
break;
}
Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [BF1942 Process Has Changed] [{oldProcessId} -> {process.Id}]");
window = await process.WaitForMainWindowAsync();
window.RemoveBorders();
goto MainLoop;
}
retryCount++;
await Task.Delay(TimeSpan.FromSeconds(1));
}
keepAlive = false;
Console.WriteLine($"[Borderless1942]: [{DateTime.Now:yyyy-MM-dd - hh:mm:ss tt}] [BF1942 Process Has Exited]");
}
}
static void UpdateWindowPosition(Window window)
{
var monitorBounds = window.GetCurrentMonitor().GetBounds();
var windowBounds = window.GetBounds();
var x = monitorBounds.Width / 2 - windowBounds.Width / 2;
var y = monitorBounds.Height / 2 - windowBounds.Height / 2;
window.SetPosition(x, y);
}