2017-05-07 20:04:31 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Newtonsoft.Json;
|
2017-07-04 17:12:25 -04:00
|
|
|
|
using System.Diagnostics;
|
2017-05-07 20:04:31 -04:00
|
|
|
|
|
|
|
|
|
namespace TimeHACK.Engine
|
|
|
|
|
{
|
|
|
|
|
public static class SaveSystem
|
|
|
|
|
{
|
2017-06-10 07:22:50 -04:00
|
|
|
|
public static Save CurrentSave { get; set; }
|
2017-06-02 10:06:52 -04:00
|
|
|
|
public static FileSystemFolderInfo filesystemflinfo { get; set; }
|
2017-07-05 14:41:23 -04:00
|
|
|
|
public static bool DevMode = false;
|
2017-05-07 20:04:31 -04:00
|
|
|
|
|
2017-07-01 17:17:57 -04:00
|
|
|
|
public static FileAssociation IconChanger = new FileAssociation();
|
|
|
|
|
|
2017-07-05 14:41:23 -04:00
|
|
|
|
public static Theme currentTheme { get; set; }
|
|
|
|
|
|
2017-05-07 20:04:31 -04:00
|
|
|
|
public static string GameDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-05-20 06:49:25 -04:00
|
|
|
|
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TimeHACK");
|
2017-05-07 20:04:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 08:33:32 -04:00
|
|
|
|
public static string AllProfilesDirectory
|
2017-05-07 20:04:31 -04:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(GameDirectory, "Profiles");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 08:33:32 -04:00
|
|
|
|
public static string ProfileName = "";
|
|
|
|
|
public static string ProfileFile = "main.save";
|
|
|
|
|
|
|
|
|
|
public static string ProfileDirectory
|
2017-05-07 20:04:31 -04:00
|
|
|
|
{
|
2017-05-20 08:33:32 -04:00
|
|
|
|
get
|
2017-05-07 20:04:31 -04:00
|
|
|
|
{
|
2017-05-20 08:33:32 -04:00
|
|
|
|
return Path.Combine(GameDirectory, Path.Combine("Profiles", ProfileName));
|
2017-05-07 20:04:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 16:42:48 -04:00
|
|
|
|
public static string ProfileFileSystemDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(ProfileDirectory, "folders");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProfileMyComputerDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(ProfileFileSystemDirectory, "Computer");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProfileSettingsDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-17 17:25:33 -04:00
|
|
|
|
return Path.Combine(ProfileMyComputerDirectory, "Settings");
|
2017-05-24 16:42:48 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProfileDocumentsDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2017-06-17 17:25:33 -04:00
|
|
|
|
return Path.Combine(ProfileMyComputerDirectory, "Doc");
|
2017-05-24 16:42:48 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProfileProgramsDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(ProfileMyComputerDirectory, "Prog");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string ProfileWindowsDirectory
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(ProfileMyComputerDirectory, "Win");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 08:33:32 -04:00
|
|
|
|
public static bool LoadSave()
|
|
|
|
|
{
|
|
|
|
|
// ON A FINAL RELEASE USE THE "FINAL RELEASE THINGS"
|
|
|
|
|
#region Final Release Things
|
|
|
|
|
//Read base64 string from file
|
|
|
|
|
//string b64 = File.ReadAllText(Path.Combine(ProfileDirectory, ProfileFile));
|
|
|
|
|
//Get Unicode byte array
|
|
|
|
|
//byte[] bytes = Convert.FromBase64String(b64);
|
|
|
|
|
//Decode the Unicode
|
|
|
|
|
//string json = Encoding.UTF8.GetString(bytes);
|
|
|
|
|
//Deserialize save object.
|
|
|
|
|
#endregion
|
|
|
|
|
// USE THE THINGS IN THE "DEVELOPER THINGS" FOR A DEVELOPMENT RELEASE
|
|
|
|
|
#region Developer Things
|
|
|
|
|
string json = File.ReadAllText(Path.Combine(ProfileDirectory, ProfileFile));
|
|
|
|
|
#endregion
|
|
|
|
|
CurrentSave = JsonConvert.DeserializeObject<Save>(json);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-07 20:04:31 -04:00
|
|
|
|
public static void NewGame()
|
|
|
|
|
{
|
2017-06-10 07:22:50 -04:00
|
|
|
|
//TODO: User must set a username....somehow
|
2017-05-24 16:42:48 -04:00
|
|
|
|
|
|
|
|
|
var save = new Save();
|
|
|
|
|
save.ExperiencedStories = new List<string>();
|
2017-07-04 17:12:25 -04:00
|
|
|
|
if (DevMode == true)
|
|
|
|
|
{
|
|
|
|
|
if (ProfileName == "98")
|
|
|
|
|
{
|
|
|
|
|
save.CurrentOS = "98";
|
2017-07-05 14:41:23 -04:00
|
|
|
|
save.ThemeName = "default98";
|
2017-07-04 18:24:33 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
save.CurrentOS = "95";
|
2017-07-05 14:41:23 -04:00
|
|
|
|
save.ThemeName = "default95";
|
|
|
|
|
currentTheme = new Default95Theme();
|
2017-07-04 17:12:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-04 18:24:33 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
save.CurrentOS = "95";
|
2017-07-05 14:41:23 -04:00
|
|
|
|
save.ThemeName = "default95";
|
|
|
|
|
currentTheme = new Default95Theme();
|
2017-07-04 18:24:33 -04:00
|
|
|
|
}
|
2017-05-24 16:42:48 -04:00
|
|
|
|
CurrentSave = save;
|
2017-07-01 17:17:57 -04:00
|
|
|
|
|
2017-06-10 07:22:50 -04:00
|
|
|
|
CheckFiles();
|
2017-05-24 16:42:48 -04:00
|
|
|
|
SaveGame();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CheckFiles()
|
|
|
|
|
{
|
2017-05-07 20:04:31 -04:00
|
|
|
|
if (!Directory.Exists(GameDirectory))
|
|
|
|
|
Directory.CreateDirectory(GameDirectory);
|
|
|
|
|
|
2017-05-20 08:33:32 -04:00
|
|
|
|
if (!Directory.Exists(AllProfilesDirectory))
|
|
|
|
|
Directory.CreateDirectory(AllProfilesDirectory);
|
|
|
|
|
|
2017-05-07 20:04:31 -04:00
|
|
|
|
if (!Directory.Exists(ProfileDirectory))
|
|
|
|
|
Directory.CreateDirectory(ProfileDirectory);
|
|
|
|
|
|
2017-05-24 16:42:48 -04:00
|
|
|
|
if (!Directory.Exists(ProfileFileSystemDirectory))
|
|
|
|
|
Directory.CreateDirectory(ProfileFileSystemDirectory);
|
2017-06-10 07:22:50 -04:00
|
|
|
|
|
|
|
|
|
SaveDirectoryInfo(ProfileFileSystemDirectory, false, "My Computer", false);
|
|
|
|
|
SaveDirectoryInfo(ProfileMyComputerDirectory, false, "Win95", true);
|
2017-06-17 17:25:33 -04:00
|
|
|
|
if (CurrentSave.CurrentOS == "95") SaveDirectoryInfo(ProfileDocumentsDirectory, false, "My Documents", true);
|
|
|
|
|
if (CurrentSave.CurrentOS != "95") SaveDirectoryInfo(ProfileSettingsDirectory, false, "Documents and Settings", true);
|
2017-06-10 07:22:50 -04:00
|
|
|
|
SaveDirectoryInfo(ProfileProgramsDirectory, true, "Program Files", true);
|
|
|
|
|
SaveDirectoryInfo(ProfileWindowsDirectory, true, "Windows", true);
|
2017-07-01 17:17:57 -04:00
|
|
|
|
|
|
|
|
|
CreateWindowsDirectory();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void CreateWindowsDirectory()
|
|
|
|
|
{
|
|
|
|
|
SaveDirectoryInfo(Path.Combine(ProfileWindowsDirectory, "System"), true, "System", true);
|
|
|
|
|
SaveDirectoryInfo(Path.Combine(ProfileWindowsDirectory, "Config"), true, "Config", true);
|
|
|
|
|
SaveDirectoryInfo(Path.Combine(ProfileWindowsDirectory, "Cursors"), true, "Cursors", true);
|
|
|
|
|
SaveDirectoryInfo(Path.Combine(ProfileWindowsDirectory, "Fonts"), true, "Fonts", true);
|
|
|
|
|
SaveDirectoryInfo(Path.Combine(ProfileWindowsDirectory, "Help"), true, "Help", true);
|
|
|
|
|
SaveDirectoryInfo(Path.Combine(ProfileWindowsDirectory, "Temp"), true, "Temp", true);
|
|
|
|
|
|
2017-07-04 17:12:25 -04:00
|
|
|
|
CreateWindowsFile(Path.Combine(ProfileWindowsDirectory, "calc.exe"), "Calculator");
|
2017-07-01 17:17:57 -04:00
|
|
|
|
CreateWindowsFile(Path.Combine(ProfileWindowsDirectory, "explorer.exe"), "windowsexplorer");
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-05 14:41:23 -04:00
|
|
|
|
public static void CreateWindowsFile(string filepath, string contents)
|
2017-07-01 17:17:57 -04:00
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(filepath, contents);
|
2017-05-07 20:04:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-05 14:41:23 -04:00
|
|
|
|
public static void SaveDirectoryInfo(string directory, bool isProtected, string label, bool allowback)
|
2017-05-24 16:42:48 -04:00
|
|
|
|
{
|
2017-06-10 07:22:50 -04:00
|
|
|
|
if (!Directory.Exists(directory))
|
|
|
|
|
Directory.CreateDirectory(directory);
|
|
|
|
|
|
2017-05-24 16:42:48 -04:00
|
|
|
|
FileSystemFolderInfo info = new FileSystemFolderInfo();
|
|
|
|
|
|
|
|
|
|
info.Isprotected = isProtected;
|
|
|
|
|
info.label = label;
|
|
|
|
|
info.allowback = allowback;
|
|
|
|
|
|
|
|
|
|
string toWrite = JsonConvert.SerializeObject(info, Formatting.Indented);
|
|
|
|
|
|
2017-06-10 07:22:50 -04:00
|
|
|
|
File.WriteAllText(Path.Combine(directory, "_data.info"), toWrite);
|
2017-05-24 16:42:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-07 20:04:31 -04:00
|
|
|
|
public static void SaveGame()
|
|
|
|
|
{
|
|
|
|
|
//Serialize the save to JSON.
|
2017-05-20 08:33:32 -04:00
|
|
|
|
string json = JsonConvert.SerializeObject(CurrentSave, Formatting.Indented);
|
|
|
|
|
|
|
|
|
|
// ADD THE TWO LINES OF CODE BELOW ON A FINAL RELEASE
|
2017-05-07 20:04:31 -04:00
|
|
|
|
//Get JSON bytes (Unicode format).
|
2017-05-20 08:33:32 -04:00
|
|
|
|
//var bytes = Encoding.UTF8.GetBytes(json);
|
2017-05-07 20:04:31 -04:00
|
|
|
|
//Encode the array into Base64.
|
2017-05-20 08:33:32 -04:00
|
|
|
|
//string b64 = Convert.ToBase64String(bytes);
|
2017-05-07 20:04:31 -04:00
|
|
|
|
//Write to disk.
|
2017-05-20 08:33:32 -04:00
|
|
|
|
|
|
|
|
|
// CHANGE THE "JSON" TO "B64" ON A FINAL RELEASE!
|
|
|
|
|
File.WriteAllText(Path.Combine(ProfileDirectory, ProfileFile), json);
|
2017-05-07 20:04:31 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Save
|
|
|
|
|
{
|
|
|
|
|
public string Username { get; set; }
|
2017-06-10 07:22:50 -04:00
|
|
|
|
|
|
|
|
|
public string CurrentOS { get; set; }
|
|
|
|
|
// public Dictionary<string, bool> InstalledPrograms { get; set; } InstallProgram is no longer needed... we have that data in the FileSystem
|
2017-05-07 20:04:31 -04:00
|
|
|
|
public List<string> ExperiencedStories { get; set; }
|
2017-07-05 12:54:34 -04:00
|
|
|
|
public bool FTime95 { get; set; }
|
2017-07-04 18:24:33 -04:00
|
|
|
|
public string ThemeName { get; set; }
|
2017-05-07 20:04:31 -04:00
|
|
|
|
}
|
2017-05-24 16:42:48 -04:00
|
|
|
|
|
|
|
|
|
public class FileSystemFolderInfo
|
|
|
|
|
{
|
2017-07-04 18:24:33 -04:00
|
|
|
|
public bool Isprotected { get; set; }
|
|
|
|
|
public string label { get; set; }
|
|
|
|
|
public bool allowback { get; set; }
|
2017-05-24 16:42:48 -04:00
|
|
|
|
}
|
2017-05-07 20:04:31 -04:00
|
|
|
|
}
|