From 62c1199965c195aed4e57b23c8c8508d5d7243f8 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Fri, 2 Dec 2022 18:32:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=89=88=E6=9C=AC=E5=8F=B7=E6=9C=80=E9=AB=98?= =?UTF-8?q?=E7=9A=84=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/fwupgrade/mainwindow.cpp | 13 ++++++++++++- app/scanner/mainwindow.cpp | 23 +++++++++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/fwupgrade/mainwindow.cpp b/app/fwupgrade/mainwindow.cpp index d267bc33..48889889 100644 --- a/app/fwupgrade/mainwindow.cpp +++ b/app/fwupgrade/mainwindow.cpp @@ -10,6 +10,7 @@ #include "dialog_updateprogress.h" #include "base/HGBase.h" #include "HGString.h" +#include #define PASSWORD_KEY 4 @@ -293,6 +294,11 @@ void MainWindow::on_comboDevList_currentIndexChanged(int index) } } +static bool Greater(const VersionInfo &info1, const VersionInfo &info2) +{ + return info1.version > info2.version; +} + void MainWindow::on_btnGetVersionList_clicked() { m_vVersion.clear(); @@ -315,13 +321,18 @@ void MainWindow::on_btnGetVersionList_clicked() inf.url = versionInfo[i].url; inf.md5 = versionInfo[i].md5; m_vVersion.push_back(inf); - ui->comboVersionList->addItem(versionInfo[i].version); } } } HGVersion_ReleaseVersionList(versionInfo, versionCount); + std::sort(m_vVersion.begin(), m_vVersion.end(), Greater); + for (int i = 0; i < m_vVersion.size(); ++i) + { + ui->comboVersionList->addItem(m_vVersion[i].version.c_str()); + } + if (m_vVersion.empty()) { QMessageBox msg(QMessageBox::Information, tr("tips"), tr("no version available"), QMessageBox::Yes, this); diff --git a/app/scanner/mainwindow.cpp b/app/scanner/mainwindow.cpp index c0d6efb3..4314fe18 100644 --- a/app/scanner/mainwindow.cpp +++ b/app/scanner/mainwindow.cpp @@ -2604,16 +2604,27 @@ void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer para p->m_versionDll->GetDriverVersionList(devType.toStdString().c_str(), &versionInfo, &versionCount); if (versionCount > 0) { - if ((std::string)(versionInfo[0].version) > p->m_devVersionNum.toStdString()) // 比较版本号 + HGUInt verionIndex = 0; + QString currVersion = versionInfo[0].version; + for (HGUInt i = 1; i < versionCount; ++i) + { + if (QString(versionInfo[i].version) > currVersion) + { + verionIndex = i; + currVersion = QString(versionInfo[i].version); + } + } + + if ((std::string)(versionInfo[verionIndex].version) > p->m_devVersionNum.toStdString()) // 比较版本号 { HGChar suffix[64]; - HGBase_GetFileSuffix(versionInfo[0].url, suffix, 64); + HGBase_GetFileSuffix(versionInfo[verionIndex].url, suffix, 64); HGChar savePath[512]; HGBase_GetConfigPath(savePath, 512); HGBase_CreateDir(savePath); HGChar fileName[128]; - sprintf(fileName, "%s.%s", versionInfo[0].version, suffix); + sprintf(fileName, "%s.%s", versionInfo[verionIndex].version, suffix); strcat(savePath, fileName); QFile saveFile(savePath); @@ -2623,9 +2634,9 @@ void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer para QString md5_2 = QCryptographicHash::hash(fileMsg, QCryptographicHash::Md5).toHex(); QFile f(savePath); - if (!f.exists() || versionInfo[0].md5 != md5_2) + if (!f.exists() || versionInfo[verionIndex].md5 != md5_2) { - HGResult ret = p->m_versionDll->HttpDownload(versionInfo[0].url, savePath, NULL, NULL); + HGResult ret = p->m_versionDll->HttpDownload(versionInfo[verionIndex].url, savePath, NULL, NULL); if (HGBASE_ERR_OK == ret) { QFile saveFile(savePath); @@ -2634,7 +2645,7 @@ void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer para saveFile.close(); QString md5_2 = QCryptographicHash::hash(fileMsg, QCryptographicHash::Md5).toHex(); - if (versionInfo[0].md5 == md5_2) + if (versionInfo[verionIndex].md5 == md5_2) { p->m_vFwUpgradeAndDevLock[index].m_upgradeFilePath = savePath; p->m_vFwUpgradeAndDevLock[index].m_handleFlag |= FwUpgradeAndDevLock::FwUpgrade;