#include "dialog_updateprogress.h" #include "ui_dialog_updateprogress.h" #include "base/HGUtility.h" #include "base/HGMd5.h" #include #include #include #include Dialog_updateProgress::Dialog_updateProgress(VersionDll *dll, HGVersionMgr mgr, const QString &url, const QString &versionNum, const QString &md5, QWidget *parent) : QDialog(parent) , m_versionDll(dll) , m_versionMgr(mgr) , m_url(url) , 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); 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; } 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); 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) { QString curPath = QDir::currentPath(); QString tmpPath = QDir::tempPath(); QFile file(curPath); #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); #endif emit p->finish(); emit p->upgradeApp(); } else { emit p->finish(); QFile::remove(cfgPath); } } void Dialog_updateProgress::on_updateProgress(int value) { ui->progressBar->setValue(value); } 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; }