调整更新升级问题

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

@ -3615,6 +3615,10 @@ void MainWindow::upgradeApp(QString pkgPath)
QFile::copy(curPath + "Qt5Widgets.dll", tmpPath + "Qt5Widgets.dll"); QFile::copy(curPath + "Qt5Widgets.dll", tmpPath + "Qt5Widgets.dll");
QFile::remove(tmpPath + "vcruntime140.dll"); QFile::remove(tmpPath + "vcruntime140.dll");
QFile::copy(curPath + "vcruntime140.dll", 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; QDir dir;
dir.mkdir(tmpPath + "platforms"); dir.mkdir(tmpPath + "platforms");
QFile::remove(tmpPath + "platforms/qwindows.dll"); QFile::remove(tmpPath + "platforms/qwindows.dll");

View File

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

View File

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

View File

@ -17,12 +17,13 @@ public:
~MainWindow(); ~MainWindow();
bool isInstallSuccess(); bool isInstallSuccess();
QString getUpgradeFailInfo();
signals: signals:
void closeWnd(); void closeWnd();
private: 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); static void HGAPI ThreadFunc(HGThread thread, HGPointer param);
private: private:
@ -32,5 +33,6 @@ private:
std::string m_pkgPath; std::string m_pkgPath;
HGThread m_thread; HGThread m_thread;
bool m_success; bool m_success;
QString m_upgradeFailInfo;
}; };
#endif // MAINWINDOW_H #endif // MAINWINDOW_H

View File

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

View File

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