-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
86 lines (77 loc) · 3.49 KB
/
Form1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ChangeWatcher {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
public FileSystemWatcher watcher;
public delegate void ArgumentChanged(string text);
public delegate void ArgumentCreated(string text);
public delegate void ArgumentDeleted(string text);
public delegate void ArgumentRenamed(string text);
public ArgumentChanged Changed;
public ArgumentCreated Created;
public ArgumentDeleted Deleted;
public ArgumentRenamed Renamed;
private void textBox1_TextChanged(object sender, EventArgs e) {
}
private void checkBox1_CheckedChanged(object sender, EventArgs e) {
if (this.checkBox1.Text == "Start") {
subscribe();
this.checkBox1.Text = "Stop";
} else {
unsubscribe();
this.checkBox1.Text = "Start";
}
}
private void Form1_Load(object sender, EventArgs e) {
watcher = new FileSystemWatcher();
watcher.Path = System.IO.Path.GetPathRoot(System.Environment.CurrentDirectory);
watcher.Filter = "*";
watcher.IncludeSubdirectories = true;
watcher.NotifyFilter = (NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size);
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.Deleted += new FileSystemEventHandler(OnDeleted);
watcher.Renamed += new RenamedEventHandler(OnRenamed);
Changed = new ArgumentChanged(Ch);
Created = new ArgumentCreated(Cr);
Deleted = new ArgumentDeleted(Dl);
Renamed = new ArgumentRenamed(Rn);
}
public void OnChanged(object sender, FileSystemEventArgs e) {
string data = DateTime.Now + " | " + "Changed" + " | " + "File: " + " | " + e.Name + "\n";
this.Invoke(Changed, data);
}
public void OnCreated(object sender, FileSystemEventArgs e) {
string data = DateTime.Now + " | " + "Created" + " | " + "File: " + " | " + e.Name + "\n";
this.Invoke(Created, data);
}
public void OnDeleted(object sender, FileSystemEventArgs e) {
string data = DateTime.Now + " | " + "Deleted" + " | " + "File: " + " | " + e.Name + "\n";
this.Invoke(Deleted, data);
}
public void OnRenamed(object sender, RenamedEventArgs e) {
string data = DateTime.Now + " | " + "Renamed" + " | " + "File: " + " | " + e.Name + "\n";
this.Invoke(Renamed, data);
}
private void Ch(string data) { this.textBox1.AppendText(data); }
private void Cr(string data) { this.textBox1.AppendText(data); }
private void Dl(string data) { this.textBox1.AppendText(data); }
private void Rn(string data) { this.textBox1.AppendText(data); }
private void subscribe() {
watcher.EnableRaisingEvents = true;
}
private void unsubscribe() {
watcher.EnableRaisingEvents = false;
}
}
}