using System.Text; using Newtonsoft.Json; using RustTools.Core.Contracts.Services; namespace RustTools.Core.Services; public class FileService : IFileService { public T Read(string folderPath, string fileName) { var path = Path.Combine(folderPath, fileName); if (File.Exists(path)) { var json = File.ReadAllText(path); return JsonConvert.DeserializeObject(json); } return default; } public void Save(string folderPath, string fileName, T content) { if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } var fileContent = JsonConvert.SerializeObject(content); File.WriteAllText(Path.Combine(folderPath, fileName), fileContent, Encoding.UTF8); } public void Delete(string folderPath, string fileName) { if (fileName != null && File.Exists(Path.Combine(folderPath, fileName))) { File.Delete(Path.Combine(folderPath, fileName)); } } }