diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index f93dd03e2..bb3e384da 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -1144,11 +1144,11 @@ public final class SWF implements SWFContainerItem, Timelined { return exported; } - private List> uniqueAS3Packs(List> packs) { - List> ret = new ArrayList<>(); + private List uniqueAS3Packs(List packs) { + List ret = new ArrayList<>(); Set classPaths = new HashSet<>(); - for (MyEntry item : packs) { - ClassPath key = item.getKey(); + for (ScriptPack item : packs) { + ClassPath key = item.getClassPath(); if (classPaths.contains(key)) { logger.log(Level.SEVERE, "Duplicate pack path found (" + key + ")!"); } else { @@ -1159,8 +1159,8 @@ public final class SWF implements SWFContainerItem, Timelined { return ret; } - public List> getAS3Packs() { - List> packs = new ArrayList<>(); + public List getAS3Packs() { + List packs = new ArrayList<>(); for (ABCContainerTag abcTag : getAbcList()) { packs.addAll(abcTag.getABC().getScriptPacks()); } @@ -1256,15 +1256,15 @@ public final class SWF implements SWFContainerItem, Timelined { final AtomicInteger cnt = new AtomicInteger(1); final List ret = new ArrayList<>(); - final List> packs = getAS3Packs(); + final List packs = getAS3Packs(); if (!parallel || packs.size() < 2) { try { CancellableWorker.call(new Callable() { @Override public Void call() throws Exception { - for (MyEntry item : packs) { - ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, exportMode, parallel, evl); + for (ScriptPack item : packs) { + ExportPackTask task = new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportMode, parallel, evl); ret.add(task.call()); } return null; @@ -1278,8 +1278,8 @@ public final class SWF implements SWFContainerItem, Timelined { } else { ExecutorService executor = Executors.newFixedThreadPool(Configuration.getParallelThreadCount()); List> futureResults = new ArrayList<>(); - for (MyEntry item : packs) { - Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getKey(), item.getValue(), outdir, exportMode, parallel, evl)); + for (ScriptPack item : packs) { + Future future = executor.submit(new ExportPackTask(handler, cnt, packs.size(), item.getClassPath(), item, outdir, exportMode, parallel, evl)); futureResults.add(future); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java index 4d857cfa1..393bc7440 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -55,7 +55,6 @@ import com.jpexs.decompiler.flash.abc.usages.MethodReturnTypeMultinameUsage; import com.jpexs.decompiler.flash.abc.usages.MultinameUsage; import com.jpexs.decompiler.flash.abc.usages.TypeNameMultinameUsage; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; -import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.decompiler.flash.types.annotations.Internal; @@ -867,8 +866,8 @@ public class ABC { } } - public List> getScriptPacks() { - List> ret = new ArrayList<>(); + public List getScriptPacks() { + List ret = new ArrayList<>(); for (int i = 0; i < script_info.size(); i++) { ret.addAll(script_info.get(i).getPacks(this, i)); } @@ -1046,22 +1045,23 @@ public class ABC { public List findScriptPacksByPath(String name) { List ret = new ArrayList<>(); - List> allPacks = getScriptPacks(); + List allPacks = getScriptPacks(); if (name.endsWith(".**") || name.equals("**") || name.endsWith(".++") || name.equals("++")) { name = name.substring(0, name.length() - 2); - for (MyEntry en : allPacks) { - if (en.getKey().toString().startsWith(name)) { - ret.add(en.getValue()); + for (ScriptPack en : allPacks) { + if (en.getClassPath().toString().startsWith(name)) { + ret.add(en); } } } else if (name.endsWith(".*") || name.equals("*") || name.endsWith(".+") || name.equals("+")) { name = name.substring(0, name.length() - 1); - for (MyEntry en : allPacks) { - if (en.getKey().toString().startsWith(name)) { - String rem = name.isEmpty() ? en.getKey().toString() : en.getKey().toString().substring(name.length()); + for (ScriptPack en : allPacks) { + String classPathStr = en.getClassPath().toString(); + if (classPathStr.startsWith(name)) { + String rem = name.isEmpty() ? classPathStr : classPathStr.substring(name.length()); if (!rem.contains(".")) { - ret.add(en.getValue()); + ret.add(en); } } } @@ -1076,10 +1076,10 @@ public class ABC { } public ScriptPack findScriptPackByPath(String name) { - List> packs = getScriptPacks(); - for (MyEntry en : packs) { - if (en.getKey().toString().equals(name)) { - return en.getValue(); + List packs = getScriptPacks(); + for (ScriptPack en : packs) { + if (en.getClassPath().toString().equals(name)) { + return en; } } return null; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java index 8c68f705e..f7b9929a2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/ScriptInfo.java @@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.Traits; -import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import java.util.ArrayList; import java.util.List; @@ -36,13 +35,13 @@ public class ScriptInfo { public ScriptInfo() { traits = new Traits(); } - + public ScriptInfo(Traits traits) { this.traits = traits; } - - public List> getPacks(ABC abc, int scriptIndex) { - List> ret = new ArrayList<>(); + + public List getPacks(ABC abc, int scriptIndex) { + List ret = new ArrayList<>(); List otherTraits = new ArrayList<>(); for (int j = 0; j < traits.traits.size(); j++) { @@ -70,7 +69,7 @@ public class ScriptInfo { } otherTraits = new ArrayList<>(); ClassPath cp = new ClassPath(packageName, objectName); - ret.add(new MyEntry<>(cp, new ScriptPack(cp, abc, scriptIndex, traitIndices))); + ret.add(new ScriptPack(cp, abc, scriptIndex, traitIndices)); } } return ret; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java index c6327ca8e..59b783b3a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/timeline/AS3Package.java @@ -34,9 +34,13 @@ public class AS3Package extends AS3ClassTreeItem { public String packageName; - public Map subPackages = new TreeMap<>(); + private final Map subPackages = new TreeMap<>(); - public Map scripts = new TreeMap<>(); + private final Map scripts = new TreeMap<>(); + + private List sortedPackages; + + private List sortedScripts; public AS3Package(String packageName, SWF swf) { super(packageName, null); @@ -49,35 +53,60 @@ public class AS3Package extends AS3ClassTreeItem { return swf; } + public List getSubPackages() { + if (sortedPackages == null) { + List list = new ArrayList<>(); + for (AS3Package subPackage : subPackages.values()) { + list.add(subPackage); + } + + sortedPackages = list; + } + + return sortedPackages; + } + + public List getScriptPacks() { + if (sortedScripts == null) { + List list = new ArrayList<>(); + for (ScriptPack script : scripts.values()) { + list.add(script); + } + + sortedScripts = list; + } + + return sortedScripts; + } + + public void addScriptPack(ScriptPack script) { + scripts.put(script.getClassPath().className, script); + sortedScripts = null; + } + + public void addSubPackage(AS3Package subPackage) { + subPackages.put(subPackage.getName(), subPackage); + sortedPackages = null; + } + + public AS3Package getSubPackage(String packageName) { + return subPackages.get(packageName); + } + public List getAllChildren() { List result = new ArrayList<>(getChildCount()); result.addAll(subPackages.values()); result.addAll(scripts.values()); return result; } - + public AS3ClassTreeItem getChild(int index) { if (index < subPackages.size()) { - for (AS3Package subPackage : subPackages.values()) { - if (index == 0) { - return subPackage; - } - - index--; - } + return getSubPackages().get(index); } index -= subPackages.size(); - - for (ScriptPack pack : scripts.values()) { - if (index == 0) { - return pack; - } - - index--; - } - - return null; + return getScriptPacks().get(index); } public int getChildCount() { @@ -107,6 +136,13 @@ public class AS3Package extends AS3ClassTreeItem { return res; } + public void clear() { + subPackages.clear(); + scripts.clear(); + sortedPackages = null; + sortedScripts = null; + } + @Override public String toString() { return packageName; diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 16c41e395..1ab2fd4d1 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -24,7 +24,6 @@ import com.jpexs.decompiler.flash.SWFBundle; import com.jpexs.decompiler.flash.SWFSourceInfo; import com.jpexs.decompiler.flash.SearchMode; import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.RenameType; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; @@ -69,7 +68,6 @@ import com.jpexs.decompiler.flash.exporters.settings.SoundExportSettings; import com.jpexs.decompiler.flash.exporters.settings.TextExportSettings; import com.jpexs.decompiler.flash.exporters.swf.SwfXmlExporter; import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.importers.BinaryDataImporter; import com.jpexs.decompiler.flash.importers.ImageImporter; import com.jpexs.decompiler.flash.importers.SwfXmlImporter; @@ -1438,14 +1436,14 @@ public class CommandLineArgumentParser { replaceAS2PCode(repText, src); } } else { - List> packs = swf.getAS3Packs(); - for (MyEntry entry : packs) { - if (entry.getKey().toString().equals(objectToReplace)) { + List packs = swf.getAS3Packs(); + for (ScriptPack entry : packs) { + if (entry.getClassPath().toString().equals(objectToReplace)) { found = true; // replace AS3 String repFile = args.pop(); String repText = Helper.readTextFile(repFile); - ScriptPack pack = entry.getValue(); + ScriptPack pack = entry; if (Path.getExtension(repFile).equals(".as")) { replaceAS3(repText, pack); } else { @@ -1627,9 +1625,9 @@ public class CommandLineArgumentParser { try { try (FileInputStream is = new FileInputStream(file)) { SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); - List> packs = swf.getAS3Packs(); - for (MyEntry entry : packs) { - System.out.println(entry.getKey().toString() + " " + entry.getValue().scriptIndex); + List packs = swf.getAS3Packs(); + for (ScriptPack entry : packs) { + System.out.println(entry.getClassPath().toString() + " " + entry.scriptIndex); } } } catch (IOException | InterruptedException e) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index d21131856..a9aa93daf 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -867,22 +867,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec public void doFilter() { List nodes = getASTreeNodes(tagTree); - boolean updateNeeded = false; for (TreeItem n : nodes) { if (n instanceof ClassesListTreeModel) { ((ClassesListTreeModel) n).setFilter(filterField.getText()); - updateNeeded = true; + TagTreeModel tm = tagTree.getModel(); + tm.updateNode(n); + View.expandTreeNodes(tagTree, tm.getTreePath(n), true); } } - - if (updateNeeded) { - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - tagTree.updateUI(); - } - }); - } } @Override diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 5dfef537a..1b6c782b2 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -58,7 +58,6 @@ import com.jpexs.decompiler.flash.gui.abc.tablemodels.StringTableModel; import com.jpexs.decompiler.flash.gui.abc.tablemodels.UIntTableModel; import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel; import com.jpexs.decompiler.flash.helpers.Freed; -import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.treeitems.TreeItem; import com.jpexs.decompiler.graph.CompilationException; @@ -177,16 +176,15 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se final List found = new ArrayList<>(); if (scriptsNode instanceof ClassesListTreeModel) { ClassesListTreeModel clModel = (ClassesListTreeModel) scriptsNode; - List> allpacks = clModel.getList(); + List allpacks = clModel.getList(); final Pattern pat = regexp ? Pattern.compile(txt, ignoreCase ? Pattern.CASE_INSENSITIVE : 0) : Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0); int pos = 0; - for (final MyEntry item : allpacks) { + for (final ScriptPack pack : allpacks) { pos++; String workText = AppStrings.translate("work.searching"); String decAdd = ""; - final ScriptPack pack = item.getValue(); if (!SWF.isCached(pack)) { decAdd = ", " + AppStrings.translate("work.decompiling"); } @@ -199,14 +197,13 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se if (pat.matcher(SWF.getCached(pack).text).find()) { ABCPanelSearchResult searchResult = new ABCPanelSearchResult(); searchResult.scriptPack = pack; - searchResult.classPath = item.getKey(); found.add(searchResult); } return null; } }; worker.execute(); - Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + allpacks.size() + ") " + item.getKey().toString() + "... ", worker); + Main.startWork(workText + " \"" + txt + "\"" + decAdd + " - (" + pos + "/" + allpacks.size() + ") " + pack.getClassPath().toString() + "... ", worker); worker.get(); } catch (InterruptedException ex) { break; @@ -686,12 +683,12 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se if (scriptsNode instanceof ClassesListTreeModel) { ClassesListTreeModel clModel = (ClassesListTreeModel) scriptsNode; ScriptPack pack = null; - for (MyEntry item : clModel.getList()) { - ClassPath classPath = item.getKey(); - + for (ScriptPack item : clModel.getList()) { + ClassPath classPath = item.getClassPath(); + // first check the className to avoid calling unnecessary toString if (name.endsWith(classPath.className) && classPath.toString().equals(name)) { - pack = item.getValue(); + pack = item; break; } } @@ -807,9 +804,9 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se try { String oldSp = null; - List> packs = abc.script_info.get(oldIndex).getPacks(abc, oldIndex); + List packs = abc.script_info.get(oldIndex).getPacks(abc, oldIndex); if (!packs.isEmpty()) { - oldSp = packs.get(0).getKey().toString(); + oldSp = packs.get(0).getClassPath().toString(); } String as = decompiledTextArea.getText(); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java index 4ddc79c3b..c4d3209fa 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java @@ -16,7 +16,6 @@ */ package com.jpexs.decompiler.flash.gui.abc; -import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; /** @@ -27,10 +26,8 @@ public class ABCPanelSearchResult { public ScriptPack scriptPack; - public ClassPath classPath; - @Override public String toString() { - return classPath.toString(); + return scriptPack.getClassPath().toString(); } } diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java b/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java index 686b66a43..fc8401188 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTreeModel.java @@ -17,12 +17,10 @@ package com.jpexs.decompiler.flash.gui.abc; import com.jpexs.decompiler.flash.SWF; -import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; import com.jpexs.decompiler.flash.gui.AppStrings; -import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.timeline.AS3Package; import com.jpexs.decompiler.flash.treeitems.AS3ClassTreeItem; import java.util.ArrayList; @@ -37,13 +35,13 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel private SWF swf; - private List> list; + private List list; private AS3Package root; private final List listeners = new ArrayList<>(); - public List> getList() { + public List getList() { return list; } @@ -73,19 +71,18 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel } public final void setFilter(String filter) { - root.scripts.clear(); - root.subPackages.clear(); + root.clear(); filter = (filter == null || filter.isEmpty()) ? null : filter.toLowerCase(); - for (MyEntry item : list) { + for (ScriptPack item : list) { if (filter != null) { - if (!item.getKey().toString().toLowerCase().contains(filter)) { + if (!item.getClassPath().toString().toLowerCase().contains(filter)) { continue; } } - AS3Package pkg = ensurePackage(item.getKey().packageStr); - pkg.scripts.put(item.getKey().className, item.getValue()); + AS3Package pkg = ensurePackage(item.getClassPath().packageStr); + pkg.addScriptPack(item); } } @@ -94,10 +91,10 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel AS3Package parent = root; while (st.hasMoreTokens()) { String pathElement = st.nextToken(); - AS3Package pkg = parent.subPackages.get(pathElement); + AS3Package pkg = parent.getSubPackage(pathElement); if (pkg == null) { pkg = new AS3Package(pathElement, swf); - parent.subPackages.put(pathElement, pkg); + parent.addSubPackage(pkg); } parent = pkg; @@ -111,14 +108,14 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel } private ScriptPack getElementByClassIndexRecursive(AS3Package item, int classIndex) { - for (AS3Package pkg : item.subPackages.values()) { + for (AS3Package pkg : item.getSubPackages()) { ScriptPack result = getElementByClassIndexRecursive(pkg, classIndex); if (result != null) { return result; } } - for (ScriptPack sc : item.scripts.values()) { + for (ScriptPack sc : item.getScriptPacks()) { for (Trait t : sc.abc.script_info.get(sc.scriptIndex).traits.traits) { if (t instanceof TraitClass) { if (((TraitClass) t).class_info == classIndex) { @@ -140,7 +137,7 @@ public class ClassesListTreeModel extends AS3ClassTreeItem implements TreeModel AS3Package pkg = (AS3Package) parent; return pkg.getAllChildren(); } - + @Override public AS3ClassTreeItem getChild(Object parent, int index) { AS3Package pkg = (AS3Package) parent; diff --git a/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java b/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java index 4b79cf335..3d87544ca 100644 --- a/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java +++ b/src/com/jpexs/decompiler/flash/gui/debugger/DebuggerTools.java @@ -18,14 +18,12 @@ package com.jpexs.decompiler.flash.gui.debugger; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; -import com.jpexs.decompiler.flash.abc.ClassPath; import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.abc.types.Multiname; import com.jpexs.decompiler.flash.abc.types.Namespace; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.DebugLogDialog; import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.Tag; import com.jpexs.helpers.Helper; @@ -49,9 +47,9 @@ public class DebuggerTools { private static ScriptPack getDebuggerScriptPack(SWF swf) { for (ABCContainerTag ac : swf.getAbcList()) { ABC a = ac.getABC(); - for (MyEntry m : a.getScriptPacks()) { - if (isDebuggerClass(m.getKey().packageStr, null)) { - return m.getValue(); + for (ScriptPack m : a.getScriptPacks()) { + if (isDebuggerClass(m.getClassPath().packageStr, null)) { + return m; } } }