simplify the remaining disk space checking code

This commit is contained in:
Mitchell Livingston 2008-03-17 21:12:07 +00:00
parent 8d5ce92d38
commit f14ee4fd6b
2 changed files with 13 additions and 16 deletions

View File

@ -2223,6 +2223,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_WARN_UNUSED_VARIABLE = NO;
MACOSX_DEPLOYMENT_TARGET = 10.4;
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
@ -2239,6 +2240,7 @@
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_WARN_UNUSED_VARIABLE = NO;
MACOSX_DEPLOYMENT_TARGET = 10.4;
PREBINDING = NO;
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";

View File

@ -536,11 +536,14 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
return YES;
NSFileManager * fileManager = [NSFileManager defaultManager];
NSString * downloadFolder = [self downloadFolder];
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
NSString * volumeName;
if ((volumeName = [[fileManager componentsToDisplayForPath: [self downloadFolder]] objectAtIndex: 0]))
if ((volumeName = [[fileManager componentsToDisplayForPath: downloadFolder] objectAtIndex: 0]))
{
NSDictionary * systemAttributes = [fileManager fileSystemAttributesAtPath: [self downloadFolder]];
NSDictionary * systemAttributes = onLeopard ? [fileManager attributesOfFileSystemForPath: downloadFolder error: NULL]
: [fileManager fileSystemAttributesAtPath: downloadFolder];
uint64_t remainingSpace = [[systemAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue], neededSpace = 0;
[self updateFileStat];
@ -553,21 +556,13 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
{
tr_file * file = &fInfo->files[i];
NSString * path = [[self downloadFolder] stringByAppendingPathComponent: [NSString stringWithUTF8String: file->name]];
if ([fileManager fileExistsAtPath: path])
{
NSDictionary * fileAttributes = [NSApp isOnLeopardOrBetter] ? [fileManager attributesOfItemAtPath: path error: NULL]
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)
{
NSLog(@"Problems getting file information for \"%@\".", path);
continue;
}
neededSpace += file->length - [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
}
else
neededSpace += file->length;
if (fileAttributes)
neededSpace -= [[fileAttributes objectForKey: NSFileSize] unsignedLongLongValue];
}
}