diff --git a/app/src/main/assets/txtChapterRule.json b/app/src/main/assets/txtTocRule.json similarity index 100% rename from app/src/main/assets/txtChapterRule.json rename to app/src/main/assets/txtTocRule.json 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 96a44e1c5..9d6777057 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 @@ -4,9 +4,8 @@ import android.content.Context import android.net.Uri import io.legado.app.App import io.legado.app.data.entities.Book -import io.legado.app.utils.DocumentUtils -import io.legado.app.utils.EncodingDetect -import io.legado.app.utils.FileUtils +import io.legado.app.data.entities.TxtTocRule +import io.legado.app.utils.* import java.io.File import java.io.RandomAccessFile @@ -29,10 +28,23 @@ object AnalyzeTxtFile { } } book.charset = EncodingDetect.getEncode(bookFile) - + val tocRules = getTocRules() //获取文件流 val bookStream = RandomAccessFile(bookFile, "r") } + + private fun getTocRules(): List { + val rules = App.db.txtTocRule().all + if (rules.isEmpty()) { + App.INSTANCE.assets.open("txtTocRule.json").readBytes().let { byteArray -> + GSON.fromJsonArray(String(byteArray))?.let { + App.db.txtTocRule().insert(*it.toTypedArray()) + return it + } + } + } + return rules + } } \ No newline at end of file