-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
73 lines (60 loc) · 2.29 KB
/
App.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using Newtonsoft.Json;
using TaskSwift.Models;
using TaskSwift.Views;
namespace TaskSwift;
public partial class App : Application
{
public static List<Views.TaskModel> tasks = new List<Views.TaskModel>();
public static List<Views.TaskModel> completedTasks = new List<Views.TaskModel>();
public static List<FlagModel> flags = new List<FlagModel>();
public static StatsModel stats = new StatsModel();
string tasksFileName = "Tasks.json";
public static string tasksFilePath;
string statsFileName = "Stats.json";
public static string statsFilePath;
string completedTasksFileName = "CompletedTasks.json";
public static string completedTasksPath;
string flagsFileName = "Flags.json";
public static string flagsFilePath;
public App()
{
InitializeComponent();
tasksFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), tasksFileName);
statsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), statsFileName);
completedTasksPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), completedTasksFileName);
flagsFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), flagsFileName);
//ResetData();
LoadStats();
LoadJson();
FlagModel.LoadFlags();
MainPage = new AppShell();
}
private void ResetData()
{
File.Delete(tasksFilePath);
//File.Delete(statsFilePath);
File.Delete(completedTasksPath);
//File.Delete(flagsFilePath);
}
public void LoadStats()
{
if (File.Exists(statsFilePath))
{
string json = File.ReadAllText(statsFilePath);
stats = JsonConvert.DeserializeObject<StatsModel>(json);
}
}
private void LoadJson()
{
if (File.Exists(tasksFilePath))
{
string json = File.ReadAllText(tasksFilePath);
tasks = JsonConvert.DeserializeObject<List<Views.TaskModel>>(json);
}
if (File.Exists(completedTasksPath))
{
string json = File.ReadAllText(completedTasksPath);
completedTasks = JsonConvert.DeserializeObject<List<Views.TaskModel>>(json);
}
}
}