aboutsummaryrefslogtreecommitdiff
path: root/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
diff options
context:
space:
mode:
authorlempamo <[email protected]>2017-06-10 15:23:05 -0400
committerlempamo <[email protected]>2017-06-10 15:23:05 -0400
commit46cca8051d340398bcab1f18d76d1650a746a5b3 (patch)
tree34f2ef3902964b428a9ed9a1ee61f5f1d8b4b4b0 /TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
parent0344f0f2ba9cc1dea9644c97b69f689e2e516c90 (diff)
parentf7a0abb9c8a8fb4235b185d8bf4ea725d53270fe (diff)
downloadhistacom2-46cca8051d340398bcab1f18d76d1650a746a5b3.tar.gz
histacom2-46cca8051d340398bcab1f18d76d1650a746a5b3.tar.bz2
histacom2-46cca8051d340398bcab1f18d76d1650a746a5b3.zip
Merge remote-tracking branch 'refs/remotes/TimeHACKDevs/master'
Diffstat (limited to 'TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs')
-rw-r--r--TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs119
1 files changed, 119 insertions, 0 deletions
diff --git a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
new file mode 100644
index 0000000..eb79543
--- /dev/null
+++ b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using TimeHACK.Engine;
+using System.IO;
+
+namespace TimeHACK.SaveDialogs
+{
+ public partial class SaveFileTroubleShooter : Form
+ {
+ public String log;
+ Save savedata = new Save();
+ String json;
+ public SaveFileTroubleShooter()
+ {
+ InitializeComponent();
+ }
+
+ private void btnClose_Click(object sender, EventArgs e)
+ {
+ this.Close();
+ }
+
+ private void SaveFileTroubleShooter_Load(object sender, EventArgs e)
+ {
+ BeginScan();
+ }
+
+ void WriteToLog(String toWrite)
+ {
+ log += toWrite + Environment.NewLine;
+ }
+
+ void BeginScan()
+ {
+ WriteToLog("Started scanning profile: " + SaveSystem.ProfileName);
+
+ // Check if the main.save file exists
+
+ if (!File.Exists(Path.Combine(SaveSystem.ProfileDirectory, "main.save")))
+ {
+ WriteToLog("ISSUE FOUND! File main.save doesn't exist");
+
+ WriteToLog("Creating one...");
+
+ SaveSystem.NewGame();
+
+ WriteToLog("Created one!");
+
+ EndScan(true);
+ return;
+ } else {
+ WriteToLog("File main.save does exist - checking contents");
+
+ // Read the main.save file
+ json = File.ReadAllText(Path.Combine(SaveSystem.ProfileDirectory, "main.save"));
+
+ savedata = Newtonsoft.Json.JsonConvert.DeserializeObject<Save>(json);
+
+ // Check the values
+
+ if (savedata.CurrentOS == null || savedata.CurrentOS == "")
+ {
+ WriteToLog("ISSUE FOUND! Data for CurrentOS is null! Giving default value...");
+ savedata.CurrentOS = "95";
+ EndScan(true);
+ }
+
+ if (savedata.ExperiencedStories == null)
+ {
+ WriteToLog("ISSUE FOUND! Data for ExperiencedStories is null! Giving default value...");
+ savedata.ExperiencedStories = new List<string>();
+ }
+
+ if (savedata.ExperiencedStories == null)
+ {
+ WriteToLog("ISSUE FOUND! Data for ExperiencedStories is null! Giving default value...");
+ savedata.ExperiencedStories = new List<string>();
+ }
+ }
+
+ if (!Directory.Exists(Path.Combine(SaveSystem.ProfileDirectory, "folders")))
+ {
+ WriteToLog("ISSUE FOUND! Directory 'folders' doesn't exist! Creating one...");
+ Directory.CreateDirectory(Path.Combine(SaveSystem.ProfileDirectory, "folders"));
+ SaveSystem.CheckFiles();
+ }
+
+
+ }
+
+ void EndScan(Boolean successful)
+ {
+ pnlResolved.Visible = true;
+ if (successful == true)
+ {
+ label2.Text = "The issue has been resolved.";
+ // Set CurrentSave to the resolved one
+
+ SaveSystem.CurrentSave = savedata;
+
+ // Set the main.save file to the resolved one
+
+ File.WriteAllText(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), Newtonsoft.Json.JsonConvert.SerializeObject(savedata));
+
+ textBox1.Text = log;
+ } else {
+ label2.Text = "The issue has not been resolved, sorry";
+ textBox1.Text = log;
+ }
+ }
+ }
+}