From 6b452c1d071d9b3fa30f913853b1ea195d0b9384 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 10 Oct 2009 19:55:47 +0000 Subject: [PATCH] update for the new tracker verification changes, and use a set instead of an array for removing trackers --- macosx/InfoWindowController.m | 3 +-- macosx/Torrent.h | 2 +- macosx/Torrent.m | 16 +++++++--------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 2c283279a..eb53a348f 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -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]) diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 1288aa75d..64a527554 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -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; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index ddd9df1c3..3d74c6841 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -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); } -- 2.40.0