From b676890aebf7e07817b680a688e6fb3536055998 Mon Sep 17 00:00:00 2001 From: Konloch Date: Sat, 26 Jun 2021 05:59:51 -0700 Subject: [PATCH] Resource Importing Code Cleanup --- .../club/bytecodeviewer/BytecodeViewer.java | 13 ++++++------- .../gui/components/FileChooser.java | 1 - .../ImportResource.java} | 13 ++++++++----- .../bytecodeviewer/util/resources/ImportType.java | 15 +++++++++++++++ 4 files changed, 29 insertions(+), 13 deletions(-) rename src/main/java/the/bytecode/club/bytecodeviewer/util/{OpenFile.java => resources/ImportResource.java} (96%) create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportType.java diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index e1feb949..23681873 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -11,7 +11,7 @@ import java.util.HashMap; import java.util.List; import java.util.Objects; import javax.swing.*; -import javax.swing.filechooser.FileFilter; + import me.konloch.kontainer.io.HTTPRequest; import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; @@ -33,6 +33,7 @@ import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.util.*; +import the.bytecode.club.bytecodeviewer.util.resources.ImportResource; import static the.bytecode.club.bytecodeviewer.Constants.*; @@ -327,11 +328,9 @@ public class BytecodeViewer * @return the file contents as a byte[] */ public static byte[] getFileContents(String name) { - for (FileContainer container : files) { - HashMap files = container.files; - if (files.containsKey(name)) - return files.get(name); - } + for (FileContainer container : files) + if (container.files.containsKey(name)) + return container.files.get(name); return null; } @@ -528,7 +527,7 @@ public class BytecodeViewer BytecodeViewer.viewer.updateBusyStatus(true); Configuration.needsReDump = true; - Thread t = new Thread(new OpenFile(files)); + Thread t = new Thread(new ImportResource(files)); t.start(); } 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 fd8ab512..42fceafe 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 @@ -1,6 +1,5 @@ package the.bytecode.club.bytecodeviewer.gui.components; -import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.util.MiscUtils; import javax.swing.*; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java similarity index 96% rename from src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java rename to src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java index 9725644b..032a597f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/OpenFile.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportResource.java @@ -1,4 +1,4 @@ -package the.bytecode.club.bytecodeviewer.util; +package the.bytecode.club.bytecodeviewer.util.resources; import org.apache.commons.io.FileUtils; import org.objectweb.asm.tree.ClassNode; @@ -6,6 +6,7 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListPane; import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI; +import the.bytecode.club.bytecodeviewer.util.*; import java.io.File; import java.io.FileInputStream; @@ -40,18 +41,20 @@ import static the.bytecode.club.bytecodeviewer.Constants.fs; /** * @author Konloch */ -public class OpenFile implements Runnable +public class ImportResource implements Runnable { private boolean update = true; private final File[] files; - public OpenFile(File[] files) {this.files = files;} + public ImportResource(File[] files) {this.files = files;} @Override public void run() { - try { - for (final File f : files) { + try + { + for (final File f : files) + { final String fn = f.getName(); if (!f.exists()) { update = false; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportType.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportType.java new file mode 100644 index 00000000..9c1a39a0 --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/resources/ImportType.java @@ -0,0 +1,15 @@ +package the.bytecode.club.bytecodeviewer.util.resources; + +/** + * @author Konloch + * @since 6/26/2021 + */ +public enum ImportType +{ + DIRECTORY, + FILE, + ZIP, + CLASS, + APK, + DEX, +}