From 148f641d30882e02d583685ff9a48d510fe4f678 Mon Sep 17 00:00:00 2001 From: shadowninja108 Date: Tue, 25 Dec 2018 23:05:54 -0700 Subject: [PATCH] Revert "Broken changes" This reverts commit 42af88374e01bc06e22e2ee56156aa66b9d9353d. --- src/LibHac/FileSystem/IFileSystem.cs | 38 +++++++++------------------- src/LibHac/Romfs.cs | 6 ++--- src/LibHac/RomfsEntry.cs | 22 ++++++++-------- 3 files changed, 24 insertions(+), 42 deletions(-) diff --git a/src/LibHac/FileSystem/IFileSystem.cs b/src/LibHac/FileSystem/IFileSystem.cs index b601d266..ea4417ae 100644 --- a/src/LibHac/FileSystem/IFileSystem.cs +++ b/src/LibHac/FileSystem/IFileSystem.cs @@ -50,10 +50,10 @@ namespace LibHac public abstract class IFileSytemEntry { - public abstract IFileSystem FileSystem { get; protected set; } - public abstract string Path { get; protected set; } + public abstract IFileSystem FileSystem { get; } + public abstract string Path { get; } public virtual string Name => System.IO.Path.GetFileName(Path); - public virtual bool Exists { get; protected set; } + public abstract bool Exists { get; } public IDirectory Parent { @@ -68,18 +68,19 @@ namespace LibHac } - public abstract class IDirectory : IFileSytemEntry + public class IDirectory : IFileSytemEntry { - public override IFileSystem FileSystem { get; protected set; } - public override string Path { get; protected set; } + public override IFileSystem FileSystem { get; } + public override string Path { get; } public override bool Exists => FileSystem.DirectoryExists(this); public IFile[] Files => FileSystem.GetFiles(this); public IDirectory[] Directories => FileSystem.GetDirectories(this); - public IDirectory(IFileSystem filesystem) + public IDirectory(IFileSystem filesystem, string path) { FileSystem = filesystem; + Path = path; } public IFile GetFile(string path) @@ -103,27 +104,20 @@ namespace LibHac } } - public class Directory : IDirectory - { - public Directory(IFileSystem fileSystem, string path) : base(fileSystem) - { - Path = path; - } - } - public class IFile : IFileSytemEntry { - public override IFileSystem FileSystem { get; protected set; } - public override string Path { get; protected set; } + public override IFileSystem FileSystem { get; } + public override string Path { get; } public override bool Exists => FileSystem.FileExists(this); public string Extension => System.IO.Path.GetExtension(Path); public string FileName => System.IO.Path.GetFileName(Path); public long Length => FileSystem.GetSize(this); - public IFile(IFileSystem filesystem) + public IFile(IFileSystem filesystem, string path) { FileSystem = filesystem; + Path = path; } public IStorage Open(FileMode mode) @@ -146,13 +140,5 @@ namespace LibHac { return base.GetHashCode(); } - - public class File : IFile - { - public File(IFileSystem fileSystem, string path) : base(fileSystem) - { - Path = path; - } - } } } diff --git a/src/LibHac/Romfs.cs b/src/LibHac/Romfs.cs index 8c382b4a..25bc1ae2 100644 --- a/src/LibHac/Romfs.cs +++ b/src/LibHac/Romfs.cs @@ -6,10 +6,8 @@ using LibHac.IO; namespace LibHac { - public class Romfs : IFileSystem + public class Romfs { - public const string Delimiter = "/"; - public new string PathSeperator = Romfs.Delimiter; public const int IvfcMaxLevel = 6; public RomfsHeader Header { get; } public List Directories { get; } = new List(); @@ -39,7 +37,7 @@ namespace LibHac int position = 0; while (position + 20 < Header.DirMetaTableSize) { - var dir = new RomfsDir(reader, this) { Offset = position }; + var dir = new RomfsDir(reader) { Offset = position }; Directories.Add(dir); if (dir.ParentDirOffset == position) RootDir = dir; position = (int)reader.BaseStream.Position; diff --git a/src/LibHac/RomfsEntry.cs b/src/LibHac/RomfsEntry.cs index 9b33f907..1fa90653 100644 --- a/src/LibHac/RomfsEntry.cs +++ b/src/LibHac/RomfsEntry.cs @@ -5,31 +5,30 @@ using System.Text; namespace LibHac { - public abstract class RomfsEntry : IFileSytemEntry + public abstract class RomfsEntry { - private const string PathSeperator = "/"; public int Offset { get; set; } public int ParentDirOffset { get; protected set; } public int NameLength { get; protected set; } - public new string Name { get; protected set; } + public string Name { get; protected set; } - public new IDirectory Parent { get; internal set; } - public override string Path { get; protected set; } + public RomfsDir ParentDir { get; internal set; } + public string FullPath { get; private set; } internal static void ResolveFilenames(IEnumerable entries) { var list = new List(); var sb = new StringBuilder(); - const string delimiter = RomfsEntry.PathSeperator; + const string delimiter = "/"; foreach (RomfsEntry file in entries) { list.Add(file.Name); - RomfsDir dir = file.Parent as RomfsDir; + RomfsDir dir = file.ParentDir; while (dir != null) { list.Add(delimiter); list.Add(dir.Name); - dir = dir.Parent as RomfsDir; + dir = dir.ParentDir; } for (int i = list.Count - 1; i >= 0; i--) @@ -37,7 +36,7 @@ namespace LibHac sb.Append(list[i]); } - file.Path = sb.ToString(); + file.FullPath = sb.ToString(); list.Clear(); sb.Clear(); } @@ -45,7 +44,7 @@ namespace LibHac } [DebuggerDisplay("{" + nameof(Name) + "}")] - public class RomfsDir : Directory + public class RomfsDir : RomfsEntry { public int NextSiblingOffset { get; } public int FirstChildOffset { get; } @@ -57,9 +56,8 @@ namespace LibHac public RomfsFile FirstFile { get; internal set; } public RomfsDir NextDirHash { get; internal set; } - public RomfsDir(BinaryReader reader, IFileSystem fs) : base(fs) + public RomfsDir(BinaryReader reader) { - FileSystem = fs; ParentDirOffset = reader.ReadInt32(); NextSiblingOffset = reader.ReadInt32(); FirstChildOffset = reader.ReadInt32();