From f829582ae418504ff6685eeb14fad5a67916c6f9 Mon Sep 17 00:00:00 2001 From: Thog Date: Fri, 24 Mar 2017 01:28:34 +0100 Subject: Implement experimental Tiny mappings loader ~ This will need some tests and more security checks --- src/main/java/cuchaz/enigma/gui/Gui.java | 4 ++++ src/main/java/cuchaz/enigma/gui/GuiController.java | 8 ++++++++ src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 16 ++++++++++++++++ 3 files changed, 28 insertions(+) (limited to 'src/main/java/cuchaz/enigma/gui') diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java index 9f8d6fc..77065a9 100644 --- a/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/src/main/java/cuchaz/enigma/gui/Gui.java @@ -63,6 +63,7 @@ public class Gui { // state public EntryReference reference; public JFileChooser jarFileChooser; + public JFileChooser tinyMappingsFileChooser; public JFileChooser enigmaMappingsFileChooser; public JFileChooser exportSourceFileChooser; public JFileChooser exportJarFileChooser; @@ -105,6 +106,7 @@ public class Gui { // init file choosers this.jarFileChooser = new FileChooserFile(); + this.tinyMappingsFileChooser = new FileChooserFile(); this.enigmaMappingsFileChooser = new FileChooserAny(); this.exportSourceFileChooser = new FileChooserFolder(); this.exportJarFileChooser = new FileChooserFile(); @@ -314,6 +316,7 @@ public class Gui { // update menu this.menuBar.closeJarMenu.setEnabled(true); + this.menuBar.openTinyMappingsMenu.setEnabled(true); this.menuBar.openEnigmaMappingsMenu.setEnabled(true); this.menuBar.saveMappingsMenu.setEnabled(false); this.menuBar.saveMappingEnigmaFileMenu.setEnabled(true); @@ -336,6 +339,7 @@ public class Gui { // update menu this.menuBar.closeJarMenu.setEnabled(false); + this.menuBar.openTinyMappingsMenu.setEnabled(false); this.menuBar.openEnigmaMappingsMenu.setEnabled(false); this.menuBar.saveMappingsMenu.setEnabled(false); this.menuBar.saveMappingEnigmaFileMenu.setEnabled(false); diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 1b461da..c3cdbf8 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java @@ -71,6 +71,14 @@ public class GuiController { refreshCurrentClass(); } + public void openTinyMappings(File file) throws IOException, MappingParseException { + this.deobfuscator.setMappings(new MappingsTinyReader().read(file)); + this.isDirty = false; + this.gui.setMappingsFile(file); + refreshClasses(); + refreshCurrentClass(); + } + public void saveMappings(File file) throws IOException { Mappings mappings = this.deobfuscator.getMappings(); switch (mappings.getOriginMappingFormat()) { diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index cd11aca..e446c5a 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -14,6 +14,7 @@ public class MenuBar extends JMenuBar { public final JMenuItem closeJarMenu; public final JMenuItem openEnigmaMappingsMenu; + public final JMenuItem openTinyMappingsMenu; public final JMenuItem saveMappingsMenu; public final JMenuItem saveMappingEnigmaFileMenu; public final JMenuItem saveMappingEnigmaDirectoryMenu; @@ -71,6 +72,21 @@ public class MenuBar extends JMenuBar { } }); this.openEnigmaMappingsMenu = item; + + item = new JMenuItem("Tiny"); + openMenu.add(item); + item.addActionListener(event -> { + if (this.gui.tinyMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { + try { + this.gui.getController().openTinyMappings(this.gui.tinyMappingsFileChooser.getSelectedFile()); + } catch (IOException ex) { + throw new Error(ex); + } catch (MappingParseException ex) { + JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage()); + } + } + }); + this.openTinyMappingsMenu = item; } { JMenuItem item = new JMenuItem("Save Mappings"); -- cgit v1.2.3