2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2006-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2022-04-07 22:26:59 +00:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
2018-09-30 10:37:30 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
2021-12-08 16:55:52 +00:00
|
|
|
|
2018-09-30 10:37:30 +00:00
|
|
|
#include <libtransmission/error.h>
|
|
|
|
#include <libtransmission/log.h>
|
2022-04-07 22:26:59 +00:00
|
|
|
#include <libtransmission/utils.h> // tr_free()
|
2018-09-30 10:37:30 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
#define ETA_IDLE_DISPLAY_SEC (2 * 60)
|
2010-08-14 17:32:52 +00:00
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface Torrent ()
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@property(nonatomic, readonly) tr_torrent* fHandle;
|
|
|
|
@property(nonatomic) tr_stat const* fStat;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) NSUserDefaults* fDefaults;
|
|
|
|
|
|
|
|
@property(nonatomic) NSImage* fIcon;
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
@property(nonatomic, copy) NSArray<FileListNode*>* fileList;
|
|
|
|
@property(nonatomic, copy) NSArray<FileListNode*>* flatFileList;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic, copy) NSIndexSet* fPreviousFinishedIndexes;
|
|
|
|
@property(nonatomic) NSDate* fPreviousFinishedIndexesDate;
|
|
|
|
|
|
|
|
@property(nonatomic) NSInteger groupValue;
|
|
|
|
@property(nonatomic) TorrentDeterminationType fGroupValueDetermination;
|
|
|
|
|
|
|
|
@property(nonatomic) TorrentDeterminationType fDownloadFolderDetermination;
|
|
|
|
|
|
|
|
@property(nonatomic) BOOL fResumeOnWake;
|
|
|
|
|
|
|
|
@property(nonatomic) BOOL fTimeMachineExcludeInitialized;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithPath:(NSString*)path
|
|
|
|
hash:(NSString*)hashString
|
|
|
|
torrentStruct:(tr_torrent*)torrentStruct
|
|
|
|
magnetAddress:(NSString*)magnetAddress
|
|
|
|
lib:(tr_session*)lib
|
|
|
|
groupValue:(NSNumber*)groupValue
|
|
|
|
removeWhenFinishSeeding:(NSNumber*)removeWhenFinishSeeding
|
|
|
|
downloadFolder:(NSString*)downloadFolder
|
|
|
|
legacyIncompleteFolder:(NSString*)incompleteFolder;
|
|
|
|
|
|
|
|
- (void)createFileList;
|
|
|
|
- (void)insertPathForComponents:(NSArray*)components
|
|
|
|
withComponentIndex:(NSUInteger)componentIndex
|
|
|
|
forParent:(FileListNode*)parent
|
|
|
|
fileSize:(uint64_t)size
|
|
|
|
index:(NSInteger)index
|
2022-04-29 22:51:40 +00:00
|
|
|
flatList:(NSMutableArray<FileListNode*>*)flatFileList;
|
|
|
|
- (void)sortFileList:(NSMutableArray<FileListNode*>*)fileNodes;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
- (void)startQueue;
|
|
|
|
- (void)ratioLimitHit;
|
|
|
|
- (void)idleLimitHit;
|
|
|
|
- (void)metadataRetrieved;
|
|
|
|
- (void)renameFinished:(BOOL)success
|
2022-04-29 22:51:40 +00:00
|
|
|
nodes:(NSArray<FileListNode*>*)nodes
|
2021-08-15 09:41:48 +00:00
|
|
|
completionHandler:(void (^)(BOOL))completionHandler
|
|
|
|
oldPath:(NSString*)oldPath
|
|
|
|
newName:(NSString*)newName;
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) BOOL shouldShowEta;
|
|
|
|
@property(nonatomic, readonly) NSString* etaString;
|
|
|
|
|
|
|
|
- (void)setTimeMachineExclude:(BOOL)exclude;
|
2008-01-09 16:26:58 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
void renameCallback(tr_torrent* torrent, char const* oldPathCharString, char const* newNameCharString, int error, void* contextInfo)
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
@autoreleasepool
|
|
|
|
{
|
|
|
|
NSString* oldPath = @(oldPathCharString);
|
|
|
|
NSString* newName = @(newNameCharString);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-02-11 01:47:51 +00:00
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* contextDict = (__bridge_transfer NSDictionary*)contextInfo;
|
|
|
|
Torrent* torrentObject = contextDict[@"Torrent"];
|
|
|
|
[torrentObject renameFinished:error == 0 nodes:contextDict[@"Nodes"]
|
|
|
|
completionHandler:contextDict[@"CompletionHandler"]
|
|
|
|
oldPath:oldPath
|
|
|
|
newName:newName];
|
2013-02-11 01:47:51 +00:00
|
|
|
});
|
2013-01-22 00:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
bool trashDataFile(char const* filename, tr_error** error)
|
2008-12-24 01:55:33 +00:00
|
|
|
{
|
2015-10-23 04:09:40 +00:00
|
|
|
if (filename == NULL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2015-10-23 04:09:40 +00:00
|
|
|
return false;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2015-10-23 04:09:40 +00:00
|
|
|
|
2012-02-11 05:13:46 +00:00
|
|
|
@autoreleasepool
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSError* localError;
|
|
|
|
if (![Torrent trashFile:@(filename) error:&localError])
|
2015-10-23 04:09:40 +00:00
|
|
|
{
|
2021-12-28 02:32:22 +00:00
|
|
|
tr_error_set(error, localError.code, localError.description.UTF8String);
|
2015-10-23 04:09:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-02-11 05:13:46 +00:00
|
|
|
}
|
2015-10-23 04:09:40 +00:00
|
|
|
|
|
|
|
return true;
|
2008-12-24 01:55:33 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@implementation Torrent
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithPath:(NSString*)path
|
|
|
|
location:(NSString*)location
|
|
|
|
deleteTorrentFile:(BOOL)torrentDelete
|
|
|
|
lib:(tr_session*)lib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
self = [self initWithPath:path hash:nil torrentStruct:NULL magnetAddress:nil lib:lib groupValue:nil
|
|
|
|
removeWhenFinishSeeding:nil
|
|
|
|
downloadFolder:location
|
|
|
|
legacyIncompleteFolder:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (self)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (torrentDelete && ![self.torrentLocation isEqualToString:path])
|
|
|
|
{
|
|
|
|
[Torrent trashFile:path error:nil];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithTorrentStruct:(tr_torrent*)torrentStruct location:(NSString*)location lib:(tr_session*)lib
|
2008-01-21 06:23:10 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
self = [self initWithPath:nil hash:nil torrentStruct:torrentStruct magnetAddress:nil lib:lib groupValue:nil
|
|
|
|
removeWhenFinishSeeding:nil
|
|
|
|
downloadFolder:location
|
|
|
|
legacyIncompleteFolder:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-21 06:23:10 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithMagnetAddress:(NSString*)address location:(NSString*)location lib:(tr_session*)lib
|
2009-11-25 04:11:52 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
self = [self initWithPath:nil hash:nil torrentStruct:nil magnetAddress:address lib:lib groupValue:nil
|
|
|
|
removeWhenFinishSeeding:nil
|
|
|
|
downloadFolder:location
|
|
|
|
legacyIncompleteFolder:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-25 04:11:52 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2022-03-02 23:11:04 +00:00
|
|
|
- (void)setResumeStatusForTorrent:(Torrent*)torrent withHistory:(NSDictionary*)history forcePause:(BOOL)pause
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-03-16 20:16:23 +00:00
|
|
|
//restore GroupValue
|
|
|
|
torrent.groupValue = [history[@"GroupValue"] intValue];
|
2022-03-30 21:52:23 +00:00
|
|
|
|
2022-03-02 23:11:04 +00:00
|
|
|
//start transfer
|
|
|
|
NSNumber* active;
|
|
|
|
if (!pause && (active = history[@"Active"]) && active.boolValue)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-03-02 23:11:04 +00:00
|
|
|
[torrent startTransferNoQueue];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-03-02 23:11:04 +00:00
|
|
|
NSNumber* ratioLimit;
|
|
|
|
if ((ratioLimit = history[@"RatioLimit"]))
|
|
|
|
{
|
|
|
|
self.ratioLimit = ratioLimit.floatValue;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDictionary*)history
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2017-07-08 15:02:00 +00:00
|
|
|
return @{
|
2021-08-15 09:41:48 +00:00
|
|
|
@"TorrentHash" : self.hashString,
|
|
|
|
@"Active" : @(self.active),
|
|
|
|
@"WaitToStart" : @(self.waitingToStart),
|
2022-02-22 16:04:20 +00:00
|
|
|
@"GroupValue" : @(self.groupValue),
|
2021-08-15 09:41:48 +00:00
|
|
|
@"RemoveWhenFinishSeeding" : @(_removeWhenFinishSeeding)
|
|
|
|
};
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)description
|
2008-05-12 01:32:33 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
return [@"Torrent: " stringByAppendingString:self.name];
|
2008-05-12 01:32:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)copyWithZone:(NSZone*)zone
|
2010-02-13 04:30:47 +00:00
|
|
|
{
|
2017-07-29 16:14:22 +00:00
|
|
|
return self;
|
2010-02-13 04:30:47 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)closeRemoveTorrent:(BOOL)trashFiles
|
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
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setTimeMachineExclude:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentRemove(self.fHandle, trashFiles, trashDataFile);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)changeDownloadFolderBeforeUsing:(NSString*)folder determinationType:(TorrentDeterminationType)determinationType
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2012-08-06 03:59:07 +00:00
|
|
|
//if data existed in original download location, unexclude it before changing the location
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setTimeMachineExclude:NO];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetDownloadDir(self.fHandle, folder.UTF8String);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadFolderDetermination = determinationType;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)currentDirectory
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return @(tr_torrentGetCurrentDir(self.fHandle));
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)getAvailability:(int8_t*)tab size:(NSInteger)size
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentAvailability(self.fHandle, tab, size);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)getAmountFinished:(float*)tab size:(NSInteger)size
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentAmountFinished(self.fHandle, tab, size);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fPreviousFinishedIndexesDate && self.fPreviousFinishedIndexesDate.timeIntervalSinceNow > -2.0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fPreviousFinishedIndexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-12-28 21:37:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2008-06-11 16:28:33 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-12-28 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPreviousFinishedPieces:(NSIndexSet*)indexes
|
2007-12-28 21:37:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPreviousFinishedIndexes = indexes;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPreviousFinishedIndexesDate = indexes != nil ? [[NSDate alloc] init] : nil;
|
2007-12-28 21:37:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)update
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-10-30 03:13:20 +00:00
|
|
|
//get previous stalled value before update
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const wasStalled = self.fStat != NULL && self.stalled;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStat = tr_torrentStat(self.fHandle);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-10-30 03:13:20 +00:00
|
|
|
//make sure the "active" filter is updated when stalled-ness changes
|
2021-08-07 07:27:56 +00:00
|
|
|
if (wasStalled != self.stalled)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2015-11-25 21:53:26 +00:00
|
|
|
//posting asynchronously with coalescing to prevent stack overflow on lots of torrents changing state at the same time
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationQueue.defaultQueue enqueueNotification:[NSNotification notificationWithName:@"UpdateQueue" object:self]
|
|
|
|
postingStyle:NSPostASAP
|
|
|
|
coalesceMask:NSNotificationCoalescingOnName
|
|
|
|
forModes:nil];
|
|
|
|
}
|
2015-11-25 21:53:26 +00:00
|
|
|
|
2012-08-06 03:59:07 +00:00
|
|
|
//when the torrent is first loaded, update the time machine exclusion
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fTimeMachineExcludeInitialized)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
[self updateTimeMachineExclude];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)startTransferIgnoringQueue:(BOOL)ignoreQueue
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2011-08-11 01:54:14 +00:00
|
|
|
if ([self alertForRemainingDiskSpace])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
ignoreQueue ? tr_torrentStartNow(self.fHandle) : tr_torrentStart(self.fHandle);
|
2011-08-02 12:43:26 +00:00
|
|
|
[self update];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-02 12:43:26 +00:00
|
|
|
//capture, specifically, stop-seeding settings changing to unlimited
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptions" object:nil];
|
2011-08-02 12:43:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)startTransferNoQueue
|
2011-08-28 00:07:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self startTransferIgnoringQueue:YES];
|
2011-08-28 00:07:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)startTransfer
|
2011-08-02 12:43:26 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self startTransferIgnoringQueue:NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)stopTransfer
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentStop(self.fHandle);
|
2011-08-11 01:54:14 +00:00
|
|
|
[self update];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)sleep
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((self.fResumeOnWake = self.active))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentStop(self.fHandle);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)wakeUp
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fResumeOnWake)
|
2010-04-14 13:36:43 +00:00
|
|
|
{
|
2022-03-17 22:39:06 +00:00
|
|
|
tr_logAddTrace("restarting because of wakeup", tr_torrentName(self.fHandle));
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentStart(self.fHandle);
|
2010-04-14 13:36:43 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSUInteger)queuePosition
|
2011-08-11 01:54:14 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->queuePosition;
|
2011-08-11 01:54:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setQueuePosition:(NSUInteger)index
|
2011-08-02 12:43:26 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetQueuePosition(self.fHandle, index);
|
2011-08-02 12:43:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)manualAnnounce
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentManualUpdate(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)canManualAnnounce
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentCanManualUpdate(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)resetCache
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentVerify(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
[self update];
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isMagnet
|
2009-11-25 05:04:19 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return !tr_torrentHasMetadata(self.fHandle);
|
2009-11-25 05:04:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)magnetLink
|
2009-12-04 13:35:15 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return @(tr_torrentGetMagnetLink(self.fHandle));
|
2009-12-04 13:35:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)ratio
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->ratio;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (tr_ratiolimit)ratioSetting
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetRatioMode(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRatioSetting:(tr_ratiolimit)setting
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetRatioMode(self.fHandle, setting);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)ratioLimit
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetRatioLimit(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRatioLimit:(CGFloat)limit
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2012-08-06 04:02:18 +00:00
|
|
|
NSParameterAssert(limit >= 0);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetRatioLimit(self.fHandle, limit);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)progressStopRatio
|
2008-06-24 04:00:39 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->seedRatioPercentDone;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (tr_idlelimit)idleSetting
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetIdleMode(self.fHandle);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setIdleSetting:(tr_idlelimit)setting
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetIdleMode(self.fHandle, setting);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSUInteger)idleLimitMinutes
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetIdleLimit(self.fHandle);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setIdleLimitMinutes:(NSUInteger)limit
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2012-08-06 04:02:18 +00:00
|
|
|
NSParameterAssert(limit > 0);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetIdleLimit(self.fHandle, limit);
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)usesSpeedLimit:(BOOL)upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentUsesSpeedLimit(self.fHandle, upload ? TR_UP : TR_DOWN);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setUseSpeedLimit:(BOOL)use upload:(BOOL)upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentUseSpeedLimit(self.fHandle, upload ? TR_UP : TR_DOWN, use);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)speedLimit:(BOOL)upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetSpeedLimit_KBps(self.fHandle, upload ? TR_UP : TR_DOWN);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (void)setSpeedLimit:(NSUInteger)limit upload:(BOOL)upload
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetSpeedLimit_KBps(self.fHandle, upload ? TR_UP : TR_DOWN, limit);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)usesGlobalSpeedLimit
|
2009-03-05 01:10:09 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentUsesSessionLimits(self.fHandle);
|
2009-03-05 01:10:09 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 17:57:22 +00:00
|
|
|
- (void)setUsesGlobalSpeedLimit:(BOOL)use
|
2009-03-05 01:10:09 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentUseSessionLimits(self.fHandle, use);
|
2009-03-05 01:10:09 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setMaxPeerConnect:(uint16_t)count
|
2007-12-22 05:21:25 +00:00
|
|
|
{
|
2012-08-06 04:02:18 +00:00
|
|
|
NSParameterAssert(count > 0);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetPeerLimit(self.fHandle, count);
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint16_t)maxPeerConnect
|
2007-12-22 05:21:25 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetPeerLimit(self.fHandle);
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)waitingToStart
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->activity == TR_STATUS_DOWNLOAD_WAIT || self.fStat->activity == TR_STATUS_SEED_WAIT;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (tr_priority_t)priority
|
2009-04-20 02:45:27 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentGetPriority(self.fHandle);
|
2009-04-20 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPriority:(tr_priority_t)priority
|
2009-04-20 02:45:27 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentSetPriority(self.fHandle, priority);
|
2009-04-20 02:45:27 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
+ (BOOL)trashFile:(NSString*)path error:(NSError**)error
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-11-10 18:20:06 +00:00
|
|
|
// Attempt to move to trash
|
|
|
|
if ([NSFileManager.defaultManager trashItemAtURL:[NSURL fileURLWithPath:path] resultingItemURL:nil error:nil])
|
2012-06-03 23:29:39 +00:00
|
|
|
{
|
2021-11-10 18:20:06 +00:00
|
|
|
NSLog(@"Old moved to Trash %@", path);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If cannot trash, just delete it (will work if it's on a remote volume)
|
|
|
|
NSError* localError;
|
|
|
|
if ([NSFileManager.defaultManager removeItemAtPath:path error:&localError])
|
|
|
|
{
|
|
|
|
NSLog(@"Old removed %@", path);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSLog(@"Old could not be trashed or removed %@: %@", path, localError.localizedDescription);
|
|
|
|
if (error != nil)
|
|
|
|
{
|
|
|
|
*error = localError;
|
2012-06-03 23:29:39 +00:00
|
|
|
}
|
2015-10-23 04:09:40 +00:00
|
|
|
|
2021-11-10 18:20:06 +00:00
|
|
|
return NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)moveTorrentDataFileTo:(NSString*)folder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* oldFolder = self.currentDirectory;
|
|
|
|
if ([oldFolder isEqualToString:folder])
|
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
//check if moving inside itself
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray *oldComponents = oldFolder.pathComponents, *newComponents = folder.pathComponents;
|
|
|
|
NSUInteger const oldCount = oldComponents.count;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (oldCount < newComponents.count && [newComponents[oldCount] isEqualToString:self.name] && [folder hasPrefix:oldFolder])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
alert.messageText = NSLocalizedString(@"A folder cannot be moved to inside itself.", "Move inside itself alert -> title");
|
|
|
|
alert.informativeText = [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")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
[alert runModal];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
return;
|
2009-10-25 03:05:25 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-01 21:56:50 +00:00
|
|
|
volatile int status;
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetLocation(self.fHandle, folder.UTF8String, YES, NULL, &status);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-01 22:26:35 +00:00
|
|
|
while (status == TR_LOC_MOVING) //block while moving (for now)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSThread sleepForTimeInterval:0.05];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
if (status == TR_LOC_DONE)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateStats" object:nil];
|
|
|
|
}
|
2009-10-21 13:01:14 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.messageText = NSLocalizedString(@"There was an error moving the data file.", "Move error alert -> title");
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.informativeText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"The move operation of \"%@\" cannot be done.", "Move error alert -> message"), self.name];
|
|
|
|
[alert addButtonWithTitle:NSLocalizedString(@"OK", "Move error alert -> button")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
[alert runModal];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 23:13:02 +00:00
|
|
|
[self updateTimeMachineExclude];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)copyTorrentFileTo:(NSString*)path
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSFileManager.defaultManager copyItemAtPath:self.torrentLocation toPath:path error:NULL];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)alertForRemainingDiskSpace
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.allDownloaded || ![self.fDefaults boolForKey:@"WarningRemainingSpace"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* downloadFolder = self.currentDirectory;
|
|
|
|
NSDictionary* systemAttributes;
|
|
|
|
if ((systemAttributes = [NSFileManager.defaultManager attributesOfFileSystemForPath:downloadFolder error:NULL]))
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
uint64_t const remainingSpace = ((NSNumber*)systemAttributes[NSFileSystemFreeSize]).unsignedLongLongValue;
|
2017-01-24 17:53:16 +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
|
2022-02-22 16:04:20 +00:00
|
|
|
if (remainingSpace < self.sizeLeft && remainingSpace < tr_torrentGetBytesLeftToAllocate(self.fHandle))
|
2008-03-17 19:59:26 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* volumeName = [NSFileManager.defaultManager componentsToDisplayForPath:downloadFolder][0];
|
|
|
|
|
|
|
|
NSAlert* alert = [[NSAlert alloc] init];
|
|
|
|
alert.messageText = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"Not enough remaining disk space to download \"%@\" completely.", "Torrent disk space alert -> title"),
|
|
|
|
self.name];
|
|
|
|
alert.informativeText = [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")];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
alert.showsSuppressionButton = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
alert.suppressionButton.title = NSLocalizedString(@"Do not check disk space again", "Torrent disk space alert -> button");
|
2008-11-05 12:42:03 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const result = [alert runModal];
|
2021-10-31 15:18:27 +00:00
|
|
|
if (alert.suppressionButton.state == NSControlStateValueOn)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setBool:NO forKey:@"WarningRemainingSpace"];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +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;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSImage*)icon
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.magnet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [NSImage imageNamed:@"Magnet"];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fIcon)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-03-17 22:39:06 +00:00
|
|
|
self.fIcon = self.folder ? [NSImage imageNamed:NSImageNameFolder] :
|
|
|
|
[NSWorkspace.sharedWorkspace iconForFileType:self.name.pathExtension];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fIcon;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)name
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return @(tr_torrentName(self.fHandle));
|
2011-08-05 03:11:22 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isFolder
|
2007-11-25 04:06:26 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentView(self.fHandle).is_folder;
|
2007-11-25 04:06:26 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)size
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentTotalSize(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)sizeLeft
|
2007-10-07 03:28:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->leftUntilDone;
|
2007-10-07 03:28:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSMutableArray*)allTrackerStats
|
2007-10-24 18:49:59 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const count = tr_torrentTrackerCount(self.fHandle);
|
2021-12-08 16:55:52 +00:00
|
|
|
auto tier = std::optional<int>{};
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
NSMutableArray* trackers = [NSMutableArray arrayWithCapacity:count * 2];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
for (size_t i = 0; i < count; ++i)
|
2007-10-24 18:49:59 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const tracker = tr_torrentTracker(self.fHandle, i);
|
2021-12-08 16:55:52 +00:00
|
|
|
|
|
|
|
if (!tier || tier != tracker.tier)
|
2008-04-24 06:42:45 +00:00
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
tier = tracker.tier;
|
|
|
|
[trackers addObject:@{ @"Tier" : @(tracker.tier + 1), @"Name" : self.name }];
|
2008-04-24 06:42:45 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-08 16:55:52 +00:00
|
|
|
auto* tracker_node = [[TrackerNode alloc] initWithTrackerView:&tracker torrent:self];
|
|
|
|
[trackers addObject:tracker_node];
|
2007-10-24 18:49:59 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-09-26 04:02:39 +00:00
|
|
|
return trackers;
|
2007-10-24 18:49:59 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSArray<NSString*>*)allTrackersFlat
|
2008-12-24 17:41:45 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const n = tr_torrentTrackerCount(self.fHandle);
|
2021-12-14 20:59:40 +00:00
|
|
|
NSMutableArray* allTrackers = [NSMutableArray arrayWithCapacity:n];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-14 20:59:40 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[allTrackers addObject:@(tr_torrentTracker(self.fHandle, i).announce)];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-09-27 15:49:33 +00:00
|
|
|
return allTrackers;
|
2008-12-24 17:41:45 +00:00
|
|
|
}
|
|
|
|
|
2021-12-14 20:59:40 +00:00
|
|
|
- (BOOL)addTrackerToNewTier:(NSString*)new_tracker
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2021-12-14 20:59:40 +00:00
|
|
|
new_tracker = [new_tracker stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
|
|
|
|
if ([new_tracker rangeOfString:@"://"].location == NSNotFound)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-14 20:59:40 +00:00
|
|
|
new_tracker = [@"http://" stringByAppendingString:new_tracker];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
char* old_list = tr_torrentGetTrackerList(self.fHandle);
|
2022-04-07 22:26:59 +00:00
|
|
|
auto const new_list = fmt::format(FMT_STRING("{:s}\n\n{:s}"), old_list, new_tracker.UTF8String);
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const success = tr_torrentSetTrackerList(self.fHandle, new_list.c_str());
|
2022-02-18 17:52:01 +00:00
|
|
|
tr_free(old_list);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-01-05 04:34:31 +00:00
|
|
|
return success;
|
2008-06-02 19:42:14 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)removeTrackers:(NSSet*)trackers
|
2008-06-02 19:42:14 +00:00
|
|
|
{
|
2022-02-18 17:52:01 +00:00
|
|
|
auto new_list = std::string{};
|
|
|
|
auto current_tier = std::optional<tr_tracker_tier_t>{};
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (size_t i = 0, n = tr_torrentTrackerCount(self.fHandle); i < n; ++i)
|
2010-01-08 02:48:08 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const tracker = tr_torrentTracker(self.fHandle, i);
|
2021-12-14 20:59:40 +00:00
|
|
|
|
|
|
|
if ([trackers containsObject:@(tracker.announce)])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-14 20:59:40 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-12-14 20:59:40 +00:00
|
|
|
|
2022-02-18 17:52:01 +00:00
|
|
|
if (current_tier && *current_tier != tracker.tier)
|
|
|
|
{
|
|
|
|
new_list += '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
new_list += tracker.announce;
|
|
|
|
new_list += '\n';
|
|
|
|
|
|
|
|
current_tier = tracker.tier;
|
2010-01-08 02:48:08 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const success = tr_torrentSetTrackerList(self.fHandle, new_list.c_str());
|
2010-01-05 04:34:31 +00:00
|
|
|
NSAssert(success, @"Removing tracker addresses failed");
|
2009-09-29 03:02:44 +00:00
|
|
|
}
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)comment
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const* comment = tr_torrentView(self.fHandle).comment;
|
2021-12-14 21:59:44 +00:00
|
|
|
return comment ? @(comment) : @"";
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)creator
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const* creator = tr_torrentView(self.fHandle).creator;
|
2021-12-14 21:59:44 +00:00
|
|
|
return creator ? @(creator) : @"";
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDate*)dateCreated
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const date = tr_torrentView(self.fHandle).date_created;
|
2021-08-15 09:41:48 +00:00
|
|
|
return date > 0 ? [NSDate dateWithTimeIntervalSince1970:date] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)pieceSize
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentView(self.fHandle).piece_size;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)pieceCount
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentView(self.fHandle).n_pieces;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)hashString
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return @(tr_torrentView(self.fHandle).hash_string);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)privateTorrent
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentView(self.fHandle).is_private;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)torrentLocation
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto* const filename = tr_torrentFilename(self.fHandle);
|
2022-01-18 05:14:00 +00:00
|
|
|
NSString* ret = @(filename ? filename : "");
|
|
|
|
tr_free(filename);
|
|
|
|
return ret;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)dataLocation
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.magnet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-11-25 05:04:19 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.folder)
|
2009-10-21 13:01:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* dataLocation = [self.currentDirectory stringByAppendingPathComponent:self.name];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![NSFileManager.defaultManager fileExistsAtPath:dataLocation])
|
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
return dataLocation;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
char* location = tr_torrentFindFile(self.fHandle, 0);
|
2009-10-21 13:01:14 +00:00
|
|
|
if (location == NULL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* dataLocation = @(location);
|
2009-10-21 13:01:14 +00:00
|
|
|
free(location);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
return dataLocation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)fileLocation:(FileListNode*)node
|
2009-10-21 13:01:14 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (node.isFolder)
|
2009-10-21 13:01:14 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* basePath = [node.path stringByAppendingPathComponent:node.name];
|
|
|
|
NSString* dataLocation = [self.currentDirectory stringByAppendingPathComponent:basePath];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![NSFileManager.defaultManager fileExistsAtPath:dataLocation])
|
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
return dataLocation;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
char* location = tr_torrentFindFile(self.fHandle, node.indexes.firstIndex);
|
2009-10-21 13:01:14 +00:00
|
|
|
if (location == NULL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-21 13:01:14 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* dataLocation = @(location);
|
2009-10-21 13:01:14 +00:00
|
|
|
free(location);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
return dataLocation;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)renameTorrent:(NSString*)newName completionHandler:(void (^)(BOOL didRename))completionHandler
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
|
|
|
NSParameterAssert(newName != nil);
|
2021-08-15 09:41:48 +00:00
|
|
|
NSParameterAssert(![newName isEqualToString:@""]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* contextInfo = @{ @"Torrent" : self, @"CompletionHandler" : [completionHandler copy] };
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentRenamePath(self.fHandle, tr_torrentName(self.fHandle), newName.UTF8String, renameCallback, (__bridge_retained void*)(contextInfo));
|
2013-01-22 00:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)renameFileNode:(FileListNode*)node
|
|
|
|
withName:(NSString*)newName
|
|
|
|
completionHandler:(void (^)(BOOL didRename))completionHandler
|
2013-01-22 00:09:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSParameterAssert(node.torrent == self);
|
2013-01-22 00:09:48 +00:00
|
|
|
NSParameterAssert(newName != nil);
|
2021-08-15 09:41:48 +00:00
|
|
|
NSParameterAssert(![newName isEqualToString:@""]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* contextInfo = @{ @"Torrent" : self, @"Nodes" : @[ node ], @"CompletionHandler" : [completionHandler copy] };
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* oldPath = [node.path stringByAppendingPathComponent:node.name];
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentRenamePath(self.fHandle, oldPath.UTF8String, newName.UTF8String, renameCallback, (__bridge_retained void*)(contextInfo));
|
2013-01-22 00:09:48 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)progress
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->percentComplete;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)progressDone
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->percentDone;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)progressLeft
|
2009-11-07 02:22:57 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.size == 0) //magnet links
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-11-25 05:04:19 +00:00
|
|
|
return 0.0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
return (CGFloat)self.sizeLeft / self.size;
|
2009-11-07 02:22:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)checkingProgress
|
2008-01-10 20:59:56 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->recheckProgress;
|
2008-01-10 20:59:56 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)availableDesired
|
2007-10-15 18:44:39 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return (CGFloat)self.fStat->desiredAvailable / self.sizeLeft;
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
2007-09-27 12:44:25 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isActive
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-03-17 22:39:06 +00:00
|
|
|
return self.fStat->activity != TR_STATUS_STOPPED && self.fStat->activity != TR_STATUS_DOWNLOAD_WAIT &&
|
|
|
|
self.fStat->activity != TR_STATUS_SEED_WAIT;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isSeeding
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->activity == TR_STATUS_SEED;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isChecking
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->activity == TR_STATUS_CHECK || self.fStat->activity == TR_STATUS_CHECK_WAIT;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isCheckingWaiting
|
2008-03-19 18:03:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->activity == TR_STATUS_CHECK_WAIT;
|
2008-03-19 18:03:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)allDownloaded
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.sizeLeft == 0 && !self.magnet;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isComplete
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.progress >= 1.0;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isFinishedSeeding
|
2010-04-02 17:57:25 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->finished;
|
2010-04-02 17:57:25 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isError
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->error == TR_STAT_LOCAL_ERROR;
|
2009-08-05 01:55:37 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isAnyErrorOrWarning
|
2009-08-05 01:55:37 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->error != TR_STAT_OK;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)errorMessage
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!self.anyErrorOrWarning)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* error;
|
2022-03-17 22:39:06 +00:00
|
|
|
if (!(error = @(self.fStat->errorString)) &&
|
|
|
|
!(error = [NSString stringWithCString:self.fStat->errorString encoding:NSISOLatin1StringEncoding]))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
error = [NSString stringWithFormat:@"(%@)", NSLocalizedString(@"unreadable error", "Torrent -> error string unreadable")];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-11-02 01:33:15 +00:00
|
|
|
//libtransmission uses "Set Location", Mac client uses "Move data file to..." - very hacky!
|
2021-08-15 09:41:48 +00:00
|
|
|
error = [error stringByReplacingOccurrencesOfString:@"Set Location" withString:[@"Move Data File To" stringByAppendingEllipsis]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSArray<NSDictionary*>*)peers
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-11-02 14:04:57 +00:00
|
|
|
int totalPeers;
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_peer_stat* peers = tr_torrentPeers(self.fHandle, &totalPeers);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* peerDicts = [NSMutableArray arrayWithCapacity:totalPeers];
|
2017-01-24 17:53:16 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_peer_stat* peer = &peers[i];
|
|
|
|
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:12];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
dict[@"Name"] = self.name;
|
2017-07-08 14:38:47 +00:00
|
|
|
dict[@"From"] = @(peer->from);
|
|
|
|
dict[@"IP"] = @(peer->addr);
|
|
|
|
dict[@"Port"] = @(peer->port);
|
|
|
|
dict[@"Progress"] = @(peer->progress);
|
|
|
|
dict[@"Seed"] = @(peer->isSeed);
|
|
|
|
dict[@"Encryption"] = @(peer->isEncrypted);
|
|
|
|
dict[@"uTP"] = @(peer->isUTP);
|
|
|
|
dict[@"Client"] = @(peer->client);
|
|
|
|
dict[@"Flags"] = @(peer->flagStr);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-01-10 00:52:02 +00:00
|
|
|
if (peer->isUploadingTo)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
dict[@"UL To Rate"] = @(peer->rateToPeer_KBps);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-01-10 00:52:02 +00:00
|
|
|
if (peer->isDownloadingFrom)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-07-08 14:38:47 +00:00
|
|
|
dict[@"DL From Rate"] = @(peer->rateToClient_KBps);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[peerDicts addObject:dict];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
tr_torrentPeersFree(peers, totalPeers);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-03-18 21:59:17 +00:00
|
|
|
return peerDicts;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSUInteger)webSeedCount
|
2008-06-08 16:38:15 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentWebseedCount(self.fHandle);
|
2008-06-08 16:38:15 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (NSArray<NSDictionary*>*)webSeeds
|
2008-06-07 23:38:05 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger n = tr_torrentWebseedCount(self.fHandle);
|
2021-12-07 18:11:28 +00:00
|
|
|
NSMutableArray* webSeeds = [NSMutableArray arrayWithCapacity:n];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-07 18:11:28 +00:00
|
|
|
for (NSUInteger i = 0; i < n; ++i)
|
2008-06-08 15:54:34 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const webseed = tr_torrentWebseed(self.fHandle, i);
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:3];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
dict[@"Name"] = self.name;
|
2021-12-07 18:11:28 +00:00
|
|
|
dict[@"Address"] = @(webseed.url);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-07 18:11:28 +00:00
|
|
|
if (webseed.is_downloading)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-07 18:11:28 +00:00
|
|
|
dict[@"DL From Rate"] = @(double(webseed.download_bytes_per_second) / 1000);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[webSeeds addObject:dict];
|
2008-06-08 15:54:34 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-06-08 18:02:16 +00:00
|
|
|
return webSeeds;
|
2008-06-07 23:38:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)progressString
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.magnet)
|
2009-11-27 03:20:19 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSString* progressString = self.fStat->metadataPercentComplete > 0.0 ?
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSString stringWithFormat:NSLocalizedString(@"%@ of torrent metadata retrieved", "Torrent -> progress string"),
|
2022-02-22 16:04:20 +00:00
|
|
|
[NSString percentString:self.fStat->metadataPercentComplete longDecimals:YES]] :
|
2021-08-15 09:41:48 +00:00
|
|
|
NSLocalizedString(@"torrent metadata needed", "Torrent -> progress string");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return [NSString stringWithFormat:@"%@ - %@", NSLocalizedString(@"Magnetized transfer", "Torrent -> progress string"), progressString];
|
2009-11-27 03:20:19 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* string;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!self.allDownloaded)
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat progress;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.folder && [self.fDefaults boolForKey:@"DisplayStatusProgressSelected"])
|
2008-04-08 03:32:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
string = [NSString stringForFilePartialSize:self.haveTotal fullSize:self.totalSizeSelected];
|
2021-08-07 07:27:56 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
string = [NSString stringForFilePartialSize:self.haveTotal fullSize:self.size];
|
2021-08-07 07:27:56 +00:00
|
|
|
progress = self.progress;
|
2008-04-08 03:32:07 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* downloadString;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!self.complete) //only multifile possible
|
2008-03-31 19:36:11 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if ([self.fDefaults boolForKey:@"DisplayStatusProgressSelected"])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
downloadString = [NSString stringWithFormat:NSLocalizedString(@"%@ selected", "Torrent -> progress string"),
|
|
|
|
[NSString stringForFileSize:self.haveTotal]];
|
|
|
|
}
|
2008-03-31 19:36:11 +00:00
|
|
|
else
|
2010-09-18 19:49:34 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
downloadString = [NSString stringForFilePartialSize:self.haveTotal fullSize:self.size];
|
|
|
|
downloadString = [downloadString stringByAppendingFormat:@" (%@)", [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
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
downloadString = [NSString stringForFileSize:self.size];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* uploadString = [NSString stringWithFormat:NSLocalizedString(@"uploaded %@ (Ratio: %@)", "Torrent -> progress string"),
|
|
|
|
[NSString stringForFileSize:self.uploadedTotal],
|
|
|
|
[NSString stringForRatio:self.ratio]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
string = [downloadString stringByAppendingFormat:@", %@", uploadString];
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-07-16 03:12:57 +00:00
|
|
|
//add time when downloading or seed limit set
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.shouldShowEta)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
string = [string stringByAppendingFormat:@" - %@", self.etaString];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-27 20:42:20 +00:00
|
|
|
return string;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)statusString
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* string;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.anyErrorOrWarning)
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
switch (self.fStat->error)
|
2009-08-05 01:55:37 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STAT_LOCAL_ERROR:
|
|
|
|
string = NSLocalizedString(@"Error", "Torrent -> status string");
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
NSAssert(NO, @"unknown error state");
|
2009-08-05 01:55:37 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* errorString = self.errorMessage;
|
|
|
|
if (errorString && ![errorString isEqualToString:@""])
|
|
|
|
{
|
|
|
|
string = [string stringByAppendingFormat:@": %@", errorString];
|
|
|
|
}
|
2007-09-27 20:42:20 +00:00
|
|
|
}
|
2007-09-27 21:12:56 +00:00
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
switch (self.fStat->activity)
|
2007-09-27 21:12:56 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
if (self.finishedSeeding)
|
|
|
|
{
|
|
|
|
string = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string = NSLocalizedString(@"Paused", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_SEED_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
2007-09-27 21:12:56 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
string = [NSString stringWithFormat:@"%@ (%@)",
|
|
|
|
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
|
|
|
|
[NSString percentString:self.checkingProgress longDecimals:YES]];
|
|
|
|
break;
|
2007-09-27 21:12:56 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
if (self.totalPeersConnected != 1)
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
string = [NSString stringWithFormat:NSLocalizedString(@"Downloading from %lu of %lu peers", "Torrent -> status string"),
|
2021-08-15 09:41:48 +00:00
|
|
|
self.peersSendingToUs,
|
|
|
|
self.totalPeersConnected];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
string = [NSString stringWithFormat:NSLocalizedString(@"Downloading from %lu of 1 peer", "Torrent -> status string"),
|
2021-08-15 09:41:48 +00:00
|
|
|
self.peersSendingToUs];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
if (NSUInteger const webSeedCount = self.fStat->webseedsSendingToUs; webSeedCount > 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
NSString* webSeedString;
|
|
|
|
if (webSeedCount == 1)
|
2008-06-10 01:49:09 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
webSeedString = NSLocalizedString(@"web seed", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
webSeedString = [NSString stringWithFormat:NSLocalizedString(@"%lu web seeds", "Torrent -> status string"), webSeedCount];
|
2008-06-10 02:40:40 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
string = [string stringByAppendingFormat:@" + %@", webSeedString];
|
|
|
|
}
|
2007-09-27 21:12:56 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
if (self.totalPeersConnected != 1)
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
string = [NSString stringWithFormat:NSLocalizedString(@"Seeding to %1$lu of %2$lu peers", "Torrent -> status string"),
|
2021-08-15 09:41:48 +00:00
|
|
|
self.peersGettingFromUs,
|
|
|
|
self.totalPeersConnected];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
string = [NSString stringWithFormat:NSLocalizedString(@"Seeding to %u of 1 peer", "Torrent -> status string"),
|
|
|
|
(unsigned int)self.peersGettingFromUs];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-27 21:12:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.stalled)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
string = [NSLocalizedString(@"Stalled", "Torrent -> status string") stringByAppendingFormat:@", %@", string];
|
|
|
|
}
|
2007-10-01 11:34:01 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-10-01 11:34:01 +00:00
|
|
|
//append even if error
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.active && !self.checking)
|
2007-10-01 11:34:01 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fStat->activity == TR_STATUS_DOWNLOAD)
|
2021-08-15 09:41:48 +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
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
string = [string stringByAppendingFormat:@" - %@: %@",
|
|
|
|
NSLocalizedString(@"UL", "Torrent -> status string"),
|
|
|
|
[NSString stringForSpeed:self.uploadRate]];
|
|
|
|
}
|
2007-09-27 21:12:56 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-27 20:42:20 +00:00
|
|
|
return string;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)shortStatusString
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* string;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
switch (self.fStat->activity)
|
2007-09-27 20:42:20 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
if (self.finishedSeeding)
|
|
|
|
{
|
|
|
|
string = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
string = NSLocalizedString(@"Paused", "Torrent -> status string");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to download", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to seed", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
string = [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
string = [NSString stringWithFormat:@"%@ (%@)",
|
|
|
|
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
|
|
|
|
[NSString percentString:self.checkingProgress longDecimals:YES]];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
string = [NSString stringWithFormat:@"%@: %@, %@: %@",
|
|
|
|
NSLocalizedString(@"DL", "Torrent -> status string"),
|
|
|
|
[NSString stringForSpeed:self.downloadRate],
|
|
|
|
NSLocalizedString(@"UL", "Torrent -> status string"),
|
|
|
|
[NSString stringForSpeed:self.uploadRate]];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TR_STATUS_SEED:
|
|
|
|
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
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-27 20:42:20 +00:00
|
|
|
return string;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)remainingTimeString
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.shouldShowEta)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.etaString;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-02-14 21:15:57 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.shortStatusString;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)stateString
|
2007-09-28 02:58:25 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
switch (self.fStat->activity)
|
2007-09-28 02:58:25 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_STOPPED:
|
|
|
|
case TR_STATUS_DOWNLOAD_WAIT:
|
|
|
|
case TR_STATUS_SEED_WAIT:
|
2010-04-06 02:53:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* string = NSLocalizedString(@"Paused", "Torrent -> status string");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* extra = nil;
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.waitingToStart)
|
2010-04-06 02:53:07 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
extra = self.fStat->activity == TR_STATUS_DOWNLOAD_WAIT ?
|
2021-08-15 09:41:48 +00:00
|
|
|
NSLocalizedString(@"Waiting to download", "Torrent -> status string") :
|
|
|
|
NSLocalizedString(@"Waiting to seed", "Torrent -> status string");
|
2010-04-06 02:53:07 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (self.finishedSeeding)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-04-06 02:53:07 +00:00
|
|
|
extra = NSLocalizedString(@"Seeding complete", "Torrent -> status string");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return extra ? [string stringByAppendingFormat:@" (%@)", extra] : string;
|
2010-04-06 02:53:07 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_CHECK_WAIT:
|
|
|
|
return [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
|
2007-09-28 02:58:25 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_CHECK:
|
|
|
|
return [NSString stringWithFormat:@"%@ (%@)",
|
|
|
|
NSLocalizedString(@"Checking existing data", "Torrent -> status string"),
|
|
|
|
[NSString percentString:self.checkingProgress longDecimals:YES]];
|
2007-09-28 02:58:25 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_DOWNLOAD:
|
|
|
|
return NSLocalizedString(@"Downloading", "Torrent -> status string");
|
2007-09-28 02:58:25 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_STATUS_SEED:
|
|
|
|
return NSLocalizedString(@"Seeding", "Torrent -> status string");
|
2007-09-28 02:58:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersConnected
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersConnected;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersTracker
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_TRACKER];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersIncoming
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_INCOMING];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersCache
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_RESUME];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersPex
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_PEX];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersDHT
|
2009-05-19 22:51:37 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_DHT];
|
2009-05-19 22:51:37 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersLocal
|
2010-05-01 16:19:40 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_LPD];
|
2010-05-01 16:19:40 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)totalPeersLTEP
|
2009-11-26 06:15:29 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersFrom[TR_PEER_FROM_LTEP];
|
2009-11-26 06:15:29 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)peersSendingToUs
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersSendingToUs;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)peersGettingFromUs
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->peersGettingFromUs;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)downloadRate
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->pieceDownloadSpeed_KBps;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)uploadRate
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->pieceUploadSpeed_KBps;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)totalRate
|
2007-11-23 16:03:49 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.downloadRate + self.uploadRate;
|
2007-11-23 16:03:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)haveVerified
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->haveValid;
|
2007-09-26 03:27:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)haveTotal
|
2007-09-26 03:27:00 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.haveVerified + self.fStat->haveUnchecked;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)totalSizeSelected
|
2008-02-27 19:34:55 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->sizeWhenDone;
|
2008-02-27 19:34:55 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)downloadedTotal
|
2007-09-26 18:32:32 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->downloadedEver;
|
2007-09-26 18:32:32 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)uploadedTotal
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->uploadedEver;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (uint64_t)failedHash
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->corruptEver;
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGroupValue:(NSInteger)groupValue determinationType:(TorrentDeterminationType)determinationType
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (groupValue != self.groupValue)
|
2012-10-30 00:22:10 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.groupValue = groupValue;
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:kTorrentDidChangeGroupNotification object:self];
|
2017-01-24 17:53:16 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fGroupValueDetermination = determinationType;
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)groupOrderValue
|
2007-12-17 20:10:51 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return [GroupsController.groups rowValueForIndex:self.groupValue];
|
2007-12-17 20:10:51 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)checkGroupValueForRemoval:(NSNotification*)notification
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.groupValue != -1 && [notification.userInfo[@"Index"] integerValue] == self.groupValue)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.groupValue = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
- (NSUInteger)fileCount
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return tr_torrentFileCount(self.fHandle);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (CGFloat)fileProgress:(FileListNode*)node
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.fileCount == 1 || self.complete)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return self.progress;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-10-27 20:56:10 +00:00
|
|
|
// #5501
|
2021-08-15 09:41:48 +00:00
|
|
|
if (node.size == 0)
|
|
|
|
{
|
2013-10-27 20:56:10 +00:00
|
|
|
return 1.0;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-10-12 13:22:13 +00:00
|
|
|
uint64_t have = 0;
|
2021-10-21 18:31:03 +00:00
|
|
|
NSIndexSet* indexSet = node.indexes;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSInteger index = indexSet.firstIndex; index != NSNotFound; index = [indexSet indexGreaterThanIndex:index])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
have += tr_torrentFile(self.fHandle, index).have;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
return (CGFloat)have / node.size;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)canChangeDownloadCheckForFile:(NSUInteger)index
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
NSAssert2(index < self.fileCount, @"Index %lu is greater than file count %lu", index, self.fileCount);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
return [self canChangeDownloadCheckForFiles:[NSIndexSet indexSetWithIndex:index]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)canChangeDownloadCheckForFiles:(NSIndexSet*)indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.fileCount == 1 || self.complete)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-31 04:22:51 +00:00
|
|
|
__block BOOL canChange = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
[indexSet enumerateIndexesWithOptions:NSEnumerationConcurrent usingBlock:^(NSUInteger index, BOOL* stop) {
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const file = tr_torrentFile(self.fHandle, index);
|
2021-11-28 03:17:47 +00:00
|
|
|
if (file.have < file.length)
|
2012-01-31 04:22:51 +00:00
|
|
|
{
|
|
|
|
canChange = YES;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
return canChange;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)checkForFiles:(NSIndexSet*)indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
BOOL onState = NO, offState = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger index = indexSet.firstIndex; index != NSNotFound; index = [indexSet indexGreaterThanIndex:index])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const file = tr_torrentFile(self.fHandle, index);
|
2021-11-28 03:17:47 +00:00
|
|
|
if (file.wanted || ![self canChangeDownloadCheckForFile:index])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
onState = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
offState = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (onState && offState)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
return NSControlStateValueMixed;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2021-10-31 15:18:27 +00:00
|
|
|
return onState ? NSControlStateValueOn : NSControlStateValueOff;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setFileCheckState:(NSInteger)state forIndexes:(NSIndexSet*)indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSUInteger count = indexSet.count;
|
2021-09-24 12:56:57 +00:00
|
|
|
tr_file_index_t* files = static_cast<tr_file_index_t*>(malloc(count * sizeof(tr_file_index_t)));
|
2021-08-15 09:41:48 +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;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetFileDLs(self.fHandle, files, count, state != NSControlStateValueOff);
|
2007-09-16 01:02:06 +00:00
|
|
|
free(files);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[self update];
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"TorrentFileCheckChange" object:self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setFilePriority:(tr_priority_t)priority forIndexes:(NSIndexSet*)indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger const count = indexSet.count;
|
2021-09-24 12:56:57 +00:00
|
|
|
tr_file_index_t* files = static_cast<tr_file_index_t*>(tr_malloc(count * sizeof(tr_file_index_t)));
|
2021-08-15 09:41:48 +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;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_torrentSetFilePriorities(self.fHandle, files, count, priority);
|
2009-12-26 00:02:20 +00:00
|
|
|
tr_free(files);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)hasFilePriority:(tr_priority_t)priority forIndexes:(NSIndexSet*)indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger index = indexSet.firstIndex; index != NSNotFound; index = [indexSet indexGreaterThanIndex:index])
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (priority == tr_torrentFile(self.fHandle, index).priority && [self canChangeDownloadCheckForFile:index])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSSet*)filePrioritiesForIndexes:(NSIndexSet*)indexSet
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
BOOL low = NO, normal = NO, high = NO;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableSet* priorities = [NSMutableSet setWithCapacity:MIN(indexSet.count, 3u)];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSUInteger index = indexSet.firstIndex; index != NSNotFound; index = [indexSet indexGreaterThanIndex:index])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![self canChangeDownloadCheckForFile:index])
|
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
continue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const priority = tr_torrentFile(self.fHandle, index).priority;
|
2010-02-12 01:32:09 +00:00
|
|
|
switch (priority)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +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 %ld", priority, index);
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[priorities addObject:@(priority)];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (low && normal && high)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
break;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
return priorities;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDate*)dateAdded
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
time_t const date = self.fStat->addedDate;
|
2021-08-15 09:41:48 +00:00
|
|
|
return [NSDate dateWithTimeIntervalSince1970:date];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDate*)dateCompleted
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
time_t const date = self.fStat->doneDate;
|
2021-08-15 09:41:48 +00:00
|
|
|
return date != 0 ? [NSDate dateWithTimeIntervalSince1970:date] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDate*)dateActivity
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
time_t const date = self.fStat->activityDate;
|
2021-08-15 09:41:48 +00:00
|
|
|
return date != 0 ? [NSDate dateWithTimeIntervalSince1970:date] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDate*)dateActivityOrAdd
|
2007-11-23 02:46:29 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* date = self.dateActivity;
|
2021-08-07 07:27:56 +00:00
|
|
|
return date ? date : self.dateAdded;
|
2007-11-23 02:46:29 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)secondsDownloading
|
2010-12-23 20:07:41 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->secondsDownloading;
|
2010-12-23 20:07:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)secondsSeeding
|
2010-12-23 20:07:41 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->secondsSeeding;
|
2010-12-23 20:07:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)stalledMinutes
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fStat->idleSecs == -1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-07-11 21:06:28 +00:00
|
|
|
return -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->idleSecs / 60;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)isStalled
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fStat->isStalled;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateTimeMachineExclude
|
2009-10-21 22:20:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[self setTimeMachineExclude:!self.allDownloaded];
|
2009-10-21 22:20:43 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)stateSortKey
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!self.active) //paused
|
2009-10-15 23:18:39 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.waitingToStart)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-15 23:18:39 +00:00
|
|
|
return 1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-15 23:18:39 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-15 23:18:39 +00:00
|
|
|
return 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-15 23:18:39 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (self.seeding) //seeding
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-15 23:18:39 +00:00
|
|
|
return 10;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2008-06-30 02:22:29 +00:00
|
|
|
else //downloading
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2009-10-15 23:18:39 +00:00
|
|
|
return 20;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSString*)trackerSortKey
|
2009-10-11 13:42:10 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* best = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (size_t i = 0, n = tr_torrentTrackerCount(self.fHandle); i < n; ++i)
|
2009-10-11 13:42:10 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const tracker = tr_torrentTracker(self.fHandle, i);
|
2021-12-08 16:55:52 +00:00
|
|
|
|
|
|
|
NSString* host = @(tracker.host);
|
|
|
|
if (!best || [host localizedCaseInsensitiveCompare:best] == NSOrderedAscending)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-08 16:55:52 +00:00
|
|
|
best = host;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-10-11 13:42:10 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-10-11 13:42:10 +00:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (tr_torrent*)torrentStruct
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
return self.fHandle;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSURL*)previewItemURL
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = self.dataLocation;
|
|
|
|
return location ? [NSURL fileURLWithPath:location] : nil;
|
2009-09-04 04:10:46 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithPath:(NSString*)path
|
|
|
|
hash:(NSString*)hashString
|
|
|
|
torrentStruct:(tr_torrent*)torrentStruct
|
|
|
|
magnetAddress:(NSString*)magnetAddress
|
|
|
|
lib:(tr_session*)lib
|
|
|
|
groupValue:(NSNumber*)groupValue
|
|
|
|
removeWhenFinishSeeding:(NSNumber*)removeWhenFinishSeeding
|
|
|
|
downloadFolder:(NSString*)downloadFolder
|
|
|
|
legacyIncompleteFolder:(NSString*)incompleteFolder
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (!(self = [super init]))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
return nil;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDefaults = NSUserDefaults.standardUserDefaults;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
if (torrentStruct)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fHandle = torrentStruct;
|
2021-08-15 09:41:48 +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
|
2021-08-15 09:41:48 +00:00
|
|
|
tr_ctor* ctor = tr_ctorNew(lib);
|
2017-01-24 17:53:16 +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)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
tr_ctorSetDownloadDir(ctor, TR_FORCE, downloadFolder.UTF8String);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2009-12-13 01:36:22 +00:00
|
|
|
if (incompleteFolder)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
tr_ctorSetIncompleteDir(ctor, incompleteFolder.UTF8String);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
bool loaded = false;
|
|
|
|
|
2009-05-22 02:08:51 +00:00
|
|
|
if (path)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-26 16:25:07 +00:00
|
|
|
loaded = tr_ctorSetMetainfoFromFile(ctor, path.UTF8String, nullptr);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
if (!loaded && magnetAddress)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-12-26 16:25:07 +00:00
|
|
|
loaded = tr_ctorSetMetainfoFromMagnetLink(ctor, magnetAddress.UTF8String, nullptr);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-12-26 16:25:07 +00:00
|
|
|
if (loaded)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fHandle = tr_torrentNew(ctor, NULL);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-05-26 23:23:07 +00:00
|
|
|
tr_ctorFree(ctor);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!_fHandle)
|
2008-05-26 23:23:07 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fResumeOnWake = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-01-23 00:30:04 +00:00
|
|
|
//don't do after this point - it messes with auto-group functionality
|
2021-08-07 07:27:56 +00:00
|
|
|
if (!self.magnet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-01-23 00:30:04 +00:00
|
|
|
[self createFileList];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDownloadFolderDetermination = TorrentDeterminationAutomatic;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-10-30 00:22:10 +00:00
|
|
|
if (groupValue)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fGroupValueDetermination = TorrentDeterminationUserSpecified;
|
|
|
|
_groupValue = groupValue.intValue;
|
2012-10-30 00:22:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fGroupValueDetermination = TorrentDeterminationAutomatic;
|
|
|
|
_groupValue = [GroupsController.groups groupIndexForTorrent:self];
|
2012-10-30 00:22:10 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
_removeWhenFinishSeeding = removeWhenFinishSeeding ? removeWhenFinishSeeding.boolValue :
|
2022-02-22 16:04:20 +00:00
|
|
|
[_fDefaults boolForKey:@"RemoveWhenFinishSeeding"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(checkGroupValueForRemoval:)
|
|
|
|
name:@"GroupValueRemoved"
|
|
|
|
object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fTimeMachineExcludeInitialized = NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
[self update];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)createFileList
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSAssert(!self.magnet, @"Cannot create a file list until the torrent is demagnetized");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.folder)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-05-14 05:31:24 +00:00
|
|
|
NSUInteger const count = self.fileCount;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSMutableArray* flatFileList = [NSMutableArray arrayWithCapacity:count];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* tempNode = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-14 05:31:24 +00:00
|
|
|
for (NSUInteger i = 0; i < count; i++)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
auto const file = tr_torrentFile(self.fHandle, i);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-11-28 03:17:47 +00:00
|
|
|
NSString* fullPath = @(file.name);
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* pathComponents = fullPath.pathComponents;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-02-19 02:04:42 +00:00
|
|
|
if (!tempNode)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
tempNode = [[FileListNode alloc] initWithFolderName:pathComponents[0] path:@"" torrent:self];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-30 17:49:52 +00:00
|
|
|
[self insertPathForComponents:pathComponents //
|
2022-03-30 21:52:23 +00:00
|
|
|
withComponentIndex:1
|
|
|
|
forParent:tempNode
|
|
|
|
fileSize:file.length
|
|
|
|
index:i
|
2021-08-15 09:41:48 +00:00
|
|
|
flatList:flatFileList];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self sortFileList:tempNode.children];
|
|
|
|
[self sortFileList:flatFileList];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fileList = [[NSArray alloc] initWithArray:tempNode.children];
|
|
|
|
self.flatFileList = [[NSArray alloc] initWithArray:flatFileList];
|
2008-05-22 18:39:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
FileListNode* node = [[FileListNode alloc] initWithFileName:self.name path:@"" size:self.size index:0 torrent:self];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fileList = @[ node ];
|
|
|
|
self.flatFileList = self.fileList;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)insertPathForComponents:(NSArray<NSString*>*)components
|
2021-08-15 09:41:48 +00:00
|
|
|
withComponentIndex:(NSUInteger)componentIndex
|
|
|
|
forParent:(FileListNode*)parent
|
|
|
|
fileSize:(uint64_t)size
|
|
|
|
index:(NSInteger)index
|
2022-04-29 22:51:40 +00:00
|
|
|
flatList:(NSMutableArray<FileListNode*>*)flatFileList
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSParameterAssert(components.count > 0);
|
|
|
|
NSParameterAssert(componentIndex < components.count);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* name = components[componentIndex];
|
|
|
|
BOOL const isFolder = componentIndex < (components.count - 1);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-14 16:07:58 +00:00
|
|
|
//determine if folder node already exists
|
2021-08-15 09:41:48 +00:00
|
|
|
__block FileListNode* node = nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
if (isFolder)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[parent.children enumerateObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
usingBlock:^(FileListNode* searchNode, NSUInteger idx, BOOL* stop) {
|
|
|
|
if ([searchNode.name isEqualToString:name] && searchNode.isFolder)
|
|
|
|
{
|
|
|
|
node = searchNode;
|
|
|
|
*stop = YES;
|
|
|
|
}
|
|
|
|
}];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = [parent.path stringByAppendingPathComponent:parent.name];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (isFolder)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
node = [[FileListNode alloc] initWithFolderName:name path:path torrent:self];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-12-07 02:36:26 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
node = [[FileListNode alloc] initWithFileName:name path:path size:size index:index torrent:self];
|
|
|
|
[flatFileList addObject:node];
|
2008-12-07 02:36:26 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[parent insertChild:node];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
if (isFolder)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[node insertIndex:index withSize:size];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-04-30 17:49:52 +00:00
|
|
|
[self insertPathForComponents:components //
|
|
|
|
withComponentIndex:componentIndex + 1
|
|
|
|
forParent:node
|
|
|
|
fileSize:size
|
2021-08-15 09:41:48 +00:00
|
|
|
index:index
|
|
|
|
flatList:flatFileList];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)sortFileList:(NSMutableArray<FileListNode*>*)fileNodes
|
2010-10-23 20:20:31 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSSortDescriptor* descriptor = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES
|
|
|
|
selector:@selector(localizedStandardCompare:)];
|
|
|
|
[fileNodes sortUsingDescriptors:@[ descriptor ]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[fileNodes enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(FileListNode* node, NSUInteger idx, BOOL* stop) {
|
2021-08-07 07:27:56 +00:00
|
|
|
if (node.isFolder)
|
2021-08-15 09:41:48 +00:00
|
|
|
[self sortFileList:node.children];
|
2012-01-09 00:57:50 +00:00
|
|
|
}];
|
2010-10-23 20:20:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)startQueue
|
2011-08-04 00:36:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateQueue" object:self];
|
2011-08-04 00:36:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)completenessChange:(tr_completeness)status wasRunning:(BOOL)wasRunning
|
2007-09-28 15:36:46 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStat = tr_torrentStat(self.fHandle); //don't call update yet to avoid auto-stop
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-07-14 14:35:57 +00:00
|
|
|
switch (status)
|
2007-09-28 15:36:46 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_SEED:
|
|
|
|
case TR_PARTIAL_SEED:
|
2013-07-14 14:35:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDictionary* statusInfo = @{@"Status" : @(status), @"WasRunning" : @(wasRunning)};
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"TorrentFinishedDownloading" object:self userInfo:statusInfo];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-14 17:12:04 +00:00
|
|
|
//quarantine the finished data
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* dataLocation = [self.currentDirectory stringByAppendingPathComponent:self.name];
|
|
|
|
NSURL* dataLocationUrl = [NSURL fileURLWithPath:dataLocation];
|
|
|
|
NSDictionary* quarantineProperties = @{
|
|
|
|
(NSString*)kLSQuarantineTypeKey : (NSString*)kLSQuarantineTypeOtherDownload
|
|
|
|
};
|
|
|
|
NSError* error = nil;
|
|
|
|
if (![dataLocationUrl setResourceValue:quarantineProperties forKey:NSURLQuarantinePropertiesKey error:&error])
|
|
|
|
{
|
|
|
|
NSLog(@"Failed to quarantine %@: %@", dataLocation, error.description);
|
|
|
|
}
|
2007-09-28 15:36:46 +00:00
|
|
|
break;
|
2013-07-14 14:35:57 +00:00
|
|
|
}
|
2021-08-15 09:41:48 +00:00
|
|
|
case TR_LEECH:
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"TorrentRestartedDownloading" object:self];
|
|
|
|
break;
|
2007-09-28 15:36:46 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)ratioLimitHit
|
2009-02-14 21:15:57 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStat = tr_torrentStat(self.fHandle);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"TorrentFinishedSeeding" object:self];
|
2009-02-14 21:15:57 +00:00
|
|
|
}
|
2007-09-28 15:36:46 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)idleLimitHit
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStat = tr_torrentStat(self.fHandle);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"TorrentFinishedSeeding" object:self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)metadataRetrieved
|
2009-11-27 03:44:00 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStat = tr_torrentStat(self.fHandle);
|
2012-10-30 00:22:10 +00:00
|
|
|
|
2010-01-23 00:30:04 +00:00
|
|
|
[self createFileList];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-10-30 00:22:10 +00:00
|
|
|
/* If the torrent is in no group, or the group was automatically determined based on criteria evaluated
|
|
|
|
* before we had metadata for this torrent, redetermine the group
|
|
|
|
*/
|
2022-02-22 16:04:20 +00:00
|
|
|
if ((self.fGroupValueDetermination == TorrentDeterminationAutomatic) || (self.groupValue == -1))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self setGroupValue:[GroupsController.groups groupIndexForTorrent:self] determinationType:TorrentDeterminationAutomatic];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-10-30 00:22:10 +00:00
|
|
|
//change the location if the group calls for it and it's either not already set or was set automatically before
|
2022-02-22 16:04:20 +00:00
|
|
|
if (((self.fDownloadFolderDetermination == TorrentDeterminationAutomatic) || !tr_torrentGetCurrentDir(self.fHandle)) &&
|
2021-08-15 09:41:48 +00:00
|
|
|
[GroupsController.groups usesCustomDownloadLocationForIndex:self.groupValue])
|
2012-10-30 00:22:10 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = [GroupsController.groups customDownloadLocationForIndex:self.groupValue];
|
|
|
|
[self changeDownloadFolderBeforeUsing:location determinationType:TorrentDeterminationAutomatic];
|
2012-10-30 00:22:10 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"ResetInspector" object:self userInfo:@{ @"Torrent" : self }];
|
2009-11-27 03:44:00 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)renameFinished:(BOOL)success
|
2022-04-29 22:51:40 +00:00
|
|
|
nodes:(NSArray<FileListNode*>*)nodes
|
2021-08-15 09:41:48 +00:00
|
|
|
completionHandler:(void (^)(BOOL))completionHandler
|
|
|
|
oldPath:(NSString*)oldPath
|
|
|
|
newName:(NSString*)newName
|
2013-02-11 01:39:44 +00:00
|
|
|
{
|
|
|
|
NSParameterAssert(completionHandler != nil);
|
|
|
|
NSParameterAssert(oldPath != nil);
|
|
|
|
NSParameterAssert(newName != nil);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path = oldPath.stringByDeletingLastPathComponent;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-02-11 01:39:44 +00:00
|
|
|
if (success)
|
|
|
|
{
|
2021-09-24 12:56:57 +00:00
|
|
|
using WeakUpdateNodeAndChildrenForRename = void (^__block __weak)(FileListNode*);
|
|
|
|
using UpdateNodeAndChildrenForRename = void (^)(FileListNode*);
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* oldName = oldPath.lastPathComponent;
|
2021-09-24 12:56:57 +00:00
|
|
|
WeakUpdateNodeAndChildrenForRename weakUpdateNodeAndChildrenForRename;
|
|
|
|
UpdateNodeAndChildrenForRename updateNodeAndChildrenForRename;
|
2021-08-15 09:41:48 +00:00
|
|
|
weakUpdateNodeAndChildrenForRename = updateNodeAndChildrenForRename = ^(FileListNode* node) {
|
|
|
|
[node updateFromOldName:oldName toNewName:newName inPath:path];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
if (node.isFolder)
|
|
|
|
{
|
|
|
|
[node.children enumerateObjectsWithOptions:NSEnumerationConcurrent
|
|
|
|
usingBlock:^(FileListNode* childNode, NSUInteger idx, BOOL* stop) {
|
|
|
|
weakUpdateNodeAndChildrenForRename(childNode);
|
|
|
|
}];
|
2013-02-11 01:39:44 +00:00
|
|
|
}
|
|
|
|
};
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-02-11 01:39:44 +00:00
|
|
|
if (!nodes)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
nodes = self.flatFileList;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
|
|
|
[nodes enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(FileListNode* node, NSUInteger idx, BOOL* stop) {
|
2013-02-11 01:39:44 +00:00
|
|
|
updateNodeAndChildrenForRename(node);
|
|
|
|
}];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-02-11 01:39:44 +00:00
|
|
|
//resort lists
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableArray* fileList = [self.fileList mutableCopy];
|
2021-08-15 09:41:48 +00:00
|
|
|
[self sortFileList:fileList];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fileList = fileList;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSMutableArray* flatFileList = [self.flatFileList mutableCopy];
|
2021-08-15 09:41:48 +00:00
|
|
|
[self sortFileList:flatFileList];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.flatFileList = flatFileList;
|
2017-02-21 20:52:41 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIcon = nil;
|
2013-02-11 01:39:44 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
NSLog(@"Error renaming %@ to %@", oldPath, [path stringByAppendingPathComponent:newName]);
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-02-11 01:39:44 +00:00
|
|
|
completionHandler(success);
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)shouldShowEta
|
2010-08-14 17:32:52 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fStat->activity == TR_STATUS_DOWNLOAD)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-08-14 17:32:52 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-08-07 07:27:56 +00:00
|
|
|
else if (self.seeding)
|
2010-08-14 17:32:52 +00:00
|
|
|
{
|
2010-08-14 19:44:43 +00:00
|
|
|
//ratio: show if it's set at all
|
2022-02-22 16:04:20 +00:00
|
|
|
if (tr_torrentGetSeedRatio(self.fHandle, NULL))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-08-14 17:32:52 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-08-14 19:44:43 +00:00
|
|
|
//idle: show only if remaining time is less than cap
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fStat->etaIdle != TR_ETA_NOT_AVAIL && self.fStat->etaIdle < ETA_IDLE_DISPLAY_SEC)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-08-14 17:51:04 +00:00
|
|
|
return YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-08-14 17:32:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-08-14 17:32:52 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fStat->eta != TR_ETA_NOT_AVAIL && self.fStat->eta != TR_ETA_UNKNOWN)
|
2010-08-14 19:44:43 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
eta = self.fStat->eta;
|
2010-08-14 19:44:43 +00:00
|
|
|
fromIdle = NO;
|
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
else if (self.fStat->etaIdle != TR_ETA_NOT_AVAIL && self.fStat->etaIdle < ETA_IDLE_DISPLAY_SEC)
|
2010-08-14 19:44:43 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
eta = self.fStat->etaIdle;
|
2010-08-14 19:44:43 +00:00
|
|
|
fromIdle = YES;
|
|
|
|
}
|
2010-08-14 15:30:43 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-08-14 15:30:43 +00:00
|
|
|
return NSLocalizedString(@"remaining time unknown", "Torrent -> eta string");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
static NSDateComponentsFormatter* formatter;
|
2020-12-23 03:00:06 +00:00
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
formatter = [NSDateComponentsFormatter new];
|
|
|
|
formatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
|
|
|
|
formatter.maximumUnitCount = 2;
|
|
|
|
formatter.collapsesLargestUnit = YES;
|
|
|
|
formatter.includesTimeRemainingPhrase = YES;
|
|
|
|
});
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* idleString = [formatter stringFromTimeInterval:eta];
|
|
|
|
|
|
|
|
if (fromIdle)
|
|
|
|
{
|
|
|
|
idleString = [idleString stringByAppendingFormat:@" (%@)", NSLocalizedString(@"inactive", "Torrent -> eta string")];
|
2014-10-17 05:12:00 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-08-14 19:44:43 +00:00
|
|
|
return idleString;
|
2008-04-07 02:55:33 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setTimeMachineExclude:(BOOL)exclude
|
2008-01-09 16:26:58 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* path;
|
2021-08-07 07:27:56 +00:00
|
|
|
if ((path = self.dataLocation))
|
2012-08-06 03:59:07 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CSBackupSetItemExcluded((__bridge CFURLRef)[NSURL fileURLWithPath:path], exclude, false);
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTimeMachineExcludeInitialized = YES;
|
2012-08-06 03:59:07 +00:00
|
|
|
}
|
2008-01-09 16:26:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 15:17:02 +00:00
|
|
|
// For backward comatibility for previously saved Group Predicates.
|
|
|
|
- (NSArray<FileListNode*>*)fFlatFileList
|
|
|
|
{
|
|
|
|
return self.flatFileList;
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|