Add IAttributeFileSystem

This commit is contained in:
Alex Barney 2019-01-06 23:04:22 -06:00
parent 8f977554f2
commit 404e05da53
3 changed files with 26 additions and 7 deletions

View file

@ -0,0 +1,10 @@
using System.IO;
namespace LibHac.IO
{
public interface IAttributeFileSystem : IFileSystem
{
FileAttributes GetFileAttributes(string path);
long GetFileSize(string path);
}
}

View file

@ -25,13 +25,11 @@ namespace LibHac.IO
public IEnumerable<DirectoryEntry> Read()
{
var entries = new List<DirectoryEntry>();
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()

View file

@ -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);