code_app/app/scanner2/dialog_updateprogress.cpp

91 lines
2.1 KiB
C++
Raw Normal View History

#include "dialog_updateprogress.h"
#include "ui_dialog_updateprogress.h"
2022-07-13 11:01:42 +00:00
#include <QMessageBox>
#include <QFile>
#include <QDir>
#include <QCryptographicHash>
2024-08-01 05:46:17 +00:00
#include "log/log.h"
extern HLOG g_hLog;
2022-07-14 10:45:35 +00:00
Dialog_updateProgress::Dialog_updateProgress(VersionDll *dll, const QString &url,
const QString &savePath, QWidget *parent) :
QDialog(parent)
2022-07-13 11:01:42 +00:00
, m_versionDll(dll)
, m_url(url)
2022-07-14 10:45:35 +00:00
, m_savePath(savePath)
, 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-10-12 03:51:41 +00:00
HGInt HGAPI 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;
}
2022-10-12 03:51:41 +00:00
void HGAPI Dialog_updateProgress::ThreadFunc(HGThread thread, HGPointer param)
{
(void)thread;
Dialog_updateProgress *p = (Dialog_updateProgress *)param;
2022-07-14 10:45:35 +00:00
HGResult ret = p->m_versionDll->HttpDownload(p->m_url.toStdString().c_str(), p->m_savePath.toStdString().c_str(), HttpDownloadThreadFunc, p);
if (HGBASE_ERR_OK != ret)
2022-07-13 11:01:42 +00:00
{
2022-07-14 10:45:35 +00:00
QFile::remove(p->m_savePath.toStdString().c_str());
2024-08-01 05:46:17 +00:00
ErrorLog(g_hLog, "UpgradeHttpDownload:%u", ret);
2022-07-13 11:01:42 +00:00
}
emit p->finish();
}
void Dialog_updateProgress::on_updateProgress(int value)
{
ui->progressBar->setValue(value);
}
2022-07-13 11:01:42 +00:00
void Dialog_updateProgress::on_finish()
{
accept();
2022-07-13 11:01:42 +00:00
}
void Dialog_updateProgress::on_pushButton_clicked()
{
close();
}
void Dialog_updateProgress::closeEvent(QCloseEvent* e)
{
m_stopThread = true;
2022-07-13 11:01:42 +00:00
}