package config;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

public class UserSettings
{
	private final String configFilePath = "config.properties";

	private Properties properties; 

	public UserSettings()
	{
		//Check if config File exists in the given location
		File configFile = new File(configFilePath);
		if (configFile.exists())	//If so, read from the file
			properties = readFromProperties(configFilePath);
		else
		{
			//If not, create a new Properties instance and write it to a file at the filePath
			properties = new Properties();
			writeProperties(properties, configFilePath);
		}
	}
	
	//Returns a properties instance read from the file at the given path
	static Properties readFromProperties(String filePath)
	{
		//Initiate properties and inputStream 
		Properties properties = new Properties();
		InputStream inputStream = null;
		
		try
		{
			//Load properties with the data from the config file
			inputStream = new FileInputStream(filePath);
			properties.load(inputStream);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			//Close inputStream if it was ever successfully created
			if (inputStream != null)
			{
				try
				{
					inputStream.close();
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
		}
		
		return properties;
	}
	
	//Write the given properties instance to the config file
	static void writeProperties(Properties properties, String filePath)
	{
		//Initiate outputStream
		OutputStream outputStream = null;

		try
		{
			//Store data from properties instance into a file at filePath
			outputStream = new FileOutputStream(filePath);
			properties.store(outputStream, null);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		finally
		{
			//Close outputStream if it was ever successfully created
			if (outputStream != null)
			{
				try
				{
					outputStream.close();
				}
				catch (IOException e)
				{
					e.printStackTrace();
				}
			}
		}
	}
	
	/**Adds or updates the property with the given key to be the given value, updates the config file*/
	public void setProperty(String key, String value)
	{
		properties.setProperty(key, value);
		writeProperties(properties, configFilePath);
	}

	/**Returns the property with the given key from the config*/
	public String getProperty(String key)
	{
		return properties.getProperty(key);
	}
	
	
	/**Returns whether the config contains a propery with the given key*/
	public boolean containsProperty(String key)
	{
		return properties.containsKey(key);
	}
	
	/**Removes the property with the given key, updates the config file*/
	public void removeProperty(String key)
	{
		properties.remove(key);
		writeProperties(properties, configFilePath);
	}
}

@@ -254,16 +254,23 @@
 e final 
+static 
 String c
@@ -316,16 +316,23 @@
 private 
+static 
 Properti
@@ -326,33 +326,39 @@
 atic Properties 
-p
+configP
 roperties; %0A%0A%09pu
@@ -359,27 +359,110 @@
  %0A%0A%09
-public UserSettings
+/**Call this at the start of the program! Loads the config file for use*/%0A%09public static void initiate
 ()%0A%09
@@ -617,25 +617,31 @@
 the file%0A%09%09%09
-p
+configP
 roperties = 
@@ -771,25 +771,31 @@
 filePath%0A%09%09%09
-p
+configP
 roperties = 
@@ -823,33 +823,39 @@
 writeProperties(
-p
+configP
 roperties, confi
@@ -1708,32 +1708,35 @@
 ng filePath)%0A%09%7B%0A
+%09%09%0A
 %09%09//Initiate out
@@ -2237,24 +2237,26 @@
 %09%7D%0A%09%09%7D%0A%09%7D%0A%09%0A
+%09%0A
 %09/**Adds or 
@@ -2348,24 +2348,31 @@
 e*/%0A%09public 
+static 
 void setProp
@@ -2403,25 +2403,126 @@
 value)%0A%09%7B%0A%09%09
-p
+//Initiate settings if we haven't already %0A%09%09if (configProperties == null)%0A%09%09%09initiate();%0A%09%09%0A%09%09configP
 roperties.se
@@ -2554,33 +2554,39 @@
 writeProperties(
-p
+configP
 roperties, confi
@@ -2671,16 +2671,23 @@
 %09public 
+static 
 String g
@@ -2710,32 +2710,133 @@
 g key)%0A%09%7B%0A%09%09
-return p
+//Initiate settings if we haven't already %0A%09%09if (configProperties == null)%0A%09%09%09initiate();%0A%09%09%0A%09%09return configP
 roperties.ge
@@ -2937,16 +2937,23 @@
 %09public 
+static 
 boolean 
@@ -2986,24 +2986,125 @@
 y)%0A%09%7B%0A%09%09
-return p
+//Initiate settings if we haven't already %0A%09%09if (configProperties == null)%0A%09%09%09initiate();%0A%09%09%0A%09%09return configP
 ropertie
@@ -3207,16 +3207,23 @@
 %09public 
+static 
 void rem
@@ -3251,17 +3251,118 @@
 y)%0A%09%7B%0A%09%09
-p
+//Initiate settings if we haven't already %0A%09%09if (configProperties == null)%0A%09%09%09initiate();%0A%09%09%0A%09%09configP
 ropertie
@@ -3394,17 +3394,23 @@
 perties(
-p
+configP
 ropertie

Convert UserSettings functionality to static