mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 21:24:18 +01:00
Make migration and immediate file saving somewhat more stable, actually dispose Framework.
This commit is contained in:
parent
ccfc05f2b2
commit
cb4f9f8131
3 changed files with 27 additions and 15 deletions
|
|
@ -139,7 +139,7 @@ public partial class Mod
|
||||||
|
|
||||||
foreach( var (group, index) in _groups.WithIndex() )
|
foreach( var (group, index) in _groups.WithIndex() )
|
||||||
{
|
{
|
||||||
IModGroup.SaveDelayed( group, ModPath, index );
|
IModGroup.Save( group, ModPath, index );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,16 @@ public sealed partial class Mod
|
||||||
private static class Migration
|
private static class Migration
|
||||||
{
|
{
|
||||||
public static bool Migrate( Mod mod, JObject json )
|
public static bool Migrate( Mod mod, JObject json )
|
||||||
=> MigrateV0ToV1( mod, json ) || MigrateV1ToV2( mod ) || MigrateV2ToV3( mod );
|
{
|
||||||
|
var ret = MigrateV0ToV1( mod, json ) || MigrateV1ToV2( mod ) || MigrateV2ToV3( mod );
|
||||||
|
if( ret )
|
||||||
|
{
|
||||||
|
// Immediately save on migration.
|
||||||
|
mod.SaveMetaFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
private static bool MigrateV2ToV3( Mod mod )
|
private static bool MigrateV2ToV3( Mod mod )
|
||||||
{
|
{
|
||||||
|
|
@ -27,10 +36,11 @@ public sealed partial class Mod
|
||||||
|
|
||||||
// Remove import time.
|
// Remove import time.
|
||||||
mod.FileVersion = 3;
|
mod.FileVersion = 3;
|
||||||
mod.SaveMeta();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static readonly Regex GroupRegex = new( @"group_\d{3}_", RegexOptions.Compiled );
|
||||||
private static bool MigrateV1ToV2( Mod mod )
|
private static bool MigrateV1ToV2( Mod mod )
|
||||||
{
|
{
|
||||||
if( mod.FileVersion > 1 )
|
if( mod.FileVersion > 1 )
|
||||||
|
|
@ -38,24 +48,26 @@ public sealed partial class Mod
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach( var (group, index) in mod.GroupFiles.WithIndex().ToArray() )
|
if (!mod.GroupFiles.All( g => GroupRegex.IsMatch( g.Name )))
|
||||||
{
|
{
|
||||||
var newName = Regex.Replace( group.Name, "^group_", $"group_{index + 1:D3}_", RegexOptions.Compiled );
|
foreach( var (group, index) in mod.GroupFiles.WithIndex().ToArray() )
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if( newName != group.Name )
|
var newName = Regex.Replace( group.Name, "^group_", $"group_{index + 1:D3}_", RegexOptions.Compiled );
|
||||||
|
try
|
||||||
{
|
{
|
||||||
group.MoveTo( Path.Combine( group.DirectoryName ?? string.Empty, newName ), false );
|
if( newName != group.Name )
|
||||||
|
{
|
||||||
|
group.MoveTo( Path.Combine( group.DirectoryName ?? string.Empty, newName ), false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch( Exception e )
|
||||||
|
{
|
||||||
|
Penumbra.Log.Error( $"Could not rename group file {group.Name} to {newName} during migration:\n{e}" );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
Penumbra.Log.Error( $"Could not rename group file {group.Name} to {newName} during migration:\n{e}" );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod.FileVersion = 2;
|
mod.FileVersion = 2;
|
||||||
mod.SaveMeta();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +140,7 @@ public sealed partial class Mod
|
||||||
|
|
||||||
mod.FileVersion = 1;
|
mod.FileVersion = 1;
|
||||||
mod.SaveDefaultMod();
|
mod.SaveDefaultMod();
|
||||||
mod.SaveMeta();
|
mod.SaveMetaFile();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ using System.Text;
|
||||||
using Dalamud.Game.Command;
|
using Dalamud.Game.Command;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Plugin;
|
using Dalamud.Plugin;
|
||||||
using Dalamud.Utility;
|
|
||||||
using EmbedIO;
|
using EmbedIO;
|
||||||
using EmbedIO.WebApi;
|
using EmbedIO.WebApi;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
|
|
@ -291,6 +290,7 @@ public class Penumbra : IDalamudPlugin
|
||||||
ObjectReloader?.Dispose();
|
ObjectReloader?.Dispose();
|
||||||
ModFileSystem?.Dispose();
|
ModFileSystem?.Dispose();
|
||||||
CollectionManager?.Dispose();
|
CollectionManager?.Dispose();
|
||||||
|
Framework?.Dispose();
|
||||||
|
|
||||||
Dalamud.Commands.RemoveHandler( CommandName );
|
Dalamud.Commands.RemoveHandler( CommandName );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue