From 829c358f1079a2eef87287b3e658c2848ea98b19 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Sun, 26 Aug 2007 18:41:45 +0000 Subject: [PATCH] - fixed some bugs introduced recently - improved debug output --- src/bittorrent.cpp | 28 +++++----- src/previewSelect.h | 3 +- src/qtorrenthandle.cpp | 116 ++++++++++++++++++++++++++++------------- src/qtorrenthandle.h | 3 -- src/trackerLogin.h | 3 +- 5 files changed, 95 insertions(+), 58 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 5ea70a9f7..2e066452f 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -367,9 +367,11 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { entry e = bdecode(std::istream_iterator(in), std::istream_iterator()); // Getting torrent file informations torrent_info t(e); - std::cout << t.info_hash() << "\n"; - QString hash = QString::fromUtf8(misc::toString(t.info_hash()).c_str()); + qDebug(" -> Hash: %s", misc::toString(t.info_hash()).c_str()); + qDebug(" -> Name: %s", t.name().c_str()); + QString hash = misc::toQString(t.info_hash()); if(s->find_torrent(t.info_hash()).is_valid()) { + qDebug("/!\\ Torrent is already in download list"); // Update info Bar if(!fromScanDir) { if(file.startsWith(torrentBackup.path())){ @@ -377,7 +379,8 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { // XXX: Why does this happen sometimes? QFileInfo fi(file); QString old_hash = fi.baseName(); - qDebug("Strange, hash changed to %s", old_hash.toUtf8().data()); + qDebug("Strange, hash changed from %s to %s", old_hash.toUtf8().data(), hash.toUtf8().data()); + Q_ASSERT(old_hash != hash); QStringList filters; filters << old_hash+".*"; QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); @@ -421,10 +424,10 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { if(index == -1) { fullAllocationModeList << hash; } - qDebug("Full allocation mode"); + qDebug(" -> Full allocation mode"); }else{ h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, true, true); - qDebug("Compact allocation mode"); + qDebug(" -> Compact allocation mode"); } if(!h.is_valid()) { // No need to keep on, it failed. @@ -436,7 +439,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { // Is this really useful and appropriate ? //h.set_max_connections(60); h.set_max_uploads(-1); - qDebug("Torrent hash is " + hash.toUtf8()); // Load filtered files loadFilesPriorities(h); // Load custom url seeds @@ -605,7 +607,7 @@ void bittorrent::saveTorrentSpeedLimits(QString hash) { } void bittorrent::loadTorrentSpeedLimits(QString hash) { - qDebug("Loading speedLimits file for %s", hash.toUtf8().data()); +// qDebug("Loading speedLimits file for %s", hash.toUtf8().data()); QTorrentHandle h = getTorrentHandle(hash); QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits"); if(!speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -633,12 +635,11 @@ void bittorrent::loadFilesPriorities(QTorrentHandle &h) { QString hash = h.hash(); QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities"); if(!pieces_file.exists()){ - qDebug("Info: priorities file does not exist for %s", hash.toUtf8().data()); return; } // Read saved file if(!pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) { - qDebug("* Error: Couldn't open priorities file: %s"); + qDebug("* Error: Couldn't open priorities file: %s", hash.toUtf8().data()); return; } QByteArray pieces_priorities = pieces_file.readAll(); @@ -667,9 +668,9 @@ void bittorrent::loadDownloadUploadForTorrent(QString hash) { if(! torrentBackup.exists()) { torrentBackup.mkpath(torrentBackup.path()); } - qDebug("Loading ratio data for %s", hash.toUtf8().data()); +// qDebug("Loading ratio data for %s", hash.toUtf8().data()); QFile ratio_file(torrentBackup.path()+QDir::separator()+ hash + ".ratio"); - if(!ratio_file.open(QIODevice::ReadOnly | QIODevice::Text)) { + if(!ratio_file.exists() || !ratio_file.open(QIODevice::ReadOnly | QIODevice::Text)) { return; } QByteArray data = ratio_file.readAll(); @@ -1105,7 +1106,6 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) { fullAllocationModeList << hash; } qDebug("Reloading torrent: %s", fileName.toUtf8().data()); - QTorrentHandle new_h; entry resumeData; // Checking if torrentBackup Dir exists // create it if it is not @@ -1128,7 +1128,7 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) { SleeperThread::msleep(1000); ++timeout; } - new_h = s->add_torrent(t, saveDir, resumeData, false); + QTorrentHandle new_h = s->add_torrent(t, saveDir, resumeData, false); qDebug("Using full allocation mode"); new_h.set_max_uploads(-1); @@ -1174,7 +1174,7 @@ QString bittorrent::getSavePath(QString hash) { if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) { line = savepath_file.readAll(); savepath_file.close(); - qDebug("Save path: %s", line.data()); + qDebug(" -> Save path: %s", line.data()); savePath = QString::fromUtf8(line.data()); }else{ // use default save path diff --git a/src/previewSelect.h b/src/previewSelect.h index 54bb0d036..119f85d06 100644 --- a/src/previewSelect.h +++ b/src/previewSelect.h @@ -91,7 +91,7 @@ class previewSelect: public QDialog, private Ui::preview { } public: - previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent){ + previewSelect(QWidget* parent, QTorrentHandle h): QDialog(parent), h(h){ setupUi(this); setAttribute(Qt::WA_DeleteOnClose); // Preview list @@ -105,7 +105,6 @@ class previewSelect: public QDialog, private Ui::preview { supported_preview_extensions << QString::fromUtf8("AVI") << QString::fromUtf8("DIVX") << QString::fromUtf8("MPG") << QString::fromUtf8("MPEG") << QString::fromUtf8("MPE") << QString::fromUtf8("MP3") << QString::fromUtf8("OGG") << QString::fromUtf8("WMV") << QString::fromUtf8("WMA") << QString::fromUtf8("RMV") << QString::fromUtf8("RMVB") << QString::fromUtf8("ASF") << QString::fromUtf8("MOV") << QString::fromUtf8("WAV") << QString::fromUtf8("MP2") << QString::fromUtf8("SWF") << QString::fromUtf8("AC3") << QString::fromUtf8("OGM") << QString::fromUtf8("MP4") << QString::fromUtf8("FLV") << QString::fromUtf8("VOB") << QString::fromUtf8("QT") << QString::fromUtf8("MKV") << QString::fromUtf8("AIF") << QString::fromUtf8("AIFF") << QString::fromUtf8("AIFC") << QString::fromUtf8("MID") << QString::fromUtf8("MPG") << QString::fromUtf8("RA") << QString::fromUtf8("RAM") << QString::fromUtf8("AU") << QString::fromUtf8("M4A") << QString::fromUtf8("FLAC") << QString::fromUtf8("M4P") << QString::fromUtf8("3GP") << QString::fromUtf8("AAC") << QString::fromUtf8("RM") << QString::fromUtf8("SWA") << QString::fromUtf8("MPC") << QString::fromUtf8("MPP"); previewList->header()->resizeSection(0, 200); // Fill list in - this->h = h; std::vector fp; h.file_progress(fp); unsigned int nbFiles = h.num_files(); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index bdb9acdbf..3d6bf2b57 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -27,82 +27,96 @@ #include "misc.h" #include "qtorrenthandle.h" -QTorrentHandle::QTorrentHandle(torrent_handle h) : h(h) { - t = h.get_torrent_info(); - s = h.status(); -} +QTorrentHandle::QTorrentHandle(torrent_handle h): h(h) {} // // Getters // torrent_handle QTorrentHandle::get_torrent_handle() const { + Q_ASSERT(h.is_valid()); return h; } torrent_info QTorrentHandle::get_torrent_info() const { - return t; + Q_ASSERT(h.is_valid()); + return h.get_torrent_info(); } QString QTorrentHandle::hash() const { - return misc::toQString(t.info_hash()); + Q_ASSERT(h.is_valid()); + return misc::toQString(h.get_torrent_info().info_hash()); } QString QTorrentHandle::name() const { + Q_ASSERT(h.is_valid()); return misc::toQString(h.name()); } float QTorrentHandle::progress() const { - return s.progress; + Q_ASSERT(h.is_valid()); + return h.status().progress; } QString QTorrentHandle::current_tracker() const { - return misc::toQString(s.current_tracker); + Q_ASSERT(h.is_valid()); + return misc::toQString(h.status().current_tracker); } bool QTorrentHandle::is_valid() const { + Q_ASSERT(h.is_valid()); return h.is_valid(); } bool QTorrentHandle::is_paused() const { + Q_ASSERT(h.is_valid()); return h.is_paused(); } size_type QTorrentHandle::total_size() const { - return t.total_size(); + Q_ASSERT(h.is_valid()); + return h.get_torrent_info().total_size(); } size_type QTorrentHandle::total_done() const { - return s.total_done; + Q_ASSERT(h.is_valid()); + return h.status().total_done; } float QTorrentHandle::download_payload_rate() const { - return s.download_payload_rate; + Q_ASSERT(h.is_valid()); + return h.status().download_payload_rate; } float QTorrentHandle::upload_payload_rate() const { - return s.upload_payload_rate; + Q_ASSERT(h.is_valid()); + return h.status().upload_payload_rate; } int QTorrentHandle::num_peers() const { - return s.num_peers; + Q_ASSERT(h.is_valid()); + return h.status().num_peers; } int QTorrentHandle::num_seeds() const { - return s.num_seeds; + Q_ASSERT(h.is_valid()); + return h.status().num_seeds; } QString QTorrentHandle::save_path() const { + Q_ASSERT(h.is_valid()); return misc::toQString(h.save_path().string()); } fs::path QTorrentHandle::save_path_boost() const { + Q_ASSERT(h.is_valid()); return h.save_path(); } QStringList QTorrentHandle::url_seeds() const { + Q_ASSERT(h.is_valid()); QStringList res; - std::vector existing_seeds = t.url_seeds(); + std::vector existing_seeds = h.get_torrent_info().url_seeds(); unsigned int nbSeeds = existing_seeds.size(); QString existing_seed; for(unsigned int i=0; i pieces_priorities_list = pieces_priorities.split('\n'); if((unsigned int)pieces_priorities_list.size() != nbFiles+1){ std::cerr << "* Error: Corrupted priorities file\n"; - return t.total_size(); + return h.get_torrent_info().total_size(); } size_type effective_size = 0; for(unsigned int i=0; i const& QTorrentHandle::trackers() const { + Q_ASSERT(h.is_valid()); return h.trackers(); } torrent_status::state_t QTorrentHandle::state() const { - return s.state; + Q_ASSERT(h.is_valid()); + return h.status().state; } QString QTorrentHandle::creator() const { - return misc::toQString(t.creator()); + Q_ASSERT(h.is_valid()); + return misc::toQString(h.get_torrent_info().creator()); } QString QTorrentHandle::comment() const { - return misc::toQString(t.comment()); + Q_ASSERT(h.is_valid()); + return misc::toQString(h.get_torrent_info().comment()); } size_type QTorrentHandle::total_failed_bytes() const { - return s.total_failed_bytes; + Q_ASSERT(h.is_valid()); + return h.status().total_failed_bytes; } void QTorrentHandle::file_progress(std::vector& fp) { + Q_ASSERT(h.is_valid()); return h.file_progress(fp); } size_type QTorrentHandle::total_payload_download() { - return s.total_payload_download; + Q_ASSERT(h.is_valid()); + return h.status().total_payload_download; } size_type QTorrentHandle::total_payload_upload() { - return s.total_payload_upload; + Q_ASSERT(h.is_valid()); + return h.status().total_payload_upload; } // Return a list of absolute paths corresponding // to all files in a torrent QStringList QTorrentHandle::files_path() const { + Q_ASSERT(h.is_valid()); QString saveDir = misc::toQString(h.save_path().string()) + QDir::separator(); QStringList res; - torrent_info::file_iterator fi = t.begin_files(); - while(fi != t.end_files()) { + torrent_info::file_iterator fi = h.get_torrent_info().begin_files(); + while(fi != h.get_torrent_info().end_files()) { res << QDir::cleanPath(saveDir + misc::toQString(fi->path.string())); fi++; } @@ -218,7 +248,8 @@ QStringList QTorrentHandle::files_path() const { } int QTorrentHandle::num_uploads() const { - return s.num_uploads; + Q_ASSERT(h.is_valid()); + return h.status().num_uploads; } // @@ -226,54 +257,67 @@ int QTorrentHandle::num_uploads() const { // void QTorrentHandle::set_download_limit(int limit) { + Q_ASSERT(h.is_valid()); h.set_download_limit(limit); } void QTorrentHandle::set_upload_limit(int limit) { + Q_ASSERT(h.is_valid()); h.set_upload_limit(limit); } void QTorrentHandle::pause() { + Q_ASSERT(h.is_valid()); h.pause(); } void QTorrentHandle::resume() { + Q_ASSERT(h.is_valid()); h.resume(); } void QTorrentHandle::remove_url_seed(QString seed) { + Q_ASSERT(h.is_valid()); h.remove_url_seed(misc::toString((const char*)seed.toUtf8())); } void QTorrentHandle::add_url_seed(QString seed) { + Q_ASSERT(h.is_valid()); h.add_url_seed(misc::toString((const char*)seed.toUtf8())); } void QTorrentHandle::set_max_uploads(int val){ + Q_ASSERT(h.is_valid()); h.set_max_uploads(val); } void QTorrentHandle::prioritize_files(std::vector v) { + Q_ASSERT(h.is_valid()); h.prioritize_files(v); } void QTorrentHandle::set_ratio(float ratio) const { + Q_ASSERT(h.is_valid()); h.set_ratio(ratio); } void QTorrentHandle::replace_trackers(std::vector const& v) const { + Q_ASSERT(h.is_valid()); h.replace_trackers(v); } void QTorrentHandle::force_reannounce() { + Q_ASSERT(h.is_valid()); h.force_reannounce(); } void QTorrentHandle::set_sequenced_download_threshold(int val) { + Q_ASSERT(h.is_valid()); h.set_sequenced_download_threshold(val); } void QTorrentHandle::set_tracker_login(QString username, QString password){ + Q_ASSERT(h.is_valid()); h.set_tracker_login(std::string(username.toUtf8().data()), std::string(password.toUtf8().data())); } @@ -283,12 +327,10 @@ void QTorrentHandle::set_tracker_login(QString username, QString password){ QTorrentHandle& QTorrentHandle::operator =(const torrent_handle& new_h) { h = new_h; - t = h.get_torrent_info(); - s = h.status(); return *this; } bool QTorrentHandle::operator ==(const QTorrentHandle& new_h) const{ - QString hash = misc::toQString(t.info_hash()); + QString hash = misc::toQString(h.get_torrent_info().info_hash()); return (hash == new_h.hash()); } diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index 354c64f21..78f57de43 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -34,8 +34,6 @@ class QStringList; class QTorrentHandle { private: torrent_handle h; - torrent_info t; - torrent_status s; public: @@ -107,7 +105,6 @@ class QTorrentHandle { // // Operators // - QTorrentHandle& operator =(const torrent_handle& new_h); bool operator ==(const QTorrentHandle& new_h) const; }; diff --git a/src/trackerLogin.h b/src/trackerLogin.h index 934ebf4ed..7fc4aae66 100644 --- a/src/trackerLogin.h +++ b/src/trackerLogin.h @@ -37,11 +37,10 @@ class trackerLogin : public QDialog, private Ui::authentication{ QTorrentHandle h; public: - trackerLogin(QWidget *parent, QTorrentHandle h): QDialog(parent){ + trackerLogin(QWidget *parent, QTorrentHandle h): QDialog(parent), h(h){ setupUi(this); setAttribute(Qt::WA_DeleteOnClose); login_logo->setPixmap(QPixmap(QString::fromUtf8(":/Icons/encrypted.png"))); - this->h = h; tracker_url->setText(h.current_tracker()); connect(this, SIGNAL(trackerLoginCancelled(QPair)), parent, SLOT(addUnauthenticatedTracker(QPair))); show();