Prepare some archive format rework

This commit is contained in:
KillzXGaming 2019-05-08 16:28:04 -04:00
parent 87d061dbe1
commit e744b3de26
31 changed files with 1284 additions and 249 deletions

View file

@ -16,7 +16,7 @@ namespace FirstPlugin
}
public class APAK : TreeNodeFile, IArchiveFile
public class APAK : TreeNodeFile
{
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "APAK" };

View file

@ -13,7 +13,7 @@ using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class BEA : TreeNodeFile, IArchiveFile
public class BEA : TreeNodeFile, IFileFormat
{
public bool CanAddFiles { get; set; } = false;
public bool CanRenameFiles { get; set; } = false;

View file

@ -11,7 +11,7 @@ using Switch_Toolbox.Library.Forms;
namespace FirstPlugin
{
public class TMPK : TreeNodeFile, IArchiveFile
public class TMPK : IFileFormat, IArchiveFile
{
public bool CanSave { get; set; }
public string[] Description { get; set; } = new string[] { "TMPK" };
@ -37,14 +37,15 @@ namespace FirstPlugin
}
}
public IEnumerable<ArchiveFileInfo> Files { get; }
public bool CanAddFiles { get; set; } = true;
public bool CanRenameFiles { get; set; } = true;
public bool CanReplaceFiles { get; set; } = true;
public bool CanDeleteFiles { get; set; } = true;
public List<FileInfo> files = new List<FileInfo>();
public IEnumerable<ArchiveFileInfo> Files => files;
public bool CanAddFiles { get; set; }
public bool CanRenameFiles { get; set; }
public bool CanReplaceFiles { get; set; }
public bool CanDeleteFiles { get; set; }
public Dictionary<long, byte[]> SavedDataEntries = new Dictionary<long, byte[]>();
public Dictionary<long, string> SavedStringEntries = new Dictionary<long, string>();
public Dictionary<string, uint> ArchiveSizes = new Dictionary<string, uint>();
@ -54,8 +55,6 @@ namespace FirstPlugin
public void Load(System.IO.Stream stream)
{
Text = FileName;
CanSave = true;
using (var reader = new FileReader(stream))
@ -69,13 +68,9 @@ namespace FirstPlugin
for (int i = 0; i < FileCount; i++)
{
var info = new FileInfo(reader);
Nodes.Add(info);
files.Add(info);
}
}
ContextMenuStrip = new STContextMenuStrip();
ContextMenuStrip.Items.Add(new ToolStripMenuItem("Save", null, Save, Keys.Control | Keys.E));
}
private void SatisfyFileSizeTable()
@ -121,21 +116,21 @@ namespace FirstPlugin
files[i]._posHeader = writer.Position;
writer.Write(uint.MaxValue);
writer.Write(uint.MaxValue);
writer.Write(files[i].Data.Length); //Padding
writer.Write(files[i].FileData.Length); //Padding
writer.Write(0); //Padding
ArchiveSizes.Add(files[i].Text, (uint)files[i].Data.Length);
ArchiveSizes.Add(files[i].FileName, (uint)files[i].FileData.Length);
}
for (int i = 0; i < files.Count; i++)
{
writer.WriteUint32Offset(files[i]._posHeader);
writer.Write(files[i].Text, Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
writer.Write(files[i].FileName, Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
}
for (int i = 0; i < files.Count; i++)
{
SetAlignment(writer, files[i].Text);
SetAlignment(writer, files[i].FileName);
writer.WriteUint32Offset(files[i]._posHeader + 4);
writer.Write(files[i].Data);
writer.Write(files[i].FileData.ToArray());
}
writer.Close();
writer.Dispose();
@ -151,45 +146,28 @@ namespace FirstPlugin
writer.Write(DefaultAlignment);
}
public class FileInfo : TreeNodeCustom
public class FileInfo : ArchiveFileInfo
{
internal long _posHeader;
public byte[] Data;
public FileInfo()
{
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export Raw Data");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
}
private void Export(object sender, EventArgs args)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.FileName = Text;
sfd.DefaultExt = Path.GetExtension(Text);
sfd.FileName = FileName;
sfd.DefaultExt = Path.GetExtension(FileName);
sfd.Filter = "Raw Data (*.*)|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
File.WriteAllBytes(sfd.FileName, Data);
File.WriteAllBytes(sfd.FileName, FileData.ToArray());
}
}
public override void OnDoubleMouseClick(TreeView treeView)
{
if (Data.Length <= 0)
return;
IFileFormat file = STFileLoader.OpenFileFormat(Text, Data, false, true, this);
if (file == null) //File returns null if no supported format is found
return;
ReplaceNode(this.Parent, this, (TreeNode)file);
}
public static void ReplaceNode(TreeNode node, TreeNode replaceNode, TreeNode NewNode)
{
if (NewNode == null)
@ -200,19 +178,6 @@ namespace FirstPlugin
node.Nodes.Insert(index, NewNode);
}
public override void OnClick(TreeView treeview)
{
HexEditor editor = (HexEditor)LibraryGUI.Instance.GetActiveContent(typeof(HexEditor));
if (editor == null)
{
editor = new HexEditor();
LibraryGUI.Instance.LoadEditor(editor);
}
editor.Text = Text;
editor.Dock = DockStyle.Fill;
editor.LoadData(Data);
}
public FileInfo(FileReader reader)
{
long pos = reader.Position;
@ -223,17 +188,13 @@ namespace FirstPlugin
uint padding = reader.ReadUInt32();
reader.Seek(NameOffset, System.IO.SeekOrigin.Begin);
Text = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
reader.Seek(FileOffset, System.IO.SeekOrigin.Begin);
Data = reader.ReadBytes((int)FileSize);
FileData = new MemoryStream(reader.ReadBytes((int)FileSize));
State = ArchiveFileState.Archived;
reader.Seek(pos + 16, System.IO.SeekOrigin.Begin);
ContextMenu = new ContextMenu();
MenuItem export = new MenuItem("Export Raw Data");
ContextMenu.MenuItems.Add(export);
export.Click += Export;
}
}

View file

@ -110,9 +110,8 @@ namespace FirstPlugin
bfres.Load(new MemoryStream(BfresWiiU.CreateNewBFRES("Untitled.bfres")));
ObjectEditor editor = new ObjectEditor();
ObjectEditor editor = new ObjectEditor(bfres);
editor.Text = "Untitled-" + 0;
editor.AddNode(bfres);
LibraryGUI.Instance.CreateMdiWindow(editor);
}
private void NewSwitchBfres(object sender, EventArgs args)
@ -123,9 +122,8 @@ namespace FirstPlugin
bfres.Load(new MemoryStream(CreateNewBFRESSwitch("Untitled.bfres")));
ObjectEditor editor = new ObjectEditor();
ObjectEditor editor = new ObjectEditor(bfres);
editor.Text = "Untitled-" + 0;
editor.AddNode(bfres);
LibraryGUI.Instance.CreateMdiWindow(editor);
}
private void DebugInfo(object sender, EventArgs args)

View file

@ -129,9 +129,8 @@ namespace FirstPlugin
kcl.Renderer = new KCLRendering();
kcl.Read(f.Write(ByteOrder));
ObjectEditor editor = new ObjectEditor();
ObjectEditor editor = new ObjectEditor(kcl);
editor.Text = name;
editor.AddNode(kcl);
LibraryGUI.Instance.CreateMdiWindow(editor);
}
}

View file

@ -124,10 +124,9 @@ namespace FirstPlugin
}
//ObjectEditor is for treenode types. Editors will be on the right side, treenodes on the left
ObjectEditor editor = new ObjectEditor();
ObjectEditor editor = new ObjectEditor((IFileFormat)fileFormat);
editor.Text = text;
LibraryGUI.Instance.CreateMdiWindow(editor, true);
editor.AddNode((TreeNode)fileFormat);
}
}

View file

@ -81,9 +81,8 @@ namespace FirstPlugin
bntx.FileName = "textures";
bntx.Load(new MemoryStream(CreateNewBNTX("textures")));
ObjectEditor editor = new ObjectEditor();
ObjectEditor editor = new ObjectEditor(bntx);
editor.Text = "Untitled-" + 0;
editor.AddNode(bntx);
LibraryGUI.Instance.CreateMdiWindow(editor);
}
private void Export(object sender, EventArgs args)

View file

@ -0,0 +1,65 @@
namespace Switch_Toolbox.Library.Forms
{
partial class ObjectEditor
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.contentContainer.SuspendLayout();
this.SuspendLayout();
//
// contentContainer
//
this.contentContainer.Controls.Add(this.stPanel1);
this.contentContainer.Size = new System.Drawing.Size(901, 537);
this.contentContainer.Controls.SetChildIndex(this.stPanel1, 0);
//
// stPanel1
//
this.stPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPanel1.Location = new System.Drawing.Point(0, 25);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(901, 512);
this.stPanel1.TabIndex = 11;
//
// ObjectEditor
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(907, 542);
this.Name = "ObjectEditor";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ObjectEditor_FormClosed);
this.contentContainer.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private STPanel stPanel1;
}
}

View file

@ -0,0 +1,165 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GL_EditorFramework.Interfaces;
using GL_EditorFramework.EditorDrawables;
using System.Text.RegularExpressions;
using Switch_Toolbox.Library.Animations;
using Switch_Toolbox.Library.IO;
namespace Switch_Toolbox.Library.Forms
{
public partial class ObjectEditor : STForm
{
private ObjectEditorTree ObjectTree;
private ObjectEditorList ObjectList; //Optionally usable for archives
private TreeView _fieldsTreeCache;
public void BeginUpdate() { ObjectTree.BeginUpdate(); }
public void EndUpdate() { ObjectTree.EndUpdate(); }
public void AddNodeCollection (TreeNodeCollection nodes, bool ClearNodes)
{
if (ObjectTree != null) {
ObjectTree.AddNodeCollection(nodes,ClearNodes);
}
}
public TreeNodeCollection GetNodes() { return ObjectTree.GetNodes(); }
public void AddNode(TreeNode node, bool ClearAllNodes = false)
{
if (ObjectTree != null) {
ObjectTree.AddNode(node, ClearAllNodes);
}
}
private void AddNodes(TreeNode node, bool ClearAllNodes = false)
{
if (ObjectTree != null) {
ObjectTree.AddNode(node, ClearAllNodes);
}
}
public void ClearNodes()
{
if (ObjectTree != null) {
ObjectTree.ClearNodes();
}
}
public bool AddFilesToActiveEditor
{
get
{
return ObjectTree.AddFilesToActiveEditor;
}
set
{
ObjectTree.AddFilesToActiveEditor = value;
}
}
public bool UseListView = true;
public ObjectEditor(IFileFormat FileFormat)
{
InitializeComponent();
if (UseListView && FileFormat is IArchiveFile)
{
ObjectList = new ObjectEditorList();
ObjectList.Dock = DockStyle.Fill;
stPanel1.Controls.Add(ObjectList);
ObjectList.FillList((IArchiveFile)FileFormat);
}
else
{
ObjectTree = new ObjectEditorTree();
ObjectTree.Dock = DockStyle.Fill;
stPanel1.Controls.Add(ObjectTree);
AddNode((TreeNode)FileFormat);
}
}
public Viewport GetViewport() => viewport;
//Attatch a viewport instance here if created.
//If the editor gets switched, we can keep the previous viewed area when switched back
Viewport viewport = null;
bool IsLoaded = false;
public void LoadViewport(Viewport Viewport)
{
viewport = Viewport;
IsLoaded = true;
}
public List<EditableObject> editableGlDrawables = new List<EditableObject>();
public List<AbstractGlDrawable> staticGlDrawables = new List<AbstractGlDrawable>();
public static void AddObject(EditableObject drawable)
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return;
editor.editableGlDrawables.Add(drawable);
}
public List<Control> GetEditors()
{
if (ObjectTree != null)
return ObjectTree.GetEditors();
else
return new List<Control>();
}
public IFileFormat GetActiveFile()
{
if (ObjectTree != null)
return ObjectTree.GetActiveFile();
else
return ObjectList.GetActiveFile();
}
public void LoadEditor(Control control)
{
ObjectTree.LoadEditor(control);
}
private void ObjectEditor_FormClosed(object sender, FormClosedEventArgs e)
{
Viewport viewport = LibraryGUI.Instance.GetActiveViewport();
if (viewport != null)
viewport.FormClosing();
if (ObjectTree != null)
ObjectTree.FormClosing();
}
public void RemoveFile(TreeNode File)
{
if (File is IFileFormat) {
((IFileFormat)File).Unload();
}
ObjectTree.RemoveFile(File);
}
public void ResetControls()
{
ObjectTree.ResetControls();
Text = "";
}
}
}

View file

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View file

@ -0,0 +1,270 @@
namespace Switch_Toolbox.Library.Forms
{
partial class ObjectEditorList
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.stPanel1 = new Switch_Toolbox.Library.Forms.STPanel();
this.treeViewCustom1 = new Switch_Toolbox.Library.TreeViewCustom();
this.stPanel3 = new Switch_Toolbox.Library.Forms.STPanel();
this.searchLbl = new Switch_Toolbox.Library.Forms.STLabel();
this.searchImgPB = new System.Windows.Forms.PictureBox();
this.stTextBox1 = new Switch_Toolbox.Library.Forms.STTextBox();
this.stContextMenuStrip1 = new Switch_Toolbox.Library.Forms.STMenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.viewToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.sortToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stPanel2 = new Switch_Toolbox.Library.Forms.STPanel();
this.listViewCustom1 = new Switch_Toolbox.Library.Forms.ListViewCustom();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.splitter1 = new System.Windows.Forms.Splitter();
this.stPanel1.SuspendLayout();
this.stPanel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.searchImgPB)).BeginInit();
this.stContextMenuStrip1.SuspendLayout();
this.stPanel2.SuspendLayout();
this.SuspendLayout();
//
// stPanel1
//
this.stPanel1.Controls.Add(this.treeViewCustom1);
this.stPanel1.Controls.Add(this.stPanel3);
this.stPanel1.Controls.Add(this.stContextMenuStrip1);
this.stPanel1.Dock = System.Windows.Forms.DockStyle.Left;
this.stPanel1.Location = new System.Drawing.Point(0, 0);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(322, 542);
this.stPanel1.TabIndex = 11;
this.stPanel1.Resize += new System.EventHandler(this.stPanel1_Resize);
//
// treeViewCustom1
//
this.treeViewCustom1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.treeViewCustom1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.treeViewCustom1.HotTracking = true;
this.treeViewCustom1.ImageIndex = 0;
this.treeViewCustom1.Location = new System.Drawing.Point(1, 53);
this.treeViewCustom1.Name = "treeViewCustom1";
this.treeViewCustom1.SelectedImageIndex = 0;
this.treeViewCustom1.ShowLines = false;
this.treeViewCustom1.ShowRootLines = false;
this.treeViewCustom1.Size = new System.Drawing.Size(319, 488);
this.treeViewCustom1.TabIndex = 0;
this.treeViewCustom1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeViewCustom1_AfterSelect);
this.treeViewCustom1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.treeViewCustom1_DoubleClick);
//
// stPanel3
//
this.stPanel3.Controls.Add(this.searchLbl);
this.stPanel3.Controls.Add(this.searchImgPB);
this.stPanel3.Controls.Add(this.stTextBox1);
this.stPanel3.Dock = System.Windows.Forms.DockStyle.Top;
this.stPanel3.Location = new System.Drawing.Point(0, 24);
this.stPanel3.Name = "stPanel3";
this.stPanel3.Size = new System.Drawing.Size(322, 26);
this.stPanel3.TabIndex = 2;
//
// searchLbl
//
this.searchLbl.AutoSize = true;
this.searchLbl.ForeColor = System.Drawing.Color.Silver;
this.searchLbl.Location = new System.Drawing.Point(9, 5);
this.searchLbl.Name = "searchLbl";
this.searchLbl.Size = new System.Drawing.Size(41, 13);
this.searchLbl.TabIndex = 2;
this.searchLbl.Text = "Search";
//
// searchImgPB
//
this.searchImgPB.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.searchImgPB.BackColor = System.Drawing.Color.Transparent;
this.searchImgPB.Image = global::Switch_Toolbox.Library.Properties.Resources.Antu_edit_find_mail_svg;
this.searchImgPB.Location = new System.Drawing.Point(-646, 5);
this.searchImgPB.Name = "searchImgPB";
this.searchImgPB.Size = new System.Drawing.Size(22, 17);
this.searchImgPB.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.searchImgPB.TabIndex = 1;
this.searchImgPB.TabStop = false;
//
// stTextBox1
//
this.stTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.stTextBox1.Location = new System.Drawing.Point(3, 3);
this.stTextBox1.Name = "stTextBox1";
this.stTextBox1.Size = new System.Drawing.Size(319, 20);
this.stTextBox1.TabIndex = 0;
this.stTextBox1.Click += new System.EventHandler(this.stTextBox1_Click);
this.stTextBox1.TextChanged += new System.EventHandler(this.stTextBox1_TextChanged);
this.stTextBox1.Leave += new System.EventHandler(this.stTextBox1_Leave);
//
// stContextMenuStrip1
//
this.stContextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.viewToolStripMenuItem});
this.stContextMenuStrip1.Location = new System.Drawing.Point(0, 0);
this.stContextMenuStrip1.Name = "stContextMenuStrip1";
this.stContextMenuStrip1.Size = new System.Drawing.Size(322, 24);
this.stContextMenuStrip1.TabIndex = 1;
this.stContextMenuStrip1.Text = "stContextMenuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Text = "File";
//
// openToolStripMenuItem
//
this.openToolStripMenuItem.Name = "openToolStripMenuItem";
this.openToolStripMenuItem.Size = new System.Drawing.Size(117, 22);
this.openToolStripMenuItem.Text = "Add File";
this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
//
// viewToolStripMenuItem
//
this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.sortToolStripMenuItem});
this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Text = "View";
//
// sortToolStripMenuItem
//
this.sortToolStripMenuItem.Name = "sortToolStripMenuItem";
this.sortToolStripMenuItem.Size = new System.Drawing.Size(95, 22);
this.sortToolStripMenuItem.Text = "Sort";
this.sortToolStripMenuItem.Click += new System.EventHandler(this.sortToolStripMenuItem_Click);
//
// stPanel2
//
this.stPanel2.Controls.Add(this.listViewCustom1);
this.stPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPanel2.Location = new System.Drawing.Point(322, 0);
this.stPanel2.Name = "stPanel2";
this.stPanel2.Size = new System.Drawing.Size(585, 542);
this.stPanel2.TabIndex = 12;
//
// listViewCustom1
//
this.listViewCustom1.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.listViewCustom1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4});
this.listViewCustom1.Dock = System.Windows.Forms.DockStyle.Fill;
this.listViewCustom1.Location = new System.Drawing.Point(0, 0);
this.listViewCustom1.Name = "listViewCustom1";
this.listViewCustom1.OwnerDraw = true;
this.listViewCustom1.Size = new System.Drawing.Size(585, 542);
this.listViewCustom1.TabIndex = 0;
this.listViewCustom1.UseCompatibleStateImageBehavior = false;
this.listViewCustom1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Text = "Name";
this.columnHeader1.Width = 268;
//
// columnHeader2
//
this.columnHeader2.Text = "Size";
this.columnHeader2.Width = 89;
//
// columnHeader3
//
this.columnHeader3.Text = "Type";
this.columnHeader3.Width = 74;
//
// columnHeader4
//
this.columnHeader4.Text = "State";
this.columnHeader4.Width = 154;
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(322, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 542);
this.splitter1.TabIndex = 13;
this.splitter1.TabStop = false;
this.splitter1.LocationChanged += new System.EventHandler(this.splitter1_LocationChanged);
this.splitter1.Resize += new System.EventHandler(this.splitter1_Resize);
//
// ObjectEditorList
//
this.Controls.Add(this.splitter1);
this.Controls.Add(this.stPanel2);
this.Controls.Add(this.stPanel1);
this.Name = "ObjectEditorList";
this.Size = new System.Drawing.Size(907, 542);
this.stPanel1.ResumeLayout(false);
this.stPanel1.PerformLayout();
this.stPanel3.ResumeLayout(false);
this.stPanel3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.searchImgPB)).EndInit();
this.stContextMenuStrip1.ResumeLayout(false);
this.stContextMenuStrip1.PerformLayout();
this.stPanel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Splitter splitter1;
public STPanel stPanel2;
private STPanel stPanel1;
private STPanel stPanel3;
private TreeViewCustom treeViewCustom1;
private STMenuStrip stContextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem viewToolStripMenuItem;
private STTextBox stTextBox1;
private System.Windows.Forms.PictureBox searchImgPB;
private STLabel searchLbl;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem sortToolStripMenuItem;
private ListViewCustom listViewCustom1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
}
}

View file

@ -0,0 +1,340 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GL_EditorFramework.Interfaces;
using GL_EditorFramework.EditorDrawables;
using System.Text.RegularExpressions;
using Switch_Toolbox.Library.Animations;
using Switch_Toolbox.Library.IO;
namespace Switch_Toolbox.Library.Forms
{
public partial class ObjectEditorList : UserControl
{
private IArchiveFile archiveFile;
private List<ArchiveFileInfo> Files;
private TreeView _fieldsTreeCache;
public void BeginUpdate() { treeViewCustom1.BeginUpdate(); }
public void EndUpdate() { treeViewCustom1.EndUpdate(); }
public void AddNodeCollection (TreeNodeCollection nodes, bool ClearNodes)
{
// Invoke the treeview to add the nodes
treeViewCustom1.Invoke((Action)delegate ()
{
treeViewCustom1.BeginUpdate(); // No visual updates until we say
if (ClearNodes)
treeViewCustom1.Nodes.Clear(); // Remove existing nodes
foreach (TreeNode node in nodes)
treeViewCustom1.Nodes.Add(node); // Add the new nodes
treeViewCustom1.EndUpdate(); // Allow the treeview to update visually
});
}
public TreeNodeCollection GetNodes() { return treeViewCustom1.Nodes; }
public void AddNode(TreeNode node, bool ClearAllNodes = false)
{
if (treeViewCustom1.InvokeRequired)
{
// Invoke the treeview to add the nodes
treeViewCustom1.Invoke((Action)delegate ()
{
AddNodes(node, ClearAllNodes);
});
}
else
{
AddNodes(node, ClearAllNodes);
}
// _fieldsTreeCache.Nodes.Add(node);
}
private void AddNodes(TreeNode node, bool ClearAllNodes = false)
{
treeViewCustom1.BeginUpdate(); // No visual updates until we say
if (ClearAllNodes)
ClearNodes();
treeViewCustom1.Nodes.Add(node); // Add the new nodes
treeViewCustom1.EndUpdate(); // Allow the treeview to update visually
}
public void ClearNodes()
{
treeViewCustom1.Nodes.Clear();
// _fieldsTreeCache.Nodes.Clear();
}
public ObjectEditorList()
{
InitializeComponent();
_fieldsTreeCache = new TreeView();
if (Runtime.ObjectEditor.ListPanelWidth > 0)
stPanel1.Width = Runtime.ObjectEditor.ListPanelWidth;
searchLbl.BackColor = stTextBox1.BackColor;
treeViewCustom1.BackColor = FormThemes.BaseTheme.ObjectEditorBackColor;
}
public Viewport GetViewport() => viewport;
//Attatch a viewport instance here if created.
//If the editor gets switched, we can keep the previous viewed area when switched back
Viewport viewport = null;
bool IsLoaded = false;
public void LoadViewport(Viewport Viewport)
{
viewport = Viewport;
IsLoaded = true;
}
public List<EditableObject> editableGlDrawables = new List<EditableObject>();
public List<AbstractGlDrawable> staticGlDrawables = new List<AbstractGlDrawable>();
public static void AddObject(EditableObject drawable)
{
var editor = LibraryGUI.Instance.GetObjectEditor();
if (editor == null)
return;
editor.editableGlDrawables.Add(drawable);
}
public IFileFormat GetActiveFile()
{
if (treeViewCustom1.Nodes.Count == 0)
return null;
if (treeViewCustom1.Nodes[0] is IFileFormat)
return (IFileFormat)treeViewCustom1.Nodes[0];
return null;
}
public void LoadEditor(Control control)
{
foreach (var ctrl in stPanel2.Controls)
{
if (ctrl is STUserControl)
((STUserControl)ctrl).OnControlClosing();
}
stPanel2.Controls.Clear();
stPanel2.Controls.Add(control);
}
private void UpdateFiles()
{
Files = archiveFile.Files.ToList();
}
public void FillList(IArchiveFile file)
{
archiveFile = file;
UpdateFiles();
treeViewCustom1.BeginUpdate();
treeViewCustom1.Nodes.Clear();
if (Files.Count > 0)
{
var lookup = Files.OrderBy(f => f.FileName.TrimStart('/', '\\')).ToLookup(f => System.IO.Path.GetDirectoryName(f.FileName.TrimStart('/', '\\')));
// Build directory tree
var root = treeViewCustom1.Nodes.Add("root", ((IFileFormat)file).FileName, "tree-archive-file", "tree-archive-file");
foreach (var dir in lookup.Select(g => g.Key))
{
dir.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries)
.Aggregate(root, (node, part) => node.Nodes[part] ?? node.Nodes.Add(part, part))
.Tag = lookup[dir];
}
root.Expand();
treeViewCustom1.SelectedNode = root;
}
treeViewCustom1.EndUpdate();
}
private void LoadFiles()
{
listViewCustom1.BeginUpdate();
listViewCustom1.Items.Clear();
if (treeViewCustom1.SelectedNode?.Tag is IEnumerable<ArchiveFileInfo> files)
{
foreach (var file in files)
{
ListViewItem item = new ListViewItem(System.IO.Path.GetFileName(file.FileName));
item.SubItems.Add(file.GetSize());
item.SubItems.Add("");
item.SubItems.Add(file.State.ToString());
listViewCustom1.Items.Add(item);
}
}
listViewCustom1.EndUpdate();
}
private void treeViewCustom1_AfterSelect(object sender, TreeViewEventArgs e)
{
LoadFiles();
}
public void FormClosing()
{
foreach (var node in TreeViewExtensions.Collect(treeViewCustom1.Nodes))
{
if (node is IFileFormat)
{
((IFileFormat)node).Unload();
}
}
ClearNodes();
}
public void RemoveFile(TreeNode File)
{
if (File is IFileFormat) {
((IFileFormat)File).Unload();
}
treeViewCustom1.Nodes.Remove(File);
}
public void ResetControls()
{
treeViewCustom1.Nodes.Clear();
stPanel2.Controls.Clear();
Text = "";
}
private void stTextBox1_TextChanged(object sender, EventArgs e)
{
UpdateSearchBox();
}
private void stTextBox1_Click(object sender, EventArgs e)
{
searchImgPB.Visible = false;
searchLbl.Visible = false;
}
private void stTextBox1_Leave(object sender, EventArgs e)
{
UpdateSearchBox();
}
private void UpdateSearchBox()
{
if (stTextBox1.Text != string.Empty)
{
searchImgPB.Visible = false;
searchLbl.Visible = false;
}
else
{
searchLbl.Visible = true;
searchImgPB.Visible = true;
}
}
private void SearchText(string searchText)
{
//blocks repainting tree till all objects loaded
this.treeViewCustom1.BeginUpdate();
this.treeViewCustom1.Nodes.Clear();
if (searchText != string.Empty)
{
foreach (TreeNode _parentNode in _fieldsTreeCache.Nodes)
{
foreach (TreeNode _childNode in _parentNode.Nodes)
{
if (_childNode.Text.StartsWith(searchText))
{
this.treeViewCustom1.Nodes.Add((TreeNode)_childNode.Clone());
}
}
}
}
else
{
foreach (TreeNode _node in this._fieldsTreeCache.Nodes)
{
treeViewCustom1.Nodes.Add((TreeNode)_node.Clone());
}
}
//enables redrawing tree after all objects have been added
this.treeViewCustom1.EndUpdate();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = Utils.GetAllFilters(FileManager.GetFileFormats());
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
Cursor.Current = Cursors.WaitCursor;
foreach (string file in ofd.FileNames)
OpenFile(file);
Cursor.Current = Cursors.Default;
}
}
private void OpenFile(string FileName)
{
object file = STFileLoader.OpenFileFormat(FileName);
if (file is TreeNode)
{
var node = (TreeNode)file;
AddNode(node);
}
else
{
STErrorDialog.Show("Invalid file type. Cannot add file to object list.", "Object List","");
}
}
private void sortToolStripMenuItem_Click(object sender, EventArgs e)
{
treeViewCustom1.Sort();
}
private void splitter1_Resize(object sender, EventArgs e)
{
}
private void splitter1_LocationChanged(object sender, EventArgs e)
{
}
private void stPanel1_Resize(object sender, EventArgs e)
{
Runtime.ObjectEditor.ListPanelWidth = stPanel1.Width;
}
private void treeViewCustom1_DoubleClick(object sender, MouseEventArgs e)
{
}
}
}

View file

@ -1,6 +1,6 @@
namespace Switch_Toolbox.Library.Forms
{
partial class ObjectEditor
partial class ObjectEditorTree
{
/// <summary>
/// Required designer variable.
@ -43,40 +43,29 @@
this.sortToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.stPanel2 = new Switch_Toolbox.Library.Forms.STPanel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.contentContainer.SuspendLayout();
this.stPanel1.SuspendLayout();
this.stPanel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.searchImgPB)).BeginInit();
this.stContextMenuStrip1.SuspendLayout();
this.SuspendLayout();
//
// contentContainer
//
this.contentContainer.Controls.Add(this.splitter1);
this.contentContainer.Controls.Add(this.stPanel2);
this.contentContainer.Controls.Add(this.stPanel1);
this.contentContainer.Size = new System.Drawing.Size(901, 537);
this.contentContainer.Controls.SetChildIndex(this.stPanel1, 0);
this.contentContainer.Controls.SetChildIndex(this.stPanel2, 0);
this.contentContainer.Controls.SetChildIndex(this.splitter1, 0);
//
// stPanel1
//
this.stPanel1.Controls.Add(this.activeEditorChkBox);
this.stPanel1.Controls.Add(this.searchLbl);
this.stPanel1.Controls.Add(this.treeViewCustom1);
this.stPanel1.Controls.Add(this.stTextBox1);
this.stPanel1.Controls.Add(this.stPanel3);
this.stPanel1.Controls.Add(this.stContextMenuStrip1);
this.stPanel1.Dock = System.Windows.Forms.DockStyle.Left;
this.stPanel1.Location = new System.Drawing.Point(0, 25);
this.stPanel1.Location = new System.Drawing.Point(0, 0);
this.stPanel1.Name = "stPanel1";
this.stPanel1.Size = new System.Drawing.Size(314, 512);
this.stPanel1.Size = new System.Drawing.Size(314, 542);
this.stPanel1.TabIndex = 11;
this.stPanel1.Resize += new System.EventHandler(this.stPanel1_Resize);
//
// activeEditorChkBox
//
this.activeEditorChkBox.AutoSize = true;
this.activeEditorChkBox.Location = new System.Drawing.Point(93, 4);
this.activeEditorChkBox.Location = new System.Drawing.Point(137, 6);
this.activeEditorChkBox.Name = "activeEditorChkBox";
this.activeEditorChkBox.Size = new System.Drawing.Size(144, 17);
this.activeEditorChkBox.TabIndex = 3;
@ -93,10 +82,10 @@
this.treeViewCustom1.CheckBoxes = true;
this.treeViewCustom1.DrawMode = System.Windows.Forms.TreeViewDrawMode.OwnerDrawAll;
this.treeViewCustom1.ImageIndex = 0;
this.treeViewCustom1.Location = new System.Drawing.Point(1, 53);
this.treeViewCustom1.Location = new System.Drawing.Point(1, 55);
this.treeViewCustom1.Name = "treeViewCustom1";
this.treeViewCustom1.SelectedImageIndex = 0;
this.treeViewCustom1.Size = new System.Drawing.Size(311, 458);
this.treeViewCustom1.Size = new System.Drawing.Size(311, 486);
this.treeViewCustom1.TabIndex = 0;
this.treeViewCustom1.AfterCheck += new System.Windows.Forms.TreeViewEventHandler(this.treeViewCustom1_AfterCheck);
this.treeViewCustom1.DrawNode += new System.Windows.Forms.DrawTreeNodeEventHandler(this.treeViewCustom1_DrawNode);
@ -106,11 +95,11 @@
//
// stPanel3
//
this.stPanel3.Controls.Add(this.searchLbl);
this.stPanel3.Controls.Add(this.searchImgPB);
this.stPanel3.Controls.Add(this.stTextBox1);
this.stPanel3.Controls.Add(this.activeEditorChkBox);
this.stPanel3.Controls.Add(this.stContextMenuStrip1);
this.stPanel3.Dock = System.Windows.Forms.DockStyle.Top;
this.stPanel3.Location = new System.Drawing.Point(0, 24);
this.stPanel3.Location = new System.Drawing.Point(0, 0);
this.stPanel3.Name = "stPanel3";
this.stPanel3.Size = new System.Drawing.Size(314, 26);
this.stPanel3.TabIndex = 2;
@ -119,7 +108,7 @@
//
this.searchLbl.AutoSize = true;
this.searchLbl.ForeColor = System.Drawing.Color.Silver;
this.searchLbl.Location = new System.Drawing.Point(9, 5);
this.searchLbl.Location = new System.Drawing.Point(3, 31);
this.searchLbl.Name = "searchLbl";
this.searchLbl.Size = new System.Drawing.Size(41, 13);
this.searchLbl.TabIndex = 2;
@ -142,7 +131,7 @@
this.stTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.stTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.stTextBox1.Location = new System.Drawing.Point(3, 3);
this.stTextBox1.Location = new System.Drawing.Point(0, 29);
this.stTextBox1.Name = "stTextBox1";
this.stTextBox1.Size = new System.Drawing.Size(311, 20);
this.stTextBox1.TabIndex = 0;
@ -152,12 +141,13 @@
//
// stContextMenuStrip1
//
this.stContextMenuStrip1.Dock = System.Windows.Forms.DockStyle.Fill;
this.stContextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.viewToolStripMenuItem});
this.stContextMenuStrip1.Location = new System.Drawing.Point(0, 0);
this.stContextMenuStrip1.Name = "stContextMenuStrip1";
this.stContextMenuStrip1.Size = new System.Drawing.Size(314, 24);
this.stContextMenuStrip1.Size = new System.Drawing.Size(314, 26);
this.stContextMenuStrip1.TabIndex = 1;
this.stContextMenuStrip1.Text = "stContextMenuStrip1";
//
@ -166,7 +156,7 @@
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.openToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 22);
this.fileToolStripMenuItem.Text = "File";
//
// openToolStripMenuItem
@ -181,7 +171,7 @@
this.viewToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.sortToolStripMenuItem});
this.viewToolStripMenuItem.Name = "viewToolStripMenuItem";
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 20);
this.viewToolStripMenuItem.Size = new System.Drawing.Size(44, 22);
this.viewToolStripMenuItem.Text = "View";
//
// sortToolStripMenuItem
@ -194,30 +184,28 @@
// stPanel2
//
this.stPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.stPanel2.Location = new System.Drawing.Point(314, 25);
this.stPanel2.Location = new System.Drawing.Point(314, 0);
this.stPanel2.Name = "stPanel2";
this.stPanel2.Size = new System.Drawing.Size(587, 512);
this.stPanel2.Size = new System.Drawing.Size(593, 542);
this.stPanel2.TabIndex = 12;
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(314, 25);
this.splitter1.Location = new System.Drawing.Point(314, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 512);
this.splitter1.Size = new System.Drawing.Size(3, 542);
this.splitter1.TabIndex = 13;
this.splitter1.TabStop = false;
this.splitter1.LocationChanged += new System.EventHandler(this.splitter1_LocationChanged);
this.splitter1.Resize += new System.EventHandler(this.splitter1_Resize);
//
// ObjectEditor
// ObjectEditorTree
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(907, 542);
this.MainMenuStrip = this.stContextMenuStrip1;
this.Name = "ObjectEditor";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ObjectEditor_FormClosed);
this.contentContainer.ResumeLayout(false);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.stPanel2);
this.Controls.Add(this.stPanel1);
this.Name = "ObjectEditorTree";
this.Size = new System.Drawing.Size(907, 542);
this.stPanel1.ResumeLayout(false);
this.stPanel1.PerformLayout();
this.stPanel3.ResumeLayout(false);

View file

@ -15,14 +15,14 @@ using Switch_Toolbox.Library.IO;
namespace Switch_Toolbox.Library.Forms
{
public partial class ObjectEditor : STForm
public partial class ObjectEditorTree : UserControl
{
private TreeView _fieldsTreeCache;
public void BeginUpdate() { treeViewCustom1.BeginUpdate(); }
public void EndUpdate() { treeViewCustom1.EndUpdate(); }
public void AddNodeCollection (TreeNodeCollection nodes, bool ClearNodes)
public void AddNodeCollection(TreeNodeCollection nodes, bool ClearNodes)
{
// Invoke the treeview to add the nodes
treeViewCustom1.Invoke((Action)delegate ()
@ -70,7 +70,7 @@ namespace Switch_Toolbox.Library.Forms
public void ClearNodes()
{
treeViewCustom1.Nodes.Clear();
// _fieldsTreeCache.Nodes.Clear();
// _fieldsTreeCache.Nodes.Clear();
}
public bool AddFilesToActiveEditor
@ -86,13 +86,7 @@ namespace Switch_Toolbox.Library.Forms
}
}
public static ObjectEditor Instance
{
get { return _instance != null ? _instance : (_instance = new ObjectEditor()); }
}
private static ObjectEditor _instance;
public ObjectEditor()
public ObjectEditorTree()
{
InitializeComponent();
@ -218,13 +212,16 @@ namespace Switch_Toolbox.Library.Forms
}
}
private void ObjectEditor_FormClosed(object sender, FormClosedEventArgs e)
public List<Control> GetEditors()
{
Viewport viewport = LibraryGUI.Instance.GetActiveViewport();
if (viewport != null)
viewport.FormClosing();
List<Control> controls = new List<Control>();
foreach (Control ctrl in stPanel2.Controls)
controls.Add(ctrl);
return controls;
}
public void FormClosing()
{
foreach (var control in stPanel2.Controls)
{
if (control is STUserControl)
@ -252,7 +249,7 @@ namespace Switch_Toolbox.Library.Forms
{
if (((Animation)e.Node).Bones.Count <= 0)
((Animation)e.Node).OpenAnimationData();
string AnimName = e.Node.Text;
AnimName = Regex.Match(AnimName, @"([A-Z][0-9][0-9])(.*)").Groups[0].ToString();
if (AnimName.Length > 3)
@ -307,7 +304,8 @@ namespace Switch_Toolbox.Library.Forms
public void RemoveFile(TreeNode File)
{
if (File is IFileFormat) {
if (File is IFileFormat)
{
((IFileFormat)File).Unload();
}
@ -333,10 +331,12 @@ namespace Switch_Toolbox.Library.Forms
CheckChildNodes(e.Node, e.Node.Checked);
IsModelChecked = false;
}
else if (e.Node is STGenericObject && !IsModelChecked) {
else if (e.Node is STGenericObject && !IsModelChecked)
{
UpdateViewport = true;
}
else if (e.Node is STBone && !IsModelChecked) {
else if (e.Node is STBone && !IsModelChecked)
{
UpdateViewport = true;
}
@ -461,7 +461,7 @@ namespace Switch_Toolbox.Library.Forms
}
else
{
STErrorDialog.Show("Invalid file type. Cannot add file to object list.", "Object List","");
STErrorDialog.Show("Invalid file type. Cannot add file to object list.", "Object List", "");
}
}

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="stContextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>

View file

@ -114,7 +114,7 @@ namespace Switch_Toolbox.Library
if (Runtime.MainForm.ActiveMdiChild is ObjectEditor)
{
foreach (var ctrl in ((ObjectEditor)Runtime.MainForm.ActiveMdiChild).stPanel2.Controls)
foreach (var ctrl in ((ObjectEditor)Runtime.MainForm.ActiveMdiChild).GetEditors())
{
if (type == null) {
return (UserControl)ctrl;
@ -158,9 +158,5 @@ namespace Switch_Toolbox.Library
{
}
public bool IsContentActive(UserControl control)
{
return ObjectEditor.Instance.Controls.Contains(control);
}
}
}

View file

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Switch_Toolbox.Library
{
public class GenericArchive
{
public List<ArchiveFileInfo> Files = new List<ArchiveFileInfo>();
}
public class ArchiveFileInfo
{
IFileFormat FileFormat = null; //Format attached for saving
protected Stream _fileData = null;
public string FileName { get; set; } = string.Empty; //Full File Name
public string Name { get; set; } = string.Empty; //File Name (No Path)
public virtual Stream FileData
{
get
{
_fileData.Position = 0;
return _fileData;
}
set { _fileData = value; }
}
}
}

View file

@ -81,11 +81,11 @@ namespace Switch_Toolbox.Library
RotationType = STBone.BoneRotationType.Quaternion;
ApplyTransforms();
//Update matrices
skeletonParent.reset();
skeletonParent.update();
ApplyTransforms();
}
public void ConvertToEular()
@ -95,11 +95,11 @@ namespace Switch_Toolbox.Library
RotationType = STBone.BoneRotationType.Euler;
ApplyTransforms();
//Update matrices
skeletonParent.reset();
skeletonParent.update();
ApplyTransforms();
}
public override void OnClick(TreeView treeView)

View file

@ -70,6 +70,7 @@ namespace Switch_Toolbox.Library.IO
string Magic = fileReader.ReadMagic(0, 4);
fileReader.Position = 0;
ushort MagicHex2 = fileReader.ReadUInt16();
if (Magic == "Yaz0")
{
@ -105,7 +106,7 @@ namespace Switch_Toolbox.Library.IO
return OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true,
CompressionType.Zlib, DecompressedFileSize, CompressedFileSize);
}
if (MagicHex == 0x1f8b0808 && CompType == CompressionType.None)
if (MagicHex == 0x1f8b0808 || MagicHex2 == 0x1f8b && CompType == CompressionType.None)
{
if (data == null)
data = File.ReadAllBytes(FileName);

View file

@ -7,7 +7,17 @@ using System.Windows.Forms;
namespace Switch_Toolbox.Library
{
public interface IArchiveFile : IFileFormat
public enum ArchiveFileState
{
Empty = 0,
Archived = 1,
Added = 2,
Replaced = 4,
Renamed = 8,
Deleted = 16
}
public interface IArchiveFile
{
bool CanAddFiles { get; }
bool CanRenameFiles { get; }
@ -15,69 +25,49 @@ namespace Switch_Toolbox.Library
bool CanDeleteFiles { get; }
IEnumerable<ArchiveFileInfo> Files { get; }
bool AddFile(ArchiveFileInfo archiveFileInfo);
bool DeleteFile(ArchiveFileInfo archiveFileInfo);
}
//This abstract class can be more advanced than the interface
public abstract class ArchiveFile : TreeNodeCustom
public class ArchiveFileInfo
{
public bool CanAddFiles { get; }
public bool CanRenameFiles { get; }
public bool CanReplaceFiles { get; }
public bool CanDeleteFiles { get; }
public FileType FileDataType = FileType.Default;
List<ArchiveFileInfo> Files { get; }
public virtual void FillTreeNodes()
//Will be used for list categories
public enum FileType
{
Default,
Images,
Archives,
Graphics,
Models,
Shaders,
Collision,
Byaml,
Parameters,
}
/* private void ExportAll(string Folder, STProgressBar progressBar)
public string GetSize()
{
int Curfile = 0;
foreach (ArchiveFileInfo file in Files)
return STMath.GetFileSize(FileData.Length, 4);
}
IFileFormat FileFormat = null; //Format attached for saving
protected Stream _fileData = null;
public string FileName { get; set; } = string.Empty; //Full File Name
public string Name { get; set; } = string.Empty; //File Name (No Path)
public virtual Stream FileData
{
get
{
int value = (Curfile * 100) / Files.Count;
progressBar.Value = value;
progressBar.Refresh();
try
{
if (!String.IsNullOrWhiteSpace(Path.GetDirectoryName($"{Folder}/{file.FullPath}")))
{
if (!File.Exists(file.FullPath))
{
if (!Directory.Exists($"{Folder}/{file.FullPath}"))
{
Directory.CreateDirectory(Path.GetDirectoryName($"{Folder}/{file.FullPath}"));
}
}
}
File.WriteAllBytes($"{Folder}/{file.FullPath}", file.FileData);
}
catch
{
}
Curfile++;
if (value == 99)
value = 100;
progressBar.Value = value;
progressBar.Refresh();
_fileData.Position = 0;
return _fileData;
}
}*/
public bool AddFile(ArchiveFileInfo archiveFileInfo)
{
return false;
set { _fileData = value; }
}
public bool DeleteFile(ArchiveFileInfo archiveFileInfo)
{
return false;
}
public ArchiveFileState State { get; set; } = ArchiveFileState.Empty;
}
}

View file

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Switch_Toolbox.Library
{
public static class STMath
{
private const long SizeOfKb = 1024;
private const long SizeOfMb = SizeOfKb * 1024;
private const long SizeOfGb = SizeOfMb * 1024;
private const long SizeOfTb = SizeOfGb * 1024;
public static double ConvertBytesToMegabytes(long bytes)
{
return (bytes / SizeOfKb) / SizeOfKb;
}
static double ConvertKilobytesToMegabytes(long kilobytes)
{
return kilobytes / SizeOfKb;
}
public static string GetFileSize(this long value, int decimalPlaces = 0)
{
var asTb = Math.Round((double)value / SizeOfTb, decimalPlaces);
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));
return chosenValue;
}
}
}

Binary file not shown.

View file

@ -384,6 +384,18 @@
<Compile Include="Forms\Editors\ImageEditor\ImageResizeDialog.Designer.cs">
<DependentUpon>ImageResizeDialog.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Editors\Object Editor\ObjectEditorList.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Forms\Editors\Object Editor\ObjectEditorList.Designer.cs">
<DependentUpon>ObjectEditorList.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Editors\Object Editor\ObjectEditorTree.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Forms\Editors\Object Editor\ObjectEditorTree.Designer.cs">
<DependentUpon>ObjectEditorTree.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Editors\TextEditor\TextEditorForm.cs">
<SubType>Form</SubType>
</Compile>
@ -397,10 +409,10 @@
<DependentUpon>TimeLine.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Extensions\MDICustom.cs" />
<Compile Include="Forms\Editors\ObjectEditor.cs">
<Compile Include="Forms\Editors\Object Editor\ObjectEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Editors\ObjectEditor.Designer.cs">
<Compile Include="Forms\Editors\Object Editor\ObjectEditor.Designer.cs">
<DependentUpon>ObjectEditor.cs</DependentUpon>
</Compile>
<Compile Include="Forms\Custom\STButton.cs">
@ -470,7 +482,6 @@
<Compile Include="Forms\Wpf\WpfTimeline.xaml.cs">
<DependentUpon>WpfTimeline.xaml</DependentUpon>
</Compile>
<Compile Include="Generics\GenericArchive.cs" />
<Compile Include="Generics\GenericMaterial.cs" />
<Compile Include="Generics\GenericMatTexture.cs" />
<Compile Include="Generics\GenericModel.cs" />
@ -493,7 +504,7 @@
<SubType>Component</SubType>
</Compile>
<Compile Include="Forms\Editors\Assimp Settings.cs">
<SubType>UserControl</SubType>
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Editors\Assimp Settings.Designer.cs">
<DependentUpon>Assimp Settings.cs</DependentUpon>
@ -533,6 +544,7 @@
<Compile Include="IO\STFileSaver.cs" />
<Compile Include="IO\StringExtension.cs" />
<Compile Include="IO\STStream.cs" />
<Compile Include="Maths\Math.cs" />
<Compile Include="Plugin\GenericPluginLoader.cs" />
<Compile Include="Forms\Editors\Animation\AnimationPanel.cs">
<SubType>UserControl</SubType>
@ -713,9 +725,15 @@
<EmbeddedResource Include="Forms\Editors\ImageEditor\ImageResizeDialog.resx">
<DependentUpon>ImageResizeDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editors\ObjectEditor.resx">
<EmbeddedResource Include="Forms\Editors\Object Editor\ObjectEditorList.resx">
<DependentUpon>ObjectEditorList.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editors\Object Editor\ObjectEditor.resx">
<DependentUpon>ObjectEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editors\Object Editor\ObjectEditorTree.resx">
<DependentUpon>ObjectEditorTree.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\Editors\ObjectList.resx">
<DependentUpon>ObjectList.cs</DependentUpon>
</EmbeddedResource>

View file

@ -256,19 +256,16 @@ namespace Toolbox
}
bool IsTreeNode = file is TreeNode;
bool IsArchiveFile = file is IArchiveFile;
if (!IsTreeNode || HasEditorActive)
if (!IsTreeNode && !IsArchiveFile || HasEditorActive)
{
SetFormatSettings(GetActiveIFileFormat());
return;
}
var node = (TreeNode)file;
//ObjectEditor is for treenode types. Editors will be on the right side, treenodes on the left
SetFormatSettings((IFileFormat)node);
//ObjectEditor is for treenode or archive file types. Editors will be on the right side, treenodes on the left
SetFormatSettings((IFileFormat)file);
//Check for active object editors
Form editor = (Form)LibraryGUI.Instance.GetActiveForm();
@ -286,23 +283,22 @@ namespace Toolbox
bool IsEditorActive = editor != null;
//Create one if none are active
if (!IsEditorActive)
{
editor = new ObjectEditor();
}
if (!useActiveEditor || !IsEditorActive)
{
editor = new ObjectEditor();
AddObjectEditorFile(node, (ObjectEditor)editor, true);
editor = new ObjectEditor(((IFileFormat)file));
editor.Text = CheckTabDupes(node.Text);
editor.MdiParent = this;
editor.Text = CheckTabDupes(((IFileFormat)file).FileName);
editor.Show();
if (file is TreeNodeFile)
{
((TreeNodeFile)file).OnAfterAdded();
}
}
else
{
AddObjectEditorFile(node, (ObjectEditor)editor, false);
AddObjectEditorFile(((TreeNode)file), (ObjectEditor)editor, false);
}
SetFormatSettings(GetActiveIFileFormat());