package seedu.ezdo.logic.commands;

import java.io.File;

import seedu.ezdo.commons.exceptions.IllegalValueException;
import seedu.ezdo.logic.commands.exceptions.CommandException;

/**
 * Changes the save location of ezDo.
 */
public class SaveCommand extends Command {

    public static final String COMMAND_WORD = "save";

    public static final String MESSAGE_USAGE = COMMAND_WORD + ": Changes the save location of ezDo. "
            + "Parameters: DIRECTORYPATH \n"
            + "Example: " + COMMAND_WORD
            + " C:\\Users\\Tom\\Desktop";

    public static final String MESSAGE_DIRECTORY_PATH_INVALID = "The directory path given is invalid.";
    public static final String MESSAGE_SAVE_TASK_SUCCESS = "New Save Location: %1$s";

    private final String directoryPath;

    /**
     * Creates a SaveCommand using raw values.
     *
     * @throws IllegalValueException if the directory path is invalid
     */
    public SaveCommand(String path) throws IllegalValueException {
        directoryPath = path;
        File directory = new File(path);
        if (directory.exists() == false && !directory.isDirectory()) { // TODO
            System.out.println("file.exists has error and not directory");
            throw new IllegalValueException(MESSAGE_DIRECTORY_PATH_INVALID);
        }
    }

    // TODO
    @Override
    public CommandResult execute() throws CommandException {
        assert directoryPath != null;
        return new CommandResult(String.format(MESSAGE_SAVE_TASK_SUCCESS, directoryPath));
    }

}

@@ -50,16 +50,157 @@
 o.File;%0A
+import java.io.IOException;%0A%0Aimport seedu.ezdo.commons.core.EventsCenter;%0Aimport seedu.ezdo.commons.events.storage.EzDoDirectoryChangedEvent;
 %0Aimport 
@@ -252,16 +252,57 @@
 eption;%0A
+import seedu.ezdo.commons.util.FileUtil;%0A
 import s
@@ -1023,15 +1023,8 @@
 es.%0A
-     *%0A
     
@@ -1176,28 +1176,27 @@
     
-directoryP
+assert p
 ath 
+!
 = 
-path
+null
 ;%0A  
@@ -1234,16 +1234,18 @@
 (path);%0A
+//
         
@@ -1252,137 +1252,36 @@
 if (
-directory.exists() == false && !directory.isDirectory()) %7B // TODO%0A            System.out.println(%22file.exists has error and not 
+!FileUtil.isDirectoryExists(
 dire
@@ -1289,12 +1289,15 @@
 tory
-%22);%0A
+)) %7B%0A//
     
@@ -1369,16 +1369,18 @@
 VALID);%0A
+//
         
@@ -1389,22 +1389,40 @@
     
-%7D%0A%0A
     
-// TODO
+directoryPath = path;%0A    %7D%0A
 %0A   
@@ -1543,96 +1543,424 @@
     
-return new CommandResult(String.format(MESSAGE_SAVE_TASK_SUCCESS, directoryPath));%0A    %7D%0A
+try %7B%0A            File file = new File(directoryPath);%0A            FileUtil.createIfMissing(file);%0A            EventsCenter.getInstance().post(new EzDoDirectoryChangedEvent(model.getEzDo(), directoryPath));%0A        return new CommandResult(String.format(MESSAGE_SAVE_TASK_SUCCESS, directoryPath));%0A        %7D catch (IOException e) %7B%0A            return new CommandResult(MESSAGE_DIRECTORY_PATH_INVALID);%0A        %7D%0A    %7D
 %0A%7D%0A

Implement execute for SaveCommand Add needed imports