From ae74e5def854ccc037aff6e58357e7f2d9d50c2f Mon Sep 17 00:00:00 2001 From: limepotato Date: Fri, 16 Feb 2024 02:49:05 -0700 Subject: [PATCH] Add config system --- .../kotlin/org/bm00/data-accessor/Config.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/kotlin/org/bm00/data-accessor/Config.kt diff --git a/src/main/kotlin/org/bm00/data-accessor/Config.kt b/src/main/kotlin/org/bm00/data-accessor/Config.kt new file mode 100644 index 0000000..5670e85 --- /dev/null +++ b/src/main/kotlin/org/bm00/data-accessor/Config.kt @@ -0,0 +1,51 @@ +package org.bm00.`data-accessor` + +import dev.dirs.ProjectDirectories +import java.io.File +import java.io.FileInputStream +import java.io.FileOutputStream +import java.io.OutputStream +import java.nio.file.Files +import java.nio.file.Path +import java.nio.file.Paths +import java.util.* + +val prop = Properties() + +class Config { + val confDir = ProjectDirectories.from("org", "bm00", "osda") + val runDir = File(confDir.configDir) + val confFile = File(confDir.configDir + "/osda.cfg") + private val prop = Properties() + private var runDirExists = runDir.exists() + init { + //Check if the directories and files exist, if not, create them. Also check if config version is incorrect. + if(!runDirExists){ + Files.createDirectories(Paths.get(confDir.configDir)) + } + if(confFile.exists()) { + FileInputStream(confFile).use { prop.load(it) } + } + //Otherwise create the necessary directories + else{ + Files.createFile(Paths.get(confDir.configDir + "/osda.cfg")) + FileInputStream(confFile).use { + prop.load(it) + prop.setProperty("configVersion", "1") + prop.setProperty("windowWidth", "46") + prop.setProperty("windowHeight", "18") + } + val out: OutputStream = FileOutputStream(confFile) + prop.store(out, "Org Secure Data Accessor - OSDA Config file") + } + } + //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 windowWidth: Int = (prop.getProperty("windowWidth")).toInt() + + val windowHeight: Int = (prop.getProperty("windowHeight")).toInt() + + val configVersion: Int = (prop.getProperty("configVersion")).toInt() + + var progressTimer = 0; +} \ No newline at end of file