2022-06-29 09:46:00 +00:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "ui_mainwindow.h"
|
2022-07-22 03:12:00 +00:00
|
|
|
#include "base/HGDef.h"
|
|
|
|
#include "base/HGInc.h"
|
2022-07-19 10:06:08 +00:00
|
|
|
#include <QLabel>
|
|
|
|
#include <QMovie>
|
2022-07-22 03:12:00 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
#include <shellapi.h>
|
|
|
|
#include <tlhelp32.h>
|
|
|
|
#endif
|
2022-06-29 09:46:00 +00:00
|
|
|
|
2022-07-14 04:01:39 +00:00
|
|
|
MainWindow::MainWindow(const std::string &appName, const std::string& pkgPath, QWidget *parent)
|
2022-06-29 09:46:00 +00:00
|
|
|
: QMainWindow(parent)
|
|
|
|
, ui(new Ui::MainWindow)
|
2022-07-14 04:01:39 +00:00
|
|
|
, m_appName(appName)
|
2022-06-30 08:42:46 +00:00
|
|
|
, m_pkgPath(pkgPath)
|
|
|
|
, m_thread(nullptr)
|
2022-07-22 03:12:00 +00:00
|
|
|
, m_success(false)
|
2022-06-29 09:46:00 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2022-06-30 08:42:46 +00:00
|
|
|
|
2022-07-19 10:06:08 +00:00
|
|
|
setWindowTitle(tr("Installation"));
|
2022-06-30 08:42:46 +00:00
|
|
|
setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint);
|
|
|
|
|
2022-07-19 10:06:08 +00:00
|
|
|
ui->label_text->setText(tr("Installation in progress, please wait..."));
|
|
|
|
|
|
|
|
QMovie *movie = new QMovie(":images/image_rsc/logo/waiting.gif");
|
|
|
|
ui->label_gif->setMovie(movie);
|
|
|
|
movie->setCacheMode(QMovie::CacheAll);
|
|
|
|
movie->setScaledSize(QSize(ui->label_gif->width(), ui->label_gif->height()));
|
|
|
|
movie->start();
|
|
|
|
ui->label_gif->show();
|
|
|
|
|
2022-06-30 08:42:46 +00:00
|
|
|
connect(this, SIGNAL(closeWnd()), this, SLOT(close()), Qt::QueuedConnection);
|
|
|
|
|
|
|
|
HGBase_OpenThread(ThreadFunc, this, &m_thread);
|
2022-06-29 09:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2022-06-30 08:42:46 +00:00
|
|
|
HGBase_CloseThread(m_thread);
|
2022-07-01 03:02:41 +00:00
|
|
|
m_thread = nullptr;
|
2022-06-30 08:42:46 +00:00
|
|
|
|
2022-06-29 09:46:00 +00:00
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-07-22 03:12:00 +00:00
|
|
|
bool MainWindow::isInstallSuccess()
|
|
|
|
{
|
|
|
|
return m_success;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MainWindow::Upgrade(const std::string& pkgPath)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
|
|
|
PROCESS_INFORMATION ProcessInfo;
|
|
|
|
STARTUPINFOA StartupInfo;
|
|
|
|
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
|
|
|
|
StartupInfo.cb = sizeof(StartupInfo);
|
|
|
|
|
|
|
|
char command[256];
|
|
|
|
sprintf(command, "%s %s", pkgPath.c_str(), "/verysilent");
|
|
|
|
if (CreateProcessA(nullptr, command, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo))
|
|
|
|
{
|
|
|
|
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
|
|
|
|
DWORD dwCode = 0;
|
|
|
|
GetExitCodeProcess(ProcessInfo.hProcess, &dwCode);
|
|
|
|
CloseHandle(ProcessInfo.hThread);
|
|
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
|
|
ret = (0 == dwCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
std::string cmd = "pkexec dpkg -i \"" + pkgPath + "\"";
|
2022-07-22 07:11:15 +00:00
|
|
|
int status = system(cmd.c_str());
|
|
|
|
if (-1 != status && WIFEXITED(status) && 0 == WEXITSTATUS(status))
|
2022-07-22 03:12:00 +00:00
|
|
|
ret = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-06-30 08:42:46 +00:00
|
|
|
void MainWindow::ThreadFunc(HGThread thread, HGPointer param)
|
|
|
|
{
|
|
|
|
(void)thread;
|
|
|
|
MainWindow* p = (MainWindow*)param;
|
2022-07-22 03:51:22 +00:00
|
|
|
p->m_success = Upgrade(p->m_pkgPath);
|
2022-06-30 08:42:46 +00:00
|
|
|
|
|
|
|
emit p->closeWnd();
|
|
|
|
}
|
|
|
|
|