using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using RainmeterStudio.Core.Model;
using RainmeterStudio.Core.Storage;
namespace RainmeterStudio.Storage
{
///
/// Project storage, loads and saves project files
///
public class ProjectStorage
{
///
/// Loads a project from file
///
/// Path to file to load
/// Loaded project
public Project Load(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 to file
///
/// Project to save
/// File to save to
public void Save(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;
}
///
/// Saves a project
///
/// Saves a project to the path specified in the 'Path' property
public void Save(Project project)
{
Save(project, project.Path);
}
}
}