Changeset 6003


Ignore:
Timestamp:
Jun 2, 2008, 7:42:14 PM (14 years ago)
Author:
livings124
Message:

for now don't allow modification of non-user added trackers

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.m

    r6002 r6003  
    934934   
    935935    Torrent * torrent= [fTorrents objectAtIndex: 0];
    936     if (![torrent updateAllTrackers: fTrackers forAdd: YES])
     936    if (![torrent updateAllTrackersForAdd: fTrackers])
    937937        NSBeep();
    938938   
     
    960960- (BOOL) tableView: (NSTableView *) tableView shouldEditTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
    961961{
    962     return ![[fTrackers objectAtIndex: row] isKindOfClass: [NSNumber class]];
     962    if (tableView != fTrackerTable)
     963        return NO;
     964   
     965    //only allow modification of custom-added trackers
     966    if ([[fTrackers objectAtIndex: row] isKindOfClass: [NSNumber class]] || ![[fTorrents objectAtIndex: 0] hasAddedTrackers])
     967        return NO;
     968   
     969    NSUInteger i;
     970    for (i = row-1; ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; i--);
     971   
     972    return [[fTrackers objectAtIndex: i] intValue] == 0;
    963973}
    964974
     
    15011511    if (numberBuiltIn > 0 && [[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveBuiltInTracker"])
    15021512    {
    1503         #warning pluralize?
    15041513        NSAlert * alert = [[NSAlert alloc] init];
    15051514       
     
    15401549    [fTrackers removeObjectsAtIndexes: indexes];
    15411550   
    1542     if (![torrent updateAllTrackers: fTrackers forAdd: NO])
     1551    if (![torrent updateAllTrackersForRemove: fTrackers])
    15431552        NSBeep();
    15441553    else
  • trunk/macosx/Torrent.h

    r5998 r6003  
    152152
    153153- (NSMutableArray *) allTrackers: (BOOL) separators;
    154 - (BOOL) updateAllTrackers: (NSMutableArray *) trackers forAdd: (BOOL) add;
     154- (BOOL) updateAllTrackersForAdd: (NSMutableArray *) trackers;
     155- (BOOL) updateAllTrackersForRemove: (NSMutableArray *) trackers;
    155156- (BOOL) hasAddedTrackers;
    156157
  • trunk/macosx/Torrent.m

    r6000 r6003  
    5454
    5555- (NSString *) etaString: (int) eta;
     56
     57- (BOOL) updateAllTrackers: (NSMutableArray *) trackers;
    5658
    5759- (void) trashFile: (NSString *) path;
     
    804806}
    805807
    806 - (BOOL) updateAllTrackers: (NSMutableArray *) trackers forAdd: (BOOL) add
    807 {
    808     #warning break up into methods
    809     if (add)
    810     {
    811         //find added tracker at end of first tier
    812         int i;
    813         for (i = 1; i < [trackers count]; i++)
    814             if ([[trackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
    815                 break;
    816         i--;
    817        
    818         NSString * tracker = [trackers objectAtIndex: i];
    819         if ([tracker rangeOfString: @"://"].location == NSNotFound)
    820         {
    821             tracker = [@"http://" stringByAppendingString: tracker];
    822             [trackers replaceObjectAtIndex: i withObject: tracker];
    823         }
    824        
    825         if (!tr_httpIsValidURL([tracker UTF8String]))
    826             return NO;
    827        
    828         fAddedTrackers = YES;
    829     }
    830     else
    831     {
    832         //check if any user-added groups
    833         if ([[trackers objectAtIndex: 0] intValue] != 0)
    834             fAddedTrackers = NO;
    835     }
    836    
    837     //get count
    838     int count = 0;
    839     NSEnumerator * enumerator = [trackers objectEnumerator];
    840     id object;
    841     while ((object = [enumerator nextObject]))
    842         if (![object isKindOfClass: [NSNumber class]])
    843             count++;
    844    
    845     //recreate the tracker structure
    846     tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, count);
    847     int tier = 0;
    848     int i = 0;
    849     enumerator = [trackers objectEnumerator];
    850     while ((object = [enumerator nextObject]))
    851     {
    852         if (![object isKindOfClass: [NSNumber class]])
    853         {
    854             trackerStructs[i].tier = tier;
    855             trackerStructs[i].announce = (char *)[object UTF8String];
    856             i++;
    857         }
    858         else
    859             tier++;
    860     }
    861    
    862     tr_torrentSetAnnounceList(fHandle, trackerStructs, count);
    863     tr_free(trackerStructs);
    864    
    865     return YES;
     808- (BOOL) updateAllTrackersForAdd: (NSMutableArray *) trackers
     809{
     810    //find added tracker at end of first tier
     811    int i;
     812    for (i = 1; i < [trackers count]; i++)
     813        if ([[trackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
     814            break;
     815    i--;
     816   
     817    NSString * tracker = [trackers objectAtIndex: i];
     818    if ([tracker rangeOfString: @"://"].location == NSNotFound)
     819    {
     820        tracker = [@"http://" stringByAppendingString: tracker];
     821        [trackers replaceObjectAtIndex: i withObject: tracker];
     822    }
     823   
     824    if (!tr_httpIsValidURL([tracker UTF8String]))
     825        return NO;
     826   
     827    fAddedTrackers = YES;
     828   
     829    return [self updateAllTrackers: trackers];
     830}
     831
     832- (BOOL) updateAllTrackersForRemove: (NSMutableArray *) trackers
     833{
     834    //check if any user-added groups
     835    if ([[trackers objectAtIndex: 0] intValue] != 0)
     836        fAddedTrackers = NO;
     837   
     838    return [self updateAllTrackers: trackers];
    866839}
    867840
     
    19301903}
    19311904
     1905- (BOOL) updateAllTrackers: (NSMutableArray *) trackers
     1906{
     1907    //get count
     1908    int count = 0;
     1909    NSEnumerator * enumerator = [trackers objectEnumerator];
     1910    id object;
     1911    while ((object = [enumerator nextObject]))
     1912        if (![object isKindOfClass: [NSNumber class]])
     1913            count++;
     1914   
     1915    //recreate the tracker structure
     1916    tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, count);
     1917    int tier = 0;
     1918    int i = 0;
     1919    enumerator = [trackers objectEnumerator];
     1920    while ((object = [enumerator nextObject]))
     1921    {
     1922        if (![object isKindOfClass: [NSNumber class]])
     1923        {
     1924            trackerStructs[i].tier = tier;
     1925            trackerStructs[i].announce = (char *)[object UTF8String];
     1926            i++;
     1927        }
     1928        else
     1929            tier++;
     1930    }
     1931   
     1932    tr_torrentSetAnnounceList(fHandle, trackerStructs, count);
     1933    tr_free(trackerStructs);
     1934   
     1935    return YES;
     1936}
     1937
    19321938- (void) trashFile: (NSString *) path
    19331939{
Note: See TracChangeset for help on using the changeset viewer.