|
1 |
| -using System.Collections.Generic; |
2 |
| -using LibHac.IO; |
3 |
| -using LibHac.IO.RomFs; |
| 1 | +using LibHac; |
| 2 | +using LibHac.Common; |
| 3 | +using LibHac.Fs; |
| 4 | +using LibHac.FsSystem.RomFs; |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Text; |
4 | 8 |
|
5 | 9 | namespace XbTool.Xb2
|
6 | 10 | {
|
7 | 11 | public class ArchiveDirectory : IDirectory
|
8 | 12 | {
|
9 |
| - IFileSystem IDirectory.ParentFileSystem => ParentFileSystem; |
10 | 13 | public ArchiveFileSystem ParentFileSystem { get; }
|
11 | 14 | public string FullPath { get; }
|
12 | 15 | public OpenDirectoryMode Mode { get; }
|
13 | 16 |
|
14 | 17 | private FindPosition InitialPosition { get; }
|
| 18 | + private FindPosition _curPosition; |
15 | 19 |
|
16 | 20 | public ArchiveDirectory(ArchiveFileSystem fs, string path, FindPosition position, OpenDirectoryMode mode)
|
17 | 21 | {
|
18 | 22 | ParentFileSystem = fs;
|
19 | 23 | InitialPosition = position;
|
| 24 | + _curPosition = position; |
20 | 25 | FullPath = path;
|
21 | 26 | Mode = mode;
|
22 | 27 | }
|
23 | 28 |
|
24 |
| - public IEnumerable<DirectoryEntry> Read() |
| 29 | + public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer) |
25 | 30 | {
|
26 |
| - FindPosition position = InitialPosition; |
27 |
| - HierarchicalRomFileTable tab = ParentFileSystem.FileTable; |
| 31 | + int i = 0; |
| 32 | + ref FindPosition position = ref _curPosition; |
| 33 | + HierarchicalRomFileTable<RomFileInfo> table = ParentFileSystem.FileTable; |
28 | 34 |
|
29 |
| - if (Mode.HasFlag(OpenDirectoryMode.Directories)) |
| 35 | + if (Mode.HasFlag(OpenDirectoryMode.Directory)) |
30 | 36 | {
|
31 |
| - while (tab.FindNextDirectory(ref position, out string name)) |
| 37 | + while (table.FindNextDirectory(ref position, out string name)) |
32 | 38 | {
|
33 |
| - yield return new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.Directory, 0); |
| 39 | + if (i >= entryBuffer.Length) |
| 40 | + break; |
| 41 | + entryBuffer[i].Type = DirectoryEntryType.Directory; |
| 42 | + entryBuffer[i].Size = 0; |
| 43 | + StringUtils.Copy(entryBuffer[i].Name, Encoding.UTF8.GetBytes(name)); |
| 44 | + i++; |
34 | 45 | }
|
35 | 46 | }
|
36 |
| - |
37 |
| - if (Mode.HasFlag(OpenDirectoryMode.Files)) |
| 47 | + if (Mode.HasFlag(OpenDirectoryMode.File)) |
38 | 48 | {
|
39 |
| - while (tab.FindNextFile(ref position, out RomFileInfo info, out string name)) |
| 49 | + while (table.FindNextFile(ref position, out RomFileInfo info, out string name)) |
40 | 50 | {
|
41 |
| - yield return new DirectoryEntry(name, FullPath + '/' + name, DirectoryEntryType.File, info.Length); |
| 51 | + if (i >= entryBuffer.Length) |
| 52 | + break; |
| 53 | + entryBuffer[i].Type = DirectoryEntryType.File; |
| 54 | + entryBuffer[i].Size = info.Length; |
| 55 | + StringUtils.Copy(entryBuffer[i].Name, Encoding.UTF8.GetBytes(name)); |
| 56 | + i++; |
42 | 57 | }
|
43 | 58 | }
|
| 59 | + |
| 60 | + entriesRead = i; |
| 61 | + return Result.Success; |
44 | 62 | }
|
45 | 63 |
|
46 |
| - public int GetEntryCount() |
| 64 | + public Result GetEntryCount(out long entryCount) |
47 | 65 | {
|
48 |
| - int count = 0; |
49 |
| - |
| 66 | + entryCount = 0; |
50 | 67 | FindPosition position = InitialPosition;
|
51 |
| - HierarchicalRomFileTable tab = ParentFileSystem.FileTable; |
| 68 | + HierarchicalRomFileTable<RomFileInfo> table = ParentFileSystem.FileTable; |
52 | 69 |
|
53 |
| - if (Mode.HasFlag(OpenDirectoryMode.Directories)) |
| 70 | + if (Mode.HasFlag(OpenDirectoryMode.Directory)) |
54 | 71 | {
|
55 |
| - while (tab.FindNextDirectory(ref position, out string _)) |
| 72 | + while (table.FindNextDirectory(ref position, out string _)) |
56 | 73 | {
|
57 |
| - count++; |
| 74 | + entryCount++; |
58 | 75 | }
|
59 | 76 | }
|
60 | 77 |
|
61 |
| - if (Mode.HasFlag(OpenDirectoryMode.Files)) |
| 78 | + if (Mode.HasFlag(OpenDirectoryMode.File)) |
62 | 79 | {
|
63 |
| - while (tab.FindNextFile(ref position, out RomFileInfo _, out string _)) |
| 80 | + while (table.FindNextFile(ref position, out RomFileInfo _, out string _)) |
64 | 81 | {
|
65 |
| - count++; |
| 82 | + entryCount++; |
66 | 83 | }
|
67 | 84 | }
|
68 | 85 |
|
69 |
| - return count; |
| 86 | + return Result.Success; |
70 | 87 | }
|
71 | 88 | }
|
72 | 89 | }
|
0 commit comments