aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-04-22 15:07:11 +0200
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2024-04-22 15:07:11 +0200
commit3dc480a6ce9e01e1cfe602bb29860b5ac2f1b7bd (patch)
tree0e29630018ec345f5bf3b7758a686a33da0558d1 /src
parent518510a89b60999422aefea1c6df38c2ef2f3269 (diff)
downloadskyhanni-3dc480a6ce9e01e1cfe602bb29860b5ac2f1b7bd.tar.gz
skyhanni-3dc480a6ce9e01e1cfe602bb29860b5ac2f1b7bd.tar.bz2
skyhanni-3dc480a6ce9e01e1cfe602bb29860b5ac2f1b7bd.zip
try 5 times to save config, if it fails once
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
index 93f40cae4..f198270b2 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt
@@ -10,6 +10,9 @@ import at.hannibal2.skyhanni.data.jsonobjects.local.VisualWordsJson
import at.hannibal2.skyhanni.events.LorenzEvent
import at.hannibal2.skyhanni.features.fishing.trophy.TrophyRarity
import at.hannibal2.skyhanni.features.misc.update.UpdateManager
+import at.hannibal2.skyhanni.test.command.ErrorManager
+import at.hannibal2.skyhanni.utils.ChatUtils
+import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.FeatureTogglesByDefaultAdapter
import at.hannibal2.skyhanni.utils.IdentityCharacteristics
import at.hannibal2.skyhanni.utils.KotlinTypeAdapterFactory
@@ -327,15 +330,34 @@ class ConfigManager {
writer.write(gson.toJson(data))
}
// Perform move — which is atomic, unlike writing — after writing is done.
+ move(unit, file, reason)
+ } catch (e: IOException) {
+ logger.log("Could not save $fileName file to $file")
+ e.printStackTrace()
+ }
+ }
+
+ private fun move(unit: File, file: File, reason: String, loop: Int = 0) {
+ try {
Files.move(
unit.toPath(),
file.toPath(),
StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.ATOMIC_MOVE
)
- } catch (e: IOException) {
- logger.log("Could not save $fileName file to $file")
- e.printStackTrace()
+ } catch (e: AccessDeniedException) {
+ if (loop == 5) {
+ ErrorManager.logErrorWithData(
+ e,
+ "could not save config.",
+ "config save reason" to reason,
+ )
+ return
+ }
+ ChatUtils.debug("config save AccessDeniedException! (loop $loop)")
+ DelayedRun.runNextTick {
+ move(unit, file, reason, loop + 1)
+ }
}
}