Hide the splash window before we show a setup error message

This commit is contained in:
Caelan Sayler
2021-08-31 22:18:36 +01:00
parent e52cfc1526
commit b9ab4a9336
3 changed files with 14 additions and 9 deletions

View File

@@ -147,13 +147,14 @@ bool CUpdateRunner::DirectoryIsWritable(wchar_t * szPath)
return true;
}
int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir)
int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir, std::function<void()>& callback)
{
PROCESS_INFORMATION pi = { 0 };
STARTUPINFO si = { 0 };
CResource zipResource;
wchar_t targetDir[MAX_PATH] = { 0 };
wchar_t logFile[MAX_PATH];
DWORD dwExitCode = 0;
std::vector<CString> to_delete;
@@ -183,8 +184,8 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback
if (!CreateDirectory(targetDir, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
wchar_t err[4096];
_swprintf_c(err, _countof(err), L"Unable to write to %s - IT policies may be restricting access to this folder", targetDir);
callback();
DisplayErrorMessage(CString(err), NULL);
return -1;
}
@@ -197,7 +198,8 @@ gotADir:
_swprintf_c(err, _countof(err), L"Unable to write to %s - IT policies may be restricting access to this folder", targetDir);
if (useFallbackDir) {
DisplayErrorMessage(CString(err), NULL);
callback();
DisplayErrorMessage(CString(err), NULL);
}
goto failedExtract;
@@ -268,12 +270,12 @@ gotADir:
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD dwExitCode;
if (!GetExitCodeProcess(pi.hProcess, &dwExitCode)) {
dwExitCode = (DWORD)-1;
}
if (dwExitCode != 0) {
callback();
DisplayErrorMessage(CString(
L"There was an error while installing the application. "
L"Check the setup log for more information and contact the author."), logFile);
@@ -290,9 +292,10 @@ gotADir:
failedExtract:
if (!useFallbackDir) {
// Take another pass at it, using C:\ProgramData instead
return ExtractUpdaterAndRun(lpCommandLine, true);
return ExtractUpdaterAndRun(lpCommandLine, true, callback);
}
DisplayErrorMessage(CString(L"Failed to extract installer"), NULL);
callback();
DisplayErrorMessage(CString(L"Failed to extract installer"), NULL);
return (int) dwExitCode;
}

View File

@@ -1,4 +1,6 @@
#pragma once
#include <functional>
class CUpdateRunner
{
@@ -8,5 +10,5 @@ public:
static HRESULT ShellExecuteFromExplorer(LPWSTR pszFile, LPWSTR pszParameters);
static bool DirectoryExists(wchar_t* szPath);
static bool DirectoryIsWritable(wchar_t* szPath);
static int ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir);
static int ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallbackDir, std::function<void()>& callback);
};

View File

@@ -89,6 +89,7 @@ int APIENTRY wWinMain(
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
CSplashWnd splash;
std::function<void()> closeSplashFn([&]() { splash.Hide(); });
bool isQuiet = (cmdLine.Find(L"-s") >= 0);
bool weAreUACElevated = CUpdateRunner::AreWeUACElevated() == S_OK;
@@ -163,12 +164,11 @@ int APIENTRY wWinMain(
goto out;
}
// TODO: hide splash before setup error is shown
splash.SetImage(MAKEINTRESOURCE(IDR_SPLASH_IMG), L"DATA");
splash.Show();
// run updater
exitCode = CUpdateRunner::ExtractUpdaterAndRun(lpCmdLine, false);
exitCode = CUpdateRunner::ExtractUpdaterAndRun(lpCmdLine, false, closeSplashFn);
out:
splash.Hide();