Add preview archive option to sarc

This commit is contained in:
KillzXGaming 2019-06-09 13:51:04 -04:00
parent b79da4ff95
commit 5546d0da24
9 changed files with 69 additions and 11 deletions

Binary file not shown.

View file

@ -282,43 +282,48 @@ namespace FirstPlugin
{
SuppressFormDialog = true;
List<IFileFormat> Formats = new List<IFileFormat>();
try
{
CallRecursive(TreeView);
CallRecursive(TreeView, Formats);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
PreviewEditor editor = new PreviewEditor();
ArchiveListPreviewForm editor = new ArchiveListPreviewForm();
editor.LoadArchive(Formats);
editor.Show();
SuppressFormDialog = false;
}
private void CallRecursive(TreeView treeView)
private void CallRecursive(TreeView treeView, List<IFileFormat> Formats)
{
// Print each node recursively.
TreeNodeCollection nodes = treeView.Nodes;
foreach (TreeNode n in nodes)
{
PrintRecursive(n);
GetNodeFileFormat(n, Formats);
}
}
private void PrintRecursive(TreeNode treeNode)
private void GetNodeFileFormat(TreeNode treeNode, List<IFileFormat> Formats)
{
// Print the node.
if (treeNode is SarcEntry)
{
((SarcEntry)treeNode).OnDoubleMouseClick(treeNode.TreeView);
var format = ((SarcEntry)treeNode).OpenFile();
if (format != null)
Formats.Add(format);
}
// Print each node recursively.
foreach (TreeNode tn in treeNode.Nodes)
{
PrintRecursive(tn);
GetNodeFileFormat(tn, Formats);
}
}
@ -361,12 +366,17 @@ namespace FirstPlugin
editor.LoadData(Data);
}
public IFileFormat OpenFile()
{
return STFileLoader.OpenFileFormat(FullName, Data, false, true, this);
}
public override void OnDoubleMouseClick(TreeView treeView)
{
if (Data.Length <= 0)
return;
IFileFormat file = STFileLoader.OpenFileFormat(FullName, Data,false, true, this);
IFileFormat file = OpenFile();
if (file == null) //File returns null if no supported format is found
return;

View file

@ -14,7 +14,7 @@ namespace FirstPlugin
{
public class BFLIM : STGenericTexture, IEditor<ImageEditorForm>, IFileFormat
{
public FileType FileType { get; set; } = FileType.Layout;
public FileType FileType { get; set; } = FileType.Image;
public override TEX_FORMAT[] SupportedFormats
{

View file

@ -22,6 +22,23 @@ namespace Switch_Toolbox.Library.Forms
private ListViewItem ActiveItem;
public void LoadArchive(List<IFileFormat> Files)
{
ImageList.ColorDepth = ColorDepth.Depth32Bit;
ImageList.ImageSize = new Size(40, 40);
listViewCustom1.LargeImageList = ImageList;
for (int i = 0; i < Files.Count; i++)
{
if (Files[i].FileType == FileType.Image)
{
Textures.AddRange(GetTextures(Files[i]));
}
}
ReloadTextures();
}
public void LoadArchive(IArchiveFile ArchiveFile)
{
ImageList.ColorDepth = ColorDepth.Depth32Bit;

View file

@ -427,18 +427,48 @@ namespace Switch_Toolbox.Library
{
ContextMenuStrip = new STContextMenuStrip();
ContextMenuStrip.Items.Add(new STToolStripItem("Rename", RenameAction) { Enabled = archiveFile.CanRenameFiles });
ContextMenuStrip.Items.Add(new STToolStripItem("Extract", ExtractAction));
ContextMenuStrip.Items.Add(new STToolStripItem("Replace", ReplaceAction) { Enabled = archiveFile.CanReplaceFiles });
ContextMenuStrip.Items.Add(new STToolStripItem("Export Raw Data", ExtractAction));
ContextMenuStrip.Items.Add(new STToolStipMenuItem("Export Raw Data to File Location", null, ExportToFileLocAction, Keys.Control | Keys.F));
ContextMenuStrip.Items.Add(new STToolStripItem("Replace Raw Data", ReplaceAction) { Enabled = archiveFile.CanReplaceFiles });
ContextMenuStrip.Items.Add(new STToolStripSeparator());
ContextMenuStrip.Items.Add(new STToolStipMenuItem("Open With Text Editor", null, OpenTextEditorAction, Keys.Control | Keys.T));
ContextMenuStrip.Items.Add(new STToolStripSeparator());
ContextMenuStrip.Items.Add(new STToolStripItem("Delete", DeleteAction) { Enabled = archiveFile.CanDeleteFiles });
}
private void OpenTextEditorAction(object sender, EventArgs args)
{
TextEditor editor = (TextEditor)LibraryGUI.Instance.GetActiveContent(typeof(TextEditor));
if (editor == null)
{
editor = new TextEditor();
LibraryGUI.Instance.LoadEditor(editor);
}
editor.Text = Text;
editor.Dock = DockStyle.Fill;
editor.FillEditor(ArchiveFileInfo.FileData);
}
private void ExtractAction(object sender, EventArgs args)
{
ArchiveFileInfo.Export();
}
private void ExportToFileLocAction(object sender, EventArgs args)
{
Cursor.Current = Cursors.WaitCursor;
File.WriteAllBytes($"{Path.GetDirectoryName(((IFileFormat)ArchiveFile).FilePath)}/{Text}", ArchiveFileInfo.FileData);
Cursor.Current = Cursors.Default;
}
private void DeleteAction(object sender, EventArgs args)
{
DialogResult result = MessageBox.Show($"Are your sure you want to remove {Text}? This cannot be undone!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
ArchiveFile.DeleteFile(ArchiveFileInfo);
Parent.Nodes.Remove(this);
}
}
private void ReplaceAction(object sender, EventArgs args)
@ -526,6 +556,7 @@ namespace Switch_Toolbox.Library
NewNode.ImageKey = replaceNode.ImageKey;
NewNode.SelectedImageKey = replaceNode.SelectedImageKey;
NewNode.Text = replaceNode.Text;
}
private void RenameAction(object sender, EventArgs args)