diff --git a/3d-viewer/3d_cache/3d_cache.cpp b/3d-viewer/3d_cache/3d_cache.cpp index 990c51dc45..2d53f748cc 100644 --- a/3d-viewer/3d_cache/3d_cache.cpp +++ b/3d-viewer/3d_cache/3d_cache.cpp @@ -39,6 +39,7 @@ #include #include +#include "common.h" #include "3d_cache.h" #include "3d_info.h" #include "common.h" @@ -584,7 +585,32 @@ bool S3D_CACHE::Set3DConfigDir( const wxString& aConfigDir ) #endif } - cfgdir.AppendDir( wxT( "cache" ) ); + // 3D cache data must go to a user's cache directory; + // unfortunately wxWidgets doesn't seem to provide + // functions to retrieve such a directory. + // + // 1. OSX: ~/Library/Caches/kicad/3d/ + // 2. Linux: ${XDG_CACHE_HOME}/kicad/3d ~/.cache/kicad/3d/ + // 3. MSWin: AppData\Local\kicad\3d + wxString cacheDir; + + #if defined(_WIN32) + wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None ); + cacheDir = wxStandardPaths::Get().GetUserLocalDataDir(); + cacheDir.append( "\\kicad\\3d" ); + #elif defined(__APPLE) + cacheDir = "${HOME}/Library/Caches/kicad/3d"; + #else // assume Linux + cacheDir = ExpandEnvVarSubstitutions( "${XDG_CACHE_HOME}" ); + + if( cacheDir.empty() || cacheDir == "${XDG_CACHE_HOME}" ) + cacheDir = "${HOME}/.cache"; + + cacheDir.append( "/kicad/3d" ); + #endif + + cacheDir = ExpandEnvVarSubstitutions( cacheDir ); + cfgdir.Assign( cacheDir, "" ); if( !cfgdir.DirExists() ) { @@ -628,9 +654,9 @@ wxString S3D_CACHE::Get3DConfigDir( bool createDefault ) cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() ); #if !defined( __WINDOWS__ ) && !defined( __WXMAC__ ) - wxString envstr = ExpandEnvVarSubstitutions( "XDG_CONFIG_HOME" ); + wxString envstr = ExpandEnvVarSubstitutions( "${XDG_CONFIG_HOME}" ); - if( envstr.IsEmpty() ) + if( envstr.IsEmpty() || envstr == "${XDG_CONFIG_HOME}" ) { // XDG_CONFIG_HOME is not set, so use the fallback cfgpath.AppendDir( wxT( ".config" ) ); diff --git a/3d-viewer/3d_cache/3d_plugin_manager.cpp b/3d-viewer/3d_cache/3d_plugin_manager.cpp index 163498d7b3..48f41d9537 100644 --- a/3d-viewer/3d_cache/3d_plugin_manager.cpp +++ b/3d-viewer/3d_cache/3d_plugin_manager.cpp @@ -133,7 +133,8 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) #endif #ifndef _WIN32 // suppress 'kicad' subdir since it is redundant on MSWin - fn.Assign( wxStandardPaths::Get().GetPluginsDir() ); + fn.Assign( wxStandardPaths::Get().GetPluginsDir(), "" ); + fn.RemoveLastDir(); fn.AppendDir( wxT( "kicad" ) ); #else fn.Assign( wxStandardPaths::Get().GetExecutablePath() ); @@ -148,8 +149,13 @@ void S3D_PLUGIN_MANAGER::loadPlugins( void ) checkPluginPath( wxT( "/opt/kicad/lib/kicad/plugins/3d" ), searchpaths ); // note: GetUserDataDir() gives '.pcbnew' rather than '.kicad' since it uses the exe name; - fn.Assign( wxStandardPaths::Get().GetUserDataDir() ); + fn.Assign( wxStandardPaths::Get().GetUserDataDir(), "" ); + fn.RemoveLastDir(); + #ifdef _WIN32 + fn.AppendDir( wxT( "kicad" ) ); + #else fn.AppendDir( wxT( ".kicad" ) ); + #endif fn.AppendDir( wxT( "plugins" ) ); fn.AppendDir( wxT( "3d" ) ); checkPluginPath( fn.GetPathWithSep(), searchpaths );