Properly initialize yaml config
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 10 Jul 2017 13:32:32 +0000 (15:32 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 10 Jul 2017 13:32:32 +0000 (15:32 +0200)
src/main/java/eu/svjatoslav/instantlauncher/configuration/ConfigurationManager.java

index aef82f2..7a8f8bc 100755 (executable)
@@ -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);