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 {
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()

View File

@ -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"))
@ -13,10 +20,14 @@ class MuWireSettings {
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