From d13f6bb870cdda71257f665367be8ef9fca86255 Mon Sep 17 00:00:00 2001 From: MikaĆ«l Capelle Date: Tue, 17 May 2022 11:47:01 +0200 Subject: Apply clang-format. --- src/profile.cpp | 427 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 213 insertions(+), 214 deletions(-) (limited to 'src/profile.cpp') diff --git a/src/profile.cpp b/src/profile.cpp index b4b0ddcb..c5ea5eec 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -19,44 +19,44 @@ along with Mod Organizer. If not, see . #include "profile.h" +#include "filesystemutilities.h" #include "modinfo.h" +#include "modinfoforeign.h" +#include "registry.h" #include "settings.h" -#include "filesystemutilities.h" #include "shared/appconfig.h" -#include -#include -#include +#include "shared/util.h" #include #include -#include "shared/util.h" -#include "registry.h" -#include "modinfoforeign.h" +#include #include +#include +#include #include -#include // for QFile -#include // for operator|, QFlags -#include // for QIODevice, etc -#include -#include -#include // for QStringList -#include // for qUtf8Printable #include #include +#include // for QFile +#include // for operator|, QFlags +#include // for QIODevice, etc +#include +#include +#include // for QStringList +#include // for qUtf8Printable #include -#include // for assert -#include // for UINT_MAX, INT_MAX, etc -#include // for size_t -#include // for wcslen +#include // for assert +#include // for UINT_MAX, INT_MAX, etc +#include // for size_t +#include // for wcslen -#include // for max, min -#include // for exception +#include // for max, min +#include // for exception #include -#include // for set -#include // for find +#include // for set #include +#include // for find using namespace MOBase; using namespace MOShared; @@ -65,13 +65,17 @@ void Profile::touchFile(QString fileName) { QFile modList(m_Directory.filePath(fileName)); if (!modList.open(QIODevice::ReadWrite)) { - throw std::runtime_error(QObject::tr("failed to create %1").arg(m_Directory.filePath(fileName)).toUtf8().constData()); + throw std::runtime_error(QObject::tr("failed to create %1") + .arg(m_Directory.filePath(fileName)) + .toUtf8() + .constData()); } } -Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDefaultSettings) - : m_ModListWriter(std::bind(&Profile::doWriteModlist, this)) - , m_GamePlugin(gamePlugin) +Profile::Profile(const QString& name, IPluginGame const* gamePlugin, + bool useDefaultSettings) + : m_ModListWriter(std::bind(&Profile::doWriteModlist, this)), + m_GamePlugin(gamePlugin) { QString profilesDir = Settings::instance().paths().profiles(); QDir profileBase(profilesDir); @@ -84,18 +88,17 @@ Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDef throw MyException(tr("failed to create %1").arg(fixedName).toUtf8().constData()); } QString fullPath = profilesDir + "/" + fixedName; - m_Directory = QDir(fullPath); - m_Settings = new QSettings(m_Directory.absoluteFilePath("settings.ini"), - QSettings::IniFormat); + m_Directory = QDir(fullPath); + m_Settings = + new QSettings(m_Directory.absoluteFilePath("settings.ini"), QSettings::IniFormat); try { // create files. Needs to happen after m_Directory was set! touchFile("modlist.txt"); touchFile("archives.txt"); - IPluginGame::ProfileSettings settings = IPluginGame::CONFIGURATION - | IPluginGame::MODS - | IPluginGame::SAVEGAMES; + IPluginGame::ProfileSettings settings = + IPluginGame::CONFIGURATION | IPluginGame::MODS | IPluginGame::SAVEGAMES; if (useDefaultSettings) { settings |= IPluginGame::PREFER_DEFAULTS; @@ -111,16 +114,14 @@ Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDef refreshModStatus(); } - -Profile::Profile(const QDir &directory, IPluginGame const *gamePlugin) - : m_Directory(directory) - , m_GamePlugin(gamePlugin) - , m_ModListWriter(std::bind(&Profile::doWriteModlist, this)) +Profile::Profile(const QDir& directory, IPluginGame const* gamePlugin) + : m_Directory(directory), m_GamePlugin(gamePlugin), + m_ModListWriter(std::bind(&Profile::doWriteModlist, this)) { assert(gamePlugin != nullptr); - m_Settings = new QSettings(directory.absoluteFilePath("settings.ini"), - QSettings::IniFormat); + m_Settings = + new QSettings(directory.absoluteFilePath("settings.ini"), QSettings::IniFormat); findProfileSettings(); if (!QFile::exists(m_Directory.filePath("modlist.txt"))) { @@ -128,27 +129,24 @@ Profile::Profile(const QDir &directory, IPluginGame const *gamePlugin) touchFile(m_Directory.filePath("modlist.txt")); } - IPluginGame::ProfileSettings settings = IPluginGame::MODS - | IPluginGame::SAVEGAMES; + IPluginGame::ProfileSettings settings = IPluginGame::MODS | IPluginGame::SAVEGAMES; gamePlugin->initializeProfile(directory, settings); refreshModStatus(); } - -Profile::Profile(const Profile &reference) - : m_Directory(reference.m_Directory) - , m_ModListWriter(std::bind(&Profile::doWriteModlist, this)) - , m_GamePlugin(reference.m_GamePlugin) +Profile::Profile(const Profile& reference) + : m_Directory(reference.m_Directory), + m_ModListWriter(std::bind(&Profile::doWriteModlist, this)), + m_GamePlugin(reference.m_GamePlugin) { - m_Settings = new QSettings(m_Directory.absoluteFilePath("settings.ini"), - QSettings::IniFormat); + m_Settings = + new QSettings(m_Directory.absoluteFilePath("settings.ini"), QSettings::IniFormat); findProfileSettings(); refreshModStatus(); } - Profile::~Profile() { delete m_Settings; @@ -179,11 +177,11 @@ void Profile::findProfileSettings() } if (setting("", "AutomaticArchiveInvalidation") == QVariant()) { - BSAInvalidation *invalidation = m_GamePlugin->feature(); - DataArchives *dataArchives = m_GamePlugin->feature(); - bool found = false; + BSAInvalidation* invalidation = m_GamePlugin->feature(); + DataArchives* dataArchives = m_GamePlugin->feature(); + bool found = false; if ((invalidation != nullptr) && (dataArchives != nullptr)) { - for (const QString &archive : dataArchives->archives(this)) { + for (const QString& archive : dataArchives->archives(this)) { if (invalidation->isInvalidationBSA(archive)) { storeSetting("", "AutomaticArchiveInvalidation", true); found = true; @@ -219,20 +217,23 @@ void Profile::cancelModlistWrite() void Profile::doWriteModlist() { - if (!m_Directory.exists()) return; + if (!m_Directory.exists()) + return; try { QString fileName = getModlistFileName(); SafeWriteFile file(fileName); - file->write(QString("# This file was automatically generated by Mod Organizer.\r\n").toUtf8()); + file->write(QString("# This file was automatically generated by Mod Organizer.\r\n") + .toUtf8()); if (m_ModStatus.empty()) { return; } - for (auto iter = m_ModIndexByPriority.crbegin(); iter != m_ModIndexByPriority.crend(); iter++) { + for (auto iter = m_ModIndexByPriority.crbegin(); + iter != m_ModIndexByPriority.crend(); iter++) { // the priority order was inverted on load so it has to be inverted again - const auto index = iter->second; + const auto index = iter->second; ModInfo::Ptr modInfo = ModInfo::getByIndex(index); if (!modInfo->hasAutomaticPriority()) { if (modInfo->isForeign()) { @@ -248,22 +249,20 @@ void Profile::doWriteModlist() } file.commitIfDifferent(m_LastModlistHash); - } catch (const std::exception &e) { + } catch (const std::exception& e) { reportError(tr("failed to write mod list: %1").arg(e.what())); return; } } - void Profile::createTweakedIniFile() { QString tweakedIni = m_Directory.absoluteFilePath("initweaks.ini"); if (QFile::exists(tweakedIni) && !shellDeleteQuiet(tweakedIni)) { const auto e = GetLastError(); - reportError( - tr("failed to update tweaked ini file, wrong settings may be used: %1") - .arg(QString::fromStdWString(formatSystemMessage(e)))); + reportError(tr("failed to update tweaked ini file, wrong settings may be used: %1") + .arg(QString::fromStdWString(formatSystemMessage(e)))); return; } @@ -277,14 +276,15 @@ void Profile::createTweakedIniFile() mergeTweak(getProfileTweaks(), tweakedIni); bool error = false; - if (!MOBase::WriteRegistryValue(L"Archive", L"bInvalidateOlderFiles", L"1", ToWString(tweakedIni).c_str())) { + if (!MOBase::WriteRegistryValue(L"Archive", L"bInvalidateOlderFiles", L"1", + ToWString(tweakedIni).c_str())) { error = true; } if (error) { const auto e = ::GetLastError(); reportError(tr("failed to create tweaked ini: %1") - .arg(QString::fromStdWString(formatSystemMessage(e)))); + .arg(QString::fromStdWString(formatSystemMessage(e)))); } } @@ -305,7 +305,8 @@ void Profile::renameModInAllProfiles(const QString& oldName, const QString& newN } // static -void Profile::renameModInList(QFile &modList, const QString &oldName, const QString &newName) +void Profile::renameModInList(QFile& modList, const QString& oldName, + const QString& newName) { if (!modList.open(QIODevice::ReadOnly)) { reportError(tr("failed to open %1").arg(modList.fileName())); @@ -357,9 +358,8 @@ void Profile::renameModInList(QFile &modList, const QString &oldName, const QStr } if (renamed) - log::debug( - "Renamed {} \"{}\" mod to \"{}\" in {}", - renamed, oldName, newName, modList.fileName()); + log::debug("Renamed {} \"{}\" mod to \"{}\" in {}", renamed, oldName, newName, + modList.fileName()); } void Profile::refreshModStatus() @@ -396,11 +396,12 @@ void Profile::refreshModStatus() // N-1 overwrite (N = number of mods) // - writeModlistNow(true); // if there are pending changes write them first + writeModlistNow(true); // if there are pending changes write them first QFile file(getModlistFileName()); if (!file.open(QIODevice::ReadOnly)) { - throw MyException(tr("\"%1\" is missing or inaccessible").arg(getModlistFileName())); + throw MyException( + tr("\"%1\" is missing or inaccessible").arg(getModlistFileName())); } bool modStatusModified = false; @@ -450,9 +451,7 @@ void Profile::refreshModStatus() unsigned int modIndex = ModInfo::getIndex(modName); if (modIndex == UINT_MAX) { - log::debug( - "mod not found: \"{}\" (profile \"{}\")", - modName, m_Directory.path()); + log::debug("mod not found: \"{}\" (profile \"{}\")", modName, m_Directory.path()); // need to rewrite the modlist to fix this modStatusModified = true; continue; @@ -469,19 +468,18 @@ void Profile::refreshModStatus() m_ModStatus[modIndex].m_Priority = index++; } } else { - log::warn( - "no mod state for \"{}\" (profile \"{}\")", - modName, m_Directory.path()); + log::warn("no mod state for \"{}\" (profile \"{}\")", modName, + m_Directory.path()); // need to rewrite the modlist to fix this modStatusModified = true; } - } // while (!file.atEnd()) + } // while (!file.atEnd()) file.close(); const int numKnownMods = index; - int topInsert = 0; + int topInsert = 0; // invert priority order to match that of the pluginlist, also // give priorities to mods not referenced in the profile and @@ -521,8 +519,8 @@ void Profile::refreshModStatus() } } - // to support insertion of new mods at the top we may now have mods with negative priority, - // so shift them all up to align priority with 0 + // to support insertion of new mods at the top we may now have mods with negative + // priority, so shift them all up to align priority with 0 if (topInsert < 0) { int offset = topInsert * -1; for (size_t i = 0; i < m_ModStatus.size(); ++i) { @@ -548,7 +546,8 @@ void Profile::refreshModStatus() // User has a mod named some variation of "overwrite". Tell them about it. if (warnAboutOverwrite) { - reportError(tr("A mod named \"overwrite\" was detected, disabled, and moved to the highest priority on the mod list. " + reportError(tr("A mod named \"overwrite\" was detected, disabled, and moved to the " + "highest priority on the mod list. " "You may want to rename this mod and enable it again.")); // also, mark the mod-list as changed modStatusModified = true; @@ -559,36 +558,32 @@ void Profile::refreshModStatus() } } - void Profile::dumpModStatus() const { for (unsigned int i = 0; i < m_ModStatus.size(); ++i) { ModInfo::Ptr info = ModInfo::getByIndex(i); - log::warn( - "{}: {} - {} ({})", - i, info->name(), m_ModStatus[i].m_Priority, - m_ModStatus[i].m_Enabled ? "enabled" : "disabled"); + log::warn("{}: {} - {} ({})", i, info->name(), m_ModStatus[i].m_Priority, + m_ModStatus[i].m_Enabled ? "enabled" : "disabled"); } } - void Profile::updateIndices() { m_ModIndexByPriority.clear(); for (unsigned int i = 0; i < m_ModStatus.size(); ++i) { - int priority = m_ModStatus[i].m_Priority; + int priority = m_ModStatus[i].m_Priority; m_ModIndexByPriority[priority] = i; } } - -std::vector > Profile::getActiveMods() +std::vector> Profile::getActiveMods() { - std::vector > result; + std::vector> result; for (const auto& [priority, index] : m_ModIndexByPriority) { if (m_ModStatus[index].m_Enabled) { ModInfo::Ptr modInfo = ModInfo::getByIndex(index); - result.push_back(std::make_tuple(modInfo->internalName(), modInfo->absolutePath(), m_ModStatus[index].m_Priority)); + result.push_back(std::make_tuple(modInfo->internalName(), modInfo->absolutePath(), + m_ModStatus[index].m_Priority)); } } @@ -618,7 +613,8 @@ void Profile::setModEnabled(unsigned int index, bool enabled) } } -void Profile::setModsEnabled(const QList& modsToEnable, const QList& modsToDisable) +void Profile::setModsEnabled(const QList& modsToEnable, + const QList& modsToDisable) { QList dirtyMods; for (auto idx : modsToEnable) { @@ -661,7 +657,6 @@ bool Profile::modEnabled(unsigned int index) const return m_ModStatus[index].m_Enabled; } - int Profile::getModPriority(unsigned int index) const { if (index >= m_ModStatus.size()) { @@ -671,8 +666,7 @@ int Profile::getModPriority(unsigned int index) const return m_ModStatus[index].m_Priority; } - -bool Profile::setModPriority(unsigned int index, int &newPriority) +bool Profile::setModPriority(unsigned int index, int& newPriority) { if (ModInfo::getByIndex(index)->hasAutomaticPriority()) { // can't change priority of overwrite/backups @@ -681,7 +675,7 @@ bool Profile::setModPriority(unsigned int index, int &newPriority) newPriority = std::clamp(newPriority, 0, static_cast(m_NumRegularMods) - 1); - int oldPriority = m_ModStatus.at(index).m_Priority; + int oldPriority = m_ModStatus.at(index).m_Priority; int lastPriority = INT_MIN; if (newPriority == oldPriority) { @@ -690,16 +684,17 @@ bool Profile::setModPriority(unsigned int index, int &newPriority) } for (const auto& [priority, index] : m_ModIndexByPriority) { - if (newPriority < oldPriority && priority >= newPriority && priority < oldPriority) { + if (newPriority < oldPriority && priority >= newPriority && + priority < oldPriority) { m_ModStatus.at(index).m_Priority += 1; - } - else if (newPriority > oldPriority && priority <= newPriority && priority > oldPriority) { + } else if (newPriority > oldPriority && priority <= newPriority && + priority > oldPriority) { m_ModStatus.at(index).m_Priority -= 1; } lastPriority = std::max(lastPriority, priority); } - newPriority = std::min(newPriority, lastPriority); + newPriority = std::min(newPriority, lastPriority); m_ModStatus.at(index).m_Priority = std::min(newPriority, lastPriority); updateIndices(); @@ -708,23 +703,24 @@ bool Profile::setModPriority(unsigned int index, int &newPriority) return true; } -Profile *Profile::createPtrFrom(const QString &name, const Profile &reference, MOBase::IPluginGame const *gamePlugin) +Profile* Profile::createPtrFrom(const QString& name, const Profile& reference, + MOBase::IPluginGame const* gamePlugin) { QString profileDirectory = Settings::instance().paths().profiles() + "/" + name; reference.copyFilesTo(profileDirectory); return new Profile(QDir(profileDirectory), gamePlugin); } -void Profile::copyFilesTo(QString &target) const +void Profile::copyFilesTo(QString& target) const { copyDir(m_Directory.absolutePath(), target, false); } -std::vector Profile::splitDZString(const wchar_t *buffer) const +std::vector Profile::splitDZString(const wchar_t* buffer) const { std::vector result; - const wchar_t *pos = buffer; - size_t length = wcslen(pos); + const wchar_t* pos = buffer; + size_t length = wcslen(pos); while (length != 0U) { result.push_back(pos); pos += length + 1; @@ -733,7 +729,7 @@ std::vector Profile::splitDZString(const wchar_t *buffer) const return result; } -void Profile::mergeTweak(const QString &tweakName, const QString &tweakedIni) const +void Profile::mergeTweak(const QString& tweakName, const QString& tweakedIni) const { static const int bufferSize = 32768; @@ -742,14 +738,15 @@ void Profile::mergeTweak(const QString &tweakName, const QString &tweakedIni) co QScopedArrayPointer buffer(new wchar_t[bufferSize]); // retrieve a list of sections - DWORD size = ::GetPrivateProfileSectionNamesW( - buffer.data(), bufferSize, tweakNameW.c_str()); + DWORD size = + ::GetPrivateProfileSectionNamesW(buffer.data(), bufferSize, tweakNameW.c_str()); if (size == bufferSize - 2) { // unfortunately there is no good way to find the required size // of the buffer throw MyException(QString("Buffer too small. Please report this as a bug. " - "For now you might want to split up %1").arg(tweakName)); + "For now you might want to split up %1") + .arg(tweakName)); } std::vector sections = splitDZString(buffer.data()); @@ -762,36 +759,37 @@ void Profile::mergeTweak(const QString &tweakName, const QString &tweakedIni) co bufferSize, tweakNameW.c_str()); if (size == bufferSize - 2) { throw MyException(QString("Buffer too small. Please report this as a bug. " - "For now you might want to split up %1").arg(tweakName)); + "For now you might want to split up %1") + .arg(tweakName)); } std::vector keys = splitDZString(buffer.data()); for (std::vector::iterator keyIter = keys.begin(); keyIter != keys.end(); ++keyIter) { - //TODO this treats everything as strings but how could I differentiate the type? - ::GetPrivateProfileStringW(iter->c_str(), keyIter->c_str(), - nullptr, buffer.data(), bufferSize, ToWString(tweakName).c_str()); - MOBase::WriteRegistryValue(iter->c_str(), keyIter->c_str(), - buffer.data(), tweakedIniW.c_str()); + // TODO this treats everything as strings but how could I differentiate the type? + ::GetPrivateProfileStringW(iter->c_str(), keyIter->c_str(), nullptr, + buffer.data(), bufferSize, + ToWString(tweakName).c_str()); + MOBase::WriteRegistryValue(iter->c_str(), keyIter->c_str(), buffer.data(), + tweakedIniW.c_str()); } } } -void Profile::mergeTweaks(ModInfo::Ptr modInfo, const QString &tweakedIni) const +void Profile::mergeTweaks(ModInfo::Ptr modInfo, const QString& tweakedIni) const { std::vector iniTweaks = modInfo->getIniTweaks(); - for (std::vector::iterator iter = iniTweaks.begin(); - iter != iniTweaks.end(); ++iter) { + for (std::vector::iterator iter = iniTweaks.begin(); iter != iniTweaks.end(); + ++iter) { mergeTweak(*iter, tweakedIni); } } - -bool Profile::invalidationActive(bool *supported) const +bool Profile::invalidationActive(bool* supported) const { - BSAInvalidation *invalidation = m_GamePlugin->feature(); - DataArchives *dataArchives = m_GamePlugin->feature(); + BSAInvalidation* invalidation = m_GamePlugin->feature(); + DataArchives* dataArchives = m_GamePlugin->feature(); if (supported != nullptr) { *supported = ((invalidation != nullptr) && (dataArchives != nullptr)); @@ -800,10 +798,9 @@ bool Profile::invalidationActive(bool *supported) const return setting("", "AutomaticArchiveInvalidation", false).toBool(); } - void Profile::deactivateInvalidation() { - BSAInvalidation *invalidation = m_GamePlugin->feature(); + BSAInvalidation* invalidation = m_GamePlugin->feature(); if (invalidation != nullptr) { invalidation->deactivate(this); @@ -812,10 +809,9 @@ void Profile::deactivateInvalidation() storeSetting("", "AutomaticArchiveInvalidation", false); } - void Profile::activateInvalidation() { - BSAInvalidation *invalidation = m_GamePlugin->feature(); + BSAInvalidation* invalidation = m_GamePlugin->feature(); if (invalidation != nullptr) { invalidation->activate(this); @@ -824,26 +820,28 @@ void Profile::activateInvalidation() storeSetting("", "AutomaticArchiveInvalidation", true); } - bool Profile::localSavesEnabled() const { return setting("", "LocalSaves", false).toBool(); } - bool Profile::enableLocalSaves(bool enable) { if (enable) { if (!m_Directory.exists("saves")) { m_Directory.mkdir("saves"); } - } else { + } else { QDialogButtonBox::StandardButton res; - res = QuestionBoxMemory::query(QApplication::activeModalWidget(), "deleteSavesQuery", - tr("Delete profile-specific save games?"), - tr("Do you want to delete the profile-specific save games? (If you select \"No\", the " - "save games will show up again if you re-enable profile-specific save games)"), - QDialogButtonBox::No | QDialogButtonBox::Yes | QDialogButtonBox::Cancel, QDialogButtonBox::No); + res = QuestionBoxMemory::query( + QApplication::activeModalWidget(), "deleteSavesQuery", + tr("Delete profile-specific save games?"), + tr("Do you want to delete the profile-specific save games? (If you select " + "\"No\", the " + "save games will show up again if you re-enable profile-specific save " + "games)"), + QDialogButtonBox::No | QDialogButtonBox::Yes | QDialogButtonBox::Cancel, + QDialogButtonBox::No); if (res == QMessageBox::Yes) { shellDelete(QStringList(m_Directory.absoluteFilePath("saves"))); } else if (res == QMessageBox::No) { @@ -854,7 +852,6 @@ bool Profile::enableLocalSaves(bool enable) } storeSetting("", "LocalSaves", enable); return true; - } bool Profile::localSettingsEnabled() const @@ -871,12 +868,15 @@ bool Profile::localSettingsEnabled() const } if (!missingFiles.empty()) { m_GamePlugin->initializeProfile(m_Directory, IPluginGame::CONFIGURATION); - QMessageBox::StandardButton res = QMessageBox::warning( - QApplication::activeModalWidget(), tr("Missing profile-specific game INI files!"), - tr("Some of your profile-specific game INI files were missing. They will now be copied " - "from the vanilla game folder. You might want to double-check your settings.\n\n" - "Missing files:\n") + missingFiles.join("\n") - ); + QMessageBox::StandardButton res = + QMessageBox::warning(QApplication::activeModalWidget(), + tr("Missing profile-specific game INI files!"), + tr("Some of your profile-specific game INI files were " + "missing. They will now be copied " + "from the vanilla game folder. You might want to " + "double-check your settings.\n\n" + "Missing files:\n") + + missingFiles.join("\n")); } } return enabled; @@ -885,14 +885,19 @@ bool Profile::localSettingsEnabled() const bool Profile::enableLocalSettings(bool enable) { if (enable) { - m_GamePlugin->initializeProfile(m_Directory.absolutePath(), IPluginGame::CONFIGURATION); + m_GamePlugin->initializeProfile(m_Directory.absolutePath(), + IPluginGame::CONFIGURATION); } else { QDialogButtonBox::StandardButton res; res = QuestionBoxMemory::query(QApplication::activeModalWidget(), "deleteINIQuery", - tr("Delete profile-specific game INI files?"), - tr("Do you want to delete the profile-specific game INI files? (If you select \"No\", the " - "INI files will be used again if you re-enable profile-specific game INI files.)"), - QDialogButtonBox::No | QDialogButtonBox::Yes | QDialogButtonBox::Cancel, QDialogButtonBox::No); + tr("Delete profile-specific game INI files?"), + tr("Do you want to delete the profile-specific game " + "INI files? (If you select \"No\", the " + "INI files will be used again if you re-enable " + "profile-specific game INI files.)"), + QDialogButtonBox::No | QDialogButtonBox::Yes | + QDialogButtonBox::Cancel, + QDialogButtonBox::No); if (res == QMessageBox::Yes) { QStringList filesToDelete; for (QString file : m_GamePlugin->iniFiles()) { @@ -970,7 +975,8 @@ QString Profile::absoluteIniFilePath(QString iniFile) const QString Profile::getProfileTweaks() const { - return QDir::cleanPath(m_Directory.absoluteFilePath(ToQString(AppConfig::profileTweakIni()))); + return QDir::cleanPath( + m_Directory.absoluteFilePath(ToQString(AppConfig::profileTweakIni()))); } QString Profile::absolutePath() const @@ -981,17 +987,16 @@ QString Profile::absolutePath() const QString Profile::savePath() const { return QDir::cleanPath(m_Directory.absoluteFilePath("saves")); - } -void Profile::rename(const QString &newName) +void Profile::rename(const QString& newName) { QDir profileDir(Settings::instance().paths().profiles()); profileDir.rename(name(), newName); m_Directory.setPath(profileDir.absoluteFilePath(newName)); } -QString keyName(const QString §ion, const QString &name) +QString keyName(const QString& section, const QString& name) { QString key = section; @@ -1006,24 +1011,24 @@ QString keyName(const QString §ion, const QString &name) return key; } -QVariant Profile::setting(const QString §ion, const QString &name, - const QVariant &fallback) const +QVariant Profile::setting(const QString& section, const QString& name, + const QVariant& fallback) const { return m_Settings->value(keyName(section, name), fallback); } -void Profile::storeSetting(const QString §ion, const QString &name, - const QVariant &value) +void Profile::storeSetting(const QString& section, const QString& name, + const QVariant& value) { m_Settings->setValue(keyName(section, name), value); } -void Profile::removeSetting(const QString §ion, const QString &name) +void Profile::removeSetting(const QString& section, const QString& name) { - m_Settings->remove(keyName(section, name)); + m_Settings->remove(keyName(section, name)); } -QVariantMap Profile::settingsByGroup(const QString §ion) const +QVariantMap Profile::settingsByGroup(const QString& section) const { QVariantMap results; m_Settings->beginGroup(section); @@ -1034,7 +1039,7 @@ QVariantMap Profile::settingsByGroup(const QString §ion) const return results; } -void Profile::storeSettingsByGroup(const QString §ion, const QVariantMap &values) +void Profile::storeSettingsByGroup(const QString& section, const QVariantMap& values) { m_Settings->beginGroup(section); for (auto key : values.keys()) { @@ -1043,7 +1048,7 @@ void Profile::storeSettingsByGroup(const QString §ion, const QVariantMap &va m_Settings->endGroup(); } -QList Profile::settingsByArray(const QString &prefix) const +QList Profile::settingsByArray(const QString& prefix) const { QList results; int size = m_Settings->beginReadArray(prefix); @@ -1059,7 +1064,8 @@ QList Profile::settingsByArray(const QString &prefix) const return results; } -void Profile::storeSettingsByArray(const QString &prefix, const QList &values) +void Profile::storeSettingsByArray(const QString& prefix, + const QList& values) { m_Settings->beginWriteArray(prefix); for (int i = 0; i < values.length(); i++) { @@ -1071,17 +1077,18 @@ void Profile::storeSettingsByArray(const QString &prefix, const QListendArray(); } -bool Profile::forcedLibrariesEnabled(const QString &executable) const +bool Profile::forcedLibrariesEnabled(const QString& executable) const { return setting("forced_libraries", executable + "/enabled", true).toBool(); } -void Profile::setForcedLibrariesEnabled(const QString &executable, bool enabled) +void Profile::setForcedLibrariesEnabled(const QString& executable, bool enabled) { storeSetting("forced_libraries", executable + "/enabled", enabled); } -QList Profile::determineForcedLibraries(const QString &executable) const +QList +Profile::determineForcedLibraries(const QString& executable) const { QList results; @@ -1092,10 +1099,12 @@ QList Profile::determineForcedLibraries(const QStri for (auto forcedLoad : forcedLoads) { bool found = false; for (auto rawSetting : rawSettings) { - if ((rawSetting.value("process").toString().compare(forcedLoad.process(), Qt::CaseInsensitive) == 0) - && (rawSetting.value("library").toString().compare(forcedLoad.library(), Qt::CaseInsensitive) == 0)) - { - results.append(forcedLoad.withEnabled(rawSetting.value("enabled", false).toBool())); + if ((rawSetting.value("process").toString().compare(forcedLoad.process(), + Qt::CaseInsensitive) == 0) && + (rawSetting.value("library").toString().compare(forcedLoad.library(), + Qt::CaseInsensitive) == 0)) { + results.append( + forcedLoad.withEnabled(rawSetting.value("enabled", false).toBool())); found = true; } } @@ -1108,26 +1117,25 @@ QList Profile::determineForcedLibraries(const QStri for (auto rawSetting : rawSettings) { bool add = true; for (auto forcedLoad : forcedLoads) { - if ((rawSetting.value("process").toString().compare(forcedLoad.process(), Qt::CaseInsensitive) == 0) - && (rawSetting.value("library").toString().compare(forcedLoad.library(), Qt::CaseInsensitive) == 0)) - { + if ((rawSetting.value("process").toString().compare(forcedLoad.process(), + Qt::CaseInsensitive) == 0) && + (rawSetting.value("library").toString().compare(forcedLoad.library(), + Qt::CaseInsensitive) == 0)) { add = false; } } if (add) { - results.append( - ExecutableForcedLoadSetting( - rawSetting.value("process").toString(), - rawSetting.value("library").toString() - ).withEnabled(rawSetting.value("enabled", false).toBool()) - ); + results.append(ExecutableForcedLoadSetting(rawSetting.value("process").toString(), + rawSetting.value("library").toString()) + .withEnabled(rawSetting.value("enabled", false).toBool())); } } return results; } -void Profile::storeForcedLibraries(const QString &executable, const QList &values) +void Profile::storeForcedLibraries(const QString& executable, + const QList& values) { QList rawSettings; for (auto setting : values) { @@ -1140,7 +1148,7 @@ void Profile::storeForcedLibraries(const QString &executable, const QListremove("forced_libraries/" + executable); } @@ -1149,8 +1157,8 @@ void Profile::debugDump() const { struct Pair { - std::size_t enabled=0; - std::size_t total=0; + std::size_t enabled = 0; + std::size_t total = 0; }; Pair total; @@ -1169,7 +1177,6 @@ void Profile::debugDump() const } }; - for (const auto& status : m_ModStatus) { auto index = m_ModIndexByPriority.find(status.m_Priority); if (index == m_ModIndexByPriority.end()) { @@ -1179,7 +1186,8 @@ void Profile::debugDump() const auto m = ModInfo::getByIndex(index->second); if (!m) { - log::error("mod index {} with priority {} not found", index->second, status.m_Priority); + log::error("mod index {} with priority {} not found", index->second, + status.m_Priority); continue; } @@ -1199,43 +1207,34 @@ void Profile::debugDump() const if (m->hasFlag(ModInfo::FLAG_FOREIGN)) { if (auto* f = dynamic_cast(m.get())) { - switch (f->modType()) - { - case ModInfo::MOD_DLC: - add(dlc, status); - break; - - case ModInfo::MOD_CC: - add(cc, status); - break; - - default: - add(unmanaged, status); - break; + switch (f->modType()) { + case ModInfo::MOD_DLC: + add(dlc, status); + break; + + case ModInfo::MOD_CC: + add(cc, status); + break; + + default: + add(unmanaged, status); + break; } } } - if (!m->hasAnyOfTheseFlags({ - ModInfo::FLAG_BACKUP, ModInfo::FLAG_FOREIGN, - ModInfo::FLAG_SEPARATOR, ModInfo::FLAG_OVERWRITE })) - { + if (!m->hasAnyOfTheseFlags({ModInfo::FLAG_BACKUP, ModInfo::FLAG_FOREIGN, + ModInfo::FLAG_SEPARATOR, ModInfo::FLAG_OVERWRITE})) { add(real, status); } } - log::debug( - "profile '{}' in '{}': " - "mods={}/{} backup={}/{} separators={}/{} real={}/{} dlc={}/{} " - "cc={}/{} unmanaged={}/{} localsaves={}, localsettings={}", - name(), absolutePath(), - total.enabled, total.total, - backup.enabled, backup.total, - separators.enabled, separators.total, - real.enabled, real.total, - dlc.enabled, dlc.total, - cc.enabled, cc.total, - unmanaged.enabled, unmanaged.total, - localSavesEnabled() ? "yes" : "no", - localSettingsEnabled() ? "yes" : "no"); + log::debug("profile '{}' in '{}': " + "mods={}/{} backup={}/{} separators={}/{} real={}/{} dlc={}/{} " + "cc={}/{} unmanaged={}/{} localsaves={}, localsettings={}", + name(), absolutePath(), total.enabled, total.total, backup.enabled, + backup.total, separators.enabled, separators.total, real.enabled, + real.total, dlc.enabled, dlc.total, cc.enabled, cc.total, + unmanaged.enabled, unmanaged.total, localSavesEnabled() ? "yes" : "no", + localSettingsEnabled() ? "yes" : "no"); } -- cgit v1.3.1