code_app/app/upgrade/mainwindow.cpp

94 lines
2.3 KiB
C++
Raw Normal View History

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)
, 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-07-19 10:06:08 +00:00
setWindowTitle(tr("Installation"));
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();
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()
{
HGBase_CloseThread(m_thread);
m_thread = nullptr;
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 + "\"";
if (0 == system(cmd.c_str()))
ret = true;
#endif
return ret;
}
void MainWindow::ThreadFunc(HGThread thread, HGPointer param)
{
(void)thread;
MainWindow* p = (MainWindow*)param;
p->m_success = Upgrade(p->m_pkgPath);
emit p->closeWnd();
}