using System; using System.IO; using System.Text.Json; using NfcActions.Models; namespace NfcActions.Services; public class SettingsService { private readonly string _settingsPath; public SettingsService() { var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var appFolder = Path.Combine(appDataPath, "NfcActions"); Directory.CreateDirectory(appFolder); _settingsPath = Path.Combine(appFolder, "settings.json"); } public AppSettings Load() { try { if (File.Exists(_settingsPath)) { var json = File.ReadAllText(_settingsPath); return JsonSerializer.Deserialize(json) ?? new AppSettings(); } } catch (Exception) { // Failed to load settings, return defaults } return new AppSettings(); } public void Save(AppSettings settings) { try { var json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText(_settingsPath, json); } catch (Exception) { // Failed to save settings } } }