diff --git a/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs b/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs index 494fd3b5..1c3fb75a 100644 --- a/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs +++ b/Switch_Toolbox_Library/Interfaces/FileFormatting/IArchiveFile.cs @@ -79,7 +79,9 @@ namespace Toolbox.Library [Browsable(false)] public virtual IFileFormat OpenFile() { - if (FileFormat != null) + if (FileFormat != null && + FileFormat.IFileInfo != null && + FileFormat.IFileInfo.ArchiveParent != null) return FileFormat; if (FileDataStream != null) @@ -174,6 +176,27 @@ namespace Toolbox.Library } } + public static void SaveFileFormat(ArchiveFileInfo archiveFile, IFileFormat fileFormat) + { + if (fileFormat != null && fileFormat.CanSave) + { + if (archiveFile.FileDataStream != null) + { + var mem = new System.IO.MemoryStream(); + fileFormat.Save(mem); + archiveFile.FileDataStream = mem; + //Reload file data + fileFormat.Load(archiveFile.FileDataStream); + } + else + { + var mem = new System.IO.MemoryStream(); + fileFormat.Save(mem); + archiveFile.FileData = STLibraryCompression.CompressFile(mem.ToArray(), fileFormat); + } + } + } + public void SaveFileFormat() { if (FileFormat != null && FileFormat.CanSave) @@ -894,9 +917,6 @@ namespace Toolbox.Library OpenFormDialog(file); else if (file is IArchiveFile) { - if (ArchiveFileInfo.FileFormat != null) - ArchiveFileInfo.FileFormat.Unload(); - var FileRoot = new ArchiveRootNodeWrapper(file.FileName, (IArchiveFile)file); FileRoot.FillTreeNodes(); @@ -910,9 +930,6 @@ namespace Toolbox.Library } else if (file is TreeNode) { - if (ArchiveFileInfo.FileFormat != null) - ArchiveFileInfo.FileFormat.Unload(); - ReplaceNode(this.Parent, treeview, this, (TreeNode)file, RootNode); }