using System.IO; using System.Text.Json; using Futonizer.Models; namespace Futonizer.Services; /// /// Loads and saves as a JSON file stored next to /// the application executable, so it travels with the app folder. /// public static class SettingsService { private static readonly string SettingsFilePath = Path.Combine(AppContext.BaseDirectory, "settings.json"); private static readonly JsonSerializerOptions Options = new() { WriteIndented = true }; public static AppSettings Load() { try { if (File.Exists(SettingsFilePath)) { string json = File.ReadAllText(SettingsFilePath); var settings = JsonSerializer.Deserialize(json, Options); if (settings is not null) return settings; } } catch { // Corrupt or unreadable settings file - fall back to defaults. } return new AppSettings(); } public static void Save(AppSettings settings) { try { string json = JsonSerializer.Serialize(settings, Options); File.WriteAllText(SettingsFilePath, json); } catch { // Best effort - ignore write failures (e.g. read-only install folder). } } }