25#include <wx/filename.h>
26#include <wx/snglinst.h>
27#include <wx/stdpaths.h>
56 m_headless( aHeadless ),
58 m_common_settings( nullptr ),
60 m_migrateLibraryTables( true )
81 if( !wxFileExists( commonSettings.GetFullPath() ) )
96 for( std::unique_ptr<JSON_SETTINGS>& settings :
m_settings )
107 std::unique_ptr<JSON_SETTINGS> ptr( aSettings );
109 ptr->SetManager(
this );
111 wxLogTrace(
traceSettings, wxT(
"Registered new settings object <%s>" ),
112 ptr->GetFullFilename() );
126 std::vector<JSON_SETTINGS*> toLoad;
130 []( std::unique_ptr<JSON_SETTINGS>& aSettings )
132 return aSettings.get();
143 [&aSettings](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
145 return aPtr.get() == aSettings;
177 [&aSettings](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
179 return aPtr.get() == aSettings;
184 wxLogTrace(
traceSettings, wxT(
"Saving %s" ), ( *it )->GetFullFilename() );
193 [&aSettings](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
195 return aPtr.get() == aSettings;
200 wxLogTrace(
traceSettings, wxT(
"Flush and release %s" ), ( *it )->GetFullFilename() );
206 size_t typeHash =
typeid( *tmp ).hash_code();
224 [&aName](
const std::pair<wxString, COLOR_SETTINGS*>& p )
226 return p.second->GetName().Lower() == aName.Lower();
257 wxLogTrace(
traceSettings, wxT(
"Attempting to load color theme %s" ), aName );
261 if( !fn.IsOk() || !fn.Exists() )
263 wxLogTrace(
traceSettings, wxT(
"Theme file %s.json not found, falling back to user" ),
270 if( settings->
GetFilename() != aName.ToStdString() )
272 wxLogTrace(
traceSettings, wxT(
"Warning: stored filename is actually %s, " ),
293 wxDirTraverseResult
OnFile(
const wxString& aFilePath )
override
295 wxFileName file( aFilePath );
297 if( file.GetExt() == wxS(
"json" ) )
300 return wxDIR_CONTINUE;
303 wxDirTraverseResult
OnDir(
const wxString& dirPath )
override
305 return wxDIR_CONTINUE;
325 if( aName.EndsWith( wxT(
".json" ) ) )
337 settings->
SetName( wxT(
"User" ) );
357 wxFileName third_party_path;
361 if( it != env.end() && !it->second.GetValue().IsEmpty() )
362 third_party_path.SetPath( it->second.GetValue() );
366 third_party_path.AppendDir( wxS(
"colors" ) );
369 wxDir third_party_colors_dir( third_party_path.GetFullPath() );
384 [&](
const wxFileName& aFilename )
390 if( system_colors_dir.IsOpened() )
391 system_colors_dir.Traverse( readOnlyLoader );
393 if( third_party_colors_dir.IsOpened() )
394 third_party_colors_dir.Traverse( readOnlyLoader );
396 if( colors_dir.IsOpened() )
397 colors_dir.Traverse( loader );
412 [aSettings] (
const std::pair<wxString, COLOR_SETTINGS*>& el )
414 return el.second->GetFilename() == aSettings->GetFilename();
421 if( !aSettings->
Store() )
423 wxLogTrace(
traceSettings, wxT(
"Color scheme %s not modified; skipping save" ),
428 wxASSERT( aSettings->
Contains( aNamespace ) );
430 wxLogTrace(
traceSettings, wxT(
"Saving color scheme %s, preserving %s" ),
434 std::optional<nlohmann::json> backup = aSettings->
GetJson( aNamespace );
440 ( *aSettings->
Internals() )[aNamespace].update( *backup );
450 wxASSERT( aSettings );
454 case SETTINGS_LOC::USER:
457 case SETTINGS_LOC::PROJECT:
461 case SETTINGS_LOC::COLORS:
464 case SETTINGS_LOC::TOOLBARS:
467 case SETTINGS_LOC::NONE:
471 wxASSERT_MSG(
false, wxT(
"Unknown settings location!" ) );
496 wxDirTraverseResult
OnFile(
const wxString& aSrcFilePath )
override
498 wxFileName file( aSrcFilePath );
503 return wxDIR_CONTINUE;
507 if( file.GetFullName() == wxT(
"installed_packages.json" ) )
508 return wxDIR_CONTINUE;
512 if( file.GetExt() == wxT(
"hotkeys" ) )
513 return wxDIR_CONTINUE;
515 wxString
path = file.GetPath();
518 file.SetPath(
path );
520 wxLogTrace(
traceSettings, wxT(
"Copying %s to %s" ), aSrcFilePath, file.GetFullPath() );
525 return wxDIR_CONTINUE;
528 wxDirTraverseResult
OnDir(
const wxString& dirPath )
override
530 wxFileName dir( dirPath );
533 if( dir.GetName() == wxS(
"colors" ) ||
534 dir.GetName() == wxS(
"3d" ) )
537 wxString
path = dir.GetPath();
542 wxMkdir( dir.GetFullPath() );
544 return wxDIR_CONTINUE;
557 wxLogTrace(
traceSettings, wxT(
"Using settings path %s" ),
path.GetFullPath() );
565 if( !
path.DirExists() )
567 wxLogTrace(
traceSettings, wxT(
"Path didn't exist; creating it" ) );
568 path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
571 wxLogTrace(
traceSettings, wxT(
"Settings migration not checked; running headless" ) );
575 if(
path.DirExists() )
577 wxFileName common =
path;
578 common.SetName( wxS(
"kicad_common" ) );
579 common.SetExt( wxS(
"json" ) );
581 if( common.Exists() )
583 wxLogTrace(
traceSettings, wxT(
"Path exists and has a kicad_common, continuing!" ) );
593 wxLogTrace(
traceSettings, wxT(
"Migration dialog canceled; exiting" ) );
597 if( !
path.DirExists() )
599 wxLogTrace(
traceSettings, wxT(
"Path didn't exist; creating it" ) );
600 path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
605 wxLogTrace(
traceSettings, wxT(
"No migration source given; starting with defaults" ) );
614 source_dir.Traverse( traverser );
626 const std::vector<wxString> libKeys = {
627 wxT(
"KICAD6_SYMBOL_DIR" ),
628 wxT(
"KICAD6_3DMODEL_DIR" ),
629 wxT(
"KICAD6_FOOTPRINT_DIR" ),
630 wxT(
"KICAD6_TEMPLATE_DIR" ),
631 wxT(
"KICAD7_SYMBOL_DIR" ),
632 wxT(
"KICAD7_3DMODEL_DIR" ),
633 wxT(
"KICAD7_FOOTPRINT_DIR" ),
634 wxT(
"KICAD7_TEMPLATE_DIR" ),
635 wxT(
"KICAD8_SYMBOL_DIR" ),
636 wxT(
"KICAD8_3DMODEL_DIR" ),
637 wxT(
"KICAD8_FOOTPRINT_DIR" ),
638 wxT(
"KICAD8_TEMPLATE_DIR" ),
641 wxT(
"KICAD_PTEMPLATES" ),
644 wxT(
"KICAD_SYMBOL_DIR" ),
647 for(
const wxString& key : libKeys )
664 std::vector<wxFileName> base_paths;
669 if( wxGetEnv( wxT(
"KICAD_CONFIG_HOME" ),
nullptr ) )
680 wxFileName wxGtkPath;
681 wxGtkPath.AssignDir( wxS(
"~/.config/kicad" ) );
682 wxGtkPath.MakeAbsolute();
683 base_paths.emplace_back( wxGtkPath );
686 wxGtkPath.AssignDir( wxS(
"~/.var/app/org.kicad.KiCad/config/kicad" ) );
687 wxGtkPath.MakeAbsolute();
688 base_paths.emplace_back( wxGtkPath );
695 auto check_dir = [&] (
const wxString& aSubDir )
700 wxString sub_path = dir.GetNameWithSep() + aSubDir;
704 aPaths->push_back( sub_path );
705 wxLogTrace(
traceSettings, wxT(
"GetPreviousVersionName: %s is valid" ), sub_path );
710 std::set<wxString> checkedPaths;
712 for(
const wxFileName& base_path : base_paths )
714 if( checkedPaths.count( base_path.GetFullPath() ) )
717 checkedPaths.insert( base_path.GetFullPath() );
719 if( !dir.Open( base_path.GetFullPath() ) )
721 wxLogTrace(
traceSettings, wxT(
"GetPreviousVersionName: could not open base path %s" ),
722 base_path.GetFullPath() );
726 wxLogTrace(
traceSettings, wxT(
"GetPreviousVersionName: checking base path %s" ),
727 base_path.GetFullPath() );
729 if( dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
734 while( dir.GetNext( &subdir ) )
745 wxT(
"GetPreviousVersionName: root path %s is valid" ), dir.GetName() );
746 aPaths->push_back( dir.GetName() );
750 std::erase_if( *aPaths, [](
const wxString& aPath ) ->
bool
752 wxFileName fulldir = wxFileName::DirName( aPath );
753 const wxArrayString& dirs = fulldir.GetDirs();
755 if( dirs.empty() || !fulldir.IsDirReadable() )
758 std::string ver = dirs.back().ToStdString();
766 std::sort( aPaths->begin(), aPaths->end(),
767 [&](
const wxString& a,
const wxString& b ) ->
bool
769 wxFileName aPath = wxFileName::DirName( a );
770 wxFileName bPath = wxFileName::DirName( b );
772 const wxArrayString& aDirs = aPath.GetDirs();
773 const wxArrayString& bDirs = bPath.GetDirs();
781 std::string verA = aDirs.back().ToStdString();
782 std::string verB = bDirs.back().ToStdString();
784 if( !extractVersion( verA ) )
787 if( !extractVersion( verB ) )
790 return compareVersions( verA, verB ) >= 0;
793 return aPaths->size() > 0;
799 wxFileName
test( aPath, wxS(
"kicad_common" ) );
804 test.SetExt(
"json" );
806 return test.Exists();
815 path.AppendDir( wxS(
"colors" ) );
817 if( !
path.DirExists() )
819 if( !wxMkdir(
path.GetPath() ) )
822 wxT(
"GetColorSettingsPath(): Path %s missing and could not be created!" ),
827 return path.GetPath();
836 path.AppendDir( wxS(
"toolbars" ) );
838 if( !
path.DirExists() )
840 if( !wxMkdir(
path.GetPath() ) )
843 wxT(
"GetToolbarSettingsPath(): Path %s missing and could not be created!" ),
848 return path.GetPath();
868 wxLogTrace(
traceSettings, wxT(
"compareSettingsVersions: bad input (%s, %s)" ),
877 else if( a_maj > b_maj )
887 else if( a_min > b_min )
901 std::regex re_version(
"(\\d+)\\.(\\d+)" );
904 if( std::regex_match( aVersionString, match, re_version ) )
908 int major = std::stoi( match[1].str() );
909 int minor = std::stoi( match[2].str() );
932 wxFileName
path( aFullPath );
937 wxString fullPath =
path.GetFullPath();
947 if( !lockFile.
Valid() )
949 wxLogTrace(
traceSettings, wxT(
"Project %s is locked; opening read-only" ), fullPath );
960 [&](
const std::unique_ptr<PROJECT>& ptr )
962 return ptr.get() == oldProject;
969 wxLogTrace(
traceSettings, wxT(
"Load project %s" ), fullPath );
971 std::unique_ptr<PROJECT>
project = std::make_unique<PROJECT>();
972 project->setProjectFullName( fullPath );
978 wxFileName projectPath( fullPath );
982 if( !projectPath.GetPath().IsEmpty() && wxTheApp && wxTheApp->IsGUI() )
983 wxSetWorkingDirectory( projectPath.GetPath() );
992 if( lockFile && aSetActive )
999 wxString fn(
path.GetName() );
1008 m_projects[fullPath]->setLocalSettings( settings );
1026 wxLogTrace(
traceSettings, wxT(
"Unload project %s" ), projectPath );
1032 [&](
const std::unique_ptr<PROJECT>& ptr )
1034 return ptr.get() == toRemove;
1042 if( wasActiveProject )
1077 && !
m_projects.begin()->second->GetProjectFullName().IsEmpty() );
1092 std::vector<wxString> ret;
1094 for(
const std::pair<const wxString, PROJECT*>& pair :
m_projects )
1097 if( !pair.first.IsEmpty() )
1098 ret.emplace_back( pair.first );
1110 wxString
path = aFullPath;
1125 project->SaveToFile( projectPath );
1139 if( aFullPath.IsSameAs( oldName ) )
1148 wxFileName fn( aFullPath );
1157 project->SetFilename( fn.GetName() );
1158 project->SaveToFile( fn.GetPath() );
1177 wxString oldName =
project->GetFilename();
1178 wxFileName fn( aFullPath );
1180 bool readOnly =
project->IsReadOnly();
1181 project->SetReadOnly(
false );
1183 project->SetFilename( fn.GetName() );
1184 project->SaveToFile( fn.GetPath() );
1185 project->SetFilename( oldName );
1193 project->SetReadOnly( readOnly );
1200 wxString fn( fullFn.GetName() );
1209 wxString
path( fullFn.GetPath() );
1231 [&file](
const std::unique_ptr<JSON_SETTINGS>& aPtr )
1233 return aPtr.get() == file;
1245 ( *it )->SaveToFile( projectPath );
1267 wxDateTime timestamp = wxDateTime::Now();
1269 wxString fileName = wxString::Format( wxT(
"%s-%s" ),
Prj().GetProjectName(),
1272 if( !aTarget.IsOk() )
1275 aTarget.SetName( fileName );
1279 if( !aTarget.DirExists() && !wxMkdir( aTarget.GetPath() ) )
1281 wxLogTrace(
traceSettings, wxT(
"Could not create project backup path %s" ),
1282 aTarget.GetPath() );
1286 if( !aTarget.IsDirWritable() )
1288 wxLogTrace(
traceSettings, wxT(
"Backup directory %s is not writable" ),
1289 aTarget.GetPath() );
1293 wxLogTrace(
traceSettings, wxT(
"Backing up project to %s" ), aTarget.GetPath() );
1303 std::function<
bool(
const wxString& )> aCond ) :
1309 wxDirTraverseResult
OnFile(
const wxString& aFile )
override
1312 m_files.emplace_back( aFile );
1314 return wxDIR_CONTINUE;
1317 wxDirTraverseResult
OnDir(
const wxString& aDirName )
override
1319 return wxDIR_CONTINUE;
1339 [&prefix](
const wxString& aFile )
1342 wxString fn( wxFileName( aFile ).GetName() );
1343 fn.Replace( prefix, wxS(
"" ) );
1348 wxFileName projectPath(
Prj().GetProjectPath(), wxEmptyString, wxEmptyString );
1351 if( !projectPath.IsOk() || !projectPath.Exists() || !projectPath.IsDirWritable() )
1356 if( !wxDirExists( backupPath ) )
1358 wxLogTrace(
traceSettings, wxT(
"Backup path %s doesn't exist, creating it" ), backupPath );
1360 if( !wxMkdir( backupPath ) )
1362 wxLogTrace(
traceSettings, wxT(
"Could not create backups path! Skipping backup" ) );
1367 wxDir dir( backupPath );
1369 if( !dir.IsOpened() )
1371 wxLogTrace(
traceSettings, wxT(
"Could not open project backups path %s" ), dir.GetName() );
1375 std::vector<wxString> files;
1378 [&modTime](
const wxString& aFile )
1380 return modTime( aFile ).IsValid();
1383 dir.Traverse( traverser, wxT(
"*.zip" ) );
1386 std::sort( files.begin(), files.end(),
1387 [&](
const wxString& aFirst,
const wxString& aSecond ) ->
bool
1389 wxDateTime first = modTime( aFirst );
1390 wxDateTime second = modTime( aSecond );
1392 return first.GetTicks() > second.GetTicks();
1396 if( !files.empty() )
1398 wxDateTime lastTime = modTime( files[0] );
1400 if( lastTime.IsValid() )
1402 wxTimeSpan
delta = wxDateTime::Now() - modTime( files[0] );
1413 if( !backupSuccessful )
1417 files.insert( files.begin(), target.GetFullPath() );
1420 if( files.size() >= 2
1423 wxRemoveFile( files[0] );
1434 wxRemoveFile( files.back() );
1442 wxULongLong totalSize = 0;
1444 for(
const wxString& file : files )
1445 totalSize += wxFileName::GetSize( file );
1447 while( !files.empty() && totalSize >
static_cast<wxULongLong
>( settings.
limit_total_size ) )
1449 totalSize -= wxFileName::GetSize( files.back() );
1450 wxRemoveFile( files.back() );
1458 wxDateTime day = modTime( files[0] );
1461 wxASSERT( day.IsValid() );
1463 std::vector<wxString> filesToDelete;
1465 for(
size_t i = 1; i < files.size(); i++ )
1467 wxDateTime dt = modTime( files[i] );
1469 if( dt.IsSameDate( day ) )
1474 filesToDelete.emplace_back( files[i] );
1483 for(
const wxString& file : filesToDelete )
1484 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)
wxString GetFullFilename() const
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
virtual void ProjectChanged()
Calls ProjectChanged() on all KIWAY_PLAYERs.
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
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)
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.
bool MigrateIfNeeded()
Handle the initialization of the user settings directory and migration from previous KiCad versions a...
wxString m_migration_source
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely save a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
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)
bool m_headless
True if running outside a UI context.
COLOR_SETTINGS * GetColorSettings(const wxString &aName)
Retrieve a color settings object that applications can read colors from.
SETTINGS_MANAGER(bool aHeadless=false)
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.
wxString GetProjectBackupsPath() const
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Load a project or sets up a new project with a specified path.
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).
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 LegacyProjectFileExtension
static const std::string FootprintLibraryTableFileName
static const std::string ArchiveFileExtension
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
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.
PGM_BASE & Pgm()
The global program "get" accessor.
#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.
Definition of file extensions used in Kicad.