Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

controller: More reliable folder deletion detection

  • Loading branch information...
commit 4cd6851faf5563f9c8285ff192f62a0e714fe065 1 parent 42d7087
@hbons authored
Showing with 43 additions and 76 deletions.
  1. +43 −76 SparkleShare/SparkleControllerBase.cs
View
119 SparkleShare/SparkleControllerBase.cs
@@ -100,7 +100,6 @@ public abstract class SparkleControllerBase {
}
}
-
public List<string> Folders {
get {
List<string> folders = SparkleConfig.DefaultConfig.Folders;
@@ -110,7 +109,6 @@ public abstract class SparkleControllerBase {
}
}
-
public List<string> UnsyncedFolders {
get {
List<string> unsynced_folders = new List<string> ();
@@ -124,7 +122,31 @@ public abstract class SparkleControllerBase {
}
}
-
+ public SparkleUser CurrentUser {
+ get {
+ return SparkleConfig.DefaultConfig.User;
+ }
+
+ set {
+ SparkleConfig.DefaultConfig.User = value;
+ }
+ }
+
+ public bool NotificationsEnabled {
+ get {
+ string notifications_enabled = SparkleConfig.DefaultConfig.GetConfigOption ("notifications");
+
+ if (string.IsNullOrEmpty (notifications_enabled)) {
+ SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
+ return true;
+
+ } else {
+ return notifications_enabled.Equals (bool.TrueString);
+ }
+ }
+ }
+
+
// Path where the plugins are kept
public abstract string PluginsPath { get; }
@@ -188,10 +210,21 @@ public virtual void Initialize ()
Filter = "*"
};
- // Remove the repository when a delete event occurs
+
watcher.Deleted += delegate (object o, FileSystemEventArgs args) {
- RemoveRepository (args.FullPath);
- SparkleConfig.DefaultConfig.RemoveFolder (Path.GetFileName (args.Name));
+ watcher.EnableRaisingEvents = false;
+
+ foreach (string folder_name in SparkleConfig.DefaultConfig.Folders) {
+ string folder_path = new SparkleFolder (folder_name).FullPath;
+
+ if (!Directory.Exists (folder_path)) {
+ SparkleConfig.DefaultConfig.RemoveFolder (folder_name);
+ RemoveRepository (folder_path);
+ }
+ }
+
+ Thread.Sleep (250);
+ watcher.EnableRaisingEvents = true;
if (FolderListChanged != null)
FolderListChanged ();
@@ -271,7 +304,6 @@ public void ShowEventLogWindow ()
}
-
public List<SparkleChangeSet> GetLog ()
{
List<SparkleChangeSet> list = new List<SparkleChangeSet> ();
@@ -457,8 +489,7 @@ public string GetHTMLLog (List<SparkleChangeSet> change_sets)
string timestamp = change_set.Timestamp.ToString ("H:mm");
if (!change_set.FirstTimestamp.Equals (new DateTime ()))
- timestamp = change_set.FirstTimestamp.ToString ("H:mm") +
- "" + timestamp;
+ timestamp = change_set.FirstTimestamp.ToString ("H:mm") + "" + timestamp;
event_entries += event_entry_html.Replace ("<!-- $event-entry-content -->", event_entry)
.Replace ("<!-- $event-user-name -->", change_set.User.Name)
@@ -466,8 +497,7 @@ public string GetHTMLLog (List<SparkleChangeSet> change_sets)
.Replace ("<!-- $event-time -->", timestamp)
.Replace ("<!-- $event-folder -->", change_set.Folder.Name)
.Replace ("<!-- $event-url -->", change_set.Url.ToString ())
- .Replace ("<!-- $event-revision -->", change_set.Revision)
- .Replace ("<!-- $event-folder-color -->", AssignColor (change_set.Folder.Name));
+ .Replace ("<!-- $event-revision -->", change_set.Revision);
}
string day_entry = "";
@@ -662,22 +692,6 @@ private void PopulateRepositories ()
}
- public bool NotificationsEnabled {
- get {
- string notifications_enabled =
- SparkleConfig.DefaultConfig.GetConfigOption ("notifications");
-
- if (String.IsNullOrEmpty (notifications_enabled)) {
- SparkleConfig.DefaultConfig.SetConfigOption ("notifications", bool.TrueString);
- return true;
-
- } else {
- return notifications_enabled.Equals (bool.TrueString);
- }
- }
- }
-
-
public void ToggleNotifications () {
bool notifications_enabled =
SparkleConfig.DefaultConfig.GetConfigOption ("notifications")
@@ -759,18 +773,6 @@ public void ImportPrivateKey ()
}
- // Looks up the user's name from the global configuration
- public SparkleUser CurrentUser {
- get {
- return SparkleConfig.DefaultConfig.User;
- }
-
- set {
- SparkleConfig.DefaultConfig.User = value;
- }
- }
-
-
// Generates and installs an RSA keypair to identify this system
public void GenerateKeyPair ()
{
@@ -993,8 +995,7 @@ public string GetAvatar (string email, int size)
public void StopFetcher ()
{
- if (this.fetcher != null)
- this.fetcher.Stop ();
+ this.fetcher.Stop ();
if (Directory.Exists (this.fetcher.TargetFolder)) {
try {
@@ -1070,6 +1071,7 @@ public void FinishFetcher ()
if (FolderListChanged != null)
FolderListChanged ();
+ this.fetcher.Dispose ();
this.fetcher = null;
} catch (Exception e) {
@@ -1084,23 +1086,6 @@ public bool CheckPassword (string password)
}
- // Checks whether there are any folders syncing and
- // quits if safe
- public void TryQuit ()
- {
- foreach (SparkleRepoBase repo in Repositories) {
- if (repo.Status == SyncStatus.SyncUp ||
- repo.Status == SyncStatus.SyncDown ||
- repo.IsBuffering) {
-
- return;
- }
- }
-
- Quit ();
- }
-
-
public virtual void Quit ()
{
foreach (SparkleRepoBase repo in Repositories)
@@ -1110,21 +1095,6 @@ public virtual void Quit ()
}
- private string [] tango_palette = new string [] {"#eaab00", "#e37222",
- "#3892ab", "#33c2cb", "#19b271", "#9eab05", "#8599a8", "#9ca696",
- "#b88454", "#cc0033", "#8f6678", "#8c6cd0", "#796cbf", "#4060af",
- "#aa9c8f", "#818a8f"};
-
- private string AssignColor (string s)
- {
- string hash = "0" + GetMD5 (s).Substring (0, 8);
- string numbers = Regex.Replace (hash, "[a-z]", "");
- int number = int.Parse (numbers);
-
- return this.tango_palette [number % this.tango_palette.Length];
- }
-
-
private string AssignAvatar (string s)
{
string hash = "0" + GetMD5 (s).Substring (0, 8);
@@ -1191,9 +1161,6 @@ private string FormatBreadCrumbs (string path_root, string path)
}
}
-
- public class ChangeSet : SparkleChangeSet { }
-
// All change sets that happened on a day
public class ActivityDay : List <SparkleChangeSet>
Please sign in to comment.
Something went wrong with that request. Please try again.