+++ /dev/null
-package eu.svjatoslav.instantlauncher;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-public class Configuration {
-
- private static final String KEY_ROOT_DIRECTORY = "KEY_ROOT_DIRECTORY";
- private static final String CONFIG_FILE_NAME = ".instantlauncher";
- private final Properties properties = new Properties();
-
- private boolean propertiesChanged = false;
-
- public Configuration() throws IOException {
- initialize();
- }
-
- private File getPropertiesFile() {
- return new File(System.getProperty("user.home") + "/" + CONFIG_FILE_NAME);
- }
-
- public File getRootDirectory() {
-
- if (properties.containsKey(KEY_ROOT_DIRECTORY)) {
- return new File(properties.getProperty(KEY_ROOT_DIRECTORY));
- } else {
- properties.put(KEY_ROOT_DIRECTORY, System.getProperty("user.home") + "/");
- propertiesChanged = true;
- return getRootDirectory();
- }
-
- }
-
- private void initialize() throws IOException {
-
- loadIfFileExists();
-
- validatePropertiesFile();
-
- if (propertiesChanged) {
- saveFile();
- }
- }
-
- private void loadIfFileExists() throws IOException {
- final File propertiesFile = getPropertiesFile();
-
- if (propertiesFile.exists()) {
- final FileInputStream inStream = new FileInputStream(propertiesFile);
- properties.load(inStream);
- inStream.close();
- }
- }
-
- private void saveFile() throws IOException {
- properties.store(new FileOutputStream(getPropertiesFile()), "Instantlauncher configuration file.");
- }
-
- private void validatePropertiesFile() {
- getRootDirectory();
- }
-
-}