|
|
@ -69,6 +69,10 @@ Bittorrent::Bittorrent() : preAllocateAll(false), addInPause(false), ratio_limit |
|
|
|
resolve_countries = false; |
|
|
|
resolve_countries = false; |
|
|
|
// To avoid some exceptions
|
|
|
|
// To avoid some exceptions
|
|
|
|
fs::path::default_name_check(fs::no_check); |
|
|
|
fs::path::default_name_check(fs::no_check); |
|
|
|
|
|
|
|
// For backward compatibility
|
|
|
|
|
|
|
|
// Move .qBittorrent content to XDG folder
|
|
|
|
|
|
|
|
// TODO: Remove after some releases (introduced in v2.1.0)
|
|
|
|
|
|
|
|
misc::moveToXDGFolders(); |
|
|
|
// Creating Bittorrent session
|
|
|
|
// Creating Bittorrent session
|
|
|
|
// Check if we should spoof utorrent
|
|
|
|
// Check if we should spoof utorrent
|
|
|
|
QList<int> version; |
|
|
|
QList<int> version; |
|
|
@ -656,7 +660,7 @@ void Bittorrent::deleteTorrent(QString hash, bool delete_local_files) { |
|
|
|
else |
|
|
|
else |
|
|
|
s->remove_torrent(h.get_torrent_handle()); |
|
|
|
s->remove_torrent(h.get_torrent_handle()); |
|
|
|
// Remove it from torrent backup directory
|
|
|
|
// Remove it from torrent backup directory
|
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QStringList filters; |
|
|
|
QStringList filters; |
|
|
|
filters << hash+".*"; |
|
|
|
filters << hash+".*"; |
|
|
|
QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); |
|
|
|
QStringList files = torrentBackup.entryList(filters, QDir::Files, QDir::Unsorted); |
|
|
@ -730,15 +734,7 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { |
|
|
|
|
|
|
|
|
|
|
|
bool fastResume=false; |
|
|
|
bool fastResume=false; |
|
|
|
Q_ASSERT(magnet_uri.startsWith("magnet:")); |
|
|
|
Q_ASSERT(magnet_uri.startsWith("magnet:")); |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
// Checking if BT_backup Dir exists
|
|
|
|
|
|
|
|
// create it if it is not
|
|
|
|
|
|
|
|
if(! torrentBackup.exists()) { |
|
|
|
|
|
|
|
if(! torrentBackup.mkpath(torrentBackup.path())) { |
|
|
|
|
|
|
|
std::cerr << "Couldn't create the directory: '" << torrentBackup.path().toLocal8Bit().data() << "'\n"; |
|
|
|
|
|
|
|
exit(1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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()) { |
|
|
@ -829,8 +825,8 @@ QTorrentHandle Bittorrent::addMagnetUri(QString magnet_uri, bool resumed) { |
|
|
|
QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) { |
|
|
|
QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed) { |
|
|
|
QTorrentHandle h; |
|
|
|
QTorrentHandle h; |
|
|
|
bool fastResume=false; |
|
|
|
bool fastResume=false; |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QString file, dest_file, hash; |
|
|
|
QString file, hash; |
|
|
|
boost::intrusive_ptr<torrent_info> t; |
|
|
|
boost::intrusive_ptr<torrent_info> t; |
|
|
|
|
|
|
|
|
|
|
|
// Checking if BT_backup Dir exists
|
|
|
|
// Checking if BT_backup Dir exists
|
|
|
@ -926,9 +922,9 @@ QTorrentHandle Bittorrent::addTorrent(QString path, bool fromScanDir, QString fr |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
// TODO: Remove in v1.6.0: For backward compatibility only
|
|
|
|
// TODO: Remove in v1.6.0: For backward compatibility only
|
|
|
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished")) { |
|
|
|
if(QFile::exists(misc::BTBackupLocation()+QDir::separator()+hash+".finished")) { |
|
|
|
p.save_path = savePath.toLocal8Bit().data(); |
|
|
|
p.save_path = savePath.toLocal8Bit().data(); |
|
|
|
QFile::remove(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".finished"); |
|
|
|
QFile::remove(misc::BTBackupLocation()+QDir::separator()+hash+".finished"); |
|
|
|
} |
|
|
|
} |
|
|
|
p.ti = t; |
|
|
|
p.ti = t; |
|
|
|
// Preallocate all?
|
|
|
|
// Preallocate all?
|
|
|
@ -1120,7 +1116,7 @@ void Bittorrent::enableLSD(bool b) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Bittorrent::loadSessionState() { |
|
|
|
void Bittorrent::loadSessionState() { |
|
|
|
boost::filesystem::ifstream ses_state_file((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data() |
|
|
|
boost::filesystem::ifstream ses_state_file((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data() |
|
|
|
, std::ios_base::binary); |
|
|
|
, std::ios_base::binary); |
|
|
|
ses_state_file.unsetf(std::ios_base::skipws); |
|
|
|
ses_state_file.unsetf(std::ios_base::skipws); |
|
|
|
s->load_state(bdecode( |
|
|
|
s->load_state(bdecode( |
|
|
@ -1131,7 +1127,7 @@ void Bittorrent::loadSessionState() { |
|
|
|
void Bittorrent::saveSessionState() { |
|
|
|
void Bittorrent::saveSessionState() { |
|
|
|
qDebug("Saving session state to disk..."); |
|
|
|
qDebug("Saving session state to disk..."); |
|
|
|
entry session_state = s->state(); |
|
|
|
entry session_state = s->state(); |
|
|
|
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("ses_state")).toLocal8Bit().data() |
|
|
|
boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("ses_state")).toLocal8Bit().data() |
|
|
|
, std::ios_base::binary); |
|
|
|
, std::ios_base::binary); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
bencode(std::ostream_iterator<char>(out), session_state); |
|
|
|
bencode(std::ostream_iterator<char>(out), session_state); |
|
|
@ -1142,7 +1138,7 @@ bool Bittorrent::enableDHT(bool b) { |
|
|
|
if(b) { |
|
|
|
if(b) { |
|
|
|
if(!DHTEnabled) { |
|
|
|
if(!DHTEnabled) { |
|
|
|
entry dht_state; |
|
|
|
entry dht_state; |
|
|
|
QString dht_state_path = misc::qBittorrentPath()+QString::fromUtf8("dht_state"); |
|
|
|
QString dht_state_path = misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state"); |
|
|
|
if(QFile::exists(dht_state_path)) { |
|
|
|
if(QFile::exists(dht_state_path)) { |
|
|
|
boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().data(), std::ios_base::binary); |
|
|
|
boost::filesystem::ifstream dht_state_file(dht_state_path.toLocal8Bit().data(), std::ios_base::binary); |
|
|
|
dht_state_file.unsetf(std::ios_base::skipws); |
|
|
|
dht_state_file.unsetf(std::ios_base::skipws); |
|
|
@ -1235,7 +1231,7 @@ void Bittorrent::saveFastResumeData() { |
|
|
|
// Saving fast resume data was successful
|
|
|
|
// Saving fast resume data was successful
|
|
|
|
--num_resume_data; |
|
|
|
--num_resume_data; |
|
|
|
if (!rd->resume_data) continue; |
|
|
|
if (!rd->resume_data) continue; |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QTorrentHandle h(rd->handle); |
|
|
|
QTorrentHandle h(rd->handle); |
|
|
|
if(!h.is_valid()) continue; |
|
|
|
if(!h.is_valid()) continue; |
|
|
|
// Remove old fastresume file if it exists
|
|
|
|
// Remove old fastresume file if it exists
|
|
|
@ -1664,7 +1660,7 @@ void Bittorrent::readAlerts() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) { |
|
|
|
else if (save_resume_data_alert* p = dynamic_cast<save_resume_data_alert*>(a.get())) { |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
QTorrentHandle h(p->handle); |
|
|
|
if(h.is_valid()) { |
|
|
|
if(h.is_valid()) { |
|
|
|
QString file = h.hash()+".fastresume"; |
|
|
|
QString file = h.hash()+".fastresume"; |
|
|
@ -1959,7 +1955,7 @@ void Bittorrent::saveDHTEntry() { |
|
|
|
if(DHTEnabled) { |
|
|
|
if(DHTEnabled) { |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
entry dht_state = s->dht_state(); |
|
|
|
entry dht_state = s->dht_state(); |
|
|
|
boost::filesystem::ofstream out((misc::qBittorrentPath()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary); |
|
|
|
boost::filesystem::ofstream out((misc::cacheLocation()+QDir::separator()+QString::fromUtf8("dht_state")).toLocal8Bit().data(), std::ios_base::binary); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
out.unsetf(std::ios_base::skipws); |
|
|
|
bencode(std::ostream_iterator<char>(out), dht_state); |
|
|
|
bencode(std::ostream_iterator<char>(out), dht_state); |
|
|
|
qDebug("DHT entry saved"); |
|
|
|
qDebug("DHT entry saved"); |
|
|
@ -1979,8 +1975,7 @@ void Bittorrent::applyEncryptionSettings(pe_settings se) { |
|
|
|
void Bittorrent::startUpTorrents() { |
|
|
|
void Bittorrent::startUpTorrents() { |
|
|
|
qDebug("Resuming unfinished torrents"); |
|
|
|
qDebug("Resuming unfinished torrents"); |
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QStringList fileNames; |
|
|
|
|
|
|
|
QStringList known_torrents = TorrentPersistentData::knownTorrents(); |
|
|
|
QStringList known_torrents = TorrentPersistentData::knownTorrents(); |
|
|
|
|
|
|
|
|
|
|
|
if(known_torrents.empty() && !settings.value("v1_4_x_torrent_imported", false).toBool()) { |
|
|
|
if(known_torrents.empty() && !settings.value("v1_4_x_torrent_imported", false).toBool()) { |
|
|
@ -2041,7 +2036,7 @@ void Bittorrent::startUpTorrents() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Import torrents temp data from v1.4.0 or earlier: save_path, filtered pieces
|
|
|
|
// Import torrents temp data from v1.4.0 or earlier: save_path, filtered pieces
|
|
|
|
// TODO: Remove in qBittorrent v1.6.0
|
|
|
|
// TODO: Remove in qBittorrent v2.2.0
|
|
|
|
void Bittorrent::importOldTempData(QString torrent_path) { |
|
|
|
void Bittorrent::importOldTempData(QString torrent_path) { |
|
|
|
// Create torrent hash
|
|
|
|
// Create torrent hash
|
|
|
|
boost::intrusive_ptr<torrent_info> t; |
|
|
|
boost::intrusive_ptr<torrent_info> t; |
|
|
@ -2049,7 +2044,7 @@ void Bittorrent::importOldTempData(QString torrent_path) { |
|
|
|
t = new torrent_info(torrent_path.toLocal8Bit().data()); |
|
|
|
t = new torrent_info(torrent_path.toLocal8Bit().data()); |
|
|
|
QString hash = misc::toQString(t->info_hash()); |
|
|
|
QString hash = misc::toQString(t->info_hash()); |
|
|
|
// Load save path
|
|
|
|
// Load save path
|
|
|
|
QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath"); |
|
|
|
QFile savepath_file(misc::BTBackupLocation()+QDir::separator()+hash+".savepath"); |
|
|
|
QByteArray line; |
|
|
|
QByteArray line; |
|
|
|
QString savePath; |
|
|
|
QString savePath; |
|
|
|
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if(savepath_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
@ -2061,7 +2056,7 @@ void Bittorrent::importOldTempData(QString torrent_path) { |
|
|
|
TorrentTempData::setSavePath(hash, savePath); |
|
|
|
TorrentTempData::setSavePath(hash, savePath); |
|
|
|
} |
|
|
|
} |
|
|
|
// Load pieces priority
|
|
|
|
// Load pieces priority
|
|
|
|
QFile pieces_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".priorities"); |
|
|
|
QFile pieces_file(misc::BTBackupLocation()+QDir::separator()+hash+".priorities"); |
|
|
|
if(pieces_file.exists()){ |
|
|
|
if(pieces_file.exists()){ |
|
|
|
// Read saved file
|
|
|
|
// Read saved file
|
|
|
|
if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if(pieces_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
@ -2082,7 +2077,7 @@ void Bittorrent::importOldTempData(QString torrent_path) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Load sequential
|
|
|
|
// Load sequential
|
|
|
|
if(QFile::exists(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".incremental")) { |
|
|
|
if(QFile::exists(misc::BTBackupLocation()+QDir::separator()+hash+".incremental")) { |
|
|
|
qDebug("Imported torrent was sequential"); |
|
|
|
qDebug("Imported torrent was sequential"); |
|
|
|
TorrentTempData::setSequential(hash, true); |
|
|
|
TorrentTempData::setSequential(hash, true); |
|
|
|
} |
|
|
|
} |
|
|
@ -2091,10 +2086,10 @@ void Bittorrent::importOldTempData(QString torrent_path) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Trackers, web seeds, speed limits
|
|
|
|
// Trackers, web seeds, speed limits
|
|
|
|
// TODO: Remove in qBittorrent v1.6.0
|
|
|
|
// TODO: Remove in qBittorrent v2.2.0
|
|
|
|
void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { |
|
|
|
void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { |
|
|
|
// Load trackers
|
|
|
|
// Load trackers
|
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers"); |
|
|
|
QFile tracker_file(torrentBackup.path()+QDir::separator()+ h.hash() + ".trackers"); |
|
|
|
if(tracker_file.exists()) { |
|
|
|
if(tracker_file.exists()) { |
|
|
|
if(tracker_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if(tracker_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
@ -2114,7 +2109,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Load Web seeds
|
|
|
|
// Load Web seeds
|
|
|
|
QFile urlseeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".urlseeds"); |
|
|
|
QFile urlseeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".urlseeds"); |
|
|
|
if(urlseeds_file.exists()) { |
|
|
|
if(urlseeds_file.exists()) { |
|
|
|
if(urlseeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if(urlseeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
QByteArray urlseeds_lines = urlseeds_file.readAll(); |
|
|
|
QByteArray urlseeds_lines = urlseeds_file.readAll(); |
|
|
@ -2143,7 +2138,7 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// Load speed limits
|
|
|
|
// Load speed limits
|
|
|
|
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".speedLimits"); |
|
|
|
QFile speeds_file(misc::BTBackupLocation()+QDir::separator()+h.hash()+".speedLimits"); |
|
|
|
if(speeds_file.exists()) { |
|
|
|
if(speeds_file.exists()) { |
|
|
|
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) { |
|
|
|
QByteArray speed_limits = speeds_file.readAll(); |
|
|
|
QByteArray speed_limits = speeds_file.readAll(); |
|
|
@ -2160,12 +2155,12 @@ void Bittorrent::applyFormerAttributeFiles(QTorrentHandle h) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Import torrents from v1.4.0 or earlier
|
|
|
|
// Import torrents from v1.4.0 or earlier
|
|
|
|
// TODO: Remove in qBittorrent v1.6.0
|
|
|
|
// TODO: Remove in qBittorrent v2.2.0
|
|
|
|
void Bittorrent::importOldTorrents() { |
|
|
|
void Bittorrent::importOldTorrents() { |
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
|
|
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent")); |
|
|
|
Q_ASSERT(!settings.value("v1_4_x_torrent_imported", false).toBool()); |
|
|
|
Q_ASSERT(!settings.value("v1_4_x_torrent_imported", false).toBool()); |
|
|
|
// Import old torrent
|
|
|
|
// Import old torrent
|
|
|
|
QDir torrentBackup(misc::qBittorrentPath() + "BT_backup"); |
|
|
|
QDir torrentBackup(misc::BTBackupLocation()); |
|
|
|
QStringList fileNames; |
|
|
|
QStringList fileNames; |
|
|
|
QStringList filters; |
|
|
|
QStringList filters; |
|
|
|
filters << "*.torrent"; |
|
|
|
filters << "*.torrent"; |
|
|
|