mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 14:04:23 +00:00
Fix magnet metadata loading. Update the queue and save_path correctly in all use cases.
This commit is contained in:
parent
c6bc4d2cd2
commit
e08ae6b668
@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
//initialize static member variables
|
//initialize static member variables
|
||||||
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
|
QHash<QString, TorrentTempData::TorrentData> TorrentTempData::data = QHash<QString, TorrentTempData::TorrentData>();
|
||||||
QStringList HiddenData::hashes = QStringList();
|
QHash<QString, bool> HiddenData::data = QHash<QString, bool>();
|
||||||
unsigned int HiddenData::metadata_counter = 0;
|
unsigned int HiddenData::metadata_counter = 0;
|
||||||
|
|
||||||
using namespace libtorrent;
|
using namespace libtorrent;
|
||||||
@ -428,9 +428,17 @@ void QBtSession::configureSession() {
|
|||||||
#endif
|
#endif
|
||||||
// Queueing System
|
// Queueing System
|
||||||
if (pref.isQueueingSystemEnabled()) {
|
if (pref.isQueueingSystemEnabled()) {
|
||||||
sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize();
|
int max_downloading = pref.getMaxActiveDownloads();
|
||||||
|
int max_active = pref.getMaxActiveTorrents();
|
||||||
|
if (max_downloading > -1)
|
||||||
|
sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_downloads = max_downloading;
|
||||||
|
if (max_active > -1)
|
||||||
|
sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_limit = max_active;
|
||||||
sessionSettings.active_seeds = pref.getMaxActiveUploads();
|
sessionSettings.active_seeds = pref.getMaxActiveUploads();
|
||||||
sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize();
|
|
||||||
sessionSettings.dont_count_slow_torrents = pref.ignoreSlowTorrentsForQueueing();
|
sessionSettings.dont_count_slow_torrents = pref.ignoreSlowTorrentsForQueueing();
|
||||||
setQueueingEnabled(true);
|
setQueueingEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
@ -991,8 +999,16 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
|
|||||||
if (HiddenData::hasData(hash) && pref.isQueueingSystemEnabled()) {
|
if (HiddenData::hasData(hash) && pref.isQueueingSystemEnabled()) {
|
||||||
//Internally increase the queue limits to ensure that the magnet is started
|
//Internally increase the queue limits to ensure that the magnet is started
|
||||||
libtorrent::session_settings sessionSettings(s->settings());
|
libtorrent::session_settings sessionSettings(s->settings());
|
||||||
sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize();
|
int max_downloading = pref.getMaxActiveDownloads();
|
||||||
sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize();
|
int max_active = pref.getMaxActiveTorrents();
|
||||||
|
if (max_downloading > -1)
|
||||||
|
sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_downloads = max_downloading;
|
||||||
|
if (max_active > -1)
|
||||||
|
sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_limit = max_active;
|
||||||
s->set_settings(sessionSettings);
|
s->set_settings(sessionSettings);
|
||||||
h.queue_position_top();
|
h.queue_position_top();
|
||||||
}
|
}
|
||||||
@ -2403,12 +2419,20 @@ void QBtSession::readAlerts() {
|
|||||||
if (h.is_valid()) {
|
if (h.is_valid()) {
|
||||||
QString hash(h.hash());
|
QString hash(h.hash());
|
||||||
if (HiddenData::hasData(hash)) {
|
if (HiddenData::hasData(hash)) {
|
||||||
HiddenData::gotMetadata();
|
HiddenData::gotMetadata(hash);
|
||||||
if (pref.isQueueingSystemEnabled()) {
|
if (pref.isQueueingSystemEnabled()) {
|
||||||
//Internally decrease the queue limits to ensure that that other queued items aren't started
|
//Internally decrease the queue limits to ensure that that other queued items aren't started
|
||||||
libtorrent::session_settings sessionSettings(s->settings());
|
libtorrent::session_settings sessionSettings(s->settings());
|
||||||
sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize();
|
int max_downloading = pref.getMaxActiveDownloads();
|
||||||
sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize();
|
int max_active = pref.getMaxActiveTorrents();
|
||||||
|
if (max_downloading > -1)
|
||||||
|
sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_downloads = max_downloading;
|
||||||
|
if (max_active > -1)
|
||||||
|
sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_limit = max_active;
|
||||||
s->set_settings(sessionSettings);
|
s->set_settings(sessionSettings);
|
||||||
}
|
}
|
||||||
h.pause();
|
h.pause();
|
||||||
@ -2958,16 +2982,26 @@ void QBtSession::backupPersistentData(const QString &hash, boost::shared_ptr<lib
|
|||||||
|
|
||||||
void QBtSession::unhideMagnet(const QString &hash) {
|
void QBtSession::unhideMagnet(const QString &hash) {
|
||||||
Preferences pref;
|
Preferences pref;
|
||||||
|
HiddenData::deleteData(hash);
|
||||||
|
QString save_path = TorrentTempData::getSavePath(hash);
|
||||||
QTorrentHandle h(getTorrentHandle(hash));
|
QTorrentHandle h(getTorrentHandle(hash));
|
||||||
|
|
||||||
if (!h.is_valid()) {
|
if (!h.is_valid()) {
|
||||||
if (pref.isQueueingSystemEnabled()) {
|
if (pref.isQueueingSystemEnabled()) {
|
||||||
//Internally decrease the queue limits to ensure that other queued items aren't started
|
//Internally decrease the queue limits to ensure that other queued items aren't started
|
||||||
libtorrent::session_settings sessionSettings(s->settings());
|
libtorrent::session_settings sessionSettings(s->settings());
|
||||||
sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize();
|
int max_downloading = pref.getMaxActiveDownloads();
|
||||||
sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize();
|
int max_active = pref.getMaxActiveTorrents();
|
||||||
|
if (max_downloading > -1)
|
||||||
|
sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_downloads = max_downloading;
|
||||||
|
if (max_active > -1)
|
||||||
|
sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_limit = max_active;
|
||||||
s->set_settings(sessionSettings);
|
s->set_settings(sessionSettings);
|
||||||
}
|
}
|
||||||
HiddenData::deleteData(hash);
|
|
||||||
TorrentTempData::deleteTempData(hash);
|
TorrentTempData::deleteTempData(hash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2976,8 +3010,16 @@ void QBtSession::unhideMagnet(const QString &hash) {
|
|||||||
if (pref.isQueueingSystemEnabled()) {
|
if (pref.isQueueingSystemEnabled()) {
|
||||||
//Internally decrease the queue limits to ensure that other queued items aren't started
|
//Internally decrease the queue limits to ensure that other queued items aren't started
|
||||||
libtorrent::session_settings sessionSettings(s->settings());
|
libtorrent::session_settings sessionSettings(s->settings());
|
||||||
sessionSettings.active_downloads = pref.getMaxActiveDownloads() + HiddenData::getDownloadingSize();
|
int max_downloading = pref.getMaxActiveDownloads();
|
||||||
sessionSettings.active_limit = pref.getMaxActiveTorrents() + HiddenData::getDownloadingSize();
|
int max_active = pref.getMaxActiveTorrents();
|
||||||
|
if (max_downloading > -1)
|
||||||
|
sessionSettings.active_downloads = max_downloading + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_downloads = max_downloading;
|
||||||
|
if (max_active > -1)
|
||||||
|
sessionSettings.active_limit = max_active + HiddenData::getDownloadingSize();
|
||||||
|
else
|
||||||
|
sessionSettings.active_limit = max_active;
|
||||||
s->set_settings(sessionSettings);
|
s->set_settings(sessionSettings);
|
||||||
}
|
}
|
||||||
if (pref.addTorrentsInPause())
|
if (pref.addTorrentsInPause())
|
||||||
@ -2985,12 +3027,10 @@ void QBtSession::unhideMagnet(const QString &hash) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
h.queue_position_bottom();
|
h.queue_position_bottom();
|
||||||
loadTorrentTempData(h, h.save_path(), !h.has_metadata());
|
loadTorrentTempData(h, h.save_path(), !h.has_metadata()); //TempData are deleted by a call to TorrentPersistentData::saveTorrentPersistentData()
|
||||||
|
|
||||||
if (!pref.addTorrentsInPause())
|
if (!pref.addTorrentsInPause())
|
||||||
h.resume();
|
h.resume();
|
||||||
HiddenData::deleteData(hash);
|
h.move_storage(save_path);
|
||||||
h.move_storage(TorrentTempData::getSavePath(hash));
|
|
||||||
TorrentTempData::deleteTempData(hash);
|
|
||||||
emit addedTorrent(h);
|
emit addedTorrent(h);
|
||||||
}
|
}
|
||||||
|
@ -117,32 +117,36 @@ private:
|
|||||||
class HiddenData {
|
class HiddenData {
|
||||||
public:
|
public:
|
||||||
static void addData(const QString &hash) {
|
static void addData(const QString &hash) {
|
||||||
hashes.append(hash);
|
data[hash] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hasData(const QString &hash) {
|
static bool hasData(const QString &hash) {
|
||||||
return hashes.contains(hash, Qt::CaseInsensitive);
|
return data.contains(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deleteData(const QString &hash) {
|
static void deleteData(const QString &hash) {
|
||||||
if (hashes.removeAll(hash))
|
if (data.value(hash, false))
|
||||||
metadata_counter--;
|
metadata_counter--;
|
||||||
|
data.remove(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getSize() {
|
static int getSize() {
|
||||||
return hashes.size();
|
return data.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getDownloadingSize() {
|
static int getDownloadingSize() {
|
||||||
return hashes.size() - metadata_counter;
|
return data.size() - metadata_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gotMetadata() {
|
static void gotMetadata(const QString &hash) {
|
||||||
|
if (!data.contains(hash))
|
||||||
|
return;
|
||||||
|
data[hash] = true;
|
||||||
metadata_counter++;
|
metadata_counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QStringList hashes;
|
static QHash<QString, bool> data;
|
||||||
static unsigned int metadata_counter;
|
static unsigned int metadata_counter;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user