2018-11-22 22:17:03 +01:00
|
|
|
|
using System;
|
|
|
|
|
using Switch_Toolbox.Library;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using FirstPlugin;
|
|
|
|
|
|
|
|
|
|
namespace Bfres.Structs
|
|
|
|
|
{
|
|
|
|
|
public class EmbeddedFilesFolder : TreeNodeCustom
|
|
|
|
|
{
|
|
|
|
|
public EmbeddedFilesFolder()
|
|
|
|
|
{
|
|
|
|
|
Text = "Embedded Files";
|
|
|
|
|
Name = "EXT";
|
|
|
|
|
|
|
|
|
|
ContextMenu = new ContextMenu();
|
|
|
|
|
MenuItem import = new MenuItem("Import");
|
|
|
|
|
ContextMenu.MenuItems.Add(import);
|
|
|
|
|
import.Click += Import;
|
|
|
|
|
MenuItem exportAll = new MenuItem("Export All");
|
|
|
|
|
ContextMenu.MenuItems.Add(exportAll);
|
|
|
|
|
exportAll.Click += ExportAll;
|
|
|
|
|
MenuItem clear = new MenuItem("Clear");
|
|
|
|
|
ContextMenu.MenuItems.Add(clear);
|
|
|
|
|
clear.Click += Clear;
|
|
|
|
|
}
|
|
|
|
|
public void Import(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public void ExportAll(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void Clear(object sender, EventArgs args)
|
|
|
|
|
{
|
2018-11-22 23:06:22 +01:00
|
|
|
|
DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all external files? This cannot be undone!", "", MessageBoxButtons.YesNo);
|
2018-11-22 22:17:03 +01:00
|
|
|
|
|
|
|
|
|
if (dialogResult == DialogResult.Yes)
|
|
|
|
|
{
|
2018-11-23 01:40:36 +01:00
|
|
|
|
foreach (var ext in Nodes)
|
|
|
|
|
{
|
2018-12-02 23:30:46 +01:00
|
|
|
|
if (ext is BNTX)
|
2018-11-23 01:40:36 +01:00
|
|
|
|
{
|
2018-12-02 23:30:46 +01:00
|
|
|
|
PluginRuntime.bntxContainers.Remove((BNTX)ext);
|
2018-11-23 01:40:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-22 22:17:03 +01:00
|
|
|
|
Nodes.Clear();
|
2018-11-23 01:40:36 +01:00
|
|
|
|
Viewport.Instance.Refresh();
|
2018-11-22 22:17:03 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public override void OnClick(TreeView treeView)
|
|
|
|
|
{
|
|
|
|
|
FormLoader.LoadEditor(this, Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class ExternalFileData : TreeNode
|
|
|
|
|
{
|
|
|
|
|
public byte[] Data;
|
|
|
|
|
public ExternalFileData(byte[] data, string Name)
|
|
|
|
|
{
|
|
|
|
|
Text = Name;
|
|
|
|
|
ImageKey = "folder";
|
|
|
|
|
Data = data;
|
|
|
|
|
|
|
|
|
|
ContextMenu = new ContextMenu();
|
|
|
|
|
MenuItem export = new MenuItem("Export");
|
|
|
|
|
ContextMenu.MenuItems.Add(export);
|
|
|
|
|
export.Click += Export;
|
|
|
|
|
MenuItem replace = new MenuItem("Replace");
|
|
|
|
|
ContextMenu.MenuItems.Add(replace);
|
|
|
|
|
replace.Click += Import;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Import(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
|
|
ofd.Filter = "All files(*.*)|*.*";
|
|
|
|
|
|
|
|
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
Data = System.IO.File.ReadAllBytes(ofd.FileName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Export(object sender, EventArgs args)
|
|
|
|
|
{
|
|
|
|
|
SaveFileDialog sfd = new SaveFileDialog();
|
|
|
|
|
sfd.Filter = "All files(*.*)|*.*";
|
|
|
|
|
|
|
|
|
|
sfd.DefaultExt = System.IO.Path.GetExtension(Text);
|
|
|
|
|
sfd.FileName = Text;
|
|
|
|
|
|
|
|
|
|
if (sfd.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
System.IO.File.WriteAllBytes(sfd.FileName, Data);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|