diff options
Diffstat (limited to 'src/settings.cpp')
| -rw-r--r-- | src/settings.cpp | 125 |
1 files changed, 119 insertions, 6 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index 85aa5f2f..f5ad83a7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include "settingsutilities.h" #include "serverinfo.h" #include "executableslist.h" +#include "instancemanager.h" #include "shared/appconfig.h" #include "env.h" #include "envmetrics.h" @@ -65,7 +66,8 @@ Settings::Settings(const QString& path, bool globalInstance) : m_Settings(path, QSettings::IniFormat), m_Game(m_Settings), m_Geometry(m_Settings), m_Widgets(m_Settings, globalInstance), m_Colors(m_Settings), - m_Plugins(m_Settings), m_Paths(m_Settings), m_Network(m_Settings), + m_Plugins(m_Settings), m_Paths(m_Settings), + m_Network(m_Settings, globalInstance), m_Nexus(*this, m_Settings), m_Steam(*this, m_Settings), m_Interface(m_Settings), m_Diagnostics(m_Settings) { @@ -468,7 +470,34 @@ const DiagnosticsSettings& Settings::diagnostics() const QSettings::Status Settings::sync() const { m_Settings.sync(); - return m_Settings.status(); + + const auto s = m_Settings.status(); + + // there's a bug in Qt at least until 5.15.0 where a utf-8 bom in the ini is + // handled correctly but still sets FormatError + // + // see qsettings.cpp, in QConfFileSettingsPrivate::readIniFile(), there's a + // specific check for utf-8, which adjusts `dataPos` so it's skipped, but + // the FLUSH_CURRENT_SECTION() macro uses `currentSectionStart`, and that one + // isn't adjusted when changing `dataPos` on the first line and so stays 0 + // + // this puts the bom in `unparsedIniSections` and eventually sets FormatError + // somewhere + // + // + // the other problem is that the status is never reset, not even when calling + // sync(), so the FormatError that's returned here is actually from reading + // the ini, not writing it + // + // + // since it's impossible to get a FormatError on write, it's considered to + // be a NoError here + + if (s == QSettings::FormatError) { + return QSettings::NoError; + } else { + return s; + } } QSettings::Status Settings::iniStatus() const @@ -479,7 +508,9 @@ QSettings::Status Settings::iniStatus() const void Settings::dump() const { static const QStringList ignore({ - "username", "password", "nexus_api_key", "nexus_username", "nexus_password" + "username", "password", + "nexus_api_key", "nexus_username", "nexus_password", + "steam_username" }); log::debug("settings:"); @@ -497,6 +528,7 @@ void Settings::dump() const } m_Network.dump(); + m_Nexus.dump(); } void Settings::managedGameChanged(IPluginGame const *gamePlugin) @@ -1524,7 +1556,7 @@ std::map<QString, QString> PathSettings::recent() const if (name.isValid() && dir.isValid()) { map.emplace(name.toString(), dir.toString()); } - }); + }); return map; } @@ -1666,9 +1698,21 @@ void PathSettings::setOverwrite(const QString& path) } -NetworkSettings::NetworkSettings(QSettings& settings) +NetworkSettings::NetworkSettings(QSettings& settings, bool globalInstance) : m_Settings(settings) { + if (globalInstance) { + updateCustomBrowser(); + } +} + +void NetworkSettings::updateCustomBrowser() +{ + if (useCustomBrowser()) { + MOBase::shell::SetUrlHandler(customBrowserCommand()); + } else { + MOBase::shell::SetUrlHandler(""); + } } bool NetworkSettings::offlineMode() const @@ -1800,6 +1844,28 @@ void NetworkSettings::updateFromOldMap() updateServers(servers); } +bool NetworkSettings::useCustomBrowser() const +{ + return get<bool>(m_Settings, "Settings", "use_custom_browser", false); +} + +void NetworkSettings::setUseCustomBrowser(bool b) +{ + set(m_Settings, "Settings", "use_custom_browser", b); + updateCustomBrowser(); +} + +QString NetworkSettings::customBrowserCommand() const +{ + return get<QString>(m_Settings, "Settings", "custom_browser", ""); +} + +void NetworkSettings::setCustomBrowserCommand(const QString& s) +{ + set(m_Settings, "Settings", "custom_browser", s); + updateCustomBrowser(); +} + ServerList NetworkSettings::serversFromOldMap() const { // for 2.2.1 and before @@ -1891,7 +1957,10 @@ void NexusSettings::setTrackedIntegration(bool b) const void NexusSettings::registerAsNXMHandler(bool force) { - const auto nxmPath = QCoreApplication::applicationDirPath() + "/nxmhandler.exe"; + const auto nxmPath = + QCoreApplication::applicationDirPath() + "/" + + QString::fromStdWString(AppConfig::nxmHandlerExe()); + const auto executable = QCoreApplication::applicationFilePath(); QString mode = force ? "forcereg" : "reg"; @@ -1944,6 +2013,50 @@ std::vector<std::chrono::seconds> NexusSettings::validationTimeouts() const return v; } +void NexusSettings::dump() const +{ + const auto iniPath = + InstanceManager::singleton().globalInstancesRootPath() + "/" + + QString::fromStdWString(AppConfig::nxmHandlerIni()); + + if (!QFileInfo(iniPath).exists()) { + log::debug("nxm ini not found at {}", iniPath); + return; + } + + QSettings s(iniPath, QSettings::IniFormat); + if (const auto st=s.status(); st != QSettings::NoError) { + log::debug("can't read nxm ini from {}", iniPath); + return; + } + + log::debug("nxmhandler settings:"); + + QSettings handler("HKEY_CURRENT_USER\\Software\\Classes\\nxm\\", QSettings::NativeFormat); + log::debug(" . primary: {}", handler.value("shell/open/command/Default").toString()); + + const auto noregister = getOptional<bool>(s, "General", "noregister"); + + if (noregister) { + log::debug(" . noregister: {}", *noregister); + } else { + log::debug(" . noregister: (not found)"); + } + + ScopedReadArray sra(s, "handlers"); + + sra.for_each([&] { + const auto games = sra.get<QVariant>("games"); + const auto executable = sra.get<QVariant>("executable"); + const auto arguments = sra.get<QVariant>("arguments"); + + log::debug(" . handler:"); + log::debug(" . games: {}", games.toString()); + log::debug(" . executable: {}", executable.toString()); + log::debug(" . arguments: {}", arguments.toString()); + }); +} + SteamSettings::SteamSettings(Settings& parent, QSettings& settings) : m_Parent(parent), m_Settings(settings) |
