From 51068294f1b262ff7a516c28c29395239c4021d4 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Mon, 19 Jul 2010 18:17:37 +0000 Subject: [PATCH] Vavious Magnet link related fixes --- src/bittorrent.cpp | 34 +++++++++++++++++++++++++--------- src/propertieswidget.cpp | 21 +++++++++------------ src/propertieswidget.h | 1 + src/torrentpersistentdata.h | 1 + 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 172c3c6b7..c6ead4538 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -772,7 +772,9 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) { const QString &fileName = h.name(); // Remove it from session if(delete_local_files) { - savePathsToRemove[hash] = h.save_path(); + QDir save_dir(h.save_path()); + if(save_dir != QDir(defaultSavePath) && (defaultTempPath.isEmpty() || save_dir != QDir(defaultTempPath))) + savePathsToRemove[hash] = save_dir.absolutePath(); s->remove_torrent(h.get_torrent_handle(), session::delete_files); } else { s->remove_torrent(h.get_torrent_handle()); @@ -883,10 +885,6 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { qDebug("addMagnetURI: Temp folder is enabled."); qDebug("addTorrent::Temp folder is enabled."); QString torrent_tmp_path = defaultTempPath.replace("\\", "/"); - if(!torrent_name.isEmpty()) { - if(!torrent_tmp_path.endsWith("/")) torrent_tmp_path += "/"; - torrent_tmp_path += torrent_name; - } p.save_path = torrent_tmp_path.toLocal8Bit().constData(); // Check if save path exists, creating it otherwise if(!QDir(torrent_tmp_path).exists()) @@ -2073,7 +2071,8 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { QString old_path = old_path_parts.join("/"); QStringList new_path_parts = misc::toQStringU(p->name).split("/"); new_path_parts.removeLast(); - if(old_path != new_path_parts.join("/")) { + if(!new_path_parts.isEmpty() && old_path != new_path_parts.join("/")) { + qDebug("Old_path(%s) != new_path(%s)", qPrintable(old_path), qPrintable(new_path_parts.join("/"))); old_path = h.save_path()+"/"+old_path; qDebug("Detected folder renaming, attempt to delete old folder: %s", qPrintable(old_path)); QDir().rmpath(old_path); @@ -2127,12 +2126,14 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { const QString& old_save_path = TorrentPersistentData::getPreviousPath(h.hash()); const QString new_save_path = QString::fromLocal8Bit(p->path.c_str()); qDebug("Torrent moved from %s to %s", qPrintable(old_save_path), qPrintable(new_save_path)); - qDebug("Attempting to remove %s", qPrintable(old_save_path)); QDir old_save_dir(old_save_path); - if(old_save_dir != QDir(defaultSavePath) && old_save_dir != QDir(defaultTempPath)) + if(old_save_dir != QDir(defaultSavePath) && old_save_dir != QDir(defaultTempPath)) { + qDebug("Attempting to remove %s", qPrintable(old_save_path)); misc::removeEmptyTree(old_save_path); - if(!new_save_path.startsWith(defaultTempPath)) + } + if(defaultTempPath.isEmpty() || !new_save_path.startsWith(defaultTempPath)) { TorrentPersistentData::saveSavePath(h.hash(), new_save_path); + } emit savePathChanged(h); //h.force_recheck(); } @@ -2173,6 +2174,21 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { // Truncate root folder const QString &root_folder = misc::truncateRootFolder(p->handle); TorrentPersistentData::setRootFolder(h.hash(), root_folder); + + // Move to a subfolder corresponding to the torrent root folder if necessary + if(!root_folder.isEmpty()) { + if(!h.is_seed() && !defaultTempPath.isEmpty()) { + QString torrent_tmp_path = defaultTempPath.replace("\\", "/"); + if(!torrent_tmp_path.endsWith("/")) torrent_tmp_path += "/"; + torrent_tmp_path += root_folder; + h.move_storage(torrent_tmp_path); + } else { + QString save_path = h.save_path().replace("\\", "/"); + if(!save_path.endsWith("/")) save_path += "/"; + save_path += root_folder; + h.move_storage(save_path); + } + } emit metadataReceived(h); if(h.is_paused()) { // XXX: Unfortunately libtorrent-rasterbar does not send a torrent_paused_alert diff --git a/src/propertieswidget.cpp b/src/propertieswidget.cpp index 3c70a0969..e275ab02f 100644 --- a/src/propertieswidget.cpp +++ b/src/propertieswidget.cpp @@ -94,6 +94,7 @@ PropertiesWidget::PropertiesWidget(QWidget *parent, GUI* main_window, TransferLi connect(PropDelegate, SIGNAL(filteredFilesChanged()), this, SLOT(filteredFilesChanged())); connect(stackedProperties, SIGNAL(currentChanged(int)), this, SLOT(loadDynamicData())); connect(BTSession, SIGNAL(savePathChanged(QTorrentHandle&)), this, SLOT(updateSavePath(QTorrentHandle&))); + connect(BTSession, SIGNAL(metadataReceived(QTorrentHandle&)), this, SLOT(updateTorrentInfos(QTorrentHandle&))); // Downloaded pieces progress bar downloaded_pieces = new DownloadedPiecesBar(this); @@ -226,6 +227,12 @@ void PropertiesWidget::updateSavePath(QTorrentHandle& _h) { } } +void PropertiesWidget::updateTorrentInfos(QTorrentHandle& _h) { + if(h.is_valid() && h == _h) { + loadTorrentInfos(h); + } +} + void PropertiesWidget::on_reannounce_btn_clicked() { if(h.is_valid()) { h.force_reannounce(); @@ -243,18 +250,8 @@ void PropertiesWidget::loadTorrentInfos(QTorrentHandle &_h) { try { // Save path - QString p; - if(h.has_metadata() && h.num_files() == 1) { - p = h.firstFileSavePath(); - } else { - p = TorrentPersistentData::getSavePath(h.hash()); - if(p.isEmpty()) - p = h.save_path(); - } -#if defined(Q_WS_WIN) || defined(Q_OS_OS2) - p = p.replace("/", "\\"); -#endif - save_path->setText(p); + updateSavePath(h); + changeSavePathButton->setEnabled(h.has_metadata()); // Creation date lbl_creationDate->setText(h.creation_date()); // Hash diff --git a/src/propertieswidget.h b/src/propertieswidget.h index b2a109215..5825d5228 100644 --- a/src/propertieswidget.h +++ b/src/propertieswidget.h @@ -85,6 +85,7 @@ protected: protected slots: void loadTorrentInfos(QTorrentHandle &h); + void updateTorrentInfos(QTorrentHandle &h); void loadUrlSeeds(); void on_main_infos_button_clicked(); void on_trackers_button_clicked(); diff --git a/src/torrentpersistentdata.h b/src/torrentpersistentdata.h index 8491328af..f53e1e769 100644 --- a/src/torrentpersistentdata.h +++ b/src/torrentpersistentdata.h @@ -316,6 +316,7 @@ public: static void saveSavePath(QString hash, QString save_path) { Q_ASSERT(!hash.isEmpty()); + qDebug("TorrentPersistentData::saveSavePath(%s)", qPrintable(save_path)); QIniSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume")); QHash all_data = settings.value("torrents", QHash()).toHash(); QHash data = all_data[hash].toHash();