DescentDevelopers / Descent3

Descent 3 by Outrage Entertainment
GNU General Public License v3.0
2.73k stars 231 forks source link

[Feature Request] Linux: use XDG directories #373

Open twolife opened 1 month ago

twolife commented 1 month ago

Hi, Currently, the configfile on linux is saved in $XDG_DATA_HOME/Outrage Entertainment/Descent 3/ (as returned by SDL_GetPrefPath()), that's cool !

In addition to that, it would be nice if:

Thanks!

JeodC commented 1 month ago

Hi there!

As outlined by #282 and #326, the eventual goal is to confine everything to the game folder itself. Personally I fail to see an argument for keeping Registry (in windows) and XDG (in Linux) when we can consolidate it all and reduce overhead by aligning all platforms to use the same process. I'll expand on this reasoning:

Regarding screenshots, I would like to allow the user to define where they're saved. As for the pilot files, that logic is performed in pilot.cpp where the variable Base_directory is searched for any *.plt files. The temp directory (custom/cache) is also io'd based on that variable, so in the end it would be more effort than it's worth to change it for a specific platform (whereas Windows would have to use the Documents/ library folder).

twolife commented 1 month ago

I completely see your point to reduce maintenance overhead. But let me explain why I see value in splitting write() operations to the user directory and leaving the rest of the commercial game data elsewhere (in a readonly directory):

If everything is confined in the game folder, that "workflow" dies

Jayman2000 commented 1 month ago

But let me explain why I see value in splitting write() operations to the user directory and leaving the rest of the commercial game data elsewhere (in a readonly directory):

  • the game engine, GPL3 code, could be packaged by a linux distribution (the binary would be installed as /usr/games/descent3)
  • the non-free game data could by installed by the user with something like g-d-p https://wiki.debian.org/Games/GameDataPackager in /usr/share/games/descent3 (this is not hypothetical, I wrote the descent3 support to g-d-p some months ago, targeting the old Loki port from 2000)

If everything is confined in the game folder, that "workflow" dies

I’m actually working on a PR that would make that workflow possible. Specifically, my PR is going to add a command-line option called --additionaldir. It will allow you to do something like this:

Descent3 --setdir <path-to-writable-dir> --additionaldir <path-to-nonfree-game-data> --additionaldir <path-to-free-game-data>

If you want to take a look at what I have so far, then you can check out ~the additionaldir-arg-5 branch in my fork~ this PR.

chewi commented 1 month ago

I would package this game for Gentoo Linux, but supporting XDG directories is critical for that.

ErikMcClure commented 1 month ago

Hi there!

As outlined by #282 and #326, the eventual goal is to confine everything to the game folder itself. Personally I fail to see an argument for keeping Registry (in windows) and XDG (in Linux) when we can consolidate it all and reduce overhead by aligning all platforms to use the same process. I'll expand on this reasoning:

Regarding screenshots, I would like to allow the user to define where they're saved. As for the pilot files, that logic is performed in pilot.cpp where the variable Base_directory is searched for any *.plt files. The temp directory (custom/cache) is also io'd based on that variable, so in the end it would be more effort than it's worth to change it for a specific platform (whereas Windows would have to use the Documents/ library folder).

Trying to write to the game folder will not work on linux distros that make the app directory immutable, like NixOS. In fact, this can also be the case on Windows, depending on where you install the game! In some locations, you might have to give the game admin permissions to let it write to it's own directory. This is actually why many auto-updating apps now install to %APPDATA% on windows (like Chrome or Firefox), so they can update themselves without needing elevated permissions.

Unfortunately, this means making everything behave the same on all OSes simply isn't possible if you want it to actually work properly. However, you can still avoid using things like the windows registry simply by storing a config file in an appropriate place. You could simplify the code a lot by simply putting the config, screenshots and everything else in a single directory, like %APPDATA%/Descent 3 on windows, and some folder determined by XDG on Linux, then the only platform specific code necessary is getting the writable folder location. So long as this writable folder isn't the actual game folder itself, everything should work on Windows and all Linux distros. If you want screenshot location to be configurable, you could just default to the config directory at first.

MaddTheSane commented 2 weeks ago

SDL2 has a function that can get a user-writable directory for saving save data/preferences. It's SDL_GetPrefPath.

Lgt2x commented 2 weeks ago

That function is already used in the loki_utils utility https://github.com/DescentDevelopers/Descent3/blob/main/Descent3/loki_utils.c#L187