diff --git a/SparkleLib/Makefile.am b/SparkleLib/Makefile.am index 3cb4dcd3..5b9bd3ec 100644 --- a/SparkleLib/Makefile.am +++ b/SparkleLib/Makefile.am @@ -24,7 +24,8 @@ SOURCES = \ SparkleListenerIrc.cs \ SparkleOptions.cs \ SparklePaths.cs \ - SparkleRepoBase.cs + SparkleRepoBase.cs \ + SparkleWatcher.cs SMARTIRC4NET_FILES_EXPANDED = $(foreach file, $(SMARTIRC4NET_FILES), $(top_builddir)/$(file)) diff --git a/SparkleLib/SparkleLib.csproj b/SparkleLib/SparkleLib.csproj index 1812f5a5..8e18cd24 100644 --- a/SparkleLib/SparkleLib.csproj +++ b/SparkleLib/SparkleLib.csproj @@ -52,6 +52,7 @@ + diff --git a/SparkleLib/SparkleRepoBase.cs b/SparkleLib/SparkleRepoBase.cs index bd23459e..d7e01545 100644 --- a/SparkleLib/SparkleRepoBase.cs +++ b/SparkleLib/SparkleRepoBase.cs @@ -37,7 +37,7 @@ namespace SparkleLib { private TimeSpan short_interval = new TimeSpan (0, 0, 3, 0); private TimeSpan long_interval = new TimeSpan (0, 0, 10, 0); - private FileSystemWatcher watcher; + private SparkleWatcher watcher; private SparkleListenerBase listener; private TimeSpan poll_interval; private Timer local_timer = new Timer () { Interval = 0.25 * 1000 }; @@ -211,16 +211,10 @@ namespace SparkleLib { private void CreateWatcher () { - this.watcher = new FileSystemWatcher (LocalPath) { - IncludeSubdirectories = true, - EnableRaisingEvents = true, - Filter = "*" + this.watcher = new SparkleWatcher (LocalPath); + this.watcher.ChangeEvent += delegate (FileSystemEventArgs args) { + OnFileActivity (args); }; - - this.watcher.Changed += new FileSystemEventHandler (OnFileActivity); - this.watcher.Created += new FileSystemEventHandler (OnFileActivity); - this.watcher.Deleted += new FileSystemEventHandler (OnFileActivity); - this.watcher.Renamed += new RenamedEventHandler (OnFileActivity); } @@ -301,7 +295,7 @@ namespace SparkleLib { // Starts a timer when something changes - public void OnFileActivity (object o, FileSystemEventArgs args) + public void OnFileActivity (FileSystemEventArgs args) { if (args.FullPath.Contains (Path.DirectorySeparatorChar + ".")) return; diff --git a/SparkleLib/SparkleWatcher.cs b/SparkleLib/SparkleWatcher.cs new file mode 100644 index 00000000..ae0ec573 --- /dev/null +++ b/SparkleLib/SparkleWatcher.cs @@ -0,0 +1,57 @@ +// SparkleShare, a collaboration and sharing tool. +// Copyright (C) 2010 Hylke Bons +// +// 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 . + + +using System; +using System.IO; + +namespace SparkleLib { + + public class SparkleWatcher : FileSystemWatcher { + + public delegate void ChangeEventEventHandler (FileSystemEventArgs args); + public event ChangeEventEventHandler ChangeEvent; + + + public SparkleWatcher (string path) : base (path) + { + IncludeSubdirectories = true; + EnableRaisingEvents = true; + Filter = "*"; + + Changed += delegate (object o, FileSystemEventArgs args) { + if (ChangeEvent != null) + ChangeEvent (args); + }; + + Created += delegate (object o, FileSystemEventArgs args) { + if (ChangeEvent != null) + ChangeEvent (args); + }; + + Deleted += delegate (object o, FileSystemEventArgs args) { + if (ChangeEvent != null) + ChangeEvent (args); + }; + + Renamed += delegate (object o, RenamedEventArgs args) { + if (ChangeEvent != null) + ChangeEvent (args); + }; + + } + } +} diff --git a/SparkleShare/Mac/SparkleMacController.cs b/SparkleShare/Mac/SparkleMacController.cs index b3902f7c..c526174b 100644 --- a/SparkleShare/Mac/SparkleMacController.cs +++ b/SparkleShare/Mac/SparkleMacController.cs @@ -57,7 +57,7 @@ namespace SparkleShare { foreach (SparkleRepoBase repo in Repositories) { if (repo.Name.Equals (repo_name)) - repo.OnFileActivity (this, args); + repo.OnFileActivity (args); } }; }