redid config sanitycheck/fallback
This commit is contained in:
@@ -224,22 +224,10 @@ public class SettingsLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadFile() {
|
|
||||||
this.login = null;
|
public void loadFile() throws Exception {
|
||||||
this.password = null;
|
|
||||||
this.proxy = null;
|
initWithDefaults();
|
||||||
this.hostname = null;
|
|
||||||
this.computeMethod = null;
|
|
||||||
this.gpu = null;
|
|
||||||
this.renderbucketSize = null;
|
|
||||||
this.cacheDir = null;
|
|
||||||
this.autoSignIn = null;
|
|
||||||
this.useSysTray = null;
|
|
||||||
this.ui = null;
|
|
||||||
this.priority = 19; // must be the same default as Configuration
|
|
||||||
this.ram = null;
|
|
||||||
this.renderTime = null;
|
|
||||||
this.theme = null;
|
|
||||||
|
|
||||||
if (new File(path).exists() == false) {
|
if (new File(path).exists() == false) {
|
||||||
return;
|
return;
|
||||||
@@ -319,8 +307,8 @@ public class SettingsLoader {
|
|||||||
this.priority = Integer.parseInt(prop.getProperty("priority"));
|
this.priority = Integer.parseInt(prop.getProperty("priority"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IOException io) {
|
catch (Exception e) { //We need the try-catch here to ensure that the input file will be closed though we'll deal with the exception in the calling method
|
||||||
io.printStackTrace();
|
throw e;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
@@ -343,8 +331,20 @@ public class SettingsLoader {
|
|||||||
System.out.println("SettingsLoader::merge config is null");
|
System.out.println("SettingsLoader::merge config is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFile();
|
try {
|
||||||
|
loadFile();
|
||||||
|
applyConfigFileValues(config);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
System.err.println("Exception while reading the config file. Falling back to defaults");
|
||||||
|
initWithDefaults();
|
||||||
|
applyConfigFileValues(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyConfigFileValues(Configuration config) {
|
||||||
if (config.getLogin().isEmpty() && login != null) {
|
if (config.getLogin().isEmpty() && login != null) {
|
||||||
config.setLogin(login);
|
config.setLogin(login);
|
||||||
}
|
}
|
||||||
@@ -442,7 +442,7 @@ public class SettingsLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (config.getTheme() == null) {
|
if (config.getTheme() == null) {
|
||||||
if (this.theme != null) {
|
if (this.theme != null && (this.theme.equals("dark") || this.theme.equals("light"))) {
|
||||||
config.setTheme(this.theme);
|
config.setTheme(this.theme);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -459,6 +459,28 @@ public class SettingsLoader {
|
|||||||
config.setAutoSignIn(Boolean.parseBoolean(autoSignIn));
|
config.setAutoSignIn(Boolean.parseBoolean(autoSignIn));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initWithDefaults() {
|
||||||
|
Configuration defaultConfigValues = new Configuration(null, null, null);
|
||||||
|
this.login = null;
|
||||||
|
this.password = null;
|
||||||
|
this.proxy = null;
|
||||||
|
this.hostname = null;
|
||||||
|
this.computeMethod = null;
|
||||||
|
this.gpu = null;
|
||||||
|
this.renderbucketSize = null;
|
||||||
|
this.cacheDir = null;
|
||||||
|
this.autoSignIn = null;
|
||||||
|
this.useSysTray = null;
|
||||||
|
this.ui = null;
|
||||||
|
this.priority = defaultConfigValues.getPriority(); // must be the same default as Configuration
|
||||||
|
this.ram = null;
|
||||||
|
this.renderTime = null;
|
||||||
|
this.theme = null;
|
||||||
|
this.cores = String.valueOf(defaultConfigValues.getNbCores());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
return String.format(
|
return String.format(
|
||||||
"SettingsLoader [path=%s, login=%s, password=%s, computeMethod=%s, gpu=%s, renderbucket-size=%s, cacheDir=%s, theme=%s, priority=%d, autosign=%s, usetray=%s]",
|
"SettingsLoader [path=%s, login=%s, password=%s, computeMethod=%s, gpu=%s, renderbucket-size=%s, cacheDir=%s, theme=%s, priority=%d, autosign=%s, usetray=%s]",
|
||||||
|
|||||||
Reference in New Issue
Block a user