1
0
mirror of synced 2024-12-01 02:27:22 +01:00

More fixes

This commit is contained in:
KillzXGaming 2019-06-18 16:27:36 -04:00
parent 2f3c60c068
commit b16a098339
5 changed files with 89 additions and 28 deletions

View File

@ -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();
}
}
}
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}