aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-22 13:08:00 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-04-22 13:08:00 +0200
commit707007fa1a00adebec09af4c1efbf8dc55bb852e (patch)
treea414dac51580e62a920b7e96406f792deb898529
parente4b637f6d2814e8876a1fd6842404d0a02d14df6 (diff)
downloadskyhanni-707007fa1a00adebec09af4c1efbf8dc55bb852e.tar.gz
skyhanni-707007fa1a00adebec09af4c1efbf8dc55bb852e.tar.bz2
skyhanni-707007fa1a00adebec09af4c1efbf8dc55bb852e.zip
throwing an error if config file is null
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index f8152f8b8..9fa562986 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -28,17 +28,13 @@ class ConfigManager {
lateinit var processor: MoulConfigProcessor<Features>
fun firstLoad() {
+ configDirectory.mkdir()
+
+ configFile = File(configDirectory, "config.json")
fixedRateTimer(name = "config-auto-save", period = 60_000L) {
saveConfig()
}
- try {
- configDirectory.mkdir()
- } catch (ignored: Exception) {
- }
-
- configFile = File(configDirectory, "config.json")
-
logger.info("Trying to load config from $configFile")
if (configFile!!.exists()) {
@@ -106,15 +102,16 @@ class ConfigManager {
}
fun saveConfig() {
+ val file = configFile ?: throw Error("Can not save config, configFile is null!")
try {
logger.info("Saving config file")
- configFile!!.parentFile.mkdirs()
- configFile!!.createNewFile()
- BufferedWriter(OutputStreamWriter(FileOutputStream(configFile!!), StandardCharsets.UTF_8)).use { writer ->
+ file.parentFile.mkdirs()
+ file.createNewFile()
+ BufferedWriter(OutputStreamWriter(FileOutputStream(file), StandardCharsets.UTF_8)).use { writer ->
writer.write(gson.toJson(SkyHanniMod.feature))
}
} catch (e: IOException) {
- logger.error("Could not save config file to $configFile", e)
+ logger.error("Could not save config file to $file", e)
}
}
} \ No newline at end of file