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

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

Loading…
Cancel
Save