From d8073db00e9b16071c8631613ac78e150ee49646 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Tue, 9 Sep 2025 17:07:27 +0200 Subject: [PATCH] load settings from config file --- .../kotlin/de/unixwork/rssreader/Settings.kt | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt index 8cb3663..63f580b 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Settings.kt @@ -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() -- 2.47.3