From e43762e7db5ec66c6fdc7a453b873b433a992e3d Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 7 May 2016 00:22:23 +0200 Subject: profiles can now be configured to use the global game settings instead of profile-local --- src/profile.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- src/profile.h | 31 ++++++++++++++++++++++++++----- src/profilesdialog.cpp | 13 +++++++++++-- src/profilesdialog.h | 3 +++ src/profilesdialog.ui | 10 ++++++++++ 5 files changed, 94 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/profile.cpp b/src/profile.cpp index d71b5a0f..9106cebe 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -72,6 +72,8 @@ Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDef QString profilesDir = Settings::instance().getProfileDirectory(); QDir profileBase(profilesDir); + m_Settings = new QSettings(profileBase.absoluteFilePath("settings.ini")); + QString fixedName = name; if (!fixDirectoryName(fixedName)) { throw MyException(tr("invalid profile name %1").arg(name)); @@ -113,19 +115,18 @@ Profile::Profile(const QDir &directory, IPluginGame const *gamePlugin) { assert(gamePlugin != nullptr); + m_Settings = new QSettings(directory.absoluteFilePath("settings.ini"), + QSettings::IniFormat); + if (!QFile::exists(m_Directory.filePath("modlist.txt"))) { qWarning("missing modlist.txt in %s", qPrintable(directory.path())); touchFile(m_Directory.filePath("modlist.txt")); } - IPluginGame::ProfileSettings settings = IPluginGame::CONFIGURATION - | IPluginGame::MODS + IPluginGame::ProfileSettings settings = IPluginGame::MODS | IPluginGame::SAVEGAMES; gamePlugin->initializeProfile(directory, settings); - if (!QFile::exists(getIniFileName())) { - reportError(QObject::tr("\"%1\" is missing or inaccessible").arg(getIniFileName())); - } refreshModStatus(); } @@ -136,12 +137,15 @@ Profile::Profile(const Profile &reference) , m_GamePlugin(reference.m_GamePlugin) { + m_Settings = new QSettings(m_Directory.absoluteFilePath("settings.ini"), + QSettings::IniFormat); refreshModStatus(); } Profile::~Profile() { + delete m_Settings; m_ModListWriter.writeImmediately(true); } @@ -655,6 +659,30 @@ bool Profile::enableLocalSaves(bool enable) return true; } +bool Profile::localSettingsEnabled() const +{ + return m_Directory.exists(getIniFileName()); +} + +bool Profile::enableLocalSettings(bool enable) +{ + // TODO: this currently assumes game settings are stored in an ini file. + // This shall become very interesting when a game stores its settings in the + // registry + QString backupFile = getIniFileName() + "_"; + if (enable) { + if (m_Directory.exists(backupFile)) { + shellRename(backupFile, getIniFileName()); + } else { + IPluginGame *game = qApp->property("managed_game").value(); + game->initializeProfile(m_Directory, IPluginGame::CONFIGURATION); + } + } else { + shellRename(getIniFileName(), backupFile); + } + + return true; +} QString Profile::getModlistFileName() const { @@ -714,3 +742,14 @@ void Profile::rename(const QString &newName) m_Directory = profileDir.absoluteFilePath(newName); } +QVariant Profile::setting(const QString §ion, const QString &name, + const QVariant &fallback) +{ + return m_Settings->value(section + "/" + name, fallback); +} + +void Profile::storeSetting(const QString §ion, const QString &name, + const QVariant &value) +{ + m_Settings->setValue(section + "/" + name, value); +} diff --git a/src/profile.h b/src/profile.h index 87dd91a5..996e561f 100644 --- a/src/profile.h +++ b/src/profile.h @@ -29,6 +29,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include @@ -112,20 +113,32 @@ public: /** * @return true if this profile uses local save games */ - bool localSavesEnabled() const; + virtual bool localSavesEnabled() const override; /** * @brief enables or disables the use of local save games for this profile - * disabling this does not delete exising local saves but they will not be visible - * in the game + * when disabling the user will be asked if he wants to remove the save games + * in the profile * @param enable if true, local saves are enabled, otherewise they are disabled */ bool enableLocalSaves(bool enable); + /** + * @return true if this profile uses local ini files + */ + virtual bool localSettingsEnabled() const override; + + /** + * @brief enables or disables the use of local ini files for this profile + * disabling this does not delete existing ini files but the global ones will be used + * @param enable + */ + bool enableLocalSettings(bool enable); + /** * @return name of the profile (this is identical to its directory name) **/ - QString name() const { return m_Directory.dirName(); } + virtual QString name() const override { return m_Directory.dirName(); } /** * @return the path of the plugins file in this profile @@ -267,6 +280,12 @@ public: void dumpModStatus() const; + QVariant setting(const QString §ion, const QString &name, + const QVariant &fallback = QVariant()); + + void storeSetting(const QString §ion, const QString &name, + const QVariant &value); + signals: /** @@ -311,7 +330,9 @@ private: QDir m_Directory; - MOBase::IPluginGame const * const m_GamePlugin; + QSettings *m_Settings; + + const MOBase::IPluginGame *m_GamePlugin; mutable QByteArray m_LastModlistHash; std::vector m_ModStatus; diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp index 40f01f0e..04c1876d 100644 --- a/src/profilesdialog.cpp +++ b/src/profilesdialog.cpp @@ -58,7 +58,6 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c QDir profilesDir(Settings::instance().getProfileDirectory()); profilesDir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot); - m_ProfilesList = findChild("profilesList"); QDirIterator profileIter(profilesDir); @@ -322,7 +321,17 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state) void ProfilesDialog::on_transferButton_clicked() { - const Profile::Ptr currentProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value(); + const Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); TransferSavesDialog transferDialog(*currentProfile, m_Game, this); transferDialog.exec(); } + +void ProfilesDialog::on_localIniFilesBox_stateChanged(int state) +{ + Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value(); + + if (!currentProfile->enableLocalSettings(state == Qt::Checked)) { + // revert checkbox-state + ui->localIniFilesBox->setChecked(state != Qt::Checked); + } +} diff --git a/src/profilesdialog.h b/src/profilesdialog.h index 0e79b94b..cab25f6a 100644 --- a/src/profilesdialog.h +++ b/src/profilesdialog.h @@ -61,6 +61,9 @@ protected: virtual void showEvent(QShowEvent *event); +private slots: + void on_localIniFilesBox_stateChanged(int state); + private: QListWidgetItem *addItem(const QString &name); diff --git a/src/profilesdialog.ui b/src/profilesdialog.ui index fe03f466..9b4e7e62 100644 --- a/src/profilesdialog.ui +++ b/src/profilesdialog.ui @@ -45,6 +45,16 @@ p, li { white-space: pre-wrap; } + + + + Local Game Settings + + + false + + + -- cgit v1.3.1