summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/gui
diff options
context:
space:
mode:
authorGravatar Thomas Guillemard2016-08-12 19:23:54 +0200
committerGravatar Adrian Siekierka2016-08-12 19:23:54 +0200
commitc4970cc4addedd4565cf8c3ed9ea92b6a4487e0c (patch)
treea6f00a59cd0d5bc41014768506d9c4d3aad48de8 /src/main/java/cuchaz/enigma/gui
parentAllow exporting mappings as SRG or Enigma (diff)
downloadenigma-fork-c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c.tar.gz
enigma-fork-c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c.tar.xz
enigma-fork-c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c.zip
Implement Enigma directory format (#1)
Others changes: ~ Rework File menu ~ Force UTF-8 for all I/O operations ~ Enigma now detect the original file format and use the correct one when you save a mapping
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui')
-rw-r--r--src/main/java/cuchaz/enigma/gui/Gui.java33
-rw-r--r--src/main/java/cuchaz/enigma/gui/GuiController.java35
-rw-r--r--src/main/java/cuchaz/enigma/gui/elements/MenuBar.java85
-rw-r--r--src/main/java/cuchaz/enigma/gui/filechooser/FileChooserAny.java11
4 files changed, 104 insertions, 60 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/Gui.java b/src/main/java/cuchaz/enigma/gui/Gui.java
index 5b0b599..2269476 100644
--- a/src/main/java/cuchaz/enigma/gui/Gui.java
+++ b/src/main/java/cuchaz/enigma/gui/Gui.java
@@ -34,6 +34,7 @@ import cuchaz.enigma.analysis.*;
34import cuchaz.enigma.gui.dialog.CrashDialog; 34import cuchaz.enigma.gui.dialog.CrashDialog;
35import cuchaz.enigma.gui.elements.MenuBar; 35import cuchaz.enigma.gui.elements.MenuBar;
36import cuchaz.enigma.gui.elements.PopupMenuBar; 36import cuchaz.enigma.gui.elements.PopupMenuBar;
37import cuchaz.enigma.gui.filechooser.FileChooserAny;
37import cuchaz.enigma.gui.filechooser.FileChooserFile; 38import cuchaz.enigma.gui.filechooser.FileChooserFile;
38import cuchaz.enigma.gui.filechooser.FileChooserFolder; 39import cuchaz.enigma.gui.filechooser.FileChooserFolder;
39import cuchaz.enigma.gui.highlight.DeobfuscatedHighlightPainter; 40import cuchaz.enigma.gui.highlight.DeobfuscatedHighlightPainter;
@@ -78,8 +79,8 @@ public class Gui {
78 public EntryReference<Entry, Entry> m_reference; 79 public EntryReference<Entry, Entry> m_reference;
79 80
80 public JFileChooser jarFileChooser; 81 public JFileChooser jarFileChooser;
81 public JFileChooser mappingsFileChooser; 82 public JFileChooser jsonMappingsFileChooser;
82 public JFileChooser oldMappingsFileChooser; 83 public JFileChooser enigmaMappingsFileChooser;
83 84
84 public JFileChooser exportSourceFileChooser; 85 public JFileChooser exportSourceFileChooser;
85 public JFileChooser exportJarFileChooser; 86 public JFileChooser exportJarFileChooser;
@@ -106,10 +107,10 @@ public class Gui {
106 107
107 // init file choosers 108 // init file choosers
108 this.jarFileChooser = new FileChooserFile(); 109 this.jarFileChooser = new FileChooserFile();
109 this.mappingsFileChooser = new FileChooserFolder(); 110 this.jsonMappingsFileChooser = new FileChooserFolder();
110 111
111 112
112 this.oldMappingsFileChooser = new FileChooserFile(); 113 this.enigmaMappingsFileChooser = new FileChooserAny();
113 this.exportSourceFileChooser = new FileChooserFolder(); 114 this.exportSourceFileChooser = new FileChooserFolder();
114 this.exportJarFileChooser = new FileChooserFile(); 115 this.exportJarFileChooser = new FileChooserFile();
115 116
@@ -315,11 +316,12 @@ public class Gui {
315 316
316 // update menu 317 // update menu
317 this.menuBar.closeJarMenu.setEnabled(true); 318 this.menuBar.closeJarMenu.setEnabled(true);
318 this.menuBar.openOldMappingsMenu.setEnabled(true); 319 this.menuBar.openEnigmaMappingsMenu.setEnabled(true);
319 this.menuBar.openMappingsMenu.setEnabled(true); 320 this.menuBar.openMappingsJsonMenu.setEnabled(true);
320 this.menuBar.saveMappingsMenu.setEnabled(false); 321 this.menuBar.saveMappingsMenu.setEnabled(false);
321 this.menuBar.saveMappingsAsMenu.setEnabled(true); 322 this.menuBar.saveMappingsJsonMenu.setEnabled(true);
322 this.menuBar.saveMappingsOldMenu.setEnabled(true); 323 this.menuBar.saveMappingEnigmaFileMenu.setEnabled(true);
324 this.menuBar.saveMappingEnigmaDirectoryMenu.setEnabled(true);
323 this.menuBar.saveMappingsSrgMenu.setEnabled(true); 325 this.menuBar.saveMappingsSrgMenu.setEnabled(true);
324 this.menuBar.closeMappingsMenu.setEnabled(true); 326 this.menuBar.closeMappingsMenu.setEnabled(true);
325 this.menuBar.exportSourceMenu.setEnabled(true); 327 this.menuBar.exportSourceMenu.setEnabled(true);
@@ -338,11 +340,12 @@ public class Gui {
338 340
339 // update menu 341 // update menu
340 this.menuBar.closeJarMenu.setEnabled(false); 342 this.menuBar.closeJarMenu.setEnabled(false);
341 this.menuBar.openOldMappingsMenu.setEnabled(false); 343 this.menuBar.openEnigmaMappingsMenu.setEnabled(false);
342 this.menuBar.openMappingsMenu.setEnabled(false); 344 this.menuBar.openMappingsJsonMenu.setEnabled(false);
343 this.menuBar.saveMappingsMenu.setEnabled(false); 345 this.menuBar.saveMappingsMenu.setEnabled(false);
344 this.menuBar.saveMappingsAsMenu.setEnabled(false); 346 this.menuBar.saveMappingsJsonMenu.setEnabled(false);
345 this.menuBar.saveMappingsOldMenu.setEnabled(false); 347 this.menuBar.saveMappingEnigmaFileMenu.setEnabled(false);
348 this.menuBar.saveMappingEnigmaDirectoryMenu.setEnabled(false);
346 this.menuBar.saveMappingsSrgMenu.setEnabled(false); 349 this.menuBar.saveMappingsSrgMenu.setEnabled(false);
347 this.menuBar.closeMappingsMenu.setEnabled(false); 350 this.menuBar.closeMappingsMenu.setEnabled(false);
348 this.menuBar.exportSourceMenu.setEnabled(false); 351 this.menuBar.exportSourceMenu.setEnabled(false);
@@ -360,7 +363,7 @@ public class Gui {
360 } 363 }
361 364
362 public void setMappingsFile(File file) { 365 public void setMappingsFile(File file) {
363 this.mappingsFileChooser.setSelectedFile(file); 366 this.jsonMappingsFileChooser.setSelectedFile(file);
364 this.menuBar.saveMappingsMenu.setEnabled(file != null); 367 this.menuBar.saveMappingsMenu.setEnabled(file != null);
365 } 368 }
366 369
@@ -721,9 +724,9 @@ public class Gui {
721 JOptionPane.QUESTION_MESSAGE, null, options, options[2]); 724 JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
722 switch (response) { 725 switch (response) {
723 case JOptionPane.YES_OPTION: // save and exit 726 case JOptionPane.YES_OPTION: // save and exit
724 if (this.mappingsFileChooser.getSelectedFile() != null || this.mappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION) { 727 if (this.jsonMappingsFileChooser.getSelectedFile() != null || this.jsonMappingsFileChooser.showSaveDialog(this.frame) == JFileChooser.APPROVE_OPTION) {
725 try { 728 try {
726 this.controller.saveMappings(this.mappingsFileChooser.getCurrentDirectory()); 729 this.controller.saveMappings(this.jsonMappingsFileChooser.getCurrentDirectory());
727 this.frame.dispose(); 730 this.frame.dispose();
728 } catch (IOException ex) { 731 } catch (IOException ex) {
729 throw new Error(ex); 732 throw new Error(ex);
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java
index fe7d097..d416345 100644
--- a/src/main/java/cuchaz/enigma/gui/GuiController.java
+++ b/src/main/java/cuchaz/enigma/gui/GuiController.java
@@ -16,7 +16,6 @@ import com.google.common.collect.Queues;
16import com.strobel.decompiler.languages.java.ast.CompilationUnit; 16import com.strobel.decompiler.languages.java.ast.CompilationUnit;
17 17
18import java.io.File; 18import java.io.File;
19import java.io.FileReader;
20import java.io.FileWriter; 19import java.io.FileWriter;
21import java.io.IOException; 20import java.io.IOException;
22import java.util.Collection; 21import java.util.Collection;
@@ -65,18 +64,16 @@ public class GuiController {
65 this.gui.onCloseJar(); 64 this.gui.onCloseJar();
66 } 65 }
67 66
68 public void openOldMappings(File file) throws IOException, MappingParseException { 67 public void openEnigmaMappings(File file) throws IOException, MappingParseException {
69 FileReader in = new FileReader(file); 68 this.deobfuscator.setMappings(new MappingsEnigmaReader().read(file));
70 this.deobfuscator.setMappings(new MappingsReaderOld().read(in));
71 in.close();
72 this.isDirty = false; 69 this.isDirty = false;
73 this.gui.setMappingsFile(file); 70 this.gui.setMappingsFile(file);
74 refreshClasses(); 71 refreshClasses();
75 refreshCurrentClass(); 72 refreshCurrentClass();
76 } 73 }
77 74
78 public void openMappings(File file) throws IOException { 75 public void openJsonMappings(File file) throws IOException {
79 this.deobfuscator.setMappings(new MappingsReader().read(file)); 76 this.deobfuscator.setMappings(new MappingsJsonReader().read(file));
80 this.isDirty = false; 77 this.isDirty = false;
81 this.gui.setMappingsFile(file); 78 this.gui.setMappingsFile(file);
82 refreshClasses(); 79 refreshClasses();
@@ -84,13 +81,29 @@ public class GuiController {
84 } 81 }
85 82
86 public void saveMappings(File file) throws IOException { 83 public void saveMappings(File file) throws IOException {
87 new MappingsWriter().write(file, this.deobfuscator.getMappings()); 84 Mappings mappings = this.deobfuscator.getMappings();
85 switch (mappings.getOriginMappingFormat())
86 {
87 case SRG_FILE:
88 saveSRGMappings(file);
89 break;
90 case JSON_DIRECTORY:
91 saveJsonMappings(file);
92 break;
93 default:
94 saveEnigmaMappings(file, Mappings.FormatType.ENIGMA_FILE != mappings.getOriginMappingFormat());
95 break;
96 }
97
98 }
99
100 public void saveJsonMappings(File file) throws IOException {
101 new MappingsJsonWriter().write(file, this.deobfuscator.getMappings());
88 this.isDirty = false; 102 this.isDirty = false;
89 } 103 }
90 104
91 public void saveOldMappings(File file) throws IOException { 105 public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException {
92 FileWriter out = new FileWriter(file); 106 new MappingsEnigmaWriter().write(file, this.deobfuscator.getMappings(), isDirectoryFormat);
93 new MappingsOldWriter().write(out, this.deobfuscator.getMappings());
94 this.isDirty = false; 107 this.isDirty = false;
95 } 108 }
96 109
diff --git a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
index e79476b..e988d74 100644
--- a/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
+++ b/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java
@@ -17,12 +17,13 @@ public class MenuBar extends JMenuBar {
17 17
18 public final JMenuItem closeJarMenu; 18 public final JMenuItem closeJarMenu;
19 19
20 public final JMenuItem openMappingsMenu; 20 public final JMenuItem openMappingsJsonMenu;
21 public final JMenuItem openOldMappingsMenu; 21 public final JMenuItem openEnigmaMappingsMenu;
22 22
23 public final JMenuItem saveMappingsMenu; 23 public final JMenuItem saveMappingsMenu;
24 public final JMenuItem saveMappingsAsMenu; 24 public final JMenuItem saveMappingsJsonMenu;
25 public final JMenuItem saveMappingsOldMenu; 25 public final JMenuItem saveMappingEnigmaFileMenu;
26 public final JMenuItem saveMappingEnigmaDirectoryMenu;
26 public final JMenuItem saveMappingsSrgMenu; 27 public final JMenuItem saveMappingsSrgMenu;
27 public final JMenuItem closeMappingsMenu; 28 public final JMenuItem closeMappingsMenu;
28 29
@@ -62,43 +63,44 @@ public class MenuBar extends JMenuBar {
62 this.closeJarMenu = item; 63 this.closeJarMenu = item;
63 } 64 }
64 menu.addSeparator(); 65 menu.addSeparator();
66 JMenu openMenu = new JMenu("Open Mappings...");
65 { 67 {
66 JMenuItem item = new JMenuItem("Open Mappings..."); 68 JMenuItem item = new JMenuItem("Enigma");
67 menu.add(item); 69 openMenu.add(item);
68 item.addActionListener(event -> { 70 item.addActionListener(event -> {
69 if (this.gui.mappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 71 if (this.gui.enigmaMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
70 try { 72 try {
71 this.gui.getController().openMappings(this.gui.mappingsFileChooser.getSelectedFile()); 73 this.gui.getController().openEnigmaMappings(this.gui.enigmaMappingsFileChooser.getSelectedFile());
72 } catch (IOException ex) { 74 } catch (IOException ex) {
73 throw new Error(ex); 75 throw new Error(ex);
76 } catch (MappingParseException ex) {
77 JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage());
74 } 78 }
75 } 79 }
76 }); 80 });
77 this.openMappingsMenu = item; 81 this.openEnigmaMappingsMenu = item;
78 } 82 }
83 menu.add(openMenu);
79 { 84 {
80 JMenuItem item = new JMenuItem("Open Old Mappings..."); 85 JMenuItem item = new JMenuItem("JSON (directory)");
81 menu.add(item); 86 openMenu.add(item);
82 item.addActionListener(event -> { 87 item.addActionListener(event -> {
83 if (this.gui.oldMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 88 if (this.gui.jsonMappingsFileChooser.showOpenDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
84 try { 89 try {
85 this.gui.getController().openOldMappings(this.gui.oldMappingsFileChooser.getSelectedFile()); 90 this.gui.getController().openJsonMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
86 } catch (IOException ex) { 91 } catch (IOException ex) {
87 throw new Error(ex); 92 throw new Error(ex);
88 } catch (MappingParseException ex) {
89 JOptionPane.showMessageDialog(this.gui.getFrame(), ex.getMessage());
90 } 93 }
91 } 94 }
92 }); 95 });
93 this.openOldMappingsMenu = item; 96 this.openMappingsJsonMenu = item;
94 } 97 }
95 menu.addSeparator();
96 { 98 {
97 JMenuItem item = new JMenuItem("Save Mappings"); 99 JMenuItem item = new JMenuItem("Save Mappings");
98 menu.add(item); 100 menu.add(item);
99 item.addActionListener(event -> { 101 item.addActionListener(event -> {
100 try { 102 try {
101 this.gui.getController().saveMappings(this.gui.mappingsFileChooser.getSelectedFile()); 103 this.gui.getController().saveMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
102 } catch (IOException ex) { 104 } catch (IOException ex) {
103 throw new Error(ex); 105 throw new Error(ex);
104 } 106 }
@@ -106,29 +108,29 @@ public class MenuBar extends JMenuBar {
106 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK)); 108 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
107 this.saveMappingsMenu = item; 109 this.saveMappingsMenu = item;
108 } 110 }
111 JMenu saveMenu = new JMenu("Save Mappings As...");
109 { 112 {
110 JMenuItem item = new JMenuItem("Save Mappings As..."); 113 JMenuItem item = new JMenuItem("Enigma (single file)");
111 menu.add(item); 114 saveMenu.add(item);
112 item.addActionListener(event -> { 115 item.addActionListener(event -> {
113 if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 116 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
114 try { 117 try {
115 this.gui.getController().saveMappings(this.gui.mappingsFileChooser.getSelectedFile()); 118 this.gui.getController().saveEnigmaMappings(this.gui.jsonMappingsFileChooser.getSelectedFile(), false);
116 this.saveMappingsMenu.setEnabled(true); 119 this.saveMappingsMenu.setEnabled(true);
117 } catch (IOException ex) { 120 } catch (IOException ex) {
118 throw new Error(ex); 121 throw new Error(ex);
119 } 122 }
120 } 123 }
121 }); 124 });
122 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 125 this.saveMappingEnigmaFileMenu = item;
123 this.saveMappingsAsMenu = item;
124 } 126 }
125 { 127 {
126 JMenuItem item = new JMenuItem("Save Mappings as Enigma"); 128 JMenuItem item = new JMenuItem("Enigma (directory)");
127 menu.add(item); 129 saveMenu.add(item);
128 item.addActionListener(event -> { 130 item.addActionListener(event -> {
129 if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 131 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
130 try { 132 try {
131 this.gui.getController().saveOldMappings(this.gui.mappingsFileChooser.getSelectedFile()); 133 this.gui.getController().saveEnigmaMappings(this.gui.jsonMappingsFileChooser.getSelectedFile(), true);
132 this.saveMappingsMenu.setEnabled(true); 134 this.saveMappingsMenu.setEnabled(true);
133 } catch (IOException ex) { 135 } catch (IOException ex) {
134 throw new Error(ex); 136 throw new Error(ex);
@@ -136,22 +138,37 @@ public class MenuBar extends JMenuBar {
136 } 138 }
137 }); 139 });
138 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); 140 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
139 this.saveMappingsOldMenu = item; 141 this.saveMappingEnigmaDirectoryMenu = item;
140 } 142 }
143 menu.add(saveMenu);
141 { 144 {
142 JMenuItem item = new JMenuItem("Save Mappings as SRG"); 145 JMenuItem item = new JMenuItem("JSON (directory)");
143 menu.add(item); 146 saveMenu.add(item);
144 item.addActionListener(event -> { 147 item.addActionListener(event -> {
145 if (this.gui.mappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) { 148 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
146 try { 149 try {
147 this.gui.getController().saveSRGMappings(this.gui.mappingsFileChooser.getSelectedFile()); 150 this.gui.getController().saveJsonMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
151 this.saveMappingsMenu.setEnabled(true);
152 } catch (IOException ex) {
153 throw new Error(ex);
154 }
155 }
156 });
157 this.saveMappingsJsonMenu = item;
158 }
159 {
160 JMenuItem item = new JMenuItem("SRG");
161 saveMenu.add(item);
162 item.addActionListener(event -> {
163 if (this.gui.jsonMappingsFileChooser.showSaveDialog(this.gui.getFrame()) == JFileChooser.APPROVE_OPTION) {
164 try {
165 this.gui.getController().saveSRGMappings(this.gui.jsonMappingsFileChooser.getSelectedFile());
148 this.saveMappingsMenu.setEnabled(true); 166 this.saveMappingsMenu.setEnabled(true);
149 } catch (IOException ex) { 167 } catch (IOException ex) {
150 throw new Error(ex); 168 throw new Error(ex);
151 } 169 }
152 } 170 }
153 }); 171 });
154 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK));
155 this.saveMappingsSrgMenu = item; 172 this.saveMappingsSrgMenu = item;
156 } 173 }
157 { 174 {
diff --git a/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserAny.java b/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserAny.java
new file mode 100644
index 0000000..2339334
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/gui/filechooser/FileChooserAny.java
@@ -0,0 +1,11 @@
1package cuchaz.enigma.gui.filechooser;
2
3import javax.swing.*;
4
5public class FileChooserAny extends JFileChooser
6{
7 public FileChooserAny() {
8 this.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
9 this.setAcceptAllFileFilterUsed(false);
10 }
11} \ No newline at end of file