private bool UpdateNovel(Object input) { if (!(input is Novel)) { return(false); } Novel updateNovel = input as Novel; if (updateNovel == null || updateNovel.UpdateState == Novel.UpdateStates.Checking || updateNovel.UpdateState == Novel.UpdateStates.Fetching || updateNovel.UpdateState == Novel.UpdateStates.Syncing) { return(false); } updateNovel.SyncToOrigin(); bool result = updateNovel.CheckForUpdate(); if (!result) { return(false); } var chapters = updateNovel.NovelChapters; List <Chapter> downloadChapters = new List <Chapter>(); foreach (Chapter c in chapters) { if (!c.HasText) { downloadChapters.Add(c); } } int downloadCount = 0; bool success; for (int i = 0; i < downloadChapters.Count && !shutDown && updateNovel != null; i++) { updateNovel.SetUpdateProgress(i + 1, downloadChapters.Count, Novel.UpdateStates.Fetching); success = updateNovel.DownloadChapter(downloadChapters[i]); if (success) { downloadCount++; } } if (updateNovel != null) { updateNovel.ChaptersNotReadCount = updateNovel.ChaptersNotReadCount + downloadCount; updateNovel.SetUpdateProgress(0, 0, Novel.UpdateStates.UpToDate); updateNovel.NotifyPropertyChanged("ChapterCountStatus"); return(true); } else { return(false); } }
private void RedownloadChapters(Source source) { Chapter[] chapters = GetSelectedChapterItem(); if (chapters.Contains(currentReadingChapter) && editModeOn) { MessageBox.Show("Please finish editing first.", "Edit", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } new Thread(delegate() { foreach (Chapter chapter in chapters) { currentReadingNovel.DownloadChapter(chapter, source); if (currentReadingChapter.ID == chapter.ID) { this.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate { ReadChapter(chapter); })); } } }).Start(); }