Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class savemagic//<3 this format, only thing is they should store the name length
- {
- public savemagic Create(IO.IO IO)
- {
- savemagic Save = new savemagic();
- Save.IO = IO;
- Save.Write();
- return Save;
- }
- #region Init
- public savemagic(IO.IO _IO) { IO = _IO; Read(); }
- public savemagic(System.String FilePath) { IO = new IO.IO(FilePath, System.IO.FileMode.Open, true); Read(); }
- internal savemagic()
- {
- Properties = new System.Collections.Generic.Dictionary<System.String, Property>();
- }
- #endregion
- #region vars
- public IO.IO IO;
- public System.Collections.Generic.Dictionary<System.String, Property> Properties { get; set; }
- #endregion
- #region voids
- public void Read()
- {
- IO.BaseStream.Position = 0;
- if (IO.Reader.ReadInt32() != 825458603)
- {
- IO.BaseStream.Close();
- throw new InvalidMagic(new System.Exception("Invalid FileMagic"));
- }
- System.Int32 Count = IO.Reader.ReadInt32();
- Properties = new System.Collections.Generic.Dictionary<System.String, Property>();
- for (System.Int32 PropertyIndex = 0; PropertyIndex < Count; PropertyIndex++)
- {
- Property Property = new Property();
- Property.Name = IO.Reader.ReadASCIIString();
- Property.Flags = IO.Reader.ReadInt32();
- Property.Data = IO.Reader.ReadBytes(IO.Reader.ReadInt32());
- Properties.Add(Property.Name, Property);
- }
- }
- public void Write()
- {
- IO.BaseStream.Position = 0;
- IO.Writer.WriteInt32(825458603);
- IO.Writer.WriteInt32(Properties.Count);
- foreach (System.Collections.Generic.KeyValuePair<System.String, Property> Property in Properties)
- {
- IO.Writer.WriteASCIIString(Property.Value.Name + "\0");
- IO.Writer.WriteInt32(Property.Value.Flags);
- IO.Writer.WriteInt32(Property.Value.Data.Length);
- IO.Writer.WriteBytes(Property.Value.Data);
- }
- IO.BaseStream.SetLength(IO.BaseStream.Position);
- }
- #endregion
- public class InvalidMagic : System.Exception
- {
- public InvalidMagic(System.Exception Inner) : base("Invalid FileMagic", Inner) { }
- }
- }
- public class Property
- {
- public System.String Name { get; set; }
- public System.Int32 Flags { get; set; }//?
- public System.Byte[] Data { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment