Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Hide the splash window before we show a setup error message
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Aug 31, 2021
1 parent e52cfc1 commit b9ab4a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 9 additions & 6 deletions src/Setup/UpdateRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand All @@ -197,7 +198,8 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback
_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;
Expand Down Expand Up @@ -268,12 +270,12 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback

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);
Expand All @@ -290,9 +292,10 @@ int CUpdateRunner::ExtractUpdaterAndRun(wchar_t* lpCommandLine, bool useFallback
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;
}
4 changes: 3 additions & 1 deletion src/Setup/UpdateRunner.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#pragma once
#include <functional>

class CUpdateRunner
{

Expand All @@ -8,5 +10,5 @@ class CUpdateRunner
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);
};
4 changes: 2 additions & 2 deletions src/Setup/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit b9ab4a9

Please sign in to comment.