package seedu.emeraldo.logic.commands;

import java.io.IOException;

import seedu.emeraldo.commons.core.Config;
import seedu.emeraldo.commons.core.EventsCenter;
import seedu.emeraldo.commons.events.storage.SaveLocationChangedEvent;
import seedu.emeraldo.commons.util.ConfigUtil;
import seedu.emeraldo.storage.StorageManager;

public class SaveToCommand extends Command{
    
    public static final String COMMAND_WORD = "saveto";
    
    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Changes the location of the xml data file"
            + "Parameters: filepath"
            + "Example: " + COMMAND_WORD
            + " C:/emeraldo_task/";
    
    public static final String MESSAGE_SUCCESS = "Save location changed to %1$s";
    
    public static final String MESSAGE_ERROR = "Failed to change save location";
    
    public static final String FILE_NAME = "emeraldo.xml";
    
    public static final String DEFAULT_LOCATION = "./data/";
    
    private String filepath;
    
    
    public SaveToCommand(String filepath){
        this.filepath = filepath;
    }
    
    public CommandResult execute() {
        /*
        TO-DO:
            change filepath in XmlEmeraldoStorage
            change filepath in Config.java
            indicateEmeraldoSaveLocationChanged()
        */

        try {
            filepath = filepath + FILE_NAME;
            Config config = new Config();
            config.setEmeraldoFilePath(filepath);
            ConfigUtil.saveConfig(config, Config.DEFAULT_CONFIG_FILE);
            EventsCenter.getInstance().post(new SaveLocationChangedEvent(filepath));
            return new CommandResult(String.format(MESSAGE_SUCCESS, filepath));
        } catch (IOException e) {
            return new CommandResult(MESSAGE_ERROR);
        }
        
        
    }

}

@@ -275,54 +275,8 @@
 til;
-%0Aimport seedu.emeraldo.storage.StorageManager;
 %0A%0Apu
@@ -489,16 +489,19 @@
 ata file
+.%5Cn
 %22%0A      
@@ -521,24 +521,26 @@
 meters: 
-filepath
+FILEPATH%5Cn
 %22%0A      
@@ -1085,188 +1085,8 @@
 () %7B
-%0A        /*%0A        TO-DO:%0A            change filepath in XmlEmeraldoStorage%0A            change filepath in Config.java%0A            indicateEmeraldoSaveLocationChanged()%0A        */
 %0A%0A  
@@ -1142,16 +1142,29 @@
 E_NAME;%0A
+            %0A
         
@@ -1247,16 +1247,16 @@
 epath);%0A
-
         
@@ -1318,16 +1318,29 @@
 _FILE);%0A
+            %0A
         

Change format for message in SaveToCommand