Skip to content

Commit 6da0703

Browse files
committed
Merge branch 'main' into BetterErrors
2 parents 3c75d48 + 044bcf5 commit 6da0703

35 files changed

Lines changed: 606 additions & 1196 deletions

CodeResources.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Reflection;
6+
using Serilog;
7+
8+
namespace ModShardLauncher
9+
{
10+
internal static class CodeResources
11+
{
12+
private static readonly Lazy<Dictionary<string, string>> _scripts = new(LoadAllScripts);
13+
public static string GetGML(string name)
14+
{
15+
if (_scripts.Value.TryGetValue(name, out var script)) return script;
16+
17+
throw new ArgumentException($"GML script '{name}' not found");
18+
}
19+
private static Dictionary<string, string> LoadAllScripts()
20+
{
21+
Dictionary<string, string> scripts = new();
22+
Assembly assembly = Assembly.GetExecutingAssembly();
23+
24+
// Load all .gml resources
25+
IEnumerable<string> resourceNames = assembly.GetManifestResourceNames()
26+
.Where(name => name.EndsWith(".gml"));
27+
foreach (string resourceName in resourceNames)
28+
{
29+
string? scriptName = Path.GetFileNameWithoutExtension(resourceName);
30+
31+
using Stream? stream =
32+
assembly.GetManifestResourceStream(resourceName) ??
33+
throw new FileNotFoundException($"GML script '{scriptName}' not found");
34+
using StreamReader reader = new(stream);
35+
scripts[scriptName.Split('.').Last()] = reader.ReadToEnd();
36+
}
37+
38+
return scripts;
39+
}
40+
}
41+
}

Controls/GeneralPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@
292292
</ComboBox>
293293
<Label Content="{DynamicResource SettingHeader_Log}" VerticalAlignment="Top" Margin="32,100,0,0"
294294
Style="{StaticResource xFont}" FontSize="12" Foreground="#95796A"/>
295-
<CheckBox HorizontalAlignment="Left" Margin="160,102,0,0" VerticalAlignment="Top" IsChecked="{Binding isEnabled, Mode=TwoWay}" Name="Logger"
295+
<CheckBox HorizontalAlignment="Left" Margin="160,102,0,0" VerticalAlignment="Top" IsChecked="{Binding Enabled, Mode=TwoWay}" Name="Logger"
296296
Checked="Logger_Checked" Unchecked="Logger_Checked">
297297
<CheckBox.Style>
298298
<Style TargetType="CheckBox">

Controls/ModBar.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<GridSplitter Width="2" Height="48" HorizontalAlignment="Center" VerticalAlignment="Bottom"
5252
Margin="12" Background="#33323F"/>
5353
<CheckBox HorizontalAlignment="Right" Margin="0,32,128,0" Content="{DynamicResource Enable}"
54-
FontFamily="{StaticResource ssFont}" Foreground="#FFFFFF" IsChecked="{Binding isEnabled, Mode=TwoWay}">
54+
FontFamily="{StaticResource ssFont}" Foreground="#FFFFFF" IsChecked="{Binding Enabled, Mode=TwoWay}">
5555
<CheckBox.Style>
5656
<Style TargetType="CheckBox">
5757
<Setter Property="IsChecked" Value="False"/>

Controls/ModInfos.xaml.cs

Lines changed: 4 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,7 +38,7 @@ private async void Save_Click(object sender, EventArgs e)
3638

3739
if (ModLoader.PatchFile())
3840
{
39-
Main.Instance.LogModList();
41+
Main.Instance.LogModListStatus();
4042
Log.Information("Successfully patch vanilla");
4143

4244
Task<bool> save = DataLoader.DoSaveDialog();
@@ -52,7 +54,7 @@ private async void Save_Click(object sender, EventArgs e)
5254
}
5355
else
5456
{
55-
Main.Instance.LogModList();
57+
Main.Instance.LogModListStatus();
5658
Log.Information("Failed patching vanilla");
5759
MessageBox.Show("Patching failed, more information can be found in the logs.", Application.Current.FindResource("SaveDataWarning").ToString());
5860
}

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
}

Extensions/ModShard.cs

Lines changed: 0 additions & 67 deletions
This file was deleted.

FileReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class ModSource
2424
{
2525
public string Name { get; set; }
2626
public string Path { get; set; }
27-
public bool isExisted => File.Exists(Path);
27+
public bool Existed => File.Exists(Path);
2828
public override string ToString()
2929
{
3030
return Name;
@@ -46,17 +46,17 @@ public class ModFile
4646
public FileStream Stream;
4747
public string Path;
4848
public Mod instance { get; set; }
49-
public bool isEnabled { get; set; }
49+
public bool Enabled { get; set; }
5050
public PatchStatus PatchStatus { get; set; } = PatchStatus.None;
51-
public bool isExisted => File.Exists(Path);
51+
public bool Existed => File.Exists(Path);
5252
public byte[] Icon { get; set; } = Array.Empty<byte>();
5353
public override string ToString()
5454
{
5555
return instance.ToString();
5656
}
5757
public byte[] GetFile(string fileName)
5858
{
59-
if(!isExisted)
59+
if(!Existed)
6060
{
6161
Log.Error("The mod {0} which was located at {1} does not exist anymore.", Name, Path);
6262
ModLoader.LoadFiles();

Main.xaml.cs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,31 @@ private void SetInitialSize()
130130
}
131131
}
132132

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

144-
case PatchStatus.Success:
145-
statusMessage = "Patching succeeded";
146-
break;
149+
case PatchStatus.Success:
150+
statusMessage = "Patching succeeded";
151+
break;
147152

148-
case PatchStatus.None:
149-
statusMessage = "Waiting to be patched";
150-
break;
151-
}
152-
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
153+
case PatchStatus.None:
154+
statusMessage = "Waiting to be patched";
155+
break;
153156
}
157+
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
154158
}
155159
private void MyToggleButton_Checked(object sender, EventArgs e)
156160
{
@@ -218,7 +222,7 @@ public class UserSettings
218222
{
219223
public string Language = "English";
220224
public bool EnableLogger = true;
221-
public List<string> EnableMods = new();
225+
public List<string> EnabledMods = new();
222226
public static void LoadSettings()
223227
{
224228
// if no settings file, early stop
@@ -232,16 +236,14 @@ public static void LoadSettings()
232236
CheckLog(Main.Settings.EnableLogger);
233237

234238
// auto check active mods
235-
if (Main.Settings.EnableMods.Count > 0)
239+
if (Main.Settings.EnabledMods.Count > 0)
236240
{
237241
List<ModFile> listModFile = ModInfos.Instance.Mods;
238-
foreach (string i in Main.Settings.EnableMods)
242+
foreach (string i in Main.Settings.EnabledMods)
239243
{
240244
(int indexMod, ModFile? modFile) = listModFile.Enumerate().FirstOrDefault(t => t.Item2.Name == i);
241-
if (modFile != null)
242-
listModFile[indexMod].isEnabled = true;
243-
else
244-
Log.Warning("Mod {0} not found", i);
245+
if (modFile != null) listModFile[indexMod].Enabled = true;
246+
else Log.Warning("Mod {0} not found", i);
245247
}
246248
}
247249
}

0 commit comments

Comments
 (0)