From 2b537d2263d312672fe4a380fb6f49bda641cd48 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 3 Jul 2017 22:27:37 +0200 Subject: [PATCH] Use XDG basedir spec for model-cache-dir (now $XDG_CACHE_HOME/panda3d 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) --- dtool/src/dtoolutil/executionEnvironment.cxx | 16 ++++++++++++++++ dtool/src/dtoolutil/filename.cxx | 15 +++++++++++---- makepanda/config.in | 2 +- makepanda/makepanda.py | 4 ++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/dtool/src/dtoolutil/executionEnvironment.cxx b/dtool/src/dtoolutil/executionEnvironment.cxx index cf7ecac50e..ad782b521e 100644 --- a/dtool/src/dtoolutil/executionEnvironment.cxx +++ b/dtool/src/dtoolutil/executionEnvironment.cxx @@ -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(); diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index 169f4bee05..c862c0aabf 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -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 @@ -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()) { diff --git a/makepanda/config.in b/makepanda/config.in index e61f73f04b..1317517339 100755 --- a/makepanda/config.in +++ b/makepanda/config.in @@ -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. diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index b707623ed4..b578340d33 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -2797,12 +2797,12 @@ else: 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")