package fi.helsinki.cs.tmc.cli.tmcstuff;

import com.google.gson.Gson;

import java.nio.file.Files;
import java.nio.file.Path;

/**
 * Reads and writes to config files on the system.
 */
public class SettingsIO {

    private String getConfigFilePath() {
        String fileSeparator;
        String configFileName;
        String configPath;
        String os = System.getProperty("os.name").toLowerCase();
        fileSeparator = System.getProperty("file.separator");
        configFileName = "tmc.conf";

        if (os.contains("windows")) {
            //TODO: Use proper Windows config file location
            configPath = System.getProperty("user.home") + fileSeparator + configFileName;
        } else {
            //Assume we're using Unix (Linux, Mac OS X or *BSD)
            String configEnv = System.getenv("XDG_CONFIG_HOME");

            if (configEnv != null && configEnv.length() > 0) {
                configPath = configEnv
                        + fileSeparator + "tmc"
                        + fileSeparator + configFileName;
            } else {
                configPath = System.getProperty("user.home")
                        + fileSeparator + ".config"
                        + fileSeparator + "tmc"
                        + fileSeparator + configFileName;
            }
        }
        return configPath;
    }

    private Path getConfigFile() {
        Path configFile = null;
        
    }
}

@@ -46,30 +46,173 @@
 ort 
-com.google.gson.Gson;%0A
+fi.helsinki.cs.tmc.core.configuration.TmcSettings;%0A%0Aimport com.google.gson.Gson;%0A%0Aimport java.io.IOException;%0Aimport java.io.Reader;%0Aimport java.nio.charset.Charset;
 %0Aimp
@@ -1120,32 +1120,35 @@
 Separator + %22tmc
+cli
 %22%0A              
@@ -1371,16 +1371,19 @@
 r + %22tmc
+cli
 %22%0A      
@@ -1531,48 +1531,575 @@
 ) %7B%0A
-        Path configFile = null;%0A        
+%0A    %7D%0A%0A    public void save(TmcSettings settings) throws IOException %7B%0A        Path location = null;%0A        //the above line is temporary!!!%0A        Gson gson = new Gson();%0A        byte%5B%5D json = gson.toJson(settings).getBytes();%0A        Files.write(location, json);%0A    %7D%0A%0A    public TmcSettings load() throws IOException %7B%0A        Path location = null;%0A        //the above line is temporary!!!%0A        Gson gson = new Gson();%0A        Reader reader = Files.newBufferedReader(location, Charset.forName(%22UTF-8%22));%0A        return gson.fromJson(reader, Settings.class);
 %0A   

work in progress