Skip to content

Commit

Permalink
Merge pull request #10 from puppy-girl/main
Browse files Browse the repository at this point in the history
Remove invalid mods from loaded mods
  • Loading branch information
NotNite authored Nov 1, 2024
2 parents 397234f + c4c441c commit 5ed074a
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 5ed074a

Please sign in to comment.