-
Notifications
You must be signed in to change notification settings - Fork 8
/
Program.cs
762 lines (618 loc) · 28.5 KB
/
Program.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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
using MovablePython;
using Squared.Task;
using Squared.Task.Data;
using Squared.Task.IO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SQLite;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Squared.Threading;
namespace Ndexer {
public class ActiveWorker : IDisposable {
public string Description = null;
public ActiveWorker (string description) {
Description = description;
Resume();
}
public void Resume () {
lock (Program.ActiveWorkers)
Program.ActiveWorkers.Add(this);
}
public void Suspend () {
lock (Program.ActiveWorkers)
Program.ActiveWorkers.Remove(this);
}
public void Dispose () {
Suspend();
}
}
public class FileIndexEntry {
public string Filename;
public long Timestamp;
public FileIndexEntry (string filename, long timestamp)
: base() {
Filename = filename;
Timestamp = timestamp;
}
public IEnumerator<object> Commit () {
var textReader = Future.RunInThread((Func<string>)(() => {
return System.IO.File.ReadAllText(Filename);
}));
using (var transaction = Program.Database.Connection.CreateTransaction()) {
yield return transaction;
yield return Program.Database.MakeSourceFileID(Filename, Timestamp);
yield return textReader;
string content = "";
try {
content = textReader.Result as string;
} catch {
}
yield return Program.Database.SetFullTextContentForFile(Filename, content);
yield return transaction.Commit();
}
}
public override string ToString () {
return String.Format("FileIndexEntry(fn={0}, ts={1})", Filename, Timestamp);
}
}
public static partial class Program {
public static TaskScheduler Scheduler;
public static TagDatabase Database;
public static List<ActiveWorker> ActiveWorkers = new List<ActiveWorker>();
public static string TrayCaption;
public static string DatabasePath;
#if !MONO
public static NotifyIcon NotifyIcon;
public static Icon Icon_Monitoring;
public static Icon Icon_Working_1, Icon_Working_2;
public static Hotkey Hotkey_Search_Files;
public static NativeWindow HotkeyWindow;
public static ContextMenuStrip ContextMenu;
#endif
private const int BatchSize = 128;
[STAThread]
static void Main (string[] argv) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (argv.Length < 1) {
using (var dlg = new SaveFileDialog()) {
dlg.Title = "Select Index Database";
dlg.Filter = "Index Databases (*.db)|*.db";
dlg.CheckFileExists = false;
dlg.CheckPathExists = true;
dlg.AddExtension = true;
dlg.AutoUpgradeEnabled = true;
dlg.OverwritePrompt = false;
if (dlg.ShowDialog() != DialogResult.OK) {
MessageBox.Show(
"NDexer cannot start without a path specified for the index database on the command line.\n" +
@"For example: ndexer.exe C:\mysource\index.db",
"NDexer Error"
);
return;
} else {
DatabasePath = dlg.FileName;
}
}
} else {
DatabasePath = System.IO.Path.GetFullPath(argv[0]);
}
if (System.IO.File.Exists(DatabasePath)) {
if (System.IO.File.Exists(DatabasePath + "_new")) {
System.IO.File.Move(DatabasePath, DatabasePath + "_old");
System.IO.File.Move(DatabasePath + "_new", DatabasePath);
System.IO.File.Delete(DatabasePath + "_old");
}
} else {
}
Scheduler = new TaskScheduler(JobQueue.WindowsMessageBased);
Database = new TagDatabase(Scheduler, DatabasePath);
InitUI();
Scheduler.Start(
MainTask(argv),
TaskExecutionPolicy.RunAsBackgroundTask
);
Application.Run();
}
public static void InitUI() {
#if !MONO
HotkeyWindow = new NativeWindow();
HotkeyWindow.CreateHandle(new CreateParams {
Caption = "NDexer Hotkey Window",
X = 0,
Y = 0,
Width = 0,
Height = 0,
Style = 0,
ExStyle = 0x08000000,
Parent = new IntPtr(-3)
});
Icon_Monitoring = Icon.FromHandle(Properties.Resources.database_monitoring.GetHicon());
Icon_Working_1 = Icon.FromHandle(Properties.Resources.database_working_1.GetHicon());
Icon_Working_2 = Icon.FromHandle(Properties.Resources.database_working_2.GetHicon());
ContextMenu = new ContextMenuStrip();
ContextMenu.Items.Add(
"&Search", null,
(e, s) => {
Scheduler.Start(ShowFullTextSearchTask(), TaskExecutionPolicy.RunAsBackgroundTask);
}
);
ContextMenu.Items.Add("-");
ContextMenu.Items.Add(
"&Configure", null,
(e, s) => {
using (var dialog = new ConfigurationDialog(Database))
if ((dialog.ShowDialog() == DialogResult.OK) && (dialog.NeedRestart))
Scheduler.Start(RestartTask(), TaskExecutionPolicy.RunAsBackgroundTask);
}
);
ContextMenu.Items.Add(
"Res&can", null,
(e, s) => {
Scheduler.Start(ScanFiles(), TaskExecutionPolicy.RunAsBackgroundTask);
}
);
ContextMenu.Items.Add(
"&Rebuild Index", null,
(e, s) => {
Scheduler.Start(ConfirmRebuildIndexTask(), TaskExecutionPolicy.RunAsBackgroundTask);
}
);
ContextMenu.Items.Add("-");
ContextMenu.Items.Add(
"E&xit", null,
(e, s) => {
Scheduler.Start(ExitTask(), TaskExecutionPolicy.RunAsBackgroundTask);
}
);
NotifyIcon = new NotifyIcon();
NotifyIcon.ContextMenuStrip = ContextMenu;
NotifyIcon.DoubleClick += (EventHandler)((s, e) => {
Scheduler.Start(ShowFullTextSearchTask(), TaskExecutionPolicy.RunAsBackgroundTask);
});
Scheduler.Start(
RefreshTrayIcon(),
TaskExecutionPolicy.RunAsBackgroundTask
);
#endif
}
public static string GetExecutablePath() {
string executablePath = System.IO.Path.GetDirectoryName(Application.ExecutablePath)
.ToLower().Replace(@"\bin\debug", "").Replace(@"\bin\release", "");
return executablePath;
}
public static string GetDataPath () {
return GetExecutablePath() + @"\data\";
}
public static IEnumerator<object> ConfirmRebuildIndexTask () {
if (MessageBox.Show(
"Are you sure you want to rebuild the index? This will take a while!", "Rebuild Index",
MessageBoxButtons.YesNo, MessageBoxIcon.Question
) == DialogResult.Yes) {
yield return RebuildIndexTask(true);
}
}
public static IEnumerator<object> GetDBSchemaVersion (ConnectionWrapper cw) {
using (var q = cw.BuildQuery("PRAGMA user_version")) {
var f = q.ExecuteScalar();
yield return f;
yield return new Result(f.Result);
}
}
public static string GetEmbeddedSchema () {
string schemaText;
using (var stream = Assembly.GetEntryAssembly().GetManifestResourceStream("Ndexer.schema.sql"))
using (var reader = new StreamReader(stream))
schemaText = reader.ReadToEnd();
return schemaText;
}
public static long GetEmbeddedSchemaVersion () {
var schema = GetEmbeddedSchema();
return long.Parse(Regex.Match(schema, "PRAGMA user_version=(?'version'[0-9]*);", RegexOptions.ExplicitCapture).Groups["version"].Value);
}
public static IEnumerator<object> RebuildIndexTask (bool saveOldData) {
using (new ActiveWorker("Rebuilding index...")) {
var conn = new SQLiteConnection(String.Format("Data Source={0}", DatabasePath + "_new"));
conn.Open();
var cw = new ConnectionWrapper(Scheduler, conn);
yield return cw.ExecuteSQL("PRAGMA auto_vacuum=none");
long schemaVersion = GetEmbeddedSchemaVersion();
var fSchema = cw.ExecuteSQL(GetEmbeddedSchema());
yield return fSchema;
var trans = cw.CreateTransaction();
yield return trans;
if (saveOldData)
using (var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders()))
while (!iter.Disposed) {
yield return iter.Fetch();
foreach (TagDatabase.Folder item in iter)
yield return cw.ExecuteSQL(
"INSERT INTO Folders (Folders_Path, Folders_Excluded) VALUES (?, ?)",
item.Path, item.Excluded
);
}
if (saveOldData)
using (var iter = new TaskEnumerator<TagDatabase.Filter>(Database.GetFilters()))
while (!iter.Disposed) {
yield return iter.Fetch();
foreach (TagDatabase.Filter item in iter)
yield return cw.ExecuteSQL(
"INSERT INTO Filters (Filters_Pattern) VALUES (?)",
item.Pattern
);
}
if (saveOldData)
using (var iter = Database.Connection.BuildQuery(
"SELECT Preferences_Name, Preferences_Value FROM Preferences"
).Execute())
while (!iter.Disposed) {
yield return iter.Fetch();
foreach (IDataRecord item in iter)
yield return cw.ExecuteSQL(
"INSERT INTO Preferences (Preferences_Name, Preferences_Value) VALUES (?, ?)",
item.GetValue(0), item.GetValue(1)
);
}
yield return trans.Commit();
yield return Database.Connection.Dispose();
yield return RestartTask();
}
}
#if !MONO
public static string[] GetDirectorNames () {
var results = new List<string>();
var types = Assembly.GetExecutingAssembly().GetTypes();
var baseType = typeof(Director);
foreach (var type in types) {
if (type.IsSubclassOf(baseType) && type.Name.EndsWith("Director"))
results.Add(type.Name.Replace("Director", ""));
}
results.Sort();
return results.ToArray();
}
public static bool TryLocateEditorExecutable (string editorName, ref string result) {
var directorType = Type.GetType(String.Format("Ndexer.{0}Director", editorName), false, true);
if (directorType == null)
return false;
var method = directorType.GetMethod("LocateExecutable", BindingFlags.Static | BindingFlags.Public);
if (method == null)
return false;
var handler = (LocateExecutableHandler)Delegate.CreateDelegate(typeof(LocateExecutableHandler), method);
return handler(ref result);
}
public static IBasicDirector GetDirector () {
var editorName = (string)Scheduler.WaitFor(Database.GetPreference("TextEditor.Name"));
var editorPath = (string)Scheduler.WaitFor(Database.GetPreference("TextEditor.Location"));
var directorType = Type.GetType(String.Format("Ndexer.{0}Director", editorName), true, true);
var constructor = directorType.GetConstructor(new Type[] { typeof(string) });
var director = (IBasicDirector)constructor.Invoke(new object[] { editorPath });
return director;
}
public static IEnumerator<object> ShowFullTextSearchTask () {
var dialog = new FindInFilesDialog();
dialog.Show();
dialog.BringToFront();
dialog.Focus();
Future<ConnectionWrapper> f;
yield return Database.OpenReadConnection().Run(out f);
dialog.SetConnection(f.Result);
}
#endif
private static IEnumerator<object> TeardownTask () {
yield return Database.Dispose();
#if !MONO
NotifyIcon.Visible = false;
#endif
}
public static IEnumerator<object> RestartTask () {
yield return TeardownTask();
Application.Restart();
}
public static IEnumerator<object> ExitTask () {
yield return TeardownTask();
Application.Exit();
}
public static IEnumerator<object> AutoShowConfiguration (string[] argv) {
bool show = false;
IFuture f;
if (argv.Contains("--configure")) {
show = true;
} else {
{
var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders());
f = Scheduler.Start(iter.GetArray());
}
yield return f;
if (((TagDatabase.Folder[])f.Result).Length == 0) {
show = true;
} else {
{
var iter = new TaskEnumerator<TagDatabase.Filter>(Database.GetFilters());
f = Scheduler.Start(iter.GetArray());
}
yield return f;
if (((TagDatabase.Filter[])f.Result).Length == 0)
show = true;
}
}
if (show) {
#if !MONO
using (var dialog = new ConfigurationDialog(Database))
if (dialog.ShowDialog() != DialogResult.OK)
yield return ExitTask();
#else
Console.WriteLine("Configuration required :-(");
yield return ExitTask();
#endif
}
}
public static IEnumerator<object> MainTask (string[] argv) {
yield return Database.Initialize();
var schemaVersion = GetEmbeddedSchemaVersion();
IFuture f;
yield return GetDBSchemaVersion(Database.Connection).Run(out f);
if (schemaVersion.CompareTo(f.Result) != 0) {
yield return RebuildIndexTask(
(f.Result != null) && (Convert.ToInt64(f.Result) > 0)
);
yield break;
}
yield return AutoShowConfiguration(argv);
yield return OnConfigurationChanged();
using (new ActiveWorker("Compacting index")) {
yield return Database.Compact();
}
Scheduler.Start(
MonitorForChanges(),
TaskExecutionPolicy.RunAsBackgroundTask
);
if (!argv.Contains("--noscan"))
Scheduler.Start(
ScanFiles(),
TaskExecutionPolicy.RunAsBackgroundTask
);
}
public static IEnumerator<object> RefreshTrayIcon () {
#if !MONO
bool toggle = false;
while (true) {
toggle = !toggle;
Icon theIcon;
string statusMessage = "";
int numWorkers = 0;
lock (ActiveWorkers)
numWorkers = ActiveWorkers.Count;
if (numWorkers > 0) {
theIcon = (toggle) ? Icon_Working_1 : Icon_Working_2;
lock (ActiveWorkers)
statusMessage = ": " + ActiveWorkers[0].Description;
} else {
theIcon = Icon_Monitoring;
}
var dbName = Path.GetDirectoryName(DatabasePath);
dbName = Path.Combine(dbName.Substring(dbName.LastIndexOf('\\') + 1), Path.GetFileNameWithoutExtension(DatabasePath));
TrayCaption = String.Format("NDexer r{2} ({0}){1}", dbName, statusMessage, Revision);
if (TrayCaption.Length >= 64)
TrayCaption = TrayCaption.Substring(0, 60) + "...";
if (NotifyIcon.Icon != theIcon)
NotifyIcon.Icon = theIcon;
if (NotifyIcon.Text != TrayCaption)
NotifyIcon.Text = TrayCaption;
if (NotifyIcon.Visible == false)
NotifyIcon.Visible = true;
yield return new Sleep(0.5);
}
#endif
}
public static IEnumerator<object> OnConfigurationChanged () {
#if !MONO
if (Hotkey_Search_Files != null) {
if (Hotkey_Search_Files.Registered)
Hotkey_Search_Files.Unregister();
}
Keys keyCode, modifiers;
Future<string> f;
yield return Database.GetPreference("Hotkeys.SearchFiles.Key").Run(out f);
keyCode = (Keys)Enum.Parse(typeof(Keys), f.Result ?? "None", true);
yield return Database.GetPreference("Hotkeys.SearchFiles.Modifiers").Run(out f);
modifiers = (Keys)Enum.Parse(typeof(Keys), f.Result ?? "None", true);
Hotkey_Search_Files = new Hotkey(keyCode, modifiers);
if (!Hotkey_Search_Files.Empty) {
Hotkey_Search_Files.Pressed += (s, e) =>
{
Scheduler.Start(ShowFullTextSearchTask(), TaskExecutionPolicy.RunAsBackgroundTask);
};
Hotkey_Search_Files.Register(HotkeyWindow);
}
#endif
yield break;
}
public static IEnumerator<object> CommitBatches (BlockingQueue<IEnumerable<string>> batches, IFuture completion) {
while (batches.Count > 0 || !completion.Completed) {
var f = batches.Dequeue();
yield return f;
var batch = f.Result as IEnumerable<string>;
if (batch != null)
yield return UpdateIndex(batch);
}
}
public static IEnumerator<object> ScanFiles () {
var time_start = DateTime.UtcNow.Ticks;
var completion = new Future<object>();
var batchQueue = new BlockingQueue<IEnumerable<string>>();
var changedFiles = new List<string>();
var deletedFiles = new List<string>();
for (int i = 0; i < System.Environment.ProcessorCount; i++)
Scheduler.Start(
CommitBatches(batchQueue, completion),
TaskExecutionPolicy.RunAsBackgroundTask
);
using (new ActiveWorker("Scanning folders for changes")) {
var changeSet = new BlockingQueue<TagDatabase.Change>();
var changeGenerator = Scheduler.Start(
Database.UpdateFileListAndGetChangeSet(changeSet),
TaskExecutionPolicy.RunAsBackgroundTask
);
changeGenerator.RegisterOnComplete((f) => changeSet.Enqueue(new TagDatabase.Change()));
int numChanges = 0;
int numDeletes = 0;
while (!changeGenerator.Completed || (changeSet.Count > 0)) {
var f = changeSet.Dequeue();
yield return f;
var change = f.Result;
if (change.Filename == null)
continue;
if (change.Deleted) {
deletedFiles.Add(change.Filename);
numDeletes += 1;
} else {
yield return Database.GetSourceFileID(change.Filename);
changedFiles.Add(change.Filename);
numChanges += 1;
}
if (deletedFiles.Count >= BatchSize) {
var transaction = Database.Connection.CreateTransaction();
yield return transaction;
foreach (string filename in deletedFiles)
yield return Database.DeleteSourceFile(filename);
deletedFiles.Clear();
yield return transaction.Commit();
}
if (changedFiles.Count >= BatchSize) {
string[] batch = changedFiles.ToArray();
changedFiles.Clear();
batchQueue.Enqueue(batch);
}
}
if (deletedFiles.Count > 0) {
var transaction = Database.Connection.CreateTransaction();
yield return transaction;
foreach (string filename in deletedFiles)
yield return Database.DeleteSourceFile(filename);
deletedFiles.Clear();
yield return transaction.Commit();
}
if (changedFiles.Count > 0) {
string[] batch = changedFiles.ToArray();
batchQueue.Enqueue(batch);
}
completion.Complete();
while (batchQueue.Count < 0)
batchQueue.Enqueue(null);
var time_end = DateTime.UtcNow.Ticks;
var elapsed = TimeSpan.FromTicks(time_end - time_start).TotalSeconds;
System.Diagnostics.Debug.WriteLine(String.Format("Disk scan complete after {2:00000.00} seconds. {0} change(s), {1} delete(s).", numChanges, numDeletes, elapsed));
}
}
public static IEnumerator<object> UpdateIndex (IEnumerable<string> filenames) {
long lastWriteTime = 0;
using (new ActiveWorker("Updating index"))
foreach (var filename in filenames) {
yield return Future.RunInThread(
() => System.IO.File.GetLastWriteTimeUtc(filename).ToFileTimeUtc()
).Bind(() => lastWriteTime);
yield return (new FileIndexEntry(filename, lastWriteTime).Commit());
}
}
public static IEnumerator<object> DeleteSourceFiles (string[] filenames) {
using (var transaction = Database.Connection.CreateTransaction()) {
yield return transaction;
foreach (string filename in filenames) {
yield return Database.DeleteSourceFileOrFolder(filename);
}
yield return transaction.Commit();
}
}
public static IEnumerator<object> PeriodicGC () {
while (true) {
long preUsage = System.GC.GetTotalMemory(false);
System.GC.Collect();
long postUsage = System.GC.GetTotalMemory(false);
System.Diagnostics.Debug.WriteLine(String.Format("Periodic GC complete. Usage {0} -> {1}.", preUsage, postUsage));
yield return new Sleep(60.0 * 5);
}
}
public static IEnumerator<object> MonitorForChanges () {
Scheduler.Start(
PeriodicGC(),
TaskExecutionPolicy.RunAsBackgroundTask
);
string[] filters;
TagDatabase.Folder[] folders = null;
{
Future<string[]> f;
yield return Database.GetFilterPatterns().Run(out f);
filters = f.Result;
}
{
var iter = new TaskEnumerator<TagDatabase.Folder>(Database.GetFolders());
yield return Scheduler.Start(iter.GetArray())
.Bind( () => folders );
}
var exclusionList = (from folder in folders where folder.Excluded select folder.Path).ToArray();
DiskMonitor monitor = new DiskMonitor(
(from folder in folders select folder.Path).ToArray(),
filters,
new string[] {
System.Text.RegularExpressions.Regex.Escape(@"\.svn\"),
System.Text.RegularExpressions.Regex.Escape(@"\.git\"),
System.Text.RegularExpressions.Regex.Escape(@"\.hg\")
}
);
monitor.Monitoring = true;
var changedFiles = new List<string>();
var deletedFiles = new List<string>();
long lastDiskChange = 0;
long updateInterval = TimeSpan.FromSeconds(10).Ticks;
while (true) {
long now = DateTime.Now.Ticks;
if ((changedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval)) {
var filenames = changedFiles.ToArray();
changedFiles.Clear();
yield return UpdateIndex(filenames);
}
if ((deletedFiles.Count > 0) && ((now - lastDiskChange) > updateInterval)) {
using (new ActiveWorker(String.Format("Pruning {0} item(s) from index", deletedFiles.Count))) {
string[] filenames = deletedFiles.ToArray();
deletedFiles.Clear();
yield return DeleteSourceFiles(filenames);
}
}
using (new ActiveWorker(String.Format("Reading disk change history"))) {
now = DateTime.Now.Ticks;
foreach (string filename in monitor.GetChangedFiles().Distinct()) {
lastDiskChange = now;
bool excluded = false;
foreach (var exclusion in exclusionList) {
if (filename.StartsWith(exclusion)) {
excluded = true;
break;
}
}
if (!excluded)
changedFiles.Add(filename);
}
foreach (string filename in monitor.GetDeletedFiles().Distinct()) {
lastDiskChange = now;
bool excluded = false;
foreach (var exclusion in exclusionList) {
if (filename.StartsWith(exclusion)) {
excluded = true;
break;
}
}
if (!excluded)
deletedFiles.Add(filename);
}
}
yield return new Sleep(2.5);
}
}
}
}