BUGFIX: Do not allocate space for unwanted files (preallocation mode)

This commit is contained in:
Christophe Dumez 2011-01-08 13:31:57 +00:00
parent 0d55befc1f
commit 3ccb2fddff
4 changed files with 61 additions and 5 deletions

View File

@ -12,6 +12,7 @@
- FEATURE: Added a search engine plugin for kickasstorrents.com
- FEATURE: Added auto-suspend upon downloads completion feature
- BUGFIX: Hide unwanted files that have to be partly downloaded
- BUGFIX: Do not allocate space for unwanted files (preallocation mode)
- I18N: Added Galician translation
- COSMETIC: Same deletion confirmation dialog in the GUI and Web UI
- COSMETIC: Simplified the top toolbar

View File

@ -932,7 +932,20 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
p.resume_data = &buf;
qDebug("Successfully loaded fast resume data");
}
} else {
// Generate fake resume data to make sure unwanted files
// are not allocated
if(preAllocateAll) {
vector<int> fp;
TorrentTempData::getFilesPriority(hash, fp);
if((int)fp.size() == t->num_files()) {
entry rd = generateFilePriorityResumeData(t, fp);
bencode(std::back_inserter(buf), rd);
p.resume_data = &buf;
}
}
}
QString savePath;
if(!from_url.isEmpty() && savepathLabel_fromurl.contains(QUrl::fromEncoded(from_url.toLocal8Bit()))) {
// Enforcing the save path defined before URL download (from RSS for example)
@ -1953,7 +1966,7 @@ void QBtSession::readAlerts() {
bool will_shutdown = (pref.shutdownWhenDownloadsComplete() ||
pref.shutdownqBTWhenDownloadsComplete() ||
pref.suspendWhenDownloadsComplete())
&& !hasDownloadingTorrents();
&& !hasDownloadingTorrents();
// AutoRun program
if(pref.isAutoRunEnabled())
autoRunExternalProgram(h, will_shutdown);
@ -2567,3 +2580,45 @@ void QBtSession::handleIPFilterError()
addConsoleMessage(tr("Error: Failed to parse the provided IP filter."), "red");
emit ipFilterParsed(true, 0);
}
entry QBtSession::generateFilePriorityResumeData(boost::intrusive_ptr<torrent_info> t, const std::vector<int> &fp)
{
entry::dictionary_type rd;
rd["file-format"] = "libtorrent resume file";
rd["file-version"] = 1;
rd["libtorrent-version"] = LIBTORRENT_VERSION;
rd["allocation"] = "full";
sha1_hash info_hash = t->info_hash();
rd["info-hash"] = std::string((char*)info_hash.begin(), (char*)info_hash.end());
// Priorities
entry::list_type priorities;
priorities.resize(fp.size());
for(uint i=0; i<fp.size(); ++i) {
priorities.push_back(entry(fp[i]));
}
rd["file_priority"] = entry(priorities);
// files sizes (useless but required)
entry::list_type sizes;
for(int i=0; i<t->num_files(); ++i) {
entry::list_type p;
p.push_back(entry(0));
p.push_back(entry(0));
sizes.push_back(entry(p));
}
rd["file sizes"] = entry(sizes);
// Slots
entry::list_type tslots;
for(int i=0; i<t->num_pieces(); ++i) {
tslots.push_back(-1);
}
rd["slots"] = entry(tslots);
entry::string_type pieces;
std::memset(&pieces[0], 0, t->num_pieces());
rd["pieces"] = entry(pieces);
entry ret(rd);
Q_ASSERT(ret.type() == entry::dictionary_t);
return ret;
}

View File

@ -167,6 +167,7 @@ private:
void loadTorrentSettings(QTorrentHandle h);
void loadTorrentTempData(QTorrentHandle h, QString savePath, bool magnet);
libtorrent::add_torrent_params initializeAddTorrentParams(QString hash);
libtorrent::entry generateFilePriorityResumeData(boost::intrusive_ptr<libtorrent::torrent_info> t, const std::vector<int> &fp);
private slots:
void addTorrentsFromScanFolder(QStringList&);

View File

@ -500,15 +500,14 @@ void QTorrentHandle::file_priority(int index, int priority) const {
}
}
// TODO: Also hide the folder on Windows
void QTorrentHandle::prioritize_files(const vector<int> &files) const {
if((int)files.size() != torrent_handle::get_torrent_info().num_files()) return;
const vector<int> prev_priorities = torrent_handle::file_priorities();
qDebug() << Q_FUNC_INFO;
bool was_seed = is_seed();
torrent_handle::prioritize_files(files);
for(uint i=0; i<files.size(); ++i) {
// Move unwanted files to a .unwanted subfolder
if(prev_priorities[i] > 0 && files[i] == 0) {
if(files[i] == 0) {
QString old_path = filepath_at(i);
QString old_name = filename_at(i);
QString parent_path = misc::branchPath(old_path);
@ -535,7 +534,7 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
}
}
// Move wanted files back to their original folder
if(prev_priorities[i] == 0 && files[i] > 0) {
if(files[i] > 0) {
QString old_path = filepath_at(i);
QString old_name = filename_at(i);
QDir parent_path(misc::branchPath(old_path));