diff --git a/Src/updaterdialog.cpp b/Src/updaterdialog.cpp index e750e1b..444ff0e 100644 --- a/Src/updaterdialog.cpp +++ b/Src/updaterdialog.cpp @@ -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(); + 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(); - 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); +} + diff --git a/Src/updaterdialog.h b/Src/updaterdialog.h index 69ce751..99562f3 100644 --- a/Src/updaterdialog.h +++ b/Src/updaterdialog.h @@ -42,6 +42,8 @@ private slots: void onDownloadFinished(); + void on_btn_update_patch_clicked(); + private: Ui::UpdaterDialog *ui; diff --git a/Src/updaterdialog.ui b/Src/updaterdialog.ui index 120e178..d5c088f 100644 --- a/Src/updaterdialog.ui +++ b/Src/updaterdialog.ui @@ -168,7 +168,13 @@ - + + + + 14 + + + @@ -247,6 +253,26 @@ + + + + + 0 + 0 + + + + + Times New Roman + 12 + true + + + + update-patch + + + @@ -263,7 +289,7 @@ - update + update-full