+/*
+ * Instantlauncher. Copyright ©2012-2019, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
package eu.svjatoslav.instantlauncher.configuration;
+import com.esotericsoftware.yamlbeans.YamlConfig;
import com.esotericsoftware.yamlbeans.YamlReader;
import com.esotericsoftware.yamlbeans.YamlWriter;
final File propertiesFile = getPropertiesFile();
if (!propertiesFile.exists()) {
initDefaultConfiguration();
- saveConfigFile();
} else
loadConfigFile(propertiesFile);
}
- private void loadConfigFile(File propertiesFile) throws FileNotFoundException, com.esotericsoftware.yamlbeans.YamlException {
+ 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) {
- configuration = new Configuration();
- configuration.fileAssociations = new HashSet<>();
- }
+ if (configuration == null)
+ initDefaultConfiguration();
}
private void saveConfigFile() throws IOException {
YamlWriter writer = new YamlWriter(new FileWriter(getPropertiesFile()));
+ 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);
}
- private void initDefaultConfiguration() {
+ private void initDefaultConfiguration() throws IOException {
+ configuration = new Configuration();
+ configuration.fileAssociations = new HashSet<>();
+
configuration.navigationRootPath = System.getProperty("user.home") + "/";
configuration.directoryOpenCommand = "nautilus -w {file}";
+ configuration.directoryTerminalOpenCommand = "gnome-terminal --working-directory={file}";
registerFileAssociation(".*\\.jpeg$", "eog {file}");
registerFileAssociation(".*\\.jpg$", "eog {file}");
registerFileAssociation(".*\\.avi$", "vlc {file}");
registerFileAssociation(".*\\.mp4$", "vlc {file}");
registerFileAssociation(".*\\.mkv$", "vlc {file}");
+
+ saveConfigFile();
}
}