aboutsummaryrefslogtreecommitdiff
path: root/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
diff options
context:
space:
mode:
authorAlex-TIMEHACK <[email protected]>2017-06-10 12:22:50 +0100
committerAlex-TIMEHACK <[email protected]>2017-06-10 12:22:50 +0100
commit316b7739bd1f2e19ba67d7fd6302b8ec0c8fa75a (patch)
tree4ed1f7005fb5a9149078f4a0d9953cffce058b2c /TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs
parenta15d2c212ad88efa571c2421bb67629a884eee89 (diff)
downloadhistacom2-316b7739bd1f2e19ba67d7fd6302b8ec0c8fa75a.tar.gz
histacom2-316b7739bd1f2e19ba67d7fd6302b8ec0c8fa75a.tar.bz2
histacom2-316b7739bd1f2e19ba67d7fd6302b8ec0c8fa75a.zip
Done ALOT of tweaks and Save troubleshooter
There is now a save troubleshooter that checks your save files if they can't load! Also, it checks what OS to load on startup of the game!
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;
+ }
+ }
+ }
+}