From 8ea6ecdea98a031d693f75727139b2a472128588 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Thu, 23 May 2019 19:59:39 +0100 Subject: [PATCH] store properties on startup --- .../main/groovy/com/muwire/core/Core.groovy | 11 +++++---- .../com/muwire/core/MuWireSettings.groovy | 23 ++++++++++++++----- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/src/main/groovy/com/muwire/core/Core.groovy b/core/src/main/groovy/com/muwire/core/Core.groovy index 68387b14..28881e3c 100644 --- a/core/src/main/groovy/com/muwire/core/Core.groovy +++ b/core/src/main/groovy/com/muwire/core/Core.groovy @@ -48,11 +48,14 @@ class Core { propsFile.withInputStream { props.load(it) } - } else + props = new MuWireSettings(props) + } else { log.info("creating default properties") - - props = new MuWireSettings(props) - + props = new MuWireSettings() + propsFile.withOutputStream { + props.write(it) + } + } log.info("initializing I2P socket manager") def i2pClient = new I2PClientFactory().createClient() diff --git a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy index bb917e6a..e60c3957 100644 --- a/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy +++ b/core/src/main/groovy/com/muwire/core/MuWireSettings.groovy @@ -4,7 +4,14 @@ import com.muwire.core.hostcache.CrawlerResponse class MuWireSettings { - MuWireSettings() {} + final boolean isLeaf + boolean allowUntrusted + String nickname + CrawlerResponse crawlerResponse + + MuWireSettings() { + this(new Properties()) + } MuWireSettings(Properties props) { isLeaf = Boolean.valueOf(props.get("leaf","false")) @@ -12,11 +19,15 @@ class MuWireSettings { crawlerResponse = CrawlerResponse.valueOf(props.get("crawlerResponse","REGISTERED")) nickname = props.getProperty("nickname","MuWireUser") } - - final boolean isLeaf - boolean allowUntrusted - String nickname - CrawlerResponse crawlerResponse + + void write(OutputStream out) throws IOException { + Properties props = new Properties() + props.setProperty("leaf", isLeaf.toString()) + props.setProperty("allowUntrusted", allowUntrusted.toString()) + props.setProperty("crawlerResponse", crawlerResponse.toString()) + props.setProperty("nickname", nickname) + props.store(out, "") + } boolean isLeaf() { isLeaf