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