mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-19 14:27:50 +01:00
More Stuff.
This commit is contained in:
parent
ef9022a746
commit
ccdafcf85d
8 changed files with 49 additions and 52 deletions
|
|
@ -120,7 +120,7 @@ public class ModDataEditor
|
|||
var newDescription = json[nameof(Mod.Description)]?.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 newFileVersion = json[nameof(Mod.FileVersion)]?.Value<uint>() ?? 0;
|
||||
var newFileVersion = json[nameof(Mod.ModMeta.FileVersion)]?.Value<uint>() ?? 0;
|
||||
var importDate = json[nameof(Mod.ImportDate)]?.Value<long>();
|
||||
var modTags = json[nameof(Mod.ModTags)]?.Values<string>().OfType<string>();
|
||||
|
||||
|
|
@ -155,10 +155,9 @@ public class ModDataEditor
|
|||
mod.Website = newWebsite;
|
||||
}
|
||||
|
||||
if (mod.FileVersion != newFileVersion)
|
||||
if (newFileVersion != Mod.ModMeta.FileVersion)
|
||||
{
|
||||
mod.FileVersion = newFileVersion;
|
||||
if (Mod.Migration.Migrate(mod, json))
|
||||
if (Mod.Migration.Migrate(mod, json, ref newFileVersion))
|
||||
{
|
||||
changes |= ModDataChangeType.Migration;
|
||||
_saveService.ImmediateSave(new Mod.ModMeta(mod));
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ public sealed partial class Mod
|
|||
|
||||
internal readonly struct ModData : ISavable
|
||||
{
|
||||
public const int FileVersion = 3;
|
||||
|
||||
private readonly Mod _mod;
|
||||
|
||||
public ModData(Mod mod)
|
||||
|
|
@ -66,7 +68,7 @@ public sealed partial class Mod
|
|||
{
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ nameof(FileVersion), JToken.FromObject(_mod.FileVersion) },
|
||||
{ nameof(FileVersion), JToken.FromObject(FileVersion) },
|
||||
{ nameof(ImportDate), JToken.FromObject(_mod.ImportDate) },
|
||||
{ nameof(LocalTags), JToken.FromObject(_mod.LocalTags) },
|
||||
{ nameof(Note), JToken.FromObject(_mod.Note) },
|
||||
|
|
|
|||
|
|
@ -15,31 +15,34 @@ public sealed partial class Mod
|
|||
{
|
||||
public static partial class Migration
|
||||
{
|
||||
public static bool Migrate(Mod mod, JObject json)
|
||||
=> MigrateV0ToV1(mod, json) || MigrateV1ToV2(mod) || MigrateV2ToV3(mod);
|
||||
|
||||
private static bool MigrateV2ToV3(Mod mod)
|
||||
{
|
||||
if (mod.FileVersion > 2)
|
||||
return false;
|
||||
|
||||
// Remove import time.
|
||||
mod.FileVersion = 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"group_\d{3}_", RegexOptions.Compiled | RegexOptions.NonBacktracking | RegexOptions.ExplicitCapture)]
|
||||
private static partial Regex GroupRegex();
|
||||
|
||||
private static bool MigrateV1ToV2(Mod mod)
|
||||
[GeneratedRegex("^group_", RegexOptions.Compiled)]
|
||||
private static partial Regex GroupStartRegex();
|
||||
|
||||
public static bool Migrate(Mod mod, JObject json, ref uint fileVersion)
|
||||
=> MigrateV0ToV1(mod, json, ref fileVersion) || MigrateV1ToV2(mod, ref fileVersion) || MigrateV2ToV3(mod, ref fileVersion);
|
||||
|
||||
private static bool MigrateV2ToV3(Mod _, ref uint fileVersion)
|
||||
{
|
||||
if (mod.FileVersion > 1)
|
||||
if (fileVersion > 2)
|
||||
return false;
|
||||
|
||||
// Remove import time.
|
||||
fileVersion = 3;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool MigrateV1ToV2(Mod mod, ref uint fileVersion)
|
||||
{
|
||||
if (fileVersion > 1)
|
||||
return false;
|
||||
|
||||
if (!mod.GroupFiles.All(g => GroupRegex().IsMatch(g.Name)))
|
||||
foreach (var (group, index) in mod.GroupFiles.WithIndex().ToArray())
|
||||
{
|
||||
var newName = Regex.Replace(group.Name, "^group_", $"group_{index + 1:D3}_", RegexOptions.Compiled);
|
||||
var newName = GroupStartRegex().Replace(group.Name, $"group_{index + 1:D3}_");
|
||||
try
|
||||
{
|
||||
if (newName != group.Name)
|
||||
|
|
@ -51,14 +54,14 @@ public sealed partial class Mod
|
|||
}
|
||||
}
|
||||
|
||||
mod.FileVersion = 2;
|
||||
fileVersion = 2;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool MigrateV0ToV1(Mod mod, JObject json)
|
||||
private static bool MigrateV0ToV1(Mod mod, JObject json, ref uint fileVersion)
|
||||
{
|
||||
if (mod.FileVersion > 0)
|
||||
if (fileVersion > 0)
|
||||
return false;
|
||||
|
||||
var swaps = json["FileSwaps"]?.ToObject<Dictionary<Utf8GamePath, FullPath>>()
|
||||
|
|
@ -110,7 +113,7 @@ public sealed partial class Mod
|
|||
Penumbra.Log.Warning($"Could not delete old meta file {oldMetaFile} during migration:\n{e}");
|
||||
}
|
||||
|
||||
mod.FileVersion = 1;
|
||||
fileVersion = 1;
|
||||
mod.SaveDefaultMod();
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ public sealed partial class Mod : IMod
|
|||
Priority = int.MaxValue,
|
||||
};
|
||||
|
||||
public const uint CurrentFileVersion = 3;
|
||||
public uint FileVersion { get; internal set; } = CurrentFileVersion;
|
||||
public LowerString Name { get; internal set; } = "New Mod";
|
||||
public LowerString Author { get; internal set; } = LowerString.Empty;
|
||||
public string Description { get; internal set; } = string.Empty;
|
||||
|
|
@ -32,6 +30,8 @@ public sealed partial class Mod : IMod
|
|||
|
||||
internal readonly struct ModMeta : ISavable
|
||||
{
|
||||
public const uint FileVersion = 3;
|
||||
|
||||
private readonly Mod _mod;
|
||||
|
||||
public ModMeta(Mod mod)
|
||||
|
|
@ -44,7 +44,7 @@ public sealed partial class Mod : IMod
|
|||
{
|
||||
var jObject = new JObject
|
||||
{
|
||||
{ nameof(FileVersion), JToken.FromObject(_mod.FileVersion) },
|
||||
{ nameof(FileVersion), JToken.FromObject(FileVersion) },
|
||||
{ nameof(Name), JToken.FromObject(_mod.Name) },
|
||||
{ nameof(Author), JToken.FromObject(_mod.Author) },
|
||||
{ nameof(Description), JToken.FromObject(_mod.Description) },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue