diff options
author | DeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com> | 2022-08-14 12:24:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-14 17:24:38 +0700 |
commit | e18629af6aee276b0be6cec473e4099cca9100f1 (patch) | |
tree | 39fc264f55b0db96d8794d0a59a4fd19bb53b5db /src/main/java/cc/polyfrost/oneconfig/config | |
parent | 67a78a550c9d87715b834b4615662cc2d9e65bed (diff) | |
download | OneConfig-e18629af6aee276b0be6cec473e4099cca9100f1.tar.gz OneConfig-e18629af6aee276b0be6cec473e4099cca9100f1.tar.bz2 OneConfig-e18629af6aee276b0be6cec473e4099cca9100f1.zip |
fix: fix profile init (#92)
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config')
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/config/Config.java | 17 | ||||
-rw-r--r-- | src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java | 22 |
2 files changed, 30 insertions, 9 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java index 7c3b7ed..eb74d2a 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java @@ -37,7 +37,6 @@ import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; import cc.polyfrost.oneconfig.config.gson.NonProfileSpecificExclusionStrategy; import cc.polyfrost.oneconfig.config.gson.ProfileExclusionStrategy; import cc.polyfrost.oneconfig.gui.elements.config.ConfigKeyBind; -import cc.polyfrost.oneconfig.internal.config.profiles.Profiles; import cc.polyfrost.oneconfig.gui.OneConfigGui; import cc.polyfrost.oneconfig.gui.elements.config.ConfigPageButton; import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; @@ -91,7 +90,7 @@ public class Config { public void initialize() { boolean migrate = false; - if (Profiles.getProfileFile(configFile).exists()) load(); + if (ConfigUtils.getProfileFile(configFile).exists()) load(); else if (mod.migrator != null) migrate = true; else save(); mod.config = this; @@ -101,7 +100,7 @@ public class Config { } public void reInitialize() { - if (Profiles.getProfileFile(configFile).exists()) load(); + if (ConfigUtils.getProfileFile(configFile).exists()) load(); else save(); } @@ -109,14 +108,14 @@ public class Config { * Save current config to file */ public void save() { - Profiles.getProfileFile(configFile).getParentFile().mkdirs(); - Profiles.getNonProfileSpecificDir(configFile).getParentFile().mkdirs(); - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { + ConfigUtils.getProfileFile(configFile).getParentFile().mkdirs(); + ConfigUtils.getNonProfileSpecificFile(configFile).getParentFile().mkdirs(); + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(ConfigUtils.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { writer.write(gson.toJson(this)); } catch (Exception e) { e.printStackTrace(); } - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(Profiles.getNonProfileSpecificDir(configFile).toPath()), StandardCharsets.UTF_8))) { + try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(ConfigUtils.getNonProfileSpecificFile(configFile).toPath()), StandardCharsets.UTF_8))) { writer.write(nonProfileSpecificGson.toJson(this)); } catch (Exception e) { e.printStackTrace(); @@ -127,12 +126,12 @@ public class Config { * Load file and overwrite current values */ public void load() { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(ConfigUtils.getProfileFile(configFile).toPath()), StandardCharsets.UTF_8))) { deserializePart(JsonUtils.PARSER.parse(reader).getAsJsonObject(), this); } catch (Exception e) { e.printStackTrace(); } - try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Profiles.getNonProfileSpecificDir(configFile).toPath()), StandardCharsets.UTF_8))) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(ConfigUtils.getNonProfileSpecificFile(configFile).toPath()), StandardCharsets.UTF_8))) { deserializePart(JsonUtils.PARSER.parse(reader).getAsJsonObject(), this); } catch (Exception e) { e.printStackTrace(); diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java index 69235f8..e050899 100644 --- a/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java +++ b/src/main/java/cc/polyfrost/oneconfig/config/core/ConfigUtils.java @@ -35,9 +35,11 @@ import cc.polyfrost.oneconfig.config.elements.OptionSubcategory; import cc.polyfrost.oneconfig.config.migration.Migrator; import cc.polyfrost.oneconfig.gui.elements.config.*; import cc.polyfrost.oneconfig.internal.config.annotations.Option; +import cc.polyfrost.oneconfig.internal.config.profiles.Profiles; import com.google.gson.FieldAttributes; import org.jetbrains.annotations.Nullable; +import java.io.File; import java.lang.annotation.Annotation; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -187,4 +189,24 @@ public class ConfigUtils { } catch (Exception ignored) { } } + + public static String getCurrentProfile() { + return Profiles.getCurrentProfile(); + } + + public static File getProfileDir() { + return Profiles.getProfileDir(); + } + + public static File getNonSpecificProfileDir() { + return Profiles.nonProfileSpecificDir; + } + + public static File getProfileFile(String file) { + return Profiles.getProfileFile(file); + } + + public static File getNonProfileSpecificFile(String file) { + return Profiles.getNonProfileSpecificFile(file); + } } |