summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Tanner <trtanner@btinternet.com>2015-11-25 08:22:40 +0000
committerThomas Tanner <trtanner@btinternet.com>2015-11-25 08:22:40 +0000
commit78b686b2bc507a5606bc7c673745b02346bc667a (patch)
treed161d6096289aed99cfb1bf79cce4c2404c202dd
parent42a68689fe60ba29367dc0c8f65083d9bde93e1f (diff)
Removes all references to GameInfo::getGameDirectory apart from one during startup
Did some const correctness improvements Also may have fixed a potential crash as the Profile copy constructor didn't copy the m_GamePlugin membber
-rw-r--r--src/directoryrefresher.cpp8
-rw-r--r--src/loadmechanism.cpp1
-rw-r--r--src/mainwindow.cpp23
-rw-r--r--src/mainwindow.h4
-rw-r--r--src/modinfo.cpp5
-rw-r--r--src/organizercore.cpp2
-rw-r--r--src/profile.cpp8
-rw-r--r--src/profile.h8
-rw-r--r--src/profilesdialog.cpp12
-rw-r--r--src/profilesdialog.h4
-rw-r--r--src/settingsdialog.cpp11
-rw-r--r--src/shared/gameinfo.h2
-rw-r--r--src/transfersavesdialog.cpp2
-rw-r--r--src/transfersavesdialog.h4
14 files changed, 54 insertions, 40 deletions
diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp
index c253f384..f4ad2a7d 100644
--- a/src/directoryrefresher.cpp
+++ b/src/directoryrefresher.cpp
@@ -18,10 +18,14 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "directoryrefresher.h"
+
+#include "iplugingame.h"
#include "utility.h"
#include "report.h"
#include "modinfo.h"
#include <gameinfo.h>
+
+#include <QApplication>
#include <QDir>
#include <QString>
@@ -141,7 +145,9 @@ void DirectoryRefresher::refresh()
m_DirectoryStructure = new DirectoryEntry(L"data", nullptr, 0);
- std::wstring dataDirectory = GameInfo::instance().getGameDirectory() + L"\\data";
+ IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
+
+ std::wstring dataDirectory = QDir::toNativeSeparators(game->dataDirectory().absolutePath()).toStdWString();
m_DirectoryStructure->addFromOrigin(L"data", dataDirectory, 0);
// TODO what was the point of having the priority in this tuple? the list is already sorted by priority
diff --git a/src/loadmechanism.cpp b/src/loadmechanism.cpp
index 4d06bea9..0d95c51c 100644
--- a/src/loadmechanism.cpp
+++ b/src/loadmechanism.cpp
@@ -64,6 +64,7 @@ void LoadMechanism::removeHintFile(QDir &targetDirectory)
bool LoadMechanism::isDirectLoadingSupported()
{
+ //FIXME: Seriously? isn't there a 'do i need steam' thing?
IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
if (game->gameName().compare("oblivion", Qt::CaseInsensitive) == 0) {
// oblivion can be loaded directly if it's not the steam variant
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 5856f57f..05650219 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -153,7 +153,6 @@ MainWindow::MainWindow(const QString &exeName
, m_ModListGroupingProxy(nullptr)
, m_ModListSortProxy(nullptr)
, m_OldExecutableIndex(-1)
- , m_GamePath(ToQString(GameInfo::instance().getGameDirectory()))
, m_CategoryFactory(CategoryFactory::instance())
, m_ContextItem(nullptr)
, m_ContextAction(nullptr)
@@ -1031,9 +1030,9 @@ void MainWindow::on_profileBox_currentIndexChanged(int index)
if (ui->profileBox->currentIndex() == 0) {
ui->profileBox->setCurrentIndex(previousIndex);
- ProfilesDialog(ui->profileBox->currentText(), this).exec();
+ ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore.managedGame(), this).exec();
while (!refreshProfiles()) {
- ProfilesDialog(ui->profileBox->currentText(), this).exec();
+ ProfilesDialog(ui->profileBox->currentText(), m_OrganizerCore.managedGame(), this).exec();
}
} else {
activateSelectedProfile();
@@ -1819,16 +1818,18 @@ void MainWindow::on_actionInstallMod_triggered()
void MainWindow::on_actionAdd_Profile_triggered()
{
- bool repeat = true;
- while (repeat) {
- ProfilesDialog profilesDialog(m_GamePath, this);
+ for (;;) {
+ //Note: Calling this with an invalid profile name. Not quite sure why
+ ProfilesDialog profilesDialog(m_OrganizerCore.managedGame()->gameDirectory().absolutePath(),
+ m_OrganizerCore.managedGame(),
+ this);
// workaround: need to disable monitoring of the saves directory, otherwise the active
// profile directory is locked
stopMonitorSaves();
profilesDialog.exec();
refreshSaveList(); // since the save list may now be outdated we have to refresh it completely
if (refreshProfiles() && !profilesDialog.failed()) {
- repeat = false;
+ break;
}
}
// addProfile();
@@ -3225,9 +3226,9 @@ void MainWindow::fixMods_clicked()
// search in data
{
- QDir dataDir(m_GamePath + "/data");
+ QDir dataDir(m_OrganizerCore.managedGame()->dataDirectory());
QStringList esps = dataDir.entryList(espFilter);
- foreach (const QString &esp, esps) {
+ for (const QString &esp : esps) {
std::map<QString, std::vector<QString> >::iterator iter = missingPlugins.find(esp);
if (iter != missingPlugins.end()) {
iter->second.push_back("<data>");
@@ -3241,7 +3242,7 @@ void MainWindow::fixMods_clicked()
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
QStringList esps = QDir(modInfo->absolutePath()).entryList(espFilter);
- foreach (const QString &esp, esps) {
+ for (const QString &esp : esps) {
std::map<QString, std::vector<QString> >::iterator iter = missingPlugins.find(esp);
if (iter != missingPlugins.end()) {
iter->second.push_back(modInfo->name());
@@ -3253,7 +3254,7 @@ void MainWindow::fixMods_clicked()
{
QDir overwriteDir(qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::overwritePath()));
QStringList esps = overwriteDir.entryList(espFilter);
- foreach (const QString &esp, esps) {
+ for (const QString &esp : esps) {
std::map<QString, std::vector<QString> >::iterator iter = missingPlugins.find(esp);
if (iter != missingPlugins.end()) {
iter->second.push_back("<overwrite>");
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 55ae40b9..b97a728e 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -285,15 +285,11 @@ private:
int m_OldExecutableIndex;
- QString m_GamePath;
-
int m_ContextRow;
QPersistentModelIndex m_ContextIdx;
QTreeWidgetItem *m_ContextItem;
QAction *m_ContextAction;
- //int m_SelectedSaveGame;
-
CategoryFactory &m_CategoryFactory;
int m_ModsToUpdate;
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index a0628bd8..d79a7919 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -1134,14 +1134,15 @@ QDateTime ModInfoForeign::creationTime() const
QString ModInfoForeign::absolutePath() const
{
- return QDir::fromNativeSeparators(ToQString(GameInfo::instance().getGameDirectory())) + "/data";
+ //I ought to store this, it's used elsewhere
+ IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
+ return game->dataDirectory().absolutePath();
}
std::vector<ModInfo::EFlag> ModInfoForeign::getFlags() const
{
std::vector<ModInfo::EFlag> result = ModInfoWithConflictInfo::getFlags();
result.push_back(FLAG_FOREIGN);
-
return result;
}
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 24077923..c3e10d37 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -1011,7 +1011,7 @@ HANDLE OrganizerCore::startApplication(const QString &executable, const QStringL
binary = QFileInfo(executable);
if (binary.isRelative()) {
// relative path, should be relative to game directory
- binary = QFileInfo(QDir::fromNativeSeparators(ToQString(GameInfo::instance().getGameDirectory())) + "/" + executable);
+ binary = QFileInfo(managedGame()->gameDirectory().absoluteFilePath(executable));
}
if (cwd.length() == 0) {
currentDirectory = binary.absolutePath();
diff --git a/src/profile.cpp b/src/profile.cpp
index 42dc56d1..77f6ebd1 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -54,7 +54,7 @@ void Profile::touchFile(QString fileName)
}
}
-Profile::Profile(const QString &name, IPluginGame *gamePlugin, bool useDefaultSettings)
+Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDefaultSettings)
: m_ModListWriter(std::bind(&Profile::writeModlistNow, this))
, m_GamePlugin(gamePlugin)
{
@@ -95,7 +95,7 @@ Profile::Profile(const QString &name, IPluginGame *gamePlugin, bool useDefaultSe
}
-Profile::Profile(const QDir &directory, IPluginGame *gamePlugin)
+Profile::Profile(const QDir &directory, IPluginGame const *gamePlugin)
: m_Directory(directory)
, m_GamePlugin(gamePlugin)
, m_ModListWriter(std::bind(&Profile::writeModlistNow, this))
@@ -122,6 +122,8 @@ Profile::Profile(const QDir &directory, IPluginGame *gamePlugin)
Profile::Profile(const Profile &reference)
: m_Directory(reference.m_Directory)
, m_ModListWriter(std::bind(&Profile::writeModlistNow, this))
+ , m_GamePlugin(reference.m_GamePlugin)
+
{
refreshModStatus();
}
@@ -483,7 +485,7 @@ void Profile::setModPriority(unsigned int index, int &newPriority)
m_ModListWriter.write();
}
-Profile *Profile::createPtrFrom(const QString &name, const Profile &reference, MOBase::IPluginGame *gamePlugin)
+Profile *Profile::createPtrFrom(const QString &name, const Profile &reference, MOBase::IPluginGame const *gamePlugin)
{
QString profileDirectory = qApp->property("dataPath").toString() + "/" + QString::fromStdWString(AppConfig::profilesPath()) + "/" + name;
reference.copyFilesTo(profileDirectory);
diff --git a/src/profile.h b/src/profile.h
index e9edca56..b306e0c5 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -57,7 +57,7 @@ public:
* @param name name of the new profile
* @param filter save game filter. Defaults to &lt;no filter&gt;.
**/
- Profile(const QString &name, MOBase::IPluginGame *gamePlugin, bool useDefaultSettings);
+ Profile(const QString &name, MOBase::IPluginGame const *gamePlugin, bool useDefaultSettings);
/**
* @brief constructor
@@ -67,7 +67,7 @@ public:
* invoking this should always produce a working profile
* @param directory directory to read the profile from
**/
- Profile(const QDir &directory, MOBase::IPluginGame *gamePlugin);
+ Profile(const QDir &directory, MOBase::IPluginGame const *gamePlugin);
Profile(const Profile &reference);
@@ -82,7 +82,7 @@ public:
* @param name of the new profile
* @param reference profile to copy from
**/
- static Profile *createPtrFrom(const QString &name, const Profile &reference, MOBase::IPluginGame *gamePlugin);
+ static Profile *createPtrFrom(const QString &name, const Profile &reference, MOBase::IPluginGame const *gamePlugin);
MOBase::DelayedFileWriter &modlistWriter() { return m_ModListWriter; }
@@ -302,7 +302,7 @@ private:
QDir m_Directory;
- MOBase::IPluginGame *m_GamePlugin;
+ MOBase::IPluginGame const * const m_GamePlugin;
mutable QByteArray m_LastModlistHash;
std::vector<ModStatus> m_ModStatus;
diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp
index 58be5448..b21aee53 100644
--- a/src/profilesdialog.cpp
+++ b/src/profilesdialog.cpp
@@ -42,10 +42,11 @@ using namespace MOShared;
Q_DECLARE_METATYPE(Profile::Ptr)
-ProfilesDialog::ProfilesDialog(const QString &profileName, QWidget *parent)
+ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame const *game, QWidget *parent)
: TutorableDialog("Profiles", parent)
, ui(new Ui::ProfilesDialog)
, m_FailState(false)
+ , m_Game(game)
{
ui->setupUi(this);
@@ -65,7 +66,6 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, QWidget *parent)
QCheckBox *invalidationBox = findChild<QCheckBox*>("invalidationBox");
- IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
BSAInvalidation *invalidation = game->feature<BSAInvalidation>();
if (invalidation == nullptr) {
@@ -104,7 +104,7 @@ QListWidgetItem *ProfilesDialog::addItem(const QString &name)
QDir profileDir(name);
QListWidgetItem *newItem = new QListWidgetItem(profileDir.dirName(), m_ProfilesList);
try {
- newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(profileDir, qApp->property("managed_game").value<IPluginGame*>()))));
+ newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(profileDir, m_Game))));
m_FailState = false;
} catch (const std::exception& e) {
reportError(tr("failed to create profile: %1").arg(e.what()));
@@ -117,7 +117,7 @@ void ProfilesDialog::createProfile(const QString &name, bool useDefaultSettings)
try {
QListWidget *profilesList = findChild<QListWidget*>("profilesList");
QListWidgetItem *newItem = new QListWidgetItem(name, profilesList);
- newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, qApp->property("managed_game").value<IPluginGame*>(), useDefaultSettings))));
+ newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, m_Game, useDefaultSettings))));
profilesList->addItem(newItem);
m_FailState = false;
} catch (const std::exception&) {
@@ -131,7 +131,7 @@ void ProfilesDialog::createProfile(const QString &name, const Profile &reference
try {
QListWidget *profilesList = findChild<QListWidget*>("profilesList");
QListWidgetItem *newItem = new QListWidgetItem(name, profilesList);
- newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference, qApp->property("managed_game").value<IPluginGame*>()))));
+ newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference, m_Game))));
profilesList->addItem(newItem);
m_FailState = false;
} catch (const std::exception&) {
@@ -324,6 +324,6 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state)
void ProfilesDialog::on_transferButton_clicked()
{
const Profile::Ptr currentProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
- TransferSavesDialog transferDialog(*currentProfile, qApp->property("managed_game").value<IPluginGame*>(), this);
+ TransferSavesDialog transferDialog(*currentProfile, m_Game, this);
transferDialog.exec();
}
diff --git a/src/profilesdialog.h b/src/profilesdialog.h
index 6dd0c1d4..26476883 100644
--- a/src/profilesdialog.h
+++ b/src/profilesdialog.h
@@ -50,7 +50,7 @@ public:
* @param parent parent widget
* @todo the game path could be retrieved from GameInfo just as easily
**/
- explicit ProfilesDialog(const QString &profileName, QWidget *parent = 0);
+ explicit ProfilesDialog(const QString &profileName, MOBase::IPluginGame const *game, QWidget *parent = 0);
~ProfilesDialog();
/**
@@ -93,7 +93,7 @@ private:
Ui::ProfilesDialog *ui;
QListWidget *m_ProfilesList;
bool m_FailState;
-
+ MOBase::IPluginGame const *m_Game;
};
#endif // PROFILESDIALOG_H
diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp
index f2160719..36e177ab 100644
--- a/src/settingsdialog.cpp
+++ b/src/settingsdialog.cpp
@@ -18,18 +18,21 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "settingsdialog.h"
+
#include "ui_settingsdialog.h"
#include "categoriesdialog.h"
#include "helper.h"
#include "noeditdelegate.h"
+#include "iplugingame.h"
#include <gameinfo.h>
+#include "settings.h"
+
#include <QDirIterator>
#include <QFileDialog>
#include <QMessageBox>
#include <QShortcut>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
-#include "settings.h"
using namespace MOBase;
@@ -87,7 +90,11 @@ void SettingsDialog::on_categoriesBtn_clicked()
void SettingsDialog::on_bsaDateBtn_clicked()
{
- Helper::backdateBSAs(qApp->property("dataPath").toString().toStdWString(), GameInfo::instance().getGameDirectory().append(L"\\data"));
+ IPluginGame *game = qApp->property("managed_game").value<IPluginGame*>();
+ QDir dir = game->dataDirectory();
+
+ Helper::backdateBSAs(qApp->property("dataPath").toString().toStdWString(),
+ dir.absolutePath().toStdWString());
}
void SettingsDialog::on_browseDownloadDirBtn_clicked()
diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h
index da6fb3dc..49b3133b 100644
--- a/src/shared/gameinfo.h
+++ b/src/shared/gameinfo.h
@@ -65,7 +65,7 @@ public:
//**Currently only used in a nasty mess at initialisation time.
virtual std::wstring getGameName() const = 0;
- //**USED IN HOOKDLL
+ //**USED IN HOOKDLL and in initialisation
virtual std::wstring getGameDirectory() const;
// get a list of file extensions for additional files belonging to a save game
diff --git a/src/transfersavesdialog.cpp b/src/transfersavesdialog.cpp
index 73267f75..d47d2bb0 100644
--- a/src/transfersavesdialog.cpp
+++ b/src/transfersavesdialog.cpp
@@ -32,7 +32,7 @@ using namespace MOBase;
using namespace MOShared;
-TransferSavesDialog::TransferSavesDialog(const Profile &profile, IPluginGame *gamePlugin, QWidget *parent)
+TransferSavesDialog::TransferSavesDialog(const Profile &profile, IPluginGame const *gamePlugin, QWidget *parent)
: TutorableDialog("TransferSaves", parent)
, ui(new Ui::TransferSavesDialog)
, m_Profile(profile)
diff --git a/src/transfersavesdialog.h b/src/transfersavesdialog.h
index b9265b6a..d9ea5b29 100644
--- a/src/transfersavesdialog.h
+++ b/src/transfersavesdialog.h
@@ -35,7 +35,7 @@ class TransferSavesDialog : public MOBase::TutorableDialog
Q_OBJECT
public:
- explicit TransferSavesDialog(const Profile &profile, MOBase::IPluginGame *gamePlugin, QWidget *parent = 0);
+ explicit TransferSavesDialog(const Profile &profile, MOBase::IPluginGame const *gamePlugin, QWidget *parent = 0);
~TransferSavesDialog();
private slots:
@@ -76,7 +76,7 @@ private:
Profile m_Profile;
- MOBase::IPluginGame *m_GamePlugin;
+ MOBase::IPluginGame const *m_GamePlugin;
std::vector<SaveGame*> m_GlobalSaves;
std::vector<SaveGame*> m_LocalSaves;