Browse Source

- Found a way not to use FullAllocationMode list in order to save memory in cpu

adaptive-webui-19844
Christophe Dumez 17 years ago
parent
commit
27e76962d1
  1. 20
      src/bittorrent.cpp
  2. 2
      src/bittorrent.h
  3. 6
      src/properties_imp.cpp
  4. 11
      src/qtorrenthandle.cpp
  5. 1
      src/qtorrenthandle.h

20
src/bittorrent.cpp

@ -186,12 +186,8 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) { @@ -186,12 +186,8 @@ void bittorrent::deleteTorrent(QString hash, bool permanent) {
trackersErrors.remove(hash);
// Remove it from ratio table
ratioData.remove(hash);
int index = fullAllocationModeList.indexOf(hash);
if(index != -1) {
fullAllocationModeList.removeAt(index);
}
// Remove it from pausedTorrents list
index = pausedTorrents.indexOf(hash);
int index = pausedTorrents.indexOf(hash);
if(index != -1) {
pausedTorrents.removeAt(index);
}
@ -424,10 +420,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) { @@ -424,10 +420,6 @@ void bittorrent::addTorrent(QString path, bool fromScanDir, QString from_url) {
// Adding files to bittorrent session
if(has_filtered_files(hash)) {
h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, false, true);
int index = fullAllocationModeList.indexOf(hash);
if(index == -1) {
fullAllocationModeList << hash;
}
qDebug(" -> Full allocation mode");
}else{
h = s->add_torrent(t, fs::path(savePath.toUtf8().data()), resume_data, true, true);
@ -1109,10 +1101,6 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) { @@ -1109,10 +1101,6 @@ void bittorrent::reloadTorrent(const QTorrentHandle &h) {
QString fileName = h.name();
QString hash = h.hash();
torrent_info t = h.get_torrent_info();
int index = fullAllocationModeList.indexOf(hash);
if(index == -1) {
fullAllocationModeList << hash;
}
qDebug("Reloading torrent: %s", fileName.toUtf8().data());
entry resumeData;
// Checking if torrentBackup Dir exists
@ -1169,12 +1157,6 @@ session_status bittorrent::getSessionStatus() const{ @@ -1169,12 +1157,6 @@ session_status bittorrent::getSessionStatus() const{
return s->status();
}
bool bittorrent::inFullAllocationMode(QString hash) const{
if(fullAllocationModeList.indexOf(hash) != -1)
return true;
return false;
}
QString bittorrent::getSavePath(QString hash) {
QFile savepath_file(misc::qBittorrentPath()+"BT_backup"+QDir::separator()+hash+".savepath");
QByteArray line;

2
src/bittorrent.h

@ -53,7 +53,6 @@ class bittorrent : public QObject{ @@ -53,7 +53,6 @@ class bittorrent : public QObject{
QHash<QString, qlonglong> ETAs;
QHash<QString, QPair<size_type,size_type> > ratioData;
QTimer *ETARefresher;
QStringList fullAllocationModeList;
QHash<QString, QList<QPair<QString, QString> > > trackersErrors;
deleteThread *deleter;
QStringList pausedTorrents;
@ -77,7 +76,6 @@ class bittorrent : public QObject{ @@ -77,7 +76,6 @@ class bittorrent : public QObject{
int getListenPort() const;
QStringList getTorrentsToPauseAfterChecking() const;
long getETA(QString hash) const;
bool inFullAllocationMode(QString hash) const;
float getRealRatio(QString hash) const;
session* getSession() const;
QList<QPair<QString, QString> > getTrackersErrors(QString hash) const;

6
src/properties_imp.cpp

@ -589,10 +589,12 @@ void properties::savePiecesPriorities(){ @@ -589,10 +589,12 @@ void properties::savePiecesPriorities(){
pieces_file.write(misc::toQByteArray(priority)+"\n");
}
pieces_file.close();
if(hasFilteredFiles && !BTSession->inFullAllocationMode(hash)){
// If h.has_filtered_pieces() s true, then the torrent
// is already in full allocation mode, no need to
// reload it.
if(hasFilteredFiles && !h.has_filtered_pieces()){
BTSession->pauseAndReloadTorrent(h);
}
BTSession->loadFilesPriorities(h);
emit filteredFilesChanged(hash);
has_filtered_files = hasFilteredFiles;
}

11
src/qtorrenthandle.cpp

@ -131,7 +131,7 @@ size_type QTorrentHandle::actual_size() const{ @@ -131,7 +131,7 @@ size_type QTorrentHandle::actual_size() const{
Q_ASSERT(h.is_valid());
size_type size = 0;
std::vector<int> piece_priorities = h.piece_priorities();
for(unsigned int i = 0; i<piece_priorities.size(); ++i){
for(unsigned int i = 0; i<piece_priorities.size(); ++i) {
if(piece_priorities[i])
size += h.get_torrent_info().piece_size(i);
}
@ -139,6 +139,15 @@ size_type QTorrentHandle::actual_size() const{ @@ -139,6 +139,15 @@ size_type QTorrentHandle::actual_size() const{
return size;
}
bool QTorrentHandle::has_filtered_pieces() const {
Q_ASSERT(h.is_valid());
std::vector<int> piece_priorities = h.piece_priorities();
for(unsigned int i = 0; i<piece_priorities.size(); ++i) {
if(!piece_priorities[i]) return true;
}
return false;
}
int QTorrentHandle::download_limit() const {
Q_ASSERT(h.is_valid());
return h.download_limit();

1
src/qtorrenthandle.h

@ -56,6 +56,7 @@ class QTorrentHandle { @@ -56,6 +56,7 @@ class QTorrentHandle {
QString current_tracker() const;
bool is_valid() const;
bool is_paused() const;
bool has_filtered_pieces() const;
// size_type total_size() const;
size_type total_done() const;
float download_payload_rate() const;

Loading…
Cancel
Save