Allow for multiple user configurations.

Use KICAD_CONFIG_HOME environment variable on all platforms so users can
maintain multiple configurations of KiCad.
This commit is contained in:
Wayne Stambaugh 2018-04-24 11:53:59 -04:00
parent dcf02f5f67
commit a7528df198
1 changed files with 14 additions and 11 deletions

View File

@ -219,29 +219,32 @@ wxString GetKicadConfigPath()
{ {
wxFileName cfgpath; wxFileName cfgpath;
// From the wxWidgets wxStandardPaths::GetUserConfigDir() help: // http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
// Unix: ~ (the home directory)
// Windows: "C:\Documents and Settings\username\Application Data"
// Mac: ~/Library/Preferences
cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() ); cfgpath.AssignDir( wxStandardPaths::Get().GetUserConfigDir() );
#if !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
wxString envstr; wxString envstr;
if( !wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) || envstr.IsEmpty() ) // wxStandardPaths does not default to ~/.config which is the current standard config
{ // location on Linux. This has been fixed in wxWidgets 3.1.1.
// XDG_CONFIG_HOME is not set, so use the fallback #if !wxCHECK_VERSION( 3, 1, 1 ) && !defined( __WINDOWS__ ) && !defined( __WXMAC__ )
cfgpath.AppendDir( wxT( ".config" ) ); if( wxGetEnv( wxT( "XDG_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
}
else
{ {
// Override the assignment above with XDG_CONFIG_HOME // Override the assignment above with XDG_CONFIG_HOME
cfgpath.AssignDir( envstr ); cfgpath.AssignDir( envstr );
} }
cfgpath.AppendDir( wxT( ".config" ) );
#endif #endif
cfgpath.AppendDir( wxT( "kicad" ) ); cfgpath.AppendDir( wxT( "kicad" ) );
// Use KICAD_CONFIG_HOME to allow the user to force a specific configuration path.
if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
{
// Override the assignment above with XDG_CONFIG_HOME
cfgpath.AssignDir( envstr );
}
if( !cfgpath.DirExists() ) if( !cfgpath.DirExists() )
{ {
cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL ); cfgpath.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );