annotate src/name/blackcap/imageprep/Settings.kt @ 2:a6f9b51d5e8d

Got jar building.
author David Barts <n5jrn@me.com>
date Fri, 17 Jul 2020 10:34:48 -0700
parents 0bded24f746e
children 5234e4500d45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
1 /*
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
2 * Our settings. Basically just some parsed properties.
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
3 */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
4 package name.blackcap.imageprep
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
5
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
6 import java.io.File
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
7
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
8 /* work around name shadowing */
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
9 private val _PROPS = PROPERTIES
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
10
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
11 object Settings {
2
a6f9b51d5e8d Got jar building.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
12 private val homeDir = System.getProperty("user.home")
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
13 val maxDimension = _PROPS.getProperty("maxDimension").toInt()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
14 val outputQuality = _PROPS.getProperty("outputQuality").toInt()
2
a6f9b51d5e8d Got jar building.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
15 val outputSuffix = _PROPS.getProperty("outputSuffix")
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
16 val outputTo = tilde(_PROPS.getProperty("outputTo"))
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
17 val outputToInputDir = strToBool(_PROPS.getProperty("outputToInputDir"))
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
18
2
a6f9b51d5e8d Got jar building.
David Barts <n5jrn@me.com>
parents: 1
diff changeset
19 private fun tilde(s: String?): String {
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
20 if (s.isNullOrEmpty())
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
21 return homeDir
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
22 if (s.startsWith("~/") || s.startsWith("~\\"))
1
0bded24f746e Compiles, still untested.
David Barts <n5jrn@me.com>
parents: 0
diff changeset
23 return File(homeDir, s.substring(2).trimStart(s[1])).toString()
0
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
24 else
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
25 return s
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
26 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
27
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
28 private fun strToBool(s: String): Boolean {
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
29 if (s.isNullOrEmpty())
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
30 return false
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
31 val c1 = s[0].toLowerCase()
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
32 return c1 == 't' || c1 == 'y'
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
33 }
e0efe7848130 Initial commit. Untested!
David Barts <davidb@stashtea.com>
parents:
diff changeset
34 }