private void parseGUI() throws ParseException { if (getToken() == TOK_LITERAL) { guiName = getTokenValue(); nextToken(); } else { error("GUI name expected"); //$NON-NLS-1$ } }
@SuppressWarnings("nls") private void processUnitExporter() { processUnitExporter(false); }
private static void configureLegacyLogging(@Nullable final String logFileName) { // Redirect output to logfiles, unless turned off. if (logFileName == null) { return; } MegaMek.redirectOutput(logFileName); }
private void processUnitBattleForceConverter() { if (getToken() == TOK_LITERAL) { filename = getTokenValue(); nextToken(); w.newLine(); MechSummary[] units = MechSummaryCache.getInstance() .getAllMechs(); for (MechSummary unit : units) { Entity entity = new MechFileParser( unit.getSourceFile(), unit.getEntryName()) .getEntity(); BattleForceElement bfe = new BattleForceElement(entity); bfe.writeCsv(w); logger.error(getClass(), "processUnitBattleForceConverter()", ex);
CommandLineParser cp = new CommandLineParser(args); cp.parse(); String lf = cp.getLogFilename(); if (lf != null) { if (lf.equals("none") || lf.equals("off")) { //$NON-NLS-1$ //$NON-NLS-2$ configureLogging(logFileName); MegaMek.showInfo(); String[] restArgs = cp.getRestArgs(); if (cp.dedicatedServer()) { MegaMek.startDedicatedServer(restArgs); } else { ButtonOrderPreferences.getInstance().setButtonPriorities(); String interfaceName = cp.getGuiName(); if (interfaceName == null) { interfaceName = PreferenceManager.getClientPreferences() .getGUIName(); MegaMek.startGUI(interfaceName, restArgs); .append(e.getMessage()).append('\n'); message.append(ARGUMENTS_DESCRIPTION_MESSAGE); MegaMek.displayMessageAndExit(message.toString(), "main(String[])");
if ((getToken() == TOK_OPTION) && getTokenValue().equals(OPTION_LOG)) { nextToken(); parseLog(); if ((getToken() == TOK_OPTION) && getTokenValue().equals(OPTION_EQUIPMENT_DB)) { nextToken(); processEquipmentDb(); if ((getToken() == TOK_OPTION) && getTokenValue().equals(OPTION_EQUIPMENT_EXTENDED_DB)) { nextToken(); processExtendedEquipmentDb(); if ((getToken() == TOK_OPTION) && getTokenValue().equals(OPTION_DATADIR)) { nextToken(); processDataDir(); if ((getToken() == TOK_OPTION) && getTokenValue().equals(OPTION_UNIT_VALIDATOR)) { nextToken(); processUnitValidator(); if ((getToken() == TOK_OPTION) && getTokenValue().equals(OPTION_UNIT_EXPORT)) { nextToken(); processUnitExporter();
private static void configureLogging(@Nullable final String logFileName) { final String qualifiedLogFilename = PreferenceManager.getClientPreferences().getLogDirectory() + File.separator + logFileName; resetLogFile(qualifiedLogFilename); configureLegacyLogging(logFileName); configureLog4j(logFileName); }
final String METHOD_NAME = "startGUI(String, String[])"; if (null == guiName) { logger.log(MegaMek.class, METHOD_NAME, LogLevel.ERROR, "guiName must be non-null"); return; logger.log(MegaMek.class, METHOD_NAME, LogLevel.ERROR, "args must be non-null"); 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);
private void processRestOfInput() { Vector<String> v = new Vector<String>(); while (getArgValue() != null) { v.addElement(getArgValue()); nextArg(); } setToken(TOK_EOF); setTokenValue(null); restArgs = v.toArray(new String[0]); } }
/** * 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; }
/** * 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; }
@Override public void flush() throws IOException { super.flush(); getFD().sync(); }; }
private void parseLog() throws ParseException { if (getToken() == TOK_LITERAL) { logFilename = getTokenValue(); nextToken(); } else { error("log file name expected"); //$NON-NLS-1$ } }
/** * 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); }
private void processDataDir() throws ParseException { String dataDirName; if (getToken() == TOK_LITERAL) { dataDirName = getTokenValue(); nextToken(); Configuration.setDataDir(new File(dataDirName)); } else { error("directory name expected"); // $NON-NLS-1$ } }
private void processExtendedEquipmentDb() throws ParseException { String filename; if (getToken() == TOK_LITERAL) { filename = getTokenValue(); nextToken(); megamek.common.EquipmentType .writeEquipmentExtendedDatabase(new File(filename)); } else { error("file name expected"); //$NON-NLS-1$ } System.exit(0); }
private void processEquipmentDb() throws ParseException { String filename; if (getToken() == TOK_LITERAL) { filename = getTokenValue(); nextToken(); megamek.common.EquipmentType.writeEquipmentDatabase(new File( filename)); } else { error("file name expected"); //$NON-NLS-1$ } System.exit(0); }