Ignore:
Timestamp:
Jul 15, 2007, 8:29:57 PM (15 years ago)
Author:
charles
Message:

remove more functions made obsolete by tr_torrentFile().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r2361 r2362  
    635635***/
    636636
     637static uint64_t
     638fileBytesCompleted ( const tr_torrent_t * tor, int fileIndex )
     639{
     640    const tr_file_t * file     =  &tor->info.files[fileIndex];
     641    const uint64_t firstBlock       =  file->offset / tor->blockSize;
     642    const uint64_t firstBlockOffset =  file->offset % tor->blockSize;
     643    const uint64_t lastOffset       =  file->length ? (file->length-1) : 0;
     644    const uint64_t lastBlock        = (file->offset + lastOffset) / tor->blockSize;
     645    const uint64_t lastBlockOffset  = (file->offset + lastOffset) % tor->blockSize;
     646    uint64_t haveBytes = 0;
     647
     648    assert( tor != NULL );
     649    assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
     650    assert( file->offset + file->length <= tor->info.totalSize );
     651    assert( (int)firstBlock < tor->blockCount );
     652    assert( (int)lastBlock < tor->blockCount );
     653    assert( firstBlock <= lastBlock );
     654    assert( tr_blockPiece( firstBlock ) == file->firstPiece );
     655    assert( tr_blockPiece( lastBlock ) == file->lastPiece );
     656
     657    if( firstBlock == lastBlock )
     658    {
     659        if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     660            haveBytes += lastBlockOffset + 1 - firstBlockOffset;
     661    }
     662    else
     663    {
     664        uint64_t i;
     665
     666        if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     667            haveBytes += tor->blockSize - firstBlockOffset;
     668
     669        for( i=firstBlock+1; i<lastBlock; ++i )
     670            if( tr_cpBlockIsComplete( tor->completion, i ) )
     671               haveBytes += tor->blockSize;
     672
     673        if( tr_cpBlockIsComplete( tor->completion, lastBlock ) )
     674            haveBytes += lastBlockOffset + 1;
     675    }
     676
     677    return haveBytes;
     678}
     679
    637680tr_file_stat_t *
    638681tr_torrentFiles( const tr_torrent_t * tor, int * fileCount )
     
    648691        cp_status_t cp;
    649692
    650         walk->bytesCompleted = tr_torrentFileBytesCompleted( tor, i );
    651 
    652         walk->progress = walk->bytesCompleted / (float)length;
     693        walk->bytesCompleted = fileBytesCompleted( tor, i );
     694
     695        walk->progress = length
     696            ? walk->bytesCompleted / (float)length
     697            : 1.0;
    653698
    654699        if( walk->bytesCompleted >= length )
     
    756801
    757802    tr_torrentReaderUnlock( tor );
    758 }
    759 
    760 uint64_t
    761 tr_torrentFileBytesCompleted ( const tr_torrent_t * tor, int fileIndex )
    762 {
    763     const tr_file_t * file     =  &tor->info.files[fileIndex];
    764     const uint64_t firstBlock       =  file->offset / tor->blockSize;
    765     const uint64_t firstBlockOffset =  file->offset % tor->blockSize;
    766     const uint64_t lastOffset       =  file->length ? (file->length-1) : 0;
    767     const uint64_t lastBlock        = (file->offset + lastOffset) / tor->blockSize;
    768     const uint64_t lastBlockOffset  = (file->offset + lastOffset) % tor->blockSize;
    769     uint64_t haveBytes = 0;
    770 
    771     assert( tor != NULL );
    772     assert( 0<=fileIndex && fileIndex<tor->info.fileCount );
    773     assert( file->offset + file->length <= tor->info.totalSize );
    774     assert( (int)firstBlock < tor->blockCount );
    775     assert( (int)lastBlock < tor->blockCount );
    776     assert( firstBlock <= lastBlock );
    777     assert( tr_blockPiece( firstBlock ) == file->firstPiece );
    778     assert( tr_blockPiece( lastBlock ) == file->lastPiece );
    779 
    780     if( firstBlock == lastBlock )
    781     {
    782         if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
    783             haveBytes += lastBlockOffset + 1 - firstBlockOffset;
    784     }
    785     else
    786     {
    787         uint64_t i;
    788 
    789         if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
    790             haveBytes += tor->blockSize - firstBlockOffset;
    791 
    792         for( i=firstBlock+1; i<lastBlock; ++i )
    793             if( tr_cpBlockIsComplete( tor->completion, i ) )
    794                haveBytes += tor->blockSize;
    795 
    796         if( tr_cpBlockIsComplete( tor->completion, lastBlock ) )
    797             haveBytes += lastBlockOffset + 1;
    798     }
    799 
    800     return haveBytes;
    801 }
    802 
    803 float
    804 tr_torrentFileCompletion ( const tr_torrent_t * tor, int fileIndex )
    805 {
    806     const uint64_t c = tr_torrentFileBytesCompleted ( tor, fileIndex );
    807     uint64_t length = tor->info.files[fileIndex].length;
    808    
    809     if( !length )
    810         return 1.0;
    811     return (double)c / length;
    812 }
    813 
    814 float*
    815 tr_torrentCompletion( const tr_torrent_t * tor )
    816 {
    817     int i;
    818     float * f;
    819     tr_torrentReaderLock( tor );
    820 
    821     f = tr_new0( float, tor->info.fileCount );
    822     for( i=0; i<tor->info.fileCount; ++i )
    823        f[i] = tr_torrentFileCompletion ( tor, i );
    824 
    825     tr_torrentReaderUnlock( tor );
    826     return f;
    827803}
    828804
Note: See TracChangeset for help on using the changeset viewer.