Skip to content

Commit

Permalink
Add auto create storage feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mario7lorenzo committed Feb 13, 2020
1 parent d05d69d commit 71f339a
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 7 deletions.
5 changes: 3 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ GUI.
## Requirements
- Duke runs in Java 11 or later.
- The `.jar` file of Duke can be found [here](https://github.com/mario7lorenzo/duke/releases)
- Make sure you have created `./data` directory, and the directory path is relative to the `.jar`
file, with three files: `archive.txt`, `notes.txt`, and `tasks.txt` inside the `./data` directory.

## Features
### Interactive GUI
Expand Down Expand Up @@ -120,6 +118,7 @@ regarding to archives are listed below:
- `archive-list`<br>Displays all the archived tasks.
- `archive-add [task-index]`<br>Moves the task of a given index in the list to the archive.
- `archive-delete [archived-task-index]`<br>Deletes the task permanently from the archive.
- `unarchive [archived-task-index]`<br>Unarchives the task from the archive.

Example of usage:
- `archive-list`<br>
Expand All @@ -128,6 +127,8 @@ Duke will list all the archived tasks.
Duke will move the first task in the current list to the archive.
- `archive-delete 1`<br>
Duke will delete the first task in the archived task list from the archive.
- `unarchive 1`<br>
Duke will unarchive the first task in the archived list.

###Notes
Duke can memorize random notes from the user. The commands regarding to notes are listed below:
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*/

public class Driver extends Application {
private final String STAGE_TITLE = "Duke";
private static final String STAGE_TITLE = "Duke";
private static final String BYE_STRING = "bye";
/**
* The main method runs the program.
Expand Down
83 changes: 79 additions & 4 deletions src/main/java/Duke.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import duke.util.Task;
import duke.util.TaskList;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

/*
Expand All @@ -35,10 +37,13 @@ public class Duke {
private ArchiveList archiveList;
private Storage taskStorage;
private Storage archiveStorage;
private Storage storage;
private NoteStorage noteStorage;
private NoteList noteList;
private Parser parser;
private static final String DATA_DIRECTORY = "./data";
private static final String TASK_DIRECTORY = "./data/tasks.txt";
private static final String ARCHIVE_DIRECTORY = "./data/archive.txt";
private static final String NOTES_DIRECTORY = "./data/notes.txt";

/**
* Constructs the Duke instance that has a list that
Expand Down Expand Up @@ -68,9 +73,10 @@ private Duke(TaskList taskList, ArchiveList archiveList,
*/

public static Duke start() throws DukeInvalidTaskFormatException, DukeInvalidDateFormatException {
Storage taskStorage = new Storage("./data/tasks.txt");
Storage archiveStorage = new Storage("./data/archive.txt");
NoteStorage noteStorage = new NoteStorage("./data/notes.txt");
setStorage();
Storage taskStorage = new Storage(TASK_DIRECTORY);
Storage archiveStorage = new Storage(ARCHIVE_DIRECTORY);
NoteStorage noteStorage = new NoteStorage(NOTES_DIRECTORY);
ArrayList<Task> tasks = new ArrayList<>();
ArrayList<Task> archives = new ArrayList<>();
ArrayList<Note> notes = new ArrayList<>();
Expand Down Expand Up @@ -115,4 +121,73 @@ public String processCommand(String commands) {
return exc.getMessage();
}
}

/**
* Sets up the storage for Duke to read and write the contents.
*/

private static void setStorage() {
createDataDirectory();
createTaskFile();
createArchiveFile();
createNoteFile();
}
/**
* Creates the data directory if it is not exist yet.
*/

private static void createDataDirectory() {
File file = new File(DATA_DIRECTORY);
if (!file.exists()) {
file.mkdir();
}
}

/**
* Creates the tasks.txt file inside the data directory if not exist yet.
*/

private static void createTaskFile() {
File file = new File(TASK_DIRECTORY);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

}
}

/**
* Creates the archive.txt file inside the data directory if not exist yet.
*/

private static void createArchiveFile() {
File file = new File(ARCHIVE_DIRECTORY);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

}
}

/**
* Creates the notes.txt file inside the data directory if not exist yet.
*/

private static void createNoteFile() {
File file = new File(NOTES_DIRECTORY);
if (!file.exists()) {
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}

}
}
}

0 comments on commit 71f339a

Please sign in to comment.