2014-07-26 07:12:56 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml.Serialization;
|
2014-08-12 13:33:13 +00:00
|
|
|
|
using RainmeterStudio.Core.Model;
|
2014-08-16 14:09:08 +00:00
|
|
|
|
using RainmeterStudio.Core.Storage;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
namespace RainmeterStudio.Storage
|
|
|
|
|
{
|
2014-08-31 11:41:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Project storage, loads and saves project files
|
|
|
|
|
/// </summary>
|
2014-07-26 07:12:56 +00:00
|
|
|
|
public class ProjectStorage
|
|
|
|
|
{
|
2014-08-31 11:41:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Loads a project from file
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="path">Path to file to load</param>
|
|
|
|
|
/// <returns>Loaded project</returns>
|
2014-07-26 07:12:56 +00:00
|
|
|
|
public Project Load(string path)
|
|
|
|
|
{
|
|
|
|
|
// Open file
|
|
|
|
|
var file = File.OpenText(path);
|
|
|
|
|
|
|
|
|
|
// Deserialize file
|
2014-08-31 11:41:24 +00:00
|
|
|
|
var serializer = new XmlSerializer(typeof(Project), new XmlRootAttribute("project"));
|
|
|
|
|
Project project = serializer.Deserialize(file) as Project;
|
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
if (project != null)
|
2014-08-31 11:41:24 +00:00
|
|
|
|
{
|
2014-07-27 13:21:06 +00:00
|
|
|
|
project.Path = path;
|
2014-08-31 11:41:24 +00:00
|
|
|
|
}
|
2014-07-27 13:21:06 +00:00
|
|
|
|
|
2014-07-26 07:12:56 +00:00
|
|
|
|
// Clean up
|
|
|
|
|
file.Close();
|
2014-08-31 11:41:24 +00:00
|
|
|
|
return project;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-31 11:41:24 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a project to file
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="project">Project to save</param>
|
|
|
|
|
/// <param name="path">File to save to</param>
|
|
|
|
|
public void Save(Project project, string path)
|
2014-07-26 07:12:56 +00:00
|
|
|
|
{
|
|
|
|
|
// Open file
|
|
|
|
|
var file = File.OpenWrite(path);
|
|
|
|
|
|
2014-07-27 13:21:06 +00:00
|
|
|
|
// Serialize file
|
2014-08-31 11:41:24 +00:00
|
|
|
|
var serializer = new XmlSerializer(typeof(Project), new XmlRootAttribute("project"));
|
|
|
|
|
serializer.Serialize(file, project);
|
2014-07-26 07:12:56 +00:00
|
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
|
file.Close();
|
2014-07-27 13:21:06 +00:00
|
|
|
|
project.Path = path;
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
2014-08-31 11:41:24 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves a project
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="project">Saves a project to the path specified in the 'Path' property</param>
|
|
|
|
|
public void Save(Project project)
|
|
|
|
|
{
|
|
|
|
|
Save(project, project.Path);
|
|
|
|
|
}
|
2014-07-26 07:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|