diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 241b6c9b5..65915b360 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -1265,3 +1265,30 @@ tr_torrentSetFileDLs ( tr_torrent_t * tor, tr_torrentWriterUnlock( tor ); } + +cp_status_t +tr_torrentGetFileStatus( const tr_torrent_t * tor, int fileIndex ) +{ + int i; + int isComplete; + const tr_file_t * file; + + assert( tor != NULL ); + assert( 0<=fileIndex ); + assert( fileIndexinfo.fileCount ); + + file = &tor->info.files[fileIndex]; + + isComplete = TRUE; + for( i=file->firstPiece; isComplete && i<=file->lastPiece; ++i ) + if( !tr_cpPieceIsComplete( tor->completion, i ) ) + isComplete = FALSE; + + if( isComplete ) + return TR_CP_COMPLETE; + + if( file->dnd ) + return TR_CP_DONE; + + return TR_CP_INCOMPLETE; +} diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 9d13b482e..422e26d63 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -246,6 +246,18 @@ void tr_torrentSetFileDLs ( tr_torrent_t * tor, void tr_torrentSetFileDL( tr_torrent_t *, int file, int do_download ); +typedef enum +{ + TR_CP_INCOMPLETE, /* doesn't have all the desired pieces */ + TR_CP_DONE, /* has all the pieces but the DND ones */ + TR_CP_COMPLETE /* has every piece */ +} +cp_status_t; + +cp_status_t tr_torrentGetFileStatus( const tr_torrent_t * tor, + int fileIndex ); + + /*********************************************************************** * tr_torrentRates *********************************************************************** @@ -534,14 +546,6 @@ struct tr_info_s tr_file_t * files; }; -typedef enum -{ - TR_CP_INCOMPLETE, /* doesn't have all the desired pieces */ - TR_CP_DONE, /* has all the pieces but the DND ones */ - TR_CP_COMPLETE /* has every piece */ -} -cp_status_t; - typedef enum { TR_STATUS_CHECK_WAIT = (1<<0), /* Waiting in queue to check files */