using ModVersionChecker.managers.interfaces; using System.Collections.Generic; using System.IO; using System.Text.Json; namespace ModVersionChecker.managers.filesystem { public class AppsManager { private readonly string FilePath = Path.Combine(AppContext.BaseDirectory, "data", "apps.json"); public List Load() { if (!File.Exists(FilePath)) return new List(); var json = File.ReadAllText(FilePath); return JsonSerializer.Deserialize>(json) ?? new(); } public void Save(List apps) { var options = new JsonSerializerOptions { WriteIndented = true }; var json = JsonSerializer.Serialize(apps, options); File.WriteAllText(FilePath, json); } public void Upsert(AppConfig app) { var apps = Load(); var index = apps.FindIndex(a => a.Id == app.Id); if (index >= 0) { apps[index] = app; } else { apps.Add(app); } Save(apps); } } }