From c4c441c0e9f7ba6ee0b48210540e3f3128d57057 Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 1 Nov 2024 14:11:22 +1100 Subject: [PATCH] Remove invalid mods from loaded mods Assembly mods that fail to load will be removed from loaded mods Mods with an invalid assembly or pack path will return a warning and won't be included in loaded mods --- GDWeave/Loader/ModLoader.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/GDWeave/Loader/ModLoader.cs b/GDWeave/Loader/ModLoader.cs index 0379ff1..56a7710 100644 --- a/GDWeave/Loader/ModLoader.cs +++ b/GDWeave/Loader/ModLoader.cs @@ -51,6 +51,16 @@ private void Register() { : null }; + if (loadedMod.AssemblyPath != null && !File.Exists(loadedMod.AssemblyPath)) { + this.logger.Warning("Assembly at {AssemblyPath} does not exist", loadedMod.AssemblyPath); + continue; + } + + if (loadedMod.PackPath != null && !File.Exists(loadedMod.PackPath)) { + this.logger.Warning("Pack file at {PackPath} does not exist", loadedMod.PackPath); + continue; + } + this.LoadedMods.Add(loadedMod); } catch (Exception e) { this.logger.Warning(e, "Failed to load mod at {ModDir}", modDir); @@ -97,6 +107,8 @@ private void Sort() { } private void LoadAssemblies() { + var invalidMods = new List(); + foreach (var loadedMod in this.LoadedMods) { if (loadedMod.AssemblyPath is not { } assemblyPath) continue; @@ -107,8 +119,13 @@ private void LoadAssemblies() { loadedMod.AssemblyMod = assemblyMod; } catch (Exception e) { this.logger.Warning(e, "Failed to load assembly for mod {ModId}", loadedMod.Manifest.Id); + invalidMods.Add(loadedMod); } } + + foreach (var invalidMod in invalidMods) { + this.LoadedMods.Remove(invalidMod); + } } private IMod? LoadAssembly(string id, string assemblyPath) {