|
@@ -17,17 +17,18 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
|
|
|
|
private static final Gson GSON = new GsonBuilder().create();
|
|
private static final Gson GSON = new GsonBuilder().create();
|
|
private static final Jankson JANKSON = Jankson.builder().build();
|
|
private static final Jankson JANKSON = Jankson.builder().build();
|
|
- private final File configFile, oldConfigFile;
|
|
|
|
|
|
+ private final File configFile, veryOldConfigFile, oldConfigFile;
|
|
private ConfigObject config;
|
|
private ConfigObject config;
|
|
private boolean craftableOnly;
|
|
private boolean craftableOnly;
|
|
|
|
|
|
public ConfigManager() {
|
|
public ConfigManager() {
|
|
- this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json");
|
|
|
|
- this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json");
|
|
|
|
|
|
+ this.veryOldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json");
|
|
|
|
+ this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json");
|
|
|
|
+ this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json5");
|
|
this.craftableOnly = false;
|
|
this.craftableOnly = false;
|
|
try {
|
|
try {
|
|
loadConfig();
|
|
loadConfig();
|
|
- RoughlyEnoughItemsCore.LOGGER.info("REI: Config is loaded.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.info("[REI] Config is loaded.");
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
@@ -37,7 +38,7 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
public void saveConfig() throws IOException {
|
|
public void saveConfig() throws IOException {
|
|
configFile.getParentFile().mkdirs();
|
|
configFile.getParentFile().mkdirs();
|
|
if (!configFile.exists() && !configFile.createNewFile()) {
|
|
if (!configFile.exists() && !configFile.createNewFile()) {
|
|
- RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config.");
|
|
config = new ConfigObject();
|
|
config = new ConfigObject();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -52,7 +53,7 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
out.close();
|
|
out.close();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config.");
|
|
config = new ConfigObject();
|
|
config = new ConfigObject();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -61,17 +62,26 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
@Override
|
|
@Override
|
|
public void loadConfig() throws IOException {
|
|
public void loadConfig() throws IOException {
|
|
configFile.getParentFile().mkdirs();
|
|
configFile.getParentFile().mkdirs();
|
|
|
|
+ if (!configFile.exists() && veryOldConfigFile.exists()) {
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.info("[REI] Detected old config file, trying to move it.");
|
|
|
|
+ try {
|
|
|
|
+ Files.move(veryOldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to move config file.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
if (!configFile.exists() && oldConfigFile.exists()) {
|
|
if (!configFile.exists() && oldConfigFile.exists()) {
|
|
- RoughlyEnoughItemsCore.LOGGER.info("REI: Detected old config file, trying to move it.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.info("[REI] Detected old config file, trying to move it.");
|
|
try {
|
|
try {
|
|
Files.move(oldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
Files.move(oldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to move config file.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to move config file.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (!configFile.exists() || !configFile.canRead()) {
|
|
if (!configFile.exists() || !configFile.canRead()) {
|
|
- RoughlyEnoughItemsCore.LOGGER.warn("REI: Config not found! Creating one.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.warn("[REI] Config not found! Creating one.");
|
|
config = new ConfigObject();
|
|
config = new ConfigObject();
|
|
saveConfig();
|
|
saveConfig();
|
|
return;
|
|
return;
|
|
@@ -80,14 +90,14 @@ public class ConfigManager implements me.shedaniel.rei.api.ConfigManager {
|
|
try {
|
|
try {
|
|
JsonObject configJson = JANKSON.load(configFile);
|
|
JsonObject configJson = JANKSON.load(configFile);
|
|
String regularized = configJson.toJson(false, false, 0);
|
|
String regularized = configJson.toJson(false, false, 0);
|
|
-
|
|
|
|
|
|
+
|
|
config = GSON.fromJson(regularized, ConfigObject.class);
|
|
config = GSON.fromJson(regularized, ConfigObject.class);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
failed = true;
|
|
failed = true;
|
|
}
|
|
}
|
|
if (failed || config == null) {
|
|
if (failed || config == null) {
|
|
- RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load config! Overwriting with default config.");
|
|
|
|
|
|
+ RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to load config! Overwriting with default config.");
|
|
config = new ConfigObject();
|
|
config = new ConfigObject();
|
|
}
|
|
}
|
|
saveConfig();
|
|
saveConfig();
|