-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
64 lines (55 loc) · 2.62 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
63
64
using System.Diagnostics;
using System.Management;
namespace GEVOWatcher
{
internal static class Program
{
private const string gameName = "EvoGameSteam-Win64-Shipping";
private static readonly ManagementEventWatcher gameStartWatcher = new($"SELECT * FROM __InstanceCreationEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = '{gameName}.exe'");
private static readonly ManagementEventWatcher gameStopWatcher = new($"SELECT * FROM __InstanceDeletionEvent WITHIN 1 WHERE TargetInstance ISA 'Win32_Process' AND TargetInstance.Name = '{gameName}.exe'");
private static bool gameRunning = Process.GetProcesses().Any((x) => x.ProcessName == gameName);
private static void StartWatching()
{
gameStartWatcher.EventArrived += new EventArrivedEventHandler(GameStarted);
gameStopWatcher.EventArrived += new EventArrivedEventHandler(GameStopped);
gameStartWatcher.Start();
gameStopWatcher.Start();
}
private static void GameStarted(object sender, EventArrivedEventArgs e) => gameRunning = true;
private static void GameStopped(object sender, EventArrivedEventArgs e)
{
gameRunning = false;
Sync();
}
private static void Sync()
{
if (!gameRunning || DialogResult.Yes == MessageBox.Show("The game is currently running.\nSyncing now will cause issues, do you still want to sync?", "Sync Now?", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
{
Process.Start("GEVOTicket.exe").WaitForExit();
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (NotifyIcon icon = new())
{
icon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
icon.ContextMenuStrip = new ContextMenuStrip()
{
Items =
{
new ToolStripMenuItem("Sync Now", null, (s, e) => { Sync(); }),
new ToolStripMenuItem("Settings", null, (s, e) => { MessageBox.Show("Currently Unsupported.", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error); }),
new ToolStripMenuItem("Exit", null, (s, e) => { Application.Exit(); })
}
};
icon.Visible = true;
Application.Run();
icon.Visible = false;
}
StartWatching();
}
}
}