-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (40 loc) · 1.96 KB
/
Program.cs
File metadata and controls
44 lines (40 loc) · 1.96 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
using System.Text.Json;
using SoulMaskServerManager.Forms;
internal static class Program
{
[STAThread]
static void Main()
{
// These MUST be called before any Win32 window is created (including SetColorMode)
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetHighDpiMode(HighDpiMode.SystemAware);
// Write any startup crash to a plain text file before the logger exists
string crashLog = Path.Combine(AppContext.BaseDirectory, "startup_crash.log");
try
{
Application.SetColorMode(SystemColorMode.Dark);
Application.ThreadException += (s, e) =>
{
string msg = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] ThreadException: {e.Exception}\n";
try { File.AppendAllText(crashLog, msg); } catch { }
MessageBox.Show($"Unhandled error: {e.Exception.Message}\n\nDetails written to:\n{crashLog}",
"SoulMask Server Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
string msg = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] UnhandledException: {e.ExceptionObject}\n";
try { File.AppendAllText(crashLog, msg); } catch { }
MessageBox.Show($"Fatal error: {e.ExceptionObject}\n\nDetails written to:\n{crashLog}",
"SoulMask Server Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
};
Application.Run(new ClusterManagerForm());
}
catch (Exception ex)
{
File.WriteAllText(crashLog, $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] STARTUP CRASH\n{ex}\n");
MessageBox.Show($"Failed to start:\n\n{ex.Message}\n\nFull details in:\n{crashLog}",
"SoulMask Server Manager — Startup Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}