update for the new tracker verification changes, and use a set instead of an array for removing trackers

This commit is contained in:
Mitchell Livingston 2009-10-10 19:55:47 +00:00
parent fe2d851e5b
commit 6b452c1d07
3 changed files with 9 additions and 12 deletions

View File

@ -1439,7 +1439,6 @@ typedef enum
return;
Torrent * torrent = [fTorrents objectAtIndex: 0];
#warning still update unselected rows
//get update tracker stats
if ([fTrackerTable editedRow] == -1)
{
@ -1704,7 +1703,7 @@ typedef enum
- (void) removeTrackers
{
const NSInteger oldCount = [fTrackers count] - [(TrackerNode *)[fTrackers lastObject] tier];
NSMutableArray * addresses = [NSMutableArray arrayWithCapacity: oldCount];
NSMutableSet * addresses = [NSMutableSet setWithCapacity: oldCount];
NSIndexSet * indexes = [fTrackerTable selectedRowIndexes];
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])

View File

@ -132,7 +132,7 @@
- (NSMutableArray *) allTrackerStats;
- (NSMutableArray *) allTrackersFlat; //used by GroupRules
- (BOOL) addTrackerToNewTier: (NSString *) tracker;
- (void) removeTrackersWithAnnounceAddresses: (NSArray *) trackers;
- (void) removeTrackersWithAnnounceAddresses: (NSSet *) trackers;
- (NSString *) comment;
- (NSString *) creator;

View File

@ -705,7 +705,6 @@ int trashDataFile(const char * filename)
return allTrackers;
}
#warning check for duplicates?
- (BOOL) addTrackerToNewTier: (NSString *) tracker
{
tracker = [tracker stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
@ -713,9 +712,6 @@ int trashDataFile(const char * filename)
if ([tracker rangeOfString: @"://"].location == NSNotFound)
tracker = [@"http://" stringByAppendingString: tracker];
if (!tr_httpIsValidURL([tracker UTF8String]))
return NO;
//recreate the tracker structure
const int oldTrackerCount = fInfo->trackerCount;
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, oldTrackerCount+1);
@ -725,13 +721,13 @@ int trashDataFile(const char * filename)
trackerStructs[oldTrackerCount].announce = (char *)[tracker UTF8String];
trackerStructs[oldTrackerCount].tier = trackerStructs[oldTrackerCount-1].tier + 1;
tr_torrentSetAnnounceList(fHandle, trackerStructs, oldTrackerCount+1);
const tr_announce_list_err result = tr_torrentSetAnnounceList(fHandle, trackerStructs, oldTrackerCount+1);
tr_free(trackerStructs);
return YES;
return result == TR_ANNOUNCE_LIST_OK;
}
- (void) removeTrackersWithAnnounceAddresses: (NSArray *) trackers
- (void) removeTrackersWithAnnounceAddresses: (NSSet *) trackers
{
//recreate the tracker structure
const int oldTrackerCount = fInfo->trackerCount;
@ -740,13 +736,15 @@ int trashDataFile(const char * filename)
NSInteger newCount = 0;
for (NSInteger oldIndex = 0; oldIndex < oldTrackerCount; ++newCount, ++oldIndex)
{
if (![trackers containsObject: [NSString stringWithUTF8String: fInfo->trackers[oldIndex].announce]])
if (![trackers member: [NSString stringWithUTF8String: fInfo->trackers[oldIndex].announce]])
trackerStructs[newCount] = fInfo->trackers[oldIndex];
else
--newCount;
}
tr_torrentSetAnnounceList(fHandle, trackerStructs, newCount);
const tr_announce_list_err result = tr_torrentSetAnnounceList(fHandle, trackerStructs, newCount);
NSAssert1(result == TR_ANNOUNCE_LIST_OK, @"Removing tracker addresses resulted in error: %d", result);
tr_free(trackerStructs);
}