2022-07-18 08:59:12 +00:00
|
|
|
#include "dialog_upgrade.h"
|
|
|
|
#include "ui_dialog_upgrade.h"
|
|
|
|
#include "base/HGUtility.h"
|
|
|
|
#include <QCryptographicHash>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QFile>
|
|
|
|
|
2022-07-21 02:56:47 +00:00
|
|
|
Dialog_upgrade::Dialog_upgrade(class VersionDll *versionDll, HGVersionInfo *versionInfo, HGUInt versionCount, QWidget *parent) :
|
2022-07-18 08:59:12 +00:00
|
|
|
QDialog(parent)
|
|
|
|
, ui(new Ui::Dialog_upgrade)
|
|
|
|
, m_versionDll(versionDll)
|
2022-07-21 02:56:47 +00:00
|
|
|
, m_versionInfo(versionInfo)
|
|
|
|
, m_versionCount(versionCount)
|
2022-07-18 08:59:12 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
setWindowTitle(tr("upgrade online"));
|
|
|
|
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
this->layout()->setSizeConstraint(QLayout::SetFixedSize);
|
|
|
|
|
|
|
|
ui->listWidget->setVisible(false);
|
|
|
|
ui->pbtn_upgrade->setVisible(false);
|
|
|
|
ui->pbtn_install->setVisible(false);
|
|
|
|
ui->pbtn_cancel->setVisible(false);
|
|
|
|
ui->label->setVisible(false);
|
|
|
|
|
2022-07-21 02:56:47 +00:00
|
|
|
for(HGUInt i = 0; i < m_versionCount; ++i)
|
2022-07-18 08:59:12 +00:00
|
|
|
{
|
|
|
|
QListWidgetItem *listwidgetItem = new QListWidgetItem;
|
2022-07-21 02:56:47 +00:00
|
|
|
listwidgetItem->setText(QString(m_versionInfo[i].version));
|
|
|
|
listwidgetItem->setData(Qt::UserRole, m_versionInfo[i].url);
|
|
|
|
listwidgetItem->setData(Qt::UserRole+1, m_versionInfo[i].md5);
|
|
|
|
listwidgetItem->setToolTip(tr("upgrade contents: ") + m_versionInfo[i].desc + tr(" bug description: ") + m_versionInfo[i].bugInfo);
|
2022-07-18 08:59:12 +00:00
|
|
|
ui->listWidget->addItem(listwidgetItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ui->listWidget->count() > 0)
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = ui->listWidget->item(0);
|
|
|
|
item->setSelected(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
HGChar currVersion[64] = {0};
|
|
|
|
m_versionDll->GetCurrVersion(HGVERSION_APPNAME_SCANNER, currVersion, 64);
|
|
|
|
HGInt result = 0;
|
|
|
|
std::string newestVersionNum = ui->listWidget->item(0)->text().toStdString().c_str();
|
|
|
|
m_versionDll->CompareVersion(currVersion, newestVersionNum.c_str(), &result);
|
2022-07-20 09:30:27 +00:00
|
|
|
if(result == 0 || result == 1)
|
2022-07-18 08:59:12 +00:00
|
|
|
{
|
|
|
|
ui->label_detectResult->setText(tr("The current version is the latest! The current version number is : ") + currVersion);
|
|
|
|
ui->pbtn_upgrade->setVisible(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->pbtn_upgrade->setVisible(true);
|
|
|
|
ui->label_detectResult->setText(tr("Discover the new version : ") +
|
|
|
|
ui->listWidget->item(0)->text().toStdString().c_str() +
|
|
|
|
tr(" ,the current version is : ") + currVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui->listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(on_listWidget_itemDoubleClicked(QListWidgetItem*)), Qt::QueuedConnection);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dialog_upgrade::~Dialog_upgrade()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_upgrade::on_pbtn_install_clicked()
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = ui->listWidget->currentItem();
|
|
|
|
on_listWidget_itemDoubleClicked(item);
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_upgrade::on_pbtn_cancel_clicked()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_upgrade::on_listWidget_itemDoubleClicked(QListWidgetItem *item)
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
|
|
|
|
HGChar currVersion[64] = {0};
|
|
|
|
m_versionDll->GetCurrVersion(HGVERSION_APPNAME_SCANNER, currVersion, 64);
|
|
|
|
|
|
|
|
std::string selectVersionNum = item->text().toStdString().c_str();
|
|
|
|
HGInt result = 0;
|
|
|
|
m_versionDll->CompareVersion(currVersion, selectVersionNum.c_str(), &result);
|
|
|
|
if(result == 0)
|
|
|
|
{
|
2022-07-18 09:16:49 +00:00
|
|
|
QMessageBox::information(this, tr("tip"), tr("Already in current version"));
|
2022-07-18 08:59:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QString url = item->data(Qt::UserRole).toString();
|
|
|
|
QString versionNum = item->text();
|
|
|
|
QString md5 = item->data(Qt::UserRole+1).toString();
|
|
|
|
|
|
|
|
HGChar savePath[512];
|
|
|
|
HGBase_GetConfigPath(savePath, 512);
|
|
|
|
HGBase_CreateDir(savePath);
|
|
|
|
strcat(savePath, (versionNum + QString("%1").arg(".exe")).toLatin1().data());
|
|
|
|
|
|
|
|
QFile saveFile(savePath);
|
|
|
|
saveFile.open(QFile::ReadOnly);
|
|
|
|
QByteArray fileMsg = saveFile.readAll();
|
|
|
|
saveFile.close();
|
|
|
|
QString md5_2 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
|
|
|
|
|
|
|
|
QFile f(savePath);
|
|
|
|
if(!f.exists() || md5 != md5_2)
|
|
|
|
{
|
2022-07-20 11:28:06 +00:00
|
|
|
Dialog_updateProgress dlg(m_versionDll, url, savePath);
|
|
|
|
connect(&dlg, SIGNAL(upgrade(QString)), this, SLOT(on_upgrade(QString)), Qt::QueuedConnection);
|
|
|
|
dlg.exec();
|
|
|
|
disconnect(&dlg, SIGNAL(upgrade(QString)), this, SLOT(on_upgrade(QString)));
|
2022-07-18 08:59:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
on_upgrade(savePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_upgrade::on_upgrade(QString pkgPath)
|
|
|
|
{
|
2022-07-21 02:56:47 +00:00
|
|
|
QString curPath = QDir::currentPath();
|
|
|
|
QString tmpPath = QDir::tempPath();
|
|
|
|
QFile file(curPath);
|
|
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
file.copy("HwUpgradeApp.exe", tmpPath + "/HwUpgradeApp.exe");
|
|
|
|
file.copy("HwBase.dll", tmpPath + "/HwBase.dll");
|
|
|
|
file.copy("HwVersion.dll", tmpPath + "/HwVersion.dll");
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
file.copy("LscUpgradeApp.exe", tmpPath + "/LscUpgradeApp.exe");
|
|
|
|
file.copy("LscBase.dll", tmpPath + "/LscBase.dll");
|
|
|
|
file.copy("LscVersion.dll", tmpPath + "/LscVersion.dll");
|
|
|
|
#else
|
|
|
|
file.copy("HGUpgradeApp.exe", tmpPath + "/HGUpgradeApp.exe");
|
|
|
|
file.copy("HGBase.dll", tmpPath + "/HGBase.dll");
|
|
|
|
file.copy("HGVersion.dll", tmpPath + "/HGVersion.dll");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
file.copy("msvcp140.dll", tmpPath + "/msvcp140.dll");
|
|
|
|
file.copy("Qt5Core.dll", tmpPath + "/Qt5Core.dll");
|
|
|
|
file.copy("Qt5Gui.dll", tmpPath + "/Qt5Gui.dll");
|
|
|
|
file.copy("Qt5Widgets.dll", tmpPath + "/Qt5Widgets.dll");
|
|
|
|
file.copy("vcruntime140.dll", tmpPath + "/vcruntime140.dll");
|
|
|
|
QDir dir;
|
|
|
|
dir.mkdir(tmpPath + "/platforms");
|
|
|
|
file.copy("platforms/qwindows.dll", tmpPath + "/platforms/qwindows.dll");
|
|
|
|
dir.mkdir(tmpPath + "/imageformats");
|
|
|
|
file.copy("imageformats/qgif.dll", tmpPath + "/imageformats/qgif.dll");
|
|
|
|
#else
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
file.copy("HwUpgradeApp", tmpPath + "/HwUpgradeApp");
|
|
|
|
file.copy("libHwBase.so", tmpPath + "/libHwBase.so");
|
|
|
|
file.copy("libHwVersion.so", tmpPath + "/libHwVersion.so");
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
file.copy("LscUpgradeApp", tmpPath + "/LscUpgradeApp");
|
|
|
|
file.copy("libLscBase.so", tmpPath + "/libLscBase.so");
|
|
|
|
file.copy("libLscVersion.so", tmpPath + "/libLscVersion.so");
|
|
|
|
#else
|
|
|
|
file.copy("HGUpgradeApp", tmpPath + "/HGUpgradeApp");
|
|
|
|
file.copy("libHGBase.so", tmpPath + "/libHGBase.so");
|
|
|
|
file.copy("libHGVersion.so", tmpPath + "/libHGVersion.so");
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-07-18 08:59:12 +00:00
|
|
|
emit upgradeApp(pkgPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_upgrade::on_pbtn_selectVersion_clicked()
|
|
|
|
{
|
|
|
|
if(ui->listWidget->count() == 0)
|
|
|
|
{
|
|
|
|
ui->pbtn_install->setVisible(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->pbtn_install->setVisible(true);
|
|
|
|
}
|
|
|
|
ui->pbtn_selectVersion->setVisible(false);
|
|
|
|
ui->listWidget->setVisible(true);
|
|
|
|
ui->pbtn_cancel->setVisible(true);
|
|
|
|
ui->label->setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_upgrade::on_pbtn_upgrade_clicked()
|
|
|
|
{
|
|
|
|
QListWidgetItem *item = ui->listWidget->item(0);
|
|
|
|
on_listWidget_itemDoubleClicked(item);
|
|
|
|
close();
|
|
|
|
}
|