Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
report proper exception strings and inner exceptions
Browse files Browse the repository at this point in the history
minor clean up
  • Loading branch information
Tyler-IN committed Apr 4, 2020
1 parent fd5d28b commit 12a3af7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
using System.Runtime;
using System.Runtime.InteropServices;
using System.Text;
using HardwareProviders;
using Helpers;
using TaleWorlds.Core;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.MountAndBlade;
using TaleWorlds.MountAndBlade.GauntletUI;

namespace CommunityPatch {

Expand All @@ -23,8 +18,14 @@ public static void CopyDiagnosticsToClipboard() {
sb.AppendLine("Recorded Unhandled Exceptions:");
var i = 0;
foreach (var exc in RecordedUnhandledExceptions) {
var excStr = RecordedUnhandledExceptions.ToString();
var excStr = exc.ToString();
sb.Append(" ").Append(++i).Append(". ").AppendLine(excStr.Replace("\n", "\n "));
var iex = exc;
var j = 0;
while (iex.InnerException != null) {
iex = iex.InnerException;
sb.Append(" ").Append(i).Append(".").Append(++j).Append(". ").AppendLine(excStr.Replace("\n", "\n "));
}
}

if (i == 0)
Expand All @@ -40,8 +41,14 @@ public static void CopyDiagnosticsToClipboard() {
sb.AppendLine("Recorded First Chance Exceptions:");
var i = 0;
foreach (var exc in RecordedFirstChanceExceptions) {
var excStr = RecordedFirstChanceExceptions.ToString();
var excStr = exc.ToString();
sb.Append(" ").Append(++i).Append(". ").AppendLine(excStr.Replace("\n", "\n "));
var iex = exc;
var j = 0;
while (iex.InnerException != null) {
iex = iex.InnerException;
sb.Append(" ").Append(i).Append(".").Append(++j).Append(". ").AppendLine(excStr.Replace("\n", "\n "));
}
}

if (RecordFirstChanceExceptions) {
Expand Down
23 changes: 20 additions & 3 deletions src/CommunityPatch/CommunityPatchSubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.MountAndBlade;
Expand All @@ -21,6 +22,8 @@ internal static readonly LinkedList<Exception> RecordedUnhandledExceptions

internal static readonly OptionsFile Options = new OptionsFile("CommunityPatch.txt");

internal static CampaignGameStarter CampaignGameStarter;

internal static bool DisableIntroVideo {
get => Options.Get<bool>(nameof(DisableIntroVideo));
set => Options.Set(nameof(DisableIntroVideo), value);
Expand Down Expand Up @@ -92,15 +95,22 @@ private void ShowModOptions()
null
),
new InquiryElement(
nameof(RecordedFirstChanceExceptions),
nameof(RecordFirstChanceExceptions),
DisableIntroVideo ? "Record First Chance Exceptions" : "Ignore First Chance Exceptions",
null
),
new InquiryElement(
nameof(CopyDiagnosticsToClipboard),
"Copy Diagnostics to Clipboard",
null
)
),
#if DEBUG
new InquiryElement(
"IntentionallyUnhandled",
"Throw Unhandled Exception",
null
),
#endif
},
true,
true,
Expand All @@ -116,7 +126,7 @@ private void ShowModOptions()
break;
case nameof(RecordFirstChanceExceptions):
RecordFirstChanceExceptions = !RecordFirstChanceExceptions;
ShowMessage($"Record FCEs: {(RecordFirstChanceExceptions ? "Disabled" : "Enabled")}.");
ShowMessage($"Record FCEs: {(RecordFirstChanceExceptions ? "Enabled" : "Disabled")}.");
Options.Save();
break;
case nameof(CopyDiagnosticsToClipboard):
Expand All @@ -127,6 +137,13 @@ private void ShowModOptions()
}
}, null));

public override void OnCampaignStart(Game game, object starterObject) {
if (starterObject is CampaignGameStarter cgs)
CampaignGameStarter = cgs;

base.OnCampaignStart(game, starterObject);
}

public override void OnGameInitializationFinished(Game game) {
var patchType = typeof(IPatch);
var patches = new LinkedList<IPatch>();
Expand Down
2 changes: 1 addition & 1 deletion src/CommunityPatch/OptionsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public OptionsFile(string fileName) {

[PublicAPI]
public void Save() {
using var sw = new StreamWriter(_path, false, Encoding.UTF8, 65536);
using var sw = new StreamWriter(_path, false, Encoding.UTF8, 65536) {NewLine = "\n"};
_toml.WriteTo(sw);
}

Expand Down
1 change: 0 additions & 1 deletion src/CommunityPatch/Patches/HealthyScoutPatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using TaleWorlds.Localization;
Expand Down
1 change: 0 additions & 1 deletion src/CommunityPatch/Patches/PeakFormPatch.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;
using TaleWorlds.Localization;
Expand Down
21 changes: 21 additions & 0 deletions src/CommunityPatch/Patches/VassalReleasePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#if false
using TaleWorlds.CampaignSystem;
using TaleWorlds.Core;

namespace CommunityPatch.Patches {

public class VassalReleasePatch : IPatch {

public bool IsApplicable(Game game)
=> Campaign.Current.ConversationManager.

public void Apply(Game game) {

game

}

}

}
#endif

0 comments on commit 12a3af7

Please sign in to comment.