mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Fill out cache storage functions in SaveDataFileSystemService
This commit is contained in:
parent
f67d51cb37
commit
86be94e9b5
2 changed files with 85 additions and 6 deletions
|
@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
|
||||||
using LibHac.Common;
|
using LibHac.Common;
|
||||||
using LibHac.Diag;
|
using LibHac.Diag;
|
||||||
using LibHac.Fs;
|
using LibHac.Fs;
|
||||||
|
using LibHac.Fs.Shim;
|
||||||
using LibHac.FsSrv.Impl;
|
using LibHac.FsSrv.Impl;
|
||||||
using LibHac.FsSrv.Sf;
|
using LibHac.FsSrv.Sf;
|
||||||
using LibHac.FsSystem;
|
using LibHac.FsSystem;
|
||||||
|
@ -15,6 +16,7 @@ using IFileSystemSf = LibHac.FsSrv.Sf.IFileSystem;
|
||||||
using IFile = LibHac.Fs.Fsa.IFile;
|
using IFile = LibHac.Fs.Fsa.IFile;
|
||||||
using IFileSf = LibHac.FsSrv.Sf.IFile;
|
using IFileSf = LibHac.FsSrv.Sf.IFile;
|
||||||
using PathNormalizer = LibHac.FsSrv.Impl.PathNormalizer;
|
using PathNormalizer = LibHac.FsSrv.Impl.PathNormalizer;
|
||||||
|
using SaveData = LibHac.Fs.SaveData;
|
||||||
using Utility = LibHac.FsSystem.Utility;
|
using Utility = LibHac.FsSystem.Utility;
|
||||||
|
|
||||||
namespace LibHac.FsSrv
|
namespace LibHac.FsSrv
|
||||||
|
@ -1397,7 +1399,6 @@ namespace LibHac.FsSrv
|
||||||
{
|
{
|
||||||
return filterReader.Read(out count, new OutBuffer(SpanHelpers.AsByteSpan(ref info)));
|
return filterReader.Read(out count, new OutBuffer(SpanHelpers.AsByteSpan(ref info)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -1488,7 +1489,44 @@ namespace LibHac.FsSrv
|
||||||
private Result OpenSaveDataInfoReaderOnlyCacheStorage(
|
private Result OpenSaveDataInfoReaderOnlyCacheStorage(
|
||||||
out ReferenceCountedDisposable<ISaveDataInfoReader> infoReader, SaveDataSpaceId spaceId)
|
out ReferenceCountedDisposable<ISaveDataInfoReader> infoReader, SaveDataSpaceId spaceId)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
UnsafeHelpers.SkipParamInit(out infoReader);
|
||||||
|
|
||||||
|
using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard);
|
||||||
|
|
||||||
|
Result rc = GetProgramInfo(out ProgramInfo programInfo);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
if (spaceId != SaveDataSpaceId.SdCache && spaceId != SaveDataSpaceId.User)
|
||||||
|
return ResultFs.InvalidSaveDataSpaceId.Log();
|
||||||
|
|
||||||
|
SaveDataIndexerAccessor accessor = null;
|
||||||
|
ReferenceCountedDisposable<SaveDataInfoReaderImpl> reader = null;
|
||||||
|
SaveDataInfoFilterReader filterReader = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
rc = OpenSaveDataIndexerAccessor(out accessor, spaceId);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
rc = accessor.Indexer.OpenSaveDataInfoReader(out reader);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
ProgramId resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId);
|
||||||
|
|
||||||
|
var filter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), resolvedProgramId,
|
||||||
|
SaveDataType.Cache, userId: default, saveDataId: default, index: default,
|
||||||
|
(int)SaveDataRank.Primary);
|
||||||
|
|
||||||
|
filterReader = new SaveDataInfoFilterReader(reader, in filter);
|
||||||
|
|
||||||
|
infoReader = new ReferenceCountedDisposable<ISaveDataInfoReader>(filterReader);
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
accessor?.Dispose();
|
||||||
|
reader?.Dispose();
|
||||||
|
filterReader?.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result OpenSaveDataMetaFileRaw(out ReferenceCountedDisposable<IFile> file, SaveDataSpaceId spaceId,
|
private Result OpenSaveDataMetaFileRaw(out ReferenceCountedDisposable<IFile> file, SaveDataSpaceId spaceId,
|
||||||
|
@ -1560,17 +1598,59 @@ namespace LibHac.FsSrv
|
||||||
|
|
||||||
private Result FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, ushort index)
|
private Result FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, ushort index)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
UnsafeHelpers.SkipParamInit(out saveInfo, out spaceId);
|
||||||
|
|
||||||
|
Result rc = GetCacheStorageSpaceId(out spaceId);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
rc = GetProgramInfo(out ProgramInfo programInfo);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
ProgramId resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId);
|
||||||
|
|
||||||
|
var filter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), resolvedProgramId, SaveDataType.Cache,
|
||||||
|
userId: default, saveDataId: default, index, (int)SaveDataRank.Primary);
|
||||||
|
|
||||||
|
rc = FindSaveDataWithFilterImpl(out long count, out SaveDataInfo info, spaceId, in filter);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return ResultFs.TargetNotFound.Log();
|
||||||
|
|
||||||
|
saveInfo = info;
|
||||||
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result DeleteCacheStorage(ushort index)
|
public Result DeleteCacheStorage(ushort index)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard);
|
||||||
|
|
||||||
|
Result rc = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
rc = Hos.Fs.DeleteSaveData(spaceId, saveInfo.SaveDataId);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result GetCacheStorageSize(out long usableDataSize, out long journalSize, ushort index)
|
public Result GetCacheStorageSize(out long usableDataSize, out long journalSize, ushort index)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
UnsafeHelpers.SkipParamInit(out usableDataSize, out journalSize);
|
||||||
|
|
||||||
|
using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard);
|
||||||
|
|
||||||
|
Result rc = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index);
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
rc = ServiceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId,
|
||||||
|
saveInfo.SaveDataId, saveInfo.Type, new U8Span(SaveDataRootPath.Str));
|
||||||
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
|
usableDataSize = extraData.DataSize;
|
||||||
|
journalSize = extraData.JournalSize;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result OpenSaveDataTransferManager(out ReferenceCountedDisposable<ISaveDataTransferManager> manager)
|
public Result OpenSaveDataTransferManager(out ReferenceCountedDisposable<ISaveDataTransferManager> manager)
|
||||||
|
|
|
@ -59,7 +59,6 @@ namespace LibHac.FsSrv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential, Size = 0x60)]
|
|
||||||
internal struct SaveDataInfoFilter
|
internal struct SaveDataInfoFilter
|
||||||
{
|
{
|
||||||
public Optional<SaveDataSpaceId> SpaceId;
|
public Optional<SaveDataSpaceId> SpaceId;
|
||||||
|
|
Loading…
Reference in a new issue