Move the settings path to PATHS to allow shifting other classes into kicommon

This commit is contained in:
Marek Roszko 2023-09-23 19:53:22 -04:00
parent 37479c4154
commit 121ea99824
12 changed files with 90 additions and 90 deletions

View File

@ -736,7 +736,7 @@ S3D_CACHE* PROJECT::Get3DCacheManager( bool aUpdateProjDir )
cache = new S3D_CACHE(); cache = new S3D_CACHE();
wxFileName cfgpath; wxFileName cfgpath;
cfgpath.AssignDir( SETTINGS_MANAGER::GetUserSettingsPath() ); cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
cfgpath.AppendDir( wxT( "3d" ) ); cfgpath.AppendDir( wxT( "3d" ) );
cache->SetProgramBase( &Pgm() ); cache->SetProgramBase( &Pgm() );

View File

@ -24,7 +24,7 @@
#include <advanced_config.h> #include <advanced_config.h>
#include <config_params.h> #include <config_params.h>
#include <settings/settings_manager.h> #include <paths.h>
#include <wx/app.h> #include <wx/app.h>
#include <wx/config.h> #include <wx/config.h>
@ -288,7 +288,7 @@ static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
static wxFileName getAdvancedCfgFilename() static wxFileName getAdvancedCfgFilename()
{ {
const static wxString cfg_filename{ wxS( "kicad_advanced" ) }; const static wxString cfg_filename{ wxS( "kicad_advanced" ) };
return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename ); return wxFileName( PATHS::GetUserSettingsPath(), cfg_filename );
} }

View File

@ -28,6 +28,7 @@
#include <footprint_info.h> #include <footprint_info.h>
#include <lib_id.h> #include <lib_id.h>
#include <lib_table_lexer.h> #include <lib_table_lexer.h>
#include <paths.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <search_stack.h> #include <search_stack.h>
#include <settings/kicad_settings.h> #include <settings/kicad_settings.h>
@ -654,7 +655,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
{ {
wxFileName fn; wxFileName fn;
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); fn.SetPath( PATHS::GetUserSettingsPath() );
fn.SetName( global_tbl_name ); fn.SetName( global_tbl_name );
return fn.GetFullPath(); return fn.GetFullPath();

View File

@ -30,7 +30,7 @@
#include <eda_base_frame.h> #include <eda_base_frame.h>
#include <eda_draw_frame.h> #include <eda_draw_frame.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <settings/settings_manager.h> #include <paths.h>
#include <tool/tool_manager.h> #include <tool/tool_manager.h>
#include "dialogs/dialog_hotkey_list.h" #include "dialogs/dialog_hotkey_list.h"
@ -357,7 +357,7 @@ void ReadHotKeyConfig( const wxString& aFileName,
{ {
wxFileName fn( wxS( "user" ) ); wxFileName fn( wxS( "user" ) );
fn.SetExt( HotkeyFileExtension ); fn.SetExt( HotkeyFileExtension );
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); fn.SetPath( PATHS::GetUserSettingsPath() );
fileName = fn.GetFullPath(); fileName = fn.GetFullPath();
} }
@ -412,7 +412,7 @@ int WriteHotKeyConfig( const std::vector<TOOL_ACTION*>& aActions )
wxFileName fn( "user" ); wxFileName fn( "user" );
fn.SetExt( HotkeyFileExtension ); fn.SetExt( HotkeyFileExtension );
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); fn.SetPath( PATHS::GetUserSettingsPath() );
// Read the existing config (all hotkeys) // Read the existing config (all hotkeys)
ReadHotKeyConfig( fn.GetFullPath(), hotkeys ); ReadHotKeyConfig( fn.GetFullPath(), hotkeys );
@ -459,7 +459,7 @@ int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map<std::string,
wxFileName fn( aFilename ); wxFileName fn( aFilename );
fn.SetExt( HotkeyFileExtension ); fn.SetExt( HotkeyFileExtension );
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); fn.SetPath( PATHS::GetUserSettingsPath() );
if( !wxFile::Exists( fn.GetFullPath() ) ) if( !wxFile::Exists( fn.GetFullPath() ) )
return 0; return 0;

View File

@ -25,8 +25,9 @@
#include <kiplatform/environment.h> #include <kiplatform/environment.h>
#include <paths.h> #include <paths.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <settings/settings_manager.h>
#include <config.h> #include <config.h>
#include <build_version.h>
#include <macros.h>
// lowercase or pretty case depending on platform // lowercase or pretty case depending on platform
#if defined( __WXMAC__ ) || defined( __WXMSW__ ) #if defined( __WXMAC__ ) || defined( __WXMSW__ )
@ -46,7 +47,7 @@ void PATHS::getUserDocumentPath( wxFileName& aPath )
aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() ); aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
aPath.AppendDir( KICAD_PATH_STR ); aPath.AppendDir( KICAD_PATH_STR );
aPath.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() ); aPath.AppendDir( GetMajorMinorVersion().ToStdString() );
} }
@ -333,7 +334,7 @@ wxString PATHS::GetUserCachePath()
} }
tmp.AppendDir( KICAD_PATH_STR ); tmp.AppendDir( KICAD_PATH_STR );
tmp.AppendDir( SETTINGS_MANAGER::GetSettingsVersion() ); tmp.AppendDir( GetMajorMinorVersion().ToStdString() );
return tmp.GetPathWithSep(); return tmp.GetPathWithSep();
} }
@ -462,3 +463,40 @@ wxString PATHS::getWindowsKiCadRoot()
return root.GetPathWithSep(); return root.GetPathWithSep();
} }
#endif #endif
wxString PATHS::GetUserSettingsPath()
{
static wxString user_settings_path;
if( user_settings_path.empty() )
user_settings_path = CalculateUserSettingsPath();
return user_settings_path;
}
wxString PATHS::CalculateUserSettingsPath( bool aIncludeVer, bool aUseEnv )
{
wxFileName cfgpath;
// http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
wxString envstr;
if( aUseEnv && wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
{
// Override the assignment above with KICAD_CONFIG_HOME
cfgpath.AssignDir( envstr );
}
else
{
cfgpath.AssignDir( KIPLATFORM::ENV::GetUserConfigPath() );
cfgpath.AppendDir( TO_STR( KICAD_CONFIG_DIR ) );
}
if( aIncludeVer )
cfgpath.AppendDir( GetMajorMinorVersion().ToStdString() );
return cfgpath.GetPath();
}

View File

@ -424,7 +424,7 @@ bool COMMON_SETTINGS::migrateSchema1to2()
bool COMMON_SETTINGS::migrateSchema2to3() bool COMMON_SETTINGS::migrateSchema2to3()
{ {
wxFileName cfgpath; wxFileName cfgpath;
cfgpath.AssignDir( SETTINGS_MANAGER::GetUserSettingsPath() ); cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
cfgpath.AppendDir( wxT( "3d" ) ); cfgpath.AppendDir( wxT( "3d" ) );
cfgpath.SetFullName( wxS( "3Dresolver.cfg" ) ); cfgpath.SetFullName( wxS( "3Dresolver.cfg" ) );
cfgpath.MakeAbsolute(); cfgpath.MakeAbsolute();

View File

@ -423,7 +423,7 @@ wxString SETTINGS_MANAGER::GetPathForSettingsFile( JSON_SETTINGS* aSettings )
switch( aSettings->GetLocation() ) switch( aSettings->GetLocation() )
{ {
case SETTINGS_LOC::USER: case SETTINGS_LOC::USER:
return GetUserSettingsPath(); return PATHS::GetUserSettingsPath();
case SETTINGS_LOC::PROJECT: case SETTINGS_LOC::PROJECT:
// TODO: MDI support // TODO: MDI support
@ -521,7 +521,7 @@ public:
bool SETTINGS_MANAGER::MigrateIfNeeded() bool SETTINGS_MANAGER::MigrateIfNeeded()
{ {
wxFileName path( GetUserSettingsPath(), wxS( "" ) ); wxFileName path( PATHS::GetUserSettingsPath(), wxS( "" ) );
wxLogTrace( traceSettings, wxT( "Using settings path %s" ), path.GetFullPath() ); wxLogTrace( traceSettings, wxT( "Using settings path %s" ), path.GetFullPath() );
if( m_headless ) if( m_headless )
@ -626,11 +626,11 @@ bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
wxDir dir; wxDir dir;
std::vector<wxFileName> base_paths; std::vector<wxFileName> base_paths;
base_paths.emplace_back( wxFileName( calculateUserSettingsPath( false ), wxS( "" ) ) ); base_paths.emplace_back( wxFileName( PATHS::CalculateUserSettingsPath( false ), wxS( "" ) ) );
// If the env override is set, also check the default paths // If the env override is set, also check the default paths
if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), nullptr ) ) if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), nullptr ) )
base_paths.emplace_back( wxFileName( calculateUserSettingsPath( false, false ), wxS( "" ) ) ); base_paths.emplace_back( wxFileName( PATHS::CalculateUserSettingsPath( false, false ), wxS( "" ) ) );
#ifdef __WXGTK__ #ifdef __WXGTK__
// When running inside FlatPak, KIPLATFORM::ENV::GetUserConfigPath() will return a sandboxed // When running inside FlatPak, KIPLATFORM::ENV::GetUserConfigPath() will return a sandboxed
@ -745,7 +745,7 @@ wxString SETTINGS_MANAGER::GetColorSettingsPath()
{ {
wxFileName path; wxFileName path;
path.AssignDir( GetUserSettingsPath() ); path.AssignDir( PATHS::GetUserSettingsPath() );
path.AppendDir( wxS( "colors" ) ); path.AppendDir( wxS( "colors" ) );
if( !path.DirExists() ) if( !path.DirExists() )
@ -760,45 +760,6 @@ wxString SETTINGS_MANAGER::GetColorSettingsPath()
return path.GetPath(); return path.GetPath();
} }
wxString SETTINGS_MANAGER::GetUserSettingsPath()
{
static wxString user_settings_path;
if( user_settings_path.empty() )
user_settings_path = calculateUserSettingsPath();
return user_settings_path;
}
wxString SETTINGS_MANAGER::calculateUserSettingsPath( bool aIncludeVer, bool aUseEnv )
{
wxFileName cfgpath;
// http://docs.wxwidgets.org/3.0/classwx_standard_paths.html#a7c7cf595d94d29147360d031647476b0
wxString envstr;
if( aUseEnv && wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), &envstr ) && !envstr.IsEmpty() )
{
// Override the assignment above with KICAD_CONFIG_HOME
cfgpath.AssignDir( envstr );
}
else
{
cfgpath.AssignDir( KIPLATFORM::ENV::GetUserConfigPath() );
cfgpath.AppendDir( TO_STR( KICAD_CONFIG_DIR ) );
}
if( aIncludeVer )
cfgpath.AppendDir( GetSettingsVersion() );
return cfgpath.GetPath();
}
std::string SETTINGS_MANAGER::GetSettingsVersion() std::string SETTINGS_MANAGER::GetSettingsVersion()
{ {
// CMake computes the major.minor string for us. // CMake computes the major.minor string for us.

View File

@ -32,7 +32,7 @@
#include <wx/listctrl.h> #include <wx/listctrl.h>
#include <wx/stc/stc.h> #include <wx/stc/stc.h>
#include <settings/settings_manager.h> #include <paths.h>
#include <launch_ext.h> #include <launch_ext.h>
@ -477,6 +477,6 @@ void PAGED_DIALOG::onResetButton( wxCommandEvent& aEvent )
void PAGED_DIALOG::onOpenPreferencesButton( wxCommandEvent& aEvent ) void PAGED_DIALOG::onOpenPreferencesButton( wxCommandEvent& aEvent )
{ {
wxString dir( SETTINGS_MANAGER::GetUserSettingsPath() ); wxString dir( PATHS::GetUserSettingsPath() );
LaunchExternal( dir ); LaunchExternal( dir );
} }

View File

@ -26,6 +26,7 @@
#include <lib_id.h> #include <lib_id.h>
#include <lib_table_lexer.h> #include <lib_table_lexer.h>
#include <paths.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <search_stack.h> #include <search_stack.h>
#include <settings/kicad_settings.h> #include <settings/kicad_settings.h>
@ -727,7 +728,7 @@ wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName()
{ {
wxFileName fn; wxFileName fn;
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() ); fn.SetPath( PATHS::GetUserSettingsPath() );
fn.SetName( global_tbl_name ); fn.SetName( global_tbl_name );
return fn.GetFullPath(); return fn.GetFullPath();

View File

@ -172,11 +172,38 @@ public:
#ifdef __WXWINDOWS__ #ifdef __WXWINDOWS__
/** /**
* @return The macOS specific bundle data directory for KiCad * @return The directory the font config support files can be found
*/ */
static wxString GetWindowsFontConfigDir(); static wxString GetWindowsFontConfigDir();
#endif #endif
/**
* Return the user configuration path used to store KiCad's configuration files.
*
* @see calculateUserSettingsPath
*
* NOTE: The path is cached at startup, it will never change during program lifetime!
*
* @return A string containing the config path for Kicad
*/
static wxString GetUserSettingsPath();
/**
* Determines the base path for user settings files.
*
* The configuration path order of precedence is determined by the following criteria:
*
* - The value of the KICAD_CONFIG_HOME environment variable
* - The value of the XDG_CONFIG_HOME environment variable.
* - The result of the call to wxStandardPaths::GetUserConfigDir() with ".config" appended
* as required on Linux builds.
*
* @param aIncludeVer will append the current KiCad version if true (default)
* @param aUseEnv will prefer the base path found in the KICAD_CONFIG_DIR if found (default)
* @return A string containing the config path for Kicad
*/
static wxString CalculateUserSettingsPath( bool aIncludeVer = true, bool aUseEnv = true );
private: private:
// we are a static helper // we are a static helper
PATHS() {} PATHS() {}

View File

@ -328,17 +328,6 @@ public:
*/ */
static wxString GetColorSettingsPath(); static wxString GetColorSettingsPath();
/**
* Return the user configuration path used to store KiCad's configuration files.
*
* @see calculateUserSettingsPath
*
* NOTE: The path is cached at startup, it will never change during program lifetime!
*
* @return A string containing the config path for Kicad
*/
static wxString GetUserSettingsPath();
/** /**
* Parses the current KiCad build version and extracts the major and minor revision to use * Parses the current KiCad build version and extracts the major and minor revision to use
* as the name of the settings directory for this KiCad version. * as the name of the settings directory for this KiCad version.
@ -350,23 +339,6 @@ public:
private: private:
JSON_SETTINGS* registerSettings( JSON_SETTINGS* aSettings, bool aLoadNow = true ); JSON_SETTINGS* registerSettings( JSON_SETTINGS* aSettings, bool aLoadNow = true );
/**
* Determines the base path for user settings files.
*
* The configuration path order of precedence is determined by the following criteria:
*
* - The value of the KICAD_CONFIG_HOME environment variable
* - The value of the XDG_CONFIG_HOME environment variable.
* - The result of the call to wxStandardPaths::GetUserConfigDir() with ".config" appended
* as required on Linux builds.
*
* @param aIncludeVer will append the current KiCad version if true (default)
* @param aUseEnv will prefer the base path found in the KICAD_CONFIG_DIR if found (default)
* @return A string containing the config path for Kicad
*/
static wxString calculateUserSettingsPath( bool aIncludeVer = true, bool aUseEnv = true );
/** /**
* Compares two settings versions, like "5.99" and "6.0" * Compares two settings versions, like "5.99" and "6.0"
* @return -1 if aFirst is older than aSecond, 1 if aFirst is newer than aSecond, 0 otherwise * @return -1 if aFirst is older than aSecond, 1 if aFirst is newer than aSecond, 0 otherwise

View File

@ -94,7 +94,7 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
} }
// Load currently installed packages // Load currently installed packages
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), wxT( "installed_packages.json" ) ); wxFileName f( PATHS::GetUserSettingsPath(), wxT( "installed_packages.json" ) );
if( f.FileExists() ) if( f.FileExists() )
{ {
@ -885,7 +885,7 @@ void PLUGIN_CONTENT_MANAGER::SaveInstalledPackages()
js["packages"].emplace_back( pair.second ); js["packages"].emplace_back( pair.second );
} }
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), wxT( "installed_packages.json" ) ); wxFileName f( PATHS::GetUserSettingsPath(), wxT( "installed_packages.json" ) );
std::ofstream stream( f.GetFullPath().fn_str() ); std::ofstream stream( f.GetFullPath().fn_str() );
stream << std::setw( 4 ) << js << std::endl; stream << std::setw( 4 ) << js << std::endl;