using System.Text.Json;
namespace VoiceCat.App.Models;
///
/// Simple Load()/Save() over %AppData%\VoiceCat\servers.json. Tolerant of a missing/corrupt
/// file — that yields an empty list rather than throwing and blocking app startup.
///
public static class ServerListStore
{
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
private static string AppDataDir => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "VoiceCat");
private static string ServersFilePath => Path.Combine(AppDataDir, "servers.json");
/// Passed to VoiceCatClient's tofuStorePath — the C++ core owns the actual pin
/// file format/logic (TofuStore), this just picks where it lives.
public static string TofuStorePath => Path.Combine(AppDataDir, "tofu_pins.txt");
public static List Load()
{
try
{
if (!File.Exists(ServersFilePath)) return new List();
string json = File.ReadAllText(ServersFilePath);
return JsonSerializer.Deserialize>(json) ?? new List();
}
catch
{
return new List();
}
}
public static void Save(List servers)
{
Directory.CreateDirectory(AppDataDir);
string json = JsonSerializer.Serialize(servers, JsonOptions);
File.WriteAllText(ServersFilePath, json);
}
}