forked from HearthSim/Hearthstone-Deck-Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
76 lines (66 loc) · 2.69 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
#region
#region
// ReSharper disable RedundantUsingDirective
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Threading;
using Garlic;
using Hearthstone_Deck_Tracker.Controls.Error;
using Hearthstone_Deck_Tracker.Plugins;
using Hearthstone_Deck_Tracker.Utility.Extensions;
#endregion
#endregion
namespace Hearthstone_Deck_Tracker
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
if(e.Exception is MissingMethodException || e.Exception is TypeLoadException)
{
var plugin =
PluginManager.Instance.Plugins.FirstOrDefault(p => new FileInfo(p.FileName).Name.Replace(".dll", "") == e.Exception.Source);
if(plugin != null)
{
plugin.IsEnabled = false;
var header = $"{plugin.NameAndVersion} is not compatible with HDT {Helper.GetCurrentVersion().ToVersionString()}.";
ErrorManager.AddError(header, "Make sure you are using the latest version of the Plugin and HDT.\n\n" + e.Exception);
e.Handled = true;
return;
}
}
var stackTrace = e.Exception.StackTrace.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
Analytics.Analytics.TrackEvent(e.Exception.GetType().ToString().Split('.').Last(), stackTrace.Length > 0 ? stackTrace[0] : "",
stackTrace.Length > 1 ? stackTrace[1] : "");
#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);
}
MessageBox.Show(e.Exception.Message + "\n\n" +
"A crash report file was created at:\n\"" + Environment.CurrentDirectory + "\\" + fileName
+ ".txt\"\n\nPlease \na) create an issue on github (https://github.com/Epix37/Hearthstone-Deck-Tracker) \nor \nb) send an email to support@hsdecktracker.net.\n\nPlease include the generated crash report(s) and a short explanation of what lead to the crash.",
"Oops! Something went wrong.", MessageBoxButton.OK, MessageBoxImage.Error);
e.Handled = true;
Shutdown();
#endif
}
private void App_OnStartup(object sender, StartupEventArgs e)
{
ShutdownMode = ShutdownMode.OnExplicitShutdown;
Core.Initialize();
}
}
}