using System.IO; using System.Text.Json; namespace SpdUp.Models; /// /// Persisted application settings. /// public sealed class AppSettings { private static readonly string _filePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SpdUp", "settings.json"); // ── General ──────────────────────────────────────────────────────── public bool MinimizeToTray { get; set; } = true; public bool StartWithWindows { get; set; } = false; public bool AutoDetectGames { get; set; } = true; public bool AutoBoostOnGameLaunch { get; set; } = true; // ── Widget ───────────────────────────────────────────────────────── public bool ShowWidget { get; set; } = false; public bool WidgetCompactMode { get; set; } = true; public double WidgetLeft { get; set; } = 100; public double WidgetTop { get; set; } = 100; public double WidgetOpacity { get; set; } = 0.85; public int WidgetUpdateIntervalMs { get; set; } = 1000; public bool WidgetClickThrough { get; set; } = false; // ── Monitoring ───────────────────────────────────────────────────── public int MonitoringIntervalMs { get; set; } = 1000; // ── Network ──────────────────────────────────────────────────────── public string PingTarget { get; set; } = "8.8.8.8"; public string PreferredDns { get; set; } = "1.1.1.1"; // ── Game Library ─────────────────────────────────────────────────── public List Games { get; set; } = new(); // ── Boost services to stop ───────────────────────────────────────── public List ServicesToStop { get; set; } = new() { "SysMain", "WSearch", "DiagTrack", "TabletInputService", "MapsBroker", "PcaSvc", "wisvc" }; // ── Persistence ──────────────────────────────────────────────────── private static readonly JsonSerializerOptions _jsonOpts = new() { WriteIndented = true, PropertyNameCaseInsensitive = true }; public static AppSettings Load() { try { if (File.Exists(_filePath)) { var json = File.ReadAllText(_filePath); return JsonSerializer.Deserialize(json, _jsonOpts) ?? new AppSettings(); } } catch { /* return default */ } return new AppSettings(); } public void Save() { try { var dir = Path.GetDirectoryName(_filePath)!; Directory.CreateDirectory(dir); File.WriteAllText(_filePath, JsonSerializer.Serialize(this, _jsonOpts)); } catch { /* best-effort */ } } }