OWtrack/OWTrack/saveManeger.cs

73 lines
1.7 KiB
C#
Raw Normal View History

2018-09-14 14:38:42 +02:00
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OWTrack
{
class saveManeger
{
2018-09-20 10:23:47 +02:00
private static string savesPath = Directory.GetCurrentDirectory() + "/saves/data.json";
2018-09-14 14:38:42 +02:00
public static Tracker GetSavedTracker()
{
try
{
2018-09-20 10:23:47 +02:00
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(savesPath));
2018-09-14 14:38:42 +02:00
}
catch (Exception e)
{
throw e;
}
}
//TODO: use para
public static Tracker GetSavedTracker(string customPath)
{
try
{
return JsonConvert.DeserializeObject<Tracker>(File.ReadAllText(Directory.GetCurrentDirectory() + "/data.json"));
}
catch (Exception e)
{
throw e;
}
}
public static bool SaveJSON(Tracker tracker)
{
try
{
File.WriteAllText(Directory.GetCurrentDirectory() + "/data.json", JsonConvert.SerializeObject(tracker));
return true;
}
catch (Exception)
{
return false;
}
}
2018-09-20 10:23:47 +02:00
public static bool saveExist()
{
try
{
if (File.Exists(savesPath))
{
return true;
}
else
{
return false;
}
}
catch (Exception e)
{
throw e;
}
}
2018-09-14 14:38:42 +02:00
}
}