KiCad PCB EDA Suite
Loading...
Searching...
No Matches
settings_manager.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 Jon Evans <[email protected]>
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22#include <regex>
23#include <wx/debug.h>
24#include <wx/dir.h>
25#include <wx/filename.h>
26#include <wx/snglinst.h>
27#include <wx/stdpaths.h>
28#include <wx/utils.h>
29
30#include <build_version.h>
31#include <confirm.h>
33#include <gestfich.h>
35#include <kiway.h>
36#include <lockfile.h>
37#include <macros.h>
38#include <pgm_base.h>
39#include <paths.h>
40#include <project.h>
49
50
52 m_headless( aHeadless ),
53 m_kiway( nullptr ),
54 m_common_settings( nullptr ),
55 m_migration_source(),
56 m_migrateLibraryTables( true )
57{
58 // Check if the settings directory already exists, and if not, perform a migration if possible
59 if( !MigrateIfNeeded() )
60 {
61 m_ok = false;
62 return;
63 }
64
65 m_ok = true;
66
67 // create the common settings shared by all applications. Not loaded immediately
69
70 // Create the built-in color settings
71 // Here to allow the Python API to access the built-in colors
73}
74
76{
77 for( std::unique_ptr<PROJECT>& project : m_projects_list )
78 project.reset();
79
80 m_projects.clear();
81
82 for( std::unique_ptr<JSON_SETTINGS>& settings : m_settings )
83 settings.reset();
84
85 m_settings.clear();
86
87 m_color_settings.clear();
88}
89
90
92{
93 std::unique_ptr<JSON_SETTINGS> ptr( aSettings );
94
95 ptr->SetManager( this );
96
97 wxLogTrace( traceSettings, wxT( "Registered new settings object <%s>" ), ptr->GetFullFilename() );
98
99 if( aLoadNow )
100 ptr->LoadFromFile( GetPathForSettingsFile( ptr.get() ) );
101
102 m_settings.push_back( std::move( ptr ) );
103 return m_settings.back().get();
104}
105
106
108{
109 // TODO(JE) We should check for dirty settings here and write them if so, because
110 // Load() could be called late in the application lifecycle
111
112 std::vector<JSON_SETTINGS*> toLoad;
113
114 // Cache a copy of raw pointers; m_settings may be modified during the load loop
115 std::transform( m_settings.begin(), m_settings.end(), std::back_inserter( toLoad ),
116 []( std::unique_ptr<JSON_SETTINGS>& aSettings )
117 {
118 return aSettings.get();
119 } );
120
121 for( JSON_SETTINGS* settings : toLoad )
122 settings->LoadFromFile( GetPathForSettingsFile( settings ) );
123}
124
125
127{
128 auto it = std::find_if( m_settings.begin(), m_settings.end(),
129 [&aSettings]( const std::unique_ptr<JSON_SETTINGS>& aPtr )
130 {
131 return aPtr.get() == aSettings;
132 } );
133
134 if( it != m_settings.end() )
135 ( *it )->LoadFromFile( GetPathForSettingsFile( it->get() ) );
136}
137
138
140{
141 for( auto&& settings : m_settings )
142 {
143 // Never automatically save color settings, caller should use SaveColorSettings
144 if( dynamic_cast<COLOR_SETTINGS*>( settings.get() ) )
145 continue;
146
147 settings->SaveToFile( GetPathForSettingsFile( settings.get() ) );
148 }
149}
150
151
153{
154 auto it = std::find_if( m_settings.begin(), m_settings.end(),
155 [&aSettings]( const std::unique_ptr<JSON_SETTINGS>& aPtr )
156 {
157 return aPtr.get() == aSettings;
158 } );
159
160 if( it != m_settings.end() )
161 {
162 wxLogTrace( traceSettings, wxT( "Saving %s" ), ( *it )->GetFullFilename() );
163 ( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) );
164 }
165}
166
167
169{
170 auto it = std::find_if( m_settings.begin(), m_settings.end(),
171 [&aSettings]( const std::unique_ptr<JSON_SETTINGS>& aPtr )
172 {
173 return aPtr.get() == aSettings;
174 } );
175
176 if( it != m_settings.end() )
177 {
178 wxLogTrace( traceSettings, wxT( "Flush and release %s" ), ( *it )->GetFullFilename() );
179
180 if( aSave )
181 ( *it )->SaveToFile( GetPathForSettingsFile( it->get() ) );
182
183 size_t typeHash = typeid( *it->get() ).hash_code();
184
185 if( m_app_settings_cache.count( typeHash ) )
186 m_app_settings_cache.erase( typeHash );
187
188 m_settings.erase( it );
189 }
190}
191
192
194{
195 // Find settings the fast way
196 if( m_color_settings.count( aName ) )
197 return m_color_settings.at( aName );
198
199 // Maybe it's the display name (cli is one method of invoke)
200 auto it = std::find_if( m_color_settings.begin(), m_color_settings.end(),
201 [&aName]( const std::pair<wxString, COLOR_SETTINGS*>& p )
202 {
203 return p.second->GetName().Lower() == aName.Lower();
204 } );
205
206 if( it != m_color_settings.end() )
207 {
208 return it->second;
209 }
210
211 // No match? See if we can load it
212 if( !aName.empty() )
213 {
215
216 if( !ret )
217 {
218 ret = registerColorSettings( aName );
220 ret->SetFilename( wxT( "user" ) );
221 ret->SetReadOnly( false );
222 }
223
224 return ret;
225 }
226
227 // This had better work
229}
230
231
233{
234 wxLogTrace( traceSettings, wxT( "Attempting to load color theme %s" ), aName );
235
236 wxFileName fn( GetColorSettingsPath(), aName, wxS( "json" ) );
237
238 if( !fn.IsOk() || !fn.Exists() )
239 {
240 wxLogTrace( traceSettings, wxT( "Theme file %s.json not found, falling back to user" ), aName );
241 return nullptr;
242 }
243
244 COLOR_SETTINGS* settings = RegisterSettings( new COLOR_SETTINGS( aName ) );
245
246 if( settings->GetFilename() != aName.ToStdString() )
247 {
248 wxLogTrace( traceSettings, wxT( "Warning: stored filename is actually %s, " ),
249 settings->GetFilename() );
250 }
251
252 m_color_settings[aName] = settings;
253
254 return settings;
255}
256
257
258class JSON_DIR_TRAVERSER : public wxDirTraverser
259{
260private:
261 std::function<void( const wxFileName& )> m_action;
262
263public:
264 explicit JSON_DIR_TRAVERSER( std::function<void( const wxFileName& )> aAction )
265 : m_action( std::move( aAction ) )
266 {
267 }
268
269 wxDirTraverseResult OnFile( const wxString& aFilePath ) override
270 {
271 wxFileName file( aFilePath );
272
273 if( file.GetExt() == wxS( "json" ) )
274 m_action( file );
275
276 return wxDIR_CONTINUE;
277 }
278
279 wxDirTraverseResult OnDir( const wxString& dirPath ) override
280 {
281 return wxDIR_CONTINUE;
282 }
283};
284
285
286COLOR_SETTINGS* SETTINGS_MANAGER::registerColorSettings( const wxString& aName, bool aAbsolutePath )
287{
288 if( !m_color_settings.count( aName ) )
289 {
290 COLOR_SETTINGS* colorSettings = RegisterSettings( new COLOR_SETTINGS( aName,
291 aAbsolutePath ) );
292 m_color_settings[aName] = colorSettings;
293 }
294
295 return m_color_settings.at( aName );
296}
297
298
300{
301 if( aName.EndsWith( wxT( ".json" ) ) )
302 return registerColorSettings( aName.BeforeLast( '.' ) );
303 else
304 return registerColorSettings( aName );
305}
306
307
309{
310 if( !m_color_settings.count( "user" ) )
311 {
312 COLOR_SETTINGS* settings = registerColorSettings( wxT( "user" ) );
313 settings->SetName( wxT( "User" ) );
314 Save( settings );
315 }
316
317 return m_color_settings.at( "user" );
318}
319
320
322{
324 m_color_settings[settings->GetFilename()] = RegisterSettings( settings, false );
325}
326
327
329{
330 // Create the built-in color settings
332
333 wxFileName third_party_path;
334 const ENV_VAR_MAP& env = Pgm().GetLocalEnvVariables();
335 auto it = env.find( wxS( "KICAD7_3RD_PARTY" ) );
336
337 if( it != env.end() && !it->second.GetValue().IsEmpty() )
338 third_party_path.SetPath( it->second.GetValue() );
339 else
340 third_party_path.SetPath( PATHS::GetDefault3rdPartyPath() );
341
342 third_party_path.AppendDir( wxS( "colors" ) );
343
344 // PCM-managed themes
345 wxDir third_party_colors_dir( third_party_path.GetFullPath() );
346
347 // System-installed themes
348 wxDir system_colors_dir( PATHS::GetStockDataPath( false ) + "/colors" );
349
350 // User-created themes
351 wxDir colors_dir( GetColorSettingsPath() );
352
353 // Search for and load any other settings
354 JSON_DIR_TRAVERSER loader( [&]( const wxFileName& aFilename )
355 {
356 registerColorSettings( aFilename.GetName() );
357 } );
358
359 JSON_DIR_TRAVERSER readOnlyLoader(
360 [&]( const wxFileName& aFilename )
361 {
362 COLOR_SETTINGS* settings = registerColorSettings( aFilename.GetFullPath(), true );
363 settings->SetReadOnly( true );
364 } );
365
366 if( system_colors_dir.IsOpened() )
367 system_colors_dir.Traverse( readOnlyLoader );
368
369 if( third_party_colors_dir.IsOpened() )
370 third_party_colors_dir.Traverse( readOnlyLoader );
371
372 if( colors_dir.IsOpened() )
373 colors_dir.Traverse( loader );
374}
375
376
378{
379 m_color_settings.clear();
381}
382
383
384void SETTINGS_MANAGER::SaveColorSettings( COLOR_SETTINGS* aSettings, const std::string& aNamespace )
385{
386 // The passed settings should already be managed
387 wxASSERT( std::find_if( m_color_settings.begin(), m_color_settings.end(),
388 [aSettings] ( const std::pair<wxString, COLOR_SETTINGS*>& el )
389 {
390 return el.second->GetFilename() == aSettings->GetFilename();
391 }
392 ) != m_color_settings.end() );
393
394 if( aSettings->IsReadOnly() )
395 return;
396
397 if( !aSettings->Store() )
398 {
399 wxLogTrace( traceSettings, wxT( "Color scheme %s not modified; skipping save" ),
400 aNamespace );
401 return;
402 }
403
404 wxASSERT( aSettings->Contains( aNamespace ) );
405
406 wxLogTrace( traceSettings, wxT( "Saving color scheme %s, preserving %s" ),
407 aSettings->GetFilename(),
408 aNamespace );
409
410 std::optional<nlohmann::json> backup = aSettings->GetJson( aNamespace );
411 wxString path = GetColorSettingsPath();
412
413 aSettings->LoadFromFile( path );
414
415 if( backup )
416 ( *aSettings->Internals() )[aNamespace].update( *backup );
417
418 aSettings->Load();
419
420 aSettings->SaveToFile( path, true );
421}
422
423
425{
426 wxASSERT( aSettings );
427
428 switch( aSettings->GetLocation() )
429 {
430 case SETTINGS_LOC::USER:
432
433 case SETTINGS_LOC::PROJECT:
434 // TODO: MDI support
435 return Prj().GetProjectPath();
436
437 case SETTINGS_LOC::COLORS:
438 return GetColorSettingsPath();
439
440 case SETTINGS_LOC::NONE:
441 return "";
442
443 default:
444 wxASSERT_MSG( false, wxT( "Unknown settings location!" ) );
445 }
446
447 return "";
448}
449
450
451class MIGRATION_TRAVERSER : public wxDirTraverser
452{
453private:
454 wxString m_src;
455 wxString m_dest;
456 wxString m_errors;
458
459public:
460 MIGRATION_TRAVERSER( const wxString& aSrcDir, const wxString& aDestDir, bool aMigrateTables ) :
461 m_src( aSrcDir ),
462 m_dest( aDestDir ),
463 m_migrateTables( aMigrateTables )
464 {
465 }
466
467 wxString GetErrors() { return m_errors; }
468
469 wxDirTraverseResult OnFile( const wxString& aSrcFilePath ) override
470 {
471 wxFileName file( aSrcFilePath );
472
473 if( !m_migrateTables && ( file.GetName() == wxT( "sym-lib-table" ) ||
474 file.GetName() == wxT( "fp-lib-table" ) ) )
475 {
476 return wxDIR_CONTINUE;
477 }
478
479 // Skip migrating PCM installed packages as packages themselves are not moved
480 if( file.GetFullName() == wxT( "installed_packages.json" ) )
481 return wxDIR_CONTINUE;
482
483 // Don't migrate hotkeys config files; we don't have a reasonable migration handler for them
484 // and so there is no way to resolve conflicts at the moment
485 if( file.GetExt() == wxT( "hotkeys" ) )
486 return wxDIR_CONTINUE;
487
488 wxString path = file.GetPath();
489
490 path.Replace( m_src, m_dest, false );
491 file.SetPath( path );
492
493 wxLogTrace( traceSettings, wxT( "Copying %s to %s" ), aSrcFilePath, file.GetFullPath() );
494
495 // For now, just copy everything
496 KiCopyFile( aSrcFilePath, file.GetFullPath(), m_errors );
497
498 return wxDIR_CONTINUE;
499 }
500
501 wxDirTraverseResult OnDir( const wxString& dirPath ) override
502 {
503 wxFileName dir( dirPath );
504
505 // Whitelist of directories to migrate
506 if( dir.GetName() == wxS( "colors" ) ||
507 dir.GetName() == wxS( "3d" ) )
508 {
509
510 wxString path = dir.GetPath();
511
512 path.Replace( m_src, m_dest, false );
513 dir.SetPath( path );
514
515 wxMkdir( dir.GetFullPath() );
516
517 return wxDIR_CONTINUE;
518 }
519 else
520 {
521 return wxDIR_IGNORE;
522 }
523 }
524};
525
526
528{
529 wxFileName path( PATHS::GetUserSettingsPath(), wxS( "" ) );
530 wxLogTrace( traceSettings, wxT( "Using settings path %s" ), path.GetFullPath() );
531
532 if( m_headless )
533 {
534 // Special case namely for cli
535 // Ensure the settings directory at least exists to prevent additional loading errors from subdirectories
536 // TODO review headless (unit tests) vs cli needs, this should be fine for unit tests though
537 if( !path.DirExists() )
538 {
539 wxLogTrace( traceSettings, wxT( "Path didn't exist; creating it" ) );
540 path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
541 }
542
543 wxLogTrace( traceSettings, wxT( "Settings migration not checked; running headless" ) );
544 return true;
545 }
546
547 if( path.DirExists() )
548 {
549 wxFileName common = path;
550 common.SetName( wxS( "kicad_common" ) );
551 common.SetExt( wxS( "json" ) );
552
553 if( common.Exists() )
554 {
555 wxLogTrace( traceSettings, wxT( "Path exists and has a kicad_common, continuing!" ) );
556 return true;
557 }
558 }
559
560 // Now we have an empty path, let's figure out what to put in it
561 DIALOG_MIGRATE_SETTINGS dlg( this );
562
563 if( dlg.ShowModal() != wxID_OK )
564 {
565 wxLogTrace( traceSettings, wxT( "Migration dialog canceled; exiting" ) );
566 return false;
567 }
568
569 if( !path.DirExists() )
570 {
571 wxLogTrace( traceSettings, wxT( "Path didn't exist; creating it" ) );
572 path.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
573 }
574
575 if( m_migration_source.IsEmpty() )
576 {
577 wxLogTrace( traceSettings, wxT( "No migration source given; starting with defaults" ) );
578 return true;
579 }
580
581 wxLogTrace( traceSettings, wxT( "Migrating from path %s" ), m_migration_source );
582
584 wxDir source_dir( m_migration_source );
585
586 source_dir.Traverse( traverser );
587
588 if( !traverser.GetErrors().empty() )
589 DisplayErrorMessage( nullptr, traverser.GetErrors() );
590
591 // Remove any library configuration if we didn't choose to import
593 {
594 COMMON_SETTINGS common;
595 wxString commonPath = GetPathForSettingsFile( &common );
596 common.LoadFromFile( commonPath );
597
598 const std::vector<wxString> libKeys = {
599 wxT( "KICAD6_SYMBOL_DIR" ),
600 wxT( "KICAD6_3DMODEL_DIR" ),
601 wxT( "KICAD6_FOOTPRINT_DIR" ),
602 wxT( "KICAD6_TEMPLATE_DIR" ), // Stores the default library table to be copied
603 wxT( "KICAD7_SYMBOL_DIR" ),
604 wxT( "KICAD7_3DMODEL_DIR" ),
605 wxT( "KICAD7_FOOTPRINT_DIR" ),
606 wxT( "KICAD7_TEMPLATE_DIR" ), // Stores the default library table to be copied
607
608 // Deprecated keys
609 wxT( "KICAD_PTEMPLATES" ),
610 wxT( "KISYS3DMOD" ),
611 wxT( "KISYSMOD" ),
612 wxT( "KICAD_SYMBOL_DIR" ),
613 };
614
615 for( const wxString& key : libKeys )
616 common.m_Env.vars.erase( key );
617
618 common.SaveToFile( commonPath );
619 }
620
621 return true;
622}
623
624
625bool SETTINGS_MANAGER::GetPreviousVersionPaths( std::vector<wxString>* aPaths )
626{
627 wxASSERT( aPaths );
628
629 aPaths->clear();
630
631 wxDir dir;
632 std::vector<wxFileName> base_paths;
633
634 base_paths.emplace_back( wxFileName( PATHS::CalculateUserSettingsPath( false ), wxS( "" ) ) );
635
636 // If the env override is set, also check the default paths
637 if( wxGetEnv( wxT( "KICAD_CONFIG_HOME" ), nullptr ) )
638 base_paths.emplace_back( wxFileName( PATHS::CalculateUserSettingsPath( false, false ), wxS( "" ) ) );
639
640#ifdef __WXGTK__
641 // When running inside FlatPak, KIPLATFORM::ENV::GetUserConfigPath() will return a sandboxed
642 // path. In case the user wants to move from non-FlatPak KiCad to FlatPak KiCad, let's add our
643 // best guess as to the non-FlatPak config path. Unfortunately FlatPak also hides the host
644 // XDG_CONFIG_HOME, so if the user customizes their config path, they will have to browse
645 // for it.
646 {
647 wxFileName wxGtkPath;
648 wxGtkPath.AssignDir( wxS( "~/.config/kicad" ) );
649 wxGtkPath.MakeAbsolute();
650 base_paths.emplace_back( wxGtkPath );
651
652 // We also want to pick up regular flatpak if we are nightly
653 wxGtkPath.AssignDir( wxS( "~/.var/app/org.kicad.KiCad/config/kicad" ) );
654 wxGtkPath.MakeAbsolute();
655 base_paths.emplace_back( wxGtkPath );
656 }
657#endif
658
659 wxString subdir;
660 std::string mine = GetSettingsVersion();
661
662 auto check_dir = [&] ( const wxString& aSubDir )
663 {
664 // Only older versions are valid for migration
665 if( compareVersions( aSubDir.ToStdString(), mine ) <= 0 )
666 {
667 wxString sub_path = dir.GetNameWithSep() + aSubDir;
668
669 if( IsSettingsPathValid( sub_path ) )
670 {
671 aPaths->push_back( sub_path );
672 wxLogTrace( traceSettings, wxT( "GetPreviousVersionName: %s is valid" ), sub_path );
673 }
674 }
675 };
676
677 std::set<wxString> checkedPaths;
678
679 for( const wxFileName& base_path : base_paths )
680 {
681 if( checkedPaths.count( base_path.GetFullPath() ) )
682 continue;
683
684 checkedPaths.insert( base_path.GetFullPath() );
685
686 if( !dir.Open( base_path.GetFullPath() ) )
687 {
688 wxLogTrace( traceSettings, wxT( "GetPreviousVersionName: could not open base path %s" ),
689 base_path.GetFullPath() );
690 continue;
691 }
692
693 wxLogTrace( traceSettings, wxT( "GetPreviousVersionName: checking base path %s" ),
694 base_path.GetFullPath() );
695
696 if( dir.GetFirst( &subdir, wxEmptyString, wxDIR_DIRS ) )
697 {
698 if( subdir != mine )
699 check_dir( subdir );
700
701 while( dir.GetNext( &subdir ) )
702 {
703 if( subdir != mine )
704 check_dir( subdir );
705 }
706 }
707
708 // If we didn't find one yet, check for legacy settings without a version directory
709 if( IsSettingsPathValid( dir.GetNameWithSep() ) )
710 {
711 wxLogTrace( traceSettings,
712 wxT( "GetPreviousVersionName: root path %s is valid" ), dir.GetName() );
713 aPaths->push_back( dir.GetName() );
714 }
715 }
716
717 std::sort( aPaths->begin(), aPaths->end(),
718 [&]( const wxString& a, const wxString& b ) -> bool
719 {
720 wxString verA = wxFileName::DirName( a ).GetDirs().back();
721 wxString verB = wxFileName::DirName( b ).GetDirs().back();
722
723 if( !extractVersion( verA.ToStdString() )
724 || !extractVersion( verB.ToStdString() ) )
725 {
726 return false;
727 }
728
729 return compareVersions( verA.ToStdString(), verB.ToStdString() ) >= 0;
730 } );
731
732 return aPaths->size() > 0;
733}
734
735
736bool SETTINGS_MANAGER::IsSettingsPathValid( const wxString& aPath )
737{
738 wxFileName test( aPath, wxS( "kicad_common" ) );
739
740 if( test.Exists() )
741 return true;
742
743 test.SetExt( "json" );
744
745 return test.Exists();
746}
747
748
750{
751 wxFileName path;
752
753 path.AssignDir( PATHS::GetUserSettingsPath() );
754 path.AppendDir( wxS( "colors" ) );
755
756 if( !path.DirExists() )
757 {
758 if( !wxMkdir( path.GetPath() ) )
759 {
760 wxLogTrace( traceSettings,
761 wxT( "GetColorSettingsPath(): Path %s missing and could not be created!" ),
762 path.GetPath() );
763 }
764 }
765
766 return path.GetPath();
767}
769{
770 // CMake computes the major.minor string for us.
771 return GetMajorMinorVersion().ToStdString();
772}
773
774
775int SETTINGS_MANAGER::compareVersions( const std::string& aFirst, const std::string& aSecond )
776{
777 int a_maj = 0;
778 int a_min = 0;
779 int b_maj = 0;
780 int b_min = 0;
781
782 if( !extractVersion( aFirst, &a_maj, &a_min ) || !extractVersion( aSecond, &b_maj, &b_min ) )
783 {
784 wxLogTrace( traceSettings, wxT( "compareSettingsVersions: bad input (%s, %s)" ), aFirst, aSecond );
785 return -1;
786 }
787
788 if( a_maj < b_maj )
789 {
790 return -1;
791 }
792 else if( a_maj > b_maj )
793 {
794 return 1;
795 }
796 else
797 {
798 if( a_min < b_min )
799 {
800 return -1;
801 }
802 else if( a_min > b_min )
803 {
804 return 1;
805 }
806 else
807 {
808 return 0;
809 }
810 }
811}
812
813
814bool SETTINGS_MANAGER::extractVersion( const std::string& aVersionString, int* aMajor, int* aMinor )
815{
816 std::regex re_version( "(\\d+)\\.(\\d+)" );
817 std::smatch match;
818
819 if( std::regex_match( aVersionString, match, re_version ) )
820 {
821 try
822 {
823 int major = std::stoi( match[1].str() );
824 int minor = std::stoi( match[2].str() );
825
826 if( aMajor )
827 *aMajor = major;
828
829 if( aMinor )
830 *aMinor = minor;
831 }
832 catch( ... )
833 {
834 return false;
835 }
836
837 return true;
838 }
839
840 return false;
841}
842
843
844bool SETTINGS_MANAGER::LoadProject( const wxString& aFullPath, bool aSetActive )
845{
846 // Normalize path to new format even if migrating from a legacy file
847 wxFileName path( aFullPath );
848
849 if( path.GetExt() == LegacyProjectFileExtension )
850 path.SetExt( ProjectFileExtension );
851
852 wxString fullPath = path.GetFullPath();
853
854 // If already loaded, we are all set. This might be called more than once over a project's
855 // lifetime in case the project is first loaded by the KiCad manager and then eeschema or
856 // pcbnew try to load it again when they are launched.
857 if( m_projects.count( fullPath ) )
858 return true;
859
860 bool readOnly = false;
861 LOCKFILE lockFile( fullPath );
862
863 if( !lockFile.Valid() )
864 {
865 wxLogTrace( traceSettings, wxT( "Project %s is locked; opening read-only" ), fullPath );
866 readOnly = true;
867 }
868
869 // No MDI yet
870 if( aSetActive && !m_projects.empty() )
871 {
872 PROJECT* oldProject = m_projects.begin()->second;
873 unloadProjectFile( oldProject, false );
874 m_projects.erase( m_projects.begin() );
875
876 auto it = std::find_if( m_projects_list.begin(), m_projects_list.end(),
877 [&]( const std::unique_ptr<PROJECT>& ptr )
878 {
879 return ptr.get() == oldProject;
880 } );
881
882 wxASSERT( it != m_projects_list.end() );
883 m_projects_list.erase( it );
884 }
885
886 wxLogTrace( traceSettings, wxT( "Load project %s" ), fullPath );
887
888 std::unique_ptr<PROJECT> project = std::make_unique<PROJECT>();
889 project->setProjectFullName( fullPath );
890
891 bool success = loadProjectFile( *project );
892
893 if( success )
894 {
895 project->SetReadOnly( readOnly || project->GetProjectFile().IsReadOnly() );
896
897 if( lockFile )
898 m_project_lock.reset( new LOCKFILE( std::move( lockFile ) ) );
899 }
900
901 m_projects_list.push_back( std::move( project ) );
902 m_projects[fullPath] = m_projects_list.back().get();
903
904 wxString fn( path.GetName() );
905
906 PROJECT_LOCAL_SETTINGS* settings = new PROJECT_LOCAL_SETTINGS( m_projects[fullPath], fn );
907
908 if( aSetActive )
909 settings = RegisterSettings( settings );
910 else
911 settings->LoadFromFile( path.GetPath() );
912
913 m_projects[fullPath]->setLocalSettings( settings );
914
915 if( aSetActive && m_kiway )
917
918 return success;
919}
920
921
922bool SETTINGS_MANAGER::UnloadProject( PROJECT* aProject, bool aSave )
923{
924 if( !aProject || !m_projects.count( aProject->GetProjectFullName() ) )
925 return false;
926
927 if( !unloadProjectFile( aProject, aSave ) )
928 return false;
929
930 wxString projectPath = aProject->GetProjectFullName();
931 wxLogTrace( traceSettings, wxT( "Unload project %s" ), projectPath );
932
933 PROJECT* toRemove = m_projects.at( projectPath );
934 auto it = std::find_if( m_projects_list.begin(), m_projects_list.end(),
935 [&]( const std::unique_ptr<PROJECT>& ptr )
936 {
937 return ptr.get() == toRemove;
938 } );
939
940 wxASSERT( it != m_projects_list.end() );
941 m_projects_list.erase( it );
942
943 m_projects.erase( projectPath );
944
945 // Immediately reload a null project; this is required until the rest of the application
946 // is refactored to not assume that Prj() always works
947 if( m_projects.empty() )
948 LoadProject( "" );
949
950 // Remove the reference in the environment to the previous project
951 wxSetEnv( PROJECT_VAR_NAME, wxS( "" ) );
952
953 // Release lock on the file, in case we had one
954 m_project_lock = nullptr;
955
956 if( m_kiway )
958
959 return true;
960}
961
962
964{
965 // No MDI yet: First project in the list is the active project
966 wxASSERT_MSG( m_projects_list.size(), wxT( "no project in list" ) );
967 return *m_projects_list.begin()->get();
968}
969
970
972{
973 return !m_projects.empty();
974}
975
976
977PROJECT* SETTINGS_MANAGER::GetProject( const wxString& aFullPath ) const
978{
979 if( m_projects.count( aFullPath ) )
980 return m_projects.at( aFullPath );
981
982 return nullptr;
983}
984
985
986std::vector<wxString> SETTINGS_MANAGER::GetOpenProjects() const
987{
988 std::vector<wxString> ret;
989
990 for( const std::pair<const wxString, PROJECT*>& pair : m_projects )
991 ret.emplace_back( pair.first );
992
993 return ret;
994}
995
996
997bool SETTINGS_MANAGER::SaveProject( const wxString& aFullPath, PROJECT* aProject )
998{
999 if( !aProject )
1000 aProject = &Prj();
1001
1002 wxString path = aFullPath;
1003
1004 if( path.empty() )
1005 path = aProject->GetProjectFullName();
1006
1007 // TODO: refactor for MDI
1008 if( aProject->IsReadOnly() )
1009 return false;
1010
1011 if( !m_project_files.count( path ) )
1012 return false;
1013
1015 wxString projectPath = aProject->GetProjectPath();
1016
1017 project->SaveToFile( projectPath );
1018 aProject->GetLocalSettings().SaveToFile( projectPath );
1019
1020 return true;
1021}
1022
1023
1024void SETTINGS_MANAGER::SaveProjectAs( const wxString& aFullPath, PROJECT* aProject )
1025{
1026 if( !aProject )
1027 aProject = &Prj();
1028
1029 wxString oldName = aProject->GetProjectFullName();
1030
1031 if( aFullPath.IsSameAs( oldName ) )
1032 {
1033 SaveProject( aFullPath, aProject );
1034 return;
1035 }
1036
1037 // Changing this will cause UnloadProject to not save over the "old" project when loading below
1038 aProject->setProjectFullName( aFullPath );
1039
1040 wxFileName fn( aFullPath );
1041
1042 PROJECT_FILE* project = m_project_files.at( oldName );
1043
1044 // Ensure read-only flags are copied; this allows doing a "Save As" on a standalong board/sch
1045 // without creating project files if the checkbox is turned off
1046 project->SetReadOnly( aProject->IsReadOnly() );
1047 aProject->GetLocalSettings().SetReadOnly( aProject->IsReadOnly() );
1048
1049 project->SetFilename( fn.GetName() );
1050 project->SaveToFile( fn.GetPath() );
1051
1052 aProject->GetLocalSettings().SetFilename( fn.GetName() );
1053 aProject->GetLocalSettings().SaveToFile( fn.GetPath() );
1054
1055 m_project_files[fn.GetFullPath()] = project;
1056 m_project_files.erase( oldName );
1057
1058 m_projects[fn.GetFullPath()] = m_projects[oldName];
1059 m_projects.erase( oldName );
1060}
1061
1062
1063void SETTINGS_MANAGER::SaveProjectCopy( const wxString& aFullPath, PROJECT* aProject )
1064{
1065 if( !aProject )
1066 aProject = &Prj();
1067
1069 wxString oldName = project->GetFilename();
1070 wxFileName fn( aFullPath );
1071
1072 bool readOnly = project->IsReadOnly();
1073 project->SetReadOnly( false );
1074
1075 project->SetFilename( fn.GetName() );
1076 project->SaveToFile( fn.GetPath() );
1077 project->SetFilename( oldName );
1078
1079 PROJECT_LOCAL_SETTINGS& localSettings = aProject->GetLocalSettings();
1080
1081 localSettings.SetFilename( fn.GetName() );
1082 localSettings.SaveToFile( fn.GetPath() );
1083 localSettings.SetFilename( oldName );
1084
1085 project->SetReadOnly( readOnly );
1086}
1087
1088
1090{
1091 wxFileName fullFn( aProject.GetProjectFullName() );
1092 wxString fn( fullFn.GetName() );
1093
1094 PROJECT_FILE* file = RegisterSettings( new PROJECT_FILE( fn ), false );
1095
1096 m_project_files[aProject.GetProjectFullName()] = file;
1097
1098 aProject.setProjectFile( file );
1099 file->SetProject( &aProject );
1100
1101 wxString path( fullFn.GetPath() );
1102
1103 return file->LoadFromFile( path );
1104}
1105
1106
1108{
1109 if( !aProject )
1110 return false;
1111
1112 wxString name = aProject->GetProjectFullName();
1113
1114 if( !m_project_files.count( name ) )
1115 return false;
1116
1118
1119 auto it = std::find_if( m_settings.begin(), m_settings.end(),
1120 [&file]( const std::unique_ptr<JSON_SETTINGS>& aPtr )
1121 {
1122 return aPtr.get() == file;
1123 } );
1124
1125 if( it != m_settings.end() )
1126 {
1127 wxString projectPath = GetPathForSettingsFile( it->get() );
1128
1129 FlushAndRelease( &aProject->GetLocalSettings(), aSave );
1130
1131 if( aSave )
1132 ( *it )->SaveToFile( projectPath );
1133
1134 m_settings.erase( it );
1135 }
1136
1137 m_project_files.erase( name );
1138
1139 return true;
1140}
1141
1142
1144{
1146}
1147
1148
1149wxString SETTINGS_MANAGER::backupDateTimeFormat = wxT( "%Y-%m-%d_%H%M%S" );
1150
1151
1153{
1154 wxDateTime timestamp = wxDateTime::Now();
1155
1156 wxString fileName = wxString::Format( wxT( "%s-%s" ), Prj().GetProjectName(),
1157 timestamp.Format( backupDateTimeFormat ) );
1158
1159 wxFileName target;
1160 target.SetPath( GetProjectBackupsPath() );
1161 target.SetName( fileName );
1162 target.SetExt( ArchiveFileExtension );
1163
1164 if( !target.DirExists() && !wxMkdir( target.GetPath() ) )
1165 {
1166 wxLogTrace( traceSettings, wxT( "Could not create project backup path %s" ), target.GetPath() );
1167 return false;
1168 }
1169
1170 if( !target.IsDirWritable() )
1171 {
1172 wxLogTrace( traceSettings, wxT( "Backup directory %s is not writable" ), target.GetPath() );
1173 return false;
1174 }
1175
1176 wxLogTrace( traceSettings, wxT( "Backing up project to %s" ), target.GetPath() );
1177
1178 PROJECT_ARCHIVER archiver;
1179
1180 return archiver.Archive( Prj().GetProjectPath(), target.GetFullPath(), aReporter );
1181}
1182
1183
1184class VECTOR_INSERT_TRAVERSER : public wxDirTraverser
1185{
1186public:
1187 VECTOR_INSERT_TRAVERSER( std::vector<wxString>& aVec,
1188 std::function<bool( const wxString& )> aCond ) :
1189 m_files( aVec ),
1190 m_condition( aCond )
1191 {
1192 }
1193
1194 wxDirTraverseResult OnFile( const wxString& aFile ) override
1195 {
1196 if( m_condition( aFile ) )
1197 m_files.emplace_back( aFile );
1198
1199 return wxDIR_CONTINUE;
1200 }
1201
1202 wxDirTraverseResult OnDir( const wxString& aDirName ) override
1203 {
1204 return wxDIR_CONTINUE;
1205 }
1206
1207private:
1208 std::vector<wxString>& m_files;
1209
1210 std::function<bool( const wxString& )> m_condition;
1211};
1212
1213
1215{
1217
1218 if( !settings.enabled )
1219 return true;
1220
1221 wxString prefix = Prj().GetProjectName() + '-';
1222
1223 auto modTime =
1224 [&prefix]( const wxString& aFile )
1225 {
1226 wxDateTime dt;
1227 wxString fn( wxFileName( aFile ).GetName() );
1228 fn.Replace( prefix, wxS( "" ) );
1229 dt.ParseFormat( fn, backupDateTimeFormat );
1230 return dt;
1231 };
1232
1233 wxFileName projectPath( Prj().GetProjectPath() );
1234
1235 // Skip backup if project path isn't valid or writable
1236 if( !projectPath.IsOk() || !projectPath.Exists() || !projectPath.IsDirWritable() )
1237 return true;
1238
1239 wxString backupPath = GetProjectBackupsPath();
1240
1241 if( !wxDirExists( backupPath ) )
1242 {
1243 wxLogTrace( traceSettings, wxT( "Backup path %s doesn't exist, creating it" ), backupPath );
1244
1245 if( !wxMkdir( backupPath ) )
1246 {
1247 wxLogTrace( traceSettings, wxT( "Could not create backups path! Skipping backup" ) );
1248 return false;
1249 }
1250 }
1251
1252 wxDir dir( backupPath );
1253
1254 if( !dir.IsOpened() )
1255 {
1256 wxLogTrace( traceSettings, wxT( "Could not open project backups path %s" ), dir.GetName() );
1257 return false;
1258 }
1259
1260 std::vector<wxString> files;
1261
1262 VECTOR_INSERT_TRAVERSER traverser( files,
1263 [&modTime]( const wxString& aFile )
1264 {
1265 return modTime( aFile ).IsValid();
1266 } );
1267
1268 dir.Traverse( traverser, wxT( "*.zip" ) );
1269
1270 // Sort newest-first
1271 std::sort( files.begin(), files.end(),
1272 [&]( const wxString& aFirst, const wxString& aSecond ) -> bool
1273 {
1274 wxDateTime first = modTime( aFirst );
1275 wxDateTime second = modTime( aSecond );
1276
1277 return first.GetTicks() > second.GetTicks();
1278 } );
1279
1280 // Do we even need to back up?
1281 if( !files.empty() )
1282 {
1283 wxDateTime lastTime = modTime( files[0] );
1284
1285 if( lastTime.IsValid() )
1286 {
1287 wxTimeSpan delta = wxDateTime::Now() - modTime( files[0] );
1288
1289 if( delta.IsShorterThan( wxTimeSpan::Seconds( settings.min_interval ) ) )
1290 return true;
1291 }
1292 }
1293
1294 // Now that we know a backup is needed, apply the retention policy
1295
1296 // Step 1: if we're over the total file limit, remove the oldest
1297 if( !files.empty() && settings.limit_total_files > 0 )
1298 {
1299 while( files.size() > static_cast<size_t>( settings.limit_total_files ) )
1300 {
1301 wxRemoveFile( files.back() );
1302 files.pop_back();
1303 }
1304 }
1305
1306 // Step 2: Stay under the total size limit
1307 if( settings.limit_total_size > 0 )
1308 {
1309 wxULongLong totalSize = 0;
1310
1311 for( const wxString& file : files )
1312 totalSize += wxFileName::GetSize( file );
1313
1314 while( !files.empty() && totalSize > static_cast<wxULongLong>( settings.limit_total_size ) )
1315 {
1316 totalSize -= wxFileName::GetSize( files.back() );
1317 wxRemoveFile( files.back() );
1318 files.pop_back();
1319 }
1320 }
1321
1322 // Step 3: Stay under the daily limit
1323 if( settings.limit_daily_files > 0 && files.size() > 1 )
1324 {
1325 wxDateTime day = modTime( files[0] );
1326 int num = 1;
1327
1328 wxASSERT( day.IsValid() );
1329
1330 std::vector<wxString> filesToDelete;
1331
1332 for( size_t i = 1; i < files.size(); i++ )
1333 {
1334 wxDateTime dt = modTime( files[i] );
1335
1336 if( dt.IsSameDate( day ) )
1337 {
1338 num++;
1339
1340 if( num > settings.limit_daily_files )
1341 filesToDelete.emplace_back( files[i] );
1342 }
1343 else
1344 {
1345 day = dt;
1346 num = 1;
1347 }
1348 }
1349
1350 for( const wxString& file : filesToDelete )
1351 wxRemoveFile( file );
1352 }
1353
1354 return BackupProject( aReporter );
1355}
1356
1357
1359{
1361}
const char * name
Definition: DXF_plotter.cpp:57
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
AUTO_BACKUP m_Backup
ENVIRONMENT m_Env
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
Definition: json_settings.h:80
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.
bool IsReadOnly() const
Definition: json_settings.h:84
void SetReadOnly(bool aReadOnly)
Definition: json_settings.h:85
JSON_SETTINGS_INTERNALS * Internals()
void SetFilename(const wxString &aFilename)
Definition: json_settings.h:77
virtual bool SaveToFile(const wxString &aDirectory="", bool aForce=false)
virtual bool Store()
Stores the current parameters into the JSON document represented by this object Note: this doesn't do...
wxString GetFilename() const
Definition: json_settings.h:73
virtual void ProjectChanged()
Calls ProjectChanged() on all KIWAY_PLAYERs.
Definition: kiway.cpp:660
bool Valid() const
Definition: lockfile.h:236
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.
Definition: paths.cpp:497
static wxString GetDefault3rdPartyPath()
Gets the default path for PCM packages.
Definition: paths.cpp:130
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
Definition: paths.cpp:151
static wxString GetUserSettingsPath()
Return the user configuration path used to store KiCad's configuration files.
Definition: paths.cpp:486
bool Archive(const wxString &aSrcDir, const wxString &aDestFile, REPORTER &aReporter, bool aVerbose=true, bool aIncludeExtraFiles=false)
Creates an archive of the project.
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:70
void SetProject(PROJECT *aProject)
Definition: project_file.h:86
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
Container for project specific data.
Definition: project.h:62
virtual void setProjectFile(PROJECT_FILE *aFile)
Set the backing store file for this project.
Definition: project.h:298
virtual bool IsReadOnly() const
Definition: project.h:142
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:137
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:143
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:155
virtual PROJECT_LOCAL_SETTINGS & GetLocalSettings() const
Definition: project.h:172
virtual void setProjectFullName(const wxString &aFullPathAndName)
Set the full directory, basename, and extension of the project.
Definition: project.cpp:105
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
static int compareVersions(const std::string &aFirst, const std::string &aSecond)
Compares two settings versions, like "5.99" and "6.0".
std::unique_ptr< LOCKFILE > m_project_lock
Lock for loaded project (expand to multiple once we support MDI)
wxString GetPathForSettingsFile(JSON_SETTINGS *aSettings)
Returns the path a given settings file should be loaded from / stored to.
static std::string GetSettingsVersion()
Parses the current KiCad build version and extracts the major and minor revision to use as the name o...
void SaveProjectAs(const wxString &aFullPath, PROJECT *aProject=nullptr)
Sets the currently loaded project path and saves it (pointers remain valid) Note that this will not m...
JSON_SETTINGS * registerSettings(JSON_SETTINGS *aSettings, bool aLoadNow=true)
static wxString GetUserSettingsPath()
A proxy for PATHS::GetUserSettingsPath rather than fighting swig.
COLOR_SETTINGS * GetColorSettings(const wxString &aName="user")
Retrieves a color settings object that applications can read colors from.
T * RegisterSettings(T *aSettings, bool aLoadNow=true)
Takes ownership of the pointer passed in.
void SaveProjectCopy(const wxString &aFullPath, PROJECT *aProject=nullptr)
Saves a copy of the current project under the given path.
bool MigrateIfNeeded()
Handles the initialization of the user settings directory and migration from previous KiCad versions ...
wxString m_migration_source
void SaveColorSettings(COLOR_SETTINGS *aSettings, const std::string &aNamespace="")
Safely saves a COLOR_SETTINGS to disk, preserving any changes outside the given namespace.
bool BackupProject(REPORTER &aReporter) const
Creates a backup archive of the current project.
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)
Extracts 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.
SETTINGS_MANAGER(bool aHeadless=false)
static wxString GetColorSettingsPath()
Returns the path where color scheme files are stored; creating it if missing (normally .
COMMON_SETTINGS * GetCommonSettings() const
Retrieves the common settings shared by all applications.
bool SaveProject(const wxString &aFullPath=wxEmptyString, PROJECT *aProject=nullptr)
Saves a loaded project.
wxString GetProjectBackupsPath() const
bool LoadProject(const wxString &aFullPath, bool aSetActive=true)
Loads 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)
Attempts 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 TODO: This should be deprecated along with Prj() once w...
bool GetPreviousVersionPaths(std::vector< wxString > *aName=nullptr)
Retrieves the name of the most recent previous KiCad version that can be found in the user settings d...
static bool IsSettingsPathValid(const wxString &aPath)
Checks if a given path is probably a valid KiCad configuration directory.
std::vector< std::unique_ptr< PROJECT > > m_projects_list
Loaded projects (ownership here)
PROJECT * GetProject(const wxString &aFullPath) const
Retrieves a loaded project by name.
bool UnloadProject(PROJECT *aProject, bool aSave=true)
Saves, unloads and unregisters the given PROJECT.
std::vector< wxString > GetOpenProjects() const
std::vector< std::unique_ptr< JSON_SETTINGS > > m_settings
bool TriggerBackupIfNeeded(REPORTER &aReporter) const
Calls 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 saves, and then unloads and unregisters the given PROJECT_FILE.
COLOR_SETTINGS * GetMigratedColorSettings()
Returns 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)
Registers 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)
Registers a PROJECT_FILE and attempts to load it from disk.
static wxString backupDateTimeFormat
void ReloadColorSettings()
Re-scans 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.
Definition: confirm.cpp:305
This file is part of the common library.
void KiCopyFile(const wxString &aSrcPath, const wxString &aDestPath, wxString &aErrors)
Definition: gestfich.cpp:278
const std::string LegacyProjectFileExtension
const std::string ProjectFileExtension
const std::string ArchiveFileExtension
const wxChar *const traceSettings
Flag to enable debug output of settings operations and management.
std::map< wxString, ENV_VAR_ITEM > ENV_VAR_MAP
File locking utilities.
This file contains miscellaneous commonly used macros and functions.
STL namespace.
see class PGM_BASE
#define PROJECT_VAR_NAME
A variable name whose value holds the current project directory.
Definition: project.h:39
#define PROJECT_BACKUPS_DIR_SUFFIX
Project settings path will be <projectname> + this.
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:119
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.
constexpr int delta
Definition of file extensions used in Kicad.