pull/32/head
GKF 6 years ago
parent 2304a1c7fb
commit 758d6c3fa1
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt
  2. 27
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -16,6 +16,9 @@ interface BookSourceDao {
@Query("select * from book_sources where exploreIsEnabled = 1 order by customOrder asc") @Query("select * from book_sources where exploreIsEnabled = 1 order by customOrder asc")
fun observeFind(): DataSource.Factory<Int, BookSource> fun observeFind(): DataSource.Factory<Int, BookSource>
@get:Query("select * from book_sources order by customOrder asc")
val all: List<BookSource>
@Query("select * from book_sources where origin = :key") @Query("select * from book_sources where origin = :key")
fun findByKey(key: String): BookSource? fun findByKey(key: String): BookSource?

@ -8,6 +8,7 @@ import com.jayway.jsonpath.Option
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.AppConst import io.legado.app.constant.AppConst
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.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.* import io.legado.app.utils.*
import org.jetbrains.anko.doAsync import org.jetbrains.anko.doAsync
@ -87,6 +88,32 @@ object Restore {
context.toast("Unable to import books:\n${e.localizedMessage}") context.toast("Unable to import books:\n${e.localizedMessage}")
} }
// Book source
val sourceFile = File(yuedu, "myBookSource.json")
val bookSources = mutableListOf<BookSource>()
if (shelfFile.exists()) try {
doAsync {
val items: List<Map<String, Any>> = jsonPath.parse(sourceFile.readText()).read("$")
val existings = App.db.bookSourceDao().all.map { it.origin }.toSet()
for (item in items) {
val jsonItem = jsonPath.parse(item)
val source = BookSource()
source.origin = jsonItem.readString("bookSourceUrl") ?: ""
if (source.origin.isBlank()) continue
if (source.origin in existings) continue
source.name = jsonItem.readString("bookSourceName") ?: ""
source.group = jsonItem.readString("bookSourceGroup") ?: ""
source.loginUrl = jsonItem.readString("loginUrl")
bookSources.add(source)
}
App.db.bookSourceDao().insert(*bookSources.toTypedArray())
}
} catch (e: Exception) {
error(e.localizedMessage)
}
// Replace rules // Replace rules
val ruleFile = File(yuedu, "myBookReplaceRule.json") val ruleFile = File(yuedu, "myBookReplaceRule.json")
val replaceRules = mutableListOf<ReplaceRule>() val replaceRules = mutableListOf<ReplaceRule>()

Loading…
Cancel
Save