NdsForge.NET 1.0.1
Read, validate, edit, compare, and build Nintendo DS and DSi images from .NET
Loading...
Searching...
No Matches
NdsDirectory.cs
1namespace NdsForge;
2
4public sealed class NdsDirectory
5{
7 private IReadOnlyList<NdsDirectory> _directories = Array.Empty<NdsDirectory>();
9 private IReadOnlyList<NdsFile> _files = Array.Empty<NdsFile>();
10
16 internal NdsDirectory(ushort id, string name, string fullPath, NdsDirectory? parent)
17 {
18 Id = id;
19 Name = name;
20 FullPath = fullPath;
21 Parent = parent;
22 }
23
25 public ushort Id { get; }
26
28 public string Name { get; }
29
31 public string FullPath { get; }
32
34 public NdsDirectory? Parent { get; }
35
37 public IReadOnlyList<NdsDirectory> Directories => _directories;
38
40 public IReadOnlyList<NdsFile> Files => _files;
41
45 public IEnumerable<NdsFile> EnumerateFiles(bool recursive = true)
46 {
47 foreach (NdsFile file in _files)
48 {
49 yield return file;
50 }
51
52 if (recursive)
53 {
54 foreach (NdsDirectory directory in _directories)
55 {
56 foreach (NdsFile file in directory.EnumerateFiles())
57 {
58 yield return file;
59 }
60 }
61 }
62 }
63
67 public IEnumerable<NdsDirectory> EnumerateDirectories(bool recursive = true)
68 {
69 foreach (NdsDirectory directory in _directories)
70 {
71 yield return directory;
72 if (recursive)
73 {
74 foreach (NdsDirectory descendant in directory.EnumerateDirectories())
75 {
76 yield return descendant;
77 }
78 }
79 }
80 }
81
85 internal void SetChildren(IReadOnlyList<NdsDirectory> directories, IReadOnlyList<NdsFile> files)
86 {
87 _directories = directories;
88 _files = files;
89 }
90}
IReadOnlyList< NdsFile > Files
Gets immediate child files in FNT order.
IEnumerable< NdsFile > EnumerateFiles(bool recursive=true)
Walks named payloads in encoded depth-first order without allocating a flattened collection.
IEnumerable< NdsDirectory > EnumerateDirectories(bool recursive=true)
Walks child directory nodes in encoded depth-first order while excluding the current node.
IReadOnlyList< NdsDirectory > Directories
Gets immediate child directories in FNT order.
string Name
Gets the byte-preserving Latin-1 name projection, or an empty string for the synthetic root.
string FullPath
Uses ordinal slash-separated semantics and represents the root with exactly /.
ushort Id
Combines the 0xF000 directory tag with the main-table record index in its low 12 bits.
NdsDirectory? Parent
Gets the parent, or null for the root.
Connects a byte-preserving FNT path and stable FAT identifier to lazily read cartridge bytes.
Definition NdsFile.cs:5