Broken changes

This commit is contained in:
shadowninja108 2018-12-23 01:18:40 -07:00
parent f62b34905e
commit 42af88374e
3 changed files with 42 additions and 24 deletions

View file

@ -50,10 +50,10 @@ namespace LibHac
public abstract class IFileSytemEntry public abstract class IFileSytemEntry
{ {
public abstract IFileSystem FileSystem { get; } public abstract IFileSystem FileSystem { get; protected set; }
public abstract string Path { get; } public abstract string Path { get; protected set; }
public virtual string Name => System.IO.Path.GetFileName(Path); public virtual string Name => System.IO.Path.GetFileName(Path);
public abstract bool Exists { get; } public virtual bool Exists { get; protected set; }
public IDirectory Parent public IDirectory Parent
{ {
@ -68,19 +68,18 @@ namespace LibHac
} }
public class IDirectory : IFileSytemEntry public abstract class IDirectory : IFileSytemEntry
{ {
public override IFileSystem FileSystem { get; } public override IFileSystem FileSystem { get; protected set; }
public override string Path { get; } public override string Path { get; protected set; }
public override bool Exists => FileSystem.DirectoryExists(this); public override bool Exists => FileSystem.DirectoryExists(this);
public IFile[] Files => FileSystem.GetFiles(this); public IFile[] Files => FileSystem.GetFiles(this);
public IDirectory[] Directories => FileSystem.GetDirectories(this); public IDirectory[] Directories => FileSystem.GetDirectories(this);
public IDirectory(IFileSystem filesystem, string path) public IDirectory(IFileSystem filesystem)
{ {
FileSystem = filesystem; FileSystem = filesystem;
Path = path;
} }
public IFile GetFile(string path) public IFile GetFile(string path)
@ -104,20 +103,27 @@ namespace LibHac
} }
} }
public class Directory : IDirectory
{
public Directory(IFileSystem fileSystem, string path) : base(fileSystem)
{
Path = path;
}
}
public class IFile : IFileSytemEntry public class IFile : IFileSytemEntry
{ {
public override IFileSystem FileSystem { get; } public override IFileSystem FileSystem { get; protected set; }
public override string Path { get; } public override string Path { get; protected set; }
public override bool Exists => FileSystem.FileExists(this); public override bool Exists => FileSystem.FileExists(this);
public string Extension => System.IO.Path.GetExtension(Path); public string Extension => System.IO.Path.GetExtension(Path);
public string FileName => System.IO.Path.GetFileName(Path); public string FileName => System.IO.Path.GetFileName(Path);
public long Length => FileSystem.GetSize(this); public long Length => FileSystem.GetSize(this);
public IFile(IFileSystem filesystem, string path) public IFile(IFileSystem filesystem)
{ {
FileSystem = filesystem; FileSystem = filesystem;
Path = path;
} }
public IStorage Open(FileMode mode) public IStorage Open(FileMode mode)
@ -140,5 +146,13 @@ namespace LibHac
{ {
return base.GetHashCode(); return base.GetHashCode();
} }
public class File : IFile
{
public File(IFileSystem fileSystem, string path) : base(fileSystem)
{
Path = path;
}
}
} }
} }

View file

@ -6,8 +6,10 @@ using LibHac.IO;
namespace LibHac namespace LibHac
{ {
public class Romfs public class Romfs : IFileSystem
{ {
public const string Delimiter = "/";
public new string PathSeperator = Romfs.Delimiter;
public const int IvfcMaxLevel = 6; public const int IvfcMaxLevel = 6;
public RomfsHeader Header { get; } public RomfsHeader Header { get; }
public List<RomfsDir> Directories { get; } = new List<RomfsDir>(); public List<RomfsDir> Directories { get; } = new List<RomfsDir>();
@ -37,7 +39,7 @@ namespace LibHac
int position = 0; int position = 0;
while (position + 20 < Header.DirMetaTableSize) while (position + 20 < Header.DirMetaTableSize)
{ {
var dir = new RomfsDir(reader) { Offset = position }; var dir = new RomfsDir(reader, this) { Offset = position };
Directories.Add(dir); Directories.Add(dir);
if (dir.ParentDirOffset == position) RootDir = dir; if (dir.ParentDirOffset == position) RootDir = dir;
position = (int)reader.BaseStream.Position; position = (int)reader.BaseStream.Position;

View file

@ -5,30 +5,31 @@ using System.Text;
namespace LibHac namespace LibHac
{ {
public abstract class RomfsEntry public abstract class RomfsEntry : IFileSytemEntry
{ {
private const string PathSeperator = "/";
public int Offset { get; set; } public int Offset { get; set; }
public int ParentDirOffset { get; protected set; } public int ParentDirOffset { get; protected set; }
public int NameLength { get; protected set; } public int NameLength { get; protected set; }
public string Name { get; protected set; } public new string Name { get; protected set; }
public RomfsDir ParentDir { get; internal set; } public new IDirectory Parent { get; internal set; }
public string FullPath { get; private set; } public override string Path { get; protected set; }
internal static void ResolveFilenames(IEnumerable<RomfsEntry> entries) internal static void ResolveFilenames(IEnumerable<RomfsEntry> entries)
{ {
var list = new List<string>(); var list = new List<string>();
var sb = new StringBuilder(); var sb = new StringBuilder();
const string delimiter = "/"; const string delimiter = RomfsEntry.PathSeperator;
foreach (RomfsEntry file in entries) foreach (RomfsEntry file in entries)
{ {
list.Add(file.Name); list.Add(file.Name);
RomfsDir dir = file.ParentDir; RomfsDir dir = file.Parent as RomfsDir;
while (dir != null) while (dir != null)
{ {
list.Add(delimiter); list.Add(delimiter);
list.Add(dir.Name); list.Add(dir.Name);
dir = dir.ParentDir; dir = dir.Parent as RomfsDir;
} }
for (int i = list.Count - 1; i >= 0; i--) for (int i = list.Count - 1; i >= 0; i--)
@ -36,7 +37,7 @@ namespace LibHac
sb.Append(list[i]); sb.Append(list[i]);
} }
file.FullPath = sb.ToString(); file.Path = sb.ToString();
list.Clear(); list.Clear();
sb.Clear(); sb.Clear();
} }
@ -44,7 +45,7 @@ namespace LibHac
} }
[DebuggerDisplay("{" + nameof(Name) + "}")] [DebuggerDisplay("{" + nameof(Name) + "}")]
public class RomfsDir : RomfsEntry public class RomfsDir : Directory
{ {
public int NextSiblingOffset { get; } public int NextSiblingOffset { get; }
public int FirstChildOffset { get; } public int FirstChildOffset { get; }
@ -56,8 +57,9 @@ namespace LibHac
public RomfsFile FirstFile { get; internal set; } public RomfsFile FirstFile { get; internal set; }
public RomfsDir NextDirHash { get; internal set; } public RomfsDir NextDirHash { get; internal set; }
public RomfsDir(BinaryReader reader) public RomfsDir(BinaryReader reader, IFileSystem fs) : base(fs)
{ {
FileSystem = fs;
ParentDirOffset = reader.ReadInt32(); ParentDirOffset = reader.ReadInt32();
NextSiblingOffset = reader.ReadInt32(); NextSiblingOffset = reader.ReadInt32();
FirstChildOffset = reader.ReadInt32(); FirstChildOffset = reader.ReadInt32();