Add SparkleConfig class to deal with configuration
This commit is contained in:
parent
1288494ae5
commit
80c676de6c
|
@ -8,6 +8,7 @@ SOURCES = \
|
|||
Defines.cs \
|
||||
SparkleBackend.cs \
|
||||
SparkleChangeSet.cs \
|
||||
SparkleConfig.cs \
|
||||
SparkleFetcherBase.cs \
|
||||
SparkleHelpers.cs \
|
||||
SparkleListenerBase.cs \
|
||||
|
@ -18,8 +19,9 @@ SOURCES = \
|
|||
Git/SparkleRepoGit.cs \
|
||||
Git/SparkleFetcherGit.cs \
|
||||
Hg/SparkleRepoHg.cs \
|
||||
Hg/SparkleFetcherHg.cs
|
||||
|
||||
Hg/SparkleFetcherHg.cs \
|
||||
Scp/SparkleFetcherScp.cs \
|
||||
Scp/SparkleRepoScp.cs
|
||||
|
||||
|
||||
SMARTIRC4NET_FILES_EXPANDED = $(foreach file, $(SMARTIRC4NET_FILES), $(top_builddir)/$(file))
|
||||
|
|
96
SparkleLib/SparkleConfig.cs
Normal file
96
SparkleLib/SparkleConfig.cs
Normal file
|
@ -0,0 +1,96 @@
|
|||
// SparkleShare, an instant update workflow to Git.
|
||||
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
using System;
|
||||
using System.Xml;
|
||||
|
||||
namespace SparkleLib {
|
||||
|
||||
public class SparkleConfig : XmlDocument {
|
||||
|
||||
public string Path;
|
||||
|
||||
|
||||
public SparkleConfig (string path)
|
||||
{
|
||||
Path = path;
|
||||
Load (Path);
|
||||
}
|
||||
|
||||
|
||||
public string UserName {
|
||||
get {
|
||||
XmlNode node = SelectSingleNode ("//user/name/text()");
|
||||
return node.Value;
|
||||
}
|
||||
|
||||
set {
|
||||
XmlNode node = SelectSingleNode ("//user/name/text()");
|
||||
node.InnerText = value;
|
||||
|
||||
Save (Path);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string UserEmail {
|
||||
get {
|
||||
XmlNode node = SelectSingleNode ("//user/name/email()");
|
||||
return node.Value;
|
||||
}
|
||||
|
||||
set {
|
||||
XmlNode node = SelectSingleNode ("//user/name/email()");
|
||||
node.InnerText = value;
|
||||
|
||||
Save (Path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void AddFolder (string name, SparkleBackend backend)
|
||||
{
|
||||
XmlNode node_folder = CreateNode (XmlNodeType.Element, "folder", null);
|
||||
|
||||
XmlNode node_name = CreateElement ("name");
|
||||
node_name.InnerText = name;
|
||||
|
||||
XmlNode node_backend = CreateElement ("backend");
|
||||
node_backend.InnerText = backend.Name;
|
||||
|
||||
node_folder.AppendChild (node_name);
|
||||
node_folder.AppendChild (node_backend);
|
||||
|
||||
XmlNode node_root = SelectSingleNode ("/");
|
||||
node_root.AppendChild (node_folder);
|
||||
|
||||
Save (Path);
|
||||
}
|
||||
|
||||
|
||||
public void RemoveFolder (string name)
|
||||
{
|
||||
foreach (XmlNode node_folder in SelectNodes ("//folder")) {
|
||||
if (node_folder ["name"].InnerText.Equals (name))
|
||||
SelectSingleNode ("/").RemoveChild (node_folder);
|
||||
}
|
||||
|
||||
Save (Path);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -51,6 +51,7 @@
|
|||
<Compile Include="SparkleListenerBase.cs" />
|
||||
<Compile Include="SparkleListenerIrc.cs" />
|
||||
<Compile Include="SparkleBackend.cs" />
|
||||
<Compile Include="SparkleConfig.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<ProjectExtensions>
|
||||
|
|
Loading…
Reference in a new issue