Browse Source

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)

rdb 8 years ago
parent
commit
2b537d2263

+ 16 - 0
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
 #endif // _WIN32
 
 
   return string();
   return string();

+ 11 - 4
dtool/src/dtoolutil/filename.cxx

@@ -600,8 +600,14 @@ get_user_appdata_directory() {
     user_appdata_directory.set_basename("files");
     user_appdata_directory.set_basename("files");
 
 
 #else
 #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
 #endif  // WIN32
 
 
@@ -649,9 +655,10 @@ get_common_appdata_directory() {
     common_appdata_directory.set_dirname(_internal_data_dir);
     common_appdata_directory.set_dirname(_internal_data_dir);
     common_appdata_directory.set_basename("files");
     common_appdata_directory.set_basename("files");
 
 
+#elif defined(__FreeBSD__)
+    common_appdata_directory = "/usr/local/share";
 #else
 #else
-    // Posix case.
-    common_appdata_directory = "/var";
+    common_appdata_directory = "/usr/share";
 #endif  // WIN32
 #endif  // WIN32
 
 
     if (common_appdata_directory.empty()) {
     if (common_appdata_directory.empty()) {

+ 1 - 1
makepanda/config.in

@@ -89,7 +89,7 @@ hardware-animated-vertices #f
 
 
 # Enable the model-cache, but only for models, not textures.
 # 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
 model-cache-textures #f
 
 
 # This option specifies the default profiles for Cg shaders.
 # This option specifies the default profiles for Cg shaders.

+ 2 - 2
makepanda/makepanda.py

@@ -2797,12 +2797,12 @@ else:
     configprc = ReadFile("makepanda/config.in")
     configprc = ReadFile("makepanda/config.in")
 
 
 if (GetTarget() == 'windows'):
 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:
 else:
     configprc = configprc.replace("aux-display pandadx9", "")
     configprc = configprc.replace("aux-display pandadx9", "")
 
 
 if (GetTarget() == 'darwin'):
 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.
     # OpenAL is not yet working well on OSX for us, so let's do this for now.
     configprc = configprc.replace("p3openal_audio", "p3fmod_audio")
     configprc = configprc.replace("p3openal_audio", "p3fmod_audio")