Code Cleanup
This commit is contained in:
parent
7214aa1bde
commit
5603f466b3
5 changed files with 144 additions and 167 deletions
|
@ -40,6 +40,7 @@ public class Constants
|
|||
public static final String libsDirectory = getBCVDirectory() + fs + "libs" + fs;
|
||||
public static String krakatauWorkingDirectory = getBCVDirectory() + fs + "krakatau_" + krakatauVersion;
|
||||
public static String enjarifyWorkingDirectory = getBCVDirectory() + fs + "enjarify_" + enjarifyVersion;
|
||||
public static final String[] SUPPORTED_FILE_EXTENSIONS = new String[]{"jar", "zip", "class", "apk", "dex", "war", "jsp"};
|
||||
|
||||
public static List<String> recentPlugins;
|
||||
public static List<String> recentFiles;
|
||||
|
|
|
@ -10,11 +10,9 @@ import javax.swing.*;
|
|||
import javax.swing.filechooser.FileFilter;
|
||||
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
|
||||
import the.bytecode.club.bytecodeviewer.Configuration;
|
||||
import the.bytecode.club.bytecodeviewer.Resources;
|
||||
import the.bytecode.club.bytecodeviewer.Settings;
|
||||
import the.bytecode.club.bytecodeviewer.*;
|
||||
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
|
||||
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
|
||||
import the.bytecode.club.bytecodeviewer.gui.components.VisibleComponent;
|
||||
import the.bytecode.club.bytecodeviewer.gui.components.AboutWindow;
|
||||
import the.bytecode.club.bytecodeviewer.gui.components.RunOptions;
|
||||
|
@ -740,52 +738,20 @@ public class MainViewerGUI extends JFrame {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void selectFile()
|
||||
public void compileOnNewThread()
|
||||
{
|
||||
final JFileChooser fc = new JFileChooser();
|
||||
|
||||
try {
|
||||
File f = new File(Configuration.lastDirectory);
|
||||
if (f.exists())
|
||||
fc.setSelectedFile(f);
|
||||
} catch (Exception ignored) {
|
||||
Thread t = new Thread(() -> BytecodeViewer.compile(true));
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void runResources()
|
||||
{
|
||||
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
|
||||
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
|
||||
return;
|
||||
}
|
||||
|
||||
fc.setDialogTitle("Select File or Folder to open in BCV");
|
||||
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||
fc.setAcceptAllFileFilterUsed(true);
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
if (f.isDirectory())
|
||||
return true;
|
||||
|
||||
String extension = MiscUtils.extension(f.getAbsolutePath());
|
||||
return extension.equals("jar") || extension.equals("zip")
|
||||
|| extension.equals("class") || extension.equals("apk")
|
||||
|| extension.equals("dex") || extension.equals("war") || extension.equals("jsp");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "APKs, DEX, Class Files or Zip/Jar/War Archives";
|
||||
}
|
||||
});
|
||||
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION) {
|
||||
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
|
||||
try {
|
||||
BytecodeViewer.viewer.updateBusyStatus(true);
|
||||
BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true);
|
||||
BytecodeViewer.viewer.updateBusyStatus(false);
|
||||
} catch (Exception e1) {
|
||||
new ExceptionUI(e1);
|
||||
}
|
||||
}
|
||||
new RunOptions().setVisible(true);
|
||||
}
|
||||
|
||||
public void reloadResources()
|
||||
|
@ -826,48 +792,34 @@ public class MainViewerGUI extends JFrame {
|
|||
}
|
||||
}
|
||||
|
||||
public void compileOnNewThread()
|
||||
public void selectFile()
|
||||
{
|
||||
Thread t = new Thread(() -> BytecodeViewer.compile(true));
|
||||
t.start();
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select File or Folder to open in BCV",
|
||||
"APKs, DEX, Class Files or Zip/Jar/War Archives",
|
||||
Constants.SUPPORTED_FILE_EXTENSIONS);
|
||||
|
||||
public void runResources()
|
||||
{
|
||||
if (BytecodeViewer.getLoadedClasses().isEmpty()) {
|
||||
BytecodeViewer.showMessage("First open a class, jar, zip, apk or dex file.");
|
||||
return;
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
{
|
||||
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
|
||||
try {
|
||||
BytecodeViewer.viewer.updateBusyStatus(true);
|
||||
BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true);
|
||||
BytecodeViewer.viewer.updateBusyStatus(false);
|
||||
} catch (Exception e1) {
|
||||
new ExceptionUI(e1);
|
||||
}
|
||||
}
|
||||
|
||||
new RunOptions().setVisible(true);
|
||||
}
|
||||
|
||||
public void showForeignLibraryWarning()
|
||||
{
|
||||
if (!deleteForeignOutdatedLibs.isSelected()) {
|
||||
BytecodeViewer.showMessage("WARNING: With this being toggled off outdated libraries will NOT be "
|
||||
+ "removed. It's also a security issue. ONLY TURN IT OFF IF YOU KNOW WHAT YOU'RE DOING.");
|
||||
}
|
||||
Configuration.deleteForeignLibraries = deleteForeignOutdatedLibs.isSelected();
|
||||
}
|
||||
|
||||
public void selectPythonC() {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return true;
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select Python 2.7 Executable",
|
||||
"Python (Or PyPy for speed) 2.7 Executable",
|
||||
"everything");
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Python (Or PyPy for speed) 2.7 Executable";
|
||||
}
|
||||
});
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
Configuration.python = fc.getSelectedFile().getAbsolutePath();
|
||||
|
@ -877,22 +829,12 @@ public class MainViewerGUI extends JFrame {
|
|||
}
|
||||
|
||||
public void selectJavac() {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return true;
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select Javac Executable",
|
||||
"Javac Executable (Requires JDK 'C:/programfiles/Java/JDK_xx/bin/javac.exe)",
|
||||
"everything");
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Javac Executable (Requires JDK 'C:/programfiles/Java/JDK_xx/bin/javac.exe)";
|
||||
}
|
||||
});
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
Configuration.javac = fc.getSelectedFile().getAbsolutePath();
|
||||
|
@ -902,22 +844,12 @@ public class MainViewerGUI extends JFrame {
|
|||
}
|
||||
|
||||
public void selectJava() {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return true;
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select Java Executable",
|
||||
"Java Executable (Inside Of JRE/JDK 'C:/programfiles/Java/JDK_xx/bin/java.exe')",
|
||||
"everything");
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Java Executable (Inside Of JRE/JDK 'C:/programfiles/Java/JDK_xx/bin/java.exe')";
|
||||
}
|
||||
});
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
Configuration.java = fc.getSelectedFile().getAbsolutePath();
|
||||
|
@ -927,22 +859,12 @@ public class MainViewerGUI extends JFrame {
|
|||
}
|
||||
|
||||
public void selectPythonC3() {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return true;
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select Python 3.x Executable",
|
||||
"Python (Or PyPy for speed) 3.x Executable",
|
||||
"everything");
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Python (Or PyPy for speed) 3.x Executable";
|
||||
}
|
||||
});
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
Configuration.python3 = fc.getSelectedFile().getAbsolutePath();
|
||||
|
@ -952,23 +874,16 @@ public class MainViewerGUI extends JFrame {
|
|||
}
|
||||
|
||||
public void selectOpenalLibraryFolder() {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return f.isDirectory();
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select Library Folder",
|
||||
"Optional Library Folder",
|
||||
"everything");
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Optional Library Folder";
|
||||
}
|
||||
});
|
||||
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
Configuration.library = fc.getSelectedFile().getAbsolutePath();
|
||||
|
@ -978,22 +893,12 @@ public class MainViewerGUI extends JFrame {
|
|||
}
|
||||
|
||||
public void selectJRERTLibrary() {
|
||||
JFileChooser fc = new JFileChooser();
|
||||
fc.setFileFilter(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File f) {
|
||||
return true;
|
||||
}
|
||||
final JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select JRE RT Jar",
|
||||
"JRE RT Library",
|
||||
"everything");
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "JRE RT Library";
|
||||
}
|
||||
});
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
Configuration.rt = fc.getSelectedFile().getAbsolutePath();
|
||||
|
@ -1004,12 +909,13 @@ public class MainViewerGUI extends JFrame {
|
|||
|
||||
public void openExternalPlugin()
|
||||
{
|
||||
JFileChooser fc = new JFileChooser();
|
||||
JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory),
|
||||
"Select External Plugin",
|
||||
"External Plugin",
|
||||
"everything");
|
||||
fc.setFileFilter(PluginManager.fileFilter());
|
||||
fc.setFileHidingEnabled(false);
|
||||
fc.setAcceptAllFileFilterUsed(false);
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
|
||||
int returnVal = fc.showOpenDialog(BytecodeViewer.viewer);
|
||||
if (returnVal == JFileChooser.APPROVE_OPTION)
|
||||
try {
|
||||
BytecodeViewer.viewer.updateBusyStatus(true);
|
||||
|
@ -1022,12 +928,12 @@ public class MainViewerGUI extends JFrame {
|
|||
|
||||
public void askBeforeExiting()
|
||||
{
|
||||
JOptionPane pane = new JOptionPane(
|
||||
"Are you sure you want to exit?");
|
||||
JOptionPane pane = new JOptionPane("Are you sure you want to exit?");
|
||||
|
||||
Object[] options = new String[]{"Yes", "No"};
|
||||
|
||||
pane.setOptions(options);
|
||||
JDialog dialog = pane.createDialog(BytecodeViewer.viewer,
|
||||
"Bytecode Viewer - Exit");
|
||||
JDialog dialog = pane.createDialog(BytecodeViewer.viewer, "Bytecode Viewer - Exit");
|
||||
dialog.setVisible(true);
|
||||
Object obj = pane.getValue();
|
||||
int result = -1;
|
||||
|
@ -1035,9 +941,21 @@ public class MainViewerGUI extends JFrame {
|
|||
if (options[k].equals(obj))
|
||||
result = k;
|
||||
|
||||
if (result == 0) {
|
||||
if (result == 0)
|
||||
{
|
||||
Configuration.canExit = true;
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void showForeignLibraryWarning()
|
||||
{
|
||||
if (!deleteForeignOutdatedLibs.isSelected())
|
||||
{
|
||||
BytecodeViewer.showMessage("WARNING: With this being toggled off outdated libraries will NOT be "
|
||||
+ "removed. It's also a security issue. ONLY TURN IT OFF IF YOU KNOW WHAT YOU'RE DOING.");
|
||||
}
|
||||
|
||||
Configuration.deleteForeignLibraries = deleteForeignOutdatedLibs.isSelected();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package the.bytecode.club.bytecodeviewer.gui.components;
|
||||
|
||||
import the.bytecode.club.bytecodeviewer.Configuration;
|
||||
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileFilter;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
|
||||
/**
|
||||
* @author Konloch
|
||||
* @since 6/25/2021
|
||||
*/
|
||||
public class FileChooser extends JFileChooser
|
||||
{
|
||||
private final File filePath;
|
||||
private final String title;
|
||||
private final String description;
|
||||
private final String[] extensions;
|
||||
private final HashSet<String> extensionSet = new HashSet<>();
|
||||
|
||||
public FileChooser(File filePath, String title, String description, String... extensions)
|
||||
{
|
||||
this.filePath = filePath;
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.extensions = extensions;
|
||||
|
||||
try {
|
||||
if (filePath.exists())
|
||||
setSelectedFile(filePath);
|
||||
} catch (Exception ignored) { }
|
||||
|
||||
setDialogTitle(title);
|
||||
setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
|
||||
setFileHidingEnabled(false);
|
||||
setAcceptAllFileFilterUsed(false);
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils;
|
|||
|
||||
/**
|
||||
* Supports loading of groovy, python or ruby scripts.
|
||||
* <p>
|
||||
*
|
||||
* Only allows one plugin to be running at once.
|
||||
*
|
||||
* @author Konloch
|
||||
|
|
|
@ -25,9 +25,8 @@ import org.jetbrains.annotations.NotNull;
|
|||
***************************************************************************/
|
||||
|
||||
/**
|
||||
* Convert the various newline conventions to the local platform's
|
||||
* newline convention. <p>
|
||||
* <p>
|
||||
* Convert the various newline conventions to the local platform's newline convention.
|
||||
*
|
||||
* This stream can be used with the Message.writeTo method to
|
||||
* generate a message that uses the local plaform's line terminator
|
||||
* for the purpose of (e.g.) saving the message to a local file.
|
||||
|
|
Loading…
Reference in a new issue