Skip to content

Commit 1759d93

Browse files
committed
[Minor] removing saving button in modsource page, improving logging
1 parent 863a818 commit 1759d93

5 files changed

Lines changed: 27 additions & 57 deletions

File tree

Controls/ModInfos.xaml.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
5+
using System.Linq;
46
using System.Threading.Tasks;
57
using System.Windows;
68
using System.Windows.Controls;
@@ -36,16 +38,19 @@ private async void Save_Click(object sender, EventArgs e)
3638

3739
bool patchSucess = false;
3840

41+
Stopwatch watch = Stopwatch.StartNew();
3942
try
4043
{
4144
ModLoader.PatchFile();
45+
long elapsedMs = watch.ElapsedMilliseconds;
46+
Main.Instance.LogModListStatus();
47+
Log.Information("Patching lasts {{{0}}} ms", elapsedMs);
4248
Log.Information("Successfully patch vanilla");
4349
patchSucess = true;
44-
Main.Instance.LogModList();
4550
}
4651
catch (Exception ex)
4752
{
48-
Main.Instance.LogModList();
53+
Main.Instance.LogModListStatus();
4954
Log.Error(ex, "Something went wrong");
5055
Log.Information("Failed patching vanilla");
5156
MessageBox.Show(ex.ToString(), Application.Current.FindResource("SaveDataWarning").ToString());

Controls/ModSourceInfos.xaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@
1919
<ImageBrush x:Key="OverSource" ImageSource="/Resources/Sprites/open_over.png"/>
2020
</controls:MyToggleButton.Resources>
2121
</controls:MyToggleButton>
22-
<controls:MyToggleButton ImageSource="/Resources/Sprites/save.png" Click="Save_Click" ToolTip="Save Data File"
23-
Margin="64,0,0,0">
24-
<controls:MyToggleButton.Resources>
25-
<ImageBrush x:Key="DownSource" ImageSource="/Resources/Sprites/save_down.png"/>
26-
<ImageBrush x:Key="OverSource" ImageSource="/Resources/Sprites/save_over.png"/>
27-
</controls:MyToggleButton.Resources>
28-
</controls:MyToggleButton>
2922
<Border BorderBrush="#43424D" BorderThickness="2"/>
3023
</Grid>
3124
<controls:MyItemsControl MaxHeight="672" Height="672" x:Name="SourceList"

Controls/ModSourceInfos.xaml.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,5 @@ private async void Open_Click(object sender, EventArgs e)
2323
await DataLoader.DoOpenDialog();
2424
Main.Instance.Refresh();
2525
}
26-
private async void Save_Click(object sender, EventArgs e)
27-
{
28-
if (DataLoader.data.FORM == null)
29-
{
30-
MessageBox.Show(Application.Current.FindResource("LoadDataWarning").ToString());
31-
return;
32-
}
33-
34-
bool patchSucess = false;
35-
36-
try
37-
{
38-
ModLoader.PatchFile();
39-
Log.Information("Successfully patch vanilla");
40-
patchSucess = true;
41-
Main.Instance.LogModList();
42-
}
43-
catch(Exception ex)
44-
{
45-
Main.Instance.LogModList();
46-
Log.Error(ex, "Something went wrong");
47-
Log.Information("Failed patching vanilla");
48-
MessageBox.Show(ex.ToString(), Application.Current.FindResource("SaveDataWarning").ToString());
49-
}
50-
51-
if (patchSucess) await DataLoader.DoSaveDialog();
52-
Main.Instance.Refresh();
53-
}
5426
}
5527
}

Main.xaml.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,31 @@ private void SetInitialSize()
131131
}
132132
}
133133

134-
public void LogModList()
134+
public void LogModListStatus()
135135
{
136136
foreach (ModFile modFile in ModPage.Mods.Where(x => x.Enabled))
137137
{
138-
string statusMessage = "";
139-
switch (modFile.PatchStatus)
140-
{
141-
case PatchStatus.Patching:
142-
statusMessage = "Patching failed";
143-
break;
138+
LogModStatus(modFile);
139+
}
140+
}
141+
public static void LogModStatus(ModFile modFile)
142+
{
143+
string statusMessage = "";
144+
switch (modFile.PatchStatus)
145+
{
146+
case PatchStatus.Patching:
147+
statusMessage = "Patching failed";
148+
break;
144149

145-
case PatchStatus.Success:
146-
statusMessage = "Patching succeeded";
147-
break;
150+
case PatchStatus.Success:
151+
statusMessage = "Patching succeeded";
152+
break;
148153

149-
case PatchStatus.None:
150-
statusMessage = "Waiting to be patched";
151-
break;
152-
}
153-
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
154+
case PatchStatus.None:
155+
statusMessage = "Waiting to be patched";
156+
break;
154157
}
158+
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
155159
}
156160
private void MyToggleButton_Checked(object sender, EventArgs e)
157161
{

ModLoader.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public static void PatchMods()
172172
List<ModFile> mods = ModInfos.Instance.Mods;
173173
Menus = new();
174174

175-
Stopwatch watch = Stopwatch.StartNew();
176175
foreach (ModFile mod in mods)
177176
{
178177
if (!mod.Enabled) continue;
@@ -192,14 +191,11 @@ public static void PatchMods()
192191
TextureLoader.LoadTextures(mod);
193192
mod.instance.PatchMod();
194193
mod.PatchStatus = PatchStatus.Success;
194+
Main.LogModStatus(mod);
195195
}
196196
Msl.AddDisclaimerRoom(Credits.Select(x => x.Item1).ToArray(), Credits.SelectMany(x => x.Item2).Distinct().ToArray());
197197
Msl.ChainDisclaimerRooms(Disclaimers);
198198
Msl.CreateMenu(Menus);
199-
200-
watch.Stop();
201-
long elapsedMs = watch.ElapsedMilliseconds;
202-
Log.Information("Patching lasts {{{0}}} ms", elapsedMs);
203199
}
204200
public static void PatchFile()
205201
{

0 commit comments

Comments
 (0)