From dd8d3af6fddf2136509f5de235892e1fc05303a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Fri, 29 Sep 2023 22:09:26 +0200 Subject: [PATCH] ABCExplorer - hide combobox for ABC openables without SWF --- .../decompiler/flash/gui/MainFrameMenu.java | 9 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 10 +- .../flash/gui/abc/ABCExplorerDialog.java | 152 +++++++++++------- .../locales/abc/ABCExplorerDialog.properties | 3 +- .../flash/gui/tagtree/TagTreeContextMenu.java | 14 +- 5 files changed, 117 insertions(+), 71 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 76596f97d..6da51071d 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -1679,16 +1679,11 @@ public abstract class MainFrameMenu implements MenuBuilder { protected void abcExplorerActionPerformed(ActionEvent evt) { - SWF swf; - if (openable instanceof SWF) { - swf = (SWF) openable; - } else if (openable instanceof ABC) { - swf = ((ABC)openable).getSwf(); - } else { + if (openable == null) { return; } - mainFrame.getPanel().showAbcExplorer(swf, null); + mainFrame.getPanel().showAbcExplorer(openable, null); } public boolean stackActionPerformed(ActionEvent evt) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 22c98502e..829ecaefa 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -454,7 +454,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se public ScrollPosStorage scrollPosStorage; - private Map abcExplorerDialogs = new WeakHashMap<>(); + private Map abcExplorerDialogs = new WeakHashMap<>(); public void savePins() { pinsPanel.save(); @@ -5923,8 +5923,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se return statusPanel; } - public ABCExplorerDialog showAbcExplorer(SWF swf, ABC abc) { - ABCExplorerDialog dialog = abcExplorerDialogs.get(swf); + public ABCExplorerDialog showAbcExplorer(Openable openable, ABC abc) { + ABCExplorerDialog dialog = abcExplorerDialogs.get(openable); if (dialog != null) { dialog.selectAbc(abc); if (!dialog.isVisible()) { @@ -5933,8 +5933,8 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se dialog.toFront(); } } else { - dialog = new ABCExplorerDialog(mainFrame.getWindow(), swf, abc); - abcExplorerDialogs.put(swf, dialog); + dialog = new ABCExplorerDialog(mainFrame.getWindow(), openable, abc); + abcExplorerDialogs.put(openable, dialog); dialog.setVisible(true); } return dialog; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCExplorerDialog.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCExplorerDialog.java index 3e76b40d8..5a2ce941e 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCExplorerDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCExplorerDialog.java @@ -40,12 +40,14 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript; import com.jpexs.decompiler.flash.gui.AppDialog; import com.jpexs.decompiler.flash.gui.FasterScrollPane; import com.jpexs.decompiler.flash.gui.View; +import static com.jpexs.decompiler.flash.gui.View.loadImage; import com.jpexs.decompiler.flash.helpers.CodeFormatting; import com.jpexs.decompiler.flash.helpers.StringBuilderTextWriter; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DoABC2Tag; import com.jpexs.decompiler.flash.tags.ShowFrameTag; import com.jpexs.decompiler.flash.tags.Tag; +import com.jpexs.decompiler.flash.treeitems.Openable; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.helpers.Helper; import java.awt.BorderLayout; @@ -55,6 +57,7 @@ import java.awt.Container; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; +import java.awt.Image; import java.awt.Window; import java.awt.event.ActionEvent; import java.util.ArrayList; @@ -79,14 +82,14 @@ import javax.swing.tree.TreePath; */ public class ABCExplorerDialog extends AppDialog { - private final List abcContainers = new ArrayList<>(); - private final JComboBox abcComboBox; + private final List abcs = new ArrayList<>(); + private JComboBox abcComboBox = null; private final JLabel tagInfoLabel; private final List abcFrames = new ArrayList<>(); private final JTabbedPane mainTabbedPane; private final JTabbedPane cpTabbedPane; - public ABCExplorerDialog(Window owner, SWF swf, ABC abc) { + public ABCExplorerDialog(Window owner, Openable openable, ABC abc) { super(owner); Container cnt = getContentPane(); cnt.setLayout(new BorderLayout()); @@ -94,62 +97,82 @@ public class ABCExplorerDialog extends AppDialog { topPanel.add(new JLabel(translate("abc"))); int selectedIndex = 0; int frame = 1; - for (Tag t : swf.getTags()) { - if (t instanceof ShowFrameTag) { - frame++; - } - if (t instanceof ABCContainerTag) { - ABCContainerTag abcCnt = (ABCContainerTag) t; - if (abcCnt.getABC() == abc) { - selectedIndex = abcContainers.size(); + if (openable instanceof SWF) { + SWF swf = (SWF) openable; + List abcContainers = new ArrayList<>(); + for (Tag t : swf.getTags()) { + if (t instanceof ShowFrameTag) { + frame++; } - abcContainers.add(abcCnt); - abcFrames.add(frame); - } - } - String[] abcComboBoxData = new String[abcContainers.size()]; - for (int i = 0; i < abcContainers.size(); i++) { - abcComboBoxData[i] = "tag" + (i + 1); - if (abcContainers.get(i) instanceof DoABC2Tag) { - DoABC2Tag doa2 = (DoABC2Tag) abcContainers.get(i); - if (doa2.name != null && !doa2.name.isEmpty()) { - abcComboBoxData[i] += " (\"" + Helper.escapePCodeString(doa2.name) + "\")"; + if (t instanceof ABCContainerTag) { + ABCContainerTag abcCnt = (ABCContainerTag) t; + if (abcCnt.getABC() == abc) { + selectedIndex = abcs.size(); + } + abcContainers.add(abcCnt); + abcs.add(abcCnt.getABC()); + abcFrames.add(frame); } } + String[] abcComboBoxData = new String[abcs.size()]; + + for (int i = 0; i < abcContainers.size(); i++) { + abcComboBoxData[i] = "tag" + (i + 1); + if (abcContainers.get(i) instanceof DoABC2Tag) { + DoABC2Tag doa2 = (DoABC2Tag) abcContainers.get(i); + if (doa2.name != null && !doa2.name.isEmpty()) { + abcComboBoxData[i] += " (\"" + Helper.escapePCodeString(doa2.name) + "\")"; + } + } + } + abcComboBox = new JComboBox<>(abcComboBoxData); + + Dimension abcComboBoxSize = new Dimension(500, abcComboBox.getPreferredSize().height); + abcComboBox.setMinimumSize(abcComboBoxSize); + abcComboBox.setPreferredSize(abcComboBoxSize); + topPanel.add(abcComboBox); + abcComboBox.addActionListener(this::abcComboBoxActionPerformed); + + } else if (openable instanceof ABC) { + abcs.add((ABC) openable); + abcFrames.add(-1); } - abcComboBox = new JComboBox<>(abcComboBoxData); - Dimension abcComboBoxSize = new Dimension(500, abcComboBox.getPreferredSize().height); - abcComboBox.setMinimumSize(abcComboBoxSize); - abcComboBox.setPreferredSize(abcComboBoxSize); - topPanel.add(abcComboBox); tagInfoLabel = new JLabel(); topPanel.add(tagInfoLabel); - abcComboBox.addActionListener(this::abcComboBoxActionPerformed); - mainTabbedPane = new JTabbedPane(); cpTabbedPane = new JTabbedPane(); cnt.add(topPanel, BorderLayout.NORTH); cnt.add(mainTabbedPane, BorderLayout.CENTER); - if (!abcContainers.isEmpty()) { - abcComboBox.setSelectedIndex(selectedIndex); + if (!abcs.isEmpty()) { + if (abcComboBox != null) { + abcComboBox.setSelectedIndex(selectedIndex); + } else { + abcComboBoxActionPerformed(null); + } } setSize(800, 600); - setTitle(translate("title") + " - " + swf.getTitleOrShortFileName()); - View.setWindowIcon(this); + setTitle(translate("title") + " - " + openable.getTitleOrShortFileName()); + List images = new ArrayList<>(); + images.add(View.loadImage("abcexplorer16")); + images.add(View.loadImage("abcexplorer32")); + setIconImages(images); View.centerScreen(this); } - + public void selectAbc(ABC abc) { - if (abc == null && !abcContainers.isEmpty()) { + if (abcComboBox == null) { + return; + } + if (abc == null && !abcs.isEmpty()) { abcComboBox.setSelectedIndex(0); return; } - for (int i = 0; i < abcContainers.size(); i++) { - if (abcContainers.get(i).getABC() == abc) { + for (int i = 0; i < abcs.size(); i++) { + if (abcs.get(i) == abc) { abcComboBox.setSelectedIndex(i); break; } @@ -157,24 +180,41 @@ public class ABCExplorerDialog extends AppDialog { } private ABC getSelectedAbc() { - return abcContainers.get(abcComboBox.getSelectedIndex()).getABC(); + if (abcs.isEmpty()) { + return null; + } + if (abcComboBox == null) { + return abcs.get(0); + } + return abcs.get(abcComboBox.getSelectedIndex()); } private void abcComboBoxActionPerformed(ActionEvent e) { - int index = abcComboBox.getSelectedIndex(); + int index = abcComboBox == null ? 0 : abcComboBox.getSelectedIndex(); if (index == -1) { return; } - ABC abc = abcContainers.get(index).getABC(); - tagInfoLabel.setText( - translate("abc.info") - .replace("%index%", "" + (index + 1)) - .replace("%count%", "" + abcComboBox.getItemCount()) - .replace("%major%", "" + abc.version.major) - .replace("%minor%", "" + abc.version.minor) - .replace("%size%", Helper.formatFileSize(abc.getDataSize())) - .replace("%frame%", "" + abcFrames.get(index)) - ); + if (abcs.isEmpty()) { + return; + } + ABC abc = abcs.get(index); + if (abcComboBox == null) { + tagInfoLabel.setText(translate("abc.info.standalone") + .replace("%major%", "" + abc.version.major) + .replace("%minor%", "" + abc.version.minor) + .replace("%size%", Helper.formatFileSize(abc.getDataSize())) + ); + } else { + tagInfoLabel.setText( + translate("abc.info") + .replace("%index%", "" + (index + 1)) + .replace("%count%", "" + abcComboBox.getItemCount()) + .replace("%major%", "" + abc.version.major) + .replace("%minor%", "" + abc.version.minor) + .replace("%size%", Helper.formatFileSize(abc.getDataSize())) + .replace("%frame%", "" + abcFrames.get(index)) + ); + } cpTabbedPane.removeAll(); @@ -215,13 +255,13 @@ public class ABCExplorerDialog extends AppDialog { mainTabbedPane.addTab("si (" + abc.script_info.size() + ")", makeTreePanel(abc, TreeType.SCRIPT_INFO)); mainTabbedPane.addTab("mb (" + abc.bodies.size() + ")", makeTreePanel(abc, TreeType.METHOD_BODY)); } - + public void selectScriptInfo(int scriptIndex) { if (mainTabbedPane.getTabCount() > 0) { mainTabbedPane.setSelectedIndex(5); JPanel pan = (JPanel) mainTabbedPane.getComponentAt(5); FasterScrollPane fasterScrollPane = (FasterScrollPane) pan.getComponent(0); - JTree tree = (JTree)fasterScrollPane.getViewport().getView(); + JTree tree = (JTree) fasterScrollPane.getViewport().getView(); TreeModel model = tree.getModel(); if (scriptIndex >= model.getChildCount(model.getRoot())) { return; @@ -567,22 +607,22 @@ public class ABCExplorerDialog extends AppDialog { case CONSTANT_INT: if (index >= abc.constants.getIntCount()) { return new ValueWithIndex(parent, currentLevelIndex, index, valueType, null, "Unknown(" + index + ")", prefix); - } + } return new ValueWithIndex(parent, currentLevelIndex, index, valueType, abc.constants.getInt(index), "" + abc.constants.getInt(index), prefix); case CONSTANT_UINT: if (index >= abc.constants.getUIntCount()) { return new ValueWithIndex(parent, currentLevelIndex, index, valueType, null, "Unknown(" + index + ")", prefix); - } + } return new ValueWithIndex(parent, currentLevelIndex, index, valueType, abc.constants.getUInt(index), "" + abc.constants.getUInt(index), prefix); case CONSTANT_DOUBLE: if (index >= abc.constants.getDoubleCount()) { return new ValueWithIndex(parent, currentLevelIndex, index, valueType, null, "Unknown(" + index + ")", prefix); - } + } return new ValueWithIndex(parent, currentLevelIndex, index, valueType, abc.constants.getDouble(index), EcmaScript.toString(abc.constants.getDouble(index)), prefix); case CONSTANT_DECIMAL: if (index >= abc.constants.getDecimalCount()) { return new ValueWithIndex(parent, currentLevelIndex, index, valueType, null, "Unknown(" + index + ")", prefix); - } + } return new ValueWithIndex(parent, currentLevelIndex, index, valueType, abc.constants.getDecimal(index), "" + abc.constants.getDecimal(index), prefix); case CONSTANT_FLOAT: if (index >= abc.constants.getFloatCount()) { @@ -593,7 +633,7 @@ public class ABCExplorerDialog extends AppDialog { if (index >= abc.constants.getFloat4Count()) { return new ValueWithIndex(parent, currentLevelIndex, index, valueType, null, "Unknown(" + index + ")", prefix); } - + Float4 f4 = abc.constants.getFloat4(index); return new ValueWithIndex(parent, currentLevelIndex, index, valueType, f4, EcmaScript.toString(f4.values[0]) + " " diff --git a/src/com/jpexs/decompiler/flash/gui/locales/abc/ABCExplorerDialog.properties b/src/com/jpexs/decompiler/flash/gui/locales/abc/ABCExplorerDialog.properties index 6b75a2a31..fec5c3d48 100644 --- a/src/com/jpexs/decompiler/flash/gui/locales/abc/ABCExplorerDialog.properties +++ b/src/com/jpexs/decompiler/flash/gui/locales/abc/ABCExplorerDialog.properties @@ -15,4 +15,5 @@ title = ABC Explorer abc = ABC: -abc.info = %index% of %count%, v%major%.%minor%, %size%, Frame %frame% \ No newline at end of file +abc.info = %index% of %count%, v%major%.%minor%, %size%, Frame %frame% +abc.info.standalone = v%major%.%minor%, %size% \ No newline at end of file diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index de2d3f67b..84ea779fd 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -1165,6 +1165,10 @@ public class TagTreeContextMenu extends JPopupMenu { abcExplorerMenuItem.setVisible(true); } + if (firstItem instanceof ABC) { + abcExplorerMenuItem.setVisible(true); + } + if (firstItem instanceof Tag) { rawEditMenuItem.setVisible(true); } @@ -1834,9 +1838,15 @@ public class TagTreeContextMenu extends JPopupMenu { return; } + if (item instanceof ABC) { + ABC abc = (ABC) item; + mainPanel.showAbcExplorer(abc, abc); + return; + } + if (item instanceof ScriptPack) { ScriptPack pack = (ScriptPack)item; - ABCExplorerDialog dialog = mainPanel.showAbcExplorer(pack.abc.getSwf(), pack.abc); + ABCExplorerDialog dialog = mainPanel.showAbcExplorer(pack.getOpenable(), pack.abc); dialog.selectScriptInfo(pack.scriptIndex); } @@ -1844,7 +1854,7 @@ public class TagTreeContextMenu extends JPopupMenu { AS3Package pkg = (AS3Package) item; if (pkg.isCompoundScript()) { ScriptPack pack = pkg.getCompoundInitializerPack(); - ABCExplorerDialog dialog = mainPanel.showAbcExplorer(pack.abc.getSwf(), pack.abc); + ABCExplorerDialog dialog = mainPanel.showAbcExplorer(pack.getOpenable(), pack.abc); dialog.selectScriptInfo(pack.scriptIndex); } }