add:增加下载pathc的功能

This commit is contained in:
2025-07-30 16:39:29 +08:00
parent e7aad6b267
commit 7eeae3c4cd
3 changed files with 87 additions and 49 deletions
+57 -47
View File
@@ -28,6 +28,7 @@ UpdaterDialog::UpdaterDialog(QWidget *parent) :
ui->setupUi(this);
this->setWindowTitle("Updater");
ui->btn_update->setEnabled(0);
ui->btn_update_patch->setEnabled(0);
m_startTime = 0;
@@ -44,6 +45,50 @@ UpdaterDialog::UpdaterDialog(QWidget *parent) :
// ui->show->appendPlainText(APPVERSION);
// ui->show->appendPlainText(APPDATE);
// ui->show->appendPlainText(MODIFYCNT);
m_pDownloader = new Downloader(this);
connect(m_pDownloader, &Downloader::doShowInfo, this, [&](const QString & s)
{
showStatus(s);
});
connect(m_pDownloader, &Downloader::onError, this, [&](QNetworkReply::NetworkError e)
{
QMetaEnum metaEnum = QMetaEnum::fromType<QNetworkReply::NetworkError>();
QString str = QString(metaEnum.valueToKey(e));
ui->show->appendPlainText(str);
});
connect(m_pDownloader, &Downloader::doFinished, this, [&]()
{
uint _end_time = QDateTime::currentSecsSinceEpoch();
uint _total_time = _end_time - m_startTime;
ui->label_3->setText("total time: " + QString::number(_total_time, 'g', 3) +
"s average speed: " + QString::number((m_totalSize / 1024.0 / _total_time), 'g', 3) + "kb/s");
ui->show->appendPlainText("download finished");
onDownloadFinished();
});
connect(m_pDownloader, &Downloader::doProgress, this, [&](quint64 received, quint64 total)
{
m_totalSize = total;
if (total > 0)
{
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(100);
ui->progressBar->setValue((received * 100) / total);
calculateSizes(received, total);
calculateTimeRemaining(received, total);
}
else
{
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(0);
ui->progressBar->setValue(-1);
ui->show->appendPlainText(tr("Downloading Updates") + "...");
}
});
}
UpdaterDialog::~UpdaterDialog()
@@ -67,6 +112,7 @@ void UpdaterDialog::on_btn_check_clicked()
}
ui->show->clear();
ui->btn_update->setEnabled(0);
ui->btn_update_patch->setEnabled(0);
//version
m_version = ui->versionInput->text();
@@ -201,6 +247,7 @@ void UpdaterDialog::onCheckReply(QNetworkReply *reply)
+ tr("\nclick cancel button to quit"));
}
ui->btn_update->setEnabled(1);
ui->btn_update_patch->setEnabled(1);
}
void UpdaterDialog::calculateSizes(qint64 received, qint64 total)
@@ -291,53 +338,6 @@ void UpdaterDialog::calculateTimeRemaining(qint64 received, qint64 total)
void UpdaterDialog::on_btn_update_clicked()
{
if(!m_pDownloader)
{
m_pDownloader = new Downloader(this);
connect(m_pDownloader, &Downloader::doShowInfo, this, [&](const QString & s)
{
showStatus(s);
});
connect(m_pDownloader, &Downloader::onError, this, [&](QNetworkReply::NetworkError e)
{
QMetaEnum metaEnum = QMetaEnum::fromType<QNetworkReply::NetworkError>();
QString str = QString(metaEnum.valueToKey(e));
ui->show->appendPlainText(str);
});
connect(m_pDownloader, &Downloader::doFinished, this, [&]()
{
uint _end_time = QDateTime::currentSecsSinceEpoch();
uint _total_time = _end_time - m_startTime;
ui->label_3->setText("total time: " + QString::number(_total_time, 'g', 3) +
"s average speed: " + QString::number((m_totalSize / 1024.0 / _total_time), 'g', 3) + "kb/s");
ui->show->appendPlainText("download finished");
onDownloadFinished();
});
connect(m_pDownloader, &Downloader::doProgress, this, [&](quint64 received, quint64 total)
{
m_totalSize = total;
if (total > 0)
{
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(100);
ui->progressBar->setValue((received * 100) / total);
calculateSizes(received, total);
calculateTimeRemaining(received, total);
}
else
{
ui->progressBar->setMinimum(0);
ui->progressBar->setMaximum(0);
ui->progressBar->setValue(-1);
ui->show->appendPlainText(tr("Downloading Updates") + "...");
}
});
}
m_pDownloader->setFileName(m_fileName);
m_startTime = QDateTime::currentDateTime().toSecsSinceEpoch();
@@ -391,3 +391,13 @@ void UpdaterDialog::onDownloadFinished()
QApplication::quit();
}
}
void UpdaterDialog::on_btn_update_patch_clicked()
{
m_pDownloader->setFileName(m_fileName);
m_startTime = QDateTime::currentDateTime().toSecsSinceEpoch();
m_bDownloadFullExe = false;
QString _url = m_patchUrl;
m_pDownloader->startDownload(_url);
}