6.7.0 - Alpha4 - Gradle 构建脚本提升 7z 格式文件的解压效率

This commit is contained in:
SuperMonster003
2025-09-10 11:27:27 +08:00
parent 6b8c6b2339
commit 627224e26b
2 changed files with 36 additions and 46 deletions

View File

@@ -10,6 +10,7 @@
"JS 脚本工具 (run-scrapers.mjs) 用于自动更新 Gradle 构建脚本锚点数据/README 通用数据/README 模板数据" "JS 脚本工具 (run-scrapers.mjs) 用于自动更新 Gradle 构建脚本锚点数据/README 通用数据/README 模板数据"
], ],
"fix": [ "fix": [
"isJavaClass/isJavaPackage 等全局方法无效的问题",
"使用 XML 语法将 JavaScript 表达式作为属性值时, this 对象可能出现指向错误的问题", "使用 XML 语法将 JavaScript 表达式作为属性值时, this 对象可能出现指向错误的问题",
"调用 images.requestScreenCapture 时用户取消授权可能导致应用崩溃的问题", "调用 images.requestScreenCapture 时用户取消授权可能导致应用崩溃的问题",
"images 部分相关方法出现异常时 oneShot 标记功能失效的问题 _[`issue #372`](http://issues.autojs6.com/372)_", "images 部分相关方法出现异常时 oneShot 标记功能失效的问题 _[`issue #372`](http://issues.autojs6.com/372)_",
@@ -58,7 +59,6 @@
"util.dpToPx/spToPx/pxToDp/pxToSp 方法, 用于像素单位转换" "util.dpToPx/spToPx/pxToDp/pxToSp 方法, 用于像素单位转换"
], ],
"fix": [ "fix": [
"isJavaClass/isJavaPackage 等全局方法无效的问题",
"屏幕旋转至横向时子标题可能显示不完整的问题", "屏幕旋转至横向时子标题可能显示不完整的问题",
"屏幕旋转至横向时部分页面内容被侧边导航栏遮挡的问题", "屏幕旋转至横向时部分页面内容被侧边导航栏遮挡的问题",
"Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_", "Android 15 部分页面状态栏背景着色区域不完整的问题 _[`issue #398`](http://issues.autojs6.com/398)_",

View File

@@ -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.ByteBuffer
import java.nio.channels.FileChannel import java.nio.channels.FileChannel
import java.security.MessageDigest import java.security.MessageDigest
import java.security.NoSuchAlgorithmException import java.security.NoSuchAlgorithmException
import java.util.zip.ZipFile import java.util.zip.ZipFile
import org.apache.commons.compress.archivers.sevenz.SevenZFile
ext.Utils = Utils ext.Utils = Utils
@@ -282,9 +284,7 @@ class Utils {
def title = "Extract the archive file for \"${project.ext["projectName"]}\" Gradle project" def title = "Extract the archive file for \"${project.ext["projectName"]}\" Gradle project"
def srcInfo = "Source: $cacheFile" def srcInfo = "Source: $cacheFile"
def destInfo = "Destination: $destFile" def destInfo = "Destination: $destFile"
def hintInfo = cacheFileExtensionName == "7z" ? [ def hintInfo = []
"Extracting \"7z\" archive file may take some time to complete.",
] : []
def maxLength = [ def maxLength = [
[title, srcInfo, destInfo].max { it.length() }, [title, srcInfo, destInfo].max { it.length() },
@@ -530,58 +530,48 @@ class Utils {
} }
private void handleSevenZip() { 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() String sourceDirPath = new File(sourceDir).path
def entry
def entries = []
def totalExtractedSize = 0L
def sourceDirPath = new File(sourceDir).path
if (sourceDirPath.startsWith(File.separator)) sourceDirPath = sourceDirPath.substring(1) if (sourceDirPath.startsWith(File.separator)) sourceDirPath = sourceDirPath.substring(1)
while ((entry = sevenZFileForTotalSize.getNextEntry()) != null) { SevenZFile sevenZFile = new SevenZFile.Builder().setFile(cacheFile).get()
def entryName = new File(entry.name).path List<SevenZArchiveEntry> allEntries = sevenZFile.getEntries()
if (entryName.startsWith(sourceDirPath)) {
entries.add(entry) List<SevenZArchiveEntry> targetEntries = allEntries.findAll { it.name.startsWith(sourceDirPath) }
totalExtractedSize += entry.size
} 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 int processedEntries = 0
byte[] buffer = new byte[64 * 1024]
while ((entry = sevenZFile.getNextEntry()) != null) { for (SevenZArchiveEntry entry : targetEntries) {
def entryName = new File(entry.name).path File outFile = project.file(new File(tempOutFile, new File(entry.name).path.substring(sourceDirPath.length())))
if (entryName.startsWith(sourceDirPath)) { if (entry.isDirectory()) {
File outFile = project.file(new File(tempOutFile, entryName.substring(sourceDirPath.length()))) outFile.mkdirs()
if (entry.isDirectory()) { } else {
outFile.mkdirs() outFile.parentFile.mkdirs()
} else { try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFile))) {
outFile.parentFile.mkdirs() sevenZFile.getInputStream(entry).withCloseable { entryInputStream ->
outFile.withOutputStream { outputStream -> int bytesRead
sevenZFile.getInputStream(entry).withCloseable { entryInputStream -> while ((bytesRead = entryInputStream.read(buffer)) != -1) {
byte[] buffer = new byte[8192] bos.write(buffer, 0, bytesRead)
int bytesRead
while ((bytesRead = entryInputStream.read(buffer)) != -1) {
outputStream.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) String formattedUncompressedSize = formatFileSize(totalExtractedSize)