summaryrefslogtreecommitdiff
path: root/src/main/java/com/keuin/kbackupfabric/config
diff options
context:
space:
mode:
authorKeuin <[email protected]>2024-01-20 12:44:17 +0800
committerKeuin <[email protected]>2024-01-20 13:02:22 +0800
commit6d53613a57d542a424d6368cb91c69dfd5c6772e (patch)
tree640510455e37cc32064da5c495256b4c0f912744 /src/main/java/com/keuin/kbackupfabric/config
parent6087003104bcc21a66bc3534b5606b999acf95db (diff)
add plugin-wide config; enable CoW through config file
Diffstat (limited to 'src/main/java/com/keuin/kbackupfabric/config')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java b/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java
new file mode 100644
index 0000000..8ece8d2
--- /dev/null
+++ b/src/main/java/com/keuin/kbackupfabric/config/KBackupConfig.java
@@ -0,0 +1,56 @@
+package com.keuin.kbackupfabric.config;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.ObjectWriter;
+import com.keuin.kbackupfabric.util.PrintUtil;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+public class KBackupConfig {
+
+ private static KBackupConfig instance = getDefault();
+ private static final String CONFIG_FILE = "kbackup.json";
+
+ @JsonProperty("incbak_cow")
+ private Boolean incbakCow;
+
+ public static KBackupConfig getInstance() {
+ return instance;
+ }
+
+ private static KBackupConfig getDefault() {
+ return new KBackupConfig(false);
+ }
+
+ public static void load() throws IOException {
+ File file = new File(CONFIG_FILE);
+ ObjectMapper om = new ObjectMapper();
+ try {
+ instance = om.readValue(file, KBackupConfig.class);
+ } catch (FileNotFoundException ignored) {
+ // generate default config file
+ PrintUtil.info("Config file does not exist. Creating default config: " + CONFIG_FILE);
+ instance = getDefault();
+ ObjectWriter w = om.writerWithDefaultPrettyPrinter();
+ w.writeValue(file, instance);
+ }
+ }
+
+ public KBackupConfig() {
+ }
+
+ public KBackupConfig(Boolean incbakCow) {
+ this.incbakCow = incbakCow;
+ }
+
+ public Boolean getIncbakCow() {
+ return this.incbakCow;
+ }
+
+ public void setIncbakCow(Boolean incbakCow) {
+ this.incbakCow = incbakCow;
+ }
+} \ No newline at end of file