mirror of
https://gitee.com/spark-store-project/spark-store
synced 2025-12-20 03:01:36 +08:00
chore:更新代码
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
#include "downloadmanager.h"
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QRegularExpression>
|
||||
#include <QFileInfo> // 添加 QFileInfo 头文件
|
||||
#include <QDebug>
|
||||
|
||||
DownloadManager::DownloadManager(QObject *parent) : QObject(parent) {}
|
||||
|
||||
@@ -20,12 +19,12 @@ void DownloadManager::startDownload(const QString &packageName, const QString &u
|
||||
QProcess *process = new QProcess(this);
|
||||
m_processes.insert(packageName, process);
|
||||
|
||||
// ✅ 改为按行读取(逐行处理)
|
||||
connect(process, &QProcess::readyReadStandardOutput, [this, process, packageName]() {
|
||||
QString output = process->readAllStandardOutput();
|
||||
while (process->canReadLine()) {
|
||||
QString line = process->readLine().trimmed();
|
||||
QRegularExpression regex(R"(\((\d+)%\))");
|
||||
QRegularExpressionMatchIterator i = regex.globalMatch(output);
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
QRegularExpressionMatch match = regex.match(line);
|
||||
if (match.hasMatch()) {
|
||||
int progress = match.captured(1).toInt();
|
||||
emit downloadProgress(packageName, progress);
|
||||
@@ -34,6 +33,7 @@ void DownloadManager::startDownload(const QString &packageName, const QString &u
|
||||
}
|
||||
});
|
||||
|
||||
// 下载完成
|
||||
connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||
[this, packageName](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||
bool success = (exitCode == 0 && exitStatus == QProcess::NormalExit);
|
||||
|
||||
@@ -2,25 +2,24 @@
|
||||
#define DOWNLOADMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QProcess>
|
||||
#include <QMap>
|
||||
|
||||
class DownloadManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DownloadManager(QObject *parent = nullptr);
|
||||
void startDownload(const QString &packageName, const QString &url, const QString &outputPath); // 修改参数列表
|
||||
void cancelDownload(const QString &packageName); // 移动到public区域
|
||||
void startDownload(const QString &packageName, const QString &url, const QString &outputPath);
|
||||
void cancelDownload(const QString &packageName);
|
||||
|
||||
signals:
|
||||
void downloadProgress(const QString &packageName, int progress);
|
||||
void downloadFinished(const QString &packageName, bool success);
|
||||
|
||||
private:
|
||||
QHash<QString, QProcess*> m_processes; // 移除旧的m_aria2Process
|
||||
// 移除旧的onAria2Progress和onAria2Finished声明
|
||||
QMap<QString, QProcess*> m_processes;
|
||||
};
|
||||
|
||||
#endif // DOWNLOADMANAGER_H
|
||||
|
||||
Reference in New Issue
Block a user