view 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
line wrap: on
line source

/*
 * Our settings. Basically just some parsed properties.
 */
package name.blackcap.imageprep

/* work around name shadowing */
private val _PROPS = PROPERTIES

object Settings {
    private var homeDir = System.getProperty("user.home")
    val maxDimension = _PROPS.getProperty("maxDimension").toInt()
    val outputQuality = _PROPS.getProperty("outputQuality").toInt()
    val outputSuffix = tilde(_PROPS.getProperty("outputSuffix"))
    val outputTo = tilde(_PROPS.getProperty("outputTo"))
    val outputToInputDir = strToBool(_PROPS.getProperty("outputToInputDir"))

    private fun tilde(s: String): String {
        if (s.isNullOrEmpty())
            return homeDir
        if (s.startsWith("~/") || s.startsWith("~\\"))
            return File(homeDir, s.substring(1).trimStart('/', '\\')).toString()
        else
            return s
    }

    private fun strToBool(s: String): Boolean {
        if (s.isNullOrEmpty())
            return false
        val c1 = s[0].toLowerCase()
        return c1 == 't' || c1 == 'y'
    }
}