Better Functioning Last Directories

This makes it easier on the user by making the directory picking process a bit better
This commit is contained in:
Konloch 2021-07-18 12:53:30 -07:00
parent 3349dd65b7
commit 0973dfdf41
12 changed files with 63 additions and 27 deletions

View file

@ -34,7 +34,9 @@ public class Configuration
public static boolean warnForEditing = false;
public static boolean runningObfuscation = false;
public static final long start = System.currentTimeMillis();
public static String lastDirectory = ".";
public static String lastOpenDirectory = ".";
public static String lastSaveDirectory = ".";
public static String lastPluginDirectory = ".";
public static boolean pingback = false;
public static boolean deleteForeignLibraries = true;
public static boolean canExit = false;
@ -50,9 +52,27 @@ public class Configuration
public static RSTATheme rstaTheme = lafTheme.getRSTATheme();
public static long lastHotKeyExecuted = 0;
public static File getLastDirectory()
public static File getLastOpenDirectory()
{
File lastDir = new File(lastDirectory);
File lastDir = new File(lastOpenDirectory);
if(lastDir.exists())
return lastDir;
return new File(".");
}
public static File getLastSaveDirectory()
{
File lastDir = new File(lastSaveDirectory);
if(lastDir.exists())
return lastDir;
return new File(".");
}
public static File getLastPluginDirectory()
{
File lastDir = new File(lastPluginDirectory);
if(lastDir.exists())
return lastDir;

View file

@ -86,7 +86,7 @@ public class GlobalHotKeys
if (!BytecodeViewer.autoCompileSuccessful())
return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select Zip Export",
"Zip Archives",
"zip");
@ -94,7 +94,7 @@ public class GlobalHotKeys
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
if (!file.getAbsolutePath().endsWith(".zip"))

View file

@ -139,7 +139,7 @@ public class SettingsSerializer
save(BytecodeViewer.viewer.isMaximized);
save("deprecated");
save("deprecated");
save(Configuration.lastDirectory);
save(Configuration.lastOpenDirectory);
save(Configuration.python2);
save(Configuration.rt);
save("deprecated");
@ -336,7 +336,7 @@ public class SettingsSerializer
}
//86 is deprecated
//87 is deprecated
Configuration.lastDirectory = asString(88);
Configuration.lastOpenDirectory = asString(88);
Configuration.python2 = asString(89);
Configuration.rt = asString(90);
@ -388,6 +388,8 @@ public class SettingsSerializer
Configuration.javaTools = asString(134);
Configuration.python2Extra = asString(135);
Configuration.python3Extra = asString(136);
Configuration.lastSaveDirectory = asString(137);
Configuration.lastPluginDirectory = asString(138);
}
catch (IndexOutOfBoundsException e)
{

View file

@ -850,7 +850,9 @@ public class MainViewerGUI extends JFrame
{
final File file = DialogueUtils.fileChooser("Select External Plugin",
"External Plugin",
Configuration.getLastOpenDirectory(),
PluginManager.fileFilter(),
(f)-> Configuration.lastPluginDirectory = f.getAbsolutePath(),
FileChooser.EVERYTHING);
if(file == null)

View file

@ -131,7 +131,7 @@ public class PluginWriter extends JFrame
if(savePath == null)
{
final String ext = FileNameUtils.getExtension(pluginName);
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastPluginDirectory(),
"Save Plugin",
"BCV Plugin",
ext);
@ -139,7 +139,7 @@ public class PluginWriter extends JFrame
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastPluginDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
String path = file.getAbsolutePath();

View file

@ -34,7 +34,7 @@ public class ResourceDecompiling
if (!BytecodeViewer.autoCompileSuccessful())
return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select Zip Export",
"Zip Archives",
"zip");
@ -42,7 +42,7 @@ public class ResourceDecompiling
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
//auto appened zip
@ -193,7 +193,7 @@ public class ResourceDecompiling
final ClassNode cn = BytecodeViewer.getCurrentlyOpenedClassNode();
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select Java Files",
"Java Source Files",
"java");
@ -201,7 +201,7 @@ public class ResourceDecompiling
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
BytecodeViewer.updateBusyStatus(true);

View file

@ -68,7 +68,7 @@ public class APKExport implements Exporter
if (!BytecodeViewer.autoCompileSuccessful())
return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select APK Export",
"Android APK",
"apk");
@ -76,7 +76,7 @@ public class APKExport implements Exporter
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
final File file = fc.getSelectedFile();
String output = file.getAbsolutePath();

View file

@ -33,7 +33,7 @@ public class DexExport implements Exporter
if (!BytecodeViewer.autoCompileSuccessful())
return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select DEX Export",
"Android DEX Files",
"dex");
@ -41,7 +41,7 @@ public class DexExport implements Exporter
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
final File file = fc.getSelectedFile();
String output = file.getAbsolutePath();

View file

@ -27,7 +27,7 @@ public class RunnableJarExporter implements Exporter
if (!BytecodeViewer.autoCompileSuccessful())
return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select Jar Export",
"Jar Archives",
"jar");
@ -35,7 +35,7 @@ public class RunnableJarExporter implements Exporter
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
String path = file.getAbsolutePath();

View file

@ -27,7 +27,7 @@ public class ZipExport implements Exporter
if (!BytecodeViewer.autoCompileSuccessful())
return;
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastSaveDirectory(),
"Select Zip Export",
"Zip Archives",
"zip");
@ -35,7 +35,7 @@ public class ZipExport implements Exporter
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
//auto append .zip

View file

@ -77,7 +77,16 @@ public class DialogueUtils
*/
public static File fileChooser(String title, String description, FileFilter filter, String... extensions)
{
final JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
return fileChooser(title, description, Configuration.getLastOpenDirectory(), filter,
(f)-> Configuration.lastOpenDirectory = f.getAbsolutePath(), extensions);
}
/**
* Prompts a File Chooser dilogue
*/
public static File fileChooser(String title, String description, File directory, FileFilter filter, OnOpenEvent onOpen, String... extensions)
{
final JFileChooser fc = new FileChooser(directory,
title,
description,
extensions);
@ -89,7 +98,7 @@ public class DialogueUtils
if (returnVal == JFileChooser.APPROVE_OPTION)
try {
File file = fc.getSelectedFile();
Configuration.lastDirectory = file.getAbsolutePath();
onOpen.onOpen(file);
return file;
} catch (Exception e1) {
BytecodeViewer.handleException(e1);
@ -97,4 +106,9 @@ public class DialogueUtils
return null;
}
public interface OnOpenEvent
{
void onOpen(File fileSelected);
}
}

View file

@ -3,13 +3,11 @@ package the.bytecode.club.bytecodeviewer.util;
import me.konloch.kontainer.io.HTTPRequest;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.api.ExceptionUI;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
@ -78,7 +76,7 @@ public class VersionChecker implements Runnable
}
else if (result == 1)
{
JFileChooser fc = new FileChooser(Configuration.getLastDirectory(),
JFileChooser fc = new FileChooser(Configuration.getLastOpenDirectory(),
"Select Save File",
"Zip Archives",
"zip");
@ -92,7 +90,7 @@ public class VersionChecker implements Runnable
int returnVal = fc.showSaveDialog(BytecodeViewer.viewer);
if (returnVal == JFileChooser.APPROVE_OPTION)
{
Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath();
Configuration.lastOpenDirectory = fc.getSelectedFile().getAbsolutePath();
File file = fc.getSelectedFile();
if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip");