From 0888983439c8b79d52a0a3f7587482c900b82d03 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 14 Feb 2020 17:43:22 -0500 Subject: [PATCH] GT-3528 - Small update to defer file chooser creation until needed --- .../fileformats/FileFormatsPlugin.java | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/Ghidra/Features/FileFormats/src/main/java/ghidra/plugins/fileformats/FileFormatsPlugin.java b/Ghidra/Features/FileFormats/src/main/java/ghidra/plugins/fileformats/FileFormatsPlugin.java index 5405e523cb..5c1e29e0ed 100644 --- a/Ghidra/Features/FileFormats/src/main/java/ghidra/plugins/fileformats/FileFormatsPlugin.java +++ b/Ghidra/Features/FileFormats/src/main/java/ghidra/plugins/fileformats/FileFormatsPlugin.java @@ -70,9 +70,6 @@ public class FileFormatsPlugin extends Plugin implements FrontEndable { public FileFormatsPlugin(PluginTool tool) { super(tool); - - chooserEclipse = new GhidraFileChooser(null); - chooserJarFolder = new GhidraFileChooser(null); } @Override @@ -107,6 +104,9 @@ public class FileFormatsPlugin extends Plugin implements FrontEndable { return; } + if (chooserEclipse == null) { + chooserEclipse = new GhidraFileChooser(null); + } chooserEclipse.setFileSelectionMode(GhidraFileChooserMode.DIRECTORIES_ONLY); chooserEclipse.setTitle("Select Eclipe Project Directory"); chooserEclipse.setApproveButtonText("SELECT"); @@ -171,35 +171,40 @@ public class FileFormatsPlugin extends Plugin implements FrontEndable { if (context instanceof FSBActionContext) { FSBActionContext fsbContext = (FSBActionContext) context; FSRL jarFSRL = FSBUtils.getFileFSRLFromContext(context); - if (jarFSRL != null) { - chooserJarFolder.setFileSelectionMode( - GhidraFileChooserMode.DIRECTORIES_ONLY); - chooserJarFolder.setTitle("Select JAR Output Directory"); - chooserJarFolder.setApproveButtonText("SELECT"); - chooserJarFolder.setSelectedFile(null); - File outputDirectory = chooserJarFolder.getSelectedFile(); - if (outputDirectory == null) { - return; - } - GTree gTree = fsbContext.getTree(); - gTree.runTask(monitor -> { - try { - JarDecompiler decompiler = - new JarDecompiler(jarFSRL, outputDirectory); - decompiler.decompile(monitor); - - if (decompiler.getLog().getMsgCount() > 0) { - Msg.showInfo(this, gTree, - "Decompiling Jar " + jarFSRL.getName(), - decompiler.getLog().toString()); - } - } - catch (Exception e) { - FSUtilities.displayException(this, gTree, "Error Decompiling Jar", - e.getMessage(), e); - } - }); + if (jarFSRL == null) { + return; } + + if (chooserJarFolder == null) { + chooserJarFolder = new GhidraFileChooser(null); + } + chooserJarFolder.setFileSelectionMode( + GhidraFileChooserMode.DIRECTORIES_ONLY); + chooserJarFolder.setTitle("Select JAR Output Directory"); + chooserJarFolder.setApproveButtonText("SELECT"); + chooserJarFolder.setSelectedFile(null); + File outputDirectory = chooserJarFolder.getSelectedFile(); + if (outputDirectory == null) { + return; + } + GTree gTree = fsbContext.getTree(); + gTree.runTask(monitor -> { + try { + JarDecompiler decompiler = + new JarDecompiler(jarFSRL, outputDirectory); + decompiler.decompile(monitor); + + if (decompiler.getLog().getMsgCount() > 0) { + Msg.showInfo(this, gTree, + "Decompiling Jar " + jarFSRL.getName(), + decompiler.getLog().toString()); + } + } + catch (Exception e) { + FSUtilities.displayException(this, gTree, "Error Decompiling Jar", + e.getMessage(), e); + } + }); } } @@ -218,6 +223,7 @@ public class FileFormatsPlugin extends Plugin implements FrontEndable { public boolean isAddToPopup(ActionContext context) { return context instanceof FSBActionContext; } + }; action.setPopupMenuData( new MenuData(new String[] { action.getMenuText() }, ImageManager.JAR, "J"));