using System.IO; using System.Text.Json; using AutoShutdown.Models; namespace AutoShutdown.Services; internal sealed class NotificationSettingsStore { private readonly string _path = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AutoShutdown", "notification-settings.json"); public NotificationSettings Load() { try { if (!File.Exists(_path)) { return NotificationSettings.Default(); } var json = File.ReadAllText(_path); return JsonSerializer.Deserialize(json) ?? NotificationSettings.Default(); } catch { return NotificationSettings.Default(); } } public void Save(NotificationSettings settings) { Directory.CreateDirectory(Path.GetDirectoryName(_path)!); var json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(_path, json); } }