private static String getGUIClassName(String guiName) { assert (guiName != null) : "guiName must be non-null"; //$NON-NLS-1$ Properties p = new Properties(); String key = "gui." + guiName; //$NON-NLS-1$ final String PROPERTIES_FILE = "megamek/MegaMek.properties"; try(InputStream is = MegaMek.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE)) { if (is != null) { p.load(is); return p.getProperty(key); } } catch (IOException e) { MegaMek.displayMessage("Property file load failed.", "getGUIClassName(String)"); //$NON-NLS-1$ } return null; }
message.append(guiName).append(". "); //$NON-NLS-1$ MegaMek.dumpArgs(message, args); MegaMek.displayMessage(message.toString(), METHOD_NAME); mainGui.start(args);
/** * Prints some information about MegaMek. Used in logfiles to figure out the * JVM and version of MegaMek. */ private static void showInfo() { final String METHOD_NAME = "showInfo"; // echo some useful stuff String msg = "Starting MegaMek v" + VERSION + " ..."; //$NON-NLS-1$ //$NON-NLS-2$ msg += "\n\tCompiled on " + new Date(TIMESTAMP).toString(); //$NON-NLS-1$ msg += "\n\tToday is " + new Date().toString(); //$NON-NLS-1$ msg += "\n\tJava vendor " + System.getProperty("java.vendor"); //$NON-NLS-1$ //$NON-NLS-2$ msg += "\n\tJava version " + System.getProperty("java.version"); //$NON-NLS-1$ //$NON-NLS-2$ msg += "\n\tPlatform " //$NON-NLS-1$ + System.getProperty("os.name") //$NON-NLS-1$ + " " //$NON-NLS-1$ + System.getProperty("os.version") //$NON-NLS-1$ + " (" //$NON-NLS-1$ + System.getProperty("os.arch") //$NON-NLS-1$ + ")"; //$NON-NLS-1$ long maxMemory = Runtime.getRuntime().maxMemory() / 1024; msg += "\n\tTotal memory available to MegaMek: " + MegaMek.commafy.format(maxMemory) + " kB"; //$NON-NLS-1$ //$NON-NLS-2$ displayMessage(msg, METHOD_NAME); }
/** * Prints the message to stdout and then exits with errorcode 1. * * @param message * the message to be displayed. */ private static void displayMessageAndExit(String message, String methodName) { MegaMek.displayMessage(message, methodName); TimerSingleton.getInstance().killTimer(); System.exit(1); }
/** * Starts a dedicated server with the arguments in args. See * {@link megamek.server.DedicatedServer#start(String[])} for more * information. * * @param args * the arguments to the dedicated server. */ private static void startDedicatedServer(String[] args) { StringBuffer message = new StringBuffer("Starting Dedicated Server. "); //$NON-NLS-1$ MegaMek.dumpArgs(message, args); MegaMek.displayMessage(message.toString(), "startDedicatedServer(String[])"); DedicatedServer.start(args); }
/** * Return the Interface to the GUI specified by the name in guiName. * * @param guiName * the name of the GUI, will be passed on to * {@link #getGUIClassName(String)}. * @return An that can start a GUI such as * {@link IMegaMekGUI}. */ @SuppressWarnings({ "rawtypes" }) private static IMegaMekGUI getGui(String guiName) { assert (guiName != null) : "guiName must be non-null"; //$NON-NLS-1$ String guiClassName = MegaMek.getGUIClassName(guiName); if (guiClassName != null) { try { Class guiClass = Class.forName(guiClassName); if (IMegaMekGUI.class.isAssignableFrom(guiClass)) { IMegaMekGUI result = (IMegaMekGUI) guiClass.newInstance(); return result; } } catch (Exception e) { MegaMek.displayMessage(GUI_CLASS_NOT_FOUND_MESSAGE + guiClassName, "getGui(String)"); } } return null; }