From 174e640c45c7c94c9f1a40cf6dcc78801122594f Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 23 Mar 2023 21:43:40 +0100 Subject: [PATCH] Move TexTools around. --- Penumbra/Configuration.cs | 2 +- Penumbra/Import/MetaFileInfo.cs | 122 ---------------- .../Import/{ => Structs}/ImporterState.cs | 2 +- Penumbra/Import/Structs/MetaFileInfo.cs | 104 +++++++++++++ .../Import/{ => Structs}/StreamDisposer.cs | 8 +- .../Import/{ => Structs}/TexToolsStructs.cs | 28 ++-- Penumbra/Import/TexToolsImport.cs | 2 + Penumbra/Import/TexToolsImporter.Archives.cs | 1 + Penumbra/Import/TexToolsImporter.Gui.cs | 1 + Penumbra/Import/TexToolsImporter.ModPack.cs | 1 + .../Import/TexToolsMeta.Deserialization.cs | 1 + Penumbra/Import/TexToolsMeta.cs | 1 + Penumbra/Import/Textures/Texture.cs | 1 - Penumbra/Import/Textures/TextureImporter.cs | 6 +- .../Interop/Services/CharacterUtility.List.cs | 4 +- Penumbra/Mods/Editor/ModBackup.cs | 137 +++++++++--------- Penumbra/Mods/Editor/ModEditor.cs | 16 +- Penumbra/Mods/Mod.Creator.cs | 2 +- Penumbra/UI/ModsTab/ModFileSystemSelector.cs | 1 + 19 files changed, 212 insertions(+), 228 deletions(-) delete mode 100644 Penumbra/Import/MetaFileInfo.cs rename Penumbra/Import/{ => Structs}/ImporterState.cs (77%) create mode 100644 Penumbra/Import/Structs/MetaFileInfo.cs rename Penumbra/Import/{ => Structs}/StreamDisposer.cs (74%) rename Penumbra/Import/{ => Structs}/TexToolsStructs.cs (69%) diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index 54ae8ac5..b1468c2c 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -9,7 +9,7 @@ using OtterGui.Classes; using OtterGui.Filesystem; using OtterGui.Widgets; using Penumbra.GameData.Enums; -using Penumbra.Import; +using Penumbra.Import.Structs; using Penumbra.Mods; using Penumbra.Services; using Penumbra.UI; diff --git a/Penumbra/Import/MetaFileInfo.cs b/Penumbra/Import/MetaFileInfo.cs deleted file mode 100644 index 99a4ff9b..00000000 --- a/Penumbra/Import/MetaFileInfo.cs +++ /dev/null @@ -1,122 +0,0 @@ -using Penumbra.GameData.Enums; -using System.Text.RegularExpressions; -using Penumbra.GameData; - -namespace Penumbra.Import; - -// Obtain information what type of object is manipulated -// by the given .meta file from TexTools, using its name. -public class MetaFileInfo -{ - private const string Pt = @"(?'PrimaryType'[a-z]*)"; // language=regex - private const string Pp = @"(?'PrimaryPrefix'[a-z])"; // language=regex - private const string Pi = @"(?'PrimaryId'\d{4})"; // language=regex - private const string Pir = @"\k'PrimaryId'"; // language=regex - private const string St = @"(?'SecondaryType'[a-z]*)"; // language=regex - private const string Sp = @"(?'SecondaryPrefix'[a-z])"; // language=regex - private const string Si = @"(?'SecondaryId'\d{4})"; // language=regex - private const string File = @"\k'PrimaryPrefix'\k'PrimaryId'(\k'SecondaryPrefix'\k'SecondaryId')?"; // language=regex - private const string Slot = @"(_(?'Slot'[a-z]{3}))?"; // language=regex - private const string Ext = @"\.meta"; - - // These are the valid regexes for .meta files that we are able to support at the moment. - private static readonly Regex HousingMeta = new($"bgcommon/hou/{Pt}/general/{Pi}/{Pir}{Ext}", RegexOptions.Compiled); - private static readonly Regex CharaMeta = new($"chara/{Pt}/{Pp}{Pi}(/obj/{St}/{Sp}{Si})?/{File}{Slot}{Ext}", RegexOptions.Compiled); - - public readonly ObjectType PrimaryType; - public readonly BodySlot SecondaryType; - public readonly ushort PrimaryId; - public readonly ushort SecondaryId; - public readonly EquipSlot EquipSlot = EquipSlot.Unknown; - public readonly CustomizationType CustomizationType = CustomizationType.Unknown; - - private static bool ValidType( ObjectType type ) - { - return type switch - { - ObjectType.Accessory => true, - ObjectType.Character => true, - ObjectType.Equipment => true, - ObjectType.DemiHuman => true, - ObjectType.Housing => true, - ObjectType.Monster => true, - ObjectType.Weapon => true, - ObjectType.Icon => false, - ObjectType.Font => false, - ObjectType.Interface => false, - ObjectType.LoadingScreen => false, - ObjectType.Map => false, - ObjectType.Vfx => false, - ObjectType.Unknown => false, - ObjectType.World => false, - _ => false, - }; - } - - public MetaFileInfo( IGamePathParser parser, string fileName ) - { - // Set the primary type from the gamePath start. - PrimaryType = parser.PathToObjectType( fileName ); - PrimaryId = 0; - SecondaryType = BodySlot.Unknown; - SecondaryId = 0; - // Not all types of objects can have valid meta data manipulation. - if( !ValidType( PrimaryType ) ) - { - PrimaryType = ObjectType.Unknown; - return; - } - - // Housing files have a separate regex that just contains the primary id. - if( PrimaryType == ObjectType.Housing ) - { - var housingMatch = HousingMeta.Match( fileName ); - if( housingMatch.Success ) - { - PrimaryId = ushort.Parse( housingMatch.Groups[ "PrimaryId" ].Value ); - } - - return; - } - - // Non-housing is in chara/. - var match = CharaMeta.Match( fileName ); - if( !match.Success ) - { - return; - } - - // The primary ID has to be available for every object. - PrimaryId = ushort.Parse( match.Groups[ "PrimaryId" ].Value ); - - // Depending on slot, we can set equip slot or customization type. - if( match.Groups[ "Slot" ].Success ) - { - switch( PrimaryType ) - { - case ObjectType.Equipment: - case ObjectType.Accessory: - if( Names.SuffixToEquipSlot.TryGetValue( match.Groups[ "Slot" ].Value, out var tmpSlot ) ) - { - EquipSlot = tmpSlot; - } - - break; - case ObjectType.Character: - if( Names.SuffixToCustomizationType.TryGetValue( match.Groups[ "Slot" ].Value, out var tmpCustom ) ) - { - CustomizationType = tmpCustom; - } - - break; - } - } - - // Secondary type and secondary id are for weapons and demihumans. - if( match.Groups[ "SecondaryType" ].Success - && Names.StringToBodySlot.TryGetValue( match.Groups[ "SecondaryType" ].Value, out SecondaryType ) ) - { - SecondaryId = ushort.Parse( match.Groups[ "SecondaryId" ].Value ); - } - } -} \ No newline at end of file diff --git a/Penumbra/Import/ImporterState.cs b/Penumbra/Import/Structs/ImporterState.cs similarity index 77% rename from Penumbra/Import/ImporterState.cs rename to Penumbra/Import/Structs/ImporterState.cs index 8d576f97..9ab2ab9a 100644 --- a/Penumbra/Import/ImporterState.cs +++ b/Penumbra/Import/Structs/ImporterState.cs @@ -1,4 +1,4 @@ -namespace Penumbra.Import; +namespace Penumbra.Import.Structs; public enum ImporterState { diff --git a/Penumbra/Import/Structs/MetaFileInfo.cs b/Penumbra/Import/Structs/MetaFileInfo.cs new file mode 100644 index 00000000..3af2db34 --- /dev/null +++ b/Penumbra/Import/Structs/MetaFileInfo.cs @@ -0,0 +1,104 @@ +using Penumbra.GameData.Enums; +using System.Text.RegularExpressions; +using Penumbra.GameData; + +namespace Penumbra.Import.Structs; + +/// +/// Obtain information what type of object is manipulated +/// by the given .meta file from TexTools, using its name. +/// +public partial struct MetaFileInfo +{ + // These are the valid regexes for .meta files that we are able to support at the moment. + [GeneratedRegex(@"bgcommon/hou/(?'Type1'[a-z]*)/general/(?'Id1'\d{4})/\k'Id1'\.meta", + RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.NonBacktracking)] + private static partial Regex HousingMeta(); + + [GeneratedRegex( + @"chara/(?'Type1'[a-z]*)/(?'Pre1'[a-z])(?'Id1'\d{4})(/obj/(?'Type2'[a-z]*)/(?'Pre2'[a-z])(?'Id2'\d{4}))?/\k'Pre1'\k'Id1'(\k'Pre2'\k'Id2')?(_(?'Slot'[a-z]{3}))?\\.meta", + RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.NonBacktracking)] + private static partial Regex CharaMeta(); + + public readonly ObjectType PrimaryType; + public readonly BodySlot SecondaryType; + public readonly ushort PrimaryId; + public readonly ushort SecondaryId; + public readonly EquipSlot EquipSlot = EquipSlot.Unknown; + public readonly CustomizationType CustomizationType = CustomizationType.Unknown; + + private static bool ValidType(ObjectType type) + => type switch + { + ObjectType.Accessory => true, + ObjectType.Character => true, + ObjectType.Equipment => true, + ObjectType.DemiHuman => true, + ObjectType.Housing => true, + ObjectType.Monster => true, + ObjectType.Weapon => true, + ObjectType.Icon => false, + ObjectType.Font => false, + ObjectType.Interface => false, + ObjectType.LoadingScreen => false, + ObjectType.Map => false, + ObjectType.Vfx => false, + ObjectType.Unknown => false, + ObjectType.World => false, + _ => false, + }; + + public MetaFileInfo(IGamePathParser parser, string fileName) + { + // Set the primary type from the gamePath start. + PrimaryType = parser.PathToObjectType(fileName); + PrimaryId = 0; + SecondaryType = BodySlot.Unknown; + SecondaryId = 0; + // Not all types of objects can have valid meta data manipulation. + if (!ValidType(PrimaryType)) + { + PrimaryType = ObjectType.Unknown; + return; + } + + // Housing files have a separate regex that just contains the primary id. + if (PrimaryType == ObjectType.Housing) + { + var housingMatch = HousingMeta().Match(fileName); + if (housingMatch.Success) + PrimaryId = ushort.Parse(housingMatch.Groups["Id1"].Value); + + return; + } + + // Non-housing is in chara/. + var match = CharaMeta().Match(fileName); + if (!match.Success) + return; + + // The primary ID has to be available for every object. + PrimaryId = ushort.Parse(match.Groups["Id1"].Value); + + // Depending on slot, we can set equip slot or customization type. + if (match.Groups["Slot"].Success) + switch (PrimaryType) + { + case ObjectType.Equipment: + case ObjectType.Accessory: + if (Names.SuffixToEquipSlot.TryGetValue(match.Groups["Slot"].Value, out var tmpSlot)) + EquipSlot = tmpSlot; + + break; + case ObjectType.Character: + if (Names.SuffixToCustomizationType.TryGetValue(match.Groups["Slot"].Value, out var tmpCustom)) + CustomizationType = tmpCustom; + + break; + } + + // Secondary type and secondary id are for weapons and demihumans. + if (match.Groups["Type2"].Success && Names.StringToBodySlot.TryGetValue(match.Groups["Type2"].Value, out SecondaryType)) + SecondaryId = ushort.Parse(match.Groups["Id2"].Value); + } +} diff --git a/Penumbra/Import/StreamDisposer.cs b/Penumbra/Import/Structs/StreamDisposer.cs similarity index 74% rename from Penumbra/Import/StreamDisposer.cs rename to Penumbra/Import/Structs/StreamDisposer.cs index fb5ccef4..65c67585 100644 --- a/Penumbra/Import/StreamDisposer.cs +++ b/Penumbra/Import/Structs/StreamDisposer.cs @@ -2,15 +2,15 @@ using Penumbra.Util; using System; using System.IO; -namespace Penumbra.Import; +namespace Penumbra.Import.Structs; // Create an automatically disposing SqPack stream. public class StreamDisposer : PenumbraSqPackStream, IDisposable { private readonly FileStream _fileStream; - public StreamDisposer( FileStream stream ) - : base( stream ) + public StreamDisposer(FileStream stream) + : base(stream) => _fileStream = stream; public new void Dispose() @@ -20,6 +20,6 @@ public class StreamDisposer : PenumbraSqPackStream, IDisposable base.Dispose(); _fileStream.Dispose(); - File.Delete( filePath ); + File.Delete(filePath); } } \ No newline at end of file diff --git a/Penumbra/Import/TexToolsStructs.cs b/Penumbra/Import/Structs/TexToolsStructs.cs similarity index 69% rename from Penumbra/Import/TexToolsStructs.cs rename to Penumbra/Import/Structs/TexToolsStructs.cs index da01dda2..cdd70c53 100644 --- a/Penumbra/Import/TexToolsStructs.cs +++ b/Penumbra/Import/Structs/TexToolsStructs.cs @@ -1,7 +1,7 @@ using System; using Penumbra.Api.Enums; -namespace Penumbra.Import; +namespace Penumbra.Import.Structs; internal static class DefaultTexToolsData { @@ -27,7 +27,7 @@ internal class SimpleMod internal class ModPackPage { public int PageIndex = 0; - public ModGroup[] ModGroups = Array.Empty< ModGroup >(); + public ModGroup[] ModGroups = Array.Empty(); } [Serializable] @@ -35,7 +35,7 @@ internal class ModGroup { public string GroupName = string.Empty; public GroupType SelectionType = GroupType.Single; - public OptionList[] OptionList = Array.Empty< OptionList >(); + public OptionList[] OptionList = Array.Empty(); public string Description = string.Empty; } @@ -45,7 +45,7 @@ internal class OptionList public string Name = string.Empty; public string Description = string.Empty; public string ImagePath = string.Empty; - public SimpleMod[] ModsJsons = Array.Empty< SimpleMod >(); + public SimpleMod[] ModsJsons = Array.Empty(); public string GroupName = string.Empty; public GroupType SelectionType = GroupType.Single; public bool IsChecked = false; @@ -60,18 +60,18 @@ internal class ExtendedModPack public string Version = string.Empty; public string Description = DefaultTexToolsData.Description; public string Url = string.Empty; - public ModPackPage[] ModPackPages = Array.Empty< ModPackPage >(); - public SimpleMod[] SimpleModsList = Array.Empty< SimpleMod >(); + public ModPackPage[] ModPackPages = Array.Empty(); + public SimpleMod[] SimpleModsList = Array.Empty(); } [Serializable] internal class SimpleModPack { - public string TtmpVersion = string.Empty; - public string Name = DefaultTexToolsData.Name; - public string Author = DefaultTexToolsData.Author; - public string Version = string.Empty; - public string Description = DefaultTexToolsData.Description; - public string Url = string.Empty; - public SimpleMod[] SimpleModsList = Array.Empty< SimpleMod >(); -} \ No newline at end of file + public string TtmpVersion = string.Empty; + public string Name = DefaultTexToolsData.Name; + public string Author = DefaultTexToolsData.Author; + public string Version = string.Empty; + public string Description = DefaultTexToolsData.Description; + public string Url = string.Empty; + public SimpleMod[] SimpleModsList = Array.Empty(); +} diff --git a/Penumbra/Import/TexToolsImport.cs b/Penumbra/Import/TexToolsImport.cs index 89672cf1..548cf90a 100644 --- a/Penumbra/Import/TexToolsImport.cs +++ b/Penumbra/Import/TexToolsImport.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -6,6 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; +using Penumbra.Import.Structs; using Penumbra.Mods; using FileMode = System.IO.FileMode; using ZipArchive = SharpCompress.Archives.Zip.ZipArchive; diff --git a/Penumbra/Import/TexToolsImporter.Archives.cs b/Penumbra/Import/TexToolsImporter.Archives.cs index 9d9f5a69..c986cc78 100644 --- a/Penumbra/Import/TexToolsImporter.Archives.cs +++ b/Penumbra/Import/TexToolsImporter.Archives.cs @@ -2,6 +2,7 @@ using Dalamud.Utility; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OtterGui.Filesystem; +using Penumbra.Import.Structs; using Penumbra.Mods; using SharpCompress.Archives; using SharpCompress.Archives.Rar; diff --git a/Penumbra/Import/TexToolsImporter.Gui.cs b/Penumbra/Import/TexToolsImporter.Gui.cs index bf997c2c..8c5ad81b 100644 --- a/Penumbra/Import/TexToolsImporter.Gui.cs +++ b/Penumbra/Import/TexToolsImporter.Gui.cs @@ -3,6 +3,7 @@ using System.Numerics; using ImGuiNET; using OtterGui; using OtterGui.Raii; +using Penumbra.Import.Structs; using Penumbra.UI.Classes; namespace Penumbra.Import; diff --git a/Penumbra/Import/TexToolsImporter.ModPack.cs b/Penumbra/Import/TexToolsImporter.ModPack.cs index 33e3c918..fd141ef3 100644 --- a/Penumbra/Import/TexToolsImporter.ModPack.cs +++ b/Penumbra/Import/TexToolsImporter.ModPack.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; using Penumbra.Api.Enums; +using Penumbra.Import.Structs; using Penumbra.Mods; using Penumbra.Util; using SharpCompress.Archives.Zip; diff --git a/Penumbra/Import/TexToolsMeta.Deserialization.cs b/Penumbra/Import/TexToolsMeta.Deserialization.cs index 252a1720..e97312b0 100644 --- a/Penumbra/Import/TexToolsMeta.Deserialization.cs +++ b/Penumbra/Import/TexToolsMeta.Deserialization.cs @@ -3,6 +3,7 @@ using System.IO; using Lumina.Extensions; using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; +using Penumbra.Import.Structs; using Penumbra.Meta.Files; using Penumbra.Meta.Manipulations; diff --git a/Penumbra/Import/TexToolsMeta.cs b/Penumbra/Import/TexToolsMeta.cs index fd01de02..cbf1e9fa 100644 --- a/Penumbra/Import/TexToolsMeta.cs +++ b/Penumbra/Import/TexToolsMeta.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using Penumbra.GameData; +using Penumbra.Import.Structs; using Penumbra.Meta.Manipulations; namespace Penumbra.Import; diff --git a/Penumbra/Import/Textures/Texture.cs b/Penumbra/Import/Textures/Texture.cs index 669f81d7..d37c8967 100644 --- a/Penumbra/Import/Textures/Texture.cs +++ b/Penumbra/Import/Textures/Texture.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Numerics; using Dalamud.Interface; -using Dalamud.Interface.ImGuiFileDialog; using ImGuiNET; using ImGuiScene; using Lumina.Data.Files; diff --git a/Penumbra/Import/Textures/TextureImporter.cs b/Penumbra/Import/Textures/TextureImporter.cs index 7e62830f..74bef485 100644 --- a/Penumbra/Import/Textures/TextureImporter.cs +++ b/Penumbra/Import/Textures/TextureImporter.cs @@ -1,10 +1,10 @@ +using System; +using System.IO; using Lumina.Data.Files; using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; -using System; -using System.IO; -namespace Penumbra.Import.Dds; +namespace Penumbra.Import.Textures; public static class TextureImporter { diff --git a/Penumbra/Interop/Services/CharacterUtility.List.cs b/Penumbra/Interop/Services/CharacterUtility.List.cs index 3e847c0f..1fc33efb 100644 --- a/Penumbra/Interop/Services/CharacterUtility.List.cs +++ b/Penumbra/Interop/Services/CharacterUtility.List.cs @@ -82,7 +82,7 @@ public unsafe partial class CharacterUtility ResetResourceInternal(); } - // Set the currently stored data of this resource to new values. + /// Set the currently stored data of this resource to new values. private void SetResourceInternal(nint data, int length) { if (!Ready) @@ -92,7 +92,7 @@ public unsafe partial class CharacterUtility resource->SetData(data, length); } - // Reset the currently stored data of this resource to its default values. + /// Reset the currently stored data of this resource to its default values. private void ResetResourceInternal() => SetResourceInternal(_defaultResourceData, _defaultResourceSize); diff --git a/Penumbra/Mods/Editor/ModBackup.cs b/Penumbra/Mods/Editor/ModBackup.cs index fe533489..21f8792b 100644 --- a/Penumbra/Mods/Editor/ModBackup.cs +++ b/Penumbra/Mods/Editor/ModBackup.cs @@ -5,141 +5,136 @@ using System.Threading.Tasks; namespace Penumbra.Mods; -// Utility to create and apply a zipped backup of a mod. +/// Utility to create and apply a zipped backup of a mod. public class ModBackup { public static bool CreatingBackup { get; private set; } - private readonly Mod _mod; - public readonly string Name; - public readonly bool Exists; + private readonly Mod.Manager _modManager; + private readonly Mod _mod; + public readonly string Name; + public readonly bool Exists; - public ModBackup( Mod.Manager modManager, Mod mod ) + public ModBackup(Mod.Manager modManager, Mod mod) { - _mod = mod; - Name = Path.Combine( modManager.ExportDirectory.FullName, _mod.ModPath.Name ) + ".pmp"; - Exists = File.Exists( Name ); + _modManager = modManager; + _mod = mod; + Name = Path.Combine(_modManager.ExportDirectory.FullName, _mod.ModPath.Name) + ".pmp"; + Exists = File.Exists(Name); } - // Migrate file extensions. - public static void MigrateZipToPmp( Mod.Manager manager ) + /// Migrate file extensions. + public static void MigrateZipToPmp(Mod.Manager manager) { - foreach( var mod in 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 ); - } + if (!File.Exists(zipName)) + continue; - Penumbra.Log.Information( $"Migrated mod export from {zipName} to {pmpName}." ); - } - catch( Exception e ) - { - Penumbra.Log.Warning( $"Could not migrate mod export of {mod.ModPath} from .pmp to .zip:\n{e}" ); - } + try + { + if (!File.Exists(pmpName)) + File.Move(zipName, pmpName); + else + File.Delete(zipName); + + Penumbra.Log.Information($"Migrated mod export from {zipName} to {pmpName}."); + } + catch (Exception e) + { + Penumbra.Log.Warning($"Could not migrate mod export of {mod.ModPath} from .pmp to .zip:\n{e}"); } } } - // Move and/or rename an exported mod. - // This object is unusable afterwards. - public void Move( string? newBasePath = null, string? newName = null ) + /// + /// Move and/or rename an exported mod. + /// This object is unusable afterwards. + /// + public void Move(string? newBasePath = null, string? newName = null) { - if( CreatingBackup || !Exists ) - { + if (CreatingBackup || !Exists) return; - } try { - newBasePath ??= Path.GetDirectoryName( Name ) ?? string.Empty; - newName = newName == null ? Path.GetFileName( Name ) : newName + ".pmp"; - var newPath = Path.Combine( newBasePath, newName ); - File.Move( Name, newPath ); + newBasePath ??= Path.GetDirectoryName(Name) ?? string.Empty; + newName = newName == null ? Path.GetFileName(Name) : newName + ".pmp"; + var newPath = Path.Combine(newBasePath, newName); + File.Move(Name, newPath); } - catch( Exception e ) + catch (Exception e) { - Penumbra.Log.Warning( $"Could not move mod export file {Name}:\n{e}" ); + Penumbra.Log.Warning($"Could not move mod export file {Name}:\n{e}"); } } - // Create a backup zip without blocking the main thread. + /// Create a backup zip without blocking the main thread. public async void CreateAsync() { - if( CreatingBackup ) - { + if (CreatingBackup) return; - } CreatingBackup = true; - await Task.Run( Create ); + await Task.Run(Create); CreatingBackup = false; } - - // Create a backup. Overwrites pre-existing backups. + /// Create a backup. Overwrites pre-existing backups. private void Create() { try { Delete(); - ZipFile.CreateFromDirectory( _mod.ModPath.FullName, Name, CompressionLevel.Optimal, false ); - Penumbra.Log.Debug( $"Created export file {Name} from {_mod.ModPath.FullName}." ); + ZipFile.CreateFromDirectory(_mod.ModPath.FullName, Name, CompressionLevel.Optimal, false); + Penumbra.Log.Debug($"Created export file {Name} from {_mod.ModPath.FullName}."); } - catch( Exception e ) + catch (Exception e) { - Penumbra.Log.Error( $"Could not export mod {_mod.Name} to \"{Name}\":\n{e}" ); + Penumbra.Log.Error($"Could not export mod {_mod.Name} to \"{Name}\":\n{e}"); } } - // Delete a pre-existing backup. + /// Delete a pre-existing backup. public void Delete() { - if( !Exists ) - { + if (!Exists) return; - } try { - File.Delete( Name ); - Penumbra.Log.Debug( $"Deleted export file {Name}." ); + File.Delete(Name); + Penumbra.Log.Debug($"Deleted export file {Name}."); } - catch( Exception e ) + catch (Exception e) { - Penumbra.Log.Error( $"Could not delete file \"{Name}\":\n{e}" ); + Penumbra.Log.Error($"Could not delete file \"{Name}\":\n{e}"); } } - // Restore a mod from a pre-existing backup. Does not check if the mod contained in the backup is even similar. - // Does an automatic reload after extraction. + /// + /// Restore a mod from a pre-existing backup. Does not check if the mod contained in the backup is even similar. + /// Does an automatic reload after extraction. + /// public void Restore() { try { - if( Directory.Exists( _mod.ModPath.FullName ) ) + if (Directory.Exists(_mod.ModPath.FullName)) { - Directory.Delete( _mod.ModPath.FullName, true ); - Penumbra.Log.Debug( $"Deleted mod folder {_mod.ModPath.FullName}." ); + Directory.Delete(_mod.ModPath.FullName, true); + Penumbra.Log.Debug($"Deleted mod folder {_mod.ModPath.FullName}."); } - ZipFile.ExtractToDirectory( Name, _mod.ModPath.FullName ); - Penumbra.Log.Debug( $"Extracted exported file {Name} to {_mod.ModPath.FullName}." ); - Penumbra.ModManager.ReloadMod( _mod.Index ); + ZipFile.ExtractToDirectory(Name, _mod.ModPath.FullName); + Penumbra.Log.Debug($"Extracted exported file {Name} to {_mod.ModPath.FullName}."); + _modManager.ReloadMod(_mod.Index); } - catch( Exception e ) + catch (Exception e) { - Penumbra.Log.Error( $"Could not restore {_mod.Name} from export \"{Name}\":\n{e}" ); + Penumbra.Log.Error($"Could not restore {_mod.Name} from export \"{Name}\":\n{e}"); } } -} \ No newline at end of file +} diff --git a/Penumbra/Mods/Editor/ModEditor.cs b/Penumbra/Mods/Editor/ModEditor.cs index c08b7bff..0b41d7c3 100644 --- a/Penumbra/Mods/Editor/ModEditor.cs +++ b/Penumbra/Mods/Editor/ModEditor.cs @@ -24,12 +24,12 @@ public class ModEditor : IDisposable public ModEditor(ModNormalizer modNormalizer, ModMetaEditor metaEditor, ModFileCollection files, ModFileEditor fileEditor, DuplicateManager duplicates, ModSwapEditor swapEditor, MdlMaterialEditor mdlMaterialEditor) { - ModNormalizer = modNormalizer; - MetaEditor = metaEditor; - Files = files; - FileEditor = fileEditor; - Duplicates = duplicates; - SwapEditor = swapEditor; + ModNormalizer = modNormalizer; + MetaEditor = metaEditor; + Files = files; + FileEditor = fileEditor; + Duplicates = duplicates; + SwapEditor = swapEditor; MdlMaterialEditor = mdlMaterialEditor; } @@ -88,7 +88,7 @@ public class ModEditor : IDisposable GroupIdx = -1; OptionIdx = 0; if (message) - global::Penumbra.Penumbra.Log.Error($"Loading invalid option {groupIdx} {optionIdx} for Mod {Mod?.Name ?? "Unknown"}."); + Penumbra.Log.Error($"Loading invalid option {groupIdx} {optionIdx} for Mod {Mod?.Name ?? "Unknown"}."); } public void Clear() @@ -125,4 +125,4 @@ public class ModEditor : IDisposable subDir.Delete(); } } -} \ No newline at end of file +} diff --git a/Penumbra/Mods/Mod.Creator.cs b/Penumbra/Mods/Mod.Creator.cs index 0fb2e5a1..0074cf77 100644 --- a/Penumbra/Mods/Mod.Creator.cs +++ b/Penumbra/Mods/Mod.Creator.cs @@ -10,7 +10,7 @@ using Newtonsoft.Json.Linq; using OtterGui.Classes; using OtterGui.Filesystem; using Penumbra.Api.Enums; -using Penumbra.Import; +using Penumbra.Import.Structs; using Penumbra.String.Classes; namespace Penumbra.Mods; diff --git a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs index 2ee27bfb..49b8ff3d 100644 --- a/Penumbra/UI/ModsTab/ModFileSystemSelector.cs +++ b/Penumbra/UI/ModsTab/ModFileSystemSelector.cs @@ -15,6 +15,7 @@ using OtterGui.Raii; using Penumbra.Api.Enums; using Penumbra.Collections; using Penumbra.Import; +using Penumbra.Import.Structs; using Penumbra.Mods; using Penumbra.Services; using Penumbra.UI.Classes;