Merge branch 'master' of http://192.168.100.140:8099/sane/code_app
This commit is contained in:
commit
714aec8209
|
@ -129,36 +129,6 @@ bool AppIsRun(const std::string& appName)
|
||||||
return false;
|
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)
|
void RunApp(const std::string& appName)
|
||||||
{
|
{
|
||||||
if (appName == HGVERSION_APPNAME_SCANNER)
|
if (appName == HGVERSION_APPNAME_SCANNER)
|
||||||
|
|
|
@ -6,9 +6,6 @@
|
||||||
// 判断app是否在运行
|
// 判断app是否在运行
|
||||||
bool AppIsRun(const std::string& appName);
|
bool AppIsRun(const std::string& appName);
|
||||||
|
|
||||||
// 升级安装, 使用之前的安装路径
|
|
||||||
bool Upgrade(const std::string& pkgPath);
|
|
||||||
|
|
||||||
// 运行app
|
// 运行app
|
||||||
void RunApp(const std::string& appName);
|
void RunApp(const std::string& appName);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
#include <QMessageBox>
|
||||||
#include "version/HGVersion.h"
|
#include "version/HGVersion.h"
|
||||||
#include "HGUpgrade.h"
|
#include "HGUpgrade.h"
|
||||||
|
|
||||||
|
@ -65,8 +66,17 @@ int main(int argc, char *argv[])
|
||||||
w.show();
|
w.show();
|
||||||
a.exec();
|
a.exec();
|
||||||
|
|
||||||
if (!AppIsRun(appName))
|
if (w.isInstallSuccess())
|
||||||
RunApp(appName);
|
{
|
||||||
|
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;
|
return 0;
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "HGUpgrade.h"
|
#include "base/HGDef.h"
|
||||||
|
#include "base/HGInc.h"
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QMovie>
|
#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)
|
MainWindow::MainWindow(const std::string &appName, const std::string& pkgPath, QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
|
@ -10,6 +16,7 @@ MainWindow::MainWindow(const std::string &appName, const std::string& pkgPath, Q
|
||||||
, m_appName(appName)
|
, m_appName(appName)
|
||||||
, m_pkgPath(pkgPath)
|
, m_pkgPath(pkgPath)
|
||||||
, m_thread(nullptr)
|
, m_thread(nullptr)
|
||||||
|
, m_success(false)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
@ -38,11 +45,48 @@ MainWindow::~MainWindow()
|
||||||
delete ui;
|
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 MainWindow::ThreadFunc(HGThread thread, HGPointer param)
|
||||||
{
|
{
|
||||||
(void)thread;
|
(void)thread;
|
||||||
MainWindow* p = (MainWindow*)param;
|
MainWindow* p = (MainWindow*)param;
|
||||||
Upgrade(p->m_pkgPath);
|
p->m_success = p->Upgrade(p->m_pkgPath);
|
||||||
|
|
||||||
emit p->closeWnd();
|
emit p->closeWnd();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,14 @@ public:
|
||||||
MainWindow(const std::string &appName, const std::string &pkgPath, QWidget *parent = nullptr);
|
MainWindow(const std::string &appName, const std::string &pkgPath, QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
bool isInstallSuccess();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void closeWnd();
|
void closeWnd();
|
||||||
|
void upgradeResult();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool Upgrade(const std::string& pkgPath);
|
||||||
static void ThreadFunc(HGThread thread, HGPointer param);
|
static void ThreadFunc(HGThread thread, HGPointer param);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -28,5 +32,6 @@ private:
|
||||||
std::string m_appName;
|
std::string m_appName;
|
||||||
std::string m_pkgPath;
|
std::string m_pkgPath;
|
||||||
HGThread m_thread;
|
HGThread m_thread;
|
||||||
|
bool m_success;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
Loading…
Reference in New Issue