bsnes icon indicating copy to clipboard operation
bsnes copied to clipboard

Investigate XDG BaseDir integration

Open Screwtapello opened this issue 4 years ago • 4 comments

Currently, bsnes more-or-less supports the XDG BaseDir specification for storing configuration on Linux - it keeps some things in ~/.config/bsnes/ and some in ~/.local/share/bsnes/ and since #103 landed it even respects $XDG_CONFIG_HOME and $XDG_DATA_HOME.

However, bsnes' external-resource handling is really designed for the Windows model, where resources tend to be next to the executable, or in the user's home directory, and the distinction between config/data/cache and the user/system/vendor hierarchy don't really exist. I recall that bsnes and higan have at different times put everything in ~/.config or put everything in ~/.local/share for simplicity's sake, and I don't know if they're any more rigorous now.

Updating bsnes to properly follow the XDG BaseDir spec on Linux without regressing Windows or macOS may be difficult, but I'd like to get an idea for how difficult it would be:

  • [x] Investigate all the places where bsnes loads an external resource
    • a good start would be finding all the things that call functions in nall/path.hpp and tracing their callers
  • [x] figure out their access (read/write), and their type (config/data/cache)
  • [ ] figure out a search algorithm for each combination of categories (read config, write config, read data, ...)
  • [ ] check whether nall provides all the ingredients for discovering the paths required by the search algorithm (I think the raw parts are in nall/path.hpp and the path construction operations are in nall/location.hpp but it would be good to check)

Once we have a good idea of where we are, and where we want to be, we can estimate how much work it would be to get from one to the other, and whether that investment is worth making.

Screwtapello avatar Nov 11 '20 04:11 Screwtapello

I expect the outcome of this issue to be a new issue ("Implement XDG BaseDir integration") that describes exactly the work to be done. If it turns out to be a lot of work, and something easier like #110 is a net improvement, we might just go for that instead.

Screwtapello avatar Nov 11 '20 05:11 Screwtapello

Subscribed. Thank you for this very good summary!

Regarding #110, another approach could be to just copy the default stuff installed under /usr/share/bsnes to their relevant location under $XDG_CONFIG_HOME and $XDG_DATA_HOME and not override the search paths in locate. This could be easily done with a wrapper script doing this check first, copy if data is absent, and finally execute the binary. Since both locations are r/w, it should be fine.

ghisvail avatar Nov 11 '20 18:11 ghisvail

Copy-at-first startup is what (I think) Linux packagers have traditionally done, but I hope someday we can do better than that.

Screwtapello avatar Nov 12 '20 01:11 Screwtapello

Locations where either locate or nall::Path, broken down with file, function, line and access (ro = read-only, rw = read-write)

Uses of nall::Path

Path Function Usage r/w
bsnes/target-bsnes/bsnes.cpp locate(string) -> string
bsnes/target-bsnes/movies.cpp Program::moviePlay dialog.setPath(Path::desktop()) ro
bsnes/target-bsnes/movies.cpp Program::movieStop dialog.setPath(Path::desktop()) ro
bsnes/target-bsnes/utility.cpp Program::selectPath dialog.setPath(Path::desktop()) ro
bsnes/target-bsnes/utility.cpp Program::selectPath window.setPath(Path::desktop()) ro
hiro/browser-dialog.cpp BrowserDialogWindow::run file::read({Path::userSettings(), "hiro/browser-dialog.bml"}) rw
hiro/browser-dialog.cpp BrowserDialogWindow::setPath Path::root() ro
hiro/browser-dialog.cpp BrowserDialog::_run() Path::user() ro
hiro/gtk/settings.cpp Settings::Settings Path::userSettings() ro
hiro/gtk/settings.cpp Settings::~Settings Path::userSettings() rw
hiro/gtk/window.cpp pWindow::construct() Path::user() ro
hiro/qt/settings.cpp Settings::Settings Path::userSettings() ro
hiro/qt/settings.cpp Settings::~Settings Path::userSettings() rw
hiro/qt/window.cpp pWindow::construct() Path::user() ro
hiro/windows/settings.cpp Settings::Settings Path::userSettings() ro
hiro/windows/settings.cpp Settings::~Settings Path::userSettings() rw
nall/arguments.hpp Aguments::construct() Path::real(programArgument) ro
nall/dl.hpp library::open Path::user() ro
nall/run.hpp invoke Path::program() ro

Uses of locate

Path Function Usage r/w
bsnes/target-bsnes/bsnes.cpp nall::main locate("settings.bml") rw
bsnes/target-bsnes/bsnes.cpp nall::main locate("Locale/") ro
bsnes/target-bsnes/presentation/presentation.cpp Presentation::updateShaders locate("Shaders/") ro
bsnes/target-bsnes/program/game-rom.cpp Program::openRomSuperFamicom locate({"Firmware/", ...}) ro
bsnes/target-bsnes/program/game.cpp Program::loadSuperFamicom locate("Database/Super Famicom.bml") ro
bsnes/target-bsnes/program/game.cpp Program::loadGameBoy locate("Database/Game Boy.bml") ro
bsnes/target-bsnes/program/game.cpp Program::loadGameBoy locate("Database/Game Boy Color.bml") ro
bsnes/target-bsnes/program/game.cpp Program::loadBSMemory locate(""Database/BS Memory.bml"") ro
bsnes/target-bsnes/program/game.cpp Program::loadSufamiTurboA locate("Database/Sufami Turbo.bml") ro
bsnes/target-bsnes/program/game.cpp Program::loadSufamiTurboB locate("Database/Sufami Turbo.bml") ro
bsnes/target-bsnes/settings/settings.cpp Settings::save locate("settings.bml") rw
bsnes/target-bsnes/tools/cheat-editor.cpp CheatDatabase::findCheats locate("Database/Cheat Codes.bml") ro
bsnes/target-bsnes/tools/cheat-editor.cpp CheatEditor::create locate("Database/Cheat Codes.bml") ro

ghisvail avatar Nov 20 '20 19:11 ghisvail