Horis 1 سال پیش
والد
کامیت
91c8fa2d6c

+ 2 - 2
app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt

@@ -122,8 +122,8 @@ interface RssSourceDao {
     @Query("select * from rssSources where sourceGroup like '%' || :group || '%'")
     @Query("select * from rssSources where sourceGroup like '%' || :group || '%'")
     fun getByGroup(group: String): List<RssSource>
     fun getByGroup(group: String): List<RssSource>
 
 
-    @Query("select 1 from rssSources where sourceUrl = :key")
-    fun has(key: String): Boolean?
+    @Query("select exists(select 1 from rssSources where sourceUrl = :key)")
+    fun has(key: String): Boolean
 
 
     @Query("update rssSources set enabled = :enable where sourceUrl = :sourceUrl")
     @Query("update rssSources set enabled = :enable where sourceUrl = :sourceUrl")
     fun enable(sourceUrl: String, enable: Boolean)
     fun enable(sourceUrl: String, enable: Boolean)

+ 8 - 2
app/src/main/java/io/legado/app/help/RuleBigDataHelp.kt

@@ -27,7 +27,7 @@ object RuleBigDataHelp {
                         FileUtils.delete(it)
                         FileUtils.delete(it)
                     } else {
                     } else {
                         val bookUrl = bookUrlFile.readText()
                         val bookUrl = bookUrlFile.readText()
-                        if (appDb.bookDao.has(bookUrl) != true) {
+                        if (!appDb.bookDao.has(bookUrl)) {
                             FileUtils.delete(it)
                             FileUtils.delete(it)
                         }
                         }
                     }
                     }
@@ -42,7 +42,7 @@ object RuleBigDataHelp {
                         FileUtils.delete(it)
                         FileUtils.delete(it)
                     } else {
                     } else {
                         val origin = originFile.readText()
                         val origin = originFile.readText()
-                        if (appDb.rssSourceDao.has(origin) != true) {
+                        if (!appDb.rssSourceDao.has(origin)) {
                             FileUtils.delete(it)
                             FileUtils.delete(it)
                         }
                         }
                     }
                     }
@@ -76,6 +76,12 @@ object RuleBigDataHelp {
         return null
         return null
     }
     }
 
 
+    fun hasBookVariable(bookUrl: String, key: String): Boolean {
+        val md5BookUrl = MD5Utils.md5Encode(bookUrl)
+        val md5Key = MD5Utils.md5Encode(key)
+        val file = File(FileUtils.getPath(bookData, md5BookUrl, "$md5Key.txt"))
+        return file.exists()
+    }
 
 
     fun putChapterVariable(bookUrl: String, chapterUrl: String, key: String, value: String?) {
     fun putChapterVariable(bookUrl: String, chapterUrl: String, key: String, value: String?) {
         val md5BookUrl = MD5Utils.md5Encode(bookUrl)
         val md5BookUrl = MD5Utils.md5Encode(bookUrl)

+ 8 - 2
app/src/main/java/io/legado/app/help/book/BookExtensions.kt

@@ -14,6 +14,7 @@ import io.legado.app.data.entities.BaseBook
 import io.legado.app.data.entities.Book
 import io.legado.app.data.entities.Book
 import io.legado.app.data.entities.BookSource
 import io.legado.app.data.entities.BookSource
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.exception.NoStackTraceException
+import io.legado.app.help.RuleBigDataHelp
 import io.legado.app.help.config.AppConfig
 import io.legado.app.help.config.AppConfig
 import io.legado.app.model.localBook.LocalBook
 import io.legado.app.model.localBook.LocalBook
 import io.legado.app.utils.FileDoc
 import io.legado.app.utils.FileDoc
@@ -268,13 +269,18 @@ fun Book.updateTo(newBook: Book): Book {
     newBook.canUpdate = canUpdate
     newBook.canUpdate = canUpdate
     newBook.readConfig = readConfig
     newBook.readConfig = readConfig
     val variableMap = variableMap.toMutableMap()
     val variableMap = variableMap.toMutableMap()
-    variableMap.putAll(newBook.variableMap)
-    newBook.variableMap.clear()
+    variableMap.keys.removeIf {
+        newBook.hasVariable(it)
+    }
     newBook.variableMap.putAll(variableMap)
     newBook.variableMap.putAll(variableMap)
     newBook.variable = GSON.toJson(variableMap)
     newBook.variable = GSON.toJson(variableMap)
     return newBook
     return newBook
 }
 }
 
 
+fun Book.hasVariable(key: String): Boolean {
+    return variableMap.contains(key) || RuleBigDataHelp.hasBookVariable(bookUrl, key)
+}
+
 fun Book.getFolderNameNoCache(): String {
 fun Book.getFolderNameNoCache(): String {
     return name.replace(AppPattern.fileNameRegex, "").let {
     return name.replace(AppPattern.fileNameRegex, "").let {
         it.substring(0, min(9, it.length)) + MD5Utils.md5Encode16(bookUrl)
         it.substring(0, min(9, it.length)) + MD5Utils.md5Encode16(bookUrl)