예제 #1
0
        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));
        }
예제 #2
0
        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));
        }
예제 #3
0
        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);
        }));
예제 #4
0
        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));
        }
예제 #5
0
 public void OpenStream(Stream stream)
 {
     try
     {
         save = SaveKh2.Read(stream);
         RefreshUi();
     }
     catch (NotImplementedException ex)
     {
         throw new SaveNotSupportedException(ex.Message);
     }
 }
예제 #6
0
        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();
        }
예제 #7
0
 public void WriteToStream(Stream stream) => SaveKh2.Write(stream, save);