mirror of
https://github.com/hawkeye-stan/msfs-popout-panel-manager.git
synced 2024-11-22 05:40:11 +00:00
59 lines
1.6 KiB
C#
59 lines
1.6 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
|
|
namespace MSFSPopoutPanelManager
|
|
{
|
|
public class FileManager
|
|
{
|
|
private string _startupPath;
|
|
|
|
public FileManager(string startupPath)
|
|
{
|
|
_startupPath = startupPath;
|
|
}
|
|
|
|
public UserData ReadUserData()
|
|
{
|
|
try
|
|
{
|
|
using (StreamReader reader = new StreamReader(_startupPath + @"\config\userdata.json"))
|
|
{
|
|
string json = reader.ReadToEnd();
|
|
return JsonConvert.DeserializeObject<UserData>(json);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void WriteUserData(UserData userData)
|
|
{
|
|
using (StreamWriter file = File.CreateText(_startupPath + @"\config\userdata.json"))
|
|
{
|
|
JsonSerializer serializer = new JsonSerializer();
|
|
serializer.Serialize(file, userData);
|
|
}
|
|
}
|
|
|
|
public List<OcrEvalData> ReadProfileData()
|
|
{
|
|
using (StreamReader reader = new StreamReader(_startupPath + @"\config\ocrdata.json"))
|
|
{
|
|
string json = reader.ReadToEnd();
|
|
|
|
try
|
|
{
|
|
return JsonConvert.DeserializeObject<List<OcrEvalData>>(json);
|
|
}
|
|
catch
|
|
{
|
|
throw new Exception("The file ocrdata.json is invalid.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|