Refactor config and merge with Paths

This commit is contained in:
Hylke Bons 2011-07-24 02:00:40 +01:00
parent 69e13ae328
commit 5afd3dc59f
12 changed files with 223 additions and 261 deletions

View file

@ -73,7 +73,7 @@ namespace SparkleLib {
public override bool Fetch ()
{
SparkleGit git = new SparkleGit (SparklePaths.SparkleTmpPath,
SparkleGit git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
"clone \"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
git.Start ();
@ -95,7 +95,7 @@ namespace SparkleLib {
// the newly cloned repository
private void InstallConfiguration ()
{
string global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config.xml");
string global_config_file_path = Path.Combine (SparkleConfig.DefaultConfig.TmpPath, "config.xml");
if (!File.Exists (global_config_file_path))
return;

View file

@ -320,7 +320,7 @@ namespace SparkleLib {
// Append a timestamp to local version
string timestamp = DateTime.Now.ToString ("HH:mm MMM d");
string their_path = conflicting_path + " (" + SparkleConfig.DefaultConfig.UserName + ", " + timestamp + ")";
string their_path = conflicting_path + " (" + SparkleConfig.DefaultConfig.User.Name + ", " + timestamp + ")";
string abs_conflicting_path = Path.Combine (LocalPath, conflicting_path);
string abs_their_path = Path.Combine (LocalPath, their_path);
@ -437,9 +437,9 @@ namespace SparkleLib {
change_set.Folder = Name;
change_set.Revision = match.Groups [1].Value;
change_set.UserName = match.Groups [2].Value;
change_set.UserEmail = match.Groups [3].Value;
change_set.IsMerge = is_merge_commit;
change_set.User.Name = match.Groups [2].Value;
change_set.User.Email = match.Groups [3].Value;
change_set.IsMagical = is_merge_commit;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [4].Value),
int.Parse (match.Groups [5].Value), int.Parse (match.Groups [6].Value),

View file

@ -234,11 +234,13 @@ namespace SparkleLib {
SparkleChangeSet change_set = new SparkleChangeSet () {
Revision = match.Groups [9].Value,
UserName = match.Groups [7].Value.Trim (),
UserEmail = match.Groups [8].Value,
IsMerge = is_merge_commit
IsMagical = is_merge_commit
};
change_set.User.Name = match.Groups [7].Value.Trim ();
change_set.User.Email = match.Groups [8].Value;
change_set.Timestamp = new DateTime (int.Parse (match.Groups [1].Value),
int.Parse (match.Groups [2].Value), int.Parse (match.Groups [3].Value),
int.Parse (match.Groups [4].Value), int.Parse (match.Groups [5].Value), 0);

View file

@ -11,10 +11,6 @@ SOURCES = \
Defines.cs \
Git/SparkleFetcherGit.cs \
Git/SparkleRepoGit.cs \
Hg/SparkleFetcherHg.cs \
Hg/SparkleRepoHg.cs \
Scp/SparkleFetcherScp.cs \
Scp/SparkleRepoScp.cs \
SparkleBackend.cs \
SparkleChangeSet.cs \
SparkleConfig.cs \
@ -24,7 +20,6 @@ SOURCES = \
SparkleListenerIrc.cs \
SparkleListenerTcp.cs \
SparkleOptions.cs \
SparklePaths.cs \
SparkleRepoBase.cs \
SparkleWatcher.cs

View file

@ -16,20 +16,20 @@
using System;
using System.IO;
using System.Collections.Generic;
namespace SparkleLib {
public class SparkleChangeSet {
public string UserName;
public string UserEmail;
public SparkleUser User = new SparkleUser ("Unknown", "Unknown");
public string Folder;
public string Revision;
public DateTime Timestamp;
public DateTime FirstTimestamp;
public bool IsMerge = false;
public bool IsMagical = false;
public List<string> Added = new List<string> ();
public List<string> Deleted = new List<string> ();
@ -89,5 +89,31 @@ namespace SparkleLib {
public string Email;
public string PublicKey;
public SparkleUser (string name, string email)
{
Name = name;
Email = email;
}
}
public class SparkleFolder {
public string Name;
// TODO: Uri
public string FullPath {
get {
return Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, Name);
}
}
public SparkleFolder (string name)
{
Name = name;
}
}
}

View file

@ -26,15 +26,33 @@ namespace SparkleLib {
public class SparkleConfig : XmlDocument {
public static SparkleConfig DefaultConfig = new SparkleConfig (
SparklePaths.SparkleConfigPath, "config.xml");
public static string ConfigPath = Path.Combine (
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData),
"sparkleshare");
public string Path;
public static SparkleConfig DefaultConfig = new SparkleConfig (
ConfigPath, "config.xml");
public string FullPath;
public string HomePath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
public string TmpPath;
public string FoldersPath {
get {
if (GetConfigOption ("folders_path") != null)
return GetConfigOption ("folders_path");
else
return Path.Combine (HomePath, "SparkleShare");
}
}
public SparkleConfig (string config_path, string config_file_name)
{
Path = System.IO.Path.Combine (config_path, config_file_name);
FullPath = System.IO.Path.Combine (config_path, config_file_name);
TmpPath = Path.Combine (FoldersPath, ".tmp");
if (!Directory.Exists (config_path)) {
Directory.CreateDirectory (config_path);
@ -47,10 +65,10 @@ namespace SparkleLib {
SparkleHelpers.DebugInfo ("Config", "Created \"" + icons_path + "\"");
}
if (!File.Exists (Path))
if (!File.Exists (FullPath))
CreateInitialConfig ();
Load (Path);
Load (FullPath);
}
@ -74,7 +92,7 @@ namespace SparkleLib {
if (string.IsNullOrEmpty (user_name))
user_name = "Unknown";
TextWriter writer = new StreamWriter (Path);
TextWriter writer = new StreamWriter (FullPath);
string n = Environment.NewLine;
writer.Write ("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + n +
@ -86,36 +104,31 @@ namespace SparkleLib {
"</sparkleshare>");
writer.Close ();
SparkleHelpers.DebugInfo ("Config", "Created \"" + Path + "\"");
SparkleHelpers.DebugInfo ("Config", "Created \"" + FullPath + "\"");
}
public string UserName {
public SparkleUser User {
get {
XmlNode node = SelectSingleNode ("/sparkleshare/user/name/text()");
return node.Value;
XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()");
string name = name_node.Value;
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
string email = email_node.Value;
return new SparkleUser (name, email);
}
set {
XmlNode node = SelectSingleNode ("/sparkleshare/user/name/text()");
node.InnerText = value;
SparkleUser user = (SparkleUser) value;
Save ();
}
}
XmlNode name_node = SelectSingleNode ("/sparkleshare/user/name/text()");
name_node.InnerText = user.Name;
XmlNode email_node = SelectSingleNode ("/sparkleshare/user/email/text()");
email_node.InnerText = user.Email;
public string UserEmail {
get {
XmlNode node = SelectSingleNode ("/sparkleshare/user/email/text()");
return node.Value;
}
set {
XmlNode node = SelectSingleNode ("/sparkleshare/user/email/text()");
node.InnerText = value;
Save ();
this.Save ();
}
}
@ -132,27 +145,6 @@ namespace SparkleLib {
}
public List<string> FolderPaths {
get {
List<string> folders = new List<string> ();
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder")) {
Uri uri = new Uri (node_folder ["url"].InnerText);
String path = uri.LocalPath;
if (!folders.Contains (path))
folders.Add (path);
if (1 < path.Length && "/" == path.Substring (0, 1))
if (!folders.Contains (path.Substring (1)))
folders.Add (path.Substring (1));
}
return folders;
}
}
public void AddFolder (string name, string url, string backend)
{
XmlNode node_name = CreateElement ("name");
@ -172,22 +164,7 @@ namespace SparkleLib {
XmlNode node_root = SelectSingleNode ("/sparkleshare");
node_root.AppendChild (node_folder);
Save ();
}
public bool SetFolderOptionalAttribute (string name, string key, string value)
{
XmlNode folder = this.GetFolder(name);
if (folder == null) return false;
if (folder[key] != null) {
folder[key].InnerText = value;
} else {
XmlNode new_node = CreateElement(key);
new_node.InnerText = value;
folder.AppendChild(new_node);
}
return true;
this.Save ();
}
@ -198,28 +175,65 @@ namespace SparkleLib {
SelectSingleNode ("/sparkleshare").RemoveChild (node_folder);
}
Save ();
this.Save ();
}
public bool FolderExists (string name)
{
XmlNode folder = this.GetFolder(name);
return folder != null;
XmlNode folder = this.GetFolder (name);
return (folder != null);
}
public string GetBackendForFolder (string name)
{
return this.GetFolderValue(name, "backend");
return this.GetFolderValue (name, "backend");
}
public string GetUrlForFolder (string name)
{
return this.GetFolderValue(name, "url");
return this.GetFolderValue (name, "url");
}
public bool SetFolderOptionalAttribute (string folder_name, string key, string value)
{
XmlNode folder = this.GetFolder (folder_name);
if (folder == null)
return false;
if (folder [key] != null) {
folder [key].InnerText = value;
} else {
XmlNode new_node = CreateElement (key);
new_node.InnerText = value;
folder.AppendChild (new_node);
}
return true;
}
public string GetFolderOptionalAttribute (string folder_name, string key)
{
XmlNode folder = this.GetFolder (folder_name);
if (folder != null) {
if (folder [key] != null)
return folder [key].InnerText;
else
return null;
} else {
return null;
}
}
public List<string> Hosts {
get {
@ -227,6 +241,7 @@ namespace SparkleLib {
foreach (XmlNode node_folder in SelectNodes ("/sparkleshare/folder")) {
Uri uri = new Uri (node_folder ["url"].InnerText);
if (!hosts.Contains (uri.Host))
hosts.Add (uri.Host);
}
@ -251,21 +266,25 @@ namespace SparkleLib {
}
}
public string GetAnnouncementsForFolder (string name)
private XmlNode GetFolder (string name)
{
return this.GetFolderValue(name, "announcements");
return SelectSingleNode (String.Format("/sparkleshare/folder[name='{0}']", name));
}
public string GetAnnouncementUrlForFolder (string name)
private string GetFolderValue (string name, string key)
{
// examples?
// tcp://localhost:9999/
// xmpp:someuser@somexmppserver?canhavefunnybits
// irc://hbons/#somechatroom
return this.GetFolderValue(name, "announcements_url");
XmlNode folder = this.GetFolder(name);
if ((folder != null) && (folder [key] != null)) {
return folder [key].InnerText;
}
return null;
}
public string GetConfigOption (string name)
{
XmlNode node = SelectSingleNode ("/sparkleshare/" + name);
@ -293,34 +312,17 @@ namespace SparkleLib {
}
SparkleHelpers.DebugInfo ("Config", "Updated " + name + ":" + content);
Save ();
this.Save ();
}
public void Save ()
private void Save ()
{
if (!File.Exists (Path))
throw new ConfigFileNotFoundException (Path + " does not exist");
if (!File.Exists (FullPath))
throw new ConfigFileNotFoundException (FullPath + " does not exist");
Save (Path);
SparkleHelpers.DebugInfo ("Config", "Updated \"" + Path + "\"");
}
private XmlNode GetFolder (string name)
{
return SelectSingleNode(String.Format("/sparkleshare/folder[name='{0}']", name));
}
private string GetFolderValue (string name, string key)
{
XmlNode folder = this.GetFolder(name);
if ((folder != null) && (folder[key] != null)) {
return folder[key].InnerText;
}
return null;
this.Save (FullPath);
SparkleHelpers.DebugInfo ("Config", "Updated \"" + FullPath + "\"");
}
}

View file

@ -113,7 +113,7 @@ namespace SparkleLib {
private void DisableHostKeyCheckingForHost (string host)
{
string path = SparklePaths.HomePath;
string path = SparkleConfig.DefaultConfig.HomePath;
if (!(SparkleBackend.Platform == PlatformID.Unix ||
SparkleBackend.Platform == PlatformID.MacOSX)) {
@ -150,7 +150,7 @@ namespace SparkleLib {
private void EnableHostKeyCheckingForHost (string host)
{
string path = SparklePaths.HomePath;
string path = SparkleConfig.DefaultConfig.HomePath;
if (!(SparkleBackend.Platform == PlatformID.Unix ||
SparkleBackend.Platform == PlatformID.MacOSX)) {

View file

@ -41,7 +41,8 @@ namespace SparkleLib {
public static SparkleListenerBase CreateListener (string folder_name, string folder_identifier)
{
string uri = SparkleConfig.DefaultConfig.GetAnnouncementUrlForFolder (folder_name);
string uri = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (
folder_name, "announcements_url");
if (uri == null) {
// This is SparkleShare's centralized notification service.

View file

@ -1,36 +0,0 @@
// SparkleShare, a collaboration and sharing tool.
// 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.IO;
namespace SparkleLib {
public static class SparklePaths {
public static string HomePath = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
public static string SparklePath = Path.Combine (HomePath ,"SparkleShare");
public static string SparkleTmpPath = Path.Combine (SparklePath, ".tmp");
public static string SparkleConfigPath = Path.Combine (Environment.GetFolderPath (
Environment.SpecialFolder.ApplicationData), "sparkleshare");
public static string SparkleLocalIconPath = Path.Combine (SparkleConfigPath, "icons");
public static string SparkleInstallPath = Path.Combine (Defines.PREFIX, "sparkleshare");
public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.DATAROOTDIR, "sparkleshare", "icons");
}
}

View file

@ -365,10 +365,8 @@ namespace SparkleLib {
if (match_notes.Success) {
SparkleNote note = new SparkleNote () {
User = new SparkleUser () {
Name = match_notes.Groups [1].Value,
Email = match_notes.Groups [2].Value
},
User = new SparkleUser (match_notes.Groups [1].Value,
match_notes.Groups [2].Value),
Timestamp = new DateTime (1970, 1, 1).AddSeconds (int.Parse (match_notes.Groups [3].Value)),
Body = match_notes.Groups [4].Value
};
@ -452,7 +450,7 @@ namespace SparkleLib {
foreach (string added in change_set.Added) {
if (added.Contains (".notes")) {
if (NewNote != null)
NewNote (change_set.UserName, change_set.UserEmail);
NewNote (change_set.User.Name, change_set.User.Email);
note_added = true;
break;
@ -524,8 +522,8 @@ namespace SparkleLib {
string n = Environment.NewLine;
note = "<note>" + n +
" <user>" + n +
" <name>" + SparkleConfig.DefaultConfig.UserName + "</name>" + n +
" <email>" + SparkleConfig.DefaultConfig.UserEmail + "</email>" + n +
" <name>" + SparkleConfig.DefaultConfig.User.Name + "</name>" + n +
" <email>" + SparkleConfig.DefaultConfig.User.Email + "</email>" + n +
" </user>" + n +
" <timestamp>" + timestamp + "</timestamp>" + n +
" <body>" + note + "</body>" + n +

View file

@ -30,7 +30,7 @@ namespace SparkleShare {
// We have to use our own custom made folder watcher, as
// System.IO.FileSystemWatcher fails watching subfolders on Mac
private SparkleMacWatcher watcher = new SparkleMacWatcher (SparklePaths.SparklePath);
private SparkleMacWatcher watcher = new SparkleMacWatcher (SparkleConfig.DefaultConfig.FoldersPath);
public SparkleMacController () : base () { }
@ -53,7 +53,7 @@ namespace SparkleShare {
repo_name = repo_name.Trim ("/".ToCharArray ());
FileSystemEventArgs args = new FileSystemEventArgs (WatcherChangeTypes.Changed,
Path.Combine (SparklePaths.SparklePath, path), Path.GetFileName (path));
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, path), Path.GetFileName (path));
foreach (SparkleRepoBase repo in Repositories) {
if (repo.Name.Equals (repo_name))
@ -109,8 +109,8 @@ namespace SparkleShare {
// Creates the SparkleShare folder in the user's home folder
public override bool CreateSparkleShareFolder ()
{
if (!Directory.Exists (SparklePaths.SparklePath)) {
Directory.CreateDirectory (SparklePaths.SparklePath);
if (!Directory.Exists (SparkleConfig.DefaultConfig.FoldersPath)) {
Directory.CreateDirectory (SparkleConfig.DefaultConfig.FoldersPath);
return true;
} else {
@ -122,7 +122,7 @@ namespace SparkleShare {
// Opens the SparkleShare folder or an (optional) subfolder
public override void OpenSparkleShareFolder (string subfolder)
{
string folder = Path.Combine (SparklePaths.SparklePath, subfolder);
string folder = Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, subfolder);
folder.Replace (" ", "\\ "); // Escape space-characters
NSWorkspace.SharedWorkspace.OpenFile (folder);

View file

@ -36,7 +36,7 @@ namespace SparkleShare {
public List <SparkleRepoBase> Repositories;
public string FolderSize;
public readonly string SparklePath = SparklePaths.SparklePath;
public readonly string SparklePath = SparkleConfig.DefaultConfig.FoldersPath;
public event OnQuitWhileSyncingEventHandler OnQuitWhileSyncing;
public delegate void OnQuitWhileSyncingEventHandler ();
@ -96,18 +96,13 @@ namespace SparkleShare {
FolderSize = GetFolderSize ();
// TODO: Legacy. Remove at some later point
string old_global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config");
if (File.Exists (old_global_config_file_path))
MigrateConfig ();
if (FirstRun)
SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
else
AddKey ();
// Watch the SparkleShare folder
FileSystemWatcher watcher = new FileSystemWatcher (SparklePaths.SparklePath) {
FileSystemWatcher watcher = new FileSystemWatcher (SparkleConfig.DefaultConfig.FoldersPath) {
IncludeSubdirectories = false,
EnableRaisingEvents = true,
Filter = "*"
@ -152,41 +147,16 @@ namespace SparkleShare {
public bool FirstRun {
get {
return SparkleConfig.DefaultConfig.UserEmail.Equals ("Unknown");
return SparkleConfig.DefaultConfig.User.Email.Equals ("Unknown");
}
}
private void MigrateConfig ()
{
string old_global_config_file_path = Path.Combine (SparklePaths.SparkleConfigPath, "config");
StreamReader reader = new StreamReader (old_global_config_file_path);
string global_config_file = reader.ReadToEnd ();
reader.Close ();
Regex regex = new Regex (@"name.+= (.+)");
Match match = regex.Match (global_config_file);
string user_name = match.Groups [1].Value;
regex = new Regex (@"email.+= (.+)");
match = regex.Match (global_config_file);
string user_email = match.Groups [1].Value;
SparkleConfig.DefaultConfig.UserName = user_name;
SparkleConfig.DefaultConfig.UserEmail = user_email;
File.Delete (old_global_config_file_path);
}
// Uploads the user's public key to the server
public bool AcceptInvitation (string server, string folder, string token)
{
// The location of the user's public key for SparkleShare
string public_key_file_path = SparkleHelpers.CombineMore (SparklePaths.HomePath, ".ssh",
string public_key_file_path = SparkleHelpers.CombineMore (SparkleConfig.DefaultConfig.HomePath, ".ssh",
"sparkleshare." + UserEmail + ".key.pub");
if (!File.Exists (public_key_file_path))
@ -224,15 +194,6 @@ namespace SparkleShare {
}
public List<string> FolderPaths {
get {
List<string> folders = SparkleConfig.DefaultConfig.FolderPaths;
folders.Sort ();
return folders;
}
}
public List<string> PreviousHosts {
get {
List<string> hosts = SparkleConfig.DefaultConfig.HostsWithUsername;
@ -261,8 +222,14 @@ namespace SparkleShare {
{
List<SparkleChangeSet> list = new List<SparkleChangeSet> ();
foreach (SparkleRepoBase repo in Repositories)
list.AddRange (repo.GetChangeSets (50));
foreach (SparkleRepoBase repo in Repositories) {
List<SparkleChangeSet> change_sets = repo.GetChangeSets (50);
if (change_sets != null)
list.AddRange (change_sets);
else
SparkleHelpers.DebugInfo ("Log", "Could not create log for " + repo.Name);
}
list.Sort ((x, y) => (x.Timestamp.CompareTo (y.Timestamp)));
list.Reverse ();
@ -279,7 +246,7 @@ namespace SparkleShare {
if (name == null)
return GetLog ();
string path = Path.Combine (SparklePaths.SparklePath, name);
string path = Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, name);
int log_size = 50;
foreach (SparkleRepoBase repo in Repositories) {
@ -308,8 +275,8 @@ namespace SparkleShare {
return null;
foreach (SparkleChangeSet change_set in change_sets) {
if (!emails.Contains (change_set.UserEmail))
emails.Add (change_set.UserEmail);
if (!emails.Contains (change_set.User.Email))
emails.Add (change_set.User.Email);
bool change_set_inserted = false;
foreach (ActivityDay stored_activity_day in activity_days) {
@ -319,8 +286,8 @@ namespace SparkleShare {
bool squash = false;
foreach (SparkleChangeSet existing_set in stored_activity_day) {
if (change_set.UserName.Equals (existing_set.UserName) &&
change_set.UserEmail.Equals (existing_set.UserEmail) &&
if (change_set.User.Name.Equals (existing_set.User.Name) &&
change_set.User.Email.Equals (existing_set.User.Email) &&
change_set.Folder.Equals (existing_set.Folder)) {
existing_set.Added.AddRange (change_set.Added);
@ -377,14 +344,14 @@ namespace SparkleShare {
foreach (SparkleChangeSet change_set in activity_day) {
string event_entry = "<dl>";
if (change_set.IsMerge) {
if (change_set.IsMagical) {
event_entry += "<dd>Did something magical</dd>";
} else {
if (change_set.Edited.Count > 0) {
foreach (string file_path in change_set.Edited) {
string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
change_set.Folder, file_path);
string absolute_file_path = Path.Combine (
SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder, file_path);
if (File.Exists (absolute_file_path))
event_entry += "<dd class='document edited'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>";
@ -395,8 +362,8 @@ namespace SparkleShare {
if (change_set.Added.Count > 0) {
foreach (string file_path in change_set.Added) {
string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
change_set.Folder, file_path);
string absolute_file_path = Path.Combine (
SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder, file_path);
if (File.Exists (absolute_file_path))
event_entry += "<dd class='document added'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>";
@ -407,8 +374,8 @@ namespace SparkleShare {
if (change_set.Deleted.Count > 0) {
foreach (string file_path in change_set.Deleted) {
string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
change_set.Folder, file_path);
string absolute_file_path = Path.Combine (
SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder, file_path);
if (File.Exists (absolute_file_path))
event_entry += "<dd class='document deleted'><a href='" + absolute_file_path + "'>" + file_path + "</a></dd>";
@ -421,10 +388,10 @@ namespace SparkleShare {
int i = 0;
foreach (string file_path in change_set.MovedFrom) {
string to_file_path = change_set.MovedTo [i];
string absolute_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
change_set.Folder, file_path);
string absolute_to_file_path = SparkleHelpers.CombineMore (SparklePaths.SparklePath,
change_set.Folder, to_file_path);
string absolute_file_path = Path.Combine (
SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder, file_path);
string absolute_to_file_path = Path.Combine (
SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder, file_path);
if (File.Exists (absolute_file_path))
event_entry += "<dd class='document moved'><a href='" + absolute_file_path + "'>" + file_path + "</a><br/>";
@ -460,8 +427,8 @@ namespace SparkleShare {
comments += "</div>";
string avatar_email = "";
if (File.Exists (GetAvatar (change_set.UserEmail, 48)))
avatar_email = change_set.UserEmail;
if (File.Exists (GetAvatar (change_set.User.Email, 48)))
avatar_email = change_set.User.Email;
event_entry += "</dl>";
@ -472,7 +439,7 @@ namespace SparkleShare {
" " + timestamp;
event_entries += event_entry_html.Replace ("<!-- $event-entry-content -->", event_entry)
.Replace ("<!-- $event-user-name -->", change_set.UserName)
.Replace ("<!-- $event-user-name -->", change_set.User.Name)
.Replace ("<!-- $event-avatar-url -->", "file://" + GetAvatar (avatar_email, 48))
.Replace ("<!-- $event-time -->", timestamp)
.Replace ("<!-- $event-folder -->", change_set.Folder)
@ -574,7 +541,7 @@ namespace SparkleShare {
// Adds a repository to the list of repositories
private void AddRepository (string folder_path)
{
if (folder_path.Equals (SparklePaths.SparkleTmpPath))
if (folder_path.Equals (SparkleConfig.DefaultConfig.TmpPath))
return;
string folder_name = Path.GetFileName (folder_path);
@ -585,20 +552,20 @@ namespace SparkleShare {
SparkleRepoBase repo = null;
if (backend.Equals ("Hg"))
/* if (backend.Equals ("Hg"))
repo = new SparkleRepoHg (folder_path, new SparkleBackendHg ());
else if (backend.Equals ("Scp"))
repo = new SparkleRepoScp (folder_path, new SparkleBackendScp ());
else
else */
repo = new SparkleRepoGit (folder_path, SparkleBackend.DefaultBackend);
repo.NewChangeSet += delegate (SparkleChangeSet change_set) {
string message = FormatMessage (change_set);
if (NotificationRaised != null)
NotificationRaised (change_set.UserName, change_set.UserEmail, message, repo.LocalPath);
NotificationRaised (change_set.User.Name, change_set.User.Email, message, repo.LocalPath);
};
repo.NewNote += delegate (string user_name, string user_email) {
@ -661,7 +628,7 @@ namespace SparkleShare {
Repositories = new List<SparkleRepoBase> ();
foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) {
string folder_path = Path.Combine (SparklePaths.SparklePath, folder_name);
string folder_path = new SparkleFolder (folder_name).FullPath;
if (Directory.Exists (folder_path))
AddRepository (folder_path);
@ -709,7 +676,9 @@ namespace SparkleShare {
private string GetFolderSize ()
{
double folder_size = CalculateFolderSize (new DirectoryInfo (SparklePaths.SparklePath));
double folder_size = CalculateFolderSize (
new DirectoryInfo (SparkleConfig.DefaultConfig.FoldersPath));
return FormatFolderSize (folder_size);
}
@ -816,7 +785,7 @@ namespace SparkleShare {
// so all activity is done with this key
public void AddKey ()
{
string keys_path = SparklePaths.SparkleConfigPath;
string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath);
string key_file_name = "sparkleshare." + UserEmail + ".key";
Process process = new Process ();
@ -840,11 +809,11 @@ namespace SparkleShare {
public string UserName
{
get {
return SparkleConfig.DefaultConfig.UserName;
return SparkleConfig.DefaultConfig.User.Name;
}
set {
SparkleConfig.DefaultConfig.UserName = value;
SparkleConfig.DefaultConfig.User = new SparkleUser (value, UserEmail);
}
}
@ -853,11 +822,11 @@ namespace SparkleShare {
public string UserEmail
{
get {
return SparkleConfig.DefaultConfig.UserEmail;
return SparkleConfig.DefaultConfig.User.Email;
}
set {
SparkleConfig.DefaultConfig.UserEmail = value;
SparkleConfig.DefaultConfig.User = new SparkleUser (UserName, value);
}
}
@ -865,7 +834,7 @@ namespace SparkleShare {
// Generates and installs an RSA keypair to identify this system
public void GenerateKeyPair ()
{
string keys_path = SparklePaths.SparkleConfigPath;
string keys_path = Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath);
string key_file_name = "sparkleshare." + UserEmail + ".key";
string key_file_path = Path.Combine (keys_path, key_file_name);
@ -914,8 +883,9 @@ namespace SparkleShare {
{
List<string> old_avatars = new List<string> ();
bool avatar_fetched = false;
string avatar_path = SparkleHelpers.CombineMore (
SparklePaths.SparkleLocalIconPath, size + "x" + size, "status");
string avatar_path = Path.Combine (
Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath), "icons",
size + "x" + size, "status");
if (!Directory.Exists (avatar_path)) {
Directory.CreateDirectory (avatar_path);
@ -974,7 +944,8 @@ namespace SparkleShare {
public string GetAvatar (string email, int size)
{
string avatar_file_path = SparkleHelpers.CombineMore (
SparklePaths.SparkleLocalIconPath, size + "x" + size, "status", "avatar-" + email);
Path.GetDirectoryName (SparkleConfig.DefaultConfig.FullPath), "icons",
size + "x" + size, "status", "avatar-" + email);
return avatar_file_path;
}
@ -985,17 +956,18 @@ namespace SparkleShare {
server = server.Trim ();
remote_folder = remote_folder.Trim ();
if (!Directory.Exists (SparklePaths.SparkleTmpPath))
Directory.CreateDirectory (SparklePaths.SparkleTmpPath);
string tmp_path = SparkleConfig.DefaultConfig.TmpPath;
if (!Directory.Exists (tmp_path))
Directory.CreateDirectory (tmp_path);
// Strip the '.git' from the name
string canonical_name = Path.GetFileNameWithoutExtension (remote_folder);
string tmp_folder = Path.Combine (SparklePaths.SparkleTmpPath, canonical_name);
string tmp_folder = Path.Combine (tmp_path, canonical_name);
SparkleFetcherBase fetcher = null;
string backend = null;
if (remote_folder.EndsWith (".hg")) {
/* if (remote_folder.EndsWith (".hg")) {
remote_folder = remote_folder.Substring (0, (remote_folder.Length - 3));
fetcher = new SparkleFetcherHg (server, remote_folder, tmp_folder);
backend = "Hg";
@ -1005,12 +977,13 @@ namespace SparkleShare {
fetcher = new SparkleFetcherScp (server, remote_folder, tmp_folder);
backend = "Scp";
} else {
} else {*/
fetcher = new SparkleFetcherGit (server, remote_folder, tmp_folder);
backend = "Git";
}
//}
bool target_folder_exists = Directory.Exists (Path.Combine (SparklePaths.SparklePath, canonical_name));
bool target_folder_exists = Directory.Exists (
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, canonical_name));
// Add a numbered suffix to the nameif a folder with the same name
// already exists. Example: "Folder (2)"
@ -1018,7 +991,7 @@ namespace SparkleShare {
while (target_folder_exists) {
i++;
target_folder_exists = Directory.Exists (
Path.Combine (SparklePaths.SparklePath, canonical_name + " (" + i + ")"));
Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, canonical_name + " (" + i + ")"));
}
string target_folder_name = canonical_name;
@ -1029,7 +1002,8 @@ namespace SparkleShare {
// Needed to do the moving
SparkleHelpers.ClearAttributes (tmp_folder);
string target_folder_path = Path.Combine (SparklePaths.SparklePath, target_folder_name);
string target_folder_path = Path.Combine (
SparkleConfig.DefaultConfig.FoldersPath, target_folder_name);
try {
Directory.Move (tmp_folder, target_folder_path);
@ -1053,8 +1027,8 @@ namespace SparkleShare {
fetcher.Dispose ();
if (Directory.Exists (SparklePaths.SparkleTmpPath))
Directory.Delete (SparklePaths.SparkleTmpPath, true);
if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true);
};
@ -1064,8 +1038,8 @@ namespace SparkleShare {
fetcher.Dispose ();
if (Directory.Exists (SparklePaths.SparkleTmpPath))
Directory.Delete (SparklePaths.SparkleTmpPath, true);
if (Directory.Exists (tmp_path))
Directory.Delete (tmp_path, true);
};