diff options
author | Walker Selby <git@walkerselby.com> | 2023-11-17 22:51:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 23:51:39 +0100 |
commit | 0dbe01932333c89ed1e6ae19f0cb950e09315a63 (patch) | |
tree | 5eed7e6664676d426a590d429a1e7e2e1cc86f02 /src/main/java/at/hannibal2 | |
parent | 4f116e2c8b5e5f28054a73e2e89dbb6746f4f597 (diff) | |
download | skyhanni-0dbe01932333c89ed1e6ae19f0cb950e09315a63.tar.gz skyhanni-0dbe01932333c89ed1e6ae19f0cb950e09315a63.tar.bz2 skyhanni-0dbe01932333c89ed1e6ae19f0cb950e09315a63.zip |
Internal Change: ConfigMigrator Variable Names (#714)
Improved readability #714
Diffstat (limited to 'src/main/java/at/hannibal2')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt | 2 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt | 42 |
2 files changed, 22 insertions, 22 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt index 3bb3555c2..ddd51b18f 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -131,7 +131,7 @@ class ConfigManager { if (jsonHolder.isNotEmpty()) { logger.log("Loading config despite config being already loaded?") } - configDirectory.mkdir() + configDirectory.mkdirs() for (fileType in ConfigFileType.entries) { diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt index 6227b0ea9..0db542e12 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigUpdaterMigrator.kt @@ -69,44 +69,44 @@ object ConfigUpdaterMigrator { logger.log("Skipping move from $oldPath to $newPath ($oldPath not present)") return } - val x = new.at(np.dropLast(1), true) - if (x !is JsonObject) { + val newParentElement = new.at(np.dropLast(1), true) + if (newParentElement !is JsonObject) { logger.log("Catastrophic: element at path $old could not be relocated to $new, since another element already inhabits that path") return } movesPerformed++ - x.add(np.last(), transform(oldElem)) + newParentElement.add(np.last(), transform(oldElem)) logger.log("Moved element from $oldPath to $newPath") } } - private fun merge(a: JsonObject, b: JsonObject): Int { - var c = 0 - b.entrySet().forEach { - val e = a.get(it.key) - val n = it.value - if (e is JsonObject && n is JsonObject) { - c += merge(e, n) + private fun merge(originalObject: JsonObject, overrideObject: JsonObject): Int { + var count = 0 + overrideObject.entrySet().forEach { + val element = originalObject.get(it.key) + val newElement = it.value + if (element is JsonObject && newElement is JsonObject) { + count += merge(element, newElement) } else { - if (e != null) { - logger.log("Encountered destructive merge. Erasing $e in favour of $n.") - c++ + if (element != null) { + logger.log("Encountered destructive merge. Erasing $element in favour of $newElement.") + count++ } - a.add(it.key, n) + originalObject.add(it.key, newElement) } } - return c + return count } fun fixConfig(config: JsonObject): JsonObject { - val lV = (config.get("lastVersion") as? JsonPrimitive)?.asIntOrNull ?: -1 - if (lV > CONFIG_VERSION) { + val lastVersion = (config.get("lastVersion") as? JsonPrimitive)?.asIntOrNull ?: -1 + if (lastVersion > CONFIG_VERSION) { error("Cannot downgrade config") } - if (lV == CONFIG_VERSION) return config - return (lV until CONFIG_VERSION).fold(config) { acc, i -> + if (lastVersion == CONFIG_VERSION) return config + return (lastVersion until CONFIG_VERSION).fold(config) { accumulator, i -> logger.log("Starting config transformation from $i to ${i + 1}") - val storage = acc.get("storage")?.asJsonObject + val storage = accumulator.get("storage")?.asJsonObject val dynamicPrefix: Map<String, List<String>> = mapOf( "#profile" to (storage?.get("players")?.asJsonObject?.entrySet() @@ -120,7 +120,7 @@ object ConfigUpdaterMigrator { (storage?.get("players")?.asJsonObject?.entrySet()?.map { "storage.players.${it.key}" } ?: listOf()), ) - val migration = ConfigFixEvent(acc, JsonObject().also { + val migration = ConfigFixEvent(accumulator, JsonObject().also { it.add("lastVersion", JsonPrimitive(i + 1)) }, i, 0, dynamicPrefix).also { it.postAndCatch() } logger.log("Transformations scheduled: ${migration.new}") |