From 908e73e0b3a09441136f07367486f2b03fdfa50d Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 16 Oct 2013 23:11:01 +0200 Subject: [PATCH] small fixes --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 10 +++---- .../com/jpexs/decompiler/flash/abc/ABC.java | 29 ------------------- .../decompiler/flash/abc/ScriptPack.java | 2 +- .../flash/abc/types/MethodBody.java | 2 +- .../flash/abc/types/traits/Trait.java | 4 +-- .../flash/abc/types/traits/Traits.java | 14 ++++----- .../jpexs/decompiler/flash/action/Action.java | 2 +- .../action/model/clauses/WithActionItem.java | 1 - .../flash/gui/abc/DecompiledEditorPane.java | 2 +- .../src/com/jpexs/decompiler/graph/Graph.java | 6 ++-- 10 files changed, 20 insertions(+), 52 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 645a660c0..b789c0941 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -670,16 +670,14 @@ public class SWF { public Void call() throws Exception { for (MyEntry item : packs) { ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.key, item.value, outdir, abcTags, exportMode, parallel); - try { - ret.add(task.call()); - } catch (Exception ex) { - Logger.getLogger(SWF.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); - } + ret.add(task.call()); } return null; } }, Configuration.DECOMPILATION_TIMEOUT, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException ex) { + } catch (ExecutionException ex) { + Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, "Error during ABC export", ex); + } catch (InterruptedException | TimeoutException ex) { Logger.getLogger(ABC.class.getName()).log(Level.SEVERE, Helper.formatTimeToText(Configuration.DECOMPILATION_TIMEOUT) + " ActionScript export limit reached", ex); } } else { diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java index 3f0b2e317..79a5c19b5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -744,35 +744,6 @@ public class ABC { } return ret; } - /*public List export(String directory, ExportMode exportMode, List abcList, String abcStr, boolean parallel) 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 (Entry entry : packs.entrySet()) { - Future future = executor.submit(new ExportPackTask(cnt, script_info.length, entry.getKey(), entry.getValue(), directory, abcList, pcode, abcStr, parallel)); - 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) { PrintStream output; diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 6686345dd..b5a12c51e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -127,7 +127,7 @@ public class ScriptPack { } else { abc.script_info[scriptIndex].traits.traits[t].convert(null, "", abcList, abc, false, exportMode, scriptIndex, -1, writer, new ArrayList(), parallel); } - String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); + String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), false); s = Helper.hexToComments(s); fos.write(s.getBytes("utf-8")); } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index a1c04f502..0c18591e3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -114,7 +114,7 @@ public class MethodBody implements Cloneable, Serializable { HilightedTextWriter writer = new HilightedTextWriter(false); toString(path, exportMode, isStatic, scriptIndex, classIndex, abc, trait, constants, method_info, scopeStack, isStaticInitializer, writer, fullyQualifiedNames, initTraits); String src = writer.toString(); - src = Graph.removeNonRefenrencedLoopLabels(src); + src = Graph.removeNonRefenrencedLoopLabels(src, false); return src; } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java index 9e5158eca..d9faf5ece 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Trait.java @@ -176,8 +176,8 @@ public abstract class Trait implements Serializable { try (FileOutputStream fos = new FileOutputStream(fileName)) { HilightedTextWriter writer = new HilightedTextWriter(false); convertPackaged(parent, "", abcList, abc, isStatic, exportMode, scriptIndex, classIndex, writer, new ArrayList(), parallel); - String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); - fos.write(s.getBytes()); + String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), false); + fos.write(s.getBytes("utf-8")); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java index c0d1fbe89..0f8c8845f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java +++ b/trunk/src/com/jpexs/decompiler/flash/abc/types/traits/Traits.java @@ -73,7 +73,7 @@ public class Traits implements Serializable { return s; } - private class TraitConvertTask implements Callable { + private class TraitConvertTask implements Callable { Trait trait; boolean makePackages; @@ -108,7 +108,7 @@ public class Traits implements Serializable { } @Override - public String call() { + public HilightedTextWriter call() { int h = traitIndex; if (classIndex != -1) { if (!isStatic) { @@ -130,7 +130,7 @@ public class Traits implements Serializable { } else { writer.endTrait(); } - return writer.toString(); + return writer; } } @@ -146,13 +146,13 @@ public class Traits implements Serializable { } } else { ExecutorService executor = Executors.newFixedThreadPool(20); - List> futureResults = null; + List> futureResults = null; futureResults = new ArrayList<>(); for (int t = 0; t < traits.length; t++) { HilightedTextWriter writer2 = new HilightedTextWriter(writer.getIsHighlighted(), writer.getIndent()); TraitConvertTask task = new TraitConvertTask(traits[t], parent, makePackages, path, abcTags, abc, isStatic, exportMode, scriptIndex, classIndex, writer2, fullyQualifiedNames, t, parallel); - Future future = executor.submit(task); + Future future = executor.submit(task); futureResults.add(future); } @@ -161,8 +161,8 @@ public class Traits implements Serializable { writer.newLine(); } try { - String taskResult = futureResults.get(f).get(); - writer.appendWithoutIndent(taskResult); + HilightedTextWriter taskResult = futureResults.get(f).get(); + writer.appendWithoutIndent(taskResult.toString()); } catch (InterruptedException | ExecutionException ex) { Logger.getLogger(Traits.class.getName()).log(Level.SEVERE, "Error during traits converting", ex); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/Action.java b/trunk/src/com/jpexs/decompiler/flash/action/Action.java index 8df65c1c3..e3e6f65b2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/Action.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/Action.java @@ -723,7 +723,7 @@ public class Action implements GraphSourceItem { public static String actionsToSource(List actions, int version, String path, boolean highlight, int indent) { HilightedTextWriter writer = new HilightedTextWriter(highlight, indent); Action.actionsToSource(actions, SWF.DEFAULT_VERSION, ""/*FIXME*/, writer); - String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); + String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), highlight); return s; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java index 0cee9db2d..7e8aa9fa1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java @@ -47,7 +47,6 @@ public class WithActionItem extends ActionItem { @Override protected HilightedTextWriter appendTo(HilightedTextWriter writer, LocalData localData) { - String ret; writer.append("with("); scope.toString(writer, localData); writer.append(")").newLine(); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index eca1db268..7726267cd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -456,7 +456,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL for (int scriptTraitIndex : scriptLeaf.traitIndices) { script.traits.traits[scriptTraitIndex].convertPackaged(null, scriptLeaf.getPath().toString(), abcList, abc, false, ExportMode.SOURCE, scriptIndex, -1, writer, new ArrayList(), Configuration.getConfig("parallelSpeedUp", true)); } - String s = Graph.removeNonRefenrencedLoopLabels(writer.toString()); + String s = Graph.removeNonRefenrencedLoopLabels(writer.toString(), true); hilightedCode = s; cache.put(scriptLeaf, new CachedDecompilation(hilightedCode)); } diff --git a/trunk/src/com/jpexs/decompiler/graph/Graph.java b/trunk/src/com/jpexs/decompiler/graph/Graph.java index e988620b8..12c96d37f 100644 --- a/trunk/src/com/jpexs/decompiler/graph/Graph.java +++ b/trunk/src/com/jpexs/decompiler/graph/Graph.java @@ -2156,17 +2156,17 @@ public class Graph { return writer; } - public static String removeNonRefenrencedLoopLabels(String source) { + public static String removeNonRefenrencedLoopLabels(String source, boolean hilighted) { String[] parts = source.split("\r\n"); String labelPattern = "loop(switch)?[0-9]*:"; StringBuilder ret = new StringBuilder(); for (int p = 0; p < parts.length; p++) { - String strippedP = Highlighting.stripHilights(parts[p]).trim(); + String strippedP = (hilighted ? Highlighting.stripHilights(parts[p]) : parts[p]).trim(); if (strippedP.matches(labelPattern)) {//endsWith(":") && (!strippedP.startsWith("case ")) && (!strippedP.equals("default:"))) { String loopname = strippedP.substring(0, strippedP.length() - 1); boolean dorefer = false; for (int q = p + 1; q < parts.length; q++) { - String strippedQ = Highlighting.stripHilights(parts[q]).trim(); + String strippedQ = (hilighted ? Highlighting.stripHilights(parts[q]) : parts[q]).trim(); if (strippedQ.equals("break " + loopname.replace("switch", "") + ";")) { dorefer = true; break;