SparkleShare/SparkleLib/SparkleWatcher.cs

64 lines
1.8 KiB
C#
Raw Normal View History

2011-06-14 22:14:03 +00:00
// 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
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/>.
using System;
2012-07-25 09:25:52 +00:00
using System.IO;
2011-06-14 22:14:03 +00:00
namespace SparkleLib {
2011-06-14 22:14:03 +00:00
2012-07-25 09:25:52 +00:00
public class SparkleWatcher : 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
2012-07-25 09:25:52 +00:00
private Object thread_lock = new Object ();
2012-07-25 09:25:52 +00:00
public SparkleWatcher (string path) : base (path)
{
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
2012-07-28 16:13:50 +00:00
private void OnChanged (object sender, FileSystemEventArgs args)
{
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
}
}