Skip to content

Commit

Permalink
fix: исправлена работа настроек по-умолчанию
Browse files Browse the repository at this point in the history
    Раньше настройки по-умолчанию загружались *только* если отсутствовал
    файл с настройками пользователя. Это приводило к тому, что
    настройки, отсутствующие в файле пользователя не замещались
    значениями по-умолчанию.
    Теперь сначала загружаются настройки по-умолчанию, а затем подгружаются
    настройки пользователя из каталога запуска. Если какая-либо из
    настроек отсутствует в файле настроек пользователя, то используется
    значение по-умолчанию.
  • Loading branch information
xlam committed Nov 21, 2018
1 parent cfa758d commit 7ac470d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main/java/ru/cyberbiology/util/ProjectProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public static ProjectProperties getInstance() {
}

private ProjectProperties(String fileName) {
defaults = new Properties();
this.fileName = fileName;
this.load();
this.loadDefaults();
this.loadUser();
}

public void setFileDirectory(String name) {
Expand All @@ -35,7 +37,6 @@ public void setFileDirectory(String name) {
}

this.setProperty("FileDirectory", name);
this.save();
}

public String getFileDirectory() {
Expand All @@ -46,22 +47,22 @@ public int botSize() {
return Integer.parseInt(getProperty("botSize", "" + Const.DEFAULT_BOT_SIZE));
}

public void load() {
private void loadUser() {
try {
this.loadFromXML(new FileInputStream(this.fileName));
} catch (IOException e) {
loadDefaultProperties();
System.err.println("WARNING: user settings can not be loaded, using defaults!");
}
}

private void loadDefaultProperties() {
private void loadDefaults() {
InputStream propertiesStream = getClass().getResourceAsStream("/" + PROPERTIES_FILE);
if (null == propertiesStream) {
System.err.println("ERROR: default.properties file not found!");
System.err.println("ERROR: default settings can not be loaded!");
System.exit(1);
}
try {
loadFromXML(propertiesStream);
defaults.loadFromXML(propertiesStream);
} catch (IOException ex) {
ex.printStackTrace();
}
Expand All @@ -83,7 +84,6 @@ public Object setProperty(String key, String value) {
}

public boolean getBoolean(String property) {
System.out.println(getProperty(property));
return "true".equals(getProperty(property, "false"));
}
}

0 comments on commit 7ac470d

Please sign in to comment.