forked from HearthSim/Hearthstone-Deck-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
87 lines (78 loc) · 2.46 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
83
84
85
86
87
#region
#region
// ReSharper disable RedundantUsingDirective
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using Hearthstone_Deck_Tracker.Controls.Error;
using Hearthstone_Deck_Tracker.Plugins;
using Hearthstone_Deck_Tracker.Utility.Extensions;
using Hearthstone_Deck_Tracker.Windows;
using Squirrel;
#endregion
#endregion
namespace Hearthstone_Deck_Tracker
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private static bool _createdReport;
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var plugin = PluginManager.Instance.Plugins.FirstOrDefault(p => new FileInfo(p.FileName).Name.Replace(".dll", "") == e.Exception.Source);
if(plugin != null)
{
var incompatibleExceptions = new[]
{
typeof(MissingMethodException), typeof(MissingFieldException),
typeof(MissingMemberException), typeof(TypeLoadException)
};
string header;
if(incompatibleExceptions.Any(x => e.Exception.GetType() == x))
{
plugin.IsEnabled = false;
header = $"{plugin.NameAndVersion} is not compatible with HDT {Helper.GetCurrentVersion().ToVersionString()}.";
}
else if(plugin.UnhandledException())
{
plugin.IsEnabled = false;
header = $"{plugin.NameAndVersion} threw too many exceptions and has been disabled.";
}
else
header = $"{plugin.NameAndVersion} threw an exception.";
ErrorManager.AddError(header, "Make sure you are using the latest version of the Plugin and HDT.\n\n" + e.Exception);
e.Handled = true;
return;
}
if(!_createdReport)
{
_createdReport = true;
new CrashDialog(e.Exception).ShowDialog();
#if(!DEBUG)
var date = DateTime.Now;
var fileName = "Crash Reports\\" + $"Crash report {date.Day}{date.Month}{date.Year}-{date.Hour}{date.Minute}";
if(!Directory.Exists("Crash Reports"))
Directory.CreateDirectory("Crash Reports");
using(var sr = new StreamWriter(fileName + ".txt", true))
{
sr.WriteLine("########## " + DateTime.Now + " ##########");
sr.WriteLine(e.Exception);
sr.WriteLine(Core.MainWindow.Options.OptionsTrackerLogging.TextBoxLog.Text);
}
#endif
e.Handled = true;
Shutdown();
}
e.Handled = true;
}
private void App_OnStartup(object sender, StartupEventArgs e)
{
ShutdownMode = ShutdownMode.OnExplicitShutdown;
Core.Initialize();
}
}
}