diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt index 8a56ad4..7938206 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -3,6 +3,7 @@ package fr.username404.snowygui.config import com.typesafe.config.Config import com.typesafe.config.ConfigException import com.typesafe.config.ConfigFactory +import com.typesafe.config.ConfigRenderOptions import fr.username404.snowygui.Snowy import net.minecraft.client.Minecraft import java.io.File @@ -14,6 +15,7 @@ object Configuration { | displayInitMessage = true |} """.trimMargin() + private val baseConf = ConfigFactory.parseString(base) @JvmField val obtained: Config = run { lateinit var result: Config @@ -26,10 +28,29 @@ object Configuration { }; result = try { ConfigFactory.parseFile(file) } catch (e: ConfigException) { - Snowy.logs.warn("Could not parse the snowy configuration file, the default configuration will be used instead.") - ConfigFactory.parseString(base) + Snowy.logs.warn("Could not parse the snowy configuration file, the default configuration will be used instead."); baseConf } } - ConfigFactory.load(result).getConfig("Snowy") + ConfigFactory.load(result).getConfig("Snowy").resolveWith(baseConf) + } + init { + Runtime.getRuntime().addShutdownHook( + Thread { + file.writeText( + """ + Snowy { + ${ + obtained.root().render( + ConfigRenderOptions.defaults() + .setFormatted(true) + .setJson(false) + .setOriginComments(false) + ).trimEnd() + } + } + """.trimIndent() + ) + } + ) } }