2019-07-28 23:53:15 +03:00
|
|
|
|
// Copyright (c) Ivan Bondarev, Stanislav Mikhalkovich (for details please see \doc\copyright.txt)
|
2015-06-02 22:52:35 +03:00
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
using System;
|
2015-05-14 22:35:07 +03:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace VisualPascalABC
|
|
|
|
|
|
{
|
|
|
|
|
|
class FSWatcherService
|
|
|
|
|
|
{
|
|
|
|
|
|
Dictionary<string, FileChangeWatcher> watchers = new Dictionary<string, FileChangeWatcher>();
|
|
|
|
|
|
public void AddWatcher(string FileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string s = FileName.ToLower();
|
|
|
|
|
|
if (!watchers.ContainsKey(s))
|
|
|
|
|
|
watchers[s] = new FileChangeWatcher(FileName);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void DisableWatcher(string FileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
string s = FileName.ToLower();
|
|
|
|
|
|
FileChangeWatcher fcw = null;
|
|
|
|
|
|
if (watchers.TryGetValue(s, out fcw))
|
|
|
|
|
|
{
|
|
|
|
|
|
fcw.Enabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void EnableWatcher(string FileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
string s = FileName.ToLower();
|
|
|
|
|
|
FileChangeWatcher fcw = null;
|
|
|
|
|
|
if (watchers.TryGetValue(s, out fcw))
|
|
|
|
|
|
{
|
|
|
|
|
|
fcw.Enabled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void RemoveWatcher(string FileName)
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
string s = FileName.ToLower();
|
|
|
|
|
|
FileChangeWatcher fcw = null;
|
|
|
|
|
|
if (watchers.TryGetValue(s, out fcw))
|
|
|
|
|
|
{
|
|
|
|
|
|
fcw.Dispose();
|
|
|
|
|
|
watchers.Remove(s);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|