public void TestChecksum() { var rand = new System.Random(0); var data = Enumerable.Range(0, 0x10000) .Select(x => (byte)rand.Next()) .ToArray(); Assert.Equal(1527299405U, SaveKh2.CalculateChecksum(data, data.Length, uint.MaxValue)); }
public void TestIsValid(uint header, bool expected) { var stream = new MemoryStream(4); new BinaryWriter(stream).Write(header); stream.Position = 0; Assert.Equal(expected, SaveKh2.IsValid(stream)); }
public void TestWriteBackTheSameExactFile() => File.OpenRead(FilePath).Using(stream => Helpers.AssertStream(stream, inStream => { var save = SaveKh2.Read <SaveKh2.SaveFinalMix>(inStream); var outStream = new MemoryStream(); SaveKh2.Write(outStream, save); return(outStream); }));
public void TestVersion(uint header, int version, GameVersion?expected) { var stream = new MemoryStream(4); var writer = new BinaryWriter(stream); writer.Write(header); writer.Write(version); stream.Position = 0; Assert.Equal(expected, SaveKh2.GetGameVersion(stream)); }
public void OpenStream(Stream stream) { try { save = SaveKh2.Read(stream); RefreshUi(); } catch (NotImplementedException ex) { throw new SaveNotSupportedException(ex.Message); } }
public void OpenStream(Stream stream) { switch (SaveKh2.GetGameVersion(stream)) { case GameVersion.Japanese: throw new SaveNotSupportedException("Japanese save file is not yet supported."); case GameVersion.American: throw new SaveNotSupportedException("American or European save file is not yet supported."); case GameVersion.FinalMix: save = SaveKh2.Read <SaveKh2.SaveFinalMix>(stream); break; case null: throw new SaveNotSupportedException("An invalid version has been specified."); default: throw new SaveNotSupportedException("The version has been recognized but it is not supported."); } RefreshUi(); }
public void WriteToStream(Stream stream) => SaveKh2.Write(stream, save);