Add QueryEntry to IFileSystem

This commit is contained in:
Alex Barney 2019-05-06 19:04:05 -05:00
parent 87e9829892
commit 67bf8b19ce
12 changed files with 77 additions and 12 deletions

View file

@ -98,6 +98,7 @@ namespace LibHac.Nand
public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException(); public void CreateFile(string path, long size, CreateFileOptions options) => throw new NotSupportedException();
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException(); public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException(); public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
private static FileAccess GetFileAccess(OpenMode mode) private static FileAccess GetFileAccess(OpenMode mode)
{ {

View file

@ -184,6 +184,11 @@ namespace LibHac.IO
BaseFileSystem.Commit(); BaseFileSystem.Commit();
} }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId)
{
BaseFileSystem.QueryEntry(outBuffer, inBuffer, path, queryId);
}
private AesXtsFileHeader ReadXtsHeader(string filePath, string keyPath) private AesXtsFileHeader ReadXtsHeader(string filePath, string keyPath)
{ {
if (!TryReadXtsHeader(filePath, keyPath, out AesXtsFileHeader header)) if (!TryReadXtsHeader(filePath, keyPath, out AesXtsFileHeader header))

View file

@ -28,6 +28,13 @@ namespace LibHac.IO
return (attributes & NxFileAttributes.Directory) != 0 && (attributes & NxFileAttributes.Archive) != 0; return (attributes & NxFileAttributes.Directory) != 0 && (attributes & NxFileAttributes.Archive) != 0;
} }
private void SetConcatenationFileAttribute(string path)
{
NxFileAttributes attributes = BaseFileSystem.GetFileAttributes(path);
attributes |= NxFileAttributes.Archive;
BaseFileSystem.SetFileAttributes(path, attributes);
}
public void CreateDirectory(string path) public void CreateDirectory(string path)
{ {
path = PathTools.Normalize(path); path = PathTools.Normalize(path);
@ -57,8 +64,7 @@ namespace LibHac.IO
if (IsConcatenationFile(parentDir)) throw new IOException("Cannot create files inside of a concatenation file"); if (IsConcatenationFile(parentDir)) throw new IOException("Cannot create files inside of a concatenation file");
BaseFileSystem.CreateDirectory(path); BaseFileSystem.CreateDirectory(path);
NxFileAttributes attributes = BaseFileSystem.GetFileAttributes(path) | NxFileAttributes.Archive; SetConcatenationFileAttribute(path);
BaseFileSystem.SetFileAttributes(path, attributes);
long remaining = size; long remaining = size;
@ -197,6 +203,13 @@ namespace LibHac.IO
BaseFileSystem.Commit(); BaseFileSystem.Commit();
} }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId)
{
if(queryId != QueryId.MakeConcatFile) throw new NotSupportedException();
SetConcatenationFileAttribute(path);
}
private int GetSubFileCount(string dirPath) private int GetSubFileCount(string dirPath)
{ {
int count = 0; int count = 0;

View file

@ -177,6 +177,11 @@ namespace LibHac.IO
var nxAttributeBits = (FileAttributes)(((int)nxAttributes & 3) << 4); var nxAttributeBits = (FileAttributes)(((int)nxAttributes & 3) << 4);
return attributes | nxAttributeBits; return attributes | nxAttributeBits;
} }
public static void SetConcatenationFileAttribute(this IFileSystem fs, string path)
{
fs.QueryEntry(Span<byte>.Empty, Span<byte>.Empty, path, QueryId.MakeConcatFile);
}
} }
[Flags] [Flags]

View file

@ -106,6 +106,8 @@ namespace LibHac.IO
/// Does nothing if called on a non-transactional file system. /// Does nothing if called on a non-transactional file system.
/// </summary> /// </summary>
void Commit(); void Commit();
void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId);
} }
/// <summary> /// <summary>
@ -131,4 +133,9 @@ namespace LibHac.IO
/// </summary> /// </summary>
CreateConcatenationFile = 1 << 0 CreateConcatenationFile = 1 << 0
} }
public enum QueryId
{
MakeConcatFile = 0
}
} }

View file

@ -97,6 +97,22 @@ namespace LibHac.IO
throw new FileNotFoundException(path); throw new FileNotFoundException(path);
} }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId)
{
path = PathTools.Normalize(path);
foreach (IFileSystem fs in Sources)
{
if (fs.FileExists(path) || fs.DirectoryExists(path))
{
fs.QueryEntry(outBuffer, inBuffer, path, queryId);
return;
}
}
throw new FileNotFoundException(path);
}
public void Commit() { } public void Commit() { }
public void CreateDirectory(string path) => throw new NotSupportedException(); public void CreateDirectory(string path) => throw new NotSupportedException();

View file

@ -1,4 +1,5 @@
using System.IO; using System;
using System.IO;
namespace LibHac.IO namespace LibHac.IO
{ {
@ -160,5 +161,7 @@ namespace LibHac.IO
} }
public void Commit() { } public void Commit() { }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
} }
} }

View file

@ -82,6 +82,7 @@ namespace LibHac.IO
public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException(); public void RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException(); public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
public void Commit() { } public void Commit() { }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
} }
public enum PartitionFileSystemType public enum PartitionFileSystemType

View file

@ -89,6 +89,7 @@ namespace LibHac.IO.RomFs
public void DeleteFile(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 RenameDirectory(string srcPath, string dstPath) => throw new NotSupportedException();
public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException(); public void RenameFile(string srcPath, string dstPath) => throw new NotSupportedException();
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
} }
public class RomfsHeader public class RomfsHeader

View file

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
namespace LibHac.IO.Save namespace LibHac.IO.Save
@ -194,6 +195,8 @@ namespace LibHac.IO.Save
Commit(Keyset); Commit(Keyset);
} }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
public bool Commit(Keyset keyset) public bool Commit(Keyset keyset)
{ {
CoreDataIvfcStorage.Flush(); CoreDataIvfcStorage.Flush();

View file

@ -1,4 +1,5 @@
using System.IO; using System;
using System.IO;
namespace LibHac.IO.Save namespace LibHac.IO.Save
{ {
@ -28,7 +29,7 @@ namespace LibHac.IO.Save
public void CreateDirectory(string path) public void CreateDirectory(string path)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public void CreateFile(string path, long size, CreateFileOptions options) public void CreateFile(string path, long size, CreateFileOptions options)
@ -45,7 +46,7 @@ namespace LibHac.IO.Save
public void DeleteDirectory(string path) public void DeleteDirectory(string path)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public void DeleteFile(string path) public void DeleteFile(string path)
@ -93,12 +94,12 @@ namespace LibHac.IO.Save
public void RenameDirectory(string srcPath, string dstPath) public void RenameDirectory(string srcPath, string dstPath)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public void RenameFile(string srcPath, string dstPath) public void RenameFile(string srcPath, string dstPath)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public bool DirectoryExists(string path) public bool DirectoryExists(string path)
@ -130,6 +131,8 @@ namespace LibHac.IO.Save
} }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
public IStorage GetBaseStorage() => BaseStorage.AsReadOnly(); public IStorage GetBaseStorage() => BaseStorage.AsReadOnly();
public IStorage GetHeaderStorage() => HeaderStorage.AsReadOnly(); public IStorage GetHeaderStorage() => HeaderStorage.AsReadOnly();

View file

@ -1,4 +1,6 @@
namespace LibHac.IO using System;
namespace LibHac.IO
{ {
public class SubdirectoryFileSystem : IFileSystem public class SubdirectoryFileSystem : IFileSystem
{ {
@ -102,5 +104,10 @@
{ {
ParentFileSystem.Commit(); ParentFileSystem.Commit();
} }
public void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId)
{
ParentFileSystem.QueryEntry(outBuffer, inBuffer, ResolveFullPath(path), queryId);
}
} }
} }