From 00d805000d01ea8dcb517f0a9ebeb4a70a77bdf7 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Mon, 10 Jul 2017 15:32:32 +0200 Subject: [PATCH] Properly initialize yaml config --- .../configuration/ConfigurationManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java b/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java index aef82f2..7a8f8bc 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java @@ -1,5 +1,6 @@ package eu.svjatoslav.instantlauncher.configuration; +import com.esotericsoftware.yamlbeans.YamlConfig; import com.esotericsoftware.yamlbeans.YamlReader; import com.esotericsoftware.yamlbeans.YamlWriter; @@ -34,6 +35,7 @@ public class ConfigurationManager { private void loadConfigFile(File propertiesFile) throws IOException { YamlReader reader = new YamlReader(new FileReader(propertiesFile)); + configureYaml(reader.getConfig()); configuration = reader.read(Configuration.class); if (configuration == null) initDefaultConfiguration(); @@ -41,12 +43,16 @@ public class ConfigurationManager { private void saveConfigFile() throws IOException { YamlWriter writer = new YamlWriter(new FileWriter(getPropertiesFile())); - writer.getConfig().setClassTag("configuration", Configuration.class); - writer.getConfig().setPropertyElementType(Configuration.class, "fileAssociations", FileAssociation.class); + configureYaml(writer.getConfig()); writer.write(configuration); writer.close(); } + private void configureYaml(YamlConfig config) { + config.setClassTag("configuration", Configuration.class); + config.setPropertyElementType(Configuration.class, "fileAssociations", FileAssociation.class); + } + private void registerFileAssociation(String fileRegex, String command) { FileAssociation association = new FileAssociation(fileRegex, command); configuration.fileAssociations.add(association); -- 2.20.1