Respackopts/src/main/java/io/gitlab/jfronny/respackopts/model/ConfigFile.java

44 lines
1.4 KiB
Java

package io.gitlab.jfronny.respackopts.model;
import io.gitlab.jfronny.respackopts.Respackopts;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class ConfigFile {
public boolean debugCommands = false;
public boolean debugLogs = false;
public boolean dashloaderCompat = true;
private static final Path rpoPath = Respackopts.FALLBACK_CONF_DIR.resolve("_respackopts.conf");
public static ConfigFile load() {
if (!Files.exists(rpoPath))
new ConfigFile().save();
try (BufferedReader br = Files.newBufferedReader(rpoPath)) {
return Respackopts.GSON.fromJson(br, ConfigFile.class);
} catch (IOException e) {
Respackopts.LOGGER.error("Could not load config, using default", e);
return new ConfigFile();
}
}
public void save() {
if (!Files.exists(Respackopts.FALLBACK_CONF_DIR)) {
try {
Files.createDirectories(Respackopts.FALLBACK_CONF_DIR);
} catch (IOException e) {
Respackopts.LOGGER.error("Could not create config dir", e);
return;
}
}
try (BufferedWriter bw = Files.newBufferedWriter(rpoPath)) {
Respackopts.GSON.toJson(this, bw);
} catch (IOException e) {
Respackopts.LOGGER.error("Could not save", e);
}
}
}