Exemplo n.º 1
0
        public void Parse(Stream stream)
        {
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                magic_       = new string(reader.ReadChars(3));
                version_     = reader.ReadByte();
                file_length_ = reader.ReadUInt32();
            }
            catch (Exception)
            {
                throw new Exception("NMMファイルではありません。");
            }

            data_stream_ = new MemoryStream((int)stream.Length);

            Stream zis = null;

            try
            {
                if (magic_ == "CWS")
                {
                    zis = new ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream(stream);
                }
                else if (magic_ == "FWS")
                {
                    zis = stream;
                }
                else
                {
                    throw new Exception("NMMファイルではありません。");
                }
                int    s;
                byte[] b = new byte[1024];
                while ((s = zis.Read(b, 0, b.Length)) > 0)
                {
                    data_stream_.Write(b, 0, s);
                }
            }
            finally
            {
                if (magic_ == "CWS" && zis != null)
                {
                    zis.Close();
                }
            }
            data_stream_.Seek(0, SeekOrigin.Begin);
            data_reader_ = new BinaryReader(data_stream_);

            frame_size_.Parse(data_reader_.BaseStream);
            frame_rate_  = data_reader_.ReadUInt16();
            frame_count_ = data_reader_.ReadUInt16();

            while (data_reader_.BaseStream.Position < data_reader_.BaseStream.Length)
            {
                Tags   tags = new Tags();
                ushort v    = data_reader_.ReadUInt16();
                if (v == 0)
                {
                    break;
                }
                tags.tag  = (byte)(v >> 6);
                tags.size = (uint)v & 0x3F;
                if (tags.size == 63)
                {
                    tags.size = data_reader_.ReadUInt32();
                }
                tags.position = (int)data_reader_.BaseStream.Position;
                data_reader_.BaseStream.Seek(tags.size, SeekOrigin.Current);
                tag_list_.Add(tags);
            }
        }
Exemplo n.º 2
0
 public PlaceObject(Tags tags, BinaryReader reader, int size)
 {
     tags_ = tags;
     reader.BaseStream.Seek(tags.position, SeekOrigin.Begin);
     Parse(reader);
 }
Exemplo n.º 3
0
 public Picture(Tags tags, BinaryReader reader, int size)
 {
     tags_ = tags;
     Parse(tags, reader, size);
 }