From 526485c7201a43f7ba73e8998064488fe0156d98 Mon Sep 17 00:00:00 2001 From: morkt Date: Wed, 15 Feb 2017 02:26:31 +0400 Subject: [PATCH] (GetSerializedSchemeVersion): moved header reading to separate method. --- GameRes/FormatCatalog.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/GameRes/FormatCatalog.cs b/GameRes/FormatCatalog.cs index ed55d2c4..6b674b74 100644 --- a/GameRes/FormatCatalog.cs +++ b/GameRes/FormatCatalog.cs @@ -254,15 +254,9 @@ namespace GameRes public void DeserializeScheme (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"); - int version = reader.ReadInt32(); - if (version <= CurrentSchemeVersion) - return; - } + int version = GetSerializedSchemeVersion (input); + if (version <= CurrentSchemeVersion) + return; using (var zs = new ZLibStream (input, CompressionMode.Decompress, true)) { var bin = new BinaryFormatter(); @@ -307,6 +301,17 @@ namespace GameRes using (var zs = new ZLibStream (output, CompressionMode.Compress, true)) 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]