From 484117aaf5bc14dd93123f8825bd7920e4eae465 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Tue, 18 Jun 2024 19:20:39 +0200 Subject: [PATCH] improve config backups --- .../client/feature/modules/client/Client.java | 18 ++++++++++++------ .../client/feature/modules/render/HUD.java | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java index 4281a02..f566797 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java @@ -7,10 +7,7 @@ import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.ClientCategory; import de.com.baseband.client.gui.GuiTheme; import de.com.baseband.client.registry.Configuration; -import de.com.baseband.client.registry.annotation.Config; -import de.com.baseband.client.registry.annotation.Description; -import de.com.baseband.client.registry.annotation.KeyBound; -import de.com.baseband.client.registry.annotation.Trigger; +import de.com.baseband.client.registry.annotation.*; import de.com.baseband.client.util.interact.Chat; import de.com.baseband.client.util.interact.RotationManager; import de.com.baseband.client.util.interact.ServerDataManager; @@ -60,15 +57,23 @@ public class Client extends Feature { @Config("Theme") public GuiTheme.Theme theme = GuiTheme.Theme.TTC; + private static final String C_CONFIG = "Config"; + + @Section(C_CONFIG) @Trigger("Save config") public void saveConfig() { Configuration.save(); BaseBand.notify("Config saved to disk"); } + @Section(C_CONFIG) + @Config("Backup file") + public String backupFile = "baseband.db.bak"; + + @Section(C_CONFIG) @Trigger("Save backup") public void saveBackup() { - try(FileOutputStream stream = new FileOutputStream("baseband.db.bak")) { + try(FileOutputStream stream = new FileOutputStream(backupFile)) { stream.write(JSON.writeReadable(Configuration.asTCN()).getBytes()); BaseBand.notify("§aCreated backup of config"); } catch (IOException e) { @@ -77,9 +82,10 @@ public class Client extends Feature { } } + @Section(C_CONFIG) @Trigger("Load backup") public void loadBackup() { - try(FileInputStream stream = new FileInputStream("baseband.db.bak")) { + try(FileInputStream stream = new FileInputStream(backupFile)) { String s = new StreamReader(stream).readAllAsString(); Configuration.cloneConfigFrom(JSON.read(s)); BaseBand.notify("§aLoaded backup of config"); diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java b/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java index c0672db..9714a02 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/render/HUD.java @@ -64,7 +64,7 @@ public class HUD extends Feature { BottomRight, } - private final String C_INFO = "Information", C_NOTIF = "Notifications"; + private static final String C_INFO = "Information", C_NOTIF = "Notifications"; @Config("Include status in length") @Description("By default, status (greyed out information tucked on the end of module names) is not factored into the sorting. This setting lets you change that.")