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.
This commit is contained in:
Kovid Goyal 2020-11-17 11:42:54 +05:30
parent fbbb8ffdf5
commit 4b0f19ccfb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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);