aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/config
diff options
context:
space:
mode:
authorWalker Selby <git@walkerselby.com>2023-11-07 20:23:08 +0000
committerGitHub <noreply@github.com>2023-11-07 21:23:08 +0100
commit5b7b2203c4ddeb1c9d40aff578cfab61df87d293 (patch)
tree6ed4c9fdec79acaa4f44f52a409c42632da4de17 /src/main/java/at/hannibal2/skyhanni/config
parentae84c3c74b346057bd6de389fa27094bec6ca9c0 (diff)
downloadskyhanni-5b7b2203c4ddeb1c9d40aff578cfab61df87d293.tar.gz
skyhanni-5b7b2203c4ddeb1c9d40aff578cfab61df87d293.tar.bz2
skyhanni-5b7b2203c4ddeb1c9d40aff578cfab61df87d293.zip
Internal Change: Cleanup ConfigUpdaterMigrator (#672)
Refactor configVersion to const CONFIG_VERSION #672
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/config')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt14
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Features.java2
2 files changed, 8 insertions, 8 deletions
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<String>, 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<String, List<String>> = 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;
}