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

Lutris: Allow checking data directory for game configs #497

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sonic2kk
Copy link
Contributor

@sonic2kk sonic2kk commented Mar 4, 2025

Fixes #495.

Overview

This PR addresses two issues with how we currently fetch game config files for Lutris, which is used to display the CtInfo dialog and Games List dialog.

I tested this change on my laptop (uses the newer ~/.local/share/lutris/games path), and this PR fixes the crash in #495 and finds the game config for the one game I have installed (GE-Proton9-25 for Battlenet displays properly in the Games List and CtInfo dialog). I have also tested this setup on my Desktop PC (uses the older ~/.config/lutris/games path), which works correctly and displays the same games with and without this change.

Problem

Currently, we check for games in the ~/.config/lutris/games folder and that folder only. However, we assume that if we get a Lutris config folder back at all from self.install_loc.get('config_dir'), then we will have a ~/.config/lutris/games. However this is not the case. So if ~/.config/lutris/games does not exist, there will be a crash when attempting to call os.listdir on that folder. This crash was the reason for opening #495.

However this was a symptom of another problem: Lutris no longer uses ~/.config/lutris/games by default and instead will use ~/.local/share/lutris for new installations. This is why I was experiencing the crash described, because my Lutris game config folder was at ~/.local/share/lutris on my laptop but at ~/.config/lutris on my Desktop PC.

The Lutris codebase has a comment noting that ~/.config/lutris is deprecated: https://github.com/lutris/lutris/blob/6b968e858955c0638bf93b3a72fec5ae650f0932/lutris/settings.py#L20-L25

So the overall problem was that:

  • We were making an assumption that ~/.config/lutris/games would always exist, which is not the case.
  • Lutris also no longer uses this folder, and instead we also need to check for ~/.local/share/lutris/games which is the newer folder. However if ~/.config/lutris/games exists, we should prefer that, and Lutris cannot use both ~/.config/lutris/games and ~/.local/share/lutris/games at the same time.

Solution

We now search ~/.local/share/lutris/games to find game configuration files (and Flatpak equivalent), if ~/.config/lutris/games does not exist (and Flatpak equivalent). Lutris will prefer ~/.config/lutris/games if it exists, but this path is deprecated and Lutris will default to using ~/.local/share/lutris/games (XDG Data Directory) if the Config directory does not exist.

As a result of this, we also fix the crash which was a symptom of this problem and the catalyst for opening #495. The crash comes from os.listdir when searching for our game config file, if ~/.config/lutris exists but not ~/.config/lutris/games, caused by the assumption that the games folder will exist in the config folder if the config folder exists. We no longer get as far as os.listdir unless we find a valid Lutris game config folder, either in the Config Directory or Data directory.

The overall implementation here will "fall up" to ~/.local/share/lutris/games if ~/.config/lutris/games is not found, different to before where we assumed the games folder existed if we got any truthy value back from install_loc.get('config_dir').

Implementation

Most of the implementation is fairly straightforward "if no Lutris games folder in config dir, check the data dir for the games folder, and if neither exist then return an empty dict". One detail worth calling out though is how we get the data directory. We do this by going two directories up from the install_loc.get('install_dir'), which in the case of Lutris will be something like ~/.local/share/lutris/runners/wine/../..games/. We get the abspath and expanduser of this so we end up with a clean path, like /home/gaben/.local/share/lutris/games.

This works, and should be safe to do, and we do similar logic in Ctmods to get the install folder we want to use (such as the vkd3d-proton Ctmod). So there is precedent for doing this in the codebase, and it should be safe to do for Flatpak paths as well, since install_dir for Lutris should always be lutris/runners/wine. Two directories up should always give us the Lutris root install. It is worth noting that we make similar assumptions about the install_dir path and directory structure around that for Heroic in heroicutil. But let me know if there are any concerns with this kind of approach!

For consistency, the whole LutrisGame#get_game_config method now works with /path/to/lutris/games instead of just getting the Lutris config folder and os.path.joining on the games folder. This means the method a bit easier to read as well imo, since we only build the path to the game in one place.


Let me know if I missed anything or if there are any concerns/edge cases I did not consider. All feedback is welcome.

Thanks! :-)

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.

Can't Open CtInfo or Games List Dialog for Lutris
1 participant