Browse Source

Use XDG folders (.cache, .local) instead of .qbittorrent

old .qbittorrent is imported and moved to XDG folder by qBittorrent so that the user does not loose anything
adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
a5d8766a9e
  1. 1
      Changelog
  2. 2
      src/GUI.cpp
  3. 59
      src/bittorrent.cpp
  4. 14
      src/engineselectdlg.cpp
  5. 97
      src/misc.h
  6. 27
      src/searchengine.cpp
  7. 2
      src/supportedengines.h

1
Changelog

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
- FEATURE: Better proxy support and preferences remodeling
- FEATURE: qBittorrent can identify itself as uTorrent, Vuze or KTorrent (Any stable version)
- FEATURE: Torrents can be renamed in transfer list
- BUGFIX: Use XDG folders (.cache, .local) instead of .qbittorrent
- COSMETIC: Use checkboxes to filter torrent content instead of comboboxes
- COSMETIC: Use alternating row colors in transfer list (set in program preferences)
- COSMETIC: Added a spin box to speed limiting dialog for manual input

2
src/GUI.cpp

@ -78,6 +78,8 @@ using namespace libtorrent; @@ -78,6 +78,8 @@ using namespace libtorrent;
// Constructor
GUI::GUI(QWidget *parent, QStringList torrentCmdLine) : QMainWindow(parent), displaySpeedInTitle(false), force_exit(false) {
setupUi(this);
qDebug("Data Location: %s", QDesktopServices::storageLocation(QDesktopServices::CacheLocation).toLocal8Bit().data());
qDebug("Data Location: %s", QDesktopServices::storageLocation(QDesktopServices::DataLocation).toLocal8Bit().data());
setWindowTitle(tr("qBittorrent %1", "e.g: qBittorrent v0.x").arg(QString::fromUtf8(VERSION)));
// Setting icons
this->setWindowIcon(QIcon(QString::fromUtf8(":/Icons/skin/qbittorrent32.png")));

59
src/bittorrent.cpp

@ -69,6 +69,10 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit @@ -69,6 +69,10 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit
resolve_countries = false;
// To avoid some exceptions
fs::path::default_name_check(fs::no_check);
// For backward compatibility
// Move .qBittorrent content to XDG folder
// TODO: Remove after some releases (introduced in v2.1.0)
misc::moveToXDGFolders();
// Creating Bittorrent session
// Check if we should spoof utorrent
QList<int> version;
@ -656,7 +660,7 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) { @@ -656,7 +660,7 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) {
else
s->remove_torrent(h.get_torrent_handle());
// Remove it from torrent backup directory
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QDir torrentBackup(misc::BTBackupLocation());
QStringList filters;
filters << hash+".*";
QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
@ -730,15 +734,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { @@ -730,15 +734,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
bool fastResume=false;
Q_ASSERT(magnet_uri.startsWith("magnet:"));
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
// Checking if BT_backup Dir exists
// create it if it is not
if(! torrentBackup.exists()) {
if(! torrentBackup.mkpath(torrentBackup.path())) {
std::cerr << "Couldn't create the directory: '" << torrentBackup.path().toLocal8Bit().data() << "'\n";
exit(1);
}
}
QDir torrentBackup(misc::BTBackupLocation());
// Check if torrent is already in download list
if(s->find_torrent(sha1_hash(hash.toLocal8Bit().data())).is_valid()) {
@ -829,8 +825,8 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { @@ -829,8 +825,8 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) {
QTorrentHandle h;
bool fastResume=false;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QString file, dest_file, hash;
QDir torrentBackup(misc::BTBackupLocation());
QString file, hash;
boost::intrusive_ptr<torrent_info> t;
// Checking if BT_backup Dir exists
@ -926,9 +922,9 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr @@ -926,9 +922,9 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr
}
#endif
// TODO: Remove in v1.6.0: For backward compatibility only
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) {
if(QFile::exists(misc::BTBackupLocation()+QDir::separator()+hash+".finished")) {
p.save_path = savePath.toLocal8Bit().data();
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished");
QFile::remove(misc::BTBackupLocation()+QDir::separator()+hash+".finished");
}
p.ti = t;
// Preallocate all?
@ -1120,7 +1116,7 @@ void Bittorrent::enableLSD(bool b) { @@ -1120,7 +1116,7 @@ void Bittorrent::enableLSD(bool b) {
}
void Bittorrent::loadSessionState() {
boost::filesystem::ifstream ses_state_file((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
boost::filesystem::ifstream ses_state_file((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
, std::ios_base::binary);
ses_state_file.unsetf(std::ios_base::skipws);
s->load_state(bdecode(
@ -1131,7 +1127,7 @@ void Bittorrent::loadSessionState() { @@ -1131,7 +1127,7 @@ void Bittorrent::loadSessionState() {
void Bittorrent::saveSessionState() {
qDebug("Saving session state to disk...");
entry session_state = s->state();
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data()
, std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), session_state);
@ -1142,7 +1138,7 @@ bool Bittorrent::enableDHT(bool b) { @@ -1142,7 +1138,7 @@ bool Bittorrent::enableDHT(bool b) {
if(b) {
if(!DHTEnabled) {
entry dht_state;
QString dht_state_path = misc::qBittorrentPath()+QString::fromUtf8("dht_state");
QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state");
if(QFile::exists(dht_state_path)) {
boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().data(), std::ios_base::binary);
dht_state_file.unsetf(std::ios_base::skipws);
@ -1235,7 +1231,7 @@ void Bittorrent::saveFastResumeData() { @@ -1235,7 +1231,7 @@ void Bittorrent::saveFastResumeData() {
// Saving fast resume data was successful
--num_resume_data;
if (!rd->resume_data) continue;
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QDir torrentBackup(misc::BTBackupLocation());
QTorrentHandle h(rd->handle);
if(!h.is_valid()) continue;
// Remove old fastresume file if it exists
@ -1664,7 +1660,7 @@ void Bittorrent::readAlerts() { @@ -1664,7 +1660,7 @@ void Bittorrent::readAlerts() {
}
}
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) {
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QDir torrentBackup(misc::BTBackupLocation());
QTorrentHandle h(p->handle);
if(h.is_valid()) {
QString file = h.hash()+".fastresume";
@ -1959,7 +1955,7 @@ void Bittorrent::saveDHTEntry() { @@ -1959,7 +1955,7 @@ void Bittorrent::saveDHTEntry() {
if(DHTEnabled) {
try{
entry dht_state = s->dht_state();
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary);
boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary);
out.unsetf(std::ios_base::skipws);
bencode(std::ostream_iterator<char>(out), dht_state);
qDebug("DHT entry saved");
@ -1979,8 +1975,7 @@ void Bittorrent::applyEncryptionSettings(pe_settings se) { @@ -1979,8 +1975,7 @@ void Bittorrent::applyEncryptionSettings(pe_settings se) {
void Bittorrent::startUpTorrents() {
qDebug("Resuming unfinished torrents");
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QStringList fileNames;
QDir torrentBackup(misc::BTBackupLocation());
QStringList known_torrents = TorrentPersistentData::knownTorrents();
if(known_torrents.empty() && !settings.value("v1_4_x_torrent_imported", false).toBool()) {
@ -2041,7 +2036,7 @@ void Bittorrent::startUpTorrents() { @@ -2041,7 +2036,7 @@ void Bittorrent::startUpTorrents() {
}
// Import torrents temp data from v1.4.0 or earlier: save_path, filtered pieces
// TODO: Remove in qBittorrent v1.6.0
// TODO: Remove in qBittorrent v2.2.0
void Bittorrent::importOldTempData(QString torrent_path) {
// Create torrent hash
boost::intrusive_ptr<torrent_info> t;
@ -2049,7 +2044,7 @@ void Bittorrent::importOldTempData(QString torrent_path) { @@ -2049,7 +2044,7 @@ void Bittorrent::importOldTempData(QString torrent_path) {
t = new torrent_info(torrent_path.toLocal8Bit().data());
QString hash = misc::toQString(t->info_hash());
// Load save path
QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath");
QFile savepath_file(misc::BTBackupLocation()+QDir::separator()+hash+".savepath");
QByteArray line;
QString savePath;
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -2061,7 +2056,7 @@ void Bittorrent::importOldTempData(QString torrent_path) { @@ -2061,7 +2056,7 @@ void Bittorrent::importOldTempData(QString torrent_path) {
TorrentTempData::setSavePath(hash, savePath);
}
// Load pieces priority
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities");
QFile pieces_file(misc::BTBackupLocation()+QDir::separator()+hash+".priorities");
if(pieces_file.exists()){
// Read saved file
if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -2082,7 +2077,7 @@ void Bittorrent::importOldTempData(QString torrent_path) { @@ -2082,7 +2077,7 @@ void Bittorrent::importOldTempData(QString torrent_path) {
}
}
// Load sequential
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) {
if(QFile::exists(misc::BTBackupLocation()+QDir::separator()+hash+".incremental")) {
qDebug("Imported torrent was sequential");
TorrentTempData::setSequential(hash, true);
}
@ -2091,10 +2086,10 @@ void Bittorrent::importOldTempData(QString torrent_path) { @@ -2091,10 +2086,10 @@ void Bittorrent::importOldTempData(QString torrent_path) {
}
// Trackers, web seeds, speed limits
// TODO: Remove in qBittorrent v1.6.0
// TODO: Remove in qBittorrent v2.2.0
void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
// Load trackers
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QDir torrentBackup(misc::BTBackupLocation());
QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers");
if(tracker_file.exists()) {
if(tracker_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -2114,7 +2109,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { @@ -2114,7 +2109,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
}
}
// Load Web seeds
QFile urlseeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".urlseeds");
QFile urlseeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".urlseeds");
if(urlseeds_file.exists()) {
if(urlseeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QByteArray urlseeds_lines = urlseeds_file.readAll();
@ -2143,7 +2138,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { @@ -2143,7 +2138,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
}
}
// Load speed limits
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".speedLimits");
QFile speeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".speedLimits");
if(speeds_file.exists()) {
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QByteArray speed_limits = speeds_file.readAll();
@ -2160,12 +2155,12 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { @@ -2160,12 +2155,12 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
}
// Import torrents from v1.4.0 or earlier
// TODO: Remove in qBittorrent v1.6.0
// TODO: Remove in qBittorrent v2.2.0
void Bittorrent::importOldTorrents() {
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent"));
Q_ASSERT(!settings.value("v1_4_x_torrent_imported", false).toBool());
// Import old torrent
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QDir torrentBackup(misc::BTBackupLocation());
QStringList fileNames;
QStringList filters;
filters << "*.torrent";

14
src/engineselectdlg.cpp

@ -170,7 +170,7 @@ void engineSelectDlg::on_actionUninstall_triggered() { @@ -170,7 +170,7 @@ void engineSelectDlg::on_actionUninstall_triggered() {
}else {
// Proceed with uninstall
// remove it from hard drive
QDir enginesFolder(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines");
QDir enginesFolder(misc::searchEngineLocation()+QDir::separator()+"engines");
QStringList filters;
filters << id+".*";
QStringList files = enginesFolder.entryList(filters, QDir::Files, QDir::Unsorted);
@ -245,7 +245,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id){ @@ -245,7 +245,7 @@ QTreeWidgetItem* engineSelectDlg::findItemWithID(QString id){
}
bool engineSelectDlg::isUpdateNeeded(QString plugin_name, float new_version) const {
float old_version = SearchEngine::getPluginVersion(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py");
float old_version = SearchEngine::getPluginVersion(misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py");
qDebug("IsUpdate needed? tobeinstalled: %.2f, alreadyinstalled: %.2f", new_version, old_version);
return (new_version > old_version);
}
@ -260,7 +260,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) { @@ -260,7 +260,7 @@ void engineSelectDlg::installPlugin(QString path, QString plugin_name) {
return;
}
// Process with install
QString dest_path = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py";
QString dest_path = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+plugin_name+".py";
bool update = false;
if(QFile::exists(dest_path)) {
// Backup in case install fails
@ -324,12 +324,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) { @@ -324,12 +324,12 @@ void engineSelectDlg::addNewEngine(QString engine_name) {
setRowColor(pluginsTree->indexOfTopLevelItem(item), "red");
}
// Handle icon
QString iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".png";
QString iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".png";
if(QFile::exists(iconPath)) {
// Good, we already have the icon
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else {
iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".ico";
iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+engine->getName()+".ico";
if(QFile::exists(iconPath)) { // ICO support
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
} else {
@ -427,9 +427,9 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) { @@ -427,9 +427,9 @@ void engineSelectDlg::processDownloadedFile(QString url, QString filePath) {
QFile icon(filePath);
icon.open(QIODevice::ReadOnly);
if(ICOHandler::canRead(&icon))
iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+id+".ico";
iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".ico";
else
iconPath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator()+id+".png";
iconPath = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator()+id+".png";
QFile::copy(filePath, iconPath);
item->setData(ENGINE_NAME, Qt::DecorationRole, QVariant(QIcon(iconPath)));
}

97
src/misc.h

@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
#include <QThread>
#include <ctime>
#include <QDateTime>
#include <QDesktopServices>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/date_time/posix_time/conversion.hpp>
@ -107,6 +108,91 @@ public: @@ -107,6 +108,91 @@ public:
return x;
}
static void copyDir(QString src_path, QString dst_path) {
QDir sourceDir(src_path);
if(!sourceDir.exists()) return;
// Create destination directory
QDir destDir(dst_path);
if(!destDir.exists()) {
if(!destDir.mkpath(destDir.absolutePath())) return;
}
// List source directory
QFileInfoList content = sourceDir.entryInfoList();
foreach(const QFileInfo& child, content) {
if(child.fileName()[0] == '.') continue;
if(child.isDir()) {
copyDir(child.absoluteFilePath(), dst_path+QDir::separator()+QDir(child.absoluteFilePath()).dirName());
continue;
}
QString src_child_path = child.absoluteFilePath();
QString dest_child_path = destDir.absoluteFilePath(child.fileName());
// Copy the file from src to dest
QFile::copy(src_child_path, dest_child_path);
// Remove source file
QFile::remove(src_child_path);
}
// Remove source folder
QString dir_name = sourceDir.dirName();
if(sourceDir.cdUp()) {
sourceDir.rmdir(dir_name);
}
}
// Introduced in v2.1.0
// For backward compatibility
// Remove after some releases
static void moveToXDGFolders() {
QString old_qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
if(QDir(old_qBtPath).exists()) {
// Copy BT_backup folder
QString old_BTBackupPath = old_qBtPath + "BT_backup";
if(QDir(old_BTBackupPath).exists()) {
copyDir(old_BTBackupPath, BTBackupLocation());
}
// Copy search engine folder
QString old_searchPath = old_qBtPath + "search_engine";
if(QDir(old_searchPath).exists()) {
copyDir(old_searchPath, searchEngineLocation());
}
// Copy *_state files
if(QFile::exists(old_qBtPath+"dht_state")) {
QFile::copy(old_qBtPath+"dht_state", cacheLocation()+QDir::separator()+"dht_state");
QFile::remove(old_qBtPath+"dht_state");
}
if(QFile::exists(old_qBtPath+"ses_state")) {
QFile::copy(old_qBtPath+"ses_state", cacheLocation()+QDir::separator()+"ses_state");
QFile::remove(old_qBtPath+"ses_state");
}
// Remove .qbittorrent folder if empty
QDir::home().rmdir(".qbittorrent");
}
}
static QString searchEngineLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)
+ QDir::separator() + "search_engine");
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
static QString BTBackupLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)
+ QDir::separator() + "BT_backup");
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
static QString cacheLocation() {
QString location = QDir::cleanPath(QDesktopServices::storageLocation(QDesktopServices::CacheLocation));
QDir locationDir(location);
if(!locationDir.exists())
locationDir.mkpath(locationDir.absolutePath());
return location;
}
static long long freeDiskSpaceOnPath(QString path) {
if(path.isEmpty()) return -1;
@ -212,17 +298,6 @@ public: @@ -212,17 +298,6 @@ public:
return false;
}
// return qBittorrent config path
static QString qBittorrentPath() {
QString qBtPath = QDir::homePath()+QDir::separator()+QString::fromUtf8(".qbittorrent") + QDir::separator();
// Create dir if it does not exist
if(!QFile::exists(qBtPath)){
QDir dir(qBtPath);
dir.mkpath(qBtPath);
}
return qBtPath;
}
// Insertion sort, used instead of bubble sort because it is
// approx. 5 times faster.
template <class T> static void insertSort(QList<QPair<int, T> > &list, const QPair<int, T>& value, Qt::SortOrder sortOrder) {

27
src/searchengine.cpp

@ -240,7 +240,7 @@ void SearchEngine::on_search_button_clicked(){ @@ -240,7 +240,7 @@ void SearchEngine::on_search_button_clicked(){
QStringList params;
QStringList engineNames;
search_stopped = false;
params << misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py";
params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
params << supported_engines->enginesEnabled().join(",");
qDebug("Search with category: %s", selectedCategory().toLocal8Bit().data());
params << selectedCategory();
@ -305,7 +305,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) { @@ -305,7 +305,7 @@ void SearchEngine::downloadTorrent(QString engine_url, QString torrent_url) {
connect(downloadProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(downloadFinished(int,QProcess::ExitStatus)));
downloaders << downloadProcess;
QStringList params;
params << misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2dl.py";
params << misc::searchEngineLocation()+QDir::separator()+"nova2dl.py";
params << engine_url;
params << torrent_url;
// Launch search
@ -358,10 +358,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) { @@ -358,10 +358,7 @@ void SearchEngine::downloadFinished(int exitcode, QProcess::ExitStatus) {
void SearchEngine::updateNova() {
qDebug("Updating nova");
// create search_engine directory if necessary
QDir search_dir(misc::qBittorrentPath()+"search_engine");
if(!search_dir.exists()){
search_dir.mkdir(misc::qBittorrentPath()+"search_engine");
}
QDir search_dir(misc::searchEngineLocation());
QFile package_file(search_dir.path()+QDir::separator()+"__init__.py");
package_file.open(QIODevice::WriteOnly | QIODevice::Text);
package_file.close();
@ -372,7 +369,7 @@ void SearchEngine::updateNova() { @@ -372,7 +369,7 @@ void SearchEngine::updateNova() {
package_file2.open(QIODevice::WriteOnly | QIODevice::Text);
package_file2.close();
// Copy search plugin files (if necessary)
QString filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py";
QString filePath = misc::searchEngineLocation()+QDir::separator()+"nova2.py";
if(getPluginVersion(":/search_engine/nova2.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath))
QFile::remove(filePath);
@ -380,33 +377,33 @@ void SearchEngine::updateNova() { @@ -380,33 +377,33 @@ void SearchEngine::updateNova() {
}
// Set permissions
QFile::Permissions perm=QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner | QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | QFile::ReadGroup | QFile::ReadGroup;
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py").setPermissions(perm);
QFile(misc::searchEngineLocation()+QDir::separator()+"nova2.py").setPermissions(perm);
filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2dl.py";
filePath = misc::searchEngineLocation()+QDir::separator()+"nova2dl.py";
if(getPluginVersion(":/search_engine/nova2dl.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)){
QFile::remove(filePath);
}
QFile::copy(":/search_engine/nova2dl.py", filePath);
}
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2dl.py").setPermissions(perm);
filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"novaprinter.py";
QFile(misc::searchEngineLocation()+QDir::separator()+"nova2dl.py").setPermissions(perm);
filePath = misc::searchEngineLocation()+QDir::separator()+"novaprinter.py";
if(getPluginVersion(":/search_engine/novaprinter.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)){
QFile::remove(filePath);
}
QFile::copy(":/search_engine/novaprinter.py", filePath);
}
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"novaprinter.py").setPermissions(perm);
filePath = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"helpers.py";
QFile(misc::searchEngineLocation()+QDir::separator()+"novaprinter.py").setPermissions(perm);
filePath = misc::searchEngineLocation()+QDir::separator()+"helpers.py";
if(getPluginVersion(":/search_engine/helpers.py") > getPluginVersion(filePath)) {
if(QFile::exists(filePath)){
QFile::remove(filePath);
}
QFile::copy(":/search_engine/helpers.py", filePath);
}
QFile(misc::qBittorrentPath()+"search_engine"+QDir::separator()+"helpers.py").setPermissions(perm);
QString destDir = misc::qBittorrentPath()+"search_engine"+QDir::separator()+"engines"+QDir::separator();
QFile(misc::searchEngineLocation()+QDir::separator()+"helpers.py").setPermissions(perm);
QString destDir = misc::searchEngineLocation()+QDir::separator()+"engines"+QDir::separator();
QDir shipped_subDir(":/search_engine/engines/");
QStringList files = shipped_subDir.entryList();
foreach(const QString &file, files){

2
src/supportedengines.h

@ -139,7 +139,7 @@ public slots: @@ -139,7 +139,7 @@ public slots:
void update() {
QProcess nova;
QStringList params;
params << misc::qBittorrentPath()+"search_engine"+QDir::separator()+"nova2.py";
params << misc::searchEngineLocation()+QDir::separator()+"nova2.py";
params << "--capabilities";
nova.start("python", params, QIODevice::ReadOnly);
nova.waitForStarted();

Loading…
Cancel
Save