mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-20 23:07:51 +01:00
Update mod loading structure.
This commit is contained in:
parent
3b8aac8eca
commit
5f8377acaa
5 changed files with 146 additions and 145 deletions
|
|
@ -1,5 +1,7 @@
|
|||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Penumbra.Mods.Editor;
|
||||
using Penumbra.Mods.Manager;
|
||||
using Penumbra.Services;
|
||||
|
||||
namespace Penumbra.Mods;
|
||||
|
|
@ -28,4 +30,85 @@ public readonly struct ModMeta(Mod mod) : ISavable
|
|||
jWriter.Formatting = Formatting.Indented;
|
||||
jObject.WriteTo(jWriter);
|
||||
}
|
||||
|
||||
public static ModDataChangeType Load(ModDataEditor editor, ModCreator creator, Mod mod)
|
||||
{
|
||||
var metaFile = editor.SaveService.FileNames.ModMetaPath(mod);
|
||||
if (!File.Exists(metaFile))
|
||||
{
|
||||
Penumbra.Log.Debug($"No mod meta found for {mod.ModPath.Name}.");
|
||||
return ModDataChangeType.Deletion;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var text = File.ReadAllText(metaFile);
|
||||
var json = JObject.Parse(text);
|
||||
|
||||
var newFileVersion = json[nameof(FileVersion)]?.Value<uint>() ?? 0;
|
||||
|
||||
// Empty name gets checked after loading and is not allowed.
|
||||
var newName = json[nameof(Mod.Name)]?.Value<string>() ?? string.Empty;
|
||||
|
||||
var newAuthor = json[nameof(Mod.Author)]?.Value<string>() ?? string.Empty;
|
||||
var newDescription = json[nameof(Mod.Description)]?.Value<string>() ?? string.Empty;
|
||||
var newImage = json[nameof(Mod.Image)]?.Value<string>() ?? string.Empty;
|
||||
var newVersion = json[nameof(Mod.Version)]?.Value<string>() ?? string.Empty;
|
||||
var newWebsite = json[nameof(Mod.Website)]?.Value<string>() ?? string.Empty;
|
||||
var modTags = (json[nameof(Mod.ModTags)] as JArray)?.Values<string>().OfType<string>();
|
||||
|
||||
ModDataChangeType changes = 0;
|
||||
if (mod.Name != newName)
|
||||
{
|
||||
changes |= ModDataChangeType.Name;
|
||||
mod.Name = newName;
|
||||
}
|
||||
|
||||
if (mod.Author != newAuthor)
|
||||
{
|
||||
changes |= ModDataChangeType.Author;
|
||||
mod.Author = newAuthor;
|
||||
}
|
||||
|
||||
if (mod.Description != newDescription)
|
||||
{
|
||||
changes |= ModDataChangeType.Description;
|
||||
mod.Description = newDescription;
|
||||
}
|
||||
|
||||
if (mod.Image != newImage)
|
||||
{
|
||||
changes |= ModDataChangeType.Image;
|
||||
mod.Image = newImage;
|
||||
}
|
||||
|
||||
if (mod.Version != newVersion)
|
||||
{
|
||||
changes |= ModDataChangeType.Version;
|
||||
mod.Version = newVersion;
|
||||
}
|
||||
|
||||
if (mod.Website != newWebsite)
|
||||
{
|
||||
changes |= ModDataChangeType.Website;
|
||||
mod.Website = newWebsite;
|
||||
}
|
||||
|
||||
if (newFileVersion != FileVersion)
|
||||
if (ModMigration.Migrate(creator, editor.SaveService, mod, json, ref newFileVersion))
|
||||
{
|
||||
changes |= ModDataChangeType.Migration;
|
||||
editor.SaveService.ImmediateSave(new ModMeta(mod));
|
||||
}
|
||||
|
||||
changes |= ModLocalData.UpdateTags(mod, modTags, null);
|
||||
|
||||
return changes;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Penumbra.Log.Error($"Could not load mod meta for {metaFile}:\n{e}");
|
||||
return ModDataChangeType.Deletion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue