mmatyas / pegasus-frontend

A cross platform, customizable graphical frontend for launching emulators and managing your game collection.
http://pegasus-frontend.org
Other
1.17k stars 104 forks source link

Shortcuts do not accept arguments #1084

Closed miguelguzmanr closed 4 months ago

miguelguzmanr commented 8 months ago

The issue

Unable to open a shortcut with arguments. Most likely because the cmd command interpreter expects a single quoted string but receives two quoted strings instead.

explorer_E2fbc19PWv

System info

Edition: Windows 11 Pro Version: 23H2 OS build 22631.2506 Experience Windows Feature Experience Pack 1000.22677.1000.0

Pegasus version

pegasus-fe_alpha16-67-g40b9b63a_win-mingw-static

Pegasus log

2023-11-06T02:05:29 [i] Executing command: [cmd,/q,/c,E:/Emulation/Emulators/Nintendo - Game Boy Advance/Default.lnk,E:\Emulation\ROMs\Nintendo - Game Boy Advance\Astro Boy - Omega Factor (USA) (En,Ja,Fr,De,Es,It).zip] 2023-11-06T02:05:29 [i] Working directory: E:\Emulation\ROMs\Nintendo - Game Boy Advance 2023-11-06T02:05:29 [i] Process 23424 started 2023-11-06T02:05:29 [i] ---------------------------------------- 2023-11-06T02:05:30 [i] ---------------------------------------- 2023-11-06T02:05:30 [w] The external program has finished with error code 1

mmatyas commented 8 months ago

Hi, I don't think shortcuts support external arguments; it's not an issue specific to Pegasus. The shortcut itself contains the program and the arguments, which you can set on the shortcut properties panel. For example:

p40rgh4d27581

miguelguzmanr commented 8 months ago

@mmatyas Thank you kindly for the insightful explanation. I understand I may have misworded the situation.

Essentially, I'm trying to open a file (rom) using a shortcut (emulator), instead of an executable program. The equivalent command would be "path/to/shorcut.lnk" "path/to/file.zip", e.g.

"E:\Emulation\Emulators\Nintendo - Game Boy Advance\Default.lnk" "E:\Emulation\ROMs\Nintendo - Game Boy Advance\Advance Guardian Heroes (USA).zip"

The thing is, in Windows, Pegasus gives shortcuts a special treatment by prefacing them with: cmd /q /c See: ProcessLauncher.cpp#L203

The parameter /c expects only one string argument (See: cmd), so when Pegasus parses the following launch option: launch: "path/to/shortcut" "{file.path}" it gets translated into cmd /q /c "path/to/shortcut" "{file.path}"

Which then errors out, as the second quoted string "{file.path}" is not expected by the /c parameter which in turn results in a strange parsing behavior.

E:\>cmd /q /c "E:\Emulation\Emulators\Nintendo - Game Boy Advance\Default.lnk" "E:\Emulation\ROMs\Nintendo - Game Boy Advance\Advance Guardian Heroes (USA).zip"
'E:\Emulation\Emulators\Nintendo' is not recognized as an internal or external command,
operable program or batch file.

In this scenario, the correct behavior should be to wrap the string in another set of double quotes. The following works as expected:

E:\>cmd /q /c ""E:\Emulation\Emulators\Nintendo - Game Boy Advance\Default.lnk" "E:\Emulation\ROMs\Nintendo - Game Boy Advance\Advance Guardian Heroes (USA).zip""

This isn't possible to do in the launch option, as the the first occurrence of two consecutive double quotation marks gets treated as an empty string (understandable).

launch: ""E:\Emulation\Emulators\Nintendo - Game Boy Advance\Default.lnk" "{file.path}""

image

Using escape sequences also results in a strange parsing behaviour.

launch: "\"E:\Emulation\Emulators\Nintendo - Game Boy Advance\Default.lnk\" \"{file.path}\""

lastrun.log

2023-11-08T16:02:33 [i] Executing command: [`E:\`,`E:\Emulation\Emulators\Nintendo`,`-`,`Game`,`Boy`,`Advance\Default.lnk\"`,`\"E:\Emulation\ROMs\Nintendo - Game Boy Advance\Advance Guardian Heroes (USA).zip\""`]
2023-11-08T16:02:33 [i] Working directory: `E:\`
2023-11-08T16:02:33 [w] Could not launch `E:/`. Either the program is missing, or you don't have the permission to run it.

Hopefully this sets a better ground of the issue at hand. I understand this may be Windows specific. Please let me know if there's anything I can help with.

mmatyas commented 7 months ago

Interesting! This does sound like a valid issue, though shortcuts are already surprisingly troublesome to handle (hence the special cmd call). The workaround would be to call directly the program pointed by the shortcut; is there a particular where that is not possible for your case? When launching a game from the command line, what happens when your game contains several " and ' characters (eg. 3-4 each)? Instead of escaping in the metadata file, have you tried using ' for surrounding the whole last part of the command?

miguelguzmanr commented 7 months ago

I chose shortcuts because it enables some customization by launching an executable program using preset arguments e.g. launch Dolphin with a specific user profile.

After some more testing, the workaround I've found is to use the workdir option. So the following setup works as expected:

launch: Default.lnk {file.path}
workdir: E:\Emulation\Emulators\Nintendo - Game Boy Advance
2023-11-12T18:39:22 [i] Executing command: [`cmd`,`/q`,`/c`,`Default.lnk`,`E:\Emulation\ROMs\Nintendo - Game Boy Advance\Advance Guardian Heroes (USA).zip`]
2023-11-12T18:39:22 [i] Working directory: `E:\Emulation\Emulators\Nintendo - Game Boy Advance`
2023-11-12T18:39:22 [i] Process 20412 started
2023-11-12T18:39:22 [i] ----------------------------------------
2023-11-12T18:40:30 [i] ----------------------------------------
2023-11-12T18:40:30 [i] The external program has finished cleanly

With that said, placing the shortcut in the same folder as the metadata.txt is the solution I went with (removing the need for a workdir option).

I guess the issue is related to having spaces in the shortcut's path.

I greatly appreciate your help Mátyás. Thank you very much for your trouble. Please feel free to close this issue.