private Result CreateExtraDataForTest(IFileSystem fileSystem, U8Span path, int saveDataSize) { fileSystem.DeleteFile(path).IgnoreResult(); Result rc = fileSystem.CreateFile(path, Unsafe.SizeOf <SaveDataExtraData>()); if (rc.IsFailure()) { return(rc); } var extraData = new SaveDataExtraData(); extraData.DataSize = saveDataSize; rc = fileSystem.OpenFile(out IFile file, path, OpenMode.ReadWrite); if (rc.IsFailure()) { return(rc); } using (file) { rc = file.Write(0, SpanHelpers.AsByteSpan(ref extraData), WriteOption.Flush); if (rc.IsFailure()) { return(rc); } } return(Result.Success); }
public void Rollback_WriteExtraDataThenCloseFs_ExtraDataIsRolledBack() { var baseFs = new InMemoryFileSystem(); DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, baseFs, true, true, true) .ThrowIfFailure(); // Write extra data and close with committing var originalExtraData = new SaveDataExtraData(); originalExtraData.DataSize = 0x12345; saveFs.WriteExtraData(in originalExtraData).ThrowIfFailure(); saveFs.CommitExtraData(false).ThrowIfFailure(); saveFs.Dispose(); DirectorySaveDataFileSystem.CreateNew(out saveFs, baseFs, true, true, true).ThrowIfFailure(); // Write a new extra data and close without committing var newExtraData = new SaveDataExtraData(); newExtraData.DataSize = 0x67890; saveFs.WriteExtraData(in newExtraData).ThrowIfFailure(); saveFs.Dispose(); // Read extra data should match the first one DirectorySaveDataFileSystem.CreateNew(out saveFs, baseFs, true, true, true).ThrowIfFailure(); Assert.Success(saveFs.ReadExtraData(out SaveDataExtraData extraData)); Assert.Equal(originalExtraData, extraData); }
public void Rollback_WriteExtraDataThenRollback_ExtraDataIsRolledBack() { var baseFs = new InMemoryFileSystem(); DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, baseFs, true, true, true) .ThrowIfFailure(); var originalExtraData = new SaveDataExtraData(); originalExtraData.DataSize = 0x12345; saveFs.WriteExtraData(in originalExtraData).ThrowIfFailure(); saveFs.CommitExtraData(false).ThrowIfFailure(); saveFs.Dispose(); DirectorySaveDataFileSystem.CreateNew(out saveFs, baseFs, true, true, true).ThrowIfFailure(); var newExtraData = new SaveDataExtraData(); newExtraData.DataSize = 0x67890; saveFs.WriteExtraData(in newExtraData).ThrowIfFailure(); Assert.Success(saveFs.Rollback()); Assert.Success(saveFs.ReadExtraData(out SaveDataExtraData extraData)); Assert.Equal(originalExtraData, extraData); }
public void WriteExtraData_CanReadBackExtraData() { (IFileSystem _, DirectorySaveDataFileSystem saveFs) = CreateFileSystemInternal(); var originalExtraData = new SaveDataExtraData(); originalExtraData.DataSize = 0x12345; Assert.Success(saveFs.WriteExtraData(in originalExtraData)); Assert.Success(saveFs.ReadExtraData(out SaveDataExtraData extraData)); Assert.Equal(originalExtraData, extraData); }
public void Commit_AfterSuccessfulCommit_CanReadCommittedExtraData() { var baseFs = new InMemoryFileSystem(); DirectorySaveDataFileSystem.CreateNew(out DirectorySaveDataFileSystem saveFs, baseFs, true, true, true) .ThrowIfFailure(); var originalExtraData = new SaveDataExtraData(); originalExtraData.DataSize = 0x12345; saveFs.WriteExtraData(in originalExtraData).ThrowIfFailure(); Assert.Success(saveFs.CommitExtraData(false)); saveFs.Dispose(); DirectorySaveDataFileSystem.CreateNew(out saveFs, baseFs, true, true, true).ThrowIfFailure(); Assert.Success(saveFs.ReadExtraData(out SaveDataExtraData extraData)); Assert.Equal(originalExtraData, extraData); }
static Result RunCommit(FileSystemClient fs, CommitOption option, FileSystemAccessor fileSystem) { if ((option.Flags & (CommitOptionFlag.ClearRestoreFlag | CommitOptionFlag.SetRestoreFlag)) == 0) { return(fileSystem.Commit()); } if (option.Flags != CommitOptionFlag.ClearRestoreFlag && option.Flags != CommitOptionFlag.SetRestoreFlag) { return(ResultFs.InvalidCommitOption.Log()); } Result rc = fileSystem.GetSaveDataAttribute(out SaveDataAttribute attribute); if (rc.IsFailure()) { return(rc); } if (attribute.ProgramId == SaveData.InvalidProgramId) { attribute.ProgramId = SaveData.AutoResolveCallerProgramId; } var extraDataMask = new SaveDataExtraData(); extraDataMask.Flags = SaveDataFlags.Restore; var extraData = new SaveDataExtraData(); extraDataMask.Flags = option.Flags == CommitOptionFlag.SetRestoreFlag ? SaveDataFlags.Restore : SaveDataFlags.None; return(fs.Impl.WriteSaveDataFileSystemExtraData(SaveDataSpaceId.User, in attribute, in extraData, in extraDataMask)); }
internal static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs, out SaveDataExtraData extraData, SaveDataSpaceId spaceId, in SaveDataAttribute attribute)
internal static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs, out SaveDataExtraData extraData, SaveDataSpaceId spaceId, ulong saveDataId) { throw new NotImplementedException(); }