2018-09-22 11:54:00 +02:00
|
|
|
/*Copyright(c) 2018 Hesham Systems LLC.
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.*/
|
|
|
|
|
2018-08-15 10:36:29 +02:00
|
|
|
using System;
|
2018-07-13 03:24:05 +02:00
|
|
|
using System.Drawing;
|
|
|
|
using System.Windows.Forms;
|
2018-08-12 01:21:12 +02:00
|
|
|
using System.IO;
|
2018-07-13 03:24:05 +02:00
|
|
|
|
|
|
|
namespace OWTrack
|
|
|
|
{
|
2018-09-08 13:32:12 +02:00
|
|
|
public partial class MainForm : Form
|
2018-07-13 03:24:05 +02:00
|
|
|
{
|
2018-10-04 08:03:54 +02:00
|
|
|
Tracker tr;
|
2018-07-13 03:57:29 +02:00
|
|
|
private const string IS_RUNNING = "Running";
|
|
|
|
private const string NOT_RUNNING = " Not running";
|
2018-08-15 10:32:42 +02:00
|
|
|
private bool SRonce = false;
|
2018-12-21 10:52:50 +01:00
|
|
|
private string Version = Program.Version.ToString();
|
2018-07-13 03:57:29 +02:00
|
|
|
|
2018-09-08 13:32:12 +02:00
|
|
|
public MainForm()
|
2018-07-13 03:24:05 +02:00
|
|
|
{
|
2018-09-20 10:23:47 +02:00
|
|
|
InitializeComponent();
|
2018-10-04 08:03:54 +02:00
|
|
|
tr = new Tracker();
|
2018-08-12 01:21:12 +02:00
|
|
|
loadSave();
|
2018-07-13 03:57:29 +02:00
|
|
|
checkStatus();
|
2018-09-01 13:11:08 +02:00
|
|
|
update();
|
2018-12-21 10:52:50 +01:00
|
|
|
label4.Text = Version;
|
|
|
|
Text = "OWTrack " + Version;
|
2018-07-13 03:57:29 +02:00
|
|
|
}
|
2018-08-12 01:21:12 +02:00
|
|
|
|
2018-07-13 03:57:29 +02:00
|
|
|
private void checkStatus()
|
2018-09-22 11:41:42 +02:00
|
|
|
{
|
|
|
|
Time.Text = DateTime.Now.ToString("h:mm tt");
|
2018-07-15 21:22:02 +02:00
|
|
|
try
|
2018-08-16 06:50:08 +02:00
|
|
|
{
|
2018-07-15 21:22:02 +02:00
|
|
|
if (tr.owRunning())
|
|
|
|
{
|
|
|
|
status.Text = IS_RUNNING;
|
2018-09-04 21:46:50 +02:00
|
|
|
status.ForeColor = Color.FromArgb(0, 192, 0);
|
2018-09-22 11:41:42 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-21 09:13:48 +01:00
|
|
|
if (tr.settings.TrackOW)
|
2018-09-27 10:06:24 +02:00
|
|
|
{
|
|
|
|
status.Text = NOT_RUNNING;
|
|
|
|
status.ForeColor = Color.Black;
|
|
|
|
}
|
|
|
|
else status.Text = "";
|
2018-09-22 11:41:42 +02:00
|
|
|
}
|
2018-07-15 21:22:02 +02:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
2018-09-22 11:41:42 +02:00
|
|
|
status.Text = e.Message;
|
|
|
|
status.ForeColor = Color.Red;
|
2018-07-15 21:22:02 +02:00
|
|
|
}
|
2018-07-13 03:24:05 +02:00
|
|
|
}
|
2018-07-13 04:13:05 +02:00
|
|
|
|
2018-12-21 10:52:50 +01:00
|
|
|
//Move to saveManeger.cs ?
|
|
|
|
//Refactor!!
|
2018-08-12 01:21:12 +02:00
|
|
|
private void loadSave()
|
|
|
|
{
|
2018-09-22 11:41:42 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory("saves");
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
MessageBox.Show("Can not create save directory.\n" + e.Message);
|
|
|
|
}
|
2018-09-20 10:23:47 +02:00
|
|
|
if (saveManeger.saveExist())
|
2018-08-12 01:21:12 +02:00
|
|
|
{
|
2018-09-20 10:23:47 +02:00
|
|
|
try
|
|
|
|
{
|
2018-12-08 18:52:26 +01:00
|
|
|
using (StreamReader st = new StreamReader(Paths.GetSaves()))
|
2018-09-03 21:11:05 +02:00
|
|
|
{
|
2018-12-20 17:11:31 +01:00
|
|
|
string line = st.ReadToEnd();
|
2018-09-03 21:11:05 +02:00
|
|
|
if (line.Contains("Overwatch.exe"))
|
|
|
|
{
|
2018-09-20 10:23:47 +02:00
|
|
|
tr = saveManeger.GetSavedTracker();
|
2018-11-24 01:24:50 +01:00
|
|
|
if (tr.startSR > 0) SRonce = true;
|
2018-09-03 21:11:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-09-03 21:30:34 +02:00
|
|
|
if (!tr.LoacteOW())
|
2018-09-20 10:23:47 +02:00
|
|
|
{
|
2018-12-21 09:13:48 +01:00
|
|
|
tr.settings.GamePath = askForGamePath();
|
2018-11-24 01:24:50 +01:00
|
|
|
}
|
2018-09-03 21:11:05 +02:00
|
|
|
}
|
2018-11-24 01:24:50 +01:00
|
|
|
st.Close();
|
2018-09-03 21:11:05 +02:00
|
|
|
}
|
2018-09-20 10:23:47 +02:00
|
|
|
}
|
|
|
|
catch (Exception e)
|
2018-08-31 19:56:47 +02:00
|
|
|
{
|
2018-09-20 10:23:47 +02:00
|
|
|
MessageBox.Show(e.Message);
|
|
|
|
}
|
2018-08-12 01:33:26 +02:00
|
|
|
}
|
2018-09-20 10:23:47 +02:00
|
|
|
else if (!tr.LoacteOW())
|
2018-08-12 01:33:26 +02:00
|
|
|
{
|
2018-12-21 09:13:48 +01:00
|
|
|
tr.settings.GamePath = askForGamePath();
|
2018-09-20 10:23:47 +02:00
|
|
|
}
|
2018-12-21 09:13:48 +01:00
|
|
|
ExeTrackCheckBx.Checked = tr.settings.TrackOW;
|
|
|
|
SRCheckBx.Checked = tr.settings.TrackSR;
|
2018-09-27 10:24:32 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-12-20 17:13:03 +01:00
|
|
|
private string askForGamePath()
|
2018-08-31 19:56:47 +02:00
|
|
|
{
|
|
|
|
openFileDialog1.Title = "Select Overwatch.exe";
|
|
|
|
openFileDialog1.DefaultExt = "exe";
|
2018-09-20 10:23:47 +02:00
|
|
|
openFileDialog1.Filter = "exe Files (*.exe)|*.exe|All files (*.*)|*.*";
|
2018-09-03 22:29:40 +02:00
|
|
|
DialogResult result = openFileDialog1.ShowDialog();
|
|
|
|
if (result == DialogResult.OK)
|
2018-08-31 19:56:47 +02:00
|
|
|
{
|
2018-09-22 11:41:42 +02:00
|
|
|
MessageBox.Show("Saved Overwatch.exe location.\nPress Clear to rest");
|
2018-10-04 08:03:54 +02:00
|
|
|
return openFileDialog1.FileName;
|
2018-08-31 19:56:47 +02:00
|
|
|
}
|
2018-11-24 01:24:50 +01:00
|
|
|
else return null;
|
2018-09-27 10:24:32 +02:00
|
|
|
}
|
2018-08-12 01:21:12 +02:00
|
|
|
|
2018-09-27 10:06:24 +02:00
|
|
|
private void SRSystem(bool state)
|
|
|
|
{
|
|
|
|
srBut.Enabled = state;
|
|
|
|
srTextBox.Enabled = state;
|
2018-12-21 09:13:48 +01:00
|
|
|
tr.settings.TrackSR = state;
|
2018-09-27 10:06:24 +02:00
|
|
|
}
|
|
|
|
|
2018-12-21 10:52:50 +01:00
|
|
|
private void OWTrackFunc(bool state) => tr.settings.TrackOW = state;
|
2018-09-27 10:06:24 +02:00
|
|
|
|
2018-09-20 08:56:16 +02:00
|
|
|
private void update()
|
|
|
|
{
|
|
|
|
Wins.Text = tr.GetWins().ToString();
|
|
|
|
Losses.Text = tr.GetLosses().ToString();
|
|
|
|
if (tr.newSR == 0)
|
|
|
|
{
|
|
|
|
if (tr.srDiff() < 1) { srLabel.Text = tr.startSR.ToString() + " - 0"; }
|
|
|
|
else srLabel.Text = tr.startSR.ToString() + " - " + tr.srDiff();
|
|
|
|
}
|
|
|
|
else srLabel.Text = tr.startSR.ToString() + " - " + tr.srDiff();
|
|
|
|
srTextBox.Text = null;
|
2018-09-23 15:08:46 +02:00
|
|
|
saveManeger.SaveJSON(tr);
|
2018-12-21 09:13:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private void AddMatch()
|
|
|
|
{
|
|
|
|
Match match = new Match
|
|
|
|
{
|
|
|
|
oldSR = tr.startSR,
|
|
|
|
newSR = tr.newSR,
|
|
|
|
ChangeInSR = tr.srDiff(),
|
|
|
|
dateTime = DateTime.Now
|
|
|
|
};
|
|
|
|
tr.matches.Add(match);
|
|
|
|
}
|
2018-09-20 08:56:16 +02:00
|
|
|
|
|
|
|
#region Events
|
2018-09-20 08:53:49 +02:00
|
|
|
private void timer1_Tick(object sender, EventArgs e) => checkStatus();
|
|
|
|
|
|
|
|
private void WinBtn_Click(object sender, EventArgs e)
|
2018-07-13 04:13:05 +02:00
|
|
|
{
|
|
|
|
tr.addWin();
|
|
|
|
update();
|
|
|
|
}
|
2018-07-20 02:28:26 +02:00
|
|
|
|
2018-09-20 08:53:49 +02:00
|
|
|
private void LossBtn_Click(object sender, EventArgs e)
|
2018-07-13 04:13:05 +02:00
|
|
|
{
|
|
|
|
tr.addLoss();
|
|
|
|
update();
|
|
|
|
}
|
2018-07-20 02:28:26 +02:00
|
|
|
|
2018-08-03 02:45:06 +02:00
|
|
|
private void reduceWinBut_Click(object sender, EventArgs e)
|
|
|
|
{
|
2018-09-20 10:33:26 +02:00
|
|
|
if (tr.wins > 0)
|
|
|
|
{
|
|
|
|
tr.reduceWin();
|
|
|
|
update();
|
|
|
|
}
|
2018-08-03 02:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void reduceLossBut_Click(object sender, EventArgs e)
|
|
|
|
{
|
2018-09-20 10:33:26 +02:00
|
|
|
if (tr.losses > 0)
|
|
|
|
{
|
|
|
|
tr.rediceLoss();
|
|
|
|
update();
|
|
|
|
}
|
2018-09-20 08:56:16 +02:00
|
|
|
}
|
2018-08-12 01:33:26 +02:00
|
|
|
|
|
|
|
private void clearBut_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
tr.reset();
|
|
|
|
update();
|
2018-08-15 10:32:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void srBut_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
int sr = 0;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
sr = Convert.ToInt32(srTextBox.Text);
|
|
|
|
}
|
|
|
|
catch (FormatException)
|
|
|
|
{
|
|
|
|
MessageBox.Show("Enter a Number!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
catch (OverflowException ex)
|
|
|
|
{
|
|
|
|
MessageBox.Show(ex.Message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (!SRonce)
|
|
|
|
{
|
|
|
|
tr.startSR = sr;
|
|
|
|
SRonce = true;
|
|
|
|
}
|
|
|
|
else tr.newSR = sr;
|
|
|
|
}
|
2018-12-21 09:13:48 +01:00
|
|
|
AddMatch();
|
2018-08-15 10:46:05 +02:00
|
|
|
update();
|
2018-09-20 08:56:16 +02:00
|
|
|
}
|
2018-09-27 10:06:24 +02:00
|
|
|
|
|
|
|
private void SRCheckBx_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
2018-09-27 10:24:32 +02:00
|
|
|
SRSystem(SRCheckBx.Checked);
|
|
|
|
update();
|
2018-09-27 10:06:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ExeTrackCheckBx_CheckedChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
OWTrackFunc(ExeTrackCheckBx.Checked);
|
2018-09-27 10:24:32 +02:00
|
|
|
update();
|
2018-09-27 10:06:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void ChngOWPathBtn_Click(object sender, EventArgs e)
|
|
|
|
{
|
2018-12-21 09:13:48 +01:00
|
|
|
tr.settings.GamePath = askForGamePath();
|
2018-09-27 10:24:32 +02:00
|
|
|
update();
|
2018-09-27 10:06:24 +02:00
|
|
|
}
|
2018-12-13 20:32:33 +01:00
|
|
|
|
|
|
|
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
|
{
|
|
|
|
notifyIcon1.Icon = null;
|
|
|
|
notifyIcon1.Dispose();
|
|
|
|
}
|
|
|
|
#endregion
|
2018-07-13 03:24:05 +02:00
|
|
|
}
|
|
|
|
}
|