diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/Main.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Main.java | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/main/java/cuchaz/enigma/Main.java b/src/main/java/cuchaz/enigma/Main.java deleted file mode 100644 index 7c87669..0000000 --- a/src/main/java/cuchaz/enigma/Main.java +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | |||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.gui.Gui; | ||
| 15 | import cuchaz.enigma.gui.GuiController; | ||
| 16 | import cuchaz.enigma.translation.mapping.serde.MappingFormat; | ||
| 17 | |||
| 18 | import joptsimple.*; | ||
| 19 | |||
| 20 | import java.io.IOException; | ||
| 21 | import java.nio.file.Files; | ||
| 22 | import java.nio.file.Path; | ||
| 23 | import java.nio.file.Paths; | ||
| 24 | |||
| 25 | import com.google.common.io.MoreFiles; | ||
| 26 | |||
| 27 | public class Main { | ||
| 28 | |||
| 29 | public static void main(String[] args) throws IOException { | ||
| 30 | OptionParser parser = new OptionParser(); | ||
| 31 | |||
| 32 | OptionSpec<Path> jar = parser.accepts("jar", "Jar file to open at startup") | ||
| 33 | .withRequiredArg() | ||
| 34 | .withValuesConvertedBy(PathConverter.INSTANCE); | ||
| 35 | |||
| 36 | OptionSpec<Path> mappings = parser.accepts("mappings", "Mappings file to open at startup") | ||
| 37 | .withRequiredArg() | ||
| 38 | .withValuesConvertedBy(PathConverter.INSTANCE); | ||
| 39 | |||
| 40 | OptionSpec<Path> profile = parser.accepts("profile", "Profile json to apply at startup") | ||
| 41 | .withRequiredArg() | ||
| 42 | .withValuesConvertedBy(PathConverter.INSTANCE); | ||
| 43 | |||
| 44 | parser.accepts("help", "Displays help information"); | ||
| 45 | |||
| 46 | try { | ||
| 47 | OptionSet options = parser.parse(args); | ||
| 48 | |||
| 49 | if (options.has("help")) { | ||
| 50 | parser.printHelpOn(System.out); | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); | ||
| 55 | |||
| 56 | Gui gui = new Gui(parsedProfile); | ||
| 57 | GuiController controller = gui.getController(); | ||
| 58 | |||
| 59 | if (options.has(jar)) { | ||
| 60 | Path jarPath = options.valueOf(jar); | ||
| 61 | controller.openJar(jarPath) | ||
| 62 | .whenComplete((v, t) -> { | ||
| 63 | if (options.has(mappings)) { | ||
| 64 | Path mappingsPath = options.valueOf(mappings); | ||
| 65 | if (Files.isDirectory(mappingsPath)) { | ||
| 66 | controller.openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsPath); | ||
| 67 | } else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(mappingsPath))) { | ||
| 68 | controller.openMappings(MappingFormat.ENIGMA_ZIP, mappingsPath); | ||
| 69 | } else { | ||
| 70 | controller.openMappings(MappingFormat.ENIGMA_FILE, mappingsPath); | ||
| 71 | } | ||
| 72 | } | ||
| 73 | }); | ||
| 74 | } | ||
| 75 | } catch (OptionException e) { | ||
| 76 | System.out.println("Invalid arguments: " + e.getMessage()); | ||
| 77 | System.out.println(); | ||
| 78 | parser.printHelpOn(System.out); | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | public static class PathConverter implements ValueConverter<Path> { | ||
| 83 | public static final ValueConverter<Path> INSTANCE = new PathConverter(); | ||
| 84 | |||
| 85 | PathConverter() { | ||
| 86 | } | ||
| 87 | |||
| 88 | @Override | ||
| 89 | public Path convert(String path) { | ||
| 90 | // expand ~ to the home dir | ||
| 91 | if (path.startsWith("~")) { | ||
| 92 | // get the home dir | ||
| 93 | Path dirHome = Paths.get(System.getProperty("user.home")); | ||
| 94 | |||
| 95 | // is the path just ~/ or is it ~user/ ? | ||
| 96 | if (path.startsWith("~/")) { | ||
| 97 | return dirHome.resolve(path.substring(2)); | ||
| 98 | } else { | ||
| 99 | return dirHome.getParent().resolve(path.substring(1)); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | |||
| 103 | return Paths.get(path); | ||
| 104 | } | ||
| 105 | |||
| 106 | @Override | ||
| 107 | public Class<? extends Path> valueType() { | ||
| 108 | return Path.class; | ||
| 109 | } | ||
| 110 | |||
| 111 | @Override | ||
| 112 | public String valuePattern() { | ||
| 113 | return "path"; | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||