diff --git a/app/src/main/java/io/legado/app/help/storage/OldRule.kt b/app/src/main/java/io/legado/app/help/storage/OldRule.kt index df2a389cc..52d1deb0e 100644 --- a/app/src/main/java/io/legado/app/help/storage/OldRule.kt +++ b/app/src/main/java/io/legado/app/help/storage/OldRule.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("", true)) return oldUrl val map = HashMap() var url: String = oldUrl var mather = headerPattern.matcher(url) 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 714b751cc..124e74303 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 @@ -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")