mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-25 20:34:13 +08:00
moved serialization code to GameRes.
This commit is contained in:
parent
9bef74d620
commit
7f74a3cf7d
@ -80,11 +80,11 @@ namespace GARbro.GUI
|
|||||||
if (string.IsNullOrEmpty (InitPath))
|
if (string.IsNullOrEmpty (InitPath))
|
||||||
InitPath = Directory.GetCurrentDirectory();
|
InitPath = Directory.GetCurrentDirectory();
|
||||||
|
|
||||||
string scheme_file = Path.Combine (exe_dir, "Formats.dat");
|
string scheme_file = Path.Combine (FormatCatalog.Instance.DataDirectory, "Formats.dat");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var file = File.OpenRead (scheme_file))
|
using (var file = File.OpenRead (scheme_file))
|
||||||
DeserializeScheme (file);
|
FormatCatalog.Instance.DeserializeScheme (file);
|
||||||
}
|
}
|
||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
@ -117,19 +117,5 @@ namespace GARbro.GUI
|
|||||||
if (Settings.Default.winState == System.Windows.WindowState.Minimized)
|
if (Settings.Default.winState == System.Windows.WindowState.Minimized)
|
||||||
Settings.Default.winState = System.Windows.WindowState.Normal;
|
Settings.Default.winState = System.Windows.WindowState.Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeserializeScheme (Stream file)
|
|
||||||
{
|
|
||||||
using (var reader = new BinaryReader (file))
|
|
||||||
{
|
|
||||||
var scheme_id = FormatCatalog.Instance.SchemeID;
|
|
||||||
var header = reader.ReadChars (scheme_id.Length);
|
|
||||||
if (!header.SequenceEqual (scheme_id))
|
|
||||||
throw new FormatException ("Invalid serialization file");
|
|
||||||
int version = reader.ReadInt32();
|
|
||||||
using (var zs = new ZLibStream (file, CompressionMode.Decompress))
|
|
||||||
FormatCatalog.Instance.DeserializeScheme (zs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using GameRes.Collections;
|
using GameRes.Collections;
|
||||||
using System.Runtime.Serialization.Formatters.Binary;
|
using System.Runtime.Serialization.Formatters.Binary;
|
||||||
|
using GameRes.Compression;
|
||||||
|
|
||||||
namespace GameRes
|
namespace GameRes
|
||||||
{
|
{
|
||||||
@ -203,19 +204,28 @@ namespace GameRes
|
|||||||
|
|
||||||
public void DeserializeScheme (Stream input)
|
public void DeserializeScheme (Stream input)
|
||||||
{
|
{
|
||||||
var bin = new BinaryFormatter();
|
using (var reader = new BinaryReader (input, System.Text.Encoding.UTF8, true))
|
||||||
var db = (SchemeDataBase)bin.Deserialize (input);
|
|
||||||
if (db.Version <= CurrentSchemeVersion)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var format in Formats)
|
|
||||||
{
|
{
|
||||||
ResourceScheme scheme;
|
var header = reader.ReadChars (SchemeID.Length);
|
||||||
if (!db.SchemeMap.TryGetValue (format.Tag, out scheme))
|
if (!header.SequenceEqual (SchemeID))
|
||||||
continue;
|
throw new FormatException ("Invalid serialization file");
|
||||||
format.Scheme = scheme;
|
int version = reader.ReadInt32();
|
||||||
|
if (version <= CurrentSchemeVersion)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
using (var zs = new ZLibStream (input, CompressionMode.Decompress))
|
||||||
|
{
|
||||||
|
var bin = new BinaryFormatter();
|
||||||
|
var db = (SchemeDataBase)bin.Deserialize (zs);
|
||||||
|
|
||||||
|
foreach (var format in Formats)
|
||||||
|
{
|
||||||
|
ResourceScheme scheme;
|
||||||
|
if (db.SchemeMap.TryGetValue (format.Tag, out scheme))
|
||||||
|
format.Scheme = scheme;
|
||||||
|
}
|
||||||
|
CurrentSchemeVersion = db.Version;
|
||||||
}
|
}
|
||||||
CurrentSchemeVersion = db.Version;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SerializeScheme (Stream output)
|
public void SerializeScheme (Stream output)
|
||||||
@ -230,8 +240,20 @@ namespace GameRes
|
|||||||
if (null != scheme)
|
if (null != scheme)
|
||||||
db.SchemeMap[format.Tag] = scheme;
|
db.SchemeMap[format.Tag] = scheme;
|
||||||
}
|
}
|
||||||
var bin = new BinaryFormatter();
|
SerializeScheme (output, db);
|
||||||
bin.Serialize (output, db);
|
}
|
||||||
|
|
||||||
|
public void SerializeScheme (Stream output, SchemeDataBase db)
|
||||||
|
{
|
||||||
|
using (var writer = new BinaryWriter (output))
|
||||||
|
{
|
||||||
|
writer.Write (SchemeID.ToCharArray());
|
||||||
|
writer.Write (db.Version);
|
||||||
|
writer.Flush();
|
||||||
|
var bin = new BinaryFormatter();
|
||||||
|
using (var zs = new ZLibStream (output, CompressionMode.Compress))
|
||||||
|
bin.Serialize (zs, db);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user