From 45bae59ac9c0995a4428b2b8848abcefdd7b0b8e Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 13 Feb 2022 14:05:50 -0600 Subject: [PATCH] Code Cleanup/Refactoring --- .../bytecode/club/bytecodeviewer/GlobalHotKeys.java | 10 +++------- .../resources/exporting/impl/APKExport.java | 12 +++--------- .../resources/exporting/impl/ZipExport.java | 11 +++-------- .../bytecode/club/bytecodeviewer/util/MiscUtils.java | 8 ++++++++ 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java index d76d8852..5358bc97 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java @@ -7,6 +7,7 @@ import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.gui.components.RunOptions; import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils; +import the.bytecode.club.bytecodeviewer.util.MiscUtils; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -113,20 +114,15 @@ public class GlobalHotKeys { Configuration.setLastSaveDirectory(fc.getSelectedFile()); - File file = fc.getSelectedFile(); - - if (!file.getAbsolutePath().endsWith(".zip")) - file = new File(file.getAbsolutePath() + ".zip"); + File file = MiscUtils.autoAppendFileExtension(".zip", fc.getSelectedFile()); if (!DialogUtils.canOverwriteFile(file)) return; - final File file2 = file; - BytecodeViewer.updateBusyStatus(true); Thread jarExport = new Thread(() -> { JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), - file2.getAbsolutePath()); + file.getAbsolutePath()); BytecodeViewer.updateBusyStatus(false); }, "Jar Export"); jarExport.start(); 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 85160ce4..1285bbad 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 @@ -101,15 +101,9 @@ public class APKExport implements Exporter { Configuration.setLastSaveDirectory(fc.getSelectedFile()); - final File file = fc.getSelectedFile(); - String output = file.getAbsolutePath(); + final File file = MiscUtils.autoAppendFileExtension(".apk", fc.getSelectedFile()); - //auto append .apk - if (!output.endsWith(".apk")) - output += ".apk"; - - final File file2 = new File(output); - if (!DialogUtils.canOverwriteFile(file2)) + if (!DialogUtils.canOverwriteFile(file)) return; Thread saveThread = new Thread(() -> @@ -120,7 +114,7 @@ public class APKExport implements Exporter Thread buildAPKThread = new Thread(() -> { - APKTool.buildAPK(new File(input), file2, finalContainer); + APKTool.buildAPK(new File(input), file, finalContainer); BytecodeViewer.updateBusyStatus(false); }, "Process APK"); buildAPKThread.start(); 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 d4a2dbb7..40bf6cc6 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 @@ -8,6 +8,7 @@ import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import the.bytecode.club.bytecodeviewer.resources.exporting.Exporter; import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils; +import the.bytecode.club.bytecodeviewer.util.MiscUtils; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -54,21 +55,15 @@ public class ZipExport implements Exporter { Configuration.setLastSaveDirectory(fc.getSelectedFile()); - File file = fc.getSelectedFile(); - - //auto append .zip - if (!file.getAbsolutePath().endsWith(".zip")) - file = new File(file.getAbsolutePath() + ".zip"); + final File file = MiscUtils.autoAppendFileExtension(".zip", fc.getSelectedFile()); //auto append .zip extension if (!DialogUtils.canOverwriteFile(file)) return; - final File file2 = file; - BytecodeViewer.updateBusyStatus(true); Thread saveThread = new Thread(() -> { - JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file2.getAbsolutePath()); + JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath()); BytecodeViewer.updateBusyStatus(false); }, "Jar Export"); saveThread.start(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java index 71011aaa..536dc7c1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/MiscUtils.java @@ -178,6 +178,14 @@ public class MiscUtils fileContents[1], fileContents[2],fileContents[3]); } + public static File autoAppendFileExtension(String extension, File file) + { + if (!file.getName().endsWith(extension)) + file = new File(file.getName() + extension); + + return file; + } + public static String extension(String name) { return name.substring(name.lastIndexOf('.') + 1); }