Code Cleanup/Refactoring

This commit is contained in:
Konloch 2022-02-13 14:05:50 -06:00
parent 17ecc2b7e1
commit 45bae59ac9
4 changed files with 17 additions and 24 deletions

View File

@ -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.gui.components.RunOptions;
import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.DialogUtils;
import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -113,20 +114,15 @@ public class GlobalHotKeys
{ {
Configuration.setLastSaveDirectory(fc.getSelectedFile()); Configuration.setLastSaveDirectory(fc.getSelectedFile());
File file = fc.getSelectedFile(); File file = MiscUtils.autoAppendFileExtension(".zip", fc.getSelectedFile());
if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip");
if (!DialogUtils.canOverwriteFile(file)) if (!DialogUtils.canOverwriteFile(file))
return; return;
final File file2 = file;
BytecodeViewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Thread jarExport = new Thread(() -> { Thread jarExport = new Thread(() -> {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(),
file2.getAbsolutePath()); file.getAbsolutePath());
BytecodeViewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Jar Export"); }, "Jar Export");
jarExport.start(); jarExport.start();

View File

@ -101,15 +101,9 @@ public class APKExport implements Exporter
{ {
Configuration.setLastSaveDirectory(fc.getSelectedFile()); Configuration.setLastSaveDirectory(fc.getSelectedFile());
final File file = fc.getSelectedFile(); final File file = MiscUtils.autoAppendFileExtension(".apk", fc.getSelectedFile());
String output = file.getAbsolutePath();
//auto append .apk if (!DialogUtils.canOverwriteFile(file))
if (!output.endsWith(".apk"))
output += ".apk";
final File file2 = new File(output);
if (!DialogUtils.canOverwriteFile(file2))
return; return;
Thread saveThread = new Thread(() -> Thread saveThread = new Thread(() ->
@ -120,7 +114,7 @@ public class APKExport implements Exporter
Thread buildAPKThread = new Thread(() -> Thread buildAPKThread = new Thread(() ->
{ {
APKTool.buildAPK(new File(input), file2, finalContainer); APKTool.buildAPK(new File(input), file, finalContainer);
BytecodeViewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Process APK"); }, "Process APK");
buildAPKThread.start(); buildAPKThread.start();

View File

@ -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.resources.exporting.Exporter;
import the.bytecode.club.bytecodeviewer.util.DialogUtils; import the.bytecode.club.bytecodeviewer.util.DialogUtils;
import the.bytecode.club.bytecodeviewer.util.JarUtils; import the.bytecode.club.bytecodeviewer.util.JarUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
/*************************************************************************** /***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -54,21 +55,15 @@ public class ZipExport implements Exporter
{ {
Configuration.setLastSaveDirectory(fc.getSelectedFile()); Configuration.setLastSaveDirectory(fc.getSelectedFile());
File file = fc.getSelectedFile(); final File file = MiscUtils.autoAppendFileExtension(".zip", fc.getSelectedFile()); //auto append .zip extension
//auto append .zip
if (!file.getAbsolutePath().endsWith(".zip"))
file = new File(file.getAbsolutePath() + ".zip");
if (!DialogUtils.canOverwriteFile(file)) if (!DialogUtils.canOverwriteFile(file))
return; return;
final File file2 = file;
BytecodeViewer.updateBusyStatus(true); BytecodeViewer.updateBusyStatus(true);
Thread saveThread = new Thread(() -> Thread saveThread = new Thread(() ->
{ {
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file2.getAbsolutePath()); JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
BytecodeViewer.updateBusyStatus(false); BytecodeViewer.updateBusyStatus(false);
}, "Jar Export"); }, "Jar Export");
saveThread.start(); saveThread.start();

View File

@ -178,6 +178,14 @@ public class MiscUtils
fileContents[1], fileContents[2],fileContents[3]); 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) { public static String extension(String name) {
return name.substring(name.lastIndexOf('.') + 1); return name.substring(name.lastIndexOf('.') + 1);
} }