- Priorities are now remembered across restart (bugfix)

This commit is contained in:
Christophe Dumez 2009-01-05 21:19:55 +00:00
parent c016c4bf66
commit 89330e11de
3 changed files with 51 additions and 12 deletions

View file

@ -86,7 +86,7 @@ bittorrent::~bittorrent() {
// XXX: Done in GUI now (earlier = safer)
/*saveDHTEntry();
saveSessionState();
saveFastResumeData();*/
tResumeData();*/
// Disable directory scanning
disableDirectoryScanning();
// Delete our objects
@ -786,7 +786,10 @@ void bittorrent::saveFastResumeData() {
std::vector<torrent_handle>::iterator torrentIT;
for(torrentIT = torrents.begin(); torrentIT != torrents.end(); 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;
h.save_resume_data();
++num_resume_data;
@ -1333,23 +1336,58 @@ void bittorrent::applyEncryptionSettings(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
// backup directory
void bittorrent::resumeUnfinishedTorrents() {
qDebug("Resuming unfinished torrents");
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup");
QStringList fileNames, filePaths;
QStringList fileNames;
// Scan torrentBackup directory
QStringList filters;
filters << "*.torrent";
fileNames = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted);
QString fileName;
foreach(fileName, fileNames) {
filePaths.append(torrentBackup.path()+QDir::separator()+fileName);
}
// Resume downloads
foreach(fileName, filePaths) {
addTorrent(fileName, false, QString(), true);
}
if(isQueueingEnabled()) {
QList<QPair<int, QString> > filePaths;
foreach(QString fileName, fileNames) {
QString filePath = torrentBackup.path()+QDir::separator()+fileName;
int prio = 99999;
// Get priority
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");
}

View file

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

View file

@ -243,7 +243,7 @@ class misc : public QObject{
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;
if(sortOrder == Qt::AscendingOrder) {
while(i < list.size() and value.first > list.at(i).first) {