private static void configureLogging(@Nullable final String logFileName) { final String qualifiedLogFilename = PreferenceManager.getClientPreferences().getLogDirectory() + File.separator + logFileName; resetLogFile(qualifiedLogFilename); configureLegacyLogging(logFileName); configureLog4j(logFileName); }
/** * 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; }
configureLogging(logFileName); MegaMek.showInfo(); MegaMek.startDedicatedServer(restArgs); } else { .getGUIName(); MegaMek.startGUI(interfaceName, restArgs); .append(e.getMessage()).append('\n'); message.append(ARGUMENTS_DESCRIPTION_MESSAGE); MegaMek.displayMessageAndExit(message.toString(), "main(String[])");
return; IMegaMekGUI mainGui = MegaMek.getGui(guiName); if (mainGui == null) { MegaMek.displayMessageAndExit(UNKNOWN_GUI_MESSAGE + guiName, METHOD_NAME); } else { StringBuffer message = new StringBuffer("Starting GUI "); //$NON-NLS-1$ message.append(guiName).append(". "); //$NON-NLS-1$ MegaMek.dumpArgs(message, args); MegaMek.displayMessage(message.toString(), METHOD_NAME); mainGui.start(args);
/** * This function redirects the standard error and output streams to the * given File name. * */ private static void redirectOutput() { try { System.out.println("Redirecting output to mekhqlog.txt"); //$NON-NLS-1$ File logDir = new File("logs"); if (!logDir.exists()) { logDir.mkdir(); } final String logFilename = "logs" + File.separator + "mekhqlog.txt"; MegaMek.resetLogFile(logFilename); PrintStream ps = new PrintStream( new BufferedOutputStream( new FileOutputStream(logFilename, true), 64)); System.setOut(ps); System.setErr(ps); } catch (Exception e) { System.err.println("Unable to redirect output to mekhqlog.txt"); //$NON-NLS-1$ e.printStackTrace(); } }
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; }
Object[] versionData = new Object[2]; versionData[0] = MegaMek.VERSION; versionData[1] = MegaMek.getMegaMekSHA256(); send(new Packet(Packet.COMMAND_CLIENT_VERSIONS, versionData)); break;
/** * 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); }