Commit bd9e207a authored by KingRainbow44's avatar KingRainbow44
Browse files

Remove old config & migrate legacy configs

parent 11161227
package emu.grasscutter; package emu.grasscutter;
import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter.*; import emu.grasscutter.Grasscutter.*;
import emu.grasscutter.game.mail.Mail.*; import emu.grasscutter.game.mail.Mail.*;
import java.io.FileReader;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
...@@ -24,6 +26,15 @@ public final class Configuration { ...@@ -24,6 +26,15 @@ public final class Configuration {
* Attempts to update the server's existing configuration to the latest configuration. * Attempts to update the server's existing configuration to the latest configuration.
*/ */
public static void updateConfig() { public static void updateConfig() {
try { // Check if the server is using a legacy config.
JsonObject configObject = Grasscutter.getGsonFactory()
.fromJson(new FileReader(Grasscutter.configFile), JsonObject.class);
if(!configObject.has("version")) {
Grasscutter.getLogger().info("Updating legacy configuration...");
Grasscutter.saveConfig(null);
}
} catch (Exception ignored) { }
var existing = config.version; var existing = config.version;
var latest = version(); var latest = version();
......
...@@ -43,7 +43,7 @@ public final class Grasscutter { ...@@ -43,7 +43,7 @@ public final class Grasscutter {
private static Language language; private static Language language;
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
private static final File configFile = new File("./config.json"); public static final File configFile = new File("./config.json");
private static int day; // Current day of week. private static int day; // Current day of week.
...@@ -60,6 +60,8 @@ public final class Grasscutter { ...@@ -60,6 +60,8 @@ public final class Grasscutter {
// Load server configuration. // Load server configuration.
config = Grasscutter.loadConfig(); config = Grasscutter.loadConfig();
// Attempt to update configuration.
Configuration.updateConfig();
// Load translation files. // Load translation files.
Grasscutter.loadLanguage(); Grasscutter.loadLanguage();
......
...@@ -11,7 +11,6 @@ import java.util.Map; ...@@ -11,7 +11,6 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import java.util.Locale; import java.util.Locale;
import emu.grasscutter.Config;
import emu.grasscutter.Configuration; import emu.grasscutter.Configuration;
import emu.grasscutter.Grasscutter; import emu.grasscutter.Grasscutter;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
......
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