Implement a proper save system

This commit is contained in:
Michael 2017-05-07 20:04:31 -04:00
parent 1220d4d995
commit 9e2582cd3f
38 changed files with 162 additions and 49 deletions

BIN
Data/google.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

1
Profiles/user.save Normal file
View file

@ -0,0 +1 @@
eyJVc2VybmFtZSI6bnVsbCwiSW5zdGFsbGVkUHJvZ3JhbXMiOnt9LCJFeHBlcmllbmNlZFN0b3JpZXMiOltdfQ==

View file

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace TimeHACK.Engine
{
public static class SaveSystem
{
public static Save CurrentSave { get; private set; }
public static string GameDirectory
{
get
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "TimeHACK");
}
}
public static string ProfileDirectory
{
get
{
return Path.Combine(GameDirectory, "Profiles");
}
}
public static bool LoadSave()
{
if(File.Exists(Path.Combine(ProfileDirectory, "user.save")))
{
//Read base64 string from file
string b64 = File.ReadAllText(Path.Combine(ProfileDirectory, "user.save"));
//Get Unicode byte array
byte[] bytes = Convert.FromBase64String(b64);
//Decode the Unicode
string json = Encoding.UTF8.GetString(bytes);
//Deserialize save object.
CurrentSave = JsonConvert.DeserializeObject<Save>(json);
return true;
}
else
{
NewGame();
return false;
}
}
public static void NewGame()
{
//TODO: User must set a username....somehow
if (!Directory.Exists(GameDirectory))
Directory.CreateDirectory(GameDirectory);
if (!Directory.Exists(ProfileDirectory))
Directory.CreateDirectory(ProfileDirectory);
var save = new Save();
save.ExperiencedStories = new List<string>();
save.InstalledPrograms = new Dictionary<string, bool>();
CurrentSave = save;
SaveGame();
}
public static void SaveGame()
{
//Serialize the save to JSON.
string json = JsonConvert.SerializeObject(CurrentSave);
//Get JSON bytes (Unicode format).
var bytes = Encoding.UTF8.GetBytes(json);
//Encode the array into Base64.
string b64 = Convert.ToBase64String(bytes);
//Write to disk.
File.WriteAllText(Path.Combine(ProfileDirectory, "user.save"), b64);
}
}
public class Save
{
public string Username { get; set; }
public Dictionary<string, bool> InstalledPrograms { get; set; }
public List<string> ExperiencedStories { get; set; }
}
}

View file

@ -47,6 +47,7 @@
<ItemGroup>
<Compile Include="BSODCreator.cs" />
<None Include="Resources\WinClassic\Window\pjBg6mKP.bin" />
<Compile Include="SaveSystem.cs" />
<Compile Include="TaskBarController.cs" />
<Compile Include="Template\Win9XBSOD.cs">
<SubType>Form</SubType>

View file

@ -0,0 +1,11 @@
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\bin\Debug\TimeHACK.Engine.dll
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\bin\Debug\TimeHACK.Engine.pdb
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\bin\Debug\Newtonsoft.Json.dll
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.Properties.Resources.resources
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.Template.Win9XBSOD.resources
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.Template.AboutBox95.resources
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.Template.Infobox95.resources
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.Template.WinClassic.resources
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.csproj.GenerateResource.Cache
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.dll
C:\Users\Michael\Documents\TimeHACK\TimeHACK.Engine\obj\Debug\TimeHACK.Engine.pdb

Binary file not shown.

Binary file not shown.

View file

@ -5,6 +5,7 @@
using System.Windows.Forms;
using TimeHACK.OS.Win95;
using TimeHACK.Engine;
using static TimeHACK.Engine.SaveSystem;
namespace TimeHACK
{
@ -19,22 +20,43 @@ public partial class TitleScreen : Form
public static DirectoryInfo datafolder;
public static DirectoryInfo profilefolder;
public static string GameDirectory
public void StartGame()
{
get
//TODO: You may want to handle story stuff to decide what OS to boot here.
if (Convert.ToInt32(VM_Width.Text) == 1337 && Convert.ToInt32(VM_Height.Text) == 1337)
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "TimeHACK");
leet();
}
else
// If VM Mode is not enabled
if (vm_mode.Checked != true)
{
// Generate fullscreen desktop
frm95 = new Windows95();
frm95.TopMost = true;
frm95.FormBorderStyle = FormBorderStyle.None;
frm95.WindowState = FormWindowState.Maximized;
frm95.Show();
Hide();
}
// If VM Mode is enabled
else
{
// Generate desktop with size entered by user
frm95 = new Windows95();
frm95.FormBorderStyle = FormBorderStyle.None;
frm95.Size = new Size(Convert.ToInt32(VM_Width.Text), Convert.ToInt32(VM_Height.Text));
frm95.FormBorderStyle = FormBorderStyle.Fixed3D;
frm95.Show();
Hide();
}
}
public TitleScreen()
{
InitializeComponent();
if (!Directory.Exists(GameDirectory)) Directory.CreateDirectory(GameDirectory);
else thfolder = new DirectoryInfo(GameDirectory);
datafolder = Directory.CreateDirectory(Path.Combine(thfolder.FullName, "Data"));
Resources.google.Save(Path.Combine(datafolder.FullName, "\\google.jpg"));
profilefolder = Directory.CreateDirectory(Path.Combine(thfolder.FullName, "\\Profiles"));
}
private void closebutton_Click(object sender, EventArgs e)
@ -60,6 +82,18 @@ private void VM_WidthHeight_KeyPress(object sender, KeyPressEventArgs e)
// When the TitleScreen Loads
private void TitleScreen_Load(object sender, EventArgs e)
{
if (!Directory.Exists(GameDirectory))
Directory.CreateDirectory(GameDirectory);
thfolder = new DirectoryInfo(GameDirectory);
string Data = Path.Combine(thfolder.FullName, "Data");
if (!Directory.Exists(Data))
Directory.CreateDirectory(Data);
Resources.google.Save(Path.Combine(Data, "google.jpg"));
profilefolder = Directory.CreateDirectory(Path.Combine(thfolder.FullName, "\\Profiles"));
// Set GameVersion
gameversion.Text = "TimeHACK " + Program.gameID;
@ -110,34 +144,8 @@ private void vmModeTimer_Tick(object sender, EventArgs e)
// When NewGame is Clicked
private void NewGame_Click(object sender, EventArgs e)
{
if (Convert.ToInt32(VM_Width.Text) == 1337 && Convert.ToInt32(VM_Height.Text) == 1337)
{
leet();
}
else
// If VM Mode is not enabled
if (vm_mode.Checked != true)
{
// Generate fullscreen desktop
frm95 = new Windows95();
frm95.TopMost = true;
frm95.FormBorderStyle = FormBorderStyle.None;
frm95.WindowState = FormWindowState.Maximized;
frm95.Show();
Hide();
}
// If VM Mode is enabled
else
{
// Generate desktop with size entered by user
frm95 = new Windows95();
frm95.FormBorderStyle = FormBorderStyle.None;
frm95.Size = new Size(Convert.ToInt32(VM_Width.Text), Convert.ToInt32(VM_Height.Text));
frm95.FormBorderStyle = FormBorderStyle.Fixed3D;
frm95.Show();
Hide();
}
NewGame();
StartGame();
}
public void BSODRewind(object sender, EventArgs e)
@ -185,7 +193,12 @@ private void NewGame_MouseLeave(object sender, EventArgs e)
#region LoadGame
private void LoadGame_Click(object sender, EventArgs e)
{
var result = LoadSave();
if(result == false)
{
MessageBox.Show(caption: "No save found.", text: "No save was found on your system. However, we have created a new one, and we will start it up for you.");
}
StartGame();
}
private void LoadGame_Enter(object sender, EventArgs e)
{

View file

@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>enHK1jtqVuqBzs5WjolvCxHtcQ4/IH2qRAoDLD4Vl1g=</dsig:DigestValue>
<dsig:DigestValue>Uz3V5ZfPvL8kbLdPsTxWUf0G46Tk2FvGdS//5mccIVQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View file

@ -63,19 +63,19 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>Td2TYOaDP/QyjPIAStenJiwmqqmIdwTWbqIXB1t1U7Q=</dsig:DigestValue>
<dsig:DigestValue>6TXNhM+YgvjkCt77w0GQTcIrotJF2QVUhEdYf1z/jr4=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="TimeHACK.Engine.dll" size="185344">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="TimeHACK.Engine.dll" size="188928">
<assemblyIdentity name="TimeHACK.Engine" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>SIXbCIc3wbx0rQbc1SZnPbW3ytPXP4QDiBiWIwFS8WY=</dsig:DigestValue>
<dsig:DigestValue>IHN6zq12VyThKYP0thtt/7SHfFzso+22RuHWIy0c4dg=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View file

@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>enHK1jtqVuqBzs5WjolvCxHtcQ4/IH2qRAoDLD4Vl1g=</dsig:DigestValue>
<dsig:DigestValue>Uz3V5ZfPvL8kbLdPsTxWUf0G46Tk2FvGdS//5mccIVQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View file

@ -63,19 +63,19 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>Td2TYOaDP/QyjPIAStenJiwmqqmIdwTWbqIXB1t1U7Q=</dsig:DigestValue>
<dsig:DigestValue>6TXNhM+YgvjkCt77w0GQTcIrotJF2QVUhEdYf1z/jr4=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="TimeHACK.Engine.dll" size="185344">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="TimeHACK.Engine.dll" size="188928">
<assemblyIdentity name="TimeHACK.Engine" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>SIXbCIc3wbx0rQbc1SZnPbW3ytPXP4QDiBiWIwFS8WY=</dsig:DigestValue>
<dsig:DigestValue>IHN6zq12VyThKYP0thtt/7SHfFzso+22RuHWIy0c4dg=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View file

@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>enHK1jtqVuqBzs5WjolvCxHtcQ4/IH2qRAoDLD4Vl1g=</dsig:DigestValue>
<dsig:DigestValue>Uz3V5ZfPvL8kbLdPsTxWUf0G46Tk2FvGdS//5mccIVQ=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>

View file

@ -63,19 +63,19 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>Td2TYOaDP/QyjPIAStenJiwmqqmIdwTWbqIXB1t1U7Q=</dsig:DigestValue>
<dsig:DigestValue>6TXNhM+YgvjkCt77w0GQTcIrotJF2QVUhEdYf1z/jr4=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="TimeHACK.Engine.dll" size="185344">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="TimeHACK.Engine.dll" size="188928">
<assemblyIdentity name="TimeHACK.Engine" version="1.0.0.0" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>SIXbCIc3wbx0rQbc1SZnPbW3ytPXP4QDiBiWIwFS8WY=</dsig:DigestValue>
<dsig:DigestValue>IHN6zq12VyThKYP0thtt/7SHfFzso+22RuHWIy0c4dg=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>