OWtrack/OWTrack/Form1.cs

216 lines
6.1 KiB
C#
Raw Normal View History

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 Newtonsoft.Json;
using System.IO;
2018-07-13 03:24:05 +02:00
2018-09-03 22:29:40 +02:00
2018-07-13 03:24:05 +02:00
namespace OWTrack
{
public partial class Form1 : Form
{
2018-07-13 03:57:29 +02:00
Tracker tr = new Tracker();
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-07-13 03:57:29 +02:00
2018-07-13 03:24:05 +02:00
public Form1()
{
2018-09-14 14:38:42 +02:00
2018-09-04 18:13:56 +02:00
InitializeComponent();
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();
label4.Text = Program.Version.ToString();
2018-09-03 22:29:40 +02:00
Text = "OWTrack " + Program.Version.ToString();
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-01 13:11:08 +02:00
{
2018-07-15 21:22:02 +02:00
try
2018-08-16 06:50:08 +02:00
{
2018-09-01 13:11:08 +02:00
Time.Text = DateTime.Now.ToString("h:mm tt");
status.Text = NOT_RUNNING;
status.ForeColor = Color.Red;
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-08-16 06:50:08 +02:00
}
2018-07-15 21:22:02 +02:00
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
2018-07-13 03:24:05 +02:00
}
2018-07-13 04:13:05 +02:00
2018-08-12 01:21:12 +02:00
private void loadSave()
{
if (saveExist())
{
tr.wins = savedTracker().wins;
tr.losses = savedTracker().losses;
2018-09-01 13:14:31 +02:00
tr.newSR = savedTracker().newSR;
tr.startSR = savedTracker().startSR;
2018-09-03 21:11:05 +02:00
tr.gamePath = savedTracker().gamePath;
2018-08-12 01:21:12 +02:00
update();
2018-09-03 21:30:34 +02:00
}
2018-08-31 19:56:47 +02:00
}
2018-08-12 01:21:12 +02:00
private bool saveExist()
{
2018-08-12 01:33:26 +02:00
try
{
2018-09-03 21:11:05 +02:00
if (File.Exists(Directory.GetCurrentDirectory() + "/data.json"))
{
using (StreamReader st = new StreamReader(Directory.GetCurrentDirectory() + "/data.json"))
{
string line = st.ReadLine();
if (line.Contains("Overwatch.exe"))
{
st.Close();
return true;
}
else
{
2018-09-03 21:30:34 +02:00
if (!tr.LoacteOW())
2018-09-03 22:29:40 +02:00
{
2018-09-03 21:30:34 +02:00
st.Close();
2018-09-03 22:29:40 +02:00
getGamePath();
2018-09-03 21:30:34 +02:00
}
2018-09-03 21:11:05 +02:00
return true;
}
}
}
2018-08-31 19:56:47 +02:00
else
{
2018-09-03 21:30:34 +02:00
if (!tr.LoacteOW())
{
getGamePath();
}
2018-08-31 19:56:47 +02:00
return false;
}
2018-08-12 01:33:26 +02:00
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
2018-08-12 01:21:12 +02:00
}
2018-09-01 13:11:08 +02:00
private void getGamePath()
2018-08-31 19:56:47 +02:00
{
openFileDialog1.Title = "Select Overwatch.exe";
openFileDialog1.DefaultExt = "exe";
openFileDialog1.Filter = "exe Files (*.exe)|*.exe|All files (*.*)|*.*";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
2018-09-03 22:29:40 +02:00
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
2018-08-31 19:56:47 +02:00
{
tr.gamePath = openFileDialog1.FileName;
}
2018-09-03 22:29:40 +02:00
else if (result == DialogResult.Cancel)
{
Close();
}
2018-09-04 19:45:09 +02:00
FindForm();
2018-09-03 22:29:40 +02:00
update();
2018-08-31 19:56:47 +02:00
}
2018-09-14 14:38:42 +02:00
private Tracker savedTracker()//
2018-08-12 01:21:12 +02:00
{
2018-08-12 01:33:26 +02:00
try
{
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json"));
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
2018-08-12 01:21:12 +02:00
}
private void timer1_Tick(object sender, EventArgs e)
{
checkStatus();
}
2018-07-13 04:13:05 +02:00
private void button1_Click(object sender, EventArgs e)
{
tr.addWin();
update();
}
2018-07-20 02:28:26 +02:00
2018-07-13 04:13:05 +02:00
private void button2_Click(object sender, EventArgs e)
{
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)
{
tr.reduceWin();
update();
}
private void reduceLossBut_Click(object sender, EventArgs e)
{
tr.rediceLoss();
update();
}
2018-07-13 04:13:05 +02:00
private void update()
{
Wins.Text = tr.GetWins().ToString();
Losses.Text = tr.GetLosses().ToString();
2018-08-15 10:46:05 +02:00
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-14 14:38:42 +02:00
File.WriteAllText(Directory.GetCurrentDirectory() + "/data.json", JsonConvert.SerializeObject(tr));//
2018-08-03 02:45:06 +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-08-15 10:46:05 +02:00
update();
2018-08-31 19:56:47 +02:00
}
2018-07-13 03:24:05 +02:00
}
}