#include "mainwindow.h" #include "ui_mainwindow.h" #include "base/HGDef.h" #include "base/HGInc.h" #include #include #include #if defined(HG_CMP_MSC) #include #include #endif MainWindow::MainWindow(const std::string &appName, const std::string& pkgPath, QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) , m_appName(appName) , m_pkgPath(pkgPath) , m_thread(nullptr) , m_success(false) { ui->setupUi(this); setWindowTitle(tr("Installation")); setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint); 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); } MainWindow::~MainWindow() { HGBase_CloseThread(m_thread); m_thread = nullptr; delete ui; } 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 + "\""; int status = system(cmd.c_str()); if (-1 != status && WIFEXITED(status) && 0 == WEXITSTATUS(status)) 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(); }