-
Notifications
You must be signed in to change notification settings - Fork 7
/
App.xaml.cs
82 lines (73 loc) · 3.35 KB
/
App.xaml.cs
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
using DiskTools.Helpers;
using Microsoft.UI.Xaml;
using System;
using System.IO;
// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.
namespace DiskTools
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeComponent();
UnhandledException += Application_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
//注册 Syncfusion 许可证
var personalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var keyPath = System.IO.Path.Combine(personalFolder, "syncfusionKey.txt");
var key = File.ReadAllText(keyPath);
if (key == "")
throw new Exception("Key file not found in C:\\Users\\<Your Account>\\Documents\\syncfusionKey.txt");
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(key);
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
private MainWindow m_window;
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
RegisterExceptionHandlingSynchronizationContext();
m_window = new();
m_window.TrackWindow();
ThemeHelper.Initialize();
m_window.Title = "Disk Tools";
m_window.Activate();
}
private void Application_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
SettingsHelper.LogManager.GetLogger("Unhandled Exception - Application").Error(e.Exception.ExceptionToMessage(), e.Exception);
e.Handled = true;
}
private void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception Exception)
{
SettingsHelper.LogManager.GetLogger("Unhandled Exception - CurrentDomain").Error(Exception.ExceptionToMessage(), Exception);
}
}
/// <summary>
/// Should be called from OnActivated and OnLaunched
/// </summary>
private void RegisterExceptionHandlingSynchronizationContext()
{
ExceptionHandlingSynchronizationContext
.Register()
.UnhandledException += SynchronizationContext_UnhandledException;
}
private void SynchronizationContext_UnhandledException(object sender, Helpers.UnhandledExceptionEventArgs e)
{
SettingsHelper.LogManager.GetLogger("Unhandled Exception - SynchronizationContext").Error(e.Exception.ExceptionToMessage(), e.Exception);
e.Handled = true;
}
}
}