Changeset 7153


Ignore:
Timestamp:
Nov 25, 2008, 3:04:17 AM (12 years ago)
Author:
livings124
Message:

#1029 show a warning dialog when removing a transfer's data if its directory contains extra files

Location:
trunk/macosx
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Defaults.plist

    r6826 r7153  
    173173        <key>UseIncompleteDownloadFolder</key>
    174174        <false/>
     175        <key>WarningCheckContentsForRemove</key>
     176        <true/>
    175177        <key>WarningCreatorBlankAddress</key>
    176178        <true/>
  • trunk/macosx/FileListNode.h

    r7007 r7153  
    5353- (NSArray *) children;
    5454
     55- (BOOL) containsPath: (NSString *) fullPath;
     56
    5557@end
  • trunk/macosx/FileListNode.m

    r7007 r7153  
    129129}
    130130
     131- (BOOL) containsPath: (NSString *) fullPath
     132{
     133    if ([fullPath isEqualToString: fPath])
     134        return YES;
     135   
     136    if (fIsFolder && [fullPath hasPrefix: fPath])
     137    {
     138        NSEnumerator * enumerator = [fChildren objectEnumerator];
     139        FileListNode * node;
     140        while ((node = [enumerator nextObject]))
     141            if ([node containsPath: fullPath])
     142                return YES;
     143    }
     144   
     145    return NO;
     146}
     147
    131148@end
    132149
  • trunk/macosx/InfoWindowController.m

    r7016 r7153  
    997997       
    998998        //determing status strings from flags
    999         NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 3];
     999        NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 6];
    10001000        NSString * flags = [peer objectForKey: @"Flags"];
    10011001       
     
    10031003            [statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)",
    10041004                "Inspector -> peer -> status")];
    1005         else if ([flags rangeOfString: @"d"].location != NSNotFound)
     1005        if ([flags rangeOfString: @"d"].location != NSNotFound)
    10061006            [statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)",
    10071007                "Inspector -> peer -> status")];
    1008         else;
    1009        
    10101008        if ([flags rangeOfString: @"U"].location != NSNotFound)
    10111009            [statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)",
    10121010                "Inspector -> peer -> status")];
    1013         else if ([flags rangeOfString: @"u"].location != NSNotFound)
     1011        if ([flags rangeOfString: @"u"].location != NSNotFound)
    10141012            [statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)",
    10151013                "Inspector -> peer -> status")];
    1016         else;
    1017        
    10181014        if ([flags rangeOfString: @"K"].location != NSNotFound)
    10191015            [statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested",
    10201016                "Inspector -> peer -> status")];
    1021        
    10221017        if ([flags rangeOfString: @"?"].location != NSNotFound)
    10231018            [statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested",
     
    10251020       
    10261021        if ([statusArray count] > 0)
    1027             [components addObject: [@"\n" stringByAppendingString: [statusArray componentsJoinedByString: @"\n\n"]]];
     1022        {
     1023            NSString * statusStrings = [statusArray componentsJoinedByString: @"\n\n"];
     1024            [components addObject: [@"\n" stringByAppendingString: statusStrings]];
     1025        }
    10281026       
    10291027        return [components componentsJoinedByString: @"\n"];
  • trunk/macosx/PrefsController.m

    r7081 r7153  
    612612    [fDefaults removeObjectForKey: @"WarningRemoveBuiltInTracker"];
    613613    [fDefaults removeObjectForKey: @"WarningInvalidOpen"];
     614    [fDefaults removeObjectForKey: @"WarningCheckContentsForRemove"];
    614615}
    615616
  • trunk/macosx/Torrent.m

    r7151 r7153  
    449449- (void) trashData
    450450{
     451    if ([self isFolder] && [fDefaults boolForKey: @"WarningCheckContentsForRemove"])
     452    {
     453        NSEnumerator * enumerator = [[NSFileManager defaultManager] enumeratorAtPath: [self dataLocation]];
     454        NSString * file;
     455        while ((file = [enumerator nextObject]))
     456        {
     457            if ([[file lastPathComponent] hasPrefix: @"."])
     458                continue;
     459           
     460            file = [[self name] stringByAppendingPathComponent: file];
     461            BOOL isExtra = YES;
     462       
     463            NSEnumerator * nodeEnumerator = [fFileList objectEnumerator];
     464            FileListNode * node;
     465            while ((node = [nodeEnumerator nextObject]))
     466            {
     467                if ([node containsPath: file])
     468                {
     469                    isExtra = NO;
     470                    break;
     471                }
     472            }
     473           
     474            if (!isExtra)
     475                continue;
     476
     477            NSLog(@"Extra file found: %@", file);
     478           
     479            NSAlert * alert = [[NSAlert alloc] init];
     480            [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"\"%@\" contains extra content.",
     481                                                        "Delete folder with extra contents -> title"), [self name]]];
     482            [alert setInformativeText: NSLocalizedString(@"The directory contains data that is not part of the transfer."
     483                " Are you sure you want to move this directory to the trash?", "Delete folder with extra contents -> message")];
     484            [alert addButtonWithTitle: NSLocalizedString(@"Remove", "Delete folder with extra contents -> button")];
     485            [alert addButtonWithTitle: NSLocalizedString(@"Keep", "Delete folder with extra contents -> button")];
     486           
     487            BOOL onLeopard = [NSApp isOnLeopardOrBetter];
     488            if (onLeopard)
     489            {
     490                [alert setShowsSuppressionButton: YES];
     491                [[alert suppressionButton] setTitle: NSLocalizedString(@"Do not check directory contents again",
     492                                                        "Delete folder with extra contents -> button")];
     493            }
     494            else
     495                [alert addButtonWithTitle: NSLocalizedString(@"Never Check", "Delete folder with extra contents -> button")];
     496
     497            NSInteger result = [alert runModal];
     498            if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertThirdButtonReturn))
     499                [fDefaults setBool: NO forKey: @"WarningCheckContentsForRemove"];
     500            [alert release];
     501           
     502            if (result == NSAlertSecondButtonReturn)
     503                return;
     504            else
     505                break;
     506        }
     507    }
     508   
    451509    [self trashFile: [self dataLocation]];
    452510}
Note: See TracChangeset for help on using the changeset viewer.