diff options
Diffstat (limited to 'ui-console')
4 files changed, 20 insertions, 8 deletions
diff --git a/ui-console/src/main/java/market/guess/ui/console/command/LoadFileMenuCommand.java b/ui-console/src/main/java/market/guess/ui/console/command/LoadFileMenuCommand.java index 11ec478..c5b3c77 100644 --- a/ui-console/src/main/java/market/guess/ui/console/command/LoadFileMenuCommand.java +++ b/ui-console/src/main/java/market/guess/ui/console/command/LoadFileMenuCommand.java | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | package market.guess.ui.console.command; | 1 | package market.guess.ui.console.command; |
| 2 | 2 | ||
| 3 | import java.nio.file.Path; | ||
| 4 | import market.guess.api.CatalogContext; | 3 | import market.guess.api.CatalogContext; |
| 5 | import market.guess.ui.console.io.InputProcessor; | 4 | import market.guess.ui.console.io.InputProcessor; |
| 6 | 5 | ||
| @@ -26,7 +25,7 @@ public final class LoadFileMenuCommand implements MenuCommand { | |||
| 26 | @Override | 25 | @Override |
| 27 | public void execute() { | 26 | public void execute() { |
| 28 | var path = io.readPath("Pleae enter the full file path to the XML file: "); | 27 | var path = io.readPath("Pleae enter the full file path to the XML file: "); |
| 29 | var result = catalog.loadEvents(Path.of(path)); | 28 | var result = catalog.loadEvents(path); |
| 30 | 29 | ||
| 31 | if (result.isSuccess()) { | 30 | if (result.isSuccess()) { |
| 32 | io.println( | 31 | io.println( |
diff --git a/ui-console/src/main/java/market/guess/ui/console/command/LoadMarketStateMenuCommand.java b/ui-console/src/main/java/market/guess/ui/console/command/LoadMarketStateMenuCommand.java index 26d00c1..30acef3 100644 --- a/ui-console/src/main/java/market/guess/ui/console/command/LoadMarketStateMenuCommand.java +++ b/ui-console/src/main/java/market/guess/ui/console/command/LoadMarketStateMenuCommand.java | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | package market.guess.ui.console.command; | 1 | package market.guess.ui.console.command; |
| 2 | 2 | ||
| 3 | import java.nio.file.Path; | ||
| 4 | import market.guess.api.CatalogContext; | 3 | import market.guess.api.CatalogContext; |
| 5 | import market.guess.ui.console.io.InputProcessor; | 4 | import market.guess.ui.console.io.InputProcessor; |
| 6 | 5 | ||
| @@ -27,7 +26,7 @@ public final class LoadMarketStateMenuCommand implements MenuCommand { | |||
| 27 | @Override | 26 | @Override |
| 28 | public void execute() { | 27 | public void execute() { |
| 29 | var path = io.readPath("Which state file to load? "); | 28 | var path = io.readPath("Which state file to load? "); |
| 30 | var result = catalog.restoreState(Path.of(path)); | 29 | var result = catalog.restoreState(path); |
| 31 | 30 | ||
| 32 | if (result.isSuccess()) { | 31 | if (result.isSuccess()) { |
| 33 | io.println("Restored %d event(s) from %s.".formatted(result.getData().eventsLoaded(), path)); | 32 | io.println("Restored %d event(s) from %s.".formatted(result.getData().eventsLoaded(), path)); |
diff --git a/ui-console/src/main/java/market/guess/ui/console/command/SaveMarketStateMenuCommand.java b/ui-console/src/main/java/market/guess/ui/console/command/SaveMarketStateMenuCommand.java index 77400d2..3c5d6b9 100644 --- a/ui-console/src/main/java/market/guess/ui/console/command/SaveMarketStateMenuCommand.java +++ b/ui-console/src/main/java/market/guess/ui/console/command/SaveMarketStateMenuCommand.java | |||
| @@ -1,6 +1,5 @@ | |||
| 1 | package market.guess.ui.console.command; | 1 | package market.guess.ui.console.command; |
| 2 | 2 | ||
| 3 | import java.nio.file.Path; | ||
| 4 | import market.guess.api.CatalogContext; | 3 | import market.guess.api.CatalogContext; |
| 5 | import market.guess.ui.console.io.InputProcessor; | 4 | import market.guess.ui.console.io.InputProcessor; |
| 6 | 5 | ||
| @@ -29,7 +28,7 @@ public final class SaveMarketStateMenuCommand implements MenuCommand { | |||
| 29 | var path = io.readPath("Save to: "); | 28 | var path = io.readPath("Save to: "); |
| 30 | 29 | ||
| 31 | try { | 30 | try { |
| 32 | catalog.saveState(Path.of(path)); | 31 | catalog.saveState(path); |
| 33 | io.println("Saved current state to %s.".formatted(path)); | 32 | io.println("Saved current state to %s.".formatted(path)); |
| 34 | } catch (Exception e) { | 33 | } catch (Exception e) { |
| 35 | io.println("Failed to save: %s".formatted(e.getMessage())); | 34 | io.println("Failed to save: %s".formatted(e.getMessage())); |
diff --git a/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java b/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java index 7587768..512fdfe 100644 --- a/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java +++ b/ui-console/src/main/java/market/guess/ui/console/io/InputProcessor.java | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | package market.guess.ui.console.io; | 1 | package market.guess.ui.console.io; |
| 2 | 2 | ||
| 3 | import java.nio.file.InvalidPathException; | ||
| 4 | import java.nio.file.Path; | ||
| 3 | import java.util.List; | 5 | import java.util.List; |
| 4 | import java.util.Scanner; | 6 | import java.util.Scanner; |
| 5 | import java.util.function.Function; | 7 | import java.util.function.Function; |
| @@ -95,7 +97,7 @@ public final class InputProcessor { | |||
| 95 | } | 97 | } |
| 96 | } | 98 | } |
| 97 | 99 | ||
| 98 | public String readPath(String prompt) { | 100 | public Path readPath(String prompt) { |
| 99 | while (true) { | 101 | while (true) { |
| 100 | var raw = readLine(prompt); | 102 | var raw = readLine(prompt); |
| 101 | 103 | ||
| @@ -104,8 +106,21 @@ public final class InputProcessor { | |||
| 104 | continue; | 106 | continue; |
| 105 | } | 107 | } |
| 106 | 108 | ||
| 107 | return raw; | 109 | try { |
| 110 | return Path.of(unquote(raw)); | ||
| 111 | } catch (InvalidPathException e) { | ||
| 112 | println("'%s' is not a valid file path.".formatted(raw)); | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
| 116 | |||
| 117 | private static String unquote(String raw) { | ||
| 118 | if (raw.length() >= 2 | ||
| 119 | && ((raw.charAt(0) == '"' && raw.charAt(raw.length() - 1) == '"') | ||
| 120 | || (raw.charAt(0) == '\'' && raw.charAt(raw.length() - 1) == '\''))) { | ||
| 121 | return raw.substring(1, raw.length() - 1); | ||
| 108 | } | 122 | } |
| 123 | return raw; | ||
| 109 | } | 124 | } |
| 110 | 125 | ||
| 111 | public boolean readYesNo(String prompt) { | 126 | public boolean readYesNo(String prompt) { |