diff --git a/Penumbra/Mods/Manager/ModDataEditor.cs b/Penumbra/Mods/Manager/ModDataEditor.cs index 91ae4a4c..7a0467d0 100644 --- a/Penumbra/Mods/Manager/ModDataEditor.cs +++ b/Penumbra/Mods/Manager/ModDataEditor.cs @@ -59,7 +59,7 @@ public class ModDataEditor(SaveService saveService, CommunicatorService communic importDate = json[nameof(Mod.ImportDate)]?.Value() ?? importDate; favorite = json[nameof(Mod.Favorite)]?.Value() ?? favorite; note = json[nameof(Mod.Note)]?.Value() ?? note; - localTags = json[nameof(Mod.LocalTags)]?.Values().OfType() ?? localTags; + localTags = (json[nameof(Mod.LocalTags)] as JArray)?.Values().OfType() ?? localTags; save = false; } catch (Exception e) @@ -119,7 +119,7 @@ public class ModDataEditor(SaveService saveService, CommunicatorService communic var newWebsite = json[nameof(Mod.Website)]?.Value() ?? string.Empty; var newFileVersion = json[nameof(ModMeta.FileVersion)]?.Value() ?? 0; var importDate = json[nameof(Mod.ImportDate)]?.Value(); - var modTags = json[nameof(Mod.ModTags)]?.Values().OfType(); + var modTags = (json[nameof(Mod.ModTags)] as JArray)?.Values().OfType(); ModDataChangeType changes = 0; if (mod.Name != newName) diff --git a/Penumbra/Mods/Manager/ModManager.cs b/Penumbra/Mods/Manager/ModManager.cs index 4b19ea4c..f170a31b 100644 --- a/Penumbra/Mods/Manager/ModManager.cs +++ b/Penumbra/Mods/Manager/ModManager.cs @@ -115,12 +115,21 @@ public sealed class ModManager : ModStorage, IDisposable, IService Penumbra.Log.Error($"Could not delete the mod {mod.ModPath.Name}:\n{e}"); } + RemoveMod(mod); + } + + /// + /// Remove a loaded mod. The event is invoked before the mod is removed from the list. + /// Does not delete the mod from the filesystem. + /// Updates indices of later mods. + /// + public void RemoveMod(Mod mod) + { _communicator.ModPathChanged.Invoke(ModPathChangeType.Deleted, mod, mod.ModPath, null); foreach (var remainingMod in Mods.Skip(mod.Index + 1)) --remainingMod.Index; Mods.RemoveAt(mod.Index); - - Penumbra.Log.Debug($"Deleted mod {mod.Name}."); + Penumbra.Log.Debug($"Removed loaded mod {mod.Name} from list."); } /// @@ -135,10 +144,9 @@ public sealed class ModManager : ModStorage, IDisposable, IService if (!Creator.ReloadMod(mod, true, out var metaChange)) { Penumbra.Log.Warning(mod.Name.Length == 0 - ? $"Reloading mod {oldName} has failed, new name is empty. Deleting instead." - : $"Reloading mod {oldName} failed, {mod.ModPath.FullName} does not exist anymore or it ha. Deleting instead."); - - DeleteMod(mod); + ? $"Reloading mod {oldName} has failed, new name is empty. Removing from loaded mods instead." + : $"Reloading mod {oldName} failed, {mod.ModPath.FullName} does not exist anymore or it has invalid data. Removing from loaded mods instead."); + RemoveMod(mod); return; }