diff --git a/src/main/java/land/chipmunk/chipmunkbot/Main.java b/src/main/java/land/chipmunk/chipmunkbot/Main.java index df79145..c97dbad 100644 --- a/src/main/java/land/chipmunk/chipmunkbot/Main.java +++ b/src/main/java/land/chipmunk/chipmunkbot/Main.java @@ -21,10 +21,8 @@ import com.google.gson.JsonParser; import com.google.gson.Gson; public class Main { - private static final File CONFIG_FILE = new File("config.json"); - - private static JsonObject getConfig () throws Exception { - if (!CONFIG_FILE.exists()) { + private static JsonObject getConfig (File file) throws Exception { + if (!file.exists()) { // Read the default config InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default_config.json"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); @@ -36,7 +34,7 @@ public class Main { String defaultConfig = stringBuilder.toString(); // Write the default config - BufferedWriter configWriter = new BufferedWriter(new FileWriter(CONFIG_FILE)); + BufferedWriter configWriter = new BufferedWriter(new FileWriter(file)); configWriter.write(defaultConfig); configWriter.close(); @@ -46,7 +44,7 @@ public class Main { return JsonParser.parseString(defaultConfig).getAsJsonObject(); } - InputStream opt = new FileInputStream(CONFIG_FILE); + InputStream opt = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(opt)); return JsonParser.parseReader(reader).getAsJsonObject(); @@ -64,7 +62,7 @@ public class Main { JsonObject config = null; try { - config = getConfig(); + config = getConfig(new File(arguments.length > 0 ? arguments[0] : "config.json")); } catch (Exception exception) { exception.printStackTrace(); System.exit(1);