diff --git a/macosx/Controller.m b/macosx/Controller.m index 25f3a9f82..5c28cecdd 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -485,7 +485,8 @@ static void sleepCallBack(void * controller, io_service_t y, natural_t messageTy enumerator = [fTorrents objectEnumerator]; Torrent * torrent; - while (!timeUp && ((torrent = [enumerator nextObject]) || tr_handleStatus(fLib)->natTraversalStatus != TR_NAT_TRAVERSAL_DISABLED)) + while (!timeUp && ((torrent = [enumerator nextObject]) + || tr_handleStatus(fLib)->natTraversalStatus != TR_NAT_TRAVERSAL_DISABLED)) while (![torrent isPaused] && !(timeUp = [start timeIntervalSinceNow] < -5.0)) { usleep(100000); diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 0baac579a..1adb2d33f 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1342,22 +1342,36 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 index = (int)indexValue; } + free(piecesAvailablity); + //determine percentage finished and available - float * piecesFinished = malloc(pieceCount * sizeof(float)); - [self getAmountFinished: piecesFinished size: pieceCount]; - - float finished = 0, available = 0; - for (i = 0; i < pieceCount; i++) + int have, avail; + if ([self progress] >= 1.0) { - finished += piecesFinished[i]; - if (piecesAvailablity[i] > 0) - available += 1.0 - piecesFinished[i]; + have = MAX_PIECES; + avail = 0; } - - int have = rintf((float)MAX_PIECES * finished / (float)pieceCount), + else if (![self isActive]) + { + have = rintf((float)MAX_PIECES * [self progress]); + avail = 0; + } + else + { + float * piecesFinished = malloc(pieceCount * sizeof(float)); + [self getAmountFinished: piecesFinished size: pieceCount]; + + float available = 0; + for (i = 0; i < pieceCount; i++) + available += 1.0 - piecesFinished[i]; + + have = rintf((float)MAX_PIECES * [self progress]); avail = rintf((float)MAX_PIECES * available / (float)pieceCount); - if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available - avail--; + if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available + avail--; + + free(piecesFinished); + } //first two lines: dark blue to show progression, green to show available p = (uint32_t *)bitmapData; @@ -1377,9 +1391,6 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 p[i + bytesPerRow / 4] = kWhite; } - free(piecesAvailablity); - free(piecesFinished); - //actually draw image NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]]; [bar addRepresentation: fBitmap];