SparkleShare/Sparkles/Watcher.cs

63 lines
1.8 KiB
C#
Raw Normal View History

2011-06-14 22:14:03 +00:00
// SparkleShare, a collaboration and sharing tool.
2017-07-23 12:47:54 +00:00
// Copyright (C) 2010 Hylke Bons <hi@planetpeanut.uk>
2011-06-14 22:14:03 +00:00
//
// This program is free software: you can redistribute it and/or modify
2013-10-11 15:13:46 +00:00
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
2011-06-14 22:14:03 +00:00
//
// 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/>.
2012-07-25 09:25:52 +00:00
using System.IO;
2011-06-14 22:14:03 +00:00
2016-03-31 08:35:26 +00:00
namespace Sparkles {
2011-06-14 22:14:03 +00:00
2016-03-30 23:36:31 +00:00
public class Watcher : FileSystemWatcher {
2012-07-28 16:13:50 +00:00
public event ChangeEventEventHandler ChangeEvent = delegate { };
2012-07-25 09:25:52 +00:00
public delegate void ChangeEventEventHandler (FileSystemEventArgs args);
2011-06-14 22:14:03 +00:00
2016-03-30 23:56:48 +00:00
object thread_lock = new object ();
2016-03-30 23:36:31 +00:00
public Watcher (string path) : base (path)
2012-07-25 09:25:52 +00:00
{
2011-06-14 22:14:03 +00:00
IncludeSubdirectories = true;
EnableRaisingEvents = true;
2012-07-25 09:25:52 +00:00
Filter = "*";
2012-07-28 16:13:50 +00:00
Changed += OnChanged;
Created += OnChanged;
Deleted += OnChanged;
Renamed += OnChanged;
}
2012-07-25 09:25:52 +00:00
2016-03-30 23:56:48 +00:00
void OnChanged (object sender, FileSystemEventArgs args)
2012-07-28 16:13:50 +00:00
{
ChangeEvent (args);
2011-06-14 22:14:03 +00:00
}
2012-07-25 09:25:52 +00:00
public void Enable ()
{
2012-07-25 09:25:52 +00:00
lock (this.thread_lock)
EnableRaisingEvents = true;
}
2012-07-25 09:25:52 +00:00
public void Disable ()
{
lock (this.thread_lock)
EnableRaisingEvents = false;
}
2011-06-14 22:14:03 +00:00
}
}