diff --git a/CHANGELOG.md b/CHANGELOG.md index 511b2d5dbda..7e38f7381b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -311,6 +311,7 @@ Feature #8109: Expose commitCrime to Lua API Feature #8130: Launcher: Add the ability to open a selected data directory in the file browser Feature #8145: Starter spell flag is not exposed + Feature #8286: Launcher: Preserve semantically identical openmw.cfg Feature #8287: Launcher: Special handling for comma in openmw.cfg entries is unintuitive and should be removed Task #5859: User openmw-cs.cfg has comment talking about settings.cfg Task #5896: Do not use deprecated MyGUI properties diff --git a/components/config/gamesettings.cpp b/components/config/gamesettings.cpp index a5e71326b25..f318cec4a44 100644 --- a/components/config/gamesettings.cpp +++ b/components/config/gamesettings.cpp @@ -301,6 +301,25 @@ bool Config::GameSettings::writeFileWithComments(QFile& file) if (fileCopy.empty()) return writeFile(stream); + QMultiMap existingSettings; + QString context = QFileInfo(file).absoluteDir().path(); + if (readFile(stream, existingSettings, context)) + { + // don't use QMultiMap operator== as mUserSettings may have blank context fields + // don't use one std::equal with custom predicate as (until Qt 6.4) there was no key-value iterator + if (std::equal(existingSettings.keyBegin(), existingSettings.keyEnd(), mUserSettings.keyBegin(), + mUserSettings.keyEnd()) + && std::equal(existingSettings.cbegin(), existingSettings.cend(), mUserSettings.cbegin(), + [](const SettingValue& l, const SettingValue& r) { + return l.originalRepresentation == r.originalRepresentation; + })) + { + // The existing file already contains what we need, don't risk scrambling comments and formatting + return true; + } + } + stream.seek(0); + // start // | // | +----------------------------------------------------------+