summaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index d41723ca..862ed5f3 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -22,10 +22,11 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "settingsdialog.h"
#include "utility.h"
#include "helper.h"
+#include "json.h"
#include <gameinfo.h>
#include <appconfig.h>
#include <utility.h>
-#include "json.h"
+#include <iplugingame.h>
#include <QCheckBox>
#include <QLineEdit>
@@ -57,13 +58,13 @@ private:
static const unsigned char Key2[20] = { 0x99, 0xb8, 0x76, 0x42, 0x3e, 0xc1, 0x60, 0xa4, 0x5b, 0x01,
0xdb, 0xf8, 0x43, 0x3a, 0xb7, 0xb6, 0x98, 0xd4, 0x7d, 0xa2 };
-Settings *Settings::s_Instance = NULL;
+Settings *Settings::s_Instance = nullptr;
-Settings::Settings()
- : m_Settings(ToQString(GameInfo::instance().getIniFilename()), QSettings::IniFormat)
+Settings::Settings(const QSettings &settingsSource)
+ : m_Settings(settingsSource.fileName(), settingsSource.format())
{
- if (s_Instance != NULL) {
+ if (s_Instance != nullptr) {
throw std::runtime_error("second instance of \"Settings\" created");
} else {
s_Instance = this;
@@ -73,13 +74,13 @@ Settings::Settings()
Settings::~Settings()
{
- s_Instance = NULL;
+ s_Instance = nullptr;
}
Settings &Settings::instance()
{
- if (s_Instance == NULL) {
+ if (s_Instance == nullptr) {
throw std::runtime_error("no instance of \"Settings\"");
}
return *s_Instance;
@@ -110,13 +111,18 @@ void Settings::registerAsNXMHandler(bool force)
std::wstring executable = ToWString(QCoreApplication::applicationFilePath());
std::wstring mode = force ? L"forcereg" : L"reg";
std::wstring parameters = mode + L" " + GameInfo::instance().getGameShortName() + L" \"" + executable + L"\"";
- HINSTANCE res = ::ShellExecuteW(NULL, L"open", nxmPath.c_str(), parameters.c_str(), NULL, SW_SHOWNORMAL);
+ HINSTANCE res = ::ShellExecuteW(nullptr, L"open", nxmPath.c_str(), parameters.c_str(), nullptr, SW_SHOWNORMAL);
if ((int)res <= 32) {
- QMessageBox::critical(NULL, tr("Failed"),
+ QMessageBox::critical(nullptr, tr("Failed"),
tr("Sorry, failed to start the helper application"));
}
}
+void Settings::managedGameChanged(IPluginGame *gamePlugin)
+{
+ m_GamePlugin = gamePlugin;
+}
+
void Settings::registerPlugin(IPlugin *plugin)
{
m_Plugins.push_back(plugin);
@@ -176,12 +182,12 @@ bool Settings::automaticLoginEnabled() const
QString Settings::getSteamAppID() const
{
- return m_Settings.value("Settings/app_id", ToQString(GameInfo::instance().getSteamAPPId(m_Settings.value("game_edition", 0).toInt()))).toString();
+ return m_Settings.value("Settings/app_id", m_GamePlugin->steamAPPId()).toString();
}
QString Settings::getDownloadDirectory() const
{
- return QDir::toNativeSeparators(m_Settings.value("Settings/download_directory", ToQString(GameInfo::instance().getDownloadDir())).toString());
+ return getConfigurablePath("download_directory", ToQString(AppConfig::downloadPath()));
}
@@ -219,14 +225,19 @@ std::map<QString, int> Settings::getPreferredServers()
return result;
}
+QString Settings::getConfigurablePath(const QString &key, const QString &def) const
+{
+ return m_Settings.value(QString("settings/") + key, qApp->property("dataPath").toString() + "/" + def).toString();
+}
+
QString Settings::getCacheDirectory() const
{
- return QDir::toNativeSeparators(m_Settings.value("Settings/cache_directory", ToQString(GameInfo::instance().getCacheDir())).toString());
+ return getConfigurablePath("cache_directory", ToQString(AppConfig::cachePath()));
}
QString Settings::getModDirectory() const
{
- return QDir::toNativeSeparators(m_Settings.value("Settings/mod_directory", ToQString(GameInfo::instance().getModsDir())).toString());
+ return getConfigurablePath("mod_directory", ToQString(AppConfig::modsPath()));
}
QString Settings::getNMMVersion() const
@@ -659,7 +670,7 @@ void Settings::query(QWidget *parent)
{ // advanced settings
if ((QDir::fromNativeSeparators(modDirEdit->text()) != QDir::fromNativeSeparators(getModDirectory())) &&
- (QMessageBox::question(NULL, tr("Confirm"), tr("Changing the mod directory affects all your profiles! "
+ (QMessageBox::question(nullptr, tr("Confirm"), tr("Changing the mod directory affects all your profiles! "
"Mods not present (or named differently) in the new location will be disabled in all profiles. "
"There is no way to undo this unless you backed up your profiles manually. Proceed?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) {
@@ -698,7 +709,7 @@ void Settings::query(QWidget *parent)
m_Settings.setValue("Settings/log_level", logLevelBox->currentIndex());
- if (appIDEdit->text() != ToQString(GameInfo::instance().getSteamAPPId())) {
+ if (appIDEdit->text() != m_GamePlugin->steamAPPId()) {
m_Settings.setValue("Settings/app_id", appIDEdit->text());
} else {
m_Settings.remove("Settings/app_id");