From 316b7739bd1f2e19ba67d7fd6302b8ec0c8fa75a Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sat, 10 Jun 2017 12:22:50 +0100 Subject: 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! --- .../SaveDialogs/SaveFileTroubleShooter.Designer.cs | 147 +++++++++++++++++++++ .../SaveDialogs/SaveFileTroubleShooter.cs | 119 +++++++++++++++++ .../SaveDialogs/SaveFileTroubleShooter.resx | 120 +++++++++++++++++ 3 files changed, 386 insertions(+) create mode 100644 TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.Designer.cs create mode 100644 TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.cs create mode 100644 TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.resx (limited to 'TimeHACK.Main/SaveDialogs') diff --git a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.Designer.cs b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.Designer.cs new file mode 100644 index 0000000..a242366 --- /dev/null +++ b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.Designer.cs @@ -0,0 +1,147 @@ +namespace TimeHACK.SaveDialogs +{ + partial class SaveFileTroubleShooter + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.label1 = new System.Windows.Forms.Label(); + this.pnlResolved = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.textBox1 = new System.Windows.Forms.TextBox(); + this.panel2 = new System.Windows.Forms.Panel(); + this.btnClose = new System.Windows.Forms.Button(); + this.pnlResolved.SuspendLayout(); + this.panel2.SuspendLayout(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(12, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(393, 20); + this.label1.TabIndex = 0; + this.label1.Text = "Please wait while we check the state of your Save file..."; + // + // pnlResolved + // + this.pnlResolved.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.pnlResolved.Controls.Add(this.textBox1); + this.pnlResolved.Controls.Add(this.label3); + this.pnlResolved.Controls.Add(this.label2); + this.pnlResolved.Location = new System.Drawing.Point(12, 38); + this.pnlResolved.Name = "pnlResolved"; + this.pnlResolved.Size = new System.Drawing.Size(589, 146); + this.pnlResolved.TabIndex = 1; + this.pnlResolved.Visible = false; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.Location = new System.Drawing.Point(8, 11); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(210, 20); + this.label2.TabIndex = 0; + this.label2.Text = "The issue has been resolved"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(9, 31); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(24, 13); + this.label3.TabIndex = 2; + this.label3.Text = "log:"; + // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(10, 55); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ReadOnly = true; + this.textBox1.Size = new System.Drawing.Size(567, 79); + this.textBox1.TabIndex = 3; + // + // panel2 + // + this.panel2.BackColor = System.Drawing.SystemColors.ControlDark; + this.panel2.Controls.Add(this.btnClose); + this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom; + this.panel2.Location = new System.Drawing.Point(0, 217); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(612, 30); + this.panel2.TabIndex = 2; + // + // btnClose + // + this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnClose.Location = new System.Drawing.Point(526, 4); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(75, 23); + this.btnClose.TabIndex = 0; + this.btnClose.Text = "Close"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // SaveFileTroubleShooter + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(612, 247); + this.Controls.Add(this.panel2); + this.Controls.Add(this.pnlResolved); + this.Controls.Add(this.label1); + this.Name = "SaveFileTroubleShooter"; + this.Text = "Save File Troubleshooter"; + this.Load += new System.EventHandler(this.SaveFileTroubleShooter_Load); + this.pnlResolved.ResumeLayout(false); + this.pnlResolved.PerformLayout(); + this.panel2.ResumeLayout(false); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Panel pnlResolved; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Button btnClose; + } +} \ No newline at end of file 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(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(); + } + + if (savedata.ExperiencedStories == null) + { + WriteToLog("ISSUE FOUND! Data for ExperiencedStories is null! Giving default value..."); + savedata.ExperiencedStories = new List(); + } + } + + 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; + } + } + } +} diff --git a/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.resx b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/TimeHACK.Main/SaveDialogs/SaveFileTroubleShooter.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file -- cgit v1.2.3