Commit 6fb1c8d3 authored by Skylot's avatar Skylot

gui: don't decode resources on file open

parent 6047a27c
...@@ -51,7 +51,7 @@ public class ResContainer implements Comparable<ResContainer> { ...@@ -51,7 +51,7 @@ public class ResContainer implements Comparable<ResContainer> {
try { try {
decoder.decode(content, os); decoder.decode(content, os);
} catch (Exception e) { } catch (Exception e) {
LOG.error("Failed to decode 9-patch png image", e); LOG.error("Failed to decode 9-patch png image, path: {}", name, e);
} }
newContent = new ByteArrayInputStream(os.toByteArray()); newContent = new ByteArrayInputStream(os.toByteArray());
} }
......
...@@ -12,7 +12,7 @@ import jadx.core.dex.info.AccessInfo; ...@@ -12,7 +12,7 @@ import jadx.core.dex.info.AccessInfo;
import jadx.gui.utils.NLS; import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils; import jadx.gui.utils.Utils;
public class JClass extends JNode { public class JClass extends JLoadableNode {
private static final long serialVersionUID = -1239986875244097177L; private static final long serialVersionUID = -1239986875244097177L;
private static final ImageIcon ICON_CLASS = Utils.openIcon("class_obj"); private static final ImageIcon ICON_CLASS = Utils.openIcon("class_obj");
...@@ -43,6 +43,11 @@ public class JClass extends JNode { ...@@ -43,6 +43,11 @@ public class JClass extends JNode {
return cls; return cls;
} }
@Override
public void loadNode() {
getRootClass().load();
}
public synchronized void load() { public synchronized void load() {
if (!loaded) { if (!loaded) {
cls.decompile(); cls.decompile();
......
package jadx.gui.treemodel;
public abstract class JLoadableNode extends JNode {
public abstract void loadNode();
}
...@@ -6,16 +6,20 @@ import java.util.List; ...@@ -6,16 +6,20 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.jetbrains.annotations.NotNull;
import jadx.api.ResourceFile; import jadx.api.ResourceFile;
import jadx.api.ResourceFileContent; import jadx.api.ResourceFileContent;
import jadx.api.ResourceType; import jadx.api.ResourceType;
import jadx.core.codegen.CodeWriter; import jadx.core.codegen.CodeWriter;
import jadx.core.xmlgen.ResContainer; import jadx.core.xmlgen.ResContainer;
import jadx.gui.utils.NLS;
import jadx.gui.utils.OverlayIcon; import jadx.gui.utils.OverlayIcon;
import jadx.gui.utils.Utils; import jadx.gui.utils.Utils;
public class JResource extends JNode implements Comparable<JResource> { import static jadx.api.ResourceFileContent.createResourceFileContentInstance;
public class JResource extends JLoadableNode implements Comparable<JResource> {
private static final long serialVersionUID = -201018424302612434L; private static final long serialVersionUID = -201018424302612434L;
private static final ImageIcon ROOT_ICON = Utils.openIcon("cf_obj"); private static final ImageIcon ROOT_ICON = Utils.openIcon("cf_obj");
...@@ -50,22 +54,35 @@ public class JResource extends JNode implements Comparable<JResource> { ...@@ -50,22 +54,35 @@ public class JResource extends JNode implements Comparable<JResource> {
this.name = name; this.name = name;
this.shortName = shortName; this.shortName = shortName;
this.type = type; this.type = type;
this.loaded = false;
} }
public final void update() { public final void update() {
loadContent();
removeAllChildren(); removeAllChildren();
if (!loaded) {
if (type == JResType.DIR
|| type == JResType.ROOT
|| resFile.getType() == ResourceType.ARSC) {
add(new TextNode(NLS.str("tree.loading")));
}
} else {
loadContent();
for (JResource res : files) { for (JResource res : files) {
res.update(); res.update();
add(res); add(res);
} }
} }
}
@Override
public void loadNode() {
loadContent();
loaded = true;
update();
}
private void loadContent() { private void loadContent() {
getContent(); getContent();
for (JResource res : files) {
res.loadContent();
}
} }
@Override @Override
...@@ -101,8 +118,8 @@ public class JResource extends JNode implements Comparable<JResource> { ...@@ -101,8 +118,8 @@ public class JResource extends JNode implements Comparable<JResource> {
String resName = rc.getName(); String resName = rc.getName();
String[] path = resName.split("/"); String[] path = resName.split("/");
String resShortName = path.length == 0 ? resName : path[path.length - 1]; String resShortName = path.length == 0 ? resName : path[path.length - 1];
ResourceFileContent fileContent = ResourceFileContent.createResourceFileContentInstance(resShortName, ResourceType.XML, cw); ResourceFileContent fileContent = createResourceFileContentInstance(resShortName, ResourceType.XML, cw);
if(fileContent != null) { if (fileContent != null) {
addPath(path, root, new JResource(fileContent, resName, resShortName, JResType.FILE)); addPath(path, root, new JResource(fileContent, resName, resShortName, JResType.FILE));
} }
} }
...@@ -242,7 +259,7 @@ public class JResource extends JNode implements Comparable<JResource> { ...@@ -242,7 +259,7 @@ public class JResource extends JNode implements Comparable<JResource> {
} }
@Override @Override
public int compareTo(JResource o) { public int compareTo(@NotNull JResource o) {
return name.compareTo(o.name); return name.compareTo(o.name);
} }
...@@ -266,5 +283,4 @@ public class JResource extends JNode implements Comparable<JResource> { ...@@ -266,5 +283,4 @@ public class JResource extends JNode implements Comparable<JResource> {
public int hashCode() { public int hashCode() {
return name.hashCode(); return name.hashCode();
} }
} }
...@@ -10,6 +10,7 @@ import java.util.regex.Pattern; ...@@ -10,6 +10,7 @@ import java.util.regex.Pattern;
import jadx.api.ResourceFile; import jadx.api.ResourceFile;
import jadx.gui.JadxWrapper; import jadx.gui.JadxWrapper;
import jadx.gui.treemodel.JResource.JResType; import jadx.gui.treemodel.JResource.JResType;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils; import jadx.gui.utils.Utils;
public class JRoot extends JNode { public class JRoot extends JNode {
...@@ -41,7 +42,7 @@ public class JRoot extends JNode { ...@@ -41,7 +42,7 @@ public class JRoot extends JNode {
if (resources.isEmpty()) { if (resources.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
JResource root = new JResource(null, "Resources", JResType.ROOT); JResource root = new JResource(null, NLS.str("tree.resources_title"), JResType.ROOT);
String splitPathStr = Pattern.quote(File.separator); String splitPathStr = Pattern.quote(File.separator);
for (ResourceFile rf : resources) { for (ResourceFile rf : resources) {
String rfName; String rfName;
......
...@@ -12,6 +12,7 @@ import java.util.Set; ...@@ -12,6 +12,7 @@ import java.util.Set;
import jadx.api.JavaPackage; import jadx.api.JavaPackage;
import jadx.gui.JadxWrapper; import jadx.gui.JadxWrapper;
import jadx.gui.utils.NLS;
import jadx.gui.utils.Utils; import jadx.gui.utils.Utils;
public class JSources extends JNode { public class JSources extends JNode {
...@@ -132,6 +133,6 @@ public class JSources extends JNode { ...@@ -132,6 +133,6 @@ public class JSources extends JNode {
@Override @Override
public String makeString() { public String makeString() {
return "Source code"; return NLS.str("tree.sources_title");
} }
} }
...@@ -41,6 +41,7 @@ import jadx.gui.jobs.IndexJob; ...@@ -41,6 +41,7 @@ import jadx.gui.jobs.IndexJob;
import jadx.gui.settings.JadxSettings; import jadx.gui.settings.JadxSettings;
import jadx.gui.settings.JadxSettingsWindow; import jadx.gui.settings.JadxSettingsWindow;
import jadx.gui.treemodel.JClass; import jadx.gui.treemodel.JClass;
import jadx.gui.treemodel.JLoadableNode;
import jadx.gui.treemodel.JNode; import jadx.gui.treemodel.JNode;
import jadx.gui.treemodel.JResource; import jadx.gui.treemodel.JResource;
import jadx.gui.treemodel.JRoot; import jadx.gui.treemodel.JRoot;
...@@ -581,9 +582,8 @@ public class MainWindow extends JFrame { ...@@ -581,9 +582,8 @@ public class MainWindow extends JFrame {
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
TreePath path = event.getPath(); TreePath path = event.getPath();
Object node = path.getLastPathComponent(); Object node = path.getLastPathComponent();
if (node instanceof JClass) { if (node instanceof JLoadableNode) {
JClass cls = (JClass) node; ((JLoadableNode) node).loadNode();
cls.getRootClass().load();
} }
} }
......
...@@ -23,6 +23,8 @@ file.save_all_msg=Select directory for save decompiled sources ...@@ -23,6 +23,8 @@ file.save_all_msg=Select directory for save decompiled sources
file.select=Select file.select=Select
file.exit=Exit file.exit=Exit
tree.sources_title=Source code
tree.resources_title=Resources
tree.loading=Loading... tree.loading=Loading...
search=Search search=Search
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment