2006-07-16 19:39:23 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2007-04-03 02:22:25 +00:00
|
|
|
* Copyright (c) 2006-2007 Transmission authors and contributors
|
2006-07-16 19:39:23 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "Torrent.h"
|
|
|
|
#import "StringAdditions.h"
|
|
|
|
|
2006-09-12 00:08:30 +00:00
|
|
|
#define BAR_HEIGHT 12.0
|
|
|
|
|
2006-10-05 21:21:30 +00:00
|
|
|
#define MAX_PIECES 324
|
|
|
|
#define BLANK_PIECE -99
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
@interface Torrent (Private)
|
|
|
|
|
|
|
|
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
|
2006-11-05 19:08:38 +00:00
|
|
|
publicTorrent: (NSNumber *) publicTorrent
|
2007-03-31 01:00:51 +00:00
|
|
|
dateAdded: (NSDate *) dateAdded dateCompleted: (NSDate *) dateCompleted
|
2007-02-02 17:54:24 +00:00
|
|
|
ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
|
2006-12-28 00:29:05 +00:00
|
|
|
limitSpeedCustom: (NSNumber *) limitCustom
|
2006-12-27 02:57:55 +00:00
|
|
|
checkUpload: (NSNumber *) checkUpload uploadLimit: (NSNumber *) uploadLimit
|
|
|
|
checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit
|
2007-03-31 20:08:10 +00:00
|
|
|
pex: (NSNumber *) pex
|
2006-12-27 02:57:55 +00:00
|
|
|
waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-02-23 13:40:30 +00:00
|
|
|
- (void) createFileList;
|
2007-01-17 23:19:53 +00:00
|
|
|
- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
|
2007-01-18 03:54:56 +00:00
|
|
|
withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
|
2007-02-23 13:40:30 +00:00
|
|
|
fileSize: (uint64_t) size state: (int) state flatList: (NSMutableArray *) flatList;
|
2006-09-12 00:08:30 +00:00
|
|
|
- (NSImage *) advancedBar;
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) trashFile: (NSString *) path;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Torrent
|
|
|
|
|
2006-09-12 00:08:30 +00:00
|
|
|
// Used to optimize drawing. They contain packed RGBA pixels for every color needed.
|
|
|
|
#define BE OSSwapBigToHostConstInt32
|
|
|
|
|
|
|
|
static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
|
2006-10-06 20:45:59 +00:00
|
|
|
kBlue = BE(0x50A0FFFF), //80, 160, 255
|
|
|
|
kBlue2 = BE(0x1E46B4FF), //30, 70, 180
|
2006-09-25 18:37:45 +00:00
|
|
|
kGray = BE(0x969696FF), //150, 150, 150
|
2006-10-06 20:45:59 +00:00
|
|
|
kGreen1 = BE(0x99FFCCFF), //153, 255, 204
|
|
|
|
kGreen2 = BE(0x66FF99FF), //102, 255, 153
|
|
|
|
kGreen3 = BE(0x00FF66FF), //0, 255, 102
|
2006-09-12 00:56:37 +00:00
|
|
|
kWhite = BE(0xFFFFFFFF); //255, 255, 255
|
2006-09-12 00:08:30 +00:00
|
|
|
|
2006-11-13 04:05:24 +00:00
|
|
|
- (id) initWithPath: (NSString *) path forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2006-11-13 04:05:24 +00:00
|
|
|
self = [self initWithHash: nil path: path lib: lib
|
|
|
|
publicTorrent: delete ? [NSNumber numberWithBool: NO] : nil
|
2007-03-31 01:00:51 +00:00
|
|
|
dateAdded: nil dateCompleted: nil
|
2007-02-02 18:11:37 +00:00
|
|
|
ratioSetting: nil ratioLimit: nil
|
2006-12-28 00:29:05 +00:00
|
|
|
limitSpeedCustom: nil
|
2006-12-27 02:57:55 +00:00
|
|
|
checkUpload: nil uploadLimit: nil
|
|
|
|
checkDownload: nil downloadLimit: nil
|
2007-03-31 20:08:10 +00:00
|
|
|
pex: nil
|
2006-12-27 02:57:55 +00:00
|
|
|
waitToStart: nil orderValue: nil];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2006-11-03 16:01:45 +00:00
|
|
|
fUseIncompleteFolder = [fDefaults boolForKey: @"UseIncompleteDownloadFolder"];
|
2007-04-19 06:05:32 +00:00
|
|
|
fIncompleteFolder = [[[fDefaults stringForKey: @"IncompleteDownloadFolder"] stringByExpandingTildeInPath] retain];
|
2006-11-03 16:01:45 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
if (!fPublicTorrent)
|
|
|
|
[self trashFile: path];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib
|
|
|
|
{
|
|
|
|
self = [self initWithHash: [history objectForKey: @"TorrentHash"]
|
|
|
|
path: [history objectForKey: @"TorrentPath"] lib: lib
|
|
|
|
publicTorrent: [history objectForKey: @"PublicCopy"]
|
2007-03-30 18:58:18 +00:00
|
|
|
dateAdded: [history objectForKey: @"Date"]
|
2007-03-31 01:00:51 +00:00
|
|
|
dateCompleted: [history objectForKey: @"DateCompleted"]
|
2007-02-02 17:54:24 +00:00
|
|
|
ratioSetting: [history objectForKey: @"RatioSetting"]
|
2006-07-16 19:39:23 +00:00
|
|
|
ratioLimit: [history objectForKey: @"RatioLimit"]
|
2006-12-28 00:29:05 +00:00
|
|
|
limitSpeedCustom: [history objectForKey: @"LimitSpeedCustom"]
|
2006-12-27 02:57:55 +00:00
|
|
|
checkUpload: [history objectForKey: @"CheckUpload"]
|
|
|
|
uploadLimit: [history objectForKey: @"UploadLimit"]
|
|
|
|
checkDownload: [history objectForKey: @"CheckDownload"]
|
|
|
|
downloadLimit: [history objectForKey: @"DownloadLimit"]
|
2007-03-31 20:08:10 +00:00
|
|
|
pex: [history objectForKey: @"Pex"]
|
2006-07-16 19:39:23 +00:00
|
|
|
waitToStart: [history objectForKey: @"WaitToStart"]
|
|
|
|
orderValue: [history objectForKey: @"OrderValue"]];
|
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2006-11-03 16:01:45 +00:00
|
|
|
//download folders
|
2006-07-16 19:39:23 +00:00
|
|
|
NSString * downloadFolder;
|
|
|
|
if (!(downloadFolder = [history objectForKey: @"DownloadFolder"]))
|
|
|
|
downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
|
2006-11-03 16:01:45 +00:00
|
|
|
|
|
|
|
NSNumber * useIncompleteFolder;
|
|
|
|
if ((useIncompleteFolder = [history objectForKey: @"UseIncompleteFolder"]))
|
|
|
|
{
|
|
|
|
if ((fUseIncompleteFolder = [useIncompleteFolder boolValue]))
|
|
|
|
{
|
|
|
|
NSString * incompleteFolder;
|
|
|
|
if (incompleteFolder = [history objectForKey: @"IncompleteFolder"])
|
2007-01-15 04:09:56 +00:00
|
|
|
fIncompleteFolder = [incompleteFolder retain];
|
2006-11-03 16:01:45 +00:00
|
|
|
else
|
|
|
|
fIncompleteFolder = [[[fDefaults stringForKey: @"IncompleteDownloadFolder"]
|
2007-01-15 04:09:56 +00:00
|
|
|
stringByExpandingTildeInPath] retain];
|
2006-11-03 16:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fUseIncompleteFolder = NO;
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
[self setDownloadFolder: downloadFolder];
|
2007-03-28 12:53:45 +00:00
|
|
|
|
|
|
|
//start transfer
|
|
|
|
BOOL start = YES;
|
|
|
|
NSNumber * active;
|
2006-07-16 19:39:23 +00:00
|
|
|
NSString * paused;
|
2007-03-28 12:53:45 +00:00
|
|
|
if ((active = [history objectForKey: @"Active"]))
|
|
|
|
start = [active boolValue];
|
|
|
|
else if ((paused = [history objectForKey: @"Paused"])) //old way of storing if active
|
|
|
|
start = [paused isEqualToString: @"NO"];
|
|
|
|
else;
|
|
|
|
|
|
|
|
if (start)
|
2006-09-28 23:32:59 +00:00
|
|
|
{
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
2006-09-28 00:48:07 +00:00
|
|
|
[self startTransfer];
|
2006-09-28 23:32:59 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) history
|
|
|
|
{
|
|
|
|
NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",
|
2006-11-05 19:08:38 +00:00
|
|
|
[self hashString], @"TorrentHash",
|
2006-11-03 16:01:45 +00:00
|
|
|
fDownloadFolder, @"DownloadFolder",
|
|
|
|
[NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
|
2007-03-28 12:53:45 +00:00
|
|
|
[NSNumber numberWithBool: [self isActive]], @"Active",
|
2007-03-30 18:58:18 +00:00
|
|
|
[self dateAdded], @"Date",
|
2007-02-09 02:34:30 +00:00
|
|
|
[NSNumber numberWithInt: fRatioSetting], @"RatioSetting",
|
2006-07-16 19:39:23 +00:00
|
|
|
[NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",
|
2007-02-02 17:33:32 +00:00
|
|
|
[NSNumber numberWithInt: fCheckUpload], @"CheckUpload",
|
2006-12-27 02:57:55 +00:00
|
|
|
[NSNumber numberWithInt: fUploadLimit], @"UploadLimit",
|
2007-02-02 17:33:32 +00:00
|
|
|
[NSNumber numberWithInt: fCheckDownload], @"CheckDownload",
|
2006-12-27 02:57:55 +00:00
|
|
|
[NSNumber numberWithInt: fDownloadLimit], @"DownloadLimit",
|
2006-07-16 19:39:23 +00:00
|
|
|
[NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
|
|
|
|
[self orderValue], @"OrderValue", nil];
|
2006-11-03 16:01:45 +00:00
|
|
|
|
|
|
|
if (fUseIncompleteFolder)
|
|
|
|
[history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
if (fPublicTorrent)
|
|
|
|
[history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"];
|
2007-03-31 01:00:51 +00:00
|
|
|
|
2007-03-31 20:08:10 +00:00
|
|
|
if (![self privateTorrent])
|
|
|
|
[history setObject: [NSNumber numberWithBool: fPex] forKey: @"Pex"];
|
|
|
|
|
2007-03-31 01:00:51 +00:00
|
|
|
if (fDateCompleted)
|
|
|
|
[history setObject: [self dateAdded] forKey: @"DateCompleted"];
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
return history;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
if (fHandle)
|
|
|
|
{
|
|
|
|
tr_torrentClose(fLib, fHandle);
|
|
|
|
|
2006-11-03 16:01:45 +00:00
|
|
|
if (fDownloadFolder)
|
|
|
|
[fDownloadFolder release];
|
|
|
|
if (fIncompleteFolder)
|
|
|
|
[fIncompleteFolder release];
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
if (fPublicTorrentLocation)
|
|
|
|
[fPublicTorrentLocation release];
|
|
|
|
|
2006-12-26 22:33:02 +00:00
|
|
|
tr_torrentRemoveSaved(fHandle);
|
|
|
|
|
2007-03-30 18:58:18 +00:00
|
|
|
[fDateAdded release];
|
2007-03-31 01:00:51 +00:00
|
|
|
if (fDateCompleted)
|
|
|
|
[fDateCompleted release];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-12-26 21:02:00 +00:00
|
|
|
if (fAnnounceDate)
|
|
|
|
[fAnnounceDate release];
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
[fIcon release];
|
|
|
|
[fIconFlipped release];
|
|
|
|
[fIconSmall release];
|
|
|
|
|
|
|
|
[fProgressString release];
|
|
|
|
[fStatusString release];
|
|
|
|
[fShortStatusString release];
|
2006-07-25 00:59:14 +00:00
|
|
|
[fRemainingTimeString release];
|
2006-10-05 21:21:30 +00:00
|
|
|
|
2007-01-17 20:50:42 +00:00
|
|
|
[fFileList release];
|
2007-02-23 13:40:30 +00:00
|
|
|
[fFileFlatList release];
|
2007-01-17 20:50:42 +00:00
|
|
|
|
2006-10-05 21:21:30 +00:00
|
|
|
[fBitmap release];
|
|
|
|
free(fPieces);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDownloadFolder: (NSString *) path
|
|
|
|
{
|
2006-11-16 21:24:24 +00:00
|
|
|
if (path)
|
|
|
|
fDownloadFolder = [path copy];
|
2006-11-03 16:01:45 +00:00
|
|
|
|
|
|
|
if (!fUseIncompleteFolder || [[NSFileManager defaultManager] fileExistsAtPath:
|
|
|
|
[path stringByAppendingPathComponent: [self name]]])
|
|
|
|
tr_torrentSetFolder(fHandle, [path UTF8String]);
|
|
|
|
else
|
|
|
|
tr_torrentSetFolder(fHandle, [fIncompleteFolder UTF8String]);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) downloadFolder
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: tr_torrentGetFolder(fHandle)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getAvailability: (int8_t *) tab size: (int) size
|
|
|
|
{
|
|
|
|
tr_torrentAvailability(fHandle, tab, size);
|
|
|
|
}
|
|
|
|
|
2006-10-13 01:34:15 +00:00
|
|
|
- (void) getAmountFinished: (float *) tab size: (int) size
|
2006-10-12 23:34:20 +00:00
|
|
|
{
|
|
|
|
tr_torrentAmountFinished(fHandle, tab, size);
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) update
|
|
|
|
{
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
|
2006-07-30 18:37:29 +00:00
|
|
|
//notification when downloading finished
|
|
|
|
if ([self justFinished])
|
2006-11-03 16:01:45 +00:00
|
|
|
{
|
2006-11-16 22:03:51 +00:00
|
|
|
BOOL canMove = YES;
|
|
|
|
|
2006-11-03 16:01:45 +00:00
|
|
|
//move file from incomplete folder to download folder
|
2006-11-16 22:03:51 +00:00
|
|
|
if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder]
|
2007-01-14 20:22:51 +00:00
|
|
|
&& (canMove = [self alertForMoveFolderAvailable]))
|
2006-11-03 16:01:45 +00:00
|
|
|
{
|
|
|
|
tr_torrentStop(fHandle);
|
|
|
|
if ([[NSFileManager defaultManager] movePath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]
|
|
|
|
toPath: [fDownloadFolder stringByAppendingPathComponent: [self name]] handler: nil])
|
|
|
|
tr_torrentSetFolder(fHandle, [fDownloadFolder UTF8String]);
|
|
|
|
tr_torrentStart(fHandle);
|
|
|
|
}
|
|
|
|
|
2006-11-16 22:03:51 +00:00
|
|
|
if (!canMove)
|
|
|
|
{
|
|
|
|
fUseIncompleteFolder = NO;
|
|
|
|
|
|
|
|
[fDownloadFolder release];
|
|
|
|
fDownloadFolder = fIncompleteFolder;
|
|
|
|
fIncompleteFolder = nil;
|
|
|
|
}
|
2007-03-31 01:00:51 +00:00
|
|
|
|
|
|
|
if (fDateCompleted)
|
|
|
|
[fDateCompleted release];
|
|
|
|
fDateCompleted = [[NSDate alloc] init];
|
2006-11-16 22:03:51 +00:00
|
|
|
|
2007-01-09 01:09:23 +00:00
|
|
|
fStat = tr_torrentStat(fHandle);
|
2006-07-30 18:37:29 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
|
2006-11-03 16:01:45 +00:00
|
|
|
}
|
2006-07-30 18:37:29 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
//check to stop for ratio
|
2007-04-20 23:51:15 +00:00
|
|
|
float stopRatio;
|
2007-04-07 21:08:00 +00:00
|
|
|
if ([self isSeeding] && (stopRatio = [self actualStopRatio]) != INVALID
|
2007-04-20 23:51:15 +00:00
|
|
|
&& [self ratio] >= stopRatio)
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
|
|
|
[self stopTransfer];
|
2006-12-28 21:24:19 +00:00
|
|
|
fStat = tr_torrentStat(fHandle);
|
2006-12-28 00:29:05 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
fFinishedSeeding = YES;
|
|
|
|
|
2007-04-20 23:07:10 +00:00
|
|
|
[self setRatioSetting: NSOffState];
|
2006-07-16 19:39:23 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStoppedForRatio" object: self];
|
|
|
|
}
|
2007-04-01 13:25:32 +00:00
|
|
|
|
|
|
|
NSMutableString * progressString = [NSMutableString stringWithString: @""],
|
|
|
|
* remainingTimeString = [NSMutableString stringWithString: @""],
|
|
|
|
* statusString = [NSMutableString string],
|
|
|
|
* shortStatusString = [NSMutableString string];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-15 04:10:34 +00:00
|
|
|
if (![self allDownloaded])
|
2007-04-01 13:25:32 +00:00
|
|
|
[progressString appendFormat: NSLocalizedString(@"%@ of %@ (%.2f%%)", "Torrent -> progress string"),
|
2006-10-24 20:51:47 +00:00
|
|
|
[NSString stringForFileSize: [self downloadedValid]],
|
|
|
|
[NSString stringForFileSize: [self size]], 100.0 * [self progress]];
|
2006-07-16 19:39:23 +00:00
|
|
|
else
|
2007-04-01 13:25:32 +00:00
|
|
|
[progressString appendFormat: NSLocalizedString(@"%@, uploaded %@ (Ratio: %@)", "Torrent -> progress string"),
|
2006-10-24 20:51:47 +00:00
|
|
|
[NSString stringForFileSize: [self size]], [NSString stringForFileSize: [self uploadedTotal]],
|
2006-12-30 19:24:09 +00:00
|
|
|
[NSString stringForRatio: [self ratio]]];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-20 03:59:50 +00:00
|
|
|
BOOL wasChecking = fChecking;
|
|
|
|
fChecking = NO;
|
2006-07-16 19:39:23 +00:00
|
|
|
switch (fStat->status)
|
|
|
|
{
|
|
|
|
NSString * tempString;
|
2007-01-20 03:59:50 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
case TR_STATUS_PAUSE:
|
2007-01-09 03:46:21 +00:00
|
|
|
if (fWaitToStart)
|
|
|
|
{
|
2007-01-15 04:09:56 +00:00
|
|
|
tempString = ![self allDownloaded]
|
2007-01-09 15:31:14 +00:00
|
|
|
? [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis]
|
2007-01-09 03:46:21 +00:00
|
|
|
: [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
}
|
|
|
|
else if (fFinishedSeeding)
|
2006-10-24 20:34:13 +00:00
|
|
|
tempString = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
2006-07-16 19:39:23 +00:00
|
|
|
else
|
2006-10-24 20:34:13 +00:00
|
|
|
tempString = NSLocalizedString(@"Paused", "Torrent -> status string");
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString setString: tempString];
|
|
|
|
[shortStatusString setString: tempString];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2006-10-24 20:34:13 +00:00
|
|
|
tempString = [NSLocalizedString(@"Checking existing files", "Torrent -> status string") stringByAppendingEllipsis];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString setString: tempString];
|
|
|
|
[shortStatusString setString: tempString];
|
|
|
|
[remainingTimeString setString: tempString];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-20 03:59:50 +00:00
|
|
|
fChecking = YES;
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString setString: @""];
|
2007-01-14 22:12:39 +00:00
|
|
|
if ([self totalPeers] != 1)
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString appendFormat: NSLocalizedString(@"Downloading from %d of %d peers",
|
2006-10-24 20:51:47 +00:00
|
|
|
"Torrent -> status string"), [self peersUploading], [self totalPeers]];
|
2006-10-24 20:34:13 +00:00
|
|
|
else
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString appendFormat: NSLocalizedString(@"Downloading from %d of 1 peer",
|
2007-02-11 23:38:36 +00:00
|
|
|
"Torrent -> status string"), [self peersUploading]];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
int eta = [self eta];
|
|
|
|
if (eta < 0)
|
2006-07-25 00:59:14 +00:00
|
|
|
{
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString setString: NSLocalizedString(@"Unknown", "Torrent -> remaining time")];
|
|
|
|
[progressString appendString: NSLocalizedString(@" - remaining time unknown", "Torrent -> progress string")];
|
2006-07-25 00:59:14 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
else
|
2006-07-25 00:59:14 +00:00
|
|
|
{
|
|
|
|
if (eta < 60)
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString appendFormat: NSLocalizedString(@"%d sec", "Torrent -> remaining time"), eta];
|
2006-07-25 00:59:14 +00:00
|
|
|
else if (eta < 3600) //60 * 60
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString appendFormat: NSLocalizedString(@"%d min %02d sec", "Torrent -> remaining time"),
|
2006-10-24 20:51:47 +00:00
|
|
|
eta / 60, eta % 60];
|
2006-07-25 00:59:14 +00:00
|
|
|
else if (eta < 86400) //24 * 60 * 60
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString appendFormat: NSLocalizedString(@"%d hr %02d min", "Torrent -> remaining time"),
|
2006-10-24 20:51:47 +00:00
|
|
|
eta / 3600, (eta / 60) % 60];
|
2006-07-25 00:59:14 +00:00
|
|
|
else
|
2006-10-24 20:34:13 +00:00
|
|
|
{
|
2007-04-01 01:49:00 +00:00
|
|
|
int days = eta / 86400;
|
|
|
|
if (days > 1)
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString appendFormat: NSLocalizedString(@"%d days %d hr", "Torrent -> remaining time"),
|
2007-04-01 01:49:00 +00:00
|
|
|
days, (eta / 3600) % 24];
|
2006-10-24 20:34:13 +00:00
|
|
|
else
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString appendFormat: NSLocalizedString(@"1 day %d hr", "Torrent -> remaining time"),
|
2007-04-01 01:49:00 +00:00
|
|
|
(eta / 3600) % 24];
|
2006-10-24 20:34:13 +00:00
|
|
|
}
|
2006-07-25 00:59:14 +00:00
|
|
|
|
2007-04-01 13:25:32 +00:00
|
|
|
[progressString appendFormat: NSLocalizedString(@" - %@ remaining", "Torrent -> progress string"),
|
|
|
|
remainingTimeString];
|
2006-07-25 00:59:14 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString setString: @""];
|
2007-01-14 22:12:39 +00:00
|
|
|
if ([self totalPeers] != 1)
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString appendFormat: NSLocalizedString(@"Seeding to %d of %d peers", "Torrent -> status string"),
|
2006-10-24 20:51:47 +00:00
|
|
|
[self peersDownloading], [self totalPeers]];
|
2006-10-24 20:34:13 +00:00
|
|
|
else
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString appendFormat: NSLocalizedString(@"Seeding to %d of 1 peer", "Torrent -> status string"),
|
2007-01-20 03:59:50 +00:00
|
|
|
[self peersDownloading]];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_STOPPING:
|
2006-10-24 20:34:13 +00:00
|
|
|
tempString = [NSLocalizedString(@"Stopping", "Torrent -> status string") stringByAppendingEllipsis];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString setString: tempString];
|
|
|
|
[shortStatusString setString: tempString];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-20 03:59:50 +00:00
|
|
|
if (wasChecking && !fChecking)
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
|
|
|
|
2007-04-23 18:49:28 +00:00
|
|
|
if ([self isError])
|
2006-09-29 05:30:36 +00:00
|
|
|
{
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString setString: [NSLocalizedString(@"Error: ", "Torrent -> status string") stringByAppendingString:
|
2006-12-17 16:36:27 +00:00
|
|
|
[self errorMessage]]];
|
2006-09-29 05:30:36 +00:00
|
|
|
}
|
2006-12-17 16:36:27 +00:00
|
|
|
|
|
|
|
BOOL wasError = fError;
|
|
|
|
if ((fError = fStat->cannotConnect))
|
2006-09-29 05:30:36 +00:00
|
|
|
{
|
2007-01-09 01:31:56 +00:00
|
|
|
if (!wasError && [self isActive])
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
2006-09-29 05:30:36 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-11-16 08:48:58 +00:00
|
|
|
if ([self isActive] && fStat->status != TR_STATUS_CHECK )
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
|
|
|
NSString * stringToAppend = @"";
|
2007-01-15 04:09:56 +00:00
|
|
|
if (![self allDownloaded])
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2006-10-24 20:51:47 +00:00
|
|
|
stringToAppend = [NSString stringWithFormat: NSLocalizedString(@"DL: %@, ", "Torrent -> status string"),
|
|
|
|
[NSString stringForSpeed: [self downloadRate]]];
|
2007-04-01 13:25:32 +00:00
|
|
|
[shortStatusString setString: @""];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
else
|
2006-08-06 20:40:12 +00:00
|
|
|
{
|
2006-12-30 19:24:09 +00:00
|
|
|
NSString * ratioString = [NSString stringForRatio: [self ratio]];
|
2006-08-06 20:40:12 +00:00
|
|
|
|
2007-04-01 13:25:32 +00:00
|
|
|
[shortStatusString setString: [NSString stringWithFormat: NSLocalizedString(@"Ratio: %@, ",
|
2006-10-24 20:51:47 +00:00
|
|
|
"Torrent -> status string"), ratioString]];
|
2007-04-01 13:25:32 +00:00
|
|
|
[remainingTimeString setString: [NSLocalizedString(@"Ratio: ", "Torrent -> status string")
|
2006-10-24 20:51:47 +00:00
|
|
|
stringByAppendingString: ratioString]];
|
2006-08-06 20:40:12 +00:00
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2006-10-24 20:51:47 +00:00
|
|
|
stringToAppend = [stringToAppend stringByAppendingString: [NSLocalizedString(@"UL: ", "Torrent -> status string")
|
|
|
|
stringByAppendingString: [NSString stringForSpeed: [self uploadRate]]]];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-04-01 13:25:32 +00:00
|
|
|
[statusString appendFormat: @" - %@", stringToAppend];
|
|
|
|
[shortStatusString appendString: stringToAppend];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
2007-04-01 13:25:32 +00:00
|
|
|
|
|
|
|
[fProgressString setString: progressString];
|
|
|
|
[fStatusString setString: statusString];
|
|
|
|
[fShortStatusString setString: shortStatusString];
|
|
|
|
[fRemainingTimeString setString: remainingTimeString];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-09-11 23:52:03 +00:00
|
|
|
- (NSDictionary *) infoForCurrentView
|
|
|
|
{
|
|
|
|
NSMutableDictionary * info = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[self name], @"Name",
|
|
|
|
[NSNumber numberWithBool: [self isSeeding]], @"Seeding",
|
|
|
|
[NSNumber numberWithFloat: [self progress]], @"Progress",
|
|
|
|
[NSNumber numberWithBool: [self isActive]], @"Active",
|
|
|
|
[NSNumber numberWithBool: [self isError]], @"Error", nil];
|
|
|
|
|
2007-03-22 04:30:08 +00:00
|
|
|
if ([self isSeeding])
|
|
|
|
{
|
|
|
|
[info setObject: [NSNumber numberWithFloat: [self ratio]] forKey: @"Ratio"];
|
|
|
|
[info setObject: [NSNumber numberWithFloat: [self actualStopRatio]] forKey: @"StopRatio"];
|
|
|
|
}
|
|
|
|
|
2006-09-11 23:52:03 +00:00
|
|
|
if (![fDefaults boolForKey: @"SmallView"])
|
|
|
|
{
|
|
|
|
[info setObject: fIconFlipped forKey: @"Icon"];
|
|
|
|
[info setObject: [self progressString] forKey: @"ProgressString"];
|
|
|
|
[info setObject: [self statusString] forKey: @"StatusString"];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[info setObject: fIconSmall forKey: @"Icon"];
|
|
|
|
[info setObject: [self remainingTimeString] forKey: @"RemainingTimeString"];
|
|
|
|
[info setObject: [self shortStatusString] forKey: @"ShortStatusString"];
|
|
|
|
}
|
|
|
|
|
2006-09-12 00:08:30 +00:00
|
|
|
if ([fDefaults boolForKey: @"UseAdvancedBar"])
|
|
|
|
[info setObject: [self advancedBar] forKey: @"AdvancedBar"];
|
|
|
|
|
2006-09-11 23:52:03 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) startTransfer
|
|
|
|
{
|
2007-01-09 15:25:07 +00:00
|
|
|
fWaitToStart = NO;
|
2006-09-28 00:32:26 +00:00
|
|
|
fFinishedSeeding = NO;
|
|
|
|
|
2007-01-14 20:22:51 +00:00
|
|
|
if (![self isActive] && [self alertForFolderAvailable] && [self alertForRemainingDiskSpace])
|
2007-01-09 01:09:23 +00:00
|
|
|
{
|
2006-07-16 19:39:23 +00:00
|
|
|
tr_torrentStart(fHandle);
|
2007-01-09 01:09:23 +00:00
|
|
|
[self update];
|
|
|
|
}
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopTransfer
|
|
|
|
{
|
2006-09-29 05:30:36 +00:00
|
|
|
fError = NO;
|
2007-01-09 01:31:56 +00:00
|
|
|
fWaitToStart = NO;
|
2006-09-29 05:30:36 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
if ([self isActive])
|
|
|
|
{
|
|
|
|
tr_torrentStop(fHandle);
|
2007-01-09 01:09:23 +00:00
|
|
|
[self update];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-01-09 01:31:56 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopTransferForQuit
|
|
|
|
{
|
|
|
|
if ([self isActive])
|
|
|
|
tr_torrentStop(fHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) sleep
|
|
|
|
{
|
|
|
|
if ((fResumeOnWake = [self isActive]))
|
|
|
|
tr_torrentStop(fHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) wakeUp
|
|
|
|
{
|
|
|
|
if (fResumeOnWake)
|
|
|
|
tr_torrentStart(fHandle);
|
|
|
|
}
|
|
|
|
|
2006-12-26 21:02:00 +00:00
|
|
|
- (void) announce
|
|
|
|
{
|
|
|
|
if (![self isActive])
|
|
|
|
return;
|
|
|
|
|
|
|
|
tr_manualUpdate(fHandle);
|
|
|
|
|
|
|
|
if (fAnnounceDate)
|
|
|
|
[fAnnounceDate release];
|
|
|
|
fAnnounceDate = [[NSDate date] retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) announceDate
|
|
|
|
{
|
|
|
|
return fAnnounceDate;
|
|
|
|
}
|
|
|
|
|
2007-04-28 01:34:39 +00:00
|
|
|
- (void) resetCache
|
|
|
|
{
|
|
|
|
tr_torrentRemoveFastResume(fHandle);
|
|
|
|
}
|
|
|
|
|
2007-01-15 04:09:56 +00:00
|
|
|
- (BOOL) allDownloaded
|
|
|
|
{
|
|
|
|
return [self progress] >= 1.0;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (float) ratio
|
|
|
|
{
|
2006-12-30 19:24:09 +00:00
|
|
|
return fStat->ratio;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 17:54:24 +00:00
|
|
|
- (int) ratioSetting
|
2006-12-28 00:29:05 +00:00
|
|
|
{
|
2007-02-02 17:54:24 +00:00
|
|
|
return fRatioSetting;
|
2006-12-28 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 17:54:24 +00:00
|
|
|
- (void) setRatioSetting: (int) setting
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-02-02 17:54:24 +00:00
|
|
|
fRatioSetting = setting;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float) ratioLimit
|
|
|
|
{
|
|
|
|
return fRatioLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioLimit: (float) limit
|
|
|
|
{
|
|
|
|
if (limit >= 0)
|
|
|
|
fRatioLimit = limit;
|
|
|
|
}
|
|
|
|
|
2007-03-22 04:30:08 +00:00
|
|
|
- (float) actualStopRatio
|
|
|
|
{
|
|
|
|
if (fRatioSetting == NSOnState)
|
|
|
|
return fRatioLimit;
|
|
|
|
else if (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"])
|
|
|
|
return [fDefaults floatForKey: @"RatioLimit"];
|
|
|
|
else
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:33:32 +00:00
|
|
|
- (int) checkUpload
|
2006-12-28 00:29:05 +00:00
|
|
|
{
|
|
|
|
return fCheckUpload;
|
|
|
|
}
|
|
|
|
|
2007-02-02 17:33:32 +00:00
|
|
|
- (void) setCheckUpload: (int) setting
|
2006-12-27 02:57:55 +00:00
|
|
|
{
|
2007-02-02 17:33:32 +00:00
|
|
|
fCheckUpload = setting;
|
2007-01-08 15:11:15 +00:00
|
|
|
[self updateSpeedSetting];
|
2006-12-28 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) uploadLimit
|
|
|
|
{
|
|
|
|
return fUploadLimit;
|
2006-12-27 02:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUploadLimit: (int) limit
|
|
|
|
{
|
|
|
|
fUploadLimit = limit;
|
2007-01-08 15:11:15 +00:00
|
|
|
[self updateSpeedSetting];
|
2006-12-28 00:29:05 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 17:33:32 +00:00
|
|
|
- (int) checkDownload
|
2006-12-28 00:29:05 +00:00
|
|
|
{
|
|
|
|
return fCheckDownload;
|
2006-12-27 02:57:55 +00:00
|
|
|
}
|
|
|
|
|
2007-02-02 17:33:32 +00:00
|
|
|
- (void) setCheckDownload: (int) setting
|
2006-12-27 02:57:55 +00:00
|
|
|
{
|
2007-02-02 17:33:32 +00:00
|
|
|
fCheckDownload = setting;
|
2007-01-08 15:11:15 +00:00
|
|
|
[self updateSpeedSetting];
|
2006-12-27 02:57:55 +00:00
|
|
|
}
|
|
|
|
|
2006-12-28 00:29:05 +00:00
|
|
|
- (int) downloadLimit
|
2006-12-27 02:57:55 +00:00
|
|
|
{
|
2006-12-28 00:29:05 +00:00
|
|
|
return fDownloadLimit;
|
2006-12-27 02:57:55 +00:00
|
|
|
}
|
|
|
|
|
2006-12-28 00:29:05 +00:00
|
|
|
- (void) setDownloadLimit: (int) limit
|
2006-12-27 02:57:55 +00:00
|
|
|
{
|
2006-12-28 00:29:05 +00:00
|
|
|
fDownloadLimit = limit;
|
2007-01-08 15:11:15 +00:00
|
|
|
[self updateSpeedSetting];
|
2006-12-27 02:57:55 +00:00
|
|
|
}
|
|
|
|
|
2007-01-08 15:11:15 +00:00
|
|
|
- (void) updateSpeedSetting
|
2006-12-27 02:57:55 +00:00
|
|
|
{
|
2007-02-02 17:33:32 +00:00
|
|
|
tr_setUseCustomUpload(fHandle, fCheckUpload != NSMixedState);
|
|
|
|
tr_setUploadLimit(fHandle, fCheckUpload == NSOnState ? fUploadLimit : -1);
|
|
|
|
|
|
|
|
tr_setUseCustomDownload(fHandle, fCheckDownload != NSMixedState);
|
|
|
|
tr_setDownloadLimit(fHandle, fCheckDownload == NSOnState ? fDownloadLimit : -1);
|
2006-12-27 02:57:55 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) setWaitToStart: (BOOL) wait
|
|
|
|
{
|
|
|
|
fWaitToStart = wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) waitingToStart
|
|
|
|
{
|
|
|
|
return fWaitToStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealData
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
|
|
|
|
2006-10-15 19:57:40 +00:00
|
|
|
- (void) revealPublicTorrent
|
|
|
|
{
|
|
|
|
if (fPublicTorrent)
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: fPublicTorrentLocation inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) trashData
|
|
|
|
{
|
|
|
|
[self trashFile: [self dataLocation]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) trashTorrent
|
|
|
|
{
|
|
|
|
if (fPublicTorrent)
|
|
|
|
[self trashFile: [self publicTorrentLocation]];
|
|
|
|
}
|
|
|
|
|
2006-11-16 19:32:01 +00:00
|
|
|
- (BOOL) alertForRemainingDiskSpace
|
2006-09-28 00:32:26 +00:00
|
|
|
{
|
2007-04-25 03:17:06 +00:00
|
|
|
if ([self allDownloaded] || ![fDefaults boolForKey: @"WarningRemainingSpace"])
|
2006-09-28 00:32:26 +00:00
|
|
|
return YES;
|
|
|
|
|
2006-11-16 19:32:01 +00:00
|
|
|
NSString * volumeName = [[[NSFileManager defaultManager] componentsToDisplayForPath: [self downloadFolder]]
|
|
|
|
objectAtIndex: 0];
|
2006-11-17 10:12:15 +00:00
|
|
|
NSDictionary * fsAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath: [self downloadFolder]];
|
2006-09-28 04:06:38 +00:00
|
|
|
uint64_t remainingSpace = [[fsAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue],
|
2006-09-28 17:38:10 +00:00
|
|
|
torrentRemaining = [self size] - (uint64_t)[self downloadedValid];
|
2006-09-28 04:06:38 +00:00
|
|
|
|
2006-11-16 19:32:01 +00:00
|
|
|
if (volumeName && remainingSpace <= torrentRemaining)
|
2006-09-28 00:32:26 +00:00
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
2006-10-24 20:51:47 +00:00
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Not enough remaining disk space to download \"%@\" completely.",
|
|
|
|
"Torrent file disk space alert -> title"), [self name]]];
|
2006-09-28 00:48:07 +00:00
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
2006-11-16 19:32:01 +00:00
|
|
|
NSLocalizedString(@"The transfer will be paused. Clear up space on \"%@\" to continue.",
|
|
|
|
"Torrent file disk space alert -> message"), volumeName]];
|
2006-10-24 20:34:13 +00:00
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Torrent file disk space alert -> button")];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Download Anyway", "Torrent file disk space alert -> button")];
|
2007-03-24 17:41:57 +00:00
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Always Download", "Torrent file disk space alert -> button")];
|
2006-09-28 00:32:26 +00:00
|
|
|
|
2007-03-24 17:41:57 +00:00
|
|
|
int result = [alert runModal];
|
2006-11-16 22:03:51 +00:00
|
|
|
[alert release];
|
2007-01-09 01:31:56 +00:00
|
|
|
|
2007-03-24 17:41:57 +00:00
|
|
|
if (result == NSAlertThirdButtonReturn)
|
2007-04-25 03:00:43 +00:00
|
|
|
[fDefaults setBool: NO forKey: @"WarningRemainingSpace"];
|
2007-03-24 17:41:57 +00:00
|
|
|
|
|
|
|
return result != NSAlertFirstButtonReturn;
|
2006-09-28 00:32:26 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-01-14 20:22:51 +00:00
|
|
|
- (BOOL) alertForFolderAvailable
|
2006-11-16 19:32:01 +00:00
|
|
|
{
|
2007-01-14 20:22:51 +00:00
|
|
|
if (access(tr_torrentGetFolder(fHandle), 0))
|
2006-11-16 19:32:01 +00:00
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
2007-01-14 20:22:51 +00:00
|
|
|
NSLocalizedString(@"The folder for downloading \"%@\" cannot be found.",
|
|
|
|
"Folder cannot be found alert -> title"), [self name]]];
|
2006-11-16 19:32:01 +00:00
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
2007-01-14 20:22:51 +00:00
|
|
|
NSLocalizedString(@"\"%@\" cannot be found. The transfer will be paused.",
|
|
|
|
"Folder cannot be found alert -> message"), [self downloadFolder]]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Folder cannot be found alert -> button")];
|
|
|
|
[alert addButtonWithTitle: [NSLocalizedString(@"Choose New Location",
|
|
|
|
"Folder cannot be found alert -> location button") stringByAppendingEllipsis]];
|
2006-11-16 19:32:01 +00:00
|
|
|
|
2007-01-09 01:31:56 +00:00
|
|
|
if ([alert runModal] != NSAlertFirstButtonReturn)
|
2006-11-16 21:24:24 +00:00
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
2007-01-15 18:50:59 +00:00
|
|
|
[panel setPrompt: NSLocalizedString(@"Select", "Folder cannot be found alert -> prompt")];
|
2006-11-16 21:24:24 +00:00
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setCanChooseFiles: NO];
|
|
|
|
[panel setCanChooseDirectories: YES];
|
2007-01-15 18:36:08 +00:00
|
|
|
[panel setCanCreateDirectories: YES];
|
2006-11-16 21:24:24 +00:00
|
|
|
|
|
|
|
[panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the download folder for \"%@\"",
|
2007-01-15 18:50:59 +00:00
|
|
|
"Folder cannot be found alert -> select destination folder"), [self name]]];
|
2006-11-16 21:24:24 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"MakeWindowKey" object: nil];
|
|
|
|
[panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: [NSApp keyWindow] modalDelegate: self
|
|
|
|
didEndSelector: @selector(destinationChoiceClosed:returnCode:contextInfo:) contextInfo: nil];
|
|
|
|
}
|
|
|
|
|
2006-11-16 22:03:51 +00:00
|
|
|
[alert release];
|
|
|
|
|
2006-11-16 21:24:24 +00:00
|
|
|
return NO;
|
2006-11-16 19:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-11-18 15:47:20 +00:00
|
|
|
- (void) destinationChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) context
|
2006-11-16 21:24:24 +00:00
|
|
|
{
|
2007-01-15 18:36:08 +00:00
|
|
|
if (code != NSOKButton)
|
|
|
|
return;
|
|
|
|
|
2006-11-16 21:24:24 +00:00
|
|
|
NSString * folder = [[openPanel filenames] objectAtIndex: 0];
|
2007-01-15 18:36:08 +00:00
|
|
|
if (fUseIncompleteFolder)
|
2006-11-16 21:24:24 +00:00
|
|
|
{
|
2007-01-15 18:36:08 +00:00
|
|
|
[fIncompleteFolder release];
|
|
|
|
fIncompleteFolder = [folder retain];
|
|
|
|
[self setDownloadFolder: nil];
|
2006-11-16 21:24:24 +00:00
|
|
|
}
|
2007-01-15 18:36:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[fDownloadFolder release];
|
|
|
|
fDownloadFolder = folder;
|
|
|
|
[self setDownloadFolder: fDownloadFolder];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self startTransfer];
|
|
|
|
[self update];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateInfoSettings" object: nil];
|
2006-11-16 21:24:24 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 20:22:51 +00:00
|
|
|
- (BOOL) alertForMoveFolderAvailable
|
2006-11-16 22:03:51 +00:00
|
|
|
{
|
2007-01-14 20:22:51 +00:00
|
|
|
if (access([fDownloadFolder UTF8String], 0))
|
2006-11-16 22:03:51 +00:00
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
2007-01-14 20:24:52 +00:00
|
|
|
NSLocalizedString(@"The folder for moving the completed \"%@\" cannot be found.",
|
2007-01-14 20:22:51 +00:00
|
|
|
"Move folder cannot be found alert -> title"), [self name]]];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"\"%@\" cannot be found. The file will remain in its current location.",
|
|
|
|
"Move folder cannot be found alert -> message"), fDownloadFolder]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Move folder cannot be found alert -> button")];
|
2006-11-16 22:03:51 +00:00
|
|
|
|
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
2006-11-16 21:24:24 +00:00
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (NSImage *) icon
|
|
|
|
{
|
|
|
|
return fIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *) iconFlipped
|
|
|
|
{
|
|
|
|
return fIconFlipped;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *) iconSmall
|
|
|
|
{
|
|
|
|
return fIconSmall;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) name
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fInfo->name];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint64_t) size
|
|
|
|
{
|
|
|
|
return fInfo->totalSize;
|
|
|
|
}
|
|
|
|
|
2006-12-26 21:02:00 +00:00
|
|
|
- (NSString *) trackerAddress
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-02-27 04:00:38 +00:00
|
|
|
return [NSString stringWithFormat: @"http://%s:%d", fStat->tracker->address, fStat->tracker->port];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-12-26 21:02:00 +00:00
|
|
|
- (NSString *) trackerAddressAnnounce
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-02-27 04:00:38 +00:00
|
|
|
return [NSString stringWithUTF8String: fStat->tracker->announce];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2006-11-23 01:38:18 +00:00
|
|
|
- (NSString *) comment
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fInfo->comment];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) creator
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fInfo->creator];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateCreated
|
|
|
|
{
|
|
|
|
int date = fInfo->dateCreated;
|
2006-12-02 01:46:54 +00:00
|
|
|
return date > 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
2006-11-23 01:38:18 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (int) pieceSize
|
|
|
|
{
|
|
|
|
return fInfo->pieceSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) pieceCount
|
|
|
|
{
|
|
|
|
return fInfo->pieceCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) hashString
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fInfo->hashString];
|
|
|
|
}
|
|
|
|
|
2006-12-17 16:36:27 +00:00
|
|
|
- (BOOL) privateTorrent
|
|
|
|
{
|
2007-01-27 22:37:10 +00:00
|
|
|
return TR_FLAG_PRIVATE & fInfo->flags;
|
2006-12-17 16:36:27 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (NSString *) torrentLocation
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: fInfo->torrent];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) publicTorrentLocation
|
|
|
|
{
|
|
|
|
return fPublicTorrentLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) dataLocation
|
|
|
|
{
|
|
|
|
return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) publicTorrent
|
|
|
|
{
|
|
|
|
return fPublicTorrent;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) stateString
|
|
|
|
{
|
|
|
|
switch( fStat->status )
|
|
|
|
{
|
|
|
|
case TR_STATUS_PAUSE:
|
2006-10-24 20:34:13 +00:00
|
|
|
return NSLocalizedString(@"Paused", "Torrent -> status string");
|
2006-07-16 19:39:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2006-10-24 20:34:13 +00:00
|
|
|
return [NSLocalizedString(@"Checking existing files", "Torrent -> status string") stringByAppendingEllipsis];
|
2006-07-16 19:39:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
2006-10-24 20:34:13 +00:00
|
|
|
return NSLocalizedString(@"Downloading", "Torrent -> status string");
|
2006-07-16 19:39:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
2006-10-24 20:34:13 +00:00
|
|
|
return NSLocalizedString(@"Seeding", "Torrent -> status string");
|
2006-07-16 19:39:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_STOPPING:
|
2006-10-24 20:34:13 +00:00
|
|
|
return [NSLocalizedString(@"Stopping", "Torrent -> status string") stringByAppendingEllipsis];
|
2006-07-16 19:39:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2006-10-24 20:34:13 +00:00
|
|
|
return NSLocalizedString(@"N/A", "Torrent -> status string");
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) progress
|
|
|
|
{
|
|
|
|
return fStat->progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) eta
|
|
|
|
{
|
|
|
|
return fStat->eta;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isActive
|
|
|
|
{
|
|
|
|
return fStat->status & TR_STATUS_ACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSeeding
|
|
|
|
{
|
|
|
|
return fStat->status == TR_STATUS_SEED;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isPaused
|
|
|
|
{
|
|
|
|
return fStat->status == TR_STATUS_PAUSE;
|
|
|
|
}
|
|
|
|
|
2006-08-29 00:09:49 +00:00
|
|
|
- (BOOL) isError
|
|
|
|
{
|
2007-04-23 18:49:28 +00:00
|
|
|
return fStat->error != 0;
|
2006-08-29 00:09:49 +00:00
|
|
|
}
|
|
|
|
|
2006-12-17 16:36:27 +00:00
|
|
|
- (NSString *) errorMessage
|
|
|
|
{
|
2007-04-11 18:26:38 +00:00
|
|
|
if (![self isError])
|
|
|
|
return @"";
|
|
|
|
|
|
|
|
NSString * error;
|
|
|
|
if (!(error = [NSString stringWithUTF8String: fStat->errorString])
|
|
|
|
&& !(error = [NSString stringWithCString: fStat->errorString encoding: NSISOLatin1StringEncoding]))
|
2007-04-18 21:17:47 +00:00
|
|
|
error = NSLocalizedString(@"(unreadable error)", "Torrent -> error string unreadable");
|
2007-04-11 18:26:38 +00:00
|
|
|
|
|
|
|
return error;
|
2006-12-17 16:36:27 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (BOOL) justFinished
|
|
|
|
{
|
|
|
|
return tr_getFinished(fHandle);
|
|
|
|
}
|
|
|
|
|
2006-08-13 15:46:02 +00:00
|
|
|
- (NSArray *) peers
|
|
|
|
{
|
2006-08-13 21:16:18 +00:00
|
|
|
int totalPeers, i;
|
|
|
|
tr_peer_stat_t * peers = tr_torrentPeers(fHandle, & totalPeers);
|
2006-08-13 15:46:02 +00:00
|
|
|
|
2006-08-13 21:16:18 +00:00
|
|
|
NSMutableArray * peerDics = [NSMutableArray arrayWithCapacity: totalPeers];
|
2006-12-18 06:25:40 +00:00
|
|
|
NSMutableDictionary * dic;
|
|
|
|
|
|
|
|
tr_peer_stat_t * peer;
|
2006-08-13 15:46:02 +00:00
|
|
|
for (i = 0; i < totalPeers; i++)
|
|
|
|
{
|
2006-12-18 06:25:40 +00:00
|
|
|
peer = &peers[i];
|
|
|
|
|
|
|
|
dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithBool: peer->isConnected], @"Connected",
|
2007-03-23 08:28:01 +00:00
|
|
|
[NSNumber numberWithInt: peer->from], @"From",
|
2006-12-18 06:25:40 +00:00
|
|
|
[NSString stringWithCString: (char *) peer->addr encoding: NSUTF8StringEncoding], @"IP",
|
|
|
|
[NSNumber numberWithInt: peer->port], @"Port", nil];
|
|
|
|
|
2007-05-04 18:42:26 +00:00
|
|
|
if (peer->isConnected)
|
|
|
|
{
|
|
|
|
[dic setObject: [NSNumber numberWithFloat: peer->progress] forKey: @"Progress"];
|
|
|
|
|
|
|
|
[dic setObject: [NSNumber numberWithBool: peer->isDownloading] forKey: @"UL To"];
|
|
|
|
if (peer->isDownloading)
|
|
|
|
[dic setObject: [NSNumber numberWithFloat: peer->uploadToRate] forKey: @"UL To Rate"];
|
|
|
|
|
|
|
|
[dic setObject: [NSNumber numberWithBool: peer->isUploading] forKey: @"DL From"];
|
|
|
|
if (peer->isUploading)
|
|
|
|
[dic setObject: [NSNumber numberWithFloat: peer->downloadFromRate] forKey: @"DL From Rate"];
|
2007-05-04 19:23:34 +00:00
|
|
|
|
|
|
|
[dic setObject: [NSString stringWithCString: (char *) peer->client encoding: NSUTF8StringEncoding] forKey: @"Client"];
|
2007-05-04 18:42:26 +00:00
|
|
|
}
|
2007-05-04 19:23:34 +00:00
|
|
|
else
|
|
|
|
[dic setObject: NSLocalizedString(@"not connected", "Peer -> client") forKey: @"Client"];
|
2006-12-18 06:25:40 +00:00
|
|
|
|
|
|
|
[peerDics addObject: dic];
|
2006-08-13 15:46:02 +00:00
|
|
|
}
|
|
|
|
|
2006-08-13 21:24:23 +00:00
|
|
|
tr_torrentPeersFree(peers, totalPeers);
|
|
|
|
|
2006-08-13 21:16:18 +00:00
|
|
|
return peerDics;
|
2006-08-13 15:46:02 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (NSString *) progressString
|
|
|
|
{
|
|
|
|
return fProgressString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) statusString
|
|
|
|
{
|
|
|
|
return fStatusString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) shortStatusString
|
|
|
|
{
|
|
|
|
return fShortStatusString;
|
|
|
|
}
|
|
|
|
|
2006-07-25 00:59:14 +00:00
|
|
|
- (NSString *) remainingTimeString
|
|
|
|
{
|
|
|
|
return fRemainingTimeString;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (int) seeders
|
|
|
|
{
|
|
|
|
return fStat->seeders;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) leechers
|
|
|
|
{
|
|
|
|
return fStat->leechers;
|
|
|
|
}
|
|
|
|
|
2006-12-02 01:46:54 +00:00
|
|
|
- (int) completedFromTracker
|
|
|
|
{
|
|
|
|
return fStat->completedFromTracker;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (int) totalPeers
|
|
|
|
{
|
|
|
|
return fStat->peersTotal;
|
|
|
|
}
|
|
|
|
|
2007-03-23 08:28:01 +00:00
|
|
|
- (int) totalPeersTracker
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_TRACKER];
|
|
|
|
}
|
|
|
|
|
2006-10-13 18:58:12 +00:00
|
|
|
- (int) totalPeersIncoming
|
|
|
|
{
|
2007-03-23 08:28:01 +00:00
|
|
|
return fStat->peersFrom[TR_PEER_FROM_INCOMING];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) totalPeersCache
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_CACHE];
|
2006-10-13 18:58:12 +00:00
|
|
|
}
|
|
|
|
|
2007-03-23 08:28:01 +00:00
|
|
|
- (int) totalPeersPex
|
2006-10-13 18:58:12 +00:00
|
|
|
{
|
2007-03-23 08:28:01 +00:00
|
|
|
return fStat->peersFrom[TR_PEER_FROM_PEX];
|
2006-10-13 18:58:12 +00:00
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
//peers uploading to you
|
|
|
|
- (int) peersUploading
|
|
|
|
{
|
|
|
|
return fStat->peersUploading;
|
|
|
|
}
|
|
|
|
|
|
|
|
//peers downloading from you
|
|
|
|
- (int) peersDownloading
|
|
|
|
{
|
|
|
|
return fStat->peersDownloading;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) downloadRate
|
|
|
|
{
|
|
|
|
return fStat->rateDownload;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) uploadRate
|
|
|
|
{
|
|
|
|
return fStat->rateUpload;
|
|
|
|
}
|
|
|
|
|
2007-04-04 01:05:04 +00:00
|
|
|
- (uint64_t) downloadedValid
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-04-04 01:05:04 +00:00
|
|
|
return fInfo->totalSize - fStat->left;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (uint64_t) downloadedTotal
|
|
|
|
{
|
|
|
|
return fStat->downloaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint64_t) uploadedTotal
|
|
|
|
{
|
|
|
|
return fStat->uploaded;
|
|
|
|
}
|
|
|
|
|
2006-08-17 03:12:40 +00:00
|
|
|
- (float) swarmSpeed
|
|
|
|
{
|
|
|
|
return fStat->swarmspeed;
|
|
|
|
}
|
|
|
|
|
2007-03-31 20:08:10 +00:00
|
|
|
- (BOOL) pex
|
|
|
|
{
|
|
|
|
return fPex;
|
|
|
|
}
|
|
|
|
|
2007-03-31 20:19:19 +00:00
|
|
|
- (void) setPex: (BOOL) setting
|
2007-03-31 20:08:10 +00:00
|
|
|
{
|
|
|
|
if (![self privateTorrent])
|
|
|
|
{
|
2007-03-31 20:19:19 +00:00
|
|
|
fPex = setting;
|
|
|
|
tr_torrentDisablePex(fHandle, !setting);
|
2007-03-31 20:08:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-02 01:34:06 +00:00
|
|
|
- (NSNumber *) orderValue
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithInt: fOrderValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setOrderValue: (int) orderValue
|
|
|
|
{
|
|
|
|
fOrderValue = orderValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fileList
|
|
|
|
{
|
|
|
|
return fFileList;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) fileCount
|
|
|
|
{
|
|
|
|
return fInfo->fileCount;
|
|
|
|
}
|
|
|
|
|
2007-02-23 19:17:31 +00:00
|
|
|
- (BOOL) updateFileProgress
|
2007-02-23 13:40:30 +00:00
|
|
|
{
|
2007-02-23 19:17:31 +00:00
|
|
|
BOOL change = NO;
|
|
|
|
float * progress = tr_torrentCompletion(fHandle);
|
|
|
|
NSNumber * progressNum;
|
|
|
|
NSMutableDictionary * item, * dict;
|
2007-02-23 13:40:30 +00:00
|
|
|
|
|
|
|
int i, fileCount = [self fileCount];
|
|
|
|
for (i = 0; i < fileCount; i++)
|
2007-02-23 19:17:31 +00:00
|
|
|
{
|
|
|
|
if (!(progressNum = [[fFileFlatList objectAtIndex: i] objectForKey: @"Progress"])
|
|
|
|
|| [progressNum floatValue] != progress[i])
|
|
|
|
{
|
|
|
|
item = [fFileFlatList objectAtIndex: i];
|
|
|
|
[item setObject: [NSNumber numberWithFloat: progress[i]] forKey: @"Progress"];
|
|
|
|
change = YES;
|
|
|
|
|
|
|
|
if (progress[i] == 1.0)
|
|
|
|
{
|
|
|
|
dict = item;
|
|
|
|
while ((dict = [dict objectForKey: @"Parent"]))
|
|
|
|
[dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]-1]
|
|
|
|
forKey: @"Remaining"];
|
|
|
|
|
2007-03-02 01:34:06 +00:00
|
|
|
[item setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"];
|
|
|
|
[self resetFileCheckStateForItemParent: item];
|
2007-02-23 19:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-02-23 13:40:30 +00:00
|
|
|
|
|
|
|
free(progress);
|
2007-02-23 19:17:31 +00:00
|
|
|
|
|
|
|
return change;
|
2007-02-23 13:40:30 +00:00
|
|
|
}
|
|
|
|
|
2007-03-02 01:34:06 +00:00
|
|
|
- (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-03-02 01:34:06 +00:00
|
|
|
[item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
|
|
|
|
|
|
|
|
if (![[item objectForKey: @"IsFolder"] boolValue])
|
|
|
|
return;
|
|
|
|
|
|
|
|
NSMutableDictionary * child;
|
|
|
|
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
|
|
|
|
while ((child = [enumerator nextObject]))
|
|
|
|
if (state != [[child objectForKey: @"Check"] intValue])
|
|
|
|
[self setFileCheckState: state forFileItem: child];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-03-02 01:34:06 +00:00
|
|
|
- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild
|
2007-01-17 06:43:07 +00:00
|
|
|
{
|
2007-03-02 01:34:06 +00:00
|
|
|
NSMutableDictionary * item;
|
|
|
|
if (!(item = [originalChild objectForKey: @"Parent"]))
|
|
|
|
return originalChild;
|
|
|
|
|
|
|
|
int state = INVALID;
|
|
|
|
|
|
|
|
NSMutableDictionary * child;
|
|
|
|
NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
|
|
|
|
while ((child = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if (state == INVALID)
|
|
|
|
{
|
|
|
|
state = [[child objectForKey: @"Check"] intValue];
|
|
|
|
if (state == NSMixedState)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (state != [[child objectForKey: @"Check"] intValue])
|
|
|
|
{
|
|
|
|
state = NSMixedState;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state != [[item objectForKey: @"Check"] intValue])
|
|
|
|
{
|
|
|
|
[item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
|
|
|
|
return [self resetFileCheckStateForItemParent: item];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return originalChild;
|
2007-01-17 06:43:07 +00:00
|
|
|
}
|
|
|
|
|
2007-03-30 18:58:18 +00:00
|
|
|
- (NSDate *) dateAdded
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
2007-03-30 18:58:18 +00:00
|
|
|
return fDateAdded;
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
2007-03-31 01:00:51 +00:00
|
|
|
- (NSDate *) dateCompleted
|
|
|
|
{
|
|
|
|
return fDateCompleted;
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (NSNumber *) stateSortKey
|
|
|
|
{
|
|
|
|
if (![self isActive])
|
|
|
|
return [NSNumber numberWithInt: 0];
|
|
|
|
else if ([self isSeeding])
|
|
|
|
return [NSNumber numberWithInt: 1];
|
|
|
|
else
|
|
|
|
return [NSNumber numberWithInt: 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) progressSortKey
|
|
|
|
{
|
2007-01-15 04:41:01 +00:00
|
|
|
return [NSNumber numberWithFloat: [self progress]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSNumber *) ratioSortKey
|
|
|
|
{
|
2007-04-20 23:51:15 +00:00
|
|
|
return [NSNumber numberWithFloat: [self ratio]];
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Torrent (Private)
|
|
|
|
|
|
|
|
//if a hash is given, attempt to load that; otherwise, attempt to open file at path
|
|
|
|
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
|
2006-11-05 19:08:38 +00:00
|
|
|
publicTorrent: (NSNumber *) publicTorrent
|
2007-03-31 01:00:51 +00:00
|
|
|
dateAdded: (NSDate *) dateAdded dateCompleted: (NSDate *) dateCompleted
|
2007-02-02 17:54:24 +00:00
|
|
|
ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
|
2006-12-28 00:29:05 +00:00
|
|
|
limitSpeedCustom: (NSNumber *) limitCustom
|
2006-12-27 02:57:55 +00:00
|
|
|
checkUpload: (NSNumber *) checkUpload uploadLimit: (NSNumber *) uploadLimit
|
|
|
|
checkDownload: (NSNumber *) checkDownload downloadLimit: (NSNumber *) downloadLimit
|
2007-03-31 20:08:10 +00:00
|
|
|
pex: (NSNumber *) pex
|
2006-12-27 02:57:55 +00:00
|
|
|
waitToStart: (NSNumber *) waitToStart orderValue: (NSNumber *) orderValue
|
2006-07-16 19:39:23 +00:00
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
fLib = lib;
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2006-11-05 19:08:38 +00:00
|
|
|
fPublicTorrent = path && (publicTorrent ? [publicTorrent boolValue] : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
|
|
|
|
if (fPublicTorrent)
|
|
|
|
fPublicTorrentLocation = [path retain];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
int error;
|
2006-11-05 19:08:38 +00:00
|
|
|
if (hashString)
|
2007-01-27 22:37:10 +00:00
|
|
|
fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FLAG_SAVE, & error);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
if (!fHandle && path)
|
2007-03-22 18:07:22 +00:00
|
|
|
fHandle = tr_torrentInit(fLib, [path UTF8String], NULL, TR_FLAG_SAVE, & error);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
if (!fHandle)
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-12-28 00:29:05 +00:00
|
|
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc addObserver: self selector: @selector(updateSpeedSetting:)
|
|
|
|
name: @"UpdateSpeedSetting" object: nil];
|
|
|
|
|
2007-03-06 03:39:48 +00:00
|
|
|
fInfo = tr_torrentInfo(fHandle);
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-03-30 18:58:18 +00:00
|
|
|
fDateAdded = dateAdded ? [dateAdded retain] : [[NSDate alloc] init];
|
2007-03-31 01:00:51 +00:00
|
|
|
if (dateCompleted)
|
|
|
|
fDateCompleted = [dateCompleted retain];
|
|
|
|
|
2007-02-02 17:54:24 +00:00
|
|
|
fRatioSetting = ratioSetting ? [ratioSetting intValue] : NSMixedState;
|
2006-07-16 19:39:23 +00:00
|
|
|
fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];
|
|
|
|
fFinishedSeeding = NO;
|
|
|
|
|
2007-02-02 17:33:32 +00:00
|
|
|
fCheckUpload = checkUpload ? [checkUpload intValue] : NSMixedState;
|
2007-01-08 15:20:18 +00:00
|
|
|
fUploadLimit = uploadLimit ? [uploadLimit intValue] : [fDefaults integerForKey: @"UploadLimit"];
|
2007-02-02 17:33:32 +00:00
|
|
|
fCheckDownload = checkDownload ? [checkDownload intValue] : NSMixedState;
|
2007-01-08 15:20:18 +00:00
|
|
|
fDownloadLimit = downloadLimit ? [downloadLimit intValue] : [fDefaults integerForKey: @"DownloadLimit"];
|
2007-01-08 15:11:15 +00:00
|
|
|
[self updateSpeedSetting];
|
2007-03-31 20:08:10 +00:00
|
|
|
|
|
|
|
if ([self privateTorrent])
|
|
|
|
fPex = NO;
|
|
|
|
else
|
|
|
|
fPex = pex ? [pex boolValue] : YES;
|
|
|
|
tr_torrentDisablePex(fHandle, !fPex);
|
2006-12-27 02:57:55 +00:00
|
|
|
|
2006-09-27 14:43:36 +00:00
|
|
|
fWaitToStart = waitToStart ? [waitToStart boolValue] : [fDefaults boolForKey: @"AutoStartDownload"];
|
2006-07-16 19:39:23 +00:00
|
|
|
fOrderValue = orderValue ? [orderValue intValue] : tr_torrentCount(fLib) - 1;
|
2006-09-29 05:30:36 +00:00
|
|
|
fError = NO;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
2007-03-11 22:12:01 +00:00
|
|
|
fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr')
|
|
|
|
: [[self name] pathExtension]] retain];
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
fIconFlipped = [fIcon copy];
|
|
|
|
[fIconFlipped setFlipped: YES];
|
|
|
|
|
|
|
|
fIconSmall = [fIconFlipped copy];
|
|
|
|
[fIconSmall setScalesWhenResized: YES];
|
|
|
|
[fIconSmall setSize: NSMakeSize(16.0, 16.0)];
|
|
|
|
|
|
|
|
fProgressString = [[NSMutableString alloc] initWithCapacity: 50];
|
|
|
|
fStatusString = [[NSMutableString alloc] initWithCapacity: 75];
|
2006-07-25 00:59:14 +00:00
|
|
|
fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
|
|
|
|
fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
|
2006-10-05 21:21:30 +00:00
|
|
|
|
2007-02-23 13:40:30 +00:00
|
|
|
[self createFileList];
|
2007-01-17 20:50:42 +00:00
|
|
|
|
2006-10-05 21:21:30 +00:00
|
|
|
//set up advanced bar
|
|
|
|
fBitmap = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes: nil
|
|
|
|
pixelsWide: MAX_PIECES pixelsHigh: BAR_HEIGHT bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES
|
|
|
|
isPlanar: NO colorSpaceName: NSCalibratedRGBColorSpace bytesPerRow: 0 bitsPerPixel: 0];
|
|
|
|
|
|
|
|
fPieces = malloc(MAX_PIECES);
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_PIECES; i++)
|
|
|
|
fPieces[i] = BLANK_PIECE;
|
2006-07-16 19:39:23 +00:00
|
|
|
|
|
|
|
[self update];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-02-23 13:40:30 +00:00
|
|
|
- (void) createFileList
|
2007-01-17 20:50:42 +00:00
|
|
|
{
|
|
|
|
int count = [self fileCount], i;
|
|
|
|
tr_file_t * file;
|
2007-02-23 13:40:30 +00:00
|
|
|
NSMutableArray * pathComponents;
|
2007-01-17 20:50:42 +00:00
|
|
|
NSString * path;
|
|
|
|
|
2007-02-23 13:40:30 +00:00
|
|
|
NSMutableArray * fileList = [[NSMutableArray alloc] init],
|
|
|
|
* fileFlatList = [[NSMutableArray alloc] initWithCapacity: count];
|
|
|
|
|
2007-01-17 20:50:42 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
file = &fInfo->files[i];
|
|
|
|
|
|
|
|
pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy];
|
|
|
|
if (fInfo->multifile)
|
|
|
|
{
|
|
|
|
path = [pathComponents objectAtIndex: 0];
|
|
|
|
[pathComponents removeObjectAtIndex: 0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
path = @"";
|
|
|
|
|
2007-02-23 13:40:30 +00:00
|
|
|
[self insertPath: pathComponents forSiblings: fileList withParent: nil previousPath: path
|
|
|
|
fileSize: file->length state: NSOnState flatList: fileFlatList];
|
2007-01-17 20:50:42 +00:00
|
|
|
[pathComponents autorelease];
|
|
|
|
}
|
2007-02-23 13:40:30 +00:00
|
|
|
|
|
|
|
fFileList = [[NSArray alloc] initWithArray: fileList];
|
|
|
|
[fileList release];
|
|
|
|
fFileFlatList = [[NSArray alloc] initWithArray: fileFlatList];
|
|
|
|
[fileFlatList release];
|
2007-01-17 20:50:42 +00:00
|
|
|
}
|
|
|
|
|
2007-01-17 23:19:53 +00:00
|
|
|
- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
|
2007-01-18 03:54:56 +00:00
|
|
|
withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
|
2007-02-23 13:40:30 +00:00
|
|
|
fileSize: (uint64_t) size state: (int) state flatList: (NSMutableArray *) flatList
|
2007-01-17 06:25:35 +00:00
|
|
|
{
|
|
|
|
NSString * name = [components objectAtIndex: 0];
|
|
|
|
BOOL isFolder = [components count] > 1;
|
|
|
|
|
|
|
|
NSMutableDictionary * dict = nil;
|
|
|
|
if (isFolder)
|
|
|
|
{
|
2007-01-17 23:19:53 +00:00
|
|
|
NSEnumerator * enumerator = [siblings objectEnumerator];
|
2007-01-17 06:25:35 +00:00
|
|
|
while ((dict = [enumerator nextObject]))
|
|
|
|
if ([[dict objectForKey: @"Name"] isEqualToString: name] && [[dict objectForKey: @"IsFolder"] boolValue])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-17 17:29:42 +00:00
|
|
|
NSString * currentPath = [previousPath stringByAppendingPathComponent: name];
|
|
|
|
|
2007-01-17 06:25:35 +00:00
|
|
|
//create new folder or item if it doesn't already exist
|
|
|
|
if (!dict)
|
|
|
|
{
|
|
|
|
dict = [NSMutableDictionary dictionaryWithObjectsAndKeys: name, @"Name",
|
2007-01-17 17:29:42 +00:00
|
|
|
[NSNumber numberWithBool: isFolder], @"IsFolder",
|
|
|
|
currentPath, @"Path", nil];
|
2007-02-23 13:40:30 +00:00
|
|
|
|
|
|
|
[siblings addObject: dict];
|
|
|
|
|
2007-01-17 06:25:35 +00:00
|
|
|
if (isFolder)
|
2007-02-23 19:17:31 +00:00
|
|
|
{
|
2007-01-17 06:25:35 +00:00
|
|
|
[dict setObject: [NSMutableArray array] forKey: @"Children"];
|
2007-02-23 19:17:31 +00:00
|
|
|
[dict setObject: [NSNumber numberWithInt: 1] forKey: @"Remaining"];
|
|
|
|
}
|
2007-01-17 07:26:33 +00:00
|
|
|
else
|
2007-02-23 13:40:30 +00:00
|
|
|
{
|
|
|
|
[flatList addObject: dict];
|
2007-01-17 07:26:33 +00:00
|
|
|
[dict setObject: [NSNumber numberWithUnsignedLongLong: size] forKey: @"Size"];
|
2007-03-05 02:31:20 +00:00
|
|
|
[dict setObject: [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]] forKey: @"Icon"];
|
2007-02-23 13:40:30 +00:00
|
|
|
}
|
2007-01-17 06:25:35 +00:00
|
|
|
|
2007-01-17 23:19:53 +00:00
|
|
|
if (parent)
|
|
|
|
[dict setObject: parent forKey: @"Parent"];
|
2007-01-18 03:54:56 +00:00
|
|
|
[dict setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
|
2007-01-17 06:25:35 +00:00
|
|
|
}
|
2007-01-18 03:54:56 +00:00
|
|
|
else
|
|
|
|
{
|
2007-02-23 19:17:31 +00:00
|
|
|
if (isFolder)
|
|
|
|
[dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]+1] forKey: @"Remaining"];
|
|
|
|
|
2007-01-18 03:54:56 +00:00
|
|
|
int dictState = [[dict objectForKey: @"Check"] intValue];
|
|
|
|
if (dictState != NSMixedState && dictState != state)
|
|
|
|
[dict setObject: [NSNumber numberWithInt: NSMixedState] forKey: @"Check"];
|
|
|
|
}
|
2007-01-17 06:25:35 +00:00
|
|
|
|
|
|
|
if (isFolder)
|
|
|
|
{
|
|
|
|
[components removeObjectAtIndex: 0];
|
2007-01-17 23:19:53 +00:00
|
|
|
[self insertPath: components forSiblings: [dict objectForKey: @"Children"]
|
2007-02-23 13:40:30 +00:00
|
|
|
withParent: dict previousPath: currentPath fileSize: size state: state flatList: flatList];
|
2007-01-17 06:25:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
- (NSImage *) advancedBar
|
|
|
|
{
|
|
|
|
uint32_t * p;
|
2006-10-05 21:21:30 +00:00
|
|
|
uint8_t * bitmapData = [fBitmap bitmapData];
|
|
|
|
int bytesPerRow = [fBitmap bytesPerRow];
|
2007-02-09 05:19:08 +00:00
|
|
|
|
|
|
|
int pieceCount = [self pieceCount];
|
|
|
|
int8_t * piecesAvailablity = malloc(pieceCount);
|
|
|
|
[self getAvailability: piecesAvailablity size: pieceCount];
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2006-10-06 20:45:59 +00:00
|
|
|
//lines 2 to 14: blue, green, or gray depending on whether we have the piece or not
|
2007-02-09 15:02:25 +00:00
|
|
|
int i, h, index = 0;
|
2007-02-09 05:19:08 +00:00
|
|
|
float increment = (float)pieceCount / (float)MAX_PIECES, indexValue = 0;
|
2006-09-25 18:37:45 +00:00
|
|
|
uint32_t color;
|
2006-10-05 21:21:30 +00:00
|
|
|
BOOL change;
|
2007-02-09 05:19:08 +00:00
|
|
|
for (i = 0; i < MAX_PIECES; i++)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2006-10-05 21:21:30 +00:00
|
|
|
change = NO;
|
2007-02-09 05:19:08 +00:00
|
|
|
if (piecesAvailablity[index] < 0)
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
if (fPieces[i] != -1)
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2006-10-06 20:45:59 +00:00
|
|
|
color = kBlue;
|
2007-02-09 05:19:08 +00:00
|
|
|
fPieces[i] = -1;
|
2006-10-05 21:21:30 +00:00
|
|
|
change = YES;
|
|
|
|
}
|
|
|
|
}
|
2007-02-09 05:19:08 +00:00
|
|
|
else if (piecesAvailablity[index] == 0)
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
if (fPieces[i] != 0)
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
|
|
|
color = kGray;
|
2007-02-09 05:19:08 +00:00
|
|
|
fPieces[i] = 0;
|
2006-10-05 21:21:30 +00:00
|
|
|
change = YES;
|
|
|
|
}
|
|
|
|
}
|
2006-10-05 21:34:22 +00:00
|
|
|
else
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
if (piecesAvailablity[index] == 1)
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
if (fPieces[i] != 1)
|
2006-10-05 21:34:22 +00:00
|
|
|
{
|
2006-10-06 20:45:59 +00:00
|
|
|
color = kGreen1;
|
2007-02-09 05:19:08 +00:00
|
|
|
fPieces[i] = 1;
|
2006-10-05 21:34:22 +00:00
|
|
|
change = YES;
|
|
|
|
}
|
2006-10-05 21:21:30 +00:00
|
|
|
}
|
2007-02-09 05:19:08 +00:00
|
|
|
else if (piecesAvailablity[index] == 2)
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
if (fPieces[i] != 2)
|
2006-10-05 21:34:22 +00:00
|
|
|
{
|
2006-10-06 20:45:59 +00:00
|
|
|
color = kGreen2;
|
2007-02-09 05:19:08 +00:00
|
|
|
fPieces[i] = 2;
|
2006-10-05 21:34:22 +00:00
|
|
|
change = YES;
|
|
|
|
}
|
2006-10-05 21:21:30 +00:00
|
|
|
}
|
2006-10-05 21:34:22 +00:00
|
|
|
else
|
2006-10-05 21:21:30 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
if (fPieces[i] != 3)
|
2006-10-05 21:34:22 +00:00
|
|
|
{
|
2006-10-06 20:45:59 +00:00
|
|
|
color = kGreen3;
|
2007-02-09 05:19:08 +00:00
|
|
|
fPieces[i] = 3;
|
2006-10-05 21:34:22 +00:00
|
|
|
change = YES;
|
|
|
|
}
|
2006-10-05 21:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-25 18:37:45 +00:00
|
|
|
|
2006-10-05 21:21:30 +00:00
|
|
|
if (change)
|
2006-09-25 18:37:45 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
//point to pixel (i, 2) and draw "vertically"
|
|
|
|
p = (uint32_t *)(bitmapData + 2 * bytesPerRow) + i;
|
2006-10-05 21:21:30 +00:00
|
|
|
for (h = 2; h < BAR_HEIGHT; h++)
|
|
|
|
{
|
|
|
|
p[0] = color;
|
|
|
|
p = (uint32_t *)((uint8_t *)p + bytesPerRow);
|
|
|
|
}
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
2007-02-09 05:19:08 +00:00
|
|
|
|
|
|
|
indexValue += increment;
|
|
|
|
index = (int)indexValue;
|
2006-09-25 18:37:45 +00:00
|
|
|
}
|
2006-10-05 21:34:22 +00:00
|
|
|
|
2007-02-09 14:33:57 +00:00
|
|
|
//determine percentage finished and available
|
2007-02-14 15:45:13 +00:00
|
|
|
int have = rintf((float)MAX_PIECES * [self progress]), avail;
|
2007-02-14 15:41:01 +00:00
|
|
|
if ([self progress] >= 1.0 || ![self isActive] || [self totalPeers] <= 0)
|
2007-02-09 14:33:57 +00:00
|
|
|
avail = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
float * piecesFinished = malloc(pieceCount * sizeof(float));
|
|
|
|
[self getAmountFinished: piecesFinished size: pieceCount];
|
|
|
|
|
|
|
|
float available = 0;
|
|
|
|
for (i = 0; i < pieceCount; i++)
|
2007-02-14 02:02:44 +00:00
|
|
|
if (piecesAvailablity[i] > 0)
|
|
|
|
available += 1.0 - piecesFinished[i];
|
2007-02-09 14:33:57 +00:00
|
|
|
|
2007-02-09 05:19:08 +00:00
|
|
|
avail = rintf((float)MAX_PIECES * available / (float)pieceCount);
|
2007-02-09 14:33:57 +00:00
|
|
|
if (have + avail > MAX_PIECES) //case if both end in .5 and all pieces are available
|
|
|
|
avail--;
|
|
|
|
|
|
|
|
free(piecesFinished);
|
|
|
|
}
|
2007-02-09 05:19:08 +00:00
|
|
|
|
2007-02-14 02:02:44 +00:00
|
|
|
free(piecesAvailablity);
|
|
|
|
|
2006-10-05 21:34:22 +00:00
|
|
|
//first two lines: dark blue to show progression, green to show available
|
2007-02-09 05:19:08 +00:00
|
|
|
p = (uint32_t *)bitmapData;
|
|
|
|
for (i = 0; i < have; i++)
|
2006-10-05 21:34:22 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
p[i] = kBlue2;
|
|
|
|
p[i + bytesPerRow / 4] = kBlue2;
|
2006-10-05 21:34:22 +00:00
|
|
|
}
|
2007-02-09 05:19:08 +00:00
|
|
|
for (; i < avail + have; i++)
|
2006-10-05 21:34:22 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
p[i] = kGreen3;
|
|
|
|
p[i + bytesPerRow / 4] = kGreen3;
|
2006-10-05 21:34:22 +00:00
|
|
|
}
|
2007-02-09 05:19:08 +00:00
|
|
|
for (; i < MAX_PIECES; i++)
|
2006-10-05 21:34:22 +00:00
|
|
|
{
|
2007-02-09 05:19:08 +00:00
|
|
|
p[i] = kWhite;
|
|
|
|
p[i + bytesPerRow / 4] = kWhite;
|
2006-10-05 21:34:22 +00:00
|
|
|
}
|
|
|
|
|
2006-09-25 18:37:45 +00:00
|
|
|
//actually draw image
|
2006-10-05 21:21:30 +00:00
|
|
|
NSImage * bar = [[NSImage alloc] initWithSize: [fBitmap size]];
|
|
|
|
[bar addRepresentation: fBitmap];
|
2006-09-25 18:37:45 +00:00
|
|
|
[bar setScalesWhenResized: YES];
|
|
|
|
|
|
|
|
return [bar autorelease];
|
|
|
|
}
|
|
|
|
|
2006-07-16 19:39:23 +00:00
|
|
|
- (void) trashFile: (NSString *) path
|
|
|
|
{
|
|
|
|
//attempt to move to trash
|
|
|
|
if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
|
|
|
|
source: [path stringByDeletingLastPathComponent] destination: @""
|
|
|
|
files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
|
|
|
|
{
|
|
|
|
//if cannot trash, just delete it (will work if it is on a remote volume)
|
|
|
|
if (![[NSFileManager defaultManager] removeFileAtPath: path handler: nil])
|
2006-11-09 04:38:32 +00:00
|
|
|
NSLog(@"Could not trash %@", path);
|
2006-07-16 19:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|