From 404e05da539dd1fa5b62c256cfa0e2c7f595e783 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 6 Jan 2019 23:04:22 -0600 Subject: [PATCH] Add IAttributeFileSystem --- src/LibHac/IO/IAttributeFileSystem.cs | 10 ++++++++++ src/LibHac/IO/LocalDirectory.cs | 8 ++------ src/LibHac/IO/LocalFileSystem.cs | 15 ++++++++++++++- 3 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 src/LibHac/IO/IAttributeFileSystem.cs diff --git a/src/LibHac/IO/IAttributeFileSystem.cs b/src/LibHac/IO/IAttributeFileSystem.cs new file mode 100644 index 00000000..1d23d0f8 --- /dev/null +++ b/src/LibHac/IO/IAttributeFileSystem.cs @@ -0,0 +1,10 @@ +using System.IO; + +namespace LibHac.IO +{ + public interface IAttributeFileSystem : IFileSystem + { + FileAttributes GetFileAttributes(string path); + long GetFileSize(string path); + } +} diff --git a/src/LibHac/IO/LocalDirectory.cs b/src/LibHac/IO/LocalDirectory.cs index 8b2455c1..231e070f 100644 --- a/src/LibHac/IO/LocalDirectory.cs +++ b/src/LibHac/IO/LocalDirectory.cs @@ -25,13 +25,11 @@ namespace LibHac.IO public IEnumerable Read() { - var entries = new List(); - if (Mode.HasFlag(OpenDirectoryMode.Directories)) { foreach (DirectoryInfo dir in DirInfo.EnumerateDirectories()) { - entries.Add(new DirectoryEntry(dir.Name, FullPath + '/' + dir.Name, DirectoryEntryType.Directory, 0)); + yield return new DirectoryEntry(dir.Name, FullPath + '/' + dir.Name, DirectoryEntryType.Directory, 0); } } @@ -39,11 +37,9 @@ namespace LibHac.IO { foreach (FileInfo file in DirInfo.EnumerateFiles()) { - entries.Add(new DirectoryEntry(file.Name, FullPath + '/' + file.Name, DirectoryEntryType.File, file.Length)); + yield return new DirectoryEntry(file.Name, FullPath + '/' + file.Name, DirectoryEntryType.File, file.Length); } } - - return entries.ToArray(); } public int GetEntryCount() diff --git a/src/LibHac/IO/LocalFileSystem.cs b/src/LibHac/IO/LocalFileSystem.cs index 7b26b4ab..1e46ef67 100644 --- a/src/LibHac/IO/LocalFileSystem.cs +++ b/src/LibHac/IO/LocalFileSystem.cs @@ -3,7 +3,7 @@ using System.IO; namespace LibHac.IO { - public class LocalFileSystem : IFileSystem + public class LocalFileSystem : IAttributeFileSystem { private string BasePath { get; } @@ -17,6 +17,19 @@ namespace LibHac.IO return Path.Combine(BasePath, path.TrimStart('/')); } + public FileAttributes GetFileAttributes(string path) + { + path = PathTools.Normalize(path); + return File.GetAttributes(ResolveLocalPath(path)); + } + + public long GetFileSize(string path) + { + path = PathTools.Normalize(path); + var info = new FileInfo(ResolveLocalPath(path)); + return info.Length; + } + public void CreateDirectory(string path) { path = PathTools.Normalize(path);