25#include <wx/filename.h>
26#include <wx/snglinst.h>
27#include <wx/stdpaths.h>
64 if( !
path.DirExists() )
66 wxLogTrace(
traceSettings, wxT(
"Path didn't exist; creating it" ) );
67 path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
75 wxLogTrace(
traceSettings, wxT(
"Note: no valid settings directory on disk" ) );
96 for( std::unique_ptr<JSON_SETTINGS>& settings :
m_settings )
107 for( std::unique_ptr<JSON_SETTINGS>& settings :
m_settings )
111 std::map<std::string, nlohmann::json> fileHistories = settings->GetFileHistories();
113 settings->Internals()->clear();
116 for(
const auto& [
path, history] : fileHistories )
117 settings->Set(
path, history );
127 for( std::unique_ptr<JSON_SETTINGS>& settings :
m_settings )
131 for(
const auto& [
path, history] : settings->GetFileHistories() )
132 settings->Set(
path, nlohmann::json::array() );
142 std::unique_ptr<JSON_SETTINGS> ptr( aSettings );
144 ptr->SetManager(
this );
146 wxLogTrace(
traceSettings, wxT(
"Registered new settings object <%s>" ),
147 ptr->GetFullFilename() );
161 std::vector<JSON_SETTINGS*> toLoad;
165 []( std::unique_ptr<JSON_SETTINGS>& aSettings )
167 return aSettings.get();
178 [&aSettings](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
180 return aPtr.get() == aSettings;
212 [&aSettings](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
214 return aPtr.get() == aSettings;
219 wxLogTrace(
traceSettings, wxT(
"Saving %s" ), ( *it )->GetFullFilename() );
228 [&aSettings](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
230 return aPtr.get() == aSettings;
235 wxLogTrace(
traceSettings, wxT(
"Flush and release %s" ), ( *it )->GetFullFilename() );
241 size_t typeHash =
typeid( *tmp ).hash_code();
259 [&aName](
const std::pair<wxString, COLOR_SETTINGS*>& p )
261 return p.second->GetName().Lower() == aName.Lower();
292 std::vector<COLOR_SETTINGS*> ret;
294 for(
const std::pair<const wxString, COLOR_SETTINGS*>& entry :
m_color_settings )
295 ret.push_back( entry.second );
298 { return a->GetName() < b->GetName(); } );
306 wxLogTrace(
traceSettings, wxT(
"Attempting to load color theme %s" ), aName );
310 if( !fn.IsOk() || !fn.Exists() )
312 wxLogTrace(
traceSettings, wxT(
"Theme file %s.json not found, falling back to user" ),
319 if( settings->
GetFilename() != aName.ToStdString() )
321 wxLogTrace(
traceSettings, wxT(
"Warning: stored filename is actually %s, " ),
342 wxDirTraverseResult
OnFile(
const wxString& aFilePath )
override
344 wxFileName file( aFilePath );
346 if( file.GetExt() == wxS(
"json" ) )
349 return wxDIR_CONTINUE;
352 wxDirTraverseResult
OnDir(
const wxString& dirPath )
override
354 return wxDIR_CONTINUE;
374 if( aName.EndsWith( wxT(
".json" ) ) )
386 settings->
SetName( wxT(
"User" ) );
406 wxFileName third_party_path;
410 if( it != env.end() && !it->second.GetValue().IsEmpty() )
411 third_party_path.SetPath( it->second.GetValue() );
415 third_party_path.AppendDir( wxS(
"colors" ) );
418 wxDir third_party_colors_dir( third_party_path.GetFullPath() );
433 [&](
const wxFileName& aFilename )
439 if( system_colors_dir.IsOpened() )
440 system_colors_dir.Traverse( readOnlyLoader );
442 if( third_party_colors_dir.IsOpened() )
443 third_party_colors_dir.Traverse( readOnlyLoader );
445 if( colors_dir.IsOpened() )
446 colors_dir.Traverse( loader );
461 [aSettings] (
const std::pair<wxString, COLOR_SETTINGS*>& el )
463 return el.second->GetFilename() == aSettings->GetFilename();
470 if( !aSettings->
Store() )
472 wxLogTrace(
traceSettings, wxT(
"Color scheme %s not modified; skipping save" ),
477 wxASSERT( aSettings->
Contains( aNamespace ) );
479 wxLogTrace(
traceSettings, wxT(
"Saving color scheme %s, preserving %s" ),
483 std::optional<nlohmann::json> backup = aSettings->
GetJson( aNamespace );
489 ( *aSettings->
Internals() )[aNamespace].update( *backup );
499 wxASSERT( aSettings );
520 wxASSERT_MSG(
false, wxT(
"Unknown settings location!" ) );
545 wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
547 wxFileName file( aSrcFilePath );
552 return wxDIR_CONTINUE;
556 if( file.GetFullName() == wxT(
"installed_packages.json" ) )
557 return wxDIR_CONTINUE;
561 if( file.GetExt() == wxT(
"hotkeys" ) )
562 return wxDIR_CONTINUE;
564 wxString
path = file.GetPath();
567 file.SetPath(
path );
569 wxLogTrace(
traceSettings, wxT(
"Copying %s to %s" ), aSrcFilePath, file.GetFullPath() );
574 return wxDIR_CONTINUE;
577 wxDirTraverseResult
OnDir(
const wxString& dirPath )
override
579 wxFileName dir( dirPath );
582 if( dir.GetName() == wxS(
"colors" ) ||
583 dir.GetName() == wxS(
"3d" ) )
586 wxString
path = dir.GetPath();
591 if( !wxDirExists( dir.GetPath() ) )
592 wxMkdir( dir.GetPath() );
594 return wxDIR_CONTINUE;
608 if(
path.DirExists() )
610 wxFileName common =
path;
611 common.SetName( wxS(
"kicad_common" ) );
612 common.SetExt( wxS(
"json" ) );
614 if( common.Exists() )
616 wxLogTrace(
traceSettings, wxT(
"Path exists and has a kicad_common, continuing!" ) );
629 if( aSourcePath.IsEmpty() )
632 wxLogTrace(
traceSettings, wxT(
"Migrating from path %s" ), aSourcePath );
636 wxDir source_dir( aSourcePath );
638 source_dir.Traverse( traverser );
650 const std::vector<wxString> libKeys = {
651 wxT(
"KICAD6_SYMBOL_DIR" ),
652 wxT(
"KICAD6_3DMODEL_DIR" ),
653 wxT(
"KICAD6_FOOTPRINT_DIR" ),
654 wxT(
"KICAD6_TEMPLATE_DIR" ),
655 wxT(
"KICAD7_SYMBOL_DIR" ),
656 wxT(
"KICAD7_3DMODEL_DIR" ),
657 wxT(
"KICAD7_FOOTPRINT_DIR" ),
658 wxT(
"KICAD7_TEMPLATE_DIR" ),
659 wxT(
"KICAD8_SYMBOL_DIR" ),
660 wxT(
"KICAD8_3DMODEL_DIR" ),
661 wxT(
"KICAD8_FOOTPRINT_DIR" ),
662 wxT(
"KICAD8_TEMPLATE_DIR" ),
665 wxT(
"KICAD_PTEMPLATES" ),
668 wxT(
"KICAD_SYMBOL_DIR" ),
671 for(
const wxString& key : libKeys )
688 std::vector<wxFileName> base_paths;
693 if( wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ),
nullptr ) )
704 wxFileName wxGtkPath;
705 wxGtkPath.AssignDir( wxS(
"~/.config/kicad" ) );
706 wxGtkPath.MakeAbsolute();
707 base_paths.emplace_back( wxGtkPath );
710 wxGtkPath.AssignDir( wxS(
"~/.var/app/org.kicad.KiCad/config/kicad" ) );
711 wxGtkPath.MakeAbsolute();
712 base_paths.emplace_back( wxGtkPath );
720 [&] (
const wxString& aSubDir )
725 wxString sub_path = dir.GetNameWithSep() + aSubDir;
729 aPaths->push_back( sub_path );
730 wxLogTrace(
traceSettings, wxT(
"GetPreviousVersionName: %s is valid" ), sub_path );
735 std::set<wxString> checkedPaths;
737 for(
const wxFileName& base_path : base_paths )
739 if( checkedPaths.count( base_path.GetFullPath() ) )
742 checkedPaths.insert( base_path.GetFullPath() );
744 if( !dir.Open( base_path.GetFullPath() ) )
746 wxLogTrace(
traceSettings, wxT(
"GetPreviousVersionName: could not open base path %s" ),
747 base_path.GetFullPath() );
751 wxLogTrace(
traceSettings, wxT(
"GetPreviousVersionName: checking base path %s" ),
752 base_path.GetFullPath() );
754 if( dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
759 while( dir.GetNext( &subdir ) )
770 wxT(
"GetPreviousVersionName: root path %s is valid" ), dir.GetName() );
771 aPaths->push_back( dir.GetName() );
775 std::erase_if( *aPaths,
776 [](
const wxString& aPath ) ->
bool
778 wxFileName fulldir = wxFileName::DirName( aPath );
779 const wxArrayString& dirs = fulldir.GetDirs();
781 if( dirs.empty() || !fulldir.IsDirReadable() )
784 std::string ver = dirs.back().ToStdString();
792 std::sort( aPaths->begin(), aPaths->end(),
793 [&](
const wxString& a,
const wxString& b ) ->
bool
795 wxFileName aPath = wxFileName::DirName( a );
796 wxFileName bPath = wxFileName::DirName( b );
798 const wxArrayString& aDirs = aPath.GetDirs();
799 const wxArrayString& bDirs = bPath.GetDirs();
807 std::string verA = aDirs.back().ToStdString();
808 std::string verB = bDirs.back().ToStdString();
810 if( !extractVersion( verA ) )
813 if( !extractVersion( verB ) )
816 return compareVersions( verA, verB ) > 0;
819 return aPaths->size() > 0;
825 wxFileName
test( aPath, wxS(
"kicad_common" ) );
830 test.SetExt(
"json" );
832 return test.Exists();
841 path.AppendDir( wxS(
"colors" ) );
843 if( !
path.DirExists() )
845 if( !wxMkdir(
path.GetPath() ) )
848 wxT(
"GetColorSettingsPath(): Path %s missing and could not be created!" ),
853 return path.GetPath();
862 path.AppendDir( wxS(
"toolbars" ) );
864 if( !
path.DirExists() )
866 if( !wxMkdir(
path.GetPath() ) )
869 wxT(
"GetToolbarSettingsPath(): Path %s missing and could not be created!" ),
874 return path.GetPath();
894 wxLogTrace(
traceSettings, wxT(
"compareSettingsVersions: bad input (%s, %s)" ),
903 else if( a_maj > b_maj )
913 else if( a_min > b_min )
927 std::regex re_version(
"(\\d+)\\.(\\d+)" );
930 if( std::regex_match( aVersionString, match, re_version ) )
934 int major = std::stoi( match[1].str() );
935 int minor = std::stoi( match[2].str() );
959 wxFileName
path( aFullPath );
964 wxString fullPath =
path.GetFullPath();
974 if( !lockFile.
Valid() )
976 wxLogTrace(
traceSettings, wxT(
"Project %s is locked; opening read-only" ), fullPath );
988 pcbFace->CancelPreload(
true );
1001 [&](
const std::unique_ptr<PROJECT>& ptr )
1003 return ptr.get() == oldProject;
1010 wxLogTrace(
traceSettings, wxT(
"Load project %s" ), fullPath );
1012 std::unique_ptr<PROJECT>
project = std::make_unique<PROJECT>();
1013 project->setProjectFullName( fullPath );
1019 wxFileName projectPath( fullPath );
1023 if( !projectPath.GetPath().IsEmpty() && wxTheApp && wxTheApp->IsGUI() )
1024 wxSetWorkingDirectory( projectPath.GetPath() );
1033 if( projectPath.GetPath().IsEmpty() )
1039 wxFileName vcsContext( projectPath );
1040 vcsContext.MakeAbsolute();
1051 if( lockFile && aSetActive )
1058 wxString fn(
path.GetName() );
1067 m_projects[fullPath]->setLocalSettings( settings );
1087 wxLogTrace(
traceSettings, wxT(
"Unload project %s" ), projectPath );
1095 if( wasActiveProject &&
m_kiway )
1098 pcbFace->CancelPreload(
true );
1110 [&](
const std::unique_ptr<PROJECT>& ptr )
1112 return ptr.get() == toRemove;
1120 if( wasActiveProject )
1137 if( wxTheApp && wxTheApp->IsGUI() )
1154 wxLogTrace(
traceSettings, wxT(
"Prj() called with no project loaded" ) );
1156 static PROJECT s_emptyProject;
1157 return s_emptyProject;
1173 && !
m_projects.begin()->second->GetProjectFullName().IsEmpty() );
1188 std::vector<wxString> ret;
1190 for(
const std::pair<const wxString, PROJECT*>& pair :
m_projects )
1193 if( !pair.first.IsEmpty() )
1194 ret.emplace_back( pair.first );
1206 wxString
path = aFullPath;
1221 project->SaveToFile( projectPath );
1235 if( aFullPath.IsSameAs( oldName ) )
1244 wxFileName fn( aFullPath );
1253 project->SetFilename( fn.GetName() );
1254 project->SaveToFile( fn.GetPath() );
1273 wxString oldName =
project->GetFilename();
1274 wxFileName fn( aFullPath );
1276 bool readOnly =
project->IsReadOnly();
1277 project->SetReadOnly(
false );
1279 project->SetFilename( fn.GetName() );
1280 project->SaveToFile( fn.GetPath() );
1281 project->SetFilename( oldName );
1289 project->SetReadOnly( readOnly );
1296 wxString fn( fullFn.GetName() );
1305 wxString
path( fullFn.GetPath() );
1327 [&file](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
1329 return aPtr.get() == file;
1341 ( *it )->SaveToFile( projectPath );
1363 wxDateTime timestamp = wxDateTime::Now();
1365 wxString fileName = wxString::Format( wxT(
"%s-%s" ),
Prj().GetProjectName(),
1368 if( !aTarget.IsOk() )
1371 aTarget.SetName( fileName );
1375 if( !aTarget.DirExists() && !wxMkdir( aTarget.GetPath() ) )
1377 wxLogTrace(
traceSettings, wxT(
"Could not create project backup path %s" ),
1378 aTarget.GetPath() );
1382 if( !aTarget.IsDirWritable() )
1384 wxLogTrace(
traceSettings, wxT(
"Backup directory %s is not writable" ),
1385 aTarget.GetPath() );
1389 wxLogTrace(
traceSettings, wxT(
"Backing up project to %s" ), aTarget.GetPath() );
1399 std::function<
bool(
const wxString& )> aCond ) :
1405 wxDirTraverseResult
OnFile(
const wxString& aFile )
override
1408 m_files.emplace_back( aFile );
1410 return wxDIR_CONTINUE;
1413 wxDirTraverseResult
OnDir(
const wxString& aDirName )
override
1415 return wxDIR_CONTINUE;
1435 [&prefix](
const wxString& aFile )
1438 wxString fn( wxFileName( aFile ).GetName() );
1439 fn.Replace( prefix, wxS(
"" ) );
1444 wxFileName projectPath(
Prj().GetProjectPath(), wxEmptyString, wxEmptyString );
1447 if( !projectPath.IsOk() || !projectPath.Exists() || !projectPath.IsDirWritable() )
1452 if( !wxDirExists( backupPath ) )
1454 wxLogTrace(
traceSettings, wxT(
"Backup path %s doesn't exist, creating it" ), backupPath );
1456 if( !wxMkdir( backupPath ) )
1458 wxLogTrace(
traceSettings, wxT(
"Could not create backups path! Skipping backup" ) );
1463 wxDir dir( backupPath );
1465 if( !dir.IsOpened() )
1467 wxLogTrace(
traceSettings, wxT(
"Could not open project backups path %s" ), dir.GetName() );
1471 std::vector<wxString> files;
1474 [&modTime](
const wxString& aFile )
1476 return modTime( aFile ).IsValid();
1479 dir.Traverse( traverser, wxT(
"*.zip" ) );
1482 std::sort( files.begin(), files.end(),
1483 [&](
const wxString& aFirst,
const wxString& aSecond ) ->
bool
1485 wxDateTime first = modTime( aFirst );
1486 wxDateTime second = modTime( aSecond );
1488 return first.GetTicks() > second.GetTicks();
1492 if( !files.empty() )
1494 wxDateTime lastTime = modTime( files[0] );
1496 if( lastTime.IsValid() )
1498 wxTimeSpan
delta = wxDateTime::Now() - modTime( files[0] );
1509 if( !backupSuccessful )
1513 files.insert( files.begin(), target.GetFullPath() );
1516 if( files.size() >= 2
1519 wxRemoveFile( files[0] );
1530 wxRemoveFile( files.back() );
1538 wxULongLong totalSize = 0;
1540 for(
const wxString& file : files )
1541 totalSize += wxFileName::GetSize( file );
1543 while( !files.empty() && totalSize >
static_cast<wxULongLong
>( settings.
limit_total_size ) )
1545 totalSize -= wxFileName::GetSize( files.back() );
1546 wxRemoveFile( files.back() );
1554 wxDateTime day = modTime( files[0] );
1557 wxASSERT( day.IsValid() );
1559 std::vector<wxString> filesToDelete;
1561 for(
size_t i = 1; i < files.size(); i++ )
1563 wxDateTime dt = modTime( files[i] );
1565 if( dt.IsSameDate( day ) )
1570 filesToDelete.emplace_back( files[i] );
1579 for(
const wxString& file : filesToDelete )
1580 wxRemoveFile( file );
wxString GetMajorMinorVersion()
Get only the major and minor version in a string major.minor.
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetName(const wxString &aName)
static std::vector< COLOR_SETTINGS * > CreateBuiltinColorSettings()
Constructs and returns a list of color settings objects based on the built-in color themes.
static const wxString COLOR_BUILTIN_DEFAULT
std::function< void(const wxFileName &)> m_action
JSON_DIR_TRAVERSER(std::function< void(const wxFileName &)> aAction)
wxDirTraverseResult OnDir(const wxString &dirPath) override
wxDirTraverseResult OnFile(const wxString &aFilePath) override
std::optional< nlohmann::json > GetJson(const std::string &aPath) const
Fetches a JSON object that is a subset of this JSON_SETTINGS object, using a path of the form "key1....
bool Contains(const std::string &aPath) const
SETTINGS_LOC GetLocation() const
virtual bool LoadFromFile(const wxString &aDirectory="")
Loads the backing file from disk and then calls Load()
virtual void Load()
Updates the parameters of this object based on the current JSON document contents.
void SetReadOnly(bool aReadOnly)
JSON_SETTINGS_INTERNALS * Internals()
void SetFilename(const wxString &aFilename)
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
Calls Store() and then writes the contents of the JSON document to a file.
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
wxString GetFilename() const
void AbortAsyncLoads()
Abort any async library loading operations in progress.
void ProjectChanged()
Notify all adapters that the project has changed.
wxDirTraverseResult OnDir(const wxString &dirPath) override
MIGRATION_TRAVERSER(const wxString &aSrcDir, const wxString &aDestDir, bool aMigrateTables)
wxDirTraverseResult OnFile(const wxString &aSrcFilePath) override
static wxString CalculateUserSettingsPath(bool aIncludeVer=true, bool aUseEnv=true)
Determines the base path for user settings files.
static wxString GetDefault3rdPartyPath()
Gets the default path for PCM packages.
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
virtual ENV_VAR_MAP & GetLocalEnvVariables() const
virtual LIBRARY_MANAGER & GetLibraryManager() const
static bool Archive(const wxString &aSrcDir, const wxString &aDestFile, REPORTER &aReporter, bool aVerbose=true, bool aIncludeExtraFiles=false)
Create an archive of the project.
static bool AreZipArchivesIdentical(const wxString &aZipFileA, const wxString &aZipFileB, REPORTER &aReporter)
Compare the CRCs of all the files in zip archive to determine whether the archives are identical.
The backing store for a PROJECT, in JSON format.
bool ShouldAutoSave() const
void SetProject(PROJECT *aProject)
bool LoadFromFile(const wxString &aDirectory="") override
Loads the backing file from disk and then calls Load()
The project local settings are things that are attached to a particular project, but also might be pa...
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then writes the contents of the JSON document to a file.
bool ShouldAutoSave() const
Container for project specific data.
virtual void setProjectFile(PROJECT_FILE *aFile)
Set the backing store file for this project.
virtual bool IsReadOnly() const
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual const wxString GetProjectPath() const
Return the full path of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
A pure virtual class used to derive REPORTER objects from.
static int compareVersions(const std::string &aFirst, const std::string &aSecond)
Compare two settings versions, like "5.99" and "6.0".
wxString GetPathForSettingsFile(JSON_SETTINGS *aSettings)
Return the path a given settings file should be loaded from / stored to.
static std::string GetSettingsVersion()
Parse the current KiCad build version and extracts the major and minor revision to use as the name of...
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Set the currently loaded project path and saves it (pointers remain valid).
JSON_SETTINGS * registerSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
static wxString GetUserSettingsPath()
A proxy for PATHS::GetUserSettingsPath() rather than fighting swig.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Take ownership of the pointer passed in.
void SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Save a copy of the current project under the given path.
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely save a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
bool MigrateFromPreviousVersion(const wxString &aSourcePath)
Handle migration of the settings from previous KiCad versions.
std::map< wxString, PROJECT * > m_projects
Loaded projects, mapped according to project full name.
static bool extractVersion(const std::string &aVersionString, int *aMajor=nullptr, int *aMinor=nullptr)
Extract the numeric version from a given settings string.
COLOR_SETTINGS * registerColorSettings(const wxString &aFilename, bool aAbsolutePath=false)
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
Retrieve a color settings object that applications can read colors from.
static wxString GetColorSettingsPath()
Return the path where color scheme files are stored; creating it if missing (normally .
COMMON_SETTINGS * GetCommonSettings() const
Retrieve the common settings shared by all applications.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Save a loaded project.
void ClearFileHistory()
Clear saved file history from all settings files.
wxString GetProjectBackupsPath() const
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
void ResetToDefaults()
Reset all program settings to defaults.
bool SettingsDirectoryValid() const
std::map< wxString, PROJECT_FILE * > m_project_files
Loaded project files, mapped according to project full name.
std::unordered_map< wxString, COLOR_SETTINGS * > m_color_settings
COLOR_SETTINGS * loadColorSettingsByName(const wxString &aName)
Attempt to load a color theme by name (the color theme directory and .json ext are assumed).
std::vector< COLOR_SETTINGS * > GetColorSettingsList()
bool IsProjectOpen() const
Helper for checking if we have a project open.
static wxString GetToolbarSettingsPath()
Return the path where toolbar configuration files are stored; creating it if missing (normally .
bool GetPreviousVersionPaths(std::vector< wxString > *aName=nullptr)
Retrieve the name of the most recent previous KiCad version that can be found in the user settings di...
static bool IsSettingsPathValid(const wxString &aPath)
Check if a given path is probably a valid KiCad configuration directory.
bool BackupProject(REPORTER &aReporter, wxFileName &aTarget) const
Create a backup archive of the current project.
std::vector< std::unique_ptr< PROJECT > > m_projects_list
Loaded projects (ownership here).
void loadAllColorSettings()
PROJECT * GetProject(const wxString &aFullPath) const
Retrieve a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Save, unload and unregister the given PROJECT.
std::vector< wxString > GetOpenProjects() const
std::vector< std::unique_ptr< JSON_SETTINGS > > m_settings
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Call BackupProject() if a new backup is needed according to the current backup policy.
bool m_migrateLibraryTables
If true, the symbol and footprint library tables will be migrated from the previous version.
bool unloadProjectFile(PROJECT *aProject, bool aSave)
Optionally save, unload and unregister the given PROJECT_FILE.
COLOR_SETTINGS * GetMigratedColorSettings()
Return a color theme for storing colors migrated from legacy (5.x and earlier) settings,...
std::unordered_map< size_t, JSON_SETTINGS * > m_app_settings_cache
Cache for app settings.
COLOR_SETTINGS * AddNewColorSettings(const wxString &aFilename)
Register a new color settings object with the given filename.
bool m_ok
True if settings loaded successfully at construction.
void registerBuiltinColorSettings()
PROJECT & Prj() const
A helper while we are not MDI-capable – return the one and only project.
bool loadProjectFile(PROJECT &aProject)
Register a PROJECT_FILE and attempt to load it from disk.
bool IsProjectOpenNotDummy() const
Helper for checking if we have a project open that is not a dummy project.
static wxString backupDateTimeFormat
void ReloadColorSettings()
Re-scan the color themes directory, reloading any changes it finds.
COMMON_SETTINGS * m_common_settings
KIWAY * m_kiway
The kiway this settings manager interacts with.
void FlushAndRelease(JSON_SETTINGS *aSettings, bool aSave=true)
If the given settings object is registered, save it to disk and unregister it.
wxDirTraverseResult OnFile(const wxString &aFile) override
wxDirTraverseResult OnDir(const wxString &aDirName) override
std::vector< wxString > & m_files
VECTOR_INSERT_TRAVERSER(std::vector< wxString > &aVec, std::function< bool(const wxString &)> aCond)
std::function< bool(const wxString &)> m_condition
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
Functions related to environment variables, including help functions.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
static const std::string SymbolLibraryTableFileName
static const std::string ProjectFileExtension
static const std::string FootprintLibraryTableFileName
static const std::string ArchiveFileExtension
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
@ TOOLBARS
The toolbar directory (e.g. ~/.config/kicad/toolbars/)
@ PROJECT
The settings directory inside a project folder.
@ USER
The main config directory (e.g. ~/.config/kicad/)
@ COLORS
The color scheme directory (e.g. ~/.config/kicad/colors/)
@ NONE
No directory prepended, full path in filename (used for PROJECT_FILE)
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API wxString GetVersionedEnvVarName(const wxString &aBaseName)
Construct a versioned environment variable based on this KiCad major version.
void SetContextPath(const wxString &aPath)
Set the filesystem path used as the repository-discovery starting point for repo-scoped VCS queries (...
PGM_BASE & Pgm()
The global program "get" accessor.
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
#define PROJECT_BACKUPS_DIR_SUFFIX
Project settings path will be <projectname> + this.
int min_interval
Minimum time, in seconds, between subsequent backups.
unsigned long long limit_total_size
Maximum total size of backups (bytes), 0 for unlimited.
int limit_total_files
Maximum number of backup archives to retain.
int limit_daily_files
Maximum files to keep per day, 0 for unlimited.
bool enabled
Automatically back up the project when files are saved.
Implement a participant in the KIWAY alchemy.
Definition of file extensions used in Kicad.