Add config system

This commit is contained in:
nelle 2024-02-16 02:49:05 -07:00
parent cdb4d0fdac
commit ae74e5def8

View file

@ -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;
}