-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
79 lines (65 loc) · 2.8 KB
/
App.xaml.cs
File metadata and controls
79 lines (65 loc) · 2.8 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
using System;
using System.Windows;
using GameRegionGuard.Helpers;
using GameRegionGuard.Services;
namespace GameRegionGuard
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
Logger.Initialize();
Logger.Info("Application starting...");
// Load user settings early so the theme is applied before the MainWindow is created.
AppSettingsService.Load();
if (ThemeService.TryApplySavedTheme())
{
Logger.Info($"Loaded saved theme: {(AppSettingsService.IsDarkTheme ? "Dark" : "Light")}");
}
if (!AdminHelper.IsAdministrator())
{
Logger.Error("Application not running as administrator");
MessageBox.Show(
"This application requires administrator privileges.\n\nPlease right-click the executable and select 'Run as Administrator'.",
"Administrator Rights Required",
MessageBoxButton.OK,
MessageBoxImage.Error);
Logger.Info("Application shutting down due to insufficient privileges");
Environment.Exit(1);
return;
}
Logger.Info("Administrator privileges confirmed");
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
DispatcherUnhandledException += OnDispatcherUnhandledException;
base.OnStartup(e);
}
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var exception = e.ExceptionObject as Exception;
Logger.Error($"Unhandled exception: {exception?.Message}\n{exception?.StackTrace}");
MessageBox.Show(
$"A critical error occurred:\n\n{exception?.Message}\n\nPlease check the log file for details.",
"Critical Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
Environment.Exit(1);
}
private void OnDispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
Logger.Error($"UI exception: {e.Exception.Message}\n{e.Exception.StackTrace}");
MessageBox.Show(
$"An error occurred:\n\n{e.Exception.Message}\n\nPlease check the log file for details.",
"Error",
MessageBoxButton.OK,
MessageBoxImage.Error);
e.Handled = true;
Environment.Exit(1);
}
protected override void OnExit(ExitEventArgs e)
{
Logger.Info($"Application exiting with code {e.ApplicationExitCode}");
Logger.Shutdown();
base.OnExit(e);
}
}
}