Standardpaths library

Marco Leise via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Mon Apr 6 14:40:28 PDT 2015


Am Sun, 05 Apr 2015 12:39:04 +0000
schrieb "FreeSlave" <freeslave93 at gmail.com>:

> On Sunday, 5 April 2015 at 11:42:42 UTC, Marco Leise wrote:
> >is this Windows?
> > return executable_path
> 
> That depends on what do you understand by data.

The data I was referring to is the stuff that is installed with
the program executable. Files that are usually the same across
installations.

> Are game's saves data too? Or content downloaded while playing
> (server-specific assets or new levels).
> In the past it was ok to write configs and 
> data to the same path where the game (or application) originally 
> installed. But starting with Vista or Windows 7 it's not the case 
> since Program Files folder become write-protected by default.

I believe modern desktops offer enough granularity to cover
each of those. For example if I was playing a game on Linux
files would go here:

/usr/share/[games/] - read-only data files.
~/.cache/ - downloaded archives, precompiled scripts, browser
            caches and other files that can be recreated or
            fetched again if they were to be deleted
~/.config/ - the user's personal configuration; may be
             overriding something in a system directory if
             desired
~/.local/share/ - pretty much a catch all for save games,
                  user created content that goes beyond the
                  scope of config files, highscores,
                  highlighting schemes in an IDE, Steam, ...

Or the other way around:

data               => /usr/share
save games         => ~/.local/share
downloaded content => ~/.local/share (or ~/.cache)
configs            => ~/.config

Windows has the Local and Roaming directories, which
serve similar but different purposes. E.g. anything machine
specific or big must not be in Roaming.
So if I generally asked for the config dir, I'd probably expect
AppData/Local on Windows and ~/.config on Linux (because I
might write a configuration that only works for this machine.)
Roaming is interesting for users that have their profiles on
servers and might switch to another workstation. So if some
configuration is "portable" and you want to create something
really fine grained you could offer that directory as an
alternative "roaming config dir" (returning null or
"~/.config" on Linux).
In any case there will be multiple results for some
directories (/usr/share, /usr/local/share) and also
several standard paths mapping to the same physical directory
(user data and user cache both map to AppData/Local on
Windows). The user needs to be made aware of this so (s)he
doesn't overwrite files in one standard path with files in a
supposedly different one.

So much for my thoughts on standard paths extreme edition. ;)

-- 
Marco



More information about the Digitalmars-d-announce mailing list