diff options
| author | RogueAI42 <[email protected]> | 2017-07-23 22:11:01 +1000 |
|---|---|---|
| committer | RogueAI42 <[email protected]> | 2017-07-23 22:11:01 +1000 |
| commit | 36931dc9860a6f1f3cf6f7b238dfda3b3c730554 (patch) | |
| tree | 98e163375aa4c5ae750df9f0ff5ded06fb702429 /TimeHACK.Main | |
| parent | bc9623bbdf635cc16cc95f8a86a241a6933a8fdd (diff) | |
| download | histacom2-36931dc9860a6f1f3cf6f7b238dfda3b3c730554.tar.gz histacom2-36931dc9860a6f1f3cf6f7b238dfda3b3c730554.tar.bz2 histacom2-36931dc9860a6f1f3cf6f7b238dfda3b3c730554.zip | |
revert revert... let's see if I can push to my own repo
This reverts commit bc9623bbdf635cc16cc95f8a86a241a6933a8fdd.
Diffstat (limited to 'TimeHACK.Main')
| -rw-r--r-- | TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs index 5ec84be..410d2d6 100644 --- a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs +++ b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs @@ -15,7 +15,7 @@ namespace TimeHACK.SaveDialogs public partial class SaveFileTroubleShooter : Form { public string log; - Save savedata = new Save(); + Save savedata; string json; public SaveFileTroubleShooter() { @@ -43,7 +43,9 @@ namespace TimeHACK.SaveDialogs // Check if the main.save file exists - if (!File.Exists(Path.Combine(SaveSystem.ProfileDirectory, "main.save"))) + string savefile = Path.Combine(SaveSystem.ProfileDirectory, "main.save"); + + if (!File.Exists(savefile)) { WriteToLog("ISSUE FOUND! File main.save doesn't exist"); @@ -58,12 +60,9 @@ namespace TimeHACK.SaveDialogs } else { WriteToLog("File main.save does exist - checking contents"); - // Read the main.save file - json = File.ReadAllText(Path.Combine(SaveSystem.ProfileDirectory, "main.save")); - try { - savedata = Newtonsoft.Json.JsonConvert.DeserializeObject<Save>(json); + savedata = SaveSystem.ReadSave(savefile); } catch { @@ -71,16 +70,18 @@ namespace TimeHACK.SaveDialogs 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")); + string backupfile = Path.Combine(SaveSystem.ProfileDirectory, "main.backup"); - File.Copy(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), Path.Combine(SaveSystem.ProfileDirectory, "main.backup")); + if (Directory.Exists(backupfile)) Directory.Delete(backupfile); + + File.Copy(savefile, backupfile); 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")}"); + WriteToLog($"The corrupt file has been stored in {backupfile}"); EndScan(true); } @@ -108,10 +109,12 @@ namespace TimeHACK.SaveDialogs } } - if (!Directory.Exists(Path.Combine(SaveSystem.ProfileDirectory, "folders"))) + string folderspath = Path.Combine(SaveSystem.ProfileDirectory, "folders"); + + if (!Directory.Exists(folderspath)) { WriteToLog("ISSUE FOUND! Directory 'folders' doesn't exist! Creating one..."); - Directory.CreateDirectory(Path.Combine(SaveSystem.ProfileDirectory, "folders")); + Directory.CreateDirectory(folderspath); SaveSystem.CheckFiles(); } @@ -130,7 +133,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, Newtonsoft.Json.Formatting.Indented)); + SaveSystem.WriteSave(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), savedata); textBox1.Text = log; } else { |
