Fix skeleton issues. More archive improvement.

This commit is contained in:
KillzXGaming 2019-05-29 14:24:24 -04:00
parent cb6cc251bd
commit d1c32844d1
19 changed files with 153 additions and 98 deletions

Binary file not shown.

View file

@ -49,10 +49,10 @@ namespace FirstPlugin
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 bool CanAddFiles { get; set; } = true;
public bool CanRenameFiles { get; set; } = true;
public bool CanReplaceFiles { get; set; } = true;
public bool CanDeleteFiles { get; set; } = true;
public Dictionary<long, byte[]> SavedDataEntries = new Dictionary<long, byte[]>();
public Dictionary<long, string> SavedStringEntries = new Dictionary<long, string>();
@ -207,12 +207,19 @@ namespace FirstPlugin
public bool AddFile(ArchiveFileInfo archiveFileInfo)
{
return false;
files.Add(new FileInfo()
{
FileData = archiveFileInfo.FileData,
FileName = archiveFileInfo.FileName,
});
return true;
}
public bool DeleteFile(ArchiveFileInfo archiveFileInfo)
{
return false;
return true;
}
}
}

View file

@ -304,10 +304,13 @@ namespace FirstPlugin
public void LoadEditors(object SelectedSection)
{
BfresEditor bfresEditor = (BfresEditor)LibraryGUI.Instance.GetActiveContent(typeof(BfresEditor));
bool HasModels = BFRESRender.models.Count > 0;
bool HasModels = false;
if (bfresEditor == null)
{
BFRESRender.UpdateModelList();
HasModels = BFRESRender.models.Count > 0;
bfresEditor = new BfresEditor(HasModels);
bfresEditor.Dock = DockStyle.Fill;
LibraryGUI.Instance.LoadEditor(bfresEditor);
@ -402,11 +405,6 @@ namespace FirstPlugin
return;
}
var toolstrips = new List<ToolStripMenuItem>();
var menu = new ToolStripMenuItem("Animation Loader", null, AnimLoader);
toolstrips.Add(menu);
if (drawables.Count <= 0)
{
//Add drawables
@ -417,7 +415,7 @@ namespace FirstPlugin
}
if (Runtime.UseOpenGL)
bfresEditor.LoadViewport(drawables, toolstrips);
bfresEditor.LoadViewport(drawables, new List<ToolStripMenuItem>());
bool IsSimpleEditor = PluginRuntime.UseSimpleBfresEditor;

View file

@ -761,8 +761,6 @@ namespace Bfres.Structs
{
Text = texture.Name;
MessageBox.Show("UPDATE PROB");
RedChannel = SetChannel(texture.CompSelR);
GreenChannel = SetChannel(texture.CompSelG);
BlueChannel = SetChannel(texture.CompSelB);

View file

@ -45,7 +45,7 @@ namespace FirstPlugin
}
}
private void UpdateModelList()
public void UpdateModelList()
{
foreach (var node in ResFileNode.Nodes)
{

View file

@ -135,18 +135,11 @@ namespace Switch_Toolbox.Library.Forms
{
// Node was not found, add it
var folder = new ArchiveFolderNodeWrapper(parentName);
folder.CanReplace = archiveFile.CanReplaceFiles;
folder.CanDelete = archiveFile.CanDeleteFiles;
folder.CanRename = archiveFile.CanRenameFiles;
var folder = new ArchiveFolderNodeWrapper(parentName, archiveFile);
if (rootIndex == roots.Length - 1)
{
ArchiveNodeWrapper wrapperFile = new ArchiveNodeWrapper(parentName);
wrapperFile.CanReplace = archiveFile.CanReplaceFiles;
wrapperFile.CanDelete = archiveFile.CanDeleteFiles;
wrapperFile.CanRename = archiveFile.CanRenameFiles;
ArchiveFileWrapper wrapperFile = new ArchiveFileWrapper(parentName, archiveFile);
wrapperFile.ArchiveFileInfo = node;
wrapperFile.Name = nodeName;
parentNode.Nodes.Add(wrapperFile);

View file

@ -492,39 +492,26 @@ namespace Switch_Toolbox.Library.Forms
AddFilesToActiveEditor = activeEditorChkBox.Checked;
}
private void AddFiles(TreeNode parentNode, string[] Files)
{
if (Files == null || Files.Length <= 0) return;
for (int i = 0; i < Files.Length; i++)
{
var File = ArchiveNodeWrapper.FromPath(Files[i]);
File.ArchiveFileInfo = new ArchiveFileInfo();
File.ArchiveFileInfo.FileData = System.IO.File.ReadAllBytes(Files[i]);
File.ArchiveFileInfo.FileName = Files[i];
parentNode.Nodes.Add(File);
}
}
private void treeViewCustom1_DragDrop(object sender, DragEventArgs e)
{
Point pt = treeViewCustom1.PointToClient(new Point(e.X, e.Y));
treeViewCustom1.SelectedNode = treeViewCustom1.GetNodeAt(pt.X, pt.Y);
bool IsFile = treeViewCustom1.SelectedNode is ArchiveNodeWrapper && treeViewCustom1.SelectedNode.Parent != null;
bool IsFile = treeViewCustom1.SelectedNode is ArchiveFileWrapper && treeViewCustom1.SelectedNode.Parent != null;
var archiveFile = GetActiveArchive();
//Use the parent folder for files if it has any
if (IsFile)
AddFiles(treeViewCustom1.SelectedNode.Parent, e.Data.GetData(DataFormats.FileDrop) as string[]);
TreeHelper.AddFiles(treeViewCustom1.SelectedNode.Parent, archiveFile, e.Data.GetData(DataFormats.FileDrop) as string[]);
else
AddFiles(treeViewCustom1.SelectedNode, e.Data.GetData(DataFormats.FileDrop) as string[]);
TreeHelper.AddFiles(treeViewCustom1.SelectedNode, archiveFile, e.Data.GetData(DataFormats.FileDrop) as string[]);
}
private void treeViewCustom1_DragOver(object sender, DragEventArgs e)
{
var file = ObjectEditor.GetActiveFile();
if (!(file is IArchiveFile)|| !((IArchiveFile)file).CanReplaceFiles)
var file = GetActiveArchive();
if (file == null || !file.CanReplaceFiles)
return;
Point pt = treeViewCustom1.PointToClient(new Point(e.X, e.Y));
@ -532,12 +519,20 @@ namespace Switch_Toolbox.Library.Forms
treeViewCustom1.SelectedNode = node;
bool IsRoot = node is ArchiveRootNodeWrapper;
bool IsFolder = node is ArchiveFolderNodeWrapper;
bool IsFile = node is ArchiveNodeWrapper && node.Parent != null;
bool IsFile = node is ArchiveFileWrapper && node.Parent != null;
if (IsFolder || IsRoot || IsFile)
e.Effect = DragDropEffects.Link;
else
e.Effect = DragDropEffects.None;
}
private IArchiveFile GetActiveArchive()
{
if (treeViewCustom1.SelectedNode != null && treeViewCustom1.SelectedNode is ArchiveBase)
return ((ArchiveBase)treeViewCustom1.SelectedNode).ArchiveFile;
return null;
}
}
}

View file

@ -29,9 +29,9 @@ namespace Switch_Toolbox.Library
int Curfile = 0;
foreach (TreeNode file in Collection)
{
if (file is ArchiveNodeWrapper)
if (file is ArchiveFileWrapper)
{
string FilePath = ((ArchiveNodeWrapper)file).ArchiveFileInfo.FileName;
string FilePath = ((ArchiveFileWrapper)file).ArchiveFileInfo.FileName;
string FolderPath = Path.GetDirectoryName(FilePath.RemoveIllegaleFolderNameCharacters());
string FileName = file.Text.RemoveIllegaleFileNameCharacters();
@ -48,10 +48,10 @@ namespace Switch_Toolbox.Library
progressBar.Refresh();
CreateDirectoryIfExists($"{path}");
if (file is ArchiveNodeWrapper)
if (file is ArchiveFileWrapper)
{
File.WriteAllBytes($"{path}",
((ArchiveNodeWrapper)file).ArchiveFileInfo.FileData);
((ArchiveFileWrapper)file).ArchiveFileInfo.FileData);
}
}
}
@ -76,5 +76,56 @@ namespace Switch_Toolbox.Library
}
}
}
public static void AddFiles(TreeNode parentNode, IArchiveFile archiveFile, string[] Files)
{
if (Files == null || Files.Length <= 0 || !archiveFile.CanAddFiles) return;
for (int i = 0; i < Files.Length; i++)
{
var File = ArchiveFileWrapper.FromPath(Files[i], archiveFile);
File.ArchiveFileInfo = new ArchiveFileInfo();
File.ArchiveFileInfo.FileData = System.IO.File.ReadAllBytes(Files[i]);
string FileName = Path.GetFileName(Files[i]);
//Don't add the root file name
if (parentNode.FullPath != string.Empty || !(parentNode is ArchiveRootNodeWrapper))
File.ArchiveFileInfo.FileName = Path.Combine(parentNode.FullPath, FileName);
else
File.ArchiveFileInfo.FileName = FileName;
bool HasAddedFile = archiveFile.AddFile(File.ArchiveFileInfo);
if (HasAddedFile)
parentNode.Nodes.Add(File);
}
}
public static void RemoveFile(ArchiveFileWrapper fileNode, IArchiveFile archiveFile)
{
if (!archiveFile.CanDeleteFiles) return;
var parentNode = fileNode.Parent;
bool HasRemovedFile = archiveFile.DeleteFile(fileNode.ArchiveFileInfo);
if (HasRemovedFile)
parentNode.Nodes.Remove(fileNode);
}
public static void RemoveFolder(TreeNode folderNode, IArchiveFile archiveFile)
{
if (!archiveFile.CanDeleteFiles) return;
foreach (var node in TreeViewExtensions.Collect(folderNode.Nodes))
{
var parentNode = node.Parent;
parentNode.Nodes.Remove(node);
if (node is ArchiveFileWrapper)
archiveFile.DeleteFile(((ArchiveFileWrapper)node).ArchiveFileInfo);
}
}
}
}

View file

@ -93,7 +93,7 @@ namespace Switch_Toolbox.Library.IO
if (data == null)
data = File.ReadAllBytes(FileName);
data = STLibraryCompression.ZLIB.Decompress(fileReader.getSection(2, data.Length - 2));
data = STLibraryCompression.ZLIB.Decompress(data);
return OpenFileFormat(FileName, data, LeaveStreamOpen, InArchive, archiveNode, true,
CompressionType.Zlib, DecompressedFileSize, CompressedFileSize);
}

View file

@ -94,17 +94,25 @@ namespace Switch_Toolbox.Library
public ArchiveFileState State { get; set; } = ArchiveFileState.Empty;
}
public class ArchiveBase : TreeNodeCustom
{
public IArchiveFile ArchiveFile; //The archive file being edited
public ArchiveBase(IArchiveFile archiveFile)
{
ArchiveFile = archiveFile;
}
}
//Wrapper for the archive file itself
public class ArchiveRootNodeWrapper : TreeNodeCustom
public class ArchiveRootNodeWrapper : ArchiveBase
{
public virtual object PropertyDisplay { get; set; }
IArchiveFile ArchiveFile;
public ArchiveRootNodeWrapper(string text, IArchiveFile archiveFile)
public ArchiveRootNodeWrapper(string text, IArchiveFile archiveFile)
: base(archiveFile)
{
Text = text;
ArchiveFile = archiveFile;
ReloadMenus();
@ -223,7 +231,7 @@ namespace Switch_Toolbox.Library
}
//Wrapper for folders
public class ArchiveFolderNodeWrapper : TreeNodeCustom
public class ArchiveFolderNodeWrapper : ArchiveBase
{
public virtual object PropertyDisplay { get; set; }
@ -249,21 +257,35 @@ namespace Switch_Toolbox.Library
}
}
public ArchiveFolderNodeWrapper(string text)
public ArchiveFolderNodeWrapper(string text, IArchiveFile archiveFile ) : base(archiveFile)
{
Text = text;
PropertyDisplay = new GenericFolderProperties();
((GenericFolderProperties)PropertyDisplay).Name = Text;
ReloadMenus();
ReloadMenus(archiveFile);
}
private void ReloadMenus()
private void ReloadMenus(IArchiveFile archiveFile)
{
ContextMenuStrip = new STContextMenuStrip();
ContextMenuStrip.Items.Add(new STToolStripItem("Rename", RenameAction) { Enabled = archiveFile.CanRenameFiles });
ContextMenuStrip.Items.Add(new STToolStripItem("Extract Folder", ExtractAction));
ContextMenuStrip.Items.Add(new STToolStripItem("Replace Folder", ReplaceAction));
ContextMenuStrip.Items.Add(new STToolStripItem("Delete Folder", DeleteAction));
ContextMenuStrip.Items.Add(new STToolStripItem("Replace Folder", ReplaceAction) { Enabled = archiveFile.CanReplaceFiles });
ContextMenuStrip.Items.Add(new STToolStripItem("Delete Folder", DeleteAction) { Enabled = archiveFile.CanDeleteFiles });
ContextMenuStrip.Items.Add(new STToolStripSeparator());
ContextMenuStrip.Items.Add(new STToolStripItem("Add File", AddFileAction) { Enabled = archiveFile.CanAddFiles });
}
private void AddFileAction(object sender, EventArgs args)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Raw Data (*.*)|*.*";
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK) {
TreeHelper.AddFiles(this, ArchiveFile, ofd.FileNames);
}
}
public override void OnClick(TreeView treeView)
@ -300,63 +322,48 @@ namespace Switch_Toolbox.Library
TreeHelper.ExtractAllFiles(ParentPath, Nodes);
}
private void ReplaceAction(object sender, EventArgs args)
private void RenameAction(object sender, EventArgs args)
{
RenameDialog dialog = new RenameDialog();
dialog.SetString(Text);
if (dialog.ShowDialog() == DialogResult.OK) { Text = dialog.textBox1.Text; }
}
private void DeleteAction(object sender, EventArgs args)
private void ReplaceAction(object sender, EventArgs args)
{
}
private void DeleteAction(object sender, EventArgs args) {
TreeHelper.RemoveFolder(this, ArchiveFile);
}
}
//Wrapper for files
public class ArchiveNodeWrapper : TreeNodeCustom
public class ArchiveFileWrapper : ArchiveBase
{
public bool CanReplace
{
set
{
if (value)
ContextMenuStrip.Items[1].Enabled = true;
else
ContextMenuStrip.Items[1].Enabled = false;
}
}
public bool CanRename = false;
public bool CanDelete
{
set
{
if (value)
ContextMenuStrip.Items[2].Enabled = true;
else
ContextMenuStrip.Items[2].Enabled = false;
}
}
public ArchiveNodeWrapper(string text)
public ArchiveFileWrapper(string text, IArchiveFile archiveFile) : base(archiveFile)
{
Text = text;
ReloadMenus();
ReloadMenus(archiveFile);
}
public static ArchiveNodeWrapper FromPath(string FilePath)
public static ArchiveFileWrapper FromPath(string FilePath, IArchiveFile archiveFile)
{
var wrapper = new ArchiveNodeWrapper(Path.GetFileName(FilePath));
var wrapper = new ArchiveFileWrapper(Path.GetFileName(FilePath), archiveFile);
wrapper.ArchiveFileInfo = new ArchiveFileInfo();
wrapper.ArchiveFileInfo.FileName = FilePath;
wrapper.ArchiveFileInfo.FileData = File.ReadAllBytes(FilePath);
return wrapper;
}
private void ReloadMenus()
private void ReloadMenus(IArchiveFile archiveFile)
{
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));
ContextMenuStrip.Items.Add(new STToolStripItem("Delete", DeleteAction));
ContextMenuStrip.Items.Add(new STToolStripItem("Replace", ReplaceAction) { Enabled = archiveFile.CanReplaceFiles });
ContextMenuStrip.Items.Add(new STToolStripItem("Delete", DeleteAction) { Enabled = archiveFile.CanDeleteFiles });
}
public virtual ArchiveFileInfo ArchiveFileInfo { get; set; }
@ -453,5 +460,13 @@ namespace Switch_Toolbox.Library
node.Nodes.RemoveAt(index);
node.Nodes.Insert(index, NewNode);
}
private void RenameAction(object sender, EventArgs args)
{
RenameDialog dialog = new RenameDialog();
dialog.SetString(Text);
if (dialog.ShowDialog() == DialogResult.OK) { Text = dialog.textBox1.Text; }
}
}
}

View file

@ -2,7 +2,7 @@ using System;
using System.Linq;
using System.Collections.Generic;
namespace Switch_Toolbox.Library
namespace Switch_Toolbox.Library.OLD
{
public class GX2
{
@ -768,8 +768,6 @@ namespace Switch_Toolbox.Library
dataOffset += ArrayImageize;
mipDataOffset += ArrayMipImageize;
break;
}
return result;

View file

@ -2,7 +2,7 @@
using System.Linq;
using System.Collections.Generic;
namespace Switch_Toolbox.Library.NEW
namespace Switch_Toolbox.Library
{
//Todo fix swizzle issues with this one
public class GX2