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 模板数据"
],
"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)_",

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.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<SevenZArchiveEntry> allEntries = sevenZFile.getEntries()
List<SevenZArchiveEntry> 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)