mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-04 10:54:35 +00:00
- Got rid of .speedlimits file and use new TorrentPersistantData system
This commit is contained in:
parent
8da148ffa1
commit
63761afd0a
@ -147,9 +147,10 @@ void bittorrent::deleteBigRatios() {
|
||||
|
||||
void bittorrent::setDownloadLimit(QString hash, long val) {
|
||||
QTorrentHandle h = getTorrentHandle(hash);
|
||||
if(h.is_valid())
|
||||
if(h.is_valid()) {
|
||||
h.set_download_limit(val);
|
||||
saveTorrentSpeedLimits(hash);
|
||||
TorrentPersistentData::saveSpeedLimits(h);
|
||||
}
|
||||
}
|
||||
|
||||
bool bittorrent::isQueueingEnabled() const {
|
||||
@ -172,9 +173,10 @@ void bittorrent::decreaseDlTorrentPriority(QString hash) {
|
||||
void bittorrent::setUploadLimit(QString hash, long val) {
|
||||
qDebug("Set upload limit rate to %ld", val);
|
||||
QTorrentHandle h = getTorrentHandle(hash);
|
||||
if(h.is_valid())
|
||||
if(h.is_valid()) {
|
||||
h.set_upload_limit(val);
|
||||
saveTorrentSpeedLimits(hash);
|
||||
TorrentPersistentData::saveSpeedLimits(h);
|
||||
}
|
||||
}
|
||||
|
||||
void bittorrent::handleDownloadFailure(QString url, QString reason) {
|
||||
@ -821,36 +823,11 @@ bool bittorrent::enableDHT(bool b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void bittorrent::saveTorrentSpeedLimits(QString hash) {
|
||||
qDebug("Saving speedLimits file for %s", hash.toLocal8Bit().data());
|
||||
QTorrentHandle h = getTorrentHandle(hash);
|
||||
int download_limit = h.download_limit();
|
||||
int upload_limit = h.upload_limit();
|
||||
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
|
||||
if(!speeds_file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug("* Error: Couldn't open speed limits file for torrent: %s", hash.toLocal8Bit().data());
|
||||
return;
|
||||
}
|
||||
speeds_file.write(misc::toQByteArray(download_limit)+QByteArray(" ")+misc::toQByteArray(upload_limit));
|
||||
speeds_file.close();
|
||||
}
|
||||
|
||||
void bittorrent::loadTorrentSpeedLimits(QString hash) {
|
||||
// qDebug("Loading speedLimits file for %s", hash.toLocal8Bit().data());
|
||||
QTorrentHandle h = getTorrentHandle(hash);
|
||||
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".speedLimits");
|
||||
if(!speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return;
|
||||
}
|
||||
QByteArray speed_limits = speeds_file.readAll();
|
||||
speeds_file.close();
|
||||
QList<QByteArray> speeds = speed_limits.split(' ');
|
||||
if(speeds.size() != 2) {
|
||||
std::cerr << "Invalid .speedLimits file for " << hash.toStdString() << '\n';
|
||||
return;
|
||||
}
|
||||
h.set_download_limit(speeds.at(0).toInt());
|
||||
h.set_upload_limit(speeds.at(1).toInt());
|
||||
qDebug("Loading speedLimits file for %s", hash.toLocal8Bit().data());
|
||||
h.set_download_limit(TorrentPersistentData::getDownloadLimit(hash));
|
||||
h.set_upload_limit(TorrentPersistentData::getUploadLimit(hash));
|
||||
}
|
||||
|
||||
// Read pieces priorities from hard disk
|
||||
@ -1674,6 +1651,22 @@ void bittorrent::applyFormerAttributeFiles(QTorrentHandle h) {
|
||||
}
|
||||
urlseeds_file.remove();
|
||||
}
|
||||
// Load speed limits
|
||||
QFile speeds_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+h.hash()+".speedLimits");
|
||||
if(speeds_file.exists()) {
|
||||
if(speeds_file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
QByteArray speed_limits = speeds_file.readAll();
|
||||
speeds_file.close();
|
||||
QList<QByteArray> speeds = speed_limits.split(' ');
|
||||
if(speeds.size() != 2) {
|
||||
std::cerr << "Invalid .speedLimits file for " << h.hash().toStdString() << '\n';
|
||||
return;
|
||||
}
|
||||
h.set_download_limit(speeds.at(0).toInt());
|
||||
h.set_upload_limit(speeds.at(1).toInt());
|
||||
}
|
||||
speeds_file.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Import torrents from v1.4.0 or earlier
|
||||
|
@ -136,7 +136,6 @@ class bittorrent : public QObject {
|
||||
void enableIPFilter(QString filter);
|
||||
void disableIPFilter();
|
||||
void setQueueingEnabled(bool enable);
|
||||
void saveTorrentSpeedLimits(QString hash);
|
||||
void loadTorrentSpeedLimits(QString hash);
|
||||
void handleDownloadFailure(QString url, QString reason);
|
||||
void loadWebSeeds(QString fileHash);
|
||||
|
@ -183,7 +183,11 @@ public:
|
||||
}
|
||||
data["url_seeds"] = url_seeds;
|
||||
}
|
||||
// Sequential download
|
||||
data["sequential"] = h.is_sequential_download();
|
||||
// Speed limits
|
||||
data["up_speed"] = h.upload_limit();
|
||||
data["dl_speed"] = h.download_limit();
|
||||
// Save data
|
||||
all_data[h.hash()] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
@ -236,6 +240,17 @@ public:
|
||||
qDebug("TorrentPersistentData: Saving save_path: %s, hash: %s", save_path.toLocal8Bit().data(), hash.toLocal8Bit().data());
|
||||
}
|
||||
|
||||
static void saveSpeedLimits(QTorrentHandle h) {
|
||||
Q_ASSERT(!hash.isEmpty());
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> data = all_data[h.hash()].toHash();
|
||||
data["up_speed"] = h.upload_limit();
|
||||
data["dl_speed"] = h.download_limit();
|
||||
all_data[h.hash()] = data;
|
||||
settings.setValue("torrents", all_data);
|
||||
}
|
||||
|
||||
static void saveUrlSeeds(QTorrentHandle h) {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
@ -291,6 +306,20 @@ public:
|
||||
return data["files_priority"].toList();
|
||||
}
|
||||
|
||||
static int getUploadLimit(QString hash) {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||
return data.value("up_speed", -1).toInt();
|
||||
}
|
||||
|
||||
static int getDownloadLimit(QString hash) {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
QHash<QString, QVariant> data = all_data[hash].toHash();
|
||||
return data.value("dl_speed", -1).toInt();
|
||||
}
|
||||
|
||||
static QString getSavePath(QString hash) {
|
||||
QSettings settings(QString::fromUtf8("qBittorrent"), QString::fromUtf8("qBittorrent-resume"));
|
||||
QHash<QString, QVariant> all_data = settings.value("torrents", QHash<QString, QVariant>()).toHash();
|
||||
|
Loading…
x
Reference in New Issue
Block a user