diff --git a/CHANGELOG.md b/CHANGELOG.md index 4478c0381..62cf2ac47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. texts are more readable and searchable - [#2333] Changing Shape tag type (DefineShape, DefineShape2, ...) - Changing PlaceObject tag type (PlaceObject, PlaceObject2, ...) +- AS2 - Information about need of decompiling all scripts to detect uninitialized class fields ### Fixed - [#2319] AS3 Compound assignments problems in some cases @@ -29,6 +30,7 @@ All notable changes to this project will be documented in this file. - [#2330] Windows EXE launcher (+ CLI) does not respect current working directory - [#2335] AS3 direct editation - Type coercion of `&&` and `||` operators - [#2334] AS1/2 P-code export - Do not export on(xxx) header +- [#2338] AS decompiling threads got stuck after cancelling / timeout ## [21.1.0] - 2024-09-23 ### Added @@ -3614,6 +3616,7 @@ Major version of SWF to XML export changed to 2. [#2330]: https://www.free-decompiler.com/flash/issues/2330 [#2335]: https://www.free-decompiler.com/flash/issues/2335 [#2334]: https://www.free-decompiler.com/flash/issues/2334 +[#2338]: https://www.free-decompiler.com/flash/issues/2338 [#943]: https://www.free-decompiler.com/flash/issues/943 [#1812]: https://www.free-decompiler.com/flash/issues/1812 [#2287]: https://www.free-decompiler.com/flash/issues/2287 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java index 943d114c0..3c7770bf9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/DecompilerPool.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.helpers.HighlightedText; import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.treeitems.Openable; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.ImmediateFuture; import java.util.ArrayList; import java.util.List; @@ -79,13 +80,18 @@ public class DecompilerPool { * @return Future */ public Future submitTask(ASMSource src, ActionList actions, ScriptDecompiledListener listener) { + CancellableWorker w = CancellableWorker.getCurrent(); Callable callable = new Callable() { @Override public HighlightedText call() throws Exception { + if (w != null) { + CancellableWorker.assignThreadToWorker(Thread.currentThread(), w); + } + if (listener != null) { listener.onStart(); } - + HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), true); writer.startFunction("!script"); src.getActionScriptSource(writer, actions); @@ -119,9 +125,13 @@ public class DecompilerPool { * @return Future */ public Future submitTask(AbcIndexing abcIndex, ScriptPack pack, ScriptDecompiledListener listener) { + CancellableWorker w = CancellableWorker.getCurrent(); Callable callable = new Callable() { @Override public HighlightedText call() throws Exception { + if (w != null) { + CancellableWorker.assignThreadToWorker(Thread.currentThread(), w); + } if (listener != null) { listener.onStart(); } @@ -211,9 +221,25 @@ public class DecompilerPool { openableToFutures.put(swf, new ArrayList<>()); } openableToFutures.get(swf).add(future); + + CancellableWorker w = CancellableWorker.getCurrent(); + + if (w != null) { + if (w.isCancelled()) { + throw new InterruptedException(); + } + w.addCancelListener(new Runnable() { + @Override + public void run() { + w.removeCancelListener(this); + future.cancel(true); + } + }); + } + try { return future.get(); - } catch (InterruptedException ex) { + } catch (InterruptedException ex) { future.cancel(true); throw ex; } catch (ExecutionException ex) { @@ -243,7 +269,7 @@ public class DecompilerPool { if (!openableToFutures.containsKey(openable)) { openableToFutures.put(openable, new ArrayList<>()); } - openableToFutures.get(openable).add(future); + openableToFutures.get(openable).add(future); try { return future.get(); } catch (InterruptedException ex) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index a2bd3a957..94d8a37f0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -173,6 +173,7 @@ import com.jpexs.decompiler.graph.model.IfItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.ByteArrayRange; import com.jpexs.helpers.Cache; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.ImmediateFuture; import com.jpexs.helpers.NulStream; @@ -658,6 +659,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { */ private final HashSet listeners = new HashSet<>(); + /** + * Lock for characters synchronization + */ + private final Object charactersLock = new Object(); + /** * Sets main GFX exporterinfo tag * @@ -945,50 +951,52 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { * @param withImported Include tags imported with importasset/2 tag? * @return Character id to character map */ - public synchronized Map getCharacters(boolean withImported) { - if (characters == null || charactersWithImported == null) { - if (destroyed) { - return new HashMap<>(); - } - Map chars = new HashMap<>(); - Map charsWithImported = new HashMap<>(); - Map> charIdtags = new HashMap<>(); - Map eimages = new HashMap<>(); - parseCharacters(getTags(), eimages, chars, charIdtags); - charsWithImported.putAll(chars); - for (int importedCharacterId : importedCharacterIds.keySet()) { - int exportedCharacterId = importedCharacterIds.get(importedCharacterId); - SWF importedSwf = importedCharacterSourceSwfs.get(importedCharacterId); - CharacterTag exportedCharacter = importedSwf.getCharacter(exportedCharacterId); - charsWithImported.put(importedCharacterId, exportedCharacter); - charIdtags.put(importedCharacterId, importedSwf.getCharacterIdTags(exportedCharacterId)); - //FIXME? eimages + public Map getCharacters(boolean withImported) { + synchronized (charactersLock) { + if (characters == null || charactersWithImported == null) { + if (destroyed) { + return new HashMap<>(); + } + Map chars = new HashMap<>(); + Map charsWithImported = new HashMap<>(); + Map> charIdtags = new HashMap<>(); + Map eimages = new HashMap<>(); + parseCharacters(getTags(), eimages, chars, charIdtags); + charsWithImported.putAll(chars); + for (int importedCharacterId : importedCharacterIds.keySet()) { + int exportedCharacterId = importedCharacterIds.get(importedCharacterId); + SWF importedSwf = importedCharacterSourceSwfs.get(importedCharacterId); + CharacterTag exportedCharacter = importedSwf.getCharacter(exportedCharacterId); + charsWithImported.put(importedCharacterId, exportedCharacter); + charIdtags.put(importedCharacterId, importedSwf.getCharacterIdTags(exportedCharacterId)); + //FIXME? eimages - charsWithImported.get(importedCharacterId).setImported(true, true); - for (CharacterIdTag chi : charIdtags.get(importedCharacterId)) { - if (chi instanceof Tag) { - ((Tag) chi).setImported(true, true); + charsWithImported.get(importedCharacterId).setImported(true, true); + for (CharacterIdTag chi : charIdtags.get(importedCharacterId)) { + if (chi instanceof Tag) { + ((Tag) chi).setImported(true, true); + } } } - } - Map charToId = new IdentityHashMap<>(); - for (int id : charsWithImported.keySet()) { - charToId.put(charsWithImported.get(id), id); - } - for (int id : charIdtags.keySet()) { - for (CharacterIdTag ch : charIdtags.get(id)) { - charToId.put(ch, id); + Map charToId = new IdentityHashMap<>(); + for (int id : charsWithImported.keySet()) { + charToId.put(charsWithImported.get(id), id); } + for (int id : charIdtags.keySet()) { + for (CharacterIdTag ch : charIdtags.get(id)) { + charToId.put(ch, id); + } + } + + characters = Collections.unmodifiableMap(chars); + charactersWithImported = Collections.unmodifiableMap(charsWithImported); + characterToId = Collections.unmodifiableMap(charToId); + characterIdTags = Collections.unmodifiableMap(charIdtags); + externalImages2 = Collections.unmodifiableMap(eimages); } - characters = Collections.unmodifiableMap(chars); - charactersWithImported = Collections.unmodifiableMap(charsWithImported); - characterToId = Collections.unmodifiableMap(charToId); - characterIdTags = Collections.unmodifiableMap(charIdtags); - externalImages2 = Collections.unmodifiableMap(eimages); + return withImported ? charactersWithImported : characters; } - - return withImported ? charactersWithImported : characters; } /** @@ -1270,11 +1278,11 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { if (fontClass == null) { return null; } - CharacterTag t = getCharacterByClass(fontClass); + CharacterTag t = getCharacterByClass(fontClass); if (t instanceof FontTag) { return (FontTag) t; } - + return null; } @@ -2313,7 +2321,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { ImportTag importTag = (ImportTag) t; String url = importTag.getUrl(); - + SWF iSwf; if (importedSwfs.containsKey(url)) { iSwf = importedSwfs.get(url); @@ -5386,7 +5394,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { List packs = getAS3Packs(); int i = 0; for (ScriptPack s : packs) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } i++; @@ -5419,7 +5427,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { List packs = getAS3Packs(); int i = 0; for (ScriptPack s : packs) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } i++; @@ -5623,7 +5631,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { List names = new ArrayList<>(asms.keySet()); Collections.sort(names); for (String name : names) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } informListeners("generate_swd", name); @@ -5720,7 +5728,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { List names = new ArrayList<>(asms.keySet()); Collections.sort(names); for (String name : names) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } informListeners("generate_swd", name); @@ -6169,11 +6177,18 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { /** * Calculates uninitialized class traits in AS2. + * + * @throws java.lang.InterruptedException On interruption */ - public void calculateAs2UninitializedClassTraits() { + public void calculateAs2UninitializedClassTraits() throws InterruptedException { uninitializedAs2ClassTraits = new HashMap<>(); UninitializedClassFieldsDetector detector = new UninitializedClassFieldsDetector(); - uninitializedAs2ClassTraits = detector.calculateAs2UninitializedClassTraits(this); + try { + uninitializedAs2ClassTraits = detector.calculateAs2UninitializedClassTraits(this); + } catch (Throwable t) { + uninitializedAs2ClassTraits = null; + throw t; + } } /** @@ -6181,12 +6196,26 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { * * @return Map of class name to map of trait name to trait */ - public synchronized Map> getUninitializedAs2ClassTraits() { - if (uninitializedAs2ClassTraits == null) { + public synchronized Map> getUninitializedAs2ClassTraits() throws InterruptedException { + if (CancellableWorker.isInterrupted()) { + throw new InterruptedException(); + } + if (uninitializedAs2ClassTraits == null) { calculateAs2UninitializedClassTraits(); } return uninitializedAs2ClassTraits; } + + public boolean needsCalculatingAS2UninitializeClassTraits(ASMSource src) { + if (!isAS3()) { + if (src instanceof DoInitActionTag) { + if (uninitializedAs2ClassTraits == null) { + return true; + } + } + } + return false; + } /** * Gets SWF (self) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java index dd5108c14..3e37a0a1c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -275,6 +275,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.SHAPERECORD; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.FakeMemoryInputStream; import com.jpexs.helpers.Helper; import com.jpexs.helpers.ImmediateFuture; @@ -1416,7 +1417,7 @@ public class SWFInputStream implements AutoCloseable { * @throws InterruptedException On interrupt */ public List readTagList(Timelined timelined, int level, boolean parallel, boolean skipUnusualTags, boolean parseTags, boolean lazy) throws IOException, InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java index 2a3df55d3..593bd92a1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ScriptPack.java @@ -466,7 +466,7 @@ public class ScriptPack extends AS3ClassTreeItem { writer.suspendMeasure(); int timeout = Configuration.decompilationTimeoutFile.get(); try { - CancellableWorker.call(new Callable() { + CancellableWorker.call("script.scriptPack.toSource", new Callable() { @Override public Void call() throws Exception { convert(abcIndex, new NulWriter(), traits, convertData, exportMode, parallel); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 8a4058fa5..c6a5934e1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -305,6 +305,7 @@ import com.jpexs.decompiler.graph.SimpleValue; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.decompiler.graph.TypeItem; import com.jpexs.decompiler.graph.model.ScriptEndItem; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.LinkedIdentityHashSet; import com.jpexs.helpers.Reference; @@ -3458,7 +3459,7 @@ public class AVM2Code implements Cloneable { toVisit.add(ip); toVisitLast.add(lastIp); while (!toVisit.isEmpty()) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } ip = toVisit.remove(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java index aca8a6f13..3381fba8c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java @@ -40,6 +40,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.NotCompileTimeItem; import com.jpexs.decompiler.graph.ScopeStack; import com.jpexs.decompiler.graph.TranslateException; +import com.jpexs.helpers.CancellableWorker; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -107,7 +108,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter { AVM2LocalData localData = newLocalData(scriptIndex, abc, abc.constants, body, isStatic, classIndex); int localReservedCount = body.getLocalReservedCount(); for (int i = 0; i < code.code.size(); i++) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java index 8a38a6ce2..6733e545d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java @@ -44,6 +44,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateException; import com.jpexs.decompiler.graph.TranslateStack; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.util.ArrayList; import java.util.HashSet; @@ -134,7 +135,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { Reference assignmentRef = new Reference<>(null); while (setReg > -1) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -200,7 +201,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { AVM2Code code = body.getCode(); for (int i = 0; i < code.code.size(); i++) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -271,7 +272,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { toVisitStacks.add(stack); outer: while (!toVisit.isEmpty()) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java index f77c87098..807340713 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java @@ -42,6 +42,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateException; import com.jpexs.decompiler.graph.TranslateStack; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.util.ArrayList; import java.util.Arrays; @@ -131,7 +132,7 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { Reference assignmentRef = new Reference<>(null); while (setReg > -1) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -290,7 +291,7 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { toVisitStacks.add(stack); outer: while (!toVisit.isEmpty()) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java index 9c1b686ef..ce2d74aec 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java @@ -78,6 +78,7 @@ import com.jpexs.decompiler.flash.ecma.NotCompileTime; import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.helpers.collections.FixItemCounterStack; import com.jpexs.decompiler.graph.TranslateException; +import com.jpexs.helpers.CancellableWorker; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -135,7 +136,7 @@ public class AVM2DeobfuscatorSimple extends AVM2DeobfuscatorZeroJumpsNullPushes int localReservedCount = body.getLocalReservedCount(); for (int i = 0; i < code.code.size(); i++) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java index 02dc2fb08..eb3353220 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java @@ -99,6 +99,7 @@ import com.jpexs.decompiler.graph.ScopeStack; import com.jpexs.decompiler.graph.TranslateException; import com.jpexs.decompiler.graph.model.FalseItem; import com.jpexs.decompiler.graph.model.TrueItem; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.util.ArrayList; import java.util.HashMap; @@ -209,7 +210,7 @@ public class AVM2DeobfuscatorSimpleOld extends AVM2DeobfuscatorZeroJumpsNullPush int localReservedCount = body.getLocalReservedCount(); Set importantOffsets = code.getImportantOffsets(body, isStatic); for (int i = 0; i < code.code.size(); i++) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorZeroJumpsNullPushes.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorZeroJumpsNullPushes.java index 23898f4b1..6439a3ada 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorZeroJumpsNullPushes.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorZeroJumpsNullPushes.java @@ -37,6 +37,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushUndefinedIns; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.helpers.SWFDecompilerAdapter; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.util.Set; @@ -83,7 +84,7 @@ public class AVM2DeobfuscatorZeroJumpsNullPushes extends SWFDecompilerAdapter { AVM2Instruction ins = code.code.get(i); if (ins.definition instanceof JumpIns) { if (ins.operands[0] == 0) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -142,7 +143,7 @@ public class AVM2DeobfuscatorZeroJumpsNullPushes extends SWFDecompilerAdapter { if (ins2.definition instanceof PopIns && !offsets.contains(ins2.getAddress()) && isSimplePush(ins1.definition)) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -159,7 +160,7 @@ public class AVM2DeobfuscatorZeroJumpsNullPushes extends SWFDecompilerAdapter { && !offsets.contains(ins2.getAddress()) && !offsets.contains(ins1.getAddress()) && isSimplePush(ins0.definition)) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } code.removeInstruction(i - 2, body); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java index a49479211..67258e3e8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java @@ -42,6 +42,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter; import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst; import com.jpexs.decompiler.flash.abc.types.traits.Traits; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.io.IOException; import java.io.Reader; @@ -1605,7 +1606,7 @@ public class ASM3Parser { } for (OffsetItem oi : offsetItems) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } if (!labelToOffset.containsKey(oi.label)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java index cffa54c17..547671321 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/ActionScript3Parser.java @@ -119,6 +119,7 @@ import com.jpexs.decompiler.graph.model.SwitchItem; import com.jpexs.decompiler.graph.model.TernarOpItem; import com.jpexs.decompiler.graph.model.TrueItem; import com.jpexs.decompiler.graph.model.WhileItem; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; import com.jpexs.helpers.utf8.Utf8Helper; @@ -473,7 +474,7 @@ public class ActionScript3Parser { } private ParsedSymbol lex() throws IOException, AVM2ParseException, InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } ParsedSymbol ret = lexer.lex(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 39cf7bcec..e3f7094b4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -482,7 +482,7 @@ public final class MethodBody implements Cloneable { } }; if (firstLevel) { - CancellableWorker.call(callable, timeout, TimeUnit.SECONDS); + CancellableWorker.call("script.methodbody.convert", callable, timeout, TimeUnit.SECONDS); } else { callable.call(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index 399c354ca..19dfbfe43 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -986,12 +986,13 @@ public abstract class Action implements GraphSourceItem { final SWF swf = asm == null ? null : asm.getSwf(); final int version = swf == null ? SWF.DEFAULT_VERSION : swf.version; try { - tree = CancellableWorker.call(new Callable>() { + tree = CancellableWorker.call("script.actionsToSource", new Callable>() { @Override public List call() throws Exception { int staticOperation = 0; boolean insideDoInitAction = (asm instanceof DoInitActionTag); - List tree = actionsToTree(uninitializedClassTraits, insideDoInitAction, false, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path, charset); + List + tree = actionsToTree(uninitializedClassTraits, insideDoInitAction, false, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path, charset); SWFDecompilerPlugin.fireActionTreeCreated(tree, swf); for (ActionTreeOperation treeOperation : treeOperations) { treeOperation.run(tree); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java index d92f24651..282bd6459 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -84,7 +84,7 @@ public class ActionListReader { */ public static ActionList readActionListTimeout(final List listeners, final SWFInputStream sis, final int version, final int ip, final int endIp, final String path, final int deobfuscationMode) throws IOException, InterruptedException, TimeoutException { try { - ActionList actions = CancellableWorker.call(new Callable() { + ActionList actions = CancellableWorker.call("script.readActionList", new Callable() { @Override public ActionList call() throws IOException, InterruptedException { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/as2/UninitializedClassFieldsDetector.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/as2/UninitializedClassFieldsDetector.java index 18c9267a5..094b2201d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/as2/UninitializedClassFieldsDetector.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/as2/UninitializedClassFieldsDetector.java @@ -34,6 +34,7 @@ import com.jpexs.decompiler.flash.tags.DoInitActionTag; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.graph.AbstractGraphTargetVisitor; import com.jpexs.decompiler.graph.GraphTargetItem; +import com.jpexs.helpers.CancellableWorker; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; @@ -185,8 +186,9 @@ public class UninitializedClassFieldsDetector { * * @param swf SWF * @return Map of class name to map of trait name to trait + * @throws java.lang.InterruptedException On interruption */ - public Map> calculateAs2UninitializedClassTraits(SWF swf) { + public Map> calculateAs2UninitializedClassTraits(SWF swf) throws InterruptedException { if (swf.isAS3()) { return new HashMap<>(); } @@ -200,6 +202,9 @@ public class UninitializedClassFieldsDetector { //get all assigned traits and inheritance tree for (String key : asms.keySet()) { + if (CancellableWorker.isInterrupted()) { + throw new InterruptedException(); + } ASMSource asm = asms.get(key); if (asm instanceof DoInitActionTag) { DoInitActionTag doi = (DoInitActionTag) asm; @@ -282,6 +287,9 @@ public class UninitializedClassFieldsDetector { //Detect this.x assigns for (String key : asms.keySet()) { + if (CancellableWorker.isInterrupted()) { + throw new InterruptedException(); + } ASMSource asm = asms.get(key); if (asm instanceof DoInitActionTag) { DoInitActionTag doi = (DoInitActionTag) asm; @@ -335,6 +343,9 @@ public class UninitializedClassFieldsDetector { //getting static classname.x assigns for (String key : asms.keySet()) { + if (CancellableWorker.isInterrupted()) { + throw new InterruptedException(); + } ASMSource asm = asms.get(key); List tree = asm.getActionsToTree(); for (GraphTargetItem item : tree) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java index 6c31ac1ad..d78d1ffbf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java @@ -83,6 +83,7 @@ import com.jpexs.decompiler.flash.helpers.collections.FixItemCounterStack; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.model.FalseItem; import com.jpexs.decompiler.graph.model.PushItem; +import com.jpexs.helpers.CancellableWorker; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -132,7 +133,7 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { } } - private boolean removeGetTimes(FastActionList actions) { + private boolean removeGetTimes(FastActionList actions) throws InterruptedException { if (actions.isEmpty()) { return false; } @@ -215,7 +216,7 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { FastActionListIterator iterator = actions.iterator(); boolean first = true; while (iterator.hasNext()) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java index f11223c67..91067bfd7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf4.ActionJump; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.graph.GraphSourceItemContainer; +import com.jpexs.helpers.CancellableWorker; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -582,7 +583,7 @@ public class FastActionList implements Collection { /** * Removes the unreachable actions. */ - public void removeUnreachableActions() { + public void removeUnreachableActions() throws InterruptedException { ActionItem item = firstItem; if (item == null) { return; @@ -629,7 +630,7 @@ public class FastActionList implements Collection { * @param jumpTarget Jump target * @return Unreachable action count */ - public int getUnreachableActionCount(ActionItem jump, ActionItem jumpTarget) { + public int getUnreachableActionCount(ActionItem jump, ActionItem jumpTarget) throws InterruptedException { ActionItem item = firstItem; if (item == null) { return 0; @@ -688,7 +689,7 @@ public class FastActionList implements Collection { * @param jump Jump * @param jumpTarget Jump target */ - private void updateReachableFlags(ActionItem jump, ActionItem jumpTarget) { + private void updateReachableFlags(ActionItem jump, ActionItem jumpTarget) throws InterruptedException { if (firstItem == null) { return; } @@ -699,9 +700,12 @@ public class FastActionList implements Collection { ActionItem firstItem2 = firstItem; boolean modified = true; while (modified) { + if (CancellableWorker.isInterrupted()) { + throw new InterruptedException(); + } modified = false; ActionItem item = firstItem2; - do { + do { ActionItem next = item.next; //ActionItem alternativeNext = null; Action action = item.action; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java index eacabe4ad..f61d75168 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/script/ActionScript2Parser.java @@ -165,6 +165,7 @@ import com.jpexs.decompiler.graph.model.SwitchItem; import com.jpexs.decompiler.graph.model.TernarOpItem; import com.jpexs.decompiler.graph.model.TrueItem; import com.jpexs.decompiler.graph.model.WhileItem; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.io.IOException; import java.io.StringReader; @@ -365,7 +366,7 @@ public class ActionScript2Parser { } private ParsedSymbol lex() throws IOException, ActionParseException, InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } ParsedSymbol ret = lexer.lex(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/BinaryDataExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/BinaryDataExporter.java index 1e5a996c1..2b7401e63 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/BinaryDataExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/BinaryDataExporter.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.exporters.settings.BinaryDataExportSettings; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.BinaryDataInterface; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.io.BufferedOutputStream; @@ -86,7 +87,7 @@ public class BinaryDataExporter { */ public List exportBinaryData(AbortRetryIgnoreHandler handler, String outdir, List binaryDatas, BinaryDataExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -133,7 +134,7 @@ public class BinaryDataExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/Font4Exporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/Font4Exporter.java index d9ec37257..495bdb92a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/Font4Exporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/Font4Exporter.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.exporters.modes.Font4ExportMode; import com.jpexs.decompiler.flash.exporters.settings.Font4ExportSettings; import com.jpexs.decompiler.flash.tags.DefineFont4Tag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.io.BufferedOutputStream; @@ -50,7 +51,7 @@ public class Font4Exporter { public List exportFonts(AbortRetryIgnoreHandler handler, String outdir, ReadOnlyTagList tags, final Font4ExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -103,7 +104,7 @@ public class Font4Exporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java index 528d0fa6a..ed187f1e7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FontExporter.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.FontTag; import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.types.SHAPE; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import fontastic.FGlyph; @@ -65,7 +66,7 @@ public class FontExporter { public List exportFonts(AbortRetryIgnoreHandler handler, String outdir, ReadOnlyTagList tags, final FontExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -118,7 +119,7 @@ public class FontExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java index 6df36b029..aaefe2d3f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/FrameExporter.java @@ -57,6 +57,7 @@ import com.jpexs.decompiler.flash.types.filters.FILTER; import com.jpexs.decompiler.flash.types.filters.GLOWFILTER; import com.jpexs.decompiler.flash.types.filters.GRADIENTBEVELFILTER; import com.jpexs.decompiler.flash.types.filters.GRADIENTGLOWFILTER; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.SerializableImage; @@ -200,7 +201,7 @@ public class FrameExporter { @Override public boolean hasNext() { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return false; } return fframes.size() > pos; @@ -226,7 +227,7 @@ public class FrameExporter { int fframe = fframes.get(pos++); BufferedImage result = SWF.frameToImageGet(tim, fframe, 0, null, 0, tim.displayRect, new Matrix(), null, backgroundColor == null && !usesTransparency ? Color.white : backgroundColor, settings.zoom, true).getBufferedImage(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return null; } if (evl != null) { @@ -239,7 +240,7 @@ public class FrameExporter { public List exportFrames(AbortRetryIgnoreHandler handler, String outdir, final SWF swf, int containerId, List frames, final FrameExportSettings settings, final EventListener evl) throws IOException, InterruptedException { final List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -318,7 +319,7 @@ public class FrameExporter { }, handler).run(); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } @@ -614,7 +615,7 @@ public class FrameExporter { } g.dispose(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return; } pos++; @@ -774,7 +775,7 @@ public class FrameExporter { Stack clipDepths = new Stack<>(); for (int frame : frames) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } result.append("\t\tcase ").append(frame).append(":\r\n"); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java index d9968ce02..e2315b16d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ImageExporter.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.HasSeparateAlphaChannel; import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.enums.ImageFormat; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.awt.Dimension; @@ -55,7 +56,7 @@ public class ImageExporter { public List exportImages(AbortRetryIgnoreHandler handler, String outdir, ReadOnlyTagList tags, ImageExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -170,7 +171,7 @@ public class ImageExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MorphShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MorphShapeExporter.java index a9428f4e6..2f1cca08c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MorphShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MorphShapeExporter.java @@ -42,6 +42,7 @@ import com.jpexs.decompiler.flash.timeline.Timeline; import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.RGB; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.SerializableImage; @@ -72,7 +73,7 @@ public class MorphShapeExporter { //TODO: implement morphshape export. How to handle 65536 frames? public List exportMorphShapes(AbortRetryIgnoreHandler handler, final String outdir, ReadOnlyTagList tags, final MorphShapeExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -257,7 +258,7 @@ public class MorphShapeExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } if (evl != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java index 1f81a83ae..7b1552de5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/MovieExporter.java @@ -33,6 +33,7 @@ import com.jpexs.decompiler.flash.flv.VIDEODATA; import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.VideoFrameTag; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.io.BufferedOutputStream; @@ -59,7 +60,7 @@ public class MovieExporter { public List exportMovies(AbortRetryIgnoreHandler handler, String outdir, ReadOnlyTagList tags, final MovieExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } if (tags.isEmpty()) { @@ -109,7 +110,7 @@ public class MovieExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } if (evl != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java index a28e00335..23c7063cc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/ShapeExporter.java @@ -40,6 +40,7 @@ import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.RGB; import com.jpexs.decompiler.flash.types.SHAPE; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.SerializableImage; @@ -69,7 +70,7 @@ public class ShapeExporter { public List exportShapes(AbortRetryIgnoreHandler handler, final String outdir, final SWF swf, ReadOnlyTagList tags, final ShapeExportSettings settings, EventListener evl, double unzoom) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -180,7 +181,7 @@ public class ShapeExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } if (evl != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java index 96cb0bdfb..407fff25b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SoundExporter.java @@ -38,6 +38,7 @@ import com.jpexs.decompiler.flash.timeline.SoundStreamFrameRange; import com.jpexs.decompiler.flash.types.sound.SoundExportFormat; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.io.BufferedOutputStream; @@ -73,7 +74,7 @@ public class SoundExporter { public List exportSounds(AbortRetryIgnoreHandler handler, String outdir, List tags, final SoundExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -133,7 +134,7 @@ public class SoundExporter { ret.add(file); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java index f355337e5..0a6e9ee55 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/SymbolClassExporter.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.exporters.settings.SymbolClassExportSettings; import com.jpexs.decompiler.flash.tags.ExportAssetsTag; import com.jpexs.decompiler.flash.tags.SymbolClassTag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.utf8.Utf8OutputStreamWriter; @@ -46,7 +47,7 @@ public class SymbolClassExporter { public List exportNames(AbortRetryIgnoreHandler handler, final String outdir, ReadOnlyTagList tags, SymbolClassExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -79,7 +80,7 @@ public class SymbolClassExporter { writer.append(sct.tags.get(i) + ";" + sct.names.get(i) + Helper.newLine); } } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java index a3bce468c..6a51c999e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/TextExporter.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.TextTag; import com.jpexs.decompiler.flash.types.CXFORMWITHALPHA; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import com.jpexs.helpers.utf8.Utf8Helper; @@ -52,7 +53,7 @@ public class TextExporter { public List exportTexts(AbortRetryIgnoreHandler handler, String outdir, ReadOnlyTagList tags, final TextExportSettings settings, EventListener evl) throws IOException, InterruptedException { List ret = new ArrayList<>(); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -130,7 +131,7 @@ public class TextExporter { fos.write(Utf8Helper.getBytes(Helper.newLine + Configuration.textExportSingleFileSeparator.get() + Helper.newLine)); }, handler).run(); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } @@ -159,7 +160,7 @@ public class TextExporter { }, handler).run(); ret.add(file); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } if (evl != null) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java index aa24433be..038214d23 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS2ScriptExporter.java @@ -118,11 +118,11 @@ public class AS2ScriptExporter { if (!parallel || tasks.size() < 2) { try { - CancellableWorker.call(new Callable() { + CancellableWorker.call("as2scriptexport", new Callable() { @Override public Void call() throws Exception { for (ExportScriptTask task : tasks) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -140,19 +140,23 @@ public class AS2ScriptExporter { ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount()); List> futureResults = new ArrayList<>(); for (ExportScriptTask task : tasks) { - Future future = executor.submit(task); + Future future = executor.submit(task); futureResults.add(future); - } + } try { - executor.shutdown(); + executor.shutdown(); if (!executor.awaitTermination(Configuration.exportTimeout.get(), TimeUnit.SECONDS)) { logger.log(Level.SEVERE, "{0} ActionScript export limit reached", Helper.formatTimeToText(Configuration.exportTimeout.get())); + + for (ExportScriptTask task : tasks) { + CancellableWorker.cancelThread(task.thread); + } } } catch (InterruptedException ex) { //ignored } finally { - executor.shutdownNow(); + executor.shutdownNow(); } for (int f = 0; f < futureResults.size(); f++) { @@ -163,9 +167,11 @@ public class AS2ScriptExporter { } catch (InterruptedException ex) { //ignored } catch (ExecutionException ex) { - logger.log(Level.SEVERE, "Error during ABC export", ex); + if (!(ex.getCause() instanceof InterruptedException)) { + logger.log(Level.SEVERE, "Error during ActionScript export", ex); + } } - } + } } return ret; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java index 5c4895701..6d728bcc4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/AS3ScriptExporter.java @@ -535,11 +535,11 @@ public class AS3ScriptExporter { if (!parallel || tasks.size() < 2) { try { - CancellableWorker.call(new Callable() { + CancellableWorker.call("as3scriptexport", new Callable() { @Override public Void call() throws Exception { for (ExportPackTask task : tasks) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -565,6 +565,10 @@ public class AS3ScriptExporter { executor.shutdown(); if (!executor.awaitTermination(Configuration.exportTimeout.get(), TimeUnit.SECONDS)) { logger.log(Level.SEVERE, "{0} ActionScript export limit reached", Helper.formatTimeToText(Configuration.exportTimeout.get())); + + for (ExportPackTask task : tasks) { + CancellableWorker.cancelThread(task.thread); + } } } catch (InterruptedException ex) { //ignored @@ -587,7 +591,7 @@ public class AS3ScriptExporter { if (exportSettings.exportEmbedFlaMode || exportSettings.exportEmbed) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } @@ -638,27 +642,27 @@ public class AS3ScriptExporter { try { BinaryDataExporter bde = new BinaryDataExporter(); bde.exportBinaryData(handler, ASSETS_DIR, rttl, new BinaryDataExportSettings(BinaryDataExportMode.RAW), evl); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } ImageExporter ie = new ImageExporter(); ie.exportImages(handler, ASSETS_DIR, rttl, new ImageExportSettings(ImageExportMode.PNG_GIF_JPEG), evl); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } SoundExporter se = new SoundExporter(); se.exportSounds(handler, ASSETS_DIR, rttl, new SoundExportSettings(SoundExportMode.MP3_WAV, exportSettings.resampleWav), evl); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } FontExporter fe = new FontExporter(); fe.exportFonts(handler, ASSETS_DIR, rttl, new FontExportSettings(FontExportMode.TTF), evl); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } Font4Exporter f4e = new Font4Exporter(); f4e.exportFonts(handler, ASSETS_DIR, rttl, new Font4ExportSettings(Font4ExportMode.CFF), evl); - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return ret; } if (!assetsTagList.isEmpty()) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java index 43c414c93..4e7a6522e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportPackTask.java @@ -59,6 +59,8 @@ public class ExportPackTask implements Callable { EventListener eventListener; AbcIndexing abcIndex; + + Thread thread; /** * Constructor. @@ -73,7 +75,7 @@ public class ExportPackTask implements Callable { * @param parallel Parallel * @param evl Event listener */ - public ExportPackTask(AbcIndexing abcIndex, AbortRetryIgnoreHandler handler, int index, int count, ClassPath path, ScriptPack pack, File file, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) { + public ExportPackTask(AbcIndexing abcIndex, AbortRetryIgnoreHandler handler, int index, int count, ClassPath path, ScriptPack pack, File file, ScriptExportSettings exportSettings, boolean parallel, EventListener evl) { this.pack = pack; this.file = file; this.exportSettings = exportSettings; @@ -88,6 +90,7 @@ public class ExportPackTask implements Callable { @Override public File call() throws IOException, InterruptedException { + this.thread = Thread.currentThread(); RunnableIOExResult rio = new RunnableIOExResult() { @Override public void run() throws IOException, InterruptedException { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java index 92019cb81..29359573a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/script/ExportScriptTask.java @@ -64,6 +64,8 @@ public class ExportScriptTask implements Callable { long stopTime; EventListener eventListener; + + Thread thread; /** * Constructor. @@ -86,9 +88,10 @@ public class ExportScriptTask implements Callable { this.handler = handler; this.eventListener = evl; } - + @Override public File call() throws IOException, InterruptedException { + thread = Thread.currentThread(); String f = Path.combine(directory, name) + exportSettings.getFileExtension(); RunnableIOExResult rio = new RunnableIOExResult() { @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java index 3b952d798..33b9e5520 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS2ScriptImporter.java @@ -23,6 +23,7 @@ import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; import com.jpexs.decompiler.flash.action.parser.script.ActionScript2Parser; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.graph.CompilationException; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Path; import java.io.File; @@ -79,7 +80,7 @@ public class AS2ScriptImporter { int importCount = 0; for (String key : asms.keySet()) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } ASMSource asm = asms.get(key); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java index 37b478778..6fb44ac1c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/AS3ScriptImporter.java @@ -22,6 +22,7 @@ import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; import com.jpexs.decompiler.flash.exporters.settings.ScriptExportSettings; import com.jpexs.decompiler.flash.treeitems.Openable; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.io.File; import java.io.IOException; @@ -75,7 +76,7 @@ public class AS3ScriptImporter { int importCount = 0; for (ScriptPack pack : packs) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return importCount; } if (!pack.isSimple) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java index 390a17684..39b472980 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ImageImporter.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ImageTag; import com.jpexs.decompiler.flash.tags.enums.ImageFormat; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -353,7 +354,7 @@ public class ImageImporter extends TagImporter { } } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java index 0b147be9f..b94048a7e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/MovieImporter.java @@ -34,6 +34,7 @@ import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag; import com.jpexs.decompiler.flash.tags.base.RemoveTag; import com.jpexs.decompiler.flash.timeline.Timelined; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; import java.io.ByteArrayInputStream; @@ -136,7 +137,7 @@ public class MovieImporter { } catch (IOException ex) { Logger.getLogger(ShapeImporter.class.getName()).log(Level.WARNING, "Cannot import movie " + characterId + " from file " + sourceFile.getName(), ex); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java index fc1acf1dc..22c39842c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/ShapeImporter.java @@ -36,6 +36,7 @@ import com.jpexs.decompiler.flash.tags.base.ShapeTag; import com.jpexs.decompiler.flash.tags.enums.ImageFormat; import com.jpexs.decompiler.flash.types.RECT; import com.jpexs.decompiler.flash.types.SHAPEWITHSTYLE; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.awt.Dimension; import java.awt.image.BufferedImage; @@ -315,7 +316,7 @@ public class ShapeImporter { } catch (IOException ex) { Logger.getLogger(ShapeImporter.class.getName()).log(Level.WARNING, "Cannot import shape " + characterId + " from file " + sourceFile.getName(), ex); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java index cf57da5b4..38f96c316 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SoundImporter.java @@ -36,6 +36,7 @@ import com.jpexs.decompiler.flash.types.sound.MP3FRAME; import com.jpexs.decompiler.flash.types.sound.MP3SOUNDDATA; import com.jpexs.decompiler.flash.types.sound.SoundFormat; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; @@ -612,7 +613,7 @@ public class SoundImporter { } catch (IOException | SoundImportException ex) { Logger.getLogger(ShapeImporter.class.getName()).log(Level.WARNING, "Cannot import sound " + characterId + " from file " + sourceFile.getName(), ex); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java index 65f8b66f5..e417e6348 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SpriteImporter.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.tags.base.CharacterIdTag; import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.PlaceObjectTypeTag; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Helper; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; @@ -241,7 +242,7 @@ public class SpriteImporter { } catch (IOException ex) { Logger.getLogger(ShapeImporter.class.getName()).log(Level.WARNING, "Cannot import sprite " + characterId + " from file " + sourceFile.getName(), ex); } - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { break; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/search/ActionScriptSearch.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/search/ActionScriptSearch.java index 58a7bd559..b8a623067 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/search/ActionScriptSearch.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/search/ActionScriptSearch.java @@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.helpers.HighlightedText; import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter; import com.jpexs.decompiler.flash.tags.base.ASMSource; import com.jpexs.decompiler.flash.treeitems.Openable; +import com.jpexs.helpers.CancellableWorker; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -231,7 +232,7 @@ public class ActionScriptSearch { Future text = SWF.getCachedFuture(pack, new ScriptDecompiledListener() { @Override public void onStart() { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { return; } if (listener != null) { @@ -242,7 +243,7 @@ public class ActionScriptSearch { @Override public void onComplete(HighlightedText result) { - if (!Thread.currentThread().isInterrupted()) { + if (!CancellableWorker.isInterrupted()) { if (listener != null) { listener.onSearch(fpos, fscope.size(), pack.getClassPath().toString()); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index a3b4efe1e..e2312c499 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -220,7 +220,7 @@ public class BUTTONCONDACTION implements ASMSource, Serializable, HasSwfAndTag { actions = getActions(); } - return Action.actionsToSource(swf.getUninitializedAs2ClassTraits(), this, actions, getScriptName(), writer, actions.getCharset()); + return Action.actionsToSource(new HashMap<>(), this, actions, getScriptName(), writer, actions.getCharset()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index c009b8c02..72f11c366 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -53,6 +53,7 @@ import com.jpexs.decompiler.graph.model.TrueItem; import com.jpexs.decompiler.graph.model.UniversalLoopItem; import com.jpexs.decompiler.graph.model.WhileItem; import com.jpexs.decompiler.graph.precontinues.GraphPrecontinueDetector; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.Reference; import java.util.ArrayDeque; import java.util.ArrayList; @@ -1441,7 +1442,7 @@ public class Graph { //For detection based on debug line information boolean[] toDelete = new boolean[list.size()]; for (int i = 0; i < list.size(); i++) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -2755,7 +2756,7 @@ public class Graph { protected final List printGraph(List foundGotos, Map> partCodes, Map partCodePos, Set visited, BaseLocalData localData, TranslateStack stack, Set allParts, GraphPart parent, GraphPart part, List stopPart, List stopPartKind, List loops, List throwStates, List ret, int staticOperation, String path, int recursionLevel) throws InterruptedException { loopPrintGraph: while (true) { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } if (stopPart == null) { @@ -3747,7 +3748,7 @@ public class Graph { * @throws InterruptedException On interrupt */ private GraphPart makeGraph(GraphPart parent, GraphPath path, GraphSource code, int startIp, int lastIp, List allBlocks, HashMap> refs, boolean[] visited) throws InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphPart.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphPart.java index 626fa24d0..cbdedbdf9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphPart.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphPart.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.graph; import com.jpexs.decompiler.flash.BaseLocalData; +import com.jpexs.helpers.CancellableWorker; import java.io.Serializable; import java.util.ArrayList; import java.util.HashSet; @@ -144,7 +145,7 @@ public class GraphPart implements Serializable { * @throws InterruptedException On interrupt */ private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet visited, List loops, List throwStates, boolean useThrow) throws InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSource.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSource.java index 46f7dbd27..8a9c55b50 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSource.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphSource.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.graph; import com.jpexs.decompiler.flash.BaseLocalData; import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.helpers.CancellableWorker; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -95,7 +96,7 @@ public abstract class GraphSource implements Serializable { * @throws InterruptedException On interrupt */ private void visitCode(int ip, int lastIp, HashMap> refs, int endIp) throws InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java index 7f50e1f5f..0581b9750 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/GraphTargetItem.java @@ -41,6 +41,7 @@ import com.jpexs.decompiler.graph.model.FalseItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.NotItem; import com.jpexs.decompiler.graph.model.TrueItem; +import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.LinkedIdentityHashSet; import com.jpexs.helpers.Reference; import java.io.Serializable; @@ -388,7 +389,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { * @throws InterruptedException On interrupt */ public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } @@ -478,7 +479,7 @@ public abstract class GraphTargetItem implements Serializable, Cloneable { * @throws InterruptedException On interrupt */ public GraphTextWriter toString(GraphTextWriter writer, LocalData localData, String implicitCoerce) throws InterruptedException { - if (Thread.currentThread().isInterrupted()) { + if (CancellableWorker.isInterrupted()) { throw new InterruptedException(); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/helpers/CancellableWorker.java b/libsrc/ffdec_lib/src/com/jpexs/helpers/CancellableWorker.java index e0a41373b..6a4fae283 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/helpers/CancellableWorker.java +++ b/libsrc/ffdec_lib/src/com/jpexs/helpers/CancellableWorker.java @@ -31,6 +31,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.logging.Level; import java.util.logging.Logger; + /*private static final Map threadWorkers = Collections.synchronizedMap(new WeakHashMap<>()); + + private static final Map parentThreadWorkers = Collections.synchronizedMap(new WeakHashMap<>()); + + private static final Map threadToParentThread = Collections.synchronizedMap(new WeakHashMap<>()); + */ + + /** * Cancellable worker. @@ -46,22 +54,87 @@ public abstract class CancellableWorker implements RunnableFuture { private FutureTask future; - private static final Map threadWorkers = Collections.synchronizedMap(new WeakHashMap<>()); - private List subWorkers = Collections.synchronizedList(new ArrayList<>()); - + + private static final Map thread2Worker = Collections.synchronizedMap(new WeakHashMap<>()); + + private Thread parentThread; + private Thread thread; + + private String name; + + private CancellableWorker parentWorker; + + private boolean canceled = false; + + private List cancelListeners = new ArrayList<>(); + public Thread getThread() { + return thread; + } + + public static void assignThreadToWorker(Thread t, CancellableWorker w) { + if (w == null) { + return; + } + thread2Worker.put(t, w); + } + + public static CancellableWorker getCurrent() { + Thread t = Thread.currentThread(); + + CancellableWorker w = thread2Worker.get(t); + return w; + } + + public void addCancelListener(Runnable listener) { + cancelListeners.add(listener); + } + + public void removeCancelListener(Runnable listener) { + cancelListeners.remove(listener); + } + + + public static boolean isInterrupted() { + Thread t = Thread.currentThread(); + if (t.isInterrupted()) { + return true; + } + + + CancellableWorker w = thread2Worker.get(t); + if (w != null) { + while (w != null) { + t = w.thread; + if (t != null && t.isInterrupted()) { + return true; + } + if (w.canceled) { + return true; + } + w = w.parentWorker; + } + } + return false; + } + /** * Constructor. + * @param name Identifier of action */ - public CancellableWorker() { + public CancellableWorker(String name) { super(); + this.name = name; Callable callable = new Callable() { @Override public T call() throws Exception { - thread = Thread.currentThread(); - threadWorkers.put(thread, CancellableWorker.this); + thread = Thread.currentThread(); + thread2Worker.put(thread, CancellableWorker.this); + if (isInterrupted()) { + throw new InterruptedException(); + } return doInBackground(); } }; @@ -104,24 +177,36 @@ public abstract class CancellableWorker implements RunnableFuture { */ @SuppressWarnings("unchecked") public final void execute() { - Thread t = Thread.currentThread(); - if (threadWorkers.containsKey(t)) { - threadWorkers.get(t).subWorkers.add(this); + parentThread = Thread.currentThread(); + if (thread2Worker.containsKey(parentThread)) { + CancellableWorker currentWorker = thread2Worker.get(parentThread); + currentWorker.subWorkers.add(this); + parentWorker = currentWorker; } onStart(); THREAD_POOL.execute(this); } @Override - public final boolean cancel(boolean mayInterruptIfRunning) { + public final boolean cancel(boolean mayInterruptIfRunning) { + canceled = true; + boolean r = future.cancel(mayInterruptIfRunning); List sw = new ArrayList<>(subWorkers); for (CancellableWorker w : sw) { w.cancel(mayInterruptIfRunning); - } - boolean r = future.cancel(mayInterruptIfRunning); - if (r) { + } + + if (r) { + + List cls = new ArrayList<>(cancelListeners); + + for (Runnable listener : cls) { + listener.run(); + } + + workerCancelled(); - } + } return r; } @@ -149,13 +234,20 @@ public abstract class CancellableWorker implements RunnableFuture { @Override public final T get(long timeout, TimeUnit unit) throws InterruptedException, - ExecutionException, TimeoutException { + ExecutionException, TimeoutException { return future.get(timeout, unit); } + @Override + public String toString() { + return "[CancellableWorker \"" + name + "\" on thread " + thread +", subworkers: " + subWorkers.size() + ", " + (canceled ? " canceled" : "") + ", " + (parentWorker != null ? "HASPARENT" : "NOPARENT"); + } + + + private void workerDone() { - if (thread != null && threadWorkers.get(thread) == this) { - threadWorkers.remove(thread); + if (thread != null && thread2Worker.get(thread) == this) { + //thread2Worker.remove(thread); } workers.remove(this); done(); @@ -163,6 +255,7 @@ public abstract class CancellableWorker implements RunnableFuture { /** * Calls a callable with a timeout. + * @param name Name * @param c Callable * @param timeout Timeout * @param timeUnit Time unit @@ -172,12 +265,8 @@ public abstract class CancellableWorker implements RunnableFuture { * @throws ExecutionException On execution error * @throws TimeoutException On timeout */ - public static T call(final Callable c, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { - Thread t = Thread.currentThread(); - if (t.isInterrupted()) { - throw new InterruptedException(); - } - CancellableWorker worker = new CancellableWorker() { + public static T call(String name, final Callable c, long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { + CancellableWorker worker = new CancellableWorker(name) { @Override protected T doInBackground() throws Exception { @@ -190,7 +279,7 @@ public abstract class CancellableWorker implements RunnableFuture { } finally { worker.cancel(true); } - } + } /** * Cancels all background threads. @@ -206,6 +295,17 @@ public abstract class CancellableWorker implements RunnableFuture { } } } + + public static void cancelThread(Thread t) { + List ws = new ArrayList<>(workers); + for (CancellableWorker w : ws) { + if (w != null) { + if (w.parentThread == t) { + w.cancel(true); + } + } + } + } /** * Frees the worker. @@ -216,4 +316,56 @@ public abstract class CancellableWorker implements RunnableFuture { w.free(); } } + + @SuppressWarnings("unchecked") + private void printTree(List out) { + out.add("worker " + name + " on thread " + thread); + List sws = new ArrayList<>(subWorkers); + for (CancellableWorker sw : sws) { + List subout = new ArrayList<>(); + sw.printTree(subout); + for (String s:subout) { + out.add("-" + s); + } + } + } + + public static void printAllWorkers() { + List aw = new ArrayList<>(workers); + + System.err.println("====ALL WORKERS ===="); + for (CancellableWorker w : aw) { + System.err.println("" + w); + } + System.err.println("/===================="); + } + + public void printTree() { + System.err.println("======================="); + List out = new ArrayList<>(); + printTree(out); + for (String s:out) { + System.err.println(s); + } + System.err.println("/======================="); + } + + public void startWorkerMonitor() { + Thread monit = new Thread() { + @Override + public void run() { + CancellableWorker w = null; + while (true) { + CancellableWorker.printAllWorkers(); + w.printTree(); + try { + Thread.sleep(5000); + } catch (InterruptedException ex) { + return; + } + } + } + }; + monit.start(); + } } diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index d7c1cb6c8..33e0c9e0a 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -2200,7 +2200,7 @@ public class CommandLineArgumentParser { boolean exportAs3Script = exportAllScript || exportFormats.contains("script_as3"); if (exportAs2Script || exportAs3Script) { System.out.println("Exporting scripts..."); - + String scriptsFolder = Path.combine(outDir, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); @@ -4102,7 +4102,7 @@ public class CommandLineArgumentParser { for (Entry streamEntry : bundle.getAll().entrySet()) { InputStream stream = streamEntry.getValue(); stream.reset(); - CancellableWorker worker = new CancellableWorker() { + CancellableWorker worker = new CancellableWorker("parseInfoBundle") { @Override public SWF doInBackground() throws Exception { final CancellableWorker worker = this; @@ -4139,7 +4139,7 @@ public class CommandLineArgumentParser { BufferedInputStream inputStream = new BufferedInputStream(fis); InputStream fInputStream = inputStream; - CancellableWorker worker = new CancellableWorker() { + CancellableWorker worker = new CancellableWorker("parseInfo") { @Override public SWF doInBackground() throws Exception { final CancellableWorker worker = this; diff --git a/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java b/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java index 151e51f43..3109a8b44 100644 --- a/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java +++ b/src/com/jpexs/decompiler/flash/console/ConsoleAbortRetryIgnoreHandler.java @@ -40,6 +40,9 @@ public class ConsoleAbortRetryIgnoreHandler implements AbortRetryIgnoreHandler { @Override public int handle(Throwable thrown) { + if (thrown instanceof InterruptedException) { + return AbortRetryIgnoreHandler.ABORT; + } if (errorMode != AbortRetryIgnoreHandler.UNDEFINED) { int result = errorMode; diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 7ab5f6f83..d1a146d90 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -350,7 +350,7 @@ public class Main { } final String ffile = file; - CancellableWorker runWorker = new CancellableWorker() { + CancellableWorker runWorker = new CancellableWorker("runWorker") { @Override protected Object doInBackground() throws Exception { Process proc; @@ -672,7 +672,7 @@ public class Main { if (tempFile != null) { final File fTempFile = tempFile; final List tempFiles = new ArrayList<>(); - CancellableWorker instrumentWorker = new CancellableWorker() { + CancellableWorker instrumentWorker = new CancellableWorker("instrumentWorker") { @Override protected Object doInBackground() throws Exception { @@ -974,7 +974,7 @@ public class Main { stream.reset(); CancellableWorker worker = null; if (streamEntry.getKey().toLowerCase().endsWith(".abc")) { - CancellableWorker abcWorker = new CancellableWorker() { + CancellableWorker abcWorker = new CancellableWorker("parseOpenable") { private ABC open(InputStream is, String file, String fileTitle) throws IOException, InterruptedException { SWF dummySwf = new SWF(); dummySwf.setFileTitle(fileTitle != null ? fileTitle : file); @@ -1005,7 +1005,7 @@ public class Main { }; worker = abcWorker; } else { - CancellableWorker swfWorker = new CancellableWorker() { + CancellableWorker swfWorker = new CancellableWorker("bundleSwfWorker") { @Override public SWF doInBackground() throws Exception { final CancellableWorker worker = this; @@ -1046,7 +1046,7 @@ public class Main { CancellableWorker worker = null; if (sourceInfo.getKind() == OpenableSourceKind.ABC) { - CancellableWorker abcWorker = new CancellableWorker() { + CancellableWorker abcWorker = new CancellableWorker("abcWorker") { private ABC open(InputStream is, String file, String fileTitle) throws IOException, InterruptedException { SWF dummySwf = new SWF(); dummySwf.setFileTitle(fileTitle != null ? fileTitle : file); @@ -1079,7 +1079,7 @@ public class Main { } else if (sourceInfo.getKind() == OpenableSourceKind.SWF) { final String[] yesno = new String[]{AppStrings.translate("button.yes"), AppStrings.translate("button.no"), AppStrings.translate("button.yes.all"), AppStrings.translate("button.no.all")}; - CancellableWorker swfWorker = new CancellableWorker() { + CancellableWorker swfWorker = new CancellableWorker("swfWorker") { private boolean yestoall = false; private boolean notoall = false; diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameStatusPanel.java b/src/com/jpexs/decompiler/flash/gui/MainFrameStatusPanel.java index 5b634b149..45c013aad 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameStatusPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameStatusPanel.java @@ -24,6 +24,8 @@ import java.awt.Insets; import java.awt.event.ActionEvent; import java.util.Timer; import java.util.TimerTask; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.BoxLayout; import javax.swing.Icon; import javax.swing.JButton; @@ -65,7 +67,7 @@ public class MainFrameStatusPanel extends JPanel { public MainFrameStatusPanel(MainPanel mainPanel) { this.mainPanel = mainPanel; createStatusPanel(); - } + } private void createStatusPanel() { JPanel statusLeftPanel = new JPanel(); @@ -77,10 +79,11 @@ public class MainFrameStatusPanel extends JPanel { cancelButton.setBorderPainted(false); cancelButton.setOpaque(false); cancelButton.addActionListener((ActionEvent e) -> { - if (currentWorker != null) { - currentWorker.cancel(true); + CancellableWorker w = currentWorker; + if (w != null) { + w.cancel(true); } - }); + }); statusLeftPanel.add(loadingPanel); statusLeftPanel.add(cancelButton); statusLeftPanel.add(statusLabel); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index c63828117..b6a2428a2 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2998,7 +2998,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se || searchDialog.searchInPCodeRadioButton.isSelected(); if (scriptSearch) { boolean pCodeSearch = searchDialog.searchInPCodeRadioButton.isSelected(); - new CancellableWorker() { + new CancellableWorker("scriptSearch") { @Override protected Void doInBackground() throws Exception { @@ -3051,7 +3051,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se }.execute(); } else if (searchDialog.searchInTextsRadioButton.isSelected()) { - new CancellableWorker() { + new CancellableWorker("searchInTexts") { @Override protected Void doInBackground() throws Exception { List textResult; @@ -3146,7 +3146,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (!txt.isEmpty()) { final SWF swf = getCurrentSwf(); - new CancellableWorker() { + new CancellableWorker("replace") { @Override protected Void doInBackground() throws Exception { int findCount = 0; @@ -3290,7 +3290,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } final SWF fswf = swf; if (confirmExperimental()) { - new CancellableWorker() { + new CancellableWorker("renameColliding") { @Override protected Integer doInBackground() throws Exception { AbcMultiNameCollisionFixer fixer = new AbcMultiNameCollisionFixer(); @@ -3339,7 +3339,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se final int multiName = getABCPanel().decompiledTextArea.getMultinameUnderCaret(new Reference(null)); final List abcList = swf.getAbcList(); if (multiName > 0) { - new CancellableWorker() { + new CancellableWorker("renameOneIdentifierAs3") { @Override public Void doInBackground() throws Exception { renameMultiname(abcList, multiName); @@ -3363,7 +3363,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } else { final String identifier = getActionPanel().getStringUnderCursor(); if (identifier != null) { - new CancellableWorker() { + new CancellableWorker("renameOneIdentifierAs2") { @Override public Void doInBackground() throws Exception { try { @@ -3456,7 +3456,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se final String fpath = path; long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("exportFlashDevelop") { @Override protected Void doInBackground() throws Exception { Helper.freeMem(); @@ -3529,7 +3529,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se SwfIntelliJIdeaExporter exporter = new SwfIntelliJIdeaExporter(); long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("exportIdea") { @Override protected Void doInBackground() throws Exception { Helper.freeMem(); @@ -3602,7 +3602,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se SwfVsCodeExporter exporter = new SwfVsCodeExporter(); long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("exportVsCode") { @Override protected Void doInBackground() throws Exception { Helper.freeMem(); @@ -3762,7 +3762,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se final FLAVersion selectedVersion = filterToFlaVersion.get(selectedFilter); final File selfile = new File(path); long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("exportFla") { @Override protected Void doInBackground() throws Exception { Helper.freeMem(); @@ -3842,7 +3842,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se MovieImporter movieImporter = new MovieImporter(); final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("importMovie") { private int count = 0; @@ -3902,7 +3902,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se SoundImporter soundImporter = new SoundImporter(); final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("importSound") { private int count = 0; @@ -3959,7 +3959,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se SpriteImporter spriteImporter = new SpriteImporter(); final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("importSprite") { private int count = 0; @@ -4019,7 +4019,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se SvgImporter svgImporter = new SvgImporter(); final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("importShape") { private int count = 0; @@ -4078,7 +4078,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se ImageImporter imageImporter = new ImageImporter(); final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("importImage") { private int count = 0; @@ -4232,7 +4232,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se } final String fScriptsFolder = scriptsFolder; final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("importScript") { private int countAs2 = 0; private int countAs3 = 0; @@ -4359,7 +4359,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (selFile != null) { final long timeBefore = System.currentTimeMillis(); - new CancellableWorker() { + new CancellableWorker("export") { @Override public Void doInBackground() throws Exception { try { @@ -4533,7 +4533,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se RenameDialog renameDialog = new RenameDialog(Main.getDefaultDialogsOwner()); if (renameDialog.showRenameDialog() == AppDialog.OK_OPTION) { final RenameType renameType = renameDialog.getRenameType(); - new CancellableWorker() { + new CancellableWorker("renameIdentifiers") { @Override protected Integer doInBackground() throws Exception { int cnt = fswf.deobfuscateIdentifiers(renameType); @@ -4611,7 +4611,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se DeobfuscationDialog deobfuscationDialog = new DeobfuscationDialog(Main.getDefaultDialogsOwner()); if (deobfuscationDialog.showDialog() == AppDialog.OK_OPTION) { DeobfuscationLevel level = deobfuscationDialog.getDeobfuscationLevel(); - new CancellableWorker() { + new CancellableWorker("deobfuscate") { @Override protected Void doInBackground() throws Exception { try { @@ -5792,7 +5792,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se public void loadFromBinaryTag(final List binaryDataTags) { Main.loadingDialog.setVisible(true); - new CancellableWorker() { + new CancellableWorker("loadFromBinaryTag") { @Override protected Void doInBackground() throws Exception { try { diff --git a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 97f762219..c8b5d9d29 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -909,7 +909,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL boolean decompileNeeded = decompiledText == null; if (decompileNeeded) { - CancellableWorker worker = new CancellableWorker() { + CancellableWorker worker = new CancellableWorker("abc.decompiledEditorPane") { @Override protected Void doInBackground() throws Exception { diff --git a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index 13d308477..6cd19a8cb 100644 --- a/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -529,7 +529,7 @@ public class ActionPanel extends JPanel implements SearchListener { decompiledEditor.setShowMarkers(false); - setDecompiledText("-", "-", "// " + AppStrings.translate("work.decompiling") + "..."); + if (src.getSwf().needsCalculatingAS2UninitializeClassTraits(src)) { + setEditorText(asm.getScriptName(), asm.getExportedScriptName(), "; ...", "text/flasm"); + setDecompiledText("-", "-", "// " + AppStrings.translate("work.decompiling.allScripts.ucf") + "..."); + } else { + setDecompiledText("-", "-", "// " + AppStrings.translate("work.decompiling") + "..."); + } }); HighlightedText htext = SWF.getCached(asm, innerActions); @@ -584,6 +589,7 @@ public class ActionPanel extends JPanel implements SearchListener