Пример #1
0
        public void ConvertSimplestSWF()
        {
            string name = "SWF2HTMLTest.ConvertSimplestSWF";
            SWF    swf  = new SWF(new SWFContext(name), false);

            ConvertSWF(name, swf);
        }
Пример #2
0
        /// <summary>
        /// Loads a SWF, saves it again and then loads what was saved. The final result is compared with
        /// a predicted output file to make sure it contains what it's supposed to contain.
        /// </summary>
        /// <param name="name">The name of the SWF which is retrieved from the resources folder.</param>
        /// <param name="reAssembleCode">If true, the ABC bytecode will be disassembled and re-assembled
        /// again to test the assembler.</param>
        private void ResaveWithPredictedOutput(string name, bool reAssembleCode)
        {
            StringBuilder binDump = new StringBuilder();

            using (SWFReader sr = new SWFReader(this.ResourceAsStream(name + @".swf"), new SWFReaderOptions()
            {
                StrictTagLength = true
            }, binDump, this))
            {
                SWF swf = null;
                try
                {
                    swf = sr.ReadSWF(new SWFContext(name));
                }
                finally
                {
                    using (FileStream fs = new FileStream(this.TestDir + name + @".bin.dump-1.txt", FileMode.Create))
                    {
                        byte[] dumpbindata = new ASCIIEncoding().GetBytes(binDump.ToString());
                        fs.Write(dumpbindata, 0, dumpbindata.Length);
                    }
                }

                Assert.IsNotNull(swf);

                if (reAssembleCode)
                {
                    swf.MarkCodeAsTampered();
                }

                /* Save it out, then reload it to make sure it can survive intact */
                this.SaveAndVerifyPredictedOutput(swf, name, false);
            }
        }
Пример #3
0
        private Test()
        {
            SWF swfParser = new SWF(@"C:\test.swf");

            swfParser.ReadHeader();
            byte[] tmp;

            //byte[] mp3 = "";
            TagInfo info;

            FileStream myFStream = new FileStream(@"C:\test.mp3", FileMode.Create, FileAccess.Write);

            do
            {
                info = swfParser.ReadTag();
                if (info.Size > 0)
                {
                    tmp = swfParser.ReadBytes((int)info.Size);
                    if (info.Id == 19)
                    {
                        myFStream.Write(tmp, 4, tmp.Length - 4);
                        //Console.WriteLine(BitConverter.ToString(tmp));
                    }
                }
            }while (info.Id > 0);

            //TextWriter tw = new StreamWriter(@"C:\test.mp3");
            //tw.Write(mp3);
            myFStream.Close();
        }
Пример #4
0
        private Test()
        {
            SWF swfParser = new SWF(@"C:\test.swf");
            swfParser.ReadHeader();
            byte[] tmp;

            //byte[] mp3 = "";
            TagInfo info;

            FileStream myFStream = new FileStream(@"C:\test.mp3", FileMode.Create, FileAccess.Write);

            do {
                info = swfParser.ReadTag();
                if (info.Size > 0) {
                    tmp = swfParser.ReadBytes((int)info.Size);
                    if (info.Id == 19) {
                        myFStream.Write(tmp, 4, tmp.Length-4);
                        //Console.WriteLine(BitConverter.ToString(tmp));
                    }
                }
            }
            while (info.Id > 0);

            //TextWriter tw = new StreamWriter(@"C:\test.mp3");
            //tw.Write(mp3);
            myFStream.Close();
        }
Пример #5
0
        private string SwfToString(SWF swf)
        {
            StringBuilder sb = new StringBuilder();

            swf.ToStringModelView(0, sb);
            return(sb.ToString());
        }
Пример #6
0
        /// <summary>
        /// Find a list of characters that match a qname pattern. If nothing is found, an
        /// exception is thrown.
        /// </summary>
        /// <param name="qname">The qname to find.</param>
        /// <param name="swf">The SWF to search.</param>
        /// <param name="patternPermitted">If this is false, the returned array will have 1 element.</param>
        /// <returns>An array of characters matching the qname or qname pattern.</returns>
        public Sprite[] SpritesFromQname(string qname, SWF swf, bool patternPermitted)
        {
            /* ISSUE 62: If qname is a pattern, we should return more than one character. */
            /* ISSUE 62: If qname is a pattern, and patternPermitted is false, throw a wobbler. */

            PlaceObject po = swf.LookupInstance(qname);

            /* ISSUE 63: There is a question of whether to error if the instance is not found. Some are
             * found with a pattern rather than a path, and you may not expect it to always find something.
             * At the moment, we shall throw an exception, because it suits our development, unit testing
             * fail-fast strictness. */
            if (po == null)
            {
                throw new SwiffotronException(
                          SwiffotronError.BadPathOrID,
                          this.Context.Sentinel("FindSpriteByQName"),
                          @"Instance not found: " + qname);
            }

            Sprite sprite = po.Character as Sprite;

            if (sprite == null)
            {
                throw new SwiffotronException(
                          SwiffotronError.BadPathOrID,
                          this.Context,
                          @"Instance does not point to sprite: " + qname);
            }

            return(new Sprite[] { sprite });
        }
Пример #7
0
 private void TestSWF(string name)
 {
     using (SWFReader swfIn = new SWFReader(ResourceAsStream(name), new SWFModeller.IO.SWFReaderOptions(), null, null))
     {
         SWF swf = swfIn.ReadSWF(new SWFContext(name));
         ConvertSWF(name, swf);
     }
 }
Пример #8
0
 public JQueryCanvasApp(string ID, SWF swf, SWF2HTMLOptions options)
 {
     this.html           = new HTMLAssist(ID);
     this.Swf            = swf;
     this.Width          = (int)Swf.FrameWidth;
     this.Height         = (int)Swf.FrameHeight;
     this.OutputComments = options.OutputComments;
     this.ConsoleLogging = options.ConsoleLogging;
 }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of a sprite and empty timeline.
 /// </summary>
 /// <param name="frameCount">The initial number of empty frames on
 /// the timeline.</param>
 public Sprite(uint frameCount, SWF root)
 {
     this._root = root;
     if (frameCount < 1)
     {
         throw new SWFModellerException(
                   SWFModellerError.Internal,
                   @"A sprite must have at least 1 frame");
     }
     FrameCount = frameCount;
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of a sprite and empty timeline.
 /// </summary>
 /// <param name="frameCount">The initial number of empty frames on
 /// the timeline.</param>
 public Sprite(uint frameCount, SWF root)
 {
     this._root = root;
     if (frameCount < 1)
     {
         throw new SWFModellerException(
                 SWFModellerError.Internal,
                 @"A sprite must have at least 1 frame");
     }
     FrameCount = frameCount;
 }
Пример #11
0
        public SWF2HTML(SWF swf, string ID, SWF2HTMLOptions options = null)
        {
            this.Swf = swf;
            this.ID  = ID;

            if (options == null)
            {
                options = new SWF2HTMLOptions(); /* Defaults */
            }

            this.Options = options;
        }
Пример #12
0
        public void OnSwiffotronReadSWF(string name, SWF swf, string log)
        {
            while (swfReadLogs.ContainsKey(name))
            {
                name = name + "_1";
            }
            swfReadLogs[name] = log;

            StringBuilder sbModel = new StringBuilder();

            swf.ToStringModelView(0, sbModel);

            swfReadModelLogs[name] = sbModel.ToString();
        }
Пример #13
0
        public void Run(string[] files)
        {
            try
            {
                foreach (string swfFile in files)
                {
                    if (!File.Exists(swfFile))
                    {
                        Console.WriteLine("Not found: " + swfFile);
                        return;
                    }
                }

                foreach (string swfFile in files)
                {
                    StringBuilder binDump   = new StringBuilder();
                    StringBuilder modelDump = new StringBuilder();

                    SWF swf = null;
                    using (FileStream fs = new FileStream(swfFile, FileMode.Open, FileAccess.Read))
                    {
                        swf = new SWFReader(fs, null, binDump, this).ReadSWF(new SWFContext(swfFile));
                        swf.ToStringModelView(0, modelDump);
                    }

                    using (FileStream binOut = new FileStream(swfFile + ".SWFDUMP.bin.txt", FileMode.Create))
                    {
                        byte[] ascii = new ASCIIEncoding().GetBytes(binDump.ToString());
                        binOut.Write(ascii, 0, ascii.Length);
                    }

                    using (FileStream modelOut = new FileStream(swfFile + ".SWFDUMP.model.txt", FileMode.Create))
                    {
                        byte[] ascii = new ASCIIEncoding().GetBytes(modelDump.ToString());
                        modelOut.Write(ascii, 0, ascii.Length);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #14
0
        public void ConvertSWF(string name)
        {
            SWF swf = new SWF(new SWFContext(name), false);

            SWF2SVG converter = new SWF2SVG(swf);

            using (FileStream output = new FileStream(TestDir + name + ".svg", FileMode.Create))
                using (Stream svgOut = converter.GetSVG())
                {
                    byte[] buffer = new byte[32768];
                    while (true)
                    {
                        int read = svgOut.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                        {
                            return;
                        }
                        output.Write(buffer, 0, read);
                    }
                }
        }
Пример #15
0
        private void ConvertSWF(string name, SWF swf)
        {
            SWF2HTML converter = new SWF2HTML(swf, name, new SWF2HTMLOptions()
            {
                OutputComments = true,
                ConsoleLogging = true
            });

            using (FileStream output = new FileStream(TestDir + name + ".html", FileMode.Create))
                using (Stream htmlOut = converter.GetHTML(true))
                {
                    byte[] buffer = new byte[32768];
                    while (true)
                    {
                        int read = htmlOut.Read(buffer, 0, buffer.Length);
                        if (read <= 0)
                        {
                            return;
                        }
                        output.Write(buffer, 0, read);
                    }
                }
        }
Пример #16
0
 public SWF2SVG(SWF swf)
 {
     this.Swf = swf;
 }
Пример #17
0
        /// <summary>
        /// Gets the transform position of an instance.
        /// </summary>
        /// <param name="qname">Fully qualified name of an instance.</param>
        /// <param name="swf">The SWF to search in/</param>
        /// <returns>A copy of the instance's position matrix.</returns>
        public Matrix PositionFromQname(string qname, SWF swf)
        {
            PlaceObject po = swf.LookupInstance(qname);

            return(po.Matrix.Copy());
        }
Пример #18
0
 public StaticText(SWF root)
 {
     this._root = root;
     Records    = new List <TextRecord>();
 }
Пример #19
0
        /// <summary>
        /// Creates a SWF string dump, saves the SWF, re-loads it and compares a new
        /// string dump. If the SWF files are different, it concludes that something
        /// went wrong.
        /// </summary>
        /// <param name="swf">The SWF to test saving/loading</param>
        /// <param name="name">The SWF file and dumps are saved for inspection to
        /// the test output folder under this name.</param>
        private void SaveAndVerifyPredictedOutput(SWF swf, string name, bool compressed)
        {
            string swfDump1 = this.SwfToString(swf);

            using (FileStream fs = new FileStream(this.TestDir + name + @".model.txt", FileMode.Create))
            {
                byte[] dump1data = new ASCIIEncoding().GetBytes(swfDump1);
                fs.Write(dump1data, 0, dump1data.Length);
            }

            StringBuilder    writeLog    = new StringBuilder();
            StringBuilder    abcWriteLog = new StringBuilder();
            SWFWriterOptions opts        = new SWFWriterOptions()
            {
                Compressed     = compressed,
                EnableDebugger = true
            };

            byte[] swfData = new SWFWriter(swf, opts, writeLog, abcWriteLog).ToByteArray();

            using (FileStream fs = new FileStream(this.TestDir + name + ".writelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(writeLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            Directory.CreateDirectory(this.TestDir + @"\abc\");
            using (FileStream fs = new FileStream(this.TestDir + @"\abc\" + name + ".writelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(abcWriteLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            using (FileStream fs = new FileStream(this.TestDir + name + ".swf", FileMode.Create))
            {
                fs.Write(swfData, 0, swfData.Length);
            }
            StringBuilder binDump = new StringBuilder();

            string swfDump2 = null;

            try
            {
                swfDump2 = this.SwfToString(
                    new SWFReader(
                        new MemoryStream(swfData),
                        new SWFReaderOptions()
                {
                    StrictTagLength = true
                },
                        binDump,
                        this)
                    .ReadSWF(new SWFContext("resaved." + name)));
            }
            finally
            {
                using (FileStream fs = new FileStream(this.TestDir + name + ".bin.dump-2.txt", FileMode.Create))
                {
                    byte[] dump2bindata = new ASCIIEncoding().GetBytes(binDump.ToString());
                    fs.Write(dump2bindata, 0, dump2bindata.Length);
                }
            }

            string finalModelFile = this.TestDir + name + ".model-dump-2.txt";

            using (FileStream fs = new FileStream(finalModelFile, FileMode.Create))
            {
                byte[] dump2data = new ASCIIEncoding().GetBytes(swfDump2);
                fs.Write(dump2data, 0, dump2data.Length);
            }

            string predicted = TestDir + name + ".model.predict.txt";

            using (Stream input = ResourceAsStream("predicted." + name + ".txt"))
                using (FileStream output = new FileStream(TestDir + name + ".model.predict.txt", FileMode.Create))
                {
                    Assert.IsNotNull(input, "Predicted output is missing! " + name);
                    CopyStream(input, output);
                }

            using (StreamWriter acceptScript = new StreamWriter(new FileStream(TestDir + "accept.bat", FileMode.Create)))
            {
                acceptScript.WriteLine("copy \"" + finalModelFile + "\" \"" + new FileInfo("..\\..\\..\\SWFModellerTest\\res\\predicted\\" + name + ".txt").FullName + "\"");
            }

            using (StreamWriter viewScript = new StreamWriter(new FileStream(TestDir + "viewdiff.bat", FileMode.Create)))
            {
                /* ISSUE 44: This should be a diff tool env var */
                viewScript.WriteLine("\"c:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" \"" + finalModelFile + "\" \"" + new FileInfo("..\\..\\..\\SWFModellerTest\\res\\predicted\\" + name + ".txt").FullName + "\"");
            }

            CompareFiles(
                predicted,
                finalModelFile,
                "Predicted output failure! These files differ: " + name + ".model.predict.txt" + ", " + name + ".model.txt");
        }
Пример #20
0
        /// <summary>
        /// This will alter the incoming SWF's font references. Any new fonts will be
        /// left untouched. Any fonts that exist in root already will have their glyphs
        /// imported into the root SWF's fonts and references will re-point to the
        /// now possibly larger font. Any fonts that exist only in incoming will be left
        /// alone since importing the SWF as a movieclip will automatically make those
        /// fonts part of root.
        /// </summary>
        /// <param name="incoming">The SWF being absorbed into the root.</param>
        /// <param name="root">The root SWF that will absord new fonts or glyphs.</param>
        private void RemapFonts(SWF incoming, SWF root)
        {
            List<SWFFont> rootFonts = new List<SWFFont>();
            root.FontProc(delegate(SWFFont font)
            {
                rootFonts.Add(font);
            });

            Dictionary<SWFFont, SWFFont> remaps = new Dictionary<SWFFont, SWFFont>();

            incoming.FontProc(delegate(SWFFont font)
            {
                foreach (SWFFont rootFont in rootFonts)
                {
                    if (font.CanMergeWith(rootFont))
                    {
                        remaps.Add(font, rootFont);

                        char[] codes = font.CodePoints;
                        foreach (char c in codes)
                        {
                            bool hasPixelAlignment = font.HasPixelAlignment;
                            bool hasLayout = font.HasLayout;

                            if (!rootFont.HasGlyph(c))
                            {
                                rootFont.AddGlyph(c, font.GetGlyphShape(c));

                                if (hasPixelAlignment)
                                {
                                    rootFont.AddPixelAlignment(c, font.GetPixelAligment(c));
                                }

                                if (hasLayout)
                                {
                                    rootFont.AddLayout(c, font.GetLayout(c));
                                }
                            }
                        }
                    }
                }
            });

            /* Now we've merged glyphs into our target fonts, we need to go over all
             * uses of the old fonts and remap them... */

            incoming.CharacterProc(delegate(ICharacter ch)
            {
                if (ch is IFontUserProcessor)
                {
                    IFontUserProcessor fup = (IFontUserProcessor)ch;

                    fup.FontUserProc(delegate(IFontUser fu)
                    {
                        if (fu.HasFont && remaps.ContainsKey(fu.Font))
                        {
                            fu.Font = remaps[fu.Font];
                        }
                    });
                }
            });
        }
Пример #21
0
        /// <summary>
        /// Initializes a new instance of a sprite by cloning another timeline.
        /// </summary>
        /// <param name="srcTimeline">The timeline to clone.</param>
        /// <param name="className">If the cloned timeline is a SWF, then
        /// you should pass in a class name here. The MainTimeline class
        /// will be renamed in here to this new name.</param>
        public Sprite(Timeline srcTimeline, SWF root, string className = null)
        {
            this._root = root;

            /* Layers are just objects that exist purely to be arranged in some
             * kind of order and be pointed at by more meaningful, other things.
             * To clone layers, we need to simply copy the list and map old
             * layer refs to our new ones. */
            Dictionary<Layer, Layer> newLayers = new Dictionary<Layer, Layer>(srcTimeline.LayerCount);
            foreach (Layer l in srcTimeline.Layers)
            {
                Layer newLayer = new Layer(this);
                LayerList.Add(newLayer);
                newLayers.Add(l, newLayer);
            }

            FrameList = new List<Frame>((int)srcTimeline.FrameCount);
            foreach (Frame f in srcTimeline.Frames)
            {
                Frame newFrame = new Frame();
                foreach (IDisplayListItem dli in f.DisplayList)
                {
                    newFrame.AddTag(dli.Clone(newLayers[dli.Layer], false));
                }
                FrameList.Add(newFrame);
            }

            if (srcTimeline is SWF)
            {
                SWF srcSWF = (SWF)srcTimeline;

                if (className != null)
                {
                    if (srcSWF.Class != null)
                    {
                        srcSWF.RenameMainTimelineClass(className);
                    }
                    /* Else the class will be generated later */
                }

                RemapFonts(srcSWF, root);

                if (className != null)
                {
                    foreach (DoABC abc in srcSWF.Scripts)
                    {
                        root.MergeScript(abc);
                    }
                }

                if (className == null)
                {
                    /* It's tempting to use ClassByName("flash.display.MovieClip") but
                     * remember that that class exists in the player, not the SWF. What
                     * we need in this case is just the name of the class, not a reference
                     * to the class itself. Because that's complicated, we assign a
                     * dummy class and watch for it when we write the class out. */
                    this.Class = AdobeClass.CreateFlashDisplayMovieClip(root.FirstScript.Code);
                }
                else
                {
                    this.Class = srcSWF.Class;
                }
            }
        }
Пример #22
0
 public EditText(SWF root)
 {
     this._root = root;
 }
Пример #23
0
        /// <summary>
        /// Initializes a new instance of a sprite by cloning another timeline.
        /// </summary>
        /// <param name="srcTimeline">The timeline to clone.</param>
        /// <param name="className">If the cloned timeline is a SWF, then
        /// you should pass in a class name here. The MainTimeline class
        /// will be renamed in here to this new name.</param>
        public Sprite(Timeline srcTimeline, SWF root, string className = null)
        {
            this._root = root;

            /* Layers are just objects that exist purely to be arranged in some
             * kind of order and be pointed at by more meaningful, other things.
             * To clone layers, we need to simply copy the list and map old
             * layer refs to our new ones. */
            Dictionary <Layer, Layer> newLayers = new Dictionary <Layer, Layer>(srcTimeline.LayerCount);

            foreach (Layer l in srcTimeline.Layers)
            {
                Layer newLayer = new Layer(this);
                LayerList.Add(newLayer);
                newLayers.Add(l, newLayer);
            }

            FrameList = new List <Frame>((int)srcTimeline.FrameCount);
            foreach (Frame f in srcTimeline.Frames)
            {
                Frame newFrame = new Frame();
                foreach (IDisplayListItem dli in f.DisplayList)
                {
                    newFrame.AddTag(dli.Clone(newLayers[dli.Layer], false));
                }
                FrameList.Add(newFrame);
            }

            if (srcTimeline is SWF)
            {
                SWF srcSWF = (SWF)srcTimeline;

                if (className != null)
                {
                    if (srcSWF.Class != null)
                    {
                        srcSWF.RenameMainTimelineClass(className);
                    }
                    /* Else the class will be generated later */
                }

                RemapFonts(srcSWF, root);

                if (className != null)
                {
                    foreach (DoABC abc in srcSWF.Scripts)
                    {
                        root.MergeScript(abc);
                    }
                }

                if (className == null)
                {
                    /* It's tempting to use ClassByName("flash.display.MovieClip") but
                     * remember that that class exists in the player, not the SWF. What
                     * we need in this case is just the name of the class, not a reference
                     * to the class itself. Because that's complicated, we assign a
                     * dummy class and watch for it when we write the class out. */
                    this.Class = AdobeClass.CreateFlashDisplayMovieClip(root.FirstScript.Code);
                }
                else
                {
                    this.Class = srcSWF.Class;
                }
            }
        }
Пример #24
0
    public void SetWallFrame(Animations a, WallSheetData dat)
    {
        //Get the location of every kind of wall frame in the spritesheet.
        Location singleStart = new Location(0, 0),

                 leftEndStart    = new Location(0, 1),
                 horzCenterStart = new Location(leftEndStart.X + dat.LeftEnds, leftEndStart.Y),
                 rightEndStart   = new Location(horzCenterStart.X + dat.HorizontalCenters, leftEndStart.Y),

                 topEndStart     = new Location(0, 2),
                 vertCenterStart = new Location(topEndStart.X + dat.TopEnds, topEndStart.Y),
                 bottomEndStart  = new Location(vertCenterStart.X + dat.VerticalCenters, topEndStart.Y),

                 tlCornerStart = new Location(0, 3),
                 trCornerStart = new Location(tlCornerStart.X + dat.TLCorners, tlCornerStart.Y),
                 blCornerStart = new Location(trCornerStart.X + dat.TRCorners, tlCornerStart.Y),
                 brCornerStart = new Location(blCornerStart.X + dat.BLCorners, tlCornerStart.Y),

                 topSideStart    = new Location(0, 4),
                 bottomSideStart = new Location(topSideStart.X + dat.TopSides, topSideStart.Y),
                 leftSideStart   = new Location(bottomSideStart.X + dat.BottomSides, topSideStart.Y),
                 rightSideStart  = new Location(leftSideStart.X + dat.LeftSides, topSideStart.Y),

                 centerStart = new Location(0, 5);

        SWF call = (loc, numb) =>
        {
            short index = (short)(loc.X + Random.Range(0, numb - 1));
            Call(new Args((short)dat.Columns, (short)dat.Rows, index, (short)loc.Y, 1, 60));
        };

        currentAnim = a;

        switch (a)
        {
        case Animations.W_Single:
            call(singleStart, dat.Singles);
            break;

        case Animations.W_LeftEnd:
            call(leftEndStart, dat.LeftEnds);
            break;

        case Animations.W_HorzCenter:
            call(horzCenterStart, dat.HorizontalCenters);
            break;

        case Animations.W_RightEnd:
            call(rightEndStart, dat.RightEnds);
            break;

        case Animations.W_TopEnd:
            call(topEndStart, dat.TopEnds);
            break;

        case Animations.W_VertCenter:
            call(vertCenterStart, dat.VerticalCenters);
            break;

        case Animations.W_BottomEnd:
            call(bottomEndStart, dat.BottomEnds);
            break;

        case Animations.W_TLCorner:
            call(tlCornerStart, dat.TLCorners);
            break;

        case Animations.W_TRCorner:
            call(trCornerStart, dat.TRCorners);
            break;

        case Animations.W_BLCorner:
            call(blCornerStart, dat.BLCorners);
            break;

        case Animations.W_BRCorner:
            call(brCornerStart, dat.BRCorners);
            break;

        case Animations.W_TopSide:
            call(topSideStart, dat.TopSides);
            break;

        case Animations.W_BottomSide:
            call(bottomSideStart, dat.BottomSides);
            break;

        case Animations.W_LeftSide:
            call(leftSideStart, dat.LeftSides);
            break;

        case Animations.W_RightSide:
            call(rightSideStart, dat.RightSides);
            break;

        case Animations.W_Center:
            call(centerStart, dat.Centers);
            break;

        default: throw new System.NotImplementedException("Not a valid wall type!");
        }
    }
Пример #25
0
        /// <summary>
        /// Creates a SWF string dump, saves the SWF, re-loads it and compares a new
        /// string dump. If the SWF files are different, it concludes that something
        /// went wrong.
        /// </summary>
        /// <param name="swf">The SWF to test saving/loading</param>
        /// <param name="name">The SWF file and dumps are saved for inspection to
        /// the test output folder under this name.</param>
        private void SaveAndVerifyPredictedOutput(SWF swf, string name, bool compressed)
        {
            string swfDump1 = this.SwfToString(swf);

            using (FileStream fs = new FileStream(this.TestDir + name + @".model.txt", FileMode.Create))
            {
                byte[] dump1data = new ASCIIEncoding().GetBytes(swfDump1);
                fs.Write(dump1data, 0, dump1data.Length);
            }

            StringBuilder writeLog = new StringBuilder();
            StringBuilder abcWriteLog = new StringBuilder();
            SWFWriterOptions opts = new SWFWriterOptions()
            {
                Compressed = compressed,
                EnableDebugger = true
            };

            byte[] swfData = new SWFWriter(swf, opts, writeLog, abcWriteLog).ToByteArray();

            using (FileStream fs = new FileStream(this.TestDir + name + ".writelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(writeLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            Directory.CreateDirectory(this.TestDir + @"\abc\");
            using (FileStream fs = new FileStream(this.TestDir + @"\abc\" + name + ".writelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(abcWriteLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            using (FileStream fs = new FileStream(this.TestDir + name + ".swf", FileMode.Create))
            {
                fs.Write(swfData, 0, swfData.Length);
            }
            StringBuilder binDump = new StringBuilder();

            string swfDump2 = null;
            try
            {
                swfDump2 = this.SwfToString(
                        new SWFReader(
                                new MemoryStream(swfData),
                                new SWFReaderOptions() { StrictTagLength = true },
                                binDump,
                                this)
                            .ReadSWF(new SWFContext("resaved." + name)));
            }
            finally
            {
                using (FileStream fs = new FileStream(this.TestDir + name + ".bin.dump-2.txt", FileMode.Create))
                {
                    byte[] dump2bindata = new ASCIIEncoding().GetBytes(binDump.ToString());
                    fs.Write(dump2bindata, 0, dump2bindata.Length);
                }
            }

            string finalModelFile = this.TestDir + name + ".model-dump-2.txt";
            using (FileStream fs = new FileStream(finalModelFile, FileMode.Create))
            {
                byte[] dump2data = new ASCIIEncoding().GetBytes(swfDump2);
                fs.Write(dump2data, 0, dump2data.Length);
            }

            string predicted = TestDir + name + ".model.predict.txt";
            using (Stream input = ResourceAsStream("predicted." + name + ".txt"))
            using (FileStream output = new FileStream(TestDir + name + ".model.predict.txt", FileMode.Create))
            {
                Assert.IsNotNull(input, "Predicted output is missing! " + name);
                CopyStream(input, output);
            }

            using (StreamWriter acceptScript = new StreamWriter(new FileStream(TestDir + "accept.bat", FileMode.Create)))
            {
                acceptScript.WriteLine("copy \"" + finalModelFile + "\" \"" + new FileInfo("..\\..\\..\\SWFModellerTest\\res\\predicted\\" + name + ".txt").FullName + "\"");
            }

            using (StreamWriter viewScript = new StreamWriter(new FileStream(TestDir + "viewdiff.bat", FileMode.Create)))
            {
                /* ISSUE 44: This should be a diff tool env var */
                viewScript.WriteLine("\"c:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" \"" + finalModelFile + "\" \"" + new FileInfo("..\\..\\..\\SWFModellerTest\\res\\predicted\\" + name + ".txt").FullName + "\"");
            }

            CompareFiles(
                predicted,
                finalModelFile,
                "Predicted output failure! These files differ: " + name + ".model.predict.txt" + ", " + name + ".model.txt");
        }
Пример #26
0
        /// <summary>
        /// This will alter the incoming SWF's font references. Any new fonts will be
        /// left untouched. Any fonts that exist in root already will have their glyphs
        /// imported into the root SWF's fonts and references will re-point to the
        /// now possibly larger font. Any fonts that exist only in incoming will be left
        /// alone since importing the SWF as a movieclip will automatically make those
        /// fonts part of root.
        /// </summary>
        /// <param name="incoming">The SWF being absorbed into the root.</param>
        /// <param name="root">The root SWF that will absord new fonts or glyphs.</param>
        private void RemapFonts(SWF incoming, SWF root)
        {
            List <SWFFont> rootFonts = new List <SWFFont>();

            root.FontProc(delegate(SWFFont font)
            {
                rootFonts.Add(font);
            });

            Dictionary <SWFFont, SWFFont> remaps = new Dictionary <SWFFont, SWFFont>();

            incoming.FontProc(delegate(SWFFont font)
            {
                foreach (SWFFont rootFont in rootFonts)
                {
                    if (font.CanMergeWith(rootFont))
                    {
                        remaps.Add(font, rootFont);

                        char[] codes = font.CodePoints;
                        foreach (char c in codes)
                        {
                            bool hasPixelAlignment = font.HasPixelAlignment;
                            bool hasLayout         = font.HasLayout;

                            if (!rootFont.HasGlyph(c))
                            {
                                rootFont.AddGlyph(c, font.GetGlyphShape(c));

                                if (hasPixelAlignment)
                                {
                                    rootFont.AddPixelAlignment(c, font.GetPixelAligment(c));
                                }

                                if (hasLayout)
                                {
                                    rootFont.AddLayout(c, font.GetLayout(c));
                                }
                            }
                        }
                    }
                }
            });

            /* Now we've merged glyphs into our target fonts, we need to go over all
             * uses of the old fonts and remap them... */

            incoming.CharacterProc(delegate(ICharacter ch)
            {
                if (ch is IFontUserProcessor)
                {
                    IFontUserProcessor fup = (IFontUserProcessor)ch;

                    fup.FontUserProc(delegate(IFontUser fu)
                    {
                        if (fu.HasFont && remaps.ContainsKey(fu.Font))
                        {
                            fu.Font = remaps[fu.Font];
                        }
                    });
                }
            });
        }
Пример #27
0
 private string SwfToString(SWF swf)
 {
     StringBuilder sb = new StringBuilder();
     swf.ToStringModelView(0, sb);
     return sb.ToString();
 }
Пример #28
0
        private void PredictedOutputTest(string xmlIn, string swfOut, out Swiffotron swiffotron)
        {
            MockStore store;
            MockCache cache;

            swiffotron = CreateMockSwiffotron(out store, out cache);

            StringBuilder writeLog              = new StringBuilder();
            StringBuilder abcWriteLog           = new StringBuilder();
            Dictionary <string, byte[]> commits = new Dictionary <string, byte[]>();

            swiffotron.Process(ResourceAsStream(xmlIn), commits, writeLog, abcWriteLog, this, this);
            CheckCommits(commits);

            using (FileStream fs = new FileStream(TestDir + xmlIn + ".writelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(writeLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            using (FileStream fs = new FileStream(TestDir + xmlIn + ".abcwritelog.txt", FileMode.Create))
            {
                byte[] writeLogData = new ASCIIEncoding().GetBytes(abcWriteLog.ToString());
                fs.Write(writeLogData, 0, writeLogData.Length);
            }

            CopyStoreToTestDir(store);

            Assert.IsTrue(store.Has(swfOut), @"Output was not saved");

            /* Check that a valid SWF file was produced by reading it back: */
            StringBuilder binDump = new StringBuilder();

            SWF swf = null;

            SWFReader sr = new SWFReader(
                store.OpenInput(swfOut),
                new SWFReaderOptions()
            {
                StrictTagLength = true
            },
                binDump,
                this);     /* constantFilter is a delegate function that will throw an exception
                            * if it spots something objectionable in the SWF's constants. */

            try
            {
                swf = sr.ReadSWF(new SWFContext(swfOut));

                /* The delegate we gave to the SWF reader for trapping ABC constants will
                 * not have been run yet since the SWF reader doesn't parse the ABC unless
                 * it really needs to. Here's how we force it to, and run the filter
                 * delegate... */

                swf.ScriptProc(delegate(DoABC abc)
                {
                    AbcCode code = abc.Code; /* Transparently parses the ABC */
                });
            }
            finally
            {
                using (FileStream fs = new FileStream(TestDir + xmlIn + ".bin.dump.txt", FileMode.Create))
                {
                    byte[] dumpbindata = new ASCIIEncoding().GetBytes(binDump.ToString());
                    fs.Write(dumpbindata, 0, dumpbindata.Length);
                }
            }

            string predicted = TestDir + swfOut + ".model.predict.txt";

            using (Stream input = ResourceAsStream("predicted." + swfOut + ".txt"))
                using (FileStream output = new FileStream(predicted, FileMode.Create))
                {
                    Assert.IsNotNull(input, "Predicted output is missing! " + swfOut);
                    CopyStream(input, output);
                }

            using (StreamWriter acceptScript = new StreamWriter(new FileStream(TestDir + "accept.bat", FileMode.Create)))
            {
                acceptScript.WriteLine("copy \"" + lastCommitModelOutput + "\" \"" + new FileInfo("..\\..\\..\\SwiffotronTest\\res\\predicted\\" + swfOut + ".txt").FullName + "\"");
            }

            using (StreamWriter viewScript = new StreamWriter(new FileStream(TestDir + "viewdiff.bat", FileMode.Create)))
            {
                /* ISSUE 44: This should be a diff tool env var */
                viewScript.WriteLine("\"c:\\Program Files (x86)\\WinMerge\\WinMergeU.exe\" \"" + lastCommitModelOutput + "\" \"" + new FileInfo("..\\..\\..\\SwiffotronTest\\res\\predicted\\" + swfOut + ".txt").FullName + "\"");
            }

            CompareFiles(
                predicted,
                lastCommitModelOutput,
                "Predicted output failure! These files differ: " + swfOut + ".model.predict.txt" + ", " + swfOut + ".model.txt");
        }
Пример #29
0
 public SWF2Raster(SWF swf)
 {
     this.Swf = swf;
 }