Further path refinements

This commit is contained in:
Marek Roszko 2021-01-27 21:06:13 -05:00
parent 2ef00e9de4
commit 4c14406788
3 changed files with 119 additions and 17 deletions

View File

@ -34,16 +34,23 @@
#define KICAD_PATH_STR "kicad"
#endif
void PATHS::getUserDocumentPath( wxFileName& aPath )
{
aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
aPath.AppendDir( KICAD_PATH_STR );
aPath.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
}
wxString PATHS::GetUserPluginsPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
tmp.AppendDir( KICAD_PATH_STR );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
tmp.AppendDir( "plugins" );
return tmp.GetFullPath();
return tmp.GetPath();
}
@ -54,46 +61,73 @@ wxString PATHS::GetUserPlugins3DPath()
tmp.AssignDir( PATHS::GetUserPluginsPath() );
tmp.AppendDir( "3d" );
return tmp.GetFullPath();
return tmp.GetPath();
}
wxString PATHS::GetUserScriptingPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
tmp.AppendDir( KICAD_PATH_STR );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
tmp.AppendDir( "scripting" );
return tmp.GetFullPath();
return tmp.GetPath();
}
wxString PATHS::GetUserTemplatesPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
tmp.AppendDir( KICAD_PATH_STR );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
tmp.AppendDir( "template" );
return tmp.GetFullPath();
return tmp.GetPath();
}
wxString PATHS::GetDefaultUserSymbolsPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AppendDir( "symbols" );
return tmp.GetPath();
}
wxString PATHS::GetDefaultUserFootprintsPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AppendDir( "footprints" );
return tmp.GetPath();
}
wxString PATHS::GetDefaultUser3DModelsPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AppendDir( "3dmodels" );
return tmp.GetPath();
}
wxString PATHS::GetDefaultUserProjectsPath()
{
wxFileName tmp;
getUserDocumentPath( tmp );
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
tmp.AppendDir( KICAD_PATH_STR );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
tmp.AppendDir( "projects" );
return tmp.GetFullPath();
return tmp.GetPath();
}
@ -165,4 +199,36 @@ wxString PATHS::GetUserCachePath()
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
return tmp.GetPathWithSep();
}
bool PATHS::EnsurePathExists( const wxString& aPath )
{
wxFileName path( aPath );
if( !path.Normalize() )
{
return false;
}
if( !wxFileName::DirExists( aPath ) )
{
if( !wxFileName::Mkdir( aPath, wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ) )
{
return false;
}
}
return true;
}
void PATHS::EnsureUserPathsExist()
{
EnsurePathExists( GetUserPluginsPath() );
EnsurePathExists( GetUserPlugins3DPath() );
EnsurePathExists( GetUserScriptingPath() );
EnsurePathExists( GetDefaultUserProjectsPath() );
EnsurePathExists( GetDefaultUserSymbolsPath() );
EnsurePathExists( GetDefaultUserFootprintsPath() );
EnsurePathExists( GetDefaultUser3DModelsPath() );
}

View File

@ -31,6 +31,7 @@
#include <kiplatform/environment.h>
#include <kiway.h>
#include <macros.h>
#include <paths.h>
#include <project.h>
#include <project/project_archiver.h>
#include <project/project_file.h>
@ -54,6 +55,8 @@ SETTINGS_MANAGER::SETTINGS_MANAGER( bool aHeadless ) :
m_migration_source(),
m_migrateLibraryTables( true )
{
PATHS::EnsureUserPathsExist();
// Check if the settings directory already exists, and if not, perform a migration if possible
if( !MigrateIfNeeded() )
{

View File

@ -26,6 +26,7 @@
class PATHS
{
public:
/**
* Gets the user path for python scripts
*/
@ -51,6 +52,21 @@ public:
*/
static wxString GetDefaultUserProjectsPath();
/**
* Gets the default path we point users to create projects
*/
static wxString GetDefaultUserSymbolsPath();
/**
* Gets the default path we point users to create projects
*/
static wxString GetDefaultUserFootprintsPath();
/**
* Gets the default path we point users to create projects
*/
static wxString GetDefaultUser3DModelsPath();
/**
* Gets the stock (install) scripting path
*/
@ -71,9 +87,26 @@ public:
*/
static wxString GetUserCachePath();
/**
* Attempts to create a given path if it does not exist
*/
static bool EnsurePathExists( const wxString& aPath );
/**
* Ensures/creates user default paths
*/
static void EnsureUserPathsExist();
private:
// we are a static helper
PATHS() {}
/**
* Gets the user path for the current kicad version which acts as the root for other user paths
*
* @param aPath Variable to receive the path
*/
static void getUserDocumentPath( wxFileName& aPath );
};
#endif