Add directory and node interfaces for archive types
This commit is contained in:
parent
48859f6041
commit
5f3fff4749
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -10,7 +10,7 @@ using Switch_Toolbox.Library.IO;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class RARC : IArchiveFile, IFileFormat
|
||||
public class RARC : IArchiveFile, IFileFormat, IDirectoryContainer
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Archive;
|
||||
|
||||
@ -44,8 +44,16 @@ namespace FirstPlugin
|
||||
}
|
||||
|
||||
public List<FileEntry> files = new List<FileEntry>();
|
||||
public List<INode> nodes = new List<INode>();
|
||||
|
||||
public IEnumerable<ArchiveFileInfo> Files => files;
|
||||
public IEnumerable<INode> Nodes => nodes;
|
||||
|
||||
public string Name
|
||||
{
|
||||
get { return FileName; }
|
||||
set { FileName = value; }
|
||||
}
|
||||
|
||||
private DirectoryEntry[] Directories;
|
||||
|
||||
@ -53,7 +61,7 @@ namespace FirstPlugin
|
||||
{
|
||||
using (var reader = new FileReader(stream))
|
||||
{
|
||||
reader.ByteOrder = Syroot.BinaryData.ByteOrder.LittleEndian;
|
||||
reader.ByteOrder = Syroot.BinaryData.ByteOrder.BigEndian;
|
||||
reader.ReadSignature(4, "RARC");
|
||||
uint FileSize = reader.ReadUInt32();
|
||||
uint HeaderSize = reader.ReadUInt32();
|
||||
@ -85,10 +93,10 @@ namespace FirstPlugin
|
||||
Directories[dir].Read(reader);
|
||||
uint NamePointer = StringTablOffset + (uint)pos + Directories[dir].NameOffset;
|
||||
Directories[dir].Name = ReadStringAtTable(reader, NamePointer);
|
||||
|
||||
nodes.Add(Directories[dir]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
reader.SeekBegin(NodeOffset + pos);
|
||||
for (int n = 0; n < TotalNodeCount; n++)
|
||||
{
|
||||
@ -124,7 +132,7 @@ namespace FirstPlugin
|
||||
|
||||
}
|
||||
|
||||
public class DirectoryEntry
|
||||
public class DirectoryEntry : IDirectoryContainer
|
||||
{
|
||||
public RARC ParentArchive { get; }
|
||||
|
||||
@ -142,6 +150,8 @@ namespace FirstPlugin
|
||||
|
||||
public DirectoryEntry(RARC rarc) { ParentArchive = rarc; }
|
||||
|
||||
public IEnumerable<INode> Nodes { get; }
|
||||
|
||||
public void Read(FileReader reader)
|
||||
{
|
||||
Identifier = reader.ReadUInt32();
|
||||
|
@ -290,7 +290,6 @@ namespace FirstPlugin
|
||||
|
||||
|
||||
Formats.Add(typeof(NSP));
|
||||
Formats.Add(typeof(BFSAR));
|
||||
Formats.Add(typeof(BNSH));
|
||||
Formats.Add(typeof(BFSHA));
|
||||
Formats.Add(typeof(BFLIM));
|
||||
@ -325,8 +324,8 @@ namespace FirstPlugin
|
||||
Formats.Add(typeof(SDF));
|
||||
Formats.Add(typeof(IStorage));
|
||||
Formats.Add(typeof(NCA));
|
||||
|
||||
|
||||
// Formats.Add(typeof(RARC));
|
||||
|
||||
//Unfinished wip formats not ready for use
|
||||
if (Runtime.DEVELOPER_DEBUG_MODE)
|
||||
{
|
||||
|
Binary file not shown.
Binary file not shown.
@ -33,7 +33,7 @@ namespace Switch_Toolbox.Library
|
||||
bool AddFile(ArchiveFileInfo archiveFileInfo);
|
||||
bool DeleteFile(ArchiveFileInfo archiveFileInfo);
|
||||
}
|
||||
public class ArchiveFileInfo
|
||||
public class ArchiveFileInfo : INode
|
||||
{
|
||||
[Browsable(false)]
|
||||
public STContextMenuStrip STContextMenuStrip;
|
||||
@ -291,6 +291,18 @@ namespace Switch_Toolbox.Library
|
||||
FillTreeNodes(this, ArchiveFile);
|
||||
}
|
||||
|
||||
private void FillDirectory(TreeNode parent, IEnumerable<INode> Nodes)
|
||||
{
|
||||
foreach (var node in Nodes)
|
||||
{
|
||||
var treeNode = new TreeNode(node.Name);
|
||||
parent.Nodes.Add(treeNode);
|
||||
|
||||
if (node is IDirectoryContainer && ((IDirectoryContainer)node).Nodes != null)
|
||||
FillDirectory(treeNode, ((IDirectoryContainer)node).Nodes);
|
||||
}
|
||||
}
|
||||
|
||||
private void FillTreeNodes(TreeNode root, IArchiveFile archiveFile)
|
||||
{
|
||||
Nodes.Clear();
|
||||
@ -299,55 +311,63 @@ namespace Switch_Toolbox.Library
|
||||
var rootTextLength = rootText.Length;
|
||||
var nodeFiles = archiveFile.Files;
|
||||
|
||||
int I = 0;
|
||||
foreach (var node in archiveFile.Files)
|
||||
if (archiveFile is IDirectoryContainer)
|
||||
{
|
||||
FillDirectory(root,((IDirectoryContainer)archiveFile).Nodes);
|
||||
}
|
||||
else //Else create directories by filename paths
|
||||
{
|
||||
if (!node.CanLoadFile)
|
||||
continue;
|
||||
|
||||
string nodeString = node.FileName;
|
||||
|
||||
var roots = nodeString.Split(new char[] { '/' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// The initial parent is the root node
|
||||
var parentNode = root;
|
||||
var sb = new System.Text.StringBuilder(rootText, nodeString.Length + rootTextLength);
|
||||
for (int rootIndex = 0; rootIndex < roots.Length; rootIndex++)
|
||||
int I = 0;
|
||||
foreach (var node in archiveFile.Files)
|
||||
{
|
||||
// Build the node name
|
||||
var parentName = roots[rootIndex];
|
||||
sb.Append("/");
|
||||
sb.Append(parentName);
|
||||
var nodeName = sb.ToString();
|
||||
if (!node.CanLoadFile)
|
||||
continue;
|
||||
|
||||
// Search for the node
|
||||
var index = parentNode.Nodes.IndexOfKey(nodeName);
|
||||
if (index == -1)
|
||||
string nodeString = node.FileName;
|
||||
|
||||
var roots = nodeString.Split(new char[] { '/' },
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
// The initial parent is the root node
|
||||
var parentNode = root;
|
||||
var sb = new System.Text.StringBuilder(rootText, nodeString.Length + rootTextLength);
|
||||
for (int rootIndex = 0; rootIndex < roots.Length; rootIndex++)
|
||||
{
|
||||
// Node was not found, add it
|
||||
// Build the node name
|
||||
var parentName = roots[rootIndex];
|
||||
sb.Append("/");
|
||||
sb.Append(parentName);
|
||||
var nodeName = sb.ToString();
|
||||
|
||||
var folder = new ArchiveFolderNodeWrapper(parentName, archiveFile);
|
||||
|
||||
if (rootIndex == roots.Length - 1)
|
||||
// Search for the node
|
||||
var index = parentNode.Nodes.IndexOfKey(nodeName);
|
||||
if (index == -1)
|
||||
{
|
||||
ArchiveFileWrapper wrapperFile = new ArchiveFileWrapper(parentName, node, archiveFile);
|
||||
wrapperFile.Name = nodeName;
|
||||
parentNode.Nodes.Add(wrapperFile);
|
||||
parentNode = wrapperFile;
|
||||
// Node was not found, add it
|
||||
|
||||
var folder = new ArchiveFolderNodeWrapper(parentName, archiveFile);
|
||||
|
||||
if (rootIndex == roots.Length - 1)
|
||||
{
|
||||
ArchiveFileWrapper wrapperFile = new ArchiveFileWrapper(parentName, node, archiveFile);
|
||||
wrapperFile.Name = nodeName;
|
||||
parentNode.Nodes.Add(wrapperFile);
|
||||
parentNode = wrapperFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
folder.Name = nodeName;
|
||||
parentNode.Nodes.Add(folder);
|
||||
parentNode = folder;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
folder.Name = nodeName;
|
||||
parentNode.Nodes.Add(folder);
|
||||
parentNode = folder;
|
||||
// Node was found, set that as parent and continue
|
||||
parentNode = parentNode.Nodes[index];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Node was found, set that as parent and continue
|
||||
parentNode = parentNode.Nodes[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
Switch_Toolbox_Library/Interfaces/IDirectoryNode.cs
Normal file
13
Switch_Toolbox_Library/Interfaces/IDirectoryNode.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public interface IDirectoryContainer : INode
|
||||
{
|
||||
IEnumerable<INode> Nodes { get; }
|
||||
}
|
||||
}
|
13
Switch_Toolbox_Library/Interfaces/INode.cs
Normal file
13
Switch_Toolbox_Library/Interfaces/INode.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Switch_Toolbox.Library
|
||||
{
|
||||
public interface INode
|
||||
{
|
||||
string Name { get; set; }
|
||||
}
|
||||
}
|
@ -566,6 +566,8 @@
|
||||
<Compile Include="Generics\GenericPolygonGroup.cs" />
|
||||
<Compile Include="Generics\GenericTexture.cs" />
|
||||
<Compile Include="Generics\OpenGLTexture.cs" />
|
||||
<Compile Include="Interfaces\IDirectoryNode.cs" />
|
||||
<Compile Include="Interfaces\INode.cs" />
|
||||
<Compile Include="Rendering\RenderableTex.cs" />
|
||||
<Compile Include="Generics\STBone.cs" />
|
||||
<Compile Include="Generics\STGenericWrapper.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user