Skip to content

Commit 5544f46

Browse files
authored
Merge pull request #1572 from firai/add-win-launcher-args
Forward command line arguments for window launchers
2 parents a16cca7 + 4a624c6 commit 5544f46

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

portable/launchers_src/launcher_template_WINDOWS.cpp

+27-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
1919
std::wstring exeDir = exePath;
2020
exeDir = exeDir.substr(0, exeDir.find_last_of(L"\\/"));
2121

22+
// Get command line string and extract arguments
23+
LPWSTR commandLine = GetCommandLineW();
24+
std::wstring args;
25+
// If executable path is double quoted, skip the entire quoted section
26+
if (commandLine[0] == L'"') {
27+
LPWSTR closingQuote = wcschr(commandLine + 1, L'"');
28+
if (closingQuote) {
29+
args = closingQuote + 1;
30+
}
31+
// For non-quoted path, skip to character after first space if it exists
32+
} else {
33+
LPWSTR spacePos = wcschr(commandLine, L' ');
34+
if (spacePos) {
35+
args = spacePos + 1;
36+
}
37+
}
38+
// Strip leading whitespace
39+
size_t args_start = args.find_first_not_of(L" ");
40+
args = (args_start != std::wstring::npos) ? args.substr(args_start) : L"";
41+
2242
// Define the path to the "scripts" directory
2343
std::wstring scriptsDir = exeDir + L"\\scripts";
2444

@@ -37,8 +57,13 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
3757
return 1;
3858
}
3959

40-
// Define the command to run
41-
std::wstring target = L"cmd.exe /c \"" LAUNCH_TARGET L"\"";
60+
// Define the command to run and append arguments if present
61+
std::wstring target;
62+
if (!args.empty()) {
63+
target = L"cmd.exe /c \"\"" LAUNCH_TARGET L"\" " + args + L"\"";
64+
} else {
65+
target = L"cmd.exe /c \"" LAUNCH_TARGET L"\"";
66+
}
4267

4368
// Configure the process startup info
4469
STARTUPINFO si = { sizeof(si) };

0 commit comments

Comments
 (0)