initial commit
This commit is contained in:
44
analog_system_monitor_dotnet/Config.cs
Normal file
44
analog_system_monitor_dotnet/Config.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json;
|
||||
|
||||
public class Config
|
||||
{
|
||||
public string OscIp { get; set; } = "127.0.0.1";
|
||||
public int OscPort { get; set; } = 9000;
|
||||
public int UpdateRateMs { get; set; } = 1000;
|
||||
|
||||
private static string ConfigPath =>
|
||||
Path.Combine(AppContext.BaseDirectory, "config.json");
|
||||
|
||||
public static Config Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(ConfigPath))
|
||||
{
|
||||
string json = File.ReadAllText(ConfigPath);
|
||||
return JsonSerializer.Deserialize<Config>(json) ?? new Config();
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
// If loading fails, create a default config
|
||||
var cfg = new Config();
|
||||
cfg.Save();
|
||||
return cfg;
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = JsonSerializer.Serialize(this, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
File.WriteAllText(ConfigPath, json);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user