From 963b0eeea6ec10b7cceacdde920610f5455158c0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 11 Dec 2015 01:07:56 +0530 Subject: [PATCH] Nicer error message when loading the Universal CRT fails --- setup/installer/windows/main.c | 38 +++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/setup/installer/windows/main.c b/setup/installer/windows/main.c index 4cb2818fb3..18a64b33dc 100644 --- a/setup/installer/windows/main.c +++ b/setup/installer/windows/main.c @@ -58,38 +58,52 @@ static ENTRYPROC load_launcher_dll() { int i = 0; DWORD sz = 0; HMODULE dll = 0; - ENTRYPROC entrypoint = 0; + ENTRYPROC entrypoint = NULL; - if ((sz = GetModuleFileNameW(NULL, buf, MAX_PATH)) >= MAX_PATH - 30) - ExitProcess(show_error(L"Installation directory path too long", L"", 1)); + if ((sz = GetModuleFileNameW(NULL, buf, MAX_PATH)) >= MAX_PATH - 30) { + show_error(L"Installation directory path too long", L"", 1); + return NULL; + } while (sz > 0) { if (buf[sz] == L'\\' || buf[sz] == L'/') break; sz--; } - if (sz <= 0) - ExitProcess(show_error(L"Executable path has no path separators", L"", 1)); + if (sz <= 0) { + show_error(L"Executable path has no path separators", L"", 1); + return NULL; + } buf[sz+1] = L'a'; buf[sz+2] = L'p'; buf[sz+3] = L'p'; buf[sz+4] = L'\\'; buf[sz+5] = L'D'; buf[sz+6] = L'L'; buf[sz+7] = L'L'; buf[sz+8] = L's'; buf[sz+9] = 0; buf[sz+10] = 0; if (SetDllDirectoryW(buf) == 0) { show_last_error(L"Failed to set DLL directory"); - ExitProcess(1); + return NULL; + } + if (!LoadLibraryW(L"ucrtbase.dll")) { + show_last_error(L"Unable to find ucrtbase.dll. You should install all Windows updates on your computer to get this file."); + return NULL; + } + if (!(dll = LoadLibraryW(L"calibre-launcher.dll"))) { + show_last_error(L"Failed to load: calibre-launcher.dll"); + return NULL; + } + if (!(entrypoint = (ENTRYPROC) GetProcAddress(dll, "execute_python_entrypoint"))) { + show_last_error(L"Failed to get the calibre-launcher dll entry point"); + return NULL; } - dll = LoadLibraryW(L"calibre-launcher.dll"); - if (!dll) ExitProcess(show_last_error(L"Failed to get the calibre-launcher dll handle")); - entrypoint = (ENTRYPROC) GetProcAddress(dll, "execute_python_entrypoint"); - if (!entrypoint) ExitProcess(show_last_error(L"Failed to get the calibre-launcher dll entry point")); return entrypoint; } int __stdcall start_here() { int ret = 0; + ENTRYPROC entrypoint = load_launcher_dll(); + if (!entrypoint) return 1; #ifdef GUI_APP // This should really be returning the value set in the WM_QUIT message, but I cannot be bothered figuring out how to get that. - load_launcher_dll()(BASENAME, MODULE, FUNCTION, 1); + entrypoint(BASENAME, MODULE, FUNCTION, 1); #else - ret = load_launcher_dll()(BASENAME, MODULE, FUNCTION, 0); + ret = entrypoint(BASENAME, MODULE, FUNCTION, 0); #endif ExitProcess(ret); return ret;