store properties on startup

pull/4/head
Zlatin Balevsky 2019-05-23 19:59:39 +01:00
parent ee8c39f032
commit 8ea6ecdea9
2 changed files with 24 additions and 10 deletions

View File

@ -48,11 +48,14 @@ class Core {
propsFile.withInputStream { propsFile.withInputStream {
props.load(it) props.load(it)
} }
} else props = new MuWireSettings(props)
} else {
log.info("creating default properties") log.info("creating default properties")
props = new MuWireSettings()
props = new MuWireSettings(props) propsFile.withOutputStream {
props.write(it)
}
}
log.info("initializing I2P socket manager") log.info("initializing I2P socket manager")
def i2pClient = new I2PClientFactory().createClient() def i2pClient = new I2PClientFactory().createClient()

View File

@ -4,7 +4,14 @@ import com.muwire.core.hostcache.CrawlerResponse
class MuWireSettings { class MuWireSettings {
MuWireSettings() {} final boolean isLeaf
boolean allowUntrusted
String nickname
CrawlerResponse crawlerResponse
MuWireSettings() {
this(new Properties())
}
MuWireSettings(Properties props) { MuWireSettings(Properties props) {
isLeaf = Boolean.valueOf(props.get("leaf","false")) isLeaf = Boolean.valueOf(props.get("leaf","false"))
@ -12,11 +19,15 @@ class MuWireSettings {
crawlerResponse = CrawlerResponse.valueOf(props.get("crawlerResponse","REGISTERED")) crawlerResponse = CrawlerResponse.valueOf(props.get("crawlerResponse","REGISTERED"))
nickname = props.getProperty("nickname","MuWireUser") nickname = props.getProperty("nickname","MuWireUser")
} }
final boolean isLeaf void write(OutputStream out) throws IOException {
boolean allowUntrusted Properties props = new Properties()
String nickname props.setProperty("leaf", isLeaf.toString())
CrawlerResponse crawlerResponse props.setProperty("allowUntrusted", allowUntrusted.toString())
props.setProperty("crawlerResponse", crawlerResponse.toString())
props.setProperty("nickname", nickname)
props.store(out, "")
}
boolean isLeaf() { boolean isLeaf() {
isLeaf isLeaf