mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add SubdirectoryFileSystem
This commit is contained in:
parent
8861f25bc7
commit
4ded38c1d6
2 changed files with 130 additions and 0 deletions
99
src/LibHac/IO/SubdirectoryFileSystem.cs
Normal file
99
src/LibHac/IO/SubdirectoryFileSystem.cs
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
namespace LibHac.IO
|
||||||
|
{
|
||||||
|
public class SubdirectoryFileSystem : IFileSystem
|
||||||
|
{
|
||||||
|
private string RootPath { get; }
|
||||||
|
private IFileSystem ParentFileSystem { get; }
|
||||||
|
|
||||||
|
private string ResolveFullPath(string path)
|
||||||
|
{
|
||||||
|
//todo
|
||||||
|
return RootPath + path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SubdirectoryFileSystem(IFileSystem fs, string rootPath)
|
||||||
|
{
|
||||||
|
ParentFileSystem = fs;
|
||||||
|
RootPath = PathTools.Normalize(rootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateDirectory(string path)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
ParentFileSystem.CreateDirectory(ResolveFullPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateFile(string path, long size)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
ParentFileSystem.CreateFile(ResolveFullPath(path), size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteDirectory(string path)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
ParentFileSystem.DeleteDirectory(ResolveFullPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DeleteFile(string path)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
ParentFileSystem.DeleteFile(ResolveFullPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
IDirectory baseDir = ParentFileSystem.OpenDirectory(ResolveFullPath(path), mode);
|
||||||
|
|
||||||
|
return new SubdirectoryFileSystemDirectory(this, baseDir, path, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IFile OpenFile(string path, OpenMode mode)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
return ParentFileSystem.OpenFile(ResolveFullPath(path), mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenameDirectory(string srcPath, string dstPath)
|
||||||
|
{
|
||||||
|
srcPath = PathTools.Normalize(srcPath);
|
||||||
|
dstPath = PathTools.Normalize(dstPath);
|
||||||
|
|
||||||
|
ParentFileSystem.RenameDirectory(ResolveFullPath(srcPath), ResolveFullPath(dstPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RenameFile(string srcPath, string dstPath)
|
||||||
|
{
|
||||||
|
srcPath = PathTools.Normalize(srcPath);
|
||||||
|
dstPath = PathTools.Normalize(dstPath);
|
||||||
|
|
||||||
|
ParentFileSystem.RenameFile(ResolveFullPath(srcPath), ResolveFullPath(dstPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DirectoryExists(string path)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
return ParentFileSystem.DirectoryExists(ResolveFullPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool FileExists(string path)
|
||||||
|
{
|
||||||
|
path = PathTools.Normalize(path);
|
||||||
|
|
||||||
|
return ParentFileSystem.FileExists(ResolveFullPath(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Commit()
|
||||||
|
{
|
||||||
|
ParentFileSystem.Commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
src/LibHac/IO/SubdirectoryFileSystemDirectory.cs
Normal file
31
src/LibHac/IO/SubdirectoryFileSystemDirectory.cs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace LibHac.IO
|
||||||
|
{
|
||||||
|
public class SubdirectoryFileSystemDirectory : IDirectory
|
||||||
|
{
|
||||||
|
public SubdirectoryFileSystemDirectory(SubdirectoryFileSystem fs, IDirectory baseDir, string path, OpenDirectoryMode mode)
|
||||||
|
{
|
||||||
|
ParentFileSystem = fs;
|
||||||
|
BaseDirectory = baseDir;
|
||||||
|
FullPath = path;
|
||||||
|
Mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IFileSystem ParentFileSystem { get; }
|
||||||
|
public string FullPath { get; }
|
||||||
|
public OpenDirectoryMode Mode { get; }
|
||||||
|
|
||||||
|
private IDirectory BaseDirectory { get; }
|
||||||
|
|
||||||
|
public IEnumerable<DirectoryEntry> Read()
|
||||||
|
{
|
||||||
|
return BaseDirectory.Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetEntryCount()
|
||||||
|
{
|
||||||
|
return BaseDirectory.GetEntryCount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue