Skip to content

Commit 21821ee

Browse files
author
FloppyDisk
committed
Add config menu and settings
1 parent 397b32d commit 21821ee

File tree

3 files changed

+60
-29
lines changed

3 files changed

+60
-29
lines changed

‎PulsarModLoader/CustomGUI/PMLSettings.cs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace PulsarModLoader.CustomGUI
1010
{
1111
class PMLSettings : ModSettingsMenu
1212
{
13+
1314
public override string Name() => "PulsarModLoader";
1415
public override void Draw()
1516
{
@@ -34,7 +35,28 @@ public override void Draw()
3435
PMLConfig.ModInfoTextAnchor.Value = Enum.GetValues(typeof(TextAnchor)).Cast<TextAnchor>().SkipWhile(e => (int)e != (int)PMLConfig.ModInfoTextAnchor.Value).Skip(1).First();
3536
}
3637
EndHorizontal();
38+
3739
if (Button("Reset to default")) PMLConfig.SetDefault();
40+
41+
//Zip Mod Settings
42+
HorizontalSlider(0, 100, 100);
43+
Label("Zip Mods");
44+
BeginHorizontal();
45+
Label($"Load Mods From Zips: {PMLConfig.ZipModLoad.Value}");
46+
if (Button("Toggle Loading Of Zip Mods"))
47+
{
48+
PMLConfig.ZipModLoad.Value = !PMLConfig.ZipModLoad.Value;
49+
}
50+
51+
EndHorizontal();
52+
BeginHorizontal();
53+
Label($"Keep Zips After Load: {PMLConfig.ZipModMode}");
54+
if (Button("Toggle Zip Mod Mode"))
55+
{
56+
PMLConfig.ZipModMode.Value = !PMLConfig.ZipModMode.Value;
57+
}
58+
EndHorizontal();
59+
HorizontalSlider(0, 100, 100);
3860
}
3961
}
40-
}
62+
}

‎PulsarModLoader/ModManager.cs‎

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -210,44 +210,50 @@ public void LoadModsDirectory(string modsDir)
210210
modDirectories.Add(modsDir);
211211

212212
//Unzip mods
213-
foreach (string ZipPath in Directory.GetFiles(modsDir, "*.zip"))
213+
if (PMLConfig.ZipModLoad)
214214
{
215-
//Get the full path from the mods dir path
216-
string ZipExtractPath = Path.GetFullPath(modsDir);
217-
218-
//Ensure that the mods dir path has a path seperator else add it.
219-
//This stops a path traversal attack from the zip file
220-
if (!ZipExtractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
215+
foreach (string ZipPath in Directory.GetFiles(modsDir, "*.zip"))
221216
{
222-
ZipExtractPath += Path.DirectorySeparatorChar;
223-
}
217+
//Get the full path from the mods dir path
218+
string ZipExtractPath = Path.GetFullPath(modsDir);
224219

225-
//Open zip file index and extract only dll files
226-
using (ZipArchive Archive = ZipFile.OpenRead(ZipPath))
227-
{
228-
foreach (ZipArchiveEntry Entry in Archive.Entries)
220+
//Ensure that the mods dir path has a path seperator else add it.
221+
//This stops a path traversal attack from the zip file
222+
if (!ZipExtractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
229223
{
230-
if (Entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
231-
{
232-
string DestinationPath = Path.GetFullPath(Path.Combine(modsDir, Entry.Name));
233-
234-
//If the mod exists, delete it and replace with this one.
235-
if (File.Exists(DestinationPath))
236-
{
237-
File.Delete(DestinationPath);
238-
}
224+
ZipExtractPath += Path.DirectorySeparatorChar;
225+
}
239226

240-
//Check the Destination is in the mods dir, then extract
241-
if (DestinationPath.StartsWith(modsDir, StringComparison.Ordinal))
227+
//Open zip file index and extract only dll files
228+
using (ZipArchive Archive = ZipFile.OpenRead(ZipPath))
229+
{
230+
foreach (ZipArchiveEntry Entry in Archive.Entries)
231+
{
232+
if (Entry.FullName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
242233
{
243-
Entry.ExtractToFile(DestinationPath);
234+
string DestinationPath = Path.GetFullPath(Path.Combine(modsDir, Entry.Name));
235+
236+
//If the mod exists, delete it and replace with this one.
237+
if (File.Exists(DestinationPath))
238+
{
239+
File.Delete(DestinationPath);
240+
}
241+
242+
//Check the Destination is in the mods dir, then extract
243+
if (DestinationPath.StartsWith(modsDir, StringComparison.Ordinal))
244+
{
245+
Entry.ExtractToFile(DestinationPath);
246+
}
244247
}
245248
}
246249
}
247-
}
248250

249-
//Delete Zip archive once we are done as we have the DLL's now
250-
File.Delete(ZipPath);
251+
//Delete Zip archive once we are done as we have the DLL's now
252+
if (PMLConfig.ZipModMode)
253+
{
254+
File.Delete(ZipPath);
255+
}
256+
}
251257
}
252258

253259
// Load mods

‎PulsarModLoader/PMLConfig.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public static class PMLConfig
1010

1111
public static SaveValue<bool> DebugMode = new SaveValue<bool>("DebugMode", false);
1212

13+
public static SaveValue<bool> ZipModLoad = new SaveValue<bool>("ZipModLoad", true);
14+
public static SaveValue<bool> ZipModMode = new SaveValue<bool>("ZipModMode", false);
15+
1316
public static SaveValue<DateTime> LastPMLUpdateCheck = new SaveValue<DateTime>("LastPMLUpdateCheck", DateTime.Today.AddDays(-2));
1417

1518
public static void SetDefault()

0 commit comments

Comments
 (0)