Changeset 1508


Ignore:
Timestamp:
Feb 23, 2007, 11:26:48 AM (15 years ago)
Author:
joshe
Message:

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

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r1452 r1508  
    502502}
    503503
     504float * tr_torrentCompletion( tr_torrent_t * tor )
     505{
     506    tr_info_t * inf = &tor->info;
     507    int         piece, file;
     508    float     * ret, prog, weight;
     509    uint64_t    piecemax, piecesize;
     510    uint64_t    filestart, fileoff, filelen, blockend, blockused;
     511
     512    tr_lockLock( &tor->lock );
     513
     514    ret       = calloc( inf->fileCount, sizeof( float ) );
     515    file      = 0;
     516    piecemax  = inf->pieceSize;
     517    filestart = 0;
     518    fileoff   = 0;
     519    piece     = 0;
     520    while( inf->pieceCount > piece )
     521    {
     522        assert( file < inf->fileCount );
     523        assert( filestart + fileoff < inf->totalSize );
     524        filelen    = inf->files[file].length;
     525        piecesize  = tr_pieceSize( piece );
     526        blockend   = MIN( filestart + filelen, piecemax * piece + piecesize );
     527        blockused  = blockend - ( filestart + fileoff );
     528        weight     = ( filelen ? ( float )blockused / ( float )filelen : 1.0 );
     529        prog       = tr_cpPercentBlocksInPiece( tor->completion, piece );
     530        ret[file] += prog * weight;
     531        fileoff   += blockused;
     532        assert( -0.1 < prog   && 1.1 > prog );
     533        assert( -0.1 < weight && 1.1 > weight );
     534        if( fileoff == filelen )
     535        {
     536            filestart += fileoff;
     537            fileoff    = 0;
     538            file++;
     539        }
     540        if( filestart + fileoff >= piecemax * piece + piecesize )
     541        {
     542            piece++;
     543        }
     544    }
     545
     546    tr_lockUnlock( &tor->lock );
     547
     548    return ret;
     549}
     550
    504551void tr_torrentAmountFinished( tr_torrent_t * tor, float * tab, int size )
    505552{
  • trunk/libtransmission/transmission.h

    r1462 r1508  
    22 * $Id$
    33 *
    4  * Copyright (c) 2005-2006 Transmission authors and contributors
     4 * Copyright (c) 2005-2007 Transmission authors and contributors
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a
     
    298298
    299299/***********************************************************************
     300 * tr_torrentCompletion
     301 ***********************************************************************
     302 * Returns the completion progress for each file in the torrent as an
     303 * array of floats the same size and order as in tr_info_t. Free the
     304 * array when done.
     305 **********************************************************************/
     306float * tr_torrentCompletion( tr_torrent_t * tor );
     307
     308/***********************************************************************
    300309 * tr_torrentRemoveSaved
    301310 ***********************************************************************
Note: See TracChangeset for help on using the changeset viewer.