|
|
@ -839,7 +839,8 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { |
|
|
|
qDebug("Successfuly loaded"); |
|
|
|
qDebug("Successfuly loaded"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
const QString &savePath = getSavePath(hash); |
|
|
|
QString torrent_name = misc::magnetUriToName(magnet_uri); |
|
|
|
|
|
|
|
const QString &savePath = getSavePath(hash, false, QString::null, torrent_name); |
|
|
|
if(!defaultTempPath.isEmpty() && resumed && !TorrentPersistentData::isSeed(hash)) { |
|
|
|
if(!defaultTempPath.isEmpty() && resumed && !TorrentPersistentData::isSeed(hash)) { |
|
|
|
qDebug("addMagnetURI: Temp folder is enabled."); |
|
|
|
qDebug("addMagnetURI: Temp folder is enabled."); |
|
|
|
p.save_path = defaultTempPath.toLocal8Bit().constData(); |
|
|
|
p.save_path = defaultTempPath.toLocal8Bit().constData(); |
|
|
@ -1035,6 +1036,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr |
|
|
|
} |
|
|
|
} |
|
|
|
return h; |
|
|
|
return h; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QString root_folder = misc::truncateRootFolder(t); |
|
|
|
add_torrent_params p; |
|
|
|
add_torrent_params p; |
|
|
|
//Getting fast resume data if existing
|
|
|
|
//Getting fast resume data if existing
|
|
|
|
std::vector<char> buf; |
|
|
|
std::vector<char> buf; |
|
|
@ -1052,7 +1054,7 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr |
|
|
|
// Enforcing the save path defined before URL download (from RSS for example)
|
|
|
|
// Enforcing the save path defined before URL download (from RSS for example)
|
|
|
|
savePath = savepath_fromurl.take(QUrl::fromEncoded(from_url.toLocal8Bit())); |
|
|
|
savePath = savepath_fromurl.take(QUrl::fromEncoded(from_url.toLocal8Bit())); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
savePath = getSavePath(hash, fromScanDir, path); |
|
|
|
savePath = getSavePath(hash, fromScanDir, path, root_folder); |
|
|
|
} |
|
|
|
} |
|
|
|
if(!defaultTempPath.isEmpty() && resumed && !TorrentPersistentData::isSeed(hash)) { |
|
|
|
if(!defaultTempPath.isEmpty() && resumed && !TorrentPersistentData::isSeed(hash)) { |
|
|
|
qDebug("addTorrent::Temp folder is enabled."); |
|
|
|
qDebug("addTorrent::Temp folder is enabled."); |
|
|
@ -1938,12 +1940,6 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid()) { |
|
|
|
qDebug("Received metadata for %s", qPrintable(h.hash())); |
|
|
|
qDebug("Received metadata for %s", qPrintable(h.hash())); |
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
|
|
|
|
// Append .!qB to incomplete files
|
|
|
|
|
|
|
|
if(appendqBExtension) |
|
|
|
|
|
|
|
appendqBextensionToTorrent(h, true); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
emit metadataReceived(h); |
|
|
|
|
|
|
|
// Save metadata
|
|
|
|
// Save metadata
|
|
|
|
const QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
const QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
if(!QFile::exists(torrentBackup.path()+QDir::separator()+h.hash()+QString(".torrent"))) |
|
|
|
if(!QFile::exists(torrentBackup.path()+QDir::separator()+h.hash()+QString(".torrent"))) |
|
|
@ -1968,11 +1964,20 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef LIBTORRENT_0_15 |
|
|
|
|
|
|
|
// Append .!qB to incomplete files
|
|
|
|
|
|
|
|
if(appendqBExtension) |
|
|
|
|
|
|
|
appendqBextensionToTorrent(h, true); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// Truncate root folder
|
|
|
|
|
|
|
|
misc::truncateRootFolder(p->handle); |
|
|
|
|
|
|
|
emit metadataReceived(h); |
|
|
|
if(h.is_paused()) { |
|
|
|
if(h.is_paused()) { |
|
|
|
// XXX: Unfortunately libtorrent-rasterbar does not send a torrent_paused_alert
|
|
|
|
// XXX: Unfortunately libtorrent-rasterbar does not send a torrent_paused_alert
|
|
|
|
// and the torrent can be paused when metadata is received
|
|
|
|
// and the torrent can be paused when metadata is received
|
|
|
|
emit pausedTorrent(h); |
|
|
|
emit pausedTorrent(h); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a.get())) { |
|
|
|
else if (file_error_alert* p = dynamic_cast<file_error_alert*>(a.get())) { |
|
|
@ -2148,7 +2153,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
return s->status(); |
|
|
|
return s->status(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString Bittorrent::getSavePath(QString hash, bool fromScanDir, QString filePath) { |
|
|
|
QString Bittorrent::getSavePath(QString hash, bool fromScanDir, QString filePath, QString root_folder) { |
|
|
|
QString savePath; |
|
|
|
QString savePath; |
|
|
|
if(TorrentTempData::hasTempData(hash)) { |
|
|
|
if(TorrentTempData::hasTempData(hash)) { |
|
|
|
savePath = TorrentTempData::getSavePath(hash); |
|
|
|
savePath = TorrentTempData::getSavePath(hash); |
|
|
@ -2168,11 +2173,19 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath)); |
|
|
|
qDebug("getSavePath, got save_path from temp data: %s", qPrintable(savePath)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
savePath = TorrentPersistentData::getSavePath(hash); |
|
|
|
savePath = TorrentPersistentData::getSavePath(hash); |
|
|
|
|
|
|
|
bool append_root_folder = false; |
|
|
|
if(savePath.isEmpty()) { |
|
|
|
if(savePath.isEmpty()) { |
|
|
|
if(fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath)) |
|
|
|
if(fromScanDir && m_scanFolders->downloadInTorrentFolder(filePath)) |
|
|
|
savePath = QFileInfo(filePath).dir().path(); |
|
|
|
savePath = QFileInfo(filePath).dir().path(); |
|
|
|
else |
|
|
|
else { |
|
|
|
savePath = defaultSavePath; |
|
|
|
savePath = defaultSavePath; |
|
|
|
|
|
|
|
append_root_folder = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
QSettings settings("qBittorrent", "qBittorrent"); |
|
|
|
|
|
|
|
if(!settings.value("ported_to_new_savepath_system", false).toBool()) { |
|
|
|
|
|
|
|
append_root_folder = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if(!fromScanDir && appendLabelToSavePath) { |
|
|
|
if(!fromScanDir && appendLabelToSavePath) { |
|
|
|
const QString &label = TorrentPersistentData::getLabel(hash); |
|
|
|
const QString &label = TorrentPersistentData::getLabel(hash); |
|
|
@ -2183,6 +2196,13 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(append_root_folder && !root_folder.isEmpty()) { |
|
|
|
|
|
|
|
// Append torrent root folder to the save path
|
|
|
|
|
|
|
|
if(!savePath.endsWith(QDir::separator())) |
|
|
|
|
|
|
|
savePath += QDir::separator(); |
|
|
|
|
|
|
|
savePath += root_folder; |
|
|
|
|
|
|
|
TorrentPersistentData::saveSavePath(hash, savePath); |
|
|
|
|
|
|
|
} |
|
|
|
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath)); |
|
|
|
qDebug("getSavePath, got save_path from persistent data: %s", qPrintable(savePath)); |
|
|
|
} |
|
|
|
} |
|
|
|
// Clean path
|
|
|
|
// Clean path
|
|
|
@ -2296,6 +2316,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
filters << "*.torrent"; |
|
|
|
filters << "*.torrent"; |
|
|
|
const QStringList &torrents_on_hd = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); |
|
|
|
const QStringList &torrents_on_hd = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); |
|
|
|
foreach(QString hash, torrents_on_hd) { |
|
|
|
foreach(QString hash, torrents_on_hd) { |
|
|
|
|
|
|
|
qDebug("found torrent with hash: %s on hard disk", qPrintable(hash)); |
|
|
|
hash.chop(8); // remove trailing .torrent
|
|
|
|
hash.chop(8); // remove trailing .torrent
|
|
|
|
if(!known_torrents.contains(hash)) { |
|
|
|
if(!known_torrents.contains(hash)) { |
|
|
|
std::cerr << "ERROR Detected!!! Adding back torrent " << qPrintable(hash) << " which got lost for some reason." << std::endl; |
|
|
|
std::cerr << "ERROR Detected!!! Adding back torrent " << qPrintable(hash) << " which got lost for some reason." << std::endl; |
|
|
@ -2317,9 +2338,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
const int prio = TorrentPersistentData::getPriority(hash); |
|
|
|
const int prio = TorrentPersistentData::getPriority(hash); |
|
|
|
torrent_queue.push(qMakePair(prio, hash)); |
|
|
|
torrent_queue.push(qMakePair(prio, hash)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
qDebug("Priority_queue size: %ld", (long)torrent_queue.size()); |
|
|
|
// Resume downloads
|
|
|
|
// Resume downloads
|
|
|
|
while(!torrent_queue.empty()) { |
|
|
|
while(!torrent_queue.empty()) { |
|
|
|
const QString &hash = torrent_queue.top().second; |
|
|
|
const QString hash = torrent_queue.top().second; |
|
|
|
torrent_queue.pop(); |
|
|
|
torrent_queue.pop(); |
|
|
|
qDebug("Starting up torrent %s", qPrintable(hash)); |
|
|
|
qDebug("Starting up torrent %s", qPrintable(hash)); |
|
|
|
if(TorrentPersistentData::isMagnet(hash)) { |
|
|
|
if(TorrentPersistentData::isMagnet(hash)) { |
|
|
@ -2338,5 +2360,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) { |
|
|
|
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true); |
|
|
|
addTorrent(torrentBackup.path()+QDir::separator()+hash+".torrent", false, QString(), true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QSettings settings("qBittorrent", "qBittorrent"); |
|
|
|
|
|
|
|
settings.setValue("ported_to_new_savepath_system", true); |
|
|
|
qDebug("Unfinished torrents resumed"); |
|
|
|
qDebug("Unfinished torrents resumed"); |
|
|
|
} |
|
|
|
} |
|
|
|