}
return val;
}
public boolean readSettingsFile() {
LineNumberReader settingsReader = null;
String line;
// maybe restore a .bak of the .ini file
if (settingsFile.isFile() == false || settingsFile.length() == 0 ) {
// try to restore .bak file
final String configDirStr = getValue(SettingsClass.DIR_CONFIG);
final File bakFile = new File(configDirStr + "frost.ini.bak");
if( bakFile.isFile() && bakFile.length() > 0 ) {
bakFile.renameTo(settingsFile);
} else {
return false;
}
}
try {
settingsReader = new LineNumberReader(new FileReader(settingsFile));
} catch (final Exception e) {
logger.warning(settingsFile.getName() + " does not exist, will create it");
return false;
}
try {
while ((line = settingsReader.readLine()) != null) {
line = line.trim();
if (line.length() != 0 && line.startsWith("#") == false) {
final StringTokenizer strtok = new StringTokenizer(line, "=");
String key = "";
String value = "";
Object objValue = value;
if (strtok.countTokens() >= 2) {
key = strtok.nextToken().trim();
value = strtok.nextToken().trim();
// to allow '=' in values
while (strtok.hasMoreElements()) {
value += "=" + strtok.nextToken();
}
if (value.startsWith("type.color(") && value.endsWith(")")) {
// this is a color
final String rgbPart = value.substring(11, value.length() - 1);
final StringTokenizer strtok2 = new StringTokenizer(rgbPart, ",");
if (strtok2.countTokens() == 3) {
try {
int red, green, blue;
red = Integer.parseInt(strtok2.nextToken().trim());
green = Integer.parseInt(strtok2.nextToken().trim());
blue = Integer.parseInt(strtok2.nextToken().trim());
final Color c = new Color(red, green, blue);
objValue = c;
} catch (final Exception ex) {
objValue = null;
}
} else {
objValue = null; // dont insert in settings, use default instead
}
}
// scan all path config values and set correct system file separator
else if ( key.equals(SettingsClass.DIR_TEMP)
|| key.equals(DIR_LOCALDATA)
|| key.equals(DIR_STORE)
|| key.equals(DIR_DOWNLOAD)
|| key.equals(DIR_LAST_USED)) {
value = setSystemFileSeparator(value);
objValue = value;
} else {
// 'old' behaviour
objValue = value;
}
if (objValue != null) {
settingsHash.put(key, objValue);
}
}
}
}
} catch (final Exception e) {
logger.log(Level.SEVERE, "Exception thrown in readSettingsFile()", e);
}
try {
settingsReader.close();
} catch (final Exception e) {
logger.log(Level.SEVERE, "Exception thrown in readSettingsFile()", e);
}
doCleanup();