using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; using RainmeterStudio.Core.Model; namespace RainmeterStudio.Storage { /// /// Reads or writes projects /// public static class ProjectStorage { /// /// Loads a project from file /// /// Path to file to load /// Loaded project public static Project Read(string path) { // Open file var file = File.OpenText(path); // Deserialize file var serializer = new XmlSerializer(typeof(Project), new XmlRootAttribute("project")); Project project = serializer.Deserialize(file) as Project; if (project != null) { project.Path = path; } // Clean up file.Close(); return project; } /// /// Saves a project /// /// Saves a project to the path specified in the 'Path' property public static void Write(Project project) { Write(project, project.Path); } /// /// Saves a project to file /// /// Project to save /// File to save to public static void Write(Project project, string path) { // Open file var file = File.OpenWrite(path); // Serialize file var serializer = new XmlSerializer(typeof(Project), new XmlRootAttribute("project")); serializer.Serialize(file, project); // Clean up file.Close(); project.Path = path; } } }