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,7 +98,8 @@ namespace LibHac.Nand
public void CreateFile(string path, long size, CreateFileOptions options) => 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 QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId) => throw new NotSupportedException();
private static FileAccess GetFileAccess(OpenMode mode)
{
// FileAccess and OpenMode have the same flags

View file

@ -184,6 +184,11 @@ namespace LibHac.IO
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)
{
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;
}
private void SetConcatenationFileAttribute(string path)
{
NxFileAttributes attributes = BaseFileSystem.GetFileAttributes(path);
attributes |= NxFileAttributes.Archive;
BaseFileSystem.SetFileAttributes(path, attributes);
}
public void CreateDirectory(string 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");
BaseFileSystem.CreateDirectory(path);
NxFileAttributes attributes = BaseFileSystem.GetFileAttributes(path) | NxFileAttributes.Archive;
BaseFileSystem.SetFileAttributes(path, attributes);
SetConcatenationFileAttribute(path);
long remaining = size;
@ -197,6 +203,13 @@ namespace LibHac.IO
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)
{
int count = 0;

View file

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

View file

@ -106,6 +106,8 @@ namespace LibHac.IO
/// Does nothing if called on a non-transactional file system.
/// </summary>
void Commit();
void QueryEntry(Span<byte> outBuffer, Span<byte> inBuffer, string path, QueryId queryId);
}
/// <summary>
@ -124,11 +126,16 @@ namespace LibHac.IO
/// </summary>
[Flags]
public enum CreateFileOptions
{
{
None = 0,
/// <summary>
/// On a <see cref="ConcatenationFileSystem"/>, creates a concatenation file.
/// </summary>
CreateConcatenationFile = 1 << 0
}
public enum QueryId
{
MakeConcatFile = 0
}
}

View file

@ -97,6 +97,22 @@ namespace LibHac.IO
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 CreateDirectory(string path) => throw new NotSupportedException();

View file

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

View file

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

View file

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

View file

@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
namespace LibHac.IO.Save
{
@ -28,7 +29,7 @@ namespace LibHac.IO.Save
public void CreateDirectory(string path)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
public void CreateFile(string path, long size, CreateFileOptions options)
@ -45,7 +46,7 @@ namespace LibHac.IO.Save
public void DeleteDirectory(string path)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
public void DeleteFile(string path)
@ -93,12 +94,12 @@ namespace LibHac.IO.Save
public void RenameDirectory(string srcPath, string dstPath)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
public void RenameFile(string srcPath, string dstPath)
{
throw new System.NotImplementedException();
throw new NotImplementedException();
}
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 GetHeaderStorage() => HeaderStorage.AsReadOnly();

View file

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