1
0
Fork 0
mirror of https://github.com/hawkeye-stan/msfs-popout-panel-manager.git synced 2024-11-25 15:20:10 +00:00
msfs-popout-panel-manager/FileManager.cs

60 lines
1.6 KiB
C#
Raw Normal View History

2021-09-17 03:18:02 +00:00
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
namespace MSFSPopoutPanelManager
{
public class FileManager
{
2021-09-23 13:34:10 +00:00
private string _startupPath;
public FileManager(string startupPath)
{
_startupPath = startupPath;
}
public UserData ReadUserData()
2021-09-17 03:18:02 +00:00
{
try
{
2021-09-23 13:34:10 +00:00
using (StreamReader reader = new StreamReader(_startupPath + @"\config\userdata.json"))
2021-09-17 03:18:02 +00:00
{
string json = reader.ReadToEnd();
return JsonConvert.DeserializeObject<UserData>(json);
}
}
catch
{
return null;
}
}
2021-09-23 13:34:10 +00:00
public void WriteUserData(UserData userData)
2021-09-17 03:18:02 +00:00
{
2021-09-23 13:34:10 +00:00
using (StreamWriter file = File.CreateText(_startupPath + @"\config\userdata.json"))
2021-09-17 03:18:02 +00:00
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, userData);
}
}
2021-09-23 13:34:10 +00:00
public List<OcrEvalData> ReadProfileData()
2021-09-17 03:18:02 +00:00
{
2021-09-23 13:34:10 +00:00
using (StreamReader reader = new StreamReader(_startupPath + @"\config\ocrdata.json"))
2021-09-17 03:18:02 +00:00
{
string json = reader.ReadToEnd();
try
{
return JsonConvert.DeserializeObject<List<OcrEvalData>>(json);
}
catch
{
throw new Exception("The file ocrdata.json is invalid.");
}
}
}
}
}