Merge branch 'saveManegerClass' into release/1.4

This commit is contained in:
HeshamTB 2018-09-20 11:26:04 +03:00
commit 500f9c5852
4 changed files with 49 additions and 90 deletions

View File

@ -47,55 +47,38 @@ namespace OWTrack
private void loadSave()
{
Directory.CreateDirectory("saves");
if (saveExist())
if (saveManeger.saveExist())
{
tr.wins = savedTracker().wins;
tr.losses = savedTracker().losses;
tr.newSR = savedTracker().newSR;
tr.startSR = savedTracker().startSR;
tr.gamePath = savedTracker().gamePath;
update();
}
}
private bool saveExist()
{
try
{
if (File.Exists(savesPath))
try
{
using (StreamReader st = new StreamReader(savesPath))
{
string line = st.ReadLine();
if (line.Contains("Overwatch.exe"))
{
tr = saveManeger.GetSavedTracker();
st.Close();
return true;
}
else
{
if (!tr.LoacteOW())
{
st.Close();
tr.gamePath = getGamePath();
}
return true;
st.Close();
}
}
}
else
catch (Exception e)
{
if (!tr.LoacteOW())
{
tr.gamePath = getGamePath();
}
return false;
MessageBox.Show(e.Message);
}
update();
}
catch (Exception e)
else if (!tr.LoacteOW())
{
MessageBox.Show(e.Message);
return false;
tr.gamePath = getGamePath();
}
}
@ -104,23 +87,19 @@ namespace OWTrack
openFileDialog1.Title = "Select Overwatch.exe";
openFileDialog1.DefaultExt = "exe";
openFileDialog1.Filter = "exe Files (*.exe)|*.exe|All files (*.*)|*.*";
//openFileDialog1.CheckFileExists = true;
//openFileDialog1.CheckPathExists = true;
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
//tr.gamePath = openFileDialog1.FileName;
MessageBox.Show("Saved Overwatch.exe location.\nPress Clear to rest\n" + openFileDialog1.FileName );
return openFileDialog1.FileName;
}
else
{
update();
return null;
//Close();
}
//Show();
//update();
}
private Tracker savedTracker()

View File

@ -18,7 +18,7 @@ namespace OWTrack
Application.Run(new MainForm());
}
public static string Version { get; } = "1.4.0a1";
public static string Version { get; } = "1.4.0a2";
//public static string Version = Application.ProductVersion;
//public static Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

View File

@ -13,7 +13,7 @@ namespace OWTrack
public string gamePath;
public void Track() { }
public void reset() { wins = 0; losses = 0; startSR = 0; newSR = 0; }
public void reset() { wins = 0; losses = 0; startSR = 0; newSR = 0; gamePath = null; }
public void addWin() { wins++; }
public void addLoss() { losses++; }
public void reduceWin() { wins--; }

View File

@ -10,11 +10,13 @@ namespace OWTrack
{
class saveManeger
{
private static string savesPath = Directory.GetCurrentDirectory() + "/saves/data.json";
public static Tracker GetSavedTracker()
{
try
{
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json"));
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(savesPath));
}
catch (Exception e)
{
@ -48,45 +50,23 @@ namespace OWTrack
}
}
//private bool saveExist()
//{
// try
// {
// 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
// {
// if (!tr.LoacteOW())
// {
// st.Close();
// getGamePath();
// }
// return true;
// }
// }
// }
// else
// {
// if (!tr.LoacteOW())
// {
// getGamePath();
// }
// return false;
// }
// }
// catch (Exception e)
// {
// MessageBox.Show(e.Message);
// return false;
// }
//}
public static bool saveExist()
{
try
{
if (File.Exists(savesPath))
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
throw e;
}
}
}
}