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.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|