Skip to content

Commit

Permalink
Merge branch 'leave-openmw.cfg-alone' into 'master'
Browse files Browse the repository at this point in the history
Don't unnecessarily overwrite openmw.cfg

Closes #8286

See merge request OpenMW/openmw!4508
  • Loading branch information
psi29a committed Jan 13, 2025
2 parents ec43849 + 085c3b0 commit 6ea3d11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions components/config/gamesettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
// |
// | +----------------------------------------------------------+
Expand Down

0 comments on commit 6ea3d11

Please sign in to comment.