Changeset 2362


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

remove more functions made obsolete by tr_torrentFile().

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-inspector.c

    r2325 r2362  
    10851085
    10861086static void
    1087 updateprogress( GtkTreeModel * model,
    1088                 GtkTreeStore * store,
    1089                 GtkTreeIter  * parent,
    1090                 const float  * progress,
    1091                 guint64      * setmeGotSize,
    1092                 guint64      * setmeTotalSize)
     1087updateprogress( GtkTreeModel   * model,
     1088                GtkTreeStore   * store,
     1089                GtkTreeIter    * parent,
     1090                tr_file_stat_t * fileStats,
     1091                guint64        * setmeGotSize,
     1092                guint64        * setmeTotalSize)
    10931093{
    10941094    GtkTreeIter iter;
     
    11021102        if (gtk_tree_model_iter_has_child( model, &iter ) )
    11031103        {
    1104             updateprogress( model, store, &iter, progress, &subGot, &subTotal);
     1104            updateprogress( model, store, &iter, fileStats, &subGot, &subTotal);
    11051105        }
    11061106        else
     
    11111111                                              -1 );
    11121112            g_assert( 0 <= index );
    1113             percent = (int)(progress[index]*100.0 + 0.5); /* [0...100] */
     1113            percent = (int)(fileStats[index].progress * 100.0 + 0.5); /* [0...100] */
    11141114            subGot = (guint64)(subTotal * percent/100.0);
    11151115        }
     
    14201420{
    14211421    guint64 foo, bar;
     1422    int fileCount = 0;
    14221423    FileData * data = (FileData*) g_object_get_data (G_OBJECT(top), "file-data");
    14231424    tr_torrent_t * tor = tr_torrent_handle( data->gtor );
    1424     float * progress = tr_torrentCompletion ( tor );
    1425     updateprogress (data->model, data->store, NULL, progress, &foo, &bar);
    1426     free( progress );
     1425    tr_file_stat_t * fileStats = tr_torrentFiles( tor, &fileCount );
     1426    updateprogress (data->model, data->store, NULL, fileStats, &foo, &bar);
     1427    tr_torrentFilesFree( fileStats, fileCount );
    14271428}
    14281429
  • 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
  • trunk/libtransmission/transmission.h

    r2361 r2362  
    440440
    441441/***********************************************************************
    442  * tr_torrentCompletion
    443  ***********************************************************************
    444  * Returns the completion progress for each file in the torrent as an
    445  * array of floats the same size and order as in tr_info_t. Free the
    446  * array when done.
    447  **********************************************************************/
    448 float * tr_torrentCompletion( const tr_torrent_t * );
    449 
    450 float tr_torrentFileCompletion( const tr_torrent_t *, int fileIndex );
    451 
    452 uint64_t tr_torrentFileBytesCompleted( const tr_torrent_t *, int fileIndex );
    453 
    454 
    455 /***********************************************************************
    456442 * tr_torrentRemoveSaved
    457443 ***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.