From 9df612c7ca0ba4cb0b62d958df4e2745fe0c04ec Mon Sep 17 00:00:00 2001 From: Tannin Date: Wed, 2 Mar 2016 21:28:17 +0100 Subject: more configuration options - overwrite path configurable - one can now set a base directory for all configurable paths - user can now opt in/out of receiving pre-release updates (not functional yet) --- src/settings.cpp | 129 ++++++++++++++++++++++++++++++++++++++++-------- src/settings.h | 27 ++++++++-- src/settingsdialog.cpp | 17 +++++++ src/settingsdialog.h | 6 +++ src/settingsdialog.ui | 131 +++++++++++++++++++++++++++++++++++++++---------- 5 files changed, 257 insertions(+), 53 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index c99b434d..41d176ea 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -33,6 +33,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include @@ -179,6 +180,11 @@ QString Settings::getSteamAppID() const return m_Settings.value("Settings/app_id", m_GamePlugin->steamAPPId()).toString(); } +bool Settings::usePrereleases() const +{ + return m_Settings.value("Settings/use_prereleases", false).toBool(); +} + void Settings::setDownloadSpeed(const QString &serverName, int bytesPerSecond) { m_Settings.beginGroup("Servers"); @@ -213,34 +219,55 @@ std::map Settings::getPreferredServers() return result; } -QString Settings::getConfigurablePath(const QString &key, const QString &def) const +QString Settings::getConfigurablePath(const QString &key, + const QString &def, + bool resolve) const +{ + QString result = QDir::fromNativeSeparators( + m_Settings.value(QString("settings/") + key, + qApp->property("dataPath").toString() + "/" + def) + .toString()); + if (resolve) { + result.replace("%BASE_DIR%", getBaseDirectory()); + } + return result; +} + +QString Settings::getBaseDirectory() const { - return QDir::fromNativeSeparators(m_Settings.value(QString("settings/") + key, qApp->property("dataPath").toString() + "/" + def).toString()); + return QDir::fromNativeSeparators(m_Settings.value( + "settings/base_directory", qApp->property("dataPath").toString()).toString()); } -QString Settings::getDownloadDirectory() const +QString Settings::getDownloadDirectory(bool resolve) const { - return getConfigurablePath("download_directory", ToQString(AppConfig::downloadPath())); + return getConfigurablePath("download_directory", ToQString(AppConfig::downloadPath()), resolve); } -QString Settings::getCacheDirectory() const +QString Settings::getCacheDirectory(bool resolve) const { - return getConfigurablePath("cache_directory", ToQString(AppConfig::cachePath())); + return getConfigurablePath("cache_directory", ToQString(AppConfig::cachePath()), resolve); } -QString Settings::getModDirectory() const +QString Settings::getModDirectory(bool resolve) const { - return getConfigurablePath("mod_directory", ToQString(AppConfig::modsPath())); + return getConfigurablePath("mod_directory", ToQString(AppConfig::modsPath()), resolve); } -QString Settings::getProfileDirectory() const +QString Settings::getProfileDirectory(bool resolve) const { - return getConfigurablePath("profiles_directory", ToQString(AppConfig::profilesPath())); + return getConfigurablePath("profiles_directory", ToQString(AppConfig::profilesPath()), resolve); +} + +QString Settings::getOverwriteDirectory(bool resolve) const +{ + return getConfigurablePath("overwrite_directory", + ToQString(AppConfig::overwritePath()), resolve); } QString Settings::getNMMVersion() const { - static const QString MIN_NMM_VERSION = "0.52.3"; + static const QString MIN_NMM_VERSION = "0.61.13"; QString result = m_Settings.value("Settings/nmm_version", MIN_NMM_VERSION).toString(); if (VersionInfo(result) < VersionInfo(MIN_NMM_VERSION)) { result = MIN_NMM_VERSION; @@ -508,12 +535,7 @@ void Settings::addLanguages(QComboBox *languageBox) void Settings::addStyles(QComboBox *styleBox) { styleBox->addItem("None", ""); -#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) styleBox->addItem("Fusion", "Fusion"); -#else - styleBox->addItem("Plastique", "Plastique"); - styleBox->addItem("Cleanlooks", "Cleanlooks"); -#endif QDirIterator langIter(QCoreApplication::applicationDirPath() + "/" + ToQString(AppConfig::stylesheetsPath()), QStringList("*.qss"), QDir::Files); while (langIter.hasNext()) { @@ -575,6 +597,7 @@ Settings::GeneralTab::GeneralTab(Settings *m_parent, SettingsDialog &m_dialog) , m_logLevelBox(m_dialog.findChild("logLevelBox")) , m_compactBox(m_dialog.findChild("compactBox")) , m_showMetaBox(m_dialog.findChild("showMetaBox")) + , m_usePrereleaseBox(m_dialog.findChild("usePrereleaseBox")) { // FIXME I think 'addLanguages' lives in here not in parent m_parent->addLanguages(m_languageBox); @@ -606,6 +629,7 @@ Settings::GeneralTab::GeneralTab(Settings *m_parent, SettingsDialog &m_dialog) m_logLevelBox->setCurrentIndex(m_parent->logLevel()); m_compactBox->setChecked(m_parent->compactDownloads()); m_showMetaBox->setChecked(m_parent->metaDownloads()); + m_usePrereleaseBox->setChecked(m_parent->usePrereleases()); } void Settings::GeneralTab::update() @@ -629,23 +653,53 @@ void Settings::GeneralTab::update() m_Settings.setValue("Settings/compact_downloads", m_compactBox->isChecked()); m_Settings.setValue("Settings/meta_downloads", m_showMetaBox->isChecked()); + m_Settings.setValue("Settings/use_prereleases", m_usePrereleaseBox->isChecked()); } Settings::PathsTab::PathsTab(Settings *parent, SettingsDialog &dialog) : SettingsTab(parent, dialog) + , m_baseDirEdit(m_dialog.findChild("baseDirEdit")) , m_downloadDirEdit(m_dialog.findChild("downloadDirEdit")) , m_modDirEdit(m_dialog.findChild("modDirEdit")) , m_cacheDirEdit(m_dialog.findChild("cacheDirEdit")) , m_profilesDirEdit(m_dialog.findChild("profilesDirEdit")) -{ - m_downloadDirEdit->setText(m_parent->getDownloadDirectory()); - m_modDirEdit->setText(m_parent->getModDirectory()); - m_cacheDirEdit->setText(m_parent->getCacheDirectory()); - m_profilesDirEdit->setText(m_parent->getProfileDirectory()); + , m_overwriteDirEdit(m_dialog.findChild("overwriteDirEdit")) +{ + m_baseDirEdit->setText(m_parent->getBaseDirectory()); + /* + m_downloadDirEdit->setText(m_parent->getDownloadDirectory(false)); + m_modDirEdit->setText(m_parent->getModDirectory(false)); + m_cacheDirEdit->setText(m_parent->getCacheDirectory(false)); + m_profilesDirEdit->setText(m_parent->getProfileDirectory(false)); + m_overwriteDirEdit->setText(m_parent->getOverwriteDirectory(false)); + */ + + QString basePath = parent->getBaseDirectory(); + QDir baseDir(basePath); + for (const auto &dir : { + std::make_pair(m_downloadDirEdit, m_parent->getDownloadDirectory(false)), + std::make_pair(m_modDirEdit, m_parent->getModDirectory(false)), + std::make_pair(m_cacheDirEdit, m_parent->getCacheDirectory(false)), + std::make_pair(m_profilesDirEdit, m_parent->getProfileDirectory(false)), + std::make_pair(m_overwriteDirEdit, m_parent->getOverwriteDirectory(false)) + }) { + QString storePath = baseDir.relativeFilePath(dir.second); + qDebug("%s -> %s", qPrintable(dir.second), qPrintable(storePath)); + if (storePath.startsWith("..") || QDir::isAbsolutePath(storePath)) { + storePath = dir.second; + } else { + storePath = QString("%BASE_DIR%/") + storePath; + } + dir.first->setText(storePath); + } } void Settings::PathsTab::update() { + typedef std::tuple Directory; + + QString basePath = m_parent->getBaseDirectory(); + if ((QDir::fromNativeSeparators(m_modDirEdit->text()) != QDir::fromNativeSeparators(m_parent->getModDirectory())) && (QMessageBox::question( @@ -660,6 +714,38 @@ void Settings::PathsTab::update() m_modDirEdit->setText(m_parent->getModDirectory()); } + for (const Directory &dir :{ + Directory{m_downloadDirEdit->text(), "download_directory", AppConfig::downloadPath()}, + Directory{m_cacheDirEdit->text(), "cache_directory", AppConfig::cachePath()}, + Directory{m_modDirEdit->text(), "mod_directory", AppConfig::modsPath()}, + Directory{m_overwriteDirEdit->text(), "overwrite_directory", AppConfig::overwritePath()}, + Directory{m_profilesDirEdit->text(), "profiles_directory", AppConfig::profilesPath()} + }) { + QString path, settingsKey; + std::wstring defaultName; + std::tie(path, settingsKey, defaultName) = dir; + + settingsKey = QString("Settings/%1").arg(settingsKey); + + QString realPath = path; + realPath.replace("%BASE_DIR%", m_parent->getBaseDirectory()); + + if (!QDir(realPath).exists()) { + QDir().mkpath(realPath); + } + + qDebug("%s -> %s", qPrintable(path), qPrintable(realPath)); + + if (QFileInfo(realPath) + != QFileInfo(basePath + "/" + QString::fromStdWString(defaultName))) { + m_Settings.setValue(settingsKey, path); + } else { + m_Settings.remove(settingsKey); + } + } + + +/* if (!QDir(m_downloadDirEdit->text()).exists()) { QDir().mkpath(m_downloadDirEdit->text()); } @@ -707,6 +793,7 @@ void Settings::PathsTab::update() } else { m_Settings.remove("Settings/profiles_directory"); } + */ } Settings::NexusTab::NexusTab(Settings *parent, SettingsDialog &dialog) diff --git a/src/settings.h b/src/settings.h index 85a3dac0..9676df70 100644 --- a/src/settings.h +++ b/src/settings.h @@ -105,10 +105,16 @@ public: **/ QString getSteamAppID() const; + /** + * retrieves the base directory under which the other directories usually + * reside + */ + QString getBaseDirectory() const; + /** * retrieve the directory where downloads are stored (with native separators) **/ - QString getDownloadDirectory() const; + QString getDownloadDirectory(bool resolve = true) const; /** * retrieve a sorted list of preferred servers @@ -118,7 +124,7 @@ public: /** * retrieve the directory where mods are stored (with native separators) **/ - QString getModDirectory() const; + QString getModDirectory(bool resolve = true) const; /** * returns the version of nmm to impersonate when connecting to nexus @@ -128,12 +134,18 @@ public: /** * retrieve the directory where the web cache is stored (with native separators) **/ - QString getCacheDirectory() const; + QString getCacheDirectory(bool resolve = true) const; /** * retrieve the directory where profiles stored (with native separators) **/ - QString getProfileDirectory() const; + QString getProfileDirectory(bool resolve = true) const; + + /** + * retrieve the directory were new files are stored that can't be assigned + * to a mod (with native separators) + */ + QString getOverwriteDirectory(bool resolve = true) const; /** * @return true if the user has set up automatic login to nexus @@ -295,6 +307,8 @@ public: */ std::vector plugins() const { return m_Plugins; } + bool usePrereleases() const; + /** * @brief register MO as the handler for nxm links * @param force set to true to enforce the registration dialog to show up, @@ -315,7 +329,7 @@ private: void addStyles(QComboBox *styleBox); void readPluginBlacklist(); void writePluginBlacklist(); - QString getConfigurablePath(const QString &key, const QString &def) const; + QString getConfigurablePath(const QString &key, const QString &def, bool resolve) const; class SettingsTab { @@ -346,6 +360,7 @@ private: QComboBox *m_logLevelBox; QCheckBox *m_compactBox; QCheckBox *m_showMetaBox; + QCheckBox *m_usePrereleaseBox; }; class PathsTab : public SettingsTab @@ -356,10 +371,12 @@ private: void update(); private: + QLineEdit *m_baseDirEdit; QLineEdit *m_downloadDirEdit; QLineEdit *m_modDirEdit; QLineEdit *m_cacheDirEdit; QLineEdit *m_profilesDirEdit; + QLineEdit *m_overwriteDirEdit; }; /** Display/store the configuration in the 'nexus' tab of the settings dialogue */ diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 5b58c9da..d354b29b 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -100,6 +100,15 @@ void SettingsDialog::on_bsaDateBtn_clicked() dir.absolutePath().toStdWString()); } +void SettingsDialog::on_browseBaseDirBtn_clicked() +{ + QString temp = QFileDialog::getExistingDirectory( + this, tr("Select base directory"), ui->baseDirEdit->text()); + if (!temp.isEmpty()) { + ui->baseDirEdit->setText(temp); + } +} + void SettingsDialog::on_browseDownloadDirBtn_clicked() { QString temp = QFileDialog::getExistingDirectory(this, tr("Select download directory"), ui->downloadDirEdit->text()); @@ -132,6 +141,14 @@ void SettingsDialog::on_browseProfilesDirBtn_clicked() } } +void SettingsDialog::on_browseOverwriteDirBtn_clicked() +{ + QString temp = QFileDialog::getExistingDirectory(this, tr("Select overwrite directory"), ui->overwriteDirEdit->text()); + if (!temp.isEmpty()) { + ui->overwriteDirEdit->setText(temp); + } +} + void SettingsDialog::on_resetDialogsButton_clicked() { if (QMessageBox::question(this, tr("Confirm?"), diff --git a/src/settingsdialog.h b/src/settingsdialog.h index d1a566b1..d266488d 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -52,6 +52,12 @@ signals: void resetDialogs(); +private slots: + void on_browseBaseDirBtn_clicked(); + +private slots: + void on_browseOverwriteDirBtn_clicked(); + private slots: void on_browseProfilesDirBtn_clicked(); diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index f54ab895..808d8296 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -107,6 +107,36 @@ p, li { white-space: pre-wrap; } + + + + Update to non-stable releases. + + + If this is enabled, the integrated update mechanism will notify of all releases, including pre-releases (alphas, betas). + +Please use this only if you're sufficiently tech-savvy to investigate issues, look for known problems in the issue tracker and create meaningful reports. + +If you use pre-releases, never contact me directly by e-mail or via private messages! + + + Install Pre-releases (Betas) + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -204,54 +234,71 @@ p, li { white-space: pre-wrap; } - + - Downloads + Base Directory - + + + + ... + + + + + + + + + + + + + ... + + + + + + + Overwrite + + + + Caches - + ... - + - - - - Directory where downloads are stored. - - - Directory where downloads are stored. - - - - - + + - Mods + Downloads - + ... - + Directory where mods are stored. @@ -261,7 +308,7 @@ p, li { white-space: pre-wrap; } - + @@ -274,23 +321,53 @@ p, li { white-space: pre-wrap; } + + + + Directory where downloads are stored. + + + Directory where downloads are stored. + + + - + - Profiles + Mods - - - - + ... + + + + + + + Profiles + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + -- cgit v1.3.1