2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2010-01-01 21:12:04 +00:00
|
|
|
* Copyright (c) 2006-2010 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-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
#import "TrackerNode.h"
|
2010-04-23 16:59:14 +00:00
|
|
|
|
|
|
|
#import "transmission.h" // required by utils.h
|
|
|
|
#import "utils.h" // tr_new()
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-08-14 17:41:12 +00:00
|
|
|
#define ETA_IDLE_DISPLAY_SEC (2*60)
|
2010-08-14 17:32:52 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface Torrent (Private)
|
|
|
|
|
2009-12-13 01:36:22 +00:00
|
|
|
- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct
|
|
|
|
magnetAddress: (NSString *) magnetAddress lib: (tr_session *) lib
|
2007-12-17 16:06:20 +00:00
|
|
|
waitToStart: (NSNumber *) waitToStart
|
2009-10-22 00:10:41 +00:00
|
|
|
groupValue: (NSNumber *) groupValue
|
2010-11-08 12:28:30 +00:00
|
|
|
timeMachineExcludeLocation: (NSString *) timeMachineExclude
|
|
|
|
downloadFolder: (NSString *) downloadFolder
|
|
|
|
legacyIncompleteFolder: (NSString *) incompleteFolder;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
- (void) createFileList;
|
2008-12-07 02:36:26 +00:00
|
|
|
- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size
|
|
|
|
index: (NSInteger) index flatList: (NSMutableArray *) flatFileList;
|
2010-10-23 20:20:31 +00:00
|
|
|
- (void) sortFileList: (NSMutableArray *) fileNodes;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-06-25 22:19:28 +00:00
|
|
|
- (void) completenessChange: (NSDictionary *) statusInfo;
|
2009-02-14 21:15:57 +00:00
|
|
|
- (void) ratioLimitHit;
|
2010-07-24 03:19:41 +00:00
|
|
|
- (void) idleLimitHit;
|
2009-11-27 03:44:00 +00:00
|
|
|
- (void) metadataRetrieved;
|
2009-02-14 21:15:57 +00:00
|
|
|
|
2010-08-14 17:32:52 +00:00
|
|
|
- (BOOL) shouldShowEta;
|
2009-02-14 21:15:57 +00:00
|
|
|
- (NSString *) etaString;
|
2008-04-07 02:55:33 +00:00
|
|
|
|
2008-01-09 16:26:58 +00:00
|
|
|
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
2010-06-25 22:19:28 +00:00
|
|
|
void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, tr_bool wasRunning, void * torrentData)
|
2007-09-28 15:36:46 +00:00
|
|
|
{
|
2010-06-25 22:19:28 +00:00
|
|
|
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [NSNumber numberWithInt: status], @"Status",
|
|
|
|
[NSNumber numberWithBool: wasRunning], @"WasRunning", nil];
|
|
|
|
[(Torrent *)torrentData performSelectorOnMainThread: @selector(completenessChange:) withObject: dict waitUntilDone: NO];
|
2009-02-14 21:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ratioLimitHitCallback(tr_torrent * torrent, void * torrentData)
|
|
|
|
{
|
|
|
|
[(Torrent *)torrentData performSelectorOnMainThread: @selector(ratioLimitHit) withObject: nil waitUntilDone: NO];
|
2007-09-28 15:36:46 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
void idleLimitHitCallback(tr_torrent * torrent, void * torrentData)
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2010-07-24 03:19:41 +00:00
|
|
|
[(Torrent *)torrentData performSelectorOnMainThread: @selector(idleLimitHit) withObject: nil waitUntilDone: NO];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2009-11-27 03:44:00 +00:00
|
|
|
void metadataCallback(tr_torrent * torrent, void * torrentData)
|
|
|
|
{
|
|
|
|
[(Torrent *)torrentData performSelectorOnMainThread: @selector(metadataRetrieved) withObject: nil waitUntilDone: NO];
|
|
|
|
}
|
|
|
|
|
2008-12-24 01:55:33 +00:00
|
|
|
int trashDataFile(const char * filename)
|
|
|
|
{
|
2009-10-26 02:33:23 +00:00
|
|
|
if (filename != NULL)
|
|
|
|
[Torrent trashFile: [NSString stringWithUTF8String: filename]];
|
2008-12-24 01:55:33 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@implementation Torrent
|
|
|
|
|
2009-07-20 00:40:01 +00:00
|
|
|
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete
|
2008-12-22 19:14:43 +00:00
|
|
|
lib: (tr_session *) lib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-12-13 01:36:22 +00:00
|
|
|
self = [self initWithPath: path hash: nil torrentStruct: NULL magnetAddress: nil lib: lib
|
2009-10-22 00:10:41 +00:00
|
|
|
waitToStart: nil groupValue: nil
|
2010-11-08 12:28:30 +00:00
|
|
|
timeMachineExcludeLocation: nil
|
|
|
|
downloadFolder: location
|
|
|
|
legacyIncompleteFolder: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
2009-07-22 14:10:07 +00:00
|
|
|
if (torrentDelete && ![[self torrentLocation] isEqualToString: path])
|
2008-12-24 01:55:33 +00:00
|
|
|
[Torrent trashFile: path];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-12-22 19:14:43 +00:00
|
|
|
- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib
|
2008-01-21 06:23:10 +00:00
|
|
|
{
|
2009-12-13 01:36:22 +00:00
|
|
|
self = [self initWithPath: nil hash: nil torrentStruct: torrentStruct magnetAddress: nil lib: lib
|
2009-10-22 00:10:41 +00:00
|
|
|
waitToStart: nil groupValue: nil
|
2010-11-08 12:28:30 +00:00
|
|
|
timeMachineExcludeLocation: nil
|
|
|
|
downloadFolder: location
|
|
|
|
legacyIncompleteFolder: nil];
|
2008-01-21 06:23:10 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-11-25 04:11:52 +00:00
|
|
|
- (id) initWithMagnetAddress: (NSString *) address location: (NSString *) location lib: (tr_session *) lib
|
|
|
|
{
|
2009-12-13 01:36:22 +00:00
|
|
|
self = [self initWithPath: nil hash: nil torrentStruct: nil magnetAddress: address
|
|
|
|
lib: lib waitToStart: nil groupValue: nil
|
2010-11-08 12:28:30 +00:00
|
|
|
timeMachineExcludeLocation: nil
|
2009-12-13 01:36:22 +00:00
|
|
|
downloadFolder: location legacyIncompleteFolder: nil];
|
2009-11-25 04:11:52 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-05-12 00:58:22 +00:00
|
|
|
- (id) initWithHistory: (NSDictionary *) history lib: (tr_session *) lib forcePause: (BOOL) pause
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-05-22 02:08:51 +00:00
|
|
|
self = [self initWithPath: [history objectForKey: @"InternalTorrentPath"]
|
|
|
|
hash: [history objectForKey: @"TorrentHash"]
|
2009-12-13 01:36:22 +00:00
|
|
|
torrentStruct: NULL
|
|
|
|
magnetAddress: nil
|
|
|
|
lib: lib
|
2007-09-16 01:02:06 +00:00
|
|
|
waitToStart: [history objectForKey: @"WaitToStart"]
|
2009-10-22 00:10:41 +00:00
|
|
|
groupValue: [history objectForKey: @"GroupValue"]
|
2010-11-08 12:28:30 +00:00
|
|
|
timeMachineExcludeLocation: [history objectForKey: @"TimeMachineExcludeLocation"]
|
2009-12-11 04:01:47 +00:00
|
|
|
downloadFolder: [history objectForKey: @"DownloadFolder"] //upgrading from versions < 1.80
|
2009-10-22 00:10:41 +00:00
|
|
|
legacyIncompleteFolder: [[history objectForKey: @"UseIncompleteFolder"] boolValue] //upgrading from versions < 1.80
|
|
|
|
? [history objectForKey: @"IncompleteFolder"] : nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
if (self)
|
|
|
|
{
|
|
|
|
//start transfer
|
|
|
|
NSNumber * active;
|
2009-05-12 00:58:22 +00:00
|
|
|
if (!pause && (active = [history objectForKey: @"Active"]) && [active boolValue])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
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]);
|
2009-02-14 21:15:57 +00:00
|
|
|
|
|
|
|
//upgrading from versions < 1.60: get old stop ratio settings
|
|
|
|
NSNumber * ratioSetting;
|
|
|
|
if ((ratioSetting = [history objectForKey: @"RatioSetting"]))
|
|
|
|
{
|
|
|
|
switch ([ratioSetting intValue])
|
|
|
|
{
|
|
|
|
case NSOnState: [self setRatioSetting: TR_RATIOLIMIT_SINGLE]; break;
|
|
|
|
case NSOffState: [self setRatioSetting: TR_RATIOLIMIT_UNLIMITED]; break;
|
|
|
|
case NSMixedState: [self setRatioSetting: TR_RATIOLIMIT_GLOBAL]; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NSNumber * ratioLimit;
|
|
|
|
if ((ratioLimit = [history objectForKey: @"RatioLimit"]))
|
|
|
|
[self setRatioLimit: [ratioLimit floatValue]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) history
|
|
|
|
{
|
2010-11-08 12:28:30 +00:00
|
|
|
NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[self torrentLocation], @"InternalTorrentPath",
|
|
|
|
[self hashString], @"TorrentHash",
|
|
|
|
[NSNumber numberWithBool: [self isActive]], @"Active",
|
|
|
|
[NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
|
|
|
|
[NSNumber numberWithInt: fGroupValue], @"GroupValue", nil];
|
|
|
|
|
|
|
|
if (fTimeMachineExclude)
|
|
|
|
[history setObject: fTimeMachineExclude forKey: @"TimeMachineExcludeLocation"];
|
|
|
|
|
|
|
|
return history;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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-06 23:45:44 +00:00
|
|
|
[fHashString release];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fIcon release];
|
|
|
|
|
|
|
|
[fFileList release];
|
2008-12-07 02:36:26 +00:00
|
|
|
[fFlatFileList release];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
[fTimeMachineExclude release];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2008-05-12 01:32:33 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [@"Torrent: " stringByAppendingString: [self name]];
|
|
|
|
}
|
|
|
|
|
2010-02-13 04:30:47 +00:00
|
|
|
- (id) copyWithZone: (NSZone *) zone
|
|
|
|
{
|
|
|
|
return [self retain];
|
|
|
|
}
|
|
|
|
|
2008-08-14 02:18:14 +00:00
|
|
|
- (void) closeRemoveTorrent
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-11-08 12:28:30 +00:00
|
|
|
//allow the file to be indexed by Time Machine
|
2009-10-21 13:01:14 +00:00
|
|
|
if (fTimeMachineExclude)
|
2009-10-21 13:03:37 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
[self setTimeMachineExclude: NO forPath: fTimeMachineExclude];
|
2009-10-21 13:03:37 +00:00
|
|
|
[fTimeMachineExclude release];
|
|
|
|
fTimeMachineExclude = nil;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
- (void) changeDownloadFolderBeforeUsing: (NSString *) folder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
|
|
|
|
[self updateTimeMachineExclude];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
- (NSString *) currentDirectory
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
return [NSString stringWithUTF8String: tr_torrentGetCurrentDir(fHandle)];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (void) getAvailability: (int8_t *) tab size: (NSInteger) size
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
tr_torrentAvailability(fHandle, tab, size);
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (void) getAmountFinished: (float *) tab size: (NSInteger) size
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
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];
|
2009-10-21 13:01:14 +00:00
|
|
|
|
|
|
|
//when the data first appears, update time machine exclusion
|
|
|
|
if (!fTimeMachineExclude)
|
|
|
|
[self updateTimeMachineExclude];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) startTransfer
|
|
|
|
{
|
|
|
|
fWaitToStart = NO;
|
|
|
|
|
2009-10-25 13:20:52 +00:00
|
|
|
if (![self isActive] && [self alertForRemainingDiskSpace])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-04-14 13:54:18 +00:00
|
|
|
tr_ninf( fInfo->name, "restarting via startTransfer" );
|
2007-09-16 01:02:06 +00:00
|
|
|
tr_torrentStart(fHandle);
|
|
|
|
[self update];
|
2010-04-02 18:05:39 +00:00
|
|
|
|
2010-07-16 03:12:57 +00:00
|
|
|
//capture, specifically, stop-seeding settings changing to unlimited
|
2010-04-02 18:05:39 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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)
|
2010-04-14 13:36:43 +00:00
|
|
|
{
|
2010-04-14 13:54:18 +00:00
|
|
|
tr_ninf( fInfo->name, "restarting because of wakeUp" );
|
2007-09-16 01:02:06 +00:00
|
|
|
tr_torrentStart(fHandle);
|
2010-04-14 13:36:43 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
|
2009-11-25 05:04:19 +00:00
|
|
|
- (BOOL) isMagnet
|
|
|
|
{
|
|
|
|
return !tr_torrentHasMetadata(fHandle);
|
|
|
|
}
|
|
|
|
|
2009-12-04 13:35:15 +00:00
|
|
|
- (NSString *) magnetLink
|
|
|
|
{
|
|
|
|
return [NSString stringWithUTF8String: tr_torrentGetMagnetLink(fHandle)];
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) ratio
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->ratio;
|
|
|
|
}
|
|
|
|
|
2009-02-14 21:15:57 +00:00
|
|
|
- (tr_ratiolimit) ratioSetting
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-02-14 21:15:57 +00:00
|
|
|
return tr_torrentGetRatioMode(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-02-14 21:15:57 +00:00
|
|
|
- (void) setRatioSetting: (tr_ratiolimit) setting
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-02-14 21:15:57 +00:00
|
|
|
tr_torrentSetRatioMode(fHandle, setting);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) ratioLimit
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-02-14 21:15:57 +00:00
|
|
|
return tr_torrentGetRatioLimit(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (void) setRatioLimit: (CGFloat) limit
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-02-14 21:15:57 +00:00
|
|
|
NSAssert(limit >= 0, @"Ratio cannot be negative");
|
|
|
|
tr_torrentSetRatioLimit(fHandle, limit);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) progressStopRatio
|
2008-06-24 04:00:39 +00:00
|
|
|
{
|
2010-04-14 00:03:34 +00:00
|
|
|
return fStat->seedRatioPercentDone;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
- (tr_idlelimit) idleSetting
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2010-07-24 03:19:41 +00:00
|
|
|
return tr_torrentGetIdleMode(fHandle);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
- (void) setIdleSetting: (tr_idlelimit) setting
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2010-07-24 03:19:41 +00:00
|
|
|
tr_torrentSetIdleMode(fHandle, setting);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
- (NSUInteger) idleLimitMinutes
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2010-07-24 03:19:41 +00:00
|
|
|
return tr_torrentGetIdleLimit(fHandle);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
- (void) setIdleLimitMinutes: (NSUInteger) limit
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2010-07-24 03:19:41 +00:00
|
|
|
NSAssert(limit > 0, @"Idle limit must be greater than zero");
|
|
|
|
tr_torrentSetIdleLimit(fHandle, limit);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
- (BOOL) usesSpeedLimit: (BOOL) upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-03-28 17:18:43 +00:00
|
|
|
return tr_torrentUsesSpeedLimit(fHandle, upload ? TR_UP : TR_DOWN);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
- (void) setUseSpeedLimit: (BOOL) use upload: (BOOL) upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-03-05 01:10:09 +00:00
|
|
|
tr_torrentUseSpeedLimit(fHandle, upload ? TR_UP : TR_DOWN, use);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) speedLimit: (BOOL) upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-07-06 03:31:17 +00:00
|
|
|
return tr_torrentGetSpeedLimit_KBps(fHandle, upload ? TR_UP : TR_DOWN);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (void) setSpeedLimit: (NSInteger) limit upload: (BOOL) upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-07-06 03:31:17 +00:00
|
|
|
tr_torrentSetSpeedLimit_KBps(fHandle, upload ? TR_UP : TR_DOWN, limit);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
- (BOOL) usesGlobalSpeedLimit
|
|
|
|
{
|
2009-03-28 17:18:43 +00:00
|
|
|
return tr_torrentUsesSessionLimits(fHandle);
|
2009-03-05 01:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUseGlobalSpeedLimit: (BOOL) use
|
|
|
|
{
|
2009-03-28 17:18:43 +00:00
|
|
|
tr_torrentUseSessionLimits(fHandle, use);
|
2009-03-05 01:10:09 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-04-20 02:45:27 +00:00
|
|
|
- (tr_priority_t) priority
|
|
|
|
{
|
|
|
|
return tr_torrentGetPriority(fHandle);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPriority: (tr_priority_t) priority
|
|
|
|
{
|
|
|
|
return tr_torrentSetPriority(fHandle, priority);
|
|
|
|
}
|
|
|
|
|
2009-10-28 21:05:50 +00:00
|
|
|
#warning when 10.6-only use recycleURLs:completionHandler:
|
2009-07-20 00:40:01 +00:00
|
|
|
+ (void) trashFile: (NSString *) path
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-07-20 00:40:01 +00:00
|
|
|
//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's on a remote volume)
|
|
|
|
NSError * error;
|
|
|
|
if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
|
|
|
|
NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) trashData
|
|
|
|
{
|
2008-12-24 01:55:33 +00:00
|
|
|
tr_torrentDeleteLocalData(fHandle, trashDataFile);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) moveTorrentDataFileTo: (NSString *) folder
|
|
|
|
{
|
2009-10-25 03:05:25 +00:00
|
|
|
NSString * oldFolder = [self currentDirectory];
|
2009-10-21 13:01:14 +00:00
|
|
|
if ([oldFolder isEqualToString: folder])
|
|
|
|
return;
|
|
|
|
|
|
|
|
//check if moving inside itself
|
|
|
|
NSArray * oldComponents = [oldFolder pathComponents],
|
|
|
|
* newComponents = [folder pathComponents];
|
2009-10-25 03:05:25 +00:00
|
|
|
const NSInteger oldCount = [oldComponents count];
|
2009-10-21 13:01:14 +00:00
|
|
|
|
2009-10-25 03:05:25 +00:00
|
|
|
if (oldCount < [newComponents count] && [[newComponents objectAtIndex: oldCount] isEqualToString: [self name]]
|
|
|
|
&& [folder hasPrefix: oldFolder])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
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")];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
return;
|
2009-10-25 03:05:25 +00:00
|
|
|
}
|
2009-10-21 13:01:14 +00:00
|
|
|
|
2009-11-01 21:56:50 +00:00
|
|
|
volatile int status;
|
2009-10-21 13:01:14 +00:00
|
|
|
tr_torrentSetLocation(fHandle, [folder UTF8String], YES, NULL, &status);
|
|
|
|
|
2009-11-01 22:26:35 +00:00
|
|
|
while (status == TR_LOC_MOVING) //block while moving (for now)
|
|
|
|
[NSThread sleepForTimeInterval: 0.05];
|
2009-10-21 22:23:08 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
if (status == TR_LOC_DONE)
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: NSLocalizedString(@"There was an error moving the data file.", "Move error alert -> title")];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat:
|
2009-10-25 03:08:13 +00:00
|
|
|
NSLocalizedString(@"The move operation of \"%@\" cannot be done.", "Move error alert -> message"), [self name]]];
|
2009-10-21 13:01:14 +00:00
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Move error alert -> button")];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
[alert runModal];
|
|
|
|
[alert release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2009-10-21 23:13:02 +00:00
|
|
|
|
|
|
|
[self updateTimeMachineExclude];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) copyTorrentFileTo: (NSString *) path
|
|
|
|
{
|
2009-08-28 23:40:11 +00:00
|
|
|
[[NSFileManager defaultManager] copyItemAtPath: [self torrentLocation] toPath: path error: NULL];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) alertForRemainingDiskSpace
|
|
|
|
{
|
|
|
|
if ([self allDownloaded] || ![fDefaults boolForKey: @"WarningRemainingSpace"])
|
|
|
|
return YES;
|
|
|
|
|
2009-10-25 13:42:22 +00:00
|
|
|
NSString * downloadFolder = [self currentDirectory], * volumeName;
|
2009-10-31 02:49:59 +00:00
|
|
|
if ((volumeName = [[[NSFileManager defaultManager] componentsToDisplayForPath: downloadFolder] objectAtIndex: 0]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-25 13:42:22 +00:00
|
|
|
NSDictionary * systemAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath: downloadFolder error: NULL];
|
2008-11-05 13:09:39 +00:00
|
|
|
uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-11-06 03:45:56 +00:00
|
|
|
//if the remaining space is greater than the size left, then there is enough space regardless of preallocation
|
2008-11-05 13:09:39 +00:00
|
|
|
if (remainingSpace < [self sizeLeft] && remainingSpace < tr_torrentGetBytesLeftToAllocate(fHandle))
|
2008-03-17 19:59:26 +00:00
|
|
|
{
|
2008-11-05 12:42:03 +00:00
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
|
|
|
[alert setMessageText: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"Not enough remaining disk space to download \"%@\" completely.",
|
|
|
|
"Torrent disk space alert -> title"), [self name]]];
|
|
|
|
[alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"The transfer will be paused."
|
|
|
|
" Clear up space on %@ or deselect files in the torrent inspector to continue.",
|
|
|
|
"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-18 03:20:27 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[alert setShowsSuppressionButton: YES];
|
|
|
|
[[alert suppressionButton] setTitle: NSLocalizedString(@"Do not check disk space again",
|
|
|
|
"Torrent disk space alert -> button")];
|
2008-11-05 12:42:03 +00:00
|
|
|
|
2009-10-25 16:31:28 +00:00
|
|
|
const NSInteger result = [alert runModal];
|
2008-12-26 05:57:51 +00:00
|
|
|
if ([[alert suppressionButton] state] == NSOnState)
|
2008-11-05 12:42:03 +00:00
|
|
|
[fDefaults setBool: NO forKey: @"WarningRemainingSpace"];
|
|
|
|
[alert release];
|
2008-03-18 03:20:27 +00:00
|
|
|
|
2008-11-05 12:42:03 +00:00
|
|
|
return result != NSAlertFirstButtonReturn;
|
2008-03-17 19:59:26 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSImage *) icon
|
|
|
|
{
|
2009-11-26 02:26:51 +00:00
|
|
|
if ([self isMagnet])
|
2009-12-20 14:44:56 +00:00
|
|
|
return [NSImage imageNamed: @"Magnet.png"];
|
2009-11-26 02:26:51 +00:00
|
|
|
|
|
|
|
#warning replace 'fldr' stuff with NSImageNameFolder on 10.6
|
2007-09-16 01:02:06 +00:00
|
|
|
if (!fIcon)
|
2008-05-29 22:16:03 +00:00
|
|
|
fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [self isFolder] ? NSFileTypeForHFSTypeCode('fldr')
|
2009-10-21 13:01:14 +00:00
|
|
|
: [[self name] pathExtension]] retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
return fIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) name
|
|
|
|
{
|
2010-02-06 00:20:20 +00:00
|
|
|
return fInfo->name != NULL ? [NSString stringWithUTF8String: fInfo->name] : fHashString;
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-06 02:35:27 +00:00
|
|
|
- (NSMutableArray *) allTrackerStats
|
2007-10-24 18:49:59 +00:00
|
|
|
{
|
2009-09-26 04:02:39 +00:00
|
|
|
int count;
|
|
|
|
tr_tracker_stat * stats = tr_torrentTrackers(fHandle, &count);
|
2008-02-27 13:52:43 +00:00
|
|
|
|
2010-02-14 04:48:12 +00:00
|
|
|
NSMutableArray * trackers = [NSMutableArray arrayWithCapacity: (count > 0 ? count + (stats[count-1].tier + 1) : 0)];
|
2009-09-26 04:02:39 +00:00
|
|
|
|
|
|
|
int prevTier = -1;
|
|
|
|
for (int i=0; i < count; ++i)
|
2007-10-24 18:49:59 +00:00
|
|
|
{
|
2009-09-26 04:02:39 +00:00
|
|
|
if (stats[i].tier != prevTier)
|
2008-04-24 06:42:45 +00:00
|
|
|
{
|
2010-02-14 04:48:12 +00:00
|
|
|
[trackers addObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger: stats[i].tier + 1], @"Tier",
|
2010-02-06 02:35:27 +00:00
|
|
|
[self name], @"Name", nil]];
|
2009-09-26 04:02:39 +00:00
|
|
|
prevTier = stats[i].tier;
|
2008-04-24 06:42:45 +00:00
|
|
|
}
|
2008-03-22 17:05:48 +00:00
|
|
|
|
2010-02-13 04:30:47 +00:00
|
|
|
TrackerNode * tracker = [[TrackerNode alloc] initWithTrackerStat: &stats[i] torrent: self];
|
2009-09-26 04:02:39 +00:00
|
|
|
[trackers addObject: tracker];
|
|
|
|
[tracker release];
|
2007-10-24 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2009-09-26 04:02:39 +00:00
|
|
|
tr_torrentTrackersFree(stats, count);
|
|
|
|
return trackers;
|
2007-10-24 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 17:17:29 +00:00
|
|
|
- (NSArray *) allTrackersFlat
|
2008-12-24 17:41:45 +00:00
|
|
|
{
|
2009-09-26 04:02:39 +00:00
|
|
|
NSMutableArray * allTrackers = [NSMutableArray arrayWithCapacity: fInfo->trackerCount];
|
|
|
|
|
2009-09-27 15:49:33 +00:00
|
|
|
for (NSInteger i=0; i < fInfo->trackerCount; i++)
|
2009-09-26 04:02:39 +00:00
|
|
|
[allTrackers addObject: [NSString stringWithUTF8String: fInfo->trackers[i].announce]];
|
2009-09-27 15:49:33 +00:00
|
|
|
|
|
|
|
return allTrackers;
|
2008-12-24 17:41:45 +00:00
|
|
|
}
|
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
- (BOOL) addTrackerToNewTier: (NSString *) tracker
|
2008-06-02 17:26:02 +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)
|
|
|
|
tracker = [@"http://" stringByAppendingString: tracker];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
//recreate the tracker structure
|
|
|
|
const int oldTrackerCount = fInfo->trackerCount;
|
|
|
|
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, oldTrackerCount+1);
|
2010-01-10 02:34:00 +00:00
|
|
|
for (NSUInteger i=0; i < oldTrackerCount; ++i)
|
2009-09-29 03:02:44 +00:00
|
|
|
trackerStructs[i] = fInfo->trackers[i];
|
|
|
|
|
|
|
|
trackerStructs[oldTrackerCount].announce = (char *)[tracker UTF8String];
|
|
|
|
trackerStructs[oldTrackerCount].tier = trackerStructs[oldTrackerCount-1].tier + 1;
|
2010-01-13 22:40:07 +00:00
|
|
|
trackerStructs[oldTrackerCount].id = oldTrackerCount;
|
2009-09-29 03:02:44 +00:00
|
|
|
|
2010-01-05 04:34:31 +00:00
|
|
|
const BOOL success = tr_torrentSetAnnounceList(fHandle, trackerStructs, oldTrackerCount+1);
|
2009-09-29 03:02:44 +00:00
|
|
|
tr_free(trackerStructs);
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2010-01-05 04:34:31 +00:00
|
|
|
return success;
|
2008-06-02 19:42:14 +00:00
|
|
|
}
|
|
|
|
|
2010-01-10 02:34:00 +00:00
|
|
|
- (void) removeTrackersWithIdentifiers: (NSIndexSet *) removeIdentifiers
|
2008-06-02 19:42:14 +00:00
|
|
|
{
|
2009-09-29 03:53:57 +00:00
|
|
|
//recreate the tracker structure
|
2010-01-10 02:34:00 +00:00
|
|
|
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, fInfo->trackerCount);
|
2009-09-29 03:53:57 +00:00
|
|
|
|
2010-01-10 02:34:00 +00:00
|
|
|
NSUInteger newCount = 0;
|
|
|
|
for (NSUInteger i = 0; i < fInfo->trackerCount; i++)
|
2010-01-08 02:48:08 +00:00
|
|
|
{
|
2010-01-13 22:40:07 +00:00
|
|
|
if (![removeIdentifiers containsIndex: fInfo->trackers[i].id])
|
2010-02-22 00:15:27 +00:00
|
|
|
trackerStructs[newCount++] = fInfo->trackers[i];
|
2010-01-08 02:48:08 +00:00
|
|
|
}
|
2009-09-29 03:53:57 +00:00
|
|
|
|
2010-01-05 04:34:31 +00:00
|
|
|
const BOOL success = tr_torrentSetAnnounceList(fHandle, trackerStructs, newCount);
|
|
|
|
NSAssert(success, @"Removing tracker addresses failed");
|
2009-10-10 19:55:47 +00:00
|
|
|
|
2009-09-29 03:53:57 +00:00
|
|
|
tr_free(trackerStructs);
|
2009-09-29 03:02:44 +00:00
|
|
|
}
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSString *) comment
|
|
|
|
{
|
2009-11-25 05:04:19 +00:00
|
|
|
return fInfo->comment ? [NSString stringWithUTF8String: fInfo->comment] : @"";
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) creator
|
|
|
|
{
|
2009-11-25 05:04:19 +00:00
|
|
|
return fInfo->creator ? [NSString stringWithUTF8String: fInfo->creator] : @"";
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateCreated
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger date = fInfo->dateCreated;
|
2007-09-16 01:02:06 +00:00
|
|
|
return date > 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) pieceSize
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fInfo->pieceSize;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) pieceCount
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
2009-11-26 02:11:00 +00:00
|
|
|
return fInfo->torrent ? [NSString stringWithUTF8String: fInfo->torrent] : @"";
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) dataLocation
|
|
|
|
{
|
2009-11-25 05:04:19 +00:00
|
|
|
if ([self isMagnet])
|
|
|
|
return nil;
|
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
if ([self isFolder])
|
|
|
|
{
|
|
|
|
NSString * dataLocation = [[self currentDirectory] stringByAppendingPathComponent: [self name]];
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: dataLocation])
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
return dataLocation;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char * location = tr_torrentFindFile(fHandle, 0);
|
|
|
|
if (location == NULL)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
NSString * dataLocation = [NSString stringWithUTF8String: location];
|
|
|
|
free(location);
|
|
|
|
|
|
|
|
return dataLocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) fileLocation: (FileListNode *) node
|
|
|
|
{
|
|
|
|
if ([node isFolder])
|
|
|
|
{
|
|
|
|
NSString * basePath = [[node path] stringByAppendingPathComponent: [node name]];
|
|
|
|
NSString * dataLocation = [[self currentDirectory] stringByAppendingPathComponent: basePath];
|
|
|
|
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath: dataLocation])
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
return dataLocation;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char * location = tr_torrentFindFile(fHandle, [[node indexes] firstIndex]);
|
|
|
|
if (location == NULL)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
NSString * dataLocation = [NSString stringWithUTF8String: location];
|
|
|
|
free(location);
|
|
|
|
|
|
|
|
return dataLocation;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) progress
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-05-31 14:07:35 +00:00
|
|
|
return fStat->percentComplete;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) progressDone
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->percentDone;
|
|
|
|
}
|
|
|
|
|
2009-11-07 02:22:57 +00:00
|
|
|
- (CGFloat) progressLeft
|
|
|
|
{
|
2009-11-25 05:04:19 +00:00
|
|
|
if ([self size] == 0) //magnet links
|
|
|
|
return 0.0;
|
|
|
|
|
2009-11-07 02:22:57 +00:00
|
|
|
return (CGFloat)[self sizeLeft] / [self size];
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) checkingProgress
|
2008-01-10 20:59:56 +00:00
|
|
|
{
|
|
|
|
return fStat->recheckProgress;
|
|
|
|
}
|
|
|
|
|
2009-09-06 21:09:33 +00:00
|
|
|
- (CGFloat) availableDesired
|
2007-10-15 18:44:39 +00:00
|
|
|
{
|
2009-09-06 21:19:19 +00:00
|
|
|
return (CGFloat)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
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
return fStat->activity != TR_STATUS_STOPPED;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSeeding
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
return fStat->activity == TR_STATUS_SEED;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isChecking
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
return fStat->activity == TR_STATUS_CHECK || fStat->activity == TR_STATUS_CHECK_WAIT;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 18:03:02 +00:00
|
|
|
- (BOOL) isCheckingWaiting
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
return fStat->activity == TR_STATUS_CHECK_WAIT;
|
2008-03-19 18:03:02 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (BOOL) allDownloaded
|
|
|
|
{
|
2009-11-27 03:20:19 +00:00
|
|
|
return [self sizeLeft] == 0 && ![self isMagnet];
|
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
|
|
|
}
|
|
|
|
|
2010-04-02 17:57:25 +00:00
|
|
|
- (BOOL) isFinishedSeeding
|
|
|
|
{
|
|
|
|
return fStat->finished;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (BOOL) isError
|
|
|
|
{
|
2009-10-17 17:15:37 +00:00
|
|
|
return fStat->error == TR_STAT_LOCAL_ERROR;
|
2009-08-05 01:55:37 +00:00
|
|
|
}
|
|
|
|
|
2009-10-17 17:15:37 +00:00
|
|
|
- (BOOL) isAnyErrorOrWarning
|
2009-08-05 01:55:37 +00:00
|
|
|
{
|
|
|
|
return fStat->error != TR_STAT_OK;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) errorMessage
|
|
|
|
{
|
2009-10-17 17:15:37 +00:00
|
|
|
if (![self isAnyErrorOrWarning])
|
2007-09-16 01:02:06 +00:00
|
|
|
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
|
|
|
|
2009-11-02 01:33:15 +00:00
|
|
|
//libtransmission uses "Set Location", Mac client uses "Move data file to..." - very hacky!
|
|
|
|
error = [error stringByReplacingOccurrencesOfString: @"Set Location" withString: [@"Move Data File To" stringByAppendingEllipsis]];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) peers
|
|
|
|
{
|
2008-11-02 14:04:57 +00:00
|
|
|
int totalPeers;
|
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
|
|
|
|
2008-11-02 14:04:57 +00:00
|
|
|
for (int i = 0; i < totalPeers; i++)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-03-18 21:59:17 +00:00
|
|
|
tr_peer_stat * peer = &peers[i];
|
2010-02-06 03:34:49 +00:00
|
|
|
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 11];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2010-02-06 03:34:49 +00:00
|
|
|
[dict setObject: [self name] forKey: @"Name"];
|
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"];
|
2008-12-03 00:18:18 +00:00
|
|
|
[dict setObject: [NSNumber numberWithBool: peer->isSeed] forKey: @"Seed"];
|
2008-03-18 21:59:17 +00:00
|
|
|
[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)
|
2010-07-06 03:40:34 +00:00
|
|
|
[dict setObject: [NSNumber numberWithDouble: peer->rateToPeer_KBps] forKey: @"UL To Rate"];
|
2008-01-10 00:52:02 +00:00
|
|
|
if (peer->isDownloadingFrom)
|
2010-07-06 03:40:34 +00:00
|
|
|
[dict setObject: [NSNumber numberWithDouble: peer->rateToClient_KBps] 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
|
|
|
{
|
2010-02-07 01:56:17 +00:00
|
|
|
NSMutableArray * webSeeds = [NSMutableArray arrayWithCapacity: fInfo->webseedCount];
|
2008-06-07 23:38:05 +00:00
|
|
|
|
2010-07-06 03:31:17 +00:00
|
|
|
double * dlSpeeds = tr_torrentWebSpeeds_KBps(fHandle);
|
2010-02-07 17:37:01 +00:00
|
|
|
|
|
|
|
for (NSInteger i = 0; i < fInfo->webseedCount; i++)
|
2008-06-08 15:54:34 +00:00
|
|
|
{
|
2010-02-07 17:37:01 +00:00
|
|
|
NSMutableDictionary * dict = [NSMutableDictionary dictionaryWithCapacity: 3];
|
2008-06-08 15:54:34 +00:00
|
|
|
|
2010-02-07 17:37:01 +00:00
|
|
|
[dict setObject: [self name] forKey: @"Name"];
|
|
|
|
[dict setObject: [NSString stringWithUTF8String: fInfo->webseeds[i]] forKey: @"Address"];
|
2008-06-08 15:54:34 +00:00
|
|
|
|
2010-02-07 17:37:01 +00:00
|
|
|
if (dlSpeeds[i] != -1.0)
|
2010-11-14 15:16:39 +00:00
|
|
|
[dict setObject: [NSNumber numberWithDouble: dlSpeeds[i]] forKey: @"DL From Rate"];
|
2010-02-07 17:37:01 +00:00
|
|
|
|
|
|
|
[webSeeds addObject: dict];
|
2008-06-08 15:54:34 +00:00
|
|
|
}
|
2008-06-07 23:38:05 +00:00
|
|
|
|
2010-02-07 17:37:01 +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
|
|
|
|
{
|
2009-11-26 06:33:35 +00:00
|
|
|
if ([self isMagnet])
|
2009-11-27 03:20:19 +00:00
|
|
|
{
|
2009-11-27 20:47:03 +00:00
|
|
|
NSString * progressString = fStat->metadataPercentComplete > 0.0
|
2010-06-24 00:00:43 +00:00
|
|
|
? [NSString stringWithFormat: NSLocalizedString(@"%@ of torrent metadata retrieved",
|
|
|
|
"Torrent -> progress string"), [NSString percentString: fStat->metadataPercentComplete longDecimals: YES]]
|
2009-11-27 20:47:03 +00:00
|
|
|
: NSLocalizedString(@"torrent metadata needed", "Torrent -> progress string");
|
|
|
|
|
2009-11-26 16:38:21 +00:00
|
|
|
return [NSString stringWithFormat: @"%@ - %@", NSLocalizedString(@"Magnetized transfer", "Torrent -> progress string"),
|
2009-11-27 03:20:19 +00:00
|
|
|
progressString];
|
|
|
|
}
|
2009-11-26 06:33:35 +00:00
|
|
|
|
2007-09-27 20:42:20 +00:00
|
|
|
NSString * string;
|
|
|
|
|
|
|
|
if (![self allDownloaded])
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat 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]]];
|
2010-06-24 00:00:43 +00:00
|
|
|
progress = [self progressDone];
|
2008-04-08 03:32:07 +00:00
|
|
|
}
|
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]]];
|
2010-06-24 00:00:43 +00:00
|
|
|
progress = [self progress];
|
2008-04-08 03:32:07 +00:00
|
|
|
}
|
2008-04-07 13:43:26 +00:00
|
|
|
|
2010-06-24 00:00:43 +00:00
|
|
|
string = [string stringByAppendingFormat: @" (%@)", [NSString percentString: progress longDecimals: YES]];
|
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
|
2010-09-18 19:49:34 +00:00
|
|
|
{
|
|
|
|
downloadString = [NSString stringWithFormat: NSLocalizedString(@"%@ of %@", "Torrent -> progress string"),
|
|
|
|
[NSString stringForFileSize: [self haveTotal]], [NSString stringForFileSize: [self size]]];
|
|
|
|
downloadString = [downloadString stringByAppendingFormat: @" (%@)",
|
2010-06-24 00:00:43 +00:00
|
|
|
[NSString percentString: [self progress] longDecimals: YES]];
|
2010-09-18 19:49:34 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2010-07-16 03:12:57 +00:00
|
|
|
//add time when downloading or seed limit set
|
2010-08-14 17:32:52 +00:00
|
|
|
if ([self shouldShowEta])
|
2009-02-14 21:15:57 +00:00
|
|
|
string = [string stringByAppendingFormat: @" - %@", [self etaString]];
|
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
|
|
|
|
2009-10-17 17:15:37 +00:00
|
|
|
if ([self isAnyErrorOrWarning])
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2009-08-05 01:55:37 +00:00
|
|
|
switch (fStat->error)
|
|
|
|
{
|
|
|
|
case TR_STAT_LOCAL_ERROR: string = NSLocalizedString(@"Error", "Torrent -> status string"); break;
|
2010-04-02 17:57:25 +00:00
|
|
|
case TR_STAT_TRACKER_ERROR: string = NSLocalizedString(@"Tracker returned error", "Torrent -> status string"); break;
|
|
|
|
case TR_STAT_TRACKER_WARNING: string = NSLocalizedString(@"Tracker returned warning", "Torrent -> status string"); break;
|
2009-08-05 01:55:37 +00:00
|
|
|
default: NSAssert(NO, @"unknown error state");
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
switch (fStat->activity)
|
2007-09-27 21:12:56 +00:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
2010-04-02 17:57:25 +00:00
|
|
|
else if ([self isFinishedSeeding])
|
2007-09-27 21:12:56 +00:00
|
|
|
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:
|
2010-06-24 00:00:43 +00:00
|
|
|
string = [NSString stringWithFormat: @"%@ (%@)",
|
2010-05-31 14:06:54 +00:00
|
|
|
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
|
2010-06-24 00:00:43 +00:00
|
|
|
[NSString percentString: [self checkingProgress] longDecimals: YES]];
|
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
|
|
|
|
2009-12-26 00:02:20 +00:00
|
|
|
const NSInteger 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])
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
if (fStat->activity == 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
|
|
|
|
2008-10-20 17:54:56 +00:00
|
|
|
switch (fStat->activity)
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
}
|
2010-04-02 17:57:25 +00:00
|
|
|
else if ([self isFinishedSeeding])
|
2007-09-27 20:42:20 +00:00
|
|
|
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:
|
2010-06-24 00:00:43 +00:00
|
|
|
string = [NSString stringWithFormat: @"%@ (%@)",
|
2010-05-31 14:06:54 +00:00
|
|
|
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
|
2010-06-24 00:00:43 +00:00
|
|
|
[NSString percentString: [self checkingProgress] longDecimals: YES]];
|
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
|
|
|
|
{
|
2010-08-14 17:32:52 +00:00
|
|
|
if ([self shouldShowEta])
|
2009-02-14 21:15:57 +00:00
|
|
|
return [self etaString];
|
|
|
|
else
|
2008-02-16 19:32:22 +00:00
|
|
|
return [self shortStatusString];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-09-28 02:58:25 +00:00
|
|
|
- (NSString *) stateString
|
|
|
|
{
|
2008-10-20 17:54:56 +00:00
|
|
|
switch (fStat->activity)
|
2007-09-28 02:58:25 +00:00
|
|
|
{
|
|
|
|
case TR_STATUS_STOPPED:
|
2010-04-06 02:53:07 +00:00
|
|
|
{
|
|
|
|
NSString * string = NSLocalizedString(@"Paused", "Torrent -> status string");
|
|
|
|
|
|
|
|
NSString * extra = nil;
|
|
|
|
if (fWaitToStart)
|
|
|
|
{
|
|
|
|
extra = ![self allDownloaded]
|
|
|
|
? NSLocalizedString(@"Waiting to download", "Torrent -> status string")
|
|
|
|
: NSLocalizedString(@"Waiting to seed", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
else if ([self isFinishedSeeding])
|
|
|
|
extra = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
|
|
|
else;
|
|
|
|
|
|
|
|
return extra ? [string stringByAppendingFormat: @" (%@)", extra] : string;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
return [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
2007-09-28 02:58:25 +00:00
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
2010-06-24 00:00:43 +00:00
|
|
|
return [NSString stringWithFormat: @"%@ (%@)",
|
2010-05-31 14:06:54 +00:00
|
|
|
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
|
2010-06-24 00:00:43 +00:00
|
|
|
[NSString percentString: [self checkingProgress] longDecimals: YES]];
|
2007-09-28 02:58:25 +00:00
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
return NSLocalizedString(@"Downloading", "Torrent -> status string");
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
return NSLocalizedString(@"Seeding", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) totalPeersConnected
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->peersConnected;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) totalPeersTracker
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_TRACKER];
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) totalPeersIncoming
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_INCOMING];
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) totalPeersCache
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-11-26 05:40:27 +00:00
|
|
|
return fStat->peersFrom[TR_PEER_FROM_RESUME];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) totalPeersPex
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_PEX];
|
|
|
|
}
|
|
|
|
|
2009-05-19 22:51:37 +00:00
|
|
|
- (NSInteger) totalPeersDHT
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_DHT];
|
|
|
|
}
|
|
|
|
|
2010-05-01 16:19:40 +00:00
|
|
|
- (NSInteger) totalPeersLocal
|
|
|
|
{
|
2010-05-08 08:54:45 +00:00
|
|
|
return fStat->peersFrom[TR_PEER_FROM_LPD];
|
2010-05-01 16:19:40 +00:00
|
|
|
}
|
|
|
|
|
2009-11-26 06:15:29 +00:00
|
|
|
- (NSInteger) totalPeersLTEP
|
|
|
|
{
|
|
|
|
return fStat->peersFrom[TR_PEER_FROM_LTEP];
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) totalPeersKnown
|
2007-10-01 16:23:00 +00:00
|
|
|
{
|
|
|
|
return fStat->peersKnown;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) peersSendingToUs
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->peersSendingToUs;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) peersGettingFromUs
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
return fStat->peersGettingFromUs;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) downloadRate
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-07-06 03:31:17 +00:00
|
|
|
return fStat->pieceDownloadSpeed_KBps;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) uploadRate
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-07-06 03:31:17 +00:00
|
|
|
return fStat->pieceUploadSpeed_KBps;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) totalRate
|
2007-11-23 16:03:49 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) groupValue
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
|
|
|
return fGroupValue;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (void) setGroupValue: (NSInteger) goupValue
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
|
|
|
fGroupValue = goupValue;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) groupOrderValue
|
2007-12-17 20:10:51 +00:00
|
|
|
{
|
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
|
|
|
{
|
2009-12-31 03:19:54 +00:00
|
|
|
if (fGroupValue != -1 && [[[notification userInfo] objectForKey: @"Index"] integerValue] == fGroupValue)
|
2007-12-17 16:06:20 +00:00
|
|
|
fGroupValue = -1;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSArray *) fileList
|
|
|
|
{
|
|
|
|
return fFileList;
|
|
|
|
}
|
|
|
|
|
2010-01-02 02:50:22 +00:00
|
|
|
- (NSArray *) flatFileList
|
|
|
|
{
|
|
|
|
return fFlatFileList;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) fileCount
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (CGFloat) fileProgress: (FileListNode *) node
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-12-26 00:02:20 +00:00
|
|
|
if ([self fileCount] == 1 || [self isComplete])
|
2009-11-07 04:48:02 +00:00
|
|
|
return [self progress];
|
|
|
|
|
2008-03-17 19:59:26 +00:00
|
|
|
if (!fFileStat)
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateFileStat];
|
2008-10-12 13:22:13 +00:00
|
|
|
|
|
|
|
NSIndexSet * indexSet = [node indexes];
|
|
|
|
|
2008-10-12 21:38:13 +00:00
|
|
|
if ([indexSet count] == 1)
|
2008-10-12 13:22:13 +00:00
|
|
|
return fFileStat[[indexSet firstIndex]].progress;
|
|
|
|
|
|
|
|
uint64_t have = 0;
|
2008-11-02 01:07:01 +00:00
|
|
|
for (NSInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
2008-10-12 13:22:13 +00:00
|
|
|
have += fFileStat[index].bytesCompleted;
|
|
|
|
|
2009-01-06 02:07:55 +00:00
|
|
|
NSAssert([node size], @"directory in torrent file has size 0");
|
2008-11-02 01:07:01 +00:00
|
|
|
return (CGFloat)have / [node size];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-12-26 00:02:20 +00:00
|
|
|
- (BOOL) canChangeDownloadCheckForFile: (NSUInteger) index
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-11-07 04:48:02 +00:00
|
|
|
NSAssert2(index < [self fileCount], @"Index %d is greater than file count %d", index, [self fileCount]);
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2009-11-07 04:48:02 +00:00
|
|
|
return fFileStat[index].progress < 1.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet
|
|
|
|
{
|
2009-11-07 04:48:02 +00:00
|
|
|
if ([self fileCount] == 1 || [self isComplete])
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
|
2008-03-17 19:59:26 +00:00
|
|
|
if (!fFileStat)
|
2007-09-16 01:02:06 +00:00
|
|
|
[self updateFileStat];
|
|
|
|
|
2009-12-26 00:02:20 +00:00
|
|
|
for (NSUInteger 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;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) checkForFiles: (NSIndexSet *) indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
BOOL onState = NO, offState = NO;
|
2009-12-26 00:02:20 +00:00
|
|
|
for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-02-12 01:32:09 +00:00
|
|
|
if (!fInfo->files[index].dnd || ![self canChangeDownloadCheckForFile: index])
|
2007-09-16 01:02:06 +00:00
|
|
|
onState = YES;
|
|
|
|
else
|
|
|
|
offState = YES;
|
|
|
|
|
|
|
|
if (onState && offState)
|
|
|
|
return NSMixedState;
|
|
|
|
}
|
|
|
|
return onState ? NSOnState : NSOffState;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (void) setFileCheckState: (NSInteger) state forIndexes: (NSIndexSet *) indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-10-12 21:38:13 +00:00
|
|
|
NSUInteger count = [indexSet count];
|
2008-03-22 18:22:10 +00:00
|
|
|
tr_file_index_t * files = malloc(count * sizeof(tr_file_index_t));
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSUInteger index = [indexSet firstIndex], i = 0; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index], i++)
|
2007-09-16 01:02:06 +00:00
|
|
|
files[i] = index;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-04-20 02:45:27 +00:00
|
|
|
- (void) setFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-10-12 21:38:13 +00:00
|
|
|
const NSUInteger count = [indexSet count];
|
2009-12-26 00:02:20 +00:00
|
|
|
tr_file_index_t * files = tr_malloc(count * sizeof(tr_file_index_t));
|
2008-10-12 21:38:13 +00:00
|
|
|
for (NSUInteger index = [indexSet firstIndex], i = 0; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index], i++)
|
2007-09-16 01:02:06 +00:00
|
|
|
files[i] = index;
|
2007-10-20 00:43:39 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
tr_torrentSetFilePriorities(fHandle, files, count, priority);
|
2009-12-26 00:02:20 +00:00
|
|
|
tr_free(files);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 02:45:27 +00:00
|
|
|
- (BOOL) hasFilePriority: (tr_priority_t) priority forIndexes: (NSIndexSet *) indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-12-26 00:02:20 +00:00
|
|
|
for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
2010-02-12 01:32:09 +00:00
|
|
|
if (priority == fInfo->files[index].priority && [self canChangeDownloadCheckForFile: index])
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet
|
|
|
|
{
|
|
|
|
BOOL low = NO, normal = NO, high = NO;
|
2009-12-26 00:02:20 +00:00
|
|
|
NSMutableSet * priorities = [NSMutableSet setWithCapacity: MIN([indexSet count], 3)];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-12-26 00:02:20 +00:00
|
|
|
for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (![self canChangeDownloadCheckForFile: index])
|
|
|
|
continue;
|
|
|
|
|
2010-02-12 22:27:42 +00:00
|
|
|
const tr_priority_t priority = fInfo->files[index].priority;
|
2010-02-12 01:32:09 +00:00
|
|
|
switch (priority)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-02-12 01:32:09 +00:00
|
|
|
case TR_PRI_LOW:
|
|
|
|
if (low)
|
|
|
|
continue;
|
|
|
|
low = YES;
|
|
|
|
break;
|
|
|
|
case TR_PRI_NORMAL:
|
|
|
|
if (normal)
|
|
|
|
continue;
|
|
|
|
normal = YES;
|
|
|
|
break;
|
|
|
|
case TR_PRI_HIGH:
|
|
|
|
if (high)
|
|
|
|
continue;
|
|
|
|
high = YES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert2(NO, @"Unknown priority %d for file index %d", priority, index);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-26 21:31:00 +00:00
|
|
|
[priorities addObject: [NSNumber numberWithInteger: priority]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (low && normal && high)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return priorities;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateAdded
|
|
|
|
{
|
2009-02-17 04:00:53 +00:00
|
|
|
const time_t date = fStat->addedDate;
|
2008-06-03 19:47:07 +00:00
|
|
|
return [NSDate dateWithTimeIntervalSince1970: date];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateCompleted
|
|
|
|
{
|
2009-02-17 04:00:53 +00:00
|
|
|
const time_t date = fStat->doneDate;
|
2008-06-03 19:47:07 +00:00
|
|
|
return date != 0 ? [NSDate dateWithTimeIntervalSince1970: date] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDate *) dateActivity
|
|
|
|
{
|
2009-02-17 04:00:53 +00:00
|
|
|
const 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];
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) stalledMinutes
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2010-07-11 21:06:28 +00:00
|
|
|
if (fStat->idleSecs == -1)
|
|
|
|
return -1;
|
|
|
|
|
2010-07-11 21:02:30 +00:00
|
|
|
return fStat->idleSecs / 60;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isStalled
|
|
|
|
{
|
|
|
|
return fStalled;
|
|
|
|
}
|
|
|
|
|
2009-10-21 22:20:43 +00:00
|
|
|
- (void) updateTimeMachineExclude
|
|
|
|
{
|
2009-10-31 16:25:00 +00:00
|
|
|
NSString * currentLocation = ![self allDownloaded] ? [self dataLocation] : nil;
|
2009-10-21 22:20:43 +00:00
|
|
|
|
2009-10-31 16:25:00 +00:00
|
|
|
//return if the locations are the same
|
|
|
|
if (fTimeMachineExclude && currentLocation && [fTimeMachineExclude isEqualToString: currentLocation])
|
|
|
|
return;
|
|
|
|
|
|
|
|
//remove old location...
|
2009-10-21 22:20:43 +00:00
|
|
|
if (fTimeMachineExclude)
|
|
|
|
{
|
|
|
|
[self setTimeMachineExclude: NO forPath: fTimeMachineExclude];
|
|
|
|
[fTimeMachineExclude release];
|
|
|
|
fTimeMachineExclude = nil;
|
|
|
|
}
|
|
|
|
|
2009-10-31 16:25:00 +00:00
|
|
|
//...set new location
|
|
|
|
if (currentLocation)
|
2009-10-21 22:20:43 +00:00
|
|
|
{
|
2009-10-31 16:25:00 +00:00
|
|
|
[self setTimeMachineExclude: YES forPath: currentLocation];
|
|
|
|
fTimeMachineExclude = [currentLocation retain];
|
2009-10-21 22:20:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2009-10-15 23:18:39 +00:00
|
|
|
{
|
|
|
|
if (fWaitToStart)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-30 02:22:29 +00:00
|
|
|
else if ([self isSeeding]) //seeding
|
2009-10-15 23:18:39 +00:00
|
|
|
return 10;
|
2008-06-30 02:22:29 +00:00
|
|
|
else //downloading
|
2009-10-15 23:18:39 +00:00
|
|
|
return 20;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 13:42:10 +00:00
|
|
|
- (NSString *) trackerSortKey
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
tr_tracker_stat * stats = tr_torrentTrackers(fHandle, &count);
|
|
|
|
|
|
|
|
NSString * best = nil;
|
|
|
|
|
|
|
|
for (int i=0; i < count; ++i)
|
|
|
|
{
|
|
|
|
NSString * tracker = [NSString stringWithUTF8String: stats[i].host];
|
|
|
|
if (!best || [tracker localizedCaseInsensitiveCompare: best] == NSOrderedAscending)
|
|
|
|
best = tracker;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_torrentTrackersFree(stats, count);
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-04 04:10:46 +00:00
|
|
|
- (NSURL *) previewItemURL
|
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
NSString * location = [self dataLocation];
|
|
|
|
return location ? [NSURL fileURLWithPath: location] : nil;
|
2009-09-04 04:10:46 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation Torrent (Private)
|
|
|
|
|
2009-12-13 01:36:22 +00:00
|
|
|
- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct
|
|
|
|
magnetAddress: (NSString *) magnetAddress lib: (tr_session *) lib
|
2007-12-17 16:06:20 +00:00
|
|
|
waitToStart: (NSNumber *) waitToStart
|
2009-09-17 00:33:39 +00:00
|
|
|
groupValue: (NSNumber *) groupValue
|
2010-11-08 12:28:30 +00:00
|
|
|
timeMachineExcludeLocation: (NSString *) timeMachineExclude
|
|
|
|
downloadFolder: (NSString *) downloadFolder
|
|
|
|
legacyIncompleteFolder: (NSString *) incompleteFolder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
fDefaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
if (torrentStruct)
|
|
|
|
fHandle = torrentStruct;
|
|
|
|
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);
|
2009-12-13 01:36:22 +00:00
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
tr_ctorSetPaused(ctor, TR_FORCE, YES);
|
2009-12-13 01:36:22 +00:00
|
|
|
if (downloadFolder)
|
|
|
|
tr_ctorSetDownloadDir(ctor, TR_FORCE, [downloadFolder UTF8String]);
|
|
|
|
if (incompleteFolder)
|
|
|
|
tr_ctorSetIncompleteDir(ctor, [incompleteFolder UTF8String]);
|
2008-05-26 23:23:07 +00:00
|
|
|
|
2009-11-25 04:11:52 +00:00
|
|
|
tr_parse_result result = TR_PARSE_ERR;
|
2009-05-22 02:08:51 +00:00
|
|
|
if (path)
|
2009-05-22 02:52:28 +00:00
|
|
|
result = tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
|
|
|
|
|
2009-12-13 01:40:53 +00:00
|
|
|
if (result != TR_PARSE_OK && magnetAddress)
|
2010-02-02 22:45:22 +00:00
|
|
|
result = tr_ctorSetMetainfoFromMagnetLink(ctor, [magnetAddress UTF8String]);
|
2009-12-13 01:40:53 +00:00
|
|
|
|
2009-06-10 22:56:24 +00:00
|
|
|
//backup - shouldn't be needed after upgrade to 1.70
|
2009-08-05 02:13:45 +00:00
|
|
|
if (result != TR_PARSE_OK && hashString)
|
2009-05-22 12:11:45 +00:00
|
|
|
result = tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
|
2008-05-26 23:23:07 +00:00
|
|
|
|
2009-08-05 02:13:45 +00:00
|
|
|
if (result == TR_PARSE_OK)
|
2009-11-25 04:11:52 +00:00
|
|
|
fHandle = tr_torrentNew(ctor, NULL);
|
2009-05-22 02:26:02 +00:00
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
tr_ctorFree(ctor);
|
|
|
|
|
|
|
|
if (!fHandle)
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
return nil;
|
2008-01-21 06:23:10 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2009-11-25 04:11:52 +00:00
|
|
|
|
|
|
|
fInfo = tr_torrentInfo(fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-10-20 17:54:56 +00:00
|
|
|
tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self);
|
2009-02-14 21:15:57 +00:00
|
|
|
tr_torrentSetRatioLimitHitCallback(fHandle, ratioLimitHitCallback, self);
|
2010-07-24 03:19:41 +00:00
|
|
|
tr_torrentSetIdleLimitHitCallback(fHandle, idleLimitHitCallback, self);
|
2009-11-27 03:44:00 +00:00
|
|
|
tr_torrentSetMetadataCallback(fHandle, metadataCallback, self);
|
2007-09-28 15:36:46 +00:00
|
|
|
|
2008-02-06 23:45:44 +00:00
|
|
|
fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-04 04:54:26 +00:00
|
|
|
fWaitToStart = waitToStart && [waitToStart boolValue];
|
2008-04-25 22:23:31 +00:00
|
|
|
fResumeOnWake = NO;
|
2010-01-23 00:30:04 +00:00
|
|
|
|
|
|
|
//don't do after this point - it messes with auto-group functionality
|
|
|
|
if (![self isMagnet])
|
|
|
|
[self createFileList];
|
2009-01-08 02:37:18 +00:00
|
|
|
|
2009-09-17 00:33:39 +00:00
|
|
|
fGroupValue = groupValue ? [groupValue intValue] : [[GroupsController groups] groupIndexForTorrent: self];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
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];
|
|
|
|
|
2010-11-08 12:28:30 +00:00
|
|
|
fTimeMachineExclude = [timeMachineExclude retain];
|
2007-09-16 01:02:06 +00:00
|
|
|
[self update];
|
2007-10-31 19:28:22 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) createFileList
|
|
|
|
{
|
2009-11-26 02:32:02 +00:00
|
|
|
NSAssert(![self isMagnet], @"Cannot create a file list until the torrent is demagnetized");
|
|
|
|
|
2008-05-29 22:16:03 +00:00
|
|
|
if ([self isFolder])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger count = [self fileCount];
|
2010-01-01 21:12:04 +00:00
|
|
|
NSMutableArray * fileList = [NSMutableArray arrayWithCapacity: count],
|
|
|
|
* flatFileList = [NSMutableArray arrayWithCapacity: count];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
for (NSInteger 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];
|
|
|
|
|
2009-12-31 03:19:54 +00:00
|
|
|
NSString * fullPath = [NSString stringWithUTF8String: file->name];
|
2009-12-31 18:55:14 +00:00
|
|
|
NSArray * pathComponents = [fullPath pathComponents];
|
2009-12-31 03:19:54 +00:00
|
|
|
NSAssert1([pathComponents count] >= 2, @"Not enough components in path %@", fullPath);
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
NSString * path = [pathComponents objectAtIndex: 0];
|
|
|
|
NSString * name = [pathComponents objectAtIndex: 1];
|
|
|
|
|
2009-12-31 03:19:54 +00:00
|
|
|
if ([pathComponents count] > 2)
|
2008-05-22 18:39:49 +00:00
|
|
|
{
|
2008-05-22 21:06:56 +00:00
|
|
|
//determine if folder node already exists
|
2008-12-26 15:11:37 +00:00
|
|
|
FileListNode * node;
|
2008-12-26 07:25:17 +00:00
|
|
|
for (node in fileList)
|
2010-01-01 21:12:04 +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];
|
|
|
|
}
|
|
|
|
|
2009-12-31 18:55:14 +00:00
|
|
|
NSMutableArray * trimmedComponents = [NSMutableArray arrayWithArray: [pathComponents subarrayWithRange:
|
|
|
|
NSMakeRange(2, [pathComponents count]-2)]];
|
|
|
|
|
2008-05-22 21:06:56 +00:00
|
|
|
[node insertIndex: i withSize: file->length];
|
2009-12-31 18:55:14 +00:00
|
|
|
[self insertPath: trimmedComponents forParent: node fileSize: file->length index: i flatList: flatFileList];
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileListNode * node = [[FileListNode alloc] initWithFileName: name path: path size: file->length index: i];
|
|
|
|
[fileList addObject: node];
|
2008-12-07 02:36:26 +00:00
|
|
|
[flatFileList addObject: node];
|
2008-05-22 18:39:49 +00:00
|
|
|
[node release];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2010-10-23 20:20:31 +00:00
|
|
|
[self sortFileList: fileList];
|
|
|
|
[self sortFileList: flatFileList];
|
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
fFileList = [[NSArray alloc] initWithArray: fileList];
|
2008-12-07 02:36:26 +00:00
|
|
|
fFlatFileList = [[NSArray alloc] initWithArray: flatFileList];
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FileListNode * node = [[FileListNode alloc] initWithFileName: [self name] path: @"" size: [self size] index: 0];
|
|
|
|
fFileList = [[NSArray arrayWithObject: node] retain];
|
2009-10-18 15:54:18 +00:00
|
|
|
fFlatFileList = [fFileList retain];
|
2008-05-22 18:39:49 +00:00
|
|
|
[node release];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-07 02:36:26 +00:00
|
|
|
- (void) insertPath: (NSMutableArray *) components forParent: (FileListNode *) parent fileSize: (uint64_t) size
|
|
|
|
index: (NSInteger) index flatList: (NSMutableArray *) flatFileList
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
NSString * name = [components objectAtIndex: 0];
|
2009-10-19 01:38:13 +00:00
|
|
|
const BOOL isFolder = [components count] > 1;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-05-22 18:39:49 +00:00
|
|
|
FileListNode * node = nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (isFolder)
|
|
|
|
{
|
2008-12-26 07:25:17 +00:00
|
|
|
for (node in [parent children])
|
2008-05-22 18:39:49 +00:00
|
|
|
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
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
NSString * path = [[parent path] stringByAppendingPathComponent: [parent name]];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (isFolder)
|
2009-10-21 13:01:14 +00:00
|
|
|
node = [[FileListNode alloc] initWithFolderName: name path: path];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-12-07 02:36:26 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
node = [[FileListNode alloc] initWithFileName: name path: path size: size index: index];
|
2008-12-07 02:36:26 +00:00
|
|
|
[flatFileList addObject: node];
|
|
|
|
}
|
2008-05-22 18:39:49 +00:00
|
|
|
|
|
|
|
[parent insertChild: node];
|
2008-11-05 02:34:44 +00:00
|
|
|
[node release];
|
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-12-07 02:36:26 +00:00
|
|
|
[self insertPath: components forParent: node fileSize: size index: index flatList: flatFileList];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-23 20:20:31 +00:00
|
|
|
- (void) sortFileList: (NSMutableArray *) fileNodes
|
|
|
|
{
|
|
|
|
NSSortDescriptor * descriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES
|
|
|
|
selector: @selector(compareFinder:)] autorelease];
|
|
|
|
[fileNodes sortUsingDescriptors: [NSArray arrayWithObject: descriptor]];
|
|
|
|
|
|
|
|
for (FileListNode * node in fileNodes)
|
|
|
|
if ([node isFolder])
|
|
|
|
[self sortFileList: [node children]];
|
|
|
|
}
|
|
|
|
|
2007-09-29 15:23:40 +00:00
|
|
|
//status has been retained
|
2010-06-25 22:19:28 +00:00
|
|
|
- (void) completenessChange: (NSDictionary *) statusInfo
|
2007-09-28 15:36:46 +00:00
|
|
|
{
|
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
|
|
|
|
2010-06-25 22:19:28 +00:00
|
|
|
switch ([[statusInfo objectForKey: @"Status"] intValue])
|
2007-09-28 15:36:46 +00:00
|
|
|
{
|
2008-11-30 01:52:45 +00:00
|
|
|
case TR_SEED:
|
|
|
|
case TR_PARTIAL_SEED:
|
2010-06-25 22:19:28 +00:00
|
|
|
//simpler to create a new dictionary than to use statusInfo - avoids retention chicanery
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self
|
|
|
|
userInfo: [NSDictionary dictionaryWithObject: [statusInfo objectForKey: @"WasRunning"] forKey: @"WasRunning"]];
|
2007-09-28 15:36:46 +00:00
|
|
|
break;
|
|
|
|
|
2008-11-30 01:52:45 +00:00
|
|
|
case TR_LEECH:
|
2007-09-28 15:36:46 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRestartedDownloading" object: self];
|
|
|
|
break;
|
|
|
|
}
|
2010-06-25 22:19:28 +00:00
|
|
|
[statusInfo release];
|
2008-06-16 23:27:38 +00:00
|
|
|
|
|
|
|
[self update];
|
2009-10-21 13:01:14 +00:00
|
|
|
[self updateTimeMachineExclude];
|
2009-02-14 21:15:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) ratioLimitHit
|
|
|
|
{
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
|
2010-08-14 19:44:43 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedSeeding" object: self];
|
2009-02-14 21:15:57 +00:00
|
|
|
}
|
2007-09-28 15:36:46 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
- (void) idleLimitHit
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
|
2010-08-14 19:44:43 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedSeeding" object: self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2009-11-27 03:44:00 +00:00
|
|
|
- (void) metadataRetrieved
|
|
|
|
{
|
|
|
|
fStat = tr_torrentStat(fHandle);
|
|
|
|
|
2010-01-23 00:30:04 +00:00
|
|
|
[self createFileList];
|
|
|
|
|
2009-11-27 16:55:36 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self];
|
2009-11-27 03:44:00 +00:00
|
|
|
}
|
|
|
|
|
2010-08-14 17:32:52 +00:00
|
|
|
- (BOOL) shouldShowEta
|
|
|
|
{
|
|
|
|
if (fStat->activity == TR_STATUS_DOWNLOAD)
|
|
|
|
return YES;
|
|
|
|
else if ([self isSeeding])
|
|
|
|
{
|
2010-08-14 19:44:43 +00:00
|
|
|
//ratio: show if it's set at all
|
|
|
|
if (tr_torrentGetSeedRatio(fHandle, NULL))
|
2010-08-14 17:32:52 +00:00
|
|
|
return YES;
|
2010-08-14 19:44:43 +00:00
|
|
|
|
|
|
|
//idle: show only if remaining time is less than cap
|
2010-08-14 17:51:04 +00:00
|
|
|
if (fStat->etaIdle != TR_ETA_NOT_AVAIL && fStat->etaIdle < ETA_IDLE_DISPLAY_SEC)
|
|
|
|
return YES;
|
2010-08-14 17:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2009-02-14 21:15:57 +00:00
|
|
|
- (NSString *) etaString
|
2008-04-07 02:55:33 +00:00
|
|
|
{
|
2010-08-14 15:30:43 +00:00
|
|
|
NSInteger eta;
|
2010-08-14 19:44:43 +00:00
|
|
|
BOOL fromIdle;
|
|
|
|
//don't check for both, since if there's a regular ETA, the torrent isn't idle so it's meaningless
|
|
|
|
if (fStat->eta != TR_ETA_NOT_AVAIL && fStat->eta != TR_ETA_UNKNOWN)
|
|
|
|
{
|
2010-08-14 15:30:43 +00:00
|
|
|
eta = fStat->eta;
|
2010-08-14 19:44:43 +00:00
|
|
|
fromIdle = NO;
|
|
|
|
}
|
|
|
|
else if (fStat->etaIdle != TR_ETA_NOT_AVAIL && fStat->etaIdle < ETA_IDLE_DISPLAY_SEC)
|
|
|
|
{
|
2010-08-14 15:30:43 +00:00
|
|
|
eta = fStat->etaIdle;
|
2010-08-14 19:44:43 +00:00
|
|
|
fromIdle = YES;
|
|
|
|
}
|
2010-08-14 15:30:43 +00:00
|
|
|
else
|
|
|
|
return NSLocalizedString(@"remaining time unknown", "Torrent -> eta string");
|
|
|
|
|
2010-08-14 19:44:43 +00:00
|
|
|
NSString * idleString = [NSString stringWithFormat: NSLocalizedString(@"%@ remaining", "Torrent -> eta string"),
|
|
|
|
[NSString timeString: eta showSeconds: YES maxFields: 2]];
|
|
|
|
if (fromIdle)
|
|
|
|
idleString = [idleString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"inactive", "Torrent -> eta string")];
|
|
|
|
|
|
|
|
return idleString;
|
2008-04-07 02:55:33 +00:00
|
|
|
}
|
|
|
|
|
2008-01-09 16:26:58 +00:00
|
|
|
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
|
|
|
|
{
|
2008-12-26 05:57:51 +00:00
|
|
|
CSBackupSetItemExcluded((CFURLRef)[NSURL fileURLWithPath: path], exclude, true);
|
2008-01-09 16:26:58 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|