From b16a098339cbd00bfeec5f602b65e4dae7b5c8c8 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Tue, 18 Jun 2019 16:27:36 -0400 Subject: [PATCH] More fixes --- .../Forms/Archive/ArchiveFilePanel.cs | 37 +++++++++-- .../Editors/Object Editor/ObjectEditorList.cs | 2 +- .../Interfaces/IArchiveFile.cs | 66 ++++++++++++++----- Switch_Toolbox_Library/Maths/Math.cs | 10 +-- Switch_Toolbox_Library/Runtime.cs | 2 + 5 files changed, 89 insertions(+), 28 deletions(-) diff --git a/Switch_Toolbox_Library/Forms/Archive/ArchiveFilePanel.cs b/Switch_Toolbox_Library/Forms/Archive/ArchiveFilePanel.cs index 7dd69a08..7c769a89 100644 --- a/Switch_Toolbox_Library/Forms/Archive/ArchiveFilePanel.cs +++ b/Switch_Toolbox_Library/Forms/Archive/ArchiveFilePanel.cs @@ -33,10 +33,15 @@ namespace Switch_Toolbox.Library.Forms private void ReloadEditors() { stComboBox1.Items.Clear(); + stComboBox1.Items.Add("Properties"); stComboBox1.Items.Add("Hex Editor"); stComboBox1.Items.Add("File Editor"); stComboBox1.Items.Add("Text Editor"); - stComboBox1.SelectedIndex = 0; + + if (Runtime.ObjectEditor.EditorDiplayIndex < stComboBox1.Items.Count) + stComboBox1.SelectedIndex = Runtime.ObjectEditor.EditorDiplayIndex; + else + stComboBox1.SelectedIndex = 0; } public void SetEditor(int Index) { stComboBox1.SelectedIndex = Index; } @@ -55,10 +60,12 @@ namespace Switch_Toolbox.Library.Forms public void UpdateEditor() { if (GetEditor() == 0) - UpdateHexView(); + UpdatePropertiesView(); if (GetEditor() == 1) - UpdateFileEditor(); + UpdateHexView(); if (GetEditor() == 2) + UpdateFileEditor(); + if (GetEditor() == 3) UpdateTextView(); } @@ -162,6 +169,19 @@ namespace Switch_Toolbox.Library.Forms return false; } + private void UpdatePropertiesView() + { + STPropertyGrid editor = (STPropertyGrid)GetActiveEditor(typeof(STPropertyGrid)); + if (editor == null) + { + editor = new STPropertyGrid(); + editor.Dock = DockStyle.Fill; + AddControl(editor); + } + editor.Text = Text; + editor.LoadProperty(ArchiveFileInfo.DisplayProperties); + } + private void UpdateHexView() { HexEditor editor = (HexEditor)GetActiveEditor(typeof(HexEditor)); @@ -172,7 +192,10 @@ namespace Switch_Toolbox.Library.Forms AddControl(editor); } editor.Text = Text; - editor.LoadData(ArchiveFileInfo.FileData); + byte[] Data = ArchiveFileInfo.FileData; + + //Only load a certain about of bytes to prevent memory dispose issues + editor.LoadData(Utils.SubArray(Data, 0, 3000)); } @@ -188,9 +211,11 @@ namespace Switch_Toolbox.Library.Forms private void stComboBox1_SelectedIndexChanged(object sender, EventArgs e) { - if (_IsLoaded) + if (_IsLoaded && stComboBox1.SelectedIndex != -1) + { + Runtime.ObjectEditor.EditorDiplayIndex = stComboBox1.SelectedIndex; UpdateEditor(); - + } } } } diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs index 89eb2af7..6d55a0a1 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorList.cs @@ -177,7 +177,7 @@ namespace Switch_Toolbox.Library.Forms ListViewItem item = new ListViewItem(System.IO.Path.GetFileName(file.FileName)); item.ImageKey = "texture"; item.Group = listViewCustom1.Groups[0]; - item.SubItems.Add(file.GetSize()); + item.SubItems.Add(file.FileSize); item.SubItems.Add(""); item.SubItems.Add(file.State.ToString()); listViewCustom1.Items.Add(item); diff --git a/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs b/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs index 94181cd2..86a60de3 100644 --- a/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs +++ b/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs @@ -7,6 +7,7 @@ using System.Windows.Forms; using Switch_Toolbox.Library.Forms; using Switch_Toolbox.Library.IO; using System.Text.RegularExpressions; +using System.ComponentModel; namespace Switch_Toolbox.Library { @@ -34,18 +35,33 @@ namespace Switch_Toolbox.Library } public class ArchiveFileInfo { + [Browsable(false)] public STContextMenuStrip STContextMenuStrip; + [Browsable(false)] public virtual STToolStripItem[] Menus { get; set; } + [Browsable(false)] public FileType FileDataType = FileType.Default; + //Wether or not to check the file magic to determine the type + //This sets the icons if there's no proper extension, and may add more special operations + //This should be disabled on larger archives! + [Browsable(false)] + public virtual bool CheckFileMagic { get; set; } = false; + + //Properties to show for the archive file when selected + [Browsable(false)] + public virtual object DisplayProperties { get; set; } + + [Browsable(false)] public virtual IFileFormat OpenFile() { return STFileLoader.OpenFileFormat( IOExtensions.RemoveIllegaleFolderNameCharacters(FileName), FileData, true); } + [Browsable(false)] public bool IsSupportedFileFormat() { if (FileData == null || FileData.Length <= 4) @@ -96,17 +112,18 @@ namespace Switch_Toolbox.Library } } - public string GetSize() - { - return STMath.GetFileSize(FileData.Length, 4); - } + public virtual string FileSize => STMath.GetFileSize(FileData.Length, 4); + [Browsable(false)] public IFileFormat FileFormat = null; //Format attached for saving + [Browsable(false)] protected byte[] _fileData = null; //Full File Name - private string _fileName = string.Empty; + private string _fileName = string.Empty; + + [Browsable(false)] public string FileName { get @@ -118,7 +135,11 @@ namespace Switch_Toolbox.Library _fileName = value; } } + + [Browsable(false)] public string Name { get; set; } = string.Empty; //File Name (No Path) + + [Browsable(false)] public virtual byte[] FileData { get @@ -131,6 +152,7 @@ namespace Switch_Toolbox.Library set { _fileData = value; } } + [Browsable(false)] public ArchiveFileState State { get; set; } = ArchiveFileState.Empty; } @@ -391,18 +413,30 @@ namespace Switch_Toolbox.Library ArchiveFileInfo = archiveFileInfo; - if (archiveFileInfo.FileData != null) + string Extension = ""; + if (ArchiveFileInfo.CheckFileMagic) { - string Extension = FindMatch(archiveFileInfo.FileData); - switch (Extension) - { - case ".bntx": SetImageKey("bntx"); break; - case ".byaml": SetImageKey("byaml"); break; - case ".aamp": SetImageKey("aamp"); break; - case ".bfres": SetImageKey("bfres"); break; - case ".sbfres": SetImageKey("sbfres"); break; - default: SetImageKey("fileBlank"); break; - } + Extension = FindMatch(archiveFileInfo.FileData); + } + + switch (Extension) + { + case ".bntx": SetImageKey("bntx"); break; + case ".byaml": SetImageKey("byaml"); break; + case ".aamp": SetImageKey("aamp"); break; + case ".bfres": SetImageKey("bfres"); break; + case ".sbfres": SetImageKey("sbfres"); break; + case ".dds": + case ".tga": + case ".jpg": + case ".jpeg": + case ".tiff": + case ".png": + case ".gif": + case ".astc": + SetImageKey("texture"); break; + + default: SetImageKey("fileBlank"); break; } } diff --git a/Switch_Toolbox_Library/Maths/Math.cs b/Switch_Toolbox_Library/Maths/Math.cs index 2fec5418..1190eb79 100644 --- a/Switch_Toolbox_Library/Maths/Math.cs +++ b/Switch_Toolbox_Library/Maths/Math.cs @@ -30,11 +30,11 @@ namespace Switch_Toolbox.Library var asGb = Math.Round((double)value / SizeOfGb, decimalPlaces); var asMb = Math.Round((double)value / SizeOfMb, decimalPlaces); var asKb = Math.Round((double)value / SizeOfKb, decimalPlaces); - string chosenValue = asTb > 1 ? string.Format("{0}Tb", asTb) - : asGb > 1 ? string.Format("{0}Gb", asGb) - : asMb > 1 ? string.Format("{0}Mb", asMb) - : asKb > 1 ? string.Format("{0}Kb", asKb) - : string.Format("{0}B", Math.Round((double)value, decimalPlaces)); + string chosenValue = asTb > 1 ? string.Format("{0} TB", asTb) + : asGb > 1 ? string.Format("{0} GB", asGb) + : asMb > 1 ? string.Format("{0} MB", asMb) + : asKb > 1 ? string.Format("{0} KB", asKb) + : string.Format("{0} bytes", Math.Round((double)value, decimalPlaces)); return chosenValue; } diff --git a/Switch_Toolbox_Library/Runtime.cs b/Switch_Toolbox_Library/Runtime.cs index 3199db86..81fb5ffa 100644 --- a/Switch_Toolbox_Library/Runtime.cs +++ b/Switch_Toolbox_Library/Runtime.cs @@ -47,6 +47,8 @@ namespace Switch_Toolbox.Library public static Point Location = new Point(364, 0); + public static int EditorDiplayIndex = 0; + public static int ListPanelWidth; }