From bfd7bfd739968af5b7bad17134783deedd424f1f Mon Sep 17 00:00:00 2001 From: Chocohead Date: Tue, 17 Mar 2020 23:28:47 +0000 Subject: Add support for reading/writing zipped mappings (#199) * Add support to read/write Enigma mappings from ZIP Takes any path which points to a ZIP as wanting to be read/written as a ZIP Paths from an existing ZIP file system will be correctly handled as directories * Fix deleting a path needing to be from the default file system * Allow calling MapSpecializedMethodsCommand directly * Fix indentation * Missing static--- src/main/java/cuchaz/enigma/command/Command.java | 4 ++++ .../cuchaz/enigma/command/MapSpecializedMethodsCommand.java | 10 ++++++---- src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/cuchaz/enigma/command') diff --git a/src/main/java/cuchaz/enigma/command/Command.java b/src/main/java/cuchaz/enigma/command/Command.java index d53ed6e..09dd321 100644 --- a/src/main/java/cuchaz/enigma/command/Command.java +++ b/src/main/java/cuchaz/enigma/command/Command.java @@ -13,6 +13,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import com.google.common.io.MoreFiles; + public abstract class Command { public final String name; @@ -49,6 +51,8 @@ public abstract class Command { protected static MappingFormat chooseEnigmaFormat(Path path) { if (Files.isDirectory(path)) { return MappingFormat.ENIGMA_DIRECTORY; + } else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(path))) { + return MappingFormat.ENIGMA_ZIP; } else { return MappingFormat.ENIGMA_FILE; } diff --git a/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java b/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java index 7696f0f..eb8d5dc 100644 --- a/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java +++ b/src/main/java/cuchaz/enigma/command/MapSpecializedMethodsCommand.java @@ -36,10 +36,13 @@ public class MapSpecializedMethodsCommand extends Command { @Override public void run(String... args) throws IOException, MappingParseException { + run(Paths.get(args[0]), args[1], Paths.get(args[2]), args[3], Paths.get(args[4])); + } + + public static void run(Path jar, String sourceFormat, Path sourcePath, String resultFormat, Path output) throws IOException, MappingParseException { MappingSaveParameters saveParameters = new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF); - EntryTree source = MappingCommandsUtil.read(args[1], Paths.get(args[2]), saveParameters); + EntryTree source = MappingCommandsUtil.read(sourceFormat, sourcePath, saveParameters); EntryTree result = new HashEntryTree<>(); - Path jar = Paths.get(args[0]); ClassCache classCache = ClassCache.of(jar); JarIndex jarIndex = classCache.index(ProgressListener.none()); BridgeMethodIndex bridgeMethodIndex = jarIndex.getBridgeMethodIndex(); @@ -60,8 +63,7 @@ public class MapSpecializedMethodsCommand extends Command { result.insert(specialized, new EntryMapping(name)); } - Path output = Paths.get(args[4]); Utils.delete(output); - MappingCommandsUtil.write(result, args[3], output, saveParameters); + MappingCommandsUtil.write(result, resultFormat, output, saveParameters); } } diff --git a/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java b/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java index fc68edf..fc7afbc 100644 --- a/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java +++ b/src/main/java/cuchaz/enigma/command/MappingCommandsUtil.java @@ -17,6 +17,7 @@ import cuchaz.enigma.translation.representation.entry.FieldEntry; import cuchaz.enigma.translation.representation.entry.MethodEntry; import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; import java.util.HashSet; import java.util.Set; @@ -81,7 +82,7 @@ public final class MappingCommandsUtil { public static EntryTree read(String type, Path path, MappingSaveParameters saveParameters) throws MappingParseException, IOException { if (type.equals("enigma")) { - return EnigmaMappingsReader.DIRECTORY.read(path, ProgressListener.none(), saveParameters); + return (Files.isDirectory(path) ? EnigmaMappingsReader.DIRECTORY : EnigmaMappingsReader.ZIP).read(path, ProgressListener.none(), saveParameters); } if (type.equals("tiny")) { -- cgit v1.2.3