diff --git a/OWTrack/Form1.cs b/OWTrack/Form1.cs index 1bfd978..cae2868 100644 --- a/OWTrack/Form1.cs +++ b/OWTrack/Form1.cs @@ -1,6 +1,8 @@ using System; using System.Drawing; using System.Windows.Forms; +using Newtonsoft.Json; +using System.IO; namespace OWTrack { @@ -13,20 +15,17 @@ namespace OWTrack public Form1() { InitializeComponent(); + loadSave(); checkStatus(); label4.Text = Program.Version; - Text = "OWTrack " + Program.Version; + Text = "OWTrack " + Program.Version; } - - private void timer1_Tick(object sender, EventArgs e) - { - checkStatus(); - } - + private void checkStatus() { try { + File.WriteAllText(Directory.GetCurrentDirectory() + "/data.json", JsonConvert.SerializeObject(tr)); Time.Text = DateTime.Now.ToString("h:mm tt"); if (tr.owRunning()) { @@ -45,6 +44,33 @@ namespace OWTrack } } + private void loadSave() + { + if (saveExist()) + { + tr.wins = savedTracker().wins; + tr.losses = savedTracker().losses; + update(); + } + else MessageBox.Show("no save"); + } + + private bool saveExist() + { + if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) { return true; } + else return false; + } + + private Tracker savedTracker() + { + return JsonConvert.DeserializeObject(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json")); + } + + private void timer1_Tick(object sender, EventArgs e) + { + checkStatus(); + } + private void button1_Click(object sender, EventArgs e) { tr.addWin(); diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index d4aa4c9..bd2977b 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -1,20 +1,19 @@ using System; using System.Diagnostics; using System.Linq; -using Newtonsoft.Json; - +using System.IO; namespace OWTrack { class Tracker { - private int wins, losses = 0; + public int wins, losses = 0; public void Track() { - } - + } + public bool owRunning() { try