From 627224e26b9c6c9a5aa315cb492b69ebd2a3d235 Mon Sep 17 00:00:00 2001 From: SuperMonster003 Date: Wed, 10 Sep 2025 11:27:27 +0800 Subject: [PATCH] =?UTF-8?q?6.7.0=20-=20Alpha4=20-=20Gradle=20=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E8=84=9A=E6=9C=AC=E6=8F=90=E5=8D=87=207z=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E6=96=87=E4=BB=B6=E7=9A=84=E8=A7=A3=E5=8E=8B=E6=95=88?= =?UTF-8?q?=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changelog/lang_zh-Hans.json | 2 +- libs/utils.build.gradle | 80 ++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 46 deletions(-) diff --git a/.changelog/lang_zh-Hans.json b/.changelog/lang_zh-Hans.json index 33aed6cc..cb5eb947 100644 --- a/.changelog/lang_zh-Hans.json +++ b/.changelog/lang_zh-Hans.json @@ -10,6 +10,7 @@ "JS 脚本工具 (run-scrapers.mjs) 用于自动更新 Gradle 构建脚本锚点数据/README 通用数据/README 模板数据" ], "fix": [ + "isJavaClass/isJavaPackage 等全局方法无效的问题", "使用 XML 语法将 JavaScript 表达式作为属性值时, this 对象可能出现指向错误的问题", "调用 images.requestScreenCapture 时用户取消授权可能导致应用崩溃的问题", "images 部分相关方法出现异常时 oneShot 标记功能失效的问题 _[`issue #372`](http://issues.autojs6.com/372)_", @@ -58,7 +59,6 @@ "util.dpToPx/spToPx/pxToDp/pxToSp 方法, 用于像素单位转换" ], "fix": [ - "isJavaClass/isJavaPackage 等全局方法无效的问题", "屏幕旋转至横向时子标题可能显示不完整的问题", "屏幕旋转至横向时部分页面内容被侧边导航栏遮挡的问题", "Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_", diff --git a/libs/utils.build.gradle b/libs/utils.build.gradle index 6630d681..da19c1c7 100644 --- a/libs/utils.build.gradle +++ b/libs/utils.build.gradle @@ -1,9 +1,11 @@ +import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry +import org.apache.commons.compress.archivers.sevenz.SevenZFile + import java.nio.ByteBuffer import java.nio.channels.FileChannel import java.security.MessageDigest import java.security.NoSuchAlgorithmException import java.util.zip.ZipFile -import org.apache.commons.compress.archivers.sevenz.SevenZFile ext.Utils = Utils @@ -282,9 +284,7 @@ class Utils { def title = "Extract the archive file for \"${project.ext["projectName"]}\" Gradle project" def srcInfo = "Source: $cacheFile" def destInfo = "Destination: $destFile" - def hintInfo = cacheFileExtensionName == "7z" ? [ - "Extracting \"7z\" archive file may take some time to complete.", - ] : [] + def hintInfo = [] def maxLength = [ [title, srcInfo, destInfo].max { it.length() }, @@ -530,58 +530,48 @@ class Utils { } private void handleSevenZip() { - def shouldPrintProgress = project.ext["platform"]["shouldPrintProgress"] == true + boolean shouldPrintProgress = project.ext["platform"]["shouldPrintProgress"] == true - def sevenZFileForTotalSize = new SevenZFile.Builder().setFile(cacheFile).get() - def entry - def entries = [] - def totalExtractedSize = 0L - - def sourceDirPath = new File(sourceDir).path + String sourceDirPath = new File(sourceDir).path if (sourceDirPath.startsWith(File.separator)) sourceDirPath = sourceDirPath.substring(1) - while ((entry = sevenZFileForTotalSize.getNextEntry()) != null) { - def entryName = new File(entry.name).path - if (entryName.startsWith(sourceDirPath)) { - entries.add(entry) - totalExtractedSize += entry.size - } + SevenZFile sevenZFile = new SevenZFile.Builder().setFile(cacheFile).get() + List allEntries = sevenZFile.getEntries() + + List targetEntries = allEntries.findAll { it.name.startsWith(sourceDirPath) } + + int entriesCount = targetEntries.size() + long totalExtractedSize = 0L + for (SevenZArchiveEntry entry : targetEntries) { + totalExtractedSize += entry.size } - sevenZFileForTotalSize.close() - - def sevenZFile = new SevenZFile.Builder().setFile(cacheFile).get() - - int totalEntries = entries.size() int processedEntries = 0 + byte[] buffer = new byte[64 * 1024] - while ((entry = sevenZFile.getNextEntry()) != null) { - def entryName = new File(entry.name).path - if (entryName.startsWith(sourceDirPath)) { - File outFile = project.file(new File(tempOutFile, entryName.substring(sourceDirPath.length()))) - if (entry.isDirectory()) { - outFile.mkdirs() - } else { - outFile.parentFile.mkdirs() - outFile.withOutputStream { outputStream -> - sevenZFile.getInputStream(entry).withCloseable { entryInputStream -> - byte[] buffer = new byte[8192] - int bytesRead - while ((bytesRead = entryInputStream.read(buffer)) != -1) { - outputStream.write(buffer, 0, bytesRead) - } + for (SevenZArchiveEntry entry : targetEntries) { + File outFile = project.file(new File(tempOutFile, new File(entry.name).path.substring(sourceDirPath.length()))) + if (entry.isDirectory()) { + outFile.mkdirs() + } else { + outFile.parentFile.mkdirs() + try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile))) { + sevenZFile.getInputStream(entry).withCloseable { entryInputStream -> + int bytesRead + while ((bytesRead = entryInputStream.read(buffer)) != -1) { + bos.write(buffer, 0, bytesRead) } } } - - if (shouldPrintProgress) { - double progress = (processedEntries * 100.0 / totalEntries) - String progressBar = generateProgressBar(progress) - print String.format("\rExtracting... [ %s ] %.2f%%", progressBar, progress) - System.out.flush() - } - processedEntries++ } + + if (shouldPrintProgress) { + double progress = (processedEntries * 100.0 / entriesCount) + String progressBar = generateProgressBar(progress) + print String.format("\rExtracting... [ %s ] %.2f%%", progressBar, progress) + System.out.flush() + } + processedEntries++ } String formattedUncompressedSize = formatFileSize(totalExtractedSize)