Skip to content

Commit

Permalink
Update file to make it work correctly on Windows
Browse files Browse the repository at this point in the history
Some commands need to be parsed differently to work on both mac and windows.

Parse.java and storage file are modified to load and save list correctly.
  • Loading branch information
MayDalag committed Mar 24, 2024
1 parent adc6b66 commit ec200d9
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 15 deletions.
8 changes: 7 additions & 1 deletion data/venus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ E|1| sm3 | Jan 1 2019 to: Jan 2 2019
D|1| 222 | Oct 2 2020
E|0| 2222 | Oct 10 2020 to: Oct 10 2020
T|0| dota2
T|0| dota2
T|0| dota2
E|0| A meeting | Feb 3 2020 to: Feb 4 2020
D|0| finish work | Feb 2 2020
E|0| input | Mar 20 2020 to: Mar 31 2020
T|0| abc
D|0| a b c d | Feb 3 2020
E|0| 12nnewb | Feb 3 2020 to: Mar 3 2020
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Venus is a **desktop app for managing events** you have planned for yourself.
It supports both **GUI and CLI** although the `GUI is more recommended`.
The `GUI` is the newest update and the CLI is a `legacy version`.

![Product Image](/docs/Ui.png)
![Product Image](Ui.png)

- [Quick Start](#quick-start)
- Features
Expand Down Expand Up @@ -196,7 +196,7 @@ Tasks are automatically saved into the file after each user action, there is
no need to save manually.

## Editing the data file
Data is saved automatically as a [venus.txt](..%2Fdata%2Fvenus.txt)
Data is saved automatically as a [doc/venus.txt](..%2Fdata%2Fvenus.txt)
Advanced users are welcome to update data. Also do take note that corrupted
data will cause issues with loading and saving.

Expand All @@ -211,4 +211,4 @@ data will cause issues with loading and saving.
| Mark a task as not done | Format `Unmark INDEX` Example: `Unmark 1` |
| Delete a task by index | Format `Delete INDEX` Example: `Delete 2` |
| Find tasks by a keyword | Format `Find KEYWORD` Example: `Find film` |
| Find duplicated tasks (GUI only) | Format `Duplicate` Example: `Duplicate` |
| Find duplicated tasks (GUI only) | Format `Duplicate` Example: `Duplicate` |
6 changes: 2 additions & 4 deletions src/main/java/venus/Parser.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package venus;

import java.io.File;

/**
* This is a Parser class that make strings understandable for the task formatters.
*
Expand Down Expand Up @@ -70,7 +68,7 @@ public static String findTodoContent(String input) {
*/
public static String[] findDeadlineContent(String input) throws DukeException {
String dString = input.substring(9);
String[] parts = dString.split(File.separator + "by");
String[] parts = dString.split("/by");
if (parts.length != 2) {
throw new DukeException("Incorrect, choose a specific deadline only please");
}
Expand All @@ -87,7 +85,7 @@ public static String[] findDeadlineContent(String input) throws DukeException {
*/
public static String[] findEventParts(String input) throws DukeException {
String dString = input.substring(6);
String[] parts = dString.split(File.separator);
String[] parts = dString.split("/");
if (parts.length != 3) {
throw new DukeException("Incorrect arguments for events");
}
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/venus/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@ public class Storage {
*/

public Storage(String filePath) {
File folder = new File(filePath);
if (!folder.exists()) { // handling folder does not exist issues
folder.mkdirs(); // Use mkdirs() to create parent directories if necessary
System.out.println("Folder does not exist, data folder is created.\n"
+ "Do not worry if system say there is error, it will fix itself.:)");
String currDir = System.getProperty("user.dir");
Path folder = Path.of(currDir, "data");
if (!Files.exists(folder)) {
try {
Files.createDirectories(folder);
System.out.println("Folder created under " + currDir);
} catch (IOException e) {
System.out.println("Folder not created, check your access!");
return;
}
}
if (!Files.exists(Path.of("data", "venus.txt"))) { // handling file does not exist
Path file = folder.resolve("venus.txt");
if (!Files.exists(file)) { // handling file does not exist
// Create the file if it doesn't exist
File f = new File("data", "venus.txt");
try {
Expand All @@ -54,7 +60,7 @@ public Storage(String filePath) {
*/
public void saveToFile(String textToAdd) throws FileNotFoundException {
try {
FileWriter fw = new FileWriter(filePath, true);
FileWriter fw = new FileWriter(System.getProperty("user.dir") + filePath, true);
String amendedText = changeToSaveString(textToAdd);
fw.write(System.lineSeparator() + amendedText);
fw.close();
Expand Down
Binary file added src/main/resources/this-is.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ec200d9

Please sign in to comment.