public static UserPrefs LoadOrMakeNew(string fileName)
{
if (string.IsNullOrEmpty(fileName))
return null;
UserPrefs userPrefs = null;
if(RobustFile.Exists(fileName))
{
try
{
userPrefs = JsonConvert.DeserializeObject<UserPrefs>(RobustFile.ReadAllText(fileName));
if (userPrefs == null)
throw new ApplicationException("JsonConvert.DeserializeObject() returned null");
}
catch (Exception e)
{
Logger.WriteEvent("error reading UserPrefs at "+fileName+" "+e.Message);
//otherwise, just give them a new user prefs
userPrefs = null;
}
}
if(userPrefs == null)
userPrefs = new UserPrefs();
userPrefs._filePath = fileName;
userPrefs._loading = false;
return userPrefs;
}