using Newtonsoft.Json; using System.IO; using Path = System.IO.Path; namespace ROIEditor { public class EstadoTrabajo { public string strDirectorioTrabajo; public string NombreImagenEditando; private static string _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "EstadoTrabajo.json"); public EstadoTrabajo() { strDirectorioTrabajo = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); NombreImagenEditando = null; } // Método para guardar el estado en un archivo JSON public void GuardarEstado() { string json = JsonConvert.SerializeObject(this); File.WriteAllText(_filePath, json); } // Método para cargar el estado desde un archivo JSON public static EstadoTrabajo CargarEstado() { if (File.Exists(_filePath)) { string json = File.ReadAllText(_filePath); return JsonConvert.DeserializeObject(json); } return new EstadoTrabajo(); // Devuelve una nueva instancia si no existe el archivo } public string CarpetaDB() { return Path.Combine(strDirectorioTrabajo, "roieditor.db"); } public string PNG_Folther_Path() { return strDirectorioTrabajo; } public string Json_Extension_Path() { string jsonPath = Path.ChangeExtension(NombreImagenEditando, ".json"); var imagePath = Path.Combine(strDirectorioTrabajo, jsonPath); return imagePath; } public string PNG_Extension_Path() { string jsonPath = Path.ChangeExtension(NombreImagenEditando, ".png"); var imagePath = Path.Combine(PNG_Folther_Path(), jsonPath); return imagePath; } } }