Exemple #1
0
        public void Read(string a_sFilename)
        {
            FileStream stream = new FileStream(a_sFilename,
                                               FileMode.Open, FileAccess.Read);

            this.reader = new BinaryFlashReader(stream);

            //Header
            //Compressed or uncompressed?
            bool bCompressed = (this.reader.ReadChar().ToString() == "C")?true:false;

            //char 2-3 is always WS:
            string sWS = new string(this.reader.ReadChars(2));

            if (sWS != "WS")
            {
                throw(new Exception("Not a Flash file"));
            }

            //Testing: I'm writing some data to an XML doc in order to see what the parser's results are
            //TODO: instead, the whole Flash data structure (after parsing) should be serializable to XML
            //I.e. a Flash->XML->Flash converter is a must later on. Or preferably XAML.
//			XmlDocument xdoc = new XmlDocument();
//			XmlNode xnode = xdoc.CreateElement("root");
//			xdoc.AppendChild(xnode);

            int Version = this.reader.ReadByte();

//			this.AddNodeAndValue(xnode, "Version", Version.ToString());

            long nFileLength = this.reader.ReadUInt32();

            //rect for the bounding rect of the whole Flash file:
            ERectangle boundingRect = this.reader.ReadRect();

//			this.AddNodeAndValue(xnode, "BoundingRect", boundingRect.ToString());

            this.FrameRate = this.reader.ReadFixed16();
            int FrameCount = this.reader.ReadUInt16();

//			this.AddNodeAndValue(xnode, "FrameRate", FrameRate.ToString());
//			this.AddNodeAndValue(xnode, "FrameCount", FrameCount.ToString());


            this.AllReadObjects = new ArrayList();
            this.Characters     = new Hashtable();
            this.Members        = new Hashtable();

            //read tag by tag until end of file:
            while (true)
            {
                Record record    = new Record(reader, this);
                Record newRecord = null;
                switch (record.Tag)
                {
                case Tags.SetBackgroundColor:
                    EH.Instance.Stage.Color = record.GetDataReader().ReadRGB();
                    break;

                case Tags.ShowFrame:
                    newRecord = record;
                    break;

                case Tags.DefineBits:
                case Tags.DefineBitsJPEG2:
                case Tags.DefineBitsJPEG3:
                case Tags.DefineBitsLossless:
                case Tags.DefineBitsLossless2:
                    if (record.Tag == Tags.DefineBits)
                    {
                        newRecord = new Shape.Image(this._jpegTables);
                    }
                    else
                    {
                        newRecord = new Shape.Image();
                    }
                    break;

                case Tags.JPEGTables:
                    if (this._jpegTables == null)
                    {
                        BinaryFlashReader subReader = record.GetDataReader();
                        this._jpegTables = subReader.ReadBytes((int)record.TagLength - 2);
                        if (subReader.ReadUInt16() != 0xd9ff)
                        {
                            throw new Exception("JPEG error");
                        }
                    }
                    break;


                case Tags.DefineFont:
                    newRecord = new Text.Font();                            //record
                    break;

                case Tags.DefineFontInfo:
                    break;

                case Tags.DefineText2:
                    newRecord = new Text.Text();                            //record
                    break;

                case Tags.DefineShape:
                case Tags.DefineShape2:
                case Tags.DefineShape3:
                case Tags.DefineShape4:
                case Tags.DefineShape5:
                    newRecord = new Shape.Shape();
                    break;

                case Tags.DefineMorphShape:
                    newRecord = new Shape.MorphShape();
                    break;

                case Tags.PlaceObject:
                case Tags.PlaceObject2:
                    newRecord = new Placement.Placement();
                    break;

                case Tags.RemoveObject:
                case Tags.RemoveObject2:
                    newRecord = new Placement.Remove();
                    break;

                case Tags.DoAction:
                case Tags.DoInitAction:
                    //newRecord = new Action.DoAnAction();
                    break;
                }

                if (newRecord != null)
                {
                    if (!newRecord.Inited)
                    {
                        newRecord.Init(record);
                    }
                    this.AllReadObjects.Add(newRecord);
                }

                if (record.Tag == Tags.End)
                {
                    break;
                }
                if (this.reader.BaseStream.Position >= nFileLength - 1)
                {
                    break;
                }
            }

            //xdoc.Save(a_sFilename+".xml");
            //zoom in:
            //this.TwipSize = 1; //20
            this._executedRecordIndex    = -1;
            this._objectByDepth          = new SortedList();
            this.CharacterIdsByDepth     = new Hashtable();
            EH.Instance.EnterFrameEvent += new EnterFrame(Instance_EnterFrameEvent);
        }
Exemple #2
0
        public void Read(string a_sFilename)
        {
            FileStream stream = new FileStream(a_sFilename,
                FileMode.Open, FileAccess.Read);
            this.reader = new BinaryFlashReader(stream);

            //Header
            //Compressed or uncompressed?
            bool bCompressed = (this.reader.ReadChar().ToString() == "C")?true:false;

            //char 2-3 is always WS:
            string sWS = new string(this.reader.ReadChars(2));
            if (sWS != "WS")
                throw(new Exception("Not a Flash file"));

            //Testing: I'm writing some data to an XML doc in order to see what the parser's results are
            //TODO: instead, the whole Flash data structure (after parsing) should be serializable to XML
            //I.e. a Flash->XML->Flash converter is a must later on. Or preferably XAML.
            //			XmlDocument xdoc = new XmlDocument();
            //			XmlNode xnode = xdoc.CreateElement("root");
            //			xdoc.AppendChild(xnode);

            int Version = this.reader.ReadByte();

            //			this.AddNodeAndValue(xnode, "Version", Version.ToString());

            long nFileLength = this.reader.ReadUInt32();

            //rect for the bounding rect of the whole Flash file:
            ERectangle boundingRect = this.reader.ReadRect();

            //			this.AddNodeAndValue(xnode, "BoundingRect", boundingRect.ToString());

            this.FrameRate = this.reader.ReadFixed16();
            int FrameCount = this.reader.ReadUInt16();

            //			this.AddNodeAndValue(xnode, "FrameRate", FrameRate.ToString());
            //			this.AddNodeAndValue(xnode, "FrameCount", FrameCount.ToString());

            this.AllReadObjects = new ArrayList();
            this.Characters = new Hashtable();
            this.Members = new Hashtable();

            //read tag by tag until end of file:
            while (true)
            {
                Record record = new Record(reader, this);
                Record newRecord = null;
                switch (record.Tag)
                {
                    case Tags.SetBackgroundColor:
                        EH.Instance.Stage.Color = record.GetDataReader().ReadRGB();
                        break;

                    case Tags.ShowFrame:
                        newRecord = record;
                        break;

                    case Tags.DefineBits:
                    case Tags.DefineBitsJPEG2:
                    case Tags.DefineBitsJPEG3:
                    case Tags.DefineBitsLossless:
                    case Tags.DefineBitsLossless2:
                        if (record.Tag == Tags.DefineBits)
                            newRecord = new Shape.Image(this._jpegTables);
                        else
                            newRecord = new Shape.Image();
                        break;
                    case Tags.JPEGTables:
                        if (this._jpegTables == null)
                        {
                            BinaryFlashReader subReader = record.GetDataReader();
                            this._jpegTables = subReader.ReadBytes((int)record.TagLength - 2);
                            if (subReader.ReadUInt16() != 0xd9ff)
                                throw new Exception("JPEG error");
                        }
                        break;

                    case Tags.DefineFont:
                        newRecord = new Text.Font();//record
                        break;
                    case Tags.DefineFontInfo:
                        break;
                    case Tags.DefineText2:
                        newRecord = new Text.Text();//record
                        break;

                    case Tags.DefineShape:
                    case Tags.DefineShape2:
                    case Tags.DefineShape3:
                    case Tags.DefineShape4:
                    case Tags.DefineShape5:
                        newRecord = new Shape.Shape();
                        break;

                    case Tags.DefineMorphShape:
                        newRecord = new Shape.MorphShape();
                        break;

                    case Tags.PlaceObject:
                    case Tags.PlaceObject2:
                        newRecord = new Placement.Placement();
                        break;

                    case Tags.RemoveObject:
                    case Tags.RemoveObject2:
                        newRecord = new Placement.Remove();
                        break;

                    case Tags.DoAction:
                    case Tags.DoInitAction:
                        //newRecord = new Action.DoAnAction();
                        break;
                }

                if (newRecord!=null)
                {
                    if (!newRecord.Inited)
                        newRecord.Init(record);
                    this.AllReadObjects.Add(newRecord);
                }

                if (record.Tag == Tags.End)
                    break;
                if (this.reader.BaseStream.Position >= nFileLength-1)
                    break;
            }

            //xdoc.Save(a_sFilename+".xml");
            //zoom in:
            //this.TwipSize = 1; //20
            this._executedRecordIndex = -1;
            this._objectByDepth = new SortedList();
            this.CharacterIdsByDepth = new Hashtable();
            EH.Instance.EnterFrameEvent+=new EnterFrame(Instance_EnterFrameEvent);
        }