From 964040e83cefb859c7ded053dcb15e66711ad37e Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 4 Jul 2021 21:24:19 -0700 Subject: [PATCH] Fixed Recent Files & Plugins --- .../club/bytecodeviewer/BytecodeViewer.java | 4 ++++ .../club/bytecodeviewer/Settings.java | 22 +++++++++++++++++-- .../resources/importing/ImportResource.java | 2 ++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 7f2c83ac..c110faa1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -509,7 +509,11 @@ public class BytecodeViewer */ public static void startPlugin(File file) { if (!file.exists()) + { + BytecodeViewer.showMessage("The plugin file " + file.getAbsolutePath() + " could not be found."); + Settings.removeRecentPlugin(file); return; + } try { PluginManager.runPlugin(file); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java index a8e9ac6f..8b403d2d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Settings.java @@ -52,7 +52,7 @@ public class Settings * * @param f the recent file */ - public static void addRecentFile(File f) + public static synchronized void addRecentFile(File f) { recentFiles.remove(f.getAbsolutePath()); // already added on the list recentFiles.add(0, f.getAbsolutePath()); @@ -61,12 +61,21 @@ public class Settings resetRecentFilesMenu(); } + public static synchronized void removeRecentFile(File f) + { + if(recentFiles.remove(f.getAbsolutePath())) + { + DiskWriter.replaceFile(filesName, MiscUtils.listToString(recentFiles), false); + resetRecentFilesMenu(); + } + } + /** * Add to the recent plugin list * * @param f the plugin file */ - public static void addRecentPlugin(File f) + public static synchronized void addRecentPlugin(File f) { recentPlugins.remove(f.getAbsolutePath()); // already added on the list recentPlugins.add(0, f.getAbsolutePath()); @@ -75,6 +84,15 @@ public class Settings resetRecentFilesMenu(); } + public static synchronized void removeRecentPlugin(File f) + { + if(recentPlugins.remove(f.getAbsolutePath())) + { + DiskWriter.replaceFile(pluginsName, MiscUtils.listToString(recentPlugins), false); + resetRecentFilesMenu(); + } + } + /** * resets the recent files menu */ diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java index fbf466bf..22544256 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/ImportResource.java @@ -1,6 +1,7 @@ package the.bytecode.club.bytecodeviewer.resources.importing; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Settings; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; @@ -49,6 +50,7 @@ public class ImportResource implements Runnable { update = false; BytecodeViewer.showMessage("The file " + file.getAbsolutePath() + " could not be found."); + Settings.removeRecentFile(file); } else {