summaryrefslogtreecommitdiff
path: root/src/profile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/profile.cpp')
-rw-r--r--src/profile.cpp83
1 files changed, 64 insertions, 19 deletions
diff --git a/src/profile.cpp b/src/profile.cpp
index 21fb0b7a..558d9114 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -20,12 +20,13 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "profile.h"
#include "modinfo.h"
-#include "safewritefile.h"
+#include "settings.h"
#include <utility.h>
#include <error_report.h>
#include "appconfig.h"
#include <iplugingame.h>
#include <report.h>
+#include <safewritefile.h>
#include <bsainvalidation.h>
#include <dataarchives.h>
@@ -68,9 +69,11 @@ Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDef
: m_ModListWriter(std::bind(&Profile::writeModlistNow, this))
, m_GamePlugin(gamePlugin)
{
- QString profilesDir = qApp->property("dataPath").toString() + "/" + ToQString(AppConfig::profilesPath());
+ 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));
@@ -112,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();
}
@@ -135,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);
}
@@ -162,7 +167,7 @@ void Profile::writeModlistNow()
return;
}
- for (int i = m_ModStatus.size() - 1; i >= 0; --i) {
+ for (int i = static_cast<int>(m_ModStatus.size()) - 1; i >= 0; --i) {
// the priority order was inverted on load so it has to be inverted again
unsigned int index = m_ModIndexByPriority[i];
if (index != UINT_MAX) {
@@ -310,7 +315,7 @@ void Profile::refreshModStatus()
// invert priority order to match that of the pluginlist. Also
// give priorities to mods not referenced in the profile
for (size_t i = 0; i < m_ModStatus.size(); ++i) {
- ModInfo::Ptr modInfo = ModInfo::getByIndex(i);
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(static_cast<int>(i));
if (modInfo->alwaysEnabled()) {
m_ModStatus[i].m_Enabled = true;
}
@@ -339,7 +344,7 @@ void Profile::refreshModStatus()
if (topInsert < 0) {
int offset = topInsert * -1;
for (size_t i = 0; i < m_ModStatus.size(); ++i) {
- ModInfo::Ptr modInfo = ModInfo::getByIndex(i);
+ ModInfo::Ptr modInfo = ModInfo::getByIndex(static_cast<unsigned int>(i));
if (modInfo->getFixedPriority() == INT_MAX) {
continue;
}
@@ -468,7 +473,9 @@ void Profile::setModPriority(unsigned int index, int &newPriority)
return;
}
- int newPriorityTemp = (std::max)(0, (std::min<int>)(m_ModStatus.size() - 1, newPriority));
+ int newPriorityTemp =
+ (std::max)(0, (std::min<int>)(static_cast<int>(m_ModStatus.size()) - 1,
+ newPriority));
// don't try to place below overwrite
while ((m_ModIndexByPriority.at(newPriorityTemp) >= m_ModStatus.size()) ||
@@ -497,7 +504,7 @@ void Profile::setModPriority(unsigned int index, int &newPriority)
Profile *Profile::createPtrFrom(const QString &name, const Profile &reference, MOBase::IPluginGame const *gamePlugin)
{
- QString profileDirectory = qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::profilesPath()) + "/" + name;
+ QString profileDirectory = Settings::instance().getProfileDirectory() + "/" + name;
reference.copyFilesTo(profileDirectory);
return new Profile(QDir(profileDirectory), gamePlugin);
}
@@ -592,7 +599,9 @@ bool Profile::invalidationActive(bool *supported) const
}
return false;
} else {
- *supported = false;
+ if (supported != nullptr) {
+ *supported = false;
+ }
}
return false;
}
@@ -633,11 +642,12 @@ bool Profile::enableLocalSaves(bool enable)
m_Directory.mkdir("saves");
}
} else {
- QMessageBox::StandardButton res = QMessageBox::question(QApplication::activeModalWidget(), tr("Delete savegames?"),
- tr("Do you want to delete local savegames? (If you select \"No\", the save games "
- "will show up again if you re-enable local savegames)"),
- QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
- QMessageBox::Cancel);
+ QMessageBox::StandardButton res = QMessageBox::question(
+ QApplication::activeModalWidget(), tr("Delete savegames?"),
+ tr("Do you want to delete local savegames? (If you select \"No\", the "
+ "save games will show up again if you re-enable local savegames)"),
+ QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
+ QMessageBox::Cancel);
if (res == QMessageBox::Yes) {
shellDelete(QStringList(m_Directory.absoluteFilePath("saves")));
} else if (res == QMessageBox::No) {
@@ -651,6 +661,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<IPluginGame *>();
+ game->initializeProfile(m_Directory, IPluginGame::CONFIGURATION);
+ }
+ } else {
+ shellRename(getIniFileName(), backupFile);
+ }
+
+ return true;
+}
QString Profile::getModlistFileName() const
{
@@ -705,8 +739,19 @@ QString Profile::savePath() const
void Profile::rename(const QString &newName)
{
- QDir profileDir(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::profilesPath()));
+ QDir profileDir(Settings::instance().getProfileDirectory());
profileDir.rename(name(), newName);
m_Directory = profileDir.absoluteFilePath(newName);
}
+QVariant Profile::setting(const QString &section, const QString &name,
+ const QVariant &fallback)
+{
+ return m_Settings->value(section + "/" + name, fallback);
+}
+
+void Profile::storeSetting(const QString &section, const QString &name,
+ const QVariant &value)
+{
+ m_Settings->setValue(section + "/" + name, value);
+}