Add GetEntryType to IFileSystem

This commit is contained in:
Alex Barney 2019-01-15 14:58:14 -06:00
parent b8b57c9fb7
commit a33f829b55
11 changed files with 126 additions and 32 deletions

View file

@ -57,6 +57,17 @@ namespace LibHac.Nand
return Fs.FileExists(path);
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
string discUtilsPath = ToDiscUtilsPath(path);
if (Fs.FileExists(discUtilsPath)) return DirectoryEntryType.File;
if (Fs.DirectoryExists(discUtilsPath)) return DirectoryEntryType.Directory;
throw new FileNotFoundException(path);
}
public FileAttributes GetFileAttributes(string path)
{
path = ToDiscUtilsPath(PathTools.Normalize(path));

View file

@ -85,6 +85,11 @@ namespace LibHac.IO
return BaseFileSystem.FileExists(path);
}
public DirectoryEntryType GetEntryType(string path)
{
return BaseFileSystem.GetEntryType(path);
}
public void Commit()
{
BaseFileSystem.Commit();

View file

@ -120,6 +120,15 @@ namespace LibHac.IO
return BaseFileSystem.FileExists(path) || BaseFileSystem.DirectoryExists(path) && IsSplitFile(path);
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
if (IsSplitFile(path)) return DirectoryEntryType.File;
return BaseFileSystem.GetEntryType(path);
}
public void Commit()
{
BaseFileSystem.Commit();

View file

@ -14,6 +14,7 @@ namespace LibHac.IO
void RenameFile(string srcPath, string dstPath);
bool DirectoryExists(string path);
bool FileExists(string path);
DirectoryEntryType GetEntryType(string path);
void Commit();
}

View file

@ -77,6 +77,26 @@ namespace LibHac.IO
return false;
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
foreach (IFileSystem fs in Sources)
{
if (fs.FileExists(path))
{
return DirectoryEntryType.File;
}
if (fs.DirectoryExists(path))
{
return DirectoryEntryType.Directory;
}
}
throw new FileNotFoundException(path);
}
public void Commit() { }
public void CreateDirectory(string path) => throw new NotSupportedException();

View file

@ -121,6 +121,24 @@ namespace LibHac.IO
return File.Exists(ResolveLocalPath(path));
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
string localPath = ResolveLocalPath(path);
if (Directory.Exists(localPath))
{
return DirectoryEntryType.Directory;
}
if (File.Exists(localPath))
{
return DirectoryEntryType.File;
}
throw new FileNotFoundException("path");
}
public void Commit()
{
throw new NotImplementedException();

View file

@ -93,6 +93,17 @@ namespace LibHac.IO
return FileDict.ContainsKey(path);
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
if (path == "/") return DirectoryEntryType.Directory;
if (FileDict.ContainsKey(path)) return DirectoryEntryType.File;
throw new FileNotFoundException(path);
}
public void Commit()
{
throw new NotSupportedException();

View file

@ -86,31 +86,21 @@ namespace LibHac.IO
}
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
if (FileDict.ContainsKey(path)) return DirectoryEntryType.File;
if (DirectoryDict.ContainsKey(path)) return DirectoryEntryType.Directory;
throw new FileNotFoundException(path);
}
public void Commit()
{
throw new NotSupportedException();
}
public void CreateDirectory(string path)
{
throw new NotSupportedException();
}
public void CreateFile(string path, long size)
{
throw new NotSupportedException();
}
public void DeleteDirectory(string path)
{
throw new NotSupportedException();
}
public void DeleteFile(string path)
{
throw new NotSupportedException();
}
public IDirectory OpenDirectory(string path, OpenDirectoryMode mode)
{
return new RomFsDirectory(this, path, mode);
@ -138,16 +128,6 @@ namespace LibHac.IO
return new RomFsFile(BaseStorage, Header.DataOffset + file.DataOffset, file.DataLength);
}
public void RenameDirectory(string srcPath, string dstPath)
{
throw new NotSupportedException();
}
public void RenameFile(string srcPath, string dstPath)
{
throw new NotSupportedException();
}
public bool DirectoryExists(string path)
{
path = PathTools.Normalize(path);
@ -166,6 +146,13 @@ namespace LibHac.IO
{
return BaseStorage;
}
public void CreateDirectory(string path) => throw new NotSupportedException();
public void CreateFile(string path, long size) => throw new NotSupportedException();
public void DeleteDirectory(string path) => throw new NotSupportedException();
public void DeleteFile(string path) => throw new NotSupportedException();
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
}
public class RomfsHeader

View file

@ -160,6 +160,11 @@ namespace LibHac.IO.Save
public bool DirectoryExists(string path) => SaveDataFileSystemCore.DirectoryExists(path);
public bool FileExists(string filename) => SaveDataFileSystemCore.FileExists(filename);
public DirectoryEntryType GetEntryType(string path)
{
return SaveDataFileSystemCore.GetEntryType(path);
}
public void Commit()
{
Commit(Keyset);

View file

@ -95,6 +95,8 @@ namespace LibHac.IO.Save
public IFile OpenFile(string path, OpenMode mode)
{
path = PathTools.Normalize(path);
if (!FileDictionary.TryGetValue(path, out SaveFileEntry file))
{
throw new FileNotFoundException();
@ -123,10 +125,28 @@ namespace LibHac.IO.Save
public bool DirectoryExists(string path)
{
throw new System.NotImplementedException();
path = PathTools.Normalize(path);
return DirDictionary.ContainsKey(path);
}
public bool FileExists(string path)
{
path = PathTools.Normalize(path);
return FileDictionary.ContainsKey(path);
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
if (DirDictionary.ContainsKey(path)) return DirectoryEntryType.Directory;
if (FileDictionary.ContainsKey(path)) return DirectoryEntryType.File;
throw new FileNotFoundException(path);
}
public bool FileExists(string filename) => FileDictionary.ContainsKey(filename);
public void Commit()
{
throw new System.NotImplementedException();

View file

@ -91,6 +91,13 @@
return ParentFileSystem.FileExists(ResolveFullPath(path));
}
public DirectoryEntryType GetEntryType(string path)
{
path = PathTools.Normalize(path);
return ParentFileSystem.GetEntryType(ResolveFullPath(path));
}
public void Commit()
{
ParentFileSystem.Commit();