-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
98 lines (78 loc) · 2.74 KB
/
Copy pathProgram.cs
File metadata and controls
98 lines (78 loc) · 2.74 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Threading;
using MiniHide.Managers;
namespace MiniHide
{
internal static class Program
{
private static Mutex? mutex;
[STAThread]
static void Main()
{
const string mutexName = "MiniHide_SingleInstance";
bool createdNew;
mutex = new Mutex(true, mutexName, out createdNew);
if (!createdNew)
{
MessageBox.Show(
"MiniHide is already running.\n\nUse the tray icon to access it.",
"MiniHide",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
return;
}
// ✅ Enable WinForms exception handling
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// ✅ Hook global exception handlers
Application.ThreadException += (sender, args) =>
{
HandleException(args.Exception);
};
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
if (args.ExceptionObject is Exception ex)
{
HandleException(ex);
}
};
ApplicationConfiguration.Initialize();
try
{
Application.Run(new MiniHideContext());
}
finally
{
mutex.ReleaseMutex();
}
}
// ✅ Crash logger
private static void HandleException(Exception ex)
{
try
{
string folder = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"MiniHide");
Directory.CreateDirectory(folder);
string file = Path.Combine(folder, "crash.log");
string message =
$"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}]\n" +
$"Type: {ex.GetType().FullName}\n" +
$"Message: {ex.Message}\n" +
$"Stack:\n{ex.StackTrace}\n\n";
File.AppendAllText(file, message);
MessageBox.Show(
"MiniHide encountered an unexpected error and needs to close.\n\n" +
"A crash log has been saved to:\n\n" +
file + "\n\n" +
"Please open this file and share it for support.",
"MiniHide Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
catch
{
// Never crash while handling a crash
}
}
}
}