Commit d4eb686f authored by kyoko12's avatar kyoko12 Committed by Melledy
Browse files

Don't silently delete config.json if there is an error.

parent 395da1eb
...@@ -153,15 +153,21 @@ public final class Grasscutter { ...@@ -153,15 +153,21 @@ public final class Grasscutter {
* Attempts to load the configuration from a file. * Attempts to load the configuration from a file.
*/ */
public static void loadConfig() { public static void loadConfig() {
// Check if config.json exists. If not, we generate a new config.
if (!configFile.exists()) {
getLogger().info("config.json could not be found. Generating a default configuration ...");
config = new ConfigContainer();
Grasscutter.saveConfig(config);
return;
}
// If the file already exists, we attempt to load it.
try (FileReader file = new FileReader(configFile)) { try (FileReader file = new FileReader(configFile)) {
config = gson.fromJson(file, ConfigContainer.class); config = gson.fromJson(file, ConfigContainer.class);
} catch (Exception exception) { }
Grasscutter.saveConfig(null); catch (Exception exception) {
config = new ConfigContainer(); getLogger().error("There was an error while trying to load the configuration from config.json. Please make sure that there are no syntax errors. If you want to start with a default configuration, delete your existing config.json.");
} catch (Error error) { System.exit(1);
// Occurred probably from an outdated config file.
Grasscutter.saveConfig(null);
config = new ConfigContainer();
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment