improve config backups
All checks were successful
/ Build BaseBand DSM & Broadway (push) Successful in 2m11s

This commit is contained in:
Daniella / Tove 2024-06-18 19:20:39 +02:00
parent 666d4fc03e
commit 484117aaf5
Signed by: TudbuT
GPG key ID: B3CF345217F202D3
2 changed files with 13 additions and 7 deletions

View file

@ -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");

View file

@ -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.")