public Result OpenSaveDataInfoReaderWithFilter(out ISaveDataInfoReader infoReader, SaveDataSpaceId spaceId, ref SaveDataFilter filter) { 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(); } }
private Result GetSaveDataInfo(out SaveDataInfo info, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute) { info = default; SaveDataIndexerReader reader = default; try { Result rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, spaceId); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Get(out SaveDataIndexerValue value, ref attribute); if (rc.IsFailure()) { return(rc); } SaveDataIndexer.GetSaveDataInfo(out info, ref attribute, ref value); return(Result.Success); } finally { reader.Dispose(); } }
private Result DeleteSaveDataFileSystemBySaveDataSpaceIdImpl(SaveDataSpaceId spaceId, ulong saveDataId) { if (saveDataId != FileSystemServer.SaveIndexerId) { SaveDataIndexerReader reader = default; try { Result rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, spaceId); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.GetBySaveDataId(out SaveDataIndexerValue value, saveDataId); if (rc.IsFailure()) { return(rc); } if (value.SpaceId != GetSpaceIdForIndexer(spaceId)) { return(ResultFs.TargetNotFound.Log()); } } finally { reader.Dispose(); } } return(DeleteSaveDataFileSystemImpl(spaceId, saveDataId)); }
public Result OpenSaveDataInfoReader(out ISaveDataInfoReader infoReader) { 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(); } }
private Result CreateSaveDataFileSystemImpl(ref SaveDataAttribute attribute, ref SaveDataCreationInfo creationInfo, ref SaveMetaCreateInfo metaCreateInfo, ref OptionalHashSalt hashSalt, bool something) { ulong saveDataId = 0; bool isDeleteNeeded = false; Result rc; SaveDataIndexerReader reader = default; try { if (attribute.SaveDataId == FileSystemServer.SaveIndexerId) { saveDataId = FileSystemServer.SaveIndexerId; rc = FsProxyCore.DoesSaveDataExist(out bool saveExists, creationInfo.SpaceId, saveDataId); if (rc.IsSuccess() && saveExists) { return(ResultFs.PathAlreadyExists.Log()); } isDeleteNeeded = true; } else { rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, creationInfo.SpaceId); if (rc.IsFailure()) { return(rc); } SaveDataAttribute indexerKey = attribute; if (attribute.SaveDataId != 0 && attribute.UserId == UserId.Zero) { saveDataId = attribute.SaveDataId; rc = reader.Indexer.AddSystemSaveData(ref indexerKey); } else { if (attribute.Type != SaveDataType.System && attribute.Type != SaveDataType.SystemBcat) { if (reader.Indexer.IsFull()) { return(ResultKvdb.TooLargeKeyOrDbFull.Log()); } } rc = reader.Indexer.Add(out saveDataId, ref indexerKey); } if (ResultFs.SaveDataPathAlreadyExists.Includes(rc)) { return(ResultFs.PathAlreadyExists.LogConverted(rc)); } isDeleteNeeded = true; rc = reader.Indexer.SetState(saveDataId, SaveDataState.Creating); if (rc.IsFailure()) { return(rc); } SaveDataSpaceId indexerSpaceId = GetSpaceIdForIndexer(creationInfo.SpaceId); rc = reader.Indexer.SetSpaceId(saveDataId, indexerSpaceId); if (rc.IsFailure()) { return(rc); } // todo: calculate size long size = 0; rc = reader.Indexer.SetSize(saveDataId, size); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Commit(); if (rc.IsFailure()) { return(rc); } } rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref creationInfo, SaveDataRootPath, hashSalt, false); if (rc.IsFailure()) { if (!ResultFs.PathAlreadyExists.Includes(rc)) { return(rc); } rc = DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId); if (rc.IsFailure()) { return(rc); } rc = FsProxyCore.CreateSaveDataFileSystem(saveDataId, ref attribute, ref creationInfo, SaveDataRootPath, hashSalt, false); if (rc.IsFailure()) { return(rc); } } if (metaCreateInfo.Type != SaveDataMetaType.None) { rc = FsProxyCore.CreateSaveDataMetaFile(saveDataId, creationInfo.SpaceId, metaCreateInfo.Type, metaCreateInfo.Size); if (rc.IsFailure()) { return(rc); } if (metaCreateInfo.Type == SaveDataMetaType.Thumbnail) { rc = FsProxyCore.OpenSaveDataMetaFile(out IFile metaFile, saveDataId, creationInfo.SpaceId, metaCreateInfo.Type); using (metaFile) { if (rc.IsFailure()) { return(rc); } ReadOnlySpan <byte> metaFileData = stackalloc byte[0x20]; rc = metaFile.Write(0, metaFileData, WriteOption.Flush); if (rc.IsFailure()) { return(rc); } } } } if (attribute.SaveDataId == FileSystemServer.SaveIndexerId || something) { isDeleteNeeded = false; return(Result.Success); } rc = reader.Indexer.SetState(saveDataId, SaveDataState.Normal); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Commit(); if (rc.IsFailure()) { return(rc); } isDeleteNeeded = false; return(Result.Success); } finally { // Revert changes if an error happened in the middle of creation if (isDeleteNeeded) { DeleteSaveDataFileSystemImpl2(creationInfo.SpaceId, saveDataId).IgnoreResult(); if (reader.IsInitialized && saveDataId != FileSystemServer.SaveIndexerId) { rc = reader.Indexer.GetBySaveDataId(out SaveDataIndexerValue value, saveDataId); if (rc.IsSuccess() && value.SpaceId == creationInfo.SpaceId) { reader.Indexer.Delete(saveDataId).IgnoreResult(); reader.Indexer.Commit().IgnoreResult(); } } } reader.Dispose(); } }
private Result DeleteSaveDataFileSystemImpl(SaveDataSpaceId spaceId, ulong saveDataId) { SaveDataIndexerReader reader = default; try { Result rc = FsServer.SaveDataIndexerManager.GetSaveDataIndexer(out reader, spaceId); if (rc.IsFailure()) { return(rc); } if (saveDataId == FileSystemServer.SaveIndexerId) { // missing: This save can only be deleted by the FS process itself } else { if (spaceId != SaveDataSpaceId.ProperSystem && spaceId != SaveDataSpaceId.SafeMode) { rc = reader.Indexer.GetBySaveDataId(out SaveDataIndexerValue value, saveDataId); if (rc.IsFailure()) { return(rc); } spaceId = value.SpaceId; } rc = reader.Indexer.GetKey(out SaveDataAttribute key, saveDataId); if (rc.IsFailure()) { return(rc); } if (key.Type == SaveDataType.System || key.Type == SaveDataType.SystemBcat) { // Check if permissions allow deleting system save data } else { // Check if permissions allow deleting save data } rc = reader.Indexer.SetState(saveDataId, SaveDataState.Creating); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Commit(); if (rc.IsFailure()) { return(rc); } } rc = DeleteSaveDataFileSystemImpl2(spaceId, saveDataId); if (rc.IsFailure()) { return(rc); } if (saveDataId != FileSystemServer.SaveIndexerId) { rc = reader.Indexer.Delete(saveDataId); if (rc.IsFailure()) { return(rc); } rc = reader.Indexer.Commit(); if (rc.IsFailure()) { return(rc); } } return(Result.Success); } finally { reader.Dispose(); } }