From 2dabe5ce3437393666d5f9ea34cf23b163349f76 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sun, 1 Mar 2009 23:48:04 +0000 Subject: [PATCH] move the percent to the stop ratio into libtransmission --- libtransmission/torrent.c | 14 +++++++++++--- libtransmission/transmission.h | 5 +++++ macosx/Torrent.m | 9 +-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index ed874132f..146a5e6b4 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -804,6 +804,7 @@ tr_torrentStat( tr_torrent * tor ) int usableSeeds = 0; uint64_t now; double downloadedForRatio, seedRatio; + tr_bool checkSeedRatio; if( !tor ) return NULL; @@ -861,7 +862,6 @@ tr_torrentStat( tr_torrent * tor ) (double) tor->info.pieceCount ) : 0.0; - s->activityDate = tor->activityDate; s->addedDate = tor->addedDate; s->doneDate = tor->doneDate; @@ -896,6 +896,8 @@ tr_torrentStat( tr_torrent * tor ) downloadedForRatio = s->downloadedEver ? s->downloadedEver : s->haveValid; s->ratio = tr_getRatio( s->uploadedEver, downloadedForRatio ); + checkSeedRatio = tr_torrentGetSeedRatio( tor, &seedRatio ); + switch( s->activity ) { case TR_STATUS_DOWNLOAD: @@ -908,7 +910,7 @@ tr_torrentStat( tr_torrent * tor ) break; case TR_STATUS_SEED: - if( tr_torrentGetSeedRatio( tor, &seedRatio ) ) + if( checkSeedRatio ) { if( s->pieceUploadSpeed < 0.1 ) s->eta = TR_ETA_UNKNOWN; @@ -924,6 +926,13 @@ tr_torrentStat( tr_torrent * tor ) break; } + if ( !checkSeedRatio || s->ratio >= seedRatio || s->ratio == TR_RATIO_INF ) + s->percentRatio = 1.0; + else if ( s->ratio == TR_RATIO_NA ) + s->percentRatio = 0.0; + else + s->percentRatio = s->ratio / seedRatio; + tr_torrentUnlock( tor ); return s; @@ -2148,7 +2157,6 @@ tr_torrentCheckSeedRatio( tr_torrent * tor ) /* maybe notify the client */ if( tor->ratio_limit_hit_func != NULL ) tor->ratio_limit_hit_func( tor, tor->ratio_limit_hit_func_user_data ); - } } } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 42a8ffd90..7c4c7f701 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -1314,6 +1314,11 @@ typedef struct tr_stat Range is [0..1] @see tr_stat.leftUntilDone */ float percentDone; + + /** The percentage of the actual ratio to the seed ratio. This will be + equal to 1 if the ratio is reached or the torrent is set to seed forever. + Range is [0..1] */ + float percentRatio; /** Speed all data being sent for this torrent. (KiB/s) This includes piece data, protocol messages, and TCP overhead */ diff --git a/macosx/Torrent.m b/macosx/Torrent.m index a0f1298d5..049d314e7 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -387,16 +387,9 @@ int trashDataFile(const char * filename) return tr_torrentGetSeedRatio(fHandle, NULL); } -#warning move to libtransmission - (CGFloat) progressStopRatio { - double stopRatio, ratio; - if (!tr_torrentGetSeedRatio(fHandle, &stopRatio) || (ratio = [self ratio]) >= stopRatio) - return 1.0; - else if (stopRatio > 0.0) - return ratio / stopRatio; - else - return 0.0; + return fStat->percentRatio; } - (tr_speedlimit) speedMode: (BOOL) upload