From 8c74d811036698ecdad4cc09c411f0e85697d78d Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 24 Sep 2012 23:15:36 -0400 Subject: [PATCH] Fix up some config file handling to be even more resilient. --- .../common/ForgeChunkManager.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/common/net/minecraftforge/common/ForgeChunkManager.java b/common/net/minecraftforge/common/ForgeChunkManager.java index 8092a9a83..ccd4d4324 100644 --- a/common/net/minecraftforge/common/ForgeChunkManager.java +++ b/common/net/minecraftforge/common/ForgeChunkManager.java @@ -530,11 +530,25 @@ public class ForgeChunkManager static void loadConfiguration(File configDir) { - Configuration config = new Configuration(new File(configDir,"forgeChunkLoading.cfg"), true); + File cfgFile = new File(configDir,"forgeChunkLoading.cfg"); + Configuration config = new Configuration(cfgFile, true); try { config.categories.clear(); - config.load(); + try + { + config.load(); + } + catch (Exception e) + { + File dest = new File(configDir,"forgeChunkLoading.cfg.bak"); + if (dest.exists()) + { + dest.delete(); + } + cfgFile.renameTo(dest); + FMLLog.log(Level.SEVERE, e, "A critical error occured reading the forgeChunkLoading.cfg file, defaults will be used - the invalid file is backed up at forgeChunkLoading.cfg.bak"); + } config.addCustomCategoryComment("defaults", "Default configuration for forge chunk loading control"); Property maxTicketCount = config.getOrCreateIntProperty("maximumTicketCount", "defaults", 200); maxTicketCount.comment = "The default maximum ticket count for a mod which does not have an override\n" + @@ -577,10 +591,6 @@ public class ForgeChunkManager chunkConstraints.put(mod, modCPT.getInt(25)); } } - catch (Exception e) - { - FMLLog.log(Level.SEVERE, e, "A critical error occured reading the forgeChunkLoading.cfg file, defaults will be used"); - } finally { config.save();