code_app/app/scanner/dialog_updateprogress.cpp

125 lines
3.2 KiB
C++
Raw Normal View History

#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"
#include <QMessageBox>
#include <QFile>
#include <QDir>
#include <QCryptographicHash>
Dialog_updateProgress::Dialog_updateProgress(VersionDll *dll, HGVersionMgr mgr, const QString &url,
2022-07-13 11:01:42 +00:00
const QString &versionNum, const QString &md5, QWidget *parent) :
QDialog(parent)
2022-07-13 11:01:42 +00:00
, m_versionDll(dll)
, m_versionMgr(mgr)
, m_url(url)
2022-07-13 11:01:42 +00:00
, m_versionNum(versionNum)
, m_md5(md5)
, 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);
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)
{
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());
HGResult ret = p->m_versionDll->HttpDownload(p->m_versionMgr, p->m_url.toStdString().c_str(), cfgPath, HttpDownloadThreadFunc, p);
if (HGBASE_ERR_OK == ret)
2022-07-13 11:01:42 +00:00
{
QString curPath = QDir::currentPath();
QString tmpPath = QDir::tempPath();
QFile file(curPath);
2022-07-13 11:01:42 +00:00
#if defined(HG_CMP_MSC)
file.copy("HGUpgrade.exe", tmpPath);
file.copy("HGBase.dll", tmpPath);
file.copy("HGVersion.dll", tmpPath);
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);
#else
file.copy("HGUpgrade", tmpPath);
file.copy("libHGBase.so", tmpPath);
file.copy("libHGVersion.so", tmpPath);
2022-07-13 11:01:42 +00:00
#endif
emit p->finish();
emit p->upgradeApp();
2022-07-13 11:01:42 +00:00
}
else
{
emit p->finish();
QFile::remove(cfgPath);
2022-07-13 11:01:42 +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();
}
void Dialog_updateProgress::on_pushButton_clicked()
{
m_stopThread = true;
HGBase_CloseThread(m_thread);
m_thread = nullptr;
close();
}
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
}