From 0f47403d0220757fed189b76e2071e25b1025cb8 Mon Sep 17 00:00:00 2001 From: Runemoro Date: Wed, 3 Jun 2020 13:39:42 -0400 Subject: Split GUI code to separate module (#242) * Split into modules * Post merge compile fixes Co-authored-by: modmuss50 --- src/main/java/cuchaz/enigma/Main.java | 116 ---------------------------------- 1 file changed, 116 deletions(-) delete mode 100644 src/main/java/cuchaz/enigma/Main.java (limited to 'src/main/java/cuchaz/enigma/Main.java') 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 @@ -/******************************************************************************* - * Copyright (c) 2015 Jeff Martin. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser General Public - * License v3.0 which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl.html - *

- * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ - -package cuchaz.enigma; - -import cuchaz.enigma.gui.Gui; -import cuchaz.enigma.gui.GuiController; -import cuchaz.enigma.translation.mapping.serde.MappingFormat; - -import joptsimple.*; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -import com.google.common.io.MoreFiles; - -public class Main { - - public static void main(String[] args) throws IOException { - OptionParser parser = new OptionParser(); - - OptionSpec jar = parser.accepts("jar", "Jar file to open at startup") - .withRequiredArg() - .withValuesConvertedBy(PathConverter.INSTANCE); - - OptionSpec mappings = parser.accepts("mappings", "Mappings file to open at startup") - .withRequiredArg() - .withValuesConvertedBy(PathConverter.INSTANCE); - - OptionSpec profile = parser.accepts("profile", "Profile json to apply at startup") - .withRequiredArg() - .withValuesConvertedBy(PathConverter.INSTANCE); - - parser.accepts("help", "Displays help information"); - - try { - OptionSet options = parser.parse(args); - - if (options.has("help")) { - parser.printHelpOn(System.out); - return; - } - - EnigmaProfile parsedProfile = EnigmaProfile.read(options.valueOf(profile)); - - Gui gui = new Gui(parsedProfile); - GuiController controller = gui.getController(); - - if (options.has(jar)) { - Path jarPath = options.valueOf(jar); - controller.openJar(jarPath) - .whenComplete((v, t) -> { - if (options.has(mappings)) { - Path mappingsPath = options.valueOf(mappings); - if (Files.isDirectory(mappingsPath)) { - controller.openMappings(MappingFormat.ENIGMA_DIRECTORY, mappingsPath); - } else if ("zip".equalsIgnoreCase(MoreFiles.getFileExtension(mappingsPath))) { - controller.openMappings(MappingFormat.ENIGMA_ZIP, mappingsPath); - } else { - controller.openMappings(MappingFormat.ENIGMA_FILE, mappingsPath); - } - } - }); - } - } catch (OptionException e) { - System.out.println("Invalid arguments: " + e.getMessage()); - System.out.println(); - parser.printHelpOn(System.out); - } - } - - public static class PathConverter implements ValueConverter { - public static final ValueConverter INSTANCE = new PathConverter(); - - PathConverter() { - } - - @Override - public Path convert(String path) { - // expand ~ to the home dir - if (path.startsWith("~")) { - // get the home dir - Path dirHome = Paths.get(System.getProperty("user.home")); - - // is the path just ~/ or is it ~user/ ? - if (path.startsWith("~/")) { - return dirHome.resolve(path.substring(2)); - } else { - return dirHome.getParent().resolve(path.substring(1)); - } - } - - return Paths.get(path); - } - - @Override - public Class valueType() { - return Path.class; - } - - @Override - public String valuePattern() { - return "path"; - } - } -} -- cgit v1.2.3