Skip to content

Commit 2b537d2

Browse files
committed
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)
1 parent 69eab74 commit 2b537d2

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

dtool/src/dtoolutil/executionEnvironment.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,22 @@ ns_get_environment_variable(const string &var) const {
341341
}
342342
}
343343

344+
#elif !defined(__APPLE__)
345+
// Similarly, we define fallbacks on POSIX systems for the variables defined
346+
// in the XDG Base Directory specification, so that they can be safely used
347+
// in Config.prc files.
348+
if (var == "XDG_CONFIG_HOME") {
349+
Filename home_dir = Filename::get_home_directory();
350+
return home_dir.get_fullpath() + "/.config";
351+
352+
} else if (var == "XDG_CACHE_HOME") {
353+
Filename home_dir = Filename::get_home_directory();
354+
return home_dir.get_fullpath() + "/.cache";
355+
356+
} else if (var == "XDG_DATA_HOME") {
357+
Filename home_dir = Filename::get_home_directory();
358+
return home_dir.get_fullpath() + "/.local/share";
359+
}
344360
#endif // _WIN32
345361

346362
return string();

dtool/src/dtoolutil/filename.cxx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,14 @@ get_user_appdata_directory() {
600600
user_appdata_directory.set_basename("files");
601601

602602
#else
603-
// Posix case.
604-
user_appdata_directory = get_home_directory();
603+
// Posix case. We follow the XDG base directory spec.
604+
struct stat st;
605+
const char *datadir = getenv("XDG_DATA_HOME");
606+
if (datadir != nullptr && stat(datadir, &st) == 0 && S_ISDIR(st.st_mode)) {
607+
user_appdata_directory = datadir;
608+
} else {
609+
user_appdata_directory = Filename(get_home_directory(), ".local/share");
610+
}
605611

606612
#endif // WIN32
607613

@@ -649,9 +655,10 @@ get_common_appdata_directory() {
649655
common_appdata_directory.set_dirname(_internal_data_dir);
650656
common_appdata_directory.set_basename("files");
651657

658+
#elif defined(__FreeBSD__)
659+
common_appdata_directory = "/usr/local/share";
652660
#else
653-
// Posix case.
654-
common_appdata_directory = "/var";
661+
common_appdata_directory = "/usr/share";
655662
#endif // WIN32
656663

657664
if (common_appdata_directory.empty()) {

makepanda/config.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ hardware-animated-vertices #f
8989

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

92-
model-cache-dir $HOME/.panda3d/cache
92+
model-cache-dir $XDG_CACHE_HOME/panda3d
9393
model-cache-textures #f
9494

9595
# This option specifies the default profiles for Cg shaders.

makepanda/makepanda.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,12 +2797,12 @@ def CreatePandaVersionFiles():
27972797
configprc = ReadFile("makepanda/config.in")
27982798

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

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

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy