2022-07-07 08:16:41 +00:00
|
|
|
#include "dialog_updateprogress.h"
|
|
|
|
#include "ui_dialog_updateprogress.h"
|
|
|
|
#include "base/HGUtility.h"
|
2022-07-13 11:01:42 +00:00
|
|
|
#include "base/HGMd5.h"
|
2022-07-13 11:25:37 +00:00
|
|
|
#include <sys/stat.h>
|
2022-07-13 11:01:42 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QCryptographicHash>
|
2022-07-07 08:16:41 +00:00
|
|
|
|
2022-07-13 11:01:42 +00:00
|
|
|
Dialog_updateProgress::Dialog_updateProgress(HGDll dll, HGVersionMgr mgr, const QString &url,
|
|
|
|
const QString &versionNum, const QString &md5, QWidget *parent) :
|
2022-07-07 08:16:41 +00:00
|
|
|
QDialog(parent)
|
2022-07-13 11:01:42 +00:00
|
|
|
, m_versionDll(dll)
|
|
|
|
, m_versionMgr(mgr)
|
2022-07-07 08:16:41 +00:00
|
|
|
, m_url(url)
|
2022-07-13 11:01:42 +00:00
|
|
|
, m_versionNum(versionNum)
|
|
|
|
, m_md5(md5)
|
2022-07-07 08:16:41 +00:00
|
|
|
, ui(new Ui::Dialog_updateProgress)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
ui->progressBar->setValue(0);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection);
|
2022-07-13 11:01:42 +00:00
|
|
|
connect(this, SIGNAL(finish()), this, SLOT(on_finish()), Qt::QueuedConnection);
|
2022-07-07 08:16:41 +00:00
|
|
|
|
|
|
|
m_stopThread = false;
|
|
|
|
HGBase_OpenThread(ThreadFunc, this, &m_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
Dialog_updateProgress::~Dialog_updateProgress()
|
|
|
|
{
|
|
|
|
if (nullptr != m_thread)
|
|
|
|
{
|
|
|
|
HGBase_CloseThread(m_thread);
|
|
|
|
m_thread = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-07-13 11:01:42 +00:00
|
|
|
HGInt Dialog_updateProgress::HttpDownloadThreadFunc(HGULonglong totalSize, HGULonglong nowSize, HGPointer param)
|
2022-07-07 08:16:41 +00:00
|
|
|
{
|
|
|
|
Dialog_updateProgress *p = (Dialog_updateProgress *)param;
|
|
|
|
if (p->m_stopThread)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totalSize != 0)
|
|
|
|
{
|
|
|
|
emit p->updateProgress(((double)nowSize / totalSize) * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_updateProgress::ThreadFunc(HGThread thread, HGPointer param)
|
|
|
|
{
|
|
|
|
(void)thread;
|
|
|
|
Dialog_updateProgress *p = (Dialog_updateProgress *)param;
|
|
|
|
|
|
|
|
HGChar cfgPath[512];
|
|
|
|
HGBase_GetConfigPath(cfgPath, 512);
|
|
|
|
HGBase_CreateDir(cfgPath);
|
2022-07-13 11:01:42 +00:00
|
|
|
strcat(cfgPath, (p->m_versionNum + QString("%1").arg(".exe")).toLatin1().data());
|
|
|
|
|
|
|
|
QFile cfgFile(cfgPath);
|
|
|
|
cfgFile.open(QFile::ReadOnly);
|
|
|
|
QByteArray fileMsg = cfgFile.readAll();
|
|
|
|
cfgFile.close();
|
|
|
|
QString md5 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
|
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
if(!p->isFileExists(cfgPath) || md5 != p->m_md5)
|
|
|
|
{
|
|
|
|
typedef HGResult (HGAPI *Func)(HGVersionMgr, const HGChar *, const HGChar *, HGHttpDownloadFunc, HGPointer);
|
|
|
|
Func func = NULL;
|
|
|
|
ret = HGBase_GetDllProcAddress(p->m_versionDll, "HGVersion_HttpDownload", (HGPointer *)&func);
|
|
|
|
if (NULL != func)
|
|
|
|
{
|
|
|
|
func(p->m_versionMgr, p->m_url.toStdString().c_str(), cfgPath, HttpDownloadThreadFunc, p);
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
QString curPath = QDir::currentPath();
|
|
|
|
QString tmpPath = QDir::tempPath();
|
|
|
|
QFile file(curPath);
|
|
|
|
file.copy("HuagoScanUpgrade.exe", tmpPath);
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
file.copy("msvcp140.dll", tmpPath);
|
|
|
|
file.copy("Qt5Core.dll", tmpPath);
|
|
|
|
file.copy("Qt5Gui.dll", tmpPath);
|
|
|
|
file.copy("Qt5Widgets.dll", tmpPath);
|
|
|
|
file.copy("vcruntime140.dll", tmpPath);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
emit p->finish();
|
|
|
|
emit p->upgradeApp();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emit p->finish();
|
|
|
|
QFile::remove(cfgPath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
emit p->finish();
|
|
|
|
emit p->upgradeApp();
|
|
|
|
}
|
2022-07-07 08:16:41 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dialog_updateProgress::on_updateProgress(int value)
|
|
|
|
{
|
|
|
|
ui->progressBar->setValue(value);
|
|
|
|
}
|
|
|
|
|
2022-07-13 11:01:42 +00:00
|
|
|
void Dialog_updateProgress::on_finish()
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2022-07-07 08:16:41 +00:00
|
|
|
void Dialog_updateProgress::on_pushButton_clicked()
|
|
|
|
{
|
|
|
|
m_stopThread = true;
|
|
|
|
HGBase_CloseThread(m_thread);
|
|
|
|
m_thread = nullptr;
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2022-07-13 11:01:42 +00:00
|
|
|
bool Dialog_updateProgress::isFileExists(const std::string &filepath)
|
|
|
|
{
|
|
|
|
struct stat buffer;
|
|
|
|
return (stat(filepath.c_str(), &buffer) == 0);
|
|
|
|
}
|
|
|
|
|
2022-07-07 08:16:41 +00:00
|
|
|
void Dialog_updateProgress::closeEvent(QCloseEvent* e)
|
|
|
|
{
|
|
|
|
(void)e;
|
|
|
|
m_stopThread = true;
|
|
|
|
HGBase_CloseThread(m_thread);
|
|
|
|
m_thread = nullptr;
|
2022-07-13 11:01:42 +00:00
|
|
|
}
|