Esempio n. 1
0
        public MovieClip(MovieClip mv)
        {
            m_vStorageObject = mv.GetStorageObject();
            m_vDataType      = mv.GetMovieClipDataType();
            m_vShapes        = new List <ScObject>();

            this.SetOffset(-Math.Abs(mv.GetOffset()));

            //Duplicate MovieClip
            using (FileStream input = new FileStream(m_vStorageObject.GetFileName(), FileMode.Open))
            {
                input.Seek(Math.Abs(mv.GetOffset()) + 5, SeekOrigin.Begin);
                using (var br = new BinaryReader(input))
                {
                    this.ParseData(br);
                }
            }

            //Set new clip id
            short maxMovieClipId = this.GetId();

            foreach (MovieClip clip in m_vStorageObject.GetMovieClips())
            {
                if (clip.GetId() > maxMovieClipId)
                {
                    maxMovieClipId = clip.GetId();
                }
            }
            maxMovieClipId++;
            this.SetId(maxMovieClipId);

            //Get max shape id
            short maxShapeId = 20000;//avoid collision with other objects in MovieClips

            foreach (Shape shape in m_vStorageObject.GetShapes())
            {
                if (shape.GetId() > maxShapeId)
                {
                    maxShapeId = shape.GetId();
                }
            }
            maxShapeId++;

            //Duplicate shapes associated to clip
            List <ScObject> newShapes = new List <ScObject>();

            foreach (Shape s in m_vShapes)
            {
                Shape newShape = new Shape(s);
                newShape.SetId(maxShapeId);
                maxShapeId++;
                newShapes.Add(newShape);
                m_vStorageObject.AddShape(newShape);//Add to global shapelist
                m_vStorageObject.AddChange(newShape);
            }
            this.m_vShapes = newShapes;
        }
Esempio n. 2
0
        public MovieClip(MovieClip mv)
        {
            m_vStorageObject = mv.GetStorageObject();
            m_vDataType = mv.GetMovieClipDataType();
            m_vShapes = new List<ScObject>();

            this.SetOffset(-Math.Abs(mv.GetOffset()));
            
            //Duplicate MovieClip
            using (FileStream input = new FileStream(m_vStorageObject.GetFileName(), FileMode.Open))
            {
                input.Seek(Math.Abs(mv.GetOffset()) + 5, SeekOrigin.Begin);
                using (var br = new BinaryReader(input))
                {
                    this.ParseData(br);
                }
            }

            //Set new clip id
            short maxMovieClipId = this.GetId();
            foreach(MovieClip clip in m_vStorageObject.GetMovieClips())
            {
                if (clip.GetId() > maxMovieClipId)
                    maxMovieClipId = clip.GetId();
            }
            maxMovieClipId++;
            this.SetId(maxMovieClipId);

            //Get max shape id
            short maxShapeId = 20000;//avoid collision with other objects in MovieClips
            foreach(Shape shape in m_vStorageObject.GetShapes())
            {
                if (shape.GetId() > maxShapeId)
                    maxShapeId = shape.GetId();
            }
            maxShapeId++;

            //Duplicate shapes associated to clip
            List<ScObject> newShapes = new List<ScObject>();
            foreach(Shape s in m_vShapes)
            {
                Shape newShape = new Shape(s);
                newShape.SetId(maxShapeId);
                maxShapeId++;
                newShapes.Add(newShape);
                m_vStorageObject.AddShape(newShape);//Add to global shapelist
                m_vStorageObject.AddChange(newShape);
            }
            this.m_vShapes = newShapes;
        }
Esempio n. 3
0
        public override void Save(FileStream input)
        {
            input.Seek(0, SeekOrigin.Begin);
            byte[] file = new byte[input.Length];
            input.Read(file, 0, file.Length);

            int cursor = (int)m_vStorageObject.GetStartExportsOffset();

            input.Seek(m_vStorageObject.GetStartExportsOffset(), SeekOrigin.Begin);

            ushort exportCount = BitConverter.ToUInt16(file, cursor);

            input.Write(BitConverter.GetBytes((ushort)(exportCount + 1)), 0, 2);
            cursor += 2;

            input.Seek(exportCount * 2, SeekOrigin.Current);
            cursor += exportCount * 2;
            input.Write(BitConverter.GetBytes(m_vExportId), 0, 2);

            for (int i = 0; i < exportCount; i++)
            {
                byte nameLength = file[cursor];
                cursor++;
                byte[] exportName = new byte[nameLength];
                Array.Copy(file, cursor, exportName, 0, nameLength);
                input.WriteByte(nameLength);
                input.Write(exportName, 0, nameLength);
                cursor += nameLength;
            }

            input.WriteByte((byte)m_vExportName.Length);
            input.Write(Encoding.UTF8.GetBytes(m_vExportName), 0, (byte)m_vExportName.Length);

            while (cursor < file.Length)
            {
                input.WriteByte(file[cursor]);
                cursor++;
            }

            //refresh all offsets
            foreach (Texture t in m_vStorageObject.GetTextures())
            {
                long offset = t.GetOffset();
                if (offset > 0)
                {
                    offset += 2 + 1 + m_vExportName.Length;
                }
                else
                {
                    offset = offset - 2 - 1 - m_vExportName.Length;
                }
                t.SetOffset(offset);
            }
            foreach (Shape s in m_vStorageObject.GetShapes())
            {
                long offset = s.GetOffset();
                if (offset > 0)
                {
                    offset += 2 + 1 + m_vExportName.Length;
                }
                else
                {
                    offset = offset - 2 - 1 - m_vExportName.Length;
                }
                s.SetOffset(offset);
                foreach (ShapeChunk sc in s.GetChunks())
                {
                    long chunkOffset = sc.GetOffset();
                    if (chunkOffset > 0)
                    {
                        chunkOffset += 2 + 1 + m_vExportName.Length;
                    }
                    else
                    {
                        chunkOffset = chunkOffset - 2 - 1 - m_vExportName.Length;
                    }
                    sc.SetOffset(chunkOffset);
                }
            }
            foreach (MovieClip mc in m_vStorageObject.GetMovieClips())
            {
                long offset = mc.GetOffset();
                if (offset > 0)
                {
                    offset += 2 + 1 + m_vExportName.Length;
                }
                else
                {
                    offset = offset - 2 - 1 - m_vExportName.Length;
                }
                mc.SetOffset(offset);
            }
            m_vStorageObject.SetEofOffset(m_vStorageObject.GetEofOffset() + 2 + 1 + m_vExportName.Length);
            //ne pas oublier eofoffset
        }