public override V2DContentHolder Process(string fileName, ContentProcessorContext context) { //System.Diagnostics.Debugger.Launch(); V2DContent result = null; V2DContentHolder vch = null; //System.Diagnostics.Debugger.Launch(); if (File.Exists(fileName)) { fileName = Path.GetFullPath(fileName); Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { vch = DDW.VexTo2DPhysics.V2D.SwfToV2DContent(scu, context); } } if (vch == null) { throw new InvalidContentException("invalid swf content"); } result = new V2DContent(); return(vch); }
private void AddSwfToTreeView(SwfCompilationUnit scu, TreeView tv) { // temp: move this to subclasss of treeview tv.Nodes.Add("root", scu.Name); TreeNode root = tv.Nodes[0]; for (int i = 0; i < scu.Tags.Count; i++) { switch (scu.Tags[i].TagType) { case TagType.DefineShape: case TagType.DefineShape2: DefineShape2Tag ds2 = (DefineShape2Tag)scu.Tags[i]; root.Nodes.Add(ds2.ShapeId.ToString(), ds2.ShapeId + ": DefineShape2"); break; case TagType.DefineShape3: DefineShape3Tag ds3 = (DefineShape3Tag)scu.Tags[i]; root.Nodes.Add(ds3.ShapeId.ToString(), ds3.ShapeId + ": DefineShape3"); break; case TagType.DefineShape4: DefineShape4Tag ds4 = (DefineShape4Tag)scu.Tags[i]; root.Nodes.Add(ds4.ShapeId.ToString(), ds4.ShapeId + ": DefineShape4"); break; } } }
public ConversionObjects(SwfCompilationUnit scu, VexObject v, string xamlFileName, string message) { this.scu = scu; this.v = v; this.xamlFileName = xamlFileName; this.message = message; }
public static string Convert(string fileName, out SwfCompilationUnit scu, out VexObject v) { v = null; string result = "Failed to convert."; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { result = "\n\n**** Converting to SwfCompilationUnit ****\n"; #if DEBUG StringWriter sw = new StringWriter(); IndentedTextWriter w = new IndentedTextWriter(sw); scu.Dump(w); Debug.WriteLine(sw.ToString()); #endif result += scu.Log.ToString(); SwfToVex s2v = new SwfToVex(); v = s2v.Convert(scu); result += "\n\n**** Converting to Vex ****\n"; result += s2v.Log.ToString(); } return(result); }
public static string Convert( bool isSilverlight, SwfCompilationUnit scu, VexObject v, out string xamlFileName) { string result = "Failed to convert."; SwfToVex s2v = new SwfToVex(); v = s2v.Convert(scu); result = "\n\n**** Converting to Vex ****\n"; result += s2v.Log.ToString(); XamlRenderer xr; if (isSilverlight) { xr = new Silverlight10Renderer(); } else { xr = new WPFRenderer(); } xr.GenerateXaml(v, out xamlFileName); result += "\n\n**** Converting to Xaml ****\n"; result += xr.Log.ToString(); result += "\n\nSuccess."; return result; }
public static VexTree ProcessFile(string fileName) { VexTree v2tree = null; if (File.Exists(fileName)) { fileName = Path.GetFullPath(fileName); Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { v2tree = ProcessSwf(scu); //SwfToV2DContent(scu, null); Console.WriteLine(""); } else { Console.WriteLine("Not a valid swf file: " + fileName); Console.WriteLine("Usage: v2d <filename>"); } } else { Console.WriteLine(fileName + " does not exist."); Console.WriteLine("Usage: v2d <filename>"); } return(v2tree); }
public Dictionary <uint, Bitmap> GenerateMappedBitmaps(SwfCompilationUnit scu) { Dictionary <uint, Bitmap> result = new Dictionary <uint, Bitmap>(); foreach (ISwfTag tag in scu.Tags) { Edge[] edges = null; if (tag is DefineShape2Tag) { DefineShape2Tag def = (DefineShape2Tag)tag; edges = ParseEdges(def.Shapes, def.ShapeBounds); Bitmap b = DrawShape(def.Shapes, edges, def.ShapeBounds); } else if (tag is DefineShape3Tag) { DefineShape3Tag def = (DefineShape3Tag)tag; edges = ParseEdges(def.Shapes, def.ShapeBounds); Bitmap b = DrawShape(def.Shapes, edges, def.ShapeBounds); } if (tag is DefineShape4Tag) { DefineShape4Tag def = (DefineShape4Tag)tag; edges = ParseEdges(def.Shapes, def.ShapeBounds); Bitmap b = DrawShape(def.Shapes, edges, def.ShapeBounds); } if (edges != null) { Program.form.edges = edges; break; } } return(result); }
public List <Bitmap> GenerateBitmaps(SwfCompilationUnit scu) { List <Bitmap> result = new List <Bitmap>(); Dictionary <uint, Bitmap> dbmp = GenerateMappedBitmaps(scu); result.AddRange(dbmp.Values); return(result); }
public void Convert(SwfCompilationUnit swf, UnsafeBitmap fullBitmap, Dictionary <uint, System.Drawing.Rectangle> rects) { this.swf = swf; this.fullBitmap = fullBitmap; this.rects = rects; foreach (ISwfTag tag in swf.Tags) { this.ParseTag(tag); } }
public static string Convert( string fileName, bool isSilverlight, out SwfCompilationUnit scu, out VexObject v, out string xamlFileName) { string result = "Failed to convert."; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { result = "\n\n**** Converting to SwfCompilationUnit ****\n"; #if DEBUG StringWriter sw = new StringWriter(); IndentedTextWriter w = new IndentedTextWriter(sw); scu.Dump(w); Debug.WriteLine(sw.ToString()); #endif result += scu.Log.ToString(); SwfToVex s2v = new SwfToVex(); v = s2v.Convert(scu); result += "\n\n**** Converting to Vex ****\n"; result += s2v.Log.ToString(); XamlRenderer xr; if (isSilverlight) { xr = new Silverlight10Renderer(); } else { xr = new WPFRenderer(); } xr.GenerateXaml(v, out xamlFileName); result += "\n\n**** Converting to Xaml ****\n"; result += xr.Log.ToString(); result += "\n\nSuccess."; } else { result = "Not a valid swf file: " + fileName; v = null; xamlFileName = ""; } return result; }
public static VexTree ProcessSwf(SwfCompilationUnit scu) { VexTree result = null; if (scu.IsValid) { SwfToVex s2v = new SwfToVex(); VexObject vo = s2v.Convert(scu); result = new VexTree(); result.Convert(vo, scu); } return(result); }
public static V2DContentHolder SwfToV2DContent(SwfCompilationUnit scu, ContentProcessorContext context) { V2DContentHolder result = null; if (scu.IsValid) { SwfToVex s2v = new SwfToVex(); VexObject vo = s2v.Convert(scu); VexTree vt = new VexTree(); vt.Convert(vo, scu); vt.WriteToXml(); result = vt.GetV2DContent(context); } return(result); }
static void Main(string[] args) { string fileName = (args.Length < 1) ? "test.swf" : args[0]; if (File.Exists(fileName)) { fileName = Path.GetFullPath(fileName); Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); form = new Form1(); //SwfToVex s2v = new SwfToVex(); //VexObject vo = s2v.Convert(scu); SwfRenderer sr = new SwfRenderer(); sr.GenerateMappedBitmaps(scu); Application.Run(form); } else { Console.WriteLine("Not a valid swf file: " + fileName); Console.WriteLine("Usage: swfrenderer <filename>"); } } else { Console.WriteLine(fileName + " does not exist."); Console.WriteLine("Usage: swfrenderer <filename>"); } }
//public static GdiForm gf; static void Main(string[] args) { string fileName = "test14.swf"; if (args.Length > 0) { fileName = args[0]; } FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r); //StringWriter sw = new StringWriter(); //IndentedTextWriter w = new IndentedTextWriter(sw); //scu.Dump(w); //Debug.WriteLine(sw.ToString()); SwfToVex s2v = new SwfToVex(); VexObject v = s2v.Convert(scu); XamlRenderer xr = new WPFRenderer(); xr.GenerateXaml(v); //GdiRenderer gr = new GdiRenderer(); //List<Bitmap> bmps = gr.GenerateBitmaps(v); ////gr.ExportBitmaps(bmps); //gf = new GdiForm(bmps); //Application.EnableVisualStyles(); //Application.Run(gf); }
static void Main(string[] args) { Console.WriteLine("SWF DUMP TOOL - swf v8"); Console.WriteLine(""); #if !DEBUG if (args.Length < 1) { Console.WriteLine(""); Console.WriteLine("Need some swf file format help? Parser tools? Generators?"); Console.WriteLine("Just give me a shout : ) [email protected]"); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Usage: swfdump <filename>"); return; } #endif string fileName = (args.Length < 1) ? "test.swf" : args[0]; if (File.Exists(fileName)) { fileName = Path.GetFullPath(fileName); Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { StringWriter sw = new StringWriter(); IndentedTextWriter w = new IndentedTextWriter(sw); // scu.Dump(w); // Console.WriteLine(sw.ToString()); SwfToVex s2v = new SwfToVex(); VexObject vo = s2v.Convert(scu); DumpTextObject(vo); //VexTo2DPhysics.VexTo2DPhysics v2dp = new VexTo2DPhysics.VexTo2DPhysics(); //v2dp.Convert(vo, scu); Console.WriteLine(""); Console.WriteLine("Need some swf file format help? [email protected]"); Console.WriteLine(""); //temp MemoryStream ms = new MemoryStream(); SwfWriter swfWriter = new SwfWriter(ms); scu.Header.IsCompressed = false; scu.ToSwf(swfWriter); byte[] swfBytes = swfWriter.ToArray(); FileStream fsw = new FileStream("dump.swf", FileMode.Create, FileAccess.Write); fsw.Write(swfBytes, 0, swfBytes.Length); fsw.Close(); ms.Close(); //Console.ReadLine(); } else { Console.WriteLine("Not a valid swf file: " + fileName); Console.WriteLine("Usage: swfdump <filename>"); } } else { Console.WriteLine(fileName + " does not exist."); Console.WriteLine("Usage: swfdump <filename>"); } }
static void Main(string[] args) { Console.WriteLine("SWF BITMAP PACKER - swf v8"); Console.WriteLine(""); string fileName = (args.Length < 1) ? "test.swf" : args[0]; bool packBitmapsOnly = (args.Length < 2) ? false : args[1].ToUpperInvariant() == "-B"; if (File.Exists(fileName)) { fileName = Path.GetFullPath(fileName); Directory.SetCurrentDirectory(Path.GetDirectoryName(fileName)); FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(fileName); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r, name); if (scu.IsValid) { UnsafeBitmap fullBitmap; Dictionary <uint, System.Drawing.Rectangle> rectResult = new Dictionary <uint, System.Drawing.Rectangle>(); SwfToVex s2v = new SwfToVex(); VexObject vo = s2v.Convert(scu); if (packBitmapsOnly) { Dictionary <uint, string> bitmapPaths = s2v.bitmapPaths; fullBitmap = BitmapPacker.PackBitmaps(bitmapPaths, rectResult); } else { fullBitmap = BitmapPacker.PackBitmaps(vo, rectResult); } foreach (var rect in rectResult) { Console.WriteLine("\t" + rect.Value + ","); } fullBitmap.Bitmap.Save("fullBitmap.png"); if (packBitmapsOnly) { BitmapSwapper bs = new BitmapSwapper(); bs.Convert(scu, fullBitmap, rectResult); MemoryStream ms = new MemoryStream(); SwfWriter swfWriter = new SwfWriter(ms); scu.ToSwf(swfWriter); byte[] swfBytes = swfWriter.ToArray(); FileStream fsw = new FileStream("result.swf", FileMode.Create, FileAccess.Write); fsw.Write(swfBytes, 0, swfBytes.Length); fsw.Close(); ms.Close(); } } else { Console.WriteLine("Not a valid swf file: " + fileName); Console.WriteLine("Usage: SwfBitmapPacker <filename>"); } } else { Console.WriteLine(fileName + " does not exist."); Console.WriteLine("Usage: SwfBitmapPacker <filename>"); } }
public LibraryItem[] AddSwf(string path) { List <LibraryItem> result = new List <LibraryItem>(); if (File.Exists(path)) { using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { BinaryReader br = new BinaryReader(fs); string name = Path.GetFileNameWithoutExtension(path); SwfReader r = new SwfReader(br.ReadBytes((int)fs.Length)); SwfCompilationUnit scu = new SwfCompilationUnit(r); if (scu.IsValid) { SwfToVex s2v = new SwfToVex(); Vex.VexObject v = s2v.Convert(scu); DateTime creationTime = File.GetLastWriteTimeUtc(path); string swfName = Path.GetFileName(path); string wf = MainForm.CurrentStage.WorkingFolderFull; bool inWorkingFolder = path.IndexOf(wf) == 0; string wp = inWorkingFolder ? path.Substring(wf.Length) : swfName; string workingPath = wp.Substring(0, wp.Length - swfName.Length); TreeNode existingNode = symbolTree.GetNode(workingPath, swfName); bool isUpdatingSwf = (existingNode != null); LibraryItem li; Dictionary <uint, uint> translator = new Dictionary <uint, uint>(); List <uint> recycledInstIds = new List <uint>(); foreach (uint key in v.Definitions.Keys) { Vex.IDefinition loadedDef = v.Definitions[key]; if (scu.SymbolClasses.ContainsKey(key)) { loadedDef.Name = scu.SymbolClasses[key]; } uint loadedId = loadedDef.Id; bool isTimeline = loadedDef is Vex.Timeline; LibraryItem existingLi = null; if (isUpdatingSwf) { loadedDef.HasSaveableChanges = true; existingLi = isTimeline ? MainForm.CurrentLibrary.GetLibraryItem(workingPath + swfName, loadedDef.Name) : MainForm.CurrentLibrary.GetByOriginalSourceId(loadedDef.Id); } if (existingLi != null) { loadedDef.Id = existingLi.DefinitionId; translator[loadedId] = loadedDef.Id; existingLi.Date = creationTime; if (isTimeline) { Vex.Timeline orgTl = (Vex.Timeline)existingLi.Definition; Vex.IInstance[] instances = orgTl.Instances.ToArray(); for (int i = 0; i < instances.Length; i++) { recycledInstIds.Add(instances[i].InstanceHash); orgTl.RemoveInstance(instances[i]); MainForm.CurrentStage.InstanceManager.RemoveInstance(instances[i].InstanceHash); } } MainForm.CurrentStage.vexObject.Definitions[loadedDef.Id] = loadedDef; existingLi.Definition = loadedDef; } else { li = MainForm.CurrentStage.CreateLibraryItem(loadedDef, false); li.Date = creationTime; li.LibraryPath = workingPath + swfName; li.OriginalSourceId = loadedId; translator[loadedId] = li.Definition.Id; if (isTimeline) { result.Add(li); AddItemToLibrary(li); } } if (isTimeline) { Vex.Timeline tl = (Vex.Timeline)loadedDef; for (int i = 0; i < tl.InstanceCount; i++) { Vex.IInstance inst = tl.InstanceAt(i); if (recycledInstIds.Count > 0) { inst.InstanceHash = recycledInstIds[0]; recycledInstIds.RemoveAt(0); } inst.DefinitionId = translator[inst.DefinitionId]; inst.ParentDefinitionId = translator[inst.ParentDefinitionId]; MainForm.CurrentStage.CreateInstance((Vex.Instance)inst); } } } } } } return(result.ToArray()); }
private void MapBitmapFills(SwfCompilationUnit scu) { //scu.Tags.FindAll(tag => tag.TagType == TagType. }