aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/equalparts
diff options
context:
space:
mode:
Diffstat (limited to 'src/eu/equalparts')
-rw-r--r--src/eu/equalparts/cardbase/cli/CardbaseCLI.java52
-rw-r--r--src/eu/equalparts/cardbase/utils/MTGUniverse.java7
2 files changed, 32 insertions, 27 deletions
diff --git a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
index e621bb5..0b2c869 100644
--- a/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
+++ b/src/eu/equalparts/cardbase/cli/CardbaseCLI.java
@@ -38,7 +38,7 @@ public final class CardbaseCLI {
/**
* Location of the help file.
*/
- static final String HELP_FILE_PATH = "/help";
+ static final String HELP_FILE_PATH = "/help_en";
/**
* Program version.
*/
@@ -79,7 +79,26 @@ public final class CardbaseCLI {
* @param args the first argument is the cardbase file. Further arguments are ignored.
*/
public static void main(String... args) {
- new CardbaseCLI(args).startInterface();
+ try {
+ new CardbaseCLI(args).startInterface();
+ } catch (JsonParseException e) {
+ System.out.println("Error: poorly formatted cardbase, check the syntax and try again.");
+ // although the problem could also be with the upstream CardSetList json.
+ if (Cardbase.DEBUG) e.printStackTrace();
+ System.exit(1);
+ } catch (JsonMappingException e) {
+ System.out.println("Error: unexpected fields found in cardbase, it may be from an old version?");
+ if (Cardbase.DEBUG) e.printStackTrace();
+ System.exit(1);
+ } catch (IOException e) {
+ System.out.println("Error: something went wrong reading cardbase file, abort...");
+ if (Cardbase.DEBUG) e.printStackTrace();
+ System.exit(1);
+ } catch (IllegalArgumentException e) {
+ System.out.println("Error: the provided file is invalid.");
+ if (Cardbase.DEBUG) e.printStackTrace();
+ System.exit(1);
+ }
}
/**
@@ -88,37 +107,24 @@ public final class CardbaseCLI {
* on the constructed object.
*
* @param args a list of arguments. Only the first argument is used, as a cardbase JSON.
+ * @throws IOException if something goes wrong while reading the provided file.
+ * @throws JsonMappingException if the provided json did not correspond to the expected format.
+ * @throws JsonParseException if the provided file did not contain valid json.
*/
- CardbaseCLI(String... args) {
+ CardbaseCLI(String... args) throws JsonParseException, JsonMappingException, IOException {
System.out.println("Welcome to Cardbase CLI!");
// set debug flag if we are debugging
if (Cardbase.DEBUG) System.out.println("Debug mode is on.");
// make the Cardbase
- if (args != null && args.length > 0) {
+ if (args != null && args.length > 0 && !args[0].isEmpty()) {
cardbaseFile = new File(args[0]);
if (cardbaseFile.exists() && cardbaseFile.isFile() && cardbaseFile.canRead()) {
System.out.println("Loading cardbase from \"" + args[0] + "\".");
- try {
- cardbase = new Cardbase(cardbaseFile);
- } catch (JsonParseException e) {
- System.out.println("Error: poorly formatted cardbase, check the syntax and try again.");
- // although the problem could also be with the upstream CardSetList json.
- if (Cardbase.DEBUG) e.printStackTrace();
- System.exit(1);
- } catch (JsonMappingException e) {
- System.out.println("Error: unexpected fields found in cardbase, it may be from an old version?");
- if (Cardbase.DEBUG) e.printStackTrace();
- System.exit(1);
- } catch (IOException e) {
- System.out.println("Error: something went wrong reading cardbase file, abort...");
- if (Cardbase.DEBUG) e.printStackTrace();
- System.exit(1);
- }
+ cardbase = new Cardbase(cardbaseFile);
} else {
- System.out.println(args[0] + " appears to be an invalid path.");
- System.exit(0);
+ throw new IllegalArgumentException();
}
} else {
System.out.println("No cardbase file was provided, creating a clean cardbase.");
@@ -465,7 +471,7 @@ public final class CardbaseCLI {
*/
String sanitiseFileName(String name) {
// POSIX-compliant valid filename characters
- name = name.replaceAll("[^-_.A-Za-z0-9]", "");
+ name = name.replaceAll("[^-_./A-Za-z0-9]", "");
// extension is not indispensable, but good practice
if (!name.endsWith(".cb")) {
name = name.concat(".cb");
diff --git a/src/eu/equalparts/cardbase/utils/MTGUniverse.java b/src/eu/equalparts/cardbase/utils/MTGUniverse.java
index 7a58c1c..b40e518 100644
--- a/src/eu/equalparts/cardbase/utils/MTGUniverse.java
+++ b/src/eu/equalparts/cardbase/utils/MTGUniverse.java
@@ -40,8 +40,7 @@ public final class MTGUniverse {
/**
* A cache of CardSets to avoid querying the server many times for the same information.
*/
- private static ArrayList<CardSetInformation> cardSets;
-
+ private static List<CardSetInformation> cardSets;
/**
* A cache of {@code FullCardSets} to avoid querying the server many times for the same information.
*/
@@ -110,13 +109,13 @@ public final class MTGUniverse {
/**
* @return a list of all card sets in the form of {@code CardSet} objects.
*/
- public static ArrayList<CardSetInformation> getCardSetList() {
+ public static List<CardSetInformation> getCardSetList() {
// if the list isn't cached, fetch and cache it
if (cardSets == null) {
try {
cardSets = JSON.mapper.readValue(new URL(BASE_DATA_URL + "SetList.json"), new TypeReference<ArrayList<CardSetInformation>>() {});
} catch (Exception e) {
- System.out.println("Error: could not fetch/parse set code list from upstream, loading fallback json...");
+ System.out.println("Error: could not fetch or parse set code list from upstream, using fallback json...");
e.printStackTrace();
try {