mirror of https://github.com/stella-emu/stella.git
The properties database is now smarter, and automatically discards entries
if they are already present in the built-in data. This eliminates a 'bug' where entries were being saved to the external properties file that were also present in the app itself. The app still worked, but it bloated the external file for no reason. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3248 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
a0536fb450
commit
e0676f2432
|
@ -177,6 +177,9 @@ void OSystem::saveConfig()
|
|||
|
||||
if(mySettings)
|
||||
mySettings->saveConfig();
|
||||
|
||||
if(myPropSet)
|
||||
myPropSet->save(myPropertiesFile);
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -39,22 +39,10 @@ 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)
|
||||
while(in >> prop)
|
||||
insert(prop);
|
||||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
bool PropertiesSet::save(const string& filename) const
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue