Use new XML based config scheme
This commit is contained in:
parent
cb27d3f551
commit
942aecc710
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
namespace SparkleLib {
|
namespace SparkleLib {
|
||||||
|
@ -69,7 +70,19 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void AddFolder (string name, SparkleBackend backend)
|
public string [] Folders {
|
||||||
|
get {
|
||||||
|
List<string> folders = new List<string> ();
|
||||||
|
|
||||||
|
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder"))
|
||||||
|
folders.Add (node_folder ["name"].InnerText);
|
||||||
|
|
||||||
|
return folders.ToArray ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void AddFolder (string name, string backend)
|
||||||
{
|
{
|
||||||
XmlNode node_folder = CreateNode (XmlNodeType.Element, "folder", null);
|
XmlNode node_folder = CreateNode (XmlNodeType.Element, "folder", null);
|
||||||
|
|
||||||
|
@ -77,7 +90,7 @@ namespace SparkleLib {
|
||||||
node_name.InnerText = name;
|
node_name.InnerText = name;
|
||||||
|
|
||||||
XmlNode node_backend = CreateElement ("backend");
|
XmlNode node_backend = CreateElement ("backend");
|
||||||
node_backend.InnerText = backend.Name;
|
node_backend.InnerText = backend;
|
||||||
|
|
||||||
node_folder.AppendChild (node_name);
|
node_folder.AppendChild (node_name);
|
||||||
node_folder.AppendChild (node_backend);
|
node_folder.AppendChild (node_backend);
|
||||||
|
@ -100,6 +113,28 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool FolderExists (string name)
|
||||||
|
{
|
||||||
|
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder")) {
|
||||||
|
if (node_folder ["name"].InnerText.Equals (name))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public string GetBackendForFolder (string name)
|
||||||
|
{
|
||||||
|
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder")) {
|
||||||
|
if (node_folder ["name"].InnerText.Equals (name))
|
||||||
|
return node_folder ["backend"].InnerText;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void Save ()
|
public void Save ()
|
||||||
{
|
{
|
||||||
if (!File.Exists (Path))
|
if (!File.Exists (Path))
|
||||||
|
|
|
@ -134,6 +134,7 @@ namespace SparkleShare {
|
||||||
// Remove the repository when a delete event occurs
|
// Remove the repository when a delete event occurs
|
||||||
watcher.Deleted += delegate (object o, FileSystemEventArgs args) {
|
watcher.Deleted += delegate (object o, FileSystemEventArgs args) {
|
||||||
RemoveRepository (args.FullPath);
|
RemoveRepository (args.FullPath);
|
||||||
|
SparkleConfig.DefaultConfig.RemoveFolder (Path.GetFileName (args.Name));
|
||||||
|
|
||||||
if (FolderListChanged != null)
|
if (FolderListChanged != null)
|
||||||
FolderListChanged ();
|
FolderListChanged ();
|
||||||
|
@ -186,8 +187,8 @@ namespace SparkleShare {
|
||||||
|
|
||||||
string user_email = match.Groups [1].Value;
|
string user_email = match.Groups [1].Value;
|
||||||
|
|
||||||
UserName = user_name;
|
WriteDefaultConfig (user_name, user_email);
|
||||||
UserEmail = UserEmail;
|
|
||||||
File.Delete (old_global_config_file_path);
|
File.Delete (old_global_config_file_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -499,18 +500,33 @@ namespace SparkleShare {
|
||||||
if (folder_path.Equals (SparklePaths.SparkleTmpPath))
|
if (folder_path.Equals (SparklePaths.SparkleTmpPath))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
string folder_name = Path.GetFileName (folder_path);
|
||||||
|
string backend = SparkleConfig.DefaultConfig.GetBackendForFolder (folder_name);
|
||||||
|
|
||||||
|
if (backend == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
SparkleRepoBase repo = null;
|
SparkleRepoBase repo = null;
|
||||||
if (Directory.Exists (Path.Combine (folder_path, ".git"))) {
|
|
||||||
|
if (backend.Equals ("Git")) { Console.WriteLine ("Git: " + folder_path);
|
||||||
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
|
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
|
||||||
|
|
||||||
} else if (Directory.Exists (Path.Combine (folder_path, ".hg"))) {
|
} else if (backend.Equals ("Hg")) {
|
||||||
SparkleBackend hg_backend = new SparkleBackend ("Hg", new string [] {"/opt/local/bin/hg", "/usr/bin/hg"});
|
SparkleBackend hg_backend = new SparkleBackend ("Hg",
|
||||||
|
new string [] {
|
||||||
|
"/opt/local/bin/hg",
|
||||||
|
"/usr/bin/hg"
|
||||||
|
});
|
||||||
|
|
||||||
repo = new SparkleRepoHg (folder_path, hg_backend);
|
repo = new SparkleRepoHg (folder_path, hg_backend);
|
||||||
} else if (Directory.Exists (Path.Combine (folder_path, ".sparkleshare"))) {
|
|
||||||
|
} else if (backend.Equals ("Scp")) {
|
||||||
SparkleBackend scp_backend = new SparkleBackend ("Scp", new string [] {"/usr/bin/scp"});
|
SparkleBackend scp_backend = new SparkleBackend ("Scp", new string [] {"/usr/bin/scp"});
|
||||||
repo = new SparkleRepoScp (folder_path, scp_backend);
|
repo = new SparkleRepoScp (folder_path, scp_backend);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) {
|
repo.NewChangeSet += delegate (SparkleChangeSet change_set, string repository_path) {
|
||||||
string message = FormatMessage (change_set);
|
string message = FormatMessage (change_set);
|
||||||
|
|
||||||
|
@ -566,8 +582,14 @@ namespace SparkleShare {
|
||||||
{
|
{
|
||||||
Repositories = new List<SparkleRepoBase> ();
|
Repositories = new List<SparkleRepoBase> ();
|
||||||
|
|
||||||
foreach (string folder_path in Directory.GetDirectories (SparklePaths.SparklePath))
|
foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) {
|
||||||
AddRepository (folder_path);
|
string folder_path = Path.Combine (SparklePaths.SparklePath, folder_name);
|
||||||
|
|
||||||
|
if (Directory.Exists (folder_path))
|
||||||
|
AddRepository (folder_path);
|
||||||
|
else
|
||||||
|
SparkleConfig.DefaultConfig.RemoveFolder (folder_name);
|
||||||
|
}
|
||||||
|
|
||||||
if (FolderListChanged != null)
|
if (FolderListChanged != null)
|
||||||
FolderListChanged ();
|
FolderListChanged ();
|
||||||
|
@ -972,15 +994,22 @@ namespace SparkleShare {
|
||||||
string canonical_name = Path.GetFileNameWithoutExtension (name);
|
string canonical_name = Path.GetFileNameWithoutExtension (name);
|
||||||
string tmp_folder = Path.Combine (SparklePaths.SparkleTmpPath, canonical_name);
|
string tmp_folder = Path.Combine (SparklePaths.SparkleTmpPath, canonical_name);
|
||||||
|
|
||||||
SparkleFetcherBase fetcher;
|
SparkleFetcherBase fetcher = null;
|
||||||
|
string backend = null;
|
||||||
|
|
||||||
if (url.EndsWith (".hg")) {
|
if (url.EndsWith (".hg")) {
|
||||||
url = url.Substring (0, (url.Length - 3));
|
url = url.Substring (0, (url.Length - 3));
|
||||||
fetcher = new SparkleFetcherHg (url, tmp_folder);
|
fetcher = new SparkleFetcherHg (url, tmp_folder);
|
||||||
|
backend = "Hg";
|
||||||
|
|
||||||
} else if (url.EndsWith (".scp")) {
|
} else if (url.EndsWith (".scp")) {
|
||||||
url = url.Substring (0, (url.Length - 4));
|
url = url.Substring (0, (url.Length - 4));
|
||||||
fetcher = new SparkleFetcherScp (url, tmp_folder);
|
fetcher = new SparkleFetcherScp (url, tmp_folder);
|
||||||
|
backend = "Scp";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
fetcher = new SparkleFetcherGit (url, tmp_folder);
|
fetcher = new SparkleFetcherGit (url, tmp_folder);
|
||||||
|
backend = "Git";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool target_folder_exists = Directory.Exists (Path.Combine (SparklePaths.SparklePath, canonical_name));
|
bool target_folder_exists = Directory.Exists (Path.Combine (SparklePaths.SparklePath, canonical_name));
|
||||||
|
@ -1011,6 +1040,8 @@ namespace SparkleShare {
|
||||||
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
SparkleHelpers.DebugInfo ("Controller", "Error moving folder: " + e.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SparkleConfig.DefaultConfig.AddFolder (target_folder_name, backend);
|
||||||
AddRepository (target_folder_path);
|
AddRepository (target_folder_path);
|
||||||
|
|
||||||
if (FolderFetched != null)
|
if (FolderFetched != null)
|
||||||
|
|
Loading…
Reference in a new issue