import java.util.Properties
class Settings {
- val properties = Properties()
-
- val dateFormat = "yyyy-MM-dd HH:mm:ss"
- val autoRefreshStartDelay = 10
- val defaultRefreshInterval = 3600
- val minRefreshWaitTime = 60
+ var dateFormat = "yyyy-MM-dd HH:mm:ss"
+ var autoRefreshStartDelay = 10
+ var defaultRefreshInterval = 3600
+ var minRefreshWaitTime = 60
fun load() {
val filePath = Toolkit.getConfigFilePath("rssreader.properties")
val file = File(filePath)
if(file.exists()) {
+ val properties = Properties()
file.inputStream().use {
properties.load(it)
}
+
+ dateFormat = properties.getProperty("DateFormat", dateFormat)
+ val autoRefreshStartDelay = properties.getProperty("AutoRefreshStartDelay")
+ autoRefreshStartDelay?.let {
+ try {
+ this.autoRefreshStartDelay = it.toInt()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ }
+ val defaultRefreshInterval = properties.getProperty("DefaultRefreshInterval")
+ defaultRefreshInterval?.let {
+ try {
+ this.defaultRefreshInterval = it.toInt()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ }
+ val minRefreshWaitTime = properties.getProperty("MinRefreshWaitTime")
+ minRefreshWaitTime?.let {
+ try {
+ this.minRefreshWaitTime = it.toInt()
+ } catch (e: NumberFormatException) {
+ e.printStackTrace()
+ }
+ }
} else {
println("create new file: $filePath")
file.createNewFile()