aboutsummaryrefslogtreecommitdiff
path: root/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
diff options
context:
space:
mode:
authorAlex-TIMEHACK <[email protected]>2017-07-21 22:14:23 +0100
committerAlex-TIMEHACK <[email protected]>2017-07-21 22:14:23 +0100
commit2c87ba5fdef12cb62d40c5a9d2513ce097ac0aa9 (patch)
treee3733218d0d4633cd11790c222c6a9366f40b1ae /TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
parent5bfa0d8184b94d22c8bd0cff404acae0ef210a3c (diff)
downloadhistacom2-2c87ba5fdef12cb62d40c5a9d2513ce097ac0aa9.tar.gz
histacom2-2c87ba5fdef12cb62d40c5a9d2513ce097ac0aa9.tar.bz2
histacom2-2c87ba5fdef12cb62d40c5a9d2513ce097ac0aa9.zip
A lot of backend work!
Diffstat (limited to 'TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs')
-rw-r--r--TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs27
1 files changed, 25 insertions, 2 deletions
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<Save>(json);
+ try
+ {
+ savedata = Newtonsoft.Json.JsonConvert.DeserializeObject<Save>(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 {