mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-19 21:03:30 -07:00
Refactor function
In SearchPluginManager::updateNova(), omit removing __pycache__ folder and pyc files, those files will be recreated anyway. Add const to variables
This commit is contained in:
parent
f951bf678d
commit
77b71e392e
1 changed files with 26 additions and 49 deletions
|
@ -369,67 +369,44 @@ void SearchPluginManager::pluginDownloadFailed(const QString &url, const QString
|
||||||
// Update nova.py search plugin if necessary
|
// Update nova.py search plugin if necessary
|
||||||
void SearchPluginManager::updateNova()
|
void SearchPluginManager::updateNova()
|
||||||
{
|
{
|
||||||
qDebug("Updating nova");
|
|
||||||
|
|
||||||
// create nova directory if necessary
|
// create nova directory if necessary
|
||||||
QDir searchDir(engineLocation());
|
const QDir searchDir(engineLocation());
|
||||||
QString novaFolder = Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3 ? "searchengine/nova3" : "searchengine/nova";
|
const QString novaFolder = Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3
|
||||||
|
? "searchengine/nova3" : "searchengine/nova";
|
||||||
|
|
||||||
QFile packageFile(searchDir.absoluteFilePath("__init__.py"));
|
QFile packageFile(searchDir.absoluteFilePath("__init__.py"));
|
||||||
packageFile.open(QIODevice::WriteOnly | QIODevice::Text);
|
packageFile.open(QIODevice::WriteOnly);
|
||||||
packageFile.close();
|
packageFile.close();
|
||||||
if (!searchDir.exists("engines"))
|
|
||||||
searchDir.mkdir("engines");
|
searchDir.mkdir("engines");
|
||||||
Utils::Fs::removeDirRecursive(searchDir.absoluteFilePath("__pycache__"));
|
|
||||||
|
|
||||||
QFile packageFile2(searchDir.absolutePath() + "/engines/__init__.py");
|
QFile packageFile2(searchDir.absolutePath() + "/engines/__init__.py");
|
||||||
packageFile2.open(QIODevice::WriteOnly | QIODevice::Text);
|
packageFile2.open(QIODevice::WriteOnly);
|
||||||
packageFile2.close();
|
packageFile2.close();
|
||||||
|
|
||||||
// Copy search plugin files (if necessary)
|
// Copy search plugin files (if necessary)
|
||||||
QString filePath = searchDir.absoluteFilePath("nova2.py");
|
const auto updateFile = [&novaFolder](const QString &filename, const bool compareVersion)
|
||||||
if (getPluginVersion(":/" + novaFolder + "/nova2.py") > getPluginVersion(filePath)) {
|
{
|
||||||
removePythonScript(filePath);
|
const QString filePathBundled = ":/" + novaFolder + '/' + filename;
|
||||||
QFile::copy(":/" + novaFolder + "/nova2.py", filePath);
|
const QString filePathDisk = QDir(engineLocation()).absoluteFilePath(filename);
|
||||||
}
|
|
||||||
|
|
||||||
filePath = searchDir.absoluteFilePath("nova2dl.py");
|
if (compareVersion && (getPluginVersion(filePathBundled) <= getPluginVersion(filePathDisk)))
|
||||||
if (getPluginVersion(":/" + novaFolder + "/nova2dl.py") > getPluginVersion(filePath)) {
|
return;
|
||||||
removePythonScript(filePath);
|
|
||||||
QFile::copy(":/" + novaFolder + "/nova2dl.py", filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
filePath = searchDir.absoluteFilePath("fix_encoding.py");
|
Utils::Fs::forceRemove(filePathDisk);
|
||||||
QFile::copy(":/" + novaFolder + "/fix_encoding.py", filePath);
|
QFile::copy(filePathBundled, filePathDisk);
|
||||||
|
};
|
||||||
|
|
||||||
filePath = searchDir.absoluteFilePath("novaprinter.py");
|
updateFile("helpers.py", true);
|
||||||
if (getPluginVersion(":/" + novaFolder + "/novaprinter.py") > getPluginVersion(filePath)) {
|
updateFile("nova2.py", true);
|
||||||
removePythonScript(filePath);
|
updateFile("nova2dl.py", true);
|
||||||
QFile::copy(":/" + novaFolder + "/novaprinter.py", filePath);
|
updateFile("novaprinter.py", true);
|
||||||
}
|
updateFile("socks.py", false);
|
||||||
|
|
||||||
filePath = searchDir.absoluteFilePath("helpers.py");
|
if (Utils::ForeignApps::pythonInfo().version.majorNumber() >= 3)
|
||||||
if (getPluginVersion(":/" + novaFolder + "/helpers.py") > getPluginVersion(filePath)) {
|
updateFile("sgmllib3.py", false);
|
||||||
removePythonScript(filePath);
|
else
|
||||||
QFile::copy(":/" + novaFolder + "/helpers.py", filePath);
|
updateFile("fix_encoding.py", false);
|
||||||
}
|
|
||||||
|
|
||||||
filePath = searchDir.absoluteFilePath("socks.py");
|
|
||||||
removePythonScript(filePath);
|
|
||||||
QFile::copy(":/" + novaFolder + "/socks.py", filePath);
|
|
||||||
|
|
||||||
if (novaFolder.endsWith("nova")) {
|
|
||||||
filePath = searchDir.absoluteFilePath("fix_encoding.py");
|
|
||||||
removePythonScript(filePath);
|
|
||||||
QFile::copy(":/" + novaFolder + "/fix_encoding.py", filePath);
|
|
||||||
}
|
|
||||||
else if (novaFolder.endsWith("nova3")) {
|
|
||||||
filePath = searchDir.absoluteFilePath("sgmllib3.py");
|
|
||||||
removePythonScript(filePath);
|
|
||||||
QFile::copy(":/" + novaFolder + "/sgmllib3.py", filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
QDir destDir(pluginsLocation());
|
|
||||||
Utils::Fs::removeDirRecursive(destDir.absoluteFilePath("__pycache__"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchPluginManager::update()
|
void SearchPluginManager::update()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue