Removed Duplicate File Filters

This commit is contained in:
Konloch 2021-07-21 09:52:01 -07:00
parent 296227360a
commit 7819fe6575
4 changed files with 63 additions and 27 deletions

View File

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

View File

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

View File

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

View File

@ -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<String> 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)