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);
}
+2
View File
@@ -42,6 +42,8 @@ private slots:
void onDownloadFinished();
void on_btn_update_patch_clicked();
private:
Ui::UpdaterDialog *ui;
+28 -2
View File
@@ -168,7 +168,13 @@
</layout>
</item>
<item>
<widget class="QPlainTextEdit" name="show"/>
<widget class="QPlainTextEdit" name="show">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
@@ -247,6 +253,26 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_update_patch">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Times New Roman</family>
<pointsize>12</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>update-patch</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_update">
<property name="sizePolicy">
@@ -263,7 +289,7 @@
</font>
</property>
<property name="text">
<string>update</string>
<string>update-full</string>
</property>
</widget>
</item>