Skip to content

Commit

Permalink
Remove invalid mods from loaded mods
Browse files Browse the repository at this point in the history
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
  • Loading branch information
puppy-girl committed Nov 1, 2024
1 parent 397234f commit c4c441c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions GDWeave/Loader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -97,6 +107,8 @@ private void Sort() {
}

private void LoadAssemblies() {
var invalidMods = new List<LoadedMod>();

foreach (var loadedMod in this.LoadedMods) {
if (loadedMod.AssemblyPath is not { } assemblyPath) continue;

Expand All @@ -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) {
Expand Down

0 comments on commit c4c441c

Please sign in to comment.