aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui/config/storage/LegacyImporter.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-09-14 16:37:57 +0200
committerLinnea Gräf <nea@nea.moe>2025-09-14 16:37:57 +0200
commit9abe9f46f04f188037687adb2740b32220ad21b2 (patch)
tree48dbd9cdf48c59853310c0b2e9bc59801522400e /src/main/kotlin/gui/config/storage/LegacyImporter.kt
parent2851c1d6834fafdaeb009dce2a3485df1388907e (diff)
downloadFirmament-9abe9f46f04f188037687adb2740b32220ad21b2.tar.gz
Firmament-9abe9f46f04f188037687adb2740b32220ad21b2.tar.bz2
Firmament-9abe9f46f04f188037687adb2740b32220ad21b2.zip
snapshot
Diffstat (limited to 'src/main/kotlin/gui/config/storage/LegacyImporter.kt')
-rw-r--r--src/main/kotlin/gui/config/storage/LegacyImporter.kt63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/main/kotlin/gui/config/storage/LegacyImporter.kt b/src/main/kotlin/gui/config/storage/LegacyImporter.kt
new file mode 100644
index 0000000..8915c17
--- /dev/null
+++ b/src/main/kotlin/gui/config/storage/LegacyImporter.kt
@@ -0,0 +1,63 @@
+package moe.nea.firmament.gui.config.storage
+
+import java.nio.file.Path
+import javax.xml.namespace.QName
+import kotlin.io.path.Path
+import kotlin.io.path.copyTo
+import kotlin.io.path.copyToRecursively
+import kotlin.io.path.createDirectories
+import kotlin.io.path.createParentDirectories
+import kotlin.io.path.exists
+import kotlin.io.path.forEachDirectoryEntry
+import kotlin.io.path.listDirectoryEntries
+import kotlin.io.path.moveTo
+import kotlin.io.path.name
+import kotlin.io.path.nameWithoutExtension
+import kotlin.io.path.writeText
+import moe.nea.firmament.gui.config.storage.FirmamentConfigLoader.configFolder
+import moe.nea.firmament.gui.config.storage.FirmamentConfigLoader.configVersionFile
+import moe.nea.firmament.gui.config.storage.FirmamentConfigLoader.storageFolder
+
+object LegacyImporter {
+ val legacyConfigVersion = 995
+ val backupPath = configFolder.resolveSibling("firmament-legacy-config-${System.currentTimeMillis()}")
+
+ fun copyIf(from: Path, to: Path) {
+ if (from.exists()) {
+ to.createParentDirectories()
+ from.copyTo(to)
+ }
+ }
+
+ fun importFromLegacy() {
+ configFolder.moveTo(backupPath)
+ configFolder.createDirectories()
+
+ copyIf(
+ backupPath.resolve("inventory-buttons.json"),
+ storageFolder.resolve("inventory-buttons.json")
+ )
+
+ backupPath.listDirectoryEntries("*.json")
+ .forEach { path ->
+ val name = path.name
+ if (name == "inventory-buttons.json")
+ return@forEach
+ path.copyTo(configFolder.resolve(name))
+ }
+
+ backupPath.resolve("profiles")
+ .forEachDirectoryEntry { category ->
+ category.forEachDirectoryEntry { profile ->
+ copyIf(
+ profile,
+ FirmamentConfigLoader.profilePath
+ .resolve(profile.nameWithoutExtension)
+ .resolve(category.name + ".json")
+ )
+ }
+ }
+
+ configVersionFile.writeText(legacyConfigVersion.toString())
+ }
+}