45 lines
1.4 KiB
Kotlin
45 lines
1.4 KiB
Kotlin
package nl.astraeus.vst.base
|
|
|
|
import java.io.File
|
|
import java.io.FileInputStream
|
|
import java.util.*
|
|
|
|
object Settings {
|
|
var port = 9004
|
|
var connectionTimeout = 30000
|
|
var jdbcStatsPort = 6001
|
|
|
|
var jdbcDriver = "nl.astraeus.jdbc.Driver"
|
|
val jdbcConnectionUrl
|
|
get() = "jdbc:stat:webServerPort=$jdbcStatsPort:jdbc:sqlite:data/vst.db"
|
|
var jdbcUser = "sa"
|
|
var jdbcPassword = ""
|
|
|
|
fun getPropertiesFromFile(filename: String): Properties? {
|
|
val propertiesFile = File(filename)
|
|
return if (propertiesFile.exists()) {
|
|
val properties = Properties()
|
|
FileInputStream(propertiesFile).use {
|
|
properties.load(it)
|
|
}
|
|
properties
|
|
} else {
|
|
null
|
|
}
|
|
}
|
|
|
|
fun readProperties(args: Array<String>) {
|
|
val filename = if (args.isNotEmpty()) args[0] else "srp.properties"
|
|
val properties =
|
|
getPropertiesFromFile(filename) ?: return // return if properties couldn't be loaded
|
|
|
|
port = properties.getProperty("port", port.toString()).toInt()
|
|
jdbcStatsPort = properties.getProperty("jdbcStatsPort", jdbcStatsPort.toString()).toInt()
|
|
connectionTimeout =
|
|
properties.getProperty("connectionTimeout", connectionTimeout.toString()).toInt()
|
|
jdbcDriver = properties.getProperty("jdbcDriver", jdbcDriver)
|
|
jdbcUser = properties.getProperty("jdbcUser", jdbcUser)
|
|
jdbcPassword = properties.getProperty("jdbcPassword", jdbcPassword)
|
|
}
|
|
}
|