From 49de6e8d2555234c5da132c5fc35287083fe7ef7 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Fri, 20 Nov 2015 18:07:06 +0000 Subject: Get rid of `GameIfo::getOrganizerDirectory` and associated member variable qApp->getProperty("dataPath") can be used instead (and is pretty much everywhere else) so it's unnecessary --- src/main.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 773bfc16..ff34145d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,7 +86,8 @@ using namespace MOShared; bool createAndMakeWritable(const std::wstring &subPath) { - QString fullPath = qApp->property("dataPath").toString() + "/" + QString::fromStdWString(subPath); + QString const dataPath = qApp->property("dataPath").toString(); + QString fullPath = dataPath + "/" + QString::fromStdWString(subPath); if (!QDir(fullPath).exists()) { QDir().mkdir(fullPath); @@ -100,7 +101,7 @@ bool createAndMakeWritable(const std::wstring &subPath) "will be made writable for the current user account). You will be asked to run " "\"helper.exe\" with administrative rights."), QMessageBox::Yes | QMessageBox::Cancel) == QMessageBox::Yes) { - if (!Helper::init(GameInfo::instance().getOrganizerDirectory())) { + if (!Helper::init(dataPath.toStdWString())) { return false; } } else { @@ -341,7 +342,7 @@ int main(int argc, char *argv[]) instanceID = instanceFile.readAll().trimmed(); } - QString dataPath = + QString const dataPath = instanceID.isEmpty() ? application.applicationDirPath() : QDir::fromNativeSeparators( QStandardPaths::writableLocation(QStandardPaths::DataLocation) @@ -373,7 +374,7 @@ int main(int argc, char *argv[]) QSplashScreen splash(pixmap); try { - if (!bootstrap()) { // requires gameinfo to be initialised! + if (!bootstrap()) { return -1; } -- cgit v1.3.1 From f339cc8431c0a7b6a4d514599e6fa57a75eb6495 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Fri, 20 Nov 2015 19:34:09 +0000 Subject: Member variable unused so removed it. Leaves one asking *why* the datapath can be inside the game directory. --- src/main.cpp | 2 +- src/shared/fallout3info.cpp | 4 ++-- src/shared/fallout3info.h | 2 +- src/shared/falloutnvinfo.cpp | 4 ++-- src/shared/falloutnvinfo.h | 2 +- src/shared/gameinfo.cpp | 20 ++++++++++---------- src/shared/gameinfo.h | 7 +++---- src/shared/oblivioninfo.cpp | 4 ++-- src/shared/oblivioninfo.h | 2 +- src/shared/skyriminfo.cpp | 4 ++-- src/shared/skyriminfo.h | 2 +- 11 files changed, 26 insertions(+), 27 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index ff34145d..4f79b0b2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -446,7 +446,7 @@ int main(int argc, char *argv[]) QString gamePath = QString::fromUtf8(settings.value("gamePath", "").toByteArray()); bool done = false; while (!done) { - if (!GameInfo::init(ToWString(application.applicationDirPath()), ToWString(dataPath), ToWString(QDir::toNativeSeparators(gamePath)))) { + 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)); diff --git a/src/shared/fallout3info.cpp b/src/shared/fallout3info.cpp index 055d3b38..9c6ad5b9 100644 --- a/src/shared/fallout3info.cpp +++ b/src/shared/fallout3info.cpp @@ -30,8 +30,8 @@ along with Mod Organizer. If not, see . namespace MOShared { -Fallout3Info::Fallout3Info(const std::wstring &moDataDirectory, const std::wstring &gameDirectory) - : GameInfo(moDataDirectory, gameDirectory) +Fallout3Info::Fallout3Info(const std::wstring &gameDirectory) + : GameInfo(gameDirectory) { identifyMyGamesDirectory(L"fallout3"); } diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index d019ee07..51abe073 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -69,7 +69,7 @@ public: private: - Fallout3Info(const std::wstring &moDataDirectory, const std::wstring &gameDirectory); + Fallout3Info(const std::wstring &gameDirectory); static bool identifyGame(const std::wstring &searchPath); diff --git a/src/shared/falloutnvinfo.cpp b/src/shared/falloutnvinfo.cpp index 2ddbf055..4601caf5 100644 --- a/src/shared/falloutnvinfo.cpp +++ b/src/shared/falloutnvinfo.cpp @@ -31,8 +31,8 @@ along with Mod Organizer. If not, see . namespace MOShared { -FalloutNVInfo::FalloutNVInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory) - : GameInfo(moDataDirectory, gameDirectory) +FalloutNVInfo::FalloutNVInfo(const std::wstring &gameDirectory) + : GameInfo(gameDirectory) { identifyMyGamesDirectory(L"falloutnv"); } diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index 9a9004ec..59b52323 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -102,7 +102,7 @@ public: private: - FalloutNVInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory); + FalloutNVInfo(const std::wstring &gameDirectory); static bool identifyGame(const std::wstring &searchPath); }; diff --git a/src/shared/gameinfo.cpp b/src/shared/gameinfo.cpp index e5e47cdf..703f4a40 100644 --- a/src/shared/gameinfo.cpp +++ b/src/shared/gameinfo.cpp @@ -40,8 +40,8 @@ namespace MOShared { GameInfo* GameInfo::s_Instance = nullptr; -GameInfo::GameInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory) - : m_GameDirectory(gameDirectory), m_OrganizerDataDirectory(moDataDirectory) +GameInfo::GameInfo(const std::wstring &gameDirectory) + : m_GameDirectory(gameDirectory) { atexit(&cleanup); } @@ -87,36 +87,36 @@ void GameInfo::identifyMyGamesDirectory(const std::wstring &file) } -bool GameInfo::identifyGame(const std::wstring &moDataDirectory, const std::wstring &searchPath) +bool GameInfo::identifyGame(const std::wstring &searchPath) { if (OblivionInfo::identifyGame(searchPath)) { - s_Instance = new OblivionInfo(moDataDirectory, searchPath); + s_Instance = new OblivionInfo(searchPath); } else if (Fallout3Info::identifyGame(searchPath)) { - s_Instance = new Fallout3Info(moDataDirectory, searchPath); + s_Instance = new Fallout3Info(searchPath); } else if (FalloutNVInfo::identifyGame(searchPath)) { - s_Instance = new FalloutNVInfo(moDataDirectory, searchPath); + s_Instance = new FalloutNVInfo(searchPath); } else if (SkyrimInfo::identifyGame(searchPath)) { - s_Instance = new SkyrimInfo(moDataDirectory, searchPath); + s_Instance = new SkyrimInfo(searchPath); } return s_Instance != nullptr; } -bool GameInfo::init(const std::wstring &moDirectory, const std::wstring &moDataDirectory, const std::wstring &gamePath) +bool GameInfo::init(const std::wstring &moDirectory, const std::wstring &gamePath) { if (s_Instance == nullptr) { if (gamePath.length() == 0) { // search upward in the directory until a recognized game-binary is found std::wstring searchPath(moDirectory); - while (!identifyGame(moDataDirectory, searchPath)) { + while (!identifyGame(searchPath)) { size_t lastSep = searchPath.find_last_of(L"/\\"); if (lastSep == std::string::npos) { return false; } searchPath.erase(lastSep); } - } else if (!identifyGame(moDataDirectory, gamePath)) { + } else if (!identifyGame(gamePath)) { return false; } } diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index 1d4b050b..47a5e767 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -100,14 +100,14 @@ public: //**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 &moDataDirectory, const std::wstring &gamePath = L""); + static bool init(const std::wstring &moDirectory, const std::wstring &gamePath = L""); //**USED IN HOOKDLL static GameInfo& instance(); protected: - GameInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory); + GameInfo(const std::wstring &gameDirectory); std::wstring getLocalAppFolder() const; const std::wstring &getMyGamesDirectory() const { return m_MyGamesDirectory; } @@ -115,7 +115,7 @@ protected: private: - static bool identifyGame(const std::wstring &moDataDirectory, const std::wstring &searchPath); + static bool identifyGame(const std::wstring &searchPath); std::wstring getSpecialPath(LPCWSTR name) const; static void cleanup(); @@ -127,7 +127,6 @@ private: std::wstring m_MyGamesDirectory; std::wstring m_GameDirectory; - std::wstring m_OrganizerDataDirectory; }; diff --git a/src/shared/oblivioninfo.cpp b/src/shared/oblivioninfo.cpp index a5760570..4b0a8499 100644 --- a/src/shared/oblivioninfo.cpp +++ b/src/shared/oblivioninfo.cpp @@ -31,8 +31,8 @@ along with Mod Organizer. If not, see . namespace MOShared { -OblivionInfo::OblivionInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory) - : GameInfo(moDataDirectory, gameDirectory) +OblivionInfo::OblivionInfo(const std::wstring &gameDirectory) + : GameInfo(gameDirectory) { identifyMyGamesDirectory(L"oblivion"); } diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index 0a6c416c..ac10b80a 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -100,7 +100,7 @@ public: private: - OblivionInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory); + OblivionInfo(const std::wstring &gameDirectory); static bool identifyGame(const std::wstring &searchPath); diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp index e122390d..bd901357 100644 --- a/src/shared/skyriminfo.cpp +++ b/src/shared/skyriminfo.cpp @@ -33,8 +33,8 @@ along with Mod Organizer. If not, see . namespace MOShared { -SkyrimInfo::SkyrimInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory) - : GameInfo(moDataDirectory, gameDirectory) +SkyrimInfo::SkyrimInfo(const std::wstring &gameDirectory) + : GameInfo(gameDirectory) { identifyMyGamesDirectory(L"skyrim"); diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index f52be73a..65977a69 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -68,7 +68,7 @@ public: private: - SkyrimInfo(const std::wstring &moDataDirectory, const std::wstring &gameDirectory); + SkyrimInfo(const std::wstring &gameDirectory); static bool identifyGame(const std::wstring &searchPath); -- cgit v1.3.1 From 38c5899fef2f21561a00bd5b1df3eff8577ec986 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Wed, 25 Nov 2015 19:31:05 +0000 Subject: Replace GameInfo::getNexusInfoUrl with IPluginGame::getNexusManagementUrl also added getNexusDisplayUrl for the other variant of getNexusPage Removed skyrim static versions note that Nexusinterface is now passed a game plugin rather than a URL and a game ID if you want to override the current game --- src/main.cpp | 33 ++++++----- src/mainwindow.cpp | 3 +- src/nexusinterface.cpp | 81 +++++++++++++------------- src/nexusinterface.h | 133 +++++++++++++++++++++++++++++++++++-------- src/organizercore.cpp | 26 +++++++-- src/organizercore.h | 3 +- src/selfupdater.cpp | 40 +++++++------ src/selfupdater.h | 5 ++ src/shared/fallout3info.cpp | 5 -- src/shared/fallout3info.h | 2 - src/shared/falloutnvinfo.cpp | 6 -- src/shared/falloutnvinfo.h | 2 - src/shared/gameinfo.h | 2 - src/shared/oblivioninfo.cpp | 6 -- src/shared/oblivioninfo.h | 2 - src/shared/skyriminfo.cpp | 11 ---- src/shared/skyriminfo.h | 3 - 17 files changed, 222 insertions(+), 141 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 4f79b0b2..72a63dc6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -498,24 +498,27 @@ int main(int argc, char *argv[]) return 1; } - IPluginGame *game = organizer.managedGame(); - - 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()); + //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()); + } } } + game->setGameVariant(settings.value("game_edition").toString()); } - game->setGameVariant(settings.value("game_edition").toString()); #pragma message("edition isn't used?") diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 05650219..f3ffdf6c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3814,8 +3814,9 @@ void MainWindow::on_actionEndorseMO_triggered() if (QMessageBox::question(this, tr("Endorse Mod Organizer"), tr("Do you want to endorse Mod Organizer on %1 now?").arg(ToQString(GameInfo::instance().getNexusPage())), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + //Why pass an empty variant of we're toggling an endorsement? NexusInterface::instance()->requestToggleEndorsement( - m_OrganizerCore.managedGame()->getNexusModOrganizerID(), true, this, QVariant(), QString()); + m_OrganizerCore.managedGame()->getNexusModOrganizerID(), true, this, QVariant(), ""); } } diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index dc027be4..cbb9ad48 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -18,14 +18,18 @@ along with Mod Organizer. If not, see . */ #include "nexusinterface.h" + +#include "iplugingame.h" #include "nxmaccessmanager.h" #include "json.h" #include "selectiondialog.h" -#include #include -#include #include +#include + +#include + using namespace MOBase; using namespace MOShared; @@ -33,34 +37,34 @@ using namespace MOShared; NexusBridge::NexusBridge(const QString &subModule) : m_Interface(NexusInterface::instance()) - , m_Url() // lazy initialized + , m_Url() //Lazily initialised (but redundant) , m_SubModule(subModule) { } void NexusBridge::requestDescription(int modID, QVariant userData) { - m_RequestIDs.insert(m_Interface->requestDescription(modID, this, userData, m_SubModule, url())); + m_RequestIDs.insert(m_Interface->requestDescription(modID, this, userData, m_SubModule)); } void NexusBridge::requestFiles(int modID, QVariant userData) { - m_RequestIDs.insert(m_Interface->requestFiles(modID, this, userData, m_SubModule, url())); + m_RequestIDs.insert(m_Interface->requestFiles(modID, this, userData, m_SubModule)); } void NexusBridge::requestFileInfo(int modID, int fileID, QVariant userData) { - m_RequestIDs.insert(m_Interface->requestFileInfo(modID, fileID, this, userData, m_SubModule, url())); + m_RequestIDs.insert(m_Interface->requestFileInfo(modID, fileID, this, userData, m_SubModule)); } void NexusBridge::requestDownloadURL(int modID, int fileID, QVariant userData) { - m_RequestIDs.insert(m_Interface->requestDownloadURL(modID, fileID, this, userData, m_SubModule, url())); + m_RequestIDs.insert(m_Interface->requestDownloadURL(modID, fileID, this, userData, m_SubModule)); } void NexusBridge::requestToggleEndorsement(int modID, bool endorse, QVariant userData) { - m_RequestIDs.insert(m_Interface->requestToggleEndorsement(modID, endorse, this, userData, m_SubModule, url())); + m_RequestIDs.insert(m_Interface->requestToggleEndorsement(modID, endorse, this, userData, m_SubModule)); } void NexusBridge::nxmDescriptionAvailable(int modID, QVariant userData, QVariant resultData, int requestID) @@ -136,13 +140,6 @@ void NexusBridge::nxmRequestFailed(int modID, int fileID, QVariant userData, int } } -QString NexusBridge::url() { - if (m_Url.isEmpty()) { - m_Url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl()); - } - return m_Url; -} - QAtomicInt NexusInterface::NXMRequestInfo::s_NextID(0); @@ -246,10 +243,9 @@ void NexusInterface::interpretNexusFileName(const QString &fileName, QString &mo int NexusInterface::requestDescription(int modID, QObject *receiver, QVariant userData, - const QString &subModule, const QString &url, int nexusGameId) + const QString &subModule, MOBase::IPluginGame const *game) { - NXMRequestInfo requestInfo(modID, NXMRequestInfo::TYPE_DESCRIPTION, userData, subModule, url, - nexusGameId == -1 ? GameInfo::instance().getNexusGameID() : nexusGameId); + NXMRequestInfo requestInfo(modID, NXMRequestInfo::TYPE_DESCRIPTION, userData, subModule, game); m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmDescriptionAvailable(int,QVariant,QVariant,int)), @@ -264,9 +260,9 @@ int NexusInterface::requestDescription(int modID, QObject *receiver, QVariant us int NexusInterface::requestUpdates(const std::vector &modIDs, QObject *receiver, QVariant userData, - const QString &subModule, const QString &url) + const QString &subModule, MOBase::IPluginGame const *game) { - NXMRequestInfo requestInfo(modIDs, NXMRequestInfo::TYPE_GETUPDATES, userData, subModule, url, GameInfo::instance().getNexusGameID()); + NXMRequestInfo requestInfo(modIDs, NXMRequestInfo::TYPE_GETUPDATES, userData, subModule, game); m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmUpdatesAvailable(std::vector,QVariant,QVariant,int)), @@ -300,9 +296,9 @@ void NexusInterface::fakeFiles() int NexusInterface::requestFiles(int modID, QObject *receiver, QVariant userData, - const QString &subModule, const QString &url) + const QString &subModule, MOBase::IPluginGame const *game) { - NXMRequestInfo requestInfo(modID, NXMRequestInfo::TYPE_FILES, userData, subModule, url, GameInfo::instance().getNexusGameID()); + NXMRequestInfo requestInfo(modID, NXMRequestInfo::TYPE_FILES, userData, subModule, game); m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmFilesAvailable(int,QVariant,QVariant,int)), receiver, SLOT(nxmFilesAvailable(int,QVariant,QVariant,int)), Qt::UniqueConnection); @@ -320,9 +316,9 @@ int NexusInterface::requestFiles(int modID, QObject *receiver, QVariant userData int NexusInterface::requestFileInfo(int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url) + MOBase::IPluginGame const *game) { - NXMRequestInfo requestInfo(modID, fileID, NXMRequestInfo::TYPE_FILEINFO, userData, subModule, url, GameInfo::instance().getNexusGameID()); + NXMRequestInfo requestInfo(modID, fileID, NXMRequestInfo::TYPE_FILEINFO, userData, subModule, game); m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmFileInfoAvailable(int,int,QVariant,QVariant,int)), @@ -337,9 +333,9 @@ int NexusInterface::requestFileInfo(int modID, int fileID, QObject *receiver, QV int NexusInterface::requestDownloadURL(int modID, int fileID, QObject *receiver, QVariant userData, - const QString &subModule, const QString &url) + const QString &subModule, MOBase::IPluginGame const *game) { - NXMRequestInfo requestInfo(modID, fileID, NXMRequestInfo::TYPE_DOWNLOADURL, userData, subModule, url, GameInfo::instance().getNexusGameID()); + NXMRequestInfo requestInfo(modID, fileID, NXMRequestInfo::TYPE_DOWNLOADURL, userData, subModule, game); m_RequestQueue.enqueue(requestInfo); connect(this, SIGNAL(nxmDownloadURLsAvailable(int,int,QVariant,QVariant,int)), @@ -354,9 +350,9 @@ int NexusInterface::requestDownloadURL(int modID, int fileID, QObject *receiver, int NexusInterface::requestToggleEndorsement(int modID, bool endorse, QObject *receiver, QVariant userData, - const QString &subModule, const QString &url) + const QString &subModule, MOBase::IPluginGame const *game) { - NXMRequestInfo requestInfo(modID, NXMRequestInfo::TYPE_TOGGLEENDORSEMENT, userData, subModule, url, GameInfo::instance().getNexusGameID()); + NXMRequestInfo requestInfo(modID, NXMRequestInfo::TYPE_TOGGLEENDORSEMENT, userData, subModule, game); requestInfo.m_Endorse = endorse; m_RequestQueue.enqueue(requestInfo); @@ -557,13 +553,18 @@ void NexusInterface::requestTimeout() } } +void NexusInterface::managedGameChanged(IPluginGame const *game) +{ + m_Game = game; +} + NexusInterface::NXMRequestInfo::NXMRequestInfo(int modID , NexusInterface::NXMRequestInfo::Type type , QVariant userData , const QString &subModule - , const QString &url - , int nexusGameId) + , MOBase::IPluginGame const *game + ) : m_ModID(modID) , m_FileID(0) , m_Reply(nullptr) @@ -572,9 +573,9 @@ NexusInterface::NXMRequestInfo::NXMRequestInfo(int modID , m_Timeout(nullptr) , m_Reroute(false) , m_ID(s_NextID.fetchAndAddAcquire(1)) - , m_URL(url) + , m_URL(game->getNexusManagementURL()) , m_SubModule(subModule) - , m_NexusGameID(nexusGameId) + , m_NexusGameID(game->getNexusGameID()) , m_Endorse(false) {} @@ -582,8 +583,8 @@ NexusInterface::NXMRequestInfo::NXMRequestInfo(std::vector modIDList , NexusInterface::NXMRequestInfo::Type type , QVariant userData , const QString &subModule - , const QString &url - , int nexusGameId) + , MOBase::IPluginGame const *game + ) : m_ModID(-1) , m_ModIDList(modIDList) , m_FileID(0) @@ -593,9 +594,9 @@ NexusInterface::NXMRequestInfo::NXMRequestInfo(std::vector modIDList , m_Timeout(nullptr) , m_Reroute(false) , m_ID(s_NextID.fetchAndAddAcquire(1)) - , m_URL(url) + , m_URL(game->getNexusManagementURL()) , m_SubModule(subModule) - , m_NexusGameID(nexusGameId) + , m_NexusGameID(game->getNexusGameID()) , m_Endorse(false) {} @@ -604,8 +605,8 @@ NexusInterface::NXMRequestInfo::NXMRequestInfo(int modID , NexusInterface::NXMRequestInfo::Type type , QVariant userData , const QString &subModule - , const QString &url - , int nexusGameId) + , MOBase::IPluginGame const *game + ) : m_ModID(modID) , m_FileID(fileID) , m_Reply(nullptr) @@ -614,8 +615,8 @@ NexusInterface::NXMRequestInfo::NXMRequestInfo(int modID , m_Timeout(nullptr) , m_Reroute(false) , m_ID(s_NextID.fetchAndAddAcquire(1)) - , m_URL(url) + , m_URL(game->getNexusManagementURL()) , m_SubModule(subModule) - , m_NexusGameID(nexusGameId) + , m_NexusGameID(game->getNexusGameID()) , m_Endorse(false) {} diff --git a/src/nexusinterface.h b/src/nexusinterface.h index c0ee50cd..9f129510 100644 --- a/src/nexusinterface.h +++ b/src/nexusinterface.h @@ -20,20 +20,21 @@ along with Mod Organizer. If not, see . #ifndef NEXUSINTERFACE_H #define NEXUSINTERFACE_H - - #include #include #include #include + #include #include #include #include #include + #include #include +namespace MOBase { class IPluginGame; } class NexusInterface; class NXMAccessManager; @@ -106,10 +107,6 @@ public slots: void nxmEndorsementToggled(int modID, QVariant userData, QVariant resultData, int requestID); void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorMessage); -private: - - QString url(); - private: NexusInterface *m_Interface; @@ -147,29 +144,67 @@ public: */ void cleanup(); + /** + * @brief request description for a mod + * + * @param modID id of the mod caller is interested in (assumed to be for the current game) + * @param receiver the object to receive the result asynchronously via a signal (nxmDescriptionAvailable) + * @param userData user data to be returned with the result + * @return int an id to identify the request + **/ + int requestDescription(int modID, QObject *receiver, QVariant userData, const QString &subModule) + { + return requestDescription(modID, receiver, userData, subModule, m_Game); + } + /** * @brief request description for a mod * * @param modID id of the mod caller is interested in * @param receiver the object to receive the result asynchronously via a signal (nxmDescriptionAvailable) * @param userData user data to be returned with the result - * @param url the url to request from + * @param game Game with which the mod is associated * @return int an id to identify the request **/ int requestDescription(int modID, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl()), - int nexusGameId = -1); + MOBase::IPluginGame const *game); + + /** + * @brief request nexus descriptions for multiple mods at once + * @param modIDs a list of ids of mods the caller is interested in (assumed to be for the current game) + * @param receiver the object to receive the result asynchronously via a signal (nxmDescriptionAvailable) + * @param userData user data to be returned with the result + * @return int an id to identify the request + */ + int requestUpdates(const std::vector &modIDs, QObject *receiver, QVariant userData, const QString &subModule) + { + return requestUpdates(modIDs, receiver, userData, subModule, m_Game); + } /** * @brief request nexus descriptions for multiple mods at once * @param modIDs a list of ids of mods the caller is interested in * @param receiver the object to receive the result asynchronously via a signal (nxmDescriptionAvailable) * @param userData user data to be returned with the result - * @param url the url to request from + * @param game the game with which the mods are associated * @return int an id to identify the request */ int requestUpdates(const std::vector &modIDs, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl())); + MOBase::IPluginGame const *game); + + /** + * @brief request a list of the files belonging to a mod + * + * @param modID id of the mod caller is interested in (assumed to be for the current game) + * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) + * @param userData user data to be returned with the result + * @return int an id to identify the request + **/ + int requestFiles(int modID, QObject *receiver, QVariant userData, const QString &subModule) + { + return requestFiles(modID, receiver, userData, subModule, m_Game); + } + /** * @brief request a list of the files belonging to a mod @@ -177,24 +212,52 @@ public: * @param modID id of the mod caller is interested in * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) * @param userData user data to be returned with the result - * @param url the url to request from + * @param game the game with which the mods are associated * @return int an id to identify the request **/ int requestFiles(int modID, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl())); + MOBase::IPluginGame const *game); /** * @brief request info about a single file of a mod * - * @param modID id of the mod caller is interested in + * @param modID id of the mod caller is interested in (assumed to be for the current game) * @param fileID id of the file the caller is interested in * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) * @param userData user data to be returned with the result - * @param url the url to request from + * @return int an id to identify the request + **/ + int requestFileInfo(int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule) + { + return requestFileInfo(modID, fileID, receiver, userData, subModule, m_Game); + } + + /** + * @brief request info about a single file of a mod + * + * @param modID id of the mod caller is interested in (assumed to be for the current game) + * @param fileID id of the file the caller is interested in + * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) + * @param userData user data to be returned with the result + * @param game the game with which the mods are associated * @return int an id to identify the request **/ int requestFileInfo(int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl())); + MOBase::IPluginGame const *game); + + /** + * @brief request the download url of a file + * + * @param modID id of the mod caller is interested in (assumed to be for the current game) + * @param fileID id of the file the caller is interested in + * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) + * @param userData user data to be returned with the result + * @return int an id to identify the request + **/ + int requestDownloadURL(int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule) + { + return requestDownloadURL(modID, fileID, receiver, userData, subModule, m_Game); + } /** * @brief request the download url of a file @@ -203,11 +266,23 @@ public: * @param fileID id of the file the caller is interested in * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) * @param userData user data to be returned with the result - * @param url the url to request from + * @param game the game with which the mods are associated * @return int an id to identify the request **/ - int requestDownloadURL(int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl())); + int requestDownloadURL(int modID, int fileID, QObject *receiver, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); + + /** + * @brief toggle endorsement state of the mod + * @param modID id of the mod (assumed to be for the current game) + * @param endorse true if the mod should be endorsed, false for un-endorse + * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) + * @param userData user data to be returned with the result + * @return int an id to identify the request + */ + int requestToggleEndorsement(int modID, bool endorse, QObject *receiver, QVariant userData, const QString &subModule) + { + return requestToggleEndorsement(modID, endorse, receiver, userData, subModule, m_Game); + } /** * @brief toggle endorsement state of the mod @@ -215,11 +290,11 @@ public: * @param endorse true if the mod should be endorsed, false for un-endorse * @param receiver the object to receive the result asynchronously via a signal (nxmFilesAvailable) * @param userData user data to be returned with the result - * @param url the url to request from + * @param game the game with which the mods are associated * @return int an id to identify the request */ int requestToggleEndorsement(int modID, bool endorse, QObject *receiver, QVariant userData, const QString &subModule, - const QString &url = MOBase::ToQString(MOShared::GameInfo::instance().getNexusInfoUrl())); + MOBase::IPluginGame const *game); /** * @param directory the directory to store cache files @@ -247,6 +322,11 @@ public: */ static void interpretNexusFileName(const QString &fileName, QString &modName, int &modID, bool query); + /** + * @brief get the currently managed game + */ + MOBase::IPluginGame const *managedGame() const; + signals: void requestNXMDownload(const QString &url); @@ -261,6 +341,9 @@ signals: void nxmEndorsementToggled(int modID, QVariant userData, QVariant resultData, int requestID); void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorString); +public slots: + void managedGameChanged(MOBase::IPluginGame const *game); + private slots: void requestFinished(); @@ -295,9 +378,9 @@ private: int m_ID; int m_Endorse; - NXMRequestInfo(int modID, Type type, QVariant userData, const QString &subModule, const QString &url, int nexusGameId); - NXMRequestInfo(std::vector modIDList, Type type, QVariant userData, const QString &subModule, const QString &url, int nexusGameId); - NXMRequestInfo(int modID, int fileID, Type type, QVariant userData, const QString &subModule, const QString &url, int nexusGameId); + NXMRequestInfo(int modID, Type type, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); + NXMRequestInfo(std::vector modIDList, Type type, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); + NXMRequestInfo(int modID, int fileID, Type type, QVariant userData, const QString &subModule, MOBase::IPluginGame const *game); private: static QAtomicInt s_NextID; @@ -324,6 +407,8 @@ private: MOBase::VersionInfo m_MOVersion; QString m_NMMVersion; + MOBase::IPluginGame const *m_Game; + }; #endif // NEXUSINTERFACE_H diff --git a/src/organizercore.cpp b/src/organizercore.cpp index c3e10d37..7473ec3e 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1,5 +1,6 @@ #include "organizercore.h" +#include "iplugingame.h" #include "mainwindow.h" #include "messagedialog.h" #include "logbuffer.h" @@ -19,11 +20,14 @@ #include #include #include + #include #include #include #include + #include + #include @@ -158,9 +162,10 @@ OrganizerCore::OrganizerCore(const QSettings &initSettings) connect(NexusInterface::instance()->getAccessManager(), SIGNAL(loginSuccessful(bool)), this, SLOT(loginSuccessful(bool))); connect(NexusInterface::instance()->getAccessManager(), SIGNAL(loginFailed(QString)), this, SLOT(loginFailed(QString))); - connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame*)), &m_Settings, SLOT(managedGameChanged(MOBase::IPluginGame*))); - connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame*)), &m_DownloadManager, SLOT(managedGameChanged(MOBase::IPluginGame*))); - connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame*)), &m_PluginList, SLOT(managedGameChanged(MOBase::IPluginGame*))); + connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame const *)), &m_Settings, SLOT(managedGameChanged(MOBase::IPluginGame const *))); + connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame const *)), &m_DownloadManager, SLOT(managedGameChanged(MOBase::IPluginGame const *))); + connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame const *)), &m_PluginList, SLOT(managedGameChanged(MOBase::IPluginGame const *))); + connect(this, SIGNAL(managedGameChanged(MOBase::IPluginGame const *)), NexusInterface::instance(), SLOT(managedGameChanged(MOBase::IPluginGame const *))); connect(&m_PluginList, &PluginList::writePluginsList, &m_PluginListsWriter, &DelayedFileWriterBase::write); @@ -393,6 +398,14 @@ void OrganizerCore::connectPlugins(PluginContainer *container) m_GamePlugin = m_PluginContainer->managedGame(m_GameName); emit managedGameChanged(m_GamePlugin); } + //Do this the hard way + for (const IPluginGame * const game : container->plugins()) { + QString n = game->getNexusName(); + if (game->getNexusName() == "Skyrim") { + m_Updater.setNexusDownload(game); + break; + } + } } void OrganizerCore::disconnectPlugins() @@ -1308,7 +1321,12 @@ PluginListSortProxy *OrganizerCore::createPluginListProxyModel() return result; } -IPluginGame *OrganizerCore::managedGame() const +IPluginGame const *OrganizerCore::managedGame() const +{ + return m_GamePlugin; +} + +IPluginGame *OrganizerCore::managedGameForUpdate() const { return m_GamePlugin; } diff --git a/src/organizercore.h b/src/organizercore.h index a673065a..c206e5e7 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -99,7 +99,8 @@ public: ModListSortProxy *createModListProxyModel(); PluginListSortProxy *createPluginListProxyModel(); - MOBase::IPluginGame *managedGame() const; + MOBase::IPluginGame const *managedGame() const; + MOBase::IPluginGame *managedGameForUpdate() const; bool isArchivesInit() const { return m_ArchivesInit; } diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 7e42f322..8fb204d8 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -18,16 +18,18 @@ along with Mod Organizer. If not, see . */ #include "selfupdater.h" + #include "utility.h" #include "installationmanager.h" +#include "iplugingame.h" #include "messagedialog.h" #include "downloadmanager.h" #include "nexusinterface.h" #include "nxmaccessmanager.h" #include -#include -#include #include +#include + #include #include #include @@ -35,7 +37,6 @@ along with Mod Organizer. If not, see . #include #include #include -#include #include @@ -62,6 +63,7 @@ SelfUpdater::SelfUpdater(NexusInterface *nexusInterface) , m_UpdateRequestID(-1) , m_Reply(nullptr) , m_Attempts(3) + , m_NexusDownload(nullptr) { QLibrary archiveLib("dlls\\archive.dll"); if (!archiveLib.load()) { @@ -101,12 +103,10 @@ void SelfUpdater::testForUpdate() emit updateAvailable(); return; } - - if (m_UpdateRequestID == -1) { + if (m_UpdateRequestID == -1 && m_NexusDownload != nullptr) { m_UpdateRequestID = m_Interface->requestDescription( - SkyrimInfo::getNexusModIDStatic(), this, QVariant(), - QString(), ToQString(SkyrimInfo::getNexusInfoUrlStatic()), - SkyrimInfo::getNexusGameIDStatic()); + m_NexusDownload->getNexusModOrganizerID(), this, QVariant(), + QString(), m_NexusDownload); } } @@ -123,9 +123,9 @@ void SelfUpdater::startUpdate() if (QMessageBox::question(m_Parent, tr("Update"), tr("An update is available (newest version: %1), do you want to install it?").arg(m_NewestVersion), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - m_UpdateRequestID = m_Interface->requestFiles(SkyrimInfo::getNexusModIDStatic(), - this, m_NewestVersion, - ToQString(SkyrimInfo::getNexusInfoUrlStatic())); + m_UpdateRequestID = m_Interface->requestFiles(m_NexusDownload->getNexusModOrganizerID(), + this, m_NewestVersion, "", + m_NexusDownload); } } } @@ -434,18 +434,18 @@ void SelfUpdater::nxmFilesAvailable(int, QVariant userData, QVariant resultData, if (updateFileID != -1) { qDebug("update available: %d", updateFileID); - m_UpdateRequestID = m_Interface->requestDownloadURL(SkyrimInfo::getNexusModIDStatic(), - updateFileID, this, updateFileName, - ToQString(SkyrimInfo::getNexusInfoUrlStatic())); + m_UpdateRequestID = m_Interface->requestDownloadURL(m_NexusDownload->getNexusModOrganizerID(), + updateFileID, this, updateFileName, "", + m_NexusDownload); } else if (mainFileID != -1) { qDebug("full download required: %d", mainFileID); if (QMessageBox::question(m_Parent, tr("Update"), tr("No incremental update available for this version, " "the complete package needs to be downloaded (%1 kB)").arg(mainFileSize), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) { - m_UpdateRequestID = m_Interface->requestDownloadURL(SkyrimInfo::getNexusModIDStatic(), - mainFileID, this, mainFileName, - ToQString(SkyrimInfo::getNexusInfoUrlStatic())); + m_UpdateRequestID = m_Interface->requestDownloadURL(m_NexusDownload->getNexusModOrganizerID(), + mainFileID, this, mainFileName, "", + m_NexusDownload); } } else { qCritical("no file for update found"); @@ -489,3 +489,9 @@ void SelfUpdater::nxmDownloadURLsAvailable(int, int, QVariant userData, QVariant } } } + +/** Set the game check for updates */ +void SelfUpdater::setNexusDownload(MOBase::IPluginGame const *game) +{ + m_NexusDownload = game; +} diff --git a/src/selfupdater.h b/src/selfupdater.h index 143b05cb..4fdc3d7d 100644 --- a/src/selfupdater.h +++ b/src/selfupdater.h @@ -29,6 +29,7 @@ along with Mod Organizer. If not, see . #include #include +namespace MOBase { class IPluginGame; } class NexusInterface; @@ -83,6 +84,9 @@ public: **/ MOBase::VersionInfo getVersion() const { return m_MOVersion; } + /** Set the game check for updates */ + void setNexusDownload(MOBase::IPluginGame const *game); + public slots: /** @@ -146,6 +150,7 @@ private: Archive *m_CurrentArchive; + MOBase::IPluginGame const *m_NexusDownload; }; diff --git a/src/shared/fallout3info.cpp b/src/shared/fallout3info.cpp index 67dc85e0..cb2a3adf 100644 --- a/src/shared/fallout3info.cpp +++ b/src/shared/fallout3info.cpp @@ -87,11 +87,6 @@ std::wstring Fallout3Info::getNexusPage(bool nmmScheme) } } -std::wstring Fallout3Info::getNexusInfoUrlStatic() -{ - return L"http://nmm.nexusmods.com/fallout3"; -} - bool Fallout3Info::rerouteToProfile(const wchar_t *fileName, const wchar_t*) { static LPCWSTR profileFiles[] = { L"fallout.ini", L"falloutprefs.ini", L"plugins.txt", nullptr }; diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index 3688bc2e..b5585eaf 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -50,8 +50,6 @@ public: virtual std::wstring getReferenceDataFile(); virtual std::wstring getNexusPage(bool nmmScheme = true); - static std::wstring getNexusInfoUrlStatic(); - virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); } virtual int getNexusGameID() { return 120; } virtual bool rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath); diff --git a/src/shared/falloutnvinfo.cpp b/src/shared/falloutnvinfo.cpp index c1eea4da..bfc31c0b 100644 --- a/src/shared/falloutnvinfo.cpp +++ b/src/shared/falloutnvinfo.cpp @@ -88,12 +88,6 @@ std::wstring FalloutNVInfo::getNexusPage(bool nmmScheme) } -std::wstring FalloutNVInfo::getNexusInfoUrlStatic() -{ - return L"http://nmm.nexusmods.com/newvegas"; -} - - bool FalloutNVInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t*) { static LPCWSTR profileFiles[] = { L"fallout.ini", L"falloutprefs.ini", L"plugins.txt", nullptr }; diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index 024ad9aa..40e11720 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -50,8 +50,6 @@ public: virtual std::wstring getReferenceDataFile(); virtual std::wstring getNexusPage(bool nmmScheme = true); - static std::wstring getNexusInfoUrlStatic(); - virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); } virtual int getNexusGameID() { return 130; } virtual bool rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath); diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index 49b3133b..45069165 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -79,9 +79,7 @@ public: virtual std::wstring getReferenceDataFile() = 0; virtual std::wstring getNexusPage(bool nmmScheme = true) = 0; - virtual std::wstring getNexusInfoUrl() = 0; virtual int getNexusGameID() = 0; - //**Still used: SkyrimInfo::getNexusModIDStatic //**USED ONLY IN HOOKDLL virtual bool rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath) = 0; diff --git a/src/shared/oblivioninfo.cpp b/src/shared/oblivioninfo.cpp index 4cd03ae8..9bd5f4b1 100644 --- a/src/shared/oblivioninfo.cpp +++ b/src/shared/oblivioninfo.cpp @@ -91,12 +91,6 @@ std::wstring OblivionInfo::getNexusPage(bool nmmScheme) } -std::wstring OblivionInfo::getNexusInfoUrlStatic() -{ - return L"http://nmm.nexusmods.com/oblivion"; -} - - bool OblivionInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t*) { static LPCWSTR profileFiles[] = { L"oblivion.ini", L"oblivionprefs.ini", L"plugins.txt", nullptr }; diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index b298ed0a..b6b3d867 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -48,8 +48,6 @@ public: virtual std::wstring getReferenceDataFile(); virtual std::wstring getNexusPage(bool nmmScheme = true); - static std::wstring getNexusInfoUrlStatic(); - virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); } virtual int getNexusGameID() { return 101; } virtual bool rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath); diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp index f7fba7ab..9b192902 100644 --- a/src/shared/skyriminfo.cpp +++ b/src/shared/skyriminfo.cpp @@ -99,17 +99,6 @@ std::wstring SkyrimInfo::getNexusPage(bool nmmScheme) } -std::wstring SkyrimInfo::getNexusInfoUrlStatic() -{ - return L"http://nmm.nexusmods.com/skyrim"; -} - - -int SkyrimInfo::getNexusModIDStatic() -{ - return 1334; -} - bool SkyrimInfo::rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath) { static LPCWSTR profileFiles[] = { L"skyrim.ini", L"skyrimprefs.ini", L"loadorder.txt", nullptr }; diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index 93e2a948..ee81ace3 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -51,9 +51,6 @@ public: virtual std::wstring getNexusPage(bool nmmScheme = true); - static std::wstring getNexusInfoUrlStatic(); - virtual std::wstring getNexusInfoUrl() { return getNexusInfoUrlStatic(); } - static int getNexusModIDStatic(); static int getNexusGameIDStatic() { return 110; } virtual int getNexusGameID() { return getNexusGameIDStatic(); } -- 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/main.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 9a88a190eb31c12aa391b1142461a09b1a32215d Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sun, 29 Nov 2015 12:55:49 +0000 Subject: Another cleanup and make the program not crash when looking at saves for the nonce --- src/main.cpp | 22 +++++++++++++--------- src/shared/gameinfo.h | 10 +++++----- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 78145a74..e9351c97 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,21 +26,16 @@ along with Mod Organizer. If not, see . #define WIN32_LEAN_AND_MEAN #include #include -#include + #include #include #include #include -#include #include "mainwindow.h" #include #include "modlist.h" #include "profile.h" #include "gameinfo.h" -#include "fallout3info.h" -#include "falloutnvinfo.h" -#include "oblivioninfo.h" -#include "skyriminfo.h" #include "spawn.h" #include "executableslist.h" #include "singleinstance.h" @@ -51,11 +46,9 @@ along with Mod Organizer. If not, see . #include "moapplication.h" #include "tutorialmanager.h" #include "nxmaccessmanager.h" -#include -#include #include #include -#include + #include #include #include @@ -77,6 +70,14 @@ along with Mod Organizer. If not, see . #include #include +#include + +#include + +#include +#include +#include + #pragma comment(linker, "/manifestDependency:\"name='dlls' processorArchitecture='x86' version='1.0.0.0' type='win32' \"") @@ -566,6 +567,9 @@ int main(int argc, char *argv[]) organizer.setManagedGame(game); + //*sigh just for making it work + GameInfo::init(application.applicationDirPath().toStdWString(), game->gameDirectory().absolutePath().toStdWString()); + organizer.createDefaultProfile(); //See the pragma - we apparently don't use this so not sure why we check it diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index 55161952..01d51f8a 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -51,6 +51,9 @@ public: virtual ~GameInfo() {} + //**USED IN HOOKDLL and savegame code + static GameInfo& instance(); + //**Used only in savegame which needs refactoring a lot. virtual GameInfo::Type getType() = 0; @@ -58,10 +61,10 @@ public: // get a list of file extensions for additional files belonging to a save game virtual std::vector getSavegameAttachmentExtensions() = 0; - //**USED IN HOOKDLL + //**USED ONLY IN HOOKDLL virtual std::wstring getGameDirectory() const; - //**USED IN HOOKDLL + //**USED ONLY 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""); @@ -79,9 +82,6 @@ public: //**USED ONLY IN HOOKDLL virtual bool rerouteToProfile(const wchar_t *fileName, const wchar_t *fullPath) = 0; - //**USED IN HOOKDLL and everywhere that uses GameInfo - static GameInfo& instance(); - protected: GameInfo(const std::wstring &gameDirectory); -- cgit v1.3.1 From c236078aa1d3b756aaabd2f2c1d28d7474de3c2d Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Sun, 29 Nov 2015 14:44:12 +0000 Subject: Fix up so that hookdll continues to work properly --- src/main.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index e9351c97..353e7202 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -334,9 +334,11 @@ QString determineProfile(QStringList &arguments, const QSettings &settings) MOBase::IPluginGame *selectGame(QSettings &settings, QDir const &gamePath, MOBase::IPluginGame *game) { settings.setValue("gameName", game->gameName()); - if (gamePath == game->gameDirectory()) { + //Sadly, hookdll needs gamePath in order to run. So following code block is + //commented out + /*if (gamePath == game->gameDirectory()) { settings.remove("gamePath"); - } else { + } else*/ { QString gameDir = gamePath.absolutePath(); game->setGamePath(gameDir); settings.setValue("gamePath", QDir::toNativeSeparators(gameDir).toUtf8().constData()); -- cgit v1.3.1