Settings & Match classes

- Added settings class
- Added Match class
This commit is contained in:
HeshamTB 2018-12-21 11:13:48 +03:00
parent b23cc399b4
commit 5b4578fede
3 changed files with 66 additions and 33 deletions

View File

@ -56,7 +56,7 @@ namespace OWTrack
} }
else else
{ {
if (tr.TrackOW) if (tr.settings.TrackOW)
{ {
status.Text = NOT_RUNNING; status.Text = NOT_RUNNING;
status.ForeColor = Color.Black; status.ForeColor = Color.Black;
@ -90,6 +90,7 @@ namespace OWTrack
string line = st.ReadToEnd(); string line = st.ReadToEnd();
if (line.Contains("Overwatch.exe")) if (line.Contains("Overwatch.exe"))
{ {
MessageBox.Show(line);
tr = saveManeger.GetSavedTracker(); tr = saveManeger.GetSavedTracker();
if (tr.startSR > 0) SRonce = true; if (tr.startSR > 0) SRonce = true;
} }
@ -97,7 +98,7 @@ namespace OWTrack
{ {
if (!tr.LoacteOW()) if (!tr.LoacteOW())
{ {
tr.gamePath = askForGamePath(); tr.settings.GamePath = askForGamePath();
} }
} }
st.Close(); st.Close();
@ -110,10 +111,10 @@ namespace OWTrack
} }
else if (!tr.LoacteOW()) else if (!tr.LoacteOW())
{ {
tr.gamePath = askForGamePath(); tr.settings.GamePath = askForGamePath();
} }
ExeTrackCheckBx.Checked = tr.TrackOW; ExeTrackCheckBx.Checked = tr.settings.TrackOW;
SRCheckBx.Checked = tr.TrackSR; SRCheckBx.Checked = tr.settings.TrackSR;
update(); update();
} }
@ -135,12 +136,12 @@ namespace OWTrack
{ {
srBut.Enabled = state; srBut.Enabled = state;
srTextBox.Enabled = state; srTextBox.Enabled = state;
tr.TrackSR = state; tr.settings.TrackSR = state;
} }
private void OWTrackFunc(bool state) private void OWTrackFunc(bool state)
{ {
tr.TrackOW = state; tr.settings.TrackOW = state;
} }
private void update() private void update()
@ -157,6 +158,18 @@ namespace OWTrack
saveManeger.SaveJSON(tr); 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 #region Events
private void timer1_Tick(object sender, EventArgs e) => checkStatus(); private void timer1_Tick(object sender, EventArgs e) => checkStatus();
@ -222,6 +235,7 @@ namespace OWTrack
} }
else tr.newSR = sr; else tr.newSR = sr;
} }
AddMatch();
update(); update();
} }
@ -239,7 +253,7 @@ namespace OWTrack
private void ChngOWPathBtn_Click(object sender, EventArgs e) private void ChngOWPathBtn_Click(object sender, EventArgs e)
{ {
tr.gamePath = askForGamePath(); tr.settings.GamePath = askForGamePath();
update(); update();
} }

View File

@ -30,9 +30,9 @@ namespace OWTrack
class Tracker class Tracker
{ {
public int wins, losses, startSR, newSR, totalMatches = 0; public int wins, losses, startSR, newSR, totalMatches = 0;
public string gamePath; //public string gamePath;
public void Track() { }//Deserailize here 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 addWin() => wins++;
public void addLoss() => losses++; public void addLoss() => losses++;
public void reduceWin() => wins--; public void reduceWin() => wins--;
@ -42,25 +42,17 @@ namespace OWTrack
public int GetTotalMatches() { return wins + losses; } public int GetTotalMatches() { return wins + losses; }
public void setNewSR(int SR) { newSR = SR; } public void setNewSR(int SR) { newSR = SR; }
public int srDiff() { return newSR - startSR; } public int srDiff() { return newSR - startSR; }
public bool TrackOW = true; public Settings settings = new Settings();
public bool TrackSR = true; public List<Match> matches = new List<Match>();
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 bool owRunning() public bool owRunning()
{ {
if (TrackOW) if (settings.TrackOW)
{ {
try try
{ {
bool isRunning = Process.GetProcessesByName("Overwatch") 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; return isRunning;
} }
catch (Exception) catch (Exception)
@ -83,8 +75,8 @@ namespace OWTrack
//{ //{
//paths.AddRange(GetFiles(drive.ToString(),"Overwatch.exe")); //paths.AddRange(GetFiles(drive.ToString(),"Overwatch.exe"));
//} //}
paths.AddRange(GetFiles(ProgramFiles.C, "Overwatch.exe")); paths.AddRange(GetFiles(Paths.ProgramFiles.C, "Overwatch.exe"));
paths.AddRange(GetFiles(ProgramFiles.D, "Overwatch.exe")); paths.AddRange(GetFiles(Paths.ProgramFiles.D, "Overwatch.exe"));
if (paths.Count > 1) if (paths.Count > 1)
{ {
@ -96,7 +88,7 @@ namespace OWTrack
else if (paths.Count == 1 else if (paths.Count == 1
&& paths[0].Contains("Overwatch.exe")) && paths[0].Contains("Overwatch.exe"))
{ {
gamePath = paths[0]; settings.GamePath = paths[0];
return true; return true;
} }
else return false; else return false;
@ -133,10 +125,28 @@ namespace OWTrack
} }
} }
class Settings
struct Settings
{ {
bool TrackSR, TrackOW; public bool TrackSR, TrackOW = true;
string OWpath; public string GamePath = "";
/// <summary>
/// Reset All values to defult
/// </summary>
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;
} }
} }

View File

@ -32,6 +32,15 @@ namespace OWTrack
public static string GetJSON() { return JSON; } public static string GetJSON() { return JSON; }
public static string GetSaves() { return SAVES; } public static string GetSaves() { return SAVES; }
public static string GetCurrentDir() { return curDir; } 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 class saveManeger