From 4dbb3b148d874238b0f8dab323f198cc8d4e40c6 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 21 Nov 2015 17:26:34 +0000 Subject: Replace some instances of qApp->property("managed_game") with the saved pointer. Pedantic note: This doesn't help the possibility of supporting multiple executables greatly, we'd have to have a lot of register-for-change events. --- src/profile.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/profile.h') diff --git a/src/profile.h b/src/profile.h index 342b6fa0..9c8139e9 100644 --- a/src/profile.h +++ b/src/profile.h @@ -65,6 +65,7 @@ public: * @param filter save game filter. Defaults to <no filter>. **/ Profile(const QString &name, MOBase::IPluginGame *gamePlugin, bool useDefaultSettings); + /** * @brief constructor * -- cgit v1.3.1 From a7ef08965097fb4b863c99de2d6291733b4bc3c0 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Tue, 24 Nov 2015 09:45:45 +0000 Subject: Use IPluginGame::getIniFiles throughout. Also removed the default constructor from Profile class and stopped registering it as a QMetaObject (which it is the only reason it is there). --- src/mainwindow.cpp | 8 +++++--- src/profile.cpp | 10 +--------- src/profile.h | 15 +++------------ 3 files changed, 9 insertions(+), 24 deletions(-) (limited to 'src/profile.h') diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ceb118ea..c08993c1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1258,9 +1258,11 @@ QDir MainWindow::currentSavesDir() const savesDir.setPath(m_OrganizerCore.currentProfile()->absolutePath() + "/saves"); } else { wchar_t path[MAX_PATH]; - ::GetPrivateProfileStringW(L"General", L"SLocalSavePath", L"Saves", - path, MAX_PATH, - (ToWString(m_OrganizerCore.currentProfile()->absolutePath()) + L"\\" + GameInfo::instance().getIniFileNames().at(0)).c_str()); + ::GetPrivateProfileStringW( + L"General", L"SLocalSavePath", L"Saves", + path, MAX_PATH, + ToWString(m_OrganizerCore.currentProfile()->absolutePath() + "/" + + m_OrganizerCore.managedGame()->getIniFiles()[0]).c_str()); savesDir.setPath(m_OrganizerCore.managedGame()->documentsDirectory().absoluteFilePath(QString::fromWCharArray(path))); } diff --git a/src/profile.cpp b/src/profile.cpp index c6a2b43d..42dc56d1 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -46,13 +46,6 @@ along with Mod Organizer. If not, see . using namespace MOBase; using namespace MOShared; - -Profile::Profile() - : m_ModListWriter(std::bind(&Profile::writeModlistNow, this)) - , m_GamePlugin(qApp->property("managed_game").value()) -{ -} - void Profile::touchFile(QString fileName) { QFile modList(m_Directory.filePath(fileName)); @@ -679,8 +672,7 @@ QString Profile::getDeleterFileName() const QString Profile::getIniFileName() const { - std::wstring primaryIniFile = *(GameInfo::instance().getIniFileNames().begin()); - return m_Directory.absoluteFilePath(ToQString(primaryIniFile)); + return m_Directory.absoluteFilePath(m_GamePlugin->getIniFiles()[0]); } QString Profile::getProfileTweaks() const diff --git a/src/profile.h b/src/profile.h index 9c8139e9..e9edca56 100644 --- a/src/profile.h +++ b/src/profile.h @@ -24,17 +24,16 @@ along with Mod Organizer. If not, see . #include "modinfo.h" #include #include + #include #include -#include #include + #include #include -namespace MOBase { - class IPluginGame; -} +namespace MOBase { class IPluginGame; } /** * @brief represents a profile @@ -50,12 +49,6 @@ public: public: - /** - * @brief default constructor - * @todo This constructor initialised nothing, the resulting object is not usable - **/ - Profile(); - /** * @brief constructor * @@ -320,7 +313,5 @@ private: }; -Q_DECLARE_METATYPE(Profile) - #endif // PROFILE_H -- cgit v1.3.1 From 78b686b2bc507a5606bc7c673745b02346bc667a Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Wed, 25 Nov 2015 08:22:40 +0000 Subject: 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 --- src/directoryrefresher.cpp | 8 +++++++- src/loadmechanism.cpp | 1 + src/mainwindow.cpp | 23 ++++++++++++----------- src/mainwindow.h | 4 ---- src/modinfo.cpp | 5 +++-- src/organizercore.cpp | 2 +- src/profile.cpp | 8 +++++--- src/profile.h | 8 ++++---- src/profilesdialog.cpp | 12 ++++++------ src/profilesdialog.h | 4 ++-- src/settingsdialog.cpp | 11 +++++++++-- src/shared/gameinfo.h | 2 +- src/transfersavesdialog.cpp | 2 +- src/transfersavesdialog.h | 4 ++-- 14 files changed, 54 insertions(+), 40 deletions(-) (limited to 'src/profile.h') 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 . */ #include "directoryrefresher.h" + +#include "iplugingame.h" #include "utility.h" #include "report.h" #include "modinfo.h" #include + +#include #include #include @@ -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(); + + 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(); 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 >::iterator iter = missingPlugins.find(esp); if (iter != missingPlugins.end()) { iter->second.push_back(""); @@ -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 >::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 >::iterator iter = missingPlugins.find(esp); if (iter != missingPlugins.end()) { iter->second.push_back(""); 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(); + return game->dataDirectory().absolutePath(); } std::vector ModInfoForeign::getFlags() const { std::vector 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 <no filter>. **/ - 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 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("invalidationBox"); - IPluginGame *game = qApp->property("managed_game").value(); BSAInvalidation *invalidation = game->feature(); 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())))); + 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("profilesList"); QListWidgetItem *newItem = new QListWidgetItem(name, profilesList); - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(new Profile(name, qApp->property("managed_game").value(), 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("profilesList"); QListWidgetItem *newItem = new QListWidgetItem(name, profilesList); - newItem->setData(Qt::UserRole, QVariant::fromValue(Profile::Ptr(Profile::createPtrFrom(name, reference, qApp->property("managed_game").value())))); + 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(); - TransferSavesDialog transferDialog(*currentProfile, qApp->property("managed_game").value(), 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 . */ #include "settingsdialog.h" + #include "ui_settingsdialog.h" #include "categoriesdialog.h" #include "helper.h" #include "noeditdelegate.h" +#include "iplugingame.h" #include +#include "settings.h" + #include #include #include #include #define WIN32_LEAN_AND_MEAN #include -#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(); + 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 m_GlobalSaves; std::vector m_LocalSaves; -- cgit v1.3.1