2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-02 16:55:05 +00:00
|
|
|
* Copyright (c) 2006-2008 Transmission authors and contributors
|
2007-09-16 01:02:06 +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"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2008-05-22 18:39:49 +00:00
|
|
|
#import "FileListNode.h"
|
2007-10-29 19:45:34 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2008-06-02 17:26:02 +00:00
|
|
|
#include "utils.h" //tr_httpIsValidURL
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
@interface Torrent (Private)
|
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
- (id) initWithHash: (NSString *) hashString path: (NSString *) path torrentStruct: (tr_torrent *) torrentStruct lib: (tr_handle *) lib
|
2007-09-16 01:02:06 +00:00
|
|
|
publicTorrent: (NSNumber *) publicTorrent
|
|
|
|
downloadFolder: (NSString *) downloadFolder
|
|
|
|
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
|
|
|
|
ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
|
2007-12-17 16:06:20 +00:00
|
|
|
waitToStart: (NSNumber *) waitToStart
|
2008-06-02 17:26:02 +00:00
|
|
|
orderValue: (NSNumber *) orderValue groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
- (BOOL) shouldUseIncompleteFolderForName: (NSString *) name;
|
|
|
|
- (void) updateDownloadFolder;
|
|
|
|
|
|
|
|
- (void) createFileList;
|
2008-05-22 18:39:49 +00:00
|
|
|
- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size index: (int) index;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
- (void) completenessChange: (NSNumber *) status;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) quickPause;
|
|
|
|
- (void) endQuickPause;
|
|
|
|
|
2008-04-07 02:55:33 +00:00
|
|
|
- (NSString *) etaString: (int) eta;
|
|
|
|
|
2008-06-05 05:00:24 +00:00
|
|
|
- (void) updateAllTrackers: (NSMutableArray *) trackers;
|
2008-06-02 19:42:14 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) trashFile: (NSString *) path;
|
|
|
|
|
2008-01-09 16:26:58 +00:00
|
|
|
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void * torrentData)
|
|
|
|
{
|
|
|
|
[(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:)
|
|
|
|
withObject: [[NSNumber alloc] initWithInt: status] waitUntilDone: NO];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@implementation Torrent
|
|
|
|
|
|
|
|
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
|
2007-09-20 20:24:33 +00:00
|
|
|
lib: (tr_handle *) lib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-26 23:23:07 +00:00
|
|
|
self = [self initWithHash: nil path: path torrentStruct: NULL lib: lib
|
2008-08-09 13:51:59 +00:00
|
|
|
publicTorrent: torrentDelete != TORRENT_FILE_DEFAULT ? [NSNumber numberWithBool: torrentDelete == TORRENT_FILE_SAVE] : nil
|
2007-09-16 01:02:06 +00:00
|
|
|
downloadFolder: location
|
|
|
|
useIncompleteFolder: nil incompleteFolder: nil
|
|
|
|
ratioSetting: nil ratioLimit: nil
|
2008-06-02 17:26:02 +00:00
|
|
|
waitToStart: nil orderValue: nil groupValue: nil addedTrackers: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2008-10-08 02:57:39 +00:00
|
|
|
//if the public and private torrent files are the same, then there is no public torrent
|
|
|
|
if ([[self torrentLocation] isEqualToString: path])
|
|
|
|
{
|
|
|
|
fPublicTorrent = NO;
|
|
|
|
[fPublicTorrentLocation release];
|
|
|
|
fPublicTorrentLocation = nil;
|
|
|
|
}
|
|
|
|
else if (!fPublicTorrent)
|
2007-09-16 01:02:06 +00:00
|
|
|
[self trashFile: path];
|
2008-10-08 02:57:39 +00:00
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_handle *) lib
|
2008-01-21 06:23:10 +00:00
|
|
|
{
|
2008-05-26 23:23:07 +00:00
|
|
|
self = [self initWithHash: nil path: nil torrentStruct: torrentStruct lib: lib
|
|
|
|
publicTorrent: [NSNumber numberWithBool: NO]
|
2008-01-21 06:23:10 +00:00
|
|
|
downloadFolder: location
|
|
|
|
useIncompleteFolder: nil incompleteFolder: nil
|
|
|
|
ratioSetting: nil ratioLimit: nil
|
2008-06-02 17:26:02 +00:00
|
|
|
waitToStart: nil orderValue: nil groupValue: nil addedTrackers: nil];
|
2008-01-21 06:23:10 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-09-20 20:24:33 +00:00
|
|
|
- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle *) lib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
self = [self initWithHash: [history objectForKey: @"TorrentHash"]
|
2008-05-26 23:23:07 +00:00
|
|
|
path: [history objectForKey: @"TorrentPath"] torrentStruct: NULL lib: lib
|
2007-09-16 01:02:06 +00:00
|
|
|
publicTorrent: [history objectForKey: @"PublicCopy"]
|
|
|
|
downloadFolder: [history objectForKey: @"DownloadFolder"]
|
|
|
|
useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
|
|
|
|
incompleteFolder: [history objectForKey: @"IncompleteFolder"]
|
|
|
|
ratioSetting: [history objectForKey: @"RatioSetting"]
|
|
|
|
ratioLimit: [history objectForKey: @"RatioLimit"]
|
|
|
|
waitToStart: [history objectForKey: @"WaitToStart"]
|
2007-12-17 16:06:20 +00:00
|
|
|
orderValue: [history objectForKey: @"OrderValue"]
|
2008-06-02 17:26:02 +00:00
|
|
|
groupValue: [history objectForKey: @"GroupValue"]
|
|
|
|
addedTrackers: [history objectForKey: @"AddedTrackers"]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
//start transfer
|
|
|
|
NSNumber * active;
|
|
|
|
if ((active = [history objectForKey: @"Active"]) && [active boolValue])
|
|
|
|
{
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
[self startTransfer];
|
|
|
|
}
|
2008-06-03 19:47:07 +00:00
|
|
|
|
2008-08-09 20:20:21 +00:00
|
|
|
//upgrading from versions < 1.30: get old added, activity, and done dates
|
2008-06-03 19:47:07 +00:00
|
|
|
NSDate * date;
|
|
|
|
if ((date = [history objectForKey: @"Date"]))
|
|
|
|
tr_torrentSetAddedDate(fHandle, [date timeIntervalSince1970]);
|
|
|
|
if ((date = [history objectForKey: @"DateActivity"]))
|
|
|
|
tr_torrentSetActivityDate(fHandle, [date timeIntervalSince1970]);
|
|
|
|
if ((date = [history objectForKey: @"DateCompleted"]))
|
|
|
|
tr_torrentSetDoneDate(fHandle, [date timeIntervalSince1970]);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) history
|
|
|
|
{
|
|
|
|
NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",
|
|
|
|
[self hashString], @"TorrentHash",
|
|
|
|
fDownloadFolder, @"DownloadFolder",
|
|
|
|
[NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
|
|
|
|
[NSNumber numberWithBool: [self isActive]], @"Active",
|
|
|
|
[NSNumber numberWithInt: fRatioSetting], @"RatioSetting",
|
|
|
|
[NSNumber numberWithFloat: fRatioLimit], @"RatioLimit",
|
|
|
|
[NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
|
2007-12-17 16:06:20 +00:00
|
|
|
[NSNumber numberWithInt: fOrderValue], @"OrderValue",
|
2008-06-02 17:26:02 +00:00
|
|
|
[NSNumber numberWithInt: fGroupValue], @"GroupValue",
|
|
|
|
[NSNumber numberWithBool: fAddedTrackers], @"AddedTrackers", nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (fIncompleteFolder)
|
|
|
|
[history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
|
|
|
|
|
|
|
|
if (fPublicTorrent)
|
|
|
|
[history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"];
|
|
|
|
|
|
|
|
return history;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-12-17 16:06:20 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
2008-03-17 19:59:26 +00:00
|
|
|
if (fFileStat)
|
|
|
|
tr_torrentFilesFree(fFileStat, [self fileCount]);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
[fPreviousFinishedIndexes release];
|
|
|
|
[fPreviousFinishedIndexesDate release];
|
2007-12-28 21:37:06 +00:00
|
|
|
|
2008-02-16 19:32:22 +00:00
|
|
|
[fNameString release];
|
2008-02-06 23:45:44 +00:00
|
|
|
[fHashString release];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fDownloadFolder release];
|
|
|
|
[fIncompleteFolder release];
|
|
|
|
|
|
|
|
[fPublicTorrentLocation release];
|
|
|
|
|
|
|
|
[fIcon release];
|
|
|
|
|
|
|
|
[fFileList release];
|
|
|
|
|
|
|
|
[fQuickPauseDict release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2008-05-12 01:32:33 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [@"Torrent: " stringByAppendingString: [self name]];
|
|
|
|
}
|
|
|
|
|
2008-08-14 02:18:14 +00:00
|
|
|
- (void) closeRemoveTorrent
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-01-05 18:30:52 +00:00
|
|
|
//allow the file to be index by Time Machine
|
2008-01-09 16:26:58 +00:00
|
|
|
[self setTimeMachineExclude: NO forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
|
2008-01-05 18:30:52 +00:00
|
|
|
|
2008-05-20 23:58:59 +00:00
|
|
|
tr_torrentRemove(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) changeIncompleteDownloadFolder: (NSString *) folder
|
|
|
|
{
|
|
|
|
fUseIncompleteFolder = folder != nil;
|
|
|
|
|
2007-09-16 16:33:49 +00:00
|
|
|
[fIncompleteFolder release];
|
|
|
|
fIncompleteFolder = fUseIncompleteFolder ? [folder retain] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[self updateDownloadFolder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) changeDownloadFolder: (NSString *) folder
|
|
|
|
{
|
2007-09-16 16:33:49 +00:00
|
|
|
[fDownloadFolder release];
|
2007-09-16 01:02:06 +00:00
|
|
|
fDownloadFolder = [folder retain];
|
|
|
|
|
|
|
|
[self updateDownloadFolder];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) downloadFolder
|
|
|
|
{
|
2008-05-19 01:05:14 +00:00
|
|
|
return [NSString stringWithUTF8String: tr_torrentGetDownloadDir(fHandle)];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getAvailability: (int8_t *) tab size: (int) size
|
|
|
|
{
|
|
|
|
tr_torrentAvailability(fHandle, tab, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) getAmountFinished: (float *) tab size: (int) size
|
|
|
|
{
|
|
|
|
tr_torrentAmountFinished(fHandle, tab, size);
|
|
|
|
}
|
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
- (NSIndexSet *) previousFinishedPieces
|
2007-12-28 21:37:06 +00:00
|
|
|
{
|
2008-06-11 16:28:33 +00:00
|
|
|
//if the torrent hasn't been seen in a bit, and therefore hasn't been refreshed, return nil
|
|
|
|
if (fPreviousFinishedIndexesDate && [fPreviousFinishedIndexesDate timeIntervalSinceNow] > -2.0)
|
|
|
|
return fPreviousFinishedIndexes;
|
2007-12-28 21:37:06 +00:00
|
|
|
else
|
2008-06-11 16:28:33 +00:00
|
|
|
return nil;
|
2007-12-28 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
-(void) setPreviousFinishedPieces: (NSIndexSet *) indexes
|
2007-12-28 21:37:06 +00:00
|
|
|
{
|
2008-06-11 16:28:33 +00:00
|
|
|
[fPreviousFinishedIndexes release];
|
|
|
|
fPreviousFinishedIndexes = [indexes retain];
|
2007-12-28 21:37:06 +00:00
|
|
|
|
2008-06-11 16:28:33 +00:00
|
|
|
[fPreviousFinishedIndexesDate release];
|
|
|
|
fPreviousFinishedIndexesDate = indexes != nil ? [[NSDate alloc] init] : nil;
|
2007-12-28 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) update
|
|
|
|
{
|
2008-01-14 04:50:19 +00:00
|
|
|
//get previous status values before update
|
2008-01-14 05:01:00 +00:00
|
|
|
BOOL wasChecking = NO, wasError = NO, wasStalled = NO;
|
|
|
|
if (fStat != NULL)
|
|
|
|
{
|
|
|
|
wasChecking = [self isChecking];
|
|
|
|
wasError = [self isError];
|
|
|
|
wasStalled = fStalled;
|
|
|
|
}
|
2008-01-14 04:50:19 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
|
|
|
|
//check to stop for ratio
|
|
|
|
float stopRatio;
|
|
|
|
if ([self isSeeding] && (stopRatio = [self actualStopRatio]) != INVALID && [self ratio] >= stopRatio)
|
|
|
|
{
|
2007-12-19 22:34:59 +00:00
|
|
|
[self setRatioSetting: NSOffState];
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentStoppedForRatio" object: self];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self stopTransfer];
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
|
|
|
|
fFinishedSeeding = YES;
|
|
|
|
}
|
2007-09-29 15:23:40 +00:00
|
|
|
|
2008-01-14 04:50:19 +00:00
|
|
|
//check if stalled (stored because based on time and needs to check if it was previously stalled)
|
2007-09-16 01:02:06 +00:00
|
|
|
fStalled = [self isActive] && [fDefaults boolForKey: @"CheckStalled"]
|
2008-03-11 03:37:09 +00:00
|
|
|
&& [self stalledMinutes] > [fDefaults integerForKey: @"StalledMinutes"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//update queue for checking (from downloading to seeding), stalled, or error
|
2008-01-14 04:50:19 +00:00
|
|
|
if ((wasChecking && ![self isChecking]) || (wasStalled != fStalled) || (!wasError && [self isError] && [self isActive]))
|
2007-09-16 01:02:06 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) startTransfer
|
|
|
|
{
|
|
|
|
fWaitToStart = NO;
|
|
|
|
fFinishedSeeding = NO;
|
|
|
|
|
|
|
|
if (![self isActive] && [self alertForFolderAvailable] && [self alertForRemainingDiskSpace])
|
|
|
|
{
|
|
|
|
tr_torrentStart(fHandle);
|
|
|
|
[self update];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) stopTransfer
|
|
|
|
{
|
|
|
|
fWaitToStart = NO;
|
|
|
|
|
|
|
|
if ([self isActive])
|
|
|
|
{
|
|
|
|
tr_torrentStop(fHandle);
|
|
|
|
[self update];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) sleep
|
|
|
|
{
|
|
|
|
if ((fResumeOnWake = [self isActive]))
|
|
|
|
tr_torrentStop(fHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) wakeUp
|
|
|
|
{
|
|
|
|
if (fResumeOnWake)
|
|
|
|
tr_torrentStart(fHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) manualAnnounce
|
|
|
|
{
|
2008-05-22 20:44:41 +00:00
|
|
|
tr_torrentManualUpdate(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canManualAnnounce
|
|
|
|
{
|
|
|
|
return tr_torrentCanManualUpdate(fHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) resetCache
|
|
|
|
{
|
2008-02-27 17:38:39 +00:00
|
|
|
tr_torrentVerify(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
[self update];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) ratio
|
|
|
|
{
|
|
|
|
return fStat->ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) ratioSetting
|
|
|
|
{
|
|
|
|
return fRatioSetting;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioSetting: (int) setting
|
|
|
|
{
|
|
|
|
fRatioSetting = setting;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) ratioLimit
|
|
|
|
{
|
|
|
|
return fRatioLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioLimit: (float) limit
|
|
|
|
{
|
|
|
|
if (limit >= 0)
|
|
|
|
fRatioLimit = limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) actualStopRatio
|
|
|
|
{
|
|
|
|
if (fRatioSetting == NSOnState)
|
|
|
|
return fRatioLimit;
|
|
|
|
else if (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"])
|
|
|
|
return [fDefaults floatForKey: @"RatioLimit"];
|
|
|
|
else
|
|
|
|
return INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) progressStopRatio
|
2008-06-24 04:00:39 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
float stopRatio, ratio;
|
|
|
|
if ((stopRatio = [self actualStopRatio]) == INVALID || (ratio = [self ratio]) >= stopRatio)
|
|
|
|
return 1.0;
|
2008-04-17 04:25:49 +00:00
|
|
|
else if (stopRatio > 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
return ratio / stopRatio;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-22 04:45:15 +00:00
|
|
|
- (tr_speedlimit) speedMode: (BOOL) upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return tr_torrentGetSpeedMode(fHandle, upload ? TR_UP : TR_DOWN);
|
|
|
|
}
|
|
|
|
|
2007-09-22 04:45:15 +00:00
|
|
|
- (void) setSpeedMode: (tr_speedlimit) mode upload: (BOOL) upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
tr_torrentSetSpeedMode(fHandle, upload ? TR_UP : TR_DOWN, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) speedLimit: (BOOL) upload
|
|
|
|
{
|
|
|
|
return tr_torrentGetSpeedLimit(fHandle, upload ? TR_UP : TR_DOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSpeedLimit: (int) limit upload: (BOOL) upload
|
|
|
|
{
|
|
|
|
tr_torrentSetSpeedLimit(fHandle, upload ? TR_UP : TR_DOWN, limit);
|
|
|
|
}
|
|
|
|
|
2007-12-22 05:21:25 +00:00
|
|
|
- (void) setMaxPeerConnect: (uint16_t) count
|
|
|
|
{
|
2008-06-17 17:17:15 +00:00
|
|
|
NSAssert(count > 0, @"max peer count must be greater than 0");
|
|
|
|
|
|
|
|
tr_torrentSetPeerLimit(fHandle, count);
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (uint16_t) maxPeerConnect
|
|
|
|
{
|
2008-05-12 16:39:32 +00:00
|
|
|
return tr_torrentGetPeerLimit(fHandle);
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) setWaitToStart: (BOOL) wait
|
|
|
|
{
|
|
|
|
fWaitToStart = wait;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) waitingToStart
|
|
|
|
{
|
|
|
|
return fWaitToStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealData
|
|
|
|
{
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealPublicTorrent
|
|
|
|
{
|
|
|
|
if (fPublicTorrent)
|
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: fPublicTorrentLocation inFileViewerRootedAtPath: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) trashData
|
|
|
|
{
|
|
|
|
[self trashFile: [self dataLocation]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) trashTorrent
|
|
|
|
{
|
|
|
|
if (fPublicTorrent)
|
2008-01-04 06:31:41 +00:00
|
|
|
{
|
|
|
|
[self trashFile: fPublicTorrentLocation];
|
|
|
|
[fPublicTorrentLocation release];
|
|
|
|
fPublicTorrentLocation = nil;
|
|
|
|
|
|
|
|
fPublicTorrent = NO;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) moveTorrentDataFileTo: (NSString *) folder
|
|
|
|
{
|
|
|
|
NSString * oldFolder = [self downloadFolder];
|
|
|
|
if (![oldFolder isEqualToString: folder] || ![fDownloadFolder isEqualToString: folder])
|
|
|
|
{
|
|
|
|
//check if moving inside itself
|
|
|
|
NSArray * oldComponents = [oldFolder pathComponents],
|
|
|
|
* newComponents = [folder pathComponents];
|
|
|
|
int count;
|
|
|
|
|
|
|
|
if ((count = [oldComponents count]) < [newComponents count]
|
|
|
|
&& [[newComponents objectAtIndex: count] isEqualToString: [self name]]
|
|
|
|
&& [oldComponents isEqualToArray:
|
|
|
|
[newComponents objectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, count)]]])
|
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: NSLocalizedString(@"A folder cannot be moved to inside itself.",
|
|
|
|
"Move inside itself alert -> title")];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
|
|
|
|
"Move inside itself alert -> message"), [self name]]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Move inside itself alert -> button")];
|
|
|
|
|
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self quickPause];
|
|
|
|
|
2007-11-21 17:39:45 +00:00
|
|
|
//allow if file can be moved or does not exist
|
2007-09-16 01:02:06 +00:00
|
|
|
if ([[NSFileManager defaultManager] movePath: [oldFolder stringByAppendingPathComponent: [self name]]
|
2007-11-21 17:39:45 +00:00
|
|
|
toPath: [folder stringByAppendingPathComponent: [self name]] handler: nil]
|
|
|
|
|| ![[NSFileManager defaultManager] fileExistsAtPath: [oldFolder stringByAppendingPathComponent: [self name]]])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//get rid of both incomplete folder and old download folder, even if move failed
|
|
|
|
fUseIncompleteFolder = NO;
|
|
|
|
if (fIncompleteFolder)
|
|
|
|
{
|
|
|
|
[fIncompleteFolder release];
|
|
|
|
fIncompleteFolder = nil;
|
|
|
|
}
|
|
|
|
[self changeDownloadFolder: folder];
|
|
|
|
|
2007-10-23 11:41:03 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[self endQuickPause];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self endQuickPause];
|
|
|
|
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: NSLocalizedString(@"There was an error moving the data file.", "Move error alert -> title")];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
|
|
|
|
"Move error alert -> message"), [self name]]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Move error alert -> button")];
|
|
|
|
|
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) copyTorrentFileTo: (NSString *) path
|
|
|
|
{
|
|
|
|
[[NSFileManager defaultManager] copyPath: [self torrentLocation] toPath: path handler: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) alertForRemainingDiskSpace
|
|
|
|
{
|
|
|
|
if ([self allDownloaded] || ![fDefaults boolForKey: @"WarningRemainingSpace"])
|
|
|
|
return YES;
|
|
|
|
|
2008-03-17 20:18:23 +00:00
|
|
|
NSFileManager * fileManager = [NSFileManager defaultManager];
|
2008-03-17 21:12:07 +00:00
|
|
|
NSString * downloadFolder = [self downloadFolder];
|
2008-03-17 20:18:23 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
NSString * volumeName;
|
2008-03-17 21:12:07 +00:00
|
|
|
if ((volumeName = [[fileManager componentsToDisplayForPath: downloadFolder] objectAtIndex: 0]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-03-17 21:44:14 +00:00
|
|
|
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
|
|
|
|
|
2008-03-17 21:12:07 +00:00
|
|
|
NSDictionary * systemAttributes = onLeopard ? [fileManager attributesOfFileSystemForPath: downloadFolder error: NULL]
|
|
|
|
: [fileManager fileSystemAttributesAtPath: downloadFolder];
|
2008-03-17 19:59:26 +00:00
|
|
|
uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue], neededSpace = 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-03-18 03:20:27 +00:00
|
|
|
//if the size left is less then remaining space, then there is enough space regardless of preallocation
|
|
|
|
if (remainingSpace < [self sizeLeft])
|
2008-03-17 19:59:26 +00:00
|
|
|
{
|
2008-03-18 03:20:27 +00:00
|
|
|
[self updateFileStat];
|
|
|
|
|
|
|
|
//determine amount needed
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < [self fileCount]; i++)
|
|
|
|
{
|
|
|
|
if (tr_torrentGetFileDL(fHandle, i))
|
|
|
|
{
|
|
|
|
tr_file * file = &fInfo->files[i];
|
|
|
|
|
|
|
|
neededSpace += file->length;
|
|
|
|
|
|
|
|
NSString * path = [downloadFolder stringByAppendingPathComponent: [NSString stringWithUTF8String: file->name]];
|
|
|
|
NSDictionary * fileAttributes = onLeopard ? [fileManager attributesOfItemAtPath: path error: NULL]
|
|
|
|
: [fileManager fileAttributesAtPath: path traverseLink: NO];
|
|
|
|
if (fileAttributes)
|
2008-04-09 18:40:22 +00:00
|
|
|
{
|
|
|
|
unsigned long long fileSize = [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
|
|
|
|
if (fileSize < neededSpace)
|
|
|
|
neededSpace -= fileSize;
|
|
|
|
else
|
|
|
|
neededSpace = 0;
|
|
|
|
}
|
2008-03-18 03:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-10 19:53:27 +00:00
|
|
|
if (remainingSpace < neededSpace)
|
2008-03-17 19:59:26 +00:00
|
|
|
{
|
2008-03-18 03:20:27 +00:00
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Not enough remaining disk space to download \"%@\" completely.",
|
2008-04-23 12:44:11 +00:00
|
|
|
"Torrent disk space alert -> title"), [self name]]];
|
2008-03-18 03:20:27 +00:00
|
|
|
[alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"The transfer will be paused."
|
|
|
|
" Clear up space on %@ or deselect files in the torrent inspector to continue.",
|
2008-04-23 12:44:11 +00:00
|
|
|
"Torrent disk space alert -> message"), volumeName]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Torrent disk space alert -> button")];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Download Anyway", "Torrent disk space alert -> button")];
|
2008-03-17 19:59:26 +00:00
|
|
|
|
2008-03-18 03:20:27 +00:00
|
|
|
if (onLeopard)
|
2008-04-23 12:44:11 +00:00
|
|
|
{
|
2008-03-18 03:20:27 +00:00
|
|
|
[alert setShowsSuppressionButton: YES];
|
2008-04-23 12:44:11 +00:00
|
|
|
[[alert suppressionButton] setTitle: NSLocalizedString(@"Do not check disk space again",
|
|
|
|
"Torrent disk space alert -> button")];
|
|
|
|
}
|
2008-03-18 03:20:27 +00:00
|
|
|
else
|
2008-04-23 12:44:11 +00:00
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Always Download", "Torrent disk space alert -> button")];
|
2008-03-18 03:20:27 +00:00
|
|
|
|
|
|
|
NSInteger result = [alert runModal];
|
|
|
|
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertThirdButtonReturn))
|
|
|
|
[fDefaults setBool: NO forKey: @"WarningRemainingSpace"];
|
|
|
|
[alert release];
|
2008-03-17 21:12:07 +00:00
|
|
|
|
2008-03-18 03:20:27 +00:00
|
|
|
return result != NSAlertFirstButtonReturn;
|
2008-03-17 19:59:26 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) alertForFolderAvailable
|
|
|
|
{
|
2007-10-13 15:58:32 +00:00
|
|
|
#warning check for change from incomplete to download folder first
|
2008-05-19 01:05:14 +00:00
|
|
|
if (access(tr_torrentGetDownloadDir(fHandle), 0))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"The folder for downloading \"%@\" cannot be used.",
|
|
|
|
"Folder cannot be used alert -> title"), [self name]]];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"\"%@\" cannot be used. The transfer will be paused.",
|
|
|
|
"Folder cannot be used alert -> message"), [self downloadFolder]]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Folder cannot be used alert -> button")];
|
|
|
|
[alert addButtonWithTitle: [NSLocalizedString(@"Choose New Location",
|
|
|
|
"Folder cannot be used alert -> location button") stringByAppendingEllipsis]];
|
|
|
|
|
|
|
|
if ([alert runModal] != NSAlertFirstButtonReturn)
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
|
|
|
[panel setPrompt: NSLocalizedString(@"Select", "Folder cannot be used alert -> prompt")];
|
|
|
|
[panel setAllowsMultipleSelection: NO];
|
|
|
|
[panel setCanChooseFiles: NO];
|
|
|
|
[panel setCanChooseDirectories: YES];
|
|
|
|
[panel setCanCreateDirectories: YES];
|
|
|
|
|
|
|
|
[panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the download folder for \"%@\"",
|
|
|
|
"Folder cannot be used alert -> select destination folder"), [self name]]];
|
|
|
|
|
|
|
|
[[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];
|
|
|
|
}
|
|
|
|
|
|
|
|
[alert release];
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) destinationChoiceClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) context
|
|
|
|
{
|
|
|
|
if (code != NSOKButton)
|
|
|
|
return;
|
|
|
|
|
2007-10-13 13:54:19 +00:00
|
|
|
[self changeDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[self startTransfer];
|
|
|
|
[self update];
|
|
|
|
|
2007-10-23 11:41:03 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) alertForMoveFolderAvailable
|
|
|
|
{
|
|
|
|
if (access([fDownloadFolder UTF8String], 0))
|
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"The folder for moving the completed \"%@\" cannot be used.",
|
|
|
|
"Move folder cannot be used alert -> title"), [self name]]];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"\"%@\" cannot be used. The file will remain in its current location.",
|
|
|
|
"Move folder cannot be used alert -> message"), fDownloadFolder]];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Move folder cannot be used alert -> button")];
|
|
|
|
|
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *) icon
|
|
|
|
{
|
|
|
|
if (!fIcon)
|
|
|
|
{
|
2008-05-29 22:16:03 +00:00
|
|
|
fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [self isFolder] ? NSFileTypeForHFSTypeCode('fldr')
|
2007-09-16 01:02:06 +00:00
|
|
|
: [[self name] pathExtension]] retain];
|
|
|
|
[fIcon setFlipped: YES];
|
|
|
|
}
|
|
|
|
return fIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) name
|
|
|
|
{
|
2008-02-16 19:32:22 +00:00
|
|
|
return fNameString;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 22:16:03 +00:00
|
|
|
- (BOOL) isFolder
|
2007-11-25 04:06:26 +00:00
|
|
|
{
|
|
|
|
return fInfo->isMultifile;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (uint64_t) size
|
|
|
|
{
|
|
|
|
return fInfo->totalSize;
|
|
|
|
}
|
|
|
|
|
2007-10-07 03:28:06 +00:00
|
|
|
- (uint64_t) sizeLeft
|
|
|
|
{
|
|
|
|
return fStat->leftUntilDone;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSString *) trackerAddressAnnounce
|
|
|
|
{
|
2008-05-22 16:59:51 +00:00
|
|
|
return fStat->announceURL ? [NSString stringWithUTF8String: fStat->announceURL] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 01:36:30 +00:00
|
|
|
- (NSDate *) lastAnnounceTime
|
|
|
|
{
|
2008-05-22 23:11:21 +00:00
|
|
|
int date = fStat->lastAnnounceTime;
|
2008-02-22 01:36:30 +00:00
|
|
|
return date > 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) nextAnnounceTime
|
|
|
|
{
|
2008-05-22 23:11:21 +00:00
|
|
|
int date = fStat->nextAnnounceTime;
|
2008-07-11 21:48:43 +00:00
|
|
|
NSTimeInterval difference;
|
|
|
|
switch (date)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return STAT_TIME_NONE;
|
|
|
|
case 1:
|
|
|
|
return STAT_TIME_NOW;
|
|
|
|
default:
|
|
|
|
difference = [[NSDate dateWithTimeIntervalSince1970: date] timeIntervalSinceNow];
|
|
|
|
return difference > 0 ? (int)difference : STAT_TIME_NONE;
|
|
|
|
}
|
2008-02-22 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) announceResponse
|
|
|
|
{
|
2008-05-22 23:11:21 +00:00
|
|
|
return [NSString stringWithUTF8String: fStat->announceResponse];
|
2008-02-22 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) trackerAddressScrape
|
|
|
|
{
|
2008-05-22 16:59:51 +00:00
|
|
|
return fStat->scrapeURL ? [NSString stringWithUTF8String: fStat->scrapeURL] : nil;
|
2008-02-22 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) lastScrapeTime
|
|
|
|
{
|
2008-05-22 23:11:21 +00:00
|
|
|
int date = fStat->lastScrapeTime;
|
2008-02-22 01:36:30 +00:00
|
|
|
return date > 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) nextScrapeTime
|
|
|
|
{
|
2008-05-22 23:11:21 +00:00
|
|
|
int date = fStat->nextScrapeTime;
|
2008-07-11 21:48:43 +00:00
|
|
|
NSTimeInterval difference;
|
|
|
|
switch (date)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return STAT_TIME_NONE;
|
|
|
|
case 1:
|
|
|
|
return STAT_TIME_NOW;
|
|
|
|
default:
|
|
|
|
difference = [[NSDate dateWithTimeIntervalSince1970: date] timeIntervalSinceNow];
|
|
|
|
return difference > 0 ? (int)difference : STAT_TIME_NONE;
|
|
|
|
}
|
2008-02-22 01:36:30 +00:00
|
|
|
}
|
2008-03-22 17:05:48 +00:00
|
|
|
|
2008-02-22 01:36:30 +00:00
|
|
|
- (NSString *) scrapeResponse
|
|
|
|
{
|
2008-05-22 23:11:21 +00:00
|
|
|
return [NSString stringWithUTF8String: fStat->scrapeResponse];
|
2008-02-22 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:26:02 +00:00
|
|
|
- (NSMutableArray *) allTrackers: (BOOL) separators
|
2007-10-24 18:49:59 +00:00
|
|
|
{
|
2008-04-24 14:41:41 +00:00
|
|
|
int count = fInfo->trackerCount, capacity = count;
|
|
|
|
if (separators)
|
|
|
|
capacity += fInfo->trackers[count-1].tier + 1;
|
|
|
|
NSMutableArray * allTrackers = [NSMutableArray arrayWithCapacity: capacity];
|
2008-02-27 13:52:43 +00:00
|
|
|
|
2008-04-24 01:55:33 +00:00
|
|
|
int i, tier = -1;
|
2008-04-24 06:42:45 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2007-10-24 18:49:59 +00:00
|
|
|
{
|
2008-04-24 14:41:41 +00:00
|
|
|
if (separators && tier != fInfo->trackers[i].tier)
|
2008-04-24 06:42:45 +00:00
|
|
|
{
|
|
|
|
tier = fInfo->trackers[i].tier;
|
2008-06-02 17:26:02 +00:00
|
|
|
[allTrackers addObject: [NSNumber numberWithInt: fAddedTrackers ? tier : tier + 1]];
|
2008-04-24 06:42:45 +00:00
|
|
|
}
|
2008-03-22 17:05:48 +00:00
|
|
|
|
2008-04-24 01:55:33 +00:00
|
|
|
[allTrackers addObject: [NSString stringWithUTF8String: fInfo->trackers[i].announce]];
|
2007-10-24 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
return allTrackers;
|
2007-10-24 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:42:14 +00:00
|
|
|
- (BOOL) updateAllTrackersForAdd: (NSMutableArray *) trackers
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2008-06-02 19:42:14 +00:00
|
|
|
//find added tracker at end of first tier
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < [trackers count]; i++)
|
|
|
|
if ([[trackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
|
|
|
|
break;
|
|
|
|
i--;
|
|
|
|
|
|
|
|
NSString * tracker = [trackers objectAtIndex: i];
|
2008-09-06 13:37:33 +00:00
|
|
|
|
2008-09-06 13:49:20 +00:00
|
|
|
tracker = [tracker stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
2008-09-06 13:37:33 +00:00
|
|
|
|
2008-06-02 19:42:14 +00:00
|
|
|
if ([tracker rangeOfString: @"://"].location == NSNotFound)
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2008-06-02 19:42:14 +00:00
|
|
|
tracker = [@"http://" stringByAppendingString: tracker];
|
|
|
|
[trackers replaceObjectAtIndex: i withObject: tracker];
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:42:14 +00:00
|
|
|
if (!tr_httpIsValidURL([tracker UTF8String]))
|
|
|
|
return NO;
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2008-06-05 05:00:24 +00:00
|
|
|
[self updateAllTrackers: trackers];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2008-06-05 05:00:24 +00:00
|
|
|
fAddedTrackers = YES;
|
|
|
|
return YES;
|
2008-06-02 19:42:14 +00:00
|
|
|
}
|
|
|
|
|
2008-06-05 15:22:18 +00:00
|
|
|
- (void) updateAllTrackersForRemove: (NSMutableArray *) trackers
|
2008-06-02 19:42:14 +00:00
|
|
|
{
|
2008-06-05 05:00:24 +00:00
|
|
|
//check if no user-added groups
|
2008-06-02 19:42:14 +00:00
|
|
|
if ([[trackers objectAtIndex: 0] intValue] != 0)
|
|
|
|
fAddedTrackers = NO;
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2008-06-05 05:00:24 +00:00
|
|
|
[self updateAllTrackers: trackers];
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasAddedTrackers
|
|
|
|
{
|
|
|
|
return fAddedTrackers;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSString *) comment
|
|
|
|
{
|
2008-02-16 19:32:22 +00:00
|
|
|
return [NSString stringWithUTF8String: fInfo->comment];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) creator
|
|
|
|
{
|
2008-02-16 19:32:22 +00:00
|
|
|
return [NSString stringWithUTF8String: fInfo->creator];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateCreated
|
|
|
|
{
|
|
|
|
int date = fInfo->dateCreated;
|
|
|
|
return date > 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) pieceSize
|
|
|
|
{
|
|
|
|
return fInfo->pieceSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) pieceCount
|
|
|
|
{
|
|
|
|
return fInfo->pieceCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) hashString
|
|
|
|
{
|
2008-02-06 23:45:44 +00:00
|
|
|
return fHashString;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) privateTorrent
|
|
|
|
{
|
2007-10-15 21:52:51 +00:00
|
|
|
return fInfo->isPrivate;
|
2007-09-16 01:02:06 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) progress
|
|
|
|
{
|
|
|
|
return fStat->percentComplete;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) progressDone
|
|
|
|
{
|
|
|
|
return fStat->percentDone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) progressLeft
|
2007-10-15 18:44:39 +00:00
|
|
|
{
|
2007-10-07 03:28:06 +00:00
|
|
|
return (float)[self sizeLeft] / [self size];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-10 20:59:56 +00:00
|
|
|
- (float) checkingProgress
|
|
|
|
{
|
|
|
|
return fStat->recheckProgress;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (int) eta
|
|
|
|
{
|
|
|
|
return fStat->eta;
|
|
|
|
}
|
|
|
|
|
2007-11-23 17:42:49 +00:00
|
|
|
- (int) etaRatio
|
|
|
|
{
|
|
|
|
if (![self isSeeding])
|
2008-04-16 12:32:07 +00:00
|
|
|
return TR_ETA_UNKNOWN;
|
2007-11-23 17:42:49 +00:00
|
|
|
|
|
|
|
float uploadRate = [self uploadRate];
|
|
|
|
if (uploadRate < 0.1)
|
2008-04-06 14:44:30 +00:00
|
|
|
return TR_ETA_UNKNOWN;
|
2007-11-23 17:42:49 +00:00
|
|
|
|
|
|
|
float stopRatio = [self actualStopRatio], ratio = [self ratio];
|
|
|
|
if (stopRatio == INVALID || ratio >= stopRatio)
|
2008-04-06 14:44:30 +00:00
|
|
|
return TR_ETA_UNKNOWN;
|
2007-11-23 17:42:49 +00:00
|
|
|
|
2008-04-15 19:57:56 +00:00
|
|
|
return (float)MAX([self downloadedTotal], [self haveTotal]) * (stopRatio - ratio) / uploadRate / 1024.0;
|
2007-11-23 17:42:49 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 20:42:20 +00:00
|
|
|
- (float) notAvailableDesired
|
2007-10-15 18:44:39 +00:00
|
|
|
{
|
2008-04-16 12:32:07 +00:00
|
|
|
return 1.0 - (float)fStat->desiredAvailable / [self sizeLeft];
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
2007-09-27 12:44:25 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (BOOL) isActive
|
|
|
|
{
|
2007-10-20 21:27:46 +00:00
|
|
|
return fStat->status != TR_STATUS_STOPPED;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSeeding
|
|
|
|
{
|
2008-03-31 17:59:16 +00:00
|
|
|
return fStat->status == TR_STATUS_SEED;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isChecking
|
|
|
|
{
|
|
|
|
return fStat->status == TR_STATUS_CHECK || fStat->status == TR_STATUS_CHECK_WAIT;
|
|
|
|
}
|
|
|
|
|
2008-03-19 18:03:02 +00:00
|
|
|
- (BOOL) isCheckingWaiting
|
|
|
|
{
|
|
|
|
return fStat->status == TR_STATUS_CHECK_WAIT;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (BOOL) allDownloaded
|
|
|
|
{
|
2007-10-15 18:20:39 +00:00
|
|
|
return [self progressDone] >= 1.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isComplete
|
|
|
|
{
|
2007-10-15 18:20:39 +00:00
|
|
|
return [self progress] >= 1.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isError
|
|
|
|
{
|
2008-04-22 13:16:39 +00:00
|
|
|
return fStat->error != TR_OK;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) errorMessage
|
|
|
|
{
|
|
|
|
if (![self isError])
|
|
|
|
return @"";
|
|
|
|
|
|
|
|
NSString * error;
|
|
|
|
if (!(error = [NSString stringWithUTF8String: fStat->errorString])
|
|
|
|
&& !(error = [NSString stringWithCString: fStat->errorString encoding: NSISOLatin1StringEncoding]))
|
2008-04-06 03:35:18 +00:00
|
|
|
error = [NSString stringWithFormat: @"(%@)", NSLocalizedString(@"unreadable error", "Torrent -> error string unreadable")];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) peers
|
|
|
|
{
|
|
|
|
int totalPeers, i;
|
2007-09-20 20:24:33 +00:00
|
|
|
tr_peer_stat * peers = tr_torrentPeers(fHandle, &totalPeers);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-03-18 21:59:17 +00:00
|
|
|
NSMutableArray * peerDicts = [NSMutableArray arrayWithCapacity: totalPeers];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
for (i = 0; i < totalPeers; i++)
|
|
|
|
{
|
2008-03-18 21:59:17 +00:00
|
|
|
tr_peer_stat * peer = &peers[i];
|
|
|
|
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 9];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-03-18 21:59:17 +00:00
|
|
|
[dict setObject: [NSNumber numberWithInt: peer->from] forKey: @"From"];
|
|
|
|
[dict setObject: [NSString stringWithUTF8String: peer->addr] forKey: @"IP"];
|
|
|
|
[dict setObject: [NSNumber numberWithInt: peer->port] forKey: @"Port"];
|
|
|
|
[dict setObject: [NSNumber numberWithFloat: peer->progress] forKey: @"Progress"];
|
|
|
|
[dict setObject: [NSNumber numberWithBool: peer->isEncrypted] forKey: @"Encryption"];
|
|
|
|
[dict setObject: [NSString stringWithUTF8String: peer->client] forKey: @"Client"];
|
|
|
|
[dict setObject: [NSString stringWithUTF8String: peer->flagStr] forKey: @"Flags"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-10 00:52:02 +00:00
|
|
|
if (peer->isUploadingTo)
|
2008-08-22 17:59:31 +00:00
|
|
|
[dict setObject: [NSNumber numberWithFloat: peer->rateToPeer] forKey: @"UL To Rate"];
|
2008-01-10 00:52:02 +00:00
|
|
|
if (peer->isDownloadingFrom)
|
2008-08-22 17:59:31 +00:00
|
|
|
[dict setObject: [NSNumber numberWithFloat: peer->rateToClient] forKey: @"DL From Rate"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-03-18 21:59:17 +00:00
|
|
|
[peerDicts addObject: dict];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tr_torrentPeersFree(peers, totalPeers);
|
|
|
|
|
2008-03-18 21:59:17 +00:00
|
|
|
return peerDicts;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 16:38:15 +00:00
|
|
|
- (NSUInteger) webSeedCount
|
|
|
|
{
|
|
|
|
return fInfo->webseedCount;
|
|
|
|
}
|
|
|
|
|
2008-06-08 18:02:16 +00:00
|
|
|
- (NSArray *) webSeeds
|
2008-06-07 23:38:05 +00:00
|
|
|
{
|
|
|
|
int webSeedCount = fInfo->webseedCount, i;
|
2008-06-08 18:02:16 +00:00
|
|
|
NSMutableArray * webSeeds = [NSMutableArray arrayWithCapacity: webSeedCount];
|
2008-06-07 23:38:05 +00:00
|
|
|
|
2008-06-10 01:49:09 +00:00
|
|
|
float * dlSpeeds = tr_torrentWebSpeeds(fHandle);
|
|
|
|
|
2008-06-07 23:38:05 +00:00
|
|
|
for (i = 0; i < webSeedCount; i++)
|
2008-06-08 15:54:34 +00:00
|
|
|
{
|
|
|
|
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 2];
|
|
|
|
|
|
|
|
[dict setObject: [NSString stringWithUTF8String: fInfo->webseeds[i]] forKey: @"Address"];
|
|
|
|
|
2008-06-10 02:40:40 +00:00
|
|
|
if (dlSpeeds[i] != -1.0)
|
2008-06-10 01:49:09 +00:00
|
|
|
[dict setObject: [NSNumber numberWithFloat: dlSpeeds[i]] forKey: @"DL From Rate"];
|
2008-06-08 15:54:34 +00:00
|
|
|
|
2008-06-08 18:02:16 +00:00
|
|
|
[webSeeds addObject: dict];
|
2008-06-08 15:54:34 +00:00
|
|
|
}
|
2008-06-07 23:38:05 +00:00
|
|
|
|
2008-06-10 01:49:09 +00:00
|
|
|
tr_free(dlSpeeds);
|
|
|
|
|
2008-06-08 18:02:16 +00:00
|
|
|
return webSeeds;
|
2008-06-07 23:38:05 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSString *) progressString
|
|
|
|
{
|
2007-09-27 20:42:20 +00:00
|
|
|
NSString * string;
|
|
|
|
|
|
|
|
if (![self allDownloaded])
|
|
|
|
{
|
2008-04-08 03:32:07 +00:00
|
|
|
float progress;
|
2008-05-29 22:16:03 +00:00
|
|
|
if ([self isFolder] && [fDefaults boolForKey: @"DisplayStatusProgressSelected"])
|
2008-04-08 03:32:07 +00:00
|
|
|
{
|
2008-04-07 13:43:26 +00:00
|
|
|
string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@ selected", "Torrent -> progress string"),
|
|
|
|
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self totalSizeSelected]]];
|
2008-04-08 03:32:07 +00:00
|
|
|
progress = 100.0 * [self progressDone];
|
|
|
|
}
|
2007-09-27 20:42:20 +00:00
|
|
|
else
|
2008-04-08 03:32:07 +00:00
|
|
|
{
|
2008-04-07 13:43:26 +00:00
|
|
|
string = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
|
|
|
|
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
|
2008-04-08 03:32:07 +00:00
|
|
|
progress = 100.0 * [self progress];
|
|
|
|
}
|
2008-04-07 13:43:26 +00:00
|
|
|
|
2008-04-08 03:32:07 +00:00
|
|
|
string = [NSString localizedStringWithFormat: @"%@ (%.2f%%)", string, progress];
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
2008-03-31 19:36:11 +00:00
|
|
|
else
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2008-03-31 19:36:11 +00:00
|
|
|
NSString * downloadString;
|
|
|
|
if (![self isComplete]) //only multifile possible
|
|
|
|
{
|
|
|
|
if ([fDefaults boolForKey: @"DisplayStatusProgressSelected"])
|
|
|
|
downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ selected", "Torrent -> progress string"),
|
2008-04-07 13:43:26 +00:00
|
|
|
[NSString stringForFileSize: [self haveTotal]]];
|
2008-03-31 19:36:11 +00:00
|
|
|
else
|
2008-04-07 13:43:26 +00:00
|
|
|
{
|
|
|
|
downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
|
|
|
|
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
|
|
|
|
|
|
|
|
downloadString = [NSString localizedStringWithFormat: @"%@ (%.2f%%)", downloadString, 100.0 * [self progress]];
|
|
|
|
}
|
2008-03-31 19:36:11 +00:00
|
|
|
}
|
2007-09-27 20:42:20 +00:00
|
|
|
else
|
2008-03-31 19:36:11 +00:00
|
|
|
downloadString = [NSString stringForFileSize: [self size]];
|
|
|
|
|
|
|
|
NSString * uploadString = [NSString stringWithFormat: NSLocalizedString(@"uploaded %@ (Ratio: %@)",
|
|
|
|
"Torrent -> progress string"), [NSString stringForFileSize: [self uploadedTotal]],
|
|
|
|
[NSString stringForRatio: [self ratio]]];
|
|
|
|
|
2008-04-07 14:09:28 +00:00
|
|
|
string = [downloadString stringByAppendingFormat: @", %@", uploadString];
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//add time when downloading
|
2007-12-22 22:02:38 +00:00
|
|
|
if (fStat->status == TR_STATUS_DOWNLOAD || ([self isSeeding]
|
|
|
|
&& (fRatioSetting == NSOnState || (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"]))))
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2007-11-23 17:49:05 +00:00
|
|
|
int eta = fStat->status == TR_STATUS_DOWNLOAD ? [self eta] : [self etaRatio];
|
2008-04-07 02:55:33 +00:00
|
|
|
string = [string stringByAppendingFormat: @" - %@", [self etaString: eta]];
|
2007-11-23 17:42:49 +00:00
|
|
|
}
|
2007-09-27 20:42:20 +00:00
|
|
|
|
|
|
|
return string;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) statusString
|
|
|
|
{
|
2007-09-27 21:12:56 +00:00
|
|
|
NSString * string;
|
2007-09-27 20:42:20 +00:00
|
|
|
|
2007-09-27 21:02:25 +00:00
|
|
|
if ([self isError])
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2008-02-22 15:39:20 +00:00
|
|
|
string = NSLocalizedString(@"Error", "Torrent -> status string");
|
2007-09-27 20:42:20 +00:00
|
|
|
NSString * errorString = [self errorMessage];
|
2008-02-22 15:39:20 +00:00
|
|
|
if (errorString && ![errorString isEqualToString: @""])
|
2008-04-01 02:18:28 +00:00
|
|
|
string = [string stringByAppendingFormat: @": %@", errorString];
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
2007-09-27 21:12:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (fStat->status)
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
if (fWaitToStart)
|
|
|
|
{
|
|
|
|
string = ![self allDownloaded]
|
|
|
|
? [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis]
|
|
|
|
: [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
}
|
|
|
|
else if (fFinishedSeeding)
|
|
|
|
string = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
|
|
|
else
|
|
|
|
string = NSLocalizedString(@"Paused", "Torrent -> status string");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2008-03-24 00:06:54 +00:00
|
|
|
string = [NSString localizedStringWithFormat: NSLocalizedString(@"Checking existing data (%.2f%%)",
|
2008-01-10 20:59:56 +00:00
|
|
|
"Torrent -> status string"), 100.0 * [self checkingProgress]];
|
2007-09-27 21:12:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
if ([self totalPeersConnected] != 1)
|
|
|
|
string = [NSString stringWithFormat: NSLocalizedString(@"Downloading from %d of %d peers",
|
|
|
|
"Torrent -> status string"), [self peersSendingToUs], [self totalPeersConnected]];
|
|
|
|
else
|
|
|
|
string = [NSString stringWithFormat: NSLocalizedString(@"Downloading from %d of 1 peer",
|
|
|
|
"Torrent -> status string"), [self peersSendingToUs]];
|
2008-06-10 01:49:09 +00:00
|
|
|
|
2008-06-10 02:40:40 +00:00
|
|
|
int webSeedCount = fStat->webseedsSendingToUs;
|
2008-06-10 01:49:09 +00:00
|
|
|
if (webSeedCount > 0)
|
|
|
|
{
|
|
|
|
NSString * webSeedString;
|
|
|
|
if (webSeedCount == 1)
|
2008-06-11 19:16:47 +00:00
|
|
|
webSeedString = NSLocalizedString(@"web seed", "Torrent -> status string");
|
2008-06-10 01:49:09 +00:00
|
|
|
else
|
|
|
|
webSeedString = [NSString stringWithFormat: NSLocalizedString(@"%d web seeds", "Torrent -> status string"),
|
|
|
|
webSeedCount];
|
|
|
|
|
|
|
|
string = [string stringByAppendingFormat: @" + %@", webSeedString];
|
2008-06-10 02:40:40 +00:00
|
|
|
}
|
2008-06-10 01:49:09 +00:00
|
|
|
|
2007-09-27 21:12:56 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
if ([self totalPeersConnected] != 1)
|
|
|
|
string = [NSString stringWithFormat: NSLocalizedString(@"Seeding to %d of %d peers", "Torrent -> status string"),
|
|
|
|
[self peersGettingFromUs], [self totalPeersConnected]];
|
|
|
|
else
|
|
|
|
string = [NSString stringWithFormat: NSLocalizedString(@"Seeding to %d of 1 peer", "Torrent -> status string"),
|
|
|
|
[self peersGettingFromUs]];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fStalled)
|
2008-04-22 13:16:39 +00:00
|
|
|
string = [NSLocalizedString(@"Stalled", "Torrent -> status string") stringByAppendingFormat: @", %@", string];
|
2007-10-01 11:34:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//append even if error
|
|
|
|
if ([self isActive] && ![self isChecking])
|
|
|
|
{
|
|
|
|
if (fStat->status == TR_STATUS_DOWNLOAD)
|
2008-03-18 21:59:17 +00:00
|
|
|
string = [string stringByAppendingFormat: @" - %@: %@, %@: %@",
|
|
|
|
NSLocalizedString(@"DL", "Torrent -> status string"), [NSString stringForSpeed: [self downloadRate]],
|
|
|
|
NSLocalizedString(@"UL", "Torrent -> status string"), [NSString stringForSpeed: [self uploadRate]]];
|
2007-10-01 11:34:01 +00:00
|
|
|
else
|
2008-03-18 21:59:17 +00:00
|
|
|
string = [string stringByAppendingFormat: @" - %@: %@",
|
|
|
|
NSLocalizedString(@"UL", "Torrent -> status string"), [NSString stringForSpeed: [self uploadRate]]];
|
2007-09-27 21:12:56 +00:00
|
|
|
}
|
2007-09-27 20:42:20 +00:00
|
|
|
|
|
|
|
return string;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) shortStatusString
|
|
|
|
{
|
2007-09-27 21:12:56 +00:00
|
|
|
NSString * string;
|
2007-09-27 20:42:20 +00:00
|
|
|
|
|
|
|
switch (fStat->status)
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
if (fWaitToStart)
|
|
|
|
{
|
|
|
|
string = ![self allDownloaded]
|
|
|
|
? [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis]
|
|
|
|
: [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
}
|
|
|
|
else if (fFinishedSeeding)
|
|
|
|
string = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
|
|
|
else
|
|
|
|
string = NSLocalizedString(@"Paused", "Torrent -> status string");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2008-03-24 00:06:54 +00:00
|
|
|
string = [NSString localizedStringWithFormat: NSLocalizedString(@"Checking existing data (%.2f%%)",
|
2008-01-10 20:59:56 +00:00
|
|
|
"Torrent -> status string"), 100.0 * [self checkingProgress]];
|
2007-09-27 20:42:20 +00:00
|
|
|
break;
|
2007-09-30 13:33:50 +00:00
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
2008-03-18 21:59:17 +00:00
|
|
|
string = [NSString stringWithFormat: @"%@: %@, %@: %@",
|
|
|
|
NSLocalizedString(@"DL", "Torrent -> status string"), [NSString stringForSpeed: [self downloadRate]],
|
|
|
|
NSLocalizedString(@"UL", "Torrent -> status string"), [NSString stringForSpeed: [self uploadRate]]];
|
2007-09-30 13:33:50 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
2008-03-18 21:59:17 +00:00
|
|
|
string = [NSString stringWithFormat: @"%@: %@, %@: %@",
|
|
|
|
NSLocalizedString(@"Ratio", "Torrent -> status string"), [NSString stringForRatio: [self ratio]],
|
|
|
|
NSLocalizedString(@"UL", "Torrent -> status string"), [NSString stringForSpeed: [self uploadRate]]];
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) remainingTimeString
|
|
|
|
{
|
2008-02-16 19:32:22 +00:00
|
|
|
if (![self isActive] || ([self isSeeding]
|
|
|
|
&& !(fRatioSetting == NSOnState || (fRatioSetting == NSMixedState && [fDefaults boolForKey: @"RatioCheck"]))))
|
|
|
|
return [self shortStatusString];
|
|
|
|
|
2008-04-07 02:55:33 +00:00
|
|
|
return [self etaString: [self isSeeding] ? [self etaRatio] : [self eta]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-28 02:58:25 +00:00
|
|
|
- (NSString *) stateString
|
|
|
|
{
|
|
|
|
switch (fStat->status)
|
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
return NSLocalizedString(@"Paused", "Torrent -> status string");
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2008-03-24 00:06:54 +00:00
|
|
|
return [NSString localizedStringWithFormat: NSLocalizedString(@"Checking existing data (%.2f%%)",
|
2008-01-10 20:59:56 +00:00
|
|
|
"Torrent -> status string"), 100.0 * [self checkingProgress]];
|
2007-09-28 02:58:25 +00:00
|
|
|
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
return [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
return NSLocalizedString(@"Downloading", "Torrent -> status string");
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
return NSLocalizedString(@"Seeding", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (int) seeders
|
|
|
|
{
|
|
|
|
return fStat->seeders;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) leechers
|
|
|
|
{
|
|
|
|
return fStat->leechers;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) completedFromTracker
|
|
|
|
{
|
2008-06-16 03:47:50 +00:00
|
|
|
return fStat->timesCompleted;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) totalPeersConnected
|
|
|
|
{
|
|
|
|
return fStat->peersConnected;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) totalPeersTracker
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_TRACKER];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) totalPeersIncoming
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_INCOMING];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) totalPeersCache
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_CACHE];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) totalPeersPex
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_PEX];
|
|
|
|
}
|
|
|
|
|
2007-10-01 16:23:00 +00:00
|
|
|
- (int) totalPeersKnown
|
|
|
|
{
|
|
|
|
return fStat->peersKnown;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (int) peersSendingToUs
|
|
|
|
{
|
|
|
|
return fStat->peersSendingToUs;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) peersGettingFromUs
|
|
|
|
{
|
|
|
|
return fStat->peersGettingFromUs;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) downloadRate
|
|
|
|
{
|
|
|
|
return fStat->rateDownload;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) uploadRate
|
|
|
|
{
|
|
|
|
return fStat->rateUpload;
|
|
|
|
}
|
|
|
|
|
2007-11-23 16:03:49 +00:00
|
|
|
- (float) totalRate
|
|
|
|
{
|
|
|
|
return [self downloadRate] + [self uploadRate];
|
|
|
|
}
|
|
|
|
|
2007-09-26 03:27:00 +00:00
|
|
|
- (uint64_t) haveVerified
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 03:27:00 +00:00
|
|
|
return fStat->haveValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (uint64_t) haveTotal
|
|
|
|
{
|
|
|
|
return [self haveVerified] + fStat->haveUnchecked;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 19:34:55 +00:00
|
|
|
- (uint64_t) totalSizeSelected
|
|
|
|
{
|
2008-04-21 00:12:05 +00:00
|
|
|
return fStat->sizeWhenDone;
|
2008-02-27 19:34:55 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 18:53:11 +00:00
|
|
|
- (uint64_t) downloadedTotal
|
2007-09-26 18:32:32 +00:00
|
|
|
{
|
2007-09-26 18:53:11 +00:00
|
|
|
return fStat->downloadedEver;
|
2007-09-26 18:32:32 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 18:53:11 +00:00
|
|
|
- (uint64_t) uploadedTotal
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 18:53:11 +00:00
|
|
|
return fStat->uploadedEver;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-26 18:32:32 +00:00
|
|
|
- (uint64_t) failedHash
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-09-26 18:32:32 +00:00
|
|
|
return fStat->corruptEver;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float) swarmSpeed
|
|
|
|
{
|
2008-05-19 01:05:14 +00:00
|
|
|
return fStat->swarmSpeed;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 15:45:58 +00:00
|
|
|
- (int) orderValue
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-14 22:29:20 +00:00
|
|
|
return fOrderValue;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setOrderValue: (int) orderValue
|
|
|
|
{
|
2007-11-23 15:45:58 +00:00
|
|
|
fOrderValue = orderValue;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
- (int) groupValue
|
|
|
|
{
|
|
|
|
return fGroupValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setGroupValue: (int) goupValue
|
|
|
|
{
|
|
|
|
fGroupValue = goupValue;
|
|
|
|
}
|
|
|
|
|
2007-12-17 20:10:51 +00:00
|
|
|
- (int) groupOrderValue
|
|
|
|
{
|
2008-03-23 04:36:30 +00:00
|
|
|
return [[GroupsController groups] rowValueForIndex: fGroupValue];
|
2007-12-17 20:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 21:11:49 +00:00
|
|
|
- (void) checkGroupValueForRemoval: (NSNotification *) notification
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
|
|
|
if (fGroupValue != -1 && [[[notification userInfo] objectForKey: @"Indexes"] containsIndex: fGroupValue])
|
|
|
|
fGroupValue = -1;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSArray *) fileList
|
|
|
|
{
|
|
|
|
return fFileList;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) fileCount
|
|
|
|
{
|
|
|
|
return fInfo->fileCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateFileStat
|
|
|
|
{
|
2008-03-17 19:59:26 +00:00
|
|
|
if (fFileStat)
|
|
|
|
tr_torrentFilesFree(fFileStat, [self fileCount]);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-03-22 20:50:41 +00:00
|
|
|
fFileStat = tr_torrentFiles(fHandle, NULL);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (float) fileProgress: (int) index
|
|
|
|
{
|
2008-03-17 19:59:26 +00:00
|
|
|
if (!fFileStat)
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateFileStat];
|
|
|
|
|
2008-03-17 19:59:26 +00:00
|
|
|
return fFileStat[index].progress;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canChangeDownloadCheckForFile: (int) index
|
|
|
|
{
|
2008-03-17 19:59:26 +00:00
|
|
|
if (!fFileStat)
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateFileStat];
|
|
|
|
|
2008-03-17 19:59:26 +00:00
|
|
|
return [self fileCount] > 1 && fFileStat[index].progress < 1.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet
|
|
|
|
{
|
|
|
|
if ([self fileCount] <= 1 || [self isComplete])
|
|
|
|
return NO;
|
|
|
|
|
2008-03-17 19:59:26 +00:00
|
|
|
if (!fFileStat)
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateFileStat];
|
|
|
|
|
|
|
|
int index;
|
|
|
|
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
2008-03-17 19:59:26 +00:00
|
|
|
if (fFileStat[index].progress < 1.0)
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) checkForFiles: (NSIndexSet *) indexSet
|
|
|
|
{
|
|
|
|
BOOL onState = NO, offState = NO;
|
|
|
|
int index;
|
|
|
|
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
|
|
|
{
|
|
|
|
if (tr_torrentGetFileDL(fHandle, index) || ![self canChangeDownloadCheckForFile: index])
|
|
|
|
onState = YES;
|
|
|
|
else
|
|
|
|
offState = YES;
|
|
|
|
|
|
|
|
if (onState && offState)
|
|
|
|
return NSMixedState;
|
|
|
|
}
|
|
|
|
return onState ? NSOnState : NSOffState;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFileCheckState: (int) state forIndexes: (NSIndexSet *) indexSet
|
|
|
|
{
|
2008-03-22 18:18:39 +00:00
|
|
|
NSUInteger count = [indexSet count], i = 0, index;
|
2008-03-22 18:22:10 +00:00
|
|
|
tr_file_index_t * files = malloc(count * sizeof(tr_file_index_t));
|
2007-09-16 01:02:06 +00:00
|
|
|
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
|
|
|
{
|
|
|
|
files[i] = index;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_torrentSetFileDLs(fHandle, files, count, state != NSOffState);
|
|
|
|
free(files);
|
|
|
|
|
|
|
|
[self update];
|
2008-02-27 19:34:55 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFileCheckChange" object: self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet
|
|
|
|
{
|
2008-03-22 18:18:39 +00:00
|
|
|
NSUInteger count = [indexSet count], i = 0, index;
|
2008-03-22 18:22:10 +00:00
|
|
|
tr_file_index_t * files = malloc(count * sizeof(tr_file_index_t));
|
2007-09-16 01:02:06 +00:00
|
|
|
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
|
|
|
{
|
|
|
|
files[i] = index;
|
|
|
|
i++;
|
|
|
|
}
|
2007-10-20 00:43:39 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
tr_torrentSetFilePriorities(fHandle, files, count, priority);
|
|
|
|
free(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
|
|
|
if (priority == tr_torrentGetFilePriority(fHandle, index) && [self canChangeDownloadCheckForFile: index])
|
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet
|
|
|
|
{
|
|
|
|
BOOL low = NO, normal = NO, high = NO;
|
|
|
|
NSMutableSet * priorities = [NSMutableSet setWithCapacity: 3];
|
|
|
|
|
|
|
|
int index, priority;
|
|
|
|
for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
|
|
|
{
|
|
|
|
if (![self canChangeDownloadCheckForFile: index])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
priority = tr_torrentGetFilePriority(fHandle, index);
|
|
|
|
if (priority == TR_PRI_LOW)
|
|
|
|
{
|
|
|
|
if (low)
|
|
|
|
continue;
|
|
|
|
low = YES;
|
|
|
|
}
|
|
|
|
else if (priority == TR_PRI_HIGH)
|
|
|
|
{
|
|
|
|
if (high)
|
|
|
|
continue;
|
|
|
|
high = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (normal)
|
|
|
|
continue;
|
|
|
|
normal = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
[priorities addObject: [NSNumber numberWithInt: priority]];
|
|
|
|
if (low && normal && high)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return priorities;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateAdded
|
|
|
|
{
|
2008-06-03 19:47:07 +00:00
|
|
|
time_t date = fStat->addedDate;
|
|
|
|
return [NSDate dateWithTimeIntervalSince1970: date];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateCompleted
|
|
|
|
{
|
2008-06-03 19:47:07 +00:00
|
|
|
time_t date = fStat->doneDate;
|
|
|
|
return date != 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateActivity
|
|
|
|
{
|
2008-05-23 20:04:41 +00:00
|
|
|
time_t date = fStat->activityDate;
|
2008-06-03 19:47:07 +00:00
|
|
|
return date != 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 02:46:29 +00:00
|
|
|
- (NSDate *) dateActivityOrAdd
|
|
|
|
{
|
|
|
|
NSDate * date = [self dateActivity];
|
|
|
|
return date ? date : [self dateAdded];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (int) stalledMinutes
|
|
|
|
{
|
2008-06-03 19:47:07 +00:00
|
|
|
time_t start = fStat->startDate;
|
|
|
|
if (start == 0)
|
2007-09-16 01:02:06 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-05-23 20:04:41 +00:00
|
|
|
NSDate * started = [NSDate dateWithTimeIntervalSince1970: start],
|
2007-09-16 01:02:06 +00:00
|
|
|
* activity = [self dateActivity];
|
|
|
|
|
2008-03-11 03:37:09 +00:00
|
|
|
NSDate * laterDate = activity ? [started laterDate: activity] : started;
|
2007-09-16 01:02:06 +00:00
|
|
|
return -1 * [laterDate timeIntervalSinceNow] / 60;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isStalled
|
|
|
|
{
|
|
|
|
return fStalled;
|
|
|
|
}
|
|
|
|
|
2008-06-30 02:22:29 +00:00
|
|
|
- (NSInteger) stateSortKey
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-06-30 02:22:29 +00:00
|
|
|
if (![self isActive]) //paused
|
|
|
|
return 0;
|
|
|
|
else if ([self isSeeding]) //seeding
|
|
|
|
return 1;
|
|
|
|
else //downloading
|
|
|
|
return 2;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-04-07 13:14:31 +00:00
|
|
|
- (tr_torrent *) torrentStruct
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-07 13:14:31 +00:00
|
|
|
return fHandle;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Torrent (Private)
|
|
|
|
|
|
|
|
//if a hash is given, attempt to load that; otherwise, attempt to open file at path
|
2008-05-26 23:23:07 +00:00
|
|
|
- (id) initWithHash: (NSString *) hashString path: (NSString *) path torrentStruct: (tr_torrent *) torrentStruct lib: (tr_handle *) lib
|
2007-09-16 01:02:06 +00:00
|
|
|
publicTorrent: (NSNumber *) publicTorrent
|
|
|
|
downloadFolder: (NSString *) downloadFolder
|
|
|
|
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
|
|
|
|
ratioSetting: (NSNumber *) ratioSetting ratioLimit: (NSNumber *) ratioLimit
|
2007-12-17 16:06:20 +00:00
|
|
|
waitToStart: (NSNumber *) waitToStart
|
2008-06-02 17:26:02 +00:00
|
|
|
orderValue: (NSNumber *) orderValue groupValue: (NSNumber *) groupValue addedTrackers: (NSNumber *) addedTrackers
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
fPublicTorrent = path && (publicTorrent ? [publicTorrent boolValue] : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
|
|
|
|
if (fPublicTorrent)
|
|
|
|
fPublicTorrentLocation = [path retain];
|
|
|
|
|
|
|
|
fDownloadFolder = downloadFolder ? downloadFolder : [fDefaults stringForKey: @"DownloadFolder"];
|
|
|
|
fDownloadFolder = [[fDownloadFolder stringByExpandingTildeInPath] retain];
|
|
|
|
|
|
|
|
fUseIncompleteFolder = useIncompleteFolder ? [useIncompleteFolder boolValue]
|
|
|
|
: [fDefaults boolForKey: @"UseIncompleteDownloadFolder"];
|
|
|
|
if (fUseIncompleteFolder)
|
|
|
|
{
|
|
|
|
fIncompleteFolder = incompleteFolder ? incompleteFolder : [fDefaults stringForKey: @"IncompleteDownloadFolder"];
|
|
|
|
fIncompleteFolder = [[fIncompleteFolder stringByExpandingTildeInPath] retain];
|
|
|
|
}
|
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
if (torrentStruct)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-26 23:23:07 +00:00
|
|
|
fHandle = torrentStruct;
|
2008-05-27 00:52:18 +00:00
|
|
|
fInfo = tr_torrentInfo(fHandle);
|
2008-05-26 23:23:07 +00:00
|
|
|
|
2008-05-27 00:52:18 +00:00
|
|
|
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: fInfo->name]]
|
2007-12-22 18:43:40 +00:00
|
|
|
? fIncompleteFolder : fDownloadFolder;
|
2008-05-26 23:23:07 +00:00
|
|
|
tr_torrentSetDownloadDir(fHandle, [currentDownloadFolder UTF8String]);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-05-26 23:23:07 +00:00
|
|
|
else
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-26 23:23:07 +00:00
|
|
|
//set libtransmission settings for initialization
|
|
|
|
tr_ctor * ctor = tr_ctorNew(lib);
|
|
|
|
tr_ctorSetPaused(ctor, TR_FORCE, YES);
|
|
|
|
tr_ctorSetPeerLimit(ctor, TR_FALLBACK, [fDefaults integerForKey: @"PeersTorrent"]);
|
|
|
|
|
|
|
|
tr_info info;
|
|
|
|
if (hashString)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-26 23:23:07 +00:00
|
|
|
tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
|
|
|
|
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
|
|
|
|
{
|
|
|
|
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
|
|
|
|
? fIncompleteFolder : fDownloadFolder;
|
|
|
|
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
|
|
|
|
|
|
|
|
fHandle = tr_torrentNew(lib, ctor, NULL);
|
|
|
|
}
|
|
|
|
tr_metainfoFree(&info);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-05-26 23:23:07 +00:00
|
|
|
if (!fHandle && path)
|
2008-01-21 06:23:10 +00:00
|
|
|
{
|
2008-05-26 23:23:07 +00:00
|
|
|
tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
|
|
|
|
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
|
|
|
|
{
|
|
|
|
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
|
|
|
|
? fIncompleteFolder : fDownloadFolder;
|
|
|
|
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
|
|
|
|
|
|
|
|
fHandle = tr_torrentNew(lib, ctor, NULL);
|
|
|
|
}
|
|
|
|
tr_metainfoFree(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_ctorFree(ctor);
|
|
|
|
|
|
|
|
if (!fHandle)
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
return nil;
|
2008-01-21 06:23:10 +00:00
|
|
|
}
|
2008-05-27 00:52:18 +00:00
|
|
|
|
|
|
|
fInfo = tr_torrentInfo(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
tr_torrentSetStatusCallback(fHandle, completenessChangeCallback, self);
|
|
|
|
|
2008-02-16 19:32:22 +00:00
|
|
|
fNameString = [[NSString alloc] initWithUTF8String: fInfo->name];
|
2008-02-06 23:45:44 +00:00
|
|
|
fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
fRatioSetting = ratioSetting ? [ratioSetting intValue] : NSMixedState;
|
|
|
|
fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];
|
|
|
|
fFinishedSeeding = NO;
|
|
|
|
|
2008-01-04 04:54:26 +00:00
|
|
|
fWaitToStart = waitToStart && [waitToStart boolValue];
|
2008-04-25 22:23:31 +00:00
|
|
|
fResumeOnWake = NO;
|
2007-10-14 22:29:20 +00:00
|
|
|
|
2008-05-22 20:44:41 +00:00
|
|
|
fOrderValue = orderValue ? [orderValue intValue] : tr_sessionCountTorrents(lib) - 1;
|
2007-12-26 20:18:29 +00:00
|
|
|
fGroupValue = groupValue ? [groupValue intValue] : -1;
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2008-06-02 17:26:02 +00:00
|
|
|
fAddedTrackers = addedTrackers ? [addedTrackers boolValue] : NO;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self createFileList];
|
|
|
|
|
2007-12-19 21:11:49 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(checkGroupValueForRemoval:)
|
2007-12-17 16:06:20 +00:00
|
|
|
name: @"GroupValueRemoved" object: nil];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self update];
|
2007-10-31 19:28:22 +00:00
|
|
|
|
|
|
|
//mark incomplete files to be ignored by Time Machine
|
2008-01-09 16:26:58 +00:00
|
|
|
[self setTimeMachineExclude: ![self allDownloaded] forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
|
2007-10-31 19:28:22 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) createFileList
|
|
|
|
{
|
2008-05-29 22:16:03 +00:00
|
|
|
if ([self isFolder])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
int count = [self fileCount], i;
|
|
|
|
NSMutableArray * fileList = [[NSMutableArray alloc] initWithCapacity: count];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
tr_file * file = &fInfo->files[i];
|
|
|
|
|
|
|
|
NSMutableArray * pathComponents = [[[NSString stringWithUTF8String: file->name] pathComponents] mutableCopy];
|
|
|
|
NSString * path = [pathComponents objectAtIndex: 0];
|
|
|
|
NSString * name = [pathComponents objectAtIndex: 1];
|
|
|
|
[pathComponents removeObjectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, 2)]];
|
|
|
|
|
|
|
|
if ([pathComponents count] > 0)
|
|
|
|
{
|
2008-05-22 21:06:56 +00:00
|
|
|
//determine if folder node already exists
|
2008-05-22 18:39:49 +00:00
|
|
|
NSEnumerator * enumerator = [fileList objectEnumerator];
|
|
|
|
FileListNode * node;
|
|
|
|
while ((node = [enumerator nextObject]))
|
2008-05-22 21:06:56 +00:00
|
|
|
if ([[node name] isEqualToString: name] && [node isFolder])
|
2008-05-22 18:39:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
node = [[FileListNode alloc] initWithFolderName: name path: path];
|
|
|
|
[fileList addObject: node];
|
|
|
|
[node release];
|
|
|
|
}
|
|
|
|
|
2008-05-22 21:06:56 +00:00
|
|
|
[node insertIndex: i withSize: file->length];
|
2008-05-22 18:39:49 +00:00
|
|
|
[self insertPath: pathComponents forParent: node fileSize: file->length index: i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i];
|
|
|
|
[fileList addObject: node];
|
|
|
|
[node release];
|
|
|
|
}
|
|
|
|
|
|
|
|
[pathComponents release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
fFileList = [[NSArray alloc] initWithArray: fileList];
|
|
|
|
[fileList release];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0];
|
|
|
|
fFileList = [[NSArray arrayWithObject: node] retain];
|
|
|
|
[node release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size index: (int) index
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSString * name = [components objectAtIndex: 0];
|
|
|
|
BOOL isFolder = [components count] > 1;
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
FileListNode * node = nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (isFolder)
|
|
|
|
{
|
2008-05-22 18:39:49 +00:00
|
|
|
NSEnumerator * enumerator = [[parent children] objectEnumerator];
|
|
|
|
while ((node = [enumerator nextObject]))
|
|
|
|
if ([[node name] isEqualToString: name] && [node isFolder])
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
//create new folder or file if it doesn't already exist
|
|
|
|
if (!node)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (isFolder)
|
2008-05-22 18:39:49 +00:00
|
|
|
node = [[FileListNode alloc] initWithFolderName: name path: [parent fullPath]];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-05-22 18:39:49 +00:00
|
|
|
node = [[FileListNode alloc] initWithFileName: name path: [parent fullPath] size: size index: index];
|
|
|
|
|
|
|
|
[parent insertChild: node];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isFolder)
|
|
|
|
{
|
2008-05-22 21:06:56 +00:00
|
|
|
[node insertIndex: index withSize: size];
|
2008-05-22 18:39:49 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[components removeObjectAtIndex: 0];
|
2008-05-22 18:39:49 +00:00
|
|
|
[self insertPath: components forParent: node fileSize: size index: index];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) shouldUseIncompleteFolderForName: (NSString *) name
|
|
|
|
{
|
|
|
|
return fUseIncompleteFolder &&
|
|
|
|
![[NSFileManager defaultManager] fileExistsAtPath: [fDownloadFolder stringByAppendingPathComponent: name]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateDownloadFolder
|
|
|
|
{
|
2008-01-05 04:30:20 +00:00
|
|
|
//remove old Time Machine location
|
2008-01-09 16:26:58 +00:00
|
|
|
[self setTimeMachineExclude: NO forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
|
2008-01-05 04:30:20 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
NSString * folder = [self shouldUseIncompleteFolderForName: [self name]] ? fIncompleteFolder : fDownloadFolder;
|
2008-05-19 01:05:14 +00:00
|
|
|
tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
|
2008-01-05 04:30:20 +00:00
|
|
|
|
2008-01-09 16:26:58 +00:00
|
|
|
[self setTimeMachineExclude: ![self allDownloaded] forPath: [folder stringByAppendingPathComponent: [self name]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-29 15:23:40 +00:00
|
|
|
//status has been retained
|
2007-09-28 15:36:46 +00:00
|
|
|
- (void) completenessChange: (NSNumber *) status
|
|
|
|
{
|
2008-06-16 23:27:38 +00:00
|
|
|
fStat = tr_torrentStat(fHandle); //don't call update yet to avoid auto-stop
|
2007-09-29 15:23:40 +00:00
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
BOOL canMove;
|
|
|
|
switch ([status intValue])
|
|
|
|
{
|
|
|
|
case TR_CP_DONE:
|
|
|
|
case TR_CP_COMPLETE:
|
|
|
|
canMove = YES;
|
2008-02-16 19:32:22 +00:00
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
//move file from incomplete folder to download folder
|
|
|
|
if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder]
|
|
|
|
&& (canMove = [self alertForMoveFolderAvailable]))
|
|
|
|
{
|
|
|
|
[self quickPause];
|
|
|
|
|
|
|
|
if ([[NSFileManager defaultManager] movePath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]
|
|
|
|
toPath: [fDownloadFolder stringByAppendingPathComponent: [self name]] handler: nil])
|
|
|
|
[self updateDownloadFolder];
|
|
|
|
else
|
|
|
|
canMove = NO;
|
|
|
|
|
|
|
|
[self endQuickPause];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canMove)
|
|
|
|
{
|
|
|
|
fUseIncompleteFolder = NO;
|
|
|
|
|
|
|
|
[fDownloadFolder release];
|
|
|
|
fDownloadFolder = fIncompleteFolder;
|
|
|
|
fIncompleteFolder = nil;
|
|
|
|
}
|
|
|
|
|
2007-10-31 19:28:22 +00:00
|
|
|
//allow to be backed up by Time Machine
|
2008-01-09 16:26:58 +00:00
|
|
|
[self setTimeMachineExclude: NO forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
|
2007-10-31 19:28:22 +00:00
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_CP_INCOMPLETE:
|
2007-10-31 19:28:22 +00:00
|
|
|
//do not allow to be backed up by Time Machine
|
2008-01-09 16:26:58 +00:00
|
|
|
[self setTimeMachineExclude: YES forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
|
2007-10-31 19:28:22 +00:00
|
|
|
|
2007-09-28 15:36:46 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRestartedDownloading" object: self];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[status release];
|
2008-06-16 23:27:38 +00:00
|
|
|
|
|
|
|
[self update];
|
2007-09-28 15:36:46 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) quickPause
|
|
|
|
{
|
|
|
|
if (fQuickPauseDict)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fQuickPauseDict = [[NSDictionary alloc] initWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithInt: [self speedMode: YES]], @"UploadSpeedMode",
|
|
|
|
[NSNumber numberWithInt: [self speedLimit: YES]], @"UploadSpeedLimit",
|
|
|
|
[NSNumber numberWithInt: [self speedMode: NO]], @"DownloadSpeedMode",
|
|
|
|
[NSNumber numberWithInt: [self speedLimit: NO]], @"DownloadSpeedLimit", nil];
|
|
|
|
|
|
|
|
[self setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: YES];
|
|
|
|
[self setSpeedLimit: 0 upload: YES];
|
|
|
|
[self setSpeedMode: TR_SPEEDLIMIT_SINGLE upload: NO];
|
|
|
|
[self setSpeedLimit: 0 upload: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) endQuickPause
|
|
|
|
{
|
|
|
|
if (!fQuickPauseDict)
|
|
|
|
return;
|
|
|
|
|
|
|
|
[self setSpeedMode: [[fQuickPauseDict objectForKey: @"UploadSpeedMode"] intValue] upload: YES];
|
|
|
|
[self setSpeedLimit: [[fQuickPauseDict objectForKey: @"UploadSpeedLimit"] intValue] upload: YES];
|
|
|
|
[self setSpeedMode: [[fQuickPauseDict objectForKey: @"DownloadSpeedMode"] intValue] upload: NO];
|
|
|
|
[self setSpeedLimit: [[fQuickPauseDict objectForKey: @"DownloadSpeedLimit"] intValue] upload: NO];
|
|
|
|
|
|
|
|
[fQuickPauseDict release];
|
|
|
|
fQuickPauseDict = nil;
|
|
|
|
}
|
|
|
|
|
2008-04-07 02:55:33 +00:00
|
|
|
- (NSString *) etaString: (int) eta
|
|
|
|
{
|
|
|
|
switch (eta)
|
|
|
|
{
|
2008-04-07 04:05:57 +00:00
|
|
|
case TR_ETA_NOT_AVAIL:
|
2008-04-07 02:55:33 +00:00
|
|
|
case TR_ETA_UNKNOWN:
|
|
|
|
return NSLocalizedString(@"remaining time unknown", "Torrent -> eta string");
|
|
|
|
default:
|
|
|
|
return [NSString stringWithFormat: NSLocalizedString(@"%@ remaining", "Torrent -> eta string"),
|
2008-06-25 05:01:04 +00:00
|
|
|
[NSString timeString: eta showSeconds: YES maxFields: 2]];
|
2008-04-07 02:55:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-05 05:00:24 +00:00
|
|
|
- (void) updateAllTrackers: (NSMutableArray *) trackers
|
2008-06-02 19:42:14 +00:00
|
|
|
{
|
|
|
|
//get count
|
|
|
|
int count = 0;
|
|
|
|
NSEnumerator * enumerator = [trackers objectEnumerator];
|
|
|
|
id object;
|
|
|
|
while ((object = [enumerator nextObject]))
|
|
|
|
if (![object isKindOfClass: [NSNumber class]])
|
|
|
|
count++;
|
|
|
|
|
|
|
|
//recreate the tracker structure
|
|
|
|
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, count);
|
|
|
|
int tier = 0;
|
|
|
|
int i = 0;
|
|
|
|
enumerator = [trackers objectEnumerator];
|
|
|
|
while ((object = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if (![object isKindOfClass: [NSNumber class]])
|
|
|
|
{
|
|
|
|
trackerStructs[i].tier = tier;
|
|
|
|
trackerStructs[i].announce = (char *)[object UTF8String];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tier++;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_torrentSetAnnounceList(fHandle, trackerStructs, count);
|
|
|
|
tr_free(trackerStructs);
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) trashFile: (NSString *) path
|
|
|
|
{
|
|
|
|
//attempt to move to trash
|
|
|
|
if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
|
2008-04-07 03:54:23 +00:00
|
|
|
source: [path stringByDeletingLastPathComponent] destination: @""
|
|
|
|
files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-04-07 03:54:23 +00:00
|
|
|
//if cannot trash, just delete it (will work if it's on a remote volume)
|
2008-04-06 03:06:26 +00:00
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
{
|
|
|
|
NSError * error;
|
|
|
|
if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
|
|
|
|
NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (![[NSFileManager defaultManager] removeFileAtPath: path handler: nil])
|
|
|
|
NSLog(@"Could not trash %@", path);
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-09 16:26:58 +00:00
|
|
|
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
|
|
|
|
{
|
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
CSBackupSetItemExcluded((CFURLRef)[NSURL fileURLWithPath: path], exclude, true);
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|