diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index dada629e..3c050e9e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -74,7 +74,6 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * http://the.bytecode.club * * TODO BUGS: - * + Last selected directory isn't set on most file chooser dialogues * + Synchronized scrolling is broken * + Spam-clicking the refresh button will cause the swing thread to deadlock (Quickly opening resources used to also do this) * This is caused by the ctrlMouseWheelZoom code, a temporary patch is just removing it worst case @@ -627,9 +626,10 @@ public class BytecodeViewer Constants.SUPPORTED_FILE_EXTENSIONS); int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); - if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); + if (returnVal == JFileChooser.APPROVE_OPTION) + { try { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true); BytecodeViewer.viewer.updateBusyStatus(false); @@ -669,7 +669,9 @@ public class BytecodeViewer "zip"); int returnVal = fc.showSaveDialog(viewer); - if (returnVal == JFileChooser.APPROVE_OPTION) { + if (returnVal == JFileChooser.APPROVE_OPTION) + { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); if (!file.getAbsolutePath().endsWith(".zip")) file = new File(file.getAbsolutePath() + ".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 33b4f864..0f8bb374 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -811,8 +811,8 @@ public class MainViewerGUI extends JFrame int returnVal = fc.showOpenDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { - Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); try { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); BytecodeViewer.viewer.updateBusyStatus(true); BytecodeViewer.openFiles(new File[]{fc.getSelectedFile()}, true); BytecodeViewer.viewer.updateBusyStatus(false); 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 298baf23..44fab720 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceDecompiling.java @@ -46,6 +46,7 @@ public class ResourceDecompiling int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); //auto appened zip @@ -222,6 +223,7 @@ public class ResourceDecompiling int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); BytecodeViewer.viewer.updateBusyStatus(true); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceExporting.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceExporting.java index 5b13130a..3875c95d 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceExporting.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceExporting.java @@ -42,6 +42,7 @@ public class ResourceExporting int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); String path = file.getAbsolutePath(); @@ -97,6 +98,7 @@ public class ResourceExporting int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); //auto append .zip @@ -159,6 +161,7 @@ public class ResourceExporting int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); final File file = fc.getSelectedFile(); String output = file.getAbsolutePath(); @@ -267,6 +270,7 @@ public class ResourceExporting int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); if (returnVal == JFileChooser.APPROVE_OPTION) { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); final File file = fc.getSelectedFile(); String output = file.getAbsolutePath(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java index 405e3d79..74ecc4eb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/ZipResourceImporter.java @@ -16,16 +16,26 @@ public class ZipResourceImporter implements Importer @Override public boolean open(File file) throws Exception { - try { - JarUtils.put(file); - } catch (IOException z) { - try { - JarUtils.put2(file); - } catch (final Exception e) { + //attempt to load archives using the first method + try + { + JarUtils.importArchiveA(file); + } + catch (IOException z) + { + //attempt to load archives using the fallback method on fail + try + { + JarUtils.importArchiveB(file); + } + catch (final Exception e) + { new ExceptionUI(e); return false; } - } catch (final Exception e) { + } + catch (final Exception e) + { new ExceptionUI(e); return false; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java index ffb33a59..91e10580 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -57,7 +57,8 @@ public class JarUtils { * @param jarFile the input jar file * @throws IOException */ - public static void put(final File jarFile) throws IOException { + public static void importArchiveA(final File jarFile) throws IOException + { FileContainer container = new FileContainer(jarFile); HashMap files = new HashMap<>(); @@ -101,8 +102,16 @@ public class JarUtils { container.files = files; BytecodeViewer.files.add(container); } - - public static void put2(final File jarFile) throws IOException { + + + /** + * A fallback solution to zip/jar archive importing if the first fails + * + * @param jarFile the input jar file + * @throws IOException + */ + public static void importArchiveB(final File jarFile) throws IOException + { //if this ever fails, worst case import Sun's jarsigner code from JDK 7 re-sign the jar to rebuild the CRC, // should also rebuild the archive byte offsets @@ -143,9 +152,9 @@ public class JarUtils { container.files = files; BytecodeViewer.files.add(container); } - - - public static ArrayList loadClasses(final File jarFile) throws IOException { + + public static ArrayList loadClasses(final File jarFile) throws IOException + { ArrayList classes = new ArrayList<>(); ZipInputStream jis = new ZipInputStream(new FileInputStream(jarFile)); ZipEntry entry; 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 f798d844..a68e6527 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/VersionChecker.java @@ -2,7 +2,9 @@ package the.bytecode.club.bytecodeviewer.util; import me.konloch.kontainer.io.HTTPRequest; import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.Configuration; import the.bytecode.club.bytecodeviewer.api.ExceptionUI; +import the.bytecode.club.bytecodeviewer.gui.components.FileChooser; import javax.swing.*; import javax.swing.filechooser.FileFilter; @@ -56,7 +58,8 @@ public class VersionChecker implements Runnable } - if (!VERSION.equals(version)) { + if (!VERSION.equals(version)) + { JOptionPane pane = new JOptionPane( "Your version: " + VERSION + ", latest version: " + version + nl + "What would you like to do?"); @@ -70,40 +73,37 @@ public class VersionChecker implements Runnable if (options[k].equals(obj)) result = k; - if (result == 0) { - if (Desktop.isDesktopSupported()) { + if (result == 0) + { + if (Desktop.isDesktopSupported()) Desktop.getDesktop().browse(new URI("https://github.com/Konloch/bytecode-viewer/releases")); - } else { + else BytecodeViewer.showMessage("Cannot open the page, please manually type it." + nl + "https://github.com/Konloch/bytecode-viewer/releases"); - } } - if (result == 1) { - JFileChooser fc = new JFileChooser(); + + if (result == 1) + { + JFileChooser fc = new FileChooser(new File(Configuration.lastDirectory), + "Select Save File", + "Zip Archives", + "zip"); + try { fc.setCurrentDirectory(new File(".").getAbsoluteFile()); //set the current working directory } catch (Exception e) { new ExceptionUI(e); } - fc.setFileFilter(new FileFilter() { - @Override - public boolean accept(File f) { - return f.isDirectory() || MiscUtils.extension(f.getAbsolutePath()).equals("zip"); - } - - @Override - public String getDescription() { - return "Zip Archives"; - } - }); - fc.setFileHidingEnabled(false); - fc.setAcceptAllFileFilterUsed(false); + int returnVal = fc.showSaveDialog(BytecodeViewer.viewer); - if (returnVal == JFileChooser.APPROVE_OPTION) { + if (returnVal == JFileChooser.APPROVE_OPTION) + { + Configuration.lastDirectory = fc.getSelectedFile().getAbsolutePath(); File file = fc.getSelectedFile(); if (!file.getAbsolutePath().endsWith(".zip")) file = new File(file.getAbsolutePath() + ".zip"); - if (file.exists()) { + if (file.exists()) + { pane = new JOptionPane("The file " + file + " exists, would you like to overwrite it?"); options = new String[]{"Yes", "No"}; pane.setOptions(options); @@ -136,12 +136,15 @@ public class VersionChecker implements Runnable BytecodeViewer.showMessage("Downloading the jar in the background, when it's finished " + "you will be alerted with another message box." + nl + nl + "Expect this to take several minutes."); - while ((len = is.read(buffer)) > 0) { + + while ((len = is.read(buffer)) > 0) + { fos.write(buffer, 0, len); fos.flush(); downloaded += 8192; int mbs = downloaded / 1048576; - if (mbs % 5 == 0 && mbs != 0) { + if (mbs % 5 == 0 && mbs != 0) + { if (!flag) System.out.println("Downloaded " + mbs + "MBs so far"); flag = true;