mirror of
https://github.com/GTNewHorizons/MouseTweaks.git
synced 2026-11-19 03:39:10 +00:00
Fix issues with importing old configs (#8)
* add more debug logging * try this * print statements now * Dont import old configs * Make it static instead
This commit is contained in:
1 parent
aed68115b5
commit
8bc9d479df
2 files changed
+8
-50
No files matched your search
@@ -1,60 +1,21 @@
|
||||
package yalter.mousetweaks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import yalter.mousetweaks.config.MTConfig;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class Config {
|
||||
|
||||
private File file;
|
||||
public static void handleOldConfig(File file) {
|
||||
if (!file.exists()) return;
|
||||
|
||||
public Config(File fileName) {
|
||||
this.file = fileName;
|
||||
}
|
||||
|
||||
public boolean hasOldConfig() {
|
||||
try {
|
||||
FileReader reader = new FileReader(this.file);
|
||||
Properties tempProps = new Properties();
|
||||
tempProps.load(reader);
|
||||
return !tempProps.containsKey("general");
|
||||
if (Files.readAllLines(file.toPath()).stream().noneMatch(str -> str.contains("general"))) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
return true; // assume yes if it failed for whatever reason
|
||||
Constants.LOGGER.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void importOldConfig() {
|
||||
try {
|
||||
FileReader reader = new FileReader(this.file);
|
||||
Properties tempProps = new Properties();
|
||||
tempProps.load(reader);
|
||||
|
||||
if (tempProps.containsKey("RMBTweak"))
|
||||
MTConfig.RMBTweak = Objects.equals(tempProps.get("RMBTweak").toString(), "1");
|
||||
|
||||
if (tempProps.containsKey("LMBTweakWithItem"))
|
||||
MTConfig.LMBTweakWithItem = Objects.equals(tempProps.get("LMBTweakWithItem").toString(), "1");
|
||||
|
||||
if (tempProps.containsKey("LMBTweakWithoutItem"))
|
||||
MTConfig.LMBTweakWithoutItem = Objects.equals(tempProps.get("LMBTweakWithoutItem").toString(), "1");
|
||||
|
||||
if (tempProps.containsKey("WheelTweak"))
|
||||
MTConfig.WheelTweak = Objects.equals(tempProps.get("WheelTweak").toString(), "1");
|
||||
|
||||
if (tempProps.containsKey("WheelSearchOrder"))
|
||||
MTConfig.WheelSearchOrder = Integer.parseInt(tempProps.get("WheelSearchOrder").toString());
|
||||
|
||||
if (tempProps.containsKey("WheelScrollDirection"))
|
||||
MTConfig.WheelScrollDirection = Integer.parseInt(tempProps.get("WheelScrollDirection").toString());
|
||||
|
||||
if (tempProps.containsKey("ScrollItemScaling"))
|
||||
MTConfig.ScrollItemScaling = Integer.parseInt(tempProps.get("ScrollItemScaling").toString());
|
||||
|
||||
file.renameTo(new File(file.getPath() + ".bak"));
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,7 @@ public class MouseTweaksForge {
|
||||
public void preinit(FMLPreInitializationEvent event) {
|
||||
if (event.getSide().isClient()) {
|
||||
try {
|
||||
Config oldConfig = new Config(event.getSuggestedConfigurationFile());
|
||||
if (oldConfig.hasOldConfig()) {
|
||||
oldConfig.importOldConfig();
|
||||
}
|
||||
Config.handleOldConfig(event.getSuggestedConfigurationFile());
|
||||
ConfigurationManager.registerConfig(MTConfig.class);
|
||||
ConfigurationManager.registerBus();
|
||||
} catch (ConfigException e) {
|
||||
|
||||
Reference in new issue
Block a user