2024-02-13 17:40:12 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2024-02-08 12:41:21 +08:00
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace WpfMaiTouchEmulator;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for App.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class App : Application
|
|
|
|
|
{
|
2024-02-13 17:40:12 +08:00
|
|
|
|
public App()
|
|
|
|
|
{
|
|
|
|
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
|
|
|
|
DispatcherUnhandledException += App_DispatcherUnhandledException;
|
|
|
|
|
Logger.CleanupOldLogFiles();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateDump(e.Exception);
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
CreateDump(e.ExceptionObject as Exception);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateDump(Exception exception)
|
|
|
|
|
{
|
|
|
|
|
var dumpFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "CrashDump.dmp");
|
|
|
|
|
|
|
|
|
|
using (var fs = new FileStream(dumpFilePath, FileMode.Create))
|
|
|
|
|
{
|
|
|
|
|
var process = Process.GetCurrentProcess();
|
|
|
|
|
DumpCreator.MiniDumpWriteDump(process.Handle, (uint)process.Id, fs.SafeFileHandle, DumpCreator.Typ.MiniDumpNormal, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Logger.Fatal("App encountered a fatal exception", exception);
|
|
|
|
|
MessageBox.Show($"A uncaught exception was thrown: {exception.Message}. \n\n {exception.StackTrace}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
Current.Shutdown(1);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-08 12:41:21 +08:00
|
|
|
|
}
|
|
|
|
|
|