mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-03-25 14:59:44 +08:00
chore:qdebug输出显示下载进度
This commit is contained in:
@@ -35,16 +35,31 @@ void DownloadManager::startDownload(const QString &appName)
|
|||||||
|
|
||||||
void DownloadManager::onProcessReadyRead()
|
void DownloadManager::onProcessReadyRead()
|
||||||
{
|
{
|
||||||
QByteArray output = m_process->readAllStandardOutput();
|
static QString buffer; // 缓存未处理的输出
|
||||||
QString outputStr = QString::fromUtf8(output);
|
buffer += QString::fromUtf8(m_process->readAllStandardOutput());
|
||||||
|
|
||||||
QRegularExpressionMatch match = m_progressRegex.match(outputStr);
|
const QStringList lines = buffer.split(QRegularExpression("[\r\n]"), Qt::SkipEmptyParts);
|
||||||
if (match.hasMatch()) {
|
|
||||||
int progress = match.captured(1).toInt();
|
for (const QString &line : lines) {
|
||||||
emit downloadProgress(progress);
|
QRegularExpressionMatch match = m_progressRegex.match(line);
|
||||||
|
if (match.hasMatch()) {
|
||||||
|
int progress = match.captured(1).toInt();
|
||||||
|
qDebug() << "匹配进度:" << progress << "% => " << line;
|
||||||
|
emit downloadProgress(progress);
|
||||||
|
} else {
|
||||||
|
// qDebug() << "未匹配行:" << line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果最后不是完整的一行,保留最后一部分
|
||||||
|
if (!buffer.endsWith('\n') && !buffer.endsWith('\r')) {
|
||||||
|
buffer = lines.last();
|
||||||
|
} else {
|
||||||
|
buffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DownloadManager::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
void DownloadManager::onProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
|
||||||
{
|
{
|
||||||
bool success = (exitStatus == QProcess::NormalExit && exitCode == 0);
|
bool success = (exitStatus == QProcess::NormalExit && exitCode == 0);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
class DownloadManager : public QObject
|
class DownloadManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
Reference in New Issue
Block a user