1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-23 19:20:56 +00:00

Merge branch 'leave-openmw.cfg-alone' into 'master'

Don't unnecessarily overwrite openmw.cfg

Closes #8286

See merge request OpenMW/openmw!4508
This commit is contained in:
psi29a 2025-01-13 08:25:43 +00:00
commit 6ea3d11a8b
2 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -301,6 +301,25 @@ bool Config::GameSettings::writeFileWithComments(QFile& file)
if (fileCopy.empty())
return writeFile(stream);
QMultiMap<QString, SettingValue> 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
// |
// | +----------------------------------------------------------+