forked from mipen/BannerlordTweaks
-
Notifications
You must be signed in to change notification settings - Fork 3
/
DebugHelpers.cs
81 lines (66 loc) · 2.6 KB
/
DebugHelpers.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
using System;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
namespace BannerlordTweaks {
public static class DebugHelpers {
[Conditional("DEBUG")]
public static void DebugMessage(string message) {
Message(message);
}
public static void Message(string message) {
InformationManager.DisplayMessage(new InformationMessage(message));
}
public static void ColorRedMessage(string message)
{
InformationManager.DisplayMessage(new InformationMessage(message, Color.ConvertStringToColor("#FF0042FF")));
}
public static void ColorGreenMessage(string message)
{
InformationManager.DisplayMessage(new InformationMessage(message, Color.ConvertStringToColor("#42FF00FF")));
}
public static void ColorBlueMessage(string message)
{
InformationManager.DisplayMessage(new InformationMessage(message, Color.ConvertStringToColor("#0042FFFF")));
}
public static void ColorOrangeMessage(string message)
{
InformationManager.DisplayMessage(new InformationMessage(message, Color.FromUint(0x00F16D26)));
}
public static void QuickInformationMessage(string message)
{
InformationManager.AddQuickInformation(new TextObject(message, null), 0, null, "");
}
// From Modlib---
public static void ShowError(string message, string title = "", Exception? exception = null) {
if (string.IsNullOrWhiteSpace(title)) {
title = "";
}
MessageBox.Show(message + "\n\n" + exception?.ToStringFull(), title);
}
public static string ToStringFull(this Exception ex) => ex != null ? GetString(ex) : "";
private static string GetString(Exception ex) {
StringBuilder sb = new StringBuilder();
GetStringRecursive(ex, sb);
sb.AppendLine();
sb.AppendLine("Stack trace:");
sb.AppendLine(ex.StackTrace);
return sb.ToString();
}
private static void GetStringRecursive(Exception ex, StringBuilder sb) {
while (true) {
sb.AppendLine(ex.GetType().Name + ":");
sb.AppendLine(ex.Message);
if (ex.InnerException == null) {
return;
}
sb.AppendLine();
ex = ex.InnerException;
}
}
// --------------
}
}