Exemplo n.º 1
0
        /// <summary>
        /// 获取书籍目录
        /// </summary>
        /// <param name="book"></param>
        public static void GetList(Book book)
        {
            BookSource bs = GetBookSource(book.Source);

            Dictionary <string, string> NewList = new Dictionary <string, string>();

            //范围
            string temp_str = Tool.GetRegexStr(GetHtml.GetHttpWebRequest(book.Url), bs.DirectoryScopeRegular);

            //分割
            string [] temp_strs = temp_str.Split(new string[] { bs.DirectoryCuttingRegular }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string tempStr in temp_strs)
            {
                string Title = Tool.GetRegexStr(tempStr, bs.DirectoryTieleRegular);
                string Url   = Tool.ObtainUrl(bs.Url, Tool.GetRegexStr(tempStr, bs.DirectoryUrlRegular), book.Url);

                //如果标题相同就会报错,所以这里回家进行简单的处理
                if (!NewList.ContainsKey(Title) && Title.Trim().Length > 2)
                {
                    NewList.Add(Title, Url);
                }

                /* 这里加上后会重复显示
                 * else
                 * {
                 *  NewList.Add(Title + Guid.NewGuid(), Url);
                 * }*/
            }
            book.ListUrl = NewList;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新全部书籍
        /// </summary>
        public static void BooksUpdate(object ob)
        {
            //获取全部书籍
            DataTable   dt    = SQLiteDBHelper.ExecuteDataTable("select *from Books", null);
            List <Book> Books = ModelConvertHelper <Book> .DataTableToList(dt);

            foreach (Book book in Books)
            {
                //获取初始搜索文本
                string html = GetHtml.GetHttpWebRequest(book.Url);

                BookSource bs = GetBookSource(book.Source);

                //检测书源有效性
                if (bs.Title is null)
                {
                    Tips tips = new Tips(book.Name + "的书源不存在,请检查书源是否已经被删除掉?");
                    tips.Show();
                    return;
                }
                //获取最新章节
                string LatestChapters = Tool.GetRegexStr(html, bs.NewestRegular).Trim();

                //获取更新时间
                string Update = Tool.GetRegexStr(html, bs.UpdateRegular).Trim();

                SQLiteDBHelper.ExecuteNonQuery("Update Books set 'Newest' = '" + LatestChapters + "', 'Update' = '" + Tool.GetUpdataDate(Update) + "' where Id =" + book.Id, null);
            }
            ((MainWindow)ob).Dispatcher.Invoke(new Action(() =>
            {
                ((MainWindow)ob).DataContext = DataFetch.GetBooks();
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 软件更新
        /// </summary>
        public static void SoftwareUpdate()
        {
            try
            {
                Update update = JsonHelper.DeserializeJsonToObject <Update>(GetHtml.GetHttp("https://script.haokaikai.cn/Update/HappyReading.json"));
                if (update.State == 1)
                {
                    MessageBox.Show(update.Msg, "软件暂停使用");
                    //关闭全部窗体并退出程序使用
                    Application.Current.Shutdown();
                    return;
                }

                if (Config.Edition != update.Edition)
                {
                    MessageBox.Show(update.Msg + "\n更新日期:" + update.UpdateDate + "\n点击确定后会自动打开下载地址!", "更新提示");
                    //打开网页
                    System.Diagnostics.Process.Start(update.Download);
                }
            }
            catch (Exception ex)
            {
                Tool.TextAdditional(ex.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取目录数
        /// </summary>
        /// <param name="book">书籍对象</param>
        /// <returns>返回目录数</returns>
        public static int GetListCount(Book book)
        {
            //获取初始搜索文本
            string html = GetHtml.GetHttpWebRequest(book.Url);

            BookSource bs = GetBookSource(book.Source);

            //获取书籍范围
            string htmlRange = Tool.GetRegexStr(html, bs.DirectoryScopeRegular).Trim();

            //分割章节
            string[] bookList = htmlRange.Split(new string[] { bs.DirectoryCuttingRegular }, StringSplitOptions.RemoveEmptyEntries);

            return(bookList.Length);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 更新书源状态
        /// </summary>
        public static void UpdateSourceState()
        {
            Thread thread = new Thread(new ThreadStart(delegate
            {
                //遍历源站
                foreach (BookSource bookSource in GetBookSources(0))
                {
                    //1代表网站可以访问,0代表不可以访问
                    int state = GetHtml.GetUnicom(bookSource.Url) ? 1 : 0;
                    UpdateState((int)bookSource.Id, state);
                }
                App.Current.Dispatcher.Invoke((Action)(() =>
                {
                    TempData.UpdateBookSourceS();
                }));
            }));

            thread.IsBackground = true;
            thread.Start();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 搜索书籍
        /// </summary>
        /// <param name="bookSource">书源</param>
        /// <param name="Keyword">书名关键词</param>
        /// <returns>返回搜索结果</returns>
        public static List <Book> Search(BookSource bookSource, string Keyword)
        {
            //这里先判断是否是全部书源搜索
            if (bookSource.Id == -5)
            {
                List <Book> Books = new List <Book>();
                foreach (BookSource Source in TempData.GetBookSourceS())
                {
                    try
                    {
                        if (Books.Count <= 0)
                        {
                            if (Search(Source, Keyword) != null)
                            {
                                Books = Search(Source, Keyword);
                            }
                        }
                        else
                        {
                            Books = Books.Concat(Search(Source, Keyword)).ToList <Book>();
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                return(Books);
            }

            //存放书籍的书架
            List <Book> books = new List <Book>();

            //获取初始搜索文本
            string html = GetHtml.GetHttpWebRequest(bookSource.SearchUrl + Keyword.Trim());

            //获取搜索书籍范围
            string htmlRange = Tool.GetRegexStr(html, bookSource.AddressRangeRegular).Trim();

            //分割搜索书籍
            string[] bookList = htmlRange.Split(new string[] { bookSource.AddressCuttingRegular }, StringSplitOptions.RemoveEmptyEntries);

            //遍历搜索到的书籍
            for (int i = 0; i < bookList.Length; i++)
            {
                //获取到书籍地址
                string BookUrl = Tool.GetRegexStr(bookList[i], bookSource.AddressRegular);

                //防止因为找不到书籍而导致的错误
                if (BookUrl.Length <= 3)
                {
                    continue;
                }

                string BookHtml = GetHtml.GetHttpWebRequest(BookUrl);

                //获取书籍名称
                string BookName = Tool.GetRegexStr(BookHtml, bookSource.BookNameRegular);


                //获取作者
                string BookAuthor = Tool.GetRegexStr(BookHtml, bookSource.AuthorRegular);

                //获取更新时间
                string BookUpdate = Tool.GetUpdataDate(Tool.GetRegexStr(BookHtml, bookSource.UpdateRegular));

                //获取最新章节名称
                string BookNewest = Tool.GetRegexStr(BookHtml, bookSource.NewestRegular);

                //获取源站名称
                string BookSource = bookSource.Title;

                //封面图
                string BookImage = Tool.GetRegexStr(BookHtml, bookSource.ImageRegular);

                //更新状态
                string BookUpdateState = Tool.GetRegexStr(BookHtml, bookSource.StateRegular);

                //简介
                string BookDetails = Tool.GetRegexStr(BookHtml, bookSource.DetailsRegular);

                books.Add(new Book {
                    Author = BookAuthor, Update = BookUpdate, Name = BookName, Source = BookSource, Newest = BookNewest, Url = BookUrl, Details = BookDetails, Image = BookImage, UpdateState = BookUpdateState
                });
            }

            if (books.Count <= 0)
            {
                return(null);
            }
            return(books);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 搜索书籍
        /// </summary>
        /// <param name="bookSource">书源</param>
        /// <param name="Keyword">书名关键词</param>
        /// <returns>返回搜索结果</returns>
        public static List <Book> Search(BookSource bookSource, string Keyword)
        {
            /*
             * //这里先判断是否是全部书源搜索
             * if (bookSource.Id == -5)
             * {
             *  List<Book> Books = new List<Book>();
             *  foreach (BookSource Source in TempData.GetBookSourceS())
             *  {
             *      try
             *      {
             *          if (Books.Count <= 0)
             *          {
             *              List<Book> T_books = Search(Source, Keyword);
             *              if (T_books != null)
             *              {
             *                  Books = T_books;
             *              }
             *          }
             *          else
             *          {
             *              Books = Books.Concat(Search(Source, Keyword)).ToList<Book>();
             *          }
             *      }
             *      catch (Exception ex)
             *      {
             *          MessageBox.Show(ex.Message);
             *          Tool.TextAdditional(ex.Message);
             *      }
             *  }
             *  return Books;
             * }*/

            //获取编码
            string Code = GetHtml.GetCode(bookSource.SearchUrl);

            //忽略大小写进行比较
            if (!Code.Equals("utf-8", StringComparison.OrdinalIgnoreCase))
            {
                if (Code.Trim().Length <= 0)
                {
                    Code = "utf-8";
                }
                //这里处理一下keyword
                Keyword = Tool.EncodingConvert(Keyword, Encoding.GetEncoding(Code));
            }
            //存放书籍的书架
            List <Book> books = new List <Book>();

            //获取初始搜索文本
            string html = GetHtml.GetHttpWebRequest(bookSource.SearchUrl + Keyword.Trim());

            //获取搜索书籍范围
            string htmlRange = Tool.GetRegexStr(html, bookSource.AddressRangeRegular).Trim();

            //分割搜索书籍
            string[] bookList = htmlRange.Split(new string[] { bookSource.AddressCuttingRegular }, StringSplitOptions.RemoveEmptyEntries);

            //遍历搜索到的书籍
            for (int i = 0; i < bookList.Length; i++)
            {
                //获取到书籍地址(对链接做出处理)
                string BookUrl = Tool.ObtainUrl(bookSource.Url, Tool.GetRegexStr(bookList[i], bookSource.AddressRegular));

                //防止因为找不到书籍而导致的错误
                if (BookUrl.Length <= 3)
                {
                    continue;
                }

                string BookHtml = GetHtml.GetHttpWebRequest(BookUrl);

                //获取书籍名称
                string BookName = Tool.GetRegexStr(BookHtml, bookSource.BookNameRegular);

                //书名都不存在,自然需要跳过本次循环
                if (BookName.Length <= 0)
                {
                    continue;
                }

                //获取作者
                string BookAuthor = Tool.GetRegexStr(BookHtml, bookSource.AuthorRegular);

                //获取更新时间
                string BookUpdate = Tool.GetUpdataDate(Tool.GetRegexStr(BookHtml, bookSource.UpdateRegular));

                //获取最新章节名称
                string BookNewest = Tool.GetRegexStr(BookHtml, bookSource.NewestRegular);

                //获取源站名称
                string BookSource = bookSource.Title;

                //封面图
                string BookImage = Tool.GetRegexStr(BookHtml, bookSource.ImageRegular);

                //更新状态
                string BookUpdateState = Tool.GetRegexStr(BookHtml, bookSource.StateRegular);

                //简介
                string BookDetails = Tool.GetRegexStr(BookHtml, bookSource.DetailsRegular);

                books.Add(new Book {
                    Author = BookAuthor, Update = BookUpdate, Name = BookName, Source = BookSource, Newest = BookNewest, Url = BookUrl, Details = BookDetails, Image = BookImage, UpdateState = BookUpdateState
                });
            }

            if (books.Count <= 0)
            {
                return(null);
            }
            return(books);
        }