Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (43 loc) · 2.51 KB
/
Copy pathProgram.cs
File metadata and controls
49 lines (43 loc) · 2.51 KB
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
using System.Threading;
namespace GhostDeck;
internal static class Program
{
[STAThread]
private static int Main(string[] args)
{
// Signed model-database override (ModelDb): a downloaded, verified, NEWER database
// replaces the compiled tables for this run - for the tray app and the CLI alike.
if (ModelDb.LoadOverride() is { } db) Devices.ApplyOverride(db);
// Any argument = CLI mode: forwarded to the running instance over the pipe, or executed
// one-shot against the EC. The tray app itself never starts with arguments.
// --stats-demo (1.44): the Statystyki view, the catalogue badges and the Community tile on a
// built-in sample summary, to look at them before the server has a week worth showing. A
// running instance takes the switch over the pipe and shows its window; otherwise this
// process starts the tray app in demo mode (args stays whole, so the elevated relaunch
// below carries the switch too).
bool demo = args.Length == 1 && args[0] == "--stats-demo";
if (demo)
{
if (Cli.TrySendToRunning(args, out _, out _)) return 0;
Stats.DemoMode = true;
}
else if (args.Length > 0) return Cli.Run(args);
// Tray start. A running instance only has to show its window - any process may ask it,
// elevated or not. Otherwise the tray needs the EC, so an unelevated launch (double-click,
// a pinned icon) goes through the one UAC prompt and ends here; the autostart task starts
// elevated already (RL HIGHEST) and never sees that prompt.
if (Elevation.SignalRunningInstance()) return 0;
if (!Elevation.IsElevated) return Elevation.Relaunch(args, wait: false);
Taskbar.SetProcessId(); // the jump list and the pinned icon hang on this identity
using var showSignal = Elevation.CreateShowEvent();
using var mtx = new Mutex(true, "GhostDeck_SingleInstance", out bool createdNew);
if (!createdNew) { showSignal.Set(); return 0; } // already running - ask it to show its window
Updater.CleanupAfterUpdate(); // drop leftover GhostDeck.update.exe / .bak from a previous update
AppLifecycle.Install(); // shutdown flag + no WinForms crash dialog, ever
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TrayContext());
return 0;
}
}