Move the settings path to PATHS to allow shifting other classes into kicommon
This commit is contained in:
parent
37479c4154
commit
121ea99824
|
@ -736,7 +736,7 @@ S3D_CACHE* PROJECT::Get3DCacheManager( bool aUpdateProjDir )
|
|||
cache = new S3D_CACHE();
|
||||
|
||||
wxFileName cfgpath;
|
||||
cfgpath.AssignDir( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
|
||||
cfgpath.AppendDir( wxT( "3d" ) );
|
||||
|
||||
cache->SetProgramBase( &Pgm() );
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <advanced_config.h>
|
||||
|
||||
#include <config_params.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <paths.h>
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/config.h>
|
||||
|
@ -288,7 +288,7 @@ static void dumpCfg( const std::vector<PARAM_CFG*>& aArray )
|
|||
static wxFileName getAdvancedCfgFilename()
|
||||
{
|
||||
const static wxString cfg_filename{ wxS( "kicad_advanced" ) };
|
||||
return wxFileName( SETTINGS_MANAGER::GetUserSettingsPath(), cfg_filename );
|
||||
return wxFileName( PATHS::GetUserSettingsPath(), cfg_filename );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include <footprint_info.h>
|
||||
#include <lib_id.h>
|
||||
#include <lib_table_lexer.h>
|
||||
#include <paths.h>
|
||||
#include <pgm_base.h>
|
||||
#include <search_stack.h>
|
||||
#include <settings/kicad_settings.h>
|
||||
|
@ -654,7 +655,7 @@ wxString FP_LIB_TABLE::GetGlobalTableFileName()
|
|||
{
|
||||
wxFileName fn;
|
||||
|
||||
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
fn.SetPath( PATHS::GetUserSettingsPath() );
|
||||
fn.SetName( global_tbl_name );
|
||||
|
||||
return fn.GetFullPath();
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <eda_base_frame.h>
|
||||
#include <eda_draw_frame.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <paths.h>
|
||||
|
||||
#include <tool/tool_manager.h>
|
||||
#include "dialogs/dialog_hotkey_list.h"
|
||||
|
@ -357,7 +357,7 @@ void ReadHotKeyConfig( const wxString& aFileName,
|
|||
{
|
||||
wxFileName fn( wxS( "user" ) );
|
||||
fn.SetExt( HotkeyFileExtension );
|
||||
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
fn.SetPath( PATHS::GetUserSettingsPath() );
|
||||
fileName = fn.GetFullPath();
|
||||
}
|
||||
|
||||
|
@ -412,7 +412,7 @@ int WriteHotKeyConfig( const std::vector<TOOL_ACTION*>& aActions )
|
|||
wxFileName fn( "user" );
|
||||
|
||||
fn.SetExt( HotkeyFileExtension );
|
||||
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
fn.SetPath( PATHS::GetUserSettingsPath() );
|
||||
|
||||
// Read the existing config (all hotkeys)
|
||||
ReadHotKeyConfig( fn.GetFullPath(), hotkeys );
|
||||
|
@ -459,7 +459,7 @@ int ReadLegacyHotkeyConfigFile( const wxString& aFilename, std::map<std::string,
|
|||
wxFileName fn( aFilename );
|
||||
|
||||
fn.SetExt( HotkeyFileExtension );
|
||||
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
fn.SetPath( PATHS::GetUserSettingsPath() );
|
||||
|
||||
if( !wxFile::Exists( fn.GetFullPath() ) )
|
||||
return 0;
|
||||
|
|
|
@ -25,8 +25,9 @@
|
|||
#include <kiplatform/environment.h>
|
||||
#include <paths.h>
|
||||
#include <pgm_base.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <config.h>
|
||||
#include <build_version.h>
|
||||
#include <macros.h>
|
||||
|
||||
// lowercase or pretty case depending on platform
|
||||
#if defined( __WXMAC__ ) || defined( __WXMSW__ )
|
||||
|
@ -46,7 +47,7 @@ void PATHS::getUserDocumentPath( wxFileName& aPath )
|
|||
aPath.AssignDir( KIPLATFORM::ENV::GetDocumentsPath() );
|
||||
|
||||
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( SETTINGS_MANAGER::GetSettingsVersion() );
|
||||
tmp.AppendDir( GetMajorMinorVersion().ToStdString() );
|
||||
|
||||
return tmp.GetPathWithSep();
|
||||
}
|
||||
|
@ -462,3 +463,40 @@ wxString PATHS::getWindowsKiCadRoot()
|
|||
return root.GetPathWithSep();
|
||||
}
|
||||
#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();
|
||||
}
|
|
@ -424,7 +424,7 @@ bool COMMON_SETTINGS::migrateSchema1to2()
|
|||
bool COMMON_SETTINGS::migrateSchema2to3()
|
||||
{
|
||||
wxFileName cfgpath;
|
||||
cfgpath.AssignDir( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
cfgpath.AssignDir( PATHS::GetUserSettingsPath() );
|
||||
cfgpath.AppendDir( wxT( "3d" ) );
|
||||
cfgpath.SetFullName( wxS( "3Dresolver.cfg" ) );
|
||||
cfgpath.MakeAbsolute();
|
||||
|
|
|
@ -423,7 +423,7 @@ wxString SETTINGS_MANAGER::GetPathForSettingsFile( JSON_SETTINGS* aSettings )
|
|||
switch( aSettings->GetLocation() )
|
||||
{
|
||||
case SETTINGS_LOC::USER:
|
||||
return GetUserSettingsPath();
|
||||
return PATHS::GetUserSettingsPath();
|
||||
|
||||
case SETTINGS_LOC::PROJECT:
|
||||
// TODO: MDI support
|
||||
|
@ -521,7 +521,7 @@ public:
|
|||
|
||||
bool SETTINGS_MANAGER::MigrateIfNeeded()
|
||||
{
|
||||
wxFileName path( GetUserSettingsPath(), wxS( "" ) );
|
||||
wxFileName path( PATHS::GetUserSettingsPath(), wxS( "" ) );
|
||||
wxLogTrace( traceSettings, wxT( "Using settings path %s" ), path.GetFullPath() );
|
||||
|
||||
if( m_headless )
|
||||
|
@ -626,11 +626,11 @@ bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
|
|||
wxDir dir;
|
||||
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( 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__
|
||||
// When running inside FlatPak, KIPLATFORM::ENV::GetUserConfigPath() will return a sandboxed
|
||||
|
@ -745,7 +745,7 @@ wxString SETTINGS_MANAGER::GetColorSettingsPath()
|
|||
{
|
||||
wxFileName path;
|
||||
|
||||
path.AssignDir( GetUserSettingsPath() );
|
||||
path.AssignDir( PATHS::GetUserSettingsPath() );
|
||||
path.AppendDir( wxS( "colors" ) );
|
||||
|
||||
if( !path.DirExists() )
|
||||
|
@ -760,45 +760,6 @@ wxString SETTINGS_MANAGER::GetColorSettingsPath()
|
|||
|
||||
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()
|
||||
{
|
||||
// CMake computes the major.minor string for us.
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include <wx/listctrl.h>
|
||||
#include <wx/stc/stc.h>
|
||||
|
||||
#include <settings/settings_manager.h>
|
||||
#include <paths.h>
|
||||
|
||||
#include <launch_ext.h>
|
||||
|
||||
|
@ -477,6 +477,6 @@ void PAGED_DIALOG::onResetButton( wxCommandEvent& aEvent )
|
|||
|
||||
void PAGED_DIALOG::onOpenPreferencesButton( wxCommandEvent& aEvent )
|
||||
{
|
||||
wxString dir( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
wxString dir( PATHS::GetUserSettingsPath() );
|
||||
LaunchExternal( dir );
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <lib_id.h>
|
||||
#include <lib_table_lexer.h>
|
||||
#include <paths.h>
|
||||
#include <pgm_base.h>
|
||||
#include <search_stack.h>
|
||||
#include <settings/kicad_settings.h>
|
||||
|
@ -727,7 +728,7 @@ wxString SYMBOL_LIB_TABLE::GetGlobalTableFileName()
|
|||
{
|
||||
wxFileName fn;
|
||||
|
||||
fn.SetPath( SETTINGS_MANAGER::GetUserSettingsPath() );
|
||||
fn.SetPath( PATHS::GetUserSettingsPath() );
|
||||
fn.SetName( global_tbl_name );
|
||||
|
||||
return fn.GetFullPath();
|
||||
|
|
|
@ -172,11 +172,38 @@ public:
|
|||
|
||||
#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();
|
||||
#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:
|
||||
// we are a static helper
|
||||
PATHS() {}
|
||||
|
|
|
@ -328,17 +328,6 @@ public:
|
|||
*/
|
||||
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
|
||||
* as the name of the settings directory for this KiCad version.
|
||||
|
@ -350,23 +339,6 @@ public:
|
|||
private:
|
||||
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"
|
||||
* @return -1 if aFirst is older than aSecond, 1 if aFirst is newer than aSecond, 0 otherwise
|
||||
|
|
|
@ -94,7 +94,7 @@ PLUGIN_CONTENT_MANAGER::PLUGIN_CONTENT_MANAGER(
|
|||
}
|
||||
|
||||
// Load currently installed packages
|
||||
wxFileName f( SETTINGS_MANAGER::GetUserSettingsPath(), wxT( "installed_packages.json" ) );
|
||||
wxFileName f( PATHS::GetUserSettingsPath(), wxT( "installed_packages.json" ) );
|
||||
|
||||
if( f.FileExists() )
|
||||
{
|
||||
|
@ -885,7 +885,7 @@ void PLUGIN_CONTENT_MANAGER::SaveInstalledPackages()
|
|||
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() );
|
||||
|
||||
stream << std::setw( 4 ) << js << std::endl;
|
||||
|
|
Loading…
Reference in New Issue