|
|
|
@ -34,6 +34,7 @@ |
|
|
|
#include <kiway.h>
|
|
|
|
#include <lockfile.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <pgm_base.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <project.h>
|
|
|
|
#include <project/project_archiver.h>
|
|
|
|
@ -70,8 +71,6 @@ SETTINGS_MANAGER::SETTINGS_MANAGER( bool aHeadless ) : |
|
|
|
|
|
|
|
// create the common settings shared by all applications. Not loaded immediately
|
|
|
|
m_common_settings = RegisterSettings( new COMMON_SETTINGS, false ); |
|
|
|
|
|
|
|
loadAllColorSettings(); |
|
|
|
} |
|
|
|
|
|
|
|
SETTINGS_MANAGER::~SETTINGS_MANAGER() |
|
|
|
@ -226,13 +225,13 @@ COLOR_SETTINGS* SETTINGS_MANAGER::loadColorSettingsByName( const wxString& aName |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class COLOR_SETTINGS_LOADER : public wxDirTraverser |
|
|
|
class JSON_DIR_TRAVERSER : public wxDirTraverser |
|
|
|
{ |
|
|
|
private: |
|
|
|
std::function<void( const wxString& )> m_action; |
|
|
|
std::function<void( const wxFileName& )> m_action; |
|
|
|
|
|
|
|
public: |
|
|
|
explicit COLOR_SETTINGS_LOADER( std::function<void( const wxString& )> aAction ) |
|
|
|
explicit JSON_DIR_TRAVERSER( std::function<void( const wxFileName& )> aAction ) |
|
|
|
: m_action( std::move( aAction ) ) |
|
|
|
{ |
|
|
|
} |
|
|
|
@ -241,17 +240,15 @@ public: |
|
|
|
{ |
|
|
|
wxFileName file( aFilePath ); |
|
|
|
|
|
|
|
if( file.GetExt() != "json" ) |
|
|
|
return wxDIR_CONTINUE; |
|
|
|
|
|
|
|
m_action( file.GetName() ); |
|
|
|
if( file.GetExt() == "json" ) |
|
|
|
m_action( file ); |
|
|
|
|
|
|
|
return wxDIR_CONTINUE; |
|
|
|
} |
|
|
|
|
|
|
|
wxDirTraverseResult OnDir( const wxString& dirPath ) override |
|
|
|
{ |
|
|
|
return wxDIR_IGNORE; |
|
|
|
return wxDIR_CONTINUE; |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
@ -296,16 +293,44 @@ void SETTINGS_MANAGER::loadAllColorSettings() |
|
|
|
for( COLOR_SETTINGS* settings : COLOR_SETTINGS::CreateBuiltinColorSettings() ) |
|
|
|
m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false ); |
|
|
|
|
|
|
|
wxFileName third_party_path; |
|
|
|
const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables(); |
|
|
|
auto it = env.find( "KICAD6_3RD_PARTY" ); |
|
|
|
|
|
|
|
if( it != env.end() && !it->second.GetValue().IsEmpty() ) |
|
|
|
third_party_path.SetPath( it->second.GetValue() ); |
|
|
|
else |
|
|
|
third_party_path.SetPath( PATHS::GetDefault3rdPartyPath() ); |
|
|
|
|
|
|
|
third_party_path.AppendDir( "colors" ); |
|
|
|
|
|
|
|
wxDir third_party_colors_dir( third_party_path.GetFullPath() ); |
|
|
|
wxString color_settings_path = GetColorSettingsPath(); |
|
|
|
|
|
|
|
JSON_DIR_TRAVERSER copier( |
|
|
|
[&]( const wxFileName& aFilename ) |
|
|
|
{ |
|
|
|
wxFileName new_file( color_settings_path, aFilename.GetFullName() ); |
|
|
|
|
|
|
|
if( !new_file.Exists() ) |
|
|
|
wxCopyFile( aFilename.GetFullPath(), new_file.GetFullPath()); |
|
|
|
} ); |
|
|
|
|
|
|
|
// Search for and load any other settings
|
|
|
|
COLOR_SETTINGS_LOADER loader( [&]( const wxString& aFilename ) |
|
|
|
{ |
|
|
|
registerColorSettings( aFilename ); |
|
|
|
} ); |
|
|
|
JSON_DIR_TRAVERSER loader( [&]( const wxFileName& aFilename ) |
|
|
|
{ |
|
|
|
registerColorSettings( aFilename.GetName() ); |
|
|
|
} ); |
|
|
|
|
|
|
|
wxDir colors_dir( GetColorSettingsPath() ); |
|
|
|
wxDir colors_dir( color_settings_path ); |
|
|
|
|
|
|
|
if( colors_dir.IsOpened() ) |
|
|
|
{ |
|
|
|
if( third_party_colors_dir.IsOpened() ) |
|
|
|
third_party_colors_dir.Traverse( copier ); |
|
|
|
|
|
|
|
colors_dir.Traverse( loader ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|