summaryrefslogtreecommitdiff
path: root/src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java
diff options
context:
space:
mode:
authorGravatar liach2019-05-15 22:03:13 -0700
committerGravatar Gegy2019-05-16 07:03:13 +0200
commitcb8823eb0b446d5c1b9b580e5578866e691771d8 (patch)
tree1e8c1a5b981f3ad42c393f5d7cb75754f25f51ba /src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java
parentcheckmappings command (#137) (diff)
downloadenigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.tar.gz
enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.tar.xz
enigma-fork-cb8823eb0b446d5c1b9b580e5578866e691771d8.zip
Feature/weave (#138)
* Add weave/stitch style command system to enigma Also fixed divide by zero stupidity Signed-off-by: liach <liach@users.noreply.github.com> * Add tests for package access index and command Signed-off-by: liach <liach@users.noreply.github.com> * Minor tweaks Signed-off-by: liach <liach@users.noreply.github.com>
Diffstat (limited to 'src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java')
-rw-r--r--src/main/java/cuchaz/enigma/command/ConvertMappingsCommand.java47
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 @@
1package cuchaz.enigma.command;
2
3import cuchaz.enigma.translation.mapping.EntryMapping;
4import cuchaz.enigma.translation.mapping.serde.MappingFormat;
5import cuchaz.enigma.translation.mapping.tree.EntryTree;
6
7import java.io.File;
8import java.nio.file.Path;
9import java.util.Locale;
10
11public 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}