Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menus: Display paths with backslashes properly #1074

Merged
merged 3 commits into from
Mar 23, 2024

Conversation

sonic2kk
Copy link
Owner

Partial fix for #1072.
See also: #1073.

Overview

On various places on the UI, we may display paths with backslashes. This PR is concerned with those paths coming from the Steam Game Launch Options, and the Custom Command arguments, and fixes them by using printf in various ways.

Problem

The problems are as follows:

  • Game Menu
    • Entering a path with backslashes in a custom command argument, such as Z:\this\is\my\path, and then saving, will strip this path of its backslashes, turning it into Z:\thisismypath.
    • This can be worked around by double escaping, but the path would then turn out like this: Z:\\this\\is\\my\\path -> Save -> Path becomes Z:\this\is\my\path -> Save again -> Z:thisismypath - This is because the path is getting stripped of backslashes from the escaping on each save
    • This means each time the Game Menu is opened, paths with backslashes need to be quadruple-escaped before saving.
  • Main Menu
    • Paths coming from Steam with backslashes (with and without quotes) will not display their backslashes properly.
    • Ex: This launch option Z:\this\is\my\path will be displayed on the SteamTinkerLaunch Main Menu as Z:thisismypath.

Solution

This PR fixes these problems in two different ways, both using printf:

  • For the Game Menu, we can use printf "%s" in a subshell when displaying the field for CUSTOMCMD_ARGS. This, for some reason I don't fully understand, fixes displaying and thus saving the paths with backslashes correctly. They are no longer mangled.
  • For the Main Menu, we can use printf "%q", which is an option that preserves strings to be used as part of a command. This handles our double-escaping for display purposes
    • We cannot use %q for the Game Menu because then the double-escapes (and the escape around any other parts of the launch command) would be displayed, which would also result in the commands not launching correctly.

Note that paths going as arguments to custom commands may need to be double-escaped, as they don't have quotes. This PR corrects the display and saving of these paths, and #1073 fixes the paths so that they are double-escaped.

Fwiw, Proton doesn't seem to get quotes for launch arguments either though (#1072 (comment)) so I think this is acceptable.

@sonic2kk sonic2kk added the shellcheck Run ShellCheck workflow against PR label Mar 23, 2024
@sonic2kk sonic2kk removed the shellcheck Run ShellCheck workflow against PR label Mar 23, 2024
@sonic2kk sonic2kk force-pushed the customcmd-args-backslash-fix branch from 637ca38 to 0dc87e0 Compare March 23, 2024 02:39
@sonic2kk
Copy link
Owner Author

Uh oh, we're running the CI twice... We can probably remove the PR one...

Fix CUSTOMCMD_ARGS with Windows paths using backslashes
getting mangled on save, from Yad stripping the '\' character.

We fix this by using `printf` in a subshell, which for
some reason allows Yad to read and thus save the path
correctly.
@sonic2kk sonic2kk force-pushed the customcmd-args-backslash-fix branch from 0dc87e0 to eace9b3 Compare March 23, 2024 02:41
@sonic2kk
Copy link
Owner Author

Tested by me and @zany130 in #1072, appears to work as expected, so merging!

@sonic2kk sonic2kk merged commit bedf6e7 into master Mar 23, 2024
1 check passed
@sonic2kk sonic2kk deleted the customcmd-args-backslash-fix branch March 24, 2024 04:00
@sonic2kk sonic2kk linked an issue Mar 24, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to pass windows paths to custom commands
1 participant