Files
AiQ_GUI/LDS.cs
2025-09-02 15:32:24 +01:00

70 lines
2.8 KiB
C#

using Newtonsoft.Json;
namespace AiQ_GUI
{
internal class LDS
{
// Path strings
public const string MAVPath = @"C:\ProgramData\MAV\AiQ_GUI\"; // Path to local storage
public const string OVsavePath = "OV_image.jpg"; // Path to save the downloaded image
public const string IROpensavePath = "IR_Open_image.jpg"; // Path to save the downloaded image
public const string IRTightsavePath = "IR_Tight_image.jpg"; // Path to save the downloaded image
public const string LDSFileName = "LDS.json"; // Local Data Store file name
const string DefaultJSON = "{\r\n \"User\": \"\",\r\n \"LastModel\": \"\",\r\n \"PSUIP\": \"\",\r\n \"EzIP\": \"\",\r\n \"ZebraIP\": \"\",\r\n \"TestTubeIP\": \"\",\r\n \"Shutter\": 0,\r\n \"Iris\": 0,\r\n \"Gain\": 0\r\n}";
public static LocalDataStore GetLDS()
{
try
{
if (!Directory.Exists(MAVPath)) // Check the AiQ folder exists in ProgramData and if it doesn't then create it
{
Directory.CreateDirectory(MAVPath);
}
if (!File.Exists(MAVPath + LDSFileName)) // Check the LDS file exists and if it doesn't then create it
{
// Save a blank version of the JSON
File.WriteAllText(MAVPath + LDSFileName, DefaultJSON);
}
StreamReader file = new(MAVPath + LDSFileName);
string Content = file.ReadToEnd();
file.Close();
return JsonConvert.DeserializeObject<LocalDataStore>(Content);
}
catch // If file can't deserialise
{
return null; // Return null to indicate failure
}
}
// Save new version to disk
public static void SetLDS(LocalDataStore localDataStore)
{
try
{
string fileJSON = JsonConvert.SerializeObject(localDataStore, Formatting.Indented);
File.WriteAllText(MAVPath + LDSFileName, fileJSON);
}
catch (Exception ex)
{
MainForm.Instance.AddToActionsList($"Error saving Local Data Store: {ex.Message}");
}
}
}
public class LocalDataStore
{
public string User { get; set; } = string.Empty;
public string LastModel { get; set; } = string.Empty;
public string PSUIP { get; set; } = string.Empty;
public string EzIP { get; set; } = string.Empty;
public string ZebraIP { get; set; } = string.Empty;
public string TestTubeIP { get; set; } = string.Empty;
public int Shutter { get; set; }
public int Iris { get; set; }
public int Gain { get; set; }
}
}