Shortcuts: Clean up code and fix bugs
Description of Changes
Large rewrite of ShortcutCreationDialog.cpp. The UI file was fine already.
- Rename
titleandnametogame_titlefor consistency and clarity.- Renamed
pathtogame_pathfor the same reason.
- Renamed
- Move a long series of conditionals into a function called
FillArgumentsList().- Only called once, but it's nice for organization.
- Fix an issue where the load save state from file functionality wasn't working.
- This was never being loaded into the CLI argument list.
- Split
EscapeShortcutCommandLine()intoEscapeShortcutCommandLineWindows()andEscapeShortcutCommandLineLinux().- Totally different functions with no interleaving and only ever called within WIN32 or Linux-specific code.
- Remove the return value for
EscapeShortcutCommandLineWindows(), as it always returnedtrue.
- Pass the string vector
launch_argumentsby reference instead of by value. - In Windows, use
SHGetKnownFolderPathto get desktop or start menu directory.- Safer and more elegant than hardcoding a path.
- Hopefully improves the situation in #13455, but no guarantees.
- Rearrange some of the Linux logic to be more efficient and readable.
- For AppImage, when copying icon, check if copied icon already exists first.
- It should exist if a shortcut has already been made before).
- Changed "Failed to create shortcut" if escape not lossless to "Problem creating shortcut".
- We already treat this as a warning and continue rather than a critical failure and return.
- Moved the invalid game title and empty path logic into the constructor.
- There's no reason to let a user select options if we know 100% for certain it will fail.
- Move Windows and Linux shortcut creation functionality into
FileSystem.cpp.- This is more generalizable functionality than just creating a game shortcut.
- Windows stuff is relatively advanced for what
ShortcutCreationDialog.cppis doing.
- Add a description to both Linux and Windows.
- For Linux, this'll show up on hover for desktop and as a subtitle for the Application Launcher.
- On Windows, this'll be show up as hover text only.
- Sanitize override ELF and load state file paths to real path and native separators.
- They were being escaped before, but that's it.
- "Path::ToNativePath" seriously needs to be renamed.
- Ideally to "Path::ToNativeSeparators" or "Path::ToNativePathSeparators".
- It's a terribly ambiguous name for no reason.
- Moves some setEnabled/setChecked logic in the dialog from
.cppto.ui.- These are entirely unconditional after UI setup.
- UI setup in the
.cppshould only be reserved for conditional or variable behavior.
Screenshots
What this did not change
EscapeShortcutCommandLineWindows() and EscapeShortcutCommandLineLinux() are basically left entirely alone. I can make a PR for them in the future, but the hurdle preventing me from touching them in this one is that they're totally undocumented and ad hoc workarounds for OS-specific quirks. I'd therefore prefer to quarantine that to a separate PR so any mistakes I make are self-contained.
Suggested Testing Steps
- Make sure shortcut creation and the various options still work on Windows and Linux.
- Make sure that choosing a file for the save state now works.
Please pay especially close attention to the Windows logic, as I am not presently able to test it.
Did you use AI to help find, test, or implement this issue or feature?
No.
You still haven't run clang-format.
Did a bit of cleanup of my own just now and then ran clang-format on the lines I touched in FileSystem.cpp and FileSystem.h to avoid some of clang-format's ugly, rigid bodges. ShortcutCreationDialog.cpp and ShortcutCreationDialog.h had clang-format run on them already.
Oh also here's some documentation on the command line escaping:
- https://specifications.freedesktop.org/desktop-entry/latest/exec-variables.html
- https://learn.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way
You can add these links as comments if you want.
Needs testing on Windows
In Windows, use
SHGetKnownFolderPathto get desktop or start menu directory.
This could be done for Linux desktops as well. The logic for that would be:
If $XDG_DATA_HOME is not null, then save to $XDG_DATA_HOME/applications
Else save the .desktop file to ~/.local/share/applications
I think you could confidently write directly to those folders (creating them if they don't exist) - but if not, you could trigger a filepicker to appear that is pointing to those folders, just as PCSX2 is doing now.
More details on the Arch Wiki. While I don't use the distribution myself, I can confirm this is true across Debian, Ubuntu and Fedora.