From 0f8ae514592c46dc8465bc5830d7a830b68affe2 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 17 Oct 2015 19:05:00 +0100 Subject: Added support for include-what-you-use in a very simplistic fashion to the Scons build. This isn't exactly production ready because the qt headers are a nightmarish web of interdependencies but it's useful for checking. I've also removed a few unused include files it detected and corrected some things that upset clang in a big way. --- src/loadmechanism.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/loadmechanism.cpp') diff --git a/src/loadmechanism.cpp b/src/loadmechanism.cpp index 4d06bea9..c01955f2 100644 --- a/src/loadmechanism.cpp +++ b/src/loadmechanism.cpp @@ -56,7 +56,7 @@ void LoadMechanism::writeHintFile(const QDir &targetDirectory) } -void LoadMechanism::removeHintFile(QDir &targetDirectory) +void LoadMechanism::removeHintFile(QDir targetDirectory) { targetDirectory.remove("mo_path.txt"); } -- 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/loadmechanism.cpp') 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 From 9e2bcffc32157b99a2d7364b869a4423ba827a32 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 28 Nov 2015 14:53:32 +0000 Subject: Reworked startup considerably so now no longer dependant on GameInfo Did some const correctness to the "managed_game" property as you shouldn't really be altering the plugin details whilst MO is running --- src/directoryrefresher.cpp | 2 +- src/loadmechanism.cpp | 14 ++-- src/main.cpp | 204 ++++++++++++++++++++++++++++++--------------- src/modinfo.cpp | 6 +- src/organizercore.cpp | 18 ++-- src/organizercore.h | 5 +- src/settingsdialog.cpp | 2 +- src/shared/fallout3info.h | 2 - src/shared/falloutnvinfo.h | 2 - src/shared/gameinfo.h | 7 +- src/shared/oblivioninfo.h | 2 - src/shared/skyriminfo.h | 2 - 12 files changed, 156 insertions(+), 110 deletions(-) (limited to 'src/loadmechanism.cpp') diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index 4eac4103..f50a717e 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -144,7 +144,7 @@ void DirectoryRefresher::refresh() m_DirectoryStructure = new DirectoryEntry(L"data", nullptr, 0); - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); std::wstring dataDirectory = QDir::toNativeSeparators(game->dataDirectory().absolutePath()).toStdWString(); m_DirectoryStructure->addFromOrigin(L"data", dataDirectory, 0); diff --git a/src/loadmechanism.cpp b/src/loadmechanism.cpp index 0d95c51c..521473b0 100644 --- a/src/loadmechanism.cpp +++ b/src/loadmechanism.cpp @@ -65,7 +65,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 const *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 return !game->gameDirectory().exists("steam_api.dll"); @@ -77,7 +77,7 @@ bool LoadMechanism::isDirectLoadingSupported() bool LoadMechanism::isScriptExtenderSupported() { - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); ScriptExtender *extender = game->feature(); // test if there even is an extender for the managed game and if so whether it's installed @@ -93,7 +93,7 @@ bool LoadMechanism::isProxyDLLSupported() // plus: the proxy dll hasn't been working for at least the whole 1.12.x versions of MO and // noone reported it so why maintain an unused feature? return false; -/* IPluginGame *game = qApp->property("managed_game").value(); +/* IPluginGame const *game = qApp->property("managed_game").value(); return game->gameDirectory().exists(QString::fromStdWString(AppConfig::proxyDLLTarget()));*/ } @@ -125,7 +125,7 @@ bool LoadMechanism::hashIdentical(const QString &fileNameLHS, const QString &fil void LoadMechanism::deactivateScriptExtender() { try { - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); ScriptExtender *extender = game->feature(); if (extender == nullptr) { throw MyException(QObject::tr("game doesn't support a script extender")); @@ -151,7 +151,7 @@ void LoadMechanism::deactivateScriptExtender() void LoadMechanism::deactivateProxyDLL() { try { - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); QString targetPath = game->gameDirectory().absoluteFilePath(QString::fromStdWString(AppConfig::proxyDLLTarget())); @@ -180,7 +180,7 @@ void LoadMechanism::deactivateProxyDLL() void LoadMechanism::activateScriptExtender() { try { - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); ScriptExtender *extender = game->feature(); if (extender == nullptr) { throw MyException(QObject::tr("game doesn't support a script extender")); @@ -220,7 +220,7 @@ void LoadMechanism::activateScriptExtender() void LoadMechanism::activateProxyDLL() { try { - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); QString targetPath = game->gameDirectory().absoluteFilePath(QString::fromStdWString(AppConfig::proxyDLLTarget())); diff --git a/src/main.cpp b/src/main.cpp index 72a63dc6..78145a74 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -330,6 +330,122 @@ QString determineProfile(QStringList &arguments, const QSettings &settings) return selectedProfileName; } +MOBase::IPluginGame *selectGame(QSettings &settings, QDir const &gamePath, MOBase::IPluginGame *game) +{ + settings.setValue("gameName", game->gameName()); + if (gamePath == game->gameDirectory()) { + settings.remove("gamePath"); + } else { + QString gameDir = gamePath.absolutePath(); + game->setGamePath(gameDir); + settings.setValue("gamePath", QDir::toNativeSeparators(gameDir).toUtf8().constData()); + } + return game; //Woot +} + + +MOBase::IPluginGame *determineCurrentGame(QString const &moPath, QSettings &settings, PluginContainer const &plugins) +{ + //Determine what game we are running where. Be very paranoid in case the + //user has done something odd. + //If the game name has been set up, use that. + QString gameName = settings.value("gameName", "").toString(); + if (!gameName.isEmpty()) { + MOBase::IPluginGame *game = plugins.managedGame(gameName); + if (game == nullptr) { + reportError(QObject::tr("Plugin to handle %1 no longer installed").arg(gameName)); + return nullptr; + } + QString gamePath = QString::fromUtf8(settings.value("gamePath", "").toByteArray()); + if (gamePath == "") { + gamePath = game->gameDirectory().absolutePath(); + } + QDir gameDir(gamePath); + if (game->looksValid(gameDir)) { + return selectGame(settings, gameDir, game); + } + } + + //gameName wasn't set, or otherwise can't be found. Try looking through all + //the plugins using the gamePath + QString gamePath = QString::fromUtf8(settings.value("gamePath", "").toByteArray()); + if (!gamePath.isEmpty()) { + QDir gameDir(gamePath); + //Look to see if one of the installed games binary file exists in the current + //game directory. + for (IPluginGame * const game : plugins.plugins()) { + if (game->looksValid(gameDir)) { + return selectGame(settings, gameDir, game); + } + } + } + + //OK, we are in a new setup or existing info is useless. + //See if MO has been installed inside a game directory + for (IPluginGame * const game : plugins.plugins()) { + if (game->isInstalled() && moPath.startsWith(game->gameDirectory().absolutePath())) { + //Found it. + return selectGame(settings, game->gameDirectory(), game); + } + } + + //Try walking up the directory tree to see if MO has been installed inside a game + { + QDir gameDir(moPath); + do { + //Look to see if one of the installed games binary file exists in the current + //directory. + for (IPluginGame * const game : plugins.plugins()) { + if (game->looksValid(gameDir)) { + return selectGame(settings, gameDir, game); + } + } + //OK, chop off the last directory and try again + } while (gameDir.cdUp()); + } + + //Then try a selection dialogue. + if (!gamePath.isEmpty() || !gameName.isEmpty()) { + reportError(QObject::tr("Could not use configuration settings for game \"%1\", path \"%2\"."). + arg(gameName).arg(gamePath)); + } + + SelectionDialog selection(QObject::tr("Please select the game to manage"), nullptr, QSize(32, 32)); + + for (IPluginGame *game : plugins.plugins()) { + if (game->isInstalled()) { + QString path = game->gameDirectory().absolutePath(); + selection.addChoice(game->gameIcon(), game->gameName(), path, QVariant::fromValue(game)); + } + } + + selection.addChoice(QString("Browse..."), QString(), QVariant::fromValue(static_cast(nullptr))); + + while (selection.exec() != QDialog::Rejected) { + IPluginGame * game = selection.getChoiceData().value(); + if (game != nullptr) { + return selectGame(settings, game->gameDirectory(), game); + } + + gamePath = QFileDialog::getExistingDirectory( + nullptr, QObject::tr("Please select the game to manage"), QString(), + QFileDialog::ShowDirsOnly); + + if (!gamePath.isEmpty()) { + QDir gameDir(gamePath); + for (IPluginGame * const game : plugins.plugins()) { + if (game->looksValid(gameDir)) { + return selectGame(settings, gameDir, game); + } + } + reportError(QObject::tr("No game identified in \"%1\". The directory is required to contain " + "the game binary and its launcher.").arg(gamePath)); + } + } + + return nullptr; +} + int main(int argc, char *argv[]) { MOApplication application(argc, argv); @@ -443,86 +559,36 @@ int main(int argc, char *argv[]) PluginContainer pluginContainer(&organizer); pluginContainer.loadPlugins(); - QString gamePath = QString::fromUtf8(settings.value("gamePath", "").toByteArray()); - bool done = false; - while (!done) { - if (!GameInfo::init(ToWString(application.applicationDirPath()), ToWString(QDir::toNativeSeparators(gamePath)))) { - if (!gamePath.isEmpty()) { - reportError(QObject::tr("No game identified in \"%1\". The directory is required to contain " - "the game binary and its launcher.").arg(gamePath)); - } - SelectionDialog selection(QObject::tr("Please select the game to manage"), nullptr, QSize(32, 32)); - - for (const IPluginGame * const game : pluginContainer.plugins()) { - if (game->isInstalled()) { - QString path = game->gameDirectory().absolutePath(); - selection.addChoice(game->gameIcon(), game->gameName(), path, path); - } - } - - selection.addChoice(QString("Browse..."), QString(), QString()); - - if (selection.exec() == QDialog::Rejected) { - gamePath = ""; - done = true; - } else { - gamePath = QDir::cleanPath(selection.getChoiceData().toString()); - if (gamePath.isEmpty()) { - gamePath = QFileDialog::getExistingDirectory( - nullptr, QObject::tr("Please select the game to manage"), QString(), - QFileDialog::ShowDirsOnly); - qDebug() << "manually selected path " << gamePath; - } - } - } else { - done = true; - gamePath = ToQString(GameInfo::instance().getGameDirectory()); - } - } - - if (gamePath.isEmpty()) { - // game not found and user canceled - return -1; - } else if (gamePath.length() != 0) { - // user selected a folder and game was initialised with it - qDebug("game path: %s", qPrintable(gamePath)); - settings.setValue("gamePath", gamePath.toUtf8().constData()); + MOBase::IPluginGame *game = determineCurrentGame(application.applicationDirPath(), settings, pluginContainer); + if (game == nullptr) { + return 1; } - organizer.setManagedGame(ToQString(GameInfo::instance().getGameName()), gamePath); + organizer.setManagedGame(game); organizer.createDefaultProfile(); - if (pluginContainer.managedGame(ToQString(GameInfo::instance().getGameName())) == nullptr) { - reportError(QObject::tr("Plugin to handle %1 not installed").arg(ToQString(GameInfo::instance().getGameName()))); - return 1; - } - - //This is probably wrong too - { - IPluginGame *game = organizer.managedGameForUpdate(); - - if (!settings.contains("game_edition")) { - QStringList editions = game->gameVariants(); - if (editions.size() > 1) { - SelectionDialog selection(QObject::tr("Please select the game edition you have (MO can't start the game correctly if this is set incorrectly!)"), nullptr); - int index = 0; - for (const QString &edition : editions) { - selection.addChoice(edition, "", index++); - } - if (selection.exec() == QDialog::Rejected) { - return -1; - } else { - settings.setValue("game_edition", selection.getChoiceString()); - } + //See the pragma - we apparently don't use this so not sure why we check it + if (!settings.contains("game_edition")) { + QStringList editions = game->gameVariants(); + if (editions.size() > 1) { + SelectionDialog selection(QObject::tr("Please select the game edition you have (MO can't start the game correctly if this is set incorrectly!)"), nullptr); + int index = 0; + for (const QString &edition : editions) { + selection.addChoice(edition, "", index++); + } + if (selection.exec() == QDialog::Rejected) { + return -1; + } else { + settings.setValue("game_edition", selection.getChoiceString()); } } - game->setGameVariant(settings.value("game_edition").toString()); } + game->setGameVariant(settings.value("game_edition").toString()); #pragma message("edition isn't used?") - qDebug("managing game at %s", qPrintable(QDir::toNativeSeparators(gamePath))); + qDebug("managing game at %s", qPrintable(QDir::toNativeSeparators(game->gameDirectory().absolutePath()))); organizer.updateExecutablesList(settings); diff --git a/src/modinfo.cpp b/src/modinfo.cpp index ef195bea..03ab9a95 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -290,7 +290,7 @@ int ModInfo::checkAllForUpdate(QObject *receiver) std::vector modIDs; //I ought to store this, it's used elsewhere - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); modIDs.push_back(game->getNexusModOrganizerID()); @@ -935,7 +935,7 @@ std::vector ModInfoRegular::getContents() const m_CachedContent.push_back(CONTENT_BSA); } - ScriptExtender *extender = qApp->property("managed_game").value()->feature(); + ScriptExtender *extender = qApp->property("managed_game").value()->feature(); if (extender != nullptr) { QString sePluginPath = extender->name() + "/plugins"; @@ -1137,7 +1137,7 @@ QDateTime ModInfoForeign::creationTime() const QString ModInfoForeign::absolutePath() const { //I ought to store this, it's used elsewhere - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); return game->dataDirectory().absolutePath(); } diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 042a9f1e..06a6dba4 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -422,15 +422,12 @@ void OrganizerCore::disconnectPlugins() m_PluginContainer = nullptr; } -void OrganizerCore::setManagedGame(const QString &gameName, const QString &gamePath) +void OrganizerCore::setManagedGame(MOBase::IPluginGame const *game) { - m_GameName = gameName; - if (m_PluginContainer != nullptr) { - m_GamePlugin = m_PluginContainer->managedGame(m_GameName); - m_GamePlugin->setGamePath(gamePath); - qApp->setProperty("managed_game", QVariant::fromValue(m_GamePlugin)); - emit managedGameChanged(m_GamePlugin); - } + m_GameName = game->gameName(); + m_GamePlugin = game; + qApp->setProperty("managed_game", QVariant::fromValue(m_GamePlugin)); + emit managedGameChanged(m_GamePlugin); } Settings &OrganizerCore::settings() @@ -1327,11 +1324,6 @@ IPluginGame const *OrganizerCore::managedGame() const return m_GamePlugin; } -IPluginGame *OrganizerCore::managedGameForUpdate() const -{ - return m_GamePlugin; -} - std::vector OrganizerCore::enabledArchives() { std::vector result; diff --git a/src/organizercore.h b/src/organizercore.h index c206e5e7..5cfbaca4 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -73,7 +73,7 @@ public: void connectPlugins(PluginContainer *container); void disconnectPlugins(); - void setManagedGame(const QString &gameName, const QString &gamePath); + void setManagedGame(const MOBase::IPluginGame *game); void updateExecutablesList(QSettings &settings); @@ -100,7 +100,6 @@ public: PluginListSortProxy *createPluginListProxyModel(); MOBase::IPluginGame const *managedGame() const; - MOBase::IPluginGame *managedGameForUpdate() const; bool isArchivesInit() const { return m_ArchivesInit; } @@ -234,7 +233,7 @@ private: IUserInterface *m_UserInterface; PluginContainer *m_PluginContainer; QString m_GameName; - MOBase::IPluginGame *m_GamePlugin; + MOBase::IPluginGame const *m_GamePlugin; Profile *m_CurrentProfile; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index c7f15dc9..8bc1dbc6 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -89,7 +89,7 @@ void SettingsDialog::on_categoriesBtn_clicked() void SettingsDialog::on_bsaDateBtn_clicked() { - IPluginGame *game = qApp->property("managed_game").value(); + IPluginGame const *game = qApp->property("managed_game").value(); QDir dir = game->dataDirectory(); Helper::backdateBSAs(qApp->property("dataPath").toString().toStdWString(), diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index ed525588..69eb9c45 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -40,8 +40,6 @@ public: virtual GameInfo::Type getType() { return TYPE_FALLOUT3; } - virtual std::wstring getGameName() const { return L"Fallout 3"; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index ee67ac17..a7ee089e 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -40,8 +40,6 @@ public: virtual GameInfo::Type getType() { return TYPE_FALLOUTNV; } - virtual std::wstring getGameName() const { return L"New Vegas"; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index de3af8b4..55161952 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -58,13 +58,10 @@ public: // get a list of file extensions for additional files belonging to a save game virtual std::vector getSavegameAttachmentExtensions() = 0; - //**Currently only used in a nasty mess at initialisation time. - virtual std::wstring getGameName() const = 0; - - //**USED IN HOOKDLL and in initialisation + //**USED IN HOOKDLL virtual std::wstring getGameDirectory() const; - //**USED IN HOOKDLL and initialisation + //**USED IN HOOKDLL // initialise with the path to the mo directory (needs to be where hook.dll is stored). This // needs to be called before the instance can be retrieved static bool init(const std::wstring &moDirectory, const std::wstring &gamePath = L""); diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index 00048930..e0a861bf 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -38,8 +38,6 @@ public: virtual GameInfo::Type getType() { return TYPE_OBLIVION; } - virtual std::wstring getGameName() const { return L"Oblivion"; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index afba1974..17b542ab 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -40,8 +40,6 @@ public: virtual GameInfo::Type getType() { return TYPE_SKYRIM; } - virtual std::wstring getGameName() const { return L"Skyrim"; } - virtual std::vector getSavegameAttachmentExtensions(); // file name of this games ini (no path) -- cgit v1.3.1 From d03e4f45efa89f135ec7d42f55f24bc816f71e0a Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sat, 28 Nov 2015 23:12:29 +0000 Subject: Abstract away the xxse_loader manipulation and make use of the 'ScriptExtender' feature instead A note: This makes loadmechanism.cpp require xxse_loader.exe to exist, not the dll as other places get the version number from the exe. --- src/loadmechanism.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/loadmechanism.cpp') diff --git a/src/loadmechanism.cpp b/src/loadmechanism.cpp index 521473b0..99fce3ba 100644 --- a/src/loadmechanism.cpp +++ b/src/loadmechanism.cpp @@ -81,9 +81,7 @@ bool LoadMechanism::isScriptExtenderSupported() ScriptExtender *extender = game->feature(); // test if there even is an extender for the managed game and if so whether it's installed - return (extender != nullptr) - && (game->gameDirectory().exists(extender->name() + "_loader.exe") - || game->gameDirectory().exists(extender->name() + "_steam_loader.dll")); + return extender != nullptr && extender->isInstalled(); } bool LoadMechanism::isProxyDLLSupported() -- cgit v1.3.1