Paths class

This commit is contained in:
HeshamTB 2018-09-27 10:17:17 +03:00
parent a77e5684c3
commit ccc2028b7f
2 changed files with 15 additions and 17 deletions

View File

@ -32,7 +32,6 @@ namespace OWTrack
Tracker tr = new Tracker(); Tracker tr = new Tracker();
private const string IS_RUNNING = "Running"; private const string IS_RUNNING = "Running";
private const string NOT_RUNNING = " Not running"; private const string NOT_RUNNING = " Not running";
private string savesPath = Directory.GetCurrentDirectory() + "/saves/data.json";
private bool SRonce = false; private bool SRonce = false;
public MainForm() public MainForm()
@ -82,7 +81,7 @@ namespace OWTrack
{ {
try try
{ {
using (StreamReader st = new StreamReader(savesPath)) using (StreamReader st = new StreamReader(Paths.SAVES))
{ {
string line = st.ReadLine(); string line = st.ReadLine();
if (line.Contains("Overwatch.exe")) if (line.Contains("Overwatch.exe"))
@ -122,7 +121,6 @@ namespace OWTrack
if (result == DialogResult.OK) if (result == DialogResult.OK)
{ {
//tr.gamePath = openFileDialog1.FileName;
MessageBox.Show("Saved Overwatch.exe location.\nPress Clear to rest"); MessageBox.Show("Saved Overwatch.exe location.\nPress Clear to rest");
return openFileDialog1.FileName; return openFileDialog1.FileName;
} }
@ -137,7 +135,7 @@ namespace OWTrack
{ {
try try
{ {
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(savesPath)); return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(Paths.SAVES));
} }
catch (Exception e) catch (Exception e)
{ {
@ -157,7 +155,7 @@ namespace OWTrack
} }
else srLabel.Text = tr.startSR.ToString() + " - " + tr.srDiff(); else srLabel.Text = tr.startSR.ToString() + " - " + tr.srDiff();
srTextBox.Text = null; srTextBox.Text = null;
File.WriteAllText(Directory.GetCurrentDirectory() + "/saves/data.json", JsonConvert.SerializeObject(tr)); File.WriteAllText(Paths.SAVES, JsonConvert.SerializeObject(tr));
} }
#region Events #region Events

View File

@ -28,20 +28,20 @@ using System.Threading.Tasks;
namespace OWTrack namespace OWTrack
{ {
static class Paths
{
private static string curDir = Directory.GetCurrentDirectory();
public static string SAVES = curDir + "/saves/data.json";
public static string JSON = curDir + "/data.json";
}
class saveManeger class saveManeger
{ {
public enum Paths
{
saves = "/saves/data.json",
saveJsonFile = "/data.json",
};
private static string savesPath = Directory.GetCurrentDirectory() + "/saves/data.json";
public static Tracker GetSavedTracker() public static Tracker GetSavedTracker()
{ {
try try
{ {
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(savesPath)); return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(Paths.SAVES));
} }
catch (Exception e) catch (Exception e)
{ {
@ -54,7 +54,7 @@ namespace OWTrack
{ {
try try
{ {
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(customPath + "/data.json")); return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(customPath));
} }
catch (Exception e) catch (Exception e)
{ {
@ -66,7 +66,7 @@ namespace OWTrack
{ {
try try
{ {
File.WriteAllText(Directory.GetCurrentDirectory() + "/data.json", JsonConvert.SerializeObject(tracker)); File.WriteAllText(Paths.JSON, JsonConvert.SerializeObject(tracker));
return true; return true;
} }
catch (Exception) catch (Exception)
@ -79,7 +79,7 @@ namespace OWTrack
{ {
try try
{ {
if (File.Exists(savesPath)) if (File.Exists(Paths.SAVES))
{ {
return true; return true;
} }