]> uap-core.de Git - rssreader.git/commitdiff
load settings from config file
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Sep 2025 15:07:27 +0000 (17:07 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Tue, 9 Sep 2025 15:07:27 +0000 (17:07 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt

index 8cb366361da33c0daff5570bc8e93eefe8dee6d5..63f580b80f939b3c832de5222a0fb6335b3f7196 100644 (file)
@@ -5,20 +5,45 @@ import java.io.File
 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()