From 5b4578fedeabb2a3279f1ea501b0b08d1374e571 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Fri, 21 Dec 2018 11:13:48 +0300 Subject: [PATCH] Settings & Match classes - Added settings class - Added Match class --- OWTrack/MainForm.cs | 32 ++++++++++++++++++------- OWTrack/Tracker.cs | 54 +++++++++++++++++++++++++----------------- OWTrack/saveManeger.cs | 13 ++++++++-- 3 files changed, 66 insertions(+), 33 deletions(-) diff --git a/OWTrack/MainForm.cs b/OWTrack/MainForm.cs index 66a9f48..1845d4e 100644 --- a/OWTrack/MainForm.cs +++ b/OWTrack/MainForm.cs @@ -56,7 +56,7 @@ namespace OWTrack } else { - if (tr.TrackOW) + if (tr.settings.TrackOW) { status.Text = NOT_RUNNING; status.ForeColor = Color.Black; @@ -90,6 +90,7 @@ namespace OWTrack string line = st.ReadToEnd(); if (line.Contains("Overwatch.exe")) { + MessageBox.Show(line); tr = saveManeger.GetSavedTracker(); if (tr.startSR > 0) SRonce = true; } @@ -97,7 +98,7 @@ namespace OWTrack { if (!tr.LoacteOW()) { - tr.gamePath = askForGamePath(); + tr.settings.GamePath = askForGamePath(); } } st.Close(); @@ -110,10 +111,10 @@ namespace OWTrack } else if (!tr.LoacteOW()) { - tr.gamePath = askForGamePath(); + tr.settings.GamePath = askForGamePath(); } - ExeTrackCheckBx.Checked = tr.TrackOW; - SRCheckBx.Checked = tr.TrackSR; + ExeTrackCheckBx.Checked = tr.settings.TrackOW; + SRCheckBx.Checked = tr.settings.TrackSR; update(); } @@ -135,12 +136,12 @@ namespace OWTrack { srBut.Enabled = state; srTextBox.Enabled = state; - tr.TrackSR = state; + tr.settings.TrackSR = state; } private void OWTrackFunc(bool state) { - tr.TrackOW = state; + tr.settings.TrackOW = state; } private void update() @@ -155,7 +156,19 @@ namespace OWTrack else srLabel.Text = tr.startSR.ToString() + " - " + tr.srDiff(); srTextBox.Text = null; saveManeger.SaveJSON(tr); - } + } + + private void AddMatch() + { + Match match = new Match + { + oldSR = tr.startSR, + newSR = tr.newSR, + ChangeInSR = tr.srDiff(), + dateTime = DateTime.Now + }; + tr.matches.Add(match); + } #region Events private void timer1_Tick(object sender, EventArgs e) => checkStatus(); @@ -222,6 +235,7 @@ namespace OWTrack } else tr.newSR = sr; } + AddMatch(); update(); } @@ -239,7 +253,7 @@ namespace OWTrack private void ChngOWPathBtn_Click(object sender, EventArgs e) { - tr.gamePath = askForGamePath(); + tr.settings.GamePath = askForGamePath(); update(); } diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 21124fe..c08ec0a 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -30,9 +30,9 @@ namespace OWTrack class Tracker { public int wins, losses, startSR, newSR, totalMatches = 0; - public string gamePath; + //public string gamePath; public void Track() { }//Deserailize here - public void reset() { wins = 0; losses = 0; startSR = 0; newSR = 0; gamePath = null; } + public void reset() { wins = 0; losses = 0; startSR = 0; newSR = 0; settings.Reset(); } public void addWin() => wins++; public void addLoss() => losses++; public void reduceWin() => wins--; @@ -41,26 +41,18 @@ namespace OWTrack public int GetLosses() { return losses; } public int GetTotalMatches() { return wins + losses; } public void setNewSR(int SR) { newSR = SR; } - public int srDiff() { return newSR - startSR; } - public bool TrackOW = true; - public bool TrackSR = true; - - struct ProgramFiles - { - public static readonly string C = "C:\\Program Files"; - public static readonly string D = "D:\\Program Files"; - public static readonly string E = "E:\\Program Files"; - public static readonly string F = "F:\\Program Files"; - } + public int srDiff() { return newSR - startSR; } + public Settings settings = new Settings(); + public List matches = new List(); public bool owRunning() { - if (TrackOW) + if (settings.TrackOW) { try { bool isRunning = Process.GetProcessesByName("Overwatch") - .FirstOrDefault(p => p.MainModule.FileName.StartsWith(gamePath)) != default(Process); + .FirstOrDefault(p => p.MainModule.FileName.StartsWith(settings.GamePath)) != default(Process); return isRunning; } catch (Exception) @@ -83,8 +75,8 @@ namespace OWTrack //{ //paths.AddRange(GetFiles(drive.ToString(),"Overwatch.exe")); //} - paths.AddRange(GetFiles(ProgramFiles.C, "Overwatch.exe")); - paths.AddRange(GetFiles(ProgramFiles.D, "Overwatch.exe")); + paths.AddRange(GetFiles(Paths.ProgramFiles.C, "Overwatch.exe")); + paths.AddRange(GetFiles(Paths.ProgramFiles.D, "Overwatch.exe")); if (paths.Count > 1) { @@ -96,7 +88,7 @@ namespace OWTrack else if (paths.Count == 1 && paths[0].Contains("Overwatch.exe")) { - gamePath = paths[0]; + settings.GamePath = paths[0]; return true; } else return false; @@ -133,10 +125,28 @@ namespace OWTrack } } - - struct Settings + class Settings { - bool TrackSR, TrackOW; - string OWpath; + public bool TrackSR, TrackOW = true; + public string GamePath = ""; + + /// + /// Reset All values to defult + /// + public void Reset() + { + TrackOW = true; + TrackSR = true; + GamePath = ""; + } + } + + public class Match + { + public Match() { } + public DateTime dateTime { get; set; } + public int oldSR; + public int newSR; + public int ChangeInSR; } } diff --git a/OWTrack/saveManeger.cs b/OWTrack/saveManeger.cs index 4ce8ac3..91c67d3 100644 --- a/OWTrack/saveManeger.cs +++ b/OWTrack/saveManeger.cs @@ -24,7 +24,7 @@ using System.IO; namespace OWTrack { - public static class Paths + public static class Paths { private static string curDir = Directory.GetCurrentDirectory(); private static string SAVES = curDir + "/saves/data.json"; @@ -32,10 +32,19 @@ namespace OWTrack public static string GetJSON() { return JSON; } public static string GetSaves() { return SAVES; } public static string GetCurrentDir() { return curDir; } + + public static class ProgramFiles + { + public static readonly string C = "C:\\Program Files"; + public static readonly string D = "D:\\Program Files"; + public static readonly string E = "E:\\Program Files"; + public static readonly string F = "F:\\Program Files"; + } + } class saveManeger - { + { /// /// Deserialize saved tracker instance. ///