diff --git a/.vs/Switch_Toolbox/v15/.suo b/.vs/Switch_Toolbox/v15/.suo index 25d9e74d..c75f9f83 100644 Binary files a/.vs/Switch_Toolbox/v15/.suo and b/.vs/Switch_Toolbox/v15/.suo differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide index ac5ad5b5..0b42cdb4 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal index 37f8974c..efd2aa6f 100644 Binary files a/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal and b/.vs/Switch_Toolbox/v15/Server/sqlite3/storage.ide-wal differ diff --git a/Switch_FileFormatsMain/FileFormats/Archives/RARC.cs b/Switch_FileFormatsMain/FileFormats/Archives/RARC.cs index 95c3a91d..17f1e780 100644 --- a/Switch_FileFormatsMain/FileFormats/Archives/RARC.cs +++ b/Switch_FileFormatsMain/FileFormats/Archives/RARC.cs @@ -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 files = new List(); + public List nodes = new List(); public IEnumerable Files => files; + public IEnumerable 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 Nodes { get; } + public void Read(FileReader reader) { Identifier = reader.ReadUInt32(); diff --git a/Switch_FileFormatsMain/Main.cs b/Switch_FileFormatsMain/Main.cs index 74040bd8..4f9b3ea7 100644 --- a/Switch_FileFormatsMain/Main.cs +++ b/Switch_FileFormatsMain/Main.cs @@ -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) { diff --git a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache index fc6f62f4..05c08fa9 100644 Binary files a/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache and b/Switch_FileFormatsMain/obj/Release/DesignTimeResolveAssemblyReferences.cache differ diff --git a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache index cd493668..03c00668 100644 Binary files a/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache and b/Switch_FileFormatsMain/obj/Release/Switch_FileFormatsMain.csprojAssemblyReference.cache differ diff --git a/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs b/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs index 2901fff5..78ae1766 100644 --- a/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs +++ b/Switch_Toolbox_Library/Interfaces/IArchiveFile.cs @@ -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 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]; - } } } } diff --git a/Switch_Toolbox_Library/Interfaces/IDirectoryNode.cs b/Switch_Toolbox_Library/Interfaces/IDirectoryNode.cs new file mode 100644 index 00000000..a74b5be4 --- /dev/null +++ b/Switch_Toolbox_Library/Interfaces/IDirectoryNode.cs @@ -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 Nodes { get; } + } +} diff --git a/Switch_Toolbox_Library/Interfaces/INode.cs b/Switch_Toolbox_Library/Interfaces/INode.cs new file mode 100644 index 00000000..ae7345ff --- /dev/null +++ b/Switch_Toolbox_Library/Interfaces/INode.cs @@ -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; } + } +} diff --git a/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj b/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj index 0a191421..30005acc 100644 --- a/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj +++ b/Switch_Toolbox_Library/Switch_Toolbox_Library.csproj @@ -566,6 +566,8 @@ + +