45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
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 { }
|
|
}
|
|
}
|