diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index d0e835816..3259f5fae 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -177,6 +177,9 @@ void OSystem::saveConfig() if(mySettings) mySettings->saveConfig(); + + if(myPropSet) + myPropSet->save(myPropertiesFile); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index 710f62003..20631f5e2 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -195,6 +195,22 @@ void Properties::writeQuotedString(ostream& out, const string& s) out.put('"'); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Properties::operator == (const Properties& properties) const +{ + for(int i = 0; i < LastPropType; ++i) + if(myProperties[i] != properties.myProperties[i]) + return false; + + return true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Properties::operator != (const Properties& properties) const +{ + return !(*this == properties); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Properties& Properties::operator = (const Properties& properties) { diff --git a/src/emucore/Props.hxx b/src/emucore/Props.hxx index 9a6c9a874..c07981df4 100644 --- a/src/emucore/Props.hxx +++ b/src/emucore/Props.hxx @@ -122,7 +122,15 @@ class Properties */ void setDefaults(); - public: + /** + Overloaded equality operator(s) + + @param properties The properties object to compare to + @return True if the properties are equal, else false + */ + bool operator == (const Properties& properties) const; + bool operator != (const Properties& properties) const; + /** Overloaded assignment operator diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 16cd88a34..826806a4e 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -39,21 +39,9 @@ void PropertiesSet::load(const string& filename) { ifstream in(filename); - // Loop reading properties - for(;;) - { - // Make sure the stream is still good or we're done - if(!in) - break; - - // Get the property list associated with this profile - Properties prop; - in >> prop; - - // If the stream is still good then insert the properties - if(in) - insert(prop); - } + Properties prop; + while(in >> prop) + insert(prop); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -165,10 +153,20 @@ void PropertiesSet::insert(const Properties& properties, bool save) if(md5 == "") return; + // Make sure the exact entry isn't already in any list + Properties defaultProps; + if(getMD5(md5, defaultProps, false) && defaultProps == properties) + return; + else if(getMD5(md5, defaultProps, true) && defaultProps == properties) + { + myExternalProps.erase(md5); + return; + } + // The status of 'save' determines which list to save to PropsList& list = save ? myExternalProps : myTempProps; - auto ret = list.insert(make_pair(md5, properties)); + auto ret = list.emplace(md5, properties); if(ret.second == false) { // Remove old item and insert again