mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2025-02-09 13:14:46 +01:00
80 lines
2.9 KiB
C#
80 lines
2.9 KiB
C#
using System;
|
|
using LibHac.Common;
|
|
using LibHac.Fs;
|
|
using LibHac.FsSystem;
|
|
using LibHac.FsSystem.Save;
|
|
|
|
namespace LibHac.FsService.Creators
|
|
{
|
|
public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
|
|
{
|
|
private Keyset Keyset { get; }
|
|
|
|
public SaveDataFileSystemCreator(Keyset keyset)
|
|
{
|
|
Keyset = keyset;
|
|
}
|
|
|
|
public Result CreateFile(out IFile file, IFileSystem sourceFileSystem, ulong saveDataId, OpenMode openMode)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Result Create(out IFileSystem fileSystem, out ISaveDataExtraDataAccessor extraDataAccessor,
|
|
IFileSystem sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac,
|
|
SaveDataType type, ITimeStampGenerator timeStampGenerator)
|
|
{
|
|
fileSystem = default;
|
|
extraDataAccessor = default;
|
|
|
|
string saveDataPath = $"/{saveDataId:x16}";
|
|
|
|
Result rc = sourceFileSystem.GetEntryType(out DirectoryEntryType entryType, saveDataPath);
|
|
if (rc.IsFailure())
|
|
{
|
|
return ResultFs.PathNotFound.Includes(rc) ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
|
|
}
|
|
|
|
switch (entryType)
|
|
{
|
|
case DirectoryEntryType.Directory:
|
|
// Actual FS does this check
|
|
// if (!allowDirectorySaveData) return ResultFs.InvalidSaveDataEntryType.Log();
|
|
|
|
rc = SubdirectoryFileSystem.CreateNew(out SubdirectoryFileSystem subDirFs, sourceFileSystem, saveDataPath.ToU8String());
|
|
if (rc.IsFailure()) return rc;
|
|
|
|
bool isPersistentSaveData = type != SaveDataType.Temporary;
|
|
bool isUserSaveData = type == SaveDataType.Account || type == SaveDataType.Device;
|
|
|
|
rc = DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, subDirFs, isPersistentSaveData, isUserSaveData);
|
|
if (rc.IsFailure()) return rc;
|
|
|
|
fileSystem = saveFs;
|
|
|
|
// Todo: Dummy ISaveDataExtraDataAccessor
|
|
|
|
return Result.Success;
|
|
|
|
case DirectoryEntryType.File:
|
|
rc = sourceFileSystem.OpenFile(out IFile saveDataFile, saveDataPath, OpenMode.ReadWrite);
|
|
if (rc.IsFailure()) return rc;
|
|
|
|
var saveDataStorage = new DisposingFileStorage(saveDataFile);
|
|
fileSystem = new SaveDataFileSystem(Keyset, saveDataStorage, IntegrityCheckLevel.ErrorOnInvalid, false);
|
|
|
|
// Todo: ISaveDataExtraDataAccessor
|
|
|
|
return Result.Success;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
|
|
public void SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
}
|