Skip to content

Commit

Permalink
Merge pull request #224 from yermak/issues/200_settings
Browse files Browse the repository at this point in the history
fix #200
  • Loading branch information
yermak committed Jan 29, 2021
2 parents cdb60c6 + b58aa95 commit 784a8e2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/main/java/uk/yermak/audiobookconverter/AppProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public class AppProperties {
final static Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static final File APP_DIR = new File(System.getProperty("APP_HOME"));
public static final File PROP_FILE = new File(APP_DIR, Version.getVersionString() + ".properties");
private static final Properties applicationProps = new Properties();

private static Properties getAppProperties() {
//TODO:add default props here
Properties defaultProperties = new Properties();
Properties applicationProps = new Properties(defaultProperties);
static {
loadAppProperties();
}

private static synchronized Properties loadAppProperties() {
if (PROP_FILE.exists()) {
try (FileInputStream in = new FileInputStream(PROP_FILE)) {
applicationProps.load(in);
Expand All @@ -31,13 +33,11 @@ private static Properties getAppProperties() {
}

public static String getProperty(String key) {
Properties applicationProps = getAppProperties();
return applicationProps.getProperty(key);
}

public static Properties getProperties(String group) {
Properties properties = new Properties();
Properties applicationProps = getAppProperties();
Enumeration<Object> keys = applicationProps.keys();
while (keys.hasMoreElements()) {
String propName = (String) keys.nextElement();
Expand All @@ -49,8 +49,7 @@ public static Properties getProperties(String group) {
return properties;
}

public static void setProperty(String key, String value) {
Properties applicationProps = getAppProperties();
public static synchronized void setProperty(String key, String value) {
applicationProps.put(key, value);
File appDir = APP_DIR;
if (appDir.exists() || appDir.mkdir()) {
Expand Down

0 comments on commit 784a8e2

Please sign in to comment.