Further path refinements
This commit is contained in:
parent
2ef00e9de4
commit
4c14406788
100
common/paths.cpp
100
common/paths.cpp
|
@ -34,16 +34,23 @@
|
||||||
#define KICAD_PATH_STR "kicad"
|
#define KICAD_PATH_STR "kicad"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void PATHS::getUserDocumentPath( wxFileName& aPath )
|
||||||
|
{
|
||||||
|
aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
||||||
|
aPath.AppendDir( KICAD_PATH_STR );
|
||||||
|
aPath.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString PATHS::GetUserPluginsPath()
|
wxString PATHS::GetUserPluginsPath()
|
||||||
{
|
{
|
||||||
wxFileName tmp;
|
wxFileName tmp;
|
||||||
|
getUserDocumentPath( tmp );
|
||||||
|
|
||||||
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
|
||||||
tmp.AppendDir( KICAD_PATH_STR );
|
|
||||||
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
|
||||||
tmp.AppendDir( "plugins" );
|
tmp.AppendDir( "plugins" );
|
||||||
|
|
||||||
return tmp.GetFullPath();
|
return tmp.GetPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,46 +61,73 @@ wxString PATHS::GetUserPlugins3DPath()
|
||||||
tmp.AssignDir( PATHS::GetUserPluginsPath() );
|
tmp.AssignDir( PATHS::GetUserPluginsPath() );
|
||||||
tmp.AppendDir( "3d" );
|
tmp.AppendDir( "3d" );
|
||||||
|
|
||||||
return tmp.GetFullPath();
|
return tmp.GetPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString PATHS::GetUserScriptingPath()
|
wxString PATHS::GetUserScriptingPath()
|
||||||
{
|
{
|
||||||
wxFileName tmp;
|
wxFileName tmp;
|
||||||
|
getUserDocumentPath( tmp );
|
||||||
|
|
||||||
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
|
||||||
tmp.AppendDir( KICAD_PATH_STR );
|
|
||||||
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
|
||||||
tmp.AppendDir( "scripting" );
|
tmp.AppendDir( "scripting" );
|
||||||
|
|
||||||
return tmp.GetFullPath();
|
return tmp.GetPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxString PATHS::GetUserTemplatesPath()
|
wxString PATHS::GetUserTemplatesPath()
|
||||||
{
|
{
|
||||||
wxFileName tmp;
|
wxFileName tmp;
|
||||||
|
getUserDocumentPath( tmp );
|
||||||
|
|
||||||
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
|
||||||
tmp.AppendDir( KICAD_PATH_STR );
|
|
||||||
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
|
||||||
tmp.AppendDir( "template" );
|
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()
|
wxString PATHS::GetDefaultUserProjectsPath()
|
||||||
{
|
{
|
||||||
wxFileName tmp;
|
wxFileName tmp;
|
||||||
|
getUserDocumentPath( tmp );
|
||||||
|
|
||||||
tmp.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
|
||||||
tmp.AppendDir( KICAD_PATH_STR );
|
|
||||||
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
|
||||||
tmp.AppendDir( "projects" );
|
tmp.AppendDir( "projects" );
|
||||||
|
|
||||||
return tmp.GetFullPath();
|
return tmp.GetPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,4 +199,36 @@ wxString PATHS::GetUserCachePath()
|
||||||
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() );
|
||||||
|
|
||||||
return tmp.GetPathWithSep();
|
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() );
|
||||||
}
|
}
|
|
@ -31,6 +31,7 @@
|
||||||
#include <kiplatform/environment.h>
|
#include <kiplatform/environment.h>
|
||||||
#include <kiway.h>
|
#include <kiway.h>
|
||||||
#include <macros.h>
|
#include <macros.h>
|
||||||
|
#include <paths.h>
|
||||||
#include <project.h>
|
#include <project.h>
|
||||||
#include <project/project_archiver.h>
|
#include <project/project_archiver.h>
|
||||||
#include <project/project_file.h>
|
#include <project/project_file.h>
|
||||||
|
@ -54,6 +55,8 @@ SETTINGS_MANAGER::SETTINGS_MANAGER( bool aHeadless ) :
|
||||||
m_migration_source(),
|
m_migration_source(),
|
||||||
m_migrateLibraryTables( true )
|
m_migrateLibraryTables( true )
|
||||||
{
|
{
|
||||||
|
PATHS::EnsureUserPathsExist();
|
||||||
|
|
||||||
// Check if the settings directory already exists, and if not, perform a migration if possible
|
// Check if the settings directory already exists, and if not, perform a migration if possible
|
||||||
if( !MigrateIfNeeded() )
|
if( !MigrateIfNeeded() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
class PATHS
|
class PATHS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user path for python scripts
|
* Gets the user path for python scripts
|
||||||
*/
|
*/
|
||||||
|
@ -51,6 +52,21 @@ public:
|
||||||
*/
|
*/
|
||||||
static wxString GetDefaultUserProjectsPath();
|
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
|
* Gets the stock (install) scripting path
|
||||||
*/
|
*/
|
||||||
|
@ -71,9 +87,26 @@ public:
|
||||||
*/
|
*/
|
||||||
static wxString GetUserCachePath();
|
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:
|
private:
|
||||||
// we are a static helper
|
// we are a static helper
|
||||||
PATHS() {}
|
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
|
#endif
|
Loading…
Reference in New Issue