From 61828ac695d778f17bd1b0250fe124ac78c63ab3 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Mon, 4 Mar 2019 20:12:21 -0330 Subject: [PATCH] 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. --- src/emucore/OSystem.cxx | 5 +---- src/emucore/PropsSet.cxx | 5 +++++ src/emucore/PropsSet.hxx | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 8db2d6ac8..07aa54b50 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -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); - } } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 1479c9b5b..0ab255043 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -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; diff --git a/src/emucore/PropsSet.hxx b/src/emucore/PropsSet.hxx index 224d2bfc8..4d5f2ee37 100644 --- a/src/emucore/PropsSet.hxx +++ b/src/emucore/PropsSet.hxx @@ -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;