Removing AS3 scripts ("ScriptPacks")

This commit is contained in:
Jindra Petřík
2021-02-16 08:17:36 +01:00
parent 3385211b54
commit b54b51d206
4 changed files with 52 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
- #1260, #1438 AS1/2 direct editing on(xxx), onClipEvent(xxx) handlers
- #1366, #1409, #1429, #1573, #1598 AS1/2/3 Add script/class (context menu on scripts folder)
- Removing BUTTONCONDACTION, CLIPACTIONRECORD
- Removing AS3 scripts
- Japanese translation
### Fixed

View File

@@ -93,6 +93,8 @@ import com.jpexs.decompiler.flash.tags.DebugIDTag;
import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag;
import com.jpexs.decompiler.flash.tags.DefineSoundTag;
import com.jpexs.decompiler.flash.tags.DefineSpriteTag;
import com.jpexs.decompiler.flash.tags.DoABC2Tag;
import com.jpexs.decompiler.flash.tags.DoABCTag;
import com.jpexs.decompiler.flash.tags.DoInitActionTag;
import com.jpexs.decompiler.flash.tags.EnableDebugger2Tag;
import com.jpexs.decompiler.flash.tags.EnableDebuggerTag;
@@ -2993,6 +2995,9 @@ public final class SWF implements SWFContainerItem, Timelined {
}
private void removeTagInternal(Timelined timelined, Tag tag, boolean removeDependencies) {
if ((tag instanceof DoABC2Tag) || (tag instanceof DoABCTag)) {
clearAbcListCache();
}
if (tag instanceof ShowFrameTag || ShowFrameTag.isNestedTagType(tag.getId())) {
timelined.removeTag(tag);
timelined.setModified(true);

View File

@@ -27,6 +27,7 @@ import com.jpexs.decompiler.flash.abc.types.ConvertData;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.Multiname;
import com.jpexs.decompiler.flash.abc.types.Namespace;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.abc.types.traits.TraitClass;
import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction;
@@ -331,6 +332,9 @@ public class ScriptPack extends AS3ClassTreeItem {
@Override
public boolean isModified() {
if (scriptIndex >= abc.script_info.size()) {
return false;
}
return abc.script_info.get(scriptIndex).isModified();
}
@@ -637,4 +641,15 @@ public class ScriptPack extends AS3ClassTreeItem {
trait.getMethodInfos(abc, GraphTextWriter.TRAIT_UNKNOWN, -1, methodInfos);
}
}
public void delete(ABC abc, boolean d) {
ScriptInfo si = abc.script_info.get(scriptIndex);
if (isSimple) {
si.delete(abc, d);
} else {
for (int t : traitIndices) {
si.traits.traits.get(t).delete(abc, d);
}
}
}
}

View File

@@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.IdentifiersDeobfuscation;
import com.jpexs.decompiler.flash.ReadOnlyTagList;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser;
import com.jpexs.decompiler.flash.action.Action;
@@ -272,13 +273,13 @@ public class TagTreeContextMenu extends JPopupMenu {
final List<SWFList> swfs = mainPanel.getSwfs();
boolean canRemove = true;
boolean onlyClipActionButtonCond = true;
boolean allDoNotHaveDependencies = true;
for (TreeItem item : items) {
if (!(item instanceof Tag) && !(item instanceof Frame)) {
if (item instanceof TagScript) {
Tag tag = ((TagScript) item).getTag();
if (tag instanceof DoActionTag || tag instanceof DoInitActionTag) {
onlyClipActionButtonCond = false;
allDoNotHaveDependencies = false;
continue;
}
}
@@ -290,10 +291,14 @@ public class TagTreeContextMenu extends JPopupMenu {
continue;
}
if (item instanceof ScriptPack) {
continue;
}
canRemove = false;
break;
} else {
onlyClipActionButtonCond = false;
allDoNotHaveDependencies = false;
}
}
@@ -351,7 +356,7 @@ public class TagTreeContextMenu extends JPopupMenu {
expandRecursiveMenuItem.setVisible(false);
removeMenuItem.setVisible(canRemove);
removeWithDependenciesMenuItem.setVisible(canRemove && !onlyClipActionButtonCond);
removeWithDependenciesMenuItem.setVisible(canRemove && !allDoNotHaveDependencies);
undoTagMenuItem.setVisible(allSelectedIsTag);
exportSelectionMenuItem.setEnabled(tagTree.hasExportableNodes());
replaceMenuItem.setVisible(false);
@@ -1288,6 +1293,10 @@ public class TagTreeContextMenu extends JPopupMenu {
}
itemsToRemoveParents.add(((TagScript) path.getParentPath().getLastPathComponent()).getTag());
itemsToRemoveSprites.add(sprite);
} else if (item instanceof ScriptPack) {
itemsToRemove.add(item);
itemsToRemoveParents.add(new Object());
itemsToRemoveSprites.add(new Object());
}
}
@@ -1307,6 +1316,7 @@ public class TagTreeContextMenu extends JPopupMenu {
if (View.showConfirmDialog(this, confirmationMessage, mainPanel.translate("message.confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
Map<SWF, List<Tag>> tagsToRemoveBySwf = new HashMap<>();
Set<SWF> swfsToClearCache = new HashSet<>();
for (int i = 0; i < itemsToRemove.size(); i++) {
Object item = itemsToRemove.get(i);
Object parent = itemsToRemoveParents.get(i);
@@ -1336,7 +1346,20 @@ public class TagTreeContextMenu extends JPopupMenu {
place.setModified(true);
tim.resetTimeline();
}
if (item instanceof ScriptPack) {
ScriptPack sp = (ScriptPack) item;
sp.delete(sp.abc, true);
sp.abc.pack();
swfsToClearCache.add(sp.getSwf());
for (ABCContainerTag ct : sp.getSwf().getAbcList()) {
if (ct.getABC() == sp.abc) {
((Tag) ct).setModified(true);
break;
}
}
}
}
for (Tag tag : tagsToRemove) {
SWF swf = tag.getSwf();
if (!tagsToRemoveBySwf.containsKey(swf)) {
@@ -1350,6 +1373,10 @@ public class TagTreeContextMenu extends JPopupMenu {
swf.removeTags(tagsToRemoveBySwf.get(swf), removeDependencies);
}
for (SWF swf : swfsToClearCache) {
swf.clearAllCache();
}
mainPanel.refreshTree();
}
}