mirror of
https://github.com/transmission/transmission
synced 2025-01-31 03:12:44 +00:00
#1029 show a warning dialog when removing a transfer's data if its directory contains extra files
This commit is contained in:
parent
8e6529ad8f
commit
a12715fc9a
6 changed files with 87 additions and 9 deletions
|
@ -172,6 +172,8 @@
|
|||
<integer>50</integer>
|
||||
<key>UseIncompleteDownloadFolder</key>
|
||||
<false/>
|
||||
<key>WarningCheckContentsForRemove</key>
|
||||
<true/>
|
||||
<key>WarningCreatorBlankAddress</key>
|
||||
<true/>
|
||||
<key>WarningDuplicate</key>
|
||||
|
|
|
@ -52,4 +52,6 @@
|
|||
|
||||
- (NSArray *) children;
|
||||
|
||||
- (BOOL) containsPath: (NSString *) fullPath;
|
||||
|
||||
@end
|
||||
|
|
|
@ -128,6 +128,23 @@
|
|||
return fChildren;
|
||||
}
|
||||
|
||||
- (BOOL) containsPath: (NSString *) fullPath
|
||||
{
|
||||
if ([fullPath isEqualToString: fPath])
|
||||
return YES;
|
||||
|
||||
if (fIsFolder && [fullPath hasPrefix: fPath])
|
||||
{
|
||||
NSEnumerator * enumerator = [fChildren objectEnumerator];
|
||||
FileListNode * node;
|
||||
while ((node = [enumerator nextObject]))
|
||||
if ([node containsPath: fullPath])
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation FileListNode (Private)
|
||||
|
|
|
@ -996,35 +996,33 @@ typedef enum
|
|||
}
|
||||
|
||||
//determing status strings from flags
|
||||
NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 3];
|
||||
NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 6];
|
||||
NSString * flags = [peer objectForKey: @"Flags"];
|
||||
|
||||
if ([flags rangeOfString: @"D"].location != NSNotFound)
|
||||
[statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)",
|
||||
"Inspector -> peer -> status")];
|
||||
else if ([flags rangeOfString: @"d"].location != NSNotFound)
|
||||
if ([flags rangeOfString: @"d"].location != NSNotFound)
|
||||
[statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)",
|
||||
"Inspector -> peer -> status")];
|
||||
else;
|
||||
|
||||
if ([flags rangeOfString: @"U"].location != NSNotFound)
|
||||
[statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)",
|
||||
"Inspector -> peer -> status")];
|
||||
else if ([flags rangeOfString: @"u"].location != NSNotFound)
|
||||
if ([flags rangeOfString: @"u"].location != NSNotFound)
|
||||
[statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)",
|
||||
"Inspector -> peer -> status")];
|
||||
else;
|
||||
|
||||
if ([flags rangeOfString: @"K"].location != NSNotFound)
|
||||
[statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested",
|
||||
"Inspector -> peer -> status")];
|
||||
|
||||
if ([flags rangeOfString: @"?"].location != NSNotFound)
|
||||
[statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested",
|
||||
"Inspector -> peer -> status")];
|
||||
|
||||
if ([statusArray count] > 0)
|
||||
[components addObject: [@"\n" stringByAppendingString: [statusArray componentsJoinedByString: @"\n\n"]]];
|
||||
{
|
||||
NSString * statusStrings = [statusArray componentsJoinedByString: @"\n\n"];
|
||||
[components addObject: [@"\n" stringByAppendingString: statusStrings]];
|
||||
}
|
||||
|
||||
return [components componentsJoinedByString: @"\n"];
|
||||
}
|
||||
|
|
|
@ -611,6 +611,7 @@ tr_handle * fHandle;
|
|||
[fDefaults removeObjectForKey: @"WarningCreatorBlankAddress"];
|
||||
[fDefaults removeObjectForKey: @"WarningRemoveBuiltInTracker"];
|
||||
[fDefaults removeObjectForKey: @"WarningInvalidOpen"];
|
||||
[fDefaults removeObjectForKey: @"WarningCheckContentsForRemove"];
|
||||
}
|
||||
|
||||
- (void) setQueue: (id) sender
|
||||
|
|
|
@ -448,6 +448,64 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo
|
|||
|
||||
- (void) trashData
|
||||
{
|
||||
if ([self isFolder] && [fDefaults boolForKey: @"WarningCheckContentsForRemove"])
|
||||
{
|
||||
NSEnumerator * enumerator = [[NSFileManager defaultManager] enumeratorAtPath: [self dataLocation]];
|
||||
NSString * file;
|
||||
while ((file = [enumerator nextObject]))
|
||||
{
|
||||
if ([[file lastPathComponent] hasPrefix: @"."])
|
||||
continue;
|
||||
|
||||
file = [[self name] stringByAppendingPathComponent: file];
|
||||
BOOL isExtra = YES;
|
||||
|
||||
NSEnumerator * nodeEnumerator = [fFileList objectEnumerator];
|
||||
FileListNode * node;
|
||||
while ((node = [nodeEnumerator nextObject]))
|
||||
{
|
||||
if ([node containsPath: file])
|
||||
{
|
||||
isExtra = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isExtra)
|
||||
continue;
|
||||
|
||||
NSLog(@"Extra file found: %@", file);
|
||||
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"\"%@\" contains extra content.",
|
||||
"Delete folder with extra contents -> title"), [self name]]];
|
||||
[alert setInformativeText: NSLocalizedString(@"The directory contains data that is not part of the transfer."
|
||||
" Are you sure you want to move this directory to the trash?", "Delete folder with extra contents -> message")];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Remove", "Delete folder with extra contents -> button")];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Keep", "Delete folder with extra contents -> button")];
|
||||
|
||||
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
|
||||
if (onLeopard)
|
||||
{
|
||||
[alert setShowsSuppressionButton: YES];
|
||||
[[alert suppressionButton] setTitle: NSLocalizedString(@"Do not check directory contents again",
|
||||
"Delete folder with extra contents -> button")];
|
||||
}
|
||||
else
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Never Check", "Delete folder with extra contents -> button")];
|
||||
|
||||
NSInteger result = [alert runModal];
|
||||
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertThirdButtonReturn))
|
||||
[fDefaults setBool: NO forKey: @"WarningCheckContentsForRemove"];
|
||||
[alert release];
|
||||
|
||||
if (result == NSAlertSecondButtonReturn)
|
||||
return;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[self trashFile: [self dataLocation]];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue