From 3f8743c58cc040035758e5914b3620911f51e793 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 10 Jan 2022 21:25:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/localBook/LocalBook.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index ea499d4d8..87ef1950e 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -81,38 +81,41 @@ object LocalBook { } fun importFile(uri: Uri): Book { - val path: String + val bookUrl: String val updateTime: Long //这个变量不要修改,否则会导致读取不到缓存 val fileName = (if (uri.isContentScheme()) { - path = uri.toString() + bookUrl = uri.toString() val doc = DocumentFile.fromSingleUri(appCtx, uri)!! updateTime = doc.lastModified() doc.name!! } else { - path = uri.path!! - val file = File(path) + bookUrl = uri.path!! + val file = File(bookUrl) updateTime = file.lastModified() file.name }) - var book = appDb.bookDao.getBook(path) + var book = appDb.bookDao.getBook(bookUrl) if (book == null) { val nameAuthor = analyzeNameAuthor(fileName) book = Book( - bookUrl = path, + bookUrl = bookUrl, name = nameAuthor.first, author = nameAuthor.second, originName = fileName, coverUrl = FileUtils.getPath( appCtx.externalFiles, "covers", - "${MD5Utils.md5Encode16(path)}.jpg" + "${MD5Utils.md5Encode16(bookUrl)}.jpg" ), latestChapterTime = updateTime ) if (book.isEpub()) EpubFile.upBookInfo(book) if (book.isUmd()) UmdFile.upBookInfo(book) appDb.bookDao.insert(book) + } else { + //已有书籍说明是更新,删除原有目录 + appDb.bookChapterDao.delByBook(bookUrl) } return book }