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

@@ -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);
}