Fix up some config file handling to be even more resilient.

This commit is contained in:
Christian 2012-09-24 23:15:36 -04:00
parent 93e7ac7b55
commit 8c74d81103

View file

@ -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();