Menus: Display paths with backslashes properly #1074
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Z:\this\is\my\path
, and then saving, will strip this path of its backslashes, turning it intoZ:\thisismypath
.Z:\\this\\is\\my\\path
-> Save -> Path becomesZ:\this\is\my\path
-> Save again ->Z:thisismypath
- This is because the path is getting stripped of backslashes from the escaping on each saveZ:\this\is\my\path
will be displayed on the SteamTinkerLaunch Main Menu asZ:thisismypath
.Solution
This PR fixes these problems in two different ways, both using
printf
:printf "%s"
in a subshell when displaying the field forCUSTOMCMD_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.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%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.