From 5b9548c63a5cbea3dd4dd673a217afc5977a26a4 Mon Sep 17 00:00:00 2001 From: kyoko12 Date: Fri, 13 May 2022 14:10:02 +0200 Subject: [PATCH] Don't silently delete config.json if there is an error. --- .../java/emu/grasscutter/Grasscutter.java | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 2af2415ab..af8a759a5 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -153,16 +153,22 @@ public final class Grasscutter { * Attempts to load the configuration from a file. */ 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)) { config = gson.fromJson(file, ConfigContainer.class); - } catch (Exception exception) { - Grasscutter.saveConfig(null); - config = new ConfigContainer(); - } catch (Error error) { - // Occurred probably from an outdated config file. - Grasscutter.saveConfig(null); - config = new ConfigContainer(); - } + } + catch (Exception exception) { + 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."); + System.exit(1); + } } public static void loadLanguage() {