mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-25 22:14:32 +00:00
- Save torrent file as soon as we get the torrent metadata so that it does not have to be redownloaded on restart
This commit is contained in:
parent
a297204b27
commit
d5da8a6277
@ -746,15 +746,18 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) {
|
|||||||
addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri));
|
addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri));
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
QDir torrentBackup(misc::BTBackupLocation());
|
||||||
if(resumed) {
|
if(resumed) {
|
||||||
qDebug("Resuming magnet URI: %s", hash.toLocal8Bit().data());
|
qDebug("Resuming magnet URI: %s", hash.toLocal8Bit().data());
|
||||||
|
// Load metadata
|
||||||
|
if(QFile::exists(torrentBackup.path()+QDir::separator()+hash+QString(".torrent")))
|
||||||
|
return addTorrent(torrentBackup.path()+QDir::separator()+hash+QString(".torrent"), false, false, true);
|
||||||
} else {
|
} else {
|
||||||
qDebug("Adding new magnet URI");
|
qDebug("Adding new magnet URI");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fastResume=false;
|
bool fastResume=false;
|
||||||
Q_ASSERT(magnet_uri.startsWith("magnet:"));
|
Q_ASSERT(magnet_uri.startsWith("magnet:"));
|
||||||
QDir torrentBackup(misc::BTBackupLocation());
|
|
||||||
|
|
||||||
// Check if torrent is already in download list
|
// Check if torrent is already in download list
|
||||||
if(s->find_torrent(sha1_hash(hash.toLocal8Bit().data())).is_valid()) {
|
if(s->find_torrent(sha1_hash(hash.toLocal8Bit().data())).is_valid()) {
|
||||||
@ -1667,7 +1670,7 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||||||
qDebug("Disabling HTTP communications proxy");
|
qDebug("Disabling HTTP communications proxy");
|
||||||
#ifdef Q_WS_WIN
|
#ifdef Q_WS_WIN
|
||||||
putenv("http_proxy=");
|
putenv("http_proxy=");
|
||||||
putenv("sock_proxy=")
|
putenv("sock_proxy=");
|
||||||
#else
|
#else
|
||||||
unsetenv("http_proxy");
|
unsetenv("http_proxy");
|
||||||
unsetenv("sock_proxy");
|
unsetenv("sock_proxy");
|
||||||
@ -1767,6 +1770,10 @@ void Bittorrent::addConsoleMessage(QString msg, QString) {
|
|||||||
appendqBextensionToTorrent(h, true);
|
appendqBextensionToTorrent(h, true);
|
||||||
#endif
|
#endif
|
||||||
emit metadataReceived(h);
|
emit metadataReceived(h);
|
||||||
|
// Save metadata
|
||||||
|
QDir torrentBackup(misc::BTBackupLocation());
|
||||||
|
if(!QFile::exists(torrentBackup.path()+QDir::separator()+h.hash()+QString(".torrent")))
|
||||||
|
h.save_torrent_file(torrentBackup.path()+QDir::separator()+h.hash()+QString(".torrent"));
|
||||||
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
|
||||||
|
@ -39,6 +39,9 @@
|
|||||||
#include "torrentpersistentdata.h"
|
#include "torrentpersistentdata.h"
|
||||||
#include <libtorrent/magnet_uri.hpp>
|
#include <libtorrent/magnet_uri.hpp>
|
||||||
#include <libtorrent/torrent_info.hpp>
|
#include <libtorrent/torrent_info.hpp>
|
||||||
|
#include <libtorrent/bencode.hpp>
|
||||||
|
#include <libtorrent/entry.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
|
||||||
QTorrentHandle::QTorrentHandle(torrent_handle h): h(h) {}
|
QTorrentHandle::QTorrentHandle(torrent_handle h): h(h) {}
|
||||||
|
|
||||||
@ -143,7 +146,7 @@ void QTorrentHandle::get_peer_info(std::vector<peer_info>& v) const {
|
|||||||
|
|
||||||
bool QTorrentHandle::first_last_piece_first() const {
|
bool QTorrentHandle::first_last_piece_first() const {
|
||||||
Q_ASSERT(h.is_valid());
|
Q_ASSERT(h.is_valid());
|
||||||
// Detect main file
|
// Detect main file
|
||||||
int rank=0;
|
int rank=0;
|
||||||
int main_file_index = 0;
|
int main_file_index = 0;
|
||||||
file_entry main_file = h.get_torrent_info().file_at(0);
|
file_entry main_file = h.get_torrent_info().file_at(0);
|
||||||
@ -570,6 +573,23 @@ void QTorrentHandle::set_peer_upload_limit(libtorrent::asio::ip::tcp::endpoint i
|
|||||||
h.set_peer_upload_limit(ip, limit);
|
h.set_peer_upload_limit(ip, limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool QTorrentHandle::save_torrent_file(QString path) {
|
||||||
|
if(!h.has_metadata()) return false;
|
||||||
|
QFile met_file(path);
|
||||||
|
if(met_file.open(QIODevice::WriteOnly)) {
|
||||||
|
entry meta = bdecode(h.get_torrent_info().metadata().get(), h.get_torrent_info().metadata().get()+h.get_torrent_info().metadata_size());
|
||||||
|
entry torrent_file(entry::dictionary_t);
|
||||||
|
torrent_file["info"] = meta;
|
||||||
|
if(!h.trackers().empty())
|
||||||
|
torrent_file["announce"] = h.trackers().front().url;
|
||||||
|
boost::filesystem::ofstream out(path.toLocal8Bit().data(), std::ios_base::binary);
|
||||||
|
out.unsetf(std::ios_base::skipws);
|
||||||
|
bencode(std::ostream_iterator<char>(out), torrent_file);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void QTorrentHandle::set_peer_download_limit(libtorrent::asio::ip::tcp::endpoint ip, int limit) const {
|
void QTorrentHandle::set_peer_download_limit(libtorrent::asio::ip::tcp::endpoint ip, int limit) const {
|
||||||
Q_ASSERT(h.is_valid());
|
Q_ASSERT(h.is_valid());
|
||||||
h.set_peer_download_limit(ip, limit);
|
h.set_peer_download_limit(ip, limit);
|
||||||
|
@ -164,6 +164,7 @@ class QTorrentHandle {
|
|||||||
void add_tracker(announce_entry const& url);
|
void add_tracker(announce_entry const& url);
|
||||||
void prioritize_first_last_piece(bool b);
|
void prioritize_first_last_piece(bool b);
|
||||||
void rename_file(int index, QString name);
|
void rename_file(int index, QString name);
|
||||||
|
bool save_torrent_file(QString path);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Operators
|
// Operators
|
||||||
|
Loading…
x
Reference in New Issue
Block a user