(GetSerializedSchemeVersion): moved header reading to separate method.

This commit is contained in:
morkt 2017-02-15 02:26:31 +04:00
parent 653ee4685d
commit 526485c720

View File

@ -254,15 +254,9 @@ namespace GameRes
public void DeserializeScheme (Stream input) public void DeserializeScheme (Stream input)
{ {
using (var reader = new BinaryReader (input, System.Text.Encoding.UTF8, true)) int version = GetSerializedSchemeVersion (input);
{ if (version <= CurrentSchemeVersion)
var header = reader.ReadChars (SchemeID.Length); return;
if (!header.SequenceEqual (SchemeID))
throw new FormatException ("Invalid serialization file");
int version = reader.ReadInt32();
if (version <= CurrentSchemeVersion)
return;
}
using (var zs = new ZLibStream (input, CompressionMode.Decompress, true)) using (var zs = new ZLibStream (input, CompressionMode.Decompress, true))
{ {
var bin = new BinaryFormatter(); var bin = new BinaryFormatter();
@ -307,6 +301,17 @@ namespace GameRes
using (var zs = new ZLibStream (output, CompressionMode.Compress, true)) using (var zs = new ZLibStream (output, CompressionMode.Compress, true))
bin.Serialize (zs, db); bin.Serialize (zs, db);
} }
public int GetSerializedSchemeVersion (Stream input)
{
using (var reader = new BinaryReader (input, System.Text.Encoding.UTF8, true))
{
var header = reader.ReadChars (SchemeID.Length);
if (!header.SequenceEqual (SchemeID))
throw new FormatException ("Invalid serialization file");
return reader.ReadInt32();
}
}
} }
[Serializable] [Serializable]