Add Penumbra Mod Pack file ending and migration.

This commit is contained in:
Ottermandias 2022-09-08 15:49:02 +02:00
parent 5eda2d3a23
commit 7b7f241923
8 changed files with 62 additions and 10 deletions

View file

@ -47,6 +47,15 @@ public partial class Configuration
m.Version1To2(); m.Version1To2();
m.Version2To3(); m.Version2To3();
m.Version3To4(); m.Version3To4();
m.Version4To5();
}
// Mod backup extension was changed from .zip to .pmp.
// Actual migration takes place in ModManager.
private void Version4To5()
{
Mod.Manager.MigrateModBackups = true;
_config.Version = 5;
} }
// SortMode was changed from an enum to a type. // SortMode was changed from an enum to a type.

View file

@ -8,7 +8,6 @@ using Newtonsoft.Json;
using OtterGui; using OtterGui;
using OtterGui.Classes; using OtterGui.Classes;
using OtterGui.Filesystem; using OtterGui.Filesystem;
using OtterGui.Widgets;
using Penumbra.Import; using Penumbra.Import;
using Penumbra.Mods; using Penumbra.Mods;
using Penumbra.UI; using Penumbra.UI;
@ -142,7 +141,7 @@ public partial class Configuration : IPluginConfiguration
// Contains some default values or boundaries for config values. // Contains some default values or boundaries for config values.
public static class Constants public static class Constants
{ {
public const int CurrentVersion = 4; public const int CurrentVersion = 5;
public const float MaxAbsoluteSize = 600; public const float MaxAbsoluteSize = 600;
public const int DefaultAbsoluteSize = 250; public const int DefaultAbsoluteSize = 250;
public const float MinAbsoluteSize = 50; public const float MinAbsoluteSize = 50;

View file

@ -121,7 +121,7 @@ public partial class TexToolsImporter : IDisposable
// Puts out warnings if extension does not correspond to data. // Puts out warnings if extension does not correspond to data.
private DirectoryInfo VerifyVersionAndImport( FileInfo modPackFile ) private DirectoryInfo VerifyVersionAndImport( FileInfo modPackFile )
{ {
if( modPackFile.Extension is ".zip" or ".7z" or ".rar" ) if( modPackFile.Extension.ToLowerInvariant() is ".pmp" or ".zip" or ".7z" or ".rar" )
{ {
return HandleRegularArchive( modPackFile ); return HandleRegularArchive( modPackFile );
} }

View file

@ -18,10 +18,39 @@ public class ModBackup
public ModBackup( Mod mod ) public ModBackup( Mod mod )
{ {
_mod = mod; _mod = mod;
Name = mod.ModPath + ".zip"; Name = _mod.ModPath + ".pmp";
Exists = File.Exists( Name ); Exists = File.Exists( Name );
} }
// Migrate file extensions.
public static void MigrateZipToPmp(Mod.Manager manager)
{
foreach( var mod in manager )
{
var pmpName = mod.ModPath + ".pmp";
var zipName = mod.ModPath + ".zip";
if( File.Exists( zipName ) )
{
try
{
if( !File.Exists( pmpName ) )
{
File.Move( zipName, pmpName );
}
else
{
File.Delete( zipName );
}
PluginLog.Information( $"Migrated mod backup from {zipName} to {pmpName}." );
}
catch( Exception e )
{
PluginLog.Warning( $"Could not migrate mod backup of {mod.ModPath} from .pmp to .zip:\n{e}" );
}
}
}
}
// Create a backup zip without blocking the main thread. // Create a backup zip without blocking the main thread.
public async void CreateAsync() public async void CreateAsync()
{ {

View file

@ -99,6 +99,11 @@ public sealed partial class Mod
ModDiscoveryFinished?.Invoke(); ModDiscoveryFinished?.Invoke();
PluginLog.Information( "Rediscovered mods." ); PluginLog.Information( "Rediscovered mods." );
if( MigrateModBackups )
{
ModBackup.MigrateZipToPmp( this );
}
} }
} }
} }

View file

@ -9,6 +9,9 @@ public sealed partial class Mod
{ {
public sealed partial class Manager : IReadOnlyList< Mod > public sealed partial class Manager : IReadOnlyList< Mod >
{ {
// Set when reading Config and migrating from v4 to v5.
public static bool MigrateModBackups = false;
// An easily accessible set of new mods. // An easily accessible set of new mods.
// Mods are added when they are created or imported. // Mods are added when they are created or imported.
// Mods are removed when they are deleted or when they are toggled in any collection. // Mods are removed when they are deleted or when they are toggled in any collection.

View file

@ -143,7 +143,7 @@ public class Penumbra : IDalamudPlugin
Dalamud.PluginInterface.UiBuilder.Draw += _windowSystem.Draw; Dalamud.PluginInterface.UiBuilder.Draw += _windowSystem.Draw;
OtterTex.NativeDll.Initialize( Dalamud.PluginInterface.AssemblyLocation.DirectoryName ); OtterTex.NativeDll.Initialize( Dalamud.PluginInterface.AssemblyLocation.DirectoryName );
PluginLog.Information( $"Loading native assembly from {OtterTex.NativeDll.Directory}." ); PluginLog.Information( $"Loading native OtterTex assembly from {OtterTex.NativeDll.Directory}." );
} }
catch catch
{ {
@ -165,10 +165,17 @@ public class Penumbra : IDalamudPlugin
private void DisposeInterface() private void DisposeInterface()
{ {
Dalamud.PluginInterface.UiBuilder.Draw -= _windowSystem.Draw; if( _windowSystem != null )
Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle; {
Dalamud.PluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
}
_launchButton?.Dispose(); _launchButton?.Dispose();
_configWindow?.Dispose(); if( _configWindow != null )
{
Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle;
_configWindow.Dispose();
}
} }
public bool Enable() public bool Enable()

View file

@ -200,7 +200,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod
private void AddImportModButton( Vector2 size ) private void AddImportModButton( Vector2 size )
{ {
var button = ImGuiUtil.DrawDisabledButton( FontAwesomeIcon.FileImport.ToIconString(), size, var button = ImGuiUtil.DrawDisabledButton( FontAwesomeIcon.FileImport.ToIconString(), size,
"Import one or multiple mods from Tex Tools Mod Pack Files.", !Penumbra.ModManager.Valid, true ); "Import one or multiple mods from Tex Tools Mod Pack Files or Penumbra Mod Pack Files.", !Penumbra.ModManager.Valid, true );
ConfigWindow.OpenTutorial( ConfigWindow.BasicTutorialSteps.ModImport ); ConfigWindow.OpenTutorial( ConfigWindow.BasicTutorialSteps.ModImport );
if( !button ) if( !button )
{ {
@ -213,7 +213,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod
_hasSetFolder = true; _hasSetFolder = true;
_fileManager.OpenFileDialog( "Import Mod Pack", _fileManager.OpenFileDialog( "Import Mod Pack",
"Mod Packs{.ttmp,.ttmp2,.zip,.7z,.rar},TexTools Mod Packs{.ttmp,.ttmp2},Archives{.zip,.7z,.rar}", ( s, f ) => "Mod Packs{.ttmp,.ttmp2,.pmp},TexTools Mod Packs{.ttmp,.ttmp2},Penumbra Mod Packs{.pmp},Archives{.zip,.7z,.rar}", ( s, f ) =>
{ {
if( s ) if( s )
{ {