Work on project storage

This commit is contained in:
2014-07-26 09:39:05 +03:00
parent 3d0a028920
commit 0c57cabe56
11 changed files with 815 additions and 9 deletions

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RainmeterEditor.Model;
namespace RainmeterEditor.Business
{
public class ProjectManager
{
public Project ActiveProject { get; protected set; }
public void Open() { }
public void Close() { }
}
}

View File

@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace RainmeterEditor.Model
{
public class Project
{
[XmlElement("name")]
public string Name { get; set; }
[XmlElement("author")]
public string Author { get; set; }
[XmlIgnore]
public Version Version { get; set; }
[XmlElement("version")]
public string VersionString
{
get
{
return Version.ToString();
}
set
{
Version = new Version(value);
}
}
[XmlElement("autoLoadFile")]
public Reference AutoLoadFile { get; set; }
[XmlArray("variableFiles")]
public List<Reference> VariableFiles { get; set; }
[XmlIgnore]
public Version MinimumRainmeter { get; set; }
[XmlElement("minimumRainmeter")]
public string MinimumRainmeterString
{
get
{
return MinimumRainmeter.ToString();
}
set
{
MinimumRainmeter = new Version(value);
}
}
[XmlIgnore]
public Version MinimumWindows { get; set; }
[XmlElement("minimumWindows")]
public string MinimumWindowsString
{
get
{
return MinimumWindows.ToString();
}
set
{
MinimumWindows = new Version(value);
}
}
[XmlElement("root")]
public Tree<Reference> Root { get; set; }
public Project()
{
Root = new Tree<Reference>();
VariableFiles = new List<Reference>();
Version = new Version();
MinimumRainmeter = new Version("3.1");
MinimumWindows = new Version("5.1");
}
public override bool Equals(object obj)
{
Project other = obj as Project;
if (other == null)
return false;
bool res = String.Equals(Author, other.Author);
res &= Reference.Equals(AutoLoadFile, other.AutoLoadFile);
res &= Version.Equals(MinimumRainmeter, other.MinimumRainmeter);
res &= Version.Equals(MinimumWindows, other.MinimumWindows);
res &= String.Equals(Name, other.Name);
res &= Tree<Reference>.Equals(Root, other.Root);
res &= Version.Equals(Version, other.Version);
return res;
}
public override int GetHashCode()
{
int hash = (Author == null) ? 0 : Author.GetHashCode();
hash = hash * 7 + ((AutoLoadFile == null) ? 0 : AutoLoadFile.GetHashCode());
hash = hash * 7 + ((MinimumRainmeter == null) ? 0 : MinimumRainmeter.GetHashCode());
hash = hash * 7 + ((MinimumWindows == null) ? 0 : MinimumWindows.GetHashCode());
hash = hash * 7 + ((Name == null) ? 0 : Name.GetHashCode());
hash = hash * 7 + ((Root == null) ? 0 : Root.GetHashCode());
hash = hash * 7 + ((Version == null) ? 0 : Version.GetHashCode());
return hash;
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace RainmeterEditor.Model
{
/// <summary>
/// Reference to a file or folder
/// </summary>
public class Reference
{
[XmlAttribute("name")]
public string Name { get; set; }
[XmlAttribute("path")]
public string Path { get; set; }
public Reference()
{
}
public Reference(string name, string path = null)
{
Name = name;
Path = path;
}
public override bool Equals(object obj)
{
var other = obj as Reference;
// Types are different, so not equal
if (other == null)
return false;
// Compare using string equals
return String.Equals(Name, other.Name) && String.Equals(Path, other.Path);
}
public override int GetHashCode()
{
int hash = (Name == null) ? 0 : Name.GetHashCode();
hash = hash * 7 + ((Path == null) ? 0 : Path.GetHashCode());
return hash;
}
}
}

View File

@ -0,0 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
namespace RainmeterEditor.Model
{
public class Tree<T>
{
[XmlElement("data")]
public T Data { get; set; }
[XmlArray("children"), XmlArrayItem("child")]
public List<Tree<T>> Children { get; set; }
public Tree()
{
Children = new List<Tree<T>>();
Data = default(T);
}
public Tree(T data)
{
Children = new List<Tree<T>>();
Data = data;
}
public int IndexOf(Tree<T> item)
{
return Children.IndexOf(item);
}
public void Insert(int index, Tree<T> item)
{
Children.Insert(index, item);
}
public void RemoveAt(int index)
{
Children.RemoveAt(index);
}
public Tree<T> this[int index]
{
get
{
return Children[index];
}
set
{
Children[index] = value;
}
}
public void Add(Tree<T> item)
{
Children.Add(item);
}
public void Clear()
{
Children.Clear();
}
public bool Contains(Tree<T> item)
{
return Children.Contains(item);
}
public void CopyTo(Tree<T>[] array, int arrayIndex)
{
Children.CopyTo(array, arrayIndex);
}
public int Count
{
get { return Children.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove(Tree<T> item)
{
return Children.Remove(item);
}
public IEnumerator<Tree<T>> GetEnumerator()
{
return Children.GetEnumerator();
}
public int IndexOf(T item)
{
return Children.IndexOf(new Tree<T>(item));
}
public void Insert(int index, T item)
{
Children.Insert(index, new Tree<T>(item));
}
public void Add(T item)
{
Children.Add(new Tree<T>(item));
}
public bool Contains(T item)
{
return Children.Contains(new Tree<T>(item));
}
public void CopyTo(T[] array, int arrayIndex)
{
foreach (var node in Children)
array[arrayIndex++] = node.Data;
}
public bool Remove(T item)
{
return Children.Remove(new Tree<T>(item));
}
public override bool Equals(object obj)
{
Tree<T> other = obj as Tree<T>;
// Types are different, so not equal
if (other == null)
return false;
// Compare data
if (!object.Equals(Data, other.Data))
return false;
// Compare children array
return Children.SequenceEqual(other.Children);
}
public override int GetHashCode()
{
int hash = ((Data == null) ? 0 : Data.GetHashCode());
foreach (var c in Children)
hash = hash * 7 + c.GetHashCode();
return hash;
}
}
}

View File

@ -70,6 +70,7 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Business\DocumentManager.cs" />
<Compile Include="Business\ProjectManager.cs" />
<Compile Include="Documents\Text\TextDocument.cs" />
<Compile Include="Documents\Text\TextEditorControl.xaml.cs">
<DependentUpon>TextEditorControl.xaml</DependentUpon>
@ -88,8 +89,11 @@
<Compile Include="Documents\Text\TextEditor.cs" />
<Compile Include="Documents\Text\TextEditorFactory.cs" />
<Compile Include="Interop\NativeLibrary.cs" />
<Compile Include="Model\Project.cs" />
<Compile Include="Model\Property.cs" />
<Compile Include="Model\RainmeterConfig.cs" />
<Compile Include="Model\Reference.cs" />
<Compile Include="Model\Tree.cs" />
<Compile Include="Rainmeter.cs" />
<Compile Include="Resources\Strings.Designer.cs">
<AutoGen>True</AutoGen>
@ -97,6 +101,7 @@
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="Model\IDocumentStorage.cs" />
<Compile Include="Storage\ProjectStorage.cs" />
<Compile Include="Storage\SkinDirectory.cs" />
<Compile Include="UI\Command.cs" />
<Compile Include="UI\Dialogs\CreateDocumentDialog.xaml.cs">

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using RainmeterEditor.Model;
namespace RainmeterEditor.Storage
{
public class ProjectStorage
{
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;
// Clean up
file.Close();
return project;
}
public void Save(string path, Project project)
{
// Open file
var file = File.OpenWrite(path);
// Deserialize file
var serializer = new XmlSerializer(typeof(Project), new XmlRootAttribute("project"));
serializer.Serialize(file, project);
// Clean up
file.Close();
}
}
}