diff options
| -rw-r--r-- | Histacom2.Engine/SaveSystem.cs | 7 | ||||
| -rw-r--r-- | Histacom2.Engine/Template/WinClassic.Designer.cs | 2 | ||||
| -rw-r--r-- | Histacom2.Engine/Template/WinClassic.cs | 66 | ||||
| -rw-r--r-- | Histacom2/SaveDialogs/SaveFileTroubleShooter.Designer.cs | 49 | ||||
| -rw-r--r-- | Histacom2/SaveDialogs/SaveFileTroubleShooter.cs | 135 | ||||
| -rw-r--r-- | Histacom2/TitleScreen.Designer.cs | 2 | ||||
| -rw-r--r-- | Histacom2/TitleScreen.cs | 2 |
7 files changed, 184 insertions, 79 deletions
diff --git a/Histacom2.Engine/SaveSystem.cs b/Histacom2.Engine/SaveSystem.cs index 7da916b..b8c619e 100644 --- a/Histacom2.Engine/SaveSystem.cs +++ b/Histacom2.Engine/SaveSystem.cs @@ -28,6 +28,13 @@ namespace Histacom2.Engine public static Theme currentTheme { get; set; } + public static bool IsBinarySave = +#if BINARY_SAVE + true; +#else + false; +#endif + #if BINARY_SAVE private static readonly byte[] magic = Encoding.UTF8.GetBytes("THSv"); private static readonly IOrderedEnumerable<System.Reflection.PropertyInfo> properties = typeof(Save).GetProperties().OrderBy(p => (p.GetCustomAttributes(typeof(OrderAttribute), false).SingleOrDefault() as OrderAttribute).Order); diff --git a/Histacom2.Engine/Template/WinClassic.Designer.cs b/Histacom2.Engine/Template/WinClassic.Designer.cs index be76be6..9092609 100644 --- a/Histacom2.Engine/Template/WinClassic.Designer.cs +++ b/Histacom2.Engine/Template/WinClassic.Designer.cs @@ -254,11 +254,13 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(300, 300); this.Controls.Add(this.program); + this.DoubleBuffered = true; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "WinClassic"; this.Text = "WinClassic"; this.Activated += new System.EventHandler(this.WinClassic_Activated); this.Deactivate += new System.EventHandler(this.WinClassic_Deactivate); + this.Paint += new System.Windows.Forms.PaintEventHandler(this.WinClassic_Paint); this.program.ResumeLayout(false); this.programtopbar.ResumeLayout(false); this.programtopbar.PerformLayout(); diff --git a/Histacom2.Engine/Template/WinClassic.cs b/Histacom2.Engine/Template/WinClassic.cs index 4c495bc..67a0322 100644 --- a/Histacom2.Engine/Template/WinClassic.cs +++ b/Histacom2.Engine/Template/WinClassic.cs @@ -18,6 +18,8 @@ namespace Histacom2.Engine.Template public bool resizable = true; public bool closeDisabled = false; public bool isActive = true; + public bool Resizing = false; + public Bitmap ResizingBmp = null; public const int WM_NCLBUTTONDOWN = 0xA1; public const int WM_SYSCOMMAND = 0x0112; @@ -73,6 +75,7 @@ namespace Histacom2.Engine.Template if (e.Button == MouseButtons.Left) { if (resizable) this.Size = new Size(MousePosition.X - this.Location.X, this.Size.Height); + this.Invalidate(); } } @@ -82,6 +85,7 @@ namespace Histacom2.Engine.Template { if (resizable) this.Width = ((this.Width + this.Location.X) - Cursor.Position.X); if (resizable)this.Location = new Point(Cursor.Position.X, this.Location.Y); + this.Invalidate(); } } @@ -90,6 +94,7 @@ namespace Histacom2.Engine.Template if (e.Button == MouseButtons.Left) { if (resizable) this.Size = new Size(this.Size.Width, MousePosition.Y - this.Location.Y); + this.Invalidate(); } } @@ -98,6 +103,7 @@ namespace Histacom2.Engine.Template if (e.Button == MouseButtons.Left) { if (resizable) this.Size = new Size(MousePosition.X - this.Location.X, MousePosition.Y - this.Location.Y); + this.Invalidate(); } } @@ -108,6 +114,7 @@ namespace Histacom2.Engine.Template if (resizable) this.Width = ((this.Width + this.Location.X) - Cursor.Position.X); if (resizable) this.Height = (Cursor.Position.Y - this.Location.Y); if (resizable) this.Location = new Point(Cursor.Position.X, this.Location.Y); + this.Invalidate(); } } @@ -119,6 +126,7 @@ namespace Histacom2.Engine.Template if (resizable) this.Location = new Point(Cursor.Position.X, this.Location.Y); if (resizable) this.Height = ((this.Height + this.Location.Y) - Cursor.Position.Y); if (resizable) this.Location = new Point(this.Location.X, Cursor.Position.Y); + this.Invalidate(); } } @@ -128,6 +136,7 @@ namespace Histacom2.Engine.Template { if(resizable) this.Height = ((this.Height + this.Location.Y) - Cursor.Position.Y); if(resizable) this.Location = new Point(this.Location.X, Cursor.Position.Y); + this.Invalidate(); } } @@ -138,6 +147,48 @@ namespace Histacom2.Engine.Template if (resizable) this.Width = (Cursor.Position.X - this.Location.X); if (resizable) this.Height = ((this.Location.Y - Cursor.Position.Y) + this.Height); if (resizable) this.Location = new Point(this.Location.X, Cursor.Position.Y); + this.Update(); + } + } + + private void WinClassic_Paint(object sender, PaintEventArgs e) + { + if (Resizing) + { + MessageBox.Show("HIT IT"); + e.Graphics.DrawImage(ResizingBmp, 0, 0, this.Width, this.Height); + } + } + + private void border_MouseDown(object sender, MouseEventArgs e) + { + var cursor = this.PointToClient(Cursor.Position); + + if (topleftcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF004, 0); + else if (toprightcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF005, 0); + else if (bottomleftcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF007, 0); + else if (bottomrightcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF008, 0); + + else if (top.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF003, 0); + else if (left.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF001, 0); + else if (right.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF002, 0); + else if (bottom.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF006, 0); + + /* Now we need to fix this weird artificating! + To lempamo: This is probably the best way I can think of the fix this + I can take a picture of the window as it is and then just draw that + and once you mouseup I will go back to the actual form + I'll have a boolean called Resizing which tells the form on paint to just draw the overlay! + */ + + var screen = Screen.PrimaryScreen; + + using (var bitmap = new Bitmap(this.Bounds.Width, this.Bounds.Height)) + using (var graphics = Graphics.FromImage(bitmap)) + { + graphics.CopyFromScreen(new Point(this.Bounds.Left, this.Bounds.Top), new Point(0, 0), this.Bounds.Size); + Resizing = true; + ResizingBmp = bitmap; } } @@ -216,20 +267,5 @@ namespace Histacom2.Engine.Template var c = (Button)sender; c.UseVisualStyleBackColor = true; } - - private void border_MouseDown(object sender, EventArgs e) - { - var cursor = this.PointToClient(Cursor.Position); - - if (topleftcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF004, 0); - else if (toprightcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF005, 0); - else if (bottomleftcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF007, 0); - else if (bottomrightcorner.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF008, 0); - - else if (top.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF003, 0); - else if (left.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF001, 0); - else if (right.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF002, 0); - else if (bottom.ClientRectangle.Contains(cursor)) SendMessage(Handle, WM_SYSCOMMAND, 0xF006, 0); - } } } diff --git a/Histacom2/SaveDialogs/SaveFileTroubleShooter.Designer.cs b/Histacom2/SaveDialogs/SaveFileTroubleShooter.Designer.cs index 4c11576..85c04fb 100644 --- a/Histacom2/SaveDialogs/SaveFileTroubleShooter.Designer.cs +++ b/Histacom2/SaveDialogs/SaveFileTroubleShooter.Designer.cs @@ -30,9 +30,9 @@ { 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.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); this.panel2 = new System.Windows.Forms.Panel(); this.btnClose = new System.Windows.Forms.Button(); this.pnlResolved.SuspendLayout(); @@ -59,19 +59,22 @@ 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.Size = new System.Drawing.Size(589, 275); this.pnlResolved.TabIndex = 1; this.pnlResolved.Visible = false; // - // label2 + // textBox1 // - 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"; + 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.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.textBox1.Size = new System.Drawing.Size(567, 208); + this.textBox1.TabIndex = 3; // // label3 // @@ -82,24 +85,22 @@ this.label3.TabIndex = 2; this.label3.Text = "log:"; // - // textBox1 + // label2 // - 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; + 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"; // // panel2 // - this.panel2.BackColor = System.Drawing.SystemColors.ControlDark; + this.panel2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); 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.Location = new System.Drawing.Point(0, 315); this.panel2.Name = "panel2"; this.panel2.Size = new System.Drawing.Size(612, 30); this.panel2.TabIndex = 2; @@ -119,7 +120,7 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(612, 247); + this.ClientSize = new System.Drawing.Size(612, 345); this.Controls.Add(this.panel2); this.Controls.Add(this.pnlResolved); this.Controls.Add(this.label1); diff --git a/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs b/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs index 9d26762..af105f0 100644 --- a/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs +++ b/Histacom2/SaveDialogs/SaveFileTroubleShooter.cs @@ -43,6 +43,7 @@ namespace Histacom2.SaveDialogs // Check if the main.save file exists string savefile = Path.Combine(SaveSystem.ProfileDirectory, "main.save"); + string oldsavefile = Path.Combine(SaveSystem.ProfileDirectory, "oldmain.save"); if (!File.Exists(savefile)) { @@ -58,54 +59,111 @@ namespace Histacom2.SaveDialogs return; } else { WriteToLog("File main.save does exist - checking contents"); + bool readable = false; try { savedata = SaveSystem.ReadSave(savefile); - + readable = true; } catch { - WriteToLog("ISSUE FOUND! File main.save is unreadable"); + WriteToLog("Save file cannot be read - scanning each line and examining them..."); + // Take a little look at the file? - WriteToLog("Sorry, there is no repairing it easily, your data will be lost"); + // But first let's just create a measure of how the JSON SHOULD look + if (!SaveSystem.IsBinarySave) + { + if (File.Exists(oldsavefile)) File.Delete(oldsavefile); + File.Copy(savefile, oldsavefile); - string backupfile = Path.Combine(SaveSystem.ProfileDirectory, "main.backup"); + SaveSystem.NewGame(); + string[] fileLines = File.ReadAllText(oldsavefile).Split('\n'); + string[] shouldBeLines = File.ReadAllText(savefile).Split('\n'); + int i = 0; - if (Directory.Exists(backupfile)) Directory.Delete(backupfile); + string newJson = ""; - File.Copy(savefile, backupfile); - SaveSystem.NewGame(); + foreach (string element in fileLines) + { + element.Replace("\n", "").Replace("\r", ""); + } - // Make sure the username is set + foreach (string line in fileLines) + { + if (!line.StartsWith("{")) + { + if (!line.StartsWith("}")) + { + try { + // We will attempt to deserialize this line - SaveSystem.CurrentSave.Username = SaveSystem.ProfileName; + Newtonsoft.Json.JsonConvert.DeserializeObject("{" + $"{Environment.NewLine}{line}{Environment.NewLine}" + "}"); - WriteToLog($"The corrupt file has been stored in {backupfile}"); + // It worked! This line is not the problem! - EndScan(true); - } - + newJson += $"{Environment.NewLine}{fileLines[i]}"; - // Check the values + WriteToLog($"The line {fileLines[i]} is fine!"); + } catch { + // If it failed to read this line the this is the line that's causing problems! - if (savedata.CurrentOS == null || savedata.CurrentOS == "") - { - WriteToLog("ISSUE FOUND! Data for CurrentOS is null! Giving default value..."); - savedata.CurrentOS = "95"; - EndScan(true); - } + try { newJson += $"{Environment.NewLine}{shouldBeLines[i]}"; + WriteToLog($"ISSUE FOUND! The line {fileLines[i]} was corrupt - it has been reset to default settings!"); + } catch { WriteToLog($"ISSUE FOUND! A line was unneeded - it has been removed as it should!"); } // The reason I'm catching that is in case someone adds a line at the end of the file or something + } + } + } + i++; + } - if (savedata.ExperiencedStories == null) - { - WriteToLog("ISSUE FOUND! Data for ExperiencedStories is null! Giving default value..."); - savedata.ExperiencedStories = new List<string>(); - } + // After all that let's see if we fixed the file - but first, add the "{" and "}" in! - if (savedata.ThemeName == null || savedata.ThemeName == "") - { - WriteToLog("ISSUE FOUND! Data for ThemeName is null! Giving default value..."); - savedata.ThemeName = "95normal"; + newJson = "{" + $"{Environment.NewLine}{newJson}{Environment.NewLine}" + "}"; + + // Now let's test it + + try + { + savedata = Newtonsoft.Json.JsonConvert.DeserializeObject<Save>(newJson); + + WriteToLog("Save file successfully recovered!"); + + File.WriteAllText(savefile, newJson); + readable = true; + + if (File.Exists(oldsavefile)) File.Delete(oldsavefile); + EndScan(true); + } catch { + // It's unusable... + + 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; + SaveSystem.SaveGame(); + + WriteToLog($"The corrupt file has been stored in {backupfile}"); + + EndScan(true); + } + } } + + + // Check the values if it was readable + + if (readable) CheckValues(); + } string folderspath = Path.Combine(SaveSystem.ProfileDirectory, "folders"); @@ -117,26 +175,29 @@ namespace Histacom2.SaveDialogs SaveSystem.CheckFiles(); } + } + private void CheckValues() + { + foreach (var field in typeof(Save).GetFields()) + { + if (field.GetValue(savedata) is string) if (field.GetValue(savedata).ToString() == null) { field.SetValue(savedata, ""); continue; } + if (field.GetValue(savedata) is Theme) if (field.GetValue(savedata) == null) { field.SetValue(savedata, new Default95Theme()); continue; } + if (field.GetValue(savedata) is List<string>) if (field.GetValue(savedata) == null) { field.SetValue(savedata, new List<string>()); } + } } void EndScan(bool successful) { pnlResolved.Visible = true; + label1.Hide(); 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"; + label2.Text = "The issue has not been resolved, sorry."; textBox1.Text = log; } } diff --git a/Histacom2/TitleScreen.Designer.cs b/Histacom2/TitleScreen.Designer.cs index 07bbc54..e29c283 100644 --- a/Histacom2/TitleScreen.Designer.cs +++ b/Histacom2/TitleScreen.Designer.cs @@ -244,7 +244,7 @@ this.startmenuitems.Name = "startmenuitems"; this.startmenuitems.Padding = new System.Windows.Forms.Padding(1, 2, 0, 0); this.startmenuitems.RenderMode = System.Windows.Forms.ToolStripRenderMode.System; - this.startmenuitems.Size = new System.Drawing.Size(140, 220); + this.startmenuitems.Size = new System.Drawing.Size(140, 239); this.startmenuitems.TabIndex = 0; this.startmenuitems.Text = "StartMenu"; // diff --git a/Histacom2/TitleScreen.cs b/Histacom2/TitleScreen.cs index 851bd19..e29c67c 100644 --- a/Histacom2/TitleScreen.cs +++ b/Histacom2/TitleScreen.cs @@ -207,8 +207,6 @@ namespace Histacom2 } catch { } - - // If VM Mode is not enabled if (vm_mode.Checked != true) |
