private GraphMeta DeserializeMeta (ZipEntry entry) { if ( entry == null ) throw new Exception ("No metadata found in serialized data."); #if !ASTAR_NO_JSON string s = GetString (entry); var reader = new JsonReader(s,readerSettings); return (GraphMeta)reader.Deserialize(typeof(GraphMeta)); #else var meta = new GraphMeta(); var mem = new System.IO.MemoryStream(); entry.Extract (mem); mem.Position = 0; var reader = new System.IO.BinaryReader(mem); if ( reader.ReadString() != "A*" ) throw new System.Exception ("Invalid magic number in saved data"); int major = reader.ReadInt32 (); int minor = reader.ReadInt32 (); int build = reader.ReadInt32 (); int revision = reader.ReadInt32 (); // Required because when saving a version with a field not set, it will save it as -1 // and then the Version constructor will throw an exception (which we do not want) if ( major < 0 ) meta.version = new Version (0, 0); else if ( minor < 0 ) meta.version = new Version (major, 0); else if ( build < 0 ) meta.version = new Version (major, minor); else if ( revision < 0 ) meta.version = new Version (major, minor, build); else meta.version = new Version (major, minor, build, revision); meta.graphs = reader.ReadInt32 (); meta.guids = new string[reader.ReadInt32()]; for ( int i = 0; i < meta.guids.Length; i++ ) meta.guids[i] = reader.ReadString(); meta.typeNames = new string[reader.ReadInt32()]; for ( int i = 0; i < meta.typeNames.Length; i++ ) meta.typeNames[i] = reader.ReadString(); meta.nodeCounts = new int[reader.ReadInt32()]; for ( int i = 0; i < meta.nodeCounts.Length; i++ ) meta.nodeCounts[i] = reader.ReadInt32(); return meta; #endif }
/** Returns the data in the zip entry as a string */ private string GetString (ZipEntry entry) { var buffer = new MemoryStream(); entry.Extract(buffer); buffer.Position = 0; var reader = new StreamReader(buffer); string s = reader.ReadToEnd(); buffer.Position = 0; reader.Dispose(); return s; }
public void AddEntry ( string name, byte[] bytes ) { dict[name] = new ZipEntry (name, bytes); }
public void AddEntry(string name, byte[] bytes) { dict[name] = new ZipEntry(name, bytes); }
/** Returns a binary reader for the data in the zip entry */ private static BinaryReader GetBinaryReader (ZipEntry entry) { var mem = new System.IO.MemoryStream(); entry.Extract(mem); mem.Position = 0; return new System.IO.BinaryReader(mem); }
private GraphMeta DeserializeMeta (ZipEntry entry) { if ( entry == null ) throw new System.Exception ("No metadata found in serialized data."); #if !ASTAR_NO_JSON string s = GetString (entry); JsonReader reader = new JsonReader(s,readerSettings); return (GraphMeta)reader.Deserialize(typeof(GraphMeta)); //JsonConvert.DeserializeObject<GraphMeta>(s,settings); #else var meta = new GraphMeta(); var mem = new System.IO.MemoryStream(); entry.Extract (mem); mem.Position = 0; var reader = new System.IO.BinaryReader(mem); if ( reader.ReadString() != "A*" ) throw new System.Exception ("Invalid magic number in saved data"); meta.version = new Version (reader.ReadInt32 (),reader.ReadInt32 (),reader.ReadInt32 (),reader.ReadInt32 ()); meta.graphs = reader.ReadInt32 (); meta.guids = new string[reader.ReadInt32()]; for ( int i = 0; i < meta.guids.Length; i++ ) meta.guids[i] = reader.ReadString(); meta.typeNames = new string[reader.ReadInt32()]; for ( int i = 0; i < meta.typeNames.Length; i++ ) meta.typeNames[i] = reader.ReadString(); meta.nodeCounts = new int[reader.ReadInt32()]; for ( int i = 0; i < meta.nodeCounts.Length; i++ ) meta.nodeCounts[i] = reader.ReadInt32(); return meta; #endif }