* <br>Fill the text areas for the command line and config file.
* <br>Fill all Controls all over the GUI.
*/
private void readConfigFile() {
// Find the config directory XPlanet would probably use.
XPlanetRessourceFinder f = new XPlanetRessourceFinder();
// Do not use the -searchdir.
// Use the -searchdir from the moment on it is known from the current
// command line (that is unknowd at this moment, because it is still
// not loaded from file).
String configDir = f.getRessourceDirectory("config");
// Now use the directory
File cfg = new File(configDir + File.separator + MainFrame.getCONFIG_NAME());
if (!cfg.exists()) {
this.logger.fine("Found no config file " + cfg.getAbsolutePath());
this.selectControlPanel("-config");
return;
}
if (!cfg.isFile()) {
this.logger.fine("Config file is not a file: " + cfg.getAbsolutePath());
this.selectControlPanel("-config");
return;
}
FileUtil util = new FileUtil();
String configParameters = null;
try {
configParameters = util.getFileAsString(cfg);
} catch (Exception ex) {
this.logger.log(Level.SEVERE, null, ex);
this.popError("Failed to read config file:\n" + cfg.getAbsolutePath() + "\n\n" + ex.getLocalizedMessage());
return;
}
this.logger.config("Read config file: " + cfg.getAbsolutePath());
// Read the command line parameters from the config file
Pattern p = Pattern.compile(MainFrame.COMMENT_COMMAND_LINE_PARAMETERS_REG_EXPR);
Matcher m = p.matcher(configParameters);
if (m.find()) {
String commandLineParameters = m.group(2);
// Allays let the GUI set the -searchdir
commandLineParameters = f.replaceSearchDir(commandLineParameters);
this.jTextAreaCommandLineParameters.setText(commandLineParameters.trim());
this.logger.finer("Setting command line parameters found in config file: " + cfg.toString());
configParameters = configParameters.replaceAll(COMMENT_COMMAND_LINE_PARAMETERS_REG_EXPR, "");
configParameters = COMMENT_COMMAND_LINE_PARAMETERS + commandLineParameters + "\n" + configParameters;
}