diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index edf0ac21d..9d54376e8 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -17,6 +17,7 @@ * 一些带有搜索框的界面自动隐藏软键盘 * 本地书籍和远程书籍导入界面支持压缩包 * 内置了两个直链上传配置,可以通过导入默认切换 +* 修复无法导入不在数组内的单个书源的本地文件 **2023/03/14** diff --git a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt index 7a55a41f4..3f614acd0 100644 --- a/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt +++ b/app/src/main/java/io/legado/app/help/source/SourceAnalyzer.kt @@ -2,6 +2,7 @@ package io.legado.app.help.source import androidx.annotation.Keep import com.jayway.jsonpath.JsonPath +import io.legado.app.R import io.legado.app.constant.AppConst import io.legado.app.constant.AppLog import io.legado.app.constant.BookSourceType @@ -11,6 +12,8 @@ import io.legado.app.exception.NoStackTraceException import io.legado.app.utils.* import java.io.InputStream import java.util.regex.Pattern +import splitties.init.appCtx + @Suppress("RegExpRedundantEscape") object SourceAnalyzer { @@ -36,7 +39,7 @@ object SourceAnalyzer { } } else -> { - throw NoStackTraceException("格式不对") + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } } bookSources @@ -46,22 +49,25 @@ object SourceAnalyzer { fun jsonToBookSources(inputStream: InputStream): Result> { return kotlin.runCatching { val bookSources = mutableListOf() -// kotlin.runCatching { - val items: List> = jsonPath.parse(inputStream).read("$") - for (item in items) { - val jsonItem = jsonPath.parse(item) + val documentContext = jsonPath.parse(inputStream) + try { + val items: List> = documentContext.read("$") + items.forEach { + val jsonItem = jsonPath.parse(it) jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { bookSources.add(it) } } -// }.onFailure { -// val item: Map = jsonPath.parse(inputStream).read("$") -// val jsonItem = jsonPath.parse(item) -// jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { -// bookSources.add(it) -// } -// } + } catch (_: Exception) { + val item: Map = documentContext.read("$") + val jsonItem = jsonPath.parse(item) + jsonToBookSource(jsonItem.jsonString()).getOrThrow().let { + bookSources.add(it) + } + } bookSources + }.onFailure { + throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) } } @@ -69,14 +75,14 @@ object SourceAnalyzer { val source = BookSource() val sourceAny = GSON.fromJsonObject(json.trim()) .onFailure { - AppLog.put("转化书源出错", it) + AppLog.put(appCtx.getString(R.string.wrong_format), it) }.getOrNull() return kotlin.runCatching { if (sourceAny?.ruleToc == null) { source.apply { val jsonItem = jsonPath.parse(json.trim()) bookSourceUrl = jsonItem.readString("bookSourceUrl") - ?: throw NoStackTraceException("格式不对") + ?: throw NoStackTraceException(appCtx.getString(R.string.wrong_format)) bookSourceName = jsonItem.readString("bookSourceName") ?: "" bookSourceGroup = jsonItem.readString("bookSourceGroup") loginUrl = jsonItem.readString("loginUrl") diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 927902142..7c44c70bb 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -372,7 +372,6 @@ Simulación Desplazado Ninguno - La fuente de este libro utiliza funciones avanzadas, para desbloquear diríjase a Donaciones y toque el código de búsqueda del sobre rojo de Alipay para recibir ese sobre. Actualiza el último capítulo después del cambio de fuente en segundo plano si está habilitado, la actualización comenzará 1 minuto después de que se abra la aplicación Ocultar automáticamente la barra de herramientas diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index a54be5b30..6fca90a60 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -376,7 +376,6 @@ Simulation Scroll None - This book source uses advanced features, please go to the Donations and tap the Alipay red envelope search code to receive the red envelope,then you can use it. Update the latest chapter after changed origin in the background if enabled,the update will start 1 minute later when the software is run Auto hide ToolBar diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 1b0012e37..69bcc61bc 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -374,7 +374,6 @@ Simulação Deslizar Nenhum - Esta fonte de livro usa recursos avançados, por favor vá até Doações e toque no código de busca do envelope vermelho Alipay para receber o envelope vermelho, depois você pode usá-lo. Atualizar o último capítulo após a alteração de origem em segundo plano se ativado, a atualização será iniciada 1 minuto depois o App for aberto Auto esconder a barra de ferramentas diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 8f31bac58..ba49aa66d 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -373,7 +373,6 @@ 仿真 滾動 無動畫 - 此書源使用了高級功能,請到捐贈裏點擊支付寶紅包搜索碼領取紅包開啟。 後台更新換源最新章節 開啟則會在軟件打開 1 分鐘後開始更新 書架 ToolBar 自動隱藏 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c90d71c01..8a453ec29 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -375,7 +375,6 @@ 模擬 滾動 無動畫 - 此書源使用了進階功能,請到捐贈裡點擊支付寶紅包搜尋碼領取紅包開啟。 後台更新換源最新章節 開啟則會在軟體打開1分鐘後開始更新 書架ToolBar自動隱藏 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index f7b42db3f..d8b424f59 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -375,7 +375,6 @@ 仿真 滚动 无动画 - 此书源使用了高级功能,请到捐赠里点击支付宝红包搜索码领取红包开启。 后台更新换源最新章节 开启则会在软件打开 1 分钟后开始更新 书架工具栏自动隐藏 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa1f00d8c..db99d95a6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -376,7 +376,6 @@ Simulation Scroll None - This book source uses advanced features, please go to the Donations and tap the Alipay red envelope search code to receive the red envelope,then you can use it. Update the latest chapter after changed origin in the background if enabled,the update will start 1 minute later when the software is run Auto hide ToolBar