From 8c9edcfbda13b39b9730d32dde3274fe6989c51c Mon Sep 17 00:00:00 2001 From: Horis <8674809+821938089@users.noreply.github.com> Date: Sun, 31 Aug 2025 21:28:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20#5379?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/Restore.kt | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Restore.kt b/app/src/main/java/io/legado/app/help/storage/Restore.kt index d612038f2..4c6ea8823 100644 --- a/app/src/main/java/io/legado/app/help/storage/Restore.kt +++ b/app/src/main/java/io/legado/app/help/storage/Restore.kt @@ -1,6 +1,7 @@ package io.legado.app.help.storage import android.content.Context +import android.database.sqlite.SQLiteConstraintException import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.BuildConfig @@ -105,14 +106,23 @@ object Restore { .forEach { book -> book.coverUrl = LocalBook.getCoverPath(book) } - val books = if (BackupConfig.ignoreLocalBook) { - it.filter { book -> - !book.isLocal + val newBooks = arrayListOf() + val ignoreLocalBook = BackupConfig.ignoreLocalBook + it.forEach { book -> + if (ignoreLocalBook && book.isLocal) { + return@forEach + } + if (appDb.bookDao.has(book.bookUrl)) { + try { + appDb.bookDao.update(book) + } catch (_: SQLiteConstraintException) { + appDb.bookDao.insert(book) + } + } else { + newBooks.add(book) } - } else { - it } - appDb.bookDao.insert(*books.toTypedArray()) + appDb.bookDao.insert(*newBooks.toTypedArray()) } fileToListT(path, "bookmark.json")?.let { appDb.bookmarkDao.insert(*it.toTypedArray())