From d5d50c6c205b505ea6f4dcae90b3797ed6c180f7 Mon Sep 17 00:00:00 2001 From: lempamo Date: Sun, 27 Aug 2017 12:25:52 -0400 Subject: better file removal and other smaller things --- Histacom2.Engine/SaveSystem.cs | 56 +++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 23 deletions(-) (limited to 'Histacom2.Engine/SaveSystem.cs') diff --git a/Histacom2.Engine/SaveSystem.cs b/Histacom2.Engine/SaveSystem.cs index ef98c10..5557dca 100644 --- a/Histacom2.Engine/SaveSystem.cs +++ b/Histacom2.Engine/SaveSystem.cs @@ -235,36 +235,46 @@ namespace Histacom2.Engine File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); } - public static void UpgradeFileSystem(string oldOS, string newOS) + public static void RemoveFileFromDirectory(string path, string filename) { - switch (oldOS) + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); + THFileInfo fi = fsfi.Files.Find((THFileInfo f) => { return f.Name == filename; }); + if (fi == null) return; + + fsfi.ByteSize -= fi.ByteSize; + CurrentSave.BytesLeft += fi.ByteSize; + + fsfi.Files.Remove(fi); + string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); + + File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); + } + + public static void UpgradeFileSystem(string newOS) + { + if (newOS == "98" || newOS == "2000" || newOS == "ME") { - case "95": - if (newOS == "98" || newOS == "2000" || newOS == "ME") - { - // We are upgrading from the old WinClassic file System to the new WinClassic filesystem! - // All the above OSes share basically the same file layout! - // (Excluding Documents And Settings) which is 2000 and ME only + // We are upgrading from the old WinClassic file System to the new WinClassic filesystem! + // All the above OSes share basically the same file layout! + // (Excluding Documents And Settings) which is 2000 and ME only - // Add Address Book into existance! + // Add Address Book into existance! - SaveDirectoryInfo(ProfileProgramsDirectory, "Outlook Express", false, "Outlook Express", true); - CreateWindowsFile(Path.Combine(ProfileProgramsDirectory, "Outlook Express"), "WAB.exe", "addressbook", 8, 512); + SaveDirectoryInfo(ProfileProgramsDirectory, "Outlook Express", false, "Outlook Express", true); + CreateWindowsFile(Path.Combine(ProfileProgramsDirectory, "Outlook Express"), "WAB.exe", "addressbook", 8, 512); - // There is no "The Microsoft Network" folder! + // There is no "The Microsoft Network" folder! - if (Directory.Exists(Path.Combine(ProfileProgramsDirectory, "The Microsoft Network"))) Directory.Delete(Path.Combine(ProfileProgramsDirectory, "The Microsoft Network"), true); - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(ProfileProgramsDirectory, "_data.info"))); - foreach (THDirInfo dir in fsfi.SubDirs) - { - if (dir.Name == "The Microsoft Network") - { - fsfi.SubDirs.Remove(dir); - break; - } - } + if (Directory.Exists(Path.Combine(ProfileProgramsDirectory, "The Microsoft Network"))) Directory.Delete(Path.Combine(ProfileProgramsDirectory, "The Microsoft Network"), true); + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(ProfileProgramsDirectory, "_data.info"))); + foreach (THDirInfo dir in fsfi.SubDirs) + { + if (dir.Name == "The Microsoft Network") + { + fsfi.SubDirs.Remove(dir); + break; } - break; + } } } -- cgit v1.2.3 From d31cd4fbce0d51ff2a51ccf40d11613163ed2a46 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Sun, 27 Aug 2017 19:40:33 +0100 Subject: Some tweaks --- Histacom2.Engine/Histacom2.Engine.csproj | 1 + Histacom2.Engine/SaveSystem.cs | 104 ++++++++++++++---- Histacom2/GlobalPrograms/WinClassicNotepad.cs | 2 +- .../Win95Apps/Win95WindowsExplorer.Designer.cs | 121 +++++++++------------ .../OS/Win95/Win95Apps/Win95WindowsExplorer.cs | 89 ++++----------- Histacom2/OS/Win95/Win95Apps/WinClassicWordPad.cs | 2 +- .../Win98/Win98Apps/WinClassicWindowsExplorer.cs | 86 ++++----------- 7 files changed, 185 insertions(+), 220 deletions(-) (limited to 'Histacom2.Engine/SaveSystem.cs') diff --git a/Histacom2.Engine/Histacom2.Engine.csproj b/Histacom2.Engine/Histacom2.Engine.csproj index beb4aa2..37c4489 100644 --- a/Histacom2.Engine/Histacom2.Engine.csproj +++ b/Histacom2.Engine/Histacom2.Engine.csproj @@ -20,6 +20,7 @@ DEBUG;TRACE prompt 4 + x86 pdbonly diff --git a/Histacom2.Engine/SaveSystem.cs b/Histacom2.Engine/SaveSystem.cs index 5557dca..7da916b 100644 --- a/Histacom2.Engine/SaveSystem.cs +++ b/Histacom2.Engine/SaveSystem.cs @@ -207,10 +207,58 @@ namespace Histacom2.Engine public static void UpdateDirectoryInfo(string path, THFileInfo newfile) { - newfile.DOSName = newfile.Name.ToUpper().Replace("*", "").Replace("+", "").Replace(":", "").Replace(";", "").Replace(" ", ""); - if (newfile.DOSName.Contains(".")) + SetDOSName(ref newfile); + + if (File.ReadAllText(Path.Combine(path, "_data.info")).Contains(newfile.DOSName)) return; + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); + fsfi.Files.Add(newfile); + fsfi.ByteSize += newfile.ByteSize; + + string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); + + File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); + } + + public static void RemoveFileFromDirectory(string path, string filename) + { + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); + THFileInfo fi = fsfi.Files.Find((THFileInfo f) => { return f.Name == filename; }); + if (fi == null) return; + + fsfi.ByteSize -= fi.ByteSize; + CurrentSave.BytesLeft += fi.ByteSize; + + fsfi.Files.Remove(fi); + string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); + + File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); + } + + public static void RemoveSubDirFromDirectory(string path, string dirname) + { + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); + THDirInfo di = fsfi.SubDirs.Find((THDirInfo f) => { return f.Name == dirname; }); + if (di == null) return; + + // Find the bytesize of the folder + + FileSystemFolderInfo dirfsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); + + fsfi.ByteSize -= dirfsfi.ByteSize; + CurrentSave.BytesLeft += dirfsfi.ByteSize; + + fsfi.SubDirs.Remove(di); + string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); + + File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); + } + + public static string SetDOSName(ref THFileInfo file) + { + file.DOSName = file.Name.ToUpper().Replace("*", "").Replace("+", "").Replace(":", "").Replace(";", "").Replace(" ", ""); + if (file.DOSName.Contains(".")) { - string[] dos = newfile.DOSName.Split('.'); + string[] dos = file.DOSName.Split('.'); if (dos.Count() > 2) { @@ -221,30 +269,45 @@ namespace Histacom2.Engine dos[1] = dos[1].Substring(0, 3); if (dos[0].Length > 8) dos[0] = dos[0].Substring(0, 6) + "~1"; - newfile.DOSName = dos[0] + "." + dos[1]; + file.DOSName = dos[0] + "." + dos[1]; } - else if (newfile.DOSName.Length > 8) newfile.DOSName = newfile.DOSName.Substring(0, 6) + "~1"; + else if (file.DOSName.Length > 8) file.DOSName = file.DOSName.Substring(0, 6) + "~1"; + return file.DOSName; + } - if (File.ReadAllText(Path.Combine(path, "_data.info")).Contains(newfile.DOSName)) return; + public static void RenameDirectory(string path, string dirname, string newname) + { FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); - fsfi.Files.Add(newfile); - fsfi.ByteSize += newfile.ByteSize; + THDirInfo di = fsfi.SubDirs.Find((THDirInfo f) => { return f.Name == dirname; }); + if (di == null) return; + + THDirInfo newDi = di; + + newDi.Name = newname; + THFileInfo tmpfi = new THFileInfo(); + newDi.DOSName = SetDOSName(ref tmpfi); + fsfi.SubDirs.Remove(di); + fsfi.SubDirs.Add(newDi); string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); } - public static void RemoveFileFromDirectory(string path, string filename) + public static void RenameFile(string path, string filename, string newname) { FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(path, "_data.info"))); THFileInfo fi = fsfi.Files.Find((THFileInfo f) => { return f.Name == filename; }); if (fi == null) return; - fsfi.ByteSize -= fi.ByteSize; - CurrentSave.BytesLeft += fi.ByteSize; + THFileInfo newFi = fi; + newFi.Name = newname; + + THFileInfo tmpfi = new THFileInfo(); + newFi.DOSName = SetDOSName(ref tmpfi); fsfi.Files.Remove(fi); + fsfi.Files.Add(newFi); string toWrite = JsonConvert.SerializeObject(fsfi, Formatting.Indented); File.WriteAllText(Path.Combine(path, "_data.info"), toWrite); @@ -278,7 +341,7 @@ namespace Histacom2.Engine } } - public static void SaveDirectoryInfo(string parent, string dirname, bool isProtected, string label, bool allowback) + public static void SaveDirectoryInfo(string parent, string dirname, bool isProtected, string label, bool allowback, bool updateParent = true) { if (File.Exists(Path.Combine(parent, dirname, "_data.info")) && Path.Combine(parent, dirname) != ProfileFileSystemDirectory) return; Directory.CreateDirectory(Path.Combine(parent, dirname)); @@ -296,15 +359,18 @@ namespace Histacom2.Engine info.SubDirs = new List(256); info.ByteSize = 0; - if (parent != ProfileDirectory) + if (updateParent == true) { - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(parent, "_data.info"))); - THDirInfo thd = new THDirInfo(); - thd.Name = info.Label; - thd.DOSName = info.DOSLabel; - fsfi.SubDirs.Add(thd); + if ((parent != ProfileDirectory)) + { + FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(parent, "_data.info"))); + THDirInfo thd = new THDirInfo(); + thd.Name = info.Label; + thd.DOSName = info.DOSLabel; + fsfi.SubDirs.Add(thd); - File.WriteAllText(Path.Combine(parent, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + File.WriteAllText(Path.Combine(parent, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + } } string toWrite = JsonConvert.SerializeObject(info, Formatting.Indented); diff --git a/Histacom2/GlobalPrograms/WinClassicNotepad.cs b/Histacom2/GlobalPrograms/WinClassicNotepad.cs index 331f0d5..72f1e41 100644 --- a/Histacom2/GlobalPrograms/WinClassicNotepad.cs +++ b/Histacom2/GlobalPrograms/WinClassicNotepad.cs @@ -15,7 +15,7 @@ namespace Histacom2.OS.Win95.Win95Apps { public partial class WinClassicNotepad : UserControl { - string CurrentFilePath = ""; + public string CurrentFilePath = ""; public WinClassicNotepad() { InitializeComponent(); diff --git a/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.Designer.cs b/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.Designer.cs index e015eda..123e477 100644 --- a/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.Designer.cs +++ b/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.Designer.cs @@ -30,6 +30,10 @@ { this.components = new System.ComponentModel.Container(); this.program = new System.Windows.Forms.Panel(); + this.pnlSave = new System.Windows.Forms.Panel(); + this.Button1 = new System.Windows.Forms.Button(); + this.Label1 = new System.Windows.Forms.Label(); + this.txtSave = new System.Windows.Forms.TextBox(); this.mainView = new System.Windows.Forms.ListView(); this.diskView = new System.Windows.Forms.TreeView(); this.MenuStrip1 = new System.Windows.Forms.MenuStrip(); @@ -37,7 +41,6 @@ this.CreateShortcutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.FolderToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.TextDocumentToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.BitmapImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.RenameToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.CloseToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -55,14 +58,10 @@ this.bottomrightcorner = new System.Windows.Forms.Panel(); this.bottomleftcorner = new System.Windows.Forms.Panel(); this.topleftcorner = new System.Windows.Forms.Panel(); - this.pnlSave = new System.Windows.Forms.Panel(); - this.Button1 = new System.Windows.Forms.Button(); - this.Label1 = new System.Windows.Forms.Label(); - this.txtSave = new System.Windows.Forms.TextBox(); this.refresh = new System.Windows.Forms.Timer(this.components); this.program.SuspendLayout(); - this.MenuStrip1.SuspendLayout(); this.pnlSave.SuspendLayout(); + this.MenuStrip1.SuspendLayout(); this.SuspendLayout(); // // program @@ -82,6 +81,47 @@ this.program.Size = new System.Drawing.Size(704, 517); this.program.TabIndex = 13; // + // pnlSave + // + this.pnlSave.Controls.Add(this.Button1); + this.pnlSave.Controls.Add(this.Label1); + this.pnlSave.Controls.Add(this.txtSave); + this.pnlSave.Location = new System.Drawing.Point(3, 474); + this.pnlSave.Name = "pnlSave"; + this.pnlSave.Size = new System.Drawing.Size(850, 35); + this.pnlSave.TabIndex = 18; + this.pnlSave.Visible = false; + // + // Button1 + // + this.Button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.Button1.Location = new System.Drawing.Point(608, 1); + this.Button1.Name = "Button1"; + this.Button1.Size = new System.Drawing.Size(75, 23); + this.Button1.TabIndex = 17; + this.Button1.Text = "Save"; + this.Button1.UseVisualStyleBackColor = true; + this.Button1.Click += new System.EventHandler(this.Button1_Click); + // + // Label1 + // + this.Label1.AutoSize = true; + this.Label1.Location = new System.Drawing.Point(3, 6); + this.Label1.Name = "Label1"; + this.Label1.Size = new System.Drawing.Size(57, 13); + this.Label1.TabIndex = 16; + this.Label1.Text = "File Name:"; + // + // txtSave + // + this.txtSave.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.txtSave.Location = new System.Drawing.Point(60, 3); + this.txtSave.Name = "txtSave"; + this.txtSave.Size = new System.Drawing.Size(542, 20); + this.txtSave.TabIndex = 15; + // // mainView // this.mainView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -136,10 +176,9 @@ // this.CreateShortcutToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.FolderToolStripMenuItem, - this.TextDocumentToolStripMenuItem, - this.BitmapImageToolStripMenuItem}); + this.TextDocumentToolStripMenuItem}); this.CreateShortcutToolStripMenuItem.Name = "CreateShortcutToolStripMenuItem"; - this.CreateShortcutToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.CreateShortcutToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.CreateShortcutToolStripMenuItem.Text = "New"; // // FolderToolStripMenuItem @@ -149,12 +188,6 @@ this.FolderToolStripMenuItem.Text = "Folder"; this.FolderToolStripMenuItem.Click += new System.EventHandler(this.FolderToolStripMenuItem_Click); // - // ShortcutToolStripMenuItem - // - this.ShortcutToolStripMenuItem.Name = "ShortcutToolStripMenuItem"; - this.ShortcutToolStripMenuItem.Size = new System.Drawing.Size(154, 22); - this.ShortcutToolStripMenuItem.Text = "Shortcut"; - // // TextDocumentToolStripMenuItem // this.TextDocumentToolStripMenuItem.Name = "TextDocumentToolStripMenuItem"; @@ -162,30 +195,24 @@ this.TextDocumentToolStripMenuItem.Text = "Text Document"; this.TextDocumentToolStripMenuItem.Click += new System.EventHandler(this.TextDocumentToolStripMenuItem_Click); // - // BitmapImageToolStripMenuItem - // - this.BitmapImageToolStripMenuItem.Name = "BitmapImageToolStripMenuItem"; - this.BitmapImageToolStripMenuItem.Size = new System.Drawing.Size(154, 22); - this.BitmapImageToolStripMenuItem.Text = "Bitmap Image"; - // // DeleteToolStripMenuItem // this.DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem"; - this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.DeleteToolStripMenuItem.Text = "Delete"; this.DeleteToolStripMenuItem.Click += new System.EventHandler(this.DeleteToolStripMenuItem_Click); // // RenameToolStripMenuItem // this.RenameToolStripMenuItem.Name = "RenameToolStripMenuItem"; - this.RenameToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.RenameToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.RenameToolStripMenuItem.Text = "Rename"; this.RenameToolStripMenuItem.Click += new System.EventHandler(this.RenameToolStripMenuItem_Click); // // CloseToolStripMenuItem // this.CloseToolStripMenuItem.Name = "CloseToolStripMenuItem"; - this.CloseToolStripMenuItem.Size = new System.Drawing.Size(117, 22); + this.CloseToolStripMenuItem.Size = new System.Drawing.Size(152, 22); this.CloseToolStripMenuItem.Text = "Close"; this.CloseToolStripMenuItem.Click += new System.EventHandler(this.CloseToolStripMenuItem_Click); // @@ -297,47 +324,6 @@ this.topleftcorner.Size = new System.Drawing.Size(4, 4); this.topleftcorner.TabIndex = 1; // - // pnlSave - // - this.pnlSave.Controls.Add(this.Button1); - this.pnlSave.Controls.Add(this.Label1); - this.pnlSave.Controls.Add(this.txtSave); - this.pnlSave.Location = new System.Drawing.Point(3, 474); - this.pnlSave.Name = "pnlSave"; - this.pnlSave.Size = new System.Drawing.Size(850, 35); - this.pnlSave.TabIndex = 18; - this.pnlSave.Visible = false; - // - // Button1 - // - this.Button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; - this.Button1.Location = new System.Drawing.Point(608, 1); - this.Button1.Name = "Button1"; - this.Button1.Size = new System.Drawing.Size(75, 23); - this.Button1.TabIndex = 17; - this.Button1.Text = "Save"; - this.Button1.UseVisualStyleBackColor = true; - this.Button1.Click += new System.EventHandler(this.Button1_Click); - // - // Label1 - // - this.Label1.AutoSize = true; - this.Label1.Location = new System.Drawing.Point(3, 6); - this.Label1.Name = "Label1"; - this.Label1.Size = new System.Drawing.Size(57, 13); - this.Label1.TabIndex = 16; - this.Label1.Text = "File Name:"; - // - // txtSave - // - this.txtSave.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.txtSave.Location = new System.Drawing.Point(60, 3); - this.txtSave.Name = "txtSave"; - this.txtSave.Size = new System.Drawing.Size(542, 20); - this.txtSave.TabIndex = 15; - // // refresh // this.refresh.Interval = 15000; @@ -353,10 +339,10 @@ this.Load += new System.EventHandler(this.WinClassicWindowsExplorer_Load); this.program.ResumeLayout(false); this.program.PerformLayout(); - this.MenuStrip1.ResumeLayout(false); - this.MenuStrip1.PerformLayout(); this.pnlSave.ResumeLayout(false); this.pnlSave.PerformLayout(); + this.MenuStrip1.ResumeLayout(false); + this.MenuStrip1.PerformLayout(); this.ResumeLayout(false); } @@ -370,7 +356,6 @@ internal System.Windows.Forms.ToolStripMenuItem CreateShortcutToolStripMenuItem; internal System.Windows.Forms.ToolStripMenuItem FolderToolStripMenuItem; internal System.Windows.Forms.ToolStripMenuItem TextDocumentToolStripMenuItem; - internal System.Windows.Forms.ToolStripMenuItem BitmapImageToolStripMenuItem; internal System.Windows.Forms.ToolStripMenuItem DeleteToolStripMenuItem; internal System.Windows.Forms.ToolStripMenuItem RenameToolStripMenuItem; internal System.Windows.Forms.ToolStripMenuItem CloseToolStripMenuItem; diff --git a/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.cs b/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.cs index 52ea334..eb24f7c 100644 --- a/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.cs +++ b/Histacom2/OS/Win95/Win95Apps/Win95WindowsExplorer.cs @@ -222,6 +222,7 @@ namespace Histacom2.OS.Win95.Win95Apps case 1: WinClassicNotepad np = new WinClassicNotepad(); np.mainText.Text = FileDialogBoxManager.ReadTextFile(fileDir); + np.CurrentFilePath = fileDir; WinClassic app = wm.StartWin95(np, "Notepad", Properties.Resources.Win95IconNotepad, true, true); Program.AddTaskbarItem(app, app.Tag.ToString(), "Notepad", Properties.Resources.Win95IconNotepad); @@ -229,6 +230,7 @@ namespace Histacom2.OS.Win95.Win95Apps case 2: WinClassicWordPad wp = new WinClassicWordPad(); wp.mainText.LoadFile(fileDir); + wp.CurrentFilePath = fileDir; WinClassic app2 = wm.StartWin95(wp, "Wordpad", Properties.Resources.Win95IconWordpad, true, true); Program.AddTaskbarItem(app2, app2.Tag.ToString(), "Wordpad", Properties.Resources.Win95IconWordpad); @@ -664,7 +666,7 @@ namespace Histacom2.OS.Win95.Win95Apps } else { - SaveDirectoryInfo(CurrentDirectory, "New Folder", false, "New Folder", true); + SaveDirectoryInfo(CurrentDirectory, "New Folder", false, "New Folder", true, false); RefreshAll(); OldLabelText = "New Folder"; @@ -723,20 +725,7 @@ namespace Histacom2.OS.Win95.Win95Apps // Remove the directory now from the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THDirInfo dir in fsfi.SubDirs) - { - if (dir.Name == mainView.FocusedItem.Text) - { - // Delete it - - fsfi.SubDirs.Remove(dir); - break; - } - } - - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + SaveSystem.RemoveSubDirFromDirectory(CurrentDirectory, mainView.FocusedItem.Text); } else { @@ -744,20 +733,7 @@ namespace Histacom2.OS.Win95.Win95Apps // Remove the file now from the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THFileInfo file in fsfi.Files) - { - if (file.Name == mainView.FocusedItem.Text) - { - // Delete it - - fsfi.Files.Remove(file); - continue; - } - } - - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + RemoveFileFromDirectory(CurrentDirectory, mainView.FocusedItem.Text); } @@ -822,54 +798,22 @@ namespace Histacom2.OS.Win95.Win95Apps Directory.Move(Path.Combine(CurrentDirectory, OldLabelText), Path.Combine(CurrentDirectory, setText)); File.Delete(Path.Combine(CurrentDirectory, setText, "_data.info")); - SaveDirectoryInfo(CurrentDirectory, setText, false, setText, true); + SaveDirectoryInfo(CurrentDirectory, setText, false, setText, true, true); // Rename the directory now in the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THDirInfo dir in fsfi.SubDirs) - { - if (dir.Name == OldLabelText) - { - // Rename it - THDirInfo oldDirInfo = dir; - oldDirInfo.Name = Path.Combine(CurrentDirectory, setText); - - fsfi.SubDirs.Remove(dir); - fsfi.SubDirs.Add(oldDirInfo); - } - } - - File.Delete(Path.Combine(CurrentDirectory, "_data.info")); - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi)); + RenameDirectory(CurrentDirectory, OldLabelText, setText); } else { - // It was a file + // It was a file File.Copy(Path.Combine(CurrentDirectory, OldLabelText), Path.Combine(CurrentDirectory, setText)); File.Delete(Path.Combine(CurrentDirectory, OldLabelText)); // Rename the file now in the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THFileInfo file in fsfi.Files) - { - if (file.Name == OldLabelText) - { - // Rename it - THFileInfo oldFileInfo = file; - oldFileInfo.Name = Path.Combine(CurrentDirectory, setText); - - fsfi.Files.Remove(file); - fsfi.Files.Add(oldFileInfo); - } - } - - File.Delete(Path.Combine(CurrentDirectory, "_data.info")); - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi)); + RenameFile(CurrentDirectory, OldLabelText, setText); } } } @@ -1045,7 +989,22 @@ namespace Histacom2.OS.Win95.Win95Apps private void TextDocumentToolStripMenuItem_Click(object sender, EventArgs e) { + if (File.Exists(CurrentDirectory + "\\New Text Document.txt")) + { + //wm.StartInfobox95("Windows Explorer", "This directory already exists", Properties.Resources.Win95Info); + //TODO: add making "New Folder (2)" + } + else + { + CreateWindowsFile(CurrentDirectory, "New Text Document.txt", "", 12, 0); + + RefreshAll(); + OldLabelText = "New Folder"; + mainView.LabelEdit = true; + mainView.FindItemWithText("New Text Document.txt").BeginEdit(); + } + RefreshTreeNode(); } } } diff --git a/Histacom2/OS/Win95/Win95Apps/WinClassicWordPad.cs b/Histacom2/OS/Win95/Win95Apps/WinClassicWordPad.cs index 05b5ec1..91d9368 100644 --- a/Histacom2/OS/Win95/Win95Apps/WinClassicWordPad.cs +++ b/Histacom2/OS/Win95/Win95Apps/WinClassicWordPad.cs @@ -22,7 +22,7 @@ namespace Histacom2.OS.Win95.Win95Apps bool doItalic = false; bool doUnderline = false; - string CurrentFilePath = ""; + public string CurrentFilePath = ""; public WinClassicWordPad() { diff --git a/Histacom2/OS/Win98/Win98Apps/WinClassicWindowsExplorer.cs b/Histacom2/OS/Win98/Win98Apps/WinClassicWindowsExplorer.cs index bff593e..9144c76 100644 --- a/Histacom2/OS/Win98/Win98Apps/WinClassicWindowsExplorer.cs +++ b/Histacom2/OS/Win98/Win98Apps/WinClassicWindowsExplorer.cs @@ -243,18 +243,28 @@ namespace Histacom2.OS.Win95.Win95Apps case 1: WinClassicNotepad np = new WinClassicNotepad(); np.mainText.Text = FileDialogBoxManager.ReadTextFile(fileDir); + np.CurrentFilePath = fileDir; WinClassic app = wm.StartWin95(np, "Notepad", Properties.Resources.Win95IconNotepad, true, true); Program.AddTaskbarItem(app, app.Tag.ToString(), "Notepad", Properties.Resources.Win95IconNotepad); + break; + case 2: + WinClassicWordPad wp = new WinClassicWordPad(); + wp.mainText.LoadFile(fileDir); + wp.CurrentFilePath = fileDir; + WinClassic app2 = wm.StartWin95(wp, "Wordpad", Properties.Resources.Win95IconWordpad, true, true); + Program.AddTaskbarItem(app2, app2.Tag.ToString(), "Wordpad", Properties.Resources.Win95IconWordpad); break; case 12: OpenApplication(FileDialogBoxManager.ReadTextFile(fileDir), fileDir); break; } - } catch { } - + catch + { + } + } void OpenApplication(string appname, string path) @@ -778,20 +788,7 @@ namespace Histacom2.OS.Win95.Win95Apps // Remove the directory now from the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THDirInfo dir in fsfi.SubDirs) - { - if (dir.Name == mainView.FocusedItem.Text) - { - // Delete it - - fsfi.SubDirs.Remove(dir); - continue; - } - } - - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + SaveSystem.RemoveSubDirFromDirectory(CurrentDirectory, mainView.FocusedItem.Text); } else { @@ -799,20 +796,7 @@ namespace Histacom2.OS.Win95.Win95Apps // Remove the file now from the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THFileInfo file in fsfi.Files) - { - if (file.Name == mainView.FocusedItem.Text) - { - // Delete it - - fsfi.Files.Remove(file); - continue; - } - } - - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + RemoveFileFromDirectory(CurrentDirectory, mainView.FocusedItem.Text); } @@ -824,6 +808,8 @@ namespace Histacom2.OS.Win95.Win95Apps { RefreshAll(); } + + RefreshTreeNode(); } internal static bool FileOrDirectoryExists(string path) @@ -876,54 +862,22 @@ namespace Histacom2.OS.Win95.Win95Apps Directory.Move(Path.Combine(CurrentDirectory, OldLabelText), Path.Combine(CurrentDirectory, setText)); File.Delete(Path.Combine(CurrentDirectory, setText, "_data.info")); - SaveDirectoryInfo(CurrentDirectory, setText, false, setText, true); + SaveDirectoryInfo(CurrentDirectory, setText, false, setText, true, true); // Rename the directory now in the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THDirInfo dir in fsfi.SubDirs) - { - if (dir.Name == mainView.FocusedItem.Tag.ToString()) - { - // Rename it - THDirInfo oldDirInfo = dir; - oldDirInfo.Name = Path.Combine(CurrentDirectory, setText); - - fsfi.SubDirs.Remove(dir); - fsfi.SubDirs.Add(oldDirInfo); - } - } - - File.Delete(Path.Combine(CurrentDirectory, "_data.info")); - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + RenameDirectory(CurrentDirectory, OldLabelText, setText); } else { - // It was a file + // It was a file File.Copy(Path.Combine(CurrentDirectory, OldLabelText), Path.Combine(CurrentDirectory, setText)); File.Delete(Path.Combine(CurrentDirectory, OldLabelText)); // Rename the file now in the _data.info - FileSystemFolderInfo fsfi = JsonConvert.DeserializeObject(File.ReadAllText(Path.Combine(CurrentDirectory, "_data.info"))); - - foreach (THFileInfo file in fsfi.Files) - { - if (file.Name == mainView.FocusedItem.Tag.ToString()) - { - // Rename it - THFileInfo oldFileInfo = file; - oldFileInfo.Name = Path.Combine(CurrentDirectory, setText); - - fsfi.Files.Remove(file); - fsfi.Files.Add(oldFileInfo); - } - } - - File.Delete(Path.Combine(CurrentDirectory, "_data.info")); - File.WriteAllText(Path.Combine(CurrentDirectory, "_data.info"), JsonConvert.SerializeObject(fsfi, Formatting.Indented)); + RenameFile(CurrentDirectory, OldLabelText, setText); } } } -- cgit v1.2.3 From 1523a8133e8267420f4ad8988e3c466bcc017442 Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Tue, 29 Aug 2017 14:00:58 +0100 Subject: Save File Trouble Shooter Re-do --- Histacom2.Engine/SaveSystem.cs | 7 ++ Histacom2.Engine/Template/WinClassic.Designer.cs | 2 + Histacom2.Engine/Template/WinClassic.cs | 66 +++++++--- .../SaveDialogs/SaveFileTroubleShooter.Designer.cs | 49 ++++---- Histacom2/SaveDialogs/SaveFileTroubleShooter.cs | 135 +++++++++++++++------ Histacom2/TitleScreen.Designer.cs | 2 +- Histacom2/TitleScreen.cs | 2 - 7 files changed, 184 insertions(+), 79 deletions(-) (limited to 'Histacom2.Engine/SaveSystem.cs') 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 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(); - } + // 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(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) if (field.GetValue(savedata) == null) { field.SetValue(savedata, new List()); } + } } 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) -- cgit v1.2.3