Added Flattened ActionScript packages (one row per package instead package tree), can be turned off in settings

Changes ActionScript packages are by default flattened
This commit is contained in:
Jindra Petřík
2022-11-19 22:53:19 +01:00
parent 5ce21673a4
commit 4f3bbe732b
14 changed files with 132 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
- [#1501] Bulk import shapes
- [#1680] Pinning items
- Indices in brackets for items with same name (like two subsequent DoAction tags)
- Flattened ActionScript packages (one row per package instead package tree), can be turned off in settings
### Fixed
- [#1869] Replace references now replaces all references, not just PlaceObject
@@ -45,6 +46,7 @@ All notable changes to this project will be documented in this file.
- GFX - DefineExternalImage2 no longer handled as character
- Raw editor does not show tag name in the tree (it's now in the new pinnable head)
- DoInitAction is not shown in resources/sprites section, only in scripts
- ActionScript packages are by default flattened (can be turned off in settings)
## [16.3.1] - 2022-11-14
### Fixed

View File

@@ -1973,6 +1973,19 @@ public final class SWF implements SWFContainerItem, Timelined {
}
private String getASMPath(boolean exportFileName, TreeItem treeItem) {
if (treeItem instanceof AS2Package) {
AS2Package pkg = (AS2Package) treeItem;
if (pkg.isFlat()) {
String parts[] = pkg.toString().split("\\.");
for (int i = 0; i < parts.length; i++) {
parts[i] = Helper.makeFileName(parts[i]);
}
return String.join(File.separator, parts);
}
}
if (!exportFileName) {
return treeItem.toString();
}

View File

@@ -808,6 +808,10 @@ public final class Configuration {
@ConfigurationDefaultString("")
public static ConfigurationItem<String> pinnedItemsTagListPaths = null;
@ConfigurationDefaultBoolean(true)
@ConfigurationCategory("script")
public static ConfigurationItem<Boolean> flattenASPackages = null;
private enum OSId {
WINDOWS, OSX, UNIX
}

View File

@@ -39,11 +39,14 @@ public class AS2Package implements TreeItem {
public Map<String, AS2Package> subPackages = new TreeMap<>();
public Map<String, ASMSource> scripts = new TreeMap<>();
private boolean flat;
public AS2Package(String name, AS2Package parent, SWF swf) {
public AS2Package(String name, AS2Package parent, SWF swf, boolean flat) {
this.name = name;
this.parent = parent;
this.swf = swf;
this.flat = flat;
}
@Override
@@ -133,4 +136,8 @@ public class AS2Package implements TreeItem {
}
return false;
}
public boolean isFlat() {
return flat;
}
}

View File

@@ -43,9 +43,12 @@ public class AS3Package extends AS3ClassTreeItem {
private List<AS3Package> sortedPackages;
private List<ScriptPack> sortedScripts;
private boolean flat;
public AS3Package(String packageName, SWF swf) {
public AS3Package(String packageName, SWF swf, boolean flat) {
super(packageName, "", null);
this.flat = flat;
this.swf = swf;
this.packageName = packageName;
}
@@ -148,6 +151,9 @@ public class AS3Package extends AS3ClassTreeItem {
@Override
public String toString() {
if (flat) {
return packageName;
}
return IdentifiersDeobfuscation.printIdentifier(true, packageName);
}

View File

@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.timeline;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.TagRemoveListener;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.BlendModeSetable;
import com.jpexs.decompiler.flash.exporters.FrameExporter;
import com.jpexs.decompiler.flash.exporters.commonshape.ExportRectangle;
@@ -191,7 +192,7 @@ public class Timeline {
this.displayRect = displayRect;
this.frameRate = swf.frameRate;
this.timelined = timelined;
as2RootPackage = new AS2Package(null, null, swf);
as2RootPackage = new AS2Package(null, null, swf, false);
}
public final int getMaxDepth() {
@@ -256,7 +257,7 @@ public class Timeline {
this.displayRect = displayRect;
this.frameRate = swf.frameRate;
this.timelined = timelined;
as2RootPackage = new AS2Package(null, null, swf);
as2RootPackage = new AS2Package(null, null, swf, false);
}
public int getFrameWithLabel(String label) {
@@ -479,10 +480,31 @@ public class Timeline {
String[] pathParts = path.contains(".") ? path.split("\\.") : new String[]{path};
AS2Package pkg = as2RootPackage;
for (int pos = 0; pos < pathParts.length - 1; pos++) {
if (Configuration.flattenASPackages.get()) {
boolean isNamedPackages = "__Packages".equals(pathParts[0]);
if (isNamedPackages && pos == 0) {
//nothing
} else {
String fullPath;
if (isNamedPackages) {
fullPath = path.substring(pathParts[0].length() + 1, path.length() - pathParts[pathParts.length - 1].length() - 1);
} else {
fullPath = path.substring(0, path.length() - pathParts[pathParts.length - 1].length() - 1);
}
AS2Package subPkg = pkg.subPackages.get(fullPath);
if (subPkg == null) {
subPkg = new AS2Package(fullPath, pkg, swf, true);
pkg.subPackages.put(fullPath, subPkg);
}
pkg = subPkg;
break;
}
}
String pathPart = pathParts[pos];
AS2Package subPkg = pkg.subPackages.get(pathPart);
if (subPkg == null) {
subPkg = new AS2Package(pathPart, pkg, swf);
subPkg = new AS2Package(pathPart, pkg, swf, false);
pkg.subPackages.put(pathPart, subPkg);
}

View File

@@ -79,6 +79,9 @@ public abstract class MainFrameMenu implements MenuBuilder {
private SWF swf;
private ConfigurationItemChangeListener<Boolean> configListenerAutoDeobfuscate;
private ConfigurationItemChangeListener<Boolean> configListenerFlattenASPackages;
private ConfigurationItemChangeListener<Boolean> configListenerSimplifyExpressions;
@@ -651,6 +654,13 @@ public abstract class MainFrameMenu implements MenuBuilder {
Configuration.autoOpenLoadedSWFs.set(selected);
}
protected void flattenASPackagesActionPerformed(ActionEvent evt) {
AbstractButton button = (AbstractButton) evt.getSource();
boolean selected = button.isSelected();
Configuration.flattenASPackages.set(selected);
}
protected void autoRenameIdentifiersActionPerformed(ActionEvent evt) {
AbstractButton button = (AbstractButton) evt.getSource();
@@ -1056,6 +1066,7 @@ public abstract class MainFrameMenu implements MenuBuilder {
addToggleMenuItem("/settings/gotoMainClassOnStartup", translate("menu.settings.gotoMainClassOnStartup"), null, null, this::gotoDucumentClassOnStartupActionPerformed, 0, null);
addToggleMenuItem("/settings/autoRenameIdentifiers", translate("menu.settings.autoRenameIdentifiers"), null, null, this::autoRenameIdentifiersActionPerformed, 0, null);
addToggleMenuItem("/settings/autoOpenLoadedSWFs", translate("menu.settings.autoOpenLoadedSWFs"), null, null, this::autoOpenLoadedSWFsActionPerformed, 0, null);
addToggleMenuItem("/settings/flattenASPackages", translate("menu.settings.flattenASPackages"), null, null, this::flattenASPackagesActionPerformed, 0, null);
if (Platform.isWindows()) {
addToggleMenuItem("/settings/associate", translate("menu.settings.addtocontextmenu"), null, null, this::associateActionPerformed, 0, null);
}
@@ -1125,6 +1136,11 @@ public abstract class MainFrameMenu implements MenuBuilder {
Configuration.autoOpenLoadedSWFs.addListener(configListenerAutoOpenLoadedSWFs = (Boolean newValue) -> {
setMenuChecked("/settings/autoOpenLoadedSWFs", newValue);
});
setMenuChecked("/settings/flattenASPackages", Configuration.flattenASPackages.get());
Configuration.flattenASPackages.addListener(configListenerFlattenASPackages = (Boolean newValue) -> {
setMenuChecked("/settings/flattenASPackages", newValue);
});
/*
if (externalFlashPlayerUnavailable) {

View File

@@ -33,6 +33,7 @@ import com.jpexs.decompiler.flash.abc.avm2.deobfuscation.DeobfuscationLevel;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.configuration.ConfigurationItem;
import com.jpexs.decompiler.flash.configuration.ConfigurationItemChangeListener;
import com.jpexs.decompiler.flash.configuration.CustomConfigurationKeys;
import com.jpexs.decompiler.flash.configuration.SwfSpecificCustomConfiguration;
import com.jpexs.decompiler.flash.dumpview.DumpInfo;
@@ -1191,6 +1192,14 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
calculateMissingNeededThread = new CalculateMissingNeededThread();
calculateMissingNeededThread.start();
pinsPanel.load();
Configuration.flattenASPackages.addListener(new ConfigurationItemChangeListener<Boolean>() {
@Override
public void configurationItemChanged(Boolean newValue) {
resetAllTimelines();
refreshTree();
}
});
}
public void closeTagTreeSearch() {
@@ -1201,6 +1210,20 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se
searchPanel.setVisible(false);
}
public void resetAllTimelines() {
List<SWFList> swfsLists = new ArrayList<>(swfs);
List<SWF> allSwfs = new ArrayList<>();
for (SWFList swfList : swfsLists) {
allSwfs.addAll(swfList);
for (SWF swf : swfList) {
Main.populateSwfs(swf, allSwfs);
}
}
for (SWF swf : allSwfs) {
swf.resetTimeline();
}
}
public void loadSwfAtPos(SWFList newSwfs, int index) {
View.checkAccess();

View File

@@ -46,14 +46,17 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
private final AS3Package root;
private final List<TreeModelListener> listeners = new ArrayList<>();
private boolean flat = true;
public List<ScriptPack> getList() {
return list;
}
public ClassesListTreeModel(SWF swf) {
public ClassesListTreeModel(SWF swf, boolean flat) {
super(null, null, null);
root = new AS3Package(null, swf);
this.flat = flat;
root = new AS3Package(null, swf, flat);
this.swf = swf;
this.list = swf.getAS3Packs();
setFilter(null);
@@ -111,12 +114,24 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel
}
private AS3Package ensurePackage(DottedChain packageStr) {
if (flat) {
String fullName = packageStr.toPrintableString(true);
if (fullName.length() == 0) {
return root;
}
AS3Package pkg = root.getSubPackage(fullName);
if (pkg == null) {
pkg = new AS3Package(fullName, swf, true);
root.addSubPackage(pkg);
}
return pkg;
}
AS3Package parent = root;
for (int i = 0; i < packageStr.size(); i++) {
String pathElement = packageStr.get(i);
AS3Package pkg = parent.getSubPackage(pathElement);
if (pkg == null) {
pkg = new AS3Package(pathElement, swf);
pkg = new AS3Package(pathElement, swf, false);
parent.addSubPackage(pkg);
}

View File

@@ -617,3 +617,7 @@ config.description.pinnedItemsTagTreePaths = Paths of nodes of tag tree which ar
config.name.pinnedItemsTagListPaths = Pinned items paths in tag list view tree
config.description.pinnedItemsTagListPaths = Paths of nodes of tag list view tree which are pinned.
config.name.flattenASPackages = Flatten ActionScript packages
config.description.flattenASPackages = Make one item per package instead of package tree.

View File

@@ -603,4 +603,7 @@ config.name.pinnedItemsTagTreePaths = Cesty p\u0159ipnut\u00fdch polo\u017eek v
config.description.pinnedItemsTagTreePaths = Cesty uzl\u016f v stromu tag\u016f, kter\u00e9 jsou p\u0159ipnuty.
config.name.pinnedItemsTagListPaths = Cesty p\u0159ipnut\u00fdch polo\u017eek v stromu seznamu tag\u016f
config.description.pinnedItemsTagListPaths = Cesty uzl\u016f v stromu seznamu tag\u016f, kter\u00e9 jsou p\u0159ipnuty.
config.description.pinnedItemsTagListPaths = Cesty uzl\u016f v stromu seznamu tag\u016f, kter\u00e9 jsou p\u0159ipnuty.
config.name.flattenASPackages = Zplo\u0161tit bal\u00ed\u010dky ActionScriptu
config.description.flattenASPackages = Zobraz\u00ed bal\u00ed\u010dky jako jednu polo\u017eku pro bal\u00ed\u010dek m\u00edsto stromu bal\u00ed\u010dku.

View File

@@ -976,4 +976,6 @@ contextmenu.unpin = Unpin
contextmenu.unpin.all = Unpin all
contextmenu.unpin.others = Unpin others
menu.tools.otherTools.clearPinnedItems = Clear pinned items
menu.tools.otherTools.clearPinnedItems = Clear pinned items
menu.settings.flattenASPackages = Flatten ActionScript packages

View File

@@ -948,4 +948,6 @@ contextmenu.unpin = Odepnout
contextmenu.unpin.all = Odepnout v\u0161e
contextmenu.unpin.others = Odepnout ostatn\u00ed
menu.tools.otherTools.clearPinnedItems = Vymazat p\u0159ipnut\u00e9 polo\u017eky
menu.tools.otherTools.clearPinnedItems = Vymazat p\u0159ipnut\u00e9 polo\u017eky
menu.settings.flattenASPackages = Zplo\u0161tit bal\u00ed\u010dky ActionScriptu

View File

@@ -17,6 +17,7 @@
package com.jpexs.decompiler.flash.gui.tagtree;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.TreeNodeType;
import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel;
@@ -287,7 +288,7 @@ public class TagTreeModel extends AbstractTagTreeModel {
Map<Tag, TagScript> currentTagScriptCache = new HashMap<>();
if (swf.isAS3()) {
if (!swf.getAbcList().isEmpty()) {
nodeList.add(new ClassesListTreeModel(swf));
nodeList.add(new ClassesListTreeModel(swf, Configuration.flattenASPackages.get()));
}
} else {
List<TreeItem> subNodes = swf.getFirstLevelASMNodes(currentTagScriptCache);