diff --git a/Penumbra/Configuration.Migration.cs b/Penumbra/Configuration.Migration.cs index a62c091b..3eca3c07 100644 --- a/Penumbra/Configuration.Migration.cs +++ b/Penumbra/Configuration.Migration.cs @@ -47,6 +47,15 @@ public partial class Configuration m.Version1To2(); m.Version2To3(); 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. diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index 0e95a7f6..9b6381a7 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -8,7 +8,6 @@ using Newtonsoft.Json; using OtterGui; using OtterGui.Classes; using OtterGui.Filesystem; -using OtterGui.Widgets; using Penumbra.Import; using Penumbra.Mods; using Penumbra.UI; @@ -142,7 +141,7 @@ public partial class Configuration : IPluginConfiguration // Contains some default values or boundaries for config values. public static class Constants { - public const int CurrentVersion = 4; + public const int CurrentVersion = 5; public const float MaxAbsoluteSize = 600; public const int DefaultAbsoluteSize = 250; public const float MinAbsoluteSize = 50; diff --git a/Penumbra/Import/TexToolsImport.cs b/Penumbra/Import/TexToolsImport.cs index 3dcf5d47..98c1df0b 100644 --- a/Penumbra/Import/TexToolsImport.cs +++ b/Penumbra/Import/TexToolsImport.cs @@ -121,7 +121,7 @@ public partial class TexToolsImporter : IDisposable // Puts out warnings if extension does not correspond to data. 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 ); } diff --git a/Penumbra/Mods/Editor/ModBackup.cs b/Penumbra/Mods/Editor/ModBackup.cs index acc9e8af..fa353fd4 100644 --- a/Penumbra/Mods/Editor/ModBackup.cs +++ b/Penumbra/Mods/Editor/ModBackup.cs @@ -18,10 +18,39 @@ public class ModBackup public ModBackup( Mod mod ) { _mod = mod; - Name = mod.ModPath + ".zip"; + Name = _mod.ModPath + ".pmp"; 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. public async void CreateAsync() { diff --git a/Penumbra/Mods/Manager/Mod.Manager.Root.cs b/Penumbra/Mods/Manager/Mod.Manager.Root.cs index 92a8c51e..cec734ee 100644 --- a/Penumbra/Mods/Manager/Mod.Manager.Root.cs +++ b/Penumbra/Mods/Manager/Mod.Manager.Root.cs @@ -99,6 +99,11 @@ public sealed partial class Mod ModDiscoveryFinished?.Invoke(); PluginLog.Information( "Rediscovered mods." ); + + if( MigrateModBackups ) + { + ModBackup.MigrateZipToPmp( this ); + } } } } \ No newline at end of file diff --git a/Penumbra/Mods/Manager/Mod.Manager.cs b/Penumbra/Mods/Manager/Mod.Manager.cs index ff800473..11f878ca 100644 --- a/Penumbra/Mods/Manager/Mod.Manager.cs +++ b/Penumbra/Mods/Manager/Mod.Manager.cs @@ -9,6 +9,9 @@ public sealed partial class 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. // Mods are added when they are created or imported. // Mods are removed when they are deleted or when they are toggled in any collection. diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index e4081ba0..fdb59a91 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -143,7 +143,7 @@ public class Penumbra : IDalamudPlugin Dalamud.PluginInterface.UiBuilder.Draw += _windowSystem.Draw; 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 { @@ -165,10 +165,17 @@ public class Penumbra : IDalamudPlugin private void DisposeInterface() { - Dalamud.PluginInterface.UiBuilder.Draw -= _windowSystem.Draw; - Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle; + if( _windowSystem != null ) + { + Dalamud.PluginInterface.UiBuilder.Draw -= _windowSystem.Draw; + } + _launchButton?.Dispose(); - _configWindow?.Dispose(); + if( _configWindow != null ) + { + Dalamud.PluginInterface.UiBuilder.OpenConfigUi -= _configWindow.Toggle; + _configWindow.Dispose(); + } } public bool Enable() diff --git a/Penumbra/UI/Classes/ModFileSystemSelector.cs b/Penumbra/UI/Classes/ModFileSystemSelector.cs index be0d838b..9b83fc67 100644 --- a/Penumbra/UI/Classes/ModFileSystemSelector.cs +++ b/Penumbra/UI/Classes/ModFileSystemSelector.cs @@ -200,7 +200,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod private void AddImportModButton( Vector2 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 ); if( !button ) { @@ -213,7 +213,7 @@ public sealed partial class ModFileSystemSelector : FileSystemSelector< Mod, Mod _hasSetFolder = true; _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 ) {