From dbbaf168aa946dcf989f7dab08f33ca5ca6e7086 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Thu, 19 Jul 2007 22:12:23 +0000 Subject: [PATCH] when checking remaining space, factor in preallocated space (but for now don't factor in non-selected files) --- macosx/English.lproj/Localizable.strings | Bin 41184 -> 41356 bytes macosx/Torrent.m | 28 +++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/macosx/English.lproj/Localizable.strings b/macosx/English.lproj/Localizable.strings index a04964fc25e64e5e562a9d3394c2bafe86224074..cde8a03d10c4759f96d30dc0f797ec1716287072 100644 GIT binary patch delta 74 zcmaEGkg4Y|(+2%U&U}U<1_g!`hSbRqQpMSef$U6%yvYKSbtmgKcHotj*?hiHP#yqj C{1(~( delta 22 ecmeA<%=F+O(+2&<$%#!;ljk?)Y))*_mInZNH3{SZ diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 49efb531e..4619866e1 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -807,19 +807,33 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80 NSString * volumeName; if ((volumeName = [[[NSFileManager defaultManager] componentsToDisplayForPath: [self downloadFolder]] objectAtIndex: 0])) { - NSDictionary * fsAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath: [self downloadFolder]]; - uint64_t remainingSpace = [[fsAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue]; + NSDictionary * systemAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath: [self downloadFolder]]; + uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue]; - #warning add file size to remaining space and add total size - if (remainingSpace <= fStat->left) + uint64_t existingSize = 0; + NSDirectoryEnumerator * enumerator; + if (enumerator = [[NSFileManager defaultManager] enumeratorAtPath: + [[self downloadFolder] stringByAppendingPathComponent: [self name]]]) + { + NSDictionary * fileAttributes; + while ([enumerator nextObject]) + { + fileAttributes = [enumerator fileAttributes]; + if (![[fileAttributes objectForKey: NSFileType] isEqualTo: NSFileTypeDirectory]) + existingSize += [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue]; + } + } + + #warning factor in checked files + if (remainingSpace + existingSize <= [self size]) { 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 %@ to continue.", - "Torrent file disk space alert -> message"), volumeName]]; + [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")]; [alert addButtonWithTitle: NSLocalizedString(@"Always Download", "Torrent file disk space alert -> button")];