Merge branch 'feature/saveAppPath' of hesham/OWtrack into master

This commit is contained in:
hesham 2018-08-12 02:38:25 +03:00 committed by HeshamTB
commit e3d1d9208f
6 changed files with 84 additions and 14 deletions

View File

@ -42,6 +42,7 @@
this.label4 = new System.Windows.Forms.Label();
this.reduceLossBut = new System.Windows.Forms.Button();
this.reduceWinBut = new System.Windows.Forms.Button();
this.clearBut = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
@ -168,15 +169,26 @@
this.reduceWinBut.Name = "reduceWinBut";
this.reduceWinBut.Size = new System.Drawing.Size(20, 24);
this.reduceWinBut.TabIndex = 9;
this.reduceWinBut.Text = "+";
this.reduceWinBut.Text = "-";
this.reduceWinBut.UseVisualStyleBackColor = true;
this.reduceWinBut.Click += new System.EventHandler(this.reduceWinBut_Click);
//
// clearBut
//
this.clearBut.Location = new System.Drawing.Point(209, 132);
this.clearBut.Name = "clearBut";
this.clearBut.Size = new System.Drawing.Size(49, 25);
this.clearBut.TabIndex = 10;
this.clearBut.Text = "clear";
this.clearBut.UseVisualStyleBackColor = true;
this.clearBut.Click += new System.EventHandler(this.clearBut_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(263, 170);
this.Controls.Add(this.clearBut);
this.Controls.Add(this.reduceWinBut);
this.Controls.Add(this.reduceLossBut);
this.Controls.Add(this.label4);
@ -214,6 +226,7 @@
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button reduceLossBut;
private System.Windows.Forms.Button reduceWinBut;
private System.Windows.Forms.Button clearBut;
}
}

View File

@ -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;
}
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,49 @@ namespace OWTrack
}
}
private void loadSave()
{
if (saveExist())
{
tr.wins = savedTracker().wins;
tr.losses = savedTracker().losses;
update();
}
else MessageBox.Show("no save");
}
private bool saveExist()
{
try
{
if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) { return true; }
else return false;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return false;
}
}
private Tracker savedTracker()
{
try
{
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json"));
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
checkStatus();
}
private void button1_Click(object sender, EventArgs e)
{
tr.addWin();
@ -75,5 +117,10 @@ namespace OWTrack
Losses.Text = tr.GetLosses().ToString();
}
private void clearBut_Click(object sender, EventArgs e)
{
tr.reset();
update();
}
}
}

View File

@ -68,6 +68,9 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
@ -102,6 +105,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@ -8,6 +8,7 @@ namespace OWTrack
{
static class Program
{
public static string Version = "1.2.2";
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -18,6 +19,6 @@ namespace OWTrack
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
public static string Version = "1.2.1";
}
}

View File

@ -1,13 +1,13 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.IO;
namespace OWTrack
{
class Tracker
{
private int wins, losses = 0;
public int wins, losses = 0;
public void Track()
{
@ -29,6 +29,7 @@ namespace OWTrack
}
}
public void reset() { wins = 0; losses = 0; }
public void addWin() { wins++; }
public void addLoss() { losses++; }
public void reduceWin() { wins--; }

4
OWTrack/packages.config Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net461" />
</packages>