Skip to content

Commit 42e2fe3

Browse files
committed
Exclude ard and arh files from Xb2FileSystem
1 parent 82091e9 commit 42e2fe3

File tree

4 files changed

+107
-7
lines changed

4 files changed

+107
-7
lines changed

XbTool/XbTool/Tasks.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,9 @@ private static void SdPrintTest(Options options)
446446
if (options.Input == null) throw new NullReferenceException("No input path was specified.");
447447
if (options.Output == null) throw new NullReferenceException("No output path was specified.");
448448

449-
IFileSystem a = Xb2.FS.Create.CreateFileSystem(options.Input);
450-
File.WriteAllLines(options.Output, a.EnumerateEntries().Select(x => x.FullPath));
449+
IFileSystem fs = new Xb2FileSystem(options.Input);
450+
File.WriteAllLines(options.Output,
451+
fs.EnumerateEntries().Where(x => x.Type == DirectoryEntryType.File).Select(x => x.FullPath));
451452
}
452453
}
453454
}

XbTool/XbTool/Xb2/ArchiveFileSystem.cs

+2
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
105105

106106
public IFile OpenFile(string path, OpenMode mode)
107107
{
108+
path = PathTools.Normalize(path);
109+
108110
if (!FileTable.TryOpenFile(path, out RomFileInfo romFileInfo))
109111
{
110112
throw new FileNotFoundException();

XbTool/XbTool/Xb2/Xb2Directory.cs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using LibHac.IO;
4+
5+
namespace XbTool.Xb2
6+
{
7+
public class Xb2Directory : IDirectory
8+
{
9+
private IDirectory BaseDirectory { get; }
10+
11+
public IFileSystem ParentFileSystem { get; }
12+
public string FullPath { get; }
13+
public OpenDirectoryMode Mode { get; }
14+
15+
public Xb2Directory(IFileSystem fs, IDirectory baseDirectory)
16+
{
17+
BaseDirectory = baseDirectory;
18+
ParentFileSystem = fs;
19+
FullPath = baseDirectory.FullPath;
20+
Mode = baseDirectory.Mode;
21+
}
22+
23+
public IEnumerable<DirectoryEntry> Read()
24+
{
25+
return BaseDirectory.Read().Where(x => !Xb2FileSystem.IsArchiveFile(x.Name));
26+
}
27+
28+
public int GetEntryCount()
29+
{
30+
return Read().Count();
31+
}
32+
}
33+
}

XbTool/XbTool/Xb2/FS/Create.cs XbTool/XbTool/Xb2/Xb2FileSystem.cs

+69-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
using LibHac;
66
using LibHac.IO;
77

8-
namespace XbTool.Xb2.FS
8+
namespace XbTool.Xb2
99
{
10-
public class Create
10+
public class Xb2FileSystem : IFileSystem
1111
{
12-
public static IFileSystem CreateFileSystem(string sdPath)
12+
private IFileSystem BaseFs { get; }
13+
14+
public Xb2FileSystem(string sdPath)
1315
{
1416
SwitchFs sdFs = OpenSdCard(sdPath);
1517
Application xb2App = sdFs.Applications[0x0100E95004038000];
@@ -39,10 +41,63 @@ public static IFileSystem CreateFileSystem(string sdPath)
3941
}
4042
}
4143

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);
4373
}
4474

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)
46101
{
47102
SwitchFs switchFs;
48103
Keyset keyset = OpenKeyset();
@@ -77,5 +132,14 @@ private static Keyset OpenKeyset()
77132

78133
return ExternalKeys.ReadKeyFile(homeKeyFile, homeTitleKeyFile, homeConsoleKeyFile);
79134
}
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();
80144
}
81145
}

0 commit comments

Comments
 (0)