-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryMonitorForm.cs
More file actions
312 lines (283 loc) · 11.1 KB
/
DirectoryMonitorForm.cs
File metadata and controls
312 lines (283 loc) · 11.1 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
using System;
using System.Windows.Forms;
using System.IO;
using FileSystemWatcherComponent.NotificationWindow;
using System.Text.RegularExpressions;
namespace DirectoryMonitorWinForm
{
/// <summary>
/// Summary description for DirectoryMonitor.
/// </summary>
public class DirectoryMonitorForm : System.Windows.Forms.Form
{
public static string filePlugFullPath;
private static string Path="";
private static string Filter="";
private static bool IncludeSubs=false;
private System.IO.FileSystemWatcher FileMonitor;
private System.Windows.Forms.Label Label1;
private System.Windows.Forms.Label Label2;
private System.Windows.Forms.Label Label3;
private System.Windows.Forms.Button ButtonStart;
private System.Windows.Forms.Button ButtonStop;
private System.Windows.Forms.TextBox directoryToMonitor;
private System.Windows.Forms.Label Label4;
private System.Windows.Forms.ComboBox fileFilterList;
private System.Windows.Forms.CheckBox subdirectoriesAreIncluded;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public DirectoryMonitorForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.FileMonitor = new System.IO.FileSystemWatcher();
this.ButtonStart = new System.Windows.Forms.Button();
this.ButtonStop = new System.Windows.Forms.Button();
this.Label1 = new System.Windows.Forms.Label();
this.directoryToMonitor = new System.Windows.Forms.TextBox();
this.Label2 = new System.Windows.Forms.Label();
this.Label3 = new System.Windows.Forms.Label();
this.Label4 = new System.Windows.Forms.Label();
this.fileFilterList = new System.Windows.Forms.ComboBox();
this.subdirectoriesAreIncluded = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.FileMonitor)).BeginInit();
this.SuspendLayout();
//
// FileMonitor
//
this.FileMonitor.EnableRaisingEvents = true;
this.FileMonitor.NotifyFilter = System.IO.NotifyFilters.FileName;
this.FileMonitor.SynchronizingObject = this;
this.FileMonitor.Deleted += new System.IO.FileSystemEventHandler(this.FileMonitor_Changed);
this.FileMonitor.Renamed += new System.IO.RenamedEventHandler(this.FileMonitor_OnRenamed);
this.FileMonitor.Changed += new System.IO.FileSystemEventHandler(this.FileMonitor_Changed);
this.FileMonitor.Created += new System.IO.FileSystemEventHandler(this.FileMonitor_Changed);
//
// ButtonStart
//
this.ButtonStart.Location = new System.Drawing.Point(144, 176);
this.ButtonStart.Name = "ButtonStart";
this.ButtonStart.Size = new System.Drawing.Size(64, 23);
this.ButtonStart.TabIndex = 0;
this.ButtonStart.Text = "Start";
this.ButtonStart.Click += new System.EventHandler(this.ButtonStart_Click);
//
// ButtonStop
//
this.ButtonStop.Location = new System.Drawing.Point(232, 176);
this.ButtonStop.Name = "ButtonStop";
this.ButtonStop.Size = new System.Drawing.Size(64, 23);
this.ButtonStop.TabIndex = 1;
this.ButtonStop.Text = "Stop";
this.ButtonStop.Click += new System.EventHandler(this.ButtonStop_Click);
//
// Label1
//
this.Label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Label1.Location = new System.Drawing.Point(16, 8);
this.Label1.Name = "Label1";
this.Label1.Size = new System.Drawing.Size(384, 24);
this.Label1.TabIndex = 2;
this.Label1.Text = "Directory Monitor";
this.Label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// directoryToMonitor
//
this.directoryToMonitor.Location = new System.Drawing.Point(96, 80);
this.directoryToMonitor.Name = "directoryToMonitor";
this.directoryToMonitor.Size = new System.Drawing.Size(312, 20);
this.directoryToMonitor.TabIndex = 3;
this.directoryToMonitor.Text = "";
//
// Label2
//
this.Label2.Location = new System.Drawing.Point(16, 32);
this.Label2.Name = "Label2";
this.Label2.Size = new System.Drawing.Size(384, 32);
this.Label2.TabIndex = 4;
this.Label2.Text = "Enter a Directory to Monitor, Select a Filter and then Click \"Start\" to begin the" +
" monitor. Click \"Stop\" to end the monitor.";
//
// Label3
//
this.Label3.Location = new System.Drawing.Point(8, 80);
this.Label3.Name = "Label3";
this.Label3.Size = new System.Drawing.Size(88, 16);
this.Label3.TabIndex = 5;
this.Label3.Text = "Directory:";
this.Label3.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// Label4
//
this.Label4.Location = new System.Drawing.Point(16, 112);
this.Label4.Name = "Label4";
this.Label4.Size = new System.Drawing.Size(72, 16);
this.Label4.TabIndex = 6;
this.Label4.Text = "Filter:";
this.Label4.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// cboFilter nadaas
//
this.fileFilterList.Items.AddRange(new object[] {
"*.apk",
"*.ipa",
"*.zip",
"*.txt"});
this.fileFilterList.Location = new System.Drawing.Point(96, 112);
this.fileFilterList.Name = "fileFilterList";
this.fileFilterList.Size = new System.Drawing.Size(121, 21);
this.fileFilterList.TabIndex = 7;
//
// checkIncludeSubs
//
this.subdirectoriesAreIncluded.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
this.subdirectoriesAreIncluded.Location = new System.Drawing.Point(232, 112);
this.subdirectoriesAreIncluded.Name = "subdirectoriesAreIncluded";
this.subdirectoriesAreIncluded.Size = new System.Drawing.Size(144, 24);
this.subdirectoriesAreIncluded.TabIndex = 9;
this.subdirectoriesAreIncluded.Text = "Include Sub Directories:";
//
// DirMon
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(416, 224);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.subdirectoriesAreIncluded,
this.fileFilterList,
this.Label4,
this.Label2,
this.directoryToMonitor,
this.Label1,
this.ButtonStop,
this.ButtonStart,
this.Label3});
this.Name = "DirMon";
this.Text = "Directory Monitor";
this.Load += new System.EventHandler(this.DirMon_Load);
((System.ComponentModel.ISupportInitialize)(this.FileMonitor)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new DirectoryMonitorForm());
}
private void FileMonitor_OnRenamed(object source, RenamedEventArgs e)
{
DateTime localDate = DateTime.Now;
// Specify what is done when a file is renamed.
string originalname = e.OldFullPath;
string renamed = e.FullPath;
//MessageBox.Show("File: "+originalname+" renamed to "+renamed + " " + localDate.ToString("dd/MM/yyyy hh:mm:ss tt"), e.OldName+" Renamed");
}
private void FileMonitor_Changed(object sender, System.IO.FileSystemEventArgs e)
{
DateTime localDate = DateTime.Now;
string ChangeType = e.ChangeType.ToString();
//display a message box for the appropriate changetype.
if (ChangeType=="Created")
{
filePlugFullPath = e.FullPath;
PopupNotifier popup = new PopupNotifier();
popup.TitleText = "There are new files";
popup.ContentText = "File: " + e.FullPath + " " + e.ChangeType + " " + localDate.ToString("dd/MM/yyyy hh:mm tt");
popup.Popup();
//MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType + " " + localDate.ToString("dd/MM/yyyy hh:mm:ss tt"), e.Name+" Created" );
}
//else if(ChangeType=="Deleted")
//{
// MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType + " " + localDate.ToString("dd/MM/yyyy hh:mm:ss tt"), e.Name+" Deleted");
//}
//else if(ChangeType=="Changed")
//{
// MessageBox.Show("File: " + e.FullPath + " " + e.ChangeType + " " + localDate.ToString("dd/MM/yyyy hh:mm:ss tt"), e.Name+" Changed" + " " + localDate.ToString("dd/MM/yyyy hh:mm:ss tt"));
//}
}
private void ButtonStart_Click(object sender, System.EventArgs e)
{
if (!String.IsNullOrEmpty(directoryToMonitor.Text))
{
if (Directory.Exists(directoryToMonitor.Text))
{
if (fileFilterList.Text != "")
{
Filter = fileFilterList.Text;
}
else
{
Filter = "*.*";
}
if (subdirectoriesAreIncluded.Checked == true)
{
IncludeSubs = true;
}
else
{
IncludeSubs = false;
}
//get the configuration properties from the form.
Path = directoryToMonitor.Text;
//Set the properties on the monitor.
FileMonitor.Path = Path.ToString();
FileMonitor.Filter = Filter.ToString();
FileMonitor.IncludeSubdirectories = IncludeSubs;
FileMonitor.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
//Begin monitoring.
FileMonitor.EnableRaisingEvents = true;
}
else
{
// return required field message
MessageBox.Show("The directory is not found");
}
}
else
{
// return required field message
MessageBox.Show("Please Enter a Directory");
}
}
private void ButtonStop_Click(object sender, System.EventArgs e)
{
//Begin monitoring.
FileMonitor.EnableRaisingEvents = false;
}
private void DirMon_Load(object sender, System.EventArgs e)
{
}
}
}