Browse Source

- Priorities are now remembered across restart (bugfix)

adaptive-webui-19844
Christophe Dumez 16 years ago
parent
commit
89330e11de
  1. 60
      src/bittorrent.cpp
  2. 1
      src/bittorrent.h
  3. 2
      src/misc.h

60
src/bittorrent.cpp

@ -86,7 +86,7 @@ bittorrent::~bittorrent() {
// XXX: Done in GUI now (earlier = safer) // XXX: Done in GUI now (earlier = safer)
/*saveDHTEntry(); /*saveDHTEntry();
saveSessionState(); saveSessionState();
saveFastResumeData();*/ tResumeData();*/
// Disable directory scanning // Disable directory scanning
disableDirectoryScanning(); disableDirectoryScanning();
// Delete our objects // Delete our objects
@ -786,7 +786,10 @@ void bittorrent::saveFastResumeData() {
std::vector<torrent_handle>::iterator torrentIT; std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) { for(torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
QTorrentHandle h = QTorrentHandle(*torrentIT); QTorrentHandle h = QTorrentHandle(*torrentIT);
if(!h.is_valid() || !h.has_metadata() || h.is_paused()) continue; if(!h.is_valid() || !h.has_metadata()) continue;
if(isQueueingEnabled())
saveTorrentPriority(h.hash(), h.queue_position());
if(h.is_paused()) continue;
if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue; if(h.state() == torrent_status::checking_files || h.state() == torrent_status::queued_for_checking) continue;
h.save_resume_data(); h.save_resume_data();
++num_resume_data; ++num_resume_data;
@ -1333,23 +1336,58 @@ void bittorrent::applyEncryptionSettings(pe_settings se) {
s->set_pe_settings(se); s->set_pe_settings(se);
} }
void bittorrent::saveTorrentPriority(QString hash, int prio) {
// Write .queued file
QFile prio_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".prio");
prio_file.open(QIODevice::WriteOnly | QIODevice::Text);
prio_file.write(QByteArray::number(prio));
prio_file.close();
}
// Will fast resume torrents in // Will fast resume torrents in
// backup directory // backup directory
void bittorrent::resumeUnfinishedTorrents() { void bittorrent::resumeUnfinishedTorrents() {
qDebug("Resuming unfinished torrents"); qDebug("Resuming unfinished torrents");
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QStringList fileNames, filePaths; QStringList fileNames;
// Scan torrentBackup directory // Scan torrentBackup directory
QStringList filters; QStringList filters;
filters << "*.torrent"; filters << "*.torrent";
fileNames = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); fileNames = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
QString fileName; if(isQueueingEnabled()) {
foreach(fileName, fileNames) { QList<QPair<int, QString> > filePaths;
filePaths.append(torrentBackup.path()+QDir::separator()+fileName); foreach(QString fileName, fileNames) {
} QString filePath = torrentBackup.path()+QDir::separator()+fileName;
// Resume downloads int prio = 99999;
foreach(fileName, filePaths) { // Get priority
addTorrent(fileName, false, QString(), true); QString prioPath = filePath;
} prioPath.replace(".torrent", ".prio");
if(QFile::exists(prioPath)) {
QFile prio_file(prioPath);
if(prio_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
bool ok = false;
prio = prio_file.readAll().toInt(&ok);
if(!ok)
prio = 99999;
prio_file.close();
}
}
misc::insertSort2<QString>(filePaths, qMakePair(prio, filePath));
}
// Resume downloads
QPair<int, QString> fileName;
foreach(fileName, filePaths) {
addTorrent(fileName.second, false, QString(), true);
}
} else {
QStringList filePaths;
foreach(QString fileName, fileNames) {
filePaths.append(torrentBackup.path()+QDir::separator()+fileName);
}
// Resume downloads
foreach(QString fileName, filePaths) {
addTorrent(fileName, false, QString(), true);
}
}
qDebug("Unfinished torrents resumed"); qDebug("Unfinished torrents resumed");
} }

1
src/bittorrent.h

@ -120,6 +120,7 @@ class bittorrent : public QObject {
void disableIPFilter(); void disableIPFilter();
void setQueueingEnabled(bool enable); void setQueueingEnabled(bool enable);
void resumeUnfinishedTorrents(); void resumeUnfinishedTorrents();
void saveTorrentPriority(QString hash, int prio);
void saveTorrentSpeedLimits(QString hash); void saveTorrentSpeedLimits(QString hash);
void loadTorrentSpeedLimits(QString hash); void loadTorrentSpeedLimits(QString hash);
void handleDownloadFailure(QString url, QString reason); void handleDownloadFailure(QString url, QString reason);

2
src/misc.h

@ -243,7 +243,7 @@ class misc : public QObject{
list.insert(i, value); list.insert(i, value);
} }
template <class T> static void insertSort2(QList<QPair<int, T> > &list, const QPair<int, T>& value, Qt::SortOrder sortOrder) { template <class T> static void insertSort2(QList<QPair<int, T> > &list, const QPair<int, T>& value, Qt::SortOrder sortOrder=Qt::AscendingOrder) {
int i = 0; int i = 0;
if(sortOrder == Qt::AscendingOrder) { if(sortOrder == Qt::AscendingOrder) {
while(i < list.size() and value.first > list.at(i).first) { while(i < list.size() and value.first > list.at(i).first) {

Loading…
Cancel
Save