aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt
diff options
context:
space:
mode:
authorxtrm <oss@xtrm.me>2023-02-04 18:18:04 +0100
committerxtrm <oss@xtrm.me>2023-02-04 18:18:04 +0100
commit99be374aa343029e670dd1c8abcc834004363fc5 (patch)
treedb7fb58825b917904378100b39b20d7baeda2a05 /src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt
parentbef30e98cf9f3697ac6fefbd82f4cb160edaad46 (diff)
downloadChatting-99be374aa343029e670dd1c8abcc834004363fc5.tar.gz
Chatting-99be374aa343029e670dd1c8abcc834004363fc5.tar.bz2
Chatting-99be374aa343029e670dd1c8abcc834004363fc5.zip
added mod icon, fixed potential crash, bumped gradle to 7.6, bumped to 1.4.2-beta5
Diffstat (limited to 'src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt')
-rw-r--r--src/main/kotlin/cc/woverflow/chatting/chat/ChatShortcuts.kt28
1 files changed, 16 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())
}
}