From 791aa8dfefa645dc3086b8e1839b4acb8aca2a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Mon, 24 Jun 2013 21:01:10 +0200 Subject: [PATCH] Issue #127 Drag-drop exportable item from tree --- .../com/jpexs/decompiler/flash/abc/ABC.java | 28 +++++++++++++++---- .../decompiler/flash/abc/ScriptPack.java | 7 +++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index c95fe2f58..624235529 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -38,8 +38,11 @@ import java.util.List; import java.util.Map; import java.util.Random; import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; @@ -659,7 +662,7 @@ public class ABC { export(directory, pcode, abcList, "", paralel); } - private class ExportPackTask implements Runnable { + private class ExportPackTask implements Callable { ScriptPack pack; String directory; @@ -683,34 +686,49 @@ public class ABC { this.paralel = paralel; } + @Override - public void run() { + public File call() throws Exception { try { - pack.export(directory, abcList, pcode, paralel); + return pack.export(directory, abcList, pcode, paralel); } catch (IOException ex) { Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, null, ex); } synchronized (ABC.class) { informListeners("export", "Exported " + informStr + " script " + index.getAndIncrement() + "/" + count + " " + path); } + return null; } } - public void export(String directory, boolean pcode, List abcList, String abcStr, boolean paralel) throws IOException { + public List export(String directory, boolean pcode, List abcList, String abcStr, boolean paralel) throws IOException { ExecutorService executor = Executors.newFixedThreadPool(20); + List> futureResults = new ArrayList<>(); AtomicInteger cnt = new AtomicInteger(1); for (int i = 0; i < script_info.length; i++) { HashMap packs = script_info[i].getPacks(this, i); for (String path : packs.keySet()) { - executor.execute(new ExportPackTask(cnt, script_info.length, path, packs.get(path), directory, abcList, pcode, abcStr, paralel)); + Future future = executor.submit(new ExportPackTask(cnt, script_info.length, path, packs.get(path), directory, abcList, pcode, abcStr, paralel)); + futureResults.add(future); } } + + List ret=new ArrayList<>(); + for (int f = 0; f < futureResults.size(); f++) { + try { + ret.add(futureResults.get(f).get()); + } catch (InterruptedException | ExecutionException ex) { + Logger.getLogger(Traits.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); + } + } + try { executor.shutdown(); executor.awaitTermination(30, TimeUnit.MINUTES); } catch (InterruptedException ex) { Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "30 minutes ActionScript export limit reached", ex); } + return ret; } public void dump(OutputStream os) { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 0586c42ff..e4c698ffc 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -96,16 +96,16 @@ public class ScriptPack { return Helper.joinStrings(pathParts, File.separator); } - public void export(String directory, List abcList, boolean pcode, boolean paralel) throws IOException { + public File export(String directory, List abcList, boolean pcode, boolean paralel) throws IOException { String scriptName = getPathScriptName(); String packageName = getPathPackage(); - File outDir = new File(directory + File.separatorChar + makeDirPath(packageName)); if (!outDir.exists()) { outDir.mkdirs(); } String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + ".as"; - try (FileOutputStream fos = new FileOutputStream(fileName)) { + File file = new File(fileName); + try (FileOutputStream fos = new FileOutputStream(file)) { for (int t : traitIndices) { Multiname name = abc.script_info[scriptIndex].traits.traits[t].getName(abc); Namespace ns = name.getNamespace(abc.constants); @@ -116,5 +116,6 @@ public class ScriptPack { } } } + return file; } }