@@ -19,25 +19,25 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
19
19
std::wstring exeDir = exePath;
20
20
exeDir = exeDir.substr (0 , exeDir.find_last_of (L" \\ /" ));
21
21
22
- // Get command line string
22
+ // Get command line string and extract arguments
23
23
LPWSTR commandLine = GetCommandLineW ();
24
- // Skip the current executable path and name
25
24
std::wstring args;
26
- if (commandLine) {
27
- // If path is double quoted, skip the entire double quote
28
- if (commandLine[0 ] == L' "' ) {
29
- LPWSTR closingQuote = wcschr (commandLine + 1 , L' "' );
30
- if (closingQuote) {
31
- args = closingQuote + 1 ; // Skip closing quote and space
32
- }
33
- // Otherwise skip to first space
34
- } else {
35
- LPWSTR spacePos = wcschr (commandLine, L' ' );
36
- if (spacePos) {
37
- args = spacePos + 1 ; // GetCommandLineW puts 2 spaces when path isn't double quoted
38
- }
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 ;
39
36
}
40
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
41
42
42
// Define the path to the "scripts" directory
43
43
std::wstring scriptsDir = exeDir + L" \\ scripts" ;
@@ -60,7 +60,7 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
60
60
// Define the command to run and append arguments if present
61
61
std::wstring target;
62
62
if (!args.empty ()) {
63
- target = L" cmd.exe /c \"\" " LAUNCH_TARGET L" \" " + args + L" \" " ;
63
+ target = L" cmd.exe /c \"\" " LAUNCH_TARGET L" \" " + args + L" \" " ;
64
64
} else {
65
65
target = L" cmd.exe /c \" " LAUNCH_TARGET L" \" " ;
66
66
}
0 commit comments