mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Added serializable project, references are now immutable.
This commit is contained in:
212
RainmeterStudio.Core/Storage/SerializableProject.cs
Normal file
212
RainmeterStudio.Core/Storage/SerializableProject.cs
Normal file
@ -0,0 +1,212 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using RainmeterStudio.Core.Model;
|
||||
using RainmeterStudio.Core.Utils;
|
||||
|
||||
namespace RainmeterStudio.Core.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper class to serialize or deserialize project objects
|
||||
/// </summary>
|
||||
public class SerializableProject
|
||||
{
|
||||
private Project _project;
|
||||
private SerializableReference _autoLoadFile;
|
||||
private List<SerializableReference> _variableFiles;
|
||||
private SerializableTree<SerializableReference> _root;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the project
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Project Project
|
||||
{
|
||||
get
|
||||
{
|
||||
_project.AutoLoadFile = _autoLoadFile.Reference;
|
||||
_project.VariableFiles = _variableFiles.Select(x => x.Reference).ToList();
|
||||
_project.Root = _root.AsTree().TransformData(x => x.Reference);
|
||||
return _project;
|
||||
}
|
||||
set
|
||||
{
|
||||
_project = value;
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the project name
|
||||
/// </summary>
|
||||
[XmlElement("name")]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return Project.Name;
|
||||
}
|
||||
set
|
||||
{
|
||||
Project.Name = value;
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the project path
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return Project.Path;
|
||||
}
|
||||
set
|
||||
{
|
||||
Project.Path = value;
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the author of the project
|
||||
/// </summary>
|
||||
[XmlElement("author")]
|
||||
public string Author
|
||||
{
|
||||
get
|
||||
{
|
||||
return Project.Author;
|
||||
}
|
||||
set
|
||||
{
|
||||
Project.Author = value;
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the project version
|
||||
/// </summary>
|
||||
[XmlElement("version")]
|
||||
public string Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return Project.Version.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
Project.Version = new Version(value);
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the reference to the file to automatically load at package installation
|
||||
/// </summary>
|
||||
[XmlElement("autoLoadFile")]
|
||||
public SerializableReference AutoLoadFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return _autoLoadFile;
|
||||
}
|
||||
set
|
||||
{
|
||||
_autoLoadFile = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of variable files
|
||||
/// </summary>
|
||||
[XmlArray("variableFiles")]
|
||||
public List<SerializableReference> VariableFiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return _variableFiles;
|
||||
}
|
||||
set
|
||||
{
|
||||
_variableFiles = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the minimum rainmeter version
|
||||
/// </summary>
|
||||
public string MinimumRainmeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return Project.MinimumRainmeter.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
Project.MinimumRainmeter = new Version(value);
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the minimum Windows version
|
||||
/// </summary>
|
||||
public string MinimumWindows
|
||||
{
|
||||
get
|
||||
{
|
||||
return Project.MinimumWindows.ToString();
|
||||
}
|
||||
set
|
||||
{
|
||||
Project.MinimumWindows = new Version(value);
|
||||
UpdateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the root node
|
||||
/// </summary>
|
||||
public SerializableTree<SerializableReference> Root
|
||||
{
|
||||
get
|
||||
{
|
||||
return _root;
|
||||
}
|
||||
set
|
||||
{
|
||||
_root = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the serializable project
|
||||
/// </summary>
|
||||
public SerializableProject()
|
||||
{
|
||||
Project = new Project();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the serializable project
|
||||
/// </summary>
|
||||
/// <param name="project">Base project</param>
|
||||
public SerializableProject(Project project)
|
||||
{
|
||||
Project = project;
|
||||
}
|
||||
|
||||
private void UpdateSelf()
|
||||
{
|
||||
_autoLoadFile = new SerializableReference(_project.AutoLoadFile);
|
||||
_variableFiles = _project.VariableFiles.Select(x => new SerializableReference(x)).ToList();
|
||||
_root = _project.Root.TransformData(x => new SerializableReference(x)).AsSerializableTree();
|
||||
}
|
||||
}
|
||||
}
|
75
RainmeterStudio.Core/Storage/SerializableReference.cs
Normal file
75
RainmeterStudio.Core/Storage/SerializableReference.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using RainmeterStudio.Core.Model;
|
||||
|
||||
namespace RainmeterStudio.Core.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a reference that can be serialized
|
||||
/// </summary>
|
||||
public class SerializableReference
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the reference
|
||||
/// </summary>
|
||||
[XmlElement("name")]
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Reference != null)
|
||||
return Reference.Name;
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
Reference = new Reference(value, Path);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the path of the reference
|
||||
/// </summary>
|
||||
[XmlElement("path")]
|
||||
public string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Reference != null)
|
||||
return Reference.Path;
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
Reference = new Reference(Name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the (immutable) reference
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public Reference Reference
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes this serializable reference
|
||||
/// </summary>
|
||||
public SerializableReference()
|
||||
{
|
||||
}
|
||||
|
||||
public SerializableReference(Reference reference)
|
||||
{
|
||||
Reference = reference;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user