/*
JWildfire - an image and animation processor written in Java
Copyright (C) 1995-2014 Andreas Maschke
This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser
General Public License as published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this software;
if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jwildfire.launcher;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
import org.jwildfire.base.Tools;
public class LauncherPrefsReader {
private String getProperty(Properties pProperties, String pKey, String pDefaultValue) {
String res = pProperties.getProperty(pKey, "").trim();
return res.length() > 0 ? res : pDefaultValue;
}
private int getIntProperty(Properties pProperties, String pKey, int pDefaultValue) {
String val = pProperties.getProperty(pKey, "").trim();
return val.length() > 0 ? Tools.stringToInt(val) : pDefaultValue;
}
private boolean getBooleanProperty(Properties pProperties, String pKey, boolean pDefaultValue) {
String val = pProperties.getProperty(pKey, "").trim();
return val.length() > 0 ? val.equalsIgnoreCase("true") : pDefaultValue;
}
// private double getDoubleProperty(Properties pProperties, String pKey, double pDefaultValue) {
// String val = pProperties.getProperty(pKey, "").trim();
// return val.length() > 0 ? Tools.stringToDouble(val) : pDefaultValue;
// }
public void readPrefs(LauncherPrefs pPrefs) throws Exception {
File file = new File(System.getProperty("user.home"), LauncherPrefs.PREFS_FILE);
if (file.exists()) {
InputStream inputStream = new FileInputStream(file);
try {
Properties props = new Properties();
props.load(inputStream);
pPrefs.setJavaPath(getProperty(props, LauncherPrefs.KEY_JAVA_PATH, pPrefs.getJavaPath()));
pPrefs.setMaxMem(getIntProperty(props, LauncherPrefs.KEY_MEMORY_MAX, pPrefs.getMaxMem()));
pPrefs.setLowPriority(getBooleanProperty(props, LauncherPrefs.KEY_PRIORITY_LOW, pPrefs.isLowPriority()));
}
finally {
inputStream.close();
}
}
}
}