From 5b7b2203c4ddeb1c9d40aff578cfab61df87d293 Mon Sep 17 00:00:00 2001 From: Walker Selby Date: Tue, 7 Nov 2023 20:23:08 +0000 Subject: Internal Change: Cleanup ConfigUpdaterMigrator (#672) Refactor configVersion to const CONFIG_VERSION #672 --- .../at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt | 14 +++++++------- src/main/java/at/hannibal2/skyhanni/config/Features.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/main/java/at/hannibal2/skyhanni/config') diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 8bb3b7268..19b77abf3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonPrimitive object ConfigUpdaterMigrator { val logger = LorenzLogger("ConfigMigration") - val configVersion = 8 + const val CONFIG_VERSION = 8 fun JsonElement.at(chain: List, init: Boolean): JsonElement? { if (chain.isEmpty()) return this if (this !is JsonObject) return null @@ -39,8 +39,8 @@ object ConfigUpdaterMigrator { logger.log("Skipping move from $oldPath to $newPath ($since <= $oldVersion)") return } - if (since > configVersion) { - error("Illegally new version $since > $configVersion") + if (since > CONFIG_VERSION) { + error("Illegally new version $since > $CONFIG_VERSION") } if (since > oldVersion + 1) { logger.log("Skipping move from $oldPath to $newPath (will be done in another pass)") @@ -80,7 +80,7 @@ object ConfigUpdaterMigrator { } } - fun merge(a: JsonObject, b: JsonObject): Int { + private fun merge(a: JsonObject, b: JsonObject): Int { var c = 0 b.entrySet().forEach { val e = a.get(it.key) @@ -100,11 +100,11 @@ object ConfigUpdaterMigrator { fun fixConfig(config: JsonObject): JsonObject { val lV = (config.get("lastVersion") as? JsonPrimitive)?.asIntOrNull ?: -1 - if (lV > configVersion) { + if (lV > CONFIG_VERSION) { error("Cannot downgrade config") } - if (lV == configVersion) return config - return (lV until configVersion).fold(config) { acc, i -> + if (lV == CONFIG_VERSION) return config + return (lV until CONFIG_VERSION).fold(config) { acc, i -> logger.log("Starting config transformation from $i to ${i + 1}") val storage = acc.get("storage")?.asJsonObject val dynamicPrefix: Map> = mapOf( diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java index ad7e5ab44..33d766fdf 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/Features.java +++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java @@ -153,6 +153,6 @@ public class Features extends Config { public Storage storage = new Storage(); @Expose - public int lastVersion = ConfigUpdaterMigrator.INSTANCE.getConfigVersion(); + public int lastVersion = ConfigUpdaterMigrator.CONFIG_VERSION; } -- cgit