private UserProfileData LoadLocalData() { StreamReader reader = null; UserProfileData data = null; try { reader = new StreamReader(Filepath); data = JsonConvert.DeserializeObject <UserProfileData>(reader.ReadToEnd()); } catch (Exception e) { Debug.LogWarning(e.Message); } finally { if (reader != null) { reader.Close(); } } return(data); }
public void Load() { bool isSuccess = false; if (!File.Exists(Filepath)) { CreateNewUserProfile(); Debug.Log("Creating new user profile."); } else { try { userProfileData = LoadLocalData(); userProfileData.LastTimeOpen = DateTime.UtcNow; isSuccess = true; //BackupLocalData(); } catch (Exception e) { OnUserProfileEvent(new UserProfileEvent(UserProfileEventType.UserProfileError)); Debug.Log("Could not load UserProfileData. " + e.Message); if (File.Exists(Filepath + ".corrupted")) { File.Delete(Filepath + ".corrupted"); } File.Move(Filepath, Filepath + ".corrupted"); CreateNewUserProfile(); } if (isSuccess) { OnUserProfileEvent(new UserProfileEvent(UserProfileEventType.UserProfileLoaded)); } } }