diff options
| author | 2023-10-09 14:22:40 +0200 | |
|---|---|---|
| committer | 2023-10-09 14:22:40 +0200 | |
| commit | 75c6da42ca360084b57f7a384cd4a7bf93bdea0a (patch) | |
| tree | 801954ee9c7cd12f244d14aabad81d0f4920d9cc /enigma-swing/src/main/java | |
| parent | Use `VisitableMappingTree` where possible (diff) | |
| download | enigma-fork-75c6da42ca360084b57f7a384cd4a7bf93bdea0a.tar.gz enigma-fork-75c6da42ca360084b57f7a384cd4a7bf93bdea0a.tar.xz enigma-fork-75c6da42ca360084b57f7a384cd4a7bf93bdea0a.zip | |
Use System Property for Mapping-IO
Diffstat (limited to 'enigma-swing/src/main/java')
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | 48 | ||||
| -rw-r--r-- | enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | 42 |
2 files changed, 22 insertions, 68 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java index 2c15305..88dc070 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -29,11 +29,6 @@ import javax.swing.JOptionPane; | |||
| 29 | import javax.swing.SwingUtilities; | 29 | import javax.swing.SwingUtilities; |
| 30 | 30 | ||
| 31 | import com.google.common.collect.Lists; | 31 | import com.google.common.collect.Lists; |
| 32 | import net.fabricmc.mappingio.MappingReader; | ||
| 33 | import net.fabricmc.mappingio.MappingWriter; | ||
| 34 | import net.fabricmc.mappingio.tree.MemoryMappingTree; | ||
| 35 | import net.fabricmc.mappingio.tree.VisitOrder; | ||
| 36 | import net.fabricmc.mappingio.tree.VisitableMappingTree; | ||
| 37 | 32 | ||
| 38 | import cuchaz.enigma.Enigma; | 33 | import cuchaz.enigma.Enigma; |
| 39 | import cuchaz.enigma.EnigmaProfile; | 34 | import cuchaz.enigma.EnigmaProfile; |
| @@ -82,7 +77,6 @@ import cuchaz.enigma.translation.mapping.EntryUtil; | |||
| 82 | import cuchaz.enigma.translation.mapping.MappingDelta; | 77 | import cuchaz.enigma.translation.mapping.MappingDelta; |
| 83 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; | 78 | import cuchaz.enigma.translation.mapping.ResolutionStrategy; |
| 84 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 79 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 85 | import cuchaz.enigma.translation.mapping.serde.MappingIoConverter; | ||
| 86 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; | 80 | import cuchaz.enigma.translation.mapping.serde.MappingParseException; |
| 87 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; | 81 | import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 88 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 82 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| @@ -105,7 +99,6 @@ public class GuiController implements ClientPacketHandler { | |||
| 105 | 99 | ||
| 106 | private Path loadedMappingPath; | 100 | private Path loadedMappingPath; |
| 107 | private MappingFormat loadedMappingFormat; | 101 | private MappingFormat loadedMappingFormat; |
| 108 | public boolean useMappingIo = true; | ||
| 109 | 102 | ||
| 110 | private ClassHandleProvider chp; | 103 | private ClassHandleProvider chp; |
| 111 | 104 | ||
| @@ -146,6 +139,11 @@ public class GuiController implements ClientPacketHandler { | |||
| 146 | this.gui.onCloseJar(); | 139 | this.gui.onCloseJar(); |
| 147 | } | 140 | } |
| 148 | 141 | ||
| 142 | public CompletableFuture<Void> openMappings(MappingFormat format, Path path, boolean useMappingIo) { | ||
| 143 | System.getProperties().setProperty("enigma.use_mappingio", useMappingIo ? "true" : "false"); | ||
| 144 | return openMappings(format, path); | ||
| 145 | } | ||
| 146 | |||
| 149 | public CompletableFuture<Void> openMappings(MappingFormat format, Path path) { | 147 | public CompletableFuture<Void> openMappings(MappingFormat format, Path path) { |
| 150 | if (project == null) { | 148 | if (project == null) { |
| 151 | return CompletableFuture.completedFuture(null); | 149 | return CompletableFuture.completedFuture(null); |
| @@ -156,26 +154,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 156 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { | 154 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { |
| 157 | try { | 155 | try { |
| 158 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | 156 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); |
| 159 | EntryTree<EntryMapping> mappings; | 157 | project.setMappings(format.read(path, progress, saveParameters)); |
| 160 | |||
| 161 | if (useMappingIo) { | ||
| 162 | String loadingMessage; | ||
| 163 | |||
| 164 | if (format.getMappingIoCounterpart().hasSingleFile()) { | ||
| 165 | loadingMessage = I18n.translate("progress.mappings.loading_file"); | ||
| 166 | } else { | ||
| 167 | loadingMessage = I18n.translate("progress.mappings.loading_directory"); | ||
| 168 | } | ||
| 169 | |||
| 170 | progress.init(1, loadingMessage); | ||
| 171 | VisitableMappingTree mappingTree = new MemoryMappingTree(); | ||
| 172 | MappingReader.read(path, format.getMappingIoCounterpart(), mappingTree); | ||
| 173 | mappings = MappingIoConverter.fromMappingIo(mappingTree, progress); | ||
| 174 | } else { | ||
| 175 | mappings = format.read(path, progress, saveParameters); | ||
| 176 | } | ||
| 177 | |||
| 178 | project.setMappings(mappings); | ||
| 179 | 158 | ||
| 180 | loadedMappingFormat = format; | 159 | loadedMappingFormat = format; |
| 181 | loadedMappingPath = path; | 160 | loadedMappingPath = path; |
| @@ -203,6 +182,11 @@ public class GuiController implements ClientPacketHandler { | |||
| 203 | return saveMappings(path, loadedMappingFormat); | 182 | return saveMappings(path, loadedMappingFormat); |
| 204 | } | 183 | } |
| 205 | 184 | ||
| 185 | public CompletableFuture<Void> saveMappings(Path path, MappingFormat format, boolean useMappingIo) { | ||
| 186 | System.getProperties().setProperty("enigma.use_mappingio", useMappingIo ? "true" : "false"); | ||
| 187 | return saveMappings(path, format); | ||
| 188 | } | ||
| 189 | |||
| 206 | /** | 190 | /** |
| 207 | * Saves the mappings, with a dialog popping up, showing the progress. | 191 | * Saves the mappings, with a dialog popping up, showing the progress. |
| 208 | * | 192 | * |
| @@ -229,15 +213,7 @@ public class GuiController implements ClientPacketHandler { | |||
| 229 | loadedMappingFormat = format; | 213 | loadedMappingFormat = format; |
| 230 | loadedMappingPath = path; | 214 | loadedMappingPath = path; |
| 231 | 215 | ||
| 232 | if (useMappingIo) { | 216 | if (saveAll) { |
| 233 | VisitableMappingTree mappingTree = MappingIoConverter.toMappingIo(mapper.getObfToDeobf(), progress); | ||
| 234 | |||
| 235 | progress.init(1, I18n.translate("progress.mappings.writing")); | ||
| 236 | MappingWriter writer = MappingWriter.create(path, format.getMappingIoCounterpart()); | ||
| 237 | mappingTree.accept(writer, VisitOrder.createByName()); | ||
| 238 | writer.close(); | ||
| 239 | progress.step(1, I18n.translate("progress.done")); | ||
| 240 | } else if (saveAll) { | ||
| 241 | format.write(mapper.getObfToDeobf(), path, progress, saveParameters); | 217 | format.write(mapper.getObfToDeobf(), path, progress, saveParameters); |
| 242 | } else { | 218 | } else { |
| 243 | format.write(mapper.getObfToDeobf(), delta, path, progress, saveParameters); | 219 | format.write(mapper.getObfToDeobf(), delta, path, progress, saveParameters); |
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java index 59362e5..30e3586 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/elements/MenuBar.java | |||
| @@ -7,7 +7,6 @@ import java.io.IOException; | |||
| 7 | import java.nio.file.Files; | 7 | import java.nio.file.Files; |
| 8 | import java.nio.file.Path; | 8 | import java.nio.file.Path; |
| 9 | import java.util.Arrays; | 9 | import java.util.Arrays; |
| 10 | import java.util.List; | ||
| 11 | import java.util.Locale; | 10 | import java.util.Locale; |
| 12 | import java.util.Map; | 11 | import java.util.Map; |
| 13 | import java.util.stream.Collectors; | 12 | import java.util.stream.Collectors; |
| @@ -404,22 +403,11 @@ public class MenuBar { | |||
| 404 | } | 403 | } |
| 405 | 404 | ||
| 406 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { | 405 | private static void prepareOpenMappingsMenu(JMenu openMappingsMenu, Gui gui) { |
| 407 | List<MappingFormat> readableMappingIoFormats = Arrays.asList( | ||
| 408 | MappingFormat.ENIGMA_DIRECTORY, | ||
| 409 | MappingFormat.ENIGMA_FILE, | ||
| 410 | MappingFormat.TINY_FILE, | ||
| 411 | MappingFormat.TINY_V2, | ||
| 412 | MappingFormat.SRG_FILE, | ||
| 413 | MappingFormat.TSRG_FILE, | ||
| 414 | MappingFormat.TSRG_2_FILE, | ||
| 415 | MappingFormat.PROGUARD); | ||
| 416 | |||
| 417 | // Mapping-IO readers | 406 | // Mapping-IO readers |
| 418 | for (MappingFormat format : readableMappingIoFormats) { | 407 | MappingFormat.getReadableFormats().stream() |
| 419 | addOpenMappingsMenuEntry(I18n.translate(format.getMappingIoCounterpart().name), | 408 | .filter(format -> format.getMappingIoCounterpart() != null) |
| 420 | format, true, openMappingsMenu, gui); | 409 | .forEach(format -> addOpenMappingsMenuEntry(I18n.translate(format.getMappingIoCounterpart().name), |
| 421 | } | 410 | format, true, openMappingsMenu, gui)); |
| 422 | |||
| 423 | openMappingsMenu.addSeparator(); | 411 | openMappingsMenu.addSeparator(); |
| 424 | 412 | ||
| 425 | // Enigma's own readers | 413 | // Enigma's own readers |
| @@ -438,8 +426,7 @@ public class MenuBar { | |||
| 438 | 426 | ||
| 439 | if (gui.enigmaMappingsFileChooser.showOpenDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 427 | if (gui.enigmaMappingsFileChooser.showOpenDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 440 | File selectedFile = gui.enigmaMappingsFileChooser.getSelectedFile(); | 428 | File selectedFile = gui.enigmaMappingsFileChooser.getSelectedFile(); |
| 441 | gui.getController().useMappingIo = mappingIo; | 429 | gui.getController().openMappings(format, selectedFile.toPath(), mappingIo); |
| 442 | gui.getController().openMappings(format, selectedFile.toPath()); | ||
| 443 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | 430 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); |
| 444 | } | 431 | } |
| 445 | }); | 432 | }); |
| @@ -447,19 +434,11 @@ public class MenuBar { | |||
| 447 | } | 434 | } |
| 448 | 435 | ||
| 449 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { | 436 | private static void prepareSaveMappingsAsMenu(JMenu saveMappingsAsMenu, JMenuItem saveMappingsItem, Gui gui) { |
| 450 | List<MappingFormat> writableMappingIoFormats = Arrays.asList( | ||
| 451 | MappingFormat.ENIGMA_DIRECTORY, | ||
| 452 | MappingFormat.ENIGMA_FILE, | ||
| 453 | MappingFormat.TINY_FILE, | ||
| 454 | MappingFormat.TINY_V2, | ||
| 455 | MappingFormat.PROGUARD); | ||
| 456 | |||
| 457 | // Mapping-IO writers | 437 | // Mapping-IO writers |
| 458 | for (MappingFormat format : writableMappingIoFormats) { | 438 | MappingFormat.getWritableFormats().stream() |
| 459 | addSaveMappingsAsMenuEntry(format.getMappingIoCounterpart().name, | 439 | .filter(format -> format.hasMappingIoWriter()) |
| 460 | format, true, saveMappingsAsMenu, saveMappingsItem, gui); | 440 | .forEach(format -> addSaveMappingsAsMenuEntry(format.getMappingIoCounterpart().name, |
| 461 | } | 441 | format, true, saveMappingsAsMenu, saveMappingsItem, gui)); |
| 462 | |||
| 463 | saveMappingsAsMenu.addSeparator(); | 442 | saveMappingsAsMenu.addSeparator(); |
| 464 | 443 | ||
| 465 | // Enigma's own writers | 444 | // Enigma's own writers |
| @@ -480,8 +459,7 @@ public class MenuBar { | |||
| 480 | } | 459 | } |
| 481 | 460 | ||
| 482 | if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { | 461 | if (gui.enigmaMappingsFileChooser.showSaveDialog(gui.getFrame()) == JFileChooser.APPROVE_OPTION) { |
| 483 | gui.getController().useMappingIo = mappingIo; | 462 | gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format, mappingIo); |
| 484 | gui.getController().saveMappings(gui.enigmaMappingsFileChooser.getSelectedFile().toPath(), format); | ||
| 485 | saveMappingsItem.setEnabled(true); | 463 | saveMappingsItem.setEnabled(true); |
| 486 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); | 464 | UiConfig.setLastSelectedDir(gui.enigmaMappingsFileChooser.getCurrentDirectory().toString()); |
| 487 | } | 465 | } |