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') 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