From 7819fe657531c51fc7d5616e23fd98b609a85a2a Mon Sep 17 00:00:00 2001 From: Konloch Date: Wed, 21 Jul 2021 09:52:01 -0700 Subject: [PATCH] Removed Duplicate File Filters --- .../club/bytecodeviewer/BytecodeViewer.java | 18 ++++----- .../gui/components/FileChooser.java | 40 +++++++++++-------- .../bytecodeviewer/plugin/PluginManager.java | 3 +- .../club/bytecodeviewer/util/DialogUtils.java | 29 +++++++++++++- 4 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 30228632..eea778ae 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -8,27 +8,27 @@ import javax.swing.*; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import me.konloch.kontainer.io.DiskReader; import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; + +import me.konloch.kontainer.io.DiskReader; + import the.bytecode.club.bytecodeviewer.bootloader.Boot; import the.bytecode.club.bytecodeviewer.api.BCV; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; +import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import the.bytecode.club.bytecodeviewer.gui.components.*; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.TabbedPane; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; -import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer; import the.bytecode.club.bytecodeviewer.plugin.PluginWriter; -import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; +import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer; import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; -import the.bytecode.club.bytecodeviewer.util.*; +import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource; +import the.bytecode.club.bytecodeviewer.util.*; import static the.bytecode.club.bytecodeviewer.Constants.*; -import static the.bytecode.club.bytecodeviewer.Settings.addRecentPlugin; -import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -193,7 +193,7 @@ public class BytecodeViewer //set translation language if (!Settings.hasSetLanguageAsSystemLanguage) - MiscUtils.setLanguage(guessLanguage()); + MiscUtils.setLanguage(MiscUtils.guessLanguage()); //handle CLI int CLI = CommandLineInput.parseCommandLine(args); @@ -551,7 +551,7 @@ public class BytecodeViewer BytecodeViewer.handleException(e); } - addRecentPlugin(file); + Settings.addRecentPlugin(file); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java index 749ed270..0c0924c5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/FileChooser.java @@ -18,6 +18,11 @@ public class FileChooser extends JFileChooser public static final String EVERYTHING = "everything"; public FileChooser(File file, String title, String description, String... extensions) + { + this(false, file, title, description, extensions); + } + + public FileChooser(boolean skipFileFilter, File file, String title, String description, String... extensions) { HashSet extensionSet = new HashSet<>(Arrays.asList(extensions)); @@ -29,24 +34,27 @@ public class FileChooser extends JFileChooser setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); setFileHidingEnabled(false); setAcceptAllFileFilterUsed(false); - setFileFilter(new FileFilter() + if(!skipFileFilter) { - @Override - public boolean accept(File f) + setFileFilter(new FileFilter() { - if (f.isDirectory()) - return true; + @Override + public boolean accept(File f) + { + if (f.isDirectory()) + return true; + + if(extensions[0].equals(EVERYTHING)) + return true; + + return extensionSet.contains(MiscUtils.extension(f.getAbsolutePath())); + } - if(extensions[0].equals(EVERYTHING)) - return true; - - return extensionSet.contains(MiscUtils.extension(f.getAbsolutePath())); - } - - @Override - public String getDescription() { - return description; - } - }); + @Override + public String getDescription() { + return description; + } + }); + } } } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java index b68b03f0..9fa9f0a5 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginManager.java @@ -8,6 +8,7 @@ import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.PluginConsole; import the.bytecode.club.bytecodeviewer.gui.components.JFrameConsoleTabbed; import the.bytecode.club.bytecodeviewer.plugin.strategies.*; +import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import the.bytecode.club.bytecodeviewer.util.MiscUtils; /*************************************************************************** @@ -167,7 +168,7 @@ public final class PluginManager @Override public String getDescription() { - return "BCV Plugins"; + return TranslatedStrings.SELECT_EXTERNAL_PLUGIN_DESCRIPTION.toString(); } } } \ No newline at end of file diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogUtils.java index 9941d92b..a594ca6e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogUtils.java @@ -9,6 +9,10 @@ import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings; import javax.swing.*; import javax.swing.filechooser.FileFilter; import java.io.File; +import java.util.Arrays; +import java.util.HashSet; + +import static the.bytecode.club.bytecodeviewer.gui.components.FileChooser.EVERYTHING; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -86,13 +90,36 @@ public class DialogUtils */ public static File fileChooser(String title, String description, File directory, FileFilter filter, OnOpenEvent onOpen, String... extensions) { - final JFileChooser fc = new FileChooser(directory, + HashSet extensionSet = new HashSet<>(Arrays.asList(extensions)); + + final JFileChooser fc = new FileChooser(true, + directory, title, description, extensions); if(filter != null) fc.setFileFilter(filter); + else + fc.setFileFilter(new FileFilter() + { + @Override + public boolean accept(File f) + { + if (f.isDirectory()) + return true; + + if(extensions[0].equals(EVERYTHING)) + return true; + + return extensionSet.contains(MiscUtils.extension(f.getAbsolutePath())); + } + + @Override + public String getDescription() { + return description; + } + }); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION)