Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
43 lines (37 loc) · 1.43 KB
/
Copy pathProgram.cs
File metadata and controls
43 lines (37 loc) · 1.43 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
namespace V2XAmbilight;
static class Program
{
static readonly string CrashLog = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"V2XAmbilight", "crash.log");
[STAThread]
static void Main(string[] args)
{
// Elevated kill helper — launched by the app itself via runas
if (args.Length == 2 && args[0] == "--kill")
{
foreach (var p in System.Diagnostics.Process.GetProcessesByName(args[1]))
try { p.Kill(); } catch { }
return;
}
// Single instance guard
using var mutex = new Mutex(true, "V2XAmbilight_SingleInstance", out bool first);
if (!first) return;
Application.ThreadException += (_, e) => LogCrash(e.Exception);
AppDomain.CurrentDomain.UnhandledException += (_, e) => LogCrash(e.ExceptionObject as Exception);
TaskScheduler.UnobservedTaskException += (_, e) => { LogCrash(e.Exception); e.SetObserved(); };
ApplicationConfiguration.Initialize();
Application.Run(new TrayApp());
}
static void LogCrash(Exception? ex)
{
if (ex is null) return;
try
{
Directory.CreateDirectory(Path.GetDirectoryName(CrashLog)!);
File.AppendAllText(CrashLog,
$"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {ex}\n\n");
}
catch { }
}
}