diff --git a/setup/installer/windows/file_dialogs.cpp b/setup/installer/windows/file_dialogs.cpp index 43e3d488fc..5ea61a01a5 100644 --- a/setup/installer/windows/file_dialogs.cpp +++ b/setup/installer/windows/file_dialogs.cpp @@ -94,7 +94,7 @@ static void print_com_error(HRESULT hr, const char *msg) { int sz = 0; const char *buf = to_utf8(emsg, &sz); if (buf == NULL) { fprintf(stderr, "%s", msg); } - else { fprintf(stderr, "%s: (HRESULT=0x%x) %s\n", msg, hr, emsg); } + else { fprintf(stderr, "%s: (HRESULT=0x%x) %s\n", msg, hr, buf); } fflush(stderr); } @@ -188,7 +188,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine HWND parent = NULL; bool save_dialog = false, multiselect = false, confirm_overwrite = false, only_dirs = false, no_symlinks = false; unsigned short len = 0; - LPWSTR title = NULL, folder = NULL, filename = NULL, save_path = NULL; + LPWSTR title = NULL, folder = NULL, filename = NULL, save_path = NULL, echo = NULL; COMDLG_FILTERSPEC *file_types = NULL; UINT num_file_types = 0; @@ -208,7 +208,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine READ(sizeof(HWND), buf); if (sizeof(HWND) == 8) parent = (HWND)*((__int64*)buf); else if (sizeof(HWND) == 4) parent = (HWND)*((__int32*)buf); - else { fprintf(stderr, "Unknown pointer size: %d", sizeof(HWND)); fflush(stderr); return 1;} + else { fprintf(stderr, "Unknown pointer size: %zd", sizeof(HWND)); fflush(stderr); return 1;} } else if CHECK_KEY("TITLE") { READSTR(title) } @@ -231,11 +231,20 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine else if CHECK_KEY("FILE_TYPES") { file_types = read_file_types(&num_file_types); if (file_types == NULL) return 1; } + else if CHECK_KEY("ECHO") { READSTR(echo) } + else { PRINTERR("Unknown key"); return 1; } } + if (echo != NULL) { + int echo_sz = 0; + char *echo_buf = to_utf8(echo, &echo_sz); + fprintf(stdout, "%s", echo_buf); + return 0; + } + return show_dialog(parent, save_dialog, title, folder, filename, save_path, multiselect, confirm_overwrite, only_dirs, no_symlinks, file_types, num_file_types); } diff --git a/src/calibre/gui2/win_file_dialogs.py b/src/calibre/gui2/win_file_dialogs.py index bf9938b286..8e91343cd6 100644 --- a/src/calibre/gui2/win_file_dialogs.py +++ b/src/calibre/gui2/win_file_dialogs.py @@ -151,8 +151,18 @@ def run_file_dialog( ans = tuple((os.path.abspath(x.decode('utf-8')) for x in h.stdoutdata.split(b'\0') if x)) return ans +def test(): + p = subprocess.Popen([HELPER], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE) + echo = '\U0001f431 Hello world!' + stdout, stderr = p.communicate(serialize_string('ECHO', echo)) + if p.wait() != 0: + raise Exception('File dialog failed: ' + stderr.decode('utf-8')) + if stdout.decode('utf-8') != echo: + raise RuntimeError('Unexpected response: %s' % stdout.decode('utf-8')) + if __name__ == '__main__': HELPER = sys.argv[-1] + test() app = QApplication([]) q = QMainWindow() _ = lambda x: x diff --git a/src/calibre/test_build.py b/src/calibre/test_build.py index 51bdf93cad..ed99d09bf6 100644 --- a/src/calibre/test_build.py +++ b/src/calibre/test_build.py @@ -177,6 +177,11 @@ def test_imaging(): raise RuntimeError('PIL choked!') fprint('PIL OK!') +def test_file_dialog_helper(): + from calibre.gui2.win_file_dialogs import test + test() + print('File dialog helper OK!') + def test_unrar(): from calibre.utils.unrar import test_basic test_basic() @@ -304,6 +309,7 @@ def test(): if iswindows: test_wpd() test_winutil() + test_file_dialog_helper() else: test_terminal() if isosx: