← Back to team overview

kicad-developers team mailing list archive

PATCH: change 3D cache location

 

Some users/developers have objected to the current 3D
cache data location (within the local kicad configurations dir).

The attached patch changes the cache directory to:
1. Linux: ${XDG_CACHE_HOME}/kicad/3d
  OR
  ~/.cache/kicad/3d/

2. OSX: ~/Library/Caches/kicad/3d/

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

These directories are the recommended locations for
their respective operating systems.

Note: users will have to manually delete or move the
cache data in the current cache location.

- 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-14 00:31:54 +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,38 @@
         #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;
+
+    wxStandardPaths spath;
+    spath.UseAppInfo( AppInfo_None );
+    cacheDir = spath.GetUserLocalDataDir();
+    cacheDir.append( "\kicad\3d" );
+
+    #if defined(_WIN32)
+    wxStandardPaths spath;
+    spath.UseAppInfo( AppInfo_None );
+    cacheDir = spath.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 = "${HOME}/.cache";
+
+    cacheDir.append( "/kicad/3d" );
+    #endif
+
+    cacheDir = ExpandEnvVarSubstitutions( cacheDir );
+    cfgdir.Assign( cacheDir, "" );
 
     if( !cfgdir.DirExists() )
     {

=== 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-14 00:31:54 +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();
+    #ifnef _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