From 4b0f19ccfb4cee58b751622da0fd58a15aaa9d69 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 17 Nov 2020 11:42:54 +0530 Subject: [PATCH] Windows: Fix calibre portable launcher not working correctly from root directory in calibre 5.5. Fixes #1904310 [v5.5 Puts calibre-portable.exe in as a book on every launch](https://bugs.launchpad.net/calibre/+bug/1904310) apparently, the cmdline parameter passed to winmain does not contain the path to the EXE *except* when the exe is in the root folder. The number of inconsistencies in the win32 API is insane. --- bypy/windows/portable.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bypy/windows/portable.cpp b/bypy/windows/portable.cpp index a34cb902e0..d1ca1767d4 100644 --- a/bypy/windows/portable.cpp +++ b/bypy/windows/portable.cpp @@ -222,15 +222,14 @@ wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR orig_cmd_line, int config_dir.append(application_dir); config_dir.append(L"Calibre Settings"); exe.append(application_dir); exe.append(L"Calibre\\"); exe.append(exe_name); - // Note that orig_cmd_line does not have argv[0] as the executable name int argc; - wchar_t **argv = CommandLineToArgvW(orig_cmd_line, &argc); + wchar_t **argv = CommandLineToArgvW(GetCommandLineW(), &argc); if (argv == NULL) { show_last_error(L"Failed to convert cmdline to argv array"); return 1; } quote_argv(exe, cmd_line); - for (int i = 0; i < argc; i++) { + for (int i = 1; i < argc; i++) { std::wstring arg(argv[i]); cmd_line.push_back(L' '); quote_argv(arg, cmd_line);