From 4f7742d422af580d12b53dedbcad3675e51e54c4 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 18 Mar 2008 03:20:27 +0000 Subject: [PATCH] speed up check for enough remaining space by first determining if there is enough space to download what's needed ignoring preallocation --- macosx/Torrent.m | 80 ++++++++++++++++++++------------------- macosx/TorrentTableView.m | 4 +- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/macosx/Torrent.m b/macosx/Torrent.m index f5367b451..487f5e034 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -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; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 3dfc76924..2b7000f6c 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -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