From bf8b975fa6ddadf96ff92958b0f501ded6a2c36a Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Wed, 23 Oct 2019 17:12:24 -0500 Subject: [PATCH] Implement more OpenSaveDataInfoReader commands --- src/LibHac/Fs/FsEnums.cs | 2 +- src/LibHac/Fs/ResultFs.cs | 2 +- src/LibHac/Fs/Shim/SaveDataManagement.cs | 24 ++++++++++++ src/LibHac/FsService/FileSystemProxy.cs | 47 ++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index b79a2a79..a6714b59 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -89,7 +89,7 @@ namespace LibHac.Fs Creating = 1, State2 = 2, MarkedForDeletion = 3, - State4 = 4, + Extending = 4, } public enum ImageDirectoryId diff --git a/src/LibHac/Fs/ResultFs.cs b/src/LibHac/Fs/ResultFs.cs index d2381684..e98f7151 100644 --- a/src/LibHac/Fs/ResultFs.cs +++ b/src/LibHac/Fs/ResultFs.cs @@ -139,6 +139,6 @@ public static Result SubStorageNotInitialized => new Result(ModuleFs, 6902); public static Result MountNameNotFound => new Result(ModuleFs, 6905); - public static Result Result6906 => new Result(ModuleFs, 6906); + public static Result SaveDataIsExtending => new Result(ModuleFs, 6906); } } diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 12aca8b2..08450ecf 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -219,6 +219,30 @@ namespace LibHac.Fs.Shim return result; } + public static Result OpenSaveDataIterator(this FileSystemClient fs, out SaveDataIterator iterator, SaveDataSpaceId spaceId, ref SaveDataFilter filter) + { + var tempIterator = new SaveDataIterator(); + SaveDataFilter tempFilter = filter; + + Result result = fs.RunOperationWithAccessLog(LocalAccessLogMode.System, + () => + { + IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + + Result rc = fsProxy.OpenSaveDataInfoReaderWithFilter(out ISaveDataInfoReader reader, spaceId, ref tempFilter); + if (rc.IsFailure()) return rc; + + tempIterator = new SaveDataIterator(fs, reader); + + return Result.Success; + }, + () => $", savedataspaceid: {spaceId}"); + + iterator = result.IsSuccess() ? tempIterator : default; + + return result; + } + public static Result DisableAutoSaveDataCreation(this FileSystemClient fsClient) { IFileSystemProxy fsProxy = fsClient.GetFileSystemProxyServiceObject(); diff --git a/src/LibHac/FsService/FileSystemProxy.cs b/src/LibHac/FsService/FileSystemProxy.cs index b4a59cea..8dd1d19e 100644 --- a/src/LibHac/FsService/FileSystemProxy.cs +++ b/src/LibHac/FsService/FileSystemProxy.cs @@ -494,8 +494,8 @@ namespace LibHac.FsService if (indexerValue.SpaceId != indexerSpaceId) return ResultFs.TargetNotFound.Log(); - if (indexerValue.State == SaveDataState.State4) - return ResultFs.Result6906.Log(); + if (indexerValue.State == SaveDataState.Extending) + return ResultFs.SaveDataIsExtending.Log(); saveDataId = indexerValue.SaveDataId; } @@ -703,7 +703,23 @@ namespace LibHac.FsService public Result OpenSaveDataInfoReader(out ISaveDataInfoReader infoReader) { - throw new NotImplementedException(); + infoReader = default; + + // Missing permission check + + SaveDataIndexerReader indexReader = default; + + try + { + Result rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out indexReader, SaveDataSpaceId.System); + if (rc.IsFailure()) return rc; + + return indexReader.Indexer.OpenSaveDataInfoReader(out infoReader); + } + finally + { + indexReader.Dispose(); + } } public Result OpenSaveDataInfoReaderBySaveDataSpaceId(out ISaveDataInfoReader infoReader, SaveDataSpaceId spaceId) @@ -741,7 +757,30 @@ namespace LibHac.FsService public Result OpenSaveDataInfoReaderWithFilter(out ISaveDataInfoReader infoReader, SaveDataSpaceId spaceId, ref SaveDataFilter filter) { - throw new NotImplementedException(); + infoReader = default; + + // Missing permission check + + SaveDataIndexerReader indexReader = default; + + try + { + Result rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out indexReader, spaceId); + if (rc.IsFailure()) return rc; + + rc = indexReader.Indexer.OpenSaveDataInfoReader(out ISaveDataInfoReader baseInfoReader); + if (rc.IsFailure()) return rc; + + var filterInternal = new SaveDataFilterInternal(ref filter, spaceId); + + infoReader = new SaveDataInfoFilterReader(baseInfoReader, ref filterInternal); + + return Result.Success; + } + finally + { + indexReader.Dispose(); + } } public Result FindSaveDataWithFilter(out long count, Span saveDataInfoBuffer, SaveDataSpaceId spaceId,