aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-05-16 01:23:43 +0200
committernea <nea@nea.moe>2023-05-16 01:23:43 +0200
commitead6762eb1c005914b05f9d3c29f334989c67513 (patch)
treecd1409756be2bc4a93195c31d432fef053afe002 /src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt
parent96c546cc73880a7c502c17aadda6ca84c847692d (diff)
downloadFirmament-ead6762eb1c005914b05f9d3c29f334989c67513.tar.gz
Firmament-ead6762eb1c005914b05f9d3c29f334989c67513.tar.bz2
Firmament-ead6762eb1c005914b05f9d3c29f334989c67513.zip
Replace references to NEU with Firmament
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt
deleted file mode 100644
index 6c9d8e8..0000000
--- a/src/main/kotlin/moe/nea/notenoughupdates/util/data/DataHolder.kt
+++ /dev/null
@@ -1,60 +0,0 @@
-package moe.nea.notenoughupdates.util.data
-
-import java.nio.file.Path
-import kotlinx.serialization.KSerializer
-import kotlin.io.path.exists
-import kotlin.io.path.readText
-import kotlin.io.path.writeText
-import moe.nea.notenoughupdates.NotEnoughUpdates
-
-abstract class DataHolder<T>(
- val serializer: KSerializer<T>,
- val name: String,
- val default: () -> T
-) : IDataHolder<T> {
-
-
- final override var data: T
- private set
-
- init {
- data = readValueOrDefault()
- IDataHolder.putDataHolder(this::class, this)
- }
-
- private val file: Path get() = NotEnoughUpdates.CONFIG_DIR.resolve("$name.json")
-
- protected fun readValueOrDefault(): T {
- if (file.exists())
- try {
- return NotEnoughUpdates.json.decodeFromString(
- serializer,
- file.readText()
- )
- } catch (e: Exception) {/* Expecting IOException and SerializationException, but Kotlin doesn't allow multi catches*/
- IDataHolder.badLoads.add(name)
- NotEnoughUpdates.logger.error(
- "Exception during loading of config file $name. This will reset this config.",
- e
- )
- }
- return default()
- }
-
- private fun writeValue(t: T) {
- file.writeText(NotEnoughUpdates.json.encodeToString(serializer, t))
- }
-
- override fun save() {
- writeValue(data)
- }
-
- override fun load() {
- data = readValueOrDefault()
- }
-
- override fun markDirty() {
- IDataHolder.markDirty(this::class)
- }
-
-}