diff --git a/src/main/kotlin/org/bm00/DataAccessor/Application.kt b/src/main/kotlin/org/bm00/DataAccessor/Application.kt new file mode 100644 index 0000000..a780eef --- /dev/null +++ b/src/main/kotlin/org/bm00/DataAccessor/Application.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/bm00/DataAccessor/Config.kt b/src/main/kotlin/org/bm00/DataAccessor/Config.kt index 7ca5e4d..00bea9f 100644 --- a/src/main/kotlin/org/bm00/DataAccessor/Config.kt +++ b/src/main/kotlin/org/bm00/DataAccessor/Config.kt @@ -33,7 +33,6 @@ class Config { FileInputStream(confFile).use { prop.load(it) prop.setProperty("configVersion", "1") - prop.setProperty("backendType", "SWING") } val out: OutputStream = FileOutputStream(confFile) 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, // so we can use them later, also make them public because I said so. - val configVersion = - 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`!") - } + val configVersion = (prop.getProperty("configVersion")).toInt() } \ No newline at end of file diff --git a/src/main/kotlin/org/bm00/DataAccessor/main.kt b/src/main/kotlin/org/bm00/DataAccessor/main.kt index 4a127a9..4e4bba4 100644 --- a/src/main/kotlin/org/bm00/DataAccessor/main.kt +++ b/src/main/kotlin/org/bm00/DataAccessor/main.kt @@ -1,18 +1,7 @@ package org.bm00.DataAccessor -import jexer.TApplication -import org.bm00.DataAccessor.windows.WelcomeWindow 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) fun main(args: Array) { Config()