pcsx2 icon indicating copy to clipboard operation
pcsx2 copied to clipboard

Shortcuts: Clean up code and fix bugs

Open TheTechnician27 opened this issue 2 months ago • 3 comments

Description of Changes

Large rewrite of ShortcutCreationDialog.cpp. The UI file was fine already.

  • Rename title and name to game_title for consistency and clarity.
    • Renamed path to game_path for the same reason.
  • 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() into EscapeShortcutCommandLineWindows() and EscapeShortcutCommandLineLinux().
    • 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 returned true.
  • Pass the string vector launch_arguments by reference instead of by value.
  • In Windows, use SHGetKnownFolderPath to 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.cpp is 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 .cpp to .ui.
    • These are entirely unconditional after UI setup.
    • UI setup in the .cpp should only be reserved for conditional or variable behavior.

Screenshots

image image

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.

TheTechnician27 avatar Nov 02 '25 05:11 TheTechnician27

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.

TheTechnician27 avatar Nov 09 '25 15:11 TheTechnician27

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.

chaoticgd avatar Nov 29 '25 23:11 chaoticgd

Needs testing on Windows

F0bes avatar Dec 05 '25 15:12 F0bes

In Windows, use SHGetKnownFolderPath to 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.

superuser-does avatar Dec 14 '25 21:12 superuser-does