mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Create FileSystemProxy class
This commit is contained in:
parent
a052ebb8a1
commit
82c5c5d9a0
5 changed files with 186 additions and 1 deletions
|
@ -13,6 +13,7 @@ namespace LibHac.Fs
|
||||||
public static readonly char DirectorySeparator = '/';
|
public static readonly char DirectorySeparator = '/';
|
||||||
public static readonly char MountSeparator = ':';
|
public static readonly char MountSeparator = ':';
|
||||||
internal const int MountNameLength = 0xF;
|
internal const int MountNameLength = 0xF;
|
||||||
|
internal const int MaxPathLength = 0x300;
|
||||||
|
|
||||||
public static string Normalize(string inPath)
|
public static string Normalize(string inPath)
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,6 +13,6 @@ namespace LibHac.FsService.Creators
|
||||||
IFileSystem sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac,
|
IFileSystem sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac,
|
||||||
SaveDataType type, ITimeStampGenerator timeStampGenerator);
|
SaveDataType type, ITimeStampGenerator timeStampGenerator);
|
||||||
|
|
||||||
Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed);
|
void SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
93
src/LibHac/FsService/FileSystemProxy.cs
Normal file
93
src/LibHac/FsService/FileSystemProxy.cs
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
using System;
|
||||||
|
using LibHac.Fs;
|
||||||
|
|
||||||
|
namespace LibHac.FsService
|
||||||
|
{
|
||||||
|
public class FileSystemProxy
|
||||||
|
{
|
||||||
|
private FileSystemProxyCore FsProxyCore { get; }
|
||||||
|
public long CurrentProcess { get; private set; }
|
||||||
|
|
||||||
|
public long SaveDataSize { get; private set; }
|
||||||
|
public long SaveDataJournalSize { get; private set; }
|
||||||
|
public string SaveDataRootPath { get; private set; }
|
||||||
|
public bool AutoCreateSaveData { get; private set; }
|
||||||
|
|
||||||
|
public Result SetCurrentProcess(long processId)
|
||||||
|
{
|
||||||
|
CurrentProcess = processId;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result DisableAutoSaveDataCreation()
|
||||||
|
{
|
||||||
|
AutoCreateSaveData = false;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result SetSaveDataSize(long saveDataSize, long saveDataJournalSize)
|
||||||
|
{
|
||||||
|
if (saveDataSize < 0 || saveDataJournalSize < 0)
|
||||||
|
{
|
||||||
|
return ResultFs.InvalidSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveDataSize = saveDataSize;
|
||||||
|
SaveDataJournalSize = saveDataJournalSize;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result SetSaveDataRootPath(string path)
|
||||||
|
{
|
||||||
|
// Missing permission check
|
||||||
|
|
||||||
|
if (path.Length > PathTools.MaxPathLength)
|
||||||
|
{
|
||||||
|
return ResultFs.TooLongPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveDataRootPath = path;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result OpenBisFileSystem(out IFileSystem fileSystem, string rootPath, BisPartitionId partitionId)
|
||||||
|
{
|
||||||
|
// Missing permission check, speed emulation storage type wrapper, and FileSystemInterfaceAdapter
|
||||||
|
|
||||||
|
return FsProxyCore.OpenBisFileSystem(out fileSystem, rootPath, partitionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result OpenSdCardFileSystem(out IFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
// Missing permission check, speed emulation storage type wrapper, and FileSystemInterfaceAdapter
|
||||||
|
|
||||||
|
return FsProxyCore.OpenSdCardFileSystem(out fileSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result OpenContentStorageFileSystem(out IFileSystem fileSystem, ContentStorageId storageId)
|
||||||
|
{
|
||||||
|
// Missing permission check, speed emulation storage type wrapper, and FileSystemInterfaceAdapter
|
||||||
|
|
||||||
|
return FsProxyCore.OpenContentStorageFileSystem(out fileSystem, storageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
||||||
|
{
|
||||||
|
// todo: use struct instead of byte span
|
||||||
|
if (seed.Length != 0x16) return ResultFs.InvalidSize;
|
||||||
|
|
||||||
|
// Missing permission check
|
||||||
|
|
||||||
|
Result res = FsProxyCore.SetSdCardEncryptionSeed(seed);
|
||||||
|
if (res.IsFailure()) return res;
|
||||||
|
|
||||||
|
// todo: Reset save data indexer
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
85
src/LibHac/FsService/FileSystemProxyCore.cs
Normal file
85
src/LibHac/FsService/FileSystemProxyCore.cs
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
using System;
|
||||||
|
using LibHac.Fs;
|
||||||
|
using LibHac.FsService.Creators;
|
||||||
|
|
||||||
|
namespace LibHac.FsService
|
||||||
|
{
|
||||||
|
public class FileSystemProxyCore
|
||||||
|
{
|
||||||
|
private FileSystemCreators FsCreators { get; }
|
||||||
|
private byte[] SdEncryptionSeed { get; } = new byte[0x10];
|
||||||
|
|
||||||
|
private const string NintendoDirectoryName = "Nintendo";
|
||||||
|
private const string ContentDirectoryName = "Contents";
|
||||||
|
|
||||||
|
public FileSystemProxyCore(FileSystemCreators fsCreators)
|
||||||
|
{
|
||||||
|
FsCreators = fsCreators;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result OpenBisFileSystem(out IFileSystem fileSystem, string rootPath, BisPartitionId partitionId)
|
||||||
|
{
|
||||||
|
return FsCreators.BuiltInStorageFileSystemCreator.Create(out fileSystem, rootPath, partitionId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result OpenSdCardFileSystem(out IFileSystem fileSystem)
|
||||||
|
{
|
||||||
|
return FsCreators.SdFileSystemCreator.Create(out fileSystem);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result OpenContentStorageFileSystem(out IFileSystem fileSystem, ContentStorageId storageId)
|
||||||
|
{
|
||||||
|
fileSystem = default;
|
||||||
|
|
||||||
|
string contentDirPath = default;
|
||||||
|
IFileSystem baseFileSystem = default;
|
||||||
|
bool isEncrypted = false;
|
||||||
|
Result baseFsResult;
|
||||||
|
|
||||||
|
switch (storageId)
|
||||||
|
{
|
||||||
|
case ContentStorageId.System:
|
||||||
|
baseFsResult = OpenBisFileSystem(out baseFileSystem, string.Empty, BisPartitionId.System);
|
||||||
|
contentDirPath = $"/{ContentDirectoryName}";
|
||||||
|
break;
|
||||||
|
case ContentStorageId.User:
|
||||||
|
baseFsResult = OpenBisFileSystem(out baseFileSystem, string.Empty, BisPartitionId.User);
|
||||||
|
contentDirPath = $"/{ContentDirectoryName}";
|
||||||
|
break;
|
||||||
|
case ContentStorageId.SdCard:
|
||||||
|
baseFsResult = OpenSdCardFileSystem(out baseFileSystem);
|
||||||
|
contentDirPath = $"/{NintendoDirectoryName}/{ContentDirectoryName}";
|
||||||
|
isEncrypted = true;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
baseFsResult = ResultFs.InvalidArgument;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseFsResult.IsFailure()) return baseFsResult;
|
||||||
|
|
||||||
|
baseFileSystem.EnsureDirectoryExists(contentDirPath);
|
||||||
|
|
||||||
|
Result subFsResult = FsCreators.SubDirectoryFileSystemCreator.Create(out IFileSystem subDirFileSystem,
|
||||||
|
baseFileSystem, contentDirPath);
|
||||||
|
if (subFsResult.IsFailure()) return subFsResult;
|
||||||
|
|
||||||
|
if (!isEncrypted)
|
||||||
|
{
|
||||||
|
fileSystem = subDirFileSystem;
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FsCreators.EncryptedFileSystemCreator.Create(out fileSystem, subDirFileSystem,
|
||||||
|
EncryptedFsKeyId.Content, SdEncryptionSeed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
||||||
|
{
|
||||||
|
seed.CopyTo(SdEncryptionSeed);
|
||||||
|
FsCreators.SaveDataFileSystemCreator.SetSdCardEncryptionSeed(seed);
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
6
src/LibHac/FsService/FileSystemService.cs
Normal file
6
src/LibHac/FsService/FileSystemService.cs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
namespace LibHac.FsService
|
||||||
|
{
|
||||||
|
public class FileSystemService
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue