Don't create an empty 'stella.pro' file when possible.

- Not a big deal, but several people are complaining when 'ghost' files are created
- If file doesn't already exist and there is nothing to add, simply don't create one
- Alternatively, we should delete the file if it's zero-sized, but that requires changes to FSNode.
This commit is contained in:
Stephen Anthony 2019-03-04 20:12:21 -03:30
parent 501e75ccb7
commit 61828ac695
3 changed files with 10 additions and 6 deletions

View File

@ -203,11 +203,8 @@ void OSystem::saveConfig()
logMessage("Saving config options ...", 2);
mySettings->save(configFile());
if(myPropSet)
{
if(myPropSet && myPropSet->save(myPropertiesFile))
logMessage("Saving properties set ...", 2);
myPropSet->save(myPropertiesFile);
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -42,6 +42,11 @@ void PropertiesSet::load(const string& filename)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
bool PropertiesSet::save(const string& filename) const
{
// Only save properties when it won't create an empty file
FilesystemNode props(filename);
if(!props.exists() && myExternalProps.size() == 0)
return false;
ofstream out(filename);
if(!out)
return false;

View File

@ -58,8 +58,10 @@ class PropertiesSet
@param filename Full pathname of output file to use
@return True on success, false on failure
Failure occurs if file couldn't be opened for writing
@return True on success, false on failure or save not needed
Failure occurs if file couldn't be opened for writing,
or if the file doesn't exist and a zero-byte file
would be created
*/
bool save(const string& filename) const;