Check for OS and refactor Application
This commit is contained in:
parent
5865ae7a13
commit
b0ea0506ac
3 changed files with 48 additions and 35 deletions
47
src/main/kotlin/org/bm00/DataAccessor/Application.kt
Normal file
47
src/main/kotlin/org/bm00/DataAccessor/Application.kt
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
package org.bm00.DataAccessor
|
||||||
|
|
||||||
|
import jexer.TApplication
|
||||||
|
import org.bm00.DataAccessor.windows.WelcomeWindow
|
||||||
|
|
||||||
|
enum class OS {
|
||||||
|
WINDOWS, LINUX, MAC, SOLARIS
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getOS(): OS? {
|
||||||
|
val os = System.getProperty("os.name").toLowerCase()
|
||||||
|
return when {
|
||||||
|
os.contains("win") -> {
|
||||||
|
OS.WINDOWS
|
||||||
|
}
|
||||||
|
os.contains("nix") || os.contains("nux") || os.contains("aix") -> {
|
||||||
|
OS.LINUX
|
||||||
|
}
|
||||||
|
os.contains("mac") -> {
|
||||||
|
OS.MAC
|
||||||
|
}
|
||||||
|
os.contains("sunos") -> {
|
||||||
|
OS.SOLARIS
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Set Jexer backend type
|
||||||
|
// Possible answers: SWING, XTERM, ECMA48
|
||||||
|
val backendType =
|
||||||
|
when (getOS())
|
||||||
|
{
|
||||||
|
OS.WINDOWS -> TApplication.BackendType.SWING
|
||||||
|
OS.LINUX -> TApplication.BackendType.SWING
|
||||||
|
OS.MAC -> TApplication.BackendType.SWING
|
||||||
|
OS.SOLARIS -> TApplication.BackendType.SWING
|
||||||
|
else -> throw Exception("Improper Backend set! Please use `SWING, XTERM, ECMA48`!")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create Jexer Application
|
||||||
|
class Application : TApplication(backendType, 80, 40, 18) {
|
||||||
|
init {
|
||||||
|
WelcomeWindow(this)
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,7 +33,6 @@ class Config {
|
||||||
FileInputStream(confFile).use {
|
FileInputStream(confFile).use {
|
||||||
prop.load(it)
|
prop.load(it)
|
||||||
prop.setProperty("configVersion", "1")
|
prop.setProperty("configVersion", "1")
|
||||||
prop.setProperty("backendType", "SWING")
|
|
||||||
}
|
}
|
||||||
val out: OutputStream = FileOutputStream(confFile)
|
val out: OutputStream = FileOutputStream(confFile)
|
||||||
prop.store(out, "Org Secure Data Accessor - OSDA Config file")
|
prop.store(out, "Org Secure Data Accessor - OSDA Config file")
|
||||||
|
@ -41,27 +40,5 @@ class Config {
|
||||||
}
|
}
|
||||||
//Convert values from the config file to in-code variables,
|
//Convert values from the config file to in-code variables,
|
||||||
// so we can use them later, also make them public because I said so.
|
// so we can use them later, also make them public because I said so.
|
||||||
val configVersion =
|
val configVersion = (prop.getProperty("configVersion")).toInt()
|
||||||
if ((prop.getProperty("configVersion")).toInt() == 1) {
|
|
||||||
println("Correct config version set!")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw Exception("The config version is not correct! Correct version is: " + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Later instead of being user configurable, change this based on the environemtn launched, and allow CMDLine args to change on runtime
|
|
||||||
// Possible answers: SWING, XTERM, ECMA48
|
|
||||||
val backendType =
|
|
||||||
if (prop.getProperty("backendType") == "SWING") {
|
|
||||||
TApplication.BackendType.SWING
|
|
||||||
}
|
|
||||||
else if (prop.getProperty("backendType") == "XTERM") {
|
|
||||||
TApplication.BackendType.XTERM
|
|
||||||
}
|
|
||||||
else if (prop.getProperty("backendType") == "ECMA48") {
|
|
||||||
TApplication.BackendType.ECMA48
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw Exception("Improper Backend set! Please use `SWING, XTERM, ECMA48`!")
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,18 +1,7 @@
|
||||||
package org.bm00.DataAccessor
|
package org.bm00.DataAccessor
|
||||||
|
|
||||||
import jexer.TApplication
|
|
||||||
import org.bm00.DataAccessor.windows.WelcomeWindow
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
val backendType = Config().backendType
|
|
||||||
|
|
||||||
class Application : TApplication(backendType, 80, 40, 18) {
|
|
||||||
init {
|
|
||||||
WelcomeWindow(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This creates a Jexer application (and calls the "backend type" which is how its rendered)
|
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
Config()
|
Config()
|
||||||
|
|
Loading…
Reference in a new issue