diff options
Diffstat (limited to 'src/main')
18 files changed, 119 insertions, 44 deletions
diff --git a/src/main/java/cuchaz/enigma/EnigmaProfile.java b/src/main/java/cuchaz/enigma/EnigmaProfile.java index feb5fdb6..a5904ee1 100644 --- a/src/main/java/cuchaz/enigma/EnigmaProfile.java +++ b/src/main/java/cuchaz/enigma/EnigmaProfile.java | |||
| @@ -4,6 +4,8 @@ import com.google.common.collect.ImmutableMap; | |||
| 4 | import com.google.gson.Gson; | 4 | import com.google.gson.Gson; |
| 5 | import com.google.gson.annotations.SerializedName; | 5 | import com.google.gson.annotations.SerializedName; |
| 6 | import cuchaz.enigma.api.service.EnigmaServiceType; | 6 | import cuchaz.enigma.api.service.EnigmaServiceType; |
| 7 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; | ||
| 8 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 7 | 9 | ||
| 8 | import javax.annotation.Nullable; | 10 | import javax.annotation.Nullable; |
| 9 | import java.io.Reader; | 11 | import java.io.Reader; |
| @@ -18,6 +20,9 @@ public final class EnigmaProfile { | |||
| 18 | @SerializedName("services") | 20 | @SerializedName("services") |
| 19 | private final Map<String, Service> serviceProfiles; | 21 | private final Map<String, Service> serviceProfiles; |
| 20 | 22 | ||
| 23 | @SerializedName("mapping_save_parameters") | ||
| 24 | private final MappingSaveParameters mappingSaveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); | ||
| 25 | |||
| 21 | private EnigmaProfile(Map<String, Service> serviceProfiles) { | 26 | private EnigmaProfile(Map<String, Service> serviceProfiles) { |
| 22 | this.serviceProfiles = serviceProfiles; | 27 | this.serviceProfiles = serviceProfiles; |
| 23 | } | 28 | } |
| @@ -31,6 +36,10 @@ public final class EnigmaProfile { | |||
| 31 | return serviceProfiles.get(serviceType.key); | 36 | return serviceProfiles.get(serviceType.key); |
| 32 | } | 37 | } |
| 33 | 38 | ||
| 39 | public MappingSaveParameters getMappingSaveParameters() { | ||
| 40 | return mappingSaveParameters; | ||
| 41 | } | ||
| 42 | |||
| 34 | public static class Service { | 43 | public static class Service { |
| 35 | private final String id; | 44 | private final String id; |
| 36 | private final Map<String, String> args; | 45 | private final Map<String, String> args; |
diff --git a/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java b/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java index 08e73e6a..9d238e3a 100644 --- a/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java +++ b/src/main/java/cuchaz/enigma/command/CheckMappingsCommand.java | |||
| @@ -5,6 +5,7 @@ import cuchaz.enigma.EnigmaProject; | |||
| 5 | import cuchaz.enigma.ProgressListener; | 5 | import cuchaz.enigma.ProgressListener; |
| 6 | import cuchaz.enigma.analysis.index.JarIndex; | 6 | import cuchaz.enigma.analysis.index.JarIndex; |
| 7 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 8 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 9 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 9 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 10 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 10 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 11 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| @@ -43,7 +44,9 @@ public class CheckMappingsCommand extends Command { | |||
| 43 | System.out.println("Reading mappings..."); | 44 | System.out.println("Reading mappings..."); |
| 44 | 45 | ||
| 45 | MappingFormat format = chooseEnigmaFormat(fileMappings); | 46 | MappingFormat format = chooseEnigmaFormat(fileMappings); |
| 46 | EntryTree<EntryMapping> mappings = format.read(fileMappings, ProgressListener.none()); | 47 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); |
| 48 | |||
| 49 | EntryTree<EntryMapping> mappings = format.read(fileMappings, ProgressListener.none(), saveParameters); | ||
| 47 | project.setMappings(mappings); | 50 | project.setMappings(mappings); |
| 48 | 51 | ||
| 49 | JarIndex idx = project.getJarIndex(); | 52 | JarIndex idx = project.getJarIndex(); |
diff --git a/src/main/java/cuchaz/enigma/command/Command.java b/src/main/java/cuchaz/enigma/command/Command.java index 41d7bfae..d53ed6ef 100644 --- a/src/main/java/cuchaz/enigma/command/Command.java +++ b/src/main/java/cuchaz/enigma/command/Command.java | |||
| @@ -4,6 +4,7 @@ import cuchaz.enigma.Enigma; | |||
| 4 | import cuchaz.enigma.EnigmaProject; | 4 | import cuchaz.enigma.EnigmaProject; |
| 5 | import cuchaz.enigma.ProgressListener; | 5 | import cuchaz.enigma.ProgressListener; |
| 6 | import cuchaz.enigma.translation.mapping.EntryMapping; | 6 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 7 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 7 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | 8 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 9 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 9 | 10 | ||
| @@ -35,7 +36,10 @@ public abstract class Command { | |||
| 35 | 36 | ||
| 36 | if (fileMappings != null) { | 37 | if (fileMappings != null) { |
| 37 | System.out.println("Reading mappings..."); | 38 | System.out.println("Reading mappings..."); |
| 38 | EntryTree<EntryMapping> mappings = chooseEnigmaFormat(fileMappings).read(fileMappings, progress); | 39 | |
| 40 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | ||
| 41 | EntryTree<EntryMapping> mappings = chooseEnigmaFormat(fileMappings).read(fileMappings, progress, saveParameters); | ||
| 42 | |||
| 39 | project.setMappings(mappings); | 43 | project.setMappings(mappings); |
| 40 | } | 44 | } |
| 41 | 45 | ||
diff --git a/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java b/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java index 1f6a0694..f57f1fa6 100644 --- a/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java +++ b/src/main/java/cuchaz/enigma/command/ComposeMappingsCommand.java | |||
| @@ -2,6 +2,8 @@ package cuchaz.enigma.command; | |||
| 2 | 2 | ||
| 3 | import cuchaz.enigma.throwables.MappingParseException; | 3 | import cuchaz.enigma.throwables.MappingParseException; |
| 4 | import cuchaz.enigma.translation.mapping.EntryMapping; | 4 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 5 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; | ||
| 6 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 5 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 6 | import cuchaz.enigma.utils.Utils; | 8 | import cuchaz.enigma.utils.Utils; |
| 7 | 9 | ||
| @@ -26,12 +28,14 @@ public class ComposeMappingsCommand extends Command { | |||
| 26 | 28 | ||
| 27 | @Override | 29 | @Override |
| 28 | public void run(String... args) throws IOException, MappingParseException { | 30 | public void run(String... args) throws IOException, MappingParseException { |
| 29 | EntryTree<EntryMapping> left = MappingCommandsUtil.read(args[0], Paths.get(args[1])); | 31 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 30 | EntryTree<EntryMapping> right = MappingCommandsUtil.read(args[2], Paths.get(args[3])); | 32 | |
| 33 | EntryTree<EntryMapping> left = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); | ||
| 34 | EntryTree<EntryMapping> right = MappingCommandsUtil.read(args[2], Paths.get(args[3]), saveParameters); | ||
| 31 | EntryTree<EntryMapping> result = MappingCommandsUtil.compose(left, right, args[6].equals("left") || args[6].equals("both"), args[6].equals("right") || args[6].equals("both")); | 35 | EntryTree<EntryMapping> result = MappingCommandsUtil.compose(left, right, args[6].equals("left") || args[6].equals("both"), args[6].equals("right") || args[6].equals("both")); |
| 32 | 36 | ||
| 33 | Path output = Paths.get(args[5]); | 37 | Path output = Paths.get(args[5]); |
| 34 | Utils.delete(output); | 38 | Utils.delete(output); |
| 35 | MappingCommandsUtil.write(result, args[4], output); | 39 | MappingCommandsUtil.write(result, args[4], output, saveParameters); |
| 36 | } | 40 | } |
| 37 | } | 41 | } |
diff --git a/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java b/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java index 775bd3ea..689df02d 100644 --- a/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java +++ b/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java | |||
| @@ -2,6 +2,8 @@ package cuchaz.enigma.command; | |||
| 2 | 2 | ||
| 3 | import cuchaz.enigma.throwables.MappingParseException; | 3 | import cuchaz.enigma.throwables.MappingParseException; |
| 4 | import cuchaz.enigma.translation.mapping.EntryMapping; | 4 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 5 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; | ||
| 6 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 5 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 6 | import cuchaz.enigma.utils.Utils; | 8 | import cuchaz.enigma.utils.Utils; |
| 7 | 9 | ||
| @@ -26,10 +28,12 @@ public class ConvertMappingsCommand extends Command { | |||
| 26 | 28 | ||
| 27 | @Override | 29 | @Override |
| 28 | public void run(String... args) throws IOException, MappingParseException { | 30 | public void run(String... args) throws IOException, MappingParseException { |
| 29 | EntryTree<EntryMapping> mappings = MappingCommandsUtil.read(args[0], Paths.get(args[1])); | 31 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 32 | |||
| 33 | EntryTree<EntryMapping> mappings = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); | ||
| 30 | 34 | ||
| 31 | Path output = Paths.get(args[3]); | 35 | Path output = Paths.get(args[3]); |
| 32 | Utils.delete(output); | 36 | Utils.delete(output); |
| 33 | MappingCommandsUtil.write(mappings, args[2], output); | 37 | MappingCommandsUtil.write(mappings, args[2], output, saveParameters); |
| 34 | } | 38 | } |
| 35 | } | 39 | } |
diff --git a/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java b/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java index bfe83081..cd11e2e6 100644 --- a/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java +++ b/src/main/java/cuchaz/enigma/command/InvertMappingsCommand.java | |||
| @@ -2,6 +2,8 @@ package cuchaz.enigma.command; | |||
| 2 | 2 | ||
| 3 | import cuchaz.enigma.throwables.MappingParseException; | 3 | import cuchaz.enigma.throwables.MappingParseException; |
| 4 | import cuchaz.enigma.translation.mapping.EntryMapping; | 4 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 5 | import cuchaz.enigma.translation.mapping.MappingFileNameFormat; | ||
| 6 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 5 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 6 | import cuchaz.enigma.utils.Utils; | 8 | import cuchaz.enigma.utils.Utils; |
| 7 | 9 | ||
| @@ -26,11 +28,13 @@ public class InvertMappingsCommand extends Command { | |||
| 26 | 28 | ||
| 27 | @Override | 29 | @Override |
| 28 | public void run(String... args) throws IOException, MappingParseException { | 30 | public void run(String... args) throws IOException, MappingParseException { |
| 29 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(args[0], Paths.get(args[1])); | 31 | MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); |
| 32 | |||
| 33 | EntryTree<EntryMapping> source = MappingCommandsUtil.read(args[0], Paths.get(args[1]), saveParameters); | ||
| 30 | EntryTree<EntryMapping> result = MappingCommandsUtil.invert(source); | 34 | EntryTree<EntryMapping> result = MappingCommandsUtil.invert(source); |
| 31 | 35 | ||
| 32 | Path output = Paths.get(args[3]); | 36 | Path output = Paths.get(args[3]); |
| 33 | Utils.delete(output); | 37 | Utils.delete(output); |
| 34 | MappingCommandsUtil.write(result, args[2], output); | 38 | MappingCommandsUtil.write(result, args[2], output, saveParameters); |
| 35 | } | 39 | } |
| 36 | } | 40 | } |
diff --git a/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java b/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java index 03d9ab7f..8384e4e7 100644 --- a/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java +++ b/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java | |||
| @@ -5,6 +5,7 @@ import cuchaz.enigma.throwables.MappingParseException; | |||
| 5 | import cuchaz.enigma.translation.MappingTranslator; | 5 | import cuchaz.enigma.translation.MappingTranslator; |
| 6 | import cuchaz.enigma.translation.Translator; | 6 | import cuchaz.enigma.translation.Translator; |
| 7 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 8 | import cuchaz.enigma.translation.mapping.VoidEntryResolver; | 9 | import cuchaz.enigma.translation.mapping.VoidEntryResolver; |
| 9 | import cuchaz.enigma.translation.mapping.serde.*; | 10 | import cuchaz.enigma.translation.mapping.serde.*; |
| 10 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 11 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| @@ -91,13 +92,13 @@ public final class MappingCommandsUtil { | |||
| 91 | return result; | 92 | return result; |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | public static EntryTree<EntryMapping> read(String type, Path path) throws MappingParseException, IOException { | 95 | public static EntryTree<EntryMapping> read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { |
| 95 | if (type.equals("enigma")) { | 96 | if (type.equals("enigma")) { |
| 96 | return EnigmaMappingsReader.DIRECTORY.read(path, ProgressListener.none()); | 97 | return EnigmaMappingsReader.DIRECTORY.read(path, ProgressListener.none(), saveParameters); |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | if (type.equals("tiny")) { | 100 | if (type.equals("tiny")) { |
| 100 | return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none()); | 101 | return TinyMappingsReader.INSTANCE.read(path, ProgressListener.none(), saveParameters); |
| 101 | } | 102 | } |
| 102 | 103 | ||
| 103 | MappingFormat format = null; | 104 | MappingFormat format = null; |
| @@ -106,15 +107,15 @@ public final class MappingCommandsUtil { | |||
| 106 | } catch (IllegalArgumentException ignored) {} | 107 | } catch (IllegalArgumentException ignored) {} |
| 107 | 108 | ||
| 108 | if (format != null) { | 109 | if (format != null) { |
| 109 | return format.getReader().read(path, ProgressListener.none()); | 110 | return format.getReader().read(path, ProgressListener.none(), saveParameters); |
| 110 | } | 111 | } |
| 111 | 112 | ||
| 112 | throw new IllegalArgumentException("no reader for " + type); | 113 | throw new IllegalArgumentException("no reader for " + type); |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path) { | 116 | public static void write(EntryTree<EntryMapping> mappings, String type, Path path, MappingSaveParameters saveParameters) { |
| 116 | if (type.equals("enigma")) { | 117 | if (type.equals("enigma")) { |
| 117 | EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none()); | 118 | EnigmaMappingsWriter.DIRECTORY.write(mappings, path, ProgressListener.none(), saveParameters); |
| 118 | return; | 119 | return; |
| 119 | } | 120 | } |
| 120 | 121 | ||
| @@ -125,7 +126,7 @@ public final class MappingCommandsUtil { | |||
| 125 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); | 126 | throw new IllegalArgumentException("specify column names as 'tiny:from_column:to_column'"); |
| 126 | } | 127 | } |
| 127 | 128 | ||
| 128 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none()); | 129 | new TinyMappingsWriter(split[1], split[2]).write(mappings, path, ProgressListener.none(), saveParameters); |
| 129 | return; | 130 | return; |
| 130 | } | 131 | } |
| 131 | 132 | ||
| @@ -135,7 +136,7 @@ public final class MappingCommandsUtil { | |||
| 135 | } catch (IllegalArgumentException ignored) {} | 136 | } catch (IllegalArgumentException ignored) {} |
| 136 | 137 | ||
| 137 | if (format != null) { | 138 | if (format != null) { |
| 138 | format.getWriter().write(mappings, path, ProgressListener.none()); | 139 | format.getWriter().write(mappings, path, ProgressListener.none(), saveParameters); |
| 139 | return; | 140 | return; |
| 140 | } | 141 | } |
| 141 | 142 | ||
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 092a07ed..89fbd10b 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -109,7 +109,9 @@ public class GuiController { | |||
| 109 | 109 | ||
| 110 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { | 110 | return ProgressDialog.runOffThread(gui.getFrame(), progress -> { |
| 111 | try { | 111 | try { |
| 112 | EntryTree<EntryMapping> mappings = format.read(path, progress); | 112 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); |
| 113 | |||
| 114 | EntryTree<EntryMapping> mappings = format.read(path, progress, saveParameters); | ||
| 113 | project.setMappings(mappings); | 115 | project.setMappings(mappings); |
| 114 | 116 | ||
| 115 | loadedMappingFormat = format; | 117 | loadedMappingFormat = format; |
| @@ -132,6 +134,7 @@ public class GuiController { | |||
| 132 | 134 | ||
| 133 | return ProgressDialog.runOffThread(this.gui.getFrame(), progress -> { | 135 | return ProgressDialog.runOffThread(this.gui.getFrame(), progress -> { |
| 134 | EntryRemapper mapper = project.getMapper(); | 136 | EntryRemapper mapper = project.getMapper(); |
| 137 | MappingSaveParameters saveParameters = enigma.getProfile().getMappingSaveParameters(); | ||
| 135 | 138 | ||
| 136 | MappingDelta<EntryMapping> delta = mapper.takeMappingDelta(); | 139 | MappingDelta<EntryMapping> delta = mapper.takeMappingDelta(); |
| 137 | boolean saveAll = !path.equals(loadedMappingPath); | 140 | boolean saveAll = !path.equals(loadedMappingPath); |
| @@ -140,9 +143,9 @@ public class GuiController { | |||
| 140 | loadedMappingPath = path; | 143 | loadedMappingPath = path; |
| 141 | 144 | ||
| 142 | if (saveAll) { | 145 | if (saveAll) { |
| 143 | format.write(mapper.getObfToDeobf(), path, progress); | 146 | format.write(mapper.getObfToDeobf(), path, progress, saveParameters); |
| 144 | } else { | 147 | } else { |
| 145 | format.write(mapper.getObfToDeobf(), delta, path, progress); | 148 | format.write(mapper.getObfToDeobf(), delta, path, progress, saveParameters); |
| 146 | } | 149 | } |
| 147 | }); | 150 | }); |
| 148 | } | 151 | } |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/MappingFileNameFormat.java b/src/main/java/cuchaz/enigma/translation/mapping/MappingFileNameFormat.java new file mode 100644 index 00000000..e40bfe75 --- /dev/null +++ b/src/main/java/cuchaz/enigma/translation/mapping/MappingFileNameFormat.java | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | package cuchaz.enigma.translation.mapping; | ||
| 2 | |||
| 3 | import com.google.gson.annotations.SerializedName; | ||
| 4 | |||
| 5 | public enum MappingFileNameFormat { | ||
| 6 | @SerializedName("by_obf") | ||
| 7 | BY_OBF, | ||
| 8 | @SerializedName("by_deobf") | ||
| 9 | BY_DEOBF | ||
| 10 | } | ||
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/MappingSaveParameters.java b/src/main/java/cuchaz/enigma/translation/mapping/MappingSaveParameters.java new file mode 100644 index 00000000..07065d6a --- /dev/null +++ b/src/main/java/cuchaz/enigma/translation/mapping/MappingSaveParameters.java | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package cuchaz.enigma.translation.mapping; | ||
| 2 | |||
| 3 | import com.google.gson.annotations.SerializedName; | ||
| 4 | |||
| 5 | public class MappingSaveParameters { | ||
| 6 | @SerializedName("file_name_format") | ||
| 7 | private final MappingFileNameFormat fileNameFormat; | ||
| 8 | |||
| 9 | public MappingSaveParameters(MappingFileNameFormat fileNameFormat) { | ||
| 10 | this.fileNameFormat = fileNameFormat; | ||
| 11 | } | ||
| 12 | |||
| 13 | public MappingFileNameFormat getFileNameFormat() { | ||
| 14 | return fileNameFormat; | ||
| 15 | } | ||
| 16 | } | ||
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java index 3f61325d..bb0f1ee0 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java | |||
| @@ -6,6 +6,7 @@ import cuchaz.enigma.throwables.MappingParseException; | |||
| 6 | import cuchaz.enigma.translation.mapping.AccessModifier; | 6 | import cuchaz.enigma.translation.mapping.AccessModifier; |
| 7 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.MappingPair; | 8 | import cuchaz.enigma.translation.mapping.MappingPair; |
| 9 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 9 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 10 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 10 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; | 11 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; |
| 11 | import cuchaz.enigma.translation.representation.MethodDescriptor; | 12 | import cuchaz.enigma.translation.representation.MethodDescriptor; |
| @@ -25,7 +26,7 @@ import java.util.stream.Collectors; | |||
| 25 | public enum EnigmaMappingsReader implements MappingsReader { | 26 | public enum EnigmaMappingsReader implements MappingsReader { |
| 26 | FILE { | 27 | FILE { |
| 27 | @Override | 28 | @Override |
| 28 | public EntryTree<EntryMapping> read(Path path, ProgressListener progress) throws IOException, MappingParseException { | 29 | public EntryTree<EntryMapping> read(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException { |
| 29 | progress.init(1, "Loading mapping file"); | 30 | progress.init(1, "Loading mapping file"); |
| 30 | 31 | ||
| 31 | EntryTree<EntryMapping> mappings = new HashEntryTree<>(); | 32 | EntryTree<EntryMapping> mappings = new HashEntryTree<>(); |
| @@ -38,7 +39,7 @@ public enum EnigmaMappingsReader implements MappingsReader { | |||
| 38 | }, | 39 | }, |
| 39 | DIRECTORY { | 40 | DIRECTORY { |
| 40 | @Override | 41 | @Override |
| 41 | public EntryTree<EntryMapping> read(Path root, ProgressListener progress) throws IOException, MappingParseException { | 42 | public EntryTree<EntryMapping> read(Path root, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException { |
| 42 | EntryTree<EntryMapping> mappings = new HashEntryTree<>(); | 43 | EntryTree<EntryMapping> mappings = new HashEntryTree<>(); |
| 43 | 44 | ||
| 44 | List<Path> files = Files.walk(root) | 45 | List<Path> files = Files.walk(root) |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java index 7a390934..7199be88 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java | |||
| @@ -31,11 +31,12 @@ import java.util.Collection; | |||
| 31 | import java.util.Objects; | 31 | import java.util.Objects; |
| 32 | import java.util.concurrent.atomic.AtomicInteger; | 32 | import java.util.concurrent.atomic.AtomicInteger; |
| 33 | import java.util.stream.Collectors; | 33 | import java.util.stream.Collectors; |
| 34 | import java.util.stream.Stream; | ||
| 34 | 35 | ||
| 35 | public enum EnigmaMappingsWriter implements MappingsWriter { | 36 | public enum EnigmaMappingsWriter implements MappingsWriter { |
| 36 | FILE { | 37 | FILE { |
| 37 | @Override | 38 | @Override |
| 38 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress) { | 39 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters saveParameters) { |
| 39 | Collection<ClassEntry> classes = mappings.getRootNodes() | 40 | Collection<ClassEntry> classes = mappings.getRootNodes() |
| 40 | .filter(entry -> entry instanceof ClassEntry) | 41 | .filter(entry -> entry instanceof ClassEntry) |
| 41 | .map(entry -> (ClassEntry) entry) | 42 | .map(entry -> (ClassEntry) entry) |
| @@ -56,13 +57,13 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 56 | }, | 57 | }, |
| 57 | DIRECTORY { | 58 | DIRECTORY { |
| 58 | @Override | 59 | @Override |
| 59 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress) { | 60 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters saveParameters) { |
| 60 | Collection<ClassEntry> changedClasses = delta.getChangedRoots() | 61 | Collection<ClassEntry> changedClasses = delta.getChangedRoots() |
| 61 | .filter(entry -> entry instanceof ClassEntry) | 62 | .filter(entry -> entry instanceof ClassEntry) |
| 62 | .map(entry -> (ClassEntry) entry) | 63 | .map(entry -> (ClassEntry) entry) |
| 63 | .collect(Collectors.toList()); | 64 | .collect(Collectors.toList()); |
| 64 | 65 | ||
| 65 | applyDeletions(path, changedClasses, mappings, delta.getBaseMappings()); | 66 | applyDeletions(path, changedClasses, mappings, delta.getBaseMappings(), saveParameters.getFileNameFormat()); |
| 66 | 67 | ||
| 67 | progress.init(changedClasses.size(), "Writing classes"); | 68 | progress.init(changedClasses.size(), "Writing classes"); |
| 68 | 69 | ||
| @@ -73,7 +74,12 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 73 | progress.step(steps.getAndIncrement(), classEntry.getFullName()); | 74 | progress.step(steps.getAndIncrement(), classEntry.getFullName()); |
| 74 | 75 | ||
| 75 | try { | 76 | try { |
| 76 | Path classPath = resolve(path, translator.translate(classEntry)); | 77 | ClassEntry fileEntry = classEntry; |
| 78 | if (saveParameters.getFileNameFormat() == MappingFileNameFormat.BY_DEOBF) { | ||
| 79 | fileEntry = translator.translate(fileEntry); | ||
| 80 | } | ||
| 81 | |||
| 82 | Path classPath = resolve(path, fileEntry); | ||
| 77 | Files.createDirectories(classPath.getParent()); | 83 | Files.createDirectories(classPath.getParent()); |
| 78 | Files.deleteIfExists(classPath); | 84 | Files.deleteIfExists(classPath); |
| 79 | 85 | ||
| @@ -87,13 +93,17 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 87 | }); | 93 | }); |
| 88 | } | 94 | } |
| 89 | 95 | ||
| 90 | private void applyDeletions(Path root, Collection<ClassEntry> changedClasses, EntryTree<EntryMapping> mappings, EntryTree<EntryMapping> oldMappings) { | 96 | private void applyDeletions(Path root, Collection<ClassEntry> changedClasses, EntryTree<EntryMapping> mappings, EntryTree<EntryMapping> oldMappings, MappingFileNameFormat fileNameFormat) { |
| 91 | Translator oldMappingTranslator = new MappingTranslator(oldMappings, VoidEntryResolver.INSTANCE); | 97 | Translator oldMappingTranslator = new MappingTranslator(oldMappings, VoidEntryResolver.INSTANCE); |
| 92 | 98 | ||
| 93 | Collection<ClassEntry> deletedClasses = changedClasses.stream() | 99 | Stream<ClassEntry> deletedClassStream = changedClasses.stream() |
| 94 | .filter(e -> !Objects.equals(oldMappings.get(e), mappings.get(e))) | 100 | .filter(e -> !Objects.equals(oldMappings.get(e), mappings.get(e))); |
| 95 | .map(oldMappingTranslator::translate) | 101 | |
| 96 | .collect(Collectors.toList()); | 102 | if (fileNameFormat == MappingFileNameFormat.BY_DEOBF) { |
| 103 | deletedClassStream = deletedClassStream.map(oldMappingTranslator::translate); | ||
| 104 | } | ||
| 105 | |||
| 106 | Collection<ClassEntry> deletedClasses = deletedClassStream.collect(Collectors.toList()); | ||
| 97 | 107 | ||
| 98 | for (ClassEntry classEntry : deletedClasses) { | 108 | for (ClassEntry classEntry : deletedClasses) { |
| 99 | try { | 109 | try { |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java index 25283523..4799589e 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | |||
| @@ -4,6 +4,7 @@ import cuchaz.enigma.ProgressListener; | |||
| 4 | import cuchaz.enigma.throwables.MappingParseException; | 4 | import cuchaz.enigma.throwables.MappingParseException; |
| 5 | import cuchaz.enigma.translation.mapping.EntryMapping; | 5 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 6 | import cuchaz.enigma.translation.mapping.MappingDelta; | 6 | import cuchaz.enigma.translation.mapping.MappingDelta; |
| 7 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 8 | 9 | ||
| 9 | import javax.annotation.Nullable; | 10 | import javax.annotation.Nullable; |
| @@ -24,22 +25,22 @@ public enum MappingFormat { | |||
| 24 | this.reader = reader; | 25 | this.reader = reader; |
| 25 | } | 26 | } |
| 26 | 27 | ||
| 27 | public void write(EntryTree<EntryMapping> mappings, Path path, ProgressListener progressListener) { | 28 | public void write(EntryTree<EntryMapping> mappings, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { |
| 28 | write(mappings, MappingDelta.added(mappings), path, progressListener); | 29 | write(mappings, MappingDelta.added(mappings), path, progressListener, saveParameters); |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 31 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progressListener) { | 32 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) { |
| 32 | if (writer == null) { | 33 | if (writer == null) { |
| 33 | throw new IllegalStateException(name() + " does not support writing"); | 34 | throw new IllegalStateException(name() + " does not support writing"); |
| 34 | } | 35 | } |
| 35 | writer.write(mappings, delta, path, progressListener); | 36 | writer.write(mappings, delta, path, progressListener, saveParameters); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener) throws IOException, MappingParseException { | 39 | public EntryTree<EntryMapping> read(Path path, ProgressListener progressListener, MappingSaveParameters saveParameters) throws IOException, MappingParseException { |
| 39 | if (reader == null) { | 40 | if (reader == null) { |
| 40 | throw new IllegalStateException(name() + " does not support reading"); | 41 | throw new IllegalStateException(name() + " does not support reading"); |
| 41 | } | 42 | } |
| 42 | return reader.read(path, progressListener); | 43 | return reader.read(path, progressListener, saveParameters); |
| 43 | } | 44 | } |
| 44 | 45 | ||
| 45 | @Nullable | 46 | @Nullable |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsReader.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsReader.java index af0933f6..4c60787d 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsReader.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsReader.java | |||
| @@ -3,11 +3,12 @@ package cuchaz.enigma.translation.mapping.serde; | |||
| 3 | import cuchaz.enigma.ProgressListener; | 3 | import cuchaz.enigma.ProgressListener; |
| 4 | import cuchaz.enigma.throwables.MappingParseException; | 4 | import cuchaz.enigma.throwables.MappingParseException; |
| 5 | import cuchaz.enigma.translation.mapping.EntryMapping; | 5 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 6 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 6 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 7 | 8 | ||
| 8 | import java.io.IOException; | 9 | import java.io.IOException; |
| 9 | import java.nio.file.Path; | 10 | import java.nio.file.Path; |
| 10 | 11 | ||
| 11 | public interface MappingsReader { | 12 | public interface MappingsReader { |
| 12 | EntryTree<EntryMapping> read(Path path, ProgressListener progress) throws MappingParseException, IOException; | 13 | EntryTree<EntryMapping> read(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws MappingParseException, IOException; |
| 13 | } | 14 | } |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsWriter.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsWriter.java index 77f6ee03..88159867 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsWriter.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingsWriter.java | |||
| @@ -3,14 +3,15 @@ package cuchaz.enigma.translation.mapping.serde; | |||
| 3 | import cuchaz.enigma.ProgressListener; | 3 | import cuchaz.enigma.ProgressListener; |
| 4 | import cuchaz.enigma.translation.mapping.EntryMapping; | 4 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 5 | import cuchaz.enigma.translation.mapping.MappingDelta; | 5 | import cuchaz.enigma.translation.mapping.MappingDelta; |
| 6 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 6 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 7 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 7 | 8 | ||
| 8 | import java.nio.file.Path; | 9 | import java.nio.file.Path; |
| 9 | 10 | ||
| 10 | public interface MappingsWriter { | 11 | public interface MappingsWriter { |
| 11 | void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress); | 12 | void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters saveParameters); |
| 12 | 13 | ||
| 13 | default void write(EntryTree<EntryMapping> mappings, Path path, ProgressListener progress) { | 14 | default void write(EntryTree<EntryMapping> mappings, Path path, ProgressListener progress, MappingSaveParameters saveParameters) { |
| 14 | write(mappings, MappingDelta.added(mappings), path, progress); | 15 | write(mappings, MappingDelta.added(mappings), path, progress, saveParameters); |
| 15 | } | 16 | } |
| 16 | } | 17 | } |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/SrgMappingsWriter.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/SrgMappingsWriter.java index 40be136a..1270d515 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/SrgMappingsWriter.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/SrgMappingsWriter.java | |||
| @@ -6,6 +6,7 @@ import cuchaz.enigma.translation.MappingTranslator; | |||
| 6 | import cuchaz.enigma.translation.Translator; | 6 | import cuchaz.enigma.translation.Translator; |
| 7 | import cuchaz.enigma.translation.mapping.EntryMapping; | 7 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 8 | import cuchaz.enigma.translation.mapping.MappingDelta; | 8 | import cuchaz.enigma.translation.mapping.MappingDelta; |
| 9 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 9 | import cuchaz.enigma.translation.mapping.VoidEntryResolver; | 10 | import cuchaz.enigma.translation.mapping.VoidEntryResolver; |
| 10 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 11 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 11 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; | 12 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; |
| @@ -29,7 +30,7 @@ public enum SrgMappingsWriter implements MappingsWriter { | |||
| 29 | INSTANCE; | 30 | INSTANCE; |
| 30 | 31 | ||
| 31 | @Override | 32 | @Override |
| 32 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress) { | 33 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters saveParameters) { |
| 33 | try { | 34 | try { |
| 34 | Files.deleteIfExists(path); | 35 | Files.deleteIfExists(path); |
| 35 | Files.createFile(path); | 36 | Files.createFile(path); |
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsReader.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsReader.java index bc866bd7..81d181ba 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsReader.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsReader.java | |||
| @@ -5,6 +5,7 @@ import cuchaz.enigma.ProgressListener; | |||
| 5 | import cuchaz.enigma.throwables.MappingParseException; | 5 | import cuchaz.enigma.throwables.MappingParseException; |
| 6 | import cuchaz.enigma.translation.mapping.EntryMapping; | 6 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 7 | import cuchaz.enigma.translation.mapping.MappingPair; | 7 | import cuchaz.enigma.translation.mapping.MappingPair; |
| 8 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 8 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 9 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 9 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; | 10 | import cuchaz.enigma.translation.mapping.tree.HashEntryTree; |
| 10 | import cuchaz.enigma.translation.representation.MethodDescriptor; | 11 | import cuchaz.enigma.translation.representation.MethodDescriptor; |
| @@ -23,7 +24,7 @@ public enum TinyMappingsReader implements MappingsReader { | |||
| 23 | INSTANCE; | 24 | INSTANCE; |
| 24 | 25 | ||
| 25 | @Override | 26 | @Override |
| 26 | public EntryTree<EntryMapping> read(Path path, ProgressListener progress) throws IOException, MappingParseException { | 27 | public EntryTree<EntryMapping> read(Path path, ProgressListener progress, MappingSaveParameters saveParameters) throws IOException, MappingParseException { |
| 27 | return read(path, Files.readAllLines(path, Charsets.UTF_8), progress); | 28 | return read(path, Files.readAllLines(path, Charsets.UTF_8), progress); |
| 28 | } | 29 | } |
| 29 | 30 | ||
diff --git a/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsWriter.java b/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsWriter.java index 0a52dad7..ee656908 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsWriter.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/TinyMappingsWriter.java | |||
| @@ -7,6 +7,7 @@ import cuchaz.enigma.translation.MappingTranslator; | |||
| 7 | import cuchaz.enigma.translation.Translator; | 7 | import cuchaz.enigma.translation.Translator; |
| 8 | import cuchaz.enigma.translation.mapping.EntryMapping; | 8 | import cuchaz.enigma.translation.mapping.EntryMapping; |
| 9 | import cuchaz.enigma.translation.mapping.MappingDelta; | 9 | import cuchaz.enigma.translation.mapping.MappingDelta; |
| 10 | import cuchaz.enigma.translation.mapping.MappingSaveParameters; | ||
| 10 | import cuchaz.enigma.translation.mapping.VoidEntryResolver; | 11 | import cuchaz.enigma.translation.mapping.VoidEntryResolver; |
| 11 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | 12 | import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 12 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; | 13 | import cuchaz.enigma.translation.mapping.tree.EntryTreeNode; |
| @@ -40,7 +41,7 @@ public class TinyMappingsWriter implements MappingsWriter { | |||
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | @Override | 43 | @Override |
| 43 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress) { | 44 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path path, ProgressListener progress, MappingSaveParameters saveParameters) { |
| 44 | try { | 45 | try { |
| 45 | Files.deleteIfExists(path); | 46 | Files.deleteIfExists(path); |
| 46 | Files.createFile(path); | 47 | Files.createFile(path); |