Browse Source

add:增加下载pathc的功能

master
TianZD 2 days ago
parent
commit
7eeae3c4cd
  1. 104
      Src/updaterdialog.cpp
  2. 2
      Src/updaterdialog.h
  3. 30
      Src/updaterdialog.ui

104
Src/updaterdialog.cpp

@ -28,6 +28,7 @@ UpdaterDialog::UpdaterDialog(QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
this->setWindowTitle("Updater"); this->setWindowTitle("Updater");
ui->btn_update->setEnabled(0); ui->btn_update->setEnabled(0);
ui->btn_update_patch->setEnabled(0);
m_startTime = 0; m_startTime = 0;
@ -44,6 +45,50 @@ UpdaterDialog::UpdaterDialog(QWidget *parent) :
// ui->show->appendPlainText(APPVERSION); // ui->show->appendPlainText(APPVERSION);
// ui->show->appendPlainText(APPDATE); // ui->show->appendPlainText(APPDATE);
// ui->show->appendPlainText(MODIFYCNT); // 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() UpdaterDialog::~UpdaterDialog()
@ -67,6 +112,7 @@ void UpdaterDialog::on_btn_check_clicked()
} }
ui->show->clear(); ui->show->clear();
ui->btn_update->setEnabled(0); ui->btn_update->setEnabled(0);
ui->btn_update_patch->setEnabled(0);
//version //version
m_version = ui->versionInput->text(); m_version = ui->versionInput->text();
@ -201,6 +247,7 @@ void UpdaterDialog::onCheckReply(QNetworkReply *reply)
+ tr("\nclick cancel button to quit")); + tr("\nclick cancel button to quit"));
} }
ui->btn_update->setEnabled(1); ui->btn_update->setEnabled(1);
ui->btn_update_patch->setEnabled(1);
} }
void UpdaterDialog::calculateSizes(qint64 received, qint64 total) void UpdaterDialog::calculateSizes(qint64 received, qint64 total)
@ -291,53 +338,6 @@ void UpdaterDialog::calculateTimeRemaining(qint64 received, qint64 total)
void UpdaterDialog::on_btn_update_clicked() 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_pDownloader->setFileName(m_fileName);
m_startTime = QDateTime::currentDateTime().toSecsSinceEpoch(); m_startTime = QDateTime::currentDateTime().toSecsSinceEpoch();
@ -391,3 +391,13 @@ void UpdaterDialog::onDownloadFinished()
QApplication::quit(); 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
Src/updaterdialog.h

@ -42,6 +42,8 @@ private slots:
void onDownloadFinished(); void onDownloadFinished();
void on_btn_update_patch_clicked();
private: private:
Ui::UpdaterDialog *ui; Ui::UpdaterDialog *ui;

30
Src/updaterdialog.ui

@ -168,7 +168,13 @@
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QPlainTextEdit" name="show"/> <widget class="QPlainTextEdit" name="show">
<property name="font">
<font>
<pointsize>14</pointsize>
</font>
</property>
</widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
@ -247,6 +253,26 @@
</property> </property>
</widget> </widget>
</item> </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> <item>
<widget class="QPushButton" name="btn_update"> <widget class="QPushButton" name="btn_update">
<property name="sizePolicy"> <property name="sizePolicy">
@ -263,7 +289,7 @@
</font> </font>
</property> </property>
<property name="text"> <property name="text">
<string>update</string> <string>update-full</string>
</property> </property>
</widget> </widget>
</item> </item>

Loading…
Cancel
Save