diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java index 93d02ae1..de8c8fcc 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java @@ -53,10 +53,25 @@ public class Configuration public static RSTATheme rstaTheme = lafTheme.getRSTATheme(); public static long lastHotKeyExecuted = 0; + public static void setLastOpenDirectory(File file) + { + lastOpenDirectory = file.getAbsolutePath(); + } + + public static void setLastSaveDirectory(File file) + { + lastSaveDirectory = file.getAbsolutePath(); + } + + public static void setLastPluginDirectory(File file) + { + lastPluginDirectory = file.getAbsolutePath(); + } + public static File getLastOpenDirectory() { File lastDir = new File(lastOpenDirectory); - if(lastDir.exists()) + if(lastDir.getParentFile().exists()) return lastDir; return new File("."); @@ -65,7 +80,7 @@ public class Configuration public static File getLastSaveDirectory() { File lastDir = new File(lastSaveDirectory); - if(lastDir.exists()) + if(lastDir.getParentFile().exists()) return lastDir; return new File("."); @@ -74,7 +89,8 @@ public class Configuration public static File getLastPluginDirectory() { File lastDir = new File(lastPluginDirectory); - if(lastDir.exists()) + + if(lastDir.getParentFile().exists()) return lastDir; return new File("."); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java index 4b5ee818..b0406248 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java @@ -94,7 +94,8 @@ public class GlobalHotKeys int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); if (!file.getAbsolutePath().endsWith(".zip")) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index c048d38e..abab8bc2 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -898,7 +898,7 @@ public class MainViewerGUI extends JFrame "External Plugin", Configuration.getLastPluginDirectory(), PluginManager.fileFilter(), - (f)-> Configuration.lastPluginDirectory = f.getAbsolutePath(), + Configuration::setLastPluginDirectory, FileChooser.EVERYTHING); if(file == null) 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 4cc8f33e..749ed270 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 @@ -5,6 +5,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; import javax.swing.filechooser.FileFilter; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashSet; @@ -16,13 +17,12 @@ public class FileChooser extends JFileChooser { public static final String EVERYTHING = "everything"; - public FileChooser(File filePath, String title, String description, String... extensions) + public FileChooser(File file, String title, String description, String... extensions) { HashSet extensionSet = new HashSet<>(Arrays.asList(extensions)); try { - if (filePath.exists()) - setSelectedFile(filePath); + setSelectedFile(file); } catch (Exception ignored) { } setDialogTitle(title); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java index 01ffe1d5..afff4660 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/PluginWriter.java @@ -105,7 +105,7 @@ public class PluginWriter extends JFrame "External Plugin", Configuration.getLastPluginDirectory(), PluginManager.fileFilter(), - (f)-> Configuration.lastPluginDirectory = f.getAbsolutePath(), + Configuration::setLastPluginDirectory, FileChooser.EVERYTHING); if(file == null || !file.exists()) @@ -168,7 +168,8 @@ public class PluginWriter extends JFrame int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastPluginDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastPluginDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); String path = file.getAbsolutePath(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java index e3b1d743..93736b94 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -43,7 +43,8 @@ public class ResourceDecompiling int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); //auto appened zip @@ -202,7 +203,8 @@ public class ResourceDecompiling int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); BytecodeViewer.updateBusyStatus(true); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java index f5529ff9..1bd8eba8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java @@ -76,7 +76,8 @@ public class APKExport implements Exporter int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + final File file = fc.getSelectedFile(); String output = file.getAbsolutePath(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java index c9026cd5..2d32aefd 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java @@ -41,7 +41,8 @@ public class DexExport implements Exporter int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + final File file = fc.getSelectedFile(); String output = file.getAbsolutePath(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java index 0a73d3db..81c53305 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/RunnableJarExporter.java @@ -35,7 +35,8 @@ public class RunnableJarExporter implements Exporter int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); String path = file.getAbsolutePath(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java index 3974d36a..ac6b81d1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java @@ -35,7 +35,8 @@ public class ZipExport implements Exporter int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastSaveDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastSaveDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); //auto append .zip diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogueUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogueUtils.java index 66789da2..3f3e431c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogueUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/DialogueUtils.java @@ -78,7 +78,7 @@ public class DialogueUtils public static File fileChooser(String title, String description, FileFilter filter, String... extensions) { return fileChooser(title, description, Configuration.getLastOpenDirectory(), filter, - (f)-> Configuration.lastOpenDirectory = f.getAbsolutePath(), extensions); + Configuration::setLastOpenDirectory, extensions); } /** diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java index e070da07..9a7f6cdc 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java @@ -90,7 +90,8 @@ public class VersionChecker implements Runnable int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastOpenDirectory = fc.getSelectedFile().getAbsolutePath(); + Configuration.setLastOpenDirectory(fc.getSelectedFile()); + File file = fc.getSelectedFile(); if (!file.getAbsolutePath().endsWith(".zip")) file = new File(file.getAbsolutePath() + ".zip");