From d1e55aeac7e885c5cfafa80437cb641405ab1457 Mon Sep 17 00:00:00 2001 From: LimePotato Date: Mon, 6 Nov 2023 04:37:51 -0700 Subject: [PATCH] XDG! --- build.gradle.kts | 2 ++ .../group/ouroboros/potrogue/data/config/Config.kt | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1d5e725..a05c3e0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { diff --git a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt index 09782ed..56f80ab 100644 --- a/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt +++ b/src/main/kotlin/group/ouroboros/potrogue/data/config/Config.kt @@ -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")