Exemple #1
0
        public void Write(BinaryWriter writer)
        {
            writer.Write((short)0x0ade);
            writer.Write(MagicChars);
            writer.Write(Version);

            writer.Write(0); // Uncompressed

            writer.WriteNullTerminatedString(SID);
            writer.Write((int)Mode);
            writer.WriteNullTerminatedString(Level);
            writer.WriteNullTerminatedString(Target);

            writer.WriteNullTerminatedString(Name);
            writer.Write(Date.ToBinary());

            writer.Write(Dead);

            if (Opacity != null)
            {
                writer.Write(true);
                writer.Write(Opacity.Value);
            }
            else
            {
                writer.Write(false);
            }

            writer.Write(Frames.Count);
            writer.Write('\r');
            writer.Write('\n');
            for (int i = 0; i < Frames.Count; i++)
            {
                GhostFrame frame = this[i];
                frame.Write(writer);
            }
        }
Exemple #2
0
 internal void Change(GhostFrame frame)
 {
     Form?.RefreshViewFrame(Frames.IndexOf(frame));
 }
Exemple #3
0
        public GhostData Read(BinaryReader reader)
        {
            if (reader.ReadInt16() != 0x0ade)
            {
                return(null); // Endianness mismatch.
            }
            char[] magic = reader.ReadChars(MagicChars.Length);
            if (magic.Length != MagicChars.Length)
            {
                return(null); // Didn't read as much as we wanted to read.
            }
            for (int i = 0; i < MagicChars.Length; i++)
            {
                if (magic[i] != MagicChars[i])
                {
                    return(null); // Magic mismatch.
                }
            }

            int version = reader.ReadInt32();

            // Don't read data from the future, but try to read data from the past.
            if (version > Version)
            {
                return(null);
            }

            int compression = reader.ReadInt32();

            if (compression != 0)
            {
                return(null); // Compression not supported yet.
            }
            SID    = reader.ReadNullTerminatedString();
            Mode   = (AreaMode)reader.ReadInt32();
            Level  = reader.ReadNullTerminatedString();
            Target = reader.ReadNullTerminatedString();

            Name = reader.ReadNullTerminatedString();
            long dateBin = reader.ReadInt64();

            try {
                Date = DateTime.FromBinary(dateBin);
            } catch {
                // The date was invalid. Let's ignore it.
                Date = DateTime.UtcNow;
            }

            Dead = reader.ReadBoolean();

            Opacity = reader.ReadBoolean() ? (float?)reader.ReadSingle() : null;

            int count = reader.ReadInt32();

            reader.ReadChar(); // \r
            reader.ReadChar(); // \n
            Frames = new ObservableCollection <object>();
            Frames.CollectionChanged += _CollectionChanged;
            for (int i = 0; i < count; i++)
            {
                GhostFrame frame = new GhostFrame();
                frame.Data = this;
                frame.Read(reader);
                Frames.Add(frame);
            }

            return(this);
        }