From f840b148aab2e81b1f17f6831b5d7c4a63e8af7c Mon Sep 17 00:00:00 2001 From: Celeter Date: Wed, 23 Sep 2020 11:45:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=BB=E5=8F=96=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E6=96=87=E4=BB=B6=E5=86=85=E7=9A=84=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=B9=B6=E5=88=A0=E9=99=A4=E5=8E=8B=E7=BC=A9?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/JsExtensions.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index 46bb029a1..4d54afab4 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -6,9 +6,11 @@ import io.legado.app.constant.AppConst.dateFormat import io.legado.app.help.http.SSLHelper import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.utils.* +import io.legado.app.utils.EncodingDetect import org.jsoup.Connection import org.jsoup.Jsoup import java.net.URLEncoder +import java.nio.charset.Charset import java.util.* @Keep @@ -40,6 +42,34 @@ interface JsExtensions { } } + /** + * js实现读取压缩文件内的文件内容,并删除压缩文件 + */ + fun getTxtInZip(zipPath: String): String { + // 解压路径 + val unzipPath = FileUtils.getPath( + FileUtils.createFolderIfNotExist(FileUtils.getCachePath()), + FileUtils.getNameExcludeExtension(zipPath) + ) + FileUtils.deleteFile(unzipPath) + val unzipFolder = FileUtils.createFolderIfNotExist(unzipPath) + val zipFile = FileUtils.createFileIfNotExist(zipPath) + ZipUtils.unzipFile(zipFile, unzipFolder) + val content = StringBuilder() + unzipFolder.listFiles().let { + if (it != null) { + for (f in it) { + val charsetName = EncodingDetect.getEncode(f) + content.append(String(f.readBytes(), Charset.forName(charsetName))).append("\n") + } + content.deleteCharAt(content.length - 1) + } + } + FileUtils.deleteFile(zipPath) + FileUtils.deleteFile(unzipPath) + return content.toString() + } + /** * js实现重定向拦截,不能删 */