Add JVM parameter to define the configuration directory
Add a new JVM parameter (-Dctbrec.config.dir) to define the directory to save the config to / load it from. If this parameter is not set, the system default directory determined by OS.getConfigDir() is used.
This commit is contained in:
parent
682f78bdac
commit
6b16a637f0
|
@ -29,9 +29,16 @@ public class Config {
|
|||
private Settings settings;
|
||||
private String filename;
|
||||
private List<Site> sites;
|
||||
private File configDir;
|
||||
|
||||
private Config(List<Site> sites) throws FileNotFoundException, IOException {
|
||||
this.sites = sites;
|
||||
if(System.getProperty("ctbrec.config.dir") != null) {
|
||||
configDir = new File(System.getProperty("ctbrec.config.dir"));
|
||||
} else {
|
||||
configDir = OS.getConfigDir();
|
||||
}
|
||||
|
||||
if(System.getProperty("ctbrec.config") != null) {
|
||||
filename = System.getProperty("ctbrec.config");
|
||||
} else {
|
||||
|
@ -45,7 +52,6 @@ public class Config {
|
|||
.add(Model.class, new ModelJsonAdapter(sites))
|
||||
.build();
|
||||
JsonAdapter<Settings> adapter = moshi.adapter(Settings.class);
|
||||
File configDir = OS.getConfigDir();
|
||||
File configFile = new File(configDir, filename);
|
||||
LOG.debug("Loading config from {}", configFile.getAbsolutePath());
|
||||
if(configFile.exists()) {
|
||||
|
@ -86,7 +92,6 @@ public class Config {
|
|||
.build();
|
||||
JsonAdapter<Settings> adapter = moshi.adapter(Settings.class).indent(" ");
|
||||
String json = adapter.toJson(settings);
|
||||
File configDir = OS.getConfigDir();
|
||||
File configFile = new File(configDir, filename);
|
||||
LOG.debug("Saving config to {}", configFile.getAbsolutePath());
|
||||
Files.createDirectories(configDir.toPath());
|
||||
|
|
Loading…
Reference in New Issue