diff options
| author | 2020-03-17 23:28:47 +0000 | |
|---|---|---|
| committer | 2020-03-17 23:28:47 +0000 | |
| commit | bfd7bfd739968af5b7bad17134783deedd424f1f (patch) | |
| tree | a9dc7906c88c1c8c40c98f0f97632cd7dd269e25 /src/main/java/cuchaz/enigma/translation | |
| parent | Fix documenting constructors (#201) (diff) | |
| download | enigma-fork-bfd7bfd739968af5b7bad17134783deedd424f1f.tar.gz enigma-fork-bfd7bfd739968af5b7bad17134783deedd424f1f.tar.xz enigma-fork-bfd7bfd739968af5b7bad17134783deedd424f1f.zip | |
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
Diffstat (limited to 'src/main/java/cuchaz/enigma/translation')
3 files changed, 28 insertions, 0 deletions
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 60ce587..a1d5e01 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsReader.java | |||
| @@ -16,6 +16,8 @@ import cuchaz.enigma.utils.I18n; | |||
| 16 | 16 | ||
| 17 | import javax.annotation.Nullable; | 17 | import javax.annotation.Nullable; |
| 18 | import java.io.IOException; | 18 | import java.io.IOException; |
| 19 | import java.nio.file.FileSystem; | ||
| 20 | import java.nio.file.FileSystems; | ||
| 19 | import java.nio.file.Files; | 21 | import java.nio.file.Files; |
| 20 | import java.nio.file.Path; | 22 | import java.nio.file.Path; |
| 21 | import java.util.ArrayDeque; | 23 | import java.util.ArrayDeque; |
| @@ -62,6 +64,14 @@ public enum EnigmaMappingsReader implements MappingsReader { | |||
| 62 | 64 | ||
| 63 | return mappings; | 65 | return mappings; |
| 64 | } | 66 | } |
| 67 | }, | ||
| 68 | ZIP { | ||
| 69 | @Override | ||
| 70 | public EntryTree<EntryMapping> read(Path zip, ProgressListener progress, MappingSaveParameters saveParameters) throws MappingParseException, IOException { | ||
| 71 | try (FileSystem fs = FileSystems.newFileSystem(zip, (ClassLoader) null)) { | ||
| 72 | return DIRECTORY.read(fs.getPath("/"), progress, saveParameters); | ||
| 73 | } | ||
| 74 | } | ||
| 65 | }; | 75 | }; |
| 66 | 76 | ||
| 67 | protected void readFile(Path path, EntryTree<EntryMapping> mappings) throws IOException, MappingParseException { | 77 | protected void readFile(Path path, EntryTree<EntryMapping> mappings) throws IOException, MappingParseException { |
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 2ce1234..2f6c7bc 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java | |||
| @@ -13,12 +13,17 @@ package cuchaz.enigma.translation.mapping.serde; | |||
| 13 | 13 | ||
| 14 | import java.io.IOException; | 14 | import java.io.IOException; |
| 15 | import java.io.PrintWriter; | 15 | import java.io.PrintWriter; |
| 16 | import java.net.URI; | ||
| 17 | import java.net.URISyntaxException; | ||
| 16 | import java.nio.file.DirectoryStream; | 18 | import java.nio.file.DirectoryStream; |
| 19 | import java.nio.file.FileSystem; | ||
| 20 | import java.nio.file.FileSystems; | ||
| 17 | import java.nio.file.Files; | 21 | import java.nio.file.Files; |
| 18 | import java.nio.file.Path; | 22 | import java.nio.file.Path; |
| 19 | import java.nio.file.Paths; | 23 | import java.nio.file.Paths; |
| 20 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
| 21 | import java.util.Collection; | 25 | import java.util.Collection; |
| 26 | import java.util.Collections; | ||
| 22 | import java.util.Objects; | 27 | import java.util.Objects; |
| 23 | import java.util.concurrent.atomic.AtomicInteger; | 28 | import java.util.concurrent.atomic.AtomicInteger; |
| 24 | import java.util.stream.Collectors; | 29 | import java.util.stream.Collectors; |
| @@ -159,6 +164,18 @@ public enum EnigmaMappingsWriter implements MappingsWriter { | |||
| 159 | private Path resolve(Path root, ClassEntry classEntry) { | 164 | private Path resolve(Path root, ClassEntry classEntry) { |
| 160 | return root.resolve(classEntry.getFullName() + ".mapping"); | 165 | return root.resolve(classEntry.getFullName() + ".mapping"); |
| 161 | } | 166 | } |
| 167 | }, | ||
| 168 | ZIP { | ||
| 169 | @Override | ||
| 170 | public void write(EntryTree<EntryMapping> mappings, MappingDelta<EntryMapping> delta, Path zip, ProgressListener progress, MappingSaveParameters saveParameters) { | ||
| 171 | try (FileSystem fs = FileSystems.newFileSystem(new URI("jar:file", null, zip.toUri().getPath(), ""), Collections.singletonMap("create", "true"))) { | ||
| 172 | DIRECTORY.write(mappings, delta, fs.getPath("/"), progress, saveParameters); | ||
| 173 | } catch (IOException e) { | ||
| 174 | e.printStackTrace(); | ||
| 175 | } catch (URISyntaxException e) { | ||
| 176 | throw new RuntimeException("Unexpected error creating URI for " + zip, e); | ||
| 177 | } | ||
| 178 | } | ||
| 162 | }; | 179 | }; |
| 163 | 180 | ||
| 164 | protected void writeRoot(PrintWriter writer, EntryTree<EntryMapping> mappings, ClassEntry classEntry) { | 181 | protected void writeRoot(PrintWriter writer, EntryTree<EntryMapping> mappings, ClassEntry classEntry) { |
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 c04eec5..6c8c343 100644 --- a/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java +++ b/src/main/java/cuchaz/enigma/translation/mapping/serde/MappingFormat.java | |||
| @@ -14,6 +14,7 @@ import java.nio.file.Path; | |||
| 14 | public enum MappingFormat { | 14 | public enum MappingFormat { |
| 15 | ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE), | 15 | ENIGMA_FILE(EnigmaMappingsWriter.FILE, EnigmaMappingsReader.FILE), |
| 16 | ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY), | 16 | ENIGMA_DIRECTORY(EnigmaMappingsWriter.DIRECTORY, EnigmaMappingsReader.DIRECTORY), |
| 17 | ENIGMA_ZIP(EnigmaMappingsWriter.ZIP, EnigmaMappingsReader.ZIP), | ||
| 17 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader()), | 18 | TINY_V2(new TinyV2Writer("intermediary", "named"), new TinyV2Reader()), |
| 18 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE), | 19 | TINY_FILE(TinyMappingsWriter.INSTANCE, TinyMappingsReader.INSTANCE), |
| 19 | SRG_FILE(SrgMappingsWriter.INSTANCE, null), | 20 | SRG_FILE(SrgMappingsWriter.INSTANCE, null), |