From 661e9d8b06ed65cec022441e4ebd91d41b42b832 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 4 May 2020 22:39:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/model/localBook/AnalyzeTxtFile.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index 494437d92..15e8597c2 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -40,6 +40,7 @@ class AnalyzeTxtFile { book: Book, pattern: Pattern? ): ArrayList { + bookStream.seek(0) val toc = arrayListOf() var tocRule: TxtTocRule? = null val rulePattern = pattern ?: let { @@ -83,7 +84,8 @@ class AnalyzeTxtFile { //获取章节内容 val chapterContent = blockContent.substring(seekPos, chapterStart) val chapterLength = chapterContent.toByteArray(charset).size - if (chapterLength > 30000 && pattern == null) { + val lastStart = toc.lastOrNull()?.start ?: 0 + if (curOffset + chapterLength - lastStart > 50000 && pattern == null) { //移除不匹配的规则 tocRules.remove(tocRule) return analyze(bookStream, book, null) @@ -139,6 +141,11 @@ class AnalyzeTxtFile { //设置指针偏移 seekPos += chapterContent.length } + if (seekPos == 0 && length > 50000 && pattern == null) { + //移除不匹配的规则 + tocRules.remove(tocRule) + return analyze(bookStream, book, null) + } } else { //进行本地虚拟分章 //章节在buffer的偏移量 var chapterOffset = 0