diff --git a/common/project/net_settings.cpp b/common/project/net_settings.cpp index ba265c619c..343745140f 100644 --- a/common/project/net_settings.cpp +++ b/common/project/net_settings.cpp @@ -54,7 +54,7 @@ static int getInSchUnits( const nlohmann::json& aObj, const std::string& aKey, i NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : - NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath ) + NESTED_SETTINGS( "net_settings", netSettingsSchemaVersion, aParent, aPath, false ) { m_DefaultNetClass = std::make_shared( NETCLASS::Default ); m_DefaultNetClass->SetDescription( _( "This is the default net class." ) ); @@ -298,6 +298,7 @@ NET_SETTINGS::NET_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : {} ) ); registerMigration( 0, 1, std::bind( &NET_SETTINGS::migrateSchema0to1, this ) ); + registerMigration( 1, 2, std::bind( &NET_SETTINGS::migrateSchema1to2, this ) ); registerMigration( 2, 3, std::bind( &NET_SETTINGS::migrateSchema2to3, this ) ); } @@ -360,6 +361,12 @@ bool NET_SETTINGS::migrateSchema0to1() } +bool NET_SETTINGS::migrateSchema1to2() +{ + return true; +} + + bool NET_SETTINGS::migrateSchema2to3() { if( m_internals->contains( "classes" ) && m_internals->At( "classes" ).is_array() ) diff --git a/common/settings/json_settings.cpp b/common/settings/json_settings.cpp index 30fd2c7c34..be90e5dc0b 100644 --- a/common/settings/json_settings.cpp +++ b/common/settings/json_settings.cpp @@ -674,29 +674,29 @@ bool JSON_SETTINGS::Migrate() while( filever < m_schemaVersion ) { + wxASSERT( m_migrators.count( filever ) > 0 ); + if( !m_migrators.count( filever ) ) { wxLogTrace( traceSettings, wxT( "Migrator missing for %s version %d!" ), typeid( *this ).name(), filever ); - filever++; + return false; + } + + std::pair> pair = m_migrators.at( filever ); + + if( pair.second() ) + { + wxLogTrace( traceSettings, wxT( "Migrated %s from %d to %d" ), typeid( *this ).name(), + filever, pair.first ); + filever = pair.first; + m_internals->At( "meta.version" ) = filever; } else { - std::pair> pair = m_migrators.at( filever ); - - if( pair.second() ) - { - wxLogTrace( traceSettings, wxT( "Migrated %s from %d to %d" ), - typeid( *this ).name(), filever, pair.first ); - filever = pair.first; - m_internals->At( "meta.version" ) = filever; - } - else - { - wxLogTrace( traceSettings, wxT( "Migration failed for %s from %d to %d" ), - typeid( *this ).name(), filever, pair.first ); - return false; - } + wxLogTrace( traceSettings, wxT( "Migration failed for %s from %d to %d" ), + typeid( *this ).name(), filever, pair.first ); + return false; } } diff --git a/common/settings/nested_settings.cpp b/common/settings/nested_settings.cpp index 7af1576deb..5a07bca96d 100644 --- a/common/settings/nested_settings.cpp +++ b/common/settings/nested_settings.cpp @@ -26,11 +26,11 @@ NESTED_SETTINGS::NESTED_SETTINGS( const std::string& aName, int aVersion, JSON_SETTINGS* aParent, - const std::string& aPath ) : + const std::string& aPath, bool aLoadFromFile ) : JSON_SETTINGS( aName, SETTINGS_LOC::NESTED, aVersion ), m_parent( aParent ), m_path( aPath ) { - SetParent( aParent ); + SetParent( aParent, aLoadFromFile ); } diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index e5ab4d85d1..5c6f0b5a9a 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -37,7 +37,7 @@ const int schSettingsSchemaVersion = 1; SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::string& aPath ) : - NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath ), + NESTED_SETTINGS( "schematic", schSettingsSchemaVersion, aParent, aPath, false ), m_DefaultLineWidth( DEFAULT_LINE_WIDTH_MILS * schIUScale.IU_PER_MILS ), m_DefaultTextSize( DEFAULT_TEXT_SIZE * schIUScale.IU_PER_MILS ), m_LabelSizeRatio( DEFAULT_LABEL_SIZE_RATIO ), diff --git a/include/project/net_settings.h b/include/project/net_settings.h index d60710ad78..e0f6542a02 100644 --- a/include/project/net_settings.h +++ b/include/project/net_settings.h @@ -96,6 +96,7 @@ public: private: bool migrateSchema0to1(); + bool migrateSchema1to2(); bool migrateSchema2to3(); // TODO: Add diff pairs, bus information, etc. diff --git a/include/settings/nested_settings.h b/include/settings/nested_settings.h index 6ad048cd17..29e226f269 100644 --- a/include/settings/nested_settings.h +++ b/include/settings/nested_settings.h @@ -32,7 +32,7 @@ class KICOMMON_API NESTED_SETTINGS : public JSON_SETTINGS { public: NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent, - const std::string& aPath ); + const std::string& aPath, bool aLoadFromFile = true ); virtual ~NESTED_SETTINGS();