2025-09-02 15:32:24 +01:00
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
2025-11-26 14:39:07 +00:00
File . WriteAllText ( MAVPath + LDSFileName , DefaultJSON ) ; // Save a blank version of the JSON
2025-09-02 15:32:24 +01:00
StreamReader file = new ( MAVPath + LDSFileName ) ;
string Content = file . ReadToEnd ( ) ;
file . Close ( ) ;
return JsonConvert . DeserializeObject < LocalDataStore > ( Content ) ;
}
catch // If file can't deserialise
{
2026-01-16 11:42:34 +00:00
Logging . LogMessage ( $"Error loading Local Data Store" ) ; // Have to log this somewhere else as MainForm wont be loaded and you will get a crossthread error
2025-09-02 15:32:24 +01:00
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 )
{
2025-12-19 16:14:13 +00:00
MainForm . Instance . AddToActionsList ( $"Error saving Local Data Store: {ex.Message}" , Level . WARNING ) ;
2026-01-16 11:42:34 +00:00
2025-09-02 15:32:24 +01:00
}
}
}
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 ; }
}
}