bugfix for loading deleted mods + safe saves

This commit is contained in:
⍚~Nex
2024-03-17 18:00:18 +01:00
parent c3691c8f08
commit 3de8fcc804
10 changed files with 56 additions and 49 deletions
+21 -2
View File
@@ -51,10 +51,11 @@ class ModsFolder {
*/
private static var __firstTime:Bool = true;
/**
* Initialises `mods` folder by adding callbacks and such.
* Initialises `mods` folder.
*/
public static function init() {
if(!getModsList().contains(Options.lastLoadedMod))
Options.lastLoadedMod = null;
}
/**
@@ -89,6 +90,24 @@ class ModsFolder {
#end
}
public static function getModsList():Array<String> {
var mods:Array<String> = [];
#if MOD_SUPPORT
for(modFolder in FileSystem.readDirectory(modsPath)) {
if (FileSystem.isDirectory('${modsPath}${modFolder}')) {
mods.push(modFolder);
} else {
var ext = Path.extension(modFolder).toLowerCase();
switch(ext) {
case 'zip':
// is a zip mod!!
mods.push(Path.withoutExtension(modFolder));
}
}
}
#end
return mods;
}
public static function getLoadedMods():Array<String> {
var libs = [];
for (i in Paths.assetsTree.libraries) {
+2 -2
View File
@@ -206,11 +206,11 @@ class Chart {
var chartPath = '${songFolderPath}/charts/${difficulty.trim()}.json';
var metaPath = '${songFolderPath}/meta.json';
File.saveContent(chartPath, Json.stringify(filteredChart, null, saveSettings.prettyPrint == true ? "\t" : null));
CoolUtil.safeSaveFile(chartPath, Json.stringify(filteredChart, null, saveSettings.prettyPrint == true ? "\t" : null));
// idk how null reacts to it so better be sure
if (saveSettings.overrideExistingMeta == true || !FileSystem.exists(metaPath))
File.saveContent(metaPath, Json.stringify(meta, null, saveSettings.prettyPrint == true ? "\t" : null));
CoolUtil.safeSaveFile(metaPath, Json.stringify(meta, null, saveSettings.prettyPrint == true ? "\t" : null));
#end
return filteredChart;
}
+1 -1
View File
@@ -120,7 +120,6 @@ class Main extends Sprite
ShaderResizeFix.init();
Logs.init();
Paths.init();
ModsFolder.init();
DiscordUtil.init();
#if GLOBAL_SCRIPT
funkin.backend.scripting.GlobalScript.init();
@@ -159,6 +158,7 @@ class Main extends Sprite
FlxG.mouse.useSystemCursor = true;
ModsFolder.init();
#if MOD_SUPPORT
ModsFolder.switchMod(modToLoad.getDefault(Options.lastLoadedMod));
#end
+16
View File
@@ -77,6 +77,22 @@ class CoolUtil
#end
}
/**
* Safe saves a file and shows a warning box instead of making the program crash
* @param path Path to save the file at.
* @param data Content of the file to save.
*/
@:noUsing public static function safeSaveFile(path:String, content:String, showErrorBox:Bool = true) {
#if sys
try sys.io.File.saveContent(path, content)
catch(e) {
var errMsg:String = 'Error while trying to save the file: ${Std.string(e).replace('\n', ' ')}';
Logs.traceColored([Logs.logText(errMsg, RED)], ERROR);
if(showErrorBox) funkin.backend.utils.NativeAPI.showMessageBox("Codename Engine Warning", errMsg, MSG_WARNING);
}
#end
}
/**
* Shortcut to parse a JSON string
* @param str Path to the JSON string