|
|
|
@ -254,9 +254,9 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
@@ -254,9 +254,9 @@ size_type QTorrentHandle::filesize_at(unsigned int index) const {
|
|
|
|
|
|
|
|
|
|
QString QTorrentHandle::filepath_at(unsigned int index) const { |
|
|
|
|
#if LIBTORRENT_VERSION_NUM < 10000 |
|
|
|
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::get_torrent_info().files().file_path(index))); |
|
|
|
|
return filepath_at(torrent_handle::get_torrent_info(), index); |
|
|
|
|
#else |
|
|
|
|
return fsutils::fromNativePath(misc::toQStringU(torrent_handle::torrent_file()->files().file_path(index))); |
|
|
|
|
return filepath_at(*torrent_handle::torrent_file(), index); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -517,10 +517,12 @@ void QTorrentHandle::file_priority(int index, int priority) const {
@@ -517,10 +517,12 @@ void QTorrentHandle::file_priority(int index, int priority) const {
|
|
|
|
|
|
|
|
|
|
void QTorrentHandle::prioritize_files(const vector<int> &files) const { |
|
|
|
|
#if LIBTORRENT_VERSION_NUM < 10000 |
|
|
|
|
if ((int)files.size() != torrent_handle::get_torrent_info().num_files()) return; |
|
|
|
|
torrent_info const& info = torrent_handle::get_torrent_info(); |
|
|
|
|
#else |
|
|
|
|
if ((int)files.size() != torrent_handle::torrent_file()->num_files()) return; |
|
|
|
|
boost::intrusive_ptr<torrent_info const> info_ptr = torrent_handle::torrent_file(); |
|
|
|
|
torrent_info const& info = *info_ptr; |
|
|
|
|
#endif |
|
|
|
|
if ((int)files.size() != info.num_files()) return; |
|
|
|
|
qDebug() << Q_FUNC_INFO; |
|
|
|
|
bool was_seed = is_seed(); |
|
|
|
|
qDebug() << Q_FUNC_INFO << "Changing files priorities..."; |
|
|
|
@ -530,14 +532,15 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
@@ -530,14 +532,15 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
|
|
|
|
QString spath = save_path(); |
|
|
|
|
|
|
|
|
|
for (uint i = 0; i < files.size(); ++i) { |
|
|
|
|
QString filepath = filepath_at(info, i); |
|
|
|
|
// Move unwanted files to a .unwanted subfolder
|
|
|
|
|
if (files[i] == 0) { |
|
|
|
|
QString old_abspath = QDir(spath).absoluteFilePath(filepath_at(i)); |
|
|
|
|
QString old_abspath = QDir(spath).absoluteFilePath(filepath); |
|
|
|
|
QString parent_abspath = fsutils::branchPath(old_abspath); |
|
|
|
|
// Make sure the file does not already exists
|
|
|
|
|
if (QDir(parent_abspath).dirName() != ".unwanted") { |
|
|
|
|
QString unwanted_abspath = parent_abspath+"/.unwanted"; |
|
|
|
|
QString new_abspath = unwanted_abspath+"/"+filename_at(i); |
|
|
|
|
QString new_abspath = unwanted_abspath+"/"+fsutils::fileName(filepath); |
|
|
|
|
qDebug() << "Unwanted path is" << unwanted_abspath; |
|
|
|
|
if (QFile::exists(new_abspath)) { |
|
|
|
|
qWarning() << "File" << new_abspath << "already exists at destination."; |
|
|
|
@ -557,17 +560,17 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
@@ -557,17 +560,17 @@ void QTorrentHandle::prioritize_files(const vector<int> &files) const {
|
|
|
|
|
#else |
|
|
|
|
Q_UNUSED(created); |
|
|
|
|
#endif |
|
|
|
|
QString parent_path = fsutils::branchPath(filepath_at(i)); |
|
|
|
|
QString parent_path = fsutils::branchPath(filepath); |
|
|
|
|
if (!parent_path.isEmpty() && !parent_path.endsWith("/")) |
|
|
|
|
parent_path += "/"; |
|
|
|
|
rename_file(i, parent_path+".unwanted/"+filename_at(i)); |
|
|
|
|
rename_file(i, parent_path+".unwanted/"+fsutils::fileName(filepath)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Move wanted files back to their original folder
|
|
|
|
|
if (files[i] > 0) { |
|
|
|
|
QString parent_relpath = fsutils::branchPath(filepath_at(i)); |
|
|
|
|
QString parent_relpath = fsutils::branchPath(filepath); |
|
|
|
|
if (QDir(parent_relpath).dirName() == ".unwanted") { |
|
|
|
|
QString old_name = filename_at(i); |
|
|
|
|
QString old_name = fsutils::fileName(filepath); |
|
|
|
|
QString new_relpath = fsutils::branchPath(parent_relpath); |
|
|
|
|
if (new_relpath.isEmpty()) |
|
|
|
|
rename_file(i, old_name); |
|
|
|
@ -673,3 +676,8 @@ float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
@@ -673,3 +676,8 @@ float QTorrentHandle::progress(const libtorrent::torrent_status &status) {
|
|
|
|
|
Q_ASSERT(progress >= 0.f && progress <= 1.f); |
|
|
|
|
return progress; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString QTorrentHandle::filepath_at(const libtorrent::torrent_info &info, unsigned int index) { |
|
|
|
|
return fsutils::fromNativePath(misc::toQStringU(info.files().file_path(index))); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|