Skip to content

Commit

Permalink
Use XDG basedir spec for model-cache-dir (now $XDG_CACHE_HOME/panda3d…
Browse files Browse the repository at this point in the history
… which is usually $HOME/.cache/panda3d)

User appdata directory on posix is now $XDG_DATA_HOME (usually $HOME/.local/share).
Common appdata dir is /usr/share (or /usr/local/share on FreeBSD)
  • Loading branch information
rdb committed Jul 3, 2017
1 parent 69eab74 commit 2b537d2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
16 changes: 16 additions & 0 deletions dtool/src/dtoolutil/executionEnvironment.cxx
Expand Up @@ -341,6 +341,22 @@ ns_get_environment_variable(const string &var) const {
}
}

#elif !defined(__APPLE__)
// Similarly, we define fallbacks on POSIX systems for the variables defined
// in the XDG Base Directory specification, so that they can be safely used
// in Config.prc files.
if (var == "XDG_CONFIG_HOME") {
Filename home_dir = Filename::get_home_directory();
return home_dir.get_fullpath() + "/.config";

} else if (var == "XDG_CACHE_HOME") {
Filename home_dir = Filename::get_home_directory();
return home_dir.get_fullpath() + "/.cache";

} else if (var == "XDG_DATA_HOME") {
Filename home_dir = Filename::get_home_directory();
return home_dir.get_fullpath() + "/.local/share";
}
#endif // _WIN32

return string();
Expand Down
15 changes: 11 additions & 4 deletions dtool/src/dtoolutil/filename.cxx
Expand Up @@ -600,8 +600,14 @@ get_user_appdata_directory() {
user_appdata_directory.set_basename("files");

#else
// Posix case.
user_appdata_directory = get_home_directory();
// Posix case. We follow the XDG base directory spec.
struct stat st;
const char *datadir = getenv("XDG_DATA_HOME");
if (datadir != nullptr && stat(datadir, &st) == 0 && S_ISDIR(st.st_mode)) {
user_appdata_directory = datadir;
} else {
user_appdata_directory = Filename(get_home_directory(), ".local/share");
}

#endif // WIN32

Expand Down Expand Up @@ -649,9 +655,10 @@ get_common_appdata_directory() {
common_appdata_directory.set_dirname(_internal_data_dir);
common_appdata_directory.set_basename("files");

#elif defined(__FreeBSD__)
common_appdata_directory = "/usr/local/share";
#else
// Posix case.
common_appdata_directory = "/var";
common_appdata_directory = "/usr/share";
#endif // WIN32

if (common_appdata_directory.empty()) {
Expand Down
2 changes: 1 addition & 1 deletion makepanda/config.in
Expand Up @@ -89,7 +89,7 @@ hardware-animated-vertices #f

# Enable the model-cache, but only for models, not textures.

model-cache-dir $HOME/.panda3d/cache
model-cache-dir $XDG_CACHE_HOME/panda3d
model-cache-textures #f

# This option specifies the default profiles for Cg shaders.
Expand Down
4 changes: 2 additions & 2 deletions makepanda/makepanda.py
Expand Up @@ -2797,12 +2797,12 @@ def CreatePandaVersionFiles():
configprc = ReadFile("makepanda/config.in")

if (GetTarget() == 'windows'):
configprc = configprc.replace("$HOME/.panda3d", "$USER_APPDATA/Panda3D-%s" % MAJOR_VERSION)
configprc = configprc.replace("$XDG_CACHE_HOME/panda3d", "$USER_APPDATA/Panda3D-%s" % MAJOR_VERSION)
else:
configprc = configprc.replace("aux-display pandadx9", "")

if (GetTarget() == 'darwin'):
configprc = configprc.replace(".panda3d/cache", "Library/Caches/Panda3D-%s" % MAJOR_VERSION)
configprc = configprc.replace("$XDG_CACHE_HOME/panda3d", "Library/Caches/Panda3D-%s" % MAJOR_VERSION)

# OpenAL is not yet working well on OSX for us, so let's do this for now.
configprc = configprc.replace("p3openal_audio", "p3fmod_audio")
Expand Down

0 comments on commit 2b537d2

Please sign in to comment.