From e8712900a4a007451211662e3f66a32c161c146a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 20 Aug 2016 19:10:49 +0200 Subject: [PATCH] FFDec AS3 compiler deleting fixes --- .../importers/FFDecAs3ScriptReplacer.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/FFDecAs3ScriptReplacer.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/FFDecAs3ScriptReplacer.java index 723dcdf12..666c5355b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/FFDecAs3ScriptReplacer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/FFDecAs3ScriptReplacer.java @@ -8,6 +8,7 @@ import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser; import com.jpexs.decompiler.flash.abc.types.ScriptInfo; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.graph.CompilationException; import java.io.File; import java.io.IOException; @@ -19,12 +20,12 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface { @Override public void replaceScript(ScriptPack pack, String text) throws As3ScriptReplaceException, IOException, InterruptedException { + ABC abc = pack.abc; + SWF swf = pack.abc.getSwf(); + String scriptName = pack.getPathScriptName() + ".as"; + int oldIndex = pack.scriptIndex; + int newIndex = abc.script_info.size(); try { - ABC abc = pack.abc; - SWF swf = pack.abc.getSwf(); - String scriptName = pack.getPathScriptName() + ".as"; - int oldIndex = pack.scriptIndex; - int newIndex = abc.script_info.size(); String documentClass = swf.getDocumentClass(); boolean isDocumentClass = documentClass != null && documentClass.equals(pack.getClassPath().toString()); @@ -48,6 +49,7 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface { List otherAbcs = new ArrayList<>(pack.allABCs); otherAbcs.remove(abc); + abc.script_info.get(oldIndex).delete(abc, true); ActionScript3Parser.compile(text, abc, otherAbcs, isDocumentClass, scriptName, newClassIndex, oldIndex); if (pack.isSimple) { @@ -55,20 +57,16 @@ public class FFDecAs3ScriptReplacer implements As3ScriptReplacerInterface { abc.script_info.set(oldIndex, abc.script_info.get(newIndex)); abc.script_info.remove(newIndex); } else { - abc.script_info.get(newIndex).setModified(true); - //Note: Is deleting traits safe? - List todel = new ArrayList<>(new TreeSet<>(pack.traitIndices)); - for (int i = todel.size() - 1; i >= 0; i--) { - si.traits.traits.remove((int) todel.get(i)); - } + //??? } - - abc.script_info.get(oldIndex) - .setModified(true); + abc.script_info.get(oldIndex).setModified(true); + abc.pack();//remove old deleted items + ((Tag) abc.parentTag).setModified(true); } catch (AVM2ParseException ex) { + abc.script_info.get(oldIndex).delete(abc, false); throw new As3ScriptReplaceException(new As3ScriptReplaceExceptionItem(null, ex.text, (int) ex.line)); } catch (CompilationException ex) { - throw new As3ScriptReplaceException(new As3ScriptReplaceExceptionItem(null, ex.text, ex.line)); + abc.script_info.get(oldIndex).delete(abc, false); } }