mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Apply clang-format to code base
This commit is contained in:
parent
f37d0be806
commit
ddb0522bbf
2199 changed files with 118692 additions and 114392 deletions
|
@ -3,16 +3,16 @@
|
|||
#include <sstream>
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
#include <components/misc/strings/algorithm.hpp>
|
||||
#include <components/files/conversion.hpp>
|
||||
#include <components/misc/strings/algorithm.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include <Base64.h>
|
||||
|
||||
void Settings::SettingsFileParser::loadSettingsFile(const std::filesystem::path &file, CategorySettingValueMap& settings,
|
||||
bool base64Encoded, bool overrideExisting)
|
||||
void Settings::SettingsFileParser::loadSettingsFile(
|
||||
const std::filesystem::path& file, CategorySettingValueMap& settings, bool base64Encoded, bool overrideExisting)
|
||||
{
|
||||
mFile = file;
|
||||
std::ifstream fstream;
|
||||
|
@ -39,7 +39,7 @@ void Settings::SettingsFileParser::loadSettingsFile(const std::filesystem::path
|
|||
{
|
||||
++mLine;
|
||||
std::string line;
|
||||
std::getline( stream.get(), line );
|
||||
std::getline(stream.get(), line);
|
||||
|
||||
size_t i = 0;
|
||||
if (!skipWhiteSpace(i, line))
|
||||
|
@ -54,9 +54,9 @@ void Settings::SettingsFileParser::loadSettingsFile(const std::filesystem::path
|
|||
if (end == std::string::npos)
|
||||
fail("unterminated category");
|
||||
|
||||
currentCategory = line.substr(i+1, end - (i+1));
|
||||
currentCategory = line.substr(i + 1, end - (i + 1));
|
||||
Misc::StringUtils::trim(currentCategory);
|
||||
i = end+1;
|
||||
i = end + 1;
|
||||
}
|
||||
|
||||
if (!skipWhiteSpace(i, line))
|
||||
|
@ -69,10 +69,10 @@ void Settings::SettingsFileParser::loadSettingsFile(const std::filesystem::path
|
|||
if (settingEnd == std::string::npos)
|
||||
fail("unterminated setting name");
|
||||
|
||||
std::string setting = line.substr(i, (settingEnd-i));
|
||||
std::string setting = line.substr(i, (settingEnd - i));
|
||||
Misc::StringUtils::trim(setting);
|
||||
|
||||
size_t valueBegin = settingEnd+1;
|
||||
size_t valueBegin = settingEnd + 1;
|
||||
std::string value = line.substr(valueBegin);
|
||||
Misc::StringUtils::trim(value);
|
||||
|
||||
|
@ -83,13 +83,15 @@ void Settings::SettingsFileParser::loadSettingsFile(const std::filesystem::path
|
|||
}
|
||||
}
|
||||
|
||||
void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path &file, const CategorySettingValueMap& settings)
|
||||
void Settings::SettingsFileParser::saveSettingsFile(
|
||||
const std::filesystem::path& file, const CategorySettingValueMap& settings)
|
||||
{
|
||||
using CategorySettingStatusMap = std::map<CategorySetting, bool>;
|
||||
|
||||
// No options have been written to the file yet.
|
||||
CategorySettingStatusMap written;
|
||||
for (auto it = settings.begin(); it != settings.end(); ++it) {
|
||||
for (auto it = settings.begin(); it != settings.end(); ++it)
|
||||
{
|
||||
written[it->first] = false;
|
||||
}
|
||||
|
||||
|
@ -117,7 +119,8 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
std::stringstream ostream;
|
||||
|
||||
// For every line in the input file...
|
||||
while (!istream.eof() && !istream.fail()) {
|
||||
while (!istream.eof() && !istream.fail())
|
||||
{
|
||||
std::string line;
|
||||
std::getline(istream, line);
|
||||
|
||||
|
@ -134,7 +137,8 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
}
|
||||
|
||||
// Don't add additional newlines at the end of the file otherwise.
|
||||
if (istream.eof()) continue;
|
||||
if (istream.eof())
|
||||
continue;
|
||||
|
||||
// Queue entirely blank lines to add them if desired.
|
||||
if (!skipWhiteSpace(i, line))
|
||||
|
@ -147,16 +151,19 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
existing = true;
|
||||
|
||||
// Copy comments.
|
||||
if (line[i] == '#') {
|
||||
if (line[i] == '#')
|
||||
{
|
||||
ostream << line << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Category heading.
|
||||
if (line[i] == '[') {
|
||||
if (line[i] == '[')
|
||||
{
|
||||
size_t end = line.find(']', i);
|
||||
// This should never happen unless the player edited the file while playing.
|
||||
if (end == std::string::npos) {
|
||||
if (end == std::string::npos)
|
||||
{
|
||||
ostream << "# unterminated category: " << line << std::endl;
|
||||
changed = true;
|
||||
continue;
|
||||
|
@ -169,8 +176,8 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
{
|
||||
if (mit->second == false && mit->first.first == currentCategory)
|
||||
{
|
||||
Log(Debug::Verbose) << "Added new setting: [" << currentCategory << "] "
|
||||
<< mit->first.second << " = " << settings.at(mit->first);
|
||||
Log(Debug::Verbose) << "Added new setting: [" << currentCategory << "] " << mit->first.second
|
||||
<< " = " << settings.at(mit->first);
|
||||
ostream << mit->first.second << " = " << settings.at(mit->first) << std::endl;
|
||||
mit->second = true;
|
||||
changed = true;
|
||||
|
@ -181,7 +188,7 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
}
|
||||
|
||||
// Update the current category.
|
||||
currentCategory = line.substr(i+1, end - (i+1));
|
||||
currentCategory = line.substr(i + 1, end - (i + 1));
|
||||
Misc::StringUtils::trim(currentCategory);
|
||||
|
||||
// Write the (new) current category to the file.
|
||||
|
@ -191,7 +198,7 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
// A setting can apparently follow the category on an input line. That's rather
|
||||
// inconvenient, since it makes it more likely to have duplicative sections,
|
||||
// which our algorithm doesn't like. Do the best we can.
|
||||
i = end+1;
|
||||
i = end + 1;
|
||||
}
|
||||
|
||||
// Truncate trailing whitespace, since we're changing the file anayway.
|
||||
|
@ -201,7 +208,8 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
// 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()) {
|
||||
if (currentCategory.empty())
|
||||
{
|
||||
ostream << "# empty category name: " << line << std::endl;
|
||||
changed = true;
|
||||
continue;
|
||||
|
@ -210,16 +218,17 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
// Which setting was at this location in the input file?
|
||||
size_t settingEnd = line.find('=', i);
|
||||
// This should never happen unless the player edited the file while playing.
|
||||
if (settingEnd == std::string::npos) {
|
||||
if (settingEnd == std::string::npos)
|
||||
{
|
||||
ostream << "# unterminated setting name: " << line << std::endl;
|
||||
changed = true;
|
||||
continue;
|
||||
}
|
||||
std::string setting = line.substr(i, (settingEnd-i));
|
||||
std::string setting = line.substr(i, (settingEnd - i));
|
||||
Misc::StringUtils::trim(setting);
|
||||
|
||||
// Get the existing value so we can see if we've changed it.
|
||||
size_t valueBegin = settingEnd+1;
|
||||
size_t valueBegin = settingEnd + 1;
|
||||
std::string value = line.substr(valueBegin);
|
||||
Misc::StringUtils::trim(value);
|
||||
|
||||
|
@ -232,7 +241,8 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
// happen if the player edited the file while playing, because loadSettingsFile()
|
||||
// will accept anything and pass it along in the map, but in the future, we might
|
||||
// want to handle invalid settings more gracefully here.
|
||||
if (finder == written.end()) {
|
||||
if (finder == written.end())
|
||||
{
|
||||
ostream << "# invalid setting: " << line << std::endl;
|
||||
changed = true;
|
||||
continue;
|
||||
|
@ -244,9 +254,10 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
// Mark that setting as written.
|
||||
finder->second = true;
|
||||
// Did we really change it?
|
||||
if (value != settings.at(key)) {
|
||||
Log(Debug::Verbose) << "Changed setting: [" << currentCategory << "] "
|
||||
<< setting << " = " << settings.at(key);
|
||||
if (value != settings.at(key))
|
||||
{
|
||||
Log(Debug::Verbose) << "Changed setting: [" << currentCategory << "] " << setting << " = "
|
||||
<< settings.at(key);
|
||||
changed = true;
|
||||
}
|
||||
// No need to write the current line, because we just emitted a replacement.
|
||||
|
@ -260,10 +271,12 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
|
||||
// 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) {
|
||||
if (mit->second == false && mit->first.first == currentCategory) {
|
||||
Log(Debug::Verbose) << "Added new setting: [" << mit->first.first << "] "
|
||||
<< mit->first.second << " = " << settings.at(mit->first);
|
||||
for (CategorySettingStatusMap::iterator mit = written.begin(); mit != written.end(); ++mit)
|
||||
{
|
||||
if (mit->second == false && mit->first.first == currentCategory)
|
||||
{
|
||||
Log(Debug::Verbose) << "Added new setting: [" << mit->first.first << "] " << mit->first.second << " = "
|
||||
<< settings.at(mit->first);
|
||||
ostream << mit->first.second << " = " << settings.at(mit->first) << std::endl;
|
||||
mit->second = true;
|
||||
changed = true;
|
||||
|
@ -272,11 +285,13 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
|
||||
// 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) {
|
||||
if (!existing)
|
||||
{
|
||||
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 'files/settings-default.cfg' in our source repo or the documentation at:" << std::endl;
|
||||
ostream << "# settings, see the file 'files/settings-default.cfg' in our source repo or the documentation at:"
|
||||
<< std::endl;
|
||||
ostream << "#" << std::endl;
|
||||
ostream << "# https://openmw.readthedocs.io/en/master/reference/modding/settings/index.html" << std::endl;
|
||||
}
|
||||
|
@ -285,18 +300,21 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
// It's possible that there are entirely new categories, or that the input file had
|
||||
// disappeared completely, so we need ensure that all settings are written to the file
|
||||
// regardless of those issues.
|
||||
for (CategorySettingStatusMap::iterator mit = written.begin(); mit != written.end(); ++mit) {
|
||||
for (CategorySettingStatusMap::iterator mit = written.begin(); mit != written.end(); ++mit)
|
||||
{
|
||||
// If the setting hasn't been written yet.
|
||||
if (mit->second == false) {
|
||||
if (mit->second == false)
|
||||
{
|
||||
// If the catgory has changed, write a new category header.
|
||||
if (mit->first.first != currentCategory) {
|
||||
if (mit->first.first != currentCategory)
|
||||
{
|
||||
currentCategory = mit->first.first;
|
||||
Log(Debug::Verbose) << "Created new setting section: " << mit->first.first;
|
||||
ostream << std::endl;
|
||||
ostream << "[" << currentCategory << "]" << std::endl;
|
||||
}
|
||||
Log(Debug::Verbose) << "Added new setting: [" << mit->first.first << "] "
|
||||
<< mit->first.second << " = " << settings.at(mit->first);
|
||||
Log(Debug::Verbose) << "Added new setting: [" << mit->first.first << "] " << mit->first.second << " = "
|
||||
<< settings.at(mit->first);
|
||||
// Then write the setting. No need to mark it as written because we're done.
|
||||
ostream << mit->first.second << " = " << settings.at(mit->first) << std::endl;
|
||||
changed = true;
|
||||
|
@ -304,7 +322,8 @@ void Settings::SettingsFileParser::saveSettingsFile(const std::filesystem::path
|
|||
}
|
||||
|
||||
// Now install the newly written file in the requested place.
|
||||
if (changed) {
|
||||
if (changed)
|
||||
{
|
||||
Log(Debug::Info) << "Updating settings file: " << file;
|
||||
std::ofstream ofstream;
|
||||
ofstream.open(file);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue