From 37f8e050c6e8d00310bf49b03404b34d430a5017 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sun, 15 Apr 2012 19:03:36 +0200 Subject: [PATCH] config: allow to specify a custom path for each folder. Closes #680 --- SparkleLib/Git/SparkleRepoGit.cs | 2 +- SparkleLib/SparkleChangeSet.cs | 10 +- SparkleLib/SparkleConfig.cs | 10 +- SparkleShare/Mac/SparkleController.cs | 2 +- SparkleShare/SparkleControllerBase.cs | 135 ++++++++++---------------- 5 files changed, 63 insertions(+), 96 deletions(-) diff --git a/SparkleLib/Git/SparkleRepoGit.cs b/SparkleLib/Git/SparkleRepoGit.cs index 97a988d9..8d259734 100644 --- a/SparkleLib/Git/SparkleRepoGit.cs +++ b/SparkleLib/Git/SparkleRepoGit.cs @@ -629,7 +629,7 @@ namespace SparkleLib.Git { if (match.Success) { SparkleChangeSet change_set = new SparkleChangeSet (); - change_set.Folder = Name; + change_set.Folder = new SparkleFolder (Name); change_set.Revision = match.Groups [1].Value; change_set.User = new SparkleUser (match.Groups [2].Value, match.Groups [3].Value); change_set.IsMagical = is_merge_commit; diff --git a/SparkleLib/SparkleChangeSet.cs b/SparkleLib/SparkleChangeSet.cs index 9293b7c3..05ca7a0c 100755 --- a/SparkleLib/SparkleChangeSet.cs +++ b/SparkleLib/SparkleChangeSet.cs @@ -25,7 +25,7 @@ namespace SparkleLib { public SparkleUser User = new SparkleUser ("Unknown", "Unknown"); - public string Folder; + public SparkleFolder Folder; public string Revision; public DateTime Timestamp; public DateTime FirstTimestamp; @@ -74,6 +74,7 @@ namespace SparkleLib { } + // TODO: Move to its own file (and update all .csproj files) public class SparkleFolder { public string Name; @@ -81,7 +82,12 @@ namespace SparkleLib { public string FullPath { get { - return Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, Name); + string custom_path = SparkleConfig.DefaultConfig.GetFolderOptionalAttribute (Name, "path"); + + if (custom_path != null) + return Path.Combine (custom_path, Name); + else + return Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, Name); } } diff --git a/SparkleLib/SparkleConfig.cs b/SparkleLib/SparkleConfig.cs index 13eddbd7..0536f098 100755 --- a/SparkleLib/SparkleConfig.cs +++ b/SparkleLib/SparkleConfig.cs @@ -256,13 +256,6 @@ namespace SparkleLib { } - public bool FolderExists (string name) - { - XmlNode folder = GetFolder (name); - return (folder != null); - } - - public string GetBackendForFolder (string name) { return GetFolderValue (name, "backend"); @@ -292,6 +285,7 @@ namespace SparkleLib { } Save (); + return true; } @@ -314,7 +308,7 @@ namespace SparkleLib { private XmlNode GetFolder (string name) { - return SelectSingleNode (String.Format("/sparkleshare/folder[name='{0}']", name)); + return SelectSingleNode (string.Format ("/sparkleshare/folder[name='{0}']", name)); } diff --git a/SparkleShare/Mac/SparkleController.cs b/SparkleShare/Mac/SparkleController.cs index 142328ff..37c8f28c 100755 --- a/SparkleShare/Mac/SparkleController.cs +++ b/SparkleShare/Mac/SparkleController.cs @@ -185,7 +185,7 @@ namespace SparkleShare { } } - + public override void OpenFolder (string path) { path = path.Replace (" ", "\\ "); // Escape space-characters diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index b65b49a7..dbbf318b 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -115,11 +115,9 @@ namespace SparkleShare { get { List unsynced_folders = new List (); - lock (this.repo_lock) { - foreach (SparkleRepoBase repo in Repositories) { - if (repo.HasUnsyncedChanges) - unsynced_folders.Add (repo.Name); - } + foreach (SparkleRepoBase repo in Repositories) { + if (repo.HasUnsyncedChanges) + unsynced_folders.Add (repo.Name); } return unsynced_folders; @@ -278,15 +276,13 @@ namespace SparkleShare { { List list = new List (); - lock (this.repo_lock) { - foreach (SparkleRepoBase repo in Repositories) { - List change_sets = repo.GetChangeSets (30); - - if (change_sets != null) - list.AddRange (change_sets); - else - SparkleHelpers.DebugInfo ("Log", "Could not create log for " + repo.Name); - } + foreach (SparkleRepoBase repo in Repositories) { + List change_sets = repo.GetChangeSets (30); + + 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))); @@ -304,14 +300,12 @@ namespace SparkleShare { if (name == null) return GetLog (); - string path = Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, name); + string path = new SparkleFolder (name).FullPath; int log_size = 50; - lock (this.repo_lock) { - foreach (SparkleRepoBase repo in Repositories) { - if (repo.LocalPath.Equals (path)) - return repo.GetChangeSets (log_size); - } + foreach (SparkleRepoBase repo in Repositories) { + if (repo.LocalPath.Equals (path)) + return repo.GetChangeSets (log_size); } return null; @@ -347,7 +341,7 @@ namespace SparkleShare { foreach (SparkleChangeSet existing_set in stored_activity_day) { 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)) { + change_set.Folder.FullPath.Equals (existing_set.Folder.FullPath)) { existing_set.Added.AddRange (change_set.Added); existing_set.Edited.AddRange (change_set.Edited); @@ -410,12 +404,7 @@ namespace SparkleShare { if (change_set.Added.Count > 0) { foreach (string file_path in change_set.Added) { event_entry += "
"; - - event_entry += FormatBreadCrumbs ( - Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder), - file_path - ); - + event_entry += FormatBreadCrumbs (change_set.Folder.FullPath, file_path); event_entry += "
"; } } @@ -423,12 +412,7 @@ namespace SparkleShare { if (change_set.Edited.Count > 0) { foreach (string file_path in change_set.Edited) { event_entry += "
"; - - event_entry += FormatBreadCrumbs ( - Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder), - file_path - ); - + event_entry += FormatBreadCrumbs (change_set.Folder.FullPath, file_path); event_entry += "
"; } } @@ -436,12 +420,7 @@ namespace SparkleShare { if (change_set.Deleted.Count > 0) { foreach (string file_path in change_set.Deleted) { event_entry += "
"; - - event_entry += FormatBreadCrumbs ( - Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder), - file_path - ); - + event_entry += FormatBreadCrumbs (change_set.Folder.FullPath, file_path); event_entry += "
"; } } @@ -451,18 +430,9 @@ namespace SparkleShare { foreach (string file_path in change_set.MovedFrom) { string to_file_path = change_set.MovedTo [i]; event_entry += "
"; - - event_entry += FormatBreadCrumbs ( - Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder), - file_path - ); - + event_entry += FormatBreadCrumbs (change_set.Folder.FullPath, file_path); event_entry += "
"; - event_entry += FormatBreadCrumbs ( - Path.Combine (SparkleConfig.DefaultConfig.FoldersPath, change_set.Folder), - to_file_path - ); - + event_entry += FormatBreadCrumbs (change_set.Folder.FullPath, file_path); event_entry += "
"; i++; @@ -492,10 +462,10 @@ namespace SparkleShare { .Replace ("", change_set.User.Name) .Replace ("", change_set_avatar) .Replace ("", timestamp) - .Replace ("", change_set.Folder) + .Replace ("", change_set.Folder.Name) .Replace ("", change_set.Url.ToString ()) .Replace ("", change_set.Revision) - .Replace ("", AssignColor (change_set.Folder)); + .Replace ("", AssignColor (change_set.Folder.Name)); } string day_entry = ""; @@ -554,17 +524,15 @@ namespace SparkleShare { bool has_syncing_repos = false; bool has_unsynced_repos = false; - lock (this.repo_lock) { - foreach (SparkleRepoBase repo in Repositories) { - if (repo.Status == SyncStatus.SyncDown || - repo.Status == SyncStatus.SyncUp || - repo.IsBuffering) { - - has_syncing_repos = true; - - } else if (repo.HasUnsyncedChanges) { - has_unsynced_repos = true; - } + foreach (SparkleRepoBase repo in Repositories) { + if (repo.Status == SyncStatus.SyncDown || + repo.Status == SyncStatus.SyncUp || + repo.IsBuffering) { + + has_syncing_repos = true; + + } else if (repo.HasUnsyncedChanges) { + has_unsynced_repos = true; } } @@ -656,18 +624,21 @@ namespace SparkleShare { { string folder_name = Path.GetFileName (folder_path); - lock (this.repo_lock) { - for (int i = 0; i < this.repositories.Count; i++) { - SparkleRepoBase repo = this.repositories [i]; - - if (repo.Name.Equals (folder_name)) { - repo.Dispose (); + for (int i = 0; i < Repositories.Length; i++) { + SparkleRepoBase repo = Repositories [i]; + + if (repo.Name.Equals (folder_name)) { + repo.Dispose (); + + lock (this.repo_lock) { this.repositories.Remove (repo); - repo = null; - break; } + + repo = null; + break; } } + } @@ -1092,27 +1063,23 @@ namespace SparkleShare { // quits if safe public void TryQuit () { - lock (this.repo_lock) { - foreach (SparkleRepoBase repo in Repositories) { - if (repo.Status == SyncStatus.SyncUp || - repo.Status == SyncStatus.SyncDown || - repo.IsBuffering) { - - return; - } + foreach (SparkleRepoBase repo in Repositories) { + if (repo.Status == SyncStatus.SyncUp || + repo.Status == SyncStatus.SyncDown || + repo.IsBuffering) { + + return; } } - + Quit (); } public virtual void Quit () { - lock (this.repo_lock) { - foreach (SparkleRepoBase repo in Repositories) - repo.Dispose (); - } + foreach (SparkleRepoBase repo in Repositories) + repo.Dispose (); Environment.Exit (0); }