mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-12-19 01:13:11 +00:00
107 lines
2.9 KiB
C#
107 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using Switch_Toolbox;
|
|
using System.Windows.Forms;
|
|
using Switch_Toolbox.Library;
|
|
using ByamlExt.Byaml;
|
|
using ByamlExt;
|
|
using FirstPlugin.Turbo;
|
|
|
|
namespace FirstPlugin
|
|
{
|
|
public class BYAML : IEditor<ByamlEditor>, IFileFormat
|
|
{
|
|
public bool CanSave { get; set; }
|
|
public string[] Description { get; set; } = new string[] { "BYAML" };
|
|
public string[] Extension { get; set; } = new string[] { "*.byaml", "*.byml", "*.bprm", "*.sbyml" };
|
|
public string FileName { get; set; }
|
|
public string FilePath { get; set; }
|
|
public IFileInfo IFileInfo { get; set; }
|
|
|
|
public bool Identify(System.IO.Stream stream)
|
|
{
|
|
using (var reader = new Switch_Toolbox.Library.IO.FileReader(stream, true))
|
|
{
|
|
if (reader.CheckSignature(2, "BY") || reader.CheckSignature(2, "YB"))
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public Type[] Types
|
|
{
|
|
get
|
|
{
|
|
List<Type> types = new List<Type>();
|
|
return types.ToArray();
|
|
}
|
|
}
|
|
|
|
class EditableNode
|
|
{
|
|
public Type type { get { return Node[Index].GetType(); } }
|
|
dynamic Node;
|
|
dynamic Index;
|
|
|
|
public dynamic Get() { return Node[Index]; }
|
|
|
|
public void Set(dynamic value) { Node[Index] = value; }
|
|
public string GetTreeViewString()
|
|
{
|
|
if (Index is int)
|
|
return Node[Index].ToString();
|
|
else
|
|
return Index + " : " + Node[Index].ToString();
|
|
}
|
|
|
|
public EditableNode(dynamic _node, dynamic _index)
|
|
{
|
|
Node = _node;
|
|
Index = _index;
|
|
}
|
|
}
|
|
|
|
bool IsDialog = false;
|
|
BymlFileData data;
|
|
|
|
public ByamlEditor OpenForm()
|
|
{
|
|
ByamlEditor editor = new ByamlEditor(data.RootNode, data.SupportPaths, data.Version, data.byteOrder, IsDialog, this);
|
|
editor.FileFormat = this;
|
|
editor.Text = FileName;
|
|
editor.Dock = DockStyle.Fill;
|
|
return editor;
|
|
}
|
|
|
|
public void Load(Stream stream)
|
|
{
|
|
CanSave = true;
|
|
|
|
IsDialog = IFileInfo != null && IFileInfo.InArchive;
|
|
|
|
data = ByamlFile.LoadN(stream, true);
|
|
}
|
|
public void Unload()
|
|
{
|
|
|
|
}
|
|
|
|
public byte[] Save()
|
|
{
|
|
MemoryStream mem = new MemoryStream();
|
|
ByamlFile.SaveN(mem, new BymlFileData
|
|
{
|
|
Version = data.Version,
|
|
byteOrder = data.byteOrder,
|
|
SupportPaths = data.SupportPaths,
|
|
RootNode = data.RootNode
|
|
});
|
|
|
|
return mem.ToArray();
|
|
}
|
|
}
|
|
}
|