← Back to team overview

kicad-developers team mailing list archive

PATCH: change 3D cache directory

 

At the moment the 3D cache data is written to a subdirectory
of the configuration directory.  The attached patch changes
the 3D cache directory to a location recommended on each
supported platform (Linux, MSWin, OSX):

1. OSX: ${HOME}/Library/Caches/kicad/3d

2. Linux: ${XDG_CACHE_HOME}/kicad/3d
  OR
   ${HOME}/.cache/kicad/3d

3. MSWin: AppData\Local\kicad\3d

I submitted a patch on June 14 but that patch was buggy
(my apologies).

- Cirilo
=== modified file '3d-viewer/3d_cache/3d_cache.cpp'
--- 3d-viewer/3d_cache/3d_cache.cpp	2016-06-09 05:48:49 +0000
+++ 3d-viewer/3d_cache/3d_cache.cpp	2016-06-18 07:53:03 +0000
@@ -39,6 +39,7 @@
 #include <glm/glm.hpp>
 #include <glm/ext.hpp>
 
+#include "common.h"
 #include "3d_cache.h"
 #include "3d_info.h"
 #include "common.h"
@@ -584,7 +585,32 @@
         #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 @@
     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" ) );

=== modified file '3d-viewer/3d_cache/3d_plugin_manager.cpp'
--- 3d-viewer/3d_cache/3d_plugin_manager.cpp	2016-06-09 05:48:49 +0000
+++ 3d-viewer/3d_cache/3d_plugin_manager.cpp	2016-06-17 21:50:24 +0000
@@ -133,7 +133,8 @@
     #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 @@
     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 );


Follow ups