File tree Expand file tree Collapse file tree 4 files changed +30
-7
lines changed Expand file tree Collapse file tree 4 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -341,6 +341,22 @@ ns_get_environment_variable(const string &var) const {
341
341
}
342
342
}
343
343
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
+ }
344
360
#endif // _WIN32
345
361
346
362
return string ();
Original file line number Diff line number Diff line change @@ -600,8 +600,14 @@ get_user_appdata_directory() {
600
600
user_appdata_directory.set_basename (" files" );
601
601
602
602
#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
+ }
605
611
606
612
#endif // WIN32
607
613
@@ -649,9 +655,10 @@ get_common_appdata_directory() {
649
655
common_appdata_directory.set_dirname (_internal_data_dir);
650
656
common_appdata_directory.set_basename (" files" );
651
657
658
+ #elif defined(__FreeBSD__)
659
+ common_appdata_directory = " /usr/local/share" ;
652
660
#else
653
- // Posix case.
654
- common_appdata_directory = " /var" ;
661
+ common_appdata_directory = " /usr/share" ;
655
662
#endif // WIN32
656
663
657
664
if (common_appdata_directory.empty ()) {
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ hardware-animated-vertices #f
89
89
90
90
# Enable the model-cache, but only for models, not textures.
91
91
92
- model-cache-dir $HOME/. panda3d/cache
92
+ model-cache-dir $XDG_CACHE_HOME/ panda3d
93
93
model-cache-textures #f
94
94
95
95
# This option specifies the default profiles for Cg shaders.
Original file line number Diff line number Diff line change @@ -2797,12 +2797,12 @@ def CreatePandaVersionFiles():
2797
2797
configprc = ReadFile ("makepanda/config.in" )
2798
2798
2799
2799
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 )
2801
2801
else :
2802
2802
configprc = configprc .replace ("aux-display pandadx9" , "" )
2803
2803
2804
2804
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 )
2806
2806
2807
2807
# OpenAL is not yet working well on OSX for us, so let's do this for now.
2808
2808
configprc = configprc .replace ("p3openal_audio" , "p3fmod_audio" )
You can’t perform that action at this time.
0 commit comments