chore:显示下载百分比

This commit is contained in:
2025-06-11 23:31:10 +08:00
parent f071fcb00d
commit e416ffdbff

View File

@@ -25,16 +25,20 @@ void DownloadManager::startDownload(const QString &url, const QString &outputPat
void DownloadManager::onAria2Progress() void DownloadManager::onAria2Progress()
{ {
QString output = m_aria2Process.readAllStandardOutput(); QString output = m_aria2Process.readAllStandardOutput();
QRegularExpression regex(R"(Download Progress: (\d+)%.*)"); QRegularExpression regex(R"(\((\d+)%\))");
QRegularExpressionMatch match = regex.match(output); QRegularExpressionMatchIterator i = regex.globalMatch(output);
while (i.hasNext()) {
QRegularExpressionMatch match = i.next();
if (match.hasMatch()) { if (match.hasMatch()) {
int progress = match.captured(1).toInt(); int progress = match.captured(1).toInt();
emit downloadProgress(progress); // 发送进度信号 emit downloadProgress(progress); // 发送进度信号
qDebug() << "下载进度:" << progress << "%"; qDebug() << "下载进度:" << progress << "%";
} }
}
} }
void DownloadManager::onAria2Finished(int exitCode, QProcess::ExitStatus exitStatus) void DownloadManager::onAria2Finished(int exitCode, QProcess::ExitStatus exitStatus)
{ {
if (exitCode == 0 && exitStatus == QProcess::NormalExit) { if (exitCode == 0 && exitStatus == QProcess::NormalExit) {