diff options
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chatting')
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt | 28 | ||||
-rw-r--r-- | src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt | 1 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt b/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt index 6add813..ef1881d 100644 --- a/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt +++ b/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt @@ -31,20 +31,24 @@ object ChatShortcuts { } else { initialized = true } - if (!shortcutsFile.exists()) { - shortcutsFile.createNewFile() - if (oldShortcutsFile.exists()) { - shortcutsFile.writeText( - oldShortcutsFile.readText() - ) - } else { - JsonObject().toString() + if (shortcutsFile.exists()) { + try { + val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject + for (shortcut in jsonObj.entrySet()) { + shortcuts.add(shortcut.key to shortcut.value.asString) + } + return + } catch (_: Throwable) { + shortcutsFile.renameTo(File(shortcutsFile.parentFile, "chatshortcuts.json.bak")) } + } + shortcutsFile.createNewFile() + if (oldShortcutsFile.exists()) { + shortcutsFile.writeText( + oldShortcutsFile.readText() + ) } else { - val jsonObj = PARSER.parse(shortcutsFile.readText()).asJsonObject - for (shortcut in jsonObj.entrySet()) { - shortcuts.add(shortcut.key to shortcut.value.asString) - } + shortcutsFile.writeText(JsonObject().toString()) } } diff --git a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt index 6e6e0ff..f8e6b2a 100644 --- a/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt +++ b/src/main/kotlin/cc/woverflow/chatting/config/ChattingConfig.kt @@ -21,6 +21,7 @@ object ChattingConfig : Config( Mod( Chatting.NAME, ModType.UTIL_QOL, + "/chatting_dark.svg", VigilanceMigrator(File(Chatting.oldModDir, Chatting.ID + ".toml").toPath().toString()) ), "chatting.json" ) { |