Skip to content

Commit 97869fb

Browse files
committed
[Minor] adding diagnostic class to sum up code behaviour upon failing, first rework of the error windowbox
1 parent 6da0703 commit 97869fb

5 files changed

Lines changed: 63 additions & 21 deletions

File tree

Controls/ModInfos.xaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading.Tasks;
77
using System.Windows;
88
using System.Windows.Controls;
9+
using ModShardLauncher.Core.Errors;
910
using ModShardLauncher.Mods;
1011
using Serilog;
1112

@@ -36,7 +37,9 @@ private async void Save_Click(object sender, EventArgs e)
3637
return;
3738
}
3839

39-
if (ModLoader.PatchFile())
40+
MSLDiagnostic? diag = ModLoader.PatchFile();
41+
42+
if (diag is null)
4043
{
4144
Main.Instance.LogModListStatus();
4245
Log.Information("Successfully patch vanilla");
@@ -56,7 +59,9 @@ private async void Save_Click(object sender, EventArgs e)
5659
{
5760
Main.Instance.LogModListStatus();
5861
Log.Information("Failed patching vanilla");
59-
MessageBox.Show("Patching failed, more information can be found in the logs.", Application.Current.FindResource("SaveDataWarning").ToString());
62+
string messageBoxText = "Do you want to save changes?";
63+
string caption = diag.Title();
64+
MessageBox.Show(messageBoxText, caption);
6065
}
6166

6267
// reload the data

Core/Errors/MSLDiagnostic.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using Serilog;
3+
4+
namespace ModShardLauncher.Core.Errors
5+
{
6+
public class MSLDiagnostic
7+
{
8+
public string ModName;
9+
public string? FileName;
10+
public string? PatchingMethod;
11+
public Exception exception;
12+
public MSLDiagnostic(Exception ex, ModFile modFile)
13+
{
14+
if (ex.Data.Contains("fileName"))
15+
{
16+
object? fileName = ex.Data["fileName"];
17+
FileName = $"{fileName}";
18+
}
19+
if (ex.Data.Contains("patchingWay"))
20+
{
21+
object? patchingWay = ex.Data["patchingWay"];
22+
PatchingMethod = $"{patchingWay}";
23+
}
24+
ModName = modFile.Name;
25+
exception = ex;
26+
}
27+
public void ToLog()
28+
{
29+
string extraInformation = " for {{{0}}}";
30+
if (FileName is not null)
31+
{
32+
extraInformation += " in file {{{1}}}";
33+
}
34+
if (PatchingMethod is not null)
35+
{
36+
extraInformation += " while patching by {{{2}}}";
37+
}
38+
Log.Error(exception, "Something went wrong" + extraInformation, ModName, FileName, PatchingMethod);
39+
}
40+
public string Title()
41+
{
42+
return $"{ModName} failed";
43+
}
44+
}
45+
}

Main.xaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ public static void LogModStatus(ModFile modFile)
156156
}
157157
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
158158
}
159+
public ModFile GetFailingMod()
160+
{
161+
return ModPage.Mods.Where(x => x.Enabled).First(x => x.PatchStatus == PatchStatus.Patching); ;
162+
}
159163
private void MyToggleButton_Checked(object sender, EventArgs e)
160164
{
161165
foreach (var i in stackPanel.Children)

ModLoader.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using UndertaleModLib.Models;
1414
using ModShardLauncher.Controls;
1515
using Serilog;
16+
using ModShardLauncher.Core.Errors;
1617

1718
namespace ModShardLauncher
1819
{
@@ -183,7 +184,7 @@ public static void PatchMods()
183184
Msl.ChainDisclaimerRooms(Disclaimers);
184185
Msl.CreateMenu(Menus);
185186
}
186-
public static bool PatchFile()
187+
public static MSLDiagnostic? PatchFile()
187188
{
188189
try
189190
{
@@ -192,26 +193,13 @@ public static bool PatchFile()
192193
PatchMods();
193194
// add the new loot related functions if there is any
194195
LootUtils.InjectLootScripts();
195-
return true;
196+
return null;
196197
}
197198
catch (Exception ex)
198199
{
199-
string extraInformation = "";
200-
object? fileName = null;
201-
object? patchingWay = null;
202-
if (ex.Data.Contains("fileName"))
203-
{
204-
fileName = ex.Data["fileName"];
205-
extraInformation += " in file {{{0}}}";
206-
}
207-
if (ex.Data.Contains("patchingWay"))
208-
{
209-
patchingWay = ex.Data["patchingWay"];
210-
extraInformation += " while patching by {{{1}}}";
211-
}
212-
213-
Log.Error(ex, "Something went wrong" + extraInformation, fileName, patchingWay);
214-
return false;
200+
MSLDiagnostic diag = new(ex, Main.Instance.GetFailingMod());
201+
diag.ToLog();
202+
return diag;
215203
}
216204
}
217205
}

ModShardLauncher.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<Compile Include="Mods/*.cs" />
2222
<Compile Include="Controls/*.cs" />
2323
<Compile Include="ModUtils/*.cs" />
24-
<Compile Include="Core/TopologicalOrdering/*.cs" />
24+
<Compile Include="Core/**/*.cs" />
2525
</ItemGroup>
2626

2727
<ItemGroup>

0 commit comments

Comments
 (0)