Custom Install Directory: Use Inline if
for Safer Default Launcher Selection
#371
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.
Fix #370.
Almost forewent my usual PR format, but that would be no fun, right? 😉
Overview
Changes the check in the Custom Install Dialog that selects the default launcher to use an inline
if
, which fixes a crash ifself.launcher
is not a key inself.install_locations_dict
. This currently occurs when there are no available launchers installed. We get aKeyError
if no launchers are found, becauseself.launcher
is not a valid key inself.install_locations_dict
.Problem
Apparently, in Python,
dictionary[key] or 'value'
will result in aKeyError
ifkey
is not defined. However in other cases, this does not happen. For example with an inlineif
I guess the conditional gets parsed first, like a "full"if
, so you can dodictionary[key] if key in dictionary else 'value'
safely, as Python won't process thedictionary[key]
first. Makes sense having thought it through (you wouldn't wantprint('hello') if condition else print ('goodbye')
to printhello
, socondition
has to be processed fiirst), but tripped me up a little.How to Replicate Error
You can test this fix by forcefully returning False at the beginning if
util#is_valid_launcher_installation
. This will result in ProtonUp-Qt not finding any launchers. Onmain
, opening the Custom Install Directory dialog will give a crash. With this change, it should work correctly.I did some testing and this prevents the crash, and the crash I was encountering matches the one described in #370 (
KeyError: ''
and noting line 53, where this fix is implemented). I am very confident this is the cause of the crash. What I am not sure of is how no Steam installation was found in #370. For some reason this seems to be coming up more in recent months for no clear reason...Future Work
There are some UIX issues I'd like to tackle in separate PRs that won't depend on the changes here. For example, adding a custom install directory will not immediately find all compatibility tools, you have to restart the launcher. If you force no launchers to be found and then add a valid path to a Steam installation's
compatibilitytools.d
, you have to restart ProtonUp-Qt for any tools to display.Small change, big PR description 😅
Thanks!