pull/32/head
kunfei 5 years ago
parent c874c6e816
commit e47a8602e7
  1. 11
      app/src/main/java/io/legado/app/help/storage/OldRule.kt
  2. 10
      app/src/main/java/io/legado/app/help/storage/Restore.kt

@ -1,6 +1,8 @@
package io.legado.app.help.storage package io.legado.app.help.storage
import com.jayway.jsonpath.Configuration
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import com.jayway.jsonpath.Option
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.rule.* import io.legado.app.data.entities.rule.*
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
@ -12,7 +14,11 @@ import java.util.regex.Pattern
object OldRule { object OldRule {
private val headerPattern = Pattern.compile("@Header:\\{.+?\\}", Pattern.CASE_INSENSITIVE) private val headerPattern = Pattern.compile("@Header:\\{.+?\\}", Pattern.CASE_INSENSITIVE)
private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE) private val jsPattern = Pattern.compile("\\{\\{.+?\\}\\}", Pattern.CASE_INSENSITIVE)
private val jsonPath = JsonPath.using(
Configuration.builder()
.options(Option.SUPPRESS_EXCEPTIONS)
.build()
)
fun jsonToBookSource(json: String): BookSource? { fun jsonToBookSource(json: String): BookSource? {
var source: BookSource? = null var source: BookSource? = null
@ -22,7 +28,7 @@ object OldRule {
runCatching { runCatching {
source ?: let { source ?: let {
source = BookSource().apply { source = BookSource().apply {
val jsonItem = JsonPath.parse(json) val jsonItem = jsonPath.parse(json)
bookSourceUrl = jsonItem.readString("bookSourceUrl") ?: "" bookSourceUrl = jsonItem.readString("bookSourceUrl") ?: ""
bookSourceName = jsonItem.readString("bookSourceName") ?: "" bookSourceName = jsonItem.readString("bookSourceName") ?: ""
bookSourceGroup = jsonItem.readString("bookSourceGroup") ?: "" bookSourceGroup = jsonItem.readString("bookSourceGroup") ?: ""
@ -88,6 +94,7 @@ object OldRule {
private fun toNewUrl(oldUrl: String?): String? { private fun toNewUrl(oldUrl: String?): String? {
if (oldUrl == null) return null if (oldUrl == null) return null
if (oldUrl.startsWith("<js>", true)) return oldUrl
val map = HashMap<String, String>() val map = HashMap<String, String>()
var url: String = oldUrl var url: String = oldUrl
var mather = headerPattern.matcher(url) var mather = headerPattern.matcher(url)

@ -17,6 +17,11 @@ import org.jetbrains.anko.uiThread
import java.io.File import java.io.File
object Restore { object Restore {
private val jsonPath = JsonPath.using(
Configuration.builder()
.options(Option.SUPPRESS_EXCEPTIONS)
.build()
)
fun restore() { fun restore() {
@ -28,11 +33,6 @@ object Restore {
fun importYueDuData(context: Context) { fun importYueDuData(context: Context) {
val yuedu = File(FileUtils.getSdPath(), "YueDu") val yuedu = File(FileUtils.getSdPath(), "YueDu")
val jsonPath = JsonPath.using(
Configuration.builder()
.options(Option.SUPPRESS_EXCEPTIONS)
.build()
)
// 导入书架 // 导入书架
val shelfFile = File(yuedu, "myBookShelf.json") val shelfFile = File(yuedu, "myBookShelf.json")

Loading…
Cancel
Save