From 0e93aeb17215e1d9e5587ce6ee01aa5887f1d207 Mon Sep 17 00:00:00 2001 From: 0neGal Date: Mon, 5 Feb 2024 00:00:41 +0100 Subject: fixed trying to remove core mods that dont exist Some code relating to removing core mods when updating/installing didn't account for `R2Northstar/mods` not even existing, thought I made checks for that already, managed to mess them up, oopsie whoopsie. --- src/modules/update.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/modules/update.js b/src/modules/update.js index 7140fcd..658e989 100644 --- a/src/modules/update.js +++ b/src/modules/update.js @@ -219,12 +219,17 @@ function remove_core_mods() { // make sure the "R2Northstar/mods" folder exists, on top of making // sure that, it is in fact a folder let mod_dir = path.join(settings().gamepath, "R2Northstar/mods"); - if (! fs.existsSync(mod_dir) && ! fs.statSync(mod_dir).isFile()) { - return + if (! fs.existsSync(mod_dir) || fs.statSync(mod_dir).isFile()) { + return; } - // get list of items in `mod_dir` - let mods = fs.readdirSync(mod_dir); + let mods = []; + let deleted_core_mods = false; + + try { + // try to get list of items in `mod_dir` + mods = fs.readdirSync(mod_dir); + }catch(err) {} // run through list for (let i = 0; i < mods.length; i++) { @@ -234,10 +239,15 @@ function remove_core_mods() { fs.rmSync(path.join(mod_dir, mods[i]), { recursive: true }) + + deleted_core_mods = true; } } - console.ok("Removed existing core mods!"); + // display message, if we even deleted any mods + if (deleted_core_mods) { + console.ok("Removed existing core mods!"); + } } // installs/Updates Northstar -- cgit v1.2.3