调整更新升级问题

This commit is contained in:
yangjiaxuan 2023-01-11 18:56:48 +08:00
parent e6b770cd27
commit 716e99f712
6 changed files with 49 additions and 20 deletions

View File

@ -3606,7 +3606,7 @@ void MainWindow::upgradeApp(QString pkgPath)
#endif
QFile::remove(tmpPath + "msvcp140.dll");
QFile::copy(curPath + "msvcp140.dll", tmpPath + "msvcp140.dll");
QFile::copy(curPath + "msvcp140.dll", tmpPath + "msvcp140.dll");
QFile::remove(tmpPath + "Qt5Core.dll");
QFile::copy(curPath + "Qt5Core.dll", tmpPath + "Qt5Core.dll");
QFile::remove(tmpPath + "Qt5Gui.dll");
@ -3615,6 +3615,10 @@ void MainWindow::upgradeApp(QString pkgPath)
QFile::copy(curPath + "Qt5Widgets.dll", tmpPath + "Qt5Widgets.dll");
QFile::remove(tmpPath + "vcruntime140.dll");
QFile::copy(curPath + "vcruntime140.dll", tmpPath + "vcruntime140.dll");
QFile::remove(tmpPath + "concrt140.dll");
QFile::copy(curPath + "concrt140.dll", tmpPath + "concrt140.dll");
QFile::remove(tmpPath + "vcruntime140_1.dll");
QFile::copy(curPath + "vcruntime140_1.dll", tmpPath + "vcruntime140_1.dll");
QDir dir;
dir.mkdir(tmpPath + "platforms");
QFile::remove(tmpPath + "platforms/qwindows.dll");

View File

@ -1,3 +1,4 @@
#include "mainwindow.h"
#include <QApplication>
@ -80,7 +81,7 @@ int main(int argc, char *argv[])
else
{
QMessageBox msg(QMessageBox::Critical, QObject::tr("error"),
QObject::tr("install failed!"),
QObject::tr("install failed!") + "\n" + w.getUpgradeFailInfo(),
QMessageBox::Ok);
msg.setButtonText(QMessageBox::Ok, QObject::tr("yes"));
msg.exec();

View File

@ -2,6 +2,7 @@
#include "ui_mainwindow.h"
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGInfo.h"
#include <QLabel>
#include <QMovie>
#include <QMessageBox>
@ -50,28 +51,47 @@ bool MainWindow::isInstallSuccess()
return m_success;
}
bool MainWindow::Upgrade(const std::string& pkgPath)
QString MainWindow::getUpgradeFailInfo()
{
return m_upgradeFailInfo;
}
bool MainWindow::Upgrade(const std::string& pkgPath, QString &failInfo)
{
bool ret = false;
failInfo.clear();
#if defined(HG_CMP_MSC)
PROCESS_INFORMATION ProcessInfo;
STARTUPINFOA StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof(StartupInfo);
// 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);
}
// char command[256];
// sprintf(command, "%s %s", pkgPath.c_str(), "/verysilent");
SHELLEXECUTEINFOA sei = {0};
sei.cbSize = sizeof(SHELLEXECUTEINFOA);
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
sei.nShow = SW_SHOWNORMAL;
sei.lpFile = pkgPath.c_str();
sei.lpParameters = "/verysilent";
sei.lpVerb = "runas";
// if (CreateProcessA(nullptr, command, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo))
if (ShellExecuteExA(&sei))
{
WaitForSingleObject(sei.hProcess, INFINITE);
DWORD dwCode = 0;
GetExitCodeProcess(sei.hProcess, &dwCode);
failInfo = QString("ExitCode=%1").arg((int)dwCode);
//CloseHandle(ProcessInfo.hThread);
CloseHandle(sei.hProcess);
ret = (0 == dwCode);
}
#else
std::string cmd = "pkexec dpkg -i \"" + pkgPath + "\"";
@ -87,7 +107,7 @@ void HGAPI MainWindow::ThreadFunc(HGThread thread, HGPointer param)
{
(void)thread;
MainWindow* p = (MainWindow*)param;
p->m_success = Upgrade(p->m_pkgPath);
p->m_success = Upgrade(p->m_pkgPath, p->m_upgradeFailInfo);
emit p->closeWnd();
}

View File

@ -17,12 +17,13 @@ public:
~MainWindow();
bool isInstallSuccess();
QString getUpgradeFailInfo();
signals:
void closeWnd();
private:
static bool Upgrade(const std::string& pkgPath);
static bool Upgrade(const std::string& pkgPath, QString &failInfo);
static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
private:
@ -32,5 +33,6 @@ private:
std::string m_pkgPath;
HGThread m_thread;
bool m_success;
QString m_upgradeFailInfo;
};
#endif // MAINWINDOW_H

View File

@ -25,6 +25,7 @@ TARGET = HGFWUpgradeApp
win32 {
DEFINES += _CRT_SECURE_NO_WARNINGS
QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'"
LIBS += -ladvapi32 -lpsapi
contains(QT_ARCH, i386) {

View File

@ -25,6 +25,7 @@ TARGET = HGUpgradeApp
win32 {
DEFINES += _CRT_SECURE_NO_WARNINGS
QMAKE_LFLAGS += /MANIFESTUAC:"level='requireAdministrator' uiAccess='false'"
LIBS += -ladvapi32 -lpsapi
contains(QT_ARCH, i386) {