From 2c87ba5fdef12cb62d40c5a9d2513ce097ac0aa9 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Fri, 21 Jul 2017 22:14:23 +0100 Subject: A lot of backend work! --- .../SaveDialogs/SaveFileTroubleShooter.cs | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs') diff --git a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs index bcd60d1..5ec84be 100644 --- a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs +++ b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs @@ -61,7 +61,30 @@ namespace TimeHACK.SaveDialogs // Read the main.save file json = File.ReadAllText(Path.Combine(SaveSystem.ProfileDirectory, "main.save")); - savedata = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + try + { + savedata = Newtonsoft.Json.JsonConvert.DeserializeObject(json); + + } catch + { + WriteToLog("ISSUE FOUND! File main.save is unreadable"); + + WriteToLog("Sorry, there is no repairing it easily, your data will be lost"); + + if (Directory.Exists(Path.Combine(SaveSystem.ProfileDirectory, "main.backup"))) Directory.Delete(Path.Combine(SaveSystem.ProfileDirectory, "main.backup")); + + File.Copy(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), Path.Combine(SaveSystem.ProfileDirectory, "main.backup")); + SaveSystem.NewGame(); + + // Make sure the username is set + + SaveSystem.CurrentSave.Username = SaveSystem.ProfileName; + + WriteToLog($"The corrupt file has been stored in {Path.Combine(SaveSystem.ProfileDirectory, "main.backup")}"); + + EndScan(true); + } + // Check the values @@ -107,7 +130,7 @@ namespace TimeHACK.SaveDialogs // Set the main.save file to the resolved one - File.WriteAllText(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), Newtonsoft.Json.JsonConvert.SerializeObject(savedata)); + File.WriteAllText(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), Newtonsoft.Json.JsonConvert.SerializeObject(savedata, Newtonsoft.Json.Formatting.Indented)); textBox1.Text = log; } else { -- cgit v1.2.3