diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/installationmanager.cpp | 16 | ||||
| -rw-r--r-- | src/installationmanager.h | 20 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 4 | ||||
| -rw-r--r-- | src/organizercore.cpp | 50 | ||||
| -rw-r--r-- | src/organizercore.h | 2 | ||||
| -rw-r--r-- | src/organizerproxy.cpp | 2 |
6 files changed, 73 insertions, 21 deletions
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index e089d560..a755b0cb 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -868,3 +868,19 @@ QStringList InstallationManager::getSupportedExtensions() const { return QStringList(std::begin(m_SupportedExtensions), std::end(m_SupportedExtensions)); } + +void InstallationManager::notifyInstallationStart(QString const& archive, bool reinstallation, ModInfo::Ptr currentMod) +{ + for (auto* installer : m_Installers) { + installer->onInstallationStart(archive, reinstallation, currentMod.get()); + } +} + +void InstallationManager::notifyInstallationEnd( + MOBase::IPluginInstaller::EInstallResult result, + ModInfo::Ptr newMod) +{ + for (auto* installer : m_Installers) { + installer->onInstallationEnd(result, newMod.get()); + } +} diff --git a/src/installationmanager.h b/src/installationmanager.h index 63e8794e..149295a6 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -34,6 +34,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>. #include <map> #include <errorcodes.h> +#include "modinfo.h" + /** * @brief manages the installation of mod archives @@ -63,6 +65,24 @@ public: void setURL(const QString &url); /** + * @brief Notify all installer plugins that an installation is about to start. + * + * @param archive Path to the archive that is going to be installed. + * @param reinstallation True if this is a reinstallation, false otherwise. + * @param currentMod The installed mod corresponding to the archive being installed, or a null + * if there is no such mod. + */ + void notifyInstallationStart(QString const& archive, bool reinstallation, ModInfo::Ptr currentMod); + + /** + * @brief notify all installer plugins that an installation has ended. + * + * @param result The result of the installation process. + * @param currentMod The newly install mod, if result is SUCCESS, a null pointer otherwise. + */ + void notifyInstallationEnd(MOBase::IPluginInstaller::EInstallResult result, ModInfo::Ptr newMod); + + /** * @brief update the directory where mods are to be installed * @param modsDirectory the mod directory * @note this is called a lot, probably redundantly diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 34805518..fb71eca3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2319,7 +2319,7 @@ void MainWindow::installMod(QString fileName) if (fileName.isEmpty()) { return; } else { - m_OrganizerCore.installMod(fileName, QString()); + m_OrganizerCore.installMod(fileName, false, nullptr, QString()); } } catch (const std::exception &e) { reportError(e.what()); @@ -2808,7 +2808,7 @@ void MainWindow::reinstallMod_clicked() fullInstallationFile = m_OrganizerCore.downloadManager()->getOutputDirectory() + "/" + installationFile; } if (QFile::exists(fullInstallationFile)) { - m_OrganizerCore.installMod(fullInstallationFile, modInfo->name()); + m_OrganizerCore.installMod(fullInstallationFile, true, modInfo, modInfo->name()); } else { QMessageBox::information(this, tr("Failed"), tr("Installation file no longer exists")); } diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 815c80c2..d33b4e39 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -713,6 +713,8 @@ QString OrganizerCore::pluginDataPath() const } MOBase::IModInterface *OrganizerCore::installMod(const QString &fileName, + bool reinstallation, + ModInfo::Ptr currentMod, const QString &initModName) { if (m_CurrentProfile == nullptr) { @@ -733,7 +735,9 @@ MOBase::IModInterface *OrganizerCore::installMod(const QString &fileName, } m_CurrentProfile->writeModlistNow(); m_InstallationManager.setModsDirectory(m_Settings.paths().mods()); - if (m_InstallationManager.install(fileName, modName, hasIniTweaks) == IPluginInstaller::RESULT_SUCCESS) { + m_InstallationManager.notifyInstallationStart(fileName, reinstallation, currentMod); + auto result = m_InstallationManager.install(fileName, modName, hasIniTweaks); + if (result == IPluginInstaller::RESULT_SUCCESS) { MessageDialog::showMessage(tr("Installation successful"), qApp->activeWindow()); refreshModList(); @@ -758,18 +762,22 @@ MOBase::IModInterface *OrganizerCore::installMod(const QString &fileName, } m_ModInstalled(modName); m_DownloadManager.markInstalled(fileName); + m_InstallationManager.notifyInstallationEnd(result, modInfo); emit modInstalled(modName); return modInfo.data(); } else { reportError(tr("mod not found: %1").arg(qUtf8Printable(modName))); } - } else if (m_InstallationManager.wasCancelled()) { - QMessageBox::information(qApp->activeWindow(), tr("Extraction cancelled"), - tr("The installation was cancelled while extracting files. " - "If this was prior to a FOMOD setup, this warning may be ignored. " - "However, if this was during installation, the mod will likely be missing files."), - QMessageBox::Ok); - refreshModList(); + } else { + m_InstallationManager.notifyInstallationEnd(result, nullptr); + if (m_InstallationManager.wasCancelled()) { + QMessageBox::information(qApp->activeWindow(), tr("Extraction cancelled"), + tr("The installation was cancelled while extracting files. " + "If this was prior to a FOMOD setup, this warning may be ignored. " + "However, if this was during installation, the mod will likely be missing files."), + QMessageBox::Ok); + refreshModList(); + } } return nullptr; } @@ -788,6 +796,7 @@ void OrganizerCore::installDownload(int index) QString gameName = m_DownloadManager.getGameName(index); int modID = m_DownloadManager.getModID(index); int fileID = m_DownloadManager.getFileInfo(index)->fileID; + ModInfo::Ptr currentMod = nullptr; GuessedValue<QString> modName; // see if there already are mods with the specified mod id @@ -798,6 +807,7 @@ void OrganizerCore::installDownload(int index) if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_BACKUP) == flags.end()) { modName.update((*iter)->name(), GUESS_PRESET); + currentMod = *iter; (*iter)->saveMeta(); } } @@ -807,7 +817,9 @@ void OrganizerCore::installDownload(int index) bool hasIniTweaks = false; m_InstallationManager.setModsDirectory(m_Settings.paths().mods()); - if (m_InstallationManager.install(fileName, modName, hasIniTweaks) == IPluginInstaller::RESULT_SUCCESS) { + m_InstallationManager.notifyInstallationStart(fileName, false, currentMod); + auto result = m_InstallationManager.install(fileName, modName, hasIniTweaks); + if (result == IPluginInstaller::RESULT_SUCCESS) { MessageDialog::showMessage(tr("Installation successful"), qApp->activeWindow()); refreshModList(); @@ -828,19 +840,23 @@ void OrganizerCore::installDownload(int index) } m_ModInstalled(modName); + m_InstallationManager.notifyInstallationEnd(IPluginInstaller::RESULT_SUCCESS, modInfo); } else { reportError(tr("mod not found: %1").arg(qUtf8Printable(modName))); } m_DownloadManager.markInstalled(index); - emit modInstalled(modName); - } else if (m_InstallationManager.wasCancelled()) { - QMessageBox::information(qApp->activeWindow(), tr("Extraction cancelled"), - tr("The installation was cancelled while extracting files. " - "If this was prior to a FOMOD setup, this warning may be ignored. " - "However, if this was during installation, the mod will likely be missing files."), - QMessageBox::Ok); - refreshModList(); + } + else { + m_InstallationManager.notifyInstallationEnd(result, nullptr); + if (m_InstallationManager.wasCancelled()) { + QMessageBox::information(qApp->activeWindow(), tr("Extraction cancelled"), + tr("The installation was cancelled while extracting files. " + "If this was prior to a FOMOD setup, this warning may be ignored. " + "However, if this was during installation, the mod will likely be missing files."), + QMessageBox::Ok); + refreshModList(); + } } } catch (const std::exception &e) { reportError(e.what()); diff --git a/src/organizercore.h b/src/organizercore.h index 2588d332..813bf084 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -309,7 +309,7 @@ public: QVariant persistent(const QString &pluginName, const QString &key, const QVariant &def) const;
void setPersistent(const QString &pluginName, const QString &key, const QVariant &value, bool sync);
QString pluginDataPath() const;
- virtual MOBase::IModInterface *installMod(const QString &fileName, const QString &initModName);
+ virtual MOBase::IModInterface *installMod(const QString &fileName, bool reinstallation, ModInfo::Ptr currentMod, const QString &initModName);
QString resolvePath(const QString &fileName) const;
QStringList listDirectories(const QString &directoryName) const;
QStringList findFiles(const QString &path, const std::function<bool (const QString &)> &filter) const;
diff --git a/src/organizerproxy.cpp b/src/organizerproxy.cpp index 9ccc3c17..a5047b43 100644 --- a/src/organizerproxy.cpp +++ b/src/organizerproxy.cpp @@ -208,7 +208,7 @@ void OrganizerProxy::refreshModList(bool saveChanges) IModInterface *OrganizerProxy::installMod(const QString &fileName, const QString &nameSuggestion)
{
- return m_Proxied->installMod(fileName, nameSuggestion);
+ return m_Proxied->installMod(fileName, false, nullptr, nameSuggestion);
}
QString OrganizerProxy::resolvePath(const QString &fileName) const
|
