From 00fcd0550fcdda621c2e4662f6ddd55ce673b931 Mon Sep 17 00:00:00 2001 From: Gegy Date: Thu, 24 Jan 2019 14:48:32 +0200 Subject: [WIP] Mapping rework (#91) * Move packages * Mapping & entry refactor: first pass * Fix deobf -> obf tree remapping * Resolve various issues * Give all entries the potential for parents and treat inner classes as children * Deobf UI tree elements * Tests pass * Sort mapping output * Fix delta tracking * Index separation and first pass for #97 * Keep track of remapped jar index * Fix child entries not being remapped * Drop non-root entries * Track dropped mappings * Fix enigma mapping ordering * EntryTreeNode interface * Small tweaks * Naive full index remap on rename * Entries can resolve to more than one root entry * Support alternative resolution strategies * Bridge method resolution * Tests pass * Fix mappings being used where there are none * Fix methods with different descriptors being considered unique. closes #89 --- .../java/cuchaz/enigma/gui/elements/MenuBar.java | 45 ++++++---------------- 1 file changed, 12 insertions(+), 33 deletions(-) (limited to 'src/main/java/cuchaz/enigma/gui/elements') diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 609aecb..f4f0277 100644 --- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java @@ -5,6 +5,7 @@ import cuchaz.enigma.config.Themes; import cuchaz.enigma.gui.Gui; import cuchaz.enigma.gui.dialog.AboutDialog; import cuchaz.enigma.throwables.MappingParseException; +import cuchaz.enigma.translation.mapping.serde.MappingFormat; import javax.swing.*; import java.awt.event.InputEvent; @@ -23,7 +24,6 @@ public class MenuBar extends JMenuBar { public final JMenuItem saveMappingEnigmaDirectoryMenu; public final JMenuItem saveMappingsSrgMenu; public final JMenuItem closeMappingsMenu; - public final JMenuItem rebuildMethodNamesMenu; public final JMenuItem exportSourceMenu; public final JMenuItem exportJarMenu; private final Gui gui; @@ -68,7 +68,9 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { try { - this.gui.getController().openEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile()); + File selectedFile = this.gui.enigmaMappingsFileChooser.getSelectedFile(); + MappingFormat format = selectedFile.isDirectory() ? MappingFormat.ENIGMA_DIRECTORY : MappingFormat.ENIGMA_FILE; + this.gui.getController().openMappings(format, selectedFile.toPath()); } catch (IOException ex) { throw new Error(ex); } catch (MappingParseException ex) { @@ -85,7 +87,7 @@ public class MenuBar extends JMenuBar { File file = new File(this.gui.tinyMappingsFileChooser.getDirectory() + File.separator + this.gui.tinyMappingsFileChooser.getFile()); if (file.exists()) { try { - this.gui.getController().openTinyMappings(file); + this.gui.getController().openMappings(MappingFormat.TINY_FILE, file.toPath()); } catch (IOException ex) { throw new Error(ex); } catch (MappingParseException ex) { @@ -99,11 +101,7 @@ public class MenuBar extends JMenuBar { JMenuItem item = new JMenuItem("Save Mappings"); menu.add(item); item.addActionListener(event -> { - try { - this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile()); - } catch (IOException ex) { - throw new Error(ex); - } + this.gui.getController().saveMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); }); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); this.saveMappingsMenu = item; @@ -116,12 +114,8 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - try { - this.gui.getController().saveEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile(), false); - this.saveMappingsMenu.setEnabled(true); - } catch (IOException ex) { - throw new Error(ex); - } + this.gui.getController().saveMappings(MappingFormat.ENIGMA_FILE, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); + this.saveMappingsMenu.setEnabled(true); } }); this.saveMappingEnigmaFileMenu = item; @@ -132,12 +126,8 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - try { - this.gui.getController().saveEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile(), true); - this.saveMappingsMenu.setEnabled(true); - } catch (IOException ex) { - throw new Error(ex); - } + this.gui.getController().saveMappings(MappingFormat.ENIGMA_DIRECTORY, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); + this.saveMappingsMenu.setEnabled(true); } }); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); @@ -149,12 +139,8 @@ public class MenuBar extends JMenuBar { item.addActionListener(event -> { // TODO: Use a specific file chooser for it if (this.gui.enigmaMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { - try { - this.gui.getController().saveSRGMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile()); - this.saveMappingsMenu.setEnabled(true); - } catch (IOException ex) { - throw new Error(ex); - } + this.gui.getController().saveMappings(MappingFormat.SRG_FILE, this.gui.enigmaMappingsFileChooser.getSelectedFile().toPath()); + this.saveMappingsMenu.setEnabled(true); } }); this.saveMappingsSrgMenu = item; @@ -183,13 +169,6 @@ public class MenuBar extends JMenuBar { this.closeMappingsMenu = item; } menu.addSeparator(); - { - JMenuItem item = new JMenuItem("Rebuild Method Names"); - menu.add(item); - item.addActionListener(event -> this.gui.getController().rebuildMethodNames()); - this.rebuildMethodNamesMenu = item; - } - menu.addSeparator(); { JMenuItem item = new JMenuItem("Export Source..."); menu.add(item); -- cgit v1.2.3