comparison src/name/blackcap/imageprep/Settings.kt @ 0:e0efe7848130

Initial commit. Untested!
author David Barts <davidb@stashtea.com>
date Thu, 16 Jul 2020 19:57:23 -0700
parents
children 0bded24f746e
comparison
equal deleted inserted replaced
-1:000000000000 0:e0efe7848130
1 /*
2 * Our settings. Basically just some parsed properties.
3 */
4 package name.blackcap.imageprep
5
6 /* work around name shadowing */
7 private val _PROPS = PROPERTIES
8
9 object Settings {
10 private var homeDir = System.getProperty("user.home")
11 val maxDimension = _PROPS.getProperty("maxDimension").toInt()
12 val outputQuality = _PROPS.getProperty("outputQuality").toInt()
13 val outputSuffix = tilde(_PROPS.getProperty("outputSuffix"))
14 val outputTo = tilde(_PROPS.getProperty("outputTo"))
15 val outputToInputDir = strToBool(_PROPS.getProperty("outputToInputDir"))
16
17 private fun tilde(s: String): String {
18 if (s.isNullOrEmpty())
19 return homeDir
20 if (s.startsWith("~/") || s.startsWith("~\\"))
21 return File(homeDir, s.substring(1).trimStart('/', '\\')).toString()
22 else
23 return s
24 }
25
26 private fun strToBool(s: String): Boolean {
27 if (s.isNullOrEmpty())
28 return false
29 val c1 = s[0].toLowerCase()
30 return c1 == 't' || c1 == 'y'
31 }
32 }