This commit is contained in:
nelle 2023-11-06 04:37:51 -07:00
parent 5ef0f2c9e3
commit d1e55aeac7
2 changed files with 8 additions and 4 deletions

View file

@ -42,6 +42,8 @@ dependencies {
implementation("com.akuleshov7:ktoml-core:0.5.0")
implementation("com.akuleshov7:ktoml-file:0.5.0")
implementation("dev.dirs:directories:26")
}
tasks {

View file

@ -1,5 +1,6 @@
package group.ouroboros.potrogue.data.config
import dev.dirs.ProjectDirectories
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
@ -12,8 +13,9 @@ import java.util.*
val prop = Properties()
class Config {
val runDir = File("./run")
val confFile = File("./run/potrogue.conf")
val confDir = ProjectDirectories.from("xyz", "limepot", "potrogue")
val runDir = File(confDir.configDir)
val confFile = File(confDir.configDir + "/potrogue.conf")
private val prop = Properties()
private var runDirExists = runDir.exists()
init {
@ -21,14 +23,14 @@ class Config {
//TODO: DataPacks and Advanced configuration system (see values.conf in jar)
//Files.createDirectories(Paths.get("./run/data"))
if(!runDirExists){
Files.createDirectories(Paths.get("./run"))
Files.createDirectories(Paths.get(confDir.configDir))
}
if(confFile.exists()) {
FileInputStream(confFile).use { prop.load(it) }
}
//Otherwise create the necessary directories
else{
Files.createFile(Path.of("./run/potrogue.conf"))
Files.createFile(Path.of(confDir.configDir + "/potrogue.conf"))
FileInputStream(confFile).use {
prop.load(it)
prop.setProperty("configVersion", "1")