Nicer error message when loading the Universal CRT fails

This commit is contained in:
Kovid Goyal 2015-12-11 01:07:56 +05:30
parent 897a1a137e
commit 963b0eeea6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -58,38 +58,52 @@ static ENTRYPROC load_launcher_dll() {
int i = 0; int i = 0;
DWORD sz = 0; DWORD sz = 0;
HMODULE dll = 0; HMODULE dll = 0;
ENTRYPROC entrypoint = 0; ENTRYPROC entrypoint = NULL;
if ((sz = GetModuleFileNameW(NULL, buf, MAX_PATH)) >= MAX_PATH - 30) if ((sz = GetModuleFileNameW(NULL, buf, MAX_PATH)) >= MAX_PATH - 30) {
ExitProcess(show_error(L"Installation directory path too long", L"", 1)); show_error(L"Installation directory path too long", L"", 1);
return NULL;
}
while (sz > 0) { while (sz > 0) {
if (buf[sz] == L'\\' || buf[sz] == L'/') break; if (buf[sz] == L'\\' || buf[sz] == L'/') break;
sz--; sz--;
} }
if (sz <= 0) if (sz <= 0) {
ExitProcess(show_error(L"Executable path has no path separators", L"", 1)); 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+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+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; buf[sz+9] = 0; buf[sz+10] = 0;
if (SetDllDirectoryW(buf) == 0) { if (SetDllDirectoryW(buf) == 0) {
show_last_error(L"Failed to set DLL directory"); 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; return entrypoint;
} }
int __stdcall start_here() { int __stdcall start_here() {
int ret = 0; int ret = 0;
ENTRYPROC entrypoint = load_launcher_dll();
if (!entrypoint) return 1;
#ifdef GUI_APP #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. // 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 #else
ret = load_launcher_dll()(BASENAME, MODULE, FUNCTION, 0); ret = entrypoint(BASENAME, MODULE, FUNCTION, 0);
#endif #endif
ExitProcess(ret); ExitProcess(ret);
return ret; return ret;