1 package eu.svjatoslav.instantlauncher;
4 import java.io.FileInputStream;
5 import java.io.FileNotFoundException;
6 import java.io.FileOutputStream;
7 import java.io.IOException;
8 import java.util.Properties;
10 public class Configuration {
12 private static final String KEY_ROOT_DIRECTORY = "KEY_ROOT_DIRECTORY";
13 private static final String CONFIG_FILE_NAME = ".instantlauncher";
14 Properties properties = new Properties();
16 boolean propertiesChanged = false;
18 public Configuration() throws FileNotFoundException, IOException {
22 public File getPropertiesFile() {
23 return new File(System.getProperty("user.home") + "/" + CONFIG_FILE_NAME);
26 public File getRootDirectory() {
28 if (properties.containsKey(KEY_ROOT_DIRECTORY)) {
29 return new File(properties.getProperty(KEY_ROOT_DIRECTORY));
31 properties.put(KEY_ROOT_DIRECTORY, System.getProperty("user.home") + "/");
32 propertiesChanged = true;
33 return getRootDirectory();
38 public void initialize() throws FileNotFoundException, IOException {
42 validatePropertiesFile();
44 if (propertiesChanged) {
49 public void loadIfFileExists() throws FileNotFoundException, IOException {
50 final File propertiesFile = getPropertiesFile();
52 if (propertiesFile.exists()) {
53 final FileInputStream inStream = new FileInputStream(propertiesFile);
54 properties.load(inStream);
59 public void saveFile() throws FileNotFoundException, IOException {
60 properties.store(new FileOutputStream(getPropertiesFile()), "Instantlauncher configuration file.");
63 public void validatePropertiesFile() {