diff options
| author | lempamo <[email protected]> | 2017-08-23 13:38:40 -0400 |
|---|---|---|
| committer | lempamo <[email protected]> | 2017-08-23 13:38:40 -0400 |
| commit | 3306d36ecbc024775972e5cf7971b2a7a70671d0 (patch) | |
| tree | 0a79e67b6723a8c75ffd66c7828bdd0ebb1bf74d /Histacom2/SaveDialogs/SaveFileTroubleShooter.cs | |
| parent | 99fef5c57360f07259fc86f433bed8a9ab59c48e (diff) | |
| download | histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.tar.gz histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.tar.bz2 histacom2-3306d36ecbc024775972e5cf7971b2a7a70671d0.zip | |
Renaming the game!
Diffstat (limited to 'Histacom2/SaveDialogs/SaveFileTroubleShooter.cs')
| -rw-r--r-- | Histacom2/SaveDialogs/SaveFileTroubleShooter.cs | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs b/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs new file mode 100644 index 0000000..f094640 --- /dev/null +++ b/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs @@ -0,0 +1,145 @@ +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 Histacom2.Engine; +using System.IO; + +namespace Histacom2.SaveDialogs +{ + public partial class SaveFileTroubleShooter : Form + { + public string log; + Save savedata; + 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 + + string savefile = Path.Combine(SaveSystem.ProfileDirectory, "main.save"); + + if (!File.Exists(savefile)) + { + 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"); + + try + { + savedata = SaveSystem.ReadSave(savefile); + + } catch + { + WriteToLog("ISSUE FOUND! File main.save is unreadable"); + + WriteToLog("Sorry, there is no repairing it easily, your data will be lost"); + + string backupfile = 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 {backupfile}"); + + EndScan(true); + } + + + // 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.ThemeName == null || savedata.ThemeName == "") + { + WriteToLog("ISSUE FOUND! Data for ThemeName is null! Giving default value..."); + savedata.ThemeName = "95normal"; + } + } + + string folderspath = Path.Combine(SaveSystem.ProfileDirectory, "folders"); + + if (!Directory.Exists(folderspath)) + { + WriteToLog("ISSUE FOUND! Directory 'folders' doesn't exist! Creating one..."); + Directory.CreateDirectory(folderspath); + SaveSystem.CheckFiles(); + } + + + } + + void EndScan(bool 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 + + SaveSystem.WriteSave(Path.Combine(SaveSystem.ProfileDirectory, "main.save"), savedata); + + textBox1.Text = log; + } else { + label2.Text = "The issue has not been resolved, sorry"; + textBox1.Text = log; + } + } + } +} |
