Centralize the 3d cache path
This commit is contained in:
parent
7b5397f81f
commit
daf9c4f319
|
@ -54,6 +54,7 @@
|
|||
#include "plugins/3dapi/ifsg_api.h"
|
||||
|
||||
#include <filename_resolver.h>
|
||||
#include <paths.h>
|
||||
#include <pgm_base.h>
|
||||
#include <project.h>
|
||||
#include <settings/common_settings.h>
|
||||
|
@ -553,40 +554,24 @@ bool S3D_CACHE::Set3DConfigDir( const wxString& aConfigDir )
|
|||
// 1. OSX: ~/Library/Caches/kicad/3d/
|
||||
// 2. Linux: ${XDG_CACHE_HOME}/kicad/3d ~/.cache/kicad/3d/
|
||||
// 3. MSWin: AppData\Local\kicad\3d
|
||||
wxString cacheDir;
|
||||
wxFileName cacheDir;
|
||||
cacheDir.AssignDir( PATHS::GetUserCachePath() );
|
||||
cacheDir.AppendDir( "3d" );
|
||||
|
||||
#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}", nullptr );
|
||||
|
||||
if( cacheDir.empty() || cacheDir == "${XDG_CACHE_HOME}" )
|
||||
cacheDir = "${HOME}/.cache";
|
||||
|
||||
cacheDir.append( "/kicad/3d" );
|
||||
#endif
|
||||
|
||||
cacheDir = ExpandEnvVarSubstitutions( cacheDir, m_project );
|
||||
cfgdir.Assign( cacheDir, "" );
|
||||
|
||||
if( !cfgdir.DirExists() )
|
||||
if( !cacheDir.DirExists() )
|
||||
{
|
||||
cfgdir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
|
||||
cacheDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
|
||||
|
||||
if( !cfgdir.DirExists() )
|
||||
if( !cacheDir.DirExists() )
|
||||
{
|
||||
wxLogTrace( MASK_3D_CACHE, "%s:%s:%d\n * failed to create 3D cache directory '%s'",
|
||||
__FILE__, __FUNCTION__, __LINE__, cfgdir.GetPath() );
|
||||
__FILE__, __FUNCTION__, __LINE__, cacheDir.GetPath() );
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
m_CacheDir = cfgdir.GetPathWithSep();
|
||||
m_CacheDir = cacheDir.GetPathWithSep();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <common.h>
|
||||
#include <paths.h>
|
||||
#include <pgm_base.h>
|
||||
#include "3d_plugin_dir.h"
|
||||
#include "3d_plugin_manager.h"
|
||||
#include "plugins/3d/3d_plugin.h"
|
||||
#include "3d_cache/sg/scenegraph.h"
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <wx/filename.h>
|
||||
#include <wx/stdpaths.h>
|
||||
#include <wx/string.h>
|
||||
|
||||
#include <kiplatform/environment.h>
|
||||
|
@ -146,4 +147,16 @@ wxString PATHS::GetStockPlugins3DPath()
|
|||
fn.AppendDir( "3d" );
|
||||
|
||||
return fn.GetPathWithSep();
|
||||
}
|
||||
|
||||
|
||||
wxString PATHS::GetUserCachePath()
|
||||
{
|
||||
wxFileName tmp;
|
||||
|
||||
tmp.AssignDir( KIPLATFORM::ENV::GetUserCacheDir() );
|
||||
tmp.AppendDir( "kicad" );
|
||||
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
||||
|
||||
return tmp.GetPathWithSep();
|
||||
}
|
|
@ -66,6 +66,11 @@ public:
|
|||
*/
|
||||
static wxString GetStockPlugins3DPath();
|
||||
|
||||
/**
|
||||
* Gets the stock (install) 3d viewer pluginspath
|
||||
*/
|
||||
static wxString GetUserCachePath();
|
||||
|
||||
private:
|
||||
// we are a static helper
|
||||
PATHS() {}
|
||||
|
|
|
@ -57,4 +57,10 @@ wxString KIPLATFORM::ENV::GetDocumentsDir()
|
|||
wxString KIPLATFORM::ENV::GetUserConfigDir()
|
||||
{
|
||||
return g_get_user_config_dir();
|
||||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserCacheDir()
|
||||
{
|
||||
return g_get_user_cache_dir();
|
||||
}
|
|
@ -55,5 +55,7 @@ namespace KIPLATFORM
|
|||
wxString GetDocumentsDir();
|
||||
|
||||
wxString GetUserConfigDir();
|
||||
|
||||
wxString GetUserCacheDir();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,4 +69,15 @@ wxString KIPLATFORM::ENV::GetDocumentsDir()
|
|||
wxString KIPLATFORM::ENV::GetUserConfigDir()
|
||||
{
|
||||
return wxStandardPaths::Get().GetUserConfigDir();
|
||||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserCacheDir()
|
||||
{
|
||||
// Unforunately AppData/Local is the closest analog to "Cache" directories of other platforms
|
||||
|
||||
// Make sure we dont include the "appinfo" (appended app name)
|
||||
wxStandardPaths::Get().UseAppInfo( wxStandardPaths::AppInfo_None );
|
||||
|
||||
return wxStandardPaths::Get().GetUserLocalDataDir();
|
||||
}
|
|
@ -61,4 +61,10 @@ wxString KIPLATFORM::ENV::GetDocumentsDir()
|
|||
wxString KIPLATFORM::ENV::GetUserConfigDir()
|
||||
{
|
||||
return wxStandardPaths::Get().GetUserConfigDir();
|
||||
}
|
||||
|
||||
|
||||
wxString KIPLATFORM::ENV::GetUserCacheDir()
|
||||
{
|
||||
return wxStandardPaths::Get().GetUserDir( wxStandardPaths::Dir::Dir_Cache );
|
||||
}
|
Loading…
Reference in New Issue