Errors loading conf.json are handled better now, allowing Factions to continue on to loading board.json instead of losing it

Also, the bad conf.json file is backed up to conf.json_bad so it can potentially be recovered
This commit is contained in:
Brettflan 2012-01-13 05:48:03 -06:00
parent 47ba56de9e
commit 8027e87078

View File

@ -86,6 +86,13 @@ public class Persist {
if (loaded == null) if (loaded == null)
{ {
p.log(Level.WARNING, "Using default as I failed to load: "+file); p.log(Level.WARNING, "Using default as I failed to load: "+file);
// backup bad file, so user can attempt to recover their changes from it
File backup = new File(file.getPath()+"_bad");
if (backup.exists()) backup.delete();
p.log(Level.WARNING, "Backing up copy of bad file to: "+backup);
file.renameTo(backup);
return def; return def;
} }
@ -129,9 +136,17 @@ public class Persist {
return null; return null;
} }
T instance = p.gson.fromJson(content, clazz); try
{
T instance = p.gson.fromJson(content, clazz);
return instance;
}
catch (Exception ex)
{ // output the error message rather than full stack trace; error parsing the file, most likely
p.log(Level.WARNING, ex.getMessage());
}
return instance; return null;
} }