[win] online installer: handle installer exit code

This commit is contained in:
SimplestStudio
2025-02-03 17:22:39 +02:00
parent 20fe31d707
commit 3939baebee
3 changed files with 19 additions and 13 deletions

View File

@ -306,12 +306,13 @@ void MainWindow::startInstall(const std::wstring &url)
} else {
hide();
}
if (!NS_File::runProcess(path, args)) {
DWORD status = NS_File::runProcess(path, args);
if (status != 0) {
if (!m_is_checked)
show();
m_bar->pulse(false);
m_bar->setProgress(0);
m_comntInfoLbl->setText(_TR(LABEL_ERR_RUNNING), true);
m_comntInfoLbl->setText((status & ERROR_LAUNCH) ? _TR(LABEL_ERR_RUNNING) : _TR(LABEL_ERR_COMMON) + wstring(L" ") + std::to_wstring(status), true);
} else {
if (m_is_checked) {
wstring app_path;
@ -410,10 +411,11 @@ void MainWindow::startUpdate()
m_bar->pulse(true);
wstring args = L"/c \"" + tmp_path;
args += (m_package == L"msi") ? L" /qn /norestart\"" : L" /UPDATE /VERYSILENT /NOLAUNCH\"";
if (!NS_File::runProcess(L"cmd", args, true)) {
DWORD status = NS_File::runProcess(L"cmd", args, true);
if (status != 0) {
m_bar->pulse(false);
m_bar->setProgress(0);
m_comntInfoLbl->setText(_TR(LABEL_ERR_RUNNING), true);
m_comntInfoLbl->setText((status & ERROR_LAUNCH) ? _TR(LABEL_ERR_RUNNING) : _TR(LABEL_ERR_COMMON) + wstring(L" ") + std::to_wstring(status), true);
} else {
if (m_checkState & ClrDataCheck) {
wstring dataPath = NS_File::appDataPath();
@ -484,10 +486,11 @@ void MainWindow::startUpdate()
// args = (m_package == L"msi") ? L"/fvamus \"" : L"/c \"";
// args += tmp_path;
// args += (m_package == L"msi") ? L"\" /qn" : L" /VERYSILENT\"";
// if (!NS_File::runProcess(cmd, args, true)) {
// DWORD status = NS_File::runProcess(cmd, args, true);
// if (status != 0) {
// m_bar->pulse(false);
// m_bar->setProgress(0);
// m_comntInfoLbl->setText(_TR(LABEL_ERR_RUNNING), true);
// m_comntInfoLbl->setText((status & ERROR_LAUNCH) ? _TR(LABEL_ERR_RUNNING) : _TR(LABEL_ERR_COMMON) + wstring(L" ") + std::to_wstring(status), true);
// } else {
// if (m_checkState & ClrDataCheck) {
// wstring dataPath = NS_File::appDataPath();
@ -524,7 +527,8 @@ void MainWindow::startUninstall()
wstring args = L"/c \"" + m_uninst_cmd;
args += (m_package == L"msi") ? L" /qn\"" : L" /VERYSILENT\"";
m_future = std::async(std::launch::async, [=]() {
if (!NS_File::runProcess(L"cmd", args, true)) {
DWORD status = NS_File::runProcess(L"cmd", args, true);
if (status != 0) {
m_bar->pulse(false);
m_bar->setProgress(0);
m_comntInfoLbl->setText(_TR(LABEL_ERR_UNINST));

View File

@ -278,7 +278,7 @@ namespace NS_Utils
namespace NS_File
{
bool runProcess(const wstring &fileName, const wstring &args, bool runAsAdmin, bool wait)
DWORD runProcess(const wstring &fileName, const wstring &args, bool runAsAdmin, bool wait)
{
SHELLEXECUTEINFO shExInfo = {0};
shExInfo.cbSize = sizeof(shExInfo);
@ -291,12 +291,13 @@ namespace NS_File
shExInfo.nShow = SW_HIDE;
shExInfo.hInstApp = NULL;
if (ShellExecuteEx(&shExInfo)) {
if (wait)
WaitForSingleObject(shExInfo.hProcess, INFINITE);
DWORD exitCode = 0;
if (wait && (WaitForSingleObject(shExInfo.hProcess, INFINITE) == WAIT_FAILED || !GetExitCodeProcess(shExInfo.hProcess, &exitCode)))
exitCode = GetLastError();
CloseHandle(shExInfo.hProcess);
return true;
return exitCode;
}
return false;
return GetLastError() | ERROR_LAUNCH;
}
// bool isProcessRunning(const wstring &fileName)

View File

@ -40,6 +40,7 @@ using std::string;
using std::wstring;
using std::to_wstring;
#define ERROR_LAUNCH 0x20000000
#define DEFAULT_ERROR_MESSAGE _T("An error occurred: ") + \
wstring(_T(__FUNCTION__)) + _T(" Line: ") + to_wstring(__LINE__)
#define ADVANCED_ERROR_MESSAGE DEFAULT_ERROR_MESSAGE + \
@ -65,7 +66,7 @@ wstring MsiProductCode(const wstring &prodName);
namespace NS_File
{
bool runProcess(const wstring &fileName, const wstring &args, bool runAsAdmin = false, bool wait = true);
DWORD runProcess(const wstring &fileName, const wstring &args, bool runAsAdmin = false, bool wait = true);
// bool isProcessRunning(const wstring &fileName);
bool fileExists(const wstring &filePath);
bool removeFile(const wstring &filePath);