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,6 +311,13 @@ namespace Switch_Toolbox.Library
|
|||||||
var rootTextLength = rootText.Length;
|
var rootTextLength = rootText.Length;
|
||||||
var nodeFiles = archiveFile.Files;
|
var nodeFiles = archiveFile.Files;
|
||||||
|
|
||||||
|
if (archiveFile is IDirectoryContainer)
|
||||||
|
{
|
||||||
|
FillDirectory(root,((IDirectoryContainer)archiveFile).Nodes);
|
||||||
|
}
|
||||||
|
else //Else create directories by filename paths
|
||||||
|
{
|
||||||
|
|
||||||
int I = 0;
|
int I = 0;
|
||||||
foreach (var node in archiveFile.Files)
|
foreach (var node in archiveFile.Files)
|
||||||
{
|
{
|
||||||
@ -352,6 +371,7 @@ namespace Switch_Toolbox.Library
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Wrapper for folders
|
//Wrapper for folders
|
||||||
public class ArchiveFolderNodeWrapper : ArchiveBase, IContextMenuNode
|
public class ArchiveFolderNodeWrapper : ArchiveBase, IContextMenuNode
|
||||||
|
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