mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Modify ISaveDataFileSystemCreator
This commit is contained in:
parent
649c72e5e6
commit
25b94292b3
3 changed files with 39 additions and 25 deletions
|
@ -9,11 +9,11 @@ namespace LibHac.FsSrv.FsCreator
|
|||
{
|
||||
Result CreateFile(out IFile file, IFileSystem sourceFileSystem, ulong saveDataId, OpenMode openMode);
|
||||
|
||||
Result Create(out IFileSystem fileSystem,
|
||||
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor, IFileSystem sourceFileSystem,
|
||||
ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac, SaveDataType type,
|
||||
ISaveDataCommitTimeStampGetter timeStampGetter);
|
||||
Result Create(out ReferenceCountedDisposable<IFileSystem> fileSystem,
|
||||
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor,
|
||||
ReferenceCountedDisposable<IFileSystem> sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData,
|
||||
bool useDeviceUniqueMac, SaveDataType type, ISaveDataCommitTimeStampGetter timeStampGetter);
|
||||
|
||||
void SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -28,16 +28,16 @@ namespace LibHac.FsSrv.FsCreator
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Result Create(out IFileSystem fileSystem,
|
||||
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor, IFileSystem sourceFileSystem,
|
||||
ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac, SaveDataType type,
|
||||
ISaveDataCommitTimeStampGetter timeStampGetter)
|
||||
public Result Create(out ReferenceCountedDisposable<IFileSystem> fileSystem,
|
||||
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor,
|
||||
ReferenceCountedDisposable<IFileSystem> sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData,
|
||||
bool useDeviceUniqueMac, SaveDataType type, ISaveDataCommitTimeStampGetter timeStampGetter)
|
||||
{
|
||||
UnsafeHelpers.SkipParamInit(out fileSystem, out extraDataAccessor);
|
||||
|
||||
var saveDataPath = $"/{saveDataId:x16}".ToU8String();
|
||||
|
||||
Result rc = sourceFileSystem.GetEntryType(out DirectoryEntryType entryType, saveDataPath);
|
||||
Result rc = sourceFileSystem.Target.GetEntryType(out DirectoryEntryType entryType, saveDataPath);
|
||||
if (rc.IsFailure())
|
||||
{
|
||||
return ResultFs.PathNotFound.Includes(rc) ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
|
||||
|
@ -48,30 +48,43 @@ namespace LibHac.FsSrv.FsCreator
|
|||
case DirectoryEntryType.Directory:
|
||||
if (!allowDirectorySaveData) return ResultFs.InvalidSaveDataEntryType.Log();
|
||||
|
||||
rc = SubdirectoryFileSystem.CreateNew(out SubdirectoryFileSystem subDirFs, sourceFileSystem,
|
||||
saveDataPath);
|
||||
if (rc.IsFailure()) return rc;
|
||||
var subDirFs = new SubdirectoryFileSystem(ref sourceFileSystem);
|
||||
|
||||
rc = subDirFs.Initialize(saveDataPath);
|
||||
if (rc.IsFailure())
|
||||
{
|
||||
subDirFs.Dispose();
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool isPersistentSaveData = type != SaveDataType.Temporary;
|
||||
bool isUserSaveData = type == SaveDataType.Account || type == SaveDataType.Device;
|
||||
|
||||
rc = DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, subDirFs,
|
||||
isPersistentSaveData, isUserSaveData, true);
|
||||
timeStampGetter, _randomGenerator, isPersistentSaveData, isUserSaveData, true, null);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
fileSystem = saveFs;
|
||||
ReferenceCountedDisposable<DirectorySaveDataFileSystem> sharedSaveFs = null;
|
||||
try
|
||||
{
|
||||
sharedSaveFs = new ReferenceCountedDisposable<DirectorySaveDataFileSystem>(saveFs);
|
||||
fileSystem = sharedSaveFs.AddReference<IFileSystem>();
|
||||
extraDataAccessor = sharedSaveFs.AddReference<ISaveDataExtraDataAccessor>();
|
||||
|
||||
// Todo: Dummy ISaveDataExtraDataAccessor
|
||||
|
||||
return Result.Success;
|
||||
return Result.Success;
|
||||
}
|
||||
finally
|
||||
{
|
||||
sharedSaveFs?.Dispose();
|
||||
}
|
||||
|
||||
case DirectoryEntryType.File:
|
||||
rc = sourceFileSystem.OpenFile(out IFile saveDataFile, saveDataPath, OpenMode.ReadWrite);
|
||||
rc = sourceFileSystem.Target.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);
|
||||
fileSystem = new ReferenceCountedDisposable<IFileSystem>(new SaveDataFileSystem(_keySet,
|
||||
saveDataStorage, IntegrityCheckLevel.ErrorOnInvalid, false));
|
||||
|
||||
// Todo: ISaveDataExtraDataAccessor
|
||||
|
||||
|
|
|
@ -146,18 +146,18 @@ namespace LibHac.FsSrv
|
|||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||
if (saveDataFs is null)
|
||||
{
|
||||
ReferenceCountedDisposable<IFileSystem> saveFs = null;
|
||||
ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor = null;
|
||||
try
|
||||
{
|
||||
// Todo: Update ISaveDataFileSystemCreator
|
||||
bool useDeviceUniqueMac = IsDeviceUniqueMac(spaceId);
|
||||
|
||||
rc = _config.SaveFsCreator.Create(out IFileSystem saveFs,
|
||||
out extraDataAccessor, saveDirectoryFs.Target, saveDataId,
|
||||
allowDirectorySaveData, useDeviceUniqueMac, type, _timeStampGetter);
|
||||
rc = _config.SaveFsCreator.Create(out saveFs, out extraDataAccessor, saveDirectoryFs,
|
||||
saveDataId, allowDirectorySaveData, useDeviceUniqueMac, type, _timeStampGetter);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
saveDataFs = new ReferenceCountedDisposable<IFileSystem>(saveFs);
|
||||
saveDataFs = Shared.Move(ref saveFs);
|
||||
|
||||
if (cacheExtraData)
|
||||
{
|
||||
|
@ -166,6 +166,7 @@ namespace LibHac.FsSrv
|
|||
}
|
||||
finally
|
||||
{
|
||||
saveFs?.Dispose();
|
||||
extraDataAccessor?.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue