Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
80ffbea
commit 7446734
Showing
26 changed files
with
444 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading; | ||
using System.IO; | ||
|
||
|
||
namespace MEditor | ||
{ | ||
|
||
public class FileMonitor | ||
{ | ||
private int TimeoutMillis = 2000; | ||
|
||
System.IO.FileSystemWatcher fsw = new System.IO.FileSystemWatcher(); | ||
System.Threading.Timer m_timer = null; | ||
List<String> files = new List<string>(); | ||
FileSystemEventHandler fswHandler = null; | ||
|
||
public FileMonitor(FileSystemEventHandler watchHandler) | ||
{ | ||
m_timer = new System.Threading.Timer(new TimerCallback(OnTimer), null, Timeout.Infinite, Timeout.Infinite); | ||
fswHandler = watchHandler; | ||
|
||
} | ||
|
||
|
||
public FileMonitor(FileSystemEventHandler watchHandler, int timerInterval) | ||
{ | ||
m_timer = new System.Threading.Timer(new TimerCallback(OnTimer), null, Timeout.Infinite, Timeout.Infinite); | ||
TimeoutMillis = timerInterval; | ||
fswHandler = watchHandler; | ||
|
||
} | ||
|
||
public void Add(string dir,string filter) | ||
{ | ||
System.IO.FileSystemWatcher fsw = new System.IO.FileSystemWatcher(dir, filter); | ||
fsw.NotifyFilter = System.IO.NotifyFilters.LastWrite; | ||
fsw.Changed += new FileSystemEventHandler(OnFileChanged); | ||
fsw.EnableRaisingEvents = true; | ||
} | ||
|
||
public void OnFileChanged(object sender, FileSystemEventArgs e) | ||
{ | ||
//MessageBox.Show("Created", "Create triggered"); | ||
Mutex mutex = new Mutex(false, "FSW"); | ||
mutex.WaitOne(); | ||
if (!files.Contains(e.FullPath)) | ||
{ | ||
files.Add(e.FullPath); | ||
} | ||
mutex.ReleaseMutex(); | ||
|
||
m_timer.Change(TimeoutMillis, Timeout.Infinite); | ||
} | ||
|
||
private void OnTimer(object state) | ||
{ | ||
List<String> backup = new List<string>(); | ||
|
||
Mutex mutex = new Mutex(false, "FSW"); | ||
mutex.WaitOne(); | ||
backup.AddRange(files); | ||
files.Clear(); | ||
mutex.ReleaseMutex(); | ||
|
||
|
||
foreach (string file in backup) | ||
{ | ||
fswHandler(this, new FileSystemEventArgs(WatcherChangeTypes.Changed, string.Empty, file)); | ||
} | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.