From 2e26ab21f461339fb1ea6a294b6386d9dc802062 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Fri, 15 Apr 2022 08:16:22 +0800 Subject: [PATCH] perf:delete file when image size is -1 * -1 --- .../app/ui/book/read/page/provider/ImageProvider.kt | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt index e11dbdccc..8696cf9d5 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ImageProvider.kt @@ -14,7 +14,6 @@ import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.localBook.EpubFile import io.legado.app.utils.BitmapUtils import io.legado.app.utils.FileUtils -import io.legado.app.utils.isXml import splitties.init.appCtx import java.io.File import java.io.FileOutputStream @@ -91,6 +90,10 @@ object ImageProvider { op.inJustDecodeBounds = true BitmapFactory.decodeFile(file.absolutePath, op) if (op.outWidth < 1 && op.outHeight < 1) { + Coroutine.async { + putDebug("ImageProvider: delete file due to image size ${op.outHeight}*${op.outWidth}. path: ${file.absolutePath}") + file.delete() + } return Size(errorBitmap.width, errorBitmap.height) } return Size(op.outWidth, op.outHeight) @@ -114,14 +117,6 @@ object ImageProvider { ?: throw NoStackTraceException("解析图片失败") bitmapLruCache.put(src, bitmap) bitmap - }.onFailure { - Coroutine.async { - putDebug("ImageProvider: decode bitmap failed. path: ${vFile.absolutePath}\n$it", it) - if (FileUtils.readText(vFile.absolutePath).isXml()) { - putDebug("ImageProvider: delete xml file. path: ${vFile.absolutePath}") - vFile.delete() - } - } }.getOrDefault(errorBitmap) }