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 CreateFile(out IFile file, IFileSystem sourceFileSystem, ulong saveDataId, OpenMode openMode);
|
||||||
|
|
||||||
Result Create(out IFileSystem fileSystem,
|
Result Create(out ReferenceCountedDisposable<IFileSystem> fileSystem,
|
||||||
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor, IFileSystem sourceFileSystem,
|
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor,
|
||||||
ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac, SaveDataType type,
|
ReferenceCountedDisposable<IFileSystem> sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData,
|
||||||
ISaveDataCommitTimeStampGetter timeStampGetter);
|
bool useDeviceUniqueMac, SaveDataType type, ISaveDataCommitTimeStampGetter timeStampGetter);
|
||||||
|
|
||||||
void SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed);
|
void SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -28,16 +28,16 @@ namespace LibHac.FsSrv.FsCreator
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result Create(out IFileSystem fileSystem,
|
public Result Create(out ReferenceCountedDisposable<IFileSystem> fileSystem,
|
||||||
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor, IFileSystem sourceFileSystem,
|
out ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor,
|
||||||
ulong saveDataId, bool allowDirectorySaveData, bool useDeviceUniqueMac, SaveDataType type,
|
ReferenceCountedDisposable<IFileSystem> sourceFileSystem, ulong saveDataId, bool allowDirectorySaveData,
|
||||||
ISaveDataCommitTimeStampGetter timeStampGetter)
|
bool useDeviceUniqueMac, SaveDataType type, ISaveDataCommitTimeStampGetter timeStampGetter)
|
||||||
{
|
{
|
||||||
UnsafeHelpers.SkipParamInit(out fileSystem, out extraDataAccessor);
|
UnsafeHelpers.SkipParamInit(out fileSystem, out extraDataAccessor);
|
||||||
|
|
||||||
var saveDataPath = $"/{saveDataId:x16}".ToU8String();
|
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())
|
if (rc.IsFailure())
|
||||||
{
|
{
|
||||||
return ResultFs.PathNotFound.Includes(rc) ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
|
return ResultFs.PathNotFound.Includes(rc) ? ResultFs.TargetNotFound.LogConverted(rc) : rc;
|
||||||
|
@ -48,30 +48,43 @@ namespace LibHac.FsSrv.FsCreator
|
||||||
case DirectoryEntryType.Directory:
|
case DirectoryEntryType.Directory:
|
||||||
if (!allowDirectorySaveData) return ResultFs.InvalidSaveDataEntryType.Log();
|
if (!allowDirectorySaveData) return ResultFs.InvalidSaveDataEntryType.Log();
|
||||||
|
|
||||||
rc = SubdirectoryFileSystem.CreateNew(out SubdirectoryFileSystem subDirFs, sourceFileSystem,
|
var subDirFs = new SubdirectoryFileSystem(ref sourceFileSystem);
|
||||||
saveDataPath);
|
|
||||||
if (rc.IsFailure()) return rc;
|
rc = subDirFs.Initialize(saveDataPath);
|
||||||
|
if (rc.IsFailure())
|
||||||
|
{
|
||||||
|
subDirFs.Dispose();
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
bool isPersistentSaveData = type != SaveDataType.Temporary;
|
bool isPersistentSaveData = type != SaveDataType.Temporary;
|
||||||
bool isUserSaveData = type == SaveDataType.Account || type == SaveDataType.Device;
|
bool isUserSaveData = type == SaveDataType.Account || type == SaveDataType.Device;
|
||||||
|
|
||||||
rc = DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, subDirFs,
|
rc = DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, subDirFs,
|
||||||
isPersistentSaveData, isUserSaveData, true);
|
timeStampGetter, _randomGenerator, isPersistentSaveData, isUserSaveData, true, null);
|
||||||
if (rc.IsFailure()) return rc;
|
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:
|
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;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
var saveDataStorage = new DisposingFileStorage(saveDataFile);
|
var saveDataStorage = new DisposingFileStorage(saveDataFile);
|
||||||
fileSystem = new SaveDataFileSystem(_keySet, saveDataStorage, IntegrityCheckLevel.ErrorOnInvalid,
|
fileSystem = new ReferenceCountedDisposable<IFileSystem>(new SaveDataFileSystem(_keySet,
|
||||||
false);
|
saveDataStorage, IntegrityCheckLevel.ErrorOnInvalid, false));
|
||||||
|
|
||||||
// Todo: ISaveDataExtraDataAccessor
|
// Todo: ISaveDataExtraDataAccessor
|
||||||
|
|
||||||
|
|
|
@ -146,18 +146,18 @@ namespace LibHac.FsSrv
|
||||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
if (saveDataFs is null)
|
if (saveDataFs is null)
|
||||||
{
|
{
|
||||||
|
ReferenceCountedDisposable<IFileSystem> saveFs = null;
|
||||||
ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor = null;
|
ReferenceCountedDisposable<ISaveDataExtraDataAccessor> extraDataAccessor = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Todo: Update ISaveDataFileSystemCreator
|
// Todo: Update ISaveDataFileSystemCreator
|
||||||
bool useDeviceUniqueMac = IsDeviceUniqueMac(spaceId);
|
bool useDeviceUniqueMac = IsDeviceUniqueMac(spaceId);
|
||||||
|
|
||||||
rc = _config.SaveFsCreator.Create(out IFileSystem saveFs,
|
rc = _config.SaveFsCreator.Create(out saveFs, out extraDataAccessor, saveDirectoryFs,
|
||||||
out extraDataAccessor, saveDirectoryFs.Target, saveDataId,
|
saveDataId, allowDirectorySaveData, useDeviceUniqueMac, type, _timeStampGetter);
|
||||||
allowDirectorySaveData, useDeviceUniqueMac, type, _timeStampGetter);
|
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
saveDataFs = new ReferenceCountedDisposable<IFileSystem>(saveFs);
|
saveDataFs = Shared.Move(ref saveFs);
|
||||||
|
|
||||||
if (cacheExtraData)
|
if (cacheExtraData)
|
||||||
{
|
{
|
||||||
|
@ -166,6 +166,7 @@ namespace LibHac.FsSrv
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
saveFs?.Dispose();
|
||||||
extraDataAccessor?.Dispose();
|
extraDataAccessor?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue