Commit bd9e207a authored by KingRainbow44's avatar KingRainbow44
Browse files

Remove old config & migrate legacy configs

parent 11161227
package emu.grasscutter;
import com.google.gson.JsonObject;
import emu.grasscutter.Grasscutter.*;
import emu.grasscutter.game.mail.Mail.*;
import java.io.FileReader;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Locale;
......@@ -24,7 +26,16 @@ public final class Configuration {
* Attempts to update the server's existing configuration to the latest configuration.
*/
public static void updateConfig() {
var existing = config.version;
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 latest = version();
if(existing == latest)
......
......@@ -43,7 +43,7 @@ public final class Grasscutter {
private static Language language;
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.
......@@ -60,6 +60,8 @@ public final class Grasscutter {
// Load server configuration.
config = Grasscutter.loadConfig();
// Attempt to update configuration.
Configuration.updateConfig();
// Load translation files.
Grasscutter.loadLanguage();
......
......@@ -11,7 +11,6 @@ import java.util.Map;
import java.util.Random;
import java.util.Locale;
import emu.grasscutter.Config;
import emu.grasscutter.Configuration;
import emu.grasscutter.Grasscutter;
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