speed up check for enough remaining space by first determining if there is enough space to download what's needed ignoring preallocation

This commit is contained in:
Mitchell Livingston 2008-03-18 03:20:27 +00:00
parent ec34995cff
commit 4f7742d422
2 changed files with 43 additions and 41 deletions

View File

@ -547,49 +547,53 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
: [fileManager fileSystemAttributesAtPath: downloadFolder];
uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue], neededSpace = 0;
[self updateFileStat];
//determine amount needed
int i;
for (i = 0; i < [self fileCount]; i++)
//if the size left is less then remaining space, then there is enough space regardless of preallocation
if (remainingSpace < [self sizeLeft])
{
if (tr_torrentGetFileDL(fHandle, i))
[self updateFileStat];
//determine amount needed
int i;
for (i = 0; i < [self fileCount]; i++)
{
tr_file * file = &fInfo->files[i];
neededSpace += file->length;
NSString * path = [downloadFolder stringByAppendingPathComponent: [NSString stringWithUTF8String: file->name]];
NSDictionary * fileAttributes = onLeopard ? [fileManager attributesOfItemAtPath: path error: NULL]
: [fileManager fileAttributesAtPath: path traverseLink: NO];
if (fileAttributes)
neededSpace -= [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
if (tr_torrentGetFileDL(fHandle, i))
{
tr_file * file = &fInfo->files[i];
neededSpace += file->length;
NSString * path = [downloadFolder stringByAppendingPathComponent: [NSString stringWithUTF8String: file->name]];
NSDictionary * fileAttributes = onLeopard ? [fileManager attributesOfItemAtPath: path error: NULL]
: [fileManager fileAttributesAtPath: path traverseLink: NO];
if (fileAttributes)
neededSpace -= [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
}
}
}
if (remainingSpace < neededSpace)
{
NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText: [NSString stringWithFormat:
NSLocalizedString(@"Not enough remaining disk space to download \"%@\" completely.",
"Torrent file disk space alert -> title"), [self name]]];
[alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"The transfer will be paused."
" Clear up space on %@ or deselect files in the torrent inspector to continue.",
"Torrent file disk space alert -> message"), volumeName]];
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Torrent file disk space alert -> button")];
[alert addButtonWithTitle: NSLocalizedString(@"Download Anyway", "Torrent file disk space alert -> button")];
if (onLeopard)
[alert setShowsSuppressionButton: YES];
else
[alert addButtonWithTitle: NSLocalizedString(@"Always Download", "Torrent file disk space alert -> button")];
if (remainingSpace < neededSpace)
{
NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText: [NSString stringWithFormat:
NSLocalizedString(@"Not enough remaining disk space to download \"%@\" completely.",
"Torrent file disk space alert -> title"), [self name]]];
[alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"The transfer will be paused."
" Clear up space on %@ or deselect files in the torrent inspector to continue.",
"Torrent file disk space alert -> message"), volumeName]];
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Torrent file disk space alert -> button")];
[alert addButtonWithTitle: NSLocalizedString(@"Download Anyway", "Torrent file disk space alert -> button")];
if (onLeopard)
[alert setShowsSuppressionButton: YES];
else
[alert addButtonWithTitle: NSLocalizedString(@"Always Download", "Torrent file disk space alert -> button")];
NSInteger result = [alert runModal];
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertThirdButtonReturn))
[fDefaults setBool: NO forKey: @"WarningRemainingSpace"];
[alert release];
return result != NSAlertFirstButtonReturn;
NSInteger result = [alert runModal];
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertThirdButtonReturn))
[fDefaults setBool: NO forKey: @"WarningRemainingSpace"];
[alert release];
return result != NSAlertFirstButtonReturn;
}
}
}
return YES;

View File

@ -821,9 +821,7 @@
{
BOOL ratio = [fDefaults boolForKey: @"DisplayGroupRowRatio"];
NSTableColumn * dlTableColumn = [self tableColumnWithIdentifier: @"DL"];
[dlTableColumn setHidden: ratio];
[[self tableColumnWithIdentifier: @"DL"] setHidden: ratio];
[[self tableColumnWithIdentifier: @"DL Image"] setHidden: ratio];
//change size of image column