diff --git a/File_Format_Library/FileFormats/BFRES/BFRES.cs b/File_Format_Library/FileFormats/BFRES/BFRES.cs index 61f06e93..10bce6ad 100644 --- a/File_Format_Library/FileFormats/BFRES/BFRES.cs +++ b/File_Format_Library/FileFormats/BFRES/BFRES.cs @@ -758,15 +758,9 @@ namespace FirstPlugin return editor; } - - public BFRESRenderBase BFRESRender; - public void Load(System.IO.Stream stream) + public static bool CheckWiiU(Stream stream) { - CanSave = true; - - ImageKey = "bfres"; - SelectedImageKey = "bfres"; - + bool IsWiiU = false; using (FileReader reader = new FileReader(stream, true)) { reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian; @@ -777,9 +771,19 @@ namespace FirstPlugin reader.Position = 0; } + return IsWiiU; + } + public BFRESRenderBase BFRESRender; + public void Load(System.IO.Stream stream) + { + CanSave = true; + + ImageKey = "bfres"; + SelectedImageKey = "bfres"; + + IsWiiU = CheckWiiU(stream); LoadMenus(IsWiiU); - BFRESRender = new BFRESRender(); DrawableContainer.Name = FileName; @@ -934,6 +938,9 @@ namespace FirstPlugin public List GetTextures() { List textures = new List(); + var bntx = GetBNTX; + if (bntx != null) + return bntx.TextureList; foreach (TreeNode folder in Nodes) { diff --git a/Switch_Toolbox_Library/Compression/CompressionMenus.cs b/Switch_Toolbox_Library/Compression/CompressionMenus.cs index 2909f816..c4a6235e 100644 --- a/Switch_Toolbox_Library/Compression/CompressionMenus.cs +++ b/Switch_Toolbox_Library/Compression/CompressionMenus.cs @@ -4,6 +4,7 @@ using System.IO; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Toolbox.Library.Forms; namespace Toolbox.Library.IO { @@ -87,29 +88,6 @@ namespace Toolbox.Library.IO else throw new Exception("Unimplimented Type! " + Name); } - public void CompressData(ICompressionFormat CompressionFormat, Stream data) - { - try - { - SaveFileForCompression(true, data, CompressionFormat); - } - catch (Exception ex) - { - MessageBox.Show($"File failed to compress with {CompressionFormat} compression! {ex.ToString()}"); - } - } - public void DecompressData(ICompressionFormat CompressionFormat, Stream data) - { - try - { - SaveFileForCompression(false, data, CompressionFormat); - } - catch (Exception ex) - { - MessageBox.Show($"File not compressed with {CompressionFormat} compression! {ex.ToString()}"); - } - } - private void OpenFileForCompression(ICompressionFormat compressionFormat, bool Compress) { OpenFileDialog ofd = new OpenFileDialog(); @@ -119,40 +97,103 @@ namespace Toolbox.Library.IO if (ofd.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; - foreach (string file in ofd.FileNames) - { - if (Compress) - CompressData(compressionFormat, File.OpenRead(ofd.FileName)); - else - DecompressData(compressionFormat, File.OpenRead(ofd.FileName)); - } + SaveFileForCompression(Compress, ofd.FileNames, compressionFormat); } } - private void SaveFileForCompression(bool Compress, Stream data, ICompressionFormat compressionFormat) + private void SaveFileForCompression(bool Compress, string[] fileNames, ICompressionFormat compressionFormat) { - SaveFileDialog sfd = new SaveFileDialog(); - sfd.Filter = "All files(*.*)|*.*"; + if (fileNames.Length == 0) + return; - Cursor.Current = Cursors.Default; - if (sfd.ShowDialog() == DialogResult.OK) + string ext = Compress ? ".comp" : ".dec"; + if (compressionFormat.Extension.Length > 0 && Compress) + ext = compressionFormat.Extension[0]; + + List failedFiles = new List(); + if (fileNames.Length > 1) { - Stream stream; - if (Compress) - stream = compressionFormat.Compress(data); - else + FolderSelectDialog ofd = new FolderSelectDialog(); + if (ofd.ShowDialog() == DialogResult.OK) { - compressionFormat.Identify(data, sfd.FileName); - stream = compressionFormat.Decompress(data); + foreach (var file in fileNames) + { + string name = Path.GetFileName(file); + using (var data = new FileStream(file, FileMode.Open, FileAccess.Read)) + { + try + { + Stream stream; + if (Compress) + stream = compressionFormat.Compress(data); + else + { + compressionFormat.Identify(data, file); + stream = compressionFormat.Decompress(data); + } + + if (stream != null) + { + stream.ExportToFile($"{ofd.SelectedPath}/{name}{ext}"); + stream.Flush(); + stream.Close(); + } + } + catch (Exception ex) + { + failedFiles.Add($"{file} \n\n {ex} \n\n"); + } + } + } + + if (failedFiles.Count > 0) + { + string action = Compress ? "compress" : "decompress"; + STErrorDialog.Show($"Some files failed to {action}! See detail list of failed files.", "Switch Toolbox", + string.Join("\n", failedFiles.ToArray())); + } + else + MessageBox.Show("Files batched successfully!"); } + } + else + { + SaveFileDialog sfd = new SaveFileDialog(); + string name = Path.GetFileName(fileNames[0]); + sfd.FileName = name + ext; + sfd.Filter = "All files(*.*)|*.*"; - if (stream != null) + Cursor.Current = Cursors.Default; + if (sfd.ShowDialog() == DialogResult.OK) { - stream.ExportToFile(sfd.FileName); - stream.Flush(); - stream.Close(); + try + { + using (var data = new FileStream(fileNames[0], FileMode.Open, FileAccess.Read)) + { + Stream stream; + if (Compress) + stream = compressionFormat.Compress(data); + else + { + compressionFormat.Identify(data, sfd.FileName); + stream = compressionFormat.Decompress(data); + } - MessageBox.Show($"File has been saved to {sfd.FileName}", "Save Notification"); + if (stream != null) + { + stream.ExportToFile(sfd.FileName); + stream.Flush(); + stream.Close(); + + MessageBox.Show($"File has been saved to {sfd.FileName}", "Save Notification"); + } + } + } + catch (Exception ex) + { + string action = Compress ? "compress" : "decompress"; + STErrorDialog.Show($"Failed to {action}! See details for info.", "Switch Toolbox", ex.ToString()); + } } } } diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index 5da46450..c718d51f 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -653,6 +653,8 @@ namespace Toolbox RegisterMenuExtIndex(toolsToolStripMenuItem, ext.ToolsMenuExtensions); if (ext.TitleBarExtensions != null) RegisterMenuExtIndex(menuStrip1, ext.TitleBarExtensions, menuStrip1.Items.Count); + if (ext.MapEditorMenuExtensions != null) + RegisterMenuExtIndex(mapEditorsToolStripMenuItem, ext.MapEditorMenuExtensions, mapEditorsToolStripMenuItem.DropDownItems.Count); } } @@ -1400,6 +1402,8 @@ namespace Toolbox } } } + else + return; if (failedFiles.Count > 0) { @@ -1468,7 +1472,7 @@ namespace Toolbox SearchArchive(settings, (IArchiveFile)fileFormat, extension, outputFolder, exportMode); else if (fileFormat is ITextureContainer && exportMode == ExportMode.Textures) { - if (settings.SeperateTextureContainers) + if (settings.SeperateTextureContainers && ((ITextureContainer)fileFormat).TextureList.Count > 0) { string name = fileFormat.FileName.Split('.').FirstOrDefault(); outputFolder = Path.Combine(outputFolder, name); @@ -1511,10 +1515,7 @@ namespace Toolbox string extension, string outputFolder, ExportMode exportMode) { string ArchiveFilePath = Path.Combine(outputFolder, Path.GetFileNameWithoutExtension(((IFileFormat)archiveFile).FileName)); - if (!Directory.Exists(ArchiveFilePath)) - Directory.CreateDirectory(ArchiveFilePath); - else - ArchiveFilePath = outputFolder; + ArchiveFilePath = outputFolder; foreach (var file in archiveFile.Files) SearchFileFormat(settings, file.OpenFile(), extension, ArchiveFilePath, exportMode);