From 33d63cfa9580c2ef5fd07056f1b69669d9176040 Mon Sep 17 00:00:00 2001 From: Honfika Date: Tue, 20 Aug 2013 19:22:27 +0200 Subject: [PATCH] Issue #332: show exporting execution times for AS2 --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 4 +- .../com/jpexs/decompiler/flash/TagNode.java | 41 ++++++++++++++++--- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index f959a2c8d..13f44e363 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -591,7 +591,9 @@ public class SWF { outdir += File.separator; } outdir += "scripts" + File.separator; - ret.addAll(TagNode.exportNodeAS(tags, handler, list, outdir, isPcode, evl)); + AtomicInteger cnt = new AtomicInteger(1); + int totalCount = TagNode.getTagCountRecursive(list); + ret.addAll(TagNode.exportNodeAS(tags, handler, list, outdir, isPcode, cnt, totalCount, evl)); return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/TagNode.java b/trunk/src/com/jpexs/decompiler/flash/TagNode.java index 003e98134..a3983db01 100644 --- a/trunk/src/com/jpexs/decompiler/flash/TagNode.java +++ b/trunk/src/com/jpexs/decompiler/flash/TagNode.java @@ -53,6 +53,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.logging.Level; +import java.util.logging.Logger; public class TagNode { @@ -231,11 +234,30 @@ public class TagNode { } } + public static int getTagCountRecursive(List nodeList) { + int count = 0; + + for (TagNode node : nodeList) { + if (node.subItems.isEmpty()) { + if ((node.tag instanceof ASMSource) && (node.export)) { + count += 1; + } + } else { + count += getTagCountRecursive(node.subItems); + } + + } + + return count; + } + public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, boolean isPcode) throws IOException { - return exportNodeAS(allTags, handler, nodeList, outdir, isPcode, null); + AtomicInteger cnt = new AtomicInteger(1); + int totalCount = TagNode.getTagCountRecursive(nodeList); + return exportNodeAS(allTags, handler, nodeList, outdir, isPcode, cnt, totalCount, null); } - public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, boolean isPcode, EventListener ev) throws IOException { + public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, boolean isPcode, AtomicInteger index, int count, EventListener ev) throws IOException { File dir = new File(outdir); List ret = new ArrayList<>(); if (!outdir.endsWith(File.separator)) { @@ -269,11 +291,10 @@ public class TagNode { do { retry = false; try { + long startTime = System.currentTimeMillis(); + String f = outdir + name + ".as"; File file = new File(f); - if (ev != null) { - ev.handleEvent("export", "Exporting " + f + " ..."); - } String res; ASMSource asm = ((ASMSource) node.tag); if (isPcode) { @@ -286,6 +307,14 @@ public class TagNode { try (FileOutputStream fos = new FileOutputStream(f)) { fos.write(res.getBytes("utf-8")); } + + long stopTime = System.currentTimeMillis(); + + if (ev != null) { + long time = stopTime - startTime; + ev.handleEvent("export", "Exported " + index.getAndIncrement() + "/" + count + " " + f + ", " + Helper.formatTimeSec(time)); + } + ret.add(file); } catch (Exception ex) { if (handler != null) { @@ -305,7 +334,7 @@ public class TagNode { } while (retry); } } else { - ret.addAll(exportNodeAS(allTags, handler, node.subItems, outdir + name, isPcode, ev)); + ret.addAll(exportNodeAS(allTags, handler, node.subItems, outdir + name, isPcode, index, count, ev)); } }