/*============Public Function=======*/ public void Update() { SetUpdateProgress(0, 0, UpdateState.Checking); Source.Source s = SourceManager.GetSource(_novelTitle, 22590, SourceManager.Sources.web69); Tuple <string, string>[] menuItems = s.GetMenuURLs(); int newlyAddedChapter = 0; for (int i = _chapters.Count; i < menuItems.Length; i++) { string chapterTitle = menuItems[i].Item1; string url = menuItems[i].Item2; Chapter newChapter = new Chapter(chapterTitle, _novelTitle, false, i); AppendNewChapter(newChapter); newlyAddedChapter++; SetUpdateProgress(i, menuItems.Length, UpdateState.Fetching); string[] novelContent = s.GetChapterContent(chapterTitle, url); string chapterLocation = newChapter.GetTextFileLocation(); System.IO.File.WriteAllLines(chapterLocation, novelContent); } SetUpdateProgress(0, 0, UpdateState.UpToDate); if (BackgroundService.Instance.novelListController.InvokeRequired) { BackgroundService.Instance.novelListController.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate { NewChapterCount = _newChapterCount + newlyAddedChapter; NotifyPropertyChanged("ChapterCount"); })); } }
private void ReadChapter(Chapter chapter) { using (StreamReader sr = new StreamReader(chapter.GetTextFileLocation())) { string chapterText = sr.ReadToEnd(); rtbChapterTextBox.Text = chapterText; chapter.Read = true; } currentChapter = chapter; currentChapterDirty = false; }
private void ReadChapter(Chapter chapter) { if (chapter == null || chapter.NovelTitle != currentReadingNovel.NovelTitle) { return; } labelTitle.Text = chapter.ChapterTitle; currentReadingNovel.StartReadingChapter(chapter); currentReadingChapter = chapter; if (Configuration.Instance.AutoPlay) { PlayAudio(chapter); } if (chapter.HasText) { try { string cacheLocation = Path.Combine(Configuration.Instance.CacheFolderLocation, chapter.HashID + ".txt"); File.Copy(chapter.GetTextFileLocation(), cacheLocation, true); using (StreamReader sr = new StreamReader(cacheLocation)) { string chapterText = sr.ReadToEnd(); rtbChapterTextBox.Text = chapterText; rtbChapterTextBox.Select(0, 0); rtbChapterTextBox.ScrollToCaret(); } } catch (Exception) { rtbChapterTextBox.Text = "Please Reload."; } } else { rtbChapterTextBox.Text = "No text file available"; } currentChapterDirty = false; if (dgvChapterList.SelectedRows.Count > 0) { foreach (DataGridViewRow row in dgvChapterList.SelectedRows) { row.Selected = false; } } }
private void FinishEditing() { if (!editModeOn) { return; } rtbChapterTextBox.BackColor = Color.AliceBlue; btnEdit.Text = "Edit"; if (currentChapterDirty) { if (currentReadingChapter != null) { string text = rtbChapterTextBox.Text; System.IO.File.WriteAllText(currentReadingChapter.GetTextFileLocation(), text); } } editModeOn = false; }
private void FinishEditing() { rtbChapterTextBox.ReadOnly = true; rtbChapterTextBox.BackColor = Color.AliceBlue; btnEdit.Text = "Edit"; if (currentChapterDirty) { Console.WriteLine("Current Chapter dirty"); if (currentChapter != null) { string text = rtbChapterTextBox.Text; System.IO.File.WriteAllText(currentChapter.GetTextFileLocation(), text); } } else { Console.WriteLine("Current Chapter clean"); } }
public void DeleteChapter(Chapter deleteChapter, bool blackList, bool verifyData = true) { if (NovelLibrary.libraryData.Chapters.Any(chapter => chapter.ID == deleteChapter.ID)) { if (deleteChapter.HasAudio) { File.Delete(deleteChapter.GetAudioFileLocation()); } if (deleteChapter.HasText) { File.Delete(deleteChapter.GetTextFileLocation()); } if (deleteChapter.ID == LastReadChapterID) { Console.WriteLine(deleteChapter.ID + " " + deleteChapter.Index + " " + deleteChapter.ChapterTitle); if (deleteChapter.Index > 0) { LastReadChapter = GetChapter(deleteChapter.Index - 1); } else if (deleteChapter.Index == 0 && ChapterCount > 1) { LastReadChapter = GetChapter(1); } else { LastReadChapter = null; } } ChapterUrl[] urls = deleteChapter.ChapterUrls.ToArray <ChapterUrl>(); if (urls != null) { if (blackList) { deleteChapter.Valid = false; } else { NovelLibrary.libraryData.Chapters.DeleteOnSubmit(deleteChapter); NovelLibrary.libraryData.ChapterUrls.DeleteAllOnSubmit(deleteChapter.ChapterUrls); } } else { NovelLibrary.libraryData.Chapters.DeleteOnSubmit(deleteChapter); } if (chapterList.Contains(deleteChapter)) { chapterList.Remove(deleteChapter); } isDirty = true; NovelLibrary.libraryData.SubmitChanges(); //foreach (Chapter c in chapters) // Console.WriteLine(c.ChapterTitle + " " + c.Index +" " + c.ID); if (verifyData) { Chapter[] chapters = NovelChapters.ToArray <Chapter>(); } NotifyPropertyChanged("ChapterCountStatus"); } }
public bool DownloadChapter(Chapter downloadChapter, Source specificSource = null) { if (downloadChapter == null || !downloadChapter.Valid) { SetUpdateProgress(0, 0, UpdateStates.Error); return(false); } if (UpdateState == UpdateStates.Syncing || UpdateState == UpdateStates.Checking) { return(false); } var result = downloadChapter.ChapterUrls; if (!result.Any()) { SetUpdateProgress(0, 0, UpdateStates.Error); return(false); } if (specificSource != null) { if (!Sources.Contains(specificSource)) { return(false); } var urlResult = (from url in downloadChapter.ChapterUrls where url.Source.ID == specificSource.ID select url); if (!urlResult.Any()) { return(false); } ChapterUrl specificUrl = urlResult.First <ChapterUrl>(); string[] novelContent = specificSource.GetChapterContent(downloadChapter.ChapterTitle, specificUrl.Url); if (novelContent == null) { return(false); } System.IO.File.WriteAllLines(downloadChapter.GetTextFileLocation(), novelContent); return(true); } ChapterUrl[] urls = (from url in result where url.Vip == false orderby url.Source.Priority ascending select url).ToArray <ChapterUrl>(); foreach (ChapterUrl url in urls) { //Console.WriteLine("Download chapter " + downloadChapter.ChapterTitle + " " + (url.Vip)); if (url == null || url.Vip) { continue; } Source source = url.Source; if (source == null || !source.Valid) { continue; } string[] novelContent = source.GetChapterContent(downloadChapter.ChapterTitle, url.Url); if (novelContent == null) { continue; } System.IO.File.WriteAllLines(downloadChapter.GetTextFileLocation(), novelContent); if (Configuration.Instance.TextExportLocation != null) { string exportFolderLocation = Path.Combine(Configuration.Instance.TextExportLocation, NovelTitle); if (!Directory.Exists(exportFolderLocation)) { Directory.CreateDirectory(exportFolderLocation); } if (Configuration.Instance.NovelExport.ContainsKey(NovelTitle)) { ExportOption exportOption = Configuration.Instance.NovelExport[NovelTitle]; if (exportOption == ExportOption.Both || exportOption == ExportOption.Text) { downloadChapter.ExportText(exportFolderLocation); } } } return(true); } return(false); }
public bool ShouldMakeAudio(Chapter chapter, bool secondaryPass) { //if (_chapters == null || _chapters.Count == 0) // return false; if (_lastReadChapter != null && _lastReadChapter.Index > chapter.Index && !secondaryPass) { return(false); } //if (Configuration.Instance.LanguageVoiceDictionary[NovelSource.NovelLanguage] == null || Configuration.Instance.LanguageVoiceDictionary[NovelSource.NovelLanguage].Equals("No Voice Selected")) // return false; //Do not make audio for novel not selected if (!MakeAudio) { return(false); } //Do not make audio for novel that is dropped if (State == NovelState.Dropped) { return(false); } //Do not make audio for novel already read and setting checked for making tts for chapter already read if (chapter.Read && !Configuration.Instance.MakeTTSForChapterAlreadyRead) { return(false); } //Do make audio for chapter that has text and chapter that has no audio if (chapter.HasText && !chapter.HasAudio) { return(true); } //Remake audio if text is editted after an audio file is made if (chapter.HasText && chapter.HasAudio) { if (File.GetLastWriteTime(chapter.GetAudioFileLocation()) < File.GetLastWriteTime(chapter.GetTextFileLocation())) { return(true); } else { return(false); } } return(false); }
/*============Public Function=======*/ public void Update() { SetUpdateProgress(0, 0, UpdateState.Checking); Source.Source s = SourceManager.GetSource(_novelTitle, 22590, SourceManager.Sources.web69); Tuple<string, string>[] menuItems = s.GetMenuURLs(); int newlyAddedChapter = 0; for (int i = _chapters.Count; i < menuItems.Length; i++) { string chapterTitle = menuItems[i].Item1; string url = menuItems[i].Item2; Chapter newChapter = new Chapter(chapterTitle, _novelTitle, false, i); AppendNewChapter(newChapter); newlyAddedChapter++; SetUpdateProgress(i, menuItems.Length, UpdateState.Fetching); string[] novelContent = s.GetChapterContent(chapterTitle, url); string chapterLocation = newChapter.GetTextFileLocation(); System.IO.File.WriteAllLines(chapterLocation, novelContent); } SetUpdateProgress(0, 0, UpdateState.UpToDate); if (BackgroundService.Instance.novelListController.InvokeRequired) { BackgroundService.Instance.novelListController.BeginInvoke(new System.Windows.Forms.MethodInvoker(delegate { NewChapterCount = _newChapterCount + newlyAddedChapter; NotifyPropertyChanged("ChapterCount"); })); } }
private void ReadChapter(Chapter chapter) { using (StreamReader sr = new StreamReader(chapter.GetTextFileLocation())) { string chapterText = sr.ReadToEnd(); rtbChapterTextBox.Text = chapterText; chapter.Read = true; } currentChapter = chapter; currentChapterDirty = false; }