Fix broken mods being deleted instead of removed. Fix tags crashing when null instead of empty.

This commit is contained in:
Ottermandias 2024-07-16 22:05:10 +02:00
parent 9c781f8563
commit 12dfaaef99
2 changed files with 16 additions and 8 deletions

View file

@ -59,7 +59,7 @@ public class ModDataEditor(SaveService saveService, CommunicatorService communic
importDate = json[nameof(Mod.ImportDate)]?.Value<long>() ?? importDate;
favorite = json[nameof(Mod.Favorite)]?.Value<bool>() ?? favorite;
note = json[nameof(Mod.Note)]?.Value<string>() ?? note;
localTags = json[nameof(Mod.LocalTags)]?.Values<string>().OfType<string>() ?? localTags;
localTags = (json[nameof(Mod.LocalTags)] as JArray)?.Values<string>().OfType<string>() ?? 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>() ?? string.Empty;
var newFileVersion = json[nameof(ModMeta.FileVersion)]?.Value<uint>() ?? 0;
var importDate = json[nameof(Mod.ImportDate)]?.Value<long>();
var modTags = json[nameof(Mod.ModTags)]?.Values<string>().OfType<string>();
var modTags = (json[nameof(Mod.ModTags)] as JArray)?.Values<string>().OfType<string>();
ModDataChangeType changes = 0;
if (mod.Name != newName)

View file

@ -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);
}
/// <summary>
/// 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.
/// </summary>
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.");
}
/// <summary>
@ -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;
}