From ad17210d7a6527d50786fbe60758e74e3c62abcb Mon Sep 17 00:00:00 2001 From: Mikaƫl Capelle Date: Tue, 1 Dec 2020 21:05:24 +0100 Subject: Compute supported extensions dynamically in installation and download manager. --- src/installationmanager.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/installationmanager.cpp') diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 06909994..078f7088 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -80,7 +80,6 @@ static T resolveFunction(QLibrary &lib, const char *name) InstallationManager::InstallationManager() : m_ParentWidget(nullptr), - m_SupportedExtensions({"zip", "rar", "7z", "fomod", "001"}), m_IsRunning(false) { m_ArchiveHandler = CreateArchive(); if (!m_ArchiveHandler->isValid()) { @@ -606,7 +605,7 @@ IPluginInstaller::EInstallResult InstallationManager::install(const QString &fil ON_BLOCK_EXIT([this]() { m_IsRunning = false; }); QFileInfo fileInfo(fileName); - if (m_SupportedExtensions.find(fileInfo.suffix()) == m_SupportedExtensions.end()) { + if (!getSupportedExtensions().contains(fileInfo.suffix(), Qt::CaseInsensitive)) { reportError(tr("File format \"%1\" not supported").arg(fileInfo.suffix())); return IPluginInstaller::RESULT_FAILED; } @@ -851,16 +850,20 @@ void InstallationManager::registerInstaller(IPluginInstaller *installer) { m_Installers.push_back(installer); installer->setInstallationManager(this); - IPluginInstallerCustom *installerCustom = dynamic_cast(installer); - if (installerCustom != nullptr) { - std::set extensions = installerCustom->supportedExtensions(); - m_SupportedExtensions.insert(extensions.begin(), extensions.end()); - } } QStringList InstallationManager::getSupportedExtensions() const { - return QStringList(std::begin(m_SupportedExtensions), std::end(m_SupportedExtensions)); + std::set supportedExtensions({ "zip", "rar", "7z", "fomod", "001" }); + for (auto* installer : m_PluginContainer->plugins()) { + if (m_PluginContainer->isEnabled(installer)) { + if (auto* installerCustom = dynamic_cast(installer)) { + std::set extensions = installerCustom->supportedExtensions(); + supportedExtensions.insert(extensions.begin(), extensions.end()); + } + } + } + return QStringList(supportedExtensions.begin(), supportedExtensions.end()); } void InstallationManager::notifyInstallationStart(QString const& archive, bool reinstallation, ModInfo::Ptr currentMod) -- cgit v1.3.1