Browse Source

Simplify function

adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
ad5c88be3d
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 31
      src/base/search/searchpluginmanager.cpp
  2. 2
      src/base/search/searchpluginmanager.h

31
src/base/search/searchpluginmanager.cpp

@ -540,32 +540,25 @@ QString SearchPluginManager::pluginPath(const QString &name)
return QString("%1/%2.py").arg(pluginsLocation(), name); return QString("%1/%2.py").arg(pluginsLocation(), name);
} }
PluginVersion SearchPluginManager::getPluginVersion(QString filePath) PluginVersion SearchPluginManager::getPluginVersion(const QString &filePath)
{ {
QFile plugin(filePath); QFile pluginFile(filePath);
if (!plugin.exists()) { if (!pluginFile.open(QIODevice::ReadOnly | QIODevice::Text))
qDebug("%s plugin does not exist, returning 0.0", qUtf8Printable(filePath));
return {};
}
if (!plugin.open(QIODevice::ReadOnly | QIODevice::Text))
return {}; return {};
const PluginVersion invalidVersion; while (!pluginFile.atEnd()) {
const QString line = QString(pluginFile.readLine()).remove(' ');
PluginVersion version;
while (!plugin.atEnd()) {
const QString line = QString(plugin.readLine()).remove(' ');
if (!line.startsWith("#VERSION:", Qt::CaseInsensitive)) continue; if (!line.startsWith("#VERSION:", Qt::CaseInsensitive)) continue;
const QString versionStr = line.mid(9); const QString versionStr = line.mid(9);
version = PluginVersion::tryParse(versionStr, invalidVersion); const PluginVersion version = PluginVersion::tryParse(versionStr, {});
if (version == invalidVersion) { if (version.isValid())
LogMsg(tr("Search plugin '%1' contains invalid version string ('%2')") return version;
.arg(Utils::Fs::fileName(filePath), line), Log::MsgType::WARNING);
}
LogMsg(tr("Search plugin '%1' contains invalid version string ('%2')")
.arg(Utils::Fs::fileName(filePath), versionStr), Log::MsgType::WARNING);
break; break;
} }
return version;
return {};
} }

2
src/base/search/searchpluginmanager.h

@ -79,7 +79,7 @@ public:
SearchHandler *startSearch(const QString &pattern, const QString &category, const QStringList &usedPlugins); SearchHandler *startSearch(const QString &pattern, const QString &category, const QStringList &usedPlugins);
SearchDownloadHandler *downloadTorrent(const QString &siteUrl, const QString &url); SearchDownloadHandler *downloadTorrent(const QString &siteUrl, const QString &url);
static PluginVersion getPluginVersion(QString filePath); static PluginVersion getPluginVersion(const QString &filePath);
static QString categoryFullName(const QString &categoryName); static QString categoryFullName(const QString &categoryName);
QString pluginFullName(const QString &pluginName); QString pluginFullName(const QString &pluginName);
static QString pluginsLocation(); static QString pluginsLocation();

Loading…
Cancel
Save