replace tr_torrentGetFileStatus() with tr_torrentFiles() for BMW

This commit is contained in:
Charles Kerr 2007-07-15 20:05:32 +00:00
parent 321b01d430
commit 59459feb26
2 changed files with 66 additions and 28 deletions

View File

@ -630,6 +630,52 @@ tr_torrentStat( tr_torrent_t * tor )
return s;
}
/***
****
***/
tr_file_stat_t *
tr_torrentFiles( const tr_torrent_t * tor, int * fileCount )
{
int i;
const int n = tor->info.fileCount;
tr_file_stat_t * files = tr_new0( tr_file_stat_t, n );
tr_file_stat_t * walk = files;
for( i=0; i<n; ++i, ++walk )
{
const uint64_t length = tor->info.files[i].length;
cp_status_t cp;
walk->bytesCompleted = tr_torrentFileBytesCompleted( tor, i );
walk->progress = walk->bytesCompleted / (float)length;
if( walk->bytesCompleted >= length )
cp = TR_CP_COMPLETE;
else if( tor->info.files[i].dnd )
cp = TR_CP_DONE;
else
cp = TR_CP_INCOMPLETE;
walk->completionStatus = cp;
}
*fileCount = n;
return files;
}
void
tr_torrentFilesFree( tr_file_stat_t * files, int fileCount UNUSED )
{
tr_free( files );
}
/***
****
***/
tr_peer_stat_t *
tr_torrentPeers( const tr_torrent_t * tor, int * peerCount )
{
@ -1281,18 +1327,3 @@ tr_torrentSetFileDLs ( tr_torrent_t * tor,
tr_torrentWriterUnlock( tor );
}
cp_status_t
tr_torrentGetFileStatus( const tr_torrent_t * tor, int fileIndex )
{
const uint64_t bytes = tr_torrentFileBytesCompleted( tor, fileIndex );
const tr_file_t * file = &tor->info.files[fileIndex];
if( bytes >= file->length )
return TR_CP_COMPLETE;
if( file->dnd )
return TR_CP_DONE;
return TR_CP_INCOMPLETE;
}

View File

@ -245,19 +245,6 @@ void tr_torrentSetFileDLs ( tr_torrent_t * tor,
/* single-file form of tr_torrentSetFileDLs */
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
***********************************************************************
@ -434,6 +421,11 @@ typedef struct tr_peer_stat_s tr_peer_stat_t;
tr_peer_stat_t * tr_torrentPeers( const tr_torrent_t *, int * peerCount );
void tr_torrentPeersFree( tr_peer_stat_t *, int peerCount );
typedef struct tr_file_stat_s tr_file_stat_t;
tr_file_stat_t * tr_torrentFiles( const tr_torrent_t *, int * fileCount );
void tr_torrentFilesFree( tr_file_stat_t *, int fileCount );
/***********************************************************************
* tr_torrentAvailability
***********************************************************************
@ -562,6 +554,14 @@ torrent_status_t;
#define TR_STATUS_INACTIVE \
(TR_STATUS_STOPPING|TR_STATUS_STOPPED)
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;
/***********************************************************************
* tr_stat_s
**********************************************************************/
@ -603,6 +603,13 @@ struct tr_stat_s
uint64_t activityDate;
};
struct tr_file_stat_s
{
uint64_t bytesCompleted;
float progress;
cp_status_t completionStatus;
};
struct tr_peer_stat_s
{
char addr[INET_ADDRSTRLEN];