1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-12 07:03:44 +00:00

Add function to return the progress of each file in a torrent.

This commit is contained in:
Josh Elsasser 2007-02-23 11:26:48 +00:00
parent 98ea79c579
commit efdc43ebb7
2 changed files with 57 additions and 1 deletions

View file

@ -501,6 +501,53 @@ void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
tr_lockUnlock( &tor->lock );
}
float * tr_torrentCompletion( tr_torrent_t * tor )
{
tr_info_t * inf = &tor->info;
int piece, file;
float * ret, prog, weight;
uint64_t piecemax, piecesize;
uint64_t filestart, fileoff, filelen, blockend, blockused;
tr_lockLock( &tor->lock );
ret = calloc( inf->fileCount, sizeof( float ) );
file = 0;
piecemax = inf->pieceSize;
filestart = 0;
fileoff = 0;
piece = 0;
while( inf->pieceCount > piece )
{
assert( file < inf->fileCount );
assert( filestart + fileoff < inf->totalSize );
filelen = inf->files[file].length;
piecesize = tr_pieceSize( piece );
blockend = MIN( filestart + filelen, piecemax * piece + piecesize );
blockused = blockend - ( filestart + fileoff );
weight = ( filelen ? ( float )blockused / ( float )filelen : 1.0 );
prog = tr_cpPercentBlocksInPiece( tor->completion, piece );
ret[file] += prog * weight;
fileoff += blockused;
assert( -0.1 < prog && 1.1 > prog );
assert( -0.1 < weight && 1.1 > weight );
if( fileoff == filelen )
{
filestart += fileoff;
fileoff = 0;
file++;
}
if( filestart + fileoff >= piecemax * piece + piecesize )
{
piece++;
}
}
tr_lockUnlock( &tor->lock );
return ret;
}
void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size )
{
int i, piece;

View file

@ -1,7 +1,7 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2005-2006 Transmission authors and contributors
* Copyright (c) 2005-2007 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@ -296,6 +296,15 @@ void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size );
/***********************************************************************
* tr_torrentCompletion
***********************************************************************
* Returns the completion progress for each file in the torrent as an
* array of floats the same size and order as in tr_info_t. Free the
* array when done.
**********************************************************************/
float * tr_torrentCompletion( tr_torrent_t * tor );
/***********************************************************************
* tr_torrentRemoveSaved
***********************************************************************