升级时自动选择版本号最高的版本

This commit is contained in:
luoliangyi 2022-12-02 18:32:48 +08:00
parent 5bbdc93c5f
commit 62c1199965
2 changed files with 29 additions and 7 deletions

View File

@ -10,6 +10,7 @@
#include "dialog_updateprogress.h" #include "dialog_updateprogress.h"
#include "base/HGBase.h" #include "base/HGBase.h"
#include "HGString.h" #include "HGString.h"
#include <algorithm>
#define PASSWORD_KEY 4 #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() void MainWindow::on_btnGetVersionList_clicked()
{ {
m_vVersion.clear(); m_vVersion.clear();
@ -315,13 +321,18 @@ void MainWindow::on_btnGetVersionList_clicked()
inf.url = versionInfo[i].url; inf.url = versionInfo[i].url;
inf.md5 = versionInfo[i].md5; inf.md5 = versionInfo[i].md5;
m_vVersion.push_back(inf); m_vVersion.push_back(inf);
ui->comboVersionList->addItem(versionInfo[i].version);
} }
} }
} }
HGVersion_ReleaseVersionList(versionInfo, versionCount); 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()) if (m_vVersion.empty())
{ {
QMessageBox msg(QMessageBox::Information, tr("tips"), tr("no version available"), QMessageBox::Yes, this); QMessageBox msg(QMessageBox::Information, tr("tips"), tr("no version available"), QMessageBox::Yes, this);

View File

@ -2604,16 +2604,27 @@ void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer para
p->m_versionDll->GetDriverVersionList(devType.toStdString().c_str(), &versionInfo, &versionCount); p->m_versionDll->GetDriverVersionList(devType.toStdString().c_str(), &versionInfo, &versionCount);
if (versionCount > 0) 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]; HGChar suffix[64];
HGBase_GetFileSuffix(versionInfo[0].url, suffix, 64); HGBase_GetFileSuffix(versionInfo[verionIndex].url, suffix, 64);
HGChar savePath[512]; HGChar savePath[512];
HGBase_GetConfigPath(savePath, 512); HGBase_GetConfigPath(savePath, 512);
HGBase_CreateDir(savePath); HGBase_CreateDir(savePath);
HGChar fileName[128]; HGChar fileName[128];
sprintf(fileName, "%s.%s", versionInfo[0].version, suffix); sprintf(fileName, "%s.%s", versionInfo[verionIndex].version, suffix);
strcat(savePath, fileName); strcat(savePath, fileName);
QFile saveFile(savePath); QFile saveFile(savePath);
@ -2623,9 +2634,9 @@ void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer para
QString md5_2 = QCryptographicHash::hash(fileMsg, QCryptographicHash::Md5).toHex(); QString md5_2 = QCryptographicHash::hash(fileMsg, QCryptographicHash::Md5).toHex();
QFile f(savePath); 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) if (HGBASE_ERR_OK == ret)
{ {
QFile saveFile(savePath); QFile saveFile(savePath);
@ -2634,7 +2645,7 @@ void HGAPI MainWindow::FwUpgradeAndDevLockThread(HGThread thread, HGPointer para
saveFile.close(); saveFile.close();
QString md5_2 = QCryptographicHash::hash(fileMsg, QCryptographicHash::Md5).toHex(); 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_upgradeFilePath = savePath;
p->m_vFwUpgradeAndDevLock[index].m_handleFlag |= FwUpgradeAndDevLock::FwUpgrade; p->m_vFwUpgradeAndDevLock[index].m_handleFlag |= FwUpgradeAndDevLock::FwUpgrade;