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