Save the Snowy configuration at exit
This commit is contained in:
parent
0c107be94b
commit
994a377a26
|
@ -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()
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue