增加安装成功与否的提示

This commit is contained in:
yangjiaxuan 2022-07-22 11:12:00 +08:00
parent ff85917c60
commit ef2bc1189a
5 changed files with 63 additions and 37 deletions

View File

@ -129,36 +129,6 @@ bool AppIsRun(const std::string& appName)
return false;
}
bool 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);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
ret = true;
}
#else
std::string cmd = "pkexec dpkg -i \"" + pkgPath + "\"";
if (0 == system(cmd.c_str()))
ret = true;
#endif
return ret;
}
void RunApp(const std::string& appName)
{
if (appName == HGVERSION_APPNAME_SCANNER)

View File

@ -6,9 +6,6 @@
// 判断app是否在运行
bool AppIsRun(const std::string& appName);
// 升级安装, 使用之前的安装路径
bool Upgrade(const std::string& pkgPath);
// 运行app
void RunApp(const std::string& appName);

View File

@ -4,6 +4,7 @@
#include <QThread>
#include <QScreen>
#include <QTranslator>
#include <QMessageBox>
#include "version/HGVersion.h"
#include "HGUpgrade.h"
@ -65,8 +66,17 @@ int main(int argc, char *argv[])
w.show();
a.exec();
if (!AppIsRun(appName))
RunApp(appName);
if (w.isInstallSuccess())
{
QMessageBox::information(nullptr, QObject::tr("tip"), QObject::tr("install succeed!"));
if (!AppIsRun(appName))
RunApp(appName);
}
else
{
QMessageBox::critical(nullptr, QObject::tr("error"), QObject::tr("install failed!"));
}
}
return 0;

View File

@ -1,8 +1,14 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "HGUpgrade.h"
#include "base/HGDef.h"
#include "base/HGInc.h"
#include <QLabel>
#include <QMovie>
#include <QMessageBox>
#if defined(HG_CMP_MSC)
#include <shellapi.h>
#include <tlhelp32.h>
#endif
MainWindow::MainWindow(const std::string &appName, const std::string& pkgPath, QWidget *parent)
: QMainWindow(parent)
@ -10,6 +16,7 @@ MainWindow::MainWindow(const std::string &appName, const std::string& pkgPath, Q
, m_appName(appName)
, m_pkgPath(pkgPath)
, m_thread(nullptr)
, m_success(false)
{
ui->setupUi(this);
@ -38,11 +45,48 @@ MainWindow::~MainWindow()
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 + "\"";
if (0 == system(cmd.c_str()))
ret = true;
#endif
return ret;
}
void MainWindow::ThreadFunc(HGThread thread, HGPointer param)
{
(void)thread;
MainWindow* p = (MainWindow*)param;
Upgrade(p->m_pkgPath);
p->m_success = p->Upgrade(p->m_pkgPath);
emit p->closeWnd();
}

View File

@ -16,10 +16,14 @@ public:
MainWindow(const std::string &appName, const std::string &pkgPath, QWidget *parent = nullptr);
~MainWindow();
bool isInstallSuccess();
signals:
void closeWnd();
void upgradeResult();
private:
bool Upgrade(const std::string& pkgPath);
static void ThreadFunc(HGThread thread, HGPointer param);
private:
@ -28,5 +32,6 @@ private:
std::string m_appName;
std::string m_pkgPath;
HGThread m_thread;
bool m_success;
};
#endif // MAINWINDOW_H