diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index d6534705..d410f47e 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -514,6 +514,16 @@ public class BytecodeViewer { BetterJOptionPane.showMessageDialog(viewer, message); } + + /** + * Send a message to alert the user + * + * @param message the message you need to send + */ + public static String showInput(String message) + { + return BetterJOptionPane.showInputDialog(viewer, message); + } /** * Alerts the user the program is running something in the background @@ -561,6 +571,14 @@ public class BytecodeViewer new ExceptionUI(t, author); } + /** + * Refreshes the title on all of the opened tabs + */ + public static void updateAllClassNodeByteArrays() + { + resourceContainers.forEach(ResourceContainer::updateClassNodeBytes); + } + /** * Refreshes the title on all of the opened tabs */ @@ -572,6 +590,23 @@ public class BytecodeViewer viewer.refreshTitle(); } } + + /** + * Refreshes the title on all of the opened tabs + */ + public static void refreshAllTabs() + { + new Thread(()-> + { + updateBusyStatus(true); + for (int i = 0; i < BytecodeViewer.viewer.workPane.tabs.getTabCount(); i++) + { + ResourceViewer viewer = ((TabbedPane) BytecodeViewer.viewer.workPane.tabs.getTabComponentAt(i)).resource; + viewer.refresh(null); + } + updateBusyStatus(false); + }, "Refresh All Tabs").start(); + } /** * Resets the workspace with optional user input required diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ChangeClassFileVersions.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ChangeClassFileVersions.java new file mode 100644 index 00000000..72fd314f --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ChangeClassFileVersions.java @@ -0,0 +1,42 @@ +package the.bytecode.club.bytecodeviewer.plugin.preinstalled; + +import org.objectweb.asm.tree.ClassNode; +import the.bytecode.club.bytecodeviewer.BytecodeViewer; +import the.bytecode.club.bytecodeviewer.api.Plugin; +import the.bytecode.club.bytecodeviewer.api.PluginConsole; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; + +/** + * As long as there are no new opcodes or API changes you can use this plugin to downgrade compiled code + * + * 1) Import a JDK-11 (or higher) Jar resource inside of BCV + * 2) Run this plugin + * 3) Export as ZIP, then rename as Jar - Your ClassFiles will now run on JDK-8 (or whatever you selected) + * + * @author Konloch + * @since 07/11/2021 + */ +public class ChangeClassFileVersions extends Plugin +{ + @Override + public void execute(ArrayList classNodeList) + { + //prompt dialogue for version number + // TODO: include a little diagram of what JDK is which number + int newVersion = Integer.parseInt(BytecodeViewer.showInput("Class Version Number: (52 = JDK 8)")); + + //update the ClassFile version + classNodeList.forEach(classNode -> classNode.version = newVersion); + + //update the the resource byte[] + BytecodeViewer.updateAllClassNodeByteArrays(); + + //force refresh all tabs + BytecodeViewer.refreshAllTabs(); + + //alert the changes + BytecodeViewer.showMessage("Set all of the class versions to " + newVersion); + } +} \ No newline at end of file