-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (45 loc) · 2.1 KB
/
Copy pathProgram.cs
File metadata and controls
50 lines (45 loc) · 2.1 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
50
using System;
using GuardWui3.Services;
namespace GuardWui3;
// Replaces the XAML-generated Main (DISABLE_XAML_GENERATED_MAIN in the csproj).
// Two jobs before any XAML loads:
// - "--run-backup auto|onconnect": the scheduled tasks launch GUARD.exe itself
// instead of cmd.exe. A GUI-subsystem exe never opens a console, so scheduled
// and on-connect runs are fully hidden (the old cmd.exe action flashed a
// console every 15 minutes for the on-connect check). The helper runs the
// generated script hidden, raises the outcome toast, and exits - no XAML,
// no window, no WinUI init.
// - Single instance per install folder: a second GUARD.exe from the same
// folder would race the settings ini and the staged updater, so it just
// activates the first window and exits. Keyed to BaseDir, so two separate
// portable copies can still run side by side.
public static class Program
{
[STAThread]
static int Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += (_, e) =>
DebugLog.Crash(e.ExceptionObject as Exception, "AppDomain");
if (args.Length >= 2 && args[0] == "--run-backup")
return HeadlessBackupRunner.Run(args[1]);
// initiallyOwned avoids a create/acquire race between two launches. The
// mutex must live for the whole run: Application.Start blocks here until
// the window closes, so the using scope covers it.
using var mutex = new System.Threading.Mutex(
initiallyOwned: true, SingleInstance.MutexName, out bool createdNew);
if (!createdNew)
{
SingleInstance.ActivateExisting();
return 0;
}
global::WinRT.ComWrappersSupport.InitializeComWrappers();
Microsoft.UI.Xaml.Application.Start(_ =>
{
var context = new Microsoft.UI.Dispatching.DispatcherQueueSynchronizationContext(
Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());
System.Threading.SynchronizationContext.SetSynchronizationContext(context);
new App();
});
return 0;
}
}