Update the OpenMW Launcher so that it only writes changed values to

the user settings.cfg file.  Add a helpful header to the top of new
settings.cfg files.  Remove old code involve whitespace management
that didn't work correctly anayway, and doesn't matter since we're not
adding comments to the file.  Remove "automatically generated"
comments.
openmw-38
cfcohen 9 years ago
parent 67c4b17581
commit ad5eaaa705

@ -80,6 +80,8 @@ bool Launcher::GraphicsPage::loadSettings()
if (!setupSDL())
return false;
mInitialSettings = mEngineSettings;
if (mEngineSettings.getBool("vsync", "Video"))
vSyncCheckBox->setCheckState(Qt::Checked);
@ -117,29 +119,53 @@ bool Launcher::GraphicsPage::loadSettings()
void Launcher::GraphicsPage::saveSettings()
{
mEngineSettings.setBool("vsync", "Video", vSyncCheckBox->checkState());
mEngineSettings.setBool("fullscreen", "Video", fullScreenCheckBox->checkState());
mEngineSettings.setBool("window border", "Video", windowBorderCheckBox->checkState());
bool iVSync = mInitialSettings.getBool("vsync", "Video");
bool cVSync = vSyncCheckBox->checkState();
if (iVSync != cVSync)
mEngineSettings.setBool("vsync", "Video", cVSync);
bool iFullScreen = mInitialSettings.getBool("fullscreen", "Video");
bool cFullScreen = fullScreenCheckBox->checkState();
if (iFullScreen != cFullScreen)
mEngineSettings.setBool("fullscreen", "Video", cFullScreen);
bool iWindowBorder = mInitialSettings.getBool("window border", "Video");
bool cWindowBorder = windowBorderCheckBox->checkState();
if (iWindowBorder != cWindowBorder)
mEngineSettings.setBool("window border", "Video", cWindowBorder);
int iAAValue = mInitialSettings.getInt("antialiasing", "Video");
// The atoi() call is safe because the pull down constrains the string values.
int aaValue = atoi(antiAliasingComboBox->currentText().toLatin1().data());
mEngineSettings.setInt("antialiasing", "Video", aaValue);
int cAAValue = atoi(antiAliasingComboBox->currentText().toLatin1().data());
if (iAAValue != cAAValue)
mEngineSettings.setInt("antialiasing", "Video", cAAValue);
int cWidth = 0;
int cHeight = 0;
if (standardRadioButton->isChecked()) {
QRegExp resolutionRe(QString("(\\d+) x (\\d+).*"));
if (resolutionRe.exactMatch(resolutionComboBox->currentText().simplified())) {
// The atoi() call is safe because the pull down constrains the string values.
int width = atoi(resolutionRe.cap(1).toLatin1().data());
int height = atoi(resolutionRe.cap(2).toLatin1().data());
mEngineSettings.setInt("resolution x", "Video", width);
mEngineSettings.setInt("resolution y", "Video", height);
cWidth = atoi(resolutionRe.cap(1).toLatin1().data());
cHeight = atoi(resolutionRe.cap(2).toLatin1().data());
}
} else {
mEngineSettings.setInt("resolution x", "Video", customWidthSpinBox->value());
mEngineSettings.setInt("resolution y", "Video", customHeightSpinBox->value());
cWidth = customWidthSpinBox->value();
cHeight = customHeightSpinBox->value();
}
mEngineSettings.setInt("screen", "Video", screenComboBox->currentIndex());
int iWidth = mInitialSettings.getInt("resolution x", "Video");
if (iWidth != cWidth)
mEngineSettings.setInt("resolution x", "Video", cWidth);
int iHeight = mInitialSettings.getInt("resolution y", "Video");
if (iHeight != cHeight)
mEngineSettings.setInt("resolution y", "Video", cHeight);
int iScreen = mInitialSettings.getInt("screen", "Video");
int cScreen = screenComboBox->currentIndex();
if (iScreen != cScreen)
mEngineSettings.setInt("screen", "Video", cScreen);
}
QStringList Launcher::GraphicsPage::getAvailableResolutions(int screen)

@ -33,6 +33,7 @@ namespace Launcher
private:
Files::ConfigurationManager &mCfgMgr;
Settings::Manager &mEngineSettings;
Settings::Manager mInitialSettings;
QStringList getAvailableResolutions(int screen);
QRect getMaximumResolution();

@ -131,9 +131,7 @@ public:
// Have we substantively changed the settings file?
bool changed = false;
// Was there anything in the existing file? This is intended to permit the deletion of
// the settings.cfg file and it's automatic recreation -- a feature not currently
// supported elsewhere in the code.
// Were there any lines at all in the file?
bool existing = false;
// The category/section we're currently in.
@ -145,7 +143,6 @@ public:
boost::filesystem::ifstream istream;
boost::filesystem::path ipath(file);
istream.open(ipath);
//std::cout << "Reading previous settings file: " << ipath << std::endl;
// Create a new string stream to write the current settings to. It's likely that the
// input file and the output file are the same, so this stream serves as a temporary file
@ -190,19 +187,13 @@ public:
// Ensure that all options in the current category have been written.
for (CategorySettingStatusMap::iterator mit = written.begin(); mit != written.end(); ++mit) {
bool missed = false;
if (mit->second == false && mit->first.first == currentCategory) {
std::cout << "Added new setting: [" << currentCategory << "] "
<< mit->first.second << " = " << settings[mit->first] << std::endl;
// With some further code changes, this comment could be more descriptive.
ostream << "# Automatically added setting." << std::endl;
ostream << mit->first.second << " = " << settings[mit->first] << std::endl;
mit->second = true;
missed = true;
changed = true;
}
// Ensure that there's a newline before the next section if we added settings.
if (missed) ostream << std::endl;
}
// Update the current category.
@ -223,7 +214,7 @@ public:
if (!skipWhiteSpace(i, line))
continue;
// If we'cve found settings befor ethe first category, something's wrong. This
// If we've found settings before the first category, something's wrong. This
// should never happen unless the player edited the file while playing, since
// the loadSettingsFile() logic rejects it.
if (currentCategory.empty()) {
@ -286,27 +277,24 @@ public:
// Ensure that all options in the current category have been written. We must complete
// the current category at the end of the file before moving on to any new categories.
for (CategorySettingStatusMap::iterator mit = written.begin(); mit != written.end(); ++mit) {
bool missed = false;
if (mit->second == false && mit->first.first == currentCategory) {
std::cout << "Added new setting: [" << mit->first.first << "] "
<< mit->first.second << " = " << settings[mit->first] << std::endl;
// With some further code changes, this comment could be more descriptive.
ostream << std::endl << "# Automatically added setting." << std::endl;
ostream << mit->first.second << " = " << settings[mit->first] << std::endl;
mit->second = true;
missed = true;
changed = true;
}
// Ensure that there's a newline before the next section if we added settings.
if (missed) ostream << std::endl;
}
// This logic triggers when the input file was effectively empty. It could be extended
// to doing something more intelligent instead, like make a copy of the default settings
// file (complete with comments) before continuing. Other code prevents OpenMW from
// executing to this point with a missing config file.
// If there was absolutely nothing in the file (or more likely the file didn't
// exist), start the newly created file with a helpful comment.
if (!existing) {
ostream << "# This file was automatically generated." << std::endl << std::endl;
ostream << "# This is the OpenMW user 'settings.cfg' file. This file only contains" << std::endl;
ostream << "# explicitly changed settings. If you would like to revert a setting" << std::endl;
ostream << "# to its default, simply remove it from this file. For available" << std::endl;
ostream << "# settings, see the file 'settings-default.cfg' or the documentation at:" << std::endl;
ostream << "#" << std::endl;
ostream << "# https://wiki.openmw.org/index.php?title=Settings" << std::endl;
}
// We still have one more thing to do before we're completely done writing the file.
@ -321,14 +309,11 @@ public:
currentCategory = mit->first.first;
std::cout << "Created new setting section: " << mit->first.first << std::endl;
ostream << std::endl;
// Add new category comments only if we're amending an existing file.
if (existing) ostream << "# Automatically added category." << std::endl;
ostream << "[" << currentCategory << "]" << std::endl;
}
std::cout << "Added new setting: [" << mit->first.first << "] "
<< mit->first.second << " = " << settings[mit->first] << std::endl;
// Then write the setting. No need to mark it as written because we're done.
ostream << std::endl;
ostream << mit->first.second << " = " << settings[mit->first] << std::endl;
changed = true;
}

Loading…
Cancel
Save