diff options
| author | 2025-08-20 20:13:18 +0300 | |
|---|---|---|
| committer | 2025-08-20 18:13:18 +0100 | |
| commit | b0c154881683d6d5cb25569db32037c35498facb (patch) | |
| tree | 8d2d08c9ea90bc9910c1e4c98d715a9ee294ba65 /enigma-swing | |
| parent | Optimize JAR indexing (#552) (diff) | |
| download | enigma-b0c154881683d6d5cb25569db32037c35498facb.tar.gz enigma-b0c154881683d6d5cb25569db32037c35498facb.tar.xz enigma-b0c154881683d6d5cb25569db32037c35498facb.zip | |
Support multiple input jars (#553)
* Support multiple input jars
This is needed for FabricMC/fabric-loom#1354.
* Remove unnecessary null check in GuiController.reloadAll
* Remove outdated TODO
Diffstat (limited to 'enigma-swing')
4 files changed, 26 insertions, 18 deletions
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java index 05146d4a..21120b8a 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Gui.java | |||
| @@ -147,6 +147,7 @@ public class Gui { | |||
| 147 | 147 | ||
| 148 | private void setupUi() { | 148 | private void setupUi() { |
| 149 | this.jarFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); | 149 | this.jarFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); |
| 150 | this.jarFileChooser.setMultiSelectionEnabled(true); | ||
| 150 | 151 | ||
| 151 | this.exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); | 152 | this.exportSourceFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); |
| 152 | this.exportSourceFileChooser.setAcceptAllFileFilterUsed(false); | 153 | this.exportSourceFileChooser.setAcceptAllFileFilterUsed(false); |
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 ad10abfc..ece11b00 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -23,6 +23,7 @@ import java.util.Objects; | |||
| 23 | import java.util.Set; | 23 | import java.util.Set; |
| 24 | import java.util.concurrent.CompletableFuture; | 24 | import java.util.concurrent.CompletableFuture; |
| 25 | import java.util.concurrent.ExecutionException; | 25 | import java.util.concurrent.ExecutionException; |
| 26 | import java.util.stream.Collectors; | ||
| 26 | import java.util.stream.Stream; | 27 | import java.util.stream.Stream; |
| 27 | 28 | ||
| 28 | import javax.swing.JOptionPane; | 29 | import javax.swing.JOptionPane; |
| @@ -119,20 +120,27 @@ public class GuiController implements ClientPacketHandler { | |||
| 119 | return project != null && project.getMapper().isDirty(); | 120 | return project != null && project.getMapper().isDirty(); |
| 120 | } | 121 | } |
| 121 | 122 | ||
| 122 | public CompletableFuture<Void> openJar(final Path jarPath) { | 123 | public CompletableFuture<Void> openJar(final List<Path> jarPaths) { |
| 123 | this.gui.onStartOpenJar(); | 124 | this.gui.onStartOpenJar(); |
| 124 | 125 | ||
| 125 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { | 126 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { |
| 126 | project = enigma.openJar(jarPath, new ClasspathClassProvider(), progress); | 127 | project = enigma.openJars(jarPaths, new ClasspathClassProvider(), progress); |
| 127 | indexTreeBuilder = new IndexTreeBuilder(project.getJarIndex()); | 128 | indexTreeBuilder = new IndexTreeBuilder(project.getJarIndex()); |
| 128 | chp = new ClassHandleProvider(project, UiConfig.getDecompiler().service); | 129 | chp = new ClassHandleProvider(project, UiConfig.getDecompiler().service); |
| 129 | SwingUtilities.invokeLater(() -> { | 130 | SwingUtilities.invokeLater(() -> { |
| 130 | gui.onFinishOpenJar(jarPath.getFileName().toString()); | 131 | gui.onFinishOpenJar(getFileNames(jarPaths)); |
| 131 | refreshClasses(); | 132 | refreshClasses(); |
| 132 | }); | 133 | }); |
| 133 | }); | 134 | }); |
| 134 | } | 135 | } |
| 135 | 136 | ||
| 137 | private static String getFileNames(List<Path> jarPaths) { | ||
| 138 | return jarPaths.stream() | ||
| 139 | .map(Path::getFileName) | ||
| 140 | .map(Object::toString) | ||
| 141 | .collect(Collectors.joining(", ")); | ||
| 142 | } | ||
| 143 | |||
| 136 | public void closeJar() { | 144 | public void closeJar() { |
| 137 | this.chp.destroy(); | 145 | this.chp.destroy(); |
| 138 | this.chp = null; | 146 | this.chp = null; |
| @@ -241,17 +249,15 @@ public class GuiController implements ClientPacketHandler { | |||
| 241 | } | 249 | } |
| 242 | 250 | ||
| 243 | public void reloadAll() { | 251 | public void reloadAll() { |
| 244 | Path jarPath = this.project.getJarPath(); | 252 | List<Path> jarPaths = this.project.getJarPaths(); |
| 245 | MappingFormat loadedMappingFormat = this.loadedMappingFormat; | 253 | MappingFormat loadedMappingFormat = this.loadedMappingFormat; |
| 246 | Path loadedMappingPath = this.loadedMappingPath; | 254 | Path loadedMappingPath = this.loadedMappingPath; |
| 247 | 255 | ||
| 248 | if (jarPath != null) { | 256 | this.closeJar(); |
| 249 | this.closeJar(); | 257 | CompletableFuture<Void> f = this.openJar(jarPaths); |
| 250 | CompletableFuture<Void> f = this.openJar(jarPath); | ||
| 251 | 258 | ||
| 252 | if (loadedMappingFormat != null && loadedMappingPath != null) { | 259 | if (loadedMappingFormat != null && loadedMappingPath != null) { |
| 253 | f.whenComplete((v, t) -> this.openMappings(loadedMappingFormat, loadedMappingPath)); | 260 | f.whenComplete((v, t) -> this.openMappings(loadedMappingFormat, loadedMappingPath)); |
| 254 | } | ||
| 255 | } | 261 | } |
| 256 | } | 262 | } |
| 257 | 263 | ||
diff --git a/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java b/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java index 213a5fea..43b16cd9 100644 --- a/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java +++ b/enigma-swing/src/main/java/cuchaz/enigma/gui/Main.java | |||
| @@ -38,7 +38,7 @@ public class Main { | |||
| 38 | public static void main(String[] args) throws IOException { | 38 | public static void main(String[] args) throws IOException { |
| 39 | OptionParser parser = new OptionParser(); | 39 | OptionParser parser = new OptionParser(); |
| 40 | 40 | ||
| 41 | OptionSpec<Path> jar = parser.accepts("jar", "Jar file to open at startup").withRequiredArg().withValuesConvertedBy(PathConverter.INSTANCE); | 41 | OptionSpec<Path> jar = parser.accepts("jar", "Jar file to open at startup; if there are multiple jars, the order must be the same between all collab session members").withRequiredArg().withValuesConvertedBy(PathConverter.INSTANCE); |
| 42 | 42 | ||
| 43 | OptionSpec<Path> mappings = parser.accepts("mappings", "Mappings file to open at startup").withRequiredArg().withValuesConvertedBy(PathConverter.INSTANCE); | 43 | OptionSpec<Path> mappings = parser.accepts("mappings", "Mappings file to open at startup").withRequiredArg().withValuesConvertedBy(PathConverter.INSTANCE); |
| 44 | 44 | ||
| @@ -137,8 +137,8 @@ public class Main { | |||
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | if (options.has(jar)) { | 139 | if (options.has(jar)) { |
| 140 | Path jarPath = options.valueOf(jar); | 140 | List<Path> jarPaths = options.valuesOf(jar); |
| 141 | controller.openJar(jarPath).whenComplete((v, t) -> { | 141 | controller.openJar(jarPaths).whenComplete((v, t) -> { |
| 142 | if (options.has(mappings)) { | 142 | if (options.has(mappings)) { |
| 143 | Path mappingsPath = options.valueOf(mappings); | 143 | Path mappingsPath = options.valueOf(mappings); |
| 144 | 144 | ||
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 d7054f78..78050bb3 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,6 +7,7 @@ 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; | ||
| 10 | import java.util.Locale; | 11 | import java.util.Locale; |
| 11 | import java.util.Map; | 12 | import java.util.Map; |
| 12 | import java.util.stream.Collectors; | 13 | import java.util.stream.Collectors; |
| @@ -235,15 +236,15 @@ public class MenuBar { | |||
| 235 | return; | 236 | return; |
| 236 | } | 237 | } |
| 237 | 238 | ||
| 238 | File file = d.getSelectedFile(); | 239 | File[] files = d.getSelectedFiles(); |
| 239 | 240 | ||
| 240 | // checks if the file name is not empty | 241 | // checks if the file name is not empty |
| 241 | if (file != null) { | 242 | if (files.length >= 1) { |
| 242 | Path path = file.toPath(); | 243 | List<Path> paths = Arrays.stream(files).map(File::toPath).toList(); |
| 243 | 244 | ||
| 244 | // checks if the file name corresponds to an existing file | 245 | // checks if the file name corresponds to an existing file |
| 245 | if (Files.exists(path)) { | 246 | if (paths.stream().allMatch(Files::exists)) { |
| 246 | this.gui.getController().openJar(path); | 247 | this.gui.getController().openJar(paths); |
| 247 | } | 248 | } |
| 248 | 249 | ||
| 249 | UiConfig.setLastSelectedDir(d.getCurrentDirectory().getAbsolutePath()); | 250 | UiConfig.setLastSelectedDir(d.getCurrentDirectory().getAbsolutePath()); |