diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java b/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java new file mode 100644 index 0000000..75d3791 --- /dev/null +++ b/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | package cuchaz.enigma.command; | ||
| 2 | |||
| 3 | import cuchaz.enigma.translation.mapping.EntryMapping; | ||
| 4 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 5 | import cuchaz.enigma.translation.mapping.tree.EntryTree; | ||
| 6 | |||
| 7 | import java.io.File; | ||
| 8 | import java.nio.file.Path; | ||
| 9 | import java.util.Locale; | ||
| 10 | |||
| 11 | public class ConvertMappingsCommand extends Command { | ||
| 12 | |||
| 13 | public ConvertMappingsCommand() { | ||
| 14 | super("convertmappings"); | ||
| 15 | } | ||
| 16 | |||
| 17 | @Override | ||
| 18 | public String getUsage() { | ||
| 19 | return "<enigma mappings> <converted mappings> <ENIGMA_FILE|ENIGMA_DIRECTORY|SRG_FILE>"; | ||
| 20 | } | ||
| 21 | |||
| 22 | @Override | ||
| 23 | public boolean isValidArgument(int length) { | ||
| 24 | return length == 3; | ||
| 25 | } | ||
| 26 | |||
| 27 | @Override | ||
| 28 | public void run(String... args) throws Exception { | ||
| 29 | Path fileMappings = getReadablePath(getArg(args, 0, "enigma mappings", true)); | ||
| 30 | File result = getWritableFile(getArg(args, 1, "converted mappings", true)); | ||
| 31 | String name = getArg(args, 2, "format desc", true); | ||
| 32 | MappingFormat saveFormat; | ||
| 33 | try { | ||
| 34 | saveFormat = MappingFormat.valueOf(name.toUpperCase(Locale.ROOT)); | ||
| 35 | } catch (IllegalArgumentException e) { | ||
| 36 | throw new IllegalArgumentException(name + "is not a valid mapping format!"); | ||
| 37 | } | ||
| 38 | |||
| 39 | System.out.println("Reading mappings..."); | ||
| 40 | |||
| 41 | MappingFormat readFormat = chooseEnigmaFormat(fileMappings); | ||
| 42 | EntryTree<EntryMapping> mappings = readFormat.read(fileMappings, new ConsoleProgressListener()); | ||
| 43 | System.out.println("Saving new mappings..."); | ||
| 44 | |||
| 45 | saveFormat.write(mappings, result.toPath(), new ConsoleProgressListener()); | ||
| 46 | } | ||
| 47 | } | ||