From: Olaf Wintermann Date: Tue, 9 Sep 2025 15:07:27 +0000 (+0200) Subject: load settings from config file X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=d8073db00e9b16071c8631613ac78e150ee49646;p=rssreader.git load settings from config file --- 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()