1 package eu.svjatoslav.instantlauncher;
4 import java.io.FileInputStream;
5 import java.io.FileOutputStream;
6 import java.io.IOException;
7 import java.util.Properties;
9 public class Configuration {
11 private static final String KEY_ROOT_DIRECTORY = "KEY_ROOT_DIRECTORY";
12 private static final String CONFIG_FILE_NAME = ".instantlauncher";
13 private final Properties properties = new Properties();
15 private boolean propertiesChanged = false;
17 public Configuration() throws IOException {
21 private File getPropertiesFile() {
22 return new File(System.getProperty("user.home") + "/" + CONFIG_FILE_NAME);
25 public File getRootDirectory() {
27 if (properties.containsKey(KEY_ROOT_DIRECTORY)) {
28 return new File(properties.getProperty(KEY_ROOT_DIRECTORY));
30 properties.put(KEY_ROOT_DIRECTORY, System.getProperty("user.home") + "/");
31 propertiesChanged = true;
32 return getRootDirectory();
37 private void initialize() throws IOException {
41 validatePropertiesFile();
43 if (propertiesChanged) {
48 private void loadIfFileExists() throws IOException {
49 final File propertiesFile = getPropertiesFile();
51 if (propertiesFile.exists()) {
52 final FileInputStream inStream = new FileInputStream(propertiesFile);
53 properties.load(inStream);
58 private void saveFile() throws IOException {
59 properties.store(new FileOutputStream(getPropertiesFile()), "Instantlauncher configuration file.");
62 private void validatePropertiesFile() {