|
5 | 5 | using LibHac;
|
6 | 6 | using LibHac.IO;
|
7 | 7 |
|
8 |
| -namespace XbTool.Xb2.FS |
| 8 | +namespace XbTool.Xb2 |
9 | 9 | {
|
10 |
| - public class Create |
| 10 | + public class Xb2FileSystem : IFileSystem |
11 | 11 | {
|
12 |
| - public static IFileSystem CreateFileSystem(string sdPath) |
| 12 | + private IFileSystem BaseFs { get; } |
| 13 | + |
| 14 | + public Xb2FileSystem(string sdPath) |
13 | 15 | {
|
14 | 16 | SwitchFs sdFs = OpenSdCard(sdPath);
|
15 | 17 | Application xb2App = sdFs.Applications[0x0100E95004038000];
|
@@ -39,10 +41,63 @@ public static IFileSystem CreateFileSystem(string sdPath)
|
39 | 41 | }
|
40 | 42 | }
|
41 | 43 |
|
42 |
| - return new LayeredFileSystem(fsList); |
| 44 | + fsList.Reverse(); |
| 45 | + BaseFs = new LayeredFileSystem(fsList); |
| 46 | + } |
| 47 | + |
| 48 | + public IDirectory OpenDirectory(string path, OpenDirectoryMode mode) |
| 49 | + { |
| 50 | + path = PathTools.Normalize(path); |
| 51 | + |
| 52 | + IDirectory baseDir = BaseFs.OpenDirectory(path, mode); |
| 53 | + |
| 54 | + return new Xb2Directory(this, baseDir); |
| 55 | + } |
| 56 | + |
| 57 | + public IFile OpenFile(string path, OpenMode mode) |
| 58 | + { |
| 59 | + path = PathTools.Normalize(path); |
| 60 | + |
| 61 | + if(IsArchiveFile(path)) throw new FileNotFoundException(); |
| 62 | + |
| 63 | + return BaseFs.OpenFile(path, mode); |
| 64 | + } |
| 65 | + |
| 66 | + public bool DirectoryExists(string path) |
| 67 | + { |
| 68 | + path = PathTools.Normalize(path); |
| 69 | + |
| 70 | + if (IsArchiveFile(path)) return false; |
| 71 | + |
| 72 | + return BaseFs.DirectoryExists(path); |
43 | 73 | }
|
44 | 74 |
|
45 |
| - public static SwitchFs OpenSdCard(string path, IProgressReport logger = null) |
| 75 | + public bool FileExists(string path) |
| 76 | + { |
| 77 | + path = PathTools.Normalize(path); |
| 78 | + |
| 79 | + if (IsArchiveFile(path)) return false; |
| 80 | + |
| 81 | + return BaseFs.FileExists(path); |
| 82 | + } |
| 83 | + |
| 84 | + public DirectoryEntryType GetEntryType(string path) |
| 85 | + { |
| 86 | + path = PathTools.Normalize(path); |
| 87 | + |
| 88 | + if (IsArchiveFile(path)) throw new FileNotFoundException(); |
| 89 | + |
| 90 | + return BaseFs.GetEntryType(path); |
| 91 | + } |
| 92 | + |
| 93 | + internal static bool IsArchiveFile(string path) |
| 94 | + { |
| 95 | + string extension = Path.GetExtension(path); |
| 96 | + |
| 97 | + return extension == ".ard" || extension == ".arh"; |
| 98 | + } |
| 99 | + |
| 100 | + private static SwitchFs OpenSdCard(string path, IProgressReport logger = null) |
46 | 101 | {
|
47 | 102 | SwitchFs switchFs;
|
48 | 103 | Keyset keyset = OpenKeyset();
|
@@ -77,5 +132,14 @@ private static Keyset OpenKeyset()
|
77 | 132 |
|
78 | 133 | return ExternalKeys.ReadKeyFile(homeKeyFile, homeTitleKeyFile, homeConsoleKeyFile);
|
79 | 134 | }
|
| 135 | + |
| 136 | + public void Commit(){} |
| 137 | + |
| 138 | + public void CreateDirectory(string path) => throw new NotSupportedException(); |
| 139 | + public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException(); |
| 140 | + public void DeleteDirectory(string path) => throw new NotSupportedException(); |
| 141 | + public void DeleteFile(string path) => throw new NotSupportedException(); |
| 142 | + public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException(); |
| 143 | + public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException(); |
80 | 144 | }
|
81 | 145 | }
|
0 commit comments