private void ChapterObjectArchiveWatcher_Event(object sender, FileSystemEventArgs e) { RunOnUiThread(() => { switch (e.ChangeType) { case WatcherChangeTypes.Created: case WatcherChangeTypes.Deleted: MangaCacheObject ExistingMangaCacheObject = MangaCacheObjects.FirstOrDefault( _ => Equals( _.MangaObject.MangaFileName(), Path.GetDirectoryName(e.Name))); if (!Equals(ExistingMangaCacheObject, null)) { Int32 ExistingMangaCacheObjectIndex = ExistingMangaCacheObject.ChapterCacheObjects.FindIndex(_ => Equals(_.ArchiveFileName, Path.GetFileName(e.Name))); if (ExistingMangaCacheObjectIndex >= 0) { ExistingMangaCacheObject.ChapterCacheObjects[ExistingMangaCacheObjectIndex].IsLocal = File.Exists(e.FullPath); } } break; } Messenger.Instance.Send(e, "ChapterObjectArchiveWatcher"); }); }
private async void MangaObjectArchiveWatcher_Event(object sender, FileSystemEventArgs e) { if (Dispatcher.Thread == Thread.CurrentThread) { MangaCacheObject ExistingMangaCacheObject = MangaCacheObjects.FirstOrDefault(_ => Equals(_.ArchiveFileName, e.Name)); switch (e.ChangeType) { case WatcherChangeTypes.Created: if (Equals(ExistingMangaCacheObject, null)) { MangaCacheObjects.Add(ExistingMangaCacheObject = new MangaCacheObject() { ArchiveFileName = e.Name }); } goto case WatcherChangeTypes.Changed; case WatcherChangeTypes.Changed: // (Re)Cache if creaded or changed if (!Equals(ExistingMangaCacheObject, null)) { // If ExistingMangaCacheObject is null we are probably still loading. MangaCacheObject ReloadedMangaCacheObject = await DispatcherReloadMangaCacheObjectAsync(e.FullPath, Equals(ExistingMangaCacheObject.CoverImage, null)); if (!Equals(ReloadedMangaCacheObject, null)) { if (Equals(ExistingMangaCacheObject, null)) { MangaCacheObjects.Add(ReloadedMangaCacheObject); } else { ExistingMangaCacheObject.Update(ReloadedMangaCacheObject); } } } break; case WatcherChangeTypes.Deleted: // Reselect nearest neighbor after delete Int32 ExistingIndex = MangaCacheObjects.IndexOf(ExistingMangaCacheObject); if (ExistingIndex >= 0) { MangaCacheObjects.RemoveAt(ExistingIndex); } // If delete was the last item subtract from index if (ExistingIndex >= MangaCacheObjects.Count) { --ExistingIndex; } Messenger.Instance.Send((ExistingIndex >= 0) ? MangaCacheObjects[ExistingIndex] : null, "SelectMangaCacheObject"); break; default: break; } Messenger.Instance.Send(e, "MangaObjectArchiveWatcher"); } else { Dispatcher.Invoke(DispatcherPriority.Send, new Action(() => MangaObjectArchiveWatcher_Event(sender, e))); } }