mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
Windows fix UTF-16 output when reporting unhandled exceptions
This commit is contained in:
parent
b1982eb6b0
commit
e73f7da330
@ -27,12 +27,15 @@ int calibre_show_python_error(const wchar_t *preamble, int code);
|
|||||||
|
|
||||||
static int _show_error(const wchar_t *preamble, const wchar_t *msg, const int code) {
|
static int _show_error(const wchar_t *preamble, const wchar_t *msg, const int code) {
|
||||||
static wchar_t buf[4096];
|
static wchar_t buf[4096];
|
||||||
|
static char utf8_buf[4096] = {0};
|
||||||
fwprintf(stderr, L"%s\r\n %s (Error Code: %d)\r\n", preamble, msg, code);
|
int n = WideCharToMultiByte(CP_UTF8, 0, preamble, -1, utf8_buf, sizeof(utf8_buf) - 1, NULL, NULL);
|
||||||
|
if (n > 0) fprintf(stderr, "%s\r\n ", utf8_buf);
|
||||||
|
n = WideCharToMultiByte(CP_UTF8, 0, msg, -1, utf8_buf, sizeof(utf8_buf) - 1, NULL, NULL);
|
||||||
|
if (n > 0) fprintf(stderr, "%s (Error Code: %d)\r\n ", utf8_buf, code);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
|
|
||||||
if (GUI_APP) {
|
if (GUI_APP) {
|
||||||
_snwprintf_s(buf, arraysz(buf), _TRUNCATE, L"%s\r\n %s (Error Code: %d)\r\n", preamble, msg, code);
|
_snwprintf_s(buf, arraysz(buf), _TRUNCATE, L"%ls\r\n %ls (Error Code: %d)\r\n", preamble, msg, code);
|
||||||
MessageBeep(MB_ICONERROR);
|
MessageBeep(MB_ICONERROR);
|
||||||
MessageBox(NULL, buf, NULL, MB_OK|MB_ICONERROR);
|
MessageBox(NULL, buf, NULL, MB_OK|MB_ICONERROR);
|
||||||
}
|
}
|
||||||
@ -106,18 +109,18 @@ get_app_dirw(void) {
|
|||||||
if (sz >= MAX_PATH-1) ExitProcess(_show_error(L"Installation directory path too long", L"", 1));
|
if (sz >= MAX_PATH-1) ExitProcess(_show_error(L"Installation directory path too long", L"", 1));
|
||||||
err = _wsplitpath_s(w_program_name, drive, 4, buf, MAX_PATH, NULL, 0, NULL, 0);
|
err = _wsplitpath_s(w_program_name, drive, 4, buf, MAX_PATH, NULL, 0, NULL, 0);
|
||||||
if (err != 0) ExitProcess(show_last_error_crt(L"Failed to find application directory"));
|
if (err != 0) ExitProcess(show_last_error_crt(L"Failed to find application directory"));
|
||||||
_snwprintf_s(w_app_dir, MAX_PATH, _TRUNCATE, L"%s%s", drive, buf);
|
_snwprintf_s(w_app_dir, MAX_PATH, _TRUNCATE, L"%ls%ls", drive, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_install_locations(void) {
|
get_install_locations(void) {
|
||||||
get_app_dir();
|
get_app_dir();
|
||||||
get_app_dirw();
|
get_app_dirw();
|
||||||
_snwprintf_s(qt_prefix_dir, MAX_PATH-1, _TRUNCATE, L"%s\\app", w_app_dir);
|
_snwprintf_s(qt_prefix_dir, MAX_PATH-1, _TRUNCATE, L"%ls\\app", w_app_dir);
|
||||||
_wputenv_s(L"CALIBRE_QT_PREFIX", qt_prefix_dir);
|
_wputenv_s(L"CALIBRE_QT_PREFIX", qt_prefix_dir);
|
||||||
_snwprintf_s(dll_dir, MAX_PATH-1, _TRUNCATE, L"%s\\app\\bin", w_app_dir);
|
_snwprintf_s(dll_dir, MAX_PATH-1, _TRUNCATE, L"%ls\\app\\bin", w_app_dir);
|
||||||
#if PY_VERSION_MAJOR >= 3
|
#if PY_VERSION_MAJOR >= 3
|
||||||
_snwprintf_s(python_path, MAX_PATH-1, _TRUNCATE, L"%s\\app\\pylib.zip", w_app_dir);
|
_snwprintf_s(python_path, MAX_PATH-1, _TRUNCATE, L"%ls\\app\\pylib.zip", w_app_dir);
|
||||||
#else
|
#else
|
||||||
_snprintf_s(python_path, MAX_PATH-1, _TRUNCATE, "%s\\app\\pylib.zip", app_dir);
|
_snprintf_s(python_path, MAX_PATH-1, _TRUNCATE, "%s\\app\\pylib.zip", app_dir);
|
||||||
#endif
|
#endif
|
||||||
@ -172,7 +175,7 @@ setup_streams() {
|
|||||||
|
|
||||||
UINT
|
UINT
|
||||||
initialize_interpreter(const char *basename, const char *module, const char *function) {
|
initialize_interpreter(const char *basename, const char *module, const char *function) {
|
||||||
DWORD sz; HMODULE dll;
|
HMODULE dll;
|
||||||
int *flag, i, argc;
|
int *flag, i, argc;
|
||||||
wchar_t **wargv;
|
wchar_t **wargv;
|
||||||
PyObject *argv, *v;
|
PyObject *argv, *v;
|
||||||
@ -253,7 +256,7 @@ pyobject_to_wchar(PyObject *o) {
|
|||||||
if (t == NULL) return NULL;
|
if (t == NULL) return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = PyUnicode_AsWideChar(t ? t : o, ans, arraysz(ans)-1);
|
s = PyUnicode_AsWideChar((PyUnicodeObject*)(t ? t : o), ans, arraysz(ans)-1);
|
||||||
Py_XDECREF(t);
|
Py_XDECREF(t);
|
||||||
if (s >= 0) ans[s] = 0;
|
if (s >= 0) ans[s] = 0;
|
||||||
else ans[s] = 0;
|
else ans[s] = 0;
|
||||||
@ -344,7 +347,8 @@ null_invalid_parameter_handler(
|
|||||||
}
|
}
|
||||||
__declspec(dllexport) int __cdecl
|
__declspec(dllexport) int __cdecl
|
||||||
simple_print(const wchar_t *msg) {
|
simple_print(const wchar_t *msg) {
|
||||||
wprintf(L"%s", msg); fflush(stdout);
|
int n = wprintf(L"%ls", msg); fflush(stdout);
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
__declspec(dllexport) int __cdecl
|
__declspec(dllexport) int __cdecl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user