-
Notifications
You must be signed in to change notification settings - Fork 2
/
UnhandledException.xaml.cs
88 lines (75 loc) · 2.51 KB
/
UnhandledException.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
88
using System;
using System.Diagnostics;
using System.Text;
using System.Windows;
using FontAwesome5;
/// <remarks>
/// See Program.cs for license.
/// </remarks>
namespace TerrariaPixelArtHelper
{
/// <summary>
/// Interaction logic for UnhandledException.xaml
/// </summary>
public partial class UnhandledException : Window
{
new UnhandledExceptionViewModel DataContext => base.DataContext as UnhandledExceptionViewModel;
public UnhandledException(Exception exception)
{
this.InitializeComponent();
if (exception == null)
exception = new Exception("Exception missing???");
string exceptionType = exception.GetType().ToString();
string exceptionMessage = exception.Message;
this.DataContext.ExceptionType = exceptionType;
this.DataContext.ExceptionMessage = exceptionMessage;
var sb = new StringBuilder();
sb.AppendLine("************** Exception Text **************");
sb.AppendLine($"{exceptionType}: {exceptionMessage}");
sb.AppendLine(exception.StackTrace);
sb.AppendLine();
sb.AppendLine("************** Loaded Assemblies **************");
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
var sbAssembly = new StringBuilder();
try
{
var assemblyName = assembly.GetName();
sbAssembly.AppendLine(assemblyName.Name);
sbAssembly.AppendLine($" Assembly Version: {assemblyName.Version}");
sbAssembly.AppendLine($" Win32 Version: {FileVersionInfo.GetVersionInfo(assembly.Location).FileVersion}");
sbAssembly.AppendLine($" CodeBase: {assembly.CodeBase}");
sbAssembly.AppendLine("----------------------------------------");
}
catch
{
continue;
}
sb.Append(sbAssembly.ToString());
}
this.DataContext.DetailsText = sb.ToString();
}
void Continue_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
void Details_Click(object sender, RoutedEventArgs e) => this.DataContext.ShowDetails = !this.DataContext.ShowDetails;
void Quit_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.Close();
}
}
/// <summary>
/// The view model for <see cref="UnhandledException" />.
/// </summary>
class UnhandledExceptionViewModel
{
public EFontAwesomeIcon DetailsIcon => this.ShowDetails ? EFontAwesomeIcon.Solid_CaretUp : EFontAwesomeIcon.Solid_CaretDown;
public string DetailsText { get; set; }
public string ExceptionMessage { get; set; }
public string ExceptionType { get; set; }
public bool ShowDetails { get; set; }
}
}